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, 2010
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/>. */
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"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
127 static int processing_has_namespace_info
;
129 static const struct objfile_data
*dwarf2_objfile_data_key
;
131 struct dwarf2_section_info
137 /* True if we have tried to read this section. */
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type
;
145 DEF_VEC_I (offset_type
);
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
151 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size
;
157 /* The hash table. */
158 const offset_type
*index_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type index_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 struct dwarf2_per_objfile
167 struct dwarf2_section_info info
;
168 struct dwarf2_section_info abbrev
;
169 struct dwarf2_section_info line
;
170 struct dwarf2_section_info loc
;
171 struct dwarf2_section_info macinfo
;
172 struct dwarf2_section_info str
;
173 struct dwarf2_section_info ranges
;
174 struct dwarf2_section_info types
;
175 struct dwarf2_section_info frame
;
176 struct dwarf2_section_info eh_frame
;
177 struct dwarf2_section_info gdb_index
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units
;
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data
**type_comp_units
;
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data
*read_in_chain
;
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types
;
203 /* A flag indicating wether this objfile has a section loaded at a
205 int has_section_at_zero
;
207 /* True if we are using the mapped index. */
208 unsigned char using_index
;
210 /* The mapped index. */
211 struct mapped_index
*index_table
;
213 /* Set during partial symbol reading, to prevent queueing of full
215 int reading_partial_symbols
;
218 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
220 /* names of the debugging sections */
222 /* Note that if the debugging section has been compressed, it might
223 have a name like .zdebug_info. */
225 #define INFO_SECTION "debug_info"
226 #define ABBREV_SECTION "debug_abbrev"
227 #define LINE_SECTION "debug_line"
228 #define LOC_SECTION "debug_loc"
229 #define MACINFO_SECTION "debug_macinfo"
230 #define STR_SECTION "debug_str"
231 #define RANGES_SECTION "debug_ranges"
232 #define TYPES_SECTION "debug_types"
233 #define FRAME_SECTION "debug_frame"
234 #define EH_FRAME_SECTION "eh_frame"
235 #define GDB_INDEX_SECTION "gdb_index"
237 /* local data types */
239 /* We hold several abbreviation tables in memory at the same time. */
240 #ifndef ABBREV_HASH_SIZE
241 #define ABBREV_HASH_SIZE 121
244 /* The data in a compilation unit header, after target2host
245 translation, looks like this. */
246 struct comp_unit_head
250 unsigned char addr_size
;
251 unsigned char signed_addr_p
;
252 unsigned int abbrev_offset
;
254 /* Size of file offsets; either 4 or 8. */
255 unsigned int offset_size
;
257 /* Size of the length field; either 4 or 12. */
258 unsigned int initial_length_size
;
260 /* Offset to the first byte of this compilation unit header in the
261 .debug_info section, for resolving relative reference dies. */
264 /* Offset to first die in this cu from the start of the cu.
265 This will be the first byte following the compilation unit header. */
266 unsigned int first_die_offset
;
269 /* Internal state when decoding a particular compilation unit. */
272 /* The objfile containing this compilation unit. */
273 struct objfile
*objfile
;
275 /* The header of the compilation unit. */
276 struct comp_unit_head header
;
278 /* Base address of this compilation unit. */
279 CORE_ADDR base_address
;
281 /* Non-zero if base_address has been set. */
284 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
286 /* The language we are debugging. */
287 enum language language
;
288 const struct language_defn
*language_defn
;
290 const char *producer
;
292 /* The generic symbol table building routines have separate lists for
293 file scope symbols and all all other scopes (local scopes). So
294 we need to select the right one to pass to add_symbol_to_list().
295 We do it by keeping a pointer to the correct list in list_in_scope.
297 FIXME: The original dwarf code just treated the file scope as the
298 first local scope, and all other local scopes as nested local
299 scopes, and worked fine. Check to see if we really need to
300 distinguish these in buildsym.c. */
301 struct pending
**list_in_scope
;
303 /* DWARF abbreviation table associated with this compilation unit. */
304 struct abbrev_info
**dwarf2_abbrevs
;
306 /* Storage for the abbrev table. */
307 struct obstack abbrev_obstack
;
309 /* Hash table holding all the loaded partial DIEs. */
312 /* Storage for things with the same lifetime as this read-in compilation
313 unit, including partial DIEs. */
314 struct obstack comp_unit_obstack
;
316 /* When multiple dwarf2_cu structures are living in memory, this field
317 chains them all together, so that they can be released efficiently.
318 We will probably also want a generation counter so that most-recently-used
319 compilation units are cached... */
320 struct dwarf2_per_cu_data
*read_in_chain
;
322 /* Backchain to our per_cu entry if the tree has been built. */
323 struct dwarf2_per_cu_data
*per_cu
;
325 /* Pointer to the die -> type map. Although it is stored
326 permanently in per_cu, we copy it here to avoid double
330 /* How many compilation units ago was this CU last referenced? */
333 /* A hash table of die offsets for following references. */
336 /* Full DIEs if read in. */
337 struct die_info
*dies
;
339 /* A set of pointers to dwarf2_per_cu_data objects for compilation
340 units referenced by this one. Only set during full symbol processing;
341 partial symbol tables do not have dependencies. */
344 /* Header data from the line table, during full symbol processing. */
345 struct line_header
*line_header
;
347 /* Mark used when releasing cached dies. */
348 unsigned int mark
: 1;
350 /* This flag will be set if this compilation unit might include
351 inter-compilation-unit references. */
352 unsigned int has_form_ref_addr
: 1;
354 /* This flag will be set if this compilation unit includes any
355 DW_TAG_namespace DIEs. If we know that there are explicit
356 DIEs for namespaces, we don't need to try to infer them
357 from mangled names. */
358 unsigned int has_namespace_info
: 1;
361 /* When using the index (and thus not using psymtabs), each CU has an
362 object of this type. This is used to hold information needed by
363 the various "quick" methods. */
364 struct dwarf2_per_cu_quick_data
366 /* The line table. This can be NULL if there was no line table. */
367 struct line_header
*lines
;
369 /* The file names from the line table. */
370 const char **file_names
;
371 /* The file names from the line table after being run through
373 const char **full_names
;
375 /* The corresponding symbol table. This is NULL if symbols for this
376 CU have not yet been read. */
377 struct symtab
*symtab
;
379 /* A temporary mark bit used when iterating over all CUs in
380 expand_symtabs_matching. */
381 unsigned int mark
: 1;
383 /* True if we've tried to read the line table. */
384 unsigned int read_lines
: 1;
387 /* Persistent data held for a compilation unit, even when not
388 processing it. We put a pointer to this structure in the
389 read_symtab_private field of the psymtab. If we encounter
390 inter-compilation-unit references, we also maintain a sorted
391 list of all compilation units. */
393 struct dwarf2_per_cu_data
395 /* The start offset and length of this compilation unit. 2**29-1
396 bytes should suffice to store the length of any compilation unit
397 - if it doesn't, GDB will fall over anyway.
398 NOTE: Unlike comp_unit_head.length, this length includes
399 initial_length_size. */
401 unsigned int length
: 29;
403 /* Flag indicating this compilation unit will be read in before
404 any of the current compilation units are processed. */
405 unsigned int queued
: 1;
407 /* This flag will be set if we need to load absolutely all DIEs
408 for this compilation unit, instead of just the ones we think
409 are interesting. It gets set if we look for a DIE in the
410 hash table and don't find it. */
411 unsigned int load_all_dies
: 1;
413 /* Non-zero if this CU is from .debug_types.
414 Otherwise it's from .debug_info. */
415 unsigned int from_debug_types
: 1;
417 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
418 of the CU cache it gets reset to NULL again. */
419 struct dwarf2_cu
*cu
;
421 /* If full symbols for this CU have been read in, then this field
422 holds a map of DIE offsets to types. It isn't always possible
423 to reconstruct this information later, so we have to preserve
427 /* The corresponding objfile. */
428 struct objfile
*objfile
;
430 /* When using partial symbol tables, the 'psymtab' field is active.
431 Otherwise the 'quick' field is active. */
434 /* The partial symbol table associated with this compilation unit,
435 or NULL for partial units (which do not have an associated
437 struct partial_symtab
*psymtab
;
439 /* Data needed by the "quick" functions. */
440 struct dwarf2_per_cu_quick_data
*quick
;
444 /* Entry in the signatured_types hash table. */
446 struct signatured_type
450 /* Offset in .debug_types of the TU (type_unit) for this type. */
453 /* Offset in .debug_types of the type defined by this TU. */
454 unsigned int type_offset
;
456 /* The CU(/TU) of this type. */
457 struct dwarf2_per_cu_data per_cu
;
460 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
461 which are used for both .debug_info and .debug_types dies.
462 All parameters here are unchanging for the life of the call.
463 This struct exists to abstract away the constant parameters of
466 struct die_reader_specs
468 /* The bfd of this objfile. */
471 /* The CU of the DIE we are parsing. */
472 struct dwarf2_cu
*cu
;
474 /* Pointer to start of section buffer.
475 This is either the start of .debug_info or .debug_types. */
476 const gdb_byte
*buffer
;
479 /* The line number information for a compilation unit (found in the
480 .debug_line section) begins with a "statement program header",
481 which contains the following information. */
484 unsigned int total_length
;
485 unsigned short version
;
486 unsigned int header_length
;
487 unsigned char minimum_instruction_length
;
488 unsigned char maximum_ops_per_instruction
;
489 unsigned char default_is_stmt
;
491 unsigned char line_range
;
492 unsigned char opcode_base
;
494 /* standard_opcode_lengths[i] is the number of operands for the
495 standard opcode whose value is i. This means that
496 standard_opcode_lengths[0] is unused, and the last meaningful
497 element is standard_opcode_lengths[opcode_base - 1]. */
498 unsigned char *standard_opcode_lengths
;
500 /* The include_directories table. NOTE! These strings are not
501 allocated with xmalloc; instead, they are pointers into
502 debug_line_buffer. If you try to free them, `free' will get
504 unsigned int num_include_dirs
, include_dirs_size
;
507 /* The file_names table. NOTE! These strings are not allocated
508 with xmalloc; instead, they are pointers into debug_line_buffer.
509 Don't try to free them directly. */
510 unsigned int num_file_names
, file_names_size
;
514 unsigned int dir_index
;
515 unsigned int mod_time
;
517 int included_p
; /* Non-zero if referenced by the Line Number Program. */
518 struct symtab
*symtab
; /* The associated symbol table, if any. */
521 /* The start and end of the statement program following this
522 header. These point into dwarf2_per_objfile->line_buffer. */
523 gdb_byte
*statement_program_start
, *statement_program_end
;
526 /* When we construct a partial symbol table entry we only
527 need this much information. */
528 struct partial_die_info
530 /* Offset of this DIE. */
533 /* DWARF-2 tag for this DIE. */
534 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
536 /* Assorted flags describing the data found in this DIE. */
537 unsigned int has_children
: 1;
538 unsigned int is_external
: 1;
539 unsigned int is_declaration
: 1;
540 unsigned int has_type
: 1;
541 unsigned int has_specification
: 1;
542 unsigned int has_pc_info
: 1;
544 /* Flag set if the SCOPE field of this structure has been
546 unsigned int scope_set
: 1;
548 /* Flag set if the DIE has a byte_size attribute. */
549 unsigned int has_byte_size
: 1;
551 /* Flag set if any of the DIE's children are template arguments. */
552 unsigned int has_template_arguments
: 1;
554 /* The name of this DIE. Normally the value of DW_AT_name, but
555 sometimes a default name for unnamed DIEs. */
558 /* The scope to prepend to our children. This is generally
559 allocated on the comp_unit_obstack, so will disappear
560 when this compilation unit leaves the cache. */
563 /* The location description associated with this DIE, if any. */
564 struct dwarf_block
*locdesc
;
566 /* If HAS_PC_INFO, the PC range associated with this DIE. */
570 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
571 DW_AT_sibling, if any. */
574 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
575 DW_AT_specification (or DW_AT_abstract_origin or
577 unsigned int spec_offset
;
579 /* Pointers to this DIE's parent, first child, and next sibling,
581 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
584 /* This data structure holds the information of an abbrev. */
587 unsigned int number
; /* number identifying abbrev */
588 enum dwarf_tag tag
; /* dwarf tag */
589 unsigned short has_children
; /* boolean */
590 unsigned short num_attrs
; /* number of attributes */
591 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
592 struct abbrev_info
*next
; /* next in chain */
597 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
598 ENUM_BITFIELD(dwarf_form
) form
: 16;
601 /* Attributes have a name and a value */
604 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
605 ENUM_BITFIELD(dwarf_form
) form
: 15;
607 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
608 field should be in u.str (existing only for DW_STRING) but it is kept
609 here for better struct attribute alignment. */
610 unsigned int string_is_canonical
: 1;
615 struct dwarf_block
*blk
;
619 struct signatured_type
*signatured_type
;
624 /* This data structure holds a complete die structure. */
627 /* DWARF-2 tag for this DIE. */
628 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
630 /* Number of attributes */
631 unsigned char num_attrs
;
633 /* True if we're presently building the full type name for the
634 type derived from this DIE. */
635 unsigned char building_fullname
: 1;
640 /* Offset in .debug_info or .debug_types section. */
643 /* The dies in a compilation unit form an n-ary tree. PARENT
644 points to this die's parent; CHILD points to the first child of
645 this node; and all the children of a given node are chained
646 together via their SIBLING fields, terminated by a die whose
648 struct die_info
*child
; /* Its first child, if any. */
649 struct die_info
*sibling
; /* Its next sibling, if any. */
650 struct die_info
*parent
; /* Its parent, if any. */
652 /* An array of attributes, with NUM_ATTRS elements. There may be
653 zero, but it's not common and zero-sized arrays are not
654 sufficiently portable C. */
655 struct attribute attrs
[1];
658 struct function_range
661 CORE_ADDR lowpc
, highpc
;
663 struct function_range
*next
;
666 /* Get at parts of an attribute structure */
668 #define DW_STRING(attr) ((attr)->u.str)
669 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
670 #define DW_UNSND(attr) ((attr)->u.unsnd)
671 #define DW_BLOCK(attr) ((attr)->u.blk)
672 #define DW_SND(attr) ((attr)->u.snd)
673 #define DW_ADDR(attr) ((attr)->u.addr)
674 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
676 /* Blocks are a bunch of untyped bytes. */
683 #ifndef ATTR_ALLOC_CHUNK
684 #define ATTR_ALLOC_CHUNK 4
687 /* Allocate fields for structs, unions and enums in this size. */
688 #ifndef DW_FIELD_ALLOC_CHUNK
689 #define DW_FIELD_ALLOC_CHUNK 4
692 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
693 but this would require a corresponding change in unpack_field_as_long
695 static int bits_per_byte
= 8;
697 /* The routines that read and process dies for a C struct or C++ class
698 pass lists of data member fields and lists of member function fields
699 in an instance of a field_info structure, as defined below. */
702 /* List of data member and baseclasses fields. */
705 struct nextfield
*next
;
710 *fields
, *baseclasses
;
712 /* Number of fields (including baseclasses). */
715 /* Number of baseclasses. */
718 /* Set if the accesibility of one of the fields is not public. */
719 int non_public_fields
;
721 /* Member function fields array, entries are allocated in the order they
722 are encountered in the object file. */
725 struct nextfnfield
*next
;
726 struct fn_field fnfield
;
730 /* Member function fieldlist array, contains name of possibly overloaded
731 member function, number of overloaded member functions and a pointer
732 to the head of the member function field chain. */
737 struct nextfnfield
*head
;
741 /* Number of entries in the fnfieldlists array. */
744 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
745 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
746 struct typedef_field_list
748 struct typedef_field field
;
749 struct typedef_field_list
*next
;
752 unsigned typedef_field_list_count
;
755 /* One item on the queue of compilation units to read in full symbols
757 struct dwarf2_queue_item
759 struct dwarf2_per_cu_data
*per_cu
;
760 struct dwarf2_queue_item
*next
;
763 /* The current queue. */
764 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
766 /* Loaded secondary compilation units are kept in memory until they
767 have not been referenced for the processing of this many
768 compilation units. Set this to zero to disable caching. Cache
769 sizes of up to at least twenty will improve startup time for
770 typical inter-CU-reference binaries, at an obvious memory cost. */
771 static int dwarf2_max_cache_age
= 5;
773 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
774 struct cmd_list_element
*c
, const char *value
)
776 fprintf_filtered (file
, _("\
777 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
782 /* Various complaints about symbol reading that don't abort the process */
785 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
787 complaint (&symfile_complaints
,
788 _("statement list doesn't fit in .debug_line section"));
792 dwarf2_debug_line_missing_file_complaint (void)
794 complaint (&symfile_complaints
,
795 _(".debug_line section has line data without a file"));
799 dwarf2_debug_line_missing_end_sequence_complaint (void)
801 complaint (&symfile_complaints
,
802 _(".debug_line section has line program sequence without an end"));
806 dwarf2_complex_location_expr_complaint (void)
808 complaint (&symfile_complaints
, _("location expression too complex"));
812 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
815 complaint (&symfile_complaints
,
816 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
821 dwarf2_macros_too_long_complaint (void)
823 complaint (&symfile_complaints
,
824 _("macro info runs off end of `.debug_macinfo' section"));
828 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
830 complaint (&symfile_complaints
,
831 _("macro debug info contains a malformed macro definition:\n`%s'"),
836 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
838 complaint (&symfile_complaints
,
839 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
842 /* local function prototypes */
844 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
846 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
849 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
851 struct partial_symtab
*);
853 static void dwarf2_build_psymtabs_hard (struct objfile
*);
855 static void scan_partial_symbols (struct partial_die_info
*,
856 CORE_ADDR
*, CORE_ADDR
*,
857 int, struct dwarf2_cu
*);
859 static void add_partial_symbol (struct partial_die_info
*,
862 static void add_partial_namespace (struct partial_die_info
*pdi
,
863 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
864 int need_pc
, struct dwarf2_cu
*cu
);
866 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
867 CORE_ADDR
*highpc
, int need_pc
,
868 struct dwarf2_cu
*cu
);
870 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
871 struct dwarf2_cu
*cu
);
873 static void add_partial_subprogram (struct partial_die_info
*pdi
,
874 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
875 int need_pc
, struct dwarf2_cu
*cu
);
877 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
878 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
879 bfd
*abfd
, struct dwarf2_cu
*cu
);
881 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
883 static void psymtab_to_symtab_1 (struct partial_symtab
*);
885 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
887 static void dwarf2_free_abbrev_table (void *);
889 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
892 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
895 static struct partial_die_info
*load_partial_dies (bfd
*,
896 gdb_byte
*, gdb_byte
*,
897 int, struct dwarf2_cu
*);
899 static gdb_byte
*read_partial_die (struct partial_die_info
*,
900 struct abbrev_info
*abbrev
,
902 gdb_byte
*, gdb_byte
*,
905 static struct partial_die_info
*find_partial_die (unsigned int,
908 static void fixup_partial_die (struct partial_die_info
*,
911 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
912 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
914 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
915 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
917 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
919 static int read_1_signed_byte (bfd
*, gdb_byte
*);
921 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
923 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
925 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
927 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
930 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
932 static LONGEST read_checked_initial_length_and_offset
933 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
934 unsigned int *, unsigned int *);
936 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
939 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
941 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
943 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
945 static char *read_indirect_string (bfd
*, gdb_byte
*,
946 const struct comp_unit_head
*,
949 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
951 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
953 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
955 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
957 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
960 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
964 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
965 struct dwarf2_cu
*cu
);
967 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
969 static struct die_info
*die_specification (struct die_info
*die
,
970 struct dwarf2_cu
**);
972 static void free_line_header (struct line_header
*lh
);
974 static void add_file_name (struct line_header
*, char *, unsigned int,
975 unsigned int, unsigned int);
977 static struct line_header
*(dwarf_decode_line_header
978 (unsigned int offset
,
979 bfd
*abfd
, struct dwarf2_cu
*cu
));
981 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
982 struct dwarf2_cu
*, struct partial_symtab
*);
984 static void dwarf2_start_subfile (char *, char *, char *);
986 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
989 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
990 struct dwarf2_cu
*, struct symbol
*);
992 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
995 static void dwarf2_const_value_attr (struct attribute
*attr
,
998 struct obstack
*obstack
,
999 struct dwarf2_cu
*cu
, long *value
,
1001 struct dwarf2_locexpr_baton
**baton
);
1003 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1005 static int need_gnat_info (struct dwarf2_cu
*);
1007 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
1009 static void set_descriptive_type (struct type
*, struct die_info
*,
1010 struct dwarf2_cu
*);
1012 static struct type
*die_containing_type (struct die_info
*,
1013 struct dwarf2_cu
*);
1015 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
1017 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1019 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1021 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1022 const char *suffix
, int physname
,
1023 struct dwarf2_cu
*cu
);
1025 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1027 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1029 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1031 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1033 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1034 struct dwarf2_cu
*, struct partial_symtab
*);
1036 static int dwarf2_get_pc_bounds (struct die_info
*,
1037 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1038 struct partial_symtab
*);
1040 static void get_scope_pc_bounds (struct die_info
*,
1041 CORE_ADDR
*, CORE_ADDR
*,
1042 struct dwarf2_cu
*);
1044 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1045 CORE_ADDR
, struct dwarf2_cu
*);
1047 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1048 struct dwarf2_cu
*);
1050 static void dwarf2_attach_fields_to_type (struct field_info
*,
1051 struct type
*, struct dwarf2_cu
*);
1053 static void dwarf2_add_member_fn (struct field_info
*,
1054 struct die_info
*, struct type
*,
1055 struct dwarf2_cu
*);
1057 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1058 struct type
*, struct dwarf2_cu
*);
1060 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1062 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1064 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1066 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1068 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1070 static struct type
*read_module_type (struct die_info
*die
,
1071 struct dwarf2_cu
*cu
);
1073 static const char *namespace_name (struct die_info
*die
,
1074 int *is_anonymous
, struct dwarf2_cu
*);
1076 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1078 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1080 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1081 struct dwarf2_cu
*);
1083 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1085 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1087 gdb_byte
**new_info_ptr
,
1088 struct die_info
*parent
);
1090 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1092 gdb_byte
**new_info_ptr
,
1093 struct die_info
*parent
);
1095 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1097 gdb_byte
**new_info_ptr
,
1098 struct die_info
*parent
);
1100 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1101 struct die_info
**, gdb_byte
*,
1104 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1106 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1109 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1111 static const char *dwarf2_full_name (char *name
,
1112 struct die_info
*die
,
1113 struct dwarf2_cu
*cu
);
1115 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1116 struct dwarf2_cu
**);
1118 static char *dwarf_tag_name (unsigned int);
1120 static char *dwarf_attr_name (unsigned int);
1122 static char *dwarf_form_name (unsigned int);
1124 static char *dwarf_bool_name (unsigned int);
1126 static char *dwarf_type_encoding_name (unsigned int);
1129 static char *dwarf_cfi_name (unsigned int);
1132 static struct die_info
*sibling_die (struct die_info
*);
1134 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1136 static void dump_die_for_error (struct die_info
*);
1138 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1141 /*static*/ void dump_die (struct die_info
*, int max_level
);
1143 static void store_in_ref_table (struct die_info
*,
1144 struct dwarf2_cu
*);
1146 static int is_ref_attr (struct attribute
*);
1148 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1150 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1152 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1154 struct dwarf2_cu
**);
1156 static struct die_info
*follow_die_ref (struct die_info
*,
1158 struct dwarf2_cu
**);
1160 static struct die_info
*follow_die_sig (struct die_info
*,
1162 struct dwarf2_cu
**);
1164 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1165 unsigned int offset
);
1167 static void read_signatured_type (struct objfile
*,
1168 struct signatured_type
*type_sig
);
1170 /* memory allocation interface */
1172 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1174 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1176 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1178 static void initialize_cu_func_list (struct dwarf2_cu
*);
1180 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1181 struct dwarf2_cu
*);
1183 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1184 char *, bfd
*, struct dwarf2_cu
*);
1186 static int attr_form_is_block (struct attribute
*);
1188 static int attr_form_is_section_offset (struct attribute
*);
1190 static int attr_form_is_constant (struct attribute
*);
1192 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1194 struct dwarf2_cu
*cu
);
1196 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1197 struct abbrev_info
*abbrev
,
1198 struct dwarf2_cu
*cu
);
1200 static void free_stack_comp_unit (void *);
1202 static hashval_t
partial_die_hash (const void *item
);
1204 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1206 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1207 (unsigned int offset
, struct objfile
*objfile
);
1209 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1210 (unsigned int offset
, struct objfile
*objfile
);
1212 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1214 static void free_one_comp_unit (void *);
1216 static void free_cached_comp_units (void *);
1218 static void age_cached_comp_units (void);
1220 static void free_one_cached_comp_unit (void *);
1222 static struct type
*set_die_type (struct die_info
*, struct type
*,
1223 struct dwarf2_cu
*);
1225 static void create_all_comp_units (struct objfile
*);
1227 static int create_debug_types_hash_table (struct objfile
*objfile
);
1229 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1232 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1234 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1235 struct dwarf2_per_cu_data
*);
1237 static void dwarf2_mark (struct dwarf2_cu
*);
1239 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1241 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1243 static void dwarf2_release_queue (void *dummy
);
1245 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1246 struct objfile
*objfile
);
1248 static void process_queue (struct objfile
*objfile
);
1250 static void find_file_and_directory (struct die_info
*die
,
1251 struct dwarf2_cu
*cu
,
1252 char **name
, char **comp_dir
);
1254 static char *file_full_name (int file
, struct line_header
*lh
,
1255 const char *comp_dir
);
1257 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1260 unsigned int buffer_size
,
1263 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1264 struct dwarf2_cu
*cu
);
1266 static htab_t
allocate_signatured_type_hash_table (struct objfile
*objfile
);
1270 /* Convert VALUE between big- and little-endian. */
1272 byte_swap (offset_type value
)
1276 result
= (value
& 0xff) << 24;
1277 result
|= (value
& 0xff00) << 8;
1278 result
|= (value
& 0xff0000) >> 8;
1279 result
|= (value
& 0xff000000) >> 24;
1283 #define MAYBE_SWAP(V) byte_swap (V)
1286 #define MAYBE_SWAP(V) (V)
1287 #endif /* WORDS_BIGENDIAN */
1289 /* The suffix for an index file. */
1290 #define INDEX_SUFFIX ".gdb-index"
1292 /* Try to locate the sections we need for DWARF 2 debugging
1293 information and return true if we have enough to do something. */
1296 dwarf2_has_info (struct objfile
*objfile
)
1298 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1299 if (!dwarf2_per_objfile
)
1301 /* Initialize per-objfile state. */
1302 struct dwarf2_per_objfile
*data
1303 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1305 memset (data
, 0, sizeof (*data
));
1306 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1307 dwarf2_per_objfile
= data
;
1309 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1310 dwarf2_per_objfile
->objfile
= objfile
;
1312 return (dwarf2_per_objfile
->info
.asection
!= NULL
1313 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1316 /* When loading sections, we can either look for ".<name>", or for
1317 * ".z<name>", which indicates a compressed section. */
1320 section_is_p (const char *section_name
, const char *name
)
1322 return (section_name
[0] == '.'
1323 && (strcmp (section_name
+ 1, name
) == 0
1324 || (section_name
[1] == 'z'
1325 && strcmp (section_name
+ 2, name
) == 0)));
1328 /* This function is mapped across the sections and remembers the
1329 offset and size of each of the debugging sections we are interested
1333 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1335 if (section_is_p (sectp
->name
, INFO_SECTION
))
1337 dwarf2_per_objfile
->info
.asection
= sectp
;
1338 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1340 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1342 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1343 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1345 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1347 dwarf2_per_objfile
->line
.asection
= sectp
;
1348 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1350 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1352 dwarf2_per_objfile
->loc
.asection
= sectp
;
1353 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1355 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1357 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1358 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1360 else if (section_is_p (sectp
->name
, STR_SECTION
))
1362 dwarf2_per_objfile
->str
.asection
= sectp
;
1363 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1365 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1367 dwarf2_per_objfile
->frame
.asection
= sectp
;
1368 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1370 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1372 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1374 if (aflag
& SEC_HAS_CONTENTS
)
1376 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1377 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1380 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1382 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1383 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1385 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1387 dwarf2_per_objfile
->types
.asection
= sectp
;
1388 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1390 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1392 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1393 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1396 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1397 && bfd_section_vma (abfd
, sectp
) == 0)
1398 dwarf2_per_objfile
->has_section_at_zero
= 1;
1401 /* Decompress a section that was compressed using zlib. Store the
1402 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1405 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1406 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1408 bfd
*abfd
= objfile
->obfd
;
1410 error (_("Support for zlib-compressed DWARF data (from '%s') "
1411 "is disabled in this copy of GDB"),
1412 bfd_get_filename (abfd
));
1414 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1415 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1416 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1417 bfd_size_type uncompressed_size
;
1418 gdb_byte
*uncompressed_buffer
;
1421 int header_size
= 12;
1423 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1424 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1425 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1426 bfd_get_filename (abfd
));
1428 /* Read the zlib header. In this case, it should be "ZLIB" followed
1429 by the uncompressed section size, 8 bytes in big-endian order. */
1430 if (compressed_size
< header_size
1431 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1432 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1433 bfd_get_filename (abfd
));
1434 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1435 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1436 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1437 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1438 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1439 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1440 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1441 uncompressed_size
+= compressed_buffer
[11];
1443 /* It is possible the section consists of several compressed
1444 buffers concatenated together, so we uncompress in a loop. */
1448 strm
.avail_in
= compressed_size
- header_size
;
1449 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1450 strm
.avail_out
= uncompressed_size
;
1451 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1453 rc
= inflateInit (&strm
);
1454 while (strm
.avail_in
> 0)
1457 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1458 bfd_get_filename (abfd
), rc
);
1459 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1460 + (uncompressed_size
- strm
.avail_out
));
1461 rc
= inflate (&strm
, Z_FINISH
);
1462 if (rc
!= Z_STREAM_END
)
1463 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1464 bfd_get_filename (abfd
), rc
);
1465 rc
= inflateReset (&strm
);
1467 rc
= inflateEnd (&strm
);
1469 || strm
.avail_out
!= 0)
1470 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1471 bfd_get_filename (abfd
), rc
);
1473 do_cleanups (cleanup
);
1474 *outbuf
= uncompressed_buffer
;
1475 *outsize
= uncompressed_size
;
1479 /* Read the contents of the section SECTP from object file specified by
1480 OBJFILE, store info about the section into INFO.
1481 If the section is compressed, uncompress it before returning. */
1484 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1486 bfd
*abfd
= objfile
->obfd
;
1487 asection
*sectp
= info
->asection
;
1488 gdb_byte
*buf
, *retbuf
;
1489 unsigned char header
[4];
1493 info
->buffer
= NULL
;
1494 info
->was_mmapped
= 0;
1497 if (info
->asection
== NULL
|| info
->size
== 0)
1500 /* Check if the file has a 4-byte header indicating compression. */
1501 if (info
->size
> sizeof (header
)
1502 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1503 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1505 /* Upon decompression, update the buffer and its size. */
1506 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1508 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1516 pagesize
= getpagesize ();
1518 /* Only try to mmap sections which are large enough: we don't want to
1519 waste space due to fragmentation. Also, only try mmap for sections
1520 without relocations. */
1522 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1524 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1525 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1526 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1527 MAP_PRIVATE
, pg_offset
);
1529 if (retbuf
!= MAP_FAILED
)
1531 info
->was_mmapped
= 1;
1532 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1533 #if HAVE_POSIX_MADVISE
1534 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1541 /* If we get here, we are a normal, not-compressed section. */
1543 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1545 /* When debugging .o files, we may need to apply relocations; see
1546 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1547 We never compress sections in .o files, so we only need to
1548 try this when the section is not compressed. */
1549 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1552 info
->buffer
= retbuf
;
1556 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1557 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1558 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1559 bfd_get_filename (abfd
));
1562 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1566 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1567 asection
**sectp
, gdb_byte
**bufp
,
1568 bfd_size_type
*sizep
)
1570 struct dwarf2_per_objfile
*data
1571 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1572 struct dwarf2_section_info
*info
;
1574 /* We may see an objfile without any DWARF, in which case we just
1583 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1584 info
= &data
->eh_frame
;
1585 else if (section_is_p (section_name
, FRAME_SECTION
))
1586 info
= &data
->frame
;
1590 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1591 /* We haven't read this section in yet. Do it now. */
1592 dwarf2_read_section (objfile
, info
);
1594 *sectp
= info
->asection
;
1595 *bufp
= info
->buffer
;
1596 *sizep
= info
->size
;
1601 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1604 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1605 struct dwarf2_per_cu_data
*per_cu
)
1607 struct cleanup
*back_to
;
1609 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1611 queue_comp_unit (per_cu
, objfile
);
1613 if (per_cu
->from_debug_types
)
1614 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1616 load_full_comp_unit (per_cu
, objfile
);
1618 process_queue (objfile
);
1620 /* Age the cache, releasing compilation units that have not
1621 been used recently. */
1622 age_cached_comp_units ();
1624 do_cleanups (back_to
);
1627 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1628 the objfile from which this CU came. Returns the resulting symbol
1630 static struct symtab
*
1631 dw2_instantiate_symtab (struct objfile
*objfile
,
1632 struct dwarf2_per_cu_data
*per_cu
)
1634 if (!per_cu
->v
.quick
->symtab
)
1636 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1637 increment_reading_symtab ();
1638 dw2_do_instantiate_symtab (objfile
, per_cu
);
1639 do_cleanups (back_to
);
1641 return per_cu
->v
.quick
->symtab
;
1644 /* Return the CU given its index. */
1645 static struct dwarf2_per_cu_data
*
1646 dw2_get_cu (int index
)
1648 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1650 index
-= dwarf2_per_objfile
->n_comp_units
;
1651 return dwarf2_per_objfile
->type_comp_units
[index
];
1653 return dwarf2_per_objfile
->all_comp_units
[index
];
1656 /* A helper function that knows how to read a 64-bit value in a way
1657 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1660 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1662 if (sizeof (ULONGEST
) < 8)
1666 /* Ignore the upper 4 bytes if they are all zero. */
1667 for (i
= 0; i
< 4; ++i
)
1668 if (bytes
[i
+ 4] != 0)
1671 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1674 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1678 /* Read the CU list from the mapped index, and use it to create all
1679 the CU objects for this objfile. Return 0 if something went wrong,
1680 1 if everything went ok. */
1682 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1683 offset_type cu_list_elements
)
1687 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1688 dwarf2_per_objfile
->all_comp_units
1689 = obstack_alloc (&objfile
->objfile_obstack
,
1690 dwarf2_per_objfile
->n_comp_units
1691 * sizeof (struct dwarf2_per_cu_data
*));
1693 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1695 struct dwarf2_per_cu_data
*the_cu
;
1696 ULONGEST offset
, length
;
1698 if (!extract_cu_value (cu_list
, &offset
)
1699 || !extract_cu_value (cu_list
+ 8, &length
))
1703 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1704 struct dwarf2_per_cu_data
);
1705 the_cu
->offset
= offset
;
1706 the_cu
->length
= length
;
1707 the_cu
->objfile
= objfile
;
1708 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1709 struct dwarf2_per_cu_quick_data
);
1710 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1716 /* Create the signatured type hash table from the index. */
1718 create_signatured_type_hash_from_index (struct objfile
*objfile
,
1719 const gdb_byte
*bytes
,
1720 offset_type elements
)
1725 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1726 dwarf2_per_objfile
->type_comp_units
1727 = obstack_alloc (&objfile
->objfile_obstack
,
1728 dwarf2_per_objfile
->n_type_comp_units
1729 * sizeof (struct dwarf2_per_cu_data
*));
1731 type_hash
= allocate_signatured_type_hash_table (objfile
);
1733 for (i
= 0; i
< elements
; i
+= 3)
1735 struct signatured_type
*type_sig
;
1736 ULONGEST offset
, type_offset
, signature
;
1739 if (!extract_cu_value (bytes
, &offset
)
1740 || !extract_cu_value (bytes
+ 8, &type_offset
))
1742 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1745 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1746 struct signatured_type
);
1747 type_sig
->signature
= signature
;
1748 type_sig
->offset
= offset
;
1749 type_sig
->type_offset
= type_offset
;
1750 type_sig
->per_cu
.from_debug_types
= 1;
1751 type_sig
->per_cu
.offset
= offset
;
1752 type_sig
->per_cu
.objfile
= objfile
;
1753 type_sig
->per_cu
.v
.quick
1754 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1755 struct dwarf2_per_cu_quick_data
);
1757 slot
= htab_find_slot (type_hash
, type_sig
, INSERT
);
1760 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1763 dwarf2_per_objfile
->signatured_types
= type_hash
;
1768 /* Read the address map data from the mapped index, and use it to
1769 populate the objfile's psymtabs_addrmap. */
1771 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1773 const gdb_byte
*iter
, *end
;
1774 struct obstack temp_obstack
;
1775 struct addrmap
*mutable_map
;
1776 struct cleanup
*cleanup
;
1779 obstack_init (&temp_obstack
);
1780 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1781 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1783 iter
= index
->address_table
;
1784 end
= iter
+ index
->address_table_size
;
1786 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1790 ULONGEST hi
, lo
, cu_index
;
1791 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1793 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1795 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1798 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1799 dw2_get_cu (cu_index
));
1802 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1803 &objfile
->objfile_obstack
);
1804 do_cleanups (cleanup
);
1807 /* The hash function for strings in the mapped index. This is the
1808 same as the hashtab.c hash function, but we keep a separate copy to
1809 maintain control over the implementation. This is necessary
1810 because the hash function is tied to the format of the mapped index
1813 mapped_index_string_hash (const void *p
)
1815 const unsigned char *str
= (const unsigned char *) p
;
1819 while ((c
= *str
++) != 0)
1820 r
= r
* 67 + c
- 113;
1825 /* Find a slot in the mapped index INDEX for the object named NAME.
1826 If NAME is found, set *VEC_OUT to point to the CU vector in the
1827 constant pool and return 1. If NAME cannot be found, return 0. */
1829 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1830 offset_type
**vec_out
)
1832 offset_type hash
= mapped_index_string_hash (name
);
1833 offset_type slot
, step
;
1835 slot
= hash
& (index
->index_table_slots
- 1);
1836 step
= ((hash
* 17) & (index
->index_table_slots
- 1)) | 1;
1840 /* Convert a slot number to an offset into the table. */
1841 offset_type i
= 2 * slot
;
1843 if (index
->index_table
[i
] == 0 && index
->index_table
[i
+ 1] == 0)
1846 str
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[i
]);
1847 if (!strcmp (name
, str
))
1849 *vec_out
= (offset_type
*) (index
->constant_pool
1850 + MAYBE_SWAP (index
->index_table
[i
+ 1]));
1854 slot
= (slot
+ step
) & (index
->index_table_slots
- 1);
1858 /* Read the index file. If everything went ok, initialize the "quick"
1859 elements of all the CUs and return 1. Otherwise, return 0. */
1861 dwarf2_read_index (struct objfile
*objfile
)
1864 struct mapped_index
*map
;
1865 offset_type
*metadata
;
1866 const gdb_byte
*cu_list
;
1867 const gdb_byte
*types_list
= NULL
;
1868 offset_type version
, cu_list_elements
;
1869 offset_type types_list_elements
= 0;
1872 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1873 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1875 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1877 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1878 /* Version check. */
1879 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1882 /* Index version 1 neglected to account for .debug_types. So,
1883 if we see .debug_types, we cannot use this index. */
1884 if (dwarf2_per_objfile
->types
.asection
!= NULL
1885 && dwarf2_per_objfile
->types
.size
!= 0)
1888 else if (version
!= 2)
1891 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1892 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1894 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1897 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1898 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1904 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1905 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1906 - MAYBE_SWAP (metadata
[i
]))
1911 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1912 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1913 - MAYBE_SWAP (metadata
[i
]));
1916 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1917 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1918 - MAYBE_SWAP (metadata
[i
]))
1919 / (2 * sizeof (offset_type
)));
1922 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1924 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1928 && types_list_elements
1929 && !create_signatured_type_hash_from_index (objfile
, types_list
,
1930 types_list_elements
))
1933 create_addrmap_from_index (objfile
, map
);
1935 dwarf2_per_objfile
->index_table
= map
;
1936 dwarf2_per_objfile
->using_index
= 1;
1941 /* A helper for the "quick" functions which sets the global
1942 dwarf2_per_objfile according to OBJFILE. */
1944 dw2_setup (struct objfile
*objfile
)
1946 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1947 gdb_assert (dwarf2_per_objfile
);
1950 /* A helper for the "quick" functions which attempts to read the line
1951 table for THIS_CU. */
1953 dw2_require_line_header (struct objfile
*objfile
,
1954 struct dwarf2_per_cu_data
*this_cu
)
1956 bfd
*abfd
= objfile
->obfd
;
1957 struct line_header
*lh
= NULL
;
1958 struct attribute
*attr
;
1959 struct cleanup
*cleanups
;
1960 struct die_info
*comp_unit_die
;
1961 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
1962 int has_children
, i
;
1963 struct dwarf2_cu cu
;
1964 unsigned int bytes_read
, buffer_size
;
1965 struct die_reader_specs reader_specs
;
1966 char *name
, *comp_dir
;
1968 if (this_cu
->v
.quick
->read_lines
)
1970 this_cu
->v
.quick
->read_lines
= 1;
1972 memset (&cu
, 0, sizeof (cu
));
1973 cu
.objfile
= objfile
;
1974 obstack_init (&cu
.comp_unit_obstack
);
1976 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
1978 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1979 buffer_size
= dwarf2_per_objfile
->info
.size
;
1980 buffer
= dwarf2_per_objfile
->info
.buffer
;
1981 info_ptr
= buffer
+ this_cu
->offset
;
1982 beg_of_comp_unit
= info_ptr
;
1984 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1985 buffer
, buffer_size
,
1988 /* Complete the cu_header. */
1989 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1990 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1993 cu
.per_cu
= this_cu
;
1995 dwarf2_read_abbrevs (abfd
, &cu
);
1996 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1998 if (this_cu
->from_debug_types
)
1999 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2000 init_cu_die_reader (&reader_specs
, &cu
);
2001 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2004 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2007 unsigned int line_offset
= DW_UNSND (attr
);
2008 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2012 do_cleanups (cleanups
);
2016 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2018 this_cu
->v
.quick
->lines
= lh
;
2020 this_cu
->v
.quick
->file_names
2021 = obstack_alloc (&objfile
->objfile_obstack
,
2022 lh
->num_file_names
* sizeof (char *));
2023 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2024 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2026 do_cleanups (cleanups
);
2029 /* A helper for the "quick" functions which computes and caches the
2030 real path for a given file name from the line table.
2031 dw2_require_line_header must have been called before this is
2034 dw2_require_full_path (struct objfile
*objfile
,
2035 struct dwarf2_per_cu_data
*cu
,
2038 if (!cu
->v
.quick
->full_names
)
2039 cu
->v
.quick
->full_names
2040 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2041 cu
->v
.quick
->lines
->num_file_names
,
2044 if (!cu
->v
.quick
->full_names
[index
])
2045 cu
->v
.quick
->full_names
[index
]
2046 = gdb_realpath (cu
->v
.quick
->file_names
[index
]);
2048 return cu
->v
.quick
->full_names
[index
];
2051 static struct symtab
*
2052 dw2_find_last_source_symtab (struct objfile
*objfile
)
2055 dw2_setup (objfile
);
2056 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2057 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2061 dw2_forget_cached_source_info (struct objfile
*objfile
)
2065 dw2_setup (objfile
);
2066 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2067 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2069 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2071 if (cu
->v
.quick
->full_names
)
2075 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2076 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
2082 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2083 const char *full_path
, const char *real_path
,
2084 struct symtab
**result
)
2087 int check_basename
= lbasename (name
) == name
;
2088 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2090 dw2_setup (objfile
);
2091 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2092 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2095 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2097 if (cu
->v
.quick
->symtab
)
2100 dw2_require_line_header (objfile
, cu
);
2101 if (!cu
->v
.quick
->lines
)
2104 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2106 const char *this_name
= cu
->v
.quick
->file_names
[j
];
2108 if (FILENAME_CMP (name
, this_name
) == 0)
2110 *result
= dw2_instantiate_symtab (objfile
, cu
);
2114 if (check_basename
&& ! base_cu
2115 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2118 if (full_path
!= NULL
)
2120 const char *this_full_name
= dw2_require_full_path (objfile
,
2124 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2126 *result
= dw2_instantiate_symtab (objfile
, cu
);
2131 if (real_path
!= NULL
)
2133 const char *this_full_name
= dw2_require_full_path (objfile
,
2136 if (this_full_name
!= NULL
)
2138 char *rp
= gdb_realpath (this_full_name
);
2139 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2142 *result
= dw2_instantiate_symtab (objfile
, cu
);
2153 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2160 static struct symtab
*
2161 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2162 const char *name
, domain_enum domain
)
2164 /* We do all the work in the pre_expand_symtabs_matching hook
2169 /* A helper function that expands all symtabs that hold an object
2172 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2174 dw2_setup (objfile
);
2176 if (dwarf2_per_objfile
->index_table
)
2180 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2183 offset_type i
, len
= MAYBE_SWAP (*vec
);
2184 for (i
= 0; i
< len
; ++i
)
2186 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2187 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (cu_index
);
2189 dw2_instantiate_symtab (objfile
, cu
);
2196 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2197 int kind
, const char *name
,
2200 dw2_do_expand_symtabs_matching (objfile
, name
);
2204 dw2_print_stats (struct objfile
*objfile
)
2208 dw2_setup (objfile
);
2210 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2211 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2213 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2215 if (!cu
->v
.quick
->symtab
)
2218 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2222 dw2_dump (struct objfile
*objfile
)
2224 /* Nothing worth printing. */
2228 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2229 struct section_offsets
*delta
)
2231 /* There's nothing to relocate here. */
2235 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2236 const char *func_name
)
2238 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2242 dw2_expand_all_symtabs (struct objfile
*objfile
)
2246 dw2_setup (objfile
);
2248 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2249 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2251 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2253 dw2_instantiate_symtab (objfile
, cu
);
2258 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2259 const char *filename
)
2263 dw2_setup (objfile
);
2264 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2265 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2268 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2270 if (cu
->v
.quick
->symtab
)
2273 dw2_require_line_header (objfile
, cu
);
2274 if (!cu
->v
.quick
->lines
)
2277 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2279 const char *this_name
= cu
->v
.quick
->file_names
[j
];
2280 if (strcmp (this_name
, filename
) == 0)
2282 dw2_instantiate_symtab (objfile
, cu
);
2290 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2292 struct dwarf2_per_cu_data
*cu
;
2295 dw2_setup (objfile
);
2297 if (!dwarf2_per_objfile
->index_table
)
2300 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2304 /* Note that this just looks at the very first one named NAME -- but
2305 actually we are looking for a function. find_main_filename
2306 should be rewritten so that it doesn't require a custom hook. It
2307 could just use the ordinary symbol tables. */
2308 /* vec[0] is the length, which must always be >0. */
2309 cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2311 dw2_require_line_header (objfile
, cu
);
2312 if (!cu
->v
.quick
->lines
)
2315 return cu
->v
.quick
->file_names
[cu
->v
.quick
->lines
->num_file_names
- 1];
2319 dw2_map_ada_symtabs (struct objfile
*objfile
,
2320 int (*wild_match
) (const char *, int, const char *),
2321 int (*is_name_suffix
) (const char *),
2322 void (*callback
) (struct objfile
*,
2323 struct symtab
*, void *),
2324 const char *name
, int global
,
2325 domain_enum
namespace, int wild
,
2328 /* For now, we don't support Ada, so this function can't be
2330 internal_error (__FILE__
, __LINE__
,
2331 _("map_ada_symtabs called via index method"));
2335 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2336 int (*file_matcher
) (const char *, void *),
2337 int (*name_matcher
) (const char *, void *),
2344 dw2_setup (objfile
);
2345 if (!dwarf2_per_objfile
->index_table
)
2348 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2349 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2352 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2354 cu
->v
.quick
->mark
= 0;
2355 if (cu
->v
.quick
->symtab
)
2358 dw2_require_line_header (objfile
, cu
);
2359 if (!cu
->v
.quick
->lines
)
2362 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2364 if (file_matcher (cu
->v
.quick
->file_names
[j
], data
))
2366 cu
->v
.quick
->mark
= 1;
2373 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2376 offset_type idx
= 2 * iter
;
2378 offset_type
*vec
, vec_len
, vec_idx
;
2380 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2381 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2384 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2385 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2387 if (! (*name_matcher
) (name
, data
))
2390 /* The name was matched, now expand corresponding CUs that were
2392 vec
= (offset_type
*) (dwarf2_per_objfile
->index_table
->constant_pool
2393 + dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1]);
2394 vec_len
= MAYBE_SWAP (vec
[0]);
2395 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2397 struct dwarf2_per_cu_data
*cu
;
2399 cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2400 if (cu
->v
.quick
->mark
)
2401 dw2_instantiate_symtab (objfile
, cu
);
2406 static struct symtab
*
2407 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2408 struct minimal_symbol
*msymbol
,
2410 struct obj_section
*section
,
2413 struct dwarf2_per_cu_data
*data
;
2415 dw2_setup (objfile
);
2417 if (!objfile
->psymtabs_addrmap
)
2420 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2424 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2425 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2426 paddress (get_objfile_arch (objfile
), pc
));
2428 return dw2_instantiate_symtab (objfile
, data
);
2432 dw2_map_symbol_names (struct objfile
*objfile
,
2433 void (*fun
) (const char *, void *),
2437 dw2_setup (objfile
);
2439 if (!dwarf2_per_objfile
->index_table
)
2443 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2446 offset_type idx
= 2 * iter
;
2448 offset_type
*vec
, vec_len
, vec_idx
;
2450 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2451 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2454 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2455 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2457 (*fun
) (name
, data
);
2462 dw2_map_symbol_filenames (struct objfile
*objfile
,
2463 void (*fun
) (const char *, const char *, void *),
2468 dw2_setup (objfile
);
2469 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2470 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2473 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2475 if (cu
->v
.quick
->symtab
)
2478 dw2_require_line_header (objfile
, cu
);
2479 if (!cu
->v
.quick
->lines
)
2482 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2484 const char *this_full_name
= dw2_require_full_path (objfile
, cu
, j
);
2485 (*fun
) (cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2491 dw2_has_symbols (struct objfile
*objfile
)
2496 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2499 dw2_find_last_source_symtab
,
2500 dw2_forget_cached_source_info
,
2503 dw2_pre_expand_symtabs_matching
,
2507 dw2_expand_symtabs_for_function
,
2508 dw2_expand_all_symtabs
,
2509 dw2_expand_symtabs_with_filename
,
2510 dw2_find_symbol_file
,
2511 dw2_map_ada_symtabs
,
2512 dw2_expand_symtabs_matching
,
2513 dw2_find_pc_sect_symtab
,
2514 dw2_map_symbol_names
,
2515 dw2_map_symbol_filenames
2518 /* Initialize for reading DWARF for this objfile. Return 0 if this
2519 file will use psymtabs, or 1 if using the GNU index. */
2522 dwarf2_initialize_objfile (struct objfile
*objfile
)
2524 /* If we're about to read full symbols, don't bother with the
2525 indices. In this case we also don't care if some other debug
2526 format is making psymtabs, because they are all about to be
2528 if ((objfile
->flags
& OBJF_READNOW
))
2532 dwarf2_per_objfile
->using_index
= 1;
2533 create_all_comp_units (objfile
);
2534 create_debug_types_hash_table (objfile
);
2536 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2537 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2539 struct dwarf2_per_cu_data
*cu
= dw2_get_cu (i
);
2541 cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2542 struct dwarf2_per_cu_quick_data
);
2545 /* Return 1 so that gdb sees the "quick" functions. However,
2546 these functions will be no-ops because we will have expanded
2551 if (dwarf2_read_index (objfile
))
2554 dwarf2_build_psymtabs (objfile
);
2560 /* Build a partial symbol table. */
2563 dwarf2_build_psymtabs (struct objfile
*objfile
)
2565 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2567 init_psymbol_list (objfile
, 1024);
2570 dwarf2_build_psymtabs_hard (objfile
);
2573 /* Return TRUE if OFFSET is within CU_HEADER. */
2576 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2578 unsigned int bottom
= cu_header
->offset
;
2579 unsigned int top
= (cu_header
->offset
2581 + cu_header
->initial_length_size
);
2583 return (offset
>= bottom
&& offset
< top
);
2586 /* Read in the comp unit header information from the debug_info at info_ptr.
2587 NOTE: This leaves members offset, first_die_offset to be filled in
2591 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2592 gdb_byte
*info_ptr
, bfd
*abfd
)
2595 unsigned int bytes_read
;
2597 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2598 cu_header
->initial_length_size
= bytes_read
;
2599 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2600 info_ptr
+= bytes_read
;
2601 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2603 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2605 info_ptr
+= bytes_read
;
2606 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2608 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2609 if (signed_addr
< 0)
2610 internal_error (__FILE__
, __LINE__
,
2611 _("read_comp_unit_head: dwarf from non elf file"));
2612 cu_header
->signed_addr_p
= signed_addr
;
2618 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2619 gdb_byte
*buffer
, unsigned int buffer_size
,
2622 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2624 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2626 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2627 error (_("Dwarf Error: wrong version in compilation unit header "
2628 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2629 bfd_get_filename (abfd
));
2631 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2632 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2633 "(offset 0x%lx + 6) [in module %s]"),
2634 (long) header
->abbrev_offset
,
2635 (long) (beg_of_comp_unit
- buffer
),
2636 bfd_get_filename (abfd
));
2638 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2639 > buffer
+ buffer_size
)
2640 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2641 "(offset 0x%lx + 0) [in module %s]"),
2642 (long) header
->length
,
2643 (long) (beg_of_comp_unit
- buffer
),
2644 bfd_get_filename (abfd
));
2649 /* Read in the types comp unit header information from .debug_types entry at
2650 types_ptr. The result is a pointer to one past the end of the header. */
2653 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2654 ULONGEST
*signature
,
2655 gdb_byte
*types_ptr
, bfd
*abfd
)
2657 gdb_byte
*initial_types_ptr
= types_ptr
;
2659 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2660 &dwarf2_per_objfile
->types
);
2661 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2663 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2665 *signature
= read_8_bytes (abfd
, types_ptr
);
2667 types_ptr
+= cu_header
->offset_size
;
2668 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2673 /* Allocate a new partial symtab for file named NAME and mark this new
2674 partial symtab as being an include of PST. */
2677 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2678 struct objfile
*objfile
)
2680 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2682 subpst
->section_offsets
= pst
->section_offsets
;
2683 subpst
->textlow
= 0;
2684 subpst
->texthigh
= 0;
2686 subpst
->dependencies
= (struct partial_symtab
**)
2687 obstack_alloc (&objfile
->objfile_obstack
,
2688 sizeof (struct partial_symtab
*));
2689 subpst
->dependencies
[0] = pst
;
2690 subpst
->number_of_dependencies
= 1;
2692 subpst
->globals_offset
= 0;
2693 subpst
->n_global_syms
= 0;
2694 subpst
->statics_offset
= 0;
2695 subpst
->n_static_syms
= 0;
2696 subpst
->symtab
= NULL
;
2697 subpst
->read_symtab
= pst
->read_symtab
;
2700 /* No private part is necessary for include psymtabs. This property
2701 can be used to differentiate between such include psymtabs and
2702 the regular ones. */
2703 subpst
->read_symtab_private
= NULL
;
2706 /* Read the Line Number Program data and extract the list of files
2707 included by the source file represented by PST. Build an include
2708 partial symtab for each of these included files. */
2711 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2712 struct die_info
*die
,
2713 struct partial_symtab
*pst
)
2715 struct objfile
*objfile
= cu
->objfile
;
2716 bfd
*abfd
= objfile
->obfd
;
2717 struct line_header
*lh
= NULL
;
2718 struct attribute
*attr
;
2720 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2723 unsigned int line_offset
= DW_UNSND (attr
);
2725 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2728 return; /* No linetable, so no includes. */
2730 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
2732 free_line_header (lh
);
2736 hash_type_signature (const void *item
)
2738 const struct signatured_type
*type_sig
= item
;
2740 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2741 return type_sig
->signature
;
2745 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2747 const struct signatured_type
*lhs
= item_lhs
;
2748 const struct signatured_type
*rhs
= item_rhs
;
2750 return lhs
->signature
== rhs
->signature
;
2753 /* Allocate a hash table for signatured types. */
2756 allocate_signatured_type_hash_table (struct objfile
*objfile
)
2758 return htab_create_alloc_ex (41,
2759 hash_type_signature
,
2762 &objfile
->objfile_obstack
,
2763 hashtab_obstack_allocate
,
2764 dummy_obstack_deallocate
);
2767 /* A helper function to add a signatured type CU to a list. */
2770 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2772 struct signatured_type
*sigt
= *slot
;
2773 struct dwarf2_per_cu_data
***datap
= datum
;
2775 **datap
= &sigt
->per_cu
;
2781 /* Create the hash table of all entries in the .debug_types section.
2782 The result is zero if there is an error (e.g. missing .debug_types section),
2783 otherwise non-zero. */
2786 create_debug_types_hash_table (struct objfile
*objfile
)
2790 struct dwarf2_per_cu_data
**iter
;
2792 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2793 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2795 if (info_ptr
== NULL
)
2797 dwarf2_per_objfile
->signatured_types
= NULL
;
2801 types_htab
= allocate_signatured_type_hash_table (objfile
);
2803 if (dwarf2_die_debug
)
2804 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2806 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2808 unsigned int offset
;
2809 unsigned int offset_size
;
2810 unsigned int type_offset
;
2811 unsigned int length
, initial_length_size
;
2812 unsigned short version
;
2814 struct signatured_type
*type_sig
;
2816 gdb_byte
*ptr
= info_ptr
;
2818 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2820 /* We need to read the type's signature in order to build the hash
2821 table, but we don't need to read anything else just yet. */
2823 /* Sanity check to ensure entire cu is present. */
2824 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2825 if (ptr
+ length
+ initial_length_size
2826 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2828 complaint (&symfile_complaints
,
2829 _("debug type entry runs off end of `.debug_types' section, ignored"));
2833 offset_size
= initial_length_size
== 4 ? 4 : 8;
2834 ptr
+= initial_length_size
;
2835 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2837 ptr
+= offset_size
; /* abbrev offset */
2838 ptr
+= 1; /* address size */
2839 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2841 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2843 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2844 memset (type_sig
, 0, sizeof (*type_sig
));
2845 type_sig
->signature
= signature
;
2846 type_sig
->offset
= offset
;
2847 type_sig
->type_offset
= type_offset
;
2848 type_sig
->per_cu
.objfile
= objfile
;
2849 type_sig
->per_cu
.from_debug_types
= 1;
2851 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2852 gdb_assert (slot
!= NULL
);
2855 if (dwarf2_die_debug
)
2856 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2857 offset
, phex (signature
, sizeof (signature
)));
2859 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2862 dwarf2_per_objfile
->signatured_types
= types_htab
;
2864 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2865 dwarf2_per_objfile
->type_comp_units
2866 = obstack_alloc (&objfile
->objfile_obstack
,
2867 dwarf2_per_objfile
->n_type_comp_units
2868 * sizeof (struct dwarf2_per_cu_data
*));
2869 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2870 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2871 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2872 == dwarf2_per_objfile
->n_type_comp_units
);
2877 /* Lookup a signature based type.
2878 Returns NULL if SIG is not present in the table. */
2880 static struct signatured_type
*
2881 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2883 struct signatured_type find_entry
, *entry
;
2885 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2887 complaint (&symfile_complaints
,
2888 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2892 find_entry
.signature
= sig
;
2893 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2897 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2900 init_cu_die_reader (struct die_reader_specs
*reader
,
2901 struct dwarf2_cu
*cu
)
2903 reader
->abfd
= cu
->objfile
->obfd
;
2905 if (cu
->per_cu
->from_debug_types
)
2907 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2908 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2912 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2913 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2917 /* Find the base address of the compilation unit for range lists and
2918 location lists. It will normally be specified by DW_AT_low_pc.
2919 In DWARF-3 draft 4, the base address could be overridden by
2920 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2921 compilation units with discontinuous ranges. */
2924 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2926 struct attribute
*attr
;
2929 cu
->base_address
= 0;
2931 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2934 cu
->base_address
= DW_ADDR (attr
);
2939 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2942 cu
->base_address
= DW_ADDR (attr
);
2948 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2949 to combine the common parts.
2950 Process a compilation unit for a psymtab.
2951 BUFFER is a pointer to the beginning of the dwarf section buffer,
2952 either .debug_info or debug_types.
2953 INFO_PTR is a pointer to the start of the CU.
2954 Returns a pointer to the next CU. */
2957 process_psymtab_comp_unit (struct objfile
*objfile
,
2958 struct dwarf2_per_cu_data
*this_cu
,
2959 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2960 unsigned int buffer_size
)
2962 bfd
*abfd
= objfile
->obfd
;
2963 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2964 struct die_info
*comp_unit_die
;
2965 struct partial_symtab
*pst
;
2967 struct cleanup
*back_to_inner
;
2968 struct dwarf2_cu cu
;
2969 int has_children
, has_pc_info
;
2970 struct attribute
*attr
;
2971 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
2972 struct die_reader_specs reader_specs
;
2974 memset (&cu
, 0, sizeof (cu
));
2975 cu
.objfile
= objfile
;
2976 obstack_init (&cu
.comp_unit_obstack
);
2978 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
2980 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2981 buffer
, buffer_size
,
2984 /* Complete the cu_header. */
2985 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2986 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2988 cu
.list_in_scope
= &file_symbols
;
2990 /* If this compilation unit was already read in, free the
2991 cached copy in order to read it in again. This is
2992 necessary because we skipped some symbols when we first
2993 read in the compilation unit (see load_partial_dies).
2994 This problem could be avoided, but the benefit is
2996 if (this_cu
->cu
!= NULL
)
2997 free_one_cached_comp_unit (this_cu
->cu
);
2999 /* Note that this is a pointer to our stack frame, being
3000 added to a global data structure. It will be cleaned up
3001 in free_stack_comp_unit when we finish with this
3002 compilation unit. */
3004 cu
.per_cu
= this_cu
;
3006 /* Read the abbrevs for this compilation unit into a table. */
3007 dwarf2_read_abbrevs (abfd
, &cu
);
3008 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3010 /* Read the compilation unit die. */
3011 if (this_cu
->from_debug_types
)
3012 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3013 init_cu_die_reader (&reader_specs
, &cu
);
3014 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3017 if (this_cu
->from_debug_types
)
3019 /* offset,length haven't been set yet for type units. */
3020 this_cu
->offset
= cu
.header
.offset
;
3021 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3023 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3025 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3026 + cu
.header
.initial_length_size
);
3027 do_cleanups (back_to_inner
);
3031 /* Set the language we're debugging. */
3032 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
3034 set_cu_language (DW_UNSND (attr
), &cu
);
3036 set_cu_language (language_minimal
, &cu
);
3038 /* Allocate a new partial symbol table structure. */
3039 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3040 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3041 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3042 /* TEXTLOW and TEXTHIGH are set below. */
3044 objfile
->global_psymbols
.next
,
3045 objfile
->static_psymbols
.next
);
3047 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3049 pst
->dirname
= DW_STRING (attr
);
3051 pst
->read_symtab_private
= this_cu
;
3053 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3055 /* Store the function that reads in the rest of the symbol table */
3056 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3058 this_cu
->v
.psymtab
= pst
;
3060 dwarf2_find_base_address (comp_unit_die
, &cu
);
3062 /* Possibly set the default values of LOWPC and HIGHPC from
3064 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3065 &best_highpc
, &cu
, pst
);
3066 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3067 /* Store the contiguous range if it is not empty; it can be empty for
3068 CUs with no code. */
3069 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3070 best_lowpc
+ baseaddr
,
3071 best_highpc
+ baseaddr
- 1, pst
);
3073 /* Check if comp unit has_children.
3074 If so, read the rest of the partial symbols from this comp unit.
3075 If not, there's no more debug_info for this comp unit. */
3078 struct partial_die_info
*first_die
;
3079 CORE_ADDR lowpc
, highpc
;
3081 lowpc
= ((CORE_ADDR
) -1);
3082 highpc
= ((CORE_ADDR
) 0);
3084 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3086 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3087 ! has_pc_info
, &cu
);
3089 /* If we didn't find a lowpc, set it to highpc to avoid
3090 complaints from `maint check'. */
3091 if (lowpc
== ((CORE_ADDR
) -1))
3094 /* If the compilation unit didn't have an explicit address range,
3095 then use the information extracted from its child dies. */
3099 best_highpc
= highpc
;
3102 pst
->textlow
= best_lowpc
+ baseaddr
;
3103 pst
->texthigh
= best_highpc
+ baseaddr
;
3105 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3106 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3107 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3108 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3109 sort_pst_symbols (pst
);
3111 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3112 + cu
.header
.initial_length_size
);
3114 if (this_cu
->from_debug_types
)
3116 /* It's not clear we want to do anything with stmt lists here.
3117 Waiting to see what gcc ultimately does. */
3121 /* Get the list of files included in the current compilation unit,
3122 and build a psymtab for each of them. */
3123 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3126 do_cleanups (back_to_inner
);
3131 /* Traversal function for htab_traverse_noresize.
3132 Process one .debug_types comp-unit. */
3135 process_type_comp_unit (void **slot
, void *info
)
3137 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3138 struct objfile
*objfile
= (struct objfile
*) info
;
3139 struct dwarf2_per_cu_data
*this_cu
;
3141 this_cu
= &entry
->per_cu
;
3143 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3144 process_psymtab_comp_unit (objfile
, this_cu
,
3145 dwarf2_per_objfile
->types
.buffer
,
3146 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3147 dwarf2_per_objfile
->types
.size
);
3152 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3153 Build partial symbol tables for the .debug_types comp-units. */
3156 build_type_psymtabs (struct objfile
*objfile
)
3158 if (! create_debug_types_hash_table (objfile
))
3161 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3162 process_type_comp_unit
, objfile
);
3165 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3168 psymtabs_addrmap_cleanup (void *o
)
3170 struct objfile
*objfile
= o
;
3172 objfile
->psymtabs_addrmap
= NULL
;
3175 /* Build the partial symbol table by doing a quick pass through the
3176 .debug_info and .debug_abbrev sections. */
3179 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3182 struct cleanup
*back_to
, *addrmap_cleanup
;
3183 struct obstack temp_obstack
;
3185 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3187 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3188 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3190 /* Any cached compilation units will be linked by the per-objfile
3191 read_in_chain. Make sure to free them when we're done. */
3192 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3194 build_type_psymtabs (objfile
);
3196 create_all_comp_units (objfile
);
3198 /* Create a temporary address map on a temporary obstack. We later
3199 copy this to the final obstack. */
3200 obstack_init (&temp_obstack
);
3201 make_cleanup_obstack_free (&temp_obstack
);
3202 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3203 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3205 /* Since the objects we're extracting from .debug_info vary in
3206 length, only the individual functions to extract them (like
3207 read_comp_unit_head and load_partial_die) can really know whether
3208 the buffer is large enough to hold another complete object.
3210 At the moment, they don't actually check that. If .debug_info
3211 holds just one extra byte after the last compilation unit's dies,
3212 then read_comp_unit_head will happily read off the end of the
3213 buffer. read_partial_die is similarly casual. Those functions
3216 For this loop condition, simply checking whether there's any data
3217 left at all should be sufficient. */
3219 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3220 + dwarf2_per_objfile
->info
.size
))
3222 struct dwarf2_per_cu_data
*this_cu
;
3224 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3227 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3228 dwarf2_per_objfile
->info
.buffer
,
3230 dwarf2_per_objfile
->info
.size
);
3233 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3234 &objfile
->objfile_obstack
);
3235 discard_cleanups (addrmap_cleanup
);
3237 do_cleanups (back_to
);
3240 /* Load the partial DIEs for a secondary CU into memory. */
3243 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3244 struct objfile
*objfile
)
3246 bfd
*abfd
= objfile
->obfd
;
3247 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3248 struct die_info
*comp_unit_die
;
3249 struct dwarf2_cu
*cu
;
3250 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3251 struct attribute
*attr
;
3253 struct die_reader_specs reader_specs
;
3256 gdb_assert (! this_cu
->from_debug_types
);
3258 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3259 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3260 beg_of_comp_unit
= info_ptr
;
3262 if (this_cu
->cu
== NULL
)
3264 cu
= alloc_one_comp_unit (objfile
);
3268 /* If an error occurs while loading, release our storage. */
3269 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3271 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3272 dwarf2_per_objfile
->info
.buffer
,
3273 dwarf2_per_objfile
->info
.size
,
3276 /* Complete the cu_header. */
3277 cu
->header
.offset
= this_cu
->offset
;
3278 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3280 /* Link this compilation unit into the compilation unit tree. */
3282 cu
->per_cu
= this_cu
;
3283 cu
->type_hash
= this_cu
->type_hash
;
3285 /* Link this CU into read_in_chain. */
3286 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3287 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3292 info_ptr
+= cu
->header
.first_die_offset
;
3295 /* Read the abbrevs for this compilation unit into a table. */
3296 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3297 dwarf2_read_abbrevs (abfd
, cu
);
3298 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3300 /* Read the compilation unit die. */
3301 init_cu_die_reader (&reader_specs
, cu
);
3302 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3305 /* Set the language we're debugging. */
3306 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3308 set_cu_language (DW_UNSND (attr
), cu
);
3310 set_cu_language (language_minimal
, cu
);
3312 /* Check if comp unit has_children.
3313 If so, read the rest of the partial symbols from this comp unit.
3314 If not, there's no more debug_info for this comp unit. */
3316 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3318 do_cleanups (free_abbrevs_cleanup
);
3322 /* We've successfully allocated this compilation unit. Let our
3323 caller clean it up when finished with it. */
3324 discard_cleanups (free_cu_cleanup
);
3328 /* Create a list of all compilation units in OBJFILE. We do this only
3329 if an inter-comp-unit reference is found; presumably if there is one,
3330 there will be many, and one will occur early in the .debug_info section.
3331 So there's no point in building this list incrementally. */
3334 create_all_comp_units (struct objfile
*objfile
)
3338 struct dwarf2_per_cu_data
**all_comp_units
;
3341 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3342 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3346 all_comp_units
= xmalloc (n_allocated
3347 * sizeof (struct dwarf2_per_cu_data
*));
3349 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3351 unsigned int length
, initial_length_size
;
3352 struct dwarf2_per_cu_data
*this_cu
;
3353 unsigned int offset
;
3355 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3357 /* Read just enough information to find out where the next
3358 compilation unit is. */
3359 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3360 &initial_length_size
);
3362 /* Save the compilation unit for later lookup. */
3363 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3364 sizeof (struct dwarf2_per_cu_data
));
3365 memset (this_cu
, 0, sizeof (*this_cu
));
3366 this_cu
->offset
= offset
;
3367 this_cu
->length
= length
+ initial_length_size
;
3368 this_cu
->objfile
= objfile
;
3370 if (n_comp_units
== n_allocated
)
3373 all_comp_units
= xrealloc (all_comp_units
,
3375 * sizeof (struct dwarf2_per_cu_data
*));
3377 all_comp_units
[n_comp_units
++] = this_cu
;
3379 info_ptr
= info_ptr
+ this_cu
->length
;
3382 dwarf2_per_objfile
->all_comp_units
3383 = obstack_alloc (&objfile
->objfile_obstack
,
3384 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3385 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3386 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3387 xfree (all_comp_units
);
3388 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3391 /* Process all loaded DIEs for compilation unit CU, starting at
3392 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3393 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3394 DW_AT_ranges). If NEED_PC is set, then this function will set
3395 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3396 and record the covered ranges in the addrmap. */
3399 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3400 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3402 struct partial_die_info
*pdi
;
3404 /* Now, march along the PDI's, descending into ones which have
3405 interesting children but skipping the children of the other ones,
3406 until we reach the end of the compilation unit. */
3412 fixup_partial_die (pdi
, cu
);
3414 /* Anonymous namespaces or modules have no name but have interesting
3415 children, so we need to look at them. Ditto for anonymous
3418 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3419 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3423 case DW_TAG_subprogram
:
3424 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3426 case DW_TAG_variable
:
3427 case DW_TAG_typedef
:
3428 case DW_TAG_union_type
:
3429 if (!pdi
->is_declaration
)
3431 add_partial_symbol (pdi
, cu
);
3434 case DW_TAG_class_type
:
3435 case DW_TAG_interface_type
:
3436 case DW_TAG_structure_type
:
3437 if (!pdi
->is_declaration
)
3439 add_partial_symbol (pdi
, cu
);
3442 case DW_TAG_enumeration_type
:
3443 if (!pdi
->is_declaration
)
3444 add_partial_enumeration (pdi
, cu
);
3446 case DW_TAG_base_type
:
3447 case DW_TAG_subrange_type
:
3448 /* File scope base type definitions are added to the partial
3450 add_partial_symbol (pdi
, cu
);
3452 case DW_TAG_namespace
:
3453 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3456 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3463 /* If the die has a sibling, skip to the sibling. */
3465 pdi
= pdi
->die_sibling
;
3469 /* Functions used to compute the fully scoped name of a partial DIE.
3471 Normally, this is simple. For C++, the parent DIE's fully scoped
3472 name is concatenated with "::" and the partial DIE's name. For
3473 Java, the same thing occurs except that "." is used instead of "::".
3474 Enumerators are an exception; they use the scope of their parent
3475 enumeration type, i.e. the name of the enumeration type is not
3476 prepended to the enumerator.
3478 There are two complexities. One is DW_AT_specification; in this
3479 case "parent" means the parent of the target of the specification,
3480 instead of the direct parent of the DIE. The other is compilers
3481 which do not emit DW_TAG_namespace; in this case we try to guess
3482 the fully qualified name of structure types from their members'
3483 linkage names. This must be done using the DIE's children rather
3484 than the children of any DW_AT_specification target. We only need
3485 to do this for structures at the top level, i.e. if the target of
3486 any DW_AT_specification (if any; otherwise the DIE itself) does not
3489 /* Compute the scope prefix associated with PDI's parent, in
3490 compilation unit CU. The result will be allocated on CU's
3491 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3492 field. NULL is returned if no prefix is necessary. */
3494 partial_die_parent_scope (struct partial_die_info
*pdi
,
3495 struct dwarf2_cu
*cu
)
3497 char *grandparent_scope
;
3498 struct partial_die_info
*parent
, *real_pdi
;
3500 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3501 then this means the parent of the specification DIE. */
3504 while (real_pdi
->has_specification
)
3505 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3507 parent
= real_pdi
->die_parent
;
3511 if (parent
->scope_set
)
3512 return parent
->scope
;
3514 fixup_partial_die (parent
, cu
);
3516 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3518 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3519 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3520 Work around this problem here. */
3521 if (cu
->language
== language_cplus
3522 && parent
->tag
== DW_TAG_namespace
3523 && strcmp (parent
->name
, "::") == 0
3524 && grandparent_scope
== NULL
)
3526 parent
->scope
= NULL
;
3527 parent
->scope_set
= 1;
3531 if (parent
->tag
== DW_TAG_namespace
3532 || parent
->tag
== DW_TAG_module
3533 || parent
->tag
== DW_TAG_structure_type
3534 || parent
->tag
== DW_TAG_class_type
3535 || parent
->tag
== DW_TAG_interface_type
3536 || parent
->tag
== DW_TAG_union_type
3537 || parent
->tag
== DW_TAG_enumeration_type
)
3539 if (grandparent_scope
== NULL
)
3540 parent
->scope
= parent
->name
;
3542 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3543 parent
->name
, 0, cu
);
3545 else if (parent
->tag
== DW_TAG_enumerator
)
3546 /* Enumerators should not get the name of the enumeration as a prefix. */
3547 parent
->scope
= grandparent_scope
;
3550 /* FIXME drow/2004-04-01: What should we be doing with
3551 function-local names? For partial symbols, we should probably be
3553 complaint (&symfile_complaints
,
3554 _("unhandled containing DIE tag %d for DIE at %d"),
3555 parent
->tag
, pdi
->offset
);
3556 parent
->scope
= grandparent_scope
;
3559 parent
->scope_set
= 1;
3560 return parent
->scope
;
3563 /* Return the fully scoped name associated with PDI, from compilation unit
3564 CU. The result will be allocated with malloc. */
3566 partial_die_full_name (struct partial_die_info
*pdi
,
3567 struct dwarf2_cu
*cu
)
3571 /* If this is a template instantiation, we can not work out the
3572 template arguments from partial DIEs. So, unfortunately, we have
3573 to go through the full DIEs. At least any work we do building
3574 types here will be reused if full symbols are loaded later. */
3575 if (pdi
->has_template_arguments
)
3577 fixup_partial_die (pdi
, cu
);
3579 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3581 struct die_info
*die
;
3582 struct attribute attr
;
3583 struct dwarf2_cu
*ref_cu
= cu
;
3586 attr
.form
= DW_FORM_ref_addr
;
3587 attr
.u
.addr
= pdi
->offset
;
3588 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3590 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3594 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3595 if (parent_scope
== NULL
)
3598 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3602 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3604 struct objfile
*objfile
= cu
->objfile
;
3606 char *actual_name
= NULL
;
3607 const struct partial_symbol
*psym
= NULL
;
3609 int built_actual_name
= 0;
3611 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3613 actual_name
= partial_die_full_name (pdi
, cu
);
3615 built_actual_name
= 1;
3617 if (actual_name
== NULL
)
3618 actual_name
= pdi
->name
;
3622 case DW_TAG_subprogram
:
3623 if (pdi
->is_external
|| cu
->language
== language_ada
)
3625 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3626 of the global scope. But in Ada, we want to be able to access
3627 nested procedures globally. So all Ada subprograms are stored
3628 in the global scope. */
3629 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3630 mst_text, objfile); */
3631 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3633 VAR_DOMAIN
, LOC_BLOCK
,
3634 &objfile
->global_psymbols
,
3635 0, pdi
->lowpc
+ baseaddr
,
3636 cu
->language
, objfile
);
3640 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3641 mst_file_text, objfile); */
3642 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3644 VAR_DOMAIN
, LOC_BLOCK
,
3645 &objfile
->static_psymbols
,
3646 0, pdi
->lowpc
+ baseaddr
,
3647 cu
->language
, objfile
);
3650 case DW_TAG_variable
:
3652 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3656 && !dwarf2_per_objfile
->has_section_at_zero
)
3658 /* A global or static variable may also have been stripped
3659 out by the linker if unused, in which case its address
3660 will be nullified; do not add such variables into partial
3661 symbol table then. */
3663 else if (pdi
->is_external
)
3666 Don't enter into the minimal symbol tables as there is
3667 a minimal symbol table entry from the ELF symbols already.
3668 Enter into partial symbol table if it has a location
3669 descriptor or a type.
3670 If the location descriptor is missing, new_symbol will create
3671 a LOC_UNRESOLVED symbol, the address of the variable will then
3672 be determined from the minimal symbol table whenever the variable
3674 The address for the partial symbol table entry is not
3675 used by GDB, but it comes in handy for debugging partial symbol
3678 if (pdi
->locdesc
|| pdi
->has_type
)
3679 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3681 VAR_DOMAIN
, LOC_STATIC
,
3682 &objfile
->global_psymbols
,
3684 cu
->language
, objfile
);
3688 /* Static Variable. Skip symbols without location descriptors. */
3689 if (pdi
->locdesc
== NULL
)
3691 if (built_actual_name
)
3692 xfree (actual_name
);
3695 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3696 mst_file_data, objfile); */
3697 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3699 VAR_DOMAIN
, LOC_STATIC
,
3700 &objfile
->static_psymbols
,
3702 cu
->language
, objfile
);
3705 case DW_TAG_typedef
:
3706 case DW_TAG_base_type
:
3707 case DW_TAG_subrange_type
:
3708 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3710 VAR_DOMAIN
, LOC_TYPEDEF
,
3711 &objfile
->static_psymbols
,
3712 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3714 case DW_TAG_namespace
:
3715 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3717 VAR_DOMAIN
, LOC_TYPEDEF
,
3718 &objfile
->global_psymbols
,
3719 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3721 case DW_TAG_class_type
:
3722 case DW_TAG_interface_type
:
3723 case DW_TAG_structure_type
:
3724 case DW_TAG_union_type
:
3725 case DW_TAG_enumeration_type
:
3726 /* Skip external references. The DWARF standard says in the section
3727 about "Structure, Union, and Class Type Entries": "An incomplete
3728 structure, union or class type is represented by a structure,
3729 union or class entry that does not have a byte size attribute
3730 and that has a DW_AT_declaration attribute." */
3731 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3733 if (built_actual_name
)
3734 xfree (actual_name
);
3738 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3739 static vs. global. */
3740 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3742 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3743 (cu
->language
== language_cplus
3744 || cu
->language
== language_java
)
3745 ? &objfile
->global_psymbols
3746 : &objfile
->static_psymbols
,
3747 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3750 case DW_TAG_enumerator
:
3751 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3753 VAR_DOMAIN
, LOC_CONST
,
3754 (cu
->language
== language_cplus
3755 || cu
->language
== language_java
)
3756 ? &objfile
->global_psymbols
3757 : &objfile
->static_psymbols
,
3758 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3764 if (built_actual_name
)
3765 xfree (actual_name
);
3768 /* Read a partial die corresponding to a namespace; also, add a symbol
3769 corresponding to that namespace to the symbol table. NAMESPACE is
3770 the name of the enclosing namespace. */
3773 add_partial_namespace (struct partial_die_info
*pdi
,
3774 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3775 int need_pc
, struct dwarf2_cu
*cu
)
3777 /* Add a symbol for the namespace. */
3779 add_partial_symbol (pdi
, cu
);
3781 /* Now scan partial symbols in that namespace. */
3783 if (pdi
->has_children
)
3784 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3787 /* Read a partial die corresponding to a Fortran module. */
3790 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3791 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3793 /* Now scan partial symbols in that module. */
3795 if (pdi
->has_children
)
3796 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3799 /* Read a partial die corresponding to a subprogram and create a partial
3800 symbol for that subprogram. When the CU language allows it, this
3801 routine also defines a partial symbol for each nested subprogram
3802 that this subprogram contains.
3804 DIE my also be a lexical block, in which case we simply search
3805 recursively for suprograms defined inside that lexical block.
3806 Again, this is only performed when the CU language allows this
3807 type of definitions. */
3810 add_partial_subprogram (struct partial_die_info
*pdi
,
3811 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3812 int need_pc
, struct dwarf2_cu
*cu
)
3814 if (pdi
->tag
== DW_TAG_subprogram
)
3816 if (pdi
->has_pc_info
)
3818 if (pdi
->lowpc
< *lowpc
)
3819 *lowpc
= pdi
->lowpc
;
3820 if (pdi
->highpc
> *highpc
)
3821 *highpc
= pdi
->highpc
;
3825 struct objfile
*objfile
= cu
->objfile
;
3827 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3828 SECT_OFF_TEXT (objfile
));
3829 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3830 pdi
->lowpc
+ baseaddr
,
3831 pdi
->highpc
- 1 + baseaddr
,
3832 cu
->per_cu
->v
.psymtab
);
3834 if (!pdi
->is_declaration
)
3835 /* Ignore subprogram DIEs that do not have a name, they are
3836 illegal. Do not emit a complaint at this point, we will
3837 do so when we convert this psymtab into a symtab. */
3839 add_partial_symbol (pdi
, cu
);
3843 if (! pdi
->has_children
)
3846 if (cu
->language
== language_ada
)
3848 pdi
= pdi
->die_child
;
3851 fixup_partial_die (pdi
, cu
);
3852 if (pdi
->tag
== DW_TAG_subprogram
3853 || pdi
->tag
== DW_TAG_lexical_block
)
3854 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3855 pdi
= pdi
->die_sibling
;
3860 /* See if we can figure out if the class lives in a namespace. We do
3861 this by looking for a member function; its demangled name will
3862 contain namespace info, if there is any. */
3865 guess_structure_name (struct partial_die_info
*struct_pdi
,
3866 struct dwarf2_cu
*cu
)
3868 if ((cu
->language
== language_cplus
3869 || cu
->language
== language_java
)
3870 && cu
->has_namespace_info
== 0
3871 && struct_pdi
->has_children
)
3873 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3874 what template types look like, because the demangler
3875 frequently doesn't give the same name as the debug info. We
3876 could fix this by only using the demangled name to get the
3877 prefix (but see comment in read_structure_type). */
3879 struct partial_die_info
*real_pdi
;
3881 /* If this DIE (this DIE's specification, if any) has a parent, then
3882 we should not do this. We'll prepend the parent's fully qualified
3883 name when we create the partial symbol. */
3885 real_pdi
= struct_pdi
;
3886 while (real_pdi
->has_specification
)
3887 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3889 if (real_pdi
->die_parent
!= NULL
)
3894 /* Read a partial die corresponding to an enumeration type. */
3897 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3898 struct dwarf2_cu
*cu
)
3900 struct partial_die_info
*pdi
;
3902 if (enum_pdi
->name
!= NULL
)
3903 add_partial_symbol (enum_pdi
, cu
);
3905 pdi
= enum_pdi
->die_child
;
3908 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3909 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3911 add_partial_symbol (pdi
, cu
);
3912 pdi
= pdi
->die_sibling
;
3916 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3917 Return the corresponding abbrev, or NULL if the number is zero (indicating
3918 an empty DIE). In either case *BYTES_READ will be set to the length of
3919 the initial number. */
3921 static struct abbrev_info
*
3922 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3923 struct dwarf2_cu
*cu
)
3925 bfd
*abfd
= cu
->objfile
->obfd
;
3926 unsigned int abbrev_number
;
3927 struct abbrev_info
*abbrev
;
3929 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3931 if (abbrev_number
== 0)
3934 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3937 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3938 bfd_get_filename (abfd
));
3944 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3945 Returns a pointer to the end of a series of DIEs, terminated by an empty
3946 DIE. Any children of the skipped DIEs will also be skipped. */
3949 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3951 struct abbrev_info
*abbrev
;
3952 unsigned int bytes_read
;
3956 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3958 return info_ptr
+ bytes_read
;
3960 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3964 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3965 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3966 abbrev corresponding to that skipped uleb128 should be passed in
3967 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3971 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3972 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
3974 unsigned int bytes_read
;
3975 struct attribute attr
;
3976 bfd
*abfd
= cu
->objfile
->obfd
;
3977 unsigned int form
, i
;
3979 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
3981 /* The only abbrev we care about is DW_AT_sibling. */
3982 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
3984 read_attribute (&attr
, &abbrev
->attrs
[i
],
3985 abfd
, info_ptr
, cu
);
3986 if (attr
.form
== DW_FORM_ref_addr
)
3987 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
3989 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
3992 /* If it isn't DW_AT_sibling, skip this attribute. */
3993 form
= abbrev
->attrs
[i
].form
;
3997 case DW_FORM_ref_addr
:
3998 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
3999 and later it is offset sized. */
4000 if (cu
->header
.version
== 2)
4001 info_ptr
+= cu
->header
.addr_size
;
4003 info_ptr
+= cu
->header
.offset_size
;
4006 info_ptr
+= cu
->header
.addr_size
;
4013 case DW_FORM_flag_present
:
4028 case DW_FORM_string
:
4029 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4030 info_ptr
+= bytes_read
;
4032 case DW_FORM_sec_offset
:
4034 info_ptr
+= cu
->header
.offset_size
;
4036 case DW_FORM_exprloc
:
4038 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4039 info_ptr
+= bytes_read
;
4041 case DW_FORM_block1
:
4042 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4044 case DW_FORM_block2
:
4045 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4047 case DW_FORM_block4
:
4048 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4052 case DW_FORM_ref_udata
:
4053 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4055 case DW_FORM_indirect
:
4056 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4057 info_ptr
+= bytes_read
;
4058 /* We need to continue parsing from here, so just go back to
4060 goto skip_attribute
;
4063 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4064 dwarf_form_name (form
),
4065 bfd_get_filename (abfd
));
4069 if (abbrev
->has_children
)
4070 return skip_children (buffer
, info_ptr
, cu
);
4075 /* Locate ORIG_PDI's sibling.
4076 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4080 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4081 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4082 bfd
*abfd
, struct dwarf2_cu
*cu
)
4084 /* Do we know the sibling already? */
4086 if (orig_pdi
->sibling
)
4087 return orig_pdi
->sibling
;
4089 /* Are there any children to deal with? */
4091 if (!orig_pdi
->has_children
)
4094 /* Skip the children the long way. */
4096 return skip_children (buffer
, info_ptr
, cu
);
4099 /* Expand this partial symbol table into a full symbol table. */
4102 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4108 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4114 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4115 gdb_flush (gdb_stdout
);
4118 /* Restore our global data. */
4119 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4120 dwarf2_objfile_data_key
);
4122 /* If this psymtab is constructed from a debug-only objfile, the
4123 has_section_at_zero flag will not necessarily be correct. We
4124 can get the correct value for this flag by looking at the data
4125 associated with the (presumably stripped) associated objfile. */
4126 if (pst
->objfile
->separate_debug_objfile_backlink
)
4128 struct dwarf2_per_objfile
*dpo_backlink
4129 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4130 dwarf2_objfile_data_key
);
4132 dwarf2_per_objfile
->has_section_at_zero
4133 = dpo_backlink
->has_section_at_zero
;
4136 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4138 psymtab_to_symtab_1 (pst
);
4140 /* Finish up the debug error message. */
4142 printf_filtered (_("done.\n"));
4147 /* Add PER_CU to the queue. */
4150 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4152 struct dwarf2_queue_item
*item
;
4155 item
= xmalloc (sizeof (*item
));
4156 item
->per_cu
= per_cu
;
4159 if (dwarf2_queue
== NULL
)
4160 dwarf2_queue
= item
;
4162 dwarf2_queue_tail
->next
= item
;
4164 dwarf2_queue_tail
= item
;
4167 /* Process the queue. */
4170 process_queue (struct objfile
*objfile
)
4172 struct dwarf2_queue_item
*item
, *next_item
;
4174 /* The queue starts out with one item, but following a DIE reference
4175 may load a new CU, adding it to the end of the queue. */
4176 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4178 if (dwarf2_per_objfile
->using_index
4179 ? !item
->per_cu
->v
.quick
->symtab
4180 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4181 process_full_comp_unit (item
->per_cu
);
4183 item
->per_cu
->queued
= 0;
4184 next_item
= item
->next
;
4188 dwarf2_queue_tail
= NULL
;
4191 /* Free all allocated queue entries. This function only releases anything if
4192 an error was thrown; if the queue was processed then it would have been
4193 freed as we went along. */
4196 dwarf2_release_queue (void *dummy
)
4198 struct dwarf2_queue_item
*item
, *last
;
4200 item
= dwarf2_queue
;
4203 /* Anything still marked queued is likely to be in an
4204 inconsistent state, so discard it. */
4205 if (item
->per_cu
->queued
)
4207 if (item
->per_cu
->cu
!= NULL
)
4208 free_one_cached_comp_unit (item
->per_cu
->cu
);
4209 item
->per_cu
->queued
= 0;
4217 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4220 /* Read in full symbols for PST, and anything it depends on. */
4223 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4225 struct dwarf2_per_cu_data
*per_cu
;
4226 struct cleanup
*back_to
;
4229 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4230 if (!pst
->dependencies
[i
]->readin
)
4232 /* Inform about additional files that need to be read in. */
4235 /* FIXME: i18n: Need to make this a single string. */
4236 fputs_filtered (" ", gdb_stdout
);
4238 fputs_filtered ("and ", gdb_stdout
);
4240 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4241 wrap_here (""); /* Flush output */
4242 gdb_flush (gdb_stdout
);
4244 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4247 per_cu
= pst
->read_symtab_private
;
4251 /* It's an include file, no symbols to read for it.
4252 Everything is in the parent symtab. */
4257 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4260 /* Load the DIEs associated with PER_CU into memory. */
4263 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4265 bfd
*abfd
= objfile
->obfd
;
4266 struct dwarf2_cu
*cu
;
4267 unsigned int offset
;
4268 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4269 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4270 struct attribute
*attr
;
4273 gdb_assert (! per_cu
->from_debug_types
);
4275 /* Set local variables from the partial symbol table info. */
4276 offset
= per_cu
->offset
;
4278 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4279 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4280 beg_of_comp_unit
= info_ptr
;
4282 if (per_cu
->cu
== NULL
)
4284 cu
= alloc_one_comp_unit (objfile
);
4288 /* If an error occurs while loading, release our storage. */
4289 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4291 /* Read in the comp_unit header. */
4292 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4294 /* Complete the cu_header. */
4295 cu
->header
.offset
= offset
;
4296 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4298 /* Read the abbrevs for this compilation unit. */
4299 dwarf2_read_abbrevs (abfd
, cu
);
4300 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4302 /* Link this compilation unit into the compilation unit tree. */
4304 cu
->per_cu
= per_cu
;
4305 cu
->type_hash
= per_cu
->type_hash
;
4307 /* Link this CU into read_in_chain. */
4308 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4309 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4314 info_ptr
+= cu
->header
.first_die_offset
;
4317 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4319 /* We try not to read any attributes in this function, because not
4320 all objfiles needed for references have been loaded yet, and symbol
4321 table processing isn't initialized. But we have to set the CU language,
4322 or we won't be able to build types correctly. */
4323 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4325 set_cu_language (DW_UNSND (attr
), cu
);
4327 set_cu_language (language_minimal
, cu
);
4329 /* Similarly, if we do not read the producer, we can not apply
4330 producer-specific interpretation. */
4331 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4333 cu
->producer
= DW_STRING (attr
);
4337 do_cleanups (free_abbrevs_cleanup
);
4339 /* We've successfully allocated this compilation unit. Let our
4340 caller clean it up when finished with it. */
4341 discard_cleanups (free_cu_cleanup
);
4345 /* Generate full symbol information for PST and CU, whose DIEs have
4346 already been loaded into memory. */
4349 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4351 struct dwarf2_cu
*cu
= per_cu
->cu
;
4352 struct objfile
*objfile
= per_cu
->objfile
;
4353 CORE_ADDR lowpc
, highpc
;
4354 struct symtab
*symtab
;
4355 struct cleanup
*back_to
;
4358 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4361 back_to
= make_cleanup (really_free_pendings
, NULL
);
4363 cu
->list_in_scope
= &file_symbols
;
4365 dwarf2_find_base_address (cu
->dies
, cu
);
4367 /* Do line number decoding in read_file_scope () */
4368 process_die (cu
->dies
, cu
);
4370 /* Some compilers don't define a DW_AT_high_pc attribute for the
4371 compilation unit. If the DW_AT_high_pc is missing, synthesize
4372 it, by scanning the DIE's below the compilation unit. */
4373 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4375 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4377 /* Set symtab language to language from DW_AT_language.
4378 If the compilation is from a C file generated by language preprocessors,
4379 do not set the language if it was already deduced by start_subfile. */
4381 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4383 symtab
->language
= cu
->language
;
4386 if (dwarf2_per_objfile
->using_index
)
4387 per_cu
->v
.quick
->symtab
= symtab
;
4390 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4391 pst
->symtab
= symtab
;
4395 do_cleanups (back_to
);
4398 /* Process a die and its children. */
4401 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4405 case DW_TAG_padding
:
4407 case DW_TAG_compile_unit
:
4408 read_file_scope (die
, cu
);
4410 case DW_TAG_type_unit
:
4411 read_type_unit_scope (die
, cu
);
4413 case DW_TAG_subprogram
:
4414 case DW_TAG_inlined_subroutine
:
4415 read_func_scope (die
, cu
);
4417 case DW_TAG_lexical_block
:
4418 case DW_TAG_try_block
:
4419 case DW_TAG_catch_block
:
4420 read_lexical_block_scope (die
, cu
);
4422 case DW_TAG_class_type
:
4423 case DW_TAG_interface_type
:
4424 case DW_TAG_structure_type
:
4425 case DW_TAG_union_type
:
4426 process_structure_scope (die
, cu
);
4428 case DW_TAG_enumeration_type
:
4429 process_enumeration_scope (die
, cu
);
4432 /* These dies have a type, but processing them does not create
4433 a symbol or recurse to process the children. Therefore we can
4434 read them on-demand through read_type_die. */
4435 case DW_TAG_subroutine_type
:
4436 case DW_TAG_set_type
:
4437 case DW_TAG_array_type
:
4438 case DW_TAG_pointer_type
:
4439 case DW_TAG_ptr_to_member_type
:
4440 case DW_TAG_reference_type
:
4441 case DW_TAG_string_type
:
4444 case DW_TAG_base_type
:
4445 case DW_TAG_subrange_type
:
4446 case DW_TAG_typedef
:
4447 /* Add a typedef symbol for the type definition, if it has a
4449 new_symbol (die
, read_type_die (die
, cu
), cu
);
4451 case DW_TAG_common_block
:
4452 read_common_block (die
, cu
);
4454 case DW_TAG_common_inclusion
:
4456 case DW_TAG_namespace
:
4457 processing_has_namespace_info
= 1;
4458 read_namespace (die
, cu
);
4461 processing_has_namespace_info
= 1;
4462 read_module (die
, cu
);
4464 case DW_TAG_imported_declaration
:
4465 case DW_TAG_imported_module
:
4466 processing_has_namespace_info
= 1;
4467 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4468 || cu
->language
!= language_fortran
))
4469 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4470 dwarf_tag_name (die
->tag
));
4471 read_import_statement (die
, cu
);
4474 new_symbol (die
, NULL
, cu
);
4479 /* A helper function for dwarf2_compute_name which determines whether DIE
4480 needs to have the name of the scope prepended to the name listed in the
4484 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4486 struct attribute
*attr
;
4490 case DW_TAG_namespace
:
4491 case DW_TAG_typedef
:
4492 case DW_TAG_class_type
:
4493 case DW_TAG_interface_type
:
4494 case DW_TAG_structure_type
:
4495 case DW_TAG_union_type
:
4496 case DW_TAG_enumeration_type
:
4497 case DW_TAG_enumerator
:
4498 case DW_TAG_subprogram
:
4502 case DW_TAG_variable
:
4503 /* We only need to prefix "globally" visible variables. These include
4504 any variable marked with DW_AT_external or any variable that
4505 lives in a namespace. [Variables in anonymous namespaces
4506 require prefixing, but they are not DW_AT_external.] */
4508 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4510 struct dwarf2_cu
*spec_cu
= cu
;
4512 return die_needs_namespace (die_specification (die
, &spec_cu
),
4516 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4517 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4518 && die
->parent
->tag
!= DW_TAG_module
)
4520 /* A variable in a lexical block of some kind does not need a
4521 namespace, even though in C++ such variables may be external
4522 and have a mangled name. */
4523 if (die
->parent
->tag
== DW_TAG_lexical_block
4524 || die
->parent
->tag
== DW_TAG_try_block
4525 || die
->parent
->tag
== DW_TAG_catch_block
4526 || die
->parent
->tag
== DW_TAG_subprogram
)
4535 /* Retrieve the last character from a mem_file. */
4538 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4540 char *last_char_p
= (char *) object
;
4543 *last_char_p
= buffer
[length
- 1];
4546 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4547 compute the physname for the object, which include a method's
4548 formal parameters (C++/Java) and return type (Java).
4550 For Ada, return the DIE's linkage name rather than the fully qualified
4551 name. PHYSNAME is ignored..
4553 The result is allocated on the objfile_obstack and canonicalized. */
4556 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4560 name
= dwarf2_name (die
, cu
);
4562 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4563 compute it by typename_concat inside GDB. */
4564 if (cu
->language
== language_ada
4565 || (cu
->language
== language_fortran
&& physname
))
4567 /* For Ada unit, we prefer the linkage name over the name, as
4568 the former contains the exported name, which the user expects
4569 to be able to reference. Ideally, we want the user to be able
4570 to reference this entity using either natural or linkage name,
4571 but we haven't started looking at this enhancement yet. */
4572 struct attribute
*attr
;
4574 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4576 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4577 if (attr
&& DW_STRING (attr
))
4578 return DW_STRING (attr
);
4581 /* These are the only languages we know how to qualify names in. */
4583 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4584 || cu
->language
== language_fortran
))
4586 if (die_needs_namespace (die
, cu
))
4590 struct ui_file
*buf
;
4592 prefix
= determine_prefix (die
, cu
);
4593 buf
= mem_fileopen ();
4594 if (*prefix
!= '\0')
4596 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4599 fputs_unfiltered (prefixed_name
, buf
);
4600 xfree (prefixed_name
);
4603 fputs_unfiltered (name
? name
: "", buf
);
4605 /* Template parameters may be specified in the DIE's DW_AT_name, or
4606 as children with DW_TAG_template_type_param or
4607 DW_TAG_value_type_param. If the latter, add them to the name
4608 here. If the name already has template parameters, then
4609 skip this step; some versions of GCC emit both, and
4610 it is more efficient to use the pre-computed name.
4612 Something to keep in mind about this process: it is very
4613 unlikely, or in some cases downright impossible, to produce
4614 something that will match the mangled name of a function.
4615 If the definition of the function has the same debug info,
4616 we should be able to match up with it anyway. But fallbacks
4617 using the minimal symbol, for instance to find a method
4618 implemented in a stripped copy of libstdc++, will not work.
4619 If we do not have debug info for the definition, we will have to
4620 match them up some other way.
4622 When we do name matching there is a related problem with function
4623 templates; two instantiated function templates are allowed to
4624 differ only by their return types, which we do not add here. */
4626 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4628 struct attribute
*attr
;
4629 struct die_info
*child
;
4632 die
->building_fullname
= 1;
4634 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4639 struct dwarf2_locexpr_baton
*baton
;
4642 if (child
->tag
!= DW_TAG_template_type_param
4643 && child
->tag
!= DW_TAG_template_value_param
)
4648 fputs_unfiltered ("<", buf
);
4652 fputs_unfiltered (", ", buf
);
4654 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4657 complaint (&symfile_complaints
,
4658 _("template parameter missing DW_AT_type"));
4659 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4662 type
= die_type (child
, cu
);
4664 if (child
->tag
== DW_TAG_template_type_param
)
4666 c_print_type (type
, "", buf
, -1, 0);
4670 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4673 complaint (&symfile_complaints
,
4674 _("template parameter missing DW_AT_const_value"));
4675 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4679 dwarf2_const_value_attr (attr
, type
, name
,
4680 &cu
->comp_unit_obstack
, cu
,
4681 &value
, &bytes
, &baton
);
4683 if (TYPE_NOSIGN (type
))
4684 /* GDB prints characters as NUMBER 'CHAR'. If that's
4685 changed, this can use value_print instead. */
4686 c_printchar (value
, type
, buf
);
4689 struct value_print_options opts
;
4692 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4696 else if (bytes
!= NULL
)
4698 v
= allocate_value (type
);
4699 memcpy (value_contents_writeable (v
), bytes
,
4700 TYPE_LENGTH (type
));
4703 v
= value_from_longest (type
, value
);
4705 /* Specify decimal so that we do not depend on the radix. */
4706 get_formatted_print_options (&opts
, 'd');
4708 value_print (v
, buf
, &opts
);
4714 die
->building_fullname
= 0;
4718 /* Close the argument list, with a space if necessary
4719 (nested templates). */
4720 char last_char
= '\0';
4721 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4722 if (last_char
== '>')
4723 fputs_unfiltered (" >", buf
);
4725 fputs_unfiltered (">", buf
);
4729 /* For Java and C++ methods, append formal parameter type
4730 information, if PHYSNAME. */
4732 if (physname
&& die
->tag
== DW_TAG_subprogram
4733 && (cu
->language
== language_cplus
4734 || cu
->language
== language_java
))
4736 struct type
*type
= read_type_die (die
, cu
);
4738 c_type_print_args (type
, buf
, 0, cu
->language
);
4740 if (cu
->language
== language_java
)
4742 /* For java, we must append the return type to method
4744 if (die
->tag
== DW_TAG_subprogram
)
4745 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4748 else if (cu
->language
== language_cplus
)
4750 if (TYPE_NFIELDS (type
) > 0
4751 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4752 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4753 fputs_unfiltered (" const", buf
);
4757 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4759 ui_file_delete (buf
);
4761 if (cu
->language
== language_cplus
)
4764 = dwarf2_canonicalize_name (name
, cu
,
4765 &cu
->objfile
->objfile_obstack
);
4776 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4777 If scope qualifiers are appropriate they will be added. The result
4778 will be allocated on the objfile_obstack, or NULL if the DIE does
4779 not have a name. NAME may either be from a previous call to
4780 dwarf2_name or NULL.
4782 The output string will be canonicalized (if C++/Java). */
4785 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4787 return dwarf2_compute_name (name
, die
, cu
, 0);
4790 /* Construct a physname for the given DIE in CU. NAME may either be
4791 from a previous call to dwarf2_name or NULL. The result will be
4792 allocated on the objfile_objstack or NULL if the DIE does not have a
4795 The output string will be canonicalized (if C++/Java). */
4798 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4800 return dwarf2_compute_name (name
, die
, cu
, 1);
4803 /* Read the import statement specified by the given die and record it. */
4806 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4808 struct attribute
*import_attr
;
4809 struct die_info
*imported_die
;
4810 struct dwarf2_cu
*imported_cu
;
4811 const char *imported_name
;
4812 const char *imported_name_prefix
;
4813 const char *canonical_name
;
4814 const char *import_alias
;
4815 const char *imported_declaration
= NULL
;
4816 const char *import_prefix
;
4820 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4821 if (import_attr
== NULL
)
4823 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4824 dwarf_tag_name (die
->tag
));
4829 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4830 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4831 if (imported_name
== NULL
)
4833 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4835 The import in the following code:
4849 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4850 <52> DW_AT_decl_file : 1
4851 <53> DW_AT_decl_line : 6
4852 <54> DW_AT_import : <0x75>
4853 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4855 <5b> DW_AT_decl_file : 1
4856 <5c> DW_AT_decl_line : 2
4857 <5d> DW_AT_type : <0x6e>
4859 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4860 <76> DW_AT_byte_size : 4
4861 <77> DW_AT_encoding : 5 (signed)
4863 imports the wrong die ( 0x75 instead of 0x58 ).
4864 This case will be ignored until the gcc bug is fixed. */
4868 /* Figure out the local name after import. */
4869 import_alias
= dwarf2_name (die
, cu
);
4871 /* Figure out where the statement is being imported to. */
4872 import_prefix
= determine_prefix (die
, cu
);
4874 /* Figure out what the scope of the imported die is and prepend it
4875 to the name of the imported die. */
4876 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4878 if (imported_die
->tag
!= DW_TAG_namespace
4879 && imported_die
->tag
!= DW_TAG_module
)
4881 imported_declaration
= imported_name
;
4882 canonical_name
= imported_name_prefix
;
4884 else if (strlen (imported_name_prefix
) > 0)
4886 temp
= alloca (strlen (imported_name_prefix
)
4887 + 2 + strlen (imported_name
) + 1);
4888 strcpy (temp
, imported_name_prefix
);
4889 strcat (temp
, "::");
4890 strcat (temp
, imported_name
);
4891 canonical_name
= temp
;
4894 canonical_name
= imported_name
;
4896 cp_add_using_directive (import_prefix
,
4899 imported_declaration
,
4900 &cu
->objfile
->objfile_obstack
);
4904 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4906 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4910 free_cu_line_header (void *arg
)
4912 struct dwarf2_cu
*cu
= arg
;
4914 free_line_header (cu
->line_header
);
4915 cu
->line_header
= NULL
;
4919 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
4920 char **name
, char **comp_dir
)
4922 struct attribute
*attr
;
4927 /* Find the filename. Do not use dwarf2_name here, since the filename
4928 is not a source language identifier. */
4929 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4932 *name
= DW_STRING (attr
);
4935 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4937 *comp_dir
= DW_STRING (attr
);
4938 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
4940 *comp_dir
= ldirname (*name
);
4941 if (*comp_dir
!= NULL
)
4942 make_cleanup (xfree
, *comp_dir
);
4944 if (*comp_dir
!= NULL
)
4946 /* Irix 6.2 native cc prepends <machine>.: to the compilation
4947 directory, get rid of it. */
4948 char *cp
= strchr (*comp_dir
, ':');
4950 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
4955 *name
= "<unknown>";
4959 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4961 struct objfile
*objfile
= cu
->objfile
;
4962 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4963 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
4964 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
4965 struct attribute
*attr
;
4967 char *comp_dir
= NULL
;
4968 struct die_info
*child_die
;
4969 bfd
*abfd
= objfile
->obfd
;
4970 struct line_header
*line_header
= 0;
4973 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4975 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
4977 /* If we didn't find a lowpc, set it to highpc to avoid complaints
4978 from finish_block. */
4979 if (lowpc
== ((CORE_ADDR
) -1))
4984 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
4986 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4989 set_cu_language (DW_UNSND (attr
), cu
);
4992 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4994 cu
->producer
= DW_STRING (attr
);
4996 /* We assume that we're processing GCC output. */
4997 processing_gcc_compilation
= 2;
4999 processing_has_namespace_info
= 0;
5001 start_symtab (name
, comp_dir
, lowpc
);
5002 record_debugformat ("DWARF 2");
5003 record_producer (cu
->producer
);
5005 initialize_cu_func_list (cu
);
5007 /* Decode line number information if present. We do this before
5008 processing child DIEs, so that the line header table is available
5009 for DW_AT_decl_file. */
5010 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5013 unsigned int line_offset
= DW_UNSND (attr
);
5014 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5017 cu
->line_header
= line_header
;
5018 make_cleanup (free_cu_line_header
, cu
);
5019 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5023 /* Process all dies in compilation unit. */
5024 if (die
->child
!= NULL
)
5026 child_die
= die
->child
;
5027 while (child_die
&& child_die
->tag
)
5029 process_die (child_die
, cu
);
5030 child_die
= sibling_die (child_die
);
5034 /* Decode macro information, if present. Dwarf 2 macro information
5035 refers to information in the line number info statement program
5036 header, so we can only read it if we've read the header
5038 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5039 if (attr
&& line_header
)
5041 unsigned int macro_offset
= DW_UNSND (attr
);
5043 dwarf_decode_macros (line_header
, macro_offset
,
5044 comp_dir
, abfd
, cu
);
5046 do_cleanups (back_to
);
5049 /* For TUs we want to skip the first top level sibling if it's not the
5050 actual type being defined by this TU. In this case the first top
5051 level sibling is there to provide context only. */
5054 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5056 struct objfile
*objfile
= cu
->objfile
;
5057 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5059 struct attribute
*attr
;
5061 char *comp_dir
= NULL
;
5062 struct die_info
*child_die
;
5063 bfd
*abfd
= objfile
->obfd
;
5065 /* start_symtab needs a low pc, but we don't really have one.
5066 Do what read_file_scope would do in the absence of such info. */
5067 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5069 /* Find the filename. Do not use dwarf2_name here, since the filename
5070 is not a source language identifier. */
5071 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5073 name
= DW_STRING (attr
);
5075 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5077 comp_dir
= DW_STRING (attr
);
5078 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5080 comp_dir
= ldirname (name
);
5081 if (comp_dir
!= NULL
)
5082 make_cleanup (xfree
, comp_dir
);
5088 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5090 set_cu_language (DW_UNSND (attr
), cu
);
5092 /* This isn't technically needed today. It is done for symmetry
5093 with read_file_scope. */
5094 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5096 cu
->producer
= DW_STRING (attr
);
5098 /* We assume that we're processing GCC output. */
5099 processing_gcc_compilation
= 2;
5101 processing_has_namespace_info
= 0;
5103 start_symtab (name
, comp_dir
, lowpc
);
5104 record_debugformat ("DWARF 2");
5105 record_producer (cu
->producer
);
5107 /* Process the dies in the type unit. */
5108 if (die
->child
== NULL
)
5110 dump_die_for_error (die
);
5111 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5112 bfd_get_filename (abfd
));
5115 child_die
= die
->child
;
5117 while (child_die
&& child_die
->tag
)
5119 process_die (child_die
, cu
);
5121 child_die
= sibling_die (child_die
);
5124 do_cleanups (back_to
);
5128 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5129 struct dwarf2_cu
*cu
)
5131 struct function_range
*thisfn
;
5133 thisfn
= (struct function_range
*)
5134 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5135 thisfn
->name
= name
;
5136 thisfn
->lowpc
= lowpc
;
5137 thisfn
->highpc
= highpc
;
5138 thisfn
->seen_line
= 0;
5139 thisfn
->next
= NULL
;
5141 if (cu
->last_fn
== NULL
)
5142 cu
->first_fn
= thisfn
;
5144 cu
->last_fn
->next
= thisfn
;
5146 cu
->last_fn
= thisfn
;
5149 /* qsort helper for inherit_abstract_dies. */
5152 unsigned_int_compar (const void *ap
, const void *bp
)
5154 unsigned int a
= *(unsigned int *) ap
;
5155 unsigned int b
= *(unsigned int *) bp
;
5157 return (a
> b
) - (b
> a
);
5160 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5161 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5162 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5165 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5167 struct die_info
*child_die
;
5168 unsigned die_children_count
;
5169 /* CU offsets which were referenced by children of the current DIE. */
5171 unsigned *offsets_end
, *offsetp
;
5172 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5173 struct die_info
*origin_die
;
5174 /* Iterator of the ORIGIN_DIE children. */
5175 struct die_info
*origin_child_die
;
5176 struct cleanup
*cleanups
;
5177 struct attribute
*attr
;
5179 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5183 origin_die
= follow_die_ref (die
, attr
, &cu
);
5184 if (die
->tag
!= origin_die
->tag
5185 && !(die
->tag
== DW_TAG_inlined_subroutine
5186 && origin_die
->tag
== DW_TAG_subprogram
))
5187 complaint (&symfile_complaints
,
5188 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5189 die
->offset
, origin_die
->offset
);
5191 child_die
= die
->child
;
5192 die_children_count
= 0;
5193 while (child_die
&& child_die
->tag
)
5195 child_die
= sibling_die (child_die
);
5196 die_children_count
++;
5198 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5199 cleanups
= make_cleanup (xfree
, offsets
);
5201 offsets_end
= offsets
;
5202 child_die
= die
->child
;
5203 while (child_die
&& child_die
->tag
)
5205 /* For each CHILD_DIE, find the corresponding child of
5206 ORIGIN_DIE. If there is more than one layer of
5207 DW_AT_abstract_origin, follow them all; there shouldn't be,
5208 but GCC versions at least through 4.4 generate this (GCC PR
5210 struct die_info
*child_origin_die
= child_die
;
5214 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
5217 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
5220 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5221 counterpart may exist. */
5222 if (child_origin_die
!= child_die
)
5224 if (child_die
->tag
!= child_origin_die
->tag
5225 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5226 && child_origin_die
->tag
== DW_TAG_subprogram
))
5227 complaint (&symfile_complaints
,
5228 _("Child DIE 0x%x and its abstract origin 0x%x have "
5229 "different tags"), child_die
->offset
,
5230 child_origin_die
->offset
);
5231 if (child_origin_die
->parent
!= origin_die
)
5232 complaint (&symfile_complaints
,
5233 _("Child DIE 0x%x and its abstract origin 0x%x have "
5234 "different parents"), child_die
->offset
,
5235 child_origin_die
->offset
);
5237 *offsets_end
++ = child_origin_die
->offset
;
5239 child_die
= sibling_die (child_die
);
5241 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5242 unsigned_int_compar
);
5243 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5244 if (offsetp
[-1] == *offsetp
)
5245 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5246 "to DIE 0x%x as their abstract origin"),
5247 die
->offset
, *offsetp
);
5250 origin_child_die
= origin_die
->child
;
5251 while (origin_child_die
&& origin_child_die
->tag
)
5253 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5254 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5256 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5258 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5259 process_die (origin_child_die
, cu
);
5261 origin_child_die
= sibling_die (origin_child_die
);
5264 do_cleanups (cleanups
);
5268 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5270 struct objfile
*objfile
= cu
->objfile
;
5271 struct context_stack
*new;
5274 struct die_info
*child_die
;
5275 struct attribute
*attr
, *call_line
, *call_file
;
5278 struct block
*block
;
5279 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5280 VEC (symbolp
) *template_args
= NULL
;
5281 struct template_symbol
*templ_func
= NULL
;
5285 /* If we do not have call site information, we can't show the
5286 caller of this inlined function. That's too confusing, so
5287 only use the scope for local variables. */
5288 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5289 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5290 if (call_line
== NULL
|| call_file
== NULL
)
5292 read_lexical_block_scope (die
, cu
);
5297 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5299 name
= dwarf2_name (die
, cu
);
5301 /* Ignore functions with missing or empty names. These are actually
5302 illegal according to the DWARF standard. */
5305 complaint (&symfile_complaints
,
5306 _("missing name for subprogram DIE at %d"), die
->offset
);
5310 /* Ignore functions with missing or invalid low and high pc attributes. */
5311 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5313 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5314 if (!attr
|| !DW_UNSND (attr
))
5315 complaint (&symfile_complaints
,
5316 _("cannot get low and high bounds for subprogram DIE at %d"),
5324 /* Record the function range for dwarf_decode_lines. */
5325 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5327 /* If we have any template arguments, then we must allocate a
5328 different sort of symbol. */
5329 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5331 if (child_die
->tag
== DW_TAG_template_type_param
5332 || child_die
->tag
== DW_TAG_template_value_param
)
5334 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5335 struct template_symbol
);
5336 templ_func
->base
.is_cplus_template_function
= 1;
5341 new = push_context (0, lowpc
);
5342 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5343 (struct symbol
*) templ_func
);
5345 /* If there is a location expression for DW_AT_frame_base, record
5347 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5349 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5350 expression is being recorded directly in the function's symbol
5351 and not in a separate frame-base object. I guess this hack is
5352 to avoid adding some sort of frame-base adjunct/annex to the
5353 function's symbol :-(. The problem with doing this is that it
5354 results in a function symbol with a location expression that
5355 has nothing to do with the location of the function, ouch! The
5356 relationship should be: a function's symbol has-a frame base; a
5357 frame-base has-a location expression. */
5358 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5360 cu
->list_in_scope
= &local_symbols
;
5362 if (die
->child
!= NULL
)
5364 child_die
= die
->child
;
5365 while (child_die
&& child_die
->tag
)
5367 if (child_die
->tag
== DW_TAG_template_type_param
5368 || child_die
->tag
== DW_TAG_template_value_param
)
5370 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5372 VEC_safe_push (symbolp
, template_args
, arg
);
5375 process_die (child_die
, cu
);
5376 child_die
= sibling_die (child_die
);
5380 inherit_abstract_dies (die
, cu
);
5382 /* If we have a DW_AT_specification, we might need to import using
5383 directives from the context of the specification DIE. See the
5384 comment in determine_prefix. */
5385 if (cu
->language
== language_cplus
5386 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5388 struct dwarf2_cu
*spec_cu
= cu
;
5389 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5393 child_die
= spec_die
->child
;
5394 while (child_die
&& child_die
->tag
)
5396 if (child_die
->tag
== DW_TAG_imported_module
)
5397 process_die (child_die
, spec_cu
);
5398 child_die
= sibling_die (child_die
);
5401 /* In some cases, GCC generates specification DIEs that
5402 themselves contain DW_AT_specification attributes. */
5403 spec_die
= die_specification (spec_die
, &spec_cu
);
5407 new = pop_context ();
5408 /* Make a block for the local symbols within. */
5409 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5410 lowpc
, highpc
, objfile
);
5412 /* For C++, set the block's scope. */
5413 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5414 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5415 determine_prefix (die
, cu
),
5416 processing_has_namespace_info
);
5418 /* If we have address ranges, record them. */
5419 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5421 /* Attach template arguments to function. */
5422 if (! VEC_empty (symbolp
, template_args
))
5424 gdb_assert (templ_func
!= NULL
);
5426 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5427 templ_func
->template_arguments
5428 = obstack_alloc (&objfile
->objfile_obstack
,
5429 (templ_func
->n_template_arguments
5430 * sizeof (struct symbol
*)));
5431 memcpy (templ_func
->template_arguments
,
5432 VEC_address (symbolp
, template_args
),
5433 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5434 VEC_free (symbolp
, template_args
);
5437 /* In C++, we can have functions nested inside functions (e.g., when
5438 a function declares a class that has methods). This means that
5439 when we finish processing a function scope, we may need to go
5440 back to building a containing block's symbol lists. */
5441 local_symbols
= new->locals
;
5442 param_symbols
= new->params
;
5443 using_directives
= new->using_directives
;
5445 /* If we've finished processing a top-level function, subsequent
5446 symbols go in the file symbol list. */
5447 if (outermost_context_p ())
5448 cu
->list_in_scope
= &file_symbols
;
5451 /* Process all the DIES contained within a lexical block scope. Start
5452 a new scope, process the dies, and then close the scope. */
5455 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5457 struct objfile
*objfile
= cu
->objfile
;
5458 struct context_stack
*new;
5459 CORE_ADDR lowpc
, highpc
;
5460 struct die_info
*child_die
;
5463 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5465 /* Ignore blocks with missing or invalid low and high pc attributes. */
5466 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5467 as multiple lexical blocks? Handling children in a sane way would
5468 be nasty. Might be easier to properly extend generic blocks to
5470 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5475 push_context (0, lowpc
);
5476 if (die
->child
!= NULL
)
5478 child_die
= die
->child
;
5479 while (child_die
&& child_die
->tag
)
5481 process_die (child_die
, cu
);
5482 child_die
= sibling_die (child_die
);
5485 new = pop_context ();
5487 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5490 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5493 /* Note that recording ranges after traversing children, as we
5494 do here, means that recording a parent's ranges entails
5495 walking across all its children's ranges as they appear in
5496 the address map, which is quadratic behavior.
5498 It would be nicer to record the parent's ranges before
5499 traversing its children, simply overriding whatever you find
5500 there. But since we don't even decide whether to create a
5501 block until after we've traversed its children, that's hard
5503 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5505 local_symbols
= new->locals
;
5506 using_directives
= new->using_directives
;
5509 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5510 Return 1 if the attributes are present and valid, otherwise, return 0.
5511 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5514 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5515 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5516 struct partial_symtab
*ranges_pst
)
5518 struct objfile
*objfile
= cu
->objfile
;
5519 struct comp_unit_head
*cu_header
= &cu
->header
;
5520 bfd
*obfd
= objfile
->obfd
;
5521 unsigned int addr_size
= cu_header
->addr_size
;
5522 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5523 /* Base address selection entry. */
5534 found_base
= cu
->base_known
;
5535 base
= cu
->base_address
;
5537 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5538 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5540 complaint (&symfile_complaints
,
5541 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5545 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5547 /* Read in the largest possible address. */
5548 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5549 if ((marker
& mask
) == mask
)
5551 /* If we found the largest possible address, then
5552 read the base address. */
5553 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5554 buffer
+= 2 * addr_size
;
5555 offset
+= 2 * addr_size
;
5561 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5565 CORE_ADDR range_beginning
, range_end
;
5567 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5568 buffer
+= addr_size
;
5569 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5570 buffer
+= addr_size
;
5571 offset
+= 2 * addr_size
;
5573 /* An end of list marker is a pair of zero addresses. */
5574 if (range_beginning
== 0 && range_end
== 0)
5575 /* Found the end of list entry. */
5578 /* Each base address selection entry is a pair of 2 values.
5579 The first is the largest possible address, the second is
5580 the base address. Check for a base address here. */
5581 if ((range_beginning
& mask
) == mask
)
5583 /* If we found the largest possible address, then
5584 read the base address. */
5585 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5592 /* We have no valid base address for the ranges
5594 complaint (&symfile_complaints
,
5595 _("Invalid .debug_ranges data (no base address)"));
5599 range_beginning
+= base
;
5602 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5603 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5604 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5607 /* FIXME: This is recording everything as a low-high
5608 segment of consecutive addresses. We should have a
5609 data structure for discontiguous block ranges
5613 low
= range_beginning
;
5619 if (range_beginning
< low
)
5620 low
= range_beginning
;
5621 if (range_end
> high
)
5627 /* If the first entry is an end-of-list marker, the range
5628 describes an empty scope, i.e. no instructions. */
5634 *high_return
= high
;
5638 /* Get low and high pc attributes from a die. Return 1 if the attributes
5639 are present and valid, otherwise, return 0. Return -1 if the range is
5640 discontinuous, i.e. derived from DW_AT_ranges information. */
5642 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5643 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5644 struct partial_symtab
*pst
)
5646 struct attribute
*attr
;
5651 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5654 high
= DW_ADDR (attr
);
5655 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5657 low
= DW_ADDR (attr
);
5659 /* Found high w/o low attribute. */
5662 /* Found consecutive range of addresses. */
5667 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5670 /* Value of the DW_AT_ranges attribute is the offset in the
5671 .debug_ranges section. */
5672 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5674 /* Found discontinuous range of addresses. */
5682 /* When using the GNU linker, .gnu.linkonce. sections are used to
5683 eliminate duplicate copies of functions and vtables and such.
5684 The linker will arbitrarily choose one and discard the others.
5685 The AT_*_pc values for such functions refer to local labels in
5686 these sections. If the section from that file was discarded, the
5687 labels are not in the output, so the relocs get a value of 0.
5688 If this is a discarded function, mark the pc bounds as invalid,
5689 so that GDB will ignore it. */
5690 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5698 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5699 its low and high PC addresses. Do nothing if these addresses could not
5700 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5701 and HIGHPC to the high address if greater than HIGHPC. */
5704 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5705 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5706 struct dwarf2_cu
*cu
)
5708 CORE_ADDR low
, high
;
5709 struct die_info
*child
= die
->child
;
5711 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5713 *lowpc
= min (*lowpc
, low
);
5714 *highpc
= max (*highpc
, high
);
5717 /* If the language does not allow nested subprograms (either inside
5718 subprograms or lexical blocks), we're done. */
5719 if (cu
->language
!= language_ada
)
5722 /* Check all the children of the given DIE. If it contains nested
5723 subprograms, then check their pc bounds. Likewise, we need to
5724 check lexical blocks as well, as they may also contain subprogram
5726 while (child
&& child
->tag
)
5728 if (child
->tag
== DW_TAG_subprogram
5729 || child
->tag
== DW_TAG_lexical_block
)
5730 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5731 child
= sibling_die (child
);
5735 /* Get the low and high pc's represented by the scope DIE, and store
5736 them in *LOWPC and *HIGHPC. If the correct values can't be
5737 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5740 get_scope_pc_bounds (struct die_info
*die
,
5741 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5742 struct dwarf2_cu
*cu
)
5744 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5745 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5746 CORE_ADDR current_low
, current_high
;
5748 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5750 best_low
= current_low
;
5751 best_high
= current_high
;
5755 struct die_info
*child
= die
->child
;
5757 while (child
&& child
->tag
)
5759 switch (child
->tag
) {
5760 case DW_TAG_subprogram
:
5761 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5763 case DW_TAG_namespace
:
5765 /* FIXME: carlton/2004-01-16: Should we do this for
5766 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5767 that current GCC's always emit the DIEs corresponding
5768 to definitions of methods of classes as children of a
5769 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5770 the DIEs giving the declarations, which could be
5771 anywhere). But I don't see any reason why the
5772 standards says that they have to be there. */
5773 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5775 if (current_low
!= ((CORE_ADDR
) -1))
5777 best_low
= min (best_low
, current_low
);
5778 best_high
= max (best_high
, current_high
);
5786 child
= sibling_die (child
);
5791 *highpc
= best_high
;
5794 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5797 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5798 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5800 struct attribute
*attr
;
5802 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5805 CORE_ADDR high
= DW_ADDR (attr
);
5807 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5810 CORE_ADDR low
= DW_ADDR (attr
);
5812 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5816 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5819 bfd
*obfd
= cu
->objfile
->obfd
;
5821 /* The value of the DW_AT_ranges attribute is the offset of the
5822 address range list in the .debug_ranges section. */
5823 unsigned long offset
= DW_UNSND (attr
);
5824 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5826 /* For some target architectures, but not others, the
5827 read_address function sign-extends the addresses it returns.
5828 To recognize base address selection entries, we need a
5830 unsigned int addr_size
= cu
->header
.addr_size
;
5831 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5833 /* The base address, to which the next pair is relative. Note
5834 that this 'base' is a DWARF concept: most entries in a range
5835 list are relative, to reduce the number of relocs against the
5836 debugging information. This is separate from this function's
5837 'baseaddr' argument, which GDB uses to relocate debugging
5838 information from a shared library based on the address at
5839 which the library was loaded. */
5840 CORE_ADDR base
= cu
->base_address
;
5841 int base_known
= cu
->base_known
;
5843 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5844 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5846 complaint (&symfile_complaints
,
5847 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5854 unsigned int bytes_read
;
5855 CORE_ADDR start
, end
;
5857 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5858 buffer
+= bytes_read
;
5859 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5860 buffer
+= bytes_read
;
5862 /* Did we find the end of the range list? */
5863 if (start
== 0 && end
== 0)
5866 /* Did we find a base address selection entry? */
5867 else if ((start
& base_select_mask
) == base_select_mask
)
5873 /* We found an ordinary address range. */
5878 complaint (&symfile_complaints
,
5879 _("Invalid .debug_ranges data (no base address)"));
5883 record_block_range (block
,
5884 baseaddr
+ base
+ start
,
5885 baseaddr
+ base
+ end
- 1);
5891 /* Add an aggregate field to the field list. */
5894 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
5895 struct dwarf2_cu
*cu
)
5897 struct objfile
*objfile
= cu
->objfile
;
5898 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5899 struct nextfield
*new_field
;
5900 struct attribute
*attr
;
5902 char *fieldname
= "";
5904 /* Allocate a new field list entry and link it in. */
5905 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
5906 make_cleanup (xfree
, new_field
);
5907 memset (new_field
, 0, sizeof (struct nextfield
));
5909 if (die
->tag
== DW_TAG_inheritance
)
5911 new_field
->next
= fip
->baseclasses
;
5912 fip
->baseclasses
= new_field
;
5916 new_field
->next
= fip
->fields
;
5917 fip
->fields
= new_field
;
5921 /* Handle accessibility and virtuality of field.
5922 The default accessibility for members is public, the default
5923 accessibility for inheritance is private. */
5924 if (die
->tag
!= DW_TAG_inheritance
)
5925 new_field
->accessibility
= DW_ACCESS_public
;
5927 new_field
->accessibility
= DW_ACCESS_private
;
5928 new_field
->virtuality
= DW_VIRTUALITY_none
;
5930 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5932 new_field
->accessibility
= DW_UNSND (attr
);
5933 if (new_field
->accessibility
!= DW_ACCESS_public
)
5934 fip
->non_public_fields
= 1;
5935 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5937 new_field
->virtuality
= DW_UNSND (attr
);
5939 fp
= &new_field
->field
;
5941 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
5943 /* Data member other than a C++ static data member. */
5945 /* Get type of field. */
5946 fp
->type
= die_type (die
, cu
);
5948 SET_FIELD_BITPOS (*fp
, 0);
5950 /* Get bit size of field (zero if none). */
5951 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
5954 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
5958 FIELD_BITSIZE (*fp
) = 0;
5961 /* Get bit offset of field. */
5962 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5965 int byte_offset
= 0;
5967 if (attr_form_is_section_offset (attr
))
5968 dwarf2_complex_location_expr_complaint ();
5969 else if (attr_form_is_constant (attr
))
5970 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5971 else if (attr_form_is_block (attr
))
5972 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5974 dwarf2_complex_location_expr_complaint ();
5976 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5978 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
5981 if (gdbarch_bits_big_endian (gdbarch
))
5983 /* For big endian bits, the DW_AT_bit_offset gives the
5984 additional bit offset from the MSB of the containing
5985 anonymous object to the MSB of the field. We don't
5986 have to do anything special since we don't need to
5987 know the size of the anonymous object. */
5988 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
5992 /* For little endian bits, compute the bit offset to the
5993 MSB of the anonymous object, subtract off the number of
5994 bits from the MSB of the field to the MSB of the
5995 object, and then subtract off the number of bits of
5996 the field itself. The result is the bit offset of
5997 the LSB of the field. */
5999 int bit_offset
= DW_UNSND (attr
);
6001 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6004 /* The size of the anonymous object containing
6005 the bit field is explicit, so use the
6006 indicated size (in bytes). */
6007 anonymous_size
= DW_UNSND (attr
);
6011 /* The size of the anonymous object containing
6012 the bit field must be inferred from the type
6013 attribute of the data member containing the
6015 anonymous_size
= TYPE_LENGTH (fp
->type
);
6017 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6018 - bit_offset
- FIELD_BITSIZE (*fp
);
6022 /* Get name of field. */
6023 fieldname
= dwarf2_name (die
, cu
);
6024 if (fieldname
== NULL
)
6027 /* The name is already allocated along with this objfile, so we don't
6028 need to duplicate it for the type. */
6029 fp
->name
= fieldname
;
6031 /* Change accessibility for artificial fields (e.g. virtual table
6032 pointer or virtual base class pointer) to private. */
6033 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6035 FIELD_ARTIFICIAL (*fp
) = 1;
6036 new_field
->accessibility
= DW_ACCESS_private
;
6037 fip
->non_public_fields
= 1;
6040 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6042 /* C++ static member. */
6044 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6045 is a declaration, but all versions of G++ as of this writing
6046 (so through at least 3.2.1) incorrectly generate
6047 DW_TAG_variable tags. */
6051 /* Get name of field. */
6052 fieldname
= dwarf2_name (die
, cu
);
6053 if (fieldname
== NULL
)
6056 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6058 /* Only create a symbol if this is an external value.
6059 new_symbol checks this and puts the value in the global symbol
6060 table, which we want. If it is not external, new_symbol
6061 will try to put the value in cu->list_in_scope which is wrong. */
6062 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6064 /* A static const member, not much different than an enum as far as
6065 we're concerned, except that we can support more types. */
6066 new_symbol (die
, NULL
, cu
);
6069 /* Get physical name. */
6070 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6072 /* The name is already allocated along with this objfile, so we don't
6073 need to duplicate it for the type. */
6074 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6075 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6076 FIELD_NAME (*fp
) = fieldname
;
6078 else if (die
->tag
== DW_TAG_inheritance
)
6080 /* C++ base class field. */
6081 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6084 int byte_offset
= 0;
6086 if (attr_form_is_section_offset (attr
))
6087 dwarf2_complex_location_expr_complaint ();
6088 else if (attr_form_is_constant (attr
))
6089 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6090 else if (attr_form_is_block (attr
))
6091 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6093 dwarf2_complex_location_expr_complaint ();
6095 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6097 FIELD_BITSIZE (*fp
) = 0;
6098 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6099 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6100 fip
->nbaseclasses
++;
6104 /* Add a typedef defined in the scope of the FIP's class. */
6107 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6108 struct dwarf2_cu
*cu
)
6110 struct objfile
*objfile
= cu
->objfile
;
6111 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6112 struct typedef_field_list
*new_field
;
6113 struct attribute
*attr
;
6114 struct typedef_field
*fp
;
6115 char *fieldname
= "";
6117 /* Allocate a new field list entry and link it in. */
6118 new_field
= xzalloc (sizeof (*new_field
));
6119 make_cleanup (xfree
, new_field
);
6121 gdb_assert (die
->tag
== DW_TAG_typedef
);
6123 fp
= &new_field
->field
;
6125 /* Get name of field. */
6126 fp
->name
= dwarf2_name (die
, cu
);
6127 if (fp
->name
== NULL
)
6130 fp
->type
= read_type_die (die
, cu
);
6132 new_field
->next
= fip
->typedef_field_list
;
6133 fip
->typedef_field_list
= new_field
;
6134 fip
->typedef_field_list_count
++;
6137 /* Create the vector of fields, and attach it to the type. */
6140 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6141 struct dwarf2_cu
*cu
)
6143 int nfields
= fip
->nfields
;
6145 /* Record the field count, allocate space for the array of fields,
6146 and create blank accessibility bitfields if necessary. */
6147 TYPE_NFIELDS (type
) = nfields
;
6148 TYPE_FIELDS (type
) = (struct field
*)
6149 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6150 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6152 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6154 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6156 TYPE_FIELD_PRIVATE_BITS (type
) =
6157 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6158 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6160 TYPE_FIELD_PROTECTED_BITS (type
) =
6161 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6162 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6164 TYPE_FIELD_IGNORE_BITS (type
) =
6165 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6166 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6169 /* If the type has baseclasses, allocate and clear a bit vector for
6170 TYPE_FIELD_VIRTUAL_BITS. */
6171 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6173 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6174 unsigned char *pointer
;
6176 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6177 pointer
= TYPE_ALLOC (type
, num_bytes
);
6178 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6179 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6180 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6183 /* Copy the saved-up fields into the field vector. Start from the head
6184 of the list, adding to the tail of the field array, so that they end
6185 up in the same order in the array in which they were added to the list. */
6186 while (nfields
-- > 0)
6188 struct nextfield
*fieldp
;
6192 fieldp
= fip
->fields
;
6193 fip
->fields
= fieldp
->next
;
6197 fieldp
= fip
->baseclasses
;
6198 fip
->baseclasses
= fieldp
->next
;
6201 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6202 switch (fieldp
->accessibility
)
6204 case DW_ACCESS_private
:
6205 if (cu
->language
!= language_ada
)
6206 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6209 case DW_ACCESS_protected
:
6210 if (cu
->language
!= language_ada
)
6211 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6214 case DW_ACCESS_public
:
6218 /* Unknown accessibility. Complain and treat it as public. */
6220 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6221 fieldp
->accessibility
);
6225 if (nfields
< fip
->nbaseclasses
)
6227 switch (fieldp
->virtuality
)
6229 case DW_VIRTUALITY_virtual
:
6230 case DW_VIRTUALITY_pure_virtual
:
6231 if (cu
->language
== language_ada
)
6232 error ("unexpected virtuality in component of Ada type");
6233 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6240 /* Add a member function to the proper fieldlist. */
6243 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6244 struct type
*type
, struct dwarf2_cu
*cu
)
6246 struct objfile
*objfile
= cu
->objfile
;
6247 struct attribute
*attr
;
6248 struct fnfieldlist
*flp
;
6250 struct fn_field
*fnp
;
6253 struct nextfnfield
*new_fnfield
;
6254 struct type
*this_type
;
6256 if (cu
->language
== language_ada
)
6257 error ("unexpected member function in Ada type");
6259 /* Get name of member function. */
6260 fieldname
= dwarf2_name (die
, cu
);
6261 if (fieldname
== NULL
)
6264 /* Get the mangled name. */
6265 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6267 /* Look up member function name in fieldlist. */
6268 for (i
= 0; i
< fip
->nfnfields
; i
++)
6270 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6274 /* Create new list element if necessary. */
6275 if (i
< fip
->nfnfields
)
6276 flp
= &fip
->fnfieldlists
[i
];
6279 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6281 fip
->fnfieldlists
= (struct fnfieldlist
*)
6282 xrealloc (fip
->fnfieldlists
,
6283 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6284 * sizeof (struct fnfieldlist
));
6285 if (fip
->nfnfields
== 0)
6286 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6288 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6289 flp
->name
= fieldname
;
6295 /* Create a new member function field and chain it to the field list
6297 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6298 make_cleanup (xfree
, new_fnfield
);
6299 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6300 new_fnfield
->next
= flp
->head
;
6301 flp
->head
= new_fnfield
;
6304 /* Fill in the member function field info. */
6305 fnp
= &new_fnfield
->fnfield
;
6306 /* The name is already allocated along with this objfile, so we don't
6307 need to duplicate it for the type. */
6308 fnp
->physname
= physname
? physname
: "";
6309 fnp
->type
= alloc_type (objfile
);
6310 this_type
= read_type_die (die
, cu
);
6311 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6313 int nparams
= TYPE_NFIELDS (this_type
);
6315 /* TYPE is the domain of this method, and THIS_TYPE is the type
6316 of the method itself (TYPE_CODE_METHOD). */
6317 smash_to_method_type (fnp
->type
, type
,
6318 TYPE_TARGET_TYPE (this_type
),
6319 TYPE_FIELDS (this_type
),
6320 TYPE_NFIELDS (this_type
),
6321 TYPE_VARARGS (this_type
));
6323 /* Handle static member functions.
6324 Dwarf2 has no clean way to discern C++ static and non-static
6325 member functions. G++ helps GDB by marking the first
6326 parameter for non-static member functions (which is the
6327 this pointer) as artificial. We obtain this information
6328 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6329 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6330 fnp
->voffset
= VOFFSET_STATIC
;
6333 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6336 /* Get fcontext from DW_AT_containing_type if present. */
6337 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6338 fnp
->fcontext
= die_containing_type (die
, cu
);
6340 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6341 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6343 /* Get accessibility. */
6344 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6347 switch (DW_UNSND (attr
))
6349 case DW_ACCESS_private
:
6350 fnp
->is_private
= 1;
6352 case DW_ACCESS_protected
:
6353 fnp
->is_protected
= 1;
6358 /* Check for artificial methods. */
6359 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6360 if (attr
&& DW_UNSND (attr
) != 0)
6361 fnp
->is_artificial
= 1;
6363 /* Get index in virtual function table if it is a virtual member
6364 function. For older versions of GCC, this is an offset in the
6365 appropriate virtual table, as specified by DW_AT_containing_type.
6366 For everyone else, it is an expression to be evaluated relative
6367 to the object address. */
6369 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6372 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6374 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6376 /* Old-style GCC. */
6377 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6379 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6380 || (DW_BLOCK (attr
)->size
> 1
6381 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6382 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6384 struct dwarf_block blk
;
6387 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6389 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6390 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6391 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6392 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6393 dwarf2_complex_location_expr_complaint ();
6395 fnp
->voffset
/= cu
->header
.addr_size
;
6399 dwarf2_complex_location_expr_complaint ();
6402 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6404 else if (attr_form_is_section_offset (attr
))
6406 dwarf2_complex_location_expr_complaint ();
6410 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6416 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6417 if (attr
&& DW_UNSND (attr
))
6419 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6420 complaint (&symfile_complaints
,
6421 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6422 fieldname
, die
->offset
);
6423 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6424 TYPE_CPLUS_DYNAMIC (type
) = 1;
6429 /* Create the vector of member function fields, and attach it to the type. */
6432 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6433 struct dwarf2_cu
*cu
)
6435 struct fnfieldlist
*flp
;
6436 int total_length
= 0;
6439 if (cu
->language
== language_ada
)
6440 error ("unexpected member functions in Ada type");
6442 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6443 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6444 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6446 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6448 struct nextfnfield
*nfp
= flp
->head
;
6449 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6452 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6453 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6454 fn_flp
->fn_fields
= (struct fn_field
*)
6455 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6456 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6457 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6459 total_length
+= flp
->length
;
6462 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6463 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6466 /* Returns non-zero if NAME is the name of a vtable member in CU's
6467 language, zero otherwise. */
6469 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6471 static const char vptr
[] = "_vptr";
6472 static const char vtable
[] = "vtable";
6474 /* Look for the C++ and Java forms of the vtable. */
6475 if ((cu
->language
== language_java
6476 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6477 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6478 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6484 /* GCC outputs unnamed structures that are really pointers to member
6485 functions, with the ABI-specified layout. If TYPE describes
6486 such a structure, smash it into a member function type.
6488 GCC shouldn't do this; it should just output pointer to member DIEs.
6489 This is GCC PR debug/28767. */
6492 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6494 struct type
*pfn_type
, *domain_type
, *new_type
;
6496 /* Check for a structure with no name and two children. */
6497 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6500 /* Check for __pfn and __delta members. */
6501 if (TYPE_FIELD_NAME (type
, 0) == NULL
6502 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6503 || TYPE_FIELD_NAME (type
, 1) == NULL
6504 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6507 /* Find the type of the method. */
6508 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6509 if (pfn_type
== NULL
6510 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6511 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6514 /* Look for the "this" argument. */
6515 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6516 if (TYPE_NFIELDS (pfn_type
) == 0
6517 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6518 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6521 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6522 new_type
= alloc_type (objfile
);
6523 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6524 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6525 TYPE_VARARGS (pfn_type
));
6526 smash_to_methodptr_type (type
, new_type
);
6529 /* Called when we find the DIE that starts a structure or union scope
6530 (definition) to process all dies that define the members of the
6533 NOTE: we need to call struct_type regardless of whether or not the
6534 DIE has an at_name attribute, since it might be an anonymous
6535 structure or union. This gets the type entered into our set of
6538 However, if the structure is incomplete (an opaque struct/union)
6539 then suppress creating a symbol table entry for it since gdb only
6540 wants to find the one with the complete definition. Note that if
6541 it is complete, we just call new_symbol, which does it's own
6542 checking about whether the struct/union is anonymous or not (and
6543 suppresses creating a symbol table entry itself). */
6545 static struct type
*
6546 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6548 struct objfile
*objfile
= cu
->objfile
;
6550 struct attribute
*attr
;
6552 struct cleanup
*back_to
;
6554 /* If the definition of this type lives in .debug_types, read that type.
6555 Don't follow DW_AT_specification though, that will take us back up
6556 the chain and we want to go down. */
6557 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6560 struct dwarf2_cu
*type_cu
= cu
;
6561 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6563 /* We could just recurse on read_structure_type, but we need to call
6564 get_die_type to ensure only one type for this DIE is created.
6565 This is important, for example, because for c++ classes we need
6566 TYPE_NAME set which is only done by new_symbol. Blech. */
6567 type
= read_type_die (type_die
, type_cu
);
6568 return set_die_type (die
, type
, cu
);
6571 back_to
= make_cleanup (null_cleanup
, 0);
6573 type
= alloc_type (objfile
);
6574 INIT_CPLUS_SPECIFIC (type
);
6576 name
= dwarf2_name (die
, cu
);
6579 if (cu
->language
== language_cplus
6580 || cu
->language
== language_java
)
6582 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
6583 if (die
->tag
== DW_TAG_structure_type
6584 || die
->tag
== DW_TAG_class_type
)
6585 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6589 /* The name is already allocated along with this objfile, so
6590 we don't need to duplicate it for the type. */
6591 TYPE_TAG_NAME (type
) = (char *) name
;
6592 if (die
->tag
== DW_TAG_class_type
)
6593 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6597 if (die
->tag
== DW_TAG_structure_type
)
6599 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6601 else if (die
->tag
== DW_TAG_union_type
)
6603 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6607 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6610 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6611 TYPE_DECLARED_CLASS (type
) = 1;
6613 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6616 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6620 TYPE_LENGTH (type
) = 0;
6623 TYPE_STUB_SUPPORTED (type
) = 1;
6624 if (die_is_declaration (die
, cu
))
6625 TYPE_STUB (type
) = 1;
6626 else if (attr
== NULL
&& die
->child
== NULL
6627 && producer_is_realview (cu
->producer
))
6628 /* RealView does not output the required DW_AT_declaration
6629 on incomplete types. */
6630 TYPE_STUB (type
) = 1;
6632 /* We need to add the type field to the die immediately so we don't
6633 infinitely recurse when dealing with pointers to the structure
6634 type within the structure itself. */
6635 set_die_type (die
, type
, cu
);
6637 /* set_die_type should be already done. */
6638 set_descriptive_type (type
, die
, cu
);
6640 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6642 struct field_info fi
;
6643 struct die_info
*child_die
;
6644 VEC (symbolp
) *template_args
= NULL
;
6646 memset (&fi
, 0, sizeof (struct field_info
));
6648 child_die
= die
->child
;
6650 while (child_die
&& child_die
->tag
)
6652 if (child_die
->tag
== DW_TAG_member
6653 || child_die
->tag
== DW_TAG_variable
)
6655 /* NOTE: carlton/2002-11-05: A C++ static data member
6656 should be a DW_TAG_member that is a declaration, but
6657 all versions of G++ as of this writing (so through at
6658 least 3.2.1) incorrectly generate DW_TAG_variable
6659 tags for them instead. */
6660 dwarf2_add_field (&fi
, child_die
, cu
);
6662 else if (child_die
->tag
== DW_TAG_subprogram
)
6664 /* C++ member function. */
6665 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6667 else if (child_die
->tag
== DW_TAG_inheritance
)
6669 /* C++ base class field. */
6670 dwarf2_add_field (&fi
, child_die
, cu
);
6672 else if (child_die
->tag
== DW_TAG_typedef
)
6673 dwarf2_add_typedef (&fi
, child_die
, cu
);
6674 else if (child_die
->tag
== DW_TAG_template_type_param
6675 || child_die
->tag
== DW_TAG_template_value_param
)
6677 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6679 VEC_safe_push (symbolp
, template_args
, arg
);
6682 child_die
= sibling_die (child_die
);
6685 /* Attach template arguments to type. */
6686 if (! VEC_empty (symbolp
, template_args
))
6688 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6689 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6690 = VEC_length (symbolp
, template_args
);
6691 TYPE_TEMPLATE_ARGUMENTS (type
)
6692 = obstack_alloc (&objfile
->objfile_obstack
,
6693 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6694 * sizeof (struct symbol
*)));
6695 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6696 VEC_address (symbolp
, template_args
),
6697 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6698 * sizeof (struct symbol
*)));
6699 VEC_free (symbolp
, template_args
);
6702 /* Attach fields and member functions to the type. */
6704 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6707 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6709 /* Get the type which refers to the base class (possibly this
6710 class itself) which contains the vtable pointer for the current
6711 class from the DW_AT_containing_type attribute. This use of
6712 DW_AT_containing_type is a GNU extension. */
6714 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6716 struct type
*t
= die_containing_type (die
, cu
);
6718 TYPE_VPTR_BASETYPE (type
) = t
;
6723 /* Our own class provides vtbl ptr. */
6724 for (i
= TYPE_NFIELDS (t
) - 1;
6725 i
>= TYPE_N_BASECLASSES (t
);
6728 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6730 if (is_vtable_name (fieldname
, cu
))
6732 TYPE_VPTR_FIELDNO (type
) = i
;
6737 /* Complain if virtual function table field not found. */
6738 if (i
< TYPE_N_BASECLASSES (t
))
6739 complaint (&symfile_complaints
,
6740 _("virtual function table pointer not found when defining class '%s'"),
6741 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6746 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6749 else if (cu
->producer
6750 && strncmp (cu
->producer
,
6751 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6753 /* The IBM XLC compiler does not provide direct indication
6754 of the containing type, but the vtable pointer is
6755 always named __vfp. */
6759 for (i
= TYPE_NFIELDS (type
) - 1;
6760 i
>= TYPE_N_BASECLASSES (type
);
6763 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6765 TYPE_VPTR_FIELDNO (type
) = i
;
6766 TYPE_VPTR_BASETYPE (type
) = type
;
6773 /* Copy fi.typedef_field_list linked list elements content into the
6774 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6775 if (fi
.typedef_field_list
)
6777 int i
= fi
.typedef_field_list_count
;
6779 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6780 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6781 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6782 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6784 /* Reverse the list order to keep the debug info elements order. */
6787 struct typedef_field
*dest
, *src
;
6789 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6790 src
= &fi
.typedef_field_list
->field
;
6791 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6797 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6799 do_cleanups (back_to
);
6804 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6806 struct die_info
*child_die
= die
->child
;
6807 struct type
*this_type
;
6809 this_type
= get_die_type (die
, cu
);
6810 if (this_type
== NULL
)
6811 this_type
= read_structure_type (die
, cu
);
6813 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6814 snapshots) has been known to create a die giving a declaration
6815 for a class that has, as a child, a die giving a definition for a
6816 nested class. So we have to process our children even if the
6817 current die is a declaration. Normally, of course, a declaration
6818 won't have any children at all. */
6820 while (child_die
!= NULL
&& child_die
->tag
)
6822 if (child_die
->tag
== DW_TAG_member
6823 || child_die
->tag
== DW_TAG_variable
6824 || child_die
->tag
== DW_TAG_inheritance
6825 || child_die
->tag
== DW_TAG_template_value_param
6826 || child_die
->tag
== DW_TAG_template_type_param
)
6831 process_die (child_die
, cu
);
6833 child_die
= sibling_die (child_die
);
6836 /* Do not consider external references. According to the DWARF standard,
6837 these DIEs are identified by the fact that they have no byte_size
6838 attribute, and a declaration attribute. */
6839 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6840 || !die_is_declaration (die
, cu
))
6841 new_symbol (die
, this_type
, cu
);
6844 /* Given a DW_AT_enumeration_type die, set its type. We do not
6845 complete the type's fields yet, or create any symbols. */
6847 static struct type
*
6848 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6850 struct objfile
*objfile
= cu
->objfile
;
6852 struct attribute
*attr
;
6855 /* If the definition of this type lives in .debug_types, read that type.
6856 Don't follow DW_AT_specification though, that will take us back up
6857 the chain and we want to go down. */
6858 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6861 struct dwarf2_cu
*type_cu
= cu
;
6862 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6864 type
= read_type_die (type_die
, type_cu
);
6865 return set_die_type (die
, type
, cu
);
6868 type
= alloc_type (objfile
);
6870 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
6871 name
= dwarf2_full_name (NULL
, die
, cu
);
6873 TYPE_TAG_NAME (type
) = (char *) name
;
6875 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6878 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6882 TYPE_LENGTH (type
) = 0;
6885 /* The enumeration DIE can be incomplete. In Ada, any type can be
6886 declared as private in the package spec, and then defined only
6887 inside the package body. Such types are known as Taft Amendment
6888 Types. When another package uses such a type, an incomplete DIE
6889 may be generated by the compiler. */
6890 if (die_is_declaration (die
, cu
))
6891 TYPE_STUB (type
) = 1;
6893 return set_die_type (die
, type
, cu
);
6896 /* Given a pointer to a die which begins an enumeration, process all
6897 the dies that define the members of the enumeration, and create the
6898 symbol for the enumeration type.
6900 NOTE: We reverse the order of the element list. */
6903 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6905 struct die_info
*child_die
;
6906 struct field
*fields
;
6909 int unsigned_enum
= 1;
6911 struct type
*this_type
;
6915 this_type
= get_die_type (die
, cu
);
6916 if (this_type
== NULL
)
6917 this_type
= read_enumeration_type (die
, cu
);
6918 if (die
->child
!= NULL
)
6920 child_die
= die
->child
;
6921 while (child_die
&& child_die
->tag
)
6923 if (child_die
->tag
!= DW_TAG_enumerator
)
6925 process_die (child_die
, cu
);
6929 name
= dwarf2_name (child_die
, cu
);
6932 sym
= new_symbol (child_die
, this_type
, cu
);
6933 if (SYMBOL_VALUE (sym
) < 0)
6936 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6938 fields
= (struct field
*)
6940 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
6941 * sizeof (struct field
));
6944 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
6945 FIELD_TYPE (fields
[num_fields
]) = NULL
;
6946 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
6947 FIELD_BITSIZE (fields
[num_fields
]) = 0;
6953 child_die
= sibling_die (child_die
);
6958 TYPE_NFIELDS (this_type
) = num_fields
;
6959 TYPE_FIELDS (this_type
) = (struct field
*)
6960 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
6961 memcpy (TYPE_FIELDS (this_type
), fields
,
6962 sizeof (struct field
) * num_fields
);
6966 TYPE_UNSIGNED (this_type
) = 1;
6969 new_symbol (die
, this_type
, cu
);
6972 /* Extract all information from a DW_TAG_array_type DIE and put it in
6973 the DIE's type field. For now, this only handles one dimensional
6976 static struct type
*
6977 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6979 struct objfile
*objfile
= cu
->objfile
;
6980 struct die_info
*child_die
;
6982 struct type
*element_type
, *range_type
, *index_type
;
6983 struct type
**range_types
= NULL
;
6984 struct attribute
*attr
;
6986 struct cleanup
*back_to
;
6989 element_type
= die_type (die
, cu
);
6991 /* The die_type call above may have already set the type for this DIE. */
6992 type
= get_die_type (die
, cu
);
6996 /* Irix 6.2 native cc creates array types without children for
6997 arrays with unspecified length. */
6998 if (die
->child
== NULL
)
7000 index_type
= objfile_type (objfile
)->builtin_int
;
7001 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7002 type
= create_array_type (NULL
, element_type
, range_type
);
7003 return set_die_type (die
, type
, cu
);
7006 back_to
= make_cleanup (null_cleanup
, NULL
);
7007 child_die
= die
->child
;
7008 while (child_die
&& child_die
->tag
)
7010 if (child_die
->tag
== DW_TAG_subrange_type
)
7012 struct type
*child_type
= read_type_die (child_die
, cu
);
7014 if (child_type
!= NULL
)
7016 /* The range type was succesfully read. Save it for
7017 the array type creation. */
7018 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7020 range_types
= (struct type
**)
7021 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7022 * sizeof (struct type
*));
7024 make_cleanup (free_current_contents
, &range_types
);
7026 range_types
[ndim
++] = child_type
;
7029 child_die
= sibling_die (child_die
);
7032 /* Dwarf2 dimensions are output from left to right, create the
7033 necessary array types in backwards order. */
7035 type
= element_type
;
7037 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7042 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7047 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7050 /* Understand Dwarf2 support for vector types (like they occur on
7051 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7052 array type. This is not part of the Dwarf2/3 standard yet, but a
7053 custom vendor extension. The main difference between a regular
7054 array and the vector variant is that vectors are passed by value
7056 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7058 make_vector_type (type
);
7060 name
= dwarf2_name (die
, cu
);
7062 TYPE_NAME (type
) = name
;
7064 /* Install the type in the die. */
7065 set_die_type (die
, type
, cu
);
7067 /* set_die_type should be already done. */
7068 set_descriptive_type (type
, die
, cu
);
7070 do_cleanups (back_to
);
7075 static enum dwarf_array_dim_ordering
7076 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7078 struct attribute
*attr
;
7080 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7082 if (attr
) return DW_SND (attr
);
7085 GNU F77 is a special case, as at 08/2004 array type info is the
7086 opposite order to the dwarf2 specification, but data is still
7087 laid out as per normal fortran.
7089 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7093 if (cu
->language
== language_fortran
7094 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7096 return DW_ORD_row_major
;
7099 switch (cu
->language_defn
->la_array_ordering
)
7101 case array_column_major
:
7102 return DW_ORD_col_major
;
7103 case array_row_major
:
7105 return DW_ORD_row_major
;
7109 /* Extract all information from a DW_TAG_set_type DIE and put it in
7110 the DIE's type field. */
7112 static struct type
*
7113 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7115 struct type
*domain_type
, *set_type
;
7116 struct attribute
*attr
;
7118 domain_type
= die_type (die
, cu
);
7120 /* The die_type call above may have already set the type for this DIE. */
7121 set_type
= get_die_type (die
, cu
);
7125 set_type
= create_set_type (NULL
, domain_type
);
7127 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7129 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7131 return set_die_type (die
, set_type
, cu
);
7134 /* First cut: install each common block member as a global variable. */
7137 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7139 struct die_info
*child_die
;
7140 struct attribute
*attr
;
7142 CORE_ADDR base
= (CORE_ADDR
) 0;
7144 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7147 /* Support the .debug_loc offsets */
7148 if (attr_form_is_block (attr
))
7150 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7152 else if (attr_form_is_section_offset (attr
))
7154 dwarf2_complex_location_expr_complaint ();
7158 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7159 "common block member");
7162 if (die
->child
!= NULL
)
7164 child_die
= die
->child
;
7165 while (child_die
&& child_die
->tag
)
7167 sym
= new_symbol (child_die
, NULL
, cu
);
7168 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7171 CORE_ADDR byte_offset
= 0;
7173 if (attr_form_is_section_offset (attr
))
7174 dwarf2_complex_location_expr_complaint ();
7175 else if (attr_form_is_constant (attr
))
7176 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7177 else if (attr_form_is_block (attr
))
7178 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7180 dwarf2_complex_location_expr_complaint ();
7182 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7183 add_symbol_to_list (sym
, &global_symbols
);
7185 child_die
= sibling_die (child_die
);
7190 /* Create a type for a C++ namespace. */
7192 static struct type
*
7193 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7195 struct objfile
*objfile
= cu
->objfile
;
7196 const char *previous_prefix
, *name
;
7200 /* For extensions, reuse the type of the original namespace. */
7201 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7203 struct die_info
*ext_die
;
7204 struct dwarf2_cu
*ext_cu
= cu
;
7206 ext_die
= dwarf2_extension (die
, &ext_cu
);
7207 type
= read_type_die (ext_die
, ext_cu
);
7208 return set_die_type (die
, type
, cu
);
7211 name
= namespace_name (die
, &is_anonymous
, cu
);
7213 /* Now build the name of the current namespace. */
7215 previous_prefix
= determine_prefix (die
, cu
);
7216 if (previous_prefix
[0] != '\0')
7217 name
= typename_concat (&objfile
->objfile_obstack
,
7218 previous_prefix
, name
, 0, cu
);
7220 /* Create the type. */
7221 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7223 TYPE_NAME (type
) = (char *) name
;
7224 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7226 return set_die_type (die
, type
, cu
);
7229 /* Read a C++ namespace. */
7232 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7234 struct objfile
*objfile
= cu
->objfile
;
7238 /* Add a symbol associated to this if we haven't seen the namespace
7239 before. Also, add a using directive if it's an anonymous
7242 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7246 type
= read_type_die (die
, cu
);
7247 new_symbol (die
, type
, cu
);
7249 name
= namespace_name (die
, &is_anonymous
, cu
);
7252 const char *previous_prefix
= determine_prefix (die
, cu
);
7254 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7255 NULL
, &objfile
->objfile_obstack
);
7259 if (die
->child
!= NULL
)
7261 struct die_info
*child_die
= die
->child
;
7263 while (child_die
&& child_die
->tag
)
7265 process_die (child_die
, cu
);
7266 child_die
= sibling_die (child_die
);
7271 /* Read a Fortran module as type. This DIE can be only a declaration used for
7272 imported module. Still we need that type as local Fortran "use ... only"
7273 declaration imports depend on the created type in determine_prefix. */
7275 static struct type
*
7276 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7278 struct objfile
*objfile
= cu
->objfile
;
7282 module_name
= dwarf2_name (die
, cu
);
7284 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7286 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7288 /* determine_prefix uses TYPE_TAG_NAME. */
7289 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7291 return set_die_type (die
, type
, cu
);
7294 /* Read a Fortran module. */
7297 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7299 struct die_info
*child_die
= die
->child
;
7301 while (child_die
&& child_die
->tag
)
7303 process_die (child_die
, cu
);
7304 child_die
= sibling_die (child_die
);
7308 /* Return the name of the namespace represented by DIE. Set
7309 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7313 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7315 struct die_info
*current_die
;
7316 const char *name
= NULL
;
7318 /* Loop through the extensions until we find a name. */
7320 for (current_die
= die
;
7321 current_die
!= NULL
;
7322 current_die
= dwarf2_extension (die
, &cu
))
7324 name
= dwarf2_name (current_die
, cu
);
7329 /* Is it an anonymous namespace? */
7331 *is_anonymous
= (name
== NULL
);
7333 name
= "(anonymous namespace)";
7338 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7339 the user defined type vector. */
7341 static struct type
*
7342 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7344 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7345 struct comp_unit_head
*cu_header
= &cu
->header
;
7347 struct attribute
*attr_byte_size
;
7348 struct attribute
*attr_address_class
;
7349 int byte_size
, addr_class
;
7350 struct type
*target_type
;
7352 target_type
= die_type (die
, cu
);
7354 /* The die_type call above may have already set the type for this DIE. */
7355 type
= get_die_type (die
, cu
);
7359 type
= lookup_pointer_type (target_type
);
7361 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7363 byte_size
= DW_UNSND (attr_byte_size
);
7365 byte_size
= cu_header
->addr_size
;
7367 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7368 if (attr_address_class
)
7369 addr_class
= DW_UNSND (attr_address_class
);
7371 addr_class
= DW_ADDR_none
;
7373 /* If the pointer size or address class is different than the
7374 default, create a type variant marked as such and set the
7375 length accordingly. */
7376 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7378 if (gdbarch_address_class_type_flags_p (gdbarch
))
7382 type_flags
= gdbarch_address_class_type_flags
7383 (gdbarch
, byte_size
, addr_class
);
7384 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7386 type
= make_type_with_address_space (type
, type_flags
);
7388 else if (TYPE_LENGTH (type
) != byte_size
)
7390 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7394 /* Should we also complain about unhandled address classes? */
7398 TYPE_LENGTH (type
) = byte_size
;
7399 return set_die_type (die
, type
, cu
);
7402 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7403 the user defined type vector. */
7405 static struct type
*
7406 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7409 struct type
*to_type
;
7410 struct type
*domain
;
7412 to_type
= die_type (die
, cu
);
7413 domain
= die_containing_type (die
, cu
);
7415 /* The calls above may have already set the type for this DIE. */
7416 type
= get_die_type (die
, cu
);
7420 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7421 type
= lookup_methodptr_type (to_type
);
7423 type
= lookup_memberptr_type (to_type
, domain
);
7425 return set_die_type (die
, type
, cu
);
7428 /* Extract all information from a DW_TAG_reference_type DIE and add to
7429 the user defined type vector. */
7431 static struct type
*
7432 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7434 struct comp_unit_head
*cu_header
= &cu
->header
;
7435 struct type
*type
, *target_type
;
7436 struct attribute
*attr
;
7438 target_type
= die_type (die
, cu
);
7440 /* The die_type call above may have already set the type for this DIE. */
7441 type
= get_die_type (die
, cu
);
7445 type
= lookup_reference_type (target_type
);
7446 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7449 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7453 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7455 return set_die_type (die
, type
, cu
);
7458 static struct type
*
7459 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7461 struct type
*base_type
, *cv_type
;
7463 base_type
= die_type (die
, cu
);
7465 /* The die_type call above may have already set the type for this DIE. */
7466 cv_type
= get_die_type (die
, cu
);
7470 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7471 return set_die_type (die
, cv_type
, cu
);
7474 static struct type
*
7475 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7477 struct type
*base_type
, *cv_type
;
7479 base_type
= die_type (die
, cu
);
7481 /* The die_type call above may have already set the type for this DIE. */
7482 cv_type
= get_die_type (die
, cu
);
7486 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7487 return set_die_type (die
, cv_type
, cu
);
7490 /* Extract all information from a DW_TAG_string_type DIE and add to
7491 the user defined type vector. It isn't really a user defined type,
7492 but it behaves like one, with other DIE's using an AT_user_def_type
7493 attribute to reference it. */
7495 static struct type
*
7496 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7498 struct objfile
*objfile
= cu
->objfile
;
7499 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7500 struct type
*type
, *range_type
, *index_type
, *char_type
;
7501 struct attribute
*attr
;
7502 unsigned int length
;
7504 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7507 length
= DW_UNSND (attr
);
7511 /* check for the DW_AT_byte_size attribute */
7512 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7515 length
= DW_UNSND (attr
);
7523 index_type
= objfile_type (objfile
)->builtin_int
;
7524 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7525 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7526 type
= create_string_type (NULL
, char_type
, range_type
);
7528 return set_die_type (die
, type
, cu
);
7531 /* Handle DIES due to C code like:
7535 int (*funcp)(int a, long l);
7539 ('funcp' generates a DW_TAG_subroutine_type DIE)
7542 static struct type
*
7543 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7545 struct type
*type
; /* Type that this function returns */
7546 struct type
*ftype
; /* Function that returns above type */
7547 struct attribute
*attr
;
7549 type
= die_type (die
, cu
);
7551 /* The die_type call above may have already set the type for this DIE. */
7552 ftype
= get_die_type (die
, cu
);
7556 ftype
= lookup_function_type (type
);
7558 /* All functions in C++, Pascal and Java have prototypes. */
7559 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7560 if ((attr
&& (DW_UNSND (attr
) != 0))
7561 || cu
->language
== language_cplus
7562 || cu
->language
== language_java
7563 || cu
->language
== language_pascal
)
7564 TYPE_PROTOTYPED (ftype
) = 1;
7565 else if (producer_is_realview (cu
->producer
))
7566 /* RealView does not emit DW_AT_prototyped. We can not
7567 distinguish prototyped and unprototyped functions; default to
7568 prototyped, since that is more common in modern code (and
7569 RealView warns about unprototyped functions). */
7570 TYPE_PROTOTYPED (ftype
) = 1;
7572 /* Store the calling convention in the type if it's available in
7573 the subroutine die. Otherwise set the calling convention to
7574 the default value DW_CC_normal. */
7575 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7576 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7578 /* We need to add the subroutine type to the die immediately so
7579 we don't infinitely recurse when dealing with parameters
7580 declared as the same subroutine type. */
7581 set_die_type (die
, ftype
, cu
);
7583 if (die
->child
!= NULL
)
7585 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7586 struct die_info
*child_die
;
7587 int nparams
, iparams
;
7589 /* Count the number of parameters.
7590 FIXME: GDB currently ignores vararg functions, but knows about
7591 vararg member functions. */
7593 child_die
= die
->child
;
7594 while (child_die
&& child_die
->tag
)
7596 if (child_die
->tag
== DW_TAG_formal_parameter
)
7598 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7599 TYPE_VARARGS (ftype
) = 1;
7600 child_die
= sibling_die (child_die
);
7603 /* Allocate storage for parameters and fill them in. */
7604 TYPE_NFIELDS (ftype
) = nparams
;
7605 TYPE_FIELDS (ftype
) = (struct field
*)
7606 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7608 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7609 even if we error out during the parameters reading below. */
7610 for (iparams
= 0; iparams
< nparams
; iparams
++)
7611 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7614 child_die
= die
->child
;
7615 while (child_die
&& child_die
->tag
)
7617 if (child_die
->tag
== DW_TAG_formal_parameter
)
7619 struct type
*arg_type
;
7621 /* DWARF version 2 has no clean way to discern C++
7622 static and non-static member functions. G++ helps
7623 GDB by marking the first parameter for non-static
7624 member functions (which is the this pointer) as
7625 artificial. We pass this information to
7626 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7628 DWARF version 3 added DW_AT_object_pointer, which GCC
7629 4.5 does not yet generate. */
7630 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7632 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7635 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7637 /* GCC/43521: In java, the formal parameter
7638 "this" is sometimes not marked with DW_AT_artificial. */
7639 if (cu
->language
== language_java
)
7641 const char *name
= dwarf2_name (child_die
, cu
);
7643 if (name
&& !strcmp (name
, "this"))
7644 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7647 arg_type
= die_type (child_die
, cu
);
7649 /* RealView does not mark THIS as const, which the testsuite
7650 expects. GCC marks THIS as const in method definitions,
7651 but not in the class specifications (GCC PR 43053). */
7652 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7653 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7656 struct dwarf2_cu
*arg_cu
= cu
;
7657 const char *name
= dwarf2_name (child_die
, cu
);
7659 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7662 /* If the compiler emits this, use it. */
7663 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7666 else if (name
&& strcmp (name
, "this") == 0)
7667 /* Function definitions will have the argument names. */
7669 else if (name
== NULL
&& iparams
== 0)
7670 /* Declarations may not have the names, so like
7671 elsewhere in GDB, assume an artificial first
7672 argument is "this". */
7676 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7680 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7683 child_die
= sibling_die (child_die
);
7690 static struct type
*
7691 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7693 struct objfile
*objfile
= cu
->objfile
;
7694 const char *name
= NULL
;
7695 struct type
*this_type
;
7697 name
= dwarf2_full_name (NULL
, die
, cu
);
7698 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7699 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7700 TYPE_NAME (this_type
) = (char *) name
;
7701 set_die_type (die
, this_type
, cu
);
7702 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7706 /* Find a representation of a given base type and install
7707 it in the TYPE field of the die. */
7709 static struct type
*
7710 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7712 struct objfile
*objfile
= cu
->objfile
;
7714 struct attribute
*attr
;
7715 int encoding
= 0, size
= 0;
7717 enum type_code code
= TYPE_CODE_INT
;
7719 struct type
*target_type
= NULL
;
7721 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7724 encoding
= DW_UNSND (attr
);
7726 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7729 size
= DW_UNSND (attr
);
7731 name
= dwarf2_name (die
, cu
);
7734 complaint (&symfile_complaints
,
7735 _("DW_AT_name missing from DW_TAG_base_type"));
7740 case DW_ATE_address
:
7741 /* Turn DW_ATE_address into a void * pointer. */
7742 code
= TYPE_CODE_PTR
;
7743 type_flags
|= TYPE_FLAG_UNSIGNED
;
7744 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7746 case DW_ATE_boolean
:
7747 code
= TYPE_CODE_BOOL
;
7748 type_flags
|= TYPE_FLAG_UNSIGNED
;
7750 case DW_ATE_complex_float
:
7751 code
= TYPE_CODE_COMPLEX
;
7752 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7754 case DW_ATE_decimal_float
:
7755 code
= TYPE_CODE_DECFLOAT
;
7758 code
= TYPE_CODE_FLT
;
7762 case DW_ATE_unsigned
:
7763 type_flags
|= TYPE_FLAG_UNSIGNED
;
7765 case DW_ATE_signed_char
:
7766 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7767 || cu
->language
== language_pascal
)
7768 code
= TYPE_CODE_CHAR
;
7770 case DW_ATE_unsigned_char
:
7771 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7772 || cu
->language
== language_pascal
)
7773 code
= TYPE_CODE_CHAR
;
7774 type_flags
|= TYPE_FLAG_UNSIGNED
;
7777 /* We just treat this as an integer and then recognize the
7778 type by name elsewhere. */
7782 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7783 dwarf_type_encoding_name (encoding
));
7787 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7788 TYPE_NAME (type
) = name
;
7789 TYPE_TARGET_TYPE (type
) = target_type
;
7791 if (name
&& strcmp (name
, "char") == 0)
7792 TYPE_NOSIGN (type
) = 1;
7794 return set_die_type (die
, type
, cu
);
7797 /* Read the given DW_AT_subrange DIE. */
7799 static struct type
*
7800 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7802 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7803 struct type
*base_type
;
7804 struct type
*range_type
;
7805 struct attribute
*attr
;
7809 LONGEST negative_mask
;
7811 base_type
= die_type (die
, cu
);
7812 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7813 check_typedef (base_type
);
7815 /* The die_type call above may have already set the type for this DIE. */
7816 range_type
= get_die_type (die
, cu
);
7820 if (cu
->language
== language_fortran
)
7822 /* FORTRAN implies a lower bound of 1, if not given. */
7826 /* FIXME: For variable sized arrays either of these could be
7827 a variable rather than a constant value. We'll allow it,
7828 but we don't know how to handle it. */
7829 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7831 low
= dwarf2_get_attr_constant_value (attr
, 0);
7833 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7836 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7838 /* GCC encodes arrays with unspecified or dynamic length
7839 with a DW_FORM_block1 attribute or a reference attribute.
7840 FIXME: GDB does not yet know how to handle dynamic
7841 arrays properly, treat them as arrays with unspecified
7844 FIXME: jimb/2003-09-22: GDB does not really know
7845 how to handle arrays of unspecified length
7846 either; we just represent them as zero-length
7847 arrays. Choose an appropriate upper bound given
7848 the lower bound we've computed above. */
7852 high
= dwarf2_get_attr_constant_value (attr
, 1);
7856 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
7859 int count
= dwarf2_get_attr_constant_value (attr
, 1);
7860 high
= low
+ count
- 1;
7864 /* Dwarf-2 specifications explicitly allows to create subrange types
7865 without specifying a base type.
7866 In that case, the base type must be set to the type of
7867 the lower bound, upper bound or count, in that order, if any of these
7868 three attributes references an object that has a type.
7869 If no base type is found, the Dwarf-2 specifications say that
7870 a signed integer type of size equal to the size of an address should
7872 For the following C code: `extern char gdb_int [];'
7873 GCC produces an empty range DIE.
7874 FIXME: muller/2010-05-28: Possible references to object for low bound,
7875 high bound or count are not yet handled by this code.
7877 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
7879 struct objfile
*objfile
= cu
->objfile
;
7880 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7881 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
7882 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
7884 /* Test "int", "long int", and "long long int" objfile types,
7885 and select the first one having a size above or equal to the
7886 architecture address size. */
7887 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7888 base_type
= int_type
;
7891 int_type
= objfile_type (objfile
)->builtin_long
;
7892 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7893 base_type
= int_type
;
7896 int_type
= objfile_type (objfile
)->builtin_long_long
;
7897 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7898 base_type
= int_type
;
7904 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
7905 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
7906 low
|= negative_mask
;
7907 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
7908 high
|= negative_mask
;
7910 range_type
= create_range_type (NULL
, base_type
, low
, high
);
7912 /* Mark arrays with dynamic length at least as an array of unspecified
7913 length. GDB could check the boundary but before it gets implemented at
7914 least allow accessing the array elements. */
7915 if (attr
&& attr
->form
== DW_FORM_block1
)
7916 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
7918 name
= dwarf2_name (die
, cu
);
7920 TYPE_NAME (range_type
) = name
;
7922 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7924 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
7926 set_die_type (die
, range_type
, cu
);
7928 /* set_die_type should be already done. */
7929 set_descriptive_type (range_type
, die
, cu
);
7934 static struct type
*
7935 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7939 /* For now, we only support the C meaning of an unspecified type: void. */
7941 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
7942 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
7944 return set_die_type (die
, type
, cu
);
7947 /* Trivial hash function for die_info: the hash value of a DIE
7948 is its offset in .debug_info for this objfile. */
7951 die_hash (const void *item
)
7953 const struct die_info
*die
= item
;
7958 /* Trivial comparison function for die_info structures: two DIEs
7959 are equal if they have the same offset. */
7962 die_eq (const void *item_lhs
, const void *item_rhs
)
7964 const struct die_info
*die_lhs
= item_lhs
;
7965 const struct die_info
*die_rhs
= item_rhs
;
7967 return die_lhs
->offset
== die_rhs
->offset
;
7970 /* Read a whole compilation unit into a linked list of dies. */
7972 static struct die_info
*
7973 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7975 struct die_reader_specs reader_specs
;
7976 int read_abbrevs
= 0;
7977 struct cleanup
*back_to
= NULL
;
7978 struct die_info
*die
;
7980 if (cu
->dwarf2_abbrevs
== NULL
)
7982 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
7983 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
7987 gdb_assert (cu
->die_hash
== NULL
);
7989 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7993 &cu
->comp_unit_obstack
,
7994 hashtab_obstack_allocate
,
7995 dummy_obstack_deallocate
);
7997 init_cu_die_reader (&reader_specs
, cu
);
7999 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8002 do_cleanups (back_to
);
8007 /* Main entry point for reading a DIE and all children.
8008 Read the DIE and dump it if requested. */
8010 static struct die_info
*
8011 read_die_and_children (const struct die_reader_specs
*reader
,
8013 gdb_byte
**new_info_ptr
,
8014 struct die_info
*parent
)
8016 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8017 new_info_ptr
, parent
);
8019 if (dwarf2_die_debug
)
8021 fprintf_unfiltered (gdb_stdlog
,
8022 "\nRead die from %s of %s:\n",
8023 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8025 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8027 : "unknown section",
8028 reader
->abfd
->filename
);
8029 dump_die (result
, dwarf2_die_debug
);
8035 /* Read a single die and all its descendents. Set the die's sibling
8036 field to NULL; set other fields in the die correctly, and set all
8037 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8038 location of the info_ptr after reading all of those dies. PARENT
8039 is the parent of the die in question. */
8041 static struct die_info
*
8042 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8044 gdb_byte
**new_info_ptr
,
8045 struct die_info
*parent
)
8047 struct die_info
*die
;
8051 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8054 *new_info_ptr
= cur_ptr
;
8057 store_in_ref_table (die
, reader
->cu
);
8060 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8064 *new_info_ptr
= cur_ptr
;
8067 die
->sibling
= NULL
;
8068 die
->parent
= parent
;
8072 /* Read a die, all of its descendents, and all of its siblings; set
8073 all of the fields of all of the dies correctly. Arguments are as
8074 in read_die_and_children. */
8076 static struct die_info
*
8077 read_die_and_siblings (const struct die_reader_specs
*reader
,
8079 gdb_byte
**new_info_ptr
,
8080 struct die_info
*parent
)
8082 struct die_info
*first_die
, *last_sibling
;
8086 first_die
= last_sibling
= NULL
;
8090 struct die_info
*die
8091 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8095 *new_info_ptr
= cur_ptr
;
8102 last_sibling
->sibling
= die
;
8108 /* Read the die from the .debug_info section buffer. Set DIEP to
8109 point to a newly allocated die with its information, except for its
8110 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8111 whether the die has children or not. */
8114 read_full_die (const struct die_reader_specs
*reader
,
8115 struct die_info
**diep
, gdb_byte
*info_ptr
,
8118 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8119 struct abbrev_info
*abbrev
;
8120 struct die_info
*die
;
8121 struct dwarf2_cu
*cu
= reader
->cu
;
8122 bfd
*abfd
= reader
->abfd
;
8124 offset
= info_ptr
- reader
->buffer
;
8125 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8126 info_ptr
+= bytes_read
;
8134 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8136 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8138 bfd_get_filename (abfd
));
8140 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8141 die
->offset
= offset
;
8142 die
->tag
= abbrev
->tag
;
8143 die
->abbrev
= abbrev_number
;
8145 die
->num_attrs
= abbrev
->num_attrs
;
8147 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8148 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8149 abfd
, info_ptr
, cu
);
8152 *has_children
= abbrev
->has_children
;
8156 /* In DWARF version 2, the description of the debugging information is
8157 stored in a separate .debug_abbrev section. Before we read any
8158 dies from a section we read in all abbreviations and install them
8159 in a hash table. This function also sets flags in CU describing
8160 the data found in the abbrev table. */
8163 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8165 struct comp_unit_head
*cu_header
= &cu
->header
;
8166 gdb_byte
*abbrev_ptr
;
8167 struct abbrev_info
*cur_abbrev
;
8168 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8169 unsigned int abbrev_form
, hash_number
;
8170 struct attr_abbrev
*cur_attrs
;
8171 unsigned int allocated_attrs
;
8173 /* Initialize dwarf2 abbrevs */
8174 obstack_init (&cu
->abbrev_obstack
);
8175 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8177 * sizeof (struct abbrev_info
*)));
8178 memset (cu
->dwarf2_abbrevs
, 0,
8179 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8181 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8182 &dwarf2_per_objfile
->abbrev
);
8183 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8184 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8185 abbrev_ptr
+= bytes_read
;
8187 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8188 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8190 /* loop until we reach an abbrev number of 0 */
8191 while (abbrev_number
)
8193 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8195 /* read in abbrev header */
8196 cur_abbrev
->number
= abbrev_number
;
8197 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8198 abbrev_ptr
+= bytes_read
;
8199 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8202 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8203 cu
->has_namespace_info
= 1;
8205 /* now read in declarations */
8206 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8207 abbrev_ptr
+= bytes_read
;
8208 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8209 abbrev_ptr
+= bytes_read
;
8212 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8214 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8216 = xrealloc (cur_attrs
, (allocated_attrs
8217 * sizeof (struct attr_abbrev
)));
8220 /* Record whether this compilation unit might have
8221 inter-compilation-unit references. If we don't know what form
8222 this attribute will have, then it might potentially be a
8223 DW_FORM_ref_addr, so we conservatively expect inter-CU
8226 if (abbrev_form
== DW_FORM_ref_addr
8227 || abbrev_form
== DW_FORM_indirect
)
8228 cu
->has_form_ref_addr
= 1;
8230 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8231 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8232 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8233 abbrev_ptr
+= bytes_read
;
8234 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8235 abbrev_ptr
+= bytes_read
;
8238 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8239 (cur_abbrev
->num_attrs
8240 * sizeof (struct attr_abbrev
)));
8241 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8242 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8244 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8245 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8246 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8248 /* Get next abbreviation.
8249 Under Irix6 the abbreviations for a compilation unit are not
8250 always properly terminated with an abbrev number of 0.
8251 Exit loop if we encounter an abbreviation which we have
8252 already read (which means we are about to read the abbreviations
8253 for the next compile unit) or if the end of the abbreviation
8254 table is reached. */
8255 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8256 >= dwarf2_per_objfile
->abbrev
.size
)
8258 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8259 abbrev_ptr
+= bytes_read
;
8260 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8267 /* Release the memory used by the abbrev table for a compilation unit. */
8270 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8272 struct dwarf2_cu
*cu
= ptr_to_cu
;
8274 obstack_free (&cu
->abbrev_obstack
, NULL
);
8275 cu
->dwarf2_abbrevs
= NULL
;
8278 /* Lookup an abbrev_info structure in the abbrev hash table. */
8280 static struct abbrev_info
*
8281 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8283 unsigned int hash_number
;
8284 struct abbrev_info
*abbrev
;
8286 hash_number
= number
% ABBREV_HASH_SIZE
;
8287 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8291 if (abbrev
->number
== number
)
8294 abbrev
= abbrev
->next
;
8299 /* Returns nonzero if TAG represents a type that we might generate a partial
8303 is_type_tag_for_partial (int tag
)
8308 /* Some types that would be reasonable to generate partial symbols for,
8309 that we don't at present. */
8310 case DW_TAG_array_type
:
8311 case DW_TAG_file_type
:
8312 case DW_TAG_ptr_to_member_type
:
8313 case DW_TAG_set_type
:
8314 case DW_TAG_string_type
:
8315 case DW_TAG_subroutine_type
:
8317 case DW_TAG_base_type
:
8318 case DW_TAG_class_type
:
8319 case DW_TAG_interface_type
:
8320 case DW_TAG_enumeration_type
:
8321 case DW_TAG_structure_type
:
8322 case DW_TAG_subrange_type
:
8323 case DW_TAG_typedef
:
8324 case DW_TAG_union_type
:
8331 /* Load all DIEs that are interesting for partial symbols into memory. */
8333 static struct partial_die_info
*
8334 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8335 int building_psymtab
, struct dwarf2_cu
*cu
)
8337 struct partial_die_info
*part_die
;
8338 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8339 struct abbrev_info
*abbrev
;
8340 unsigned int bytes_read
;
8341 unsigned int load_all
= 0;
8343 int nesting_level
= 1;
8348 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8352 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8356 &cu
->comp_unit_obstack
,
8357 hashtab_obstack_allocate
,
8358 dummy_obstack_deallocate
);
8360 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8361 sizeof (struct partial_die_info
));
8365 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8367 /* A NULL abbrev means the end of a series of children. */
8370 if (--nesting_level
== 0)
8372 /* PART_DIE was probably the last thing allocated on the
8373 comp_unit_obstack, so we could call obstack_free
8374 here. We don't do that because the waste is small,
8375 and will be cleaned up when we're done with this
8376 compilation unit. This way, we're also more robust
8377 against other users of the comp_unit_obstack. */
8380 info_ptr
+= bytes_read
;
8381 last_die
= parent_die
;
8382 parent_die
= parent_die
->die_parent
;
8386 /* Check for template arguments. We never save these; if
8387 they're seen, we just mark the parent, and go on our way. */
8388 if (parent_die
!= NULL
8389 && cu
->language
== language_cplus
8390 && (abbrev
->tag
== DW_TAG_template_type_param
8391 || abbrev
->tag
== DW_TAG_template_value_param
))
8393 parent_die
->has_template_arguments
= 1;
8397 /* We don't need a partial DIE for the template argument. */
8398 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8404 /* We only recurse into subprograms looking for template arguments.
8405 Skip their other children. */
8407 && cu
->language
== language_cplus
8408 && parent_die
!= NULL
8409 && parent_die
->tag
== DW_TAG_subprogram
)
8411 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8415 /* Check whether this DIE is interesting enough to save. Normally
8416 we would not be interested in members here, but there may be
8417 later variables referencing them via DW_AT_specification (for
8420 && !is_type_tag_for_partial (abbrev
->tag
)
8421 && abbrev
->tag
!= DW_TAG_enumerator
8422 && abbrev
->tag
!= DW_TAG_subprogram
8423 && abbrev
->tag
!= DW_TAG_lexical_block
8424 && abbrev
->tag
!= DW_TAG_variable
8425 && abbrev
->tag
!= DW_TAG_namespace
8426 && abbrev
->tag
!= DW_TAG_module
8427 && abbrev
->tag
!= DW_TAG_member
)
8429 /* Otherwise we skip to the next sibling, if any. */
8430 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8434 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8435 buffer
, info_ptr
, cu
);
8437 /* This two-pass algorithm for processing partial symbols has a
8438 high cost in cache pressure. Thus, handle some simple cases
8439 here which cover the majority of C partial symbols. DIEs
8440 which neither have specification tags in them, nor could have
8441 specification tags elsewhere pointing at them, can simply be
8442 processed and discarded.
8444 This segment is also optional; scan_partial_symbols and
8445 add_partial_symbol will handle these DIEs if we chain
8446 them in normally. When compilers which do not emit large
8447 quantities of duplicate debug information are more common,
8448 this code can probably be removed. */
8450 /* Any complete simple types at the top level (pretty much all
8451 of them, for a language without namespaces), can be processed
8453 if (parent_die
== NULL
8454 && part_die
->has_specification
== 0
8455 && part_die
->is_declaration
== 0
8456 && (part_die
->tag
== DW_TAG_typedef
8457 || part_die
->tag
== DW_TAG_base_type
8458 || part_die
->tag
== DW_TAG_subrange_type
))
8460 if (building_psymtab
&& part_die
->name
!= NULL
)
8461 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8462 VAR_DOMAIN
, LOC_TYPEDEF
,
8463 &cu
->objfile
->static_psymbols
,
8464 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8465 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8469 /* If we're at the second level, and we're an enumerator, and
8470 our parent has no specification (meaning possibly lives in a
8471 namespace elsewhere), then we can add the partial symbol now
8472 instead of queueing it. */
8473 if (part_die
->tag
== DW_TAG_enumerator
8474 && parent_die
!= NULL
8475 && parent_die
->die_parent
== NULL
8476 && parent_die
->tag
== DW_TAG_enumeration_type
8477 && parent_die
->has_specification
== 0)
8479 if (part_die
->name
== NULL
)
8480 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8481 else if (building_psymtab
)
8482 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8483 VAR_DOMAIN
, LOC_CONST
,
8484 (cu
->language
== language_cplus
8485 || cu
->language
== language_java
)
8486 ? &cu
->objfile
->global_psymbols
8487 : &cu
->objfile
->static_psymbols
,
8488 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8490 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8494 /* We'll save this DIE so link it in. */
8495 part_die
->die_parent
= parent_die
;
8496 part_die
->die_sibling
= NULL
;
8497 part_die
->die_child
= NULL
;
8499 if (last_die
&& last_die
== parent_die
)
8500 last_die
->die_child
= part_die
;
8502 last_die
->die_sibling
= part_die
;
8504 last_die
= part_die
;
8506 if (first_die
== NULL
)
8507 first_die
= part_die
;
8509 /* Maybe add the DIE to the hash table. Not all DIEs that we
8510 find interesting need to be in the hash table, because we
8511 also have the parent/sibling/child chains; only those that we
8512 might refer to by offset later during partial symbol reading.
8514 For now this means things that might have be the target of a
8515 DW_AT_specification, DW_AT_abstract_origin, or
8516 DW_AT_extension. DW_AT_extension will refer only to
8517 namespaces; DW_AT_abstract_origin refers to functions (and
8518 many things under the function DIE, but we do not recurse
8519 into function DIEs during partial symbol reading) and
8520 possibly variables as well; DW_AT_specification refers to
8521 declarations. Declarations ought to have the DW_AT_declaration
8522 flag. It happens that GCC forgets to put it in sometimes, but
8523 only for functions, not for types.
8525 Adding more things than necessary to the hash table is harmless
8526 except for the performance cost. Adding too few will result in
8527 wasted time in find_partial_die, when we reread the compilation
8528 unit with load_all_dies set. */
8531 || abbrev
->tag
== DW_TAG_subprogram
8532 || abbrev
->tag
== DW_TAG_variable
8533 || abbrev
->tag
== DW_TAG_namespace
8534 || part_die
->is_declaration
)
8538 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8539 part_die
->offset
, INSERT
);
8543 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8544 sizeof (struct partial_die_info
));
8546 /* For some DIEs we want to follow their children (if any). For C
8547 we have no reason to follow the children of structures; for other
8548 languages we have to, so that we can get at method physnames
8549 to infer fully qualified class names, for DW_AT_specification,
8550 and for C++ template arguments. For C++, we also look one level
8551 inside functions to find template arguments (if the name of the
8552 function does not already contain the template arguments).
8554 For Ada, we need to scan the children of subprograms and lexical
8555 blocks as well because Ada allows the definition of nested
8556 entities that could be interesting for the debugger, such as
8557 nested subprograms for instance. */
8558 if (last_die
->has_children
8560 || last_die
->tag
== DW_TAG_namespace
8561 || last_die
->tag
== DW_TAG_module
8562 || last_die
->tag
== DW_TAG_enumeration_type
8563 || (cu
->language
== language_cplus
8564 && last_die
->tag
== DW_TAG_subprogram
8565 && (last_die
->name
== NULL
8566 || strchr (last_die
->name
, '<') == NULL
))
8567 || (cu
->language
!= language_c
8568 && (last_die
->tag
== DW_TAG_class_type
8569 || last_die
->tag
== DW_TAG_interface_type
8570 || last_die
->tag
== DW_TAG_structure_type
8571 || last_die
->tag
== DW_TAG_union_type
))
8572 || (cu
->language
== language_ada
8573 && (last_die
->tag
== DW_TAG_subprogram
8574 || last_die
->tag
== DW_TAG_lexical_block
))))
8577 parent_die
= last_die
;
8581 /* Otherwise we skip to the next sibling, if any. */
8582 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8584 /* Back to the top, do it again. */
8588 /* Read a minimal amount of information into the minimal die structure. */
8591 read_partial_die (struct partial_die_info
*part_die
,
8592 struct abbrev_info
*abbrev
,
8593 unsigned int abbrev_len
, bfd
*abfd
,
8594 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8595 struct dwarf2_cu
*cu
)
8598 struct attribute attr
;
8599 int has_low_pc_attr
= 0;
8600 int has_high_pc_attr
= 0;
8602 memset (part_die
, 0, sizeof (struct partial_die_info
));
8604 part_die
->offset
= info_ptr
- buffer
;
8606 info_ptr
+= abbrev_len
;
8611 part_die
->tag
= abbrev
->tag
;
8612 part_die
->has_children
= abbrev
->has_children
;
8614 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8616 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8618 /* Store the data if it is of an attribute we want to keep in a
8619 partial symbol table. */
8623 switch (part_die
->tag
)
8625 case DW_TAG_compile_unit
:
8626 case DW_TAG_type_unit
:
8627 /* Compilation units have a DW_AT_name that is a filename, not
8628 a source language identifier. */
8629 case DW_TAG_enumeration_type
:
8630 case DW_TAG_enumerator
:
8631 /* These tags always have simple identifiers already; no need
8632 to canonicalize them. */
8633 part_die
->name
= DW_STRING (&attr
);
8637 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8638 &cu
->objfile
->objfile_obstack
);
8642 case DW_AT_linkage_name
:
8643 case DW_AT_MIPS_linkage_name
:
8644 /* Note that both forms of linkage name might appear. We
8645 assume they will be the same, and we only store the last
8647 if (cu
->language
== language_ada
)
8648 part_die
->name
= DW_STRING (&attr
);
8651 has_low_pc_attr
= 1;
8652 part_die
->lowpc
= DW_ADDR (&attr
);
8655 has_high_pc_attr
= 1;
8656 part_die
->highpc
= DW_ADDR (&attr
);
8658 case DW_AT_location
:
8659 /* Support the .debug_loc offsets */
8660 if (attr_form_is_block (&attr
))
8662 part_die
->locdesc
= DW_BLOCK (&attr
);
8664 else if (attr_form_is_section_offset (&attr
))
8666 dwarf2_complex_location_expr_complaint ();
8670 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8671 "partial symbol information");
8674 case DW_AT_external
:
8675 part_die
->is_external
= DW_UNSND (&attr
);
8677 case DW_AT_declaration
:
8678 part_die
->is_declaration
= DW_UNSND (&attr
);
8681 part_die
->has_type
= 1;
8683 case DW_AT_abstract_origin
:
8684 case DW_AT_specification
:
8685 case DW_AT_extension
:
8686 part_die
->has_specification
= 1;
8687 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8690 /* Ignore absolute siblings, they might point outside of
8691 the current compile unit. */
8692 if (attr
.form
== DW_FORM_ref_addr
)
8693 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8695 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8697 case DW_AT_byte_size
:
8698 part_die
->has_byte_size
= 1;
8700 case DW_AT_calling_convention
:
8701 /* DWARF doesn't provide a way to identify a program's source-level
8702 entry point. DW_AT_calling_convention attributes are only meant
8703 to describe functions' calling conventions.
8705 However, because it's a necessary piece of information in
8706 Fortran, and because DW_CC_program is the only piece of debugging
8707 information whose definition refers to a 'main program' at all,
8708 several compilers have begun marking Fortran main programs with
8709 DW_CC_program --- even when those functions use the standard
8710 calling conventions.
8712 So until DWARF specifies a way to provide this information and
8713 compilers pick up the new representation, we'll support this
8715 if (DW_UNSND (&attr
) == DW_CC_program
8716 && cu
->language
== language_fortran
)
8717 set_main_name (part_die
->name
);
8724 /* When using the GNU linker, .gnu.linkonce. sections are used to
8725 eliminate duplicate copies of functions and vtables and such.
8726 The linker will arbitrarily choose one and discard the others.
8727 The AT_*_pc values for such functions refer to local labels in
8728 these sections. If the section from that file was discarded, the
8729 labels are not in the output, so the relocs get a value of 0.
8730 If this is a discarded function, mark the pc bounds as invalid,
8731 so that GDB will ignore it. */
8732 if (has_low_pc_attr
&& has_high_pc_attr
8733 && part_die
->lowpc
< part_die
->highpc
8734 && (part_die
->lowpc
!= 0
8735 || dwarf2_per_objfile
->has_section_at_zero
))
8736 part_die
->has_pc_info
= 1;
8741 /* Find a cached partial DIE at OFFSET in CU. */
8743 static struct partial_die_info
*
8744 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8746 struct partial_die_info
*lookup_die
= NULL
;
8747 struct partial_die_info part_die
;
8749 part_die
.offset
= offset
;
8750 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8755 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8756 except in the case of .debug_types DIEs which do not reference
8757 outside their CU (they do however referencing other types via
8760 static struct partial_die_info
*
8761 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8763 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8764 struct partial_die_info
*pd
= NULL
;
8766 if (cu
->per_cu
->from_debug_types
)
8768 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8774 if (offset_in_cu_p (&cu
->header
, offset
))
8776 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8781 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8783 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8784 load_partial_comp_unit (per_cu
, cu
->objfile
);
8786 per_cu
->cu
->last_used
= 0;
8787 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8789 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8791 struct cleanup
*back_to
;
8792 struct partial_die_info comp_unit_die
;
8793 struct abbrev_info
*abbrev
;
8794 unsigned int bytes_read
;
8797 per_cu
->load_all_dies
= 1;
8799 /* Re-read the DIEs. */
8800 back_to
= make_cleanup (null_cleanup
, 0);
8801 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8803 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8804 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8806 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8807 + per_cu
->cu
->header
.offset
8808 + per_cu
->cu
->header
.first_die_offset
);
8809 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8810 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8811 per_cu
->cu
->objfile
->obfd
,
8812 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8814 if (comp_unit_die
.has_children
)
8815 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8816 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8818 do_cleanups (back_to
);
8820 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8826 internal_error (__FILE__
, __LINE__
,
8827 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8828 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8832 /* Adjust PART_DIE before generating a symbol for it. This function
8833 may set the is_external flag or change the DIE's name. */
8836 fixup_partial_die (struct partial_die_info
*part_die
,
8837 struct dwarf2_cu
*cu
)
8839 /* If we found a reference attribute and the DIE has no name, try
8840 to find a name in the referred to DIE. */
8842 if (part_die
->name
== NULL
&& part_die
->has_specification
)
8844 struct partial_die_info
*spec_die
;
8846 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
8848 fixup_partial_die (spec_die
, cu
);
8852 part_die
->name
= spec_die
->name
;
8854 /* Copy DW_AT_external attribute if it is set. */
8855 if (spec_die
->is_external
)
8856 part_die
->is_external
= spec_die
->is_external
;
8860 /* Set default names for some unnamed DIEs. */
8861 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
8862 || part_die
->tag
== DW_TAG_class_type
))
8863 part_die
->name
= "(anonymous class)";
8865 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
8866 part_die
->name
= "(anonymous namespace)";
8868 if (part_die
->tag
== DW_TAG_structure_type
8869 || part_die
->tag
== DW_TAG_class_type
8870 || part_die
->tag
== DW_TAG_union_type
)
8871 guess_structure_name (part_die
, cu
);
8874 /* Read an attribute value described by an attribute form. */
8877 read_attribute_value (struct attribute
*attr
, unsigned form
,
8878 bfd
*abfd
, gdb_byte
*info_ptr
,
8879 struct dwarf2_cu
*cu
)
8881 struct comp_unit_head
*cu_header
= &cu
->header
;
8882 unsigned int bytes_read
;
8883 struct dwarf_block
*blk
;
8888 case DW_FORM_ref_addr
:
8889 if (cu
->header
.version
== 2)
8890 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8892 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8893 info_ptr
+= bytes_read
;
8896 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8897 info_ptr
+= bytes_read
;
8899 case DW_FORM_block2
:
8900 blk
= dwarf_alloc_block (cu
);
8901 blk
->size
= read_2_bytes (abfd
, info_ptr
);
8903 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8904 info_ptr
+= blk
->size
;
8905 DW_BLOCK (attr
) = blk
;
8907 case DW_FORM_block4
:
8908 blk
= dwarf_alloc_block (cu
);
8909 blk
->size
= read_4_bytes (abfd
, info_ptr
);
8911 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8912 info_ptr
+= blk
->size
;
8913 DW_BLOCK (attr
) = blk
;
8916 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
8920 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
8924 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
8927 case DW_FORM_sec_offset
:
8928 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8929 info_ptr
+= bytes_read
;
8931 case DW_FORM_string
:
8932 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
8933 DW_STRING_IS_CANONICAL (attr
) = 0;
8934 info_ptr
+= bytes_read
;
8937 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
8939 DW_STRING_IS_CANONICAL (attr
) = 0;
8940 info_ptr
+= bytes_read
;
8942 case DW_FORM_exprloc
:
8944 blk
= dwarf_alloc_block (cu
);
8945 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8946 info_ptr
+= bytes_read
;
8947 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8948 info_ptr
+= blk
->size
;
8949 DW_BLOCK (attr
) = blk
;
8951 case DW_FORM_block1
:
8952 blk
= dwarf_alloc_block (cu
);
8953 blk
->size
= read_1_byte (abfd
, info_ptr
);
8955 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8956 info_ptr
+= blk
->size
;
8957 DW_BLOCK (attr
) = blk
;
8960 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8964 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8967 case DW_FORM_flag_present
:
8968 DW_UNSND (attr
) = 1;
8971 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
8972 info_ptr
+= bytes_read
;
8975 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8976 info_ptr
+= bytes_read
;
8979 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
8983 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
8987 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
8991 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
8995 /* Convert the signature to something we can record in DW_UNSND
8997 NOTE: This is NULL if the type wasn't found. */
8998 DW_SIGNATURED_TYPE (attr
) =
8999 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9002 case DW_FORM_ref_udata
:
9003 DW_ADDR (attr
) = (cu
->header
.offset
9004 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9005 info_ptr
+= bytes_read
;
9007 case DW_FORM_indirect
:
9008 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9009 info_ptr
+= bytes_read
;
9010 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9013 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9014 dwarf_form_name (form
),
9015 bfd_get_filename (abfd
));
9018 /* We have seen instances where the compiler tried to emit a byte
9019 size attribute of -1 which ended up being encoded as an unsigned
9020 0xffffffff. Although 0xffffffff is technically a valid size value,
9021 an object of this size seems pretty unlikely so we can relatively
9022 safely treat these cases as if the size attribute was invalid and
9023 treat them as zero by default. */
9024 if (attr
->name
== DW_AT_byte_size
9025 && form
== DW_FORM_data4
9026 && DW_UNSND (attr
) >= 0xffffffff)
9029 (&symfile_complaints
,
9030 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9031 hex_string (DW_UNSND (attr
)));
9032 DW_UNSND (attr
) = 0;
9038 /* Read an attribute described by an abbreviated attribute. */
9041 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9042 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9044 attr
->name
= abbrev
->name
;
9045 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9048 /* read dwarf information from a buffer */
9051 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9053 return bfd_get_8 (abfd
, buf
);
9057 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9059 return bfd_get_signed_8 (abfd
, buf
);
9063 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9065 return bfd_get_16 (abfd
, buf
);
9069 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9071 return bfd_get_signed_16 (abfd
, buf
);
9075 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9077 return bfd_get_32 (abfd
, buf
);
9081 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9083 return bfd_get_signed_32 (abfd
, buf
);
9087 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9089 return bfd_get_64 (abfd
, buf
);
9093 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9094 unsigned int *bytes_read
)
9096 struct comp_unit_head
*cu_header
= &cu
->header
;
9097 CORE_ADDR retval
= 0;
9099 if (cu_header
->signed_addr_p
)
9101 switch (cu_header
->addr_size
)
9104 retval
= bfd_get_signed_16 (abfd
, buf
);
9107 retval
= bfd_get_signed_32 (abfd
, buf
);
9110 retval
= bfd_get_signed_64 (abfd
, buf
);
9113 internal_error (__FILE__
, __LINE__
,
9114 _("read_address: bad switch, signed [in module %s]"),
9115 bfd_get_filename (abfd
));
9120 switch (cu_header
->addr_size
)
9123 retval
= bfd_get_16 (abfd
, buf
);
9126 retval
= bfd_get_32 (abfd
, buf
);
9129 retval
= bfd_get_64 (abfd
, buf
);
9132 internal_error (__FILE__
, __LINE__
,
9133 _("read_address: bad switch, unsigned [in module %s]"),
9134 bfd_get_filename (abfd
));
9138 *bytes_read
= cu_header
->addr_size
;
9142 /* Read the initial length from a section. The (draft) DWARF 3
9143 specification allows the initial length to take up either 4 bytes
9144 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9145 bytes describe the length and all offsets will be 8 bytes in length
9148 An older, non-standard 64-bit format is also handled by this
9149 function. The older format in question stores the initial length
9150 as an 8-byte quantity without an escape value. Lengths greater
9151 than 2^32 aren't very common which means that the initial 4 bytes
9152 is almost always zero. Since a length value of zero doesn't make
9153 sense for the 32-bit format, this initial zero can be considered to
9154 be an escape value which indicates the presence of the older 64-bit
9155 format. As written, the code can't detect (old format) lengths
9156 greater than 4GB. If it becomes necessary to handle lengths
9157 somewhat larger than 4GB, we could allow other small values (such
9158 as the non-sensical values of 1, 2, and 3) to also be used as
9159 escape values indicating the presence of the old format.
9161 The value returned via bytes_read should be used to increment the
9162 relevant pointer after calling read_initial_length().
9164 [ Note: read_initial_length() and read_offset() are based on the
9165 document entitled "DWARF Debugging Information Format", revision
9166 3, draft 8, dated November 19, 2001. This document was obtained
9169 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9171 This document is only a draft and is subject to change. (So beware.)
9173 Details regarding the older, non-standard 64-bit format were
9174 determined empirically by examining 64-bit ELF files produced by
9175 the SGI toolchain on an IRIX 6.5 machine.
9177 - Kevin, July 16, 2002
9181 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9183 LONGEST length
= bfd_get_32 (abfd
, buf
);
9185 if (length
== 0xffffffff)
9187 length
= bfd_get_64 (abfd
, buf
+ 4);
9190 else if (length
== 0)
9192 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9193 length
= bfd_get_64 (abfd
, buf
);
9204 /* Cover function for read_initial_length.
9205 Returns the length of the object at BUF, and stores the size of the
9206 initial length in *BYTES_READ and stores the size that offsets will be in
9208 If the initial length size is not equivalent to that specified in
9209 CU_HEADER then issue a complaint.
9210 This is useful when reading non-comp-unit headers. */
9213 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9214 const struct comp_unit_head
*cu_header
,
9215 unsigned int *bytes_read
,
9216 unsigned int *offset_size
)
9218 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9220 gdb_assert (cu_header
->initial_length_size
== 4
9221 || cu_header
->initial_length_size
== 8
9222 || cu_header
->initial_length_size
== 12);
9224 if (cu_header
->initial_length_size
!= *bytes_read
)
9225 complaint (&symfile_complaints
,
9226 _("intermixed 32-bit and 64-bit DWARF sections"));
9228 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9232 /* Read an offset from the data stream. The size of the offset is
9233 given by cu_header->offset_size. */
9236 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9237 unsigned int *bytes_read
)
9239 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9241 *bytes_read
= cu_header
->offset_size
;
9245 /* Read an offset from the data stream. */
9248 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9252 switch (offset_size
)
9255 retval
= bfd_get_32 (abfd
, buf
);
9258 retval
= bfd_get_64 (abfd
, buf
);
9261 internal_error (__FILE__
, __LINE__
,
9262 _("read_offset_1: bad switch [in module %s]"),
9263 bfd_get_filename (abfd
));
9270 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9272 /* If the size of a host char is 8 bits, we can return a pointer
9273 to the buffer, otherwise we have to copy the data to a buffer
9274 allocated on the temporary obstack. */
9275 gdb_assert (HOST_CHAR_BIT
== 8);
9280 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9282 /* If the size of a host char is 8 bits, we can return a pointer
9283 to the string, otherwise we have to copy the string to a buffer
9284 allocated on the temporary obstack. */
9285 gdb_assert (HOST_CHAR_BIT
== 8);
9288 *bytes_read_ptr
= 1;
9291 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9292 return (char *) buf
;
9296 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9297 const struct comp_unit_head
*cu_header
,
9298 unsigned int *bytes_read_ptr
)
9300 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9302 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9303 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9305 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9306 bfd_get_filename (abfd
));
9309 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9311 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9312 bfd_get_filename (abfd
));
9315 gdb_assert (HOST_CHAR_BIT
== 8);
9316 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9318 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9321 static unsigned long
9322 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9324 unsigned long result
;
9325 unsigned int num_read
;
9335 byte
= bfd_get_8 (abfd
, buf
);
9338 result
|= ((unsigned long)(byte
& 127) << shift
);
9339 if ((byte
& 128) == 0)
9345 *bytes_read_ptr
= num_read
;
9350 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9353 int i
, shift
, num_read
;
9362 byte
= bfd_get_8 (abfd
, buf
);
9365 result
|= ((long)(byte
& 127) << shift
);
9367 if ((byte
& 128) == 0)
9372 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9373 result
|= -(((long)1) << shift
);
9374 *bytes_read_ptr
= num_read
;
9378 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9381 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9387 byte
= bfd_get_8 (abfd
, buf
);
9389 if ((byte
& 128) == 0)
9395 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9402 cu
->language
= language_c
;
9404 case DW_LANG_C_plus_plus
:
9405 cu
->language
= language_cplus
;
9408 cu
->language
= language_d
;
9410 case DW_LANG_Fortran77
:
9411 case DW_LANG_Fortran90
:
9412 case DW_LANG_Fortran95
:
9413 cu
->language
= language_fortran
;
9415 case DW_LANG_Mips_Assembler
:
9416 cu
->language
= language_asm
;
9419 cu
->language
= language_java
;
9423 cu
->language
= language_ada
;
9425 case DW_LANG_Modula2
:
9426 cu
->language
= language_m2
;
9428 case DW_LANG_Pascal83
:
9429 cu
->language
= language_pascal
;
9432 cu
->language
= language_objc
;
9434 case DW_LANG_Cobol74
:
9435 case DW_LANG_Cobol85
:
9437 cu
->language
= language_minimal
;
9440 cu
->language_defn
= language_def (cu
->language
);
9443 /* Return the named attribute or NULL if not there. */
9445 static struct attribute
*
9446 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9449 struct attribute
*spec
= NULL
;
9451 for (i
= 0; i
< die
->num_attrs
; ++i
)
9453 if (die
->attrs
[i
].name
== name
)
9454 return &die
->attrs
[i
];
9455 if (die
->attrs
[i
].name
== DW_AT_specification
9456 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9457 spec
= &die
->attrs
[i
];
9462 die
= follow_die_ref (die
, spec
, &cu
);
9463 return dwarf2_attr (die
, name
, cu
);
9469 /* Return the named attribute or NULL if not there,
9470 but do not follow DW_AT_specification, etc.
9471 This is for use in contexts where we're reading .debug_types dies.
9472 Following DW_AT_specification, DW_AT_abstract_origin will take us
9473 back up the chain, and we want to go down. */
9475 static struct attribute
*
9476 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9477 struct dwarf2_cu
*cu
)
9481 for (i
= 0; i
< die
->num_attrs
; ++i
)
9482 if (die
->attrs
[i
].name
== name
)
9483 return &die
->attrs
[i
];
9488 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9489 and holds a non-zero value. This function should only be used for
9490 DW_FORM_flag or DW_FORM_flag_present attributes. */
9493 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9495 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9497 return (attr
&& DW_UNSND (attr
));
9501 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9503 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9504 which value is non-zero. However, we have to be careful with
9505 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9506 (via dwarf2_flag_true_p) follows this attribute. So we may
9507 end up accidently finding a declaration attribute that belongs
9508 to a different DIE referenced by the specification attribute,
9509 even though the given DIE does not have a declaration attribute. */
9510 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9511 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9514 /* Return the die giving the specification for DIE, if there is
9515 one. *SPEC_CU is the CU containing DIE on input, and the CU
9516 containing the return value on output. If there is no
9517 specification, but there is an abstract origin, that is
9520 static struct die_info
*
9521 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9523 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9526 if (spec_attr
== NULL
)
9527 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9529 if (spec_attr
== NULL
)
9532 return follow_die_ref (die
, spec_attr
, spec_cu
);
9535 /* Free the line_header structure *LH, and any arrays and strings it
9538 free_line_header (struct line_header
*lh
)
9540 if (lh
->standard_opcode_lengths
)
9541 xfree (lh
->standard_opcode_lengths
);
9543 /* Remember that all the lh->file_names[i].name pointers are
9544 pointers into debug_line_buffer, and don't need to be freed. */
9546 xfree (lh
->file_names
);
9548 /* Similarly for the include directory names. */
9549 if (lh
->include_dirs
)
9550 xfree (lh
->include_dirs
);
9556 /* Add an entry to LH's include directory table. */
9558 add_include_dir (struct line_header
*lh
, char *include_dir
)
9560 /* Grow the array if necessary. */
9561 if (lh
->include_dirs_size
== 0)
9563 lh
->include_dirs_size
= 1; /* for testing */
9564 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9565 * sizeof (*lh
->include_dirs
));
9567 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9569 lh
->include_dirs_size
*= 2;
9570 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9571 (lh
->include_dirs_size
9572 * sizeof (*lh
->include_dirs
)));
9575 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9579 /* Add an entry to LH's file name table. */
9581 add_file_name (struct line_header
*lh
,
9583 unsigned int dir_index
,
9584 unsigned int mod_time
,
9585 unsigned int length
)
9587 struct file_entry
*fe
;
9589 /* Grow the array if necessary. */
9590 if (lh
->file_names_size
== 0)
9592 lh
->file_names_size
= 1; /* for testing */
9593 lh
->file_names
= xmalloc (lh
->file_names_size
9594 * sizeof (*lh
->file_names
));
9596 else if (lh
->num_file_names
>= lh
->file_names_size
)
9598 lh
->file_names_size
*= 2;
9599 lh
->file_names
= xrealloc (lh
->file_names
,
9600 (lh
->file_names_size
9601 * sizeof (*lh
->file_names
)));
9604 fe
= &lh
->file_names
[lh
->num_file_names
++];
9606 fe
->dir_index
= dir_index
;
9607 fe
->mod_time
= mod_time
;
9608 fe
->length
= length
;
9614 /* Read the statement program header starting at OFFSET in
9615 .debug_line, according to the endianness of ABFD. Return a pointer
9616 to a struct line_header, allocated using xmalloc.
9618 NOTE: the strings in the include directory and file name tables of
9619 the returned object point into debug_line_buffer, and must not be
9621 static struct line_header
*
9622 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9623 struct dwarf2_cu
*cu
)
9625 struct cleanup
*back_to
;
9626 struct line_header
*lh
;
9628 unsigned int bytes_read
, offset_size
;
9630 char *cur_dir
, *cur_file
;
9632 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9633 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9635 complaint (&symfile_complaints
, _("missing .debug_line section"));
9639 /* Make sure that at least there's room for the total_length field.
9640 That could be 12 bytes long, but we're just going to fudge that. */
9641 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9643 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9647 lh
= xmalloc (sizeof (*lh
));
9648 memset (lh
, 0, sizeof (*lh
));
9649 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9652 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9654 /* Read in the header. */
9656 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9657 &bytes_read
, &offset_size
);
9658 line_ptr
+= bytes_read
;
9659 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9660 + dwarf2_per_objfile
->line
.size
))
9662 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9665 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9666 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9668 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9669 line_ptr
+= offset_size
;
9670 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9672 if (lh
->version
>= 4)
9674 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9678 lh
->maximum_ops_per_instruction
= 1;
9680 if (lh
->maximum_ops_per_instruction
== 0)
9682 lh
->maximum_ops_per_instruction
= 1;
9683 complaint (&symfile_complaints
,
9684 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9687 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9689 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9691 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9693 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9695 lh
->standard_opcode_lengths
9696 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9698 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9699 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9701 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9705 /* Read directory table. */
9706 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9708 line_ptr
+= bytes_read
;
9709 add_include_dir (lh
, cur_dir
);
9711 line_ptr
+= bytes_read
;
9713 /* Read file name table. */
9714 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9716 unsigned int dir_index
, mod_time
, length
;
9718 line_ptr
+= bytes_read
;
9719 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9720 line_ptr
+= bytes_read
;
9721 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9722 line_ptr
+= bytes_read
;
9723 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9724 line_ptr
+= bytes_read
;
9726 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9728 line_ptr
+= bytes_read
;
9729 lh
->statement_program_start
= line_ptr
;
9731 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9732 + dwarf2_per_objfile
->line
.size
))
9733 complaint (&symfile_complaints
,
9734 _("line number info header doesn't fit in `.debug_line' section"));
9736 discard_cleanups (back_to
);
9740 /* This function exists to work around a bug in certain compilers
9741 (particularly GCC 2.95), in which the first line number marker of a
9742 function does not show up until after the prologue, right before
9743 the second line number marker. This function shifts ADDRESS down
9744 to the beginning of the function if necessary, and is called on
9745 addresses passed to record_line. */
9748 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9750 struct function_range
*fn
;
9752 /* Find the function_range containing address. */
9757 cu
->cached_fn
= cu
->first_fn
;
9761 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9767 while (fn
&& fn
!= cu
->cached_fn
)
9768 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9778 if (address
!= fn
->lowpc
)
9779 complaint (&symfile_complaints
,
9780 _("misplaced first line number at 0x%lx for '%s'"),
9781 (unsigned long) address
, fn
->name
);
9786 /* Decode the Line Number Program (LNP) for the given line_header
9787 structure and CU. The actual information extracted and the type
9788 of structures created from the LNP depends on the value of PST.
9790 1. If PST is NULL, then this procedure uses the data from the program
9791 to create all necessary symbol tables, and their linetables.
9792 The compilation directory of the file is passed in COMP_DIR,
9793 and must not be NULL.
9795 2. If PST is not NULL, this procedure reads the program to determine
9796 the list of files included by the unit represented by PST, and
9797 builds all the associated partial symbol tables. In this case,
9798 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9799 is not used to compute the full name of the symtab, and therefore
9800 omitting it when building the partial symtab does not introduce
9801 the potential for inconsistency - a partial symtab and its associated
9802 symbtab having a different fullname -). */
9805 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
9806 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
9808 gdb_byte
*line_ptr
, *extended_end
;
9810 unsigned int bytes_read
, extended_len
;
9811 unsigned char op_code
, extended_op
, adj_opcode
;
9813 struct objfile
*objfile
= cu
->objfile
;
9814 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9815 const int decode_for_pst_p
= (pst
!= NULL
);
9816 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
9818 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9820 line_ptr
= lh
->statement_program_start
;
9821 line_end
= lh
->statement_program_end
;
9823 /* Read the statement sequences until there's nothing left. */
9824 while (line_ptr
< line_end
)
9826 /* state machine registers */
9827 CORE_ADDR address
= 0;
9828 unsigned int file
= 1;
9829 unsigned int line
= 1;
9830 unsigned int column
= 0;
9831 int is_stmt
= lh
->default_is_stmt
;
9832 int basic_block
= 0;
9833 int end_sequence
= 0;
9835 unsigned char op_index
= 0;
9837 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
9839 /* Start a subfile for the current file of the state machine. */
9840 /* lh->include_dirs and lh->file_names are 0-based, but the
9841 directory and file name numbers in the statement program
9843 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9847 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9849 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9852 /* Decode the table. */
9853 while (!end_sequence
)
9855 op_code
= read_1_byte (abfd
, line_ptr
);
9857 if (line_ptr
> line_end
)
9859 dwarf2_debug_line_missing_end_sequence_complaint ();
9863 if (op_code
>= lh
->opcode_base
)
9865 /* Special operand. */
9866 adj_opcode
= op_code
- lh
->opcode_base
;
9867 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
9868 / lh
->maximum_ops_per_instruction
)
9869 * lh
->minimum_instruction_length
);
9870 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
9871 % lh
->maximum_ops_per_instruction
);
9872 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
9873 if (lh
->num_file_names
< file
|| file
== 0)
9874 dwarf2_debug_line_missing_file_complaint ();
9875 /* For now we ignore lines not starting on an
9876 instruction boundary. */
9877 else if (op_index
== 0)
9879 lh
->file_names
[file
- 1].included_p
= 1;
9880 if (!decode_for_pst_p
&& is_stmt
)
9882 if (last_subfile
!= current_subfile
)
9884 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9886 record_line (last_subfile
, 0, addr
);
9887 last_subfile
= current_subfile
;
9889 /* Append row to matrix using current values. */
9890 addr
= check_cu_functions (address
, cu
);
9891 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9892 record_line (current_subfile
, line
, addr
);
9897 else switch (op_code
)
9899 case DW_LNS_extended_op
:
9900 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9901 line_ptr
+= bytes_read
;
9902 extended_end
= line_ptr
+ extended_len
;
9903 extended_op
= read_1_byte (abfd
, line_ptr
);
9905 switch (extended_op
)
9907 case DW_LNE_end_sequence
:
9910 case DW_LNE_set_address
:
9911 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
9913 line_ptr
+= bytes_read
;
9914 address
+= baseaddr
;
9916 case DW_LNE_define_file
:
9919 unsigned int dir_index
, mod_time
, length
;
9921 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
9922 line_ptr
+= bytes_read
;
9924 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9925 line_ptr
+= bytes_read
;
9927 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9928 line_ptr
+= bytes_read
;
9930 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9931 line_ptr
+= bytes_read
;
9932 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9935 case DW_LNE_set_discriminator
:
9936 /* The discriminator is not interesting to the debugger;
9938 line_ptr
= extended_end
;
9941 complaint (&symfile_complaints
,
9942 _("mangled .debug_line section"));
9945 /* Make sure that we parsed the extended op correctly. If e.g.
9946 we expected a different address size than the producer used,
9947 we may have read the wrong number of bytes. */
9948 if (line_ptr
!= extended_end
)
9950 complaint (&symfile_complaints
,
9951 _("mangled .debug_line section"));
9956 if (lh
->num_file_names
< file
|| file
== 0)
9957 dwarf2_debug_line_missing_file_complaint ();
9960 lh
->file_names
[file
- 1].included_p
= 1;
9961 if (!decode_for_pst_p
&& is_stmt
)
9963 if (last_subfile
!= current_subfile
)
9965 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9967 record_line (last_subfile
, 0, addr
);
9968 last_subfile
= current_subfile
;
9970 addr
= check_cu_functions (address
, cu
);
9971 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9972 record_line (current_subfile
, line
, addr
);
9977 case DW_LNS_advance_pc
:
9980 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9982 address
+= (((op_index
+ adjust
)
9983 / lh
->maximum_ops_per_instruction
)
9984 * lh
->minimum_instruction_length
);
9985 op_index
= ((op_index
+ adjust
)
9986 % lh
->maximum_ops_per_instruction
);
9987 line_ptr
+= bytes_read
;
9990 case DW_LNS_advance_line
:
9991 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
9992 line_ptr
+= bytes_read
;
9994 case DW_LNS_set_file
:
9996 /* The arrays lh->include_dirs and lh->file_names are
9997 0-based, but the directory and file name numbers in
9998 the statement program are 1-based. */
9999 struct file_entry
*fe
;
10002 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10003 line_ptr
+= bytes_read
;
10004 if (lh
->num_file_names
< file
|| file
== 0)
10005 dwarf2_debug_line_missing_file_complaint ();
10008 fe
= &lh
->file_names
[file
- 1];
10010 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10011 if (!decode_for_pst_p
)
10013 last_subfile
= current_subfile
;
10014 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10019 case DW_LNS_set_column
:
10020 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10021 line_ptr
+= bytes_read
;
10023 case DW_LNS_negate_stmt
:
10024 is_stmt
= (!is_stmt
);
10026 case DW_LNS_set_basic_block
:
10029 /* Add to the address register of the state machine the
10030 address increment value corresponding to special opcode
10031 255. I.e., this value is scaled by the minimum
10032 instruction length since special opcode 255 would have
10033 scaled the the increment. */
10034 case DW_LNS_const_add_pc
:
10036 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10038 address
+= (((op_index
+ adjust
)
10039 / lh
->maximum_ops_per_instruction
)
10040 * lh
->minimum_instruction_length
);
10041 op_index
= ((op_index
+ adjust
)
10042 % lh
->maximum_ops_per_instruction
);
10045 case DW_LNS_fixed_advance_pc
:
10046 address
+= read_2_bytes (abfd
, line_ptr
);
10052 /* Unknown standard opcode, ignore it. */
10055 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10057 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10058 line_ptr
+= bytes_read
;
10063 if (lh
->num_file_names
< file
|| file
== 0)
10064 dwarf2_debug_line_missing_file_complaint ();
10067 lh
->file_names
[file
- 1].included_p
= 1;
10068 if (!decode_for_pst_p
)
10070 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10071 record_line (current_subfile
, 0, addr
);
10076 if (decode_for_pst_p
)
10080 /* Now that we're done scanning the Line Header Program, we can
10081 create the psymtab of each included file. */
10082 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10083 if (lh
->file_names
[file_index
].included_p
== 1)
10085 const struct file_entry fe
= lh
->file_names
[file_index
];
10086 char *include_name
= fe
.name
;
10087 char *dir_name
= NULL
;
10088 char *pst_filename
= pst
->filename
;
10091 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10093 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
10095 include_name
= concat (dir_name
, SLASH_STRING
,
10096 include_name
, (char *)NULL
);
10097 make_cleanup (xfree
, include_name
);
10100 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10102 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
10103 pst_filename
, (char *)NULL
);
10104 make_cleanup (xfree
, pst_filename
);
10107 if (strcmp (include_name
, pst_filename
) != 0)
10108 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10113 /* Make sure a symtab is created for every file, even files
10114 which contain only variables (i.e. no code with associated
10118 struct file_entry
*fe
;
10120 for (i
= 0; i
< lh
->num_file_names
; i
++)
10124 fe
= &lh
->file_names
[i
];
10126 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10127 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10129 /* Skip the main file; we don't need it, and it must be
10130 allocated last, so that it will show up before the
10131 non-primary symtabs in the objfile's symtab list. */
10132 if (current_subfile
== first_subfile
)
10135 if (current_subfile
->symtab
== NULL
)
10136 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10138 fe
->symtab
= current_subfile
->symtab
;
10143 /* Start a subfile for DWARF. FILENAME is the name of the file and
10144 DIRNAME the name of the source directory which contains FILENAME
10145 or NULL if not known. COMP_DIR is the compilation directory for the
10146 linetable's compilation unit or NULL if not known.
10147 This routine tries to keep line numbers from identical absolute and
10148 relative file names in a common subfile.
10150 Using the `list' example from the GDB testsuite, which resides in
10151 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10152 of /srcdir/list0.c yields the following debugging information for list0.c:
10154 DW_AT_name: /srcdir/list0.c
10155 DW_AT_comp_dir: /compdir
10156 files.files[0].name: list0.h
10157 files.files[0].dir: /srcdir
10158 files.files[1].name: list0.c
10159 files.files[1].dir: /srcdir
10161 The line number information for list0.c has to end up in a single
10162 subfile, so that `break /srcdir/list0.c:1' works as expected.
10163 start_subfile will ensure that this happens provided that we pass the
10164 concatenation of files.files[1].dir and files.files[1].name as the
10168 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
10172 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10173 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10174 second argument to start_subfile. To be consistent, we do the
10175 same here. In order not to lose the line information directory,
10176 we concatenate it to the filename when it makes sense.
10177 Note that the Dwarf3 standard says (speaking of filenames in line
10178 information): ``The directory index is ignored for file names
10179 that represent full path names''. Thus ignoring dirname in the
10180 `else' branch below isn't an issue. */
10182 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10183 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10185 fullname
= filename
;
10187 start_subfile (fullname
, comp_dir
);
10189 if (fullname
!= filename
)
10194 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10195 struct dwarf2_cu
*cu
)
10197 struct objfile
*objfile
= cu
->objfile
;
10198 struct comp_unit_head
*cu_header
= &cu
->header
;
10200 /* NOTE drow/2003-01-30: There used to be a comment and some special
10201 code here to turn a symbol with DW_AT_external and a
10202 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10203 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10204 with some versions of binutils) where shared libraries could have
10205 relocations against symbols in their debug information - the
10206 minimal symbol would have the right address, but the debug info
10207 would not. It's no longer necessary, because we will explicitly
10208 apply relocations when we read in the debug information now. */
10210 /* A DW_AT_location attribute with no contents indicates that a
10211 variable has been optimized away. */
10212 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10214 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10218 /* Handle one degenerate form of location expression specially, to
10219 preserve GDB's previous behavior when section offsets are
10220 specified. If this is just a DW_OP_addr then mark this symbol
10223 if (attr_form_is_block (attr
)
10224 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10225 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10227 unsigned int dummy
;
10229 SYMBOL_VALUE_ADDRESS (sym
) =
10230 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10231 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10232 fixup_symbol_section (sym
, objfile
);
10233 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10234 SYMBOL_SECTION (sym
));
10238 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10239 expression evaluator, and use LOC_COMPUTED only when necessary
10240 (i.e. when the value of a register or memory location is
10241 referenced, or a thread-local block, etc.). Then again, it might
10242 not be worthwhile. I'm assuming that it isn't unless performance
10243 or memory numbers show me otherwise. */
10245 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10246 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10249 /* Given a pointer to a DWARF information entry, figure out if we need
10250 to make a symbol table entry for it, and if so, create a new entry
10251 and return a pointer to it.
10252 If TYPE is NULL, determine symbol type from the die, otherwise
10253 used the passed type.
10254 If SPACE is not NULL, use it to hold the new symbol. If it is
10255 NULL, allocate a new symbol on the objfile's obstack. */
10257 static struct symbol
*
10258 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10259 struct symbol
*space
)
10261 struct objfile
*objfile
= cu
->objfile
;
10262 struct symbol
*sym
= NULL
;
10264 struct attribute
*attr
= NULL
;
10265 struct attribute
*attr2
= NULL
;
10266 CORE_ADDR baseaddr
;
10267 struct pending
**list_to_add
= NULL
;
10269 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10271 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10273 name
= dwarf2_name (die
, cu
);
10276 const char *linkagename
;
10277 int suppress_add
= 0;
10282 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10283 OBJSTAT (objfile
, n_syms
++);
10285 /* Cache this symbol's name and the name's demangled form (if any). */
10286 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10287 linkagename
= dwarf2_physname (name
, die
, cu
);
10288 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10290 /* Fortran does not have mangling standard and the mangling does differ
10291 between gfortran, iFort etc. */
10292 if (cu
->language
== language_fortran
10293 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10294 symbol_set_demangled_name (&(sym
->ginfo
),
10295 (char *) dwarf2_full_name (name
, die
, cu
),
10298 /* Default assumptions.
10299 Use the passed type or decode it from the die. */
10300 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10301 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10303 SYMBOL_TYPE (sym
) = type
;
10305 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10306 attr
= dwarf2_attr (die
,
10307 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10311 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10314 attr
= dwarf2_attr (die
,
10315 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10319 int file_index
= DW_UNSND (attr
);
10321 if (cu
->line_header
== NULL
10322 || file_index
> cu
->line_header
->num_file_names
)
10323 complaint (&symfile_complaints
,
10324 _("file index out of range"));
10325 else if (file_index
> 0)
10327 struct file_entry
*fe
;
10329 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10330 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10337 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10340 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10342 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10343 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10344 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10345 add_symbol_to_list (sym
, cu
->list_in_scope
);
10347 case DW_TAG_subprogram
:
10348 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10350 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10351 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10352 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10353 || cu
->language
== language_ada
)
10355 /* Subprograms marked external are stored as a global symbol.
10356 Ada subprograms, whether marked external or not, are always
10357 stored as a global symbol, because we want to be able to
10358 access them globally. For instance, we want to be able
10359 to break on a nested subprogram without having to
10360 specify the context. */
10361 list_to_add
= &global_symbols
;
10365 list_to_add
= cu
->list_in_scope
;
10368 case DW_TAG_inlined_subroutine
:
10369 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10371 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10372 SYMBOL_INLINED (sym
) = 1;
10373 /* Do not add the symbol to any lists. It will be found via
10374 BLOCK_FUNCTION from the blockvector. */
10376 case DW_TAG_template_value_param
:
10378 /* Fall through. */
10379 case DW_TAG_variable
:
10380 case DW_TAG_member
:
10381 /* Compilation with minimal debug info may result in variables
10382 with missing type entries. Change the misleading `void' type
10383 to something sensible. */
10384 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10386 = objfile_type (objfile
)->nodebug_data_symbol
;
10388 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10389 /* In the case of DW_TAG_member, we should only be called for
10390 static const members. */
10391 if (die
->tag
== DW_TAG_member
)
10393 /* dwarf2_add_field uses die_is_declaration,
10394 so we do the same. */
10395 gdb_assert (die_is_declaration (die
, cu
));
10400 dwarf2_const_value (attr
, sym
, cu
);
10401 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10404 if (attr2
&& (DW_UNSND (attr2
) != 0))
10405 list_to_add
= &global_symbols
;
10407 list_to_add
= cu
->list_in_scope
;
10411 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10414 var_decode_location (attr
, sym
, cu
);
10415 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10416 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10417 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10418 && !dwarf2_per_objfile
->has_section_at_zero
)
10420 /* When a static variable is eliminated by the linker,
10421 the corresponding debug information is not stripped
10422 out, but the variable address is set to null;
10423 do not add such variables into symbol table. */
10425 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10427 /* Workaround gfortran PR debug/40040 - it uses
10428 DW_AT_location for variables in -fPIC libraries which may
10429 get overriden by other libraries/executable and get
10430 a different address. Resolve it by the minimal symbol
10431 which may come from inferior's executable using copy
10432 relocation. Make this workaround only for gfortran as for
10433 other compilers GDB cannot guess the minimal symbol
10434 Fortran mangling kind. */
10435 if (cu
->language
== language_fortran
&& die
->parent
10436 && die
->parent
->tag
== DW_TAG_module
10438 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10439 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10441 /* A variable with DW_AT_external is never static,
10442 but it may be block-scoped. */
10443 list_to_add
= (cu
->list_in_scope
== &file_symbols
10444 ? &global_symbols
: cu
->list_in_scope
);
10447 list_to_add
= cu
->list_in_scope
;
10451 /* We do not know the address of this symbol.
10452 If it is an external symbol and we have type information
10453 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10454 The address of the variable will then be determined from
10455 the minimal symbol table whenever the variable is
10457 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10458 if (attr2
&& (DW_UNSND (attr2
) != 0)
10459 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10461 /* A variable with DW_AT_external is never static, but it
10462 may be block-scoped. */
10463 list_to_add
= (cu
->list_in_scope
== &file_symbols
10464 ? &global_symbols
: cu
->list_in_scope
);
10466 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10468 else if (!die_is_declaration (die
, cu
))
10470 /* Use the default LOC_OPTIMIZED_OUT class. */
10471 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10473 list_to_add
= cu
->list_in_scope
;
10477 case DW_TAG_formal_parameter
:
10478 /* If we are inside a function, mark this as an argument. If
10479 not, we might be looking at an argument to an inlined function
10480 when we do not have enough information to show inlined frames;
10481 pretend it's a local variable in that case so that the user can
10483 if (context_stack_depth
> 0
10484 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10485 SYMBOL_IS_ARGUMENT (sym
) = 1;
10486 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10489 var_decode_location (attr
, sym
, cu
);
10491 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10494 dwarf2_const_value (attr
, sym
, cu
);
10496 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10497 if (attr
&& DW_UNSND (attr
))
10499 struct type
*ref_type
;
10501 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10502 SYMBOL_TYPE (sym
) = ref_type
;
10505 list_to_add
= cu
->list_in_scope
;
10507 case DW_TAG_unspecified_parameters
:
10508 /* From varargs functions; gdb doesn't seem to have any
10509 interest in this information, so just ignore it for now.
10512 case DW_TAG_template_type_param
:
10514 /* Fall through. */
10515 case DW_TAG_class_type
:
10516 case DW_TAG_interface_type
:
10517 case DW_TAG_structure_type
:
10518 case DW_TAG_union_type
:
10519 case DW_TAG_set_type
:
10520 case DW_TAG_enumeration_type
:
10521 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10522 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10525 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10526 really ever be static objects: otherwise, if you try
10527 to, say, break of a class's method and you're in a file
10528 which doesn't mention that class, it won't work unless
10529 the check for all static symbols in lookup_symbol_aux
10530 saves you. See the OtherFileClass tests in
10531 gdb.c++/namespace.exp. */
10535 list_to_add
= (cu
->list_in_scope
== &file_symbols
10536 && (cu
->language
== language_cplus
10537 || cu
->language
== language_java
)
10538 ? &global_symbols
: cu
->list_in_scope
);
10541 /* The semantics of C++ state that "struct foo { ... }" also
10542 defines a typedef for "foo". A Java class declaration also
10543 defines a typedef for the class. */
10544 if (cu
->language
== language_cplus
10545 || cu
->language
== language_java
10546 || cu
->language
== language_ada
)
10548 /* The symbol's name is already allocated along with
10549 this objfile, so we don't need to duplicate it for
10551 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10552 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10556 case DW_TAG_typedef
:
10557 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10558 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10559 list_to_add
= cu
->list_in_scope
;
10561 case DW_TAG_base_type
:
10562 case DW_TAG_subrange_type
:
10563 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10564 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10565 list_to_add
= cu
->list_in_scope
;
10567 case DW_TAG_enumerator
:
10568 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10571 dwarf2_const_value (attr
, sym
, cu
);
10574 /* NOTE: carlton/2003-11-10: See comment above in the
10575 DW_TAG_class_type, etc. block. */
10577 list_to_add
= (cu
->list_in_scope
== &file_symbols
10578 && (cu
->language
== language_cplus
10579 || cu
->language
== language_java
)
10580 ? &global_symbols
: cu
->list_in_scope
);
10583 case DW_TAG_namespace
:
10584 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10585 list_to_add
= &global_symbols
;
10588 /* Not a tag we recognize. Hopefully we aren't processing
10589 trash data, but since we must specifically ignore things
10590 we don't recognize, there is nothing else we should do at
10592 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10593 dwarf_tag_name (die
->tag
));
10599 sym
->hash_next
= objfile
->template_symbols
;
10600 objfile
->template_symbols
= sym
;
10601 list_to_add
= NULL
;
10604 if (list_to_add
!= NULL
)
10605 add_symbol_to_list (sym
, list_to_add
);
10607 /* For the benefit of old versions of GCC, check for anonymous
10608 namespaces based on the demangled name. */
10609 if (!processing_has_namespace_info
10610 && cu
->language
== language_cplus
)
10611 cp_scan_for_anonymous_namespaces (sym
);
10616 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10618 static struct symbol
*
10619 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10621 return new_symbol_full (die
, type
, cu
, NULL
);
10624 /* Given an attr with a DW_FORM_dataN value in host byte order,
10625 zero-extend it as appropriate for the symbol's type. The DWARF
10626 standard (v4) is not entirely clear about the meaning of using
10627 DW_FORM_dataN for a constant with a signed type, where the type is
10628 wider than the data. The conclusion of a discussion on the DWARF
10629 list was that this is unspecified. We choose to always zero-extend
10630 because that is the interpretation long in use by GCC. */
10633 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10634 const char *name
, struct obstack
*obstack
,
10635 struct dwarf2_cu
*cu
, long *value
, int bits
)
10637 struct objfile
*objfile
= cu
->objfile
;
10638 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10639 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10640 LONGEST l
= DW_UNSND (attr
);
10642 if (bits
< sizeof (*value
) * 8)
10644 l
&= ((LONGEST
) 1 << bits
) - 1;
10647 else if (bits
== sizeof (*value
) * 8)
10651 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10652 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10659 /* Read a constant value from an attribute. Either set *VALUE, or if
10660 the value does not fit in *VALUE, set *BYTES - either already
10661 allocated on the objfile obstack, or newly allocated on OBSTACK,
10662 or, set *BATON, if we translated the constant to a location
10666 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10667 const char *name
, struct obstack
*obstack
,
10668 struct dwarf2_cu
*cu
,
10669 long *value
, gdb_byte
**bytes
,
10670 struct dwarf2_locexpr_baton
**baton
)
10672 struct objfile
*objfile
= cu
->objfile
;
10673 struct comp_unit_head
*cu_header
= &cu
->header
;
10674 struct dwarf_block
*blk
;
10675 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10676 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10682 switch (attr
->form
)
10688 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10689 dwarf2_const_value_length_mismatch_complaint (name
,
10690 cu_header
->addr_size
,
10691 TYPE_LENGTH (type
));
10692 /* Symbols of this form are reasonably rare, so we just
10693 piggyback on the existing location code rather than writing
10694 a new implementation of symbol_computed_ops. */
10695 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
10696 sizeof (struct dwarf2_locexpr_baton
));
10697 (*baton
)->per_cu
= cu
->per_cu
;
10698 gdb_assert ((*baton
)->per_cu
);
10700 (*baton
)->size
= 2 + cu_header
->addr_size
;
10701 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
10702 (*baton
)->data
= data
;
10704 data
[0] = DW_OP_addr
;
10705 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10706 byte_order
, DW_ADDR (attr
));
10707 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10710 case DW_FORM_string
:
10712 /* DW_STRING is already allocated on the objfile obstack, point
10714 *bytes
= (gdb_byte
*) DW_STRING (attr
);
10716 case DW_FORM_block1
:
10717 case DW_FORM_block2
:
10718 case DW_FORM_block4
:
10719 case DW_FORM_block
:
10720 case DW_FORM_exprloc
:
10721 blk
= DW_BLOCK (attr
);
10722 if (TYPE_LENGTH (type
) != blk
->size
)
10723 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
10724 TYPE_LENGTH (type
));
10725 *bytes
= blk
->data
;
10728 /* The DW_AT_const_value attributes are supposed to carry the
10729 symbol's value "represented as it would be on the target
10730 architecture." By the time we get here, it's already been
10731 converted to host endianness, so we just need to sign- or
10732 zero-extend it as appropriate. */
10733 case DW_FORM_data1
:
10734 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
10736 case DW_FORM_data2
:
10737 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
10739 case DW_FORM_data4
:
10740 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
10742 case DW_FORM_data8
:
10743 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
10746 case DW_FORM_sdata
:
10747 *value
= DW_SND (attr
);
10750 case DW_FORM_udata
:
10751 *value
= DW_UNSND (attr
);
10755 complaint (&symfile_complaints
,
10756 _("unsupported const value attribute form: '%s'"),
10757 dwarf_form_name (attr
->form
));
10764 /* Copy constant value from an attribute to a symbol. */
10767 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10768 struct dwarf2_cu
*cu
)
10770 struct objfile
*objfile
= cu
->objfile
;
10771 struct comp_unit_head
*cu_header
= &cu
->header
;
10774 struct dwarf2_locexpr_baton
*baton
;
10776 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
10777 SYMBOL_PRINT_NAME (sym
),
10778 &objfile
->objfile_obstack
, cu
,
10779 &value
, &bytes
, &baton
);
10783 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10784 SYMBOL_LOCATION_BATON (sym
) = baton
;
10785 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10787 else if (bytes
!= NULL
)
10789 SYMBOL_VALUE_BYTES (sym
) = bytes
;
10790 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10794 SYMBOL_VALUE (sym
) = value
;
10795 SYMBOL_CLASS (sym
) = LOC_CONST
;
10800 /* Return the type of the die in question using its DW_AT_type attribute. */
10802 static struct type
*
10803 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10805 struct attribute
*type_attr
;
10806 struct die_info
*type_die
;
10808 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10811 /* A missing DW_AT_type represents a void type. */
10812 return objfile_type (cu
->objfile
)->builtin_void
;
10815 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10817 return tag_type_to_type (type_die
, cu
);
10820 /* True iff CU's producer generates GNAT Ada auxiliary information
10821 that allows to find parallel types through that information instead
10822 of having to do expensive parallel lookups by type name. */
10825 need_gnat_info (struct dwarf2_cu
*cu
)
10827 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10828 of GNAT produces this auxiliary information, without any indication
10829 that it is produced. Part of enhancing the FSF version of GNAT
10830 to produce that information will be to put in place an indicator
10831 that we can use in order to determine whether the descriptive type
10832 info is available or not. One suggestion that has been made is
10833 to use a new attribute, attached to the CU die. For now, assume
10834 that the descriptive type info is not available. */
10839 /* Return the auxiliary type of the die in question using its
10840 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10841 attribute is not present. */
10843 static struct type
*
10844 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10846 struct attribute
*type_attr
;
10847 struct die_info
*type_die
;
10849 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
10853 type_die
= follow_die_ref (die
, type_attr
, &cu
);
10854 return tag_type_to_type (type_die
, cu
);
10857 /* If DIE has a descriptive_type attribute, then set the TYPE's
10858 descriptive type accordingly. */
10861 set_descriptive_type (struct type
*type
, struct die_info
*die
,
10862 struct dwarf2_cu
*cu
)
10864 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
10866 if (descriptive_type
)
10868 ALLOCATE_GNAT_AUX_TYPE (type
);
10869 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
10873 /* Return the containing type of the die in question using its
10874 DW_AT_containing_type attribute. */
10876 static struct type
*
10877 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10879 struct attribute
*type_attr
;
10880 struct die_info
*type_die
;
10882 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
10884 error (_("Dwarf Error: Problem turning containing type into gdb type "
10885 "[in module %s]"), cu
->objfile
->name
);
10887 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10888 return tag_type_to_type (type_die
, cu
);
10891 static struct type
*
10892 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10894 struct type
*this_type
;
10896 this_type
= read_type_die (die
, cu
);
10899 char *message
, *saved
;
10901 /* read_type_die already issued a complaint. */
10902 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
10906 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
10907 message
, strlen (message
));
10910 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
10915 static struct type
*
10916 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10918 struct type
*this_type
;
10920 this_type
= get_die_type (die
, cu
);
10926 case DW_TAG_class_type
:
10927 case DW_TAG_interface_type
:
10928 case DW_TAG_structure_type
:
10929 case DW_TAG_union_type
:
10930 this_type
= read_structure_type (die
, cu
);
10932 case DW_TAG_enumeration_type
:
10933 this_type
= read_enumeration_type (die
, cu
);
10935 case DW_TAG_subprogram
:
10936 case DW_TAG_subroutine_type
:
10937 case DW_TAG_inlined_subroutine
:
10938 this_type
= read_subroutine_type (die
, cu
);
10940 case DW_TAG_array_type
:
10941 this_type
= read_array_type (die
, cu
);
10943 case DW_TAG_set_type
:
10944 this_type
= read_set_type (die
, cu
);
10946 case DW_TAG_pointer_type
:
10947 this_type
= read_tag_pointer_type (die
, cu
);
10949 case DW_TAG_ptr_to_member_type
:
10950 this_type
= read_tag_ptr_to_member_type (die
, cu
);
10952 case DW_TAG_reference_type
:
10953 this_type
= read_tag_reference_type (die
, cu
);
10955 case DW_TAG_const_type
:
10956 this_type
= read_tag_const_type (die
, cu
);
10958 case DW_TAG_volatile_type
:
10959 this_type
= read_tag_volatile_type (die
, cu
);
10961 case DW_TAG_string_type
:
10962 this_type
= read_tag_string_type (die
, cu
);
10964 case DW_TAG_typedef
:
10965 this_type
= read_typedef (die
, cu
);
10967 case DW_TAG_subrange_type
:
10968 this_type
= read_subrange_type (die
, cu
);
10970 case DW_TAG_base_type
:
10971 this_type
= read_base_type (die
, cu
);
10973 case DW_TAG_unspecified_type
:
10974 this_type
= read_unspecified_type (die
, cu
);
10976 case DW_TAG_namespace
:
10977 this_type
= read_namespace_type (die
, cu
);
10979 case DW_TAG_module
:
10980 this_type
= read_module_type (die
, cu
);
10983 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
10984 dwarf_tag_name (die
->tag
));
10991 /* Return the name of the namespace/class that DIE is defined within,
10992 or "" if we can't tell. The caller should not xfree the result.
10994 For example, if we're within the method foo() in the following
11004 then determine_prefix on foo's die will return "N::C". */
11007 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11009 struct die_info
*parent
, *spec_die
;
11010 struct dwarf2_cu
*spec_cu
;
11011 struct type
*parent_type
;
11013 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11014 && cu
->language
!= language_fortran
)
11017 /* We have to be careful in the presence of DW_AT_specification.
11018 For example, with GCC 3.4, given the code
11022 // Definition of N::foo.
11026 then we'll have a tree of DIEs like this:
11028 1: DW_TAG_compile_unit
11029 2: DW_TAG_namespace // N
11030 3: DW_TAG_subprogram // declaration of N::foo
11031 4: DW_TAG_subprogram // definition of N::foo
11032 DW_AT_specification // refers to die #3
11034 Thus, when processing die #4, we have to pretend that we're in
11035 the context of its DW_AT_specification, namely the contex of die
11038 spec_die
= die_specification (die
, &spec_cu
);
11039 if (spec_die
== NULL
)
11040 parent
= die
->parent
;
11043 parent
= spec_die
->parent
;
11047 if (parent
== NULL
)
11049 else if (parent
->building_fullname
)
11052 const char *parent_name
;
11054 /* It has been seen on RealView 2.2 built binaries,
11055 DW_TAG_template_type_param types actually _defined_ as
11056 children of the parent class:
11059 template class <class Enum> Class{};
11060 Class<enum E> class_e;
11062 1: DW_TAG_class_type (Class)
11063 2: DW_TAG_enumeration_type (E)
11064 3: DW_TAG_enumerator (enum1:0)
11065 3: DW_TAG_enumerator (enum2:1)
11067 2: DW_TAG_template_type_param
11068 DW_AT_type DW_FORM_ref_udata (E)
11070 Besides being broken debug info, it can put GDB into an
11071 infinite loop. Consider:
11073 When we're building the full name for Class<E>, we'll start
11074 at Class, and go look over its template type parameters,
11075 finding E. We'll then try to build the full name of E, and
11076 reach here. We're now trying to build the full name of E,
11077 and look over the parent DIE for containing scope. In the
11078 broken case, if we followed the parent DIE of E, we'd again
11079 find Class, and once again go look at its template type
11080 arguments, etc., etc. Simply don't consider such parent die
11081 as source-level parent of this die (it can't be, the language
11082 doesn't allow it), and break the loop here. */
11083 name
= dwarf2_name (die
, cu
);
11084 parent_name
= dwarf2_name (parent
, cu
);
11085 complaint (&symfile_complaints
,
11086 _("template param type '%s' defined within parent '%s'"),
11087 name
? name
: "<unknown>",
11088 parent_name
? parent_name
: "<unknown>");
11092 switch (parent
->tag
)
11094 case DW_TAG_namespace
:
11095 parent_type
= read_type_die (parent
, cu
);
11096 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11097 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11098 Work around this problem here. */
11099 if (cu
->language
== language_cplus
11100 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11102 /* We give a name to even anonymous namespaces. */
11103 return TYPE_TAG_NAME (parent_type
);
11104 case DW_TAG_class_type
:
11105 case DW_TAG_interface_type
:
11106 case DW_TAG_structure_type
:
11107 case DW_TAG_union_type
:
11108 case DW_TAG_module
:
11109 parent_type
= read_type_die (parent
, cu
);
11110 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11111 return TYPE_TAG_NAME (parent_type
);
11113 /* An anonymous structure is only allowed non-static data
11114 members; no typedefs, no member functions, et cetera.
11115 So it does not need a prefix. */
11118 return determine_prefix (parent
, cu
);
11122 /* Return a newly-allocated string formed by concatenating PREFIX and
11123 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11124 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11125 perform an obconcat, otherwise allocate storage for the result. The CU argument
11126 is used to determine the language and hence, the appropriate separator. */
11128 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11131 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11132 int physname
, struct dwarf2_cu
*cu
)
11134 const char *lead
= "";
11137 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11139 else if (cu
->language
== language_java
)
11141 else if (cu
->language
== language_fortran
&& physname
)
11143 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11144 DW_AT_MIPS_linkage_name is preferred and used instead. */
11152 if (prefix
== NULL
)
11154 if (suffix
== NULL
)
11159 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11161 strcpy (retval
, lead
);
11162 strcat (retval
, prefix
);
11163 strcat (retval
, sep
);
11164 strcat (retval
, suffix
);
11169 /* We have an obstack. */
11170 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11174 /* Return sibling of die, NULL if no sibling. */
11176 static struct die_info
*
11177 sibling_die (struct die_info
*die
)
11179 return die
->sibling
;
11182 /* Get name of a die, return NULL if not found. */
11185 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11186 struct obstack
*obstack
)
11188 if (name
&& cu
->language
== language_cplus
)
11190 char *canon_name
= cp_canonicalize_string (name
);
11192 if (canon_name
!= NULL
)
11194 if (strcmp (canon_name
, name
) != 0)
11195 name
= obsavestring (canon_name
, strlen (canon_name
),
11197 xfree (canon_name
);
11204 /* Get name of a die, return NULL if not found. */
11207 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11209 struct attribute
*attr
;
11211 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11212 if (!attr
|| !DW_STRING (attr
))
11217 case DW_TAG_compile_unit
:
11218 /* Compilation units have a DW_AT_name that is a filename, not
11219 a source language identifier. */
11220 case DW_TAG_enumeration_type
:
11221 case DW_TAG_enumerator
:
11222 /* These tags always have simple identifiers already; no need
11223 to canonicalize them. */
11224 return DW_STRING (attr
);
11226 case DW_TAG_subprogram
:
11227 /* Java constructors will all be named "<init>", so return
11228 the class name when we see this special case. */
11229 if (cu
->language
== language_java
11230 && DW_STRING (attr
) != NULL
11231 && strcmp (DW_STRING (attr
), "<init>") == 0)
11233 struct dwarf2_cu
*spec_cu
= cu
;
11234 struct die_info
*spec_die
;
11236 /* GCJ will output '<init>' for Java constructor names.
11237 For this special case, return the name of the parent class. */
11239 /* GCJ may output suprogram DIEs with AT_specification set.
11240 If so, use the name of the specified DIE. */
11241 spec_die
= die_specification (die
, &spec_cu
);
11242 if (spec_die
!= NULL
)
11243 return dwarf2_name (spec_die
, spec_cu
);
11248 if (die
->tag
== DW_TAG_class_type
)
11249 return dwarf2_name (die
, cu
);
11251 while (die
->tag
!= DW_TAG_compile_unit
);
11255 case DW_TAG_class_type
:
11256 case DW_TAG_interface_type
:
11257 case DW_TAG_structure_type
:
11258 case DW_TAG_union_type
:
11259 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11260 structures or unions. These were of the form "._%d" in GCC 4.1,
11261 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11262 and GCC 4.4. We work around this problem by ignoring these. */
11263 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11264 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11272 if (!DW_STRING_IS_CANONICAL (attr
))
11275 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11276 &cu
->objfile
->objfile_obstack
);
11277 DW_STRING_IS_CANONICAL (attr
) = 1;
11279 return DW_STRING (attr
);
11282 /* Return the die that this die in an extension of, or NULL if there
11283 is none. *EXT_CU is the CU containing DIE on input, and the CU
11284 containing the return value on output. */
11286 static struct die_info
*
11287 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11289 struct attribute
*attr
;
11291 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11295 return follow_die_ref (die
, attr
, ext_cu
);
11298 /* Convert a DIE tag into its string name. */
11301 dwarf_tag_name (unsigned tag
)
11305 case DW_TAG_padding
:
11306 return "DW_TAG_padding";
11307 case DW_TAG_array_type
:
11308 return "DW_TAG_array_type";
11309 case DW_TAG_class_type
:
11310 return "DW_TAG_class_type";
11311 case DW_TAG_entry_point
:
11312 return "DW_TAG_entry_point";
11313 case DW_TAG_enumeration_type
:
11314 return "DW_TAG_enumeration_type";
11315 case DW_TAG_formal_parameter
:
11316 return "DW_TAG_formal_parameter";
11317 case DW_TAG_imported_declaration
:
11318 return "DW_TAG_imported_declaration";
11320 return "DW_TAG_label";
11321 case DW_TAG_lexical_block
:
11322 return "DW_TAG_lexical_block";
11323 case DW_TAG_member
:
11324 return "DW_TAG_member";
11325 case DW_TAG_pointer_type
:
11326 return "DW_TAG_pointer_type";
11327 case DW_TAG_reference_type
:
11328 return "DW_TAG_reference_type";
11329 case DW_TAG_compile_unit
:
11330 return "DW_TAG_compile_unit";
11331 case DW_TAG_string_type
:
11332 return "DW_TAG_string_type";
11333 case DW_TAG_structure_type
:
11334 return "DW_TAG_structure_type";
11335 case DW_TAG_subroutine_type
:
11336 return "DW_TAG_subroutine_type";
11337 case DW_TAG_typedef
:
11338 return "DW_TAG_typedef";
11339 case DW_TAG_union_type
:
11340 return "DW_TAG_union_type";
11341 case DW_TAG_unspecified_parameters
:
11342 return "DW_TAG_unspecified_parameters";
11343 case DW_TAG_variant
:
11344 return "DW_TAG_variant";
11345 case DW_TAG_common_block
:
11346 return "DW_TAG_common_block";
11347 case DW_TAG_common_inclusion
:
11348 return "DW_TAG_common_inclusion";
11349 case DW_TAG_inheritance
:
11350 return "DW_TAG_inheritance";
11351 case DW_TAG_inlined_subroutine
:
11352 return "DW_TAG_inlined_subroutine";
11353 case DW_TAG_module
:
11354 return "DW_TAG_module";
11355 case DW_TAG_ptr_to_member_type
:
11356 return "DW_TAG_ptr_to_member_type";
11357 case DW_TAG_set_type
:
11358 return "DW_TAG_set_type";
11359 case DW_TAG_subrange_type
:
11360 return "DW_TAG_subrange_type";
11361 case DW_TAG_with_stmt
:
11362 return "DW_TAG_with_stmt";
11363 case DW_TAG_access_declaration
:
11364 return "DW_TAG_access_declaration";
11365 case DW_TAG_base_type
:
11366 return "DW_TAG_base_type";
11367 case DW_TAG_catch_block
:
11368 return "DW_TAG_catch_block";
11369 case DW_TAG_const_type
:
11370 return "DW_TAG_const_type";
11371 case DW_TAG_constant
:
11372 return "DW_TAG_constant";
11373 case DW_TAG_enumerator
:
11374 return "DW_TAG_enumerator";
11375 case DW_TAG_file_type
:
11376 return "DW_TAG_file_type";
11377 case DW_TAG_friend
:
11378 return "DW_TAG_friend";
11379 case DW_TAG_namelist
:
11380 return "DW_TAG_namelist";
11381 case DW_TAG_namelist_item
:
11382 return "DW_TAG_namelist_item";
11383 case DW_TAG_packed_type
:
11384 return "DW_TAG_packed_type";
11385 case DW_TAG_subprogram
:
11386 return "DW_TAG_subprogram";
11387 case DW_TAG_template_type_param
:
11388 return "DW_TAG_template_type_param";
11389 case DW_TAG_template_value_param
:
11390 return "DW_TAG_template_value_param";
11391 case DW_TAG_thrown_type
:
11392 return "DW_TAG_thrown_type";
11393 case DW_TAG_try_block
:
11394 return "DW_TAG_try_block";
11395 case DW_TAG_variant_part
:
11396 return "DW_TAG_variant_part";
11397 case DW_TAG_variable
:
11398 return "DW_TAG_variable";
11399 case DW_TAG_volatile_type
:
11400 return "DW_TAG_volatile_type";
11401 case DW_TAG_dwarf_procedure
:
11402 return "DW_TAG_dwarf_procedure";
11403 case DW_TAG_restrict_type
:
11404 return "DW_TAG_restrict_type";
11405 case DW_TAG_interface_type
:
11406 return "DW_TAG_interface_type";
11407 case DW_TAG_namespace
:
11408 return "DW_TAG_namespace";
11409 case DW_TAG_imported_module
:
11410 return "DW_TAG_imported_module";
11411 case DW_TAG_unspecified_type
:
11412 return "DW_TAG_unspecified_type";
11413 case DW_TAG_partial_unit
:
11414 return "DW_TAG_partial_unit";
11415 case DW_TAG_imported_unit
:
11416 return "DW_TAG_imported_unit";
11417 case DW_TAG_condition
:
11418 return "DW_TAG_condition";
11419 case DW_TAG_shared_type
:
11420 return "DW_TAG_shared_type";
11421 case DW_TAG_type_unit
:
11422 return "DW_TAG_type_unit";
11423 case DW_TAG_MIPS_loop
:
11424 return "DW_TAG_MIPS_loop";
11425 case DW_TAG_HP_array_descriptor
:
11426 return "DW_TAG_HP_array_descriptor";
11427 case DW_TAG_format_label
:
11428 return "DW_TAG_format_label";
11429 case DW_TAG_function_template
:
11430 return "DW_TAG_function_template";
11431 case DW_TAG_class_template
:
11432 return "DW_TAG_class_template";
11433 case DW_TAG_GNU_BINCL
:
11434 return "DW_TAG_GNU_BINCL";
11435 case DW_TAG_GNU_EINCL
:
11436 return "DW_TAG_GNU_EINCL";
11437 case DW_TAG_upc_shared_type
:
11438 return "DW_TAG_upc_shared_type";
11439 case DW_TAG_upc_strict_type
:
11440 return "DW_TAG_upc_strict_type";
11441 case DW_TAG_upc_relaxed_type
:
11442 return "DW_TAG_upc_relaxed_type";
11443 case DW_TAG_PGI_kanji_type
:
11444 return "DW_TAG_PGI_kanji_type";
11445 case DW_TAG_PGI_interface_block
:
11446 return "DW_TAG_PGI_interface_block";
11448 return "DW_TAG_<unknown>";
11452 /* Convert a DWARF attribute code into its string name. */
11455 dwarf_attr_name (unsigned attr
)
11459 case DW_AT_sibling
:
11460 return "DW_AT_sibling";
11461 case DW_AT_location
:
11462 return "DW_AT_location";
11464 return "DW_AT_name";
11465 case DW_AT_ordering
:
11466 return "DW_AT_ordering";
11467 case DW_AT_subscr_data
:
11468 return "DW_AT_subscr_data";
11469 case DW_AT_byte_size
:
11470 return "DW_AT_byte_size";
11471 case DW_AT_bit_offset
:
11472 return "DW_AT_bit_offset";
11473 case DW_AT_bit_size
:
11474 return "DW_AT_bit_size";
11475 case DW_AT_element_list
:
11476 return "DW_AT_element_list";
11477 case DW_AT_stmt_list
:
11478 return "DW_AT_stmt_list";
11480 return "DW_AT_low_pc";
11481 case DW_AT_high_pc
:
11482 return "DW_AT_high_pc";
11483 case DW_AT_language
:
11484 return "DW_AT_language";
11486 return "DW_AT_member";
11488 return "DW_AT_discr";
11489 case DW_AT_discr_value
:
11490 return "DW_AT_discr_value";
11491 case DW_AT_visibility
:
11492 return "DW_AT_visibility";
11494 return "DW_AT_import";
11495 case DW_AT_string_length
:
11496 return "DW_AT_string_length";
11497 case DW_AT_common_reference
:
11498 return "DW_AT_common_reference";
11499 case DW_AT_comp_dir
:
11500 return "DW_AT_comp_dir";
11501 case DW_AT_const_value
:
11502 return "DW_AT_const_value";
11503 case DW_AT_containing_type
:
11504 return "DW_AT_containing_type";
11505 case DW_AT_default_value
:
11506 return "DW_AT_default_value";
11508 return "DW_AT_inline";
11509 case DW_AT_is_optional
:
11510 return "DW_AT_is_optional";
11511 case DW_AT_lower_bound
:
11512 return "DW_AT_lower_bound";
11513 case DW_AT_producer
:
11514 return "DW_AT_producer";
11515 case DW_AT_prototyped
:
11516 return "DW_AT_prototyped";
11517 case DW_AT_return_addr
:
11518 return "DW_AT_return_addr";
11519 case DW_AT_start_scope
:
11520 return "DW_AT_start_scope";
11521 case DW_AT_bit_stride
:
11522 return "DW_AT_bit_stride";
11523 case DW_AT_upper_bound
:
11524 return "DW_AT_upper_bound";
11525 case DW_AT_abstract_origin
:
11526 return "DW_AT_abstract_origin";
11527 case DW_AT_accessibility
:
11528 return "DW_AT_accessibility";
11529 case DW_AT_address_class
:
11530 return "DW_AT_address_class";
11531 case DW_AT_artificial
:
11532 return "DW_AT_artificial";
11533 case DW_AT_base_types
:
11534 return "DW_AT_base_types";
11535 case DW_AT_calling_convention
:
11536 return "DW_AT_calling_convention";
11538 return "DW_AT_count";
11539 case DW_AT_data_member_location
:
11540 return "DW_AT_data_member_location";
11541 case DW_AT_decl_column
:
11542 return "DW_AT_decl_column";
11543 case DW_AT_decl_file
:
11544 return "DW_AT_decl_file";
11545 case DW_AT_decl_line
:
11546 return "DW_AT_decl_line";
11547 case DW_AT_declaration
:
11548 return "DW_AT_declaration";
11549 case DW_AT_discr_list
:
11550 return "DW_AT_discr_list";
11551 case DW_AT_encoding
:
11552 return "DW_AT_encoding";
11553 case DW_AT_external
:
11554 return "DW_AT_external";
11555 case DW_AT_frame_base
:
11556 return "DW_AT_frame_base";
11558 return "DW_AT_friend";
11559 case DW_AT_identifier_case
:
11560 return "DW_AT_identifier_case";
11561 case DW_AT_macro_info
:
11562 return "DW_AT_macro_info";
11563 case DW_AT_namelist_items
:
11564 return "DW_AT_namelist_items";
11565 case DW_AT_priority
:
11566 return "DW_AT_priority";
11567 case DW_AT_segment
:
11568 return "DW_AT_segment";
11569 case DW_AT_specification
:
11570 return "DW_AT_specification";
11571 case DW_AT_static_link
:
11572 return "DW_AT_static_link";
11574 return "DW_AT_type";
11575 case DW_AT_use_location
:
11576 return "DW_AT_use_location";
11577 case DW_AT_variable_parameter
:
11578 return "DW_AT_variable_parameter";
11579 case DW_AT_virtuality
:
11580 return "DW_AT_virtuality";
11581 case DW_AT_vtable_elem_location
:
11582 return "DW_AT_vtable_elem_location";
11583 /* DWARF 3 values. */
11584 case DW_AT_allocated
:
11585 return "DW_AT_allocated";
11586 case DW_AT_associated
:
11587 return "DW_AT_associated";
11588 case DW_AT_data_location
:
11589 return "DW_AT_data_location";
11590 case DW_AT_byte_stride
:
11591 return "DW_AT_byte_stride";
11592 case DW_AT_entry_pc
:
11593 return "DW_AT_entry_pc";
11594 case DW_AT_use_UTF8
:
11595 return "DW_AT_use_UTF8";
11596 case DW_AT_extension
:
11597 return "DW_AT_extension";
11599 return "DW_AT_ranges";
11600 case DW_AT_trampoline
:
11601 return "DW_AT_trampoline";
11602 case DW_AT_call_column
:
11603 return "DW_AT_call_column";
11604 case DW_AT_call_file
:
11605 return "DW_AT_call_file";
11606 case DW_AT_call_line
:
11607 return "DW_AT_call_line";
11608 case DW_AT_description
:
11609 return "DW_AT_description";
11610 case DW_AT_binary_scale
:
11611 return "DW_AT_binary_scale";
11612 case DW_AT_decimal_scale
:
11613 return "DW_AT_decimal_scale";
11615 return "DW_AT_small";
11616 case DW_AT_decimal_sign
:
11617 return "DW_AT_decimal_sign";
11618 case DW_AT_digit_count
:
11619 return "DW_AT_digit_count";
11620 case DW_AT_picture_string
:
11621 return "DW_AT_picture_string";
11622 case DW_AT_mutable
:
11623 return "DW_AT_mutable";
11624 case DW_AT_threads_scaled
:
11625 return "DW_AT_threads_scaled";
11626 case DW_AT_explicit
:
11627 return "DW_AT_explicit";
11628 case DW_AT_object_pointer
:
11629 return "DW_AT_object_pointer";
11630 case DW_AT_endianity
:
11631 return "DW_AT_endianity";
11632 case DW_AT_elemental
:
11633 return "DW_AT_elemental";
11635 return "DW_AT_pure";
11636 case DW_AT_recursive
:
11637 return "DW_AT_recursive";
11638 /* DWARF 4 values. */
11639 case DW_AT_signature
:
11640 return "DW_AT_signature";
11641 case DW_AT_linkage_name
:
11642 return "DW_AT_linkage_name";
11643 /* SGI/MIPS extensions. */
11644 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11645 case DW_AT_MIPS_fde
:
11646 return "DW_AT_MIPS_fde";
11648 case DW_AT_MIPS_loop_begin
:
11649 return "DW_AT_MIPS_loop_begin";
11650 case DW_AT_MIPS_tail_loop_begin
:
11651 return "DW_AT_MIPS_tail_loop_begin";
11652 case DW_AT_MIPS_epilog_begin
:
11653 return "DW_AT_MIPS_epilog_begin";
11654 case DW_AT_MIPS_loop_unroll_factor
:
11655 return "DW_AT_MIPS_loop_unroll_factor";
11656 case DW_AT_MIPS_software_pipeline_depth
:
11657 return "DW_AT_MIPS_software_pipeline_depth";
11658 case DW_AT_MIPS_linkage_name
:
11659 return "DW_AT_MIPS_linkage_name";
11660 case DW_AT_MIPS_stride
:
11661 return "DW_AT_MIPS_stride";
11662 case DW_AT_MIPS_abstract_name
:
11663 return "DW_AT_MIPS_abstract_name";
11664 case DW_AT_MIPS_clone_origin
:
11665 return "DW_AT_MIPS_clone_origin";
11666 case DW_AT_MIPS_has_inlines
:
11667 return "DW_AT_MIPS_has_inlines";
11668 /* HP extensions. */
11669 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11670 case DW_AT_HP_block_index
:
11671 return "DW_AT_HP_block_index";
11673 case DW_AT_HP_unmodifiable
:
11674 return "DW_AT_HP_unmodifiable";
11675 case DW_AT_HP_actuals_stmt_list
:
11676 return "DW_AT_HP_actuals_stmt_list";
11677 case DW_AT_HP_proc_per_section
:
11678 return "DW_AT_HP_proc_per_section";
11679 case DW_AT_HP_raw_data_ptr
:
11680 return "DW_AT_HP_raw_data_ptr";
11681 case DW_AT_HP_pass_by_reference
:
11682 return "DW_AT_HP_pass_by_reference";
11683 case DW_AT_HP_opt_level
:
11684 return "DW_AT_HP_opt_level";
11685 case DW_AT_HP_prof_version_id
:
11686 return "DW_AT_HP_prof_version_id";
11687 case DW_AT_HP_opt_flags
:
11688 return "DW_AT_HP_opt_flags";
11689 case DW_AT_HP_cold_region_low_pc
:
11690 return "DW_AT_HP_cold_region_low_pc";
11691 case DW_AT_HP_cold_region_high_pc
:
11692 return "DW_AT_HP_cold_region_high_pc";
11693 case DW_AT_HP_all_variables_modifiable
:
11694 return "DW_AT_HP_all_variables_modifiable";
11695 case DW_AT_HP_linkage_name
:
11696 return "DW_AT_HP_linkage_name";
11697 case DW_AT_HP_prof_flags
:
11698 return "DW_AT_HP_prof_flags";
11699 /* GNU extensions. */
11700 case DW_AT_sf_names
:
11701 return "DW_AT_sf_names";
11702 case DW_AT_src_info
:
11703 return "DW_AT_src_info";
11704 case DW_AT_mac_info
:
11705 return "DW_AT_mac_info";
11706 case DW_AT_src_coords
:
11707 return "DW_AT_src_coords";
11708 case DW_AT_body_begin
:
11709 return "DW_AT_body_begin";
11710 case DW_AT_body_end
:
11711 return "DW_AT_body_end";
11712 case DW_AT_GNU_vector
:
11713 return "DW_AT_GNU_vector";
11714 case DW_AT_GNU_odr_signature
:
11715 return "DW_AT_GNU_odr_signature";
11716 /* VMS extensions. */
11717 case DW_AT_VMS_rtnbeg_pd_address
:
11718 return "DW_AT_VMS_rtnbeg_pd_address";
11719 /* UPC extension. */
11720 case DW_AT_upc_threads_scaled
:
11721 return "DW_AT_upc_threads_scaled";
11722 /* PGI (STMicroelectronics) extensions. */
11723 case DW_AT_PGI_lbase
:
11724 return "DW_AT_PGI_lbase";
11725 case DW_AT_PGI_soffset
:
11726 return "DW_AT_PGI_soffset";
11727 case DW_AT_PGI_lstride
:
11728 return "DW_AT_PGI_lstride";
11730 return "DW_AT_<unknown>";
11734 /* Convert a DWARF value form code into its string name. */
11737 dwarf_form_name (unsigned form
)
11742 return "DW_FORM_addr";
11743 case DW_FORM_block2
:
11744 return "DW_FORM_block2";
11745 case DW_FORM_block4
:
11746 return "DW_FORM_block4";
11747 case DW_FORM_data2
:
11748 return "DW_FORM_data2";
11749 case DW_FORM_data4
:
11750 return "DW_FORM_data4";
11751 case DW_FORM_data8
:
11752 return "DW_FORM_data8";
11753 case DW_FORM_string
:
11754 return "DW_FORM_string";
11755 case DW_FORM_block
:
11756 return "DW_FORM_block";
11757 case DW_FORM_block1
:
11758 return "DW_FORM_block1";
11759 case DW_FORM_data1
:
11760 return "DW_FORM_data1";
11762 return "DW_FORM_flag";
11763 case DW_FORM_sdata
:
11764 return "DW_FORM_sdata";
11766 return "DW_FORM_strp";
11767 case DW_FORM_udata
:
11768 return "DW_FORM_udata";
11769 case DW_FORM_ref_addr
:
11770 return "DW_FORM_ref_addr";
11772 return "DW_FORM_ref1";
11774 return "DW_FORM_ref2";
11776 return "DW_FORM_ref4";
11778 return "DW_FORM_ref8";
11779 case DW_FORM_ref_udata
:
11780 return "DW_FORM_ref_udata";
11781 case DW_FORM_indirect
:
11782 return "DW_FORM_indirect";
11783 case DW_FORM_sec_offset
:
11784 return "DW_FORM_sec_offset";
11785 case DW_FORM_exprloc
:
11786 return "DW_FORM_exprloc";
11787 case DW_FORM_flag_present
:
11788 return "DW_FORM_flag_present";
11790 return "DW_FORM_sig8";
11792 return "DW_FORM_<unknown>";
11796 /* Convert a DWARF stack opcode into its string name. */
11799 dwarf_stack_op_name (unsigned op
, int def
)
11804 return "DW_OP_addr";
11806 return "DW_OP_deref";
11807 case DW_OP_const1u
:
11808 return "DW_OP_const1u";
11809 case DW_OP_const1s
:
11810 return "DW_OP_const1s";
11811 case DW_OP_const2u
:
11812 return "DW_OP_const2u";
11813 case DW_OP_const2s
:
11814 return "DW_OP_const2s";
11815 case DW_OP_const4u
:
11816 return "DW_OP_const4u";
11817 case DW_OP_const4s
:
11818 return "DW_OP_const4s";
11819 case DW_OP_const8u
:
11820 return "DW_OP_const8u";
11821 case DW_OP_const8s
:
11822 return "DW_OP_const8s";
11824 return "DW_OP_constu";
11826 return "DW_OP_consts";
11828 return "DW_OP_dup";
11830 return "DW_OP_drop";
11832 return "DW_OP_over";
11834 return "DW_OP_pick";
11836 return "DW_OP_swap";
11838 return "DW_OP_rot";
11840 return "DW_OP_xderef";
11842 return "DW_OP_abs";
11844 return "DW_OP_and";
11846 return "DW_OP_div";
11848 return "DW_OP_minus";
11850 return "DW_OP_mod";
11852 return "DW_OP_mul";
11854 return "DW_OP_neg";
11856 return "DW_OP_not";
11860 return "DW_OP_plus";
11861 case DW_OP_plus_uconst
:
11862 return "DW_OP_plus_uconst";
11864 return "DW_OP_shl";
11866 return "DW_OP_shr";
11868 return "DW_OP_shra";
11870 return "DW_OP_xor";
11872 return "DW_OP_bra";
11886 return "DW_OP_skip";
11888 return "DW_OP_lit0";
11890 return "DW_OP_lit1";
11892 return "DW_OP_lit2";
11894 return "DW_OP_lit3";
11896 return "DW_OP_lit4";
11898 return "DW_OP_lit5";
11900 return "DW_OP_lit6";
11902 return "DW_OP_lit7";
11904 return "DW_OP_lit8";
11906 return "DW_OP_lit9";
11908 return "DW_OP_lit10";
11910 return "DW_OP_lit11";
11912 return "DW_OP_lit12";
11914 return "DW_OP_lit13";
11916 return "DW_OP_lit14";
11918 return "DW_OP_lit15";
11920 return "DW_OP_lit16";
11922 return "DW_OP_lit17";
11924 return "DW_OP_lit18";
11926 return "DW_OP_lit19";
11928 return "DW_OP_lit20";
11930 return "DW_OP_lit21";
11932 return "DW_OP_lit22";
11934 return "DW_OP_lit23";
11936 return "DW_OP_lit24";
11938 return "DW_OP_lit25";
11940 return "DW_OP_lit26";
11942 return "DW_OP_lit27";
11944 return "DW_OP_lit28";
11946 return "DW_OP_lit29";
11948 return "DW_OP_lit30";
11950 return "DW_OP_lit31";
11952 return "DW_OP_reg0";
11954 return "DW_OP_reg1";
11956 return "DW_OP_reg2";
11958 return "DW_OP_reg3";
11960 return "DW_OP_reg4";
11962 return "DW_OP_reg5";
11964 return "DW_OP_reg6";
11966 return "DW_OP_reg7";
11968 return "DW_OP_reg8";
11970 return "DW_OP_reg9";
11972 return "DW_OP_reg10";
11974 return "DW_OP_reg11";
11976 return "DW_OP_reg12";
11978 return "DW_OP_reg13";
11980 return "DW_OP_reg14";
11982 return "DW_OP_reg15";
11984 return "DW_OP_reg16";
11986 return "DW_OP_reg17";
11988 return "DW_OP_reg18";
11990 return "DW_OP_reg19";
11992 return "DW_OP_reg20";
11994 return "DW_OP_reg21";
11996 return "DW_OP_reg22";
11998 return "DW_OP_reg23";
12000 return "DW_OP_reg24";
12002 return "DW_OP_reg25";
12004 return "DW_OP_reg26";
12006 return "DW_OP_reg27";
12008 return "DW_OP_reg28";
12010 return "DW_OP_reg29";
12012 return "DW_OP_reg30";
12014 return "DW_OP_reg31";
12016 return "DW_OP_breg0";
12018 return "DW_OP_breg1";
12020 return "DW_OP_breg2";
12022 return "DW_OP_breg3";
12024 return "DW_OP_breg4";
12026 return "DW_OP_breg5";
12028 return "DW_OP_breg6";
12030 return "DW_OP_breg7";
12032 return "DW_OP_breg8";
12034 return "DW_OP_breg9";
12036 return "DW_OP_breg10";
12038 return "DW_OP_breg11";
12040 return "DW_OP_breg12";
12042 return "DW_OP_breg13";
12044 return "DW_OP_breg14";
12046 return "DW_OP_breg15";
12048 return "DW_OP_breg16";
12050 return "DW_OP_breg17";
12052 return "DW_OP_breg18";
12054 return "DW_OP_breg19";
12056 return "DW_OP_breg20";
12058 return "DW_OP_breg21";
12060 return "DW_OP_breg22";
12062 return "DW_OP_breg23";
12064 return "DW_OP_breg24";
12066 return "DW_OP_breg25";
12068 return "DW_OP_breg26";
12070 return "DW_OP_breg27";
12072 return "DW_OP_breg28";
12074 return "DW_OP_breg29";
12076 return "DW_OP_breg30";
12078 return "DW_OP_breg31";
12080 return "DW_OP_regx";
12082 return "DW_OP_fbreg";
12084 return "DW_OP_bregx";
12086 return "DW_OP_piece";
12087 case DW_OP_deref_size
:
12088 return "DW_OP_deref_size";
12089 case DW_OP_xderef_size
:
12090 return "DW_OP_xderef_size";
12092 return "DW_OP_nop";
12093 /* DWARF 3 extensions. */
12094 case DW_OP_push_object_address
:
12095 return "DW_OP_push_object_address";
12097 return "DW_OP_call2";
12099 return "DW_OP_call4";
12100 case DW_OP_call_ref
:
12101 return "DW_OP_call_ref";
12102 case DW_OP_form_tls_address
:
12103 return "DW_OP_form_tls_address";
12104 case DW_OP_call_frame_cfa
:
12105 return "DW_OP_call_frame_cfa";
12106 case DW_OP_bit_piece
:
12107 return "DW_OP_bit_piece";
12108 /* DWARF 4 extensions. */
12109 case DW_OP_implicit_value
:
12110 return "DW_OP_implicit_value";
12111 case DW_OP_stack_value
:
12112 return "DW_OP_stack_value";
12113 /* GNU extensions. */
12114 case DW_OP_GNU_push_tls_address
:
12115 return "DW_OP_GNU_push_tls_address";
12116 case DW_OP_GNU_uninit
:
12117 return "DW_OP_GNU_uninit";
12119 return def
? "OP_<unknown>" : NULL
;
12124 dwarf_bool_name (unsigned mybool
)
12132 /* Convert a DWARF type code into its string name. */
12135 dwarf_type_encoding_name (unsigned enc
)
12140 return "DW_ATE_void";
12141 case DW_ATE_address
:
12142 return "DW_ATE_address";
12143 case DW_ATE_boolean
:
12144 return "DW_ATE_boolean";
12145 case DW_ATE_complex_float
:
12146 return "DW_ATE_complex_float";
12148 return "DW_ATE_float";
12149 case DW_ATE_signed
:
12150 return "DW_ATE_signed";
12151 case DW_ATE_signed_char
:
12152 return "DW_ATE_signed_char";
12153 case DW_ATE_unsigned
:
12154 return "DW_ATE_unsigned";
12155 case DW_ATE_unsigned_char
:
12156 return "DW_ATE_unsigned_char";
12158 case DW_ATE_imaginary_float
:
12159 return "DW_ATE_imaginary_float";
12160 case DW_ATE_packed_decimal
:
12161 return "DW_ATE_packed_decimal";
12162 case DW_ATE_numeric_string
:
12163 return "DW_ATE_numeric_string";
12164 case DW_ATE_edited
:
12165 return "DW_ATE_edited";
12166 case DW_ATE_signed_fixed
:
12167 return "DW_ATE_signed_fixed";
12168 case DW_ATE_unsigned_fixed
:
12169 return "DW_ATE_unsigned_fixed";
12170 case DW_ATE_decimal_float
:
12171 return "DW_ATE_decimal_float";
12174 return "DW_ATE_UTF";
12175 /* HP extensions. */
12176 case DW_ATE_HP_float80
:
12177 return "DW_ATE_HP_float80";
12178 case DW_ATE_HP_complex_float80
:
12179 return "DW_ATE_HP_complex_float80";
12180 case DW_ATE_HP_float128
:
12181 return "DW_ATE_HP_float128";
12182 case DW_ATE_HP_complex_float128
:
12183 return "DW_ATE_HP_complex_float128";
12184 case DW_ATE_HP_floathpintel
:
12185 return "DW_ATE_HP_floathpintel";
12186 case DW_ATE_HP_imaginary_float80
:
12187 return "DW_ATE_HP_imaginary_float80";
12188 case DW_ATE_HP_imaginary_float128
:
12189 return "DW_ATE_HP_imaginary_float128";
12191 return "DW_ATE_<unknown>";
12195 /* Convert a DWARF call frame info operation to its string name. */
12199 dwarf_cfi_name (unsigned cfi_opc
)
12203 case DW_CFA_advance_loc
:
12204 return "DW_CFA_advance_loc";
12205 case DW_CFA_offset
:
12206 return "DW_CFA_offset";
12207 case DW_CFA_restore
:
12208 return "DW_CFA_restore";
12210 return "DW_CFA_nop";
12211 case DW_CFA_set_loc
:
12212 return "DW_CFA_set_loc";
12213 case DW_CFA_advance_loc1
:
12214 return "DW_CFA_advance_loc1";
12215 case DW_CFA_advance_loc2
:
12216 return "DW_CFA_advance_loc2";
12217 case DW_CFA_advance_loc4
:
12218 return "DW_CFA_advance_loc4";
12219 case DW_CFA_offset_extended
:
12220 return "DW_CFA_offset_extended";
12221 case DW_CFA_restore_extended
:
12222 return "DW_CFA_restore_extended";
12223 case DW_CFA_undefined
:
12224 return "DW_CFA_undefined";
12225 case DW_CFA_same_value
:
12226 return "DW_CFA_same_value";
12227 case DW_CFA_register
:
12228 return "DW_CFA_register";
12229 case DW_CFA_remember_state
:
12230 return "DW_CFA_remember_state";
12231 case DW_CFA_restore_state
:
12232 return "DW_CFA_restore_state";
12233 case DW_CFA_def_cfa
:
12234 return "DW_CFA_def_cfa";
12235 case DW_CFA_def_cfa_register
:
12236 return "DW_CFA_def_cfa_register";
12237 case DW_CFA_def_cfa_offset
:
12238 return "DW_CFA_def_cfa_offset";
12240 case DW_CFA_def_cfa_expression
:
12241 return "DW_CFA_def_cfa_expression";
12242 case DW_CFA_expression
:
12243 return "DW_CFA_expression";
12244 case DW_CFA_offset_extended_sf
:
12245 return "DW_CFA_offset_extended_sf";
12246 case DW_CFA_def_cfa_sf
:
12247 return "DW_CFA_def_cfa_sf";
12248 case DW_CFA_def_cfa_offset_sf
:
12249 return "DW_CFA_def_cfa_offset_sf";
12250 case DW_CFA_val_offset
:
12251 return "DW_CFA_val_offset";
12252 case DW_CFA_val_offset_sf
:
12253 return "DW_CFA_val_offset_sf";
12254 case DW_CFA_val_expression
:
12255 return "DW_CFA_val_expression";
12256 /* SGI/MIPS specific. */
12257 case DW_CFA_MIPS_advance_loc8
:
12258 return "DW_CFA_MIPS_advance_loc8";
12259 /* GNU extensions. */
12260 case DW_CFA_GNU_window_save
:
12261 return "DW_CFA_GNU_window_save";
12262 case DW_CFA_GNU_args_size
:
12263 return "DW_CFA_GNU_args_size";
12264 case DW_CFA_GNU_negative_offset_extended
:
12265 return "DW_CFA_GNU_negative_offset_extended";
12267 return "DW_CFA_<unknown>";
12273 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12277 print_spaces (indent
, f
);
12278 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12279 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12281 if (die
->parent
!= NULL
)
12283 print_spaces (indent
, f
);
12284 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12285 die
->parent
->offset
);
12288 print_spaces (indent
, f
);
12289 fprintf_unfiltered (f
, " has children: %s\n",
12290 dwarf_bool_name (die
->child
!= NULL
));
12292 print_spaces (indent
, f
);
12293 fprintf_unfiltered (f
, " attributes:\n");
12295 for (i
= 0; i
< die
->num_attrs
; ++i
)
12297 print_spaces (indent
, f
);
12298 fprintf_unfiltered (f
, " %s (%s) ",
12299 dwarf_attr_name (die
->attrs
[i
].name
),
12300 dwarf_form_name (die
->attrs
[i
].form
));
12302 switch (die
->attrs
[i
].form
)
12304 case DW_FORM_ref_addr
:
12306 fprintf_unfiltered (f
, "address: ");
12307 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12309 case DW_FORM_block2
:
12310 case DW_FORM_block4
:
12311 case DW_FORM_block
:
12312 case DW_FORM_block1
:
12313 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12315 case DW_FORM_exprloc
:
12316 fprintf_unfiltered (f
, "expression: size %u",
12317 DW_BLOCK (&die
->attrs
[i
])->size
);
12322 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12323 (long) (DW_ADDR (&die
->attrs
[i
])));
12325 case DW_FORM_data1
:
12326 case DW_FORM_data2
:
12327 case DW_FORM_data4
:
12328 case DW_FORM_data8
:
12329 case DW_FORM_udata
:
12330 case DW_FORM_sdata
:
12331 fprintf_unfiltered (f
, "constant: %s",
12332 pulongest (DW_UNSND (&die
->attrs
[i
])));
12334 case DW_FORM_sec_offset
:
12335 fprintf_unfiltered (f
, "section offset: %s",
12336 pulongest (DW_UNSND (&die
->attrs
[i
])));
12339 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12340 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12341 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12343 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12345 case DW_FORM_string
:
12347 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12348 DW_STRING (&die
->attrs
[i
])
12349 ? DW_STRING (&die
->attrs
[i
]) : "",
12350 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12353 if (DW_UNSND (&die
->attrs
[i
]))
12354 fprintf_unfiltered (f
, "flag: TRUE");
12356 fprintf_unfiltered (f
, "flag: FALSE");
12358 case DW_FORM_flag_present
:
12359 fprintf_unfiltered (f
, "flag: TRUE");
12361 case DW_FORM_indirect
:
12362 /* the reader will have reduced the indirect form to
12363 the "base form" so this form should not occur */
12364 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12367 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12368 die
->attrs
[i
].form
);
12371 fprintf_unfiltered (f
, "\n");
12376 dump_die_for_error (struct die_info
*die
)
12378 dump_die_shallow (gdb_stderr
, 0, die
);
12382 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12384 int indent
= level
* 4;
12386 gdb_assert (die
!= NULL
);
12388 if (level
>= max_level
)
12391 dump_die_shallow (f
, indent
, die
);
12393 if (die
->child
!= NULL
)
12395 print_spaces (indent
, f
);
12396 fprintf_unfiltered (f
, " Children:");
12397 if (level
+ 1 < max_level
)
12399 fprintf_unfiltered (f
, "\n");
12400 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12404 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12408 if (die
->sibling
!= NULL
&& level
> 0)
12410 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12414 /* This is called from the pdie macro in gdbinit.in.
12415 It's not static so gcc will keep a copy callable from gdb. */
12418 dump_die (struct die_info
*die
, int max_level
)
12420 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12424 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12428 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12434 is_ref_attr (struct attribute
*attr
)
12436 switch (attr
->form
)
12438 case DW_FORM_ref_addr
:
12443 case DW_FORM_ref_udata
:
12450 static unsigned int
12451 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12453 if (is_ref_attr (attr
))
12454 return DW_ADDR (attr
);
12456 complaint (&symfile_complaints
,
12457 _("unsupported die ref attribute form: '%s'"),
12458 dwarf_form_name (attr
->form
));
12462 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12463 * the value held by the attribute is not constant. */
12466 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12468 if (attr
->form
== DW_FORM_sdata
)
12469 return DW_SND (attr
);
12470 else if (attr
->form
== DW_FORM_udata
12471 || attr
->form
== DW_FORM_data1
12472 || attr
->form
== DW_FORM_data2
12473 || attr
->form
== DW_FORM_data4
12474 || attr
->form
== DW_FORM_data8
)
12475 return DW_UNSND (attr
);
12478 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12479 dwarf_form_name (attr
->form
));
12480 return default_value
;
12484 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12485 unit and add it to our queue.
12486 The result is non-zero if PER_CU was queued, otherwise the result is zero
12487 meaning either PER_CU is already queued or it is already loaded. */
12490 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12491 struct dwarf2_per_cu_data
*per_cu
)
12493 /* We may arrive here during partial symbol reading, if we need full
12494 DIEs to process an unusual case (e.g. template arguments). Do
12495 not queue PER_CU, just tell our caller to load its DIEs. */
12496 if (dwarf2_per_objfile
->reading_partial_symbols
)
12498 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12503 /* Mark the dependence relation so that we don't flush PER_CU
12505 dwarf2_add_dependence (this_cu
, per_cu
);
12507 /* If it's already on the queue, we have nothing to do. */
12508 if (per_cu
->queued
)
12511 /* If the compilation unit is already loaded, just mark it as
12513 if (per_cu
->cu
!= NULL
)
12515 per_cu
->cu
->last_used
= 0;
12519 /* Add it to the queue. */
12520 queue_comp_unit (per_cu
, this_cu
->objfile
);
12525 /* Follow reference or signature attribute ATTR of SRC_DIE.
12526 On entry *REF_CU is the CU of SRC_DIE.
12527 On exit *REF_CU is the CU of the result. */
12529 static struct die_info
*
12530 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12531 struct dwarf2_cu
**ref_cu
)
12533 struct die_info
*die
;
12535 if (is_ref_attr (attr
))
12536 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12537 else if (attr
->form
== DW_FORM_sig8
)
12538 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12541 dump_die_for_error (src_die
);
12542 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12543 (*ref_cu
)->objfile
->name
);
12549 /* Follow reference OFFSET.
12550 On entry *REF_CU is the CU of source DIE referencing OFFSET.
12551 On exit *REF_CU is the CU of the result. */
12553 static struct die_info
*
12554 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
12556 struct die_info temp_die
;
12557 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
12559 gdb_assert (cu
->per_cu
!= NULL
);
12563 if (cu
->per_cu
->from_debug_types
)
12565 /* .debug_types CUs cannot reference anything outside their CU.
12566 If they need to, they have to reference a signatured type via
12568 if (! offset_in_cu_p (&cu
->header
, offset
))
12571 else if (! offset_in_cu_p (&cu
->header
, offset
))
12573 struct dwarf2_per_cu_data
*per_cu
;
12575 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
12577 /* If necessary, add it to the queue and load its DIEs. */
12578 if (maybe_queue_comp_unit (cu
, per_cu
))
12579 load_full_comp_unit (per_cu
, cu
->objfile
);
12581 target_cu
= per_cu
->cu
;
12583 else if (cu
->dies
== NULL
)
12585 /* We're loading full DIEs during partial symbol reading. */
12586 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
12587 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
12590 *ref_cu
= target_cu
;
12591 temp_die
.offset
= offset
;
12592 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
12595 /* Follow reference attribute ATTR of SRC_DIE.
12596 On entry *REF_CU is the CU of SRC_DIE.
12597 On exit *REF_CU is the CU of the result. */
12599 static struct die_info
*
12600 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
12601 struct dwarf2_cu
**ref_cu
)
12603 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12604 struct dwarf2_cu
*cu
= *ref_cu
;
12605 struct die_info
*die
;
12607 die
= follow_die_offset (offset
, ref_cu
);
12609 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12610 "at 0x%x [in module %s]"),
12611 offset
, src_die
->offset
, cu
->objfile
->name
);
12616 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12617 value is intended for DW_OP_call*. */
12619 struct dwarf2_locexpr_baton
12620 dwarf2_fetch_die_location_block (unsigned int offset
,
12621 struct dwarf2_per_cu_data
*per_cu
)
12623 struct dwarf2_cu
*cu
= per_cu
->cu
;
12624 struct die_info
*die
;
12625 struct attribute
*attr
;
12626 struct dwarf2_locexpr_baton retval
;
12628 die
= follow_die_offset (offset
, &cu
);
12630 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12631 offset
, per_cu
->cu
->objfile
->name
);
12633 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12636 /* DWARF: "If there is no such attribute, then there is no effect.". */
12638 retval
.data
= NULL
;
12643 if (!attr_form_is_block (attr
))
12644 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12645 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12646 offset
, per_cu
->cu
->objfile
->name
);
12648 retval
.data
= DW_BLOCK (attr
)->data
;
12649 retval
.size
= DW_BLOCK (attr
)->size
;
12651 retval
.per_cu
= cu
->per_cu
;
12655 /* Follow the signature attribute ATTR in SRC_DIE.
12656 On entry *REF_CU is the CU of SRC_DIE.
12657 On exit *REF_CU is the CU of the result. */
12659 static struct die_info
*
12660 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
12661 struct dwarf2_cu
**ref_cu
)
12663 struct objfile
*objfile
= (*ref_cu
)->objfile
;
12664 struct die_info temp_die
;
12665 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12666 struct dwarf2_cu
*sig_cu
;
12667 struct die_info
*die
;
12669 /* sig_type will be NULL if the signatured type is missing from
12671 if (sig_type
== NULL
)
12672 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12673 "at 0x%x [in module %s]"),
12674 src_die
->offset
, objfile
->name
);
12676 /* If necessary, add it to the queue and load its DIEs. */
12678 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12679 read_signatured_type (objfile
, sig_type
);
12681 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12683 sig_cu
= sig_type
->per_cu
.cu
;
12684 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12685 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12692 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12693 "at 0x%x [in module %s]"),
12694 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12697 /* Given an offset of a signatured type, return its signatured_type. */
12699 static struct signatured_type
*
12700 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12702 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12703 unsigned int length
, initial_length_size
;
12704 unsigned int sig_offset
;
12705 struct signatured_type find_entry
, *type_sig
;
12707 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12708 sig_offset
= (initial_length_size
12710 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
12711 + 1 /*address_size*/);
12712 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
12713 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
12715 /* This is only used to lookup previously recorded types.
12716 If we didn't find it, it's our bug. */
12717 gdb_assert (type_sig
!= NULL
);
12718 gdb_assert (offset
== type_sig
->offset
);
12723 /* Read in signatured type at OFFSET and build its CU and die(s). */
12726 read_signatured_type_at_offset (struct objfile
*objfile
,
12727 unsigned int offset
)
12729 struct signatured_type
*type_sig
;
12731 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12733 /* We have the section offset, but we need the signature to do the
12734 hash table lookup. */
12735 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
12737 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12739 read_signatured_type (objfile
, type_sig
);
12741 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
12744 /* Read in a signatured type and build its CU and DIEs. */
12747 read_signatured_type (struct objfile
*objfile
,
12748 struct signatured_type
*type_sig
)
12750 gdb_byte
*types_ptr
;
12751 struct die_reader_specs reader_specs
;
12752 struct dwarf2_cu
*cu
;
12753 ULONGEST signature
;
12754 struct cleanup
*back_to
, *free_cu_cleanup
;
12755 struct attribute
*attr
;
12757 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12758 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
12760 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12762 cu
= xmalloc (sizeof (struct dwarf2_cu
));
12763 memset (cu
, 0, sizeof (struct dwarf2_cu
));
12764 obstack_init (&cu
->comp_unit_obstack
);
12765 cu
->objfile
= objfile
;
12766 type_sig
->per_cu
.cu
= cu
;
12767 cu
->per_cu
= &type_sig
->per_cu
;
12769 /* If an error occurs while loading, release our storage. */
12770 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
12772 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
12773 types_ptr
, objfile
->obfd
);
12774 gdb_assert (signature
== type_sig
->signature
);
12777 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12781 &cu
->comp_unit_obstack
,
12782 hashtab_obstack_allocate
,
12783 dummy_obstack_deallocate
);
12785 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
12786 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
12788 init_cu_die_reader (&reader_specs
, cu
);
12790 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
12793 /* We try not to read any attributes in this function, because not
12794 all objfiles needed for references have been loaded yet, and symbol
12795 table processing isn't initialized. But we have to set the CU language,
12796 or we won't be able to build types correctly. */
12797 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
12799 set_cu_language (DW_UNSND (attr
), cu
);
12801 set_cu_language (language_minimal
, cu
);
12803 do_cleanups (back_to
);
12805 /* We've successfully allocated this compilation unit. Let our caller
12806 clean it up when finished with it. */
12807 discard_cleanups (free_cu_cleanup
);
12809 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
12810 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
12813 /* Decode simple location descriptions.
12814 Given a pointer to a dwarf block that defines a location, compute
12815 the location and return the value.
12817 NOTE drow/2003-11-18: This function is called in two situations
12818 now: for the address of static or global variables (partial symbols
12819 only) and for offsets into structures which are expected to be
12820 (more or less) constant. The partial symbol case should go away,
12821 and only the constant case should remain. That will let this
12822 function complain more accurately. A few special modes are allowed
12823 without complaint for global variables (for instance, global
12824 register values and thread-local values).
12826 A location description containing no operations indicates that the
12827 object is optimized out. The return value is 0 for that case.
12828 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12829 callers will only want a very basic result and this can become a
12832 Note that stack[0] is unused except as a default error return.
12833 Note that stack overflow is not yet handled. */
12836 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
12838 struct objfile
*objfile
= cu
->objfile
;
12840 int size
= blk
->size
;
12841 gdb_byte
*data
= blk
->data
;
12842 CORE_ADDR stack
[64];
12844 unsigned int bytes_read
, unsnd
;
12888 stack
[++stacki
] = op
- DW_OP_lit0
;
12923 stack
[++stacki
] = op
- DW_OP_reg0
;
12925 dwarf2_complex_location_expr_complaint ();
12929 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12931 stack
[++stacki
] = unsnd
;
12933 dwarf2_complex_location_expr_complaint ();
12937 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
12942 case DW_OP_const1u
:
12943 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
12947 case DW_OP_const1s
:
12948 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
12952 case DW_OP_const2u
:
12953 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
12957 case DW_OP_const2s
:
12958 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
12962 case DW_OP_const4u
:
12963 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
12967 case DW_OP_const4s
:
12968 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
12973 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
12979 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
12984 stack
[stacki
+ 1] = stack
[stacki
];
12989 stack
[stacki
- 1] += stack
[stacki
];
12993 case DW_OP_plus_uconst
:
12994 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12999 stack
[stacki
- 1] -= stack
[stacki
];
13004 /* If we're not the last op, then we definitely can't encode
13005 this using GDB's address_class enum. This is valid for partial
13006 global symbols, although the variable's address will be bogus
13009 dwarf2_complex_location_expr_complaint ();
13012 case DW_OP_GNU_push_tls_address
:
13013 /* The top of the stack has the offset from the beginning
13014 of the thread control block at which the variable is located. */
13015 /* Nothing should follow this operator, so the top of stack would
13017 /* This is valid for partial global symbols, but the variable's
13018 address will be bogus in the psymtab. */
13020 dwarf2_complex_location_expr_complaint ();
13023 case DW_OP_GNU_uninit
:
13027 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13028 dwarf_stack_op_name (op
, 1));
13029 return (stack
[stacki
]);
13032 return (stack
[stacki
]);
13035 /* memory allocation interface */
13037 static struct dwarf_block
*
13038 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13040 struct dwarf_block
*blk
;
13042 blk
= (struct dwarf_block
*)
13043 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13047 static struct abbrev_info
*
13048 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13050 struct abbrev_info
*abbrev
;
13052 abbrev
= (struct abbrev_info
*)
13053 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13054 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13058 static struct die_info
*
13059 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13061 struct die_info
*die
;
13062 size_t size
= sizeof (struct die_info
);
13065 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13067 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13068 memset (die
, 0, sizeof (struct die_info
));
13073 /* Macro support. */
13076 /* Return the full name of file number I in *LH's file name table.
13077 Use COMP_DIR as the name of the current directory of the
13078 compilation. The result is allocated using xmalloc; the caller is
13079 responsible for freeing it. */
13081 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13083 /* Is the file number a valid index into the line header's file name
13084 table? Remember that file numbers start with one, not zero. */
13085 if (1 <= file
&& file
<= lh
->num_file_names
)
13087 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13089 if (IS_ABSOLUTE_PATH (fe
->name
))
13090 return xstrdup (fe
->name
);
13098 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13104 dir_len
= strlen (dir
);
13105 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13106 strcpy (full_name
, dir
);
13107 full_name
[dir_len
] = '/';
13108 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13112 return xstrdup (fe
->name
);
13117 /* The compiler produced a bogus file number. We can at least
13118 record the macro definitions made in the file, even if we
13119 won't be able to find the file by name. */
13120 char fake_name
[80];
13122 sprintf (fake_name
, "<bad macro file number %d>", file
);
13124 complaint (&symfile_complaints
,
13125 _("bad file number in macro information (%d)"),
13128 return xstrdup (fake_name
);
13133 static struct macro_source_file
*
13134 macro_start_file (int file
, int line
,
13135 struct macro_source_file
*current_file
,
13136 const char *comp_dir
,
13137 struct line_header
*lh
, struct objfile
*objfile
)
13139 /* The full name of this source file. */
13140 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13142 /* We don't create a macro table for this compilation unit
13143 at all until we actually get a filename. */
13144 if (! pending_macros
)
13145 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13146 objfile
->macro_cache
);
13148 if (! current_file
)
13149 /* If we have no current file, then this must be the start_file
13150 directive for the compilation unit's main source file. */
13151 current_file
= macro_set_main (pending_macros
, full_name
);
13153 current_file
= macro_include (current_file
, line
, full_name
);
13157 return current_file
;
13161 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13162 followed by a null byte. */
13164 copy_string (const char *buf
, int len
)
13166 char *s
= xmalloc (len
+ 1);
13168 memcpy (s
, buf
, len
);
13174 static const char *
13175 consume_improper_spaces (const char *p
, const char *body
)
13179 complaint (&symfile_complaints
,
13180 _("macro definition contains spaces in formal argument list:\n`%s'"),
13192 parse_macro_definition (struct macro_source_file
*file
, int line
,
13197 /* The body string takes one of two forms. For object-like macro
13198 definitions, it should be:
13200 <macro name> " " <definition>
13202 For function-like macro definitions, it should be:
13204 <macro name> "() " <definition>
13206 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13208 Spaces may appear only where explicitly indicated, and in the
13211 The Dwarf 2 spec says that an object-like macro's name is always
13212 followed by a space, but versions of GCC around March 2002 omit
13213 the space when the macro's definition is the empty string.
13215 The Dwarf 2 spec says that there should be no spaces between the
13216 formal arguments in a function-like macro's formal argument list,
13217 but versions of GCC around March 2002 include spaces after the
13221 /* Find the extent of the macro name. The macro name is terminated
13222 by either a space or null character (for an object-like macro) or
13223 an opening paren (for a function-like macro). */
13224 for (p
= body
; *p
; p
++)
13225 if (*p
== ' ' || *p
== '(')
13228 if (*p
== ' ' || *p
== '\0')
13230 /* It's an object-like macro. */
13231 int name_len
= p
- body
;
13232 char *name
= copy_string (body
, name_len
);
13233 const char *replacement
;
13236 replacement
= body
+ name_len
+ 1;
13239 dwarf2_macro_malformed_definition_complaint (body
);
13240 replacement
= body
+ name_len
;
13243 macro_define_object (file
, line
, name
, replacement
);
13247 else if (*p
== '(')
13249 /* It's a function-like macro. */
13250 char *name
= copy_string (body
, p
- body
);
13253 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13257 p
= consume_improper_spaces (p
, body
);
13259 /* Parse the formal argument list. */
13260 while (*p
&& *p
!= ')')
13262 /* Find the extent of the current argument name. */
13263 const char *arg_start
= p
;
13265 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13268 if (! *p
|| p
== arg_start
)
13269 dwarf2_macro_malformed_definition_complaint (body
);
13272 /* Make sure argv has room for the new argument. */
13273 if (argc
>= argv_size
)
13276 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13279 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13282 p
= consume_improper_spaces (p
, body
);
13284 /* Consume the comma, if present. */
13289 p
= consume_improper_spaces (p
, body
);
13298 /* Perfectly formed definition, no complaints. */
13299 macro_define_function (file
, line
, name
,
13300 argc
, (const char **) argv
,
13302 else if (*p
== '\0')
13304 /* Complain, but do define it. */
13305 dwarf2_macro_malformed_definition_complaint (body
);
13306 macro_define_function (file
, line
, name
,
13307 argc
, (const char **) argv
,
13311 /* Just complain. */
13312 dwarf2_macro_malformed_definition_complaint (body
);
13315 /* Just complain. */
13316 dwarf2_macro_malformed_definition_complaint (body
);
13322 for (i
= 0; i
< argc
; i
++)
13328 dwarf2_macro_malformed_definition_complaint (body
);
13333 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13334 char *comp_dir
, bfd
*abfd
,
13335 struct dwarf2_cu
*cu
)
13337 gdb_byte
*mac_ptr
, *mac_end
;
13338 struct macro_source_file
*current_file
= 0;
13339 enum dwarf_macinfo_record_type macinfo_type
;
13340 int at_commandline
;
13342 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13343 &dwarf2_per_objfile
->macinfo
);
13344 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13346 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13350 /* First pass: Find the name of the base filename.
13351 This filename is needed in order to process all macros whose definition
13352 (or undefinition) comes from the command line. These macros are defined
13353 before the first DW_MACINFO_start_file entry, and yet still need to be
13354 associated to the base file.
13356 To determine the base file name, we scan the macro definitions until we
13357 reach the first DW_MACINFO_start_file entry. We then initialize
13358 CURRENT_FILE accordingly so that any macro definition found before the
13359 first DW_MACINFO_start_file can still be associated to the base file. */
13361 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13362 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13363 + dwarf2_per_objfile
->macinfo
.size
;
13367 /* Do we at least have room for a macinfo type byte? */
13368 if (mac_ptr
>= mac_end
)
13370 /* Complaint is printed during the second pass as GDB will probably
13371 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13375 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13378 switch (macinfo_type
)
13380 /* A zero macinfo type indicates the end of the macro
13385 case DW_MACINFO_define
:
13386 case DW_MACINFO_undef
:
13387 /* Only skip the data by MAC_PTR. */
13389 unsigned int bytes_read
;
13391 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13392 mac_ptr
+= bytes_read
;
13393 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13394 mac_ptr
+= bytes_read
;
13398 case DW_MACINFO_start_file
:
13400 unsigned int bytes_read
;
13403 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13404 mac_ptr
+= bytes_read
;
13405 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13406 mac_ptr
+= bytes_read
;
13408 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13413 case DW_MACINFO_end_file
:
13414 /* No data to skip by MAC_PTR. */
13417 case DW_MACINFO_vendor_ext
:
13418 /* Only skip the data by MAC_PTR. */
13420 unsigned int bytes_read
;
13422 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13423 mac_ptr
+= bytes_read
;
13424 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13425 mac_ptr
+= bytes_read
;
13432 } while (macinfo_type
!= 0 && current_file
== NULL
);
13434 /* Second pass: Process all entries.
13436 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13437 command-line macro definitions/undefinitions. This flag is unset when we
13438 reach the first DW_MACINFO_start_file entry. */
13440 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13442 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13443 GDB is still reading the definitions from command line. First
13444 DW_MACINFO_start_file will need to be ignored as it was already executed
13445 to create CURRENT_FILE for the main source holding also the command line
13446 definitions. On first met DW_MACINFO_start_file this flag is reset to
13447 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13449 at_commandline
= 1;
13453 /* Do we at least have room for a macinfo type byte? */
13454 if (mac_ptr
>= mac_end
)
13456 dwarf2_macros_too_long_complaint ();
13460 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13463 switch (macinfo_type
)
13465 /* A zero macinfo type indicates the end of the macro
13470 case DW_MACINFO_define
:
13471 case DW_MACINFO_undef
:
13473 unsigned int bytes_read
;
13477 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13478 mac_ptr
+= bytes_read
;
13479 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13480 mac_ptr
+= bytes_read
;
13482 if (! current_file
)
13484 /* DWARF violation as no main source is present. */
13485 complaint (&symfile_complaints
,
13486 _("debug info with no main source gives macro %s "
13488 macinfo_type
== DW_MACINFO_define
?
13490 macinfo_type
== DW_MACINFO_undef
?
13491 _("undefinition") :
13492 _("something-or-other"), line
, body
);
13495 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13496 complaint (&symfile_complaints
,
13497 _("debug info gives %s macro %s with %s line %d: %s"),
13498 at_commandline
? _("command-line") : _("in-file"),
13499 macinfo_type
== DW_MACINFO_define
?
13501 macinfo_type
== DW_MACINFO_undef
?
13502 _("undefinition") :
13503 _("something-or-other"),
13504 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13506 if (macinfo_type
== DW_MACINFO_define
)
13507 parse_macro_definition (current_file
, line
, body
);
13508 else if (macinfo_type
== DW_MACINFO_undef
)
13509 macro_undef (current_file
, line
, body
);
13513 case DW_MACINFO_start_file
:
13515 unsigned int bytes_read
;
13518 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13519 mac_ptr
+= bytes_read
;
13520 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13521 mac_ptr
+= bytes_read
;
13523 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13524 complaint (&symfile_complaints
,
13525 _("debug info gives source %d included "
13526 "from %s at %s line %d"),
13527 file
, at_commandline
? _("command-line") : _("file"),
13528 line
== 0 ? _("zero") : _("non-zero"), line
);
13530 if (at_commandline
)
13532 /* This DW_MACINFO_start_file was executed in the pass one. */
13533 at_commandline
= 0;
13536 current_file
= macro_start_file (file
, line
,
13537 current_file
, comp_dir
,
13542 case DW_MACINFO_end_file
:
13543 if (! current_file
)
13544 complaint (&symfile_complaints
,
13545 _("macro debug info has an unmatched `close_file' directive"));
13548 current_file
= current_file
->included_by
;
13549 if (! current_file
)
13551 enum dwarf_macinfo_record_type next_type
;
13553 /* GCC circa March 2002 doesn't produce the zero
13554 type byte marking the end of the compilation
13555 unit. Complain if it's not there, but exit no
13558 /* Do we at least have room for a macinfo type byte? */
13559 if (mac_ptr
>= mac_end
)
13561 dwarf2_macros_too_long_complaint ();
13565 /* We don't increment mac_ptr here, so this is just
13567 next_type
= read_1_byte (abfd
, mac_ptr
);
13568 if (next_type
!= 0)
13569 complaint (&symfile_complaints
,
13570 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13577 case DW_MACINFO_vendor_ext
:
13579 unsigned int bytes_read
;
13583 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13584 mac_ptr
+= bytes_read
;
13585 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13586 mac_ptr
+= bytes_read
;
13588 /* We don't recognize any vendor extensions. */
13592 } while (macinfo_type
!= 0);
13595 /* Check if the attribute's form is a DW_FORM_block*
13596 if so return true else false. */
13598 attr_form_is_block (struct attribute
*attr
)
13600 return (attr
== NULL
? 0 :
13601 attr
->form
== DW_FORM_block1
13602 || attr
->form
== DW_FORM_block2
13603 || attr
->form
== DW_FORM_block4
13604 || attr
->form
== DW_FORM_block
13605 || attr
->form
== DW_FORM_exprloc
);
13608 /* Return non-zero if ATTR's value is a section offset --- classes
13609 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13610 You may use DW_UNSND (attr) to retrieve such offsets.
13612 Section 7.5.4, "Attribute Encodings", explains that no attribute
13613 may have a value that belongs to more than one of these classes; it
13614 would be ambiguous if we did, because we use the same forms for all
13617 attr_form_is_section_offset (struct attribute
*attr
)
13619 return (attr
->form
== DW_FORM_data4
13620 || attr
->form
== DW_FORM_data8
13621 || attr
->form
== DW_FORM_sec_offset
);
13625 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13626 zero otherwise. When this function returns true, you can apply
13627 dwarf2_get_attr_constant_value to it.
13629 However, note that for some attributes you must check
13630 attr_form_is_section_offset before using this test. DW_FORM_data4
13631 and DW_FORM_data8 are members of both the constant class, and of
13632 the classes that contain offsets into other debug sections
13633 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13634 that, if an attribute's can be either a constant or one of the
13635 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13636 taken as section offsets, not constants. */
13638 attr_form_is_constant (struct attribute
*attr
)
13640 switch (attr
->form
)
13642 case DW_FORM_sdata
:
13643 case DW_FORM_udata
:
13644 case DW_FORM_data1
:
13645 case DW_FORM_data2
:
13646 case DW_FORM_data4
:
13647 case DW_FORM_data8
:
13655 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
13656 struct dwarf2_cu
*cu
)
13658 if (attr_form_is_section_offset (attr
)
13659 /* ".debug_loc" may not exist at all, or the offset may be outside
13660 the section. If so, fall through to the complaint in the
13662 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
13664 struct dwarf2_loclist_baton
*baton
;
13666 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13667 sizeof (struct dwarf2_loclist_baton
));
13668 baton
->per_cu
= cu
->per_cu
;
13669 gdb_assert (baton
->per_cu
);
13671 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13672 &dwarf2_per_objfile
->loc
);
13674 /* We don't know how long the location list is, but make sure we
13675 don't run off the edge of the section. */
13676 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
13677 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
13678 baton
->base_address
= cu
->base_address
;
13679 if (cu
->base_known
== 0)
13680 complaint (&symfile_complaints
,
13681 _("Location list used without specifying the CU base address."));
13683 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13684 SYMBOL_LOCATION_BATON (sym
) = baton
;
13688 struct dwarf2_locexpr_baton
*baton
;
13690 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13691 sizeof (struct dwarf2_locexpr_baton
));
13692 baton
->per_cu
= cu
->per_cu
;
13693 gdb_assert (baton
->per_cu
);
13695 if (attr_form_is_block (attr
))
13697 /* Note that we're just copying the block's data pointer
13698 here, not the actual data. We're still pointing into the
13699 info_buffer for SYM's objfile; right now we never release
13700 that buffer, but when we do clean up properly this may
13702 baton
->size
= DW_BLOCK (attr
)->size
;
13703 baton
->data
= DW_BLOCK (attr
)->data
;
13707 dwarf2_invalid_attrib_class_complaint ("location description",
13708 SYMBOL_NATURAL_NAME (sym
));
13710 baton
->data
= NULL
;
13713 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13714 SYMBOL_LOCATION_BATON (sym
) = baton
;
13718 /* Return the OBJFILE associated with the compilation unit CU. If CU
13719 came from a separate debuginfo file, then the master objfile is
13723 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
13725 struct objfile
*objfile
= per_cu
->objfile
;
13727 /* Return the master objfile, so that we can report and look up the
13728 correct file containing this variable. */
13729 if (objfile
->separate_debug_objfile_backlink
)
13730 objfile
= objfile
->separate_debug_objfile_backlink
;
13735 /* Return the address size given in the compilation unit header for CU. */
13738 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
13741 return per_cu
->cu
->header
.addr_size
;
13744 /* If the CU is not currently read in, we re-read its header. */
13745 struct objfile
*objfile
= per_cu
->objfile
;
13746 struct dwarf2_per_objfile
*per_objfile
13747 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13748 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13749 struct comp_unit_head cu_header
;
13751 memset (&cu_header
, 0, sizeof cu_header
);
13752 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13753 return cu_header
.addr_size
;
13757 /* Return the offset size given in the compilation unit header for CU. */
13760 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
13763 return per_cu
->cu
->header
.offset_size
;
13766 /* If the CU is not currently read in, we re-read its header. */
13767 struct objfile
*objfile
= per_cu
->objfile
;
13768 struct dwarf2_per_objfile
*per_objfile
13769 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13770 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13771 struct comp_unit_head cu_header
;
13773 memset (&cu_header
, 0, sizeof cu_header
);
13774 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13775 return cu_header
.offset_size
;
13779 /* Return the text offset of the CU. The returned offset comes from
13780 this CU's objfile. If this objfile came from a separate debuginfo
13781 file, then the offset may be different from the corresponding
13782 offset in the parent objfile. */
13785 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
13787 struct objfile
*objfile
= per_cu
->objfile
;
13789 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13792 /* Locate the .debug_info compilation unit from CU's objfile which contains
13793 the DIE at OFFSET. Raises an error on failure. */
13795 static struct dwarf2_per_cu_data
*
13796 dwarf2_find_containing_comp_unit (unsigned int offset
,
13797 struct objfile
*objfile
)
13799 struct dwarf2_per_cu_data
*this_cu
;
13803 high
= dwarf2_per_objfile
->n_comp_units
- 1;
13806 int mid
= low
+ (high
- low
) / 2;
13808 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
13813 gdb_assert (low
== high
);
13814 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
13817 error (_("Dwarf Error: could not find partial DIE containing "
13818 "offset 0x%lx [in module %s]"),
13819 (long) offset
, bfd_get_filename (objfile
->obfd
));
13821 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
13822 return dwarf2_per_objfile
->all_comp_units
[low
-1];
13826 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
13827 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
13828 && offset
>= this_cu
->offset
+ this_cu
->length
)
13829 error (_("invalid dwarf2 offset %u"), offset
);
13830 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
13835 /* Locate the compilation unit from OBJFILE which is located at exactly
13836 OFFSET. Raises an error on failure. */
13838 static struct dwarf2_per_cu_data
*
13839 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
13841 struct dwarf2_per_cu_data
*this_cu
;
13843 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
13844 if (this_cu
->offset
!= offset
)
13845 error (_("no compilation unit with offset %u."), offset
);
13849 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13851 static struct dwarf2_cu
*
13852 alloc_one_comp_unit (struct objfile
*objfile
)
13854 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
13855 cu
->objfile
= objfile
;
13856 obstack_init (&cu
->comp_unit_obstack
);
13860 /* Release one cached compilation unit, CU. We unlink it from the tree
13861 of compilation units, but we don't remove it from the read_in_chain;
13862 the caller is responsible for that.
13863 NOTE: DATA is a void * because this function is also used as a
13864 cleanup routine. */
13867 free_one_comp_unit (void *data
)
13869 struct dwarf2_cu
*cu
= data
;
13871 if (cu
->per_cu
!= NULL
)
13872 cu
->per_cu
->cu
= NULL
;
13875 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13880 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13881 when we're finished with it. We can't free the pointer itself, but be
13882 sure to unlink it from the cache. Also release any associated storage
13883 and perform cache maintenance.
13885 Only used during partial symbol parsing. */
13888 free_stack_comp_unit (void *data
)
13890 struct dwarf2_cu
*cu
= data
;
13892 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13893 cu
->partial_dies
= NULL
;
13895 if (cu
->per_cu
!= NULL
)
13897 /* This compilation unit is on the stack in our caller, so we
13898 should not xfree it. Just unlink it. */
13899 cu
->per_cu
->cu
= NULL
;
13902 /* If we had a per-cu pointer, then we may have other compilation
13903 units loaded, so age them now. */
13904 age_cached_comp_units ();
13908 /* Free all cached compilation units. */
13911 free_cached_comp_units (void *data
)
13913 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13915 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13916 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13917 while (per_cu
!= NULL
)
13919 struct dwarf2_per_cu_data
*next_cu
;
13921 next_cu
= per_cu
->cu
->read_in_chain
;
13923 free_one_comp_unit (per_cu
->cu
);
13924 *last_chain
= next_cu
;
13930 /* Increase the age counter on each cached compilation unit, and free
13931 any that are too old. */
13934 age_cached_comp_units (void)
13936 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13938 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
13939 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13940 while (per_cu
!= NULL
)
13942 per_cu
->cu
->last_used
++;
13943 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
13944 dwarf2_mark (per_cu
->cu
);
13945 per_cu
= per_cu
->cu
->read_in_chain
;
13948 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13949 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13950 while (per_cu
!= NULL
)
13952 struct dwarf2_per_cu_data
*next_cu
;
13954 next_cu
= per_cu
->cu
->read_in_chain
;
13956 if (!per_cu
->cu
->mark
)
13958 free_one_comp_unit (per_cu
->cu
);
13959 *last_chain
= next_cu
;
13962 last_chain
= &per_cu
->cu
->read_in_chain
;
13968 /* Remove a single compilation unit from the cache. */
13971 free_one_cached_comp_unit (void *target_cu
)
13973 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13975 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13976 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13977 while (per_cu
!= NULL
)
13979 struct dwarf2_per_cu_data
*next_cu
;
13981 next_cu
= per_cu
->cu
->read_in_chain
;
13983 if (per_cu
->cu
== target_cu
)
13985 free_one_comp_unit (per_cu
->cu
);
13986 *last_chain
= next_cu
;
13990 last_chain
= &per_cu
->cu
->read_in_chain
;
13996 /* Release all extra memory associated with OBJFILE. */
13999 dwarf2_free_objfile (struct objfile
*objfile
)
14001 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14003 if (dwarf2_per_objfile
== NULL
)
14006 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14007 free_cached_comp_units (NULL
);
14009 if (dwarf2_per_objfile
->using_index
)
14013 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14016 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14018 if (!cu
->v
.quick
->lines
)
14021 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
14023 if (cu
->v
.quick
->file_names
)
14024 xfree ((void *) cu
->v
.quick
->file_names
[j
]);
14025 if (cu
->v
.quick
->full_names
)
14026 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
14029 free_line_header (cu
->v
.quick
->lines
);
14033 /* Everything else should be on the objfile obstack. */
14036 /* A pair of DIE offset and GDB type pointer. We store these
14037 in a hash table separate from the DIEs, and preserve them
14038 when the DIEs are flushed out of cache. */
14040 struct dwarf2_offset_and_type
14042 unsigned int offset
;
14046 /* Hash function for a dwarf2_offset_and_type. */
14049 offset_and_type_hash (const void *item
)
14051 const struct dwarf2_offset_and_type
*ofs
= item
;
14053 return ofs
->offset
;
14056 /* Equality function for a dwarf2_offset_and_type. */
14059 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14061 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14062 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14064 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14067 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14068 table if necessary. For convenience, return TYPE.
14070 The DIEs reading must have careful ordering to:
14071 * Not cause infite loops trying to read in DIEs as a prerequisite for
14072 reading current DIE.
14073 * Not trying to dereference contents of still incompletely read in types
14074 while reading in other DIEs.
14075 * Enable referencing still incompletely read in types just by a pointer to
14076 the type without accessing its fields.
14078 Therefore caller should follow these rules:
14079 * Try to fetch any prerequisite types we may need to build this DIE type
14080 before building the type and calling set_die_type.
14081 * After building typer call set_die_type for current DIE as soon as
14082 possible before fetching more types to complete the current type.
14083 * Make the type as complete as possible before fetching more types. */
14085 static struct type
*
14086 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14088 struct dwarf2_offset_and_type
**slot
, ofs
;
14090 /* For Ada types, make sure that the gnat-specific data is always
14091 initialized (if not already set). There are a few types where
14092 we should not be doing so, because the type-specific area is
14093 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14094 where the type-specific area is used to store the floatformat).
14095 But this is not a problem, because the gnat-specific information
14096 is actually not needed for these types. */
14097 if (need_gnat_info (cu
)
14098 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14099 && TYPE_CODE (type
) != TYPE_CODE_FLT
14100 && !HAVE_GNAT_AUX_INFO (type
))
14101 INIT_GNAT_SPECIFIC (type
);
14103 if (cu
->type_hash
== NULL
)
14105 gdb_assert (cu
->per_cu
!= NULL
);
14106 cu
->per_cu
->type_hash
14107 = htab_create_alloc_ex (cu
->header
.length
/ 24,
14108 offset_and_type_hash
,
14109 offset_and_type_eq
,
14111 &cu
->objfile
->objfile_obstack
,
14112 hashtab_obstack_allocate
,
14113 dummy_obstack_deallocate
);
14114 cu
->type_hash
= cu
->per_cu
->type_hash
;
14117 ofs
.offset
= die
->offset
;
14119 slot
= (struct dwarf2_offset_and_type
**)
14120 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
14122 complaint (&symfile_complaints
,
14123 _("A problem internal to GDB: DIE 0x%x has type already set"),
14125 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
14130 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
14131 not have a saved type. */
14133 static struct type
*
14134 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14136 struct dwarf2_offset_and_type
*slot
, ofs
;
14137 htab_t type_hash
= cu
->type_hash
;
14139 if (type_hash
== NULL
)
14142 ofs
.offset
= die
->offset
;
14143 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14150 /* Add a dependence relationship from CU to REF_PER_CU. */
14153 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14154 struct dwarf2_per_cu_data
*ref_per_cu
)
14158 if (cu
->dependencies
== NULL
)
14160 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14161 NULL
, &cu
->comp_unit_obstack
,
14162 hashtab_obstack_allocate
,
14163 dummy_obstack_deallocate
);
14165 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14167 *slot
= ref_per_cu
;
14170 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14171 Set the mark field in every compilation unit in the
14172 cache that we must keep because we are keeping CU. */
14175 dwarf2_mark_helper (void **slot
, void *data
)
14177 struct dwarf2_per_cu_data
*per_cu
;
14179 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14180 if (per_cu
->cu
->mark
)
14182 per_cu
->cu
->mark
= 1;
14184 if (per_cu
->cu
->dependencies
!= NULL
)
14185 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14190 /* Set the mark field in CU and in every other compilation unit in the
14191 cache that we must keep because we are keeping CU. */
14194 dwarf2_mark (struct dwarf2_cu
*cu
)
14199 if (cu
->dependencies
!= NULL
)
14200 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14204 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14208 per_cu
->cu
->mark
= 0;
14209 per_cu
= per_cu
->cu
->read_in_chain
;
14213 /* Trivial hash function for partial_die_info: the hash value of a DIE
14214 is its offset in .debug_info for this objfile. */
14217 partial_die_hash (const void *item
)
14219 const struct partial_die_info
*part_die
= item
;
14221 return part_die
->offset
;
14224 /* Trivial comparison function for partial_die_info structures: two DIEs
14225 are equal if they have the same offset. */
14228 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14230 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14231 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14233 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14236 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14237 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14240 set_dwarf2_cmd (char *args
, int from_tty
)
14242 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14246 show_dwarf2_cmd (char *args
, int from_tty
)
14248 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14251 /* If section described by INFO was mmapped, munmap it now. */
14254 munmap_section_buffer (struct dwarf2_section_info
*info
)
14256 if (info
->was_mmapped
)
14259 intptr_t begin
= (intptr_t) info
->buffer
;
14260 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14261 size_t map_length
= info
->size
+ begin
- map_begin
;
14263 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14265 /* Without HAVE_MMAP, we should never be here to begin with. */
14271 /* munmap debug sections for OBJFILE, if necessary. */
14274 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14276 struct dwarf2_per_objfile
*data
= d
;
14278 munmap_section_buffer (&data
->info
);
14279 munmap_section_buffer (&data
->abbrev
);
14280 munmap_section_buffer (&data
->line
);
14281 munmap_section_buffer (&data
->str
);
14282 munmap_section_buffer (&data
->macinfo
);
14283 munmap_section_buffer (&data
->ranges
);
14284 munmap_section_buffer (&data
->loc
);
14285 munmap_section_buffer (&data
->frame
);
14286 munmap_section_buffer (&data
->eh_frame
);
14287 munmap_section_buffer (&data
->gdb_index
);
14292 /* The contents of the hash table we create when building the string
14294 struct strtab_entry
14296 offset_type offset
;
14300 /* Hash function for a strtab_entry. */
14302 hash_strtab_entry (const void *e
)
14304 const struct strtab_entry
*entry
= e
;
14305 return mapped_index_string_hash (entry
->str
);
14308 /* Equality function for a strtab_entry. */
14310 eq_strtab_entry (const void *a
, const void *b
)
14312 const struct strtab_entry
*ea
= a
;
14313 const struct strtab_entry
*eb
= b
;
14314 return !strcmp (ea
->str
, eb
->str
);
14317 /* Create a strtab_entry hash table. */
14319 create_strtab (void)
14321 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14322 xfree
, xcalloc
, xfree
);
14325 /* Add a string to the constant pool. Return the string's offset in
14328 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14331 struct strtab_entry entry
;
14332 struct strtab_entry
*result
;
14335 slot
= htab_find_slot (table
, &entry
, INSERT
);
14340 result
= XNEW (struct strtab_entry
);
14341 result
->offset
= obstack_object_size (cpool
);
14343 obstack_grow_str0 (cpool
, str
);
14346 return result
->offset
;
14349 /* An entry in the symbol table. */
14350 struct symtab_index_entry
14352 /* The name of the symbol. */
14354 /* The offset of the name in the constant pool. */
14355 offset_type index_offset
;
14356 /* A sorted vector of the indices of all the CUs that hold an object
14358 VEC (offset_type
) *cu_indices
;
14361 /* The symbol table. This is a power-of-2-sized hash table. */
14362 struct mapped_symtab
14364 offset_type n_elements
;
14366 struct symtab_index_entry
**data
;
14369 /* Hash function for a symtab_index_entry. */
14371 hash_symtab_entry (const void *e
)
14373 const struct symtab_index_entry
*entry
= e
;
14374 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14375 sizeof (offset_type
) * VEC_length (offset_type
,
14376 entry
->cu_indices
),
14380 /* Equality function for a symtab_index_entry. */
14382 eq_symtab_entry (const void *a
, const void *b
)
14384 const struct symtab_index_entry
*ea
= a
;
14385 const struct symtab_index_entry
*eb
= b
;
14386 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14387 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14389 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14390 VEC_address (offset_type
, eb
->cu_indices
),
14391 sizeof (offset_type
) * len
);
14394 /* Destroy a symtab_index_entry. */
14396 delete_symtab_entry (void *p
)
14398 struct symtab_index_entry
*entry
= p
;
14399 VEC_free (offset_type
, entry
->cu_indices
);
14403 /* Create a hash table holding symtab_index_entry objects. */
14405 create_index_table (void)
14407 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14408 delete_symtab_entry
, xcalloc
, xfree
);
14411 /* Create a new mapped symtab object. */
14412 static struct mapped_symtab
*
14413 create_mapped_symtab (void)
14415 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14416 symtab
->n_elements
= 0;
14417 symtab
->size
= 1024;
14418 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14422 /* Destroy a mapped_symtab. */
14424 cleanup_mapped_symtab (void *p
)
14426 struct mapped_symtab
*symtab
= p
;
14427 /* The contents of the array are freed when the other hash table is
14429 xfree (symtab
->data
);
14433 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14435 static struct symtab_index_entry
**
14436 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14438 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14440 index
= hash
& (symtab
->size
- 1);
14441 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14445 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14446 return &symtab
->data
[index
];
14447 index
= (index
+ step
) & (symtab
->size
- 1);
14451 /* Expand SYMTAB's hash table. */
14453 hash_expand (struct mapped_symtab
*symtab
)
14455 offset_type old_size
= symtab
->size
;
14457 struct symtab_index_entry
**old_entries
= symtab
->data
;
14460 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14462 for (i
= 0; i
< old_size
; ++i
)
14464 if (old_entries
[i
])
14466 struct symtab_index_entry
**slot
= find_slot (symtab
,
14467 old_entries
[i
]->name
);
14468 *slot
= old_entries
[i
];
14472 xfree (old_entries
);
14475 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14476 is the index of the CU in which the symbol appears. */
14478 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
14479 offset_type cu_index
)
14481 struct symtab_index_entry
**slot
;
14483 ++symtab
->n_elements
;
14484 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
14485 hash_expand (symtab
);
14487 slot
= find_slot (symtab
, name
);
14490 *slot
= XNEW (struct symtab_index_entry
);
14491 (*slot
)->name
= name
;
14492 (*slot
)->cu_indices
= NULL
;
14494 /* Don't push an index twice. Due to how we add entries we only
14495 have to check the last one. */
14496 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
14497 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
14498 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
14501 /* Add a vector of indices to the constant pool. */
14503 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
14504 struct symtab_index_entry
*entry
)
14508 slot
= htab_find_slot (index_table
, entry
, INSERT
);
14511 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
14512 offset_type val
= MAYBE_SWAP (len
);
14517 entry
->index_offset
= obstack_object_size (cpool
);
14519 obstack_grow (cpool
, &val
, sizeof (val
));
14521 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
14524 val
= MAYBE_SWAP (iter
);
14525 obstack_grow (cpool
, &val
, sizeof (val
));
14530 struct symtab_index_entry
*old_entry
= *slot
;
14531 entry
->index_offset
= old_entry
->index_offset
;
14534 return entry
->index_offset
;
14537 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14538 constant pool entries going into the obstack CPOOL. */
14540 write_hash_table (struct mapped_symtab
*symtab
,
14541 struct obstack
*output
, struct obstack
*cpool
)
14544 htab_t index_table
;
14547 index_table
= create_index_table ();
14548 str_table
= create_strtab ();
14549 /* We add all the index vectors to the constant pool first, to
14550 ensure alignment is ok. */
14551 for (i
= 0; i
< symtab
->size
; ++i
)
14553 if (symtab
->data
[i
])
14554 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
14557 /* Now write out the hash table. */
14558 for (i
= 0; i
< symtab
->size
; ++i
)
14560 offset_type str_off
, vec_off
;
14562 if (symtab
->data
[i
])
14564 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
14565 vec_off
= symtab
->data
[i
]->index_offset
;
14569 /* While 0 is a valid constant pool index, it is not valid
14570 to have 0 for both offsets. */
14575 str_off
= MAYBE_SWAP (str_off
);
14576 vec_off
= MAYBE_SWAP (vec_off
);
14578 obstack_grow (output
, &str_off
, sizeof (str_off
));
14579 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
14582 htab_delete (str_table
);
14583 htab_delete (index_table
);
14586 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14587 from PST; CU_INDEX is the index of the CU in the vector of all
14590 add_address_entry (struct objfile
*objfile
,
14591 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
14592 unsigned int cu_index
)
14594 offset_type offset
;
14596 CORE_ADDR baseaddr
;
14598 /* Don't bother recording empty ranges. */
14599 if (pst
->textlow
== pst
->texthigh
)
14602 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14604 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
14605 obstack_grow (addr_obstack
, addr
, 8);
14606 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
14607 obstack_grow (addr_obstack
, addr
, 8);
14608 offset
= MAYBE_SWAP (cu_index
);
14609 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
14612 /* Add a list of partial symbols to SYMTAB. */
14614 write_psymbols (struct mapped_symtab
*symtab
,
14615 struct partial_symbol
**psymp
,
14617 offset_type cu_index
)
14619 for (; count
-- > 0; ++psymp
)
14621 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
14622 error (_("Ada is not currently supported by the index"));
14623 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
14627 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14628 exception if there is an error. */
14630 write_obstack (FILE *file
, struct obstack
*obstack
)
14632 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
14634 != obstack_object_size (obstack
))
14635 error (_("couldn't data write to file"));
14638 /* Unlink a file if the argument is not NULL. */
14640 unlink_if_set (void *p
)
14642 char **filename
= p
;
14644 unlink (*filename
);
14647 /* A helper struct used when iterating over debug_types. */
14648 struct signatured_type_index_data
14650 struct objfile
*objfile
;
14651 struct mapped_symtab
*symtab
;
14652 struct obstack
*types_list
;
14656 /* A helper function that writes a single signatured_type to an
14659 write_one_signatured_type (void **slot
, void *d
)
14661 struct signatured_type_index_data
*info
= d
;
14662 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
14663 struct dwarf2_per_cu_data
*cu
= &entry
->per_cu
;
14664 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14667 write_psymbols (info
->symtab
,
14668 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14669 psymtab
->n_global_syms
, info
->cu_index
);
14670 write_psymbols (info
->symtab
,
14671 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14672 psymtab
->n_static_syms
, info
->cu_index
);
14674 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
14675 obstack_grow (info
->types_list
, val
, 8);
14676 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
14677 obstack_grow (info
->types_list
, val
, 8);
14678 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
14679 obstack_grow (info
->types_list
, val
, 8);
14686 /* Create an index file for OBJFILE in the directory DIR. */
14688 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
14690 struct cleanup
*cleanup
;
14691 char *filename
, *cleanup_filename
;
14692 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
14693 struct obstack cu_list
, types_cu_list
;
14696 struct mapped_symtab
*symtab
;
14697 offset_type val
, size_of_contents
, total_len
;
14701 if (!objfile
->psymtabs
)
14703 if (dwarf2_per_objfile
->using_index
)
14704 error (_("Cannot use an index to create the index"));
14706 if (stat (objfile
->name
, &st
) < 0)
14707 perror_with_name (_("Could not stat"));
14709 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
14710 INDEX_SUFFIX
, (char *) NULL
);
14711 cleanup
= make_cleanup (xfree
, filename
);
14713 out_file
= fopen (filename
, "wb");
14715 error (_("Can't open `%s' for writing"), filename
);
14717 cleanup_filename
= filename
;
14718 make_cleanup (unlink_if_set
, &cleanup_filename
);
14720 symtab
= create_mapped_symtab ();
14721 make_cleanup (cleanup_mapped_symtab
, symtab
);
14723 obstack_init (&addr_obstack
);
14724 make_cleanup_obstack_free (&addr_obstack
);
14726 obstack_init (&cu_list
);
14727 make_cleanup_obstack_free (&cu_list
);
14729 obstack_init (&types_cu_list
);
14730 make_cleanup_obstack_free (&types_cu_list
);
14732 /* The list is already sorted, so we don't need to do additional
14733 work here. Also, the debug_types entries do not appear in
14734 all_comp_units, but only in their own hash table. */
14735 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14737 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14738 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14741 write_psymbols (symtab
,
14742 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14743 psymtab
->n_global_syms
, i
);
14744 write_psymbols (symtab
,
14745 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14746 psymtab
->n_static_syms
, i
);
14748 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
14750 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->offset
);
14751 obstack_grow (&cu_list
, val
, 8);
14752 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->length
);
14753 obstack_grow (&cu_list
, val
, 8);
14756 /* Write out the .debug_type entries, if any. */
14757 if (dwarf2_per_objfile
->signatured_types
)
14759 struct signatured_type_index_data sig_data
;
14761 sig_data
.objfile
= objfile
;
14762 sig_data
.symtab
= symtab
;
14763 sig_data
.types_list
= &types_cu_list
;
14764 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
14765 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
14766 write_one_signatured_type
, &sig_data
);
14769 obstack_init (&constant_pool
);
14770 make_cleanup_obstack_free (&constant_pool
);
14771 obstack_init (&symtab_obstack
);
14772 make_cleanup_obstack_free (&symtab_obstack
);
14773 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
14775 obstack_init (&contents
);
14776 make_cleanup_obstack_free (&contents
);
14777 size_of_contents
= 6 * sizeof (offset_type
);
14778 total_len
= size_of_contents
;
14780 /* The version number. */
14781 val
= MAYBE_SWAP (2);
14782 obstack_grow (&contents
, &val
, sizeof (val
));
14784 /* The offset of the CU list from the start of the file. */
14785 val
= MAYBE_SWAP (total_len
);
14786 obstack_grow (&contents
, &val
, sizeof (val
));
14787 total_len
+= obstack_object_size (&cu_list
);
14789 /* The offset of the types CU list from the start of the file. */
14790 val
= MAYBE_SWAP (total_len
);
14791 obstack_grow (&contents
, &val
, sizeof (val
));
14792 total_len
+= obstack_object_size (&types_cu_list
);
14794 /* The offset of the address table from the start of the file. */
14795 val
= MAYBE_SWAP (total_len
);
14796 obstack_grow (&contents
, &val
, sizeof (val
));
14797 total_len
+= obstack_object_size (&addr_obstack
);
14799 /* The offset of the symbol table from the start of the file. */
14800 val
= MAYBE_SWAP (total_len
);
14801 obstack_grow (&contents
, &val
, sizeof (val
));
14802 total_len
+= obstack_object_size (&symtab_obstack
);
14804 /* The offset of the constant pool from the start of the file. */
14805 val
= MAYBE_SWAP (total_len
);
14806 obstack_grow (&contents
, &val
, sizeof (val
));
14807 total_len
+= obstack_object_size (&constant_pool
);
14809 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
14811 write_obstack (out_file
, &contents
);
14812 write_obstack (out_file
, &cu_list
);
14813 write_obstack (out_file
, &types_cu_list
);
14814 write_obstack (out_file
, &addr_obstack
);
14815 write_obstack (out_file
, &symtab_obstack
);
14816 write_obstack (out_file
, &constant_pool
);
14820 /* We want to keep the file, so we set cleanup_filename to NULL
14821 here. See unlink_if_set. */
14822 cleanup_filename
= NULL
;
14824 do_cleanups (cleanup
);
14827 /* The mapped index file format is designed to be directly mmap()able
14828 on any architecture. In most cases, a datum is represented using a
14829 little-endian 32-bit integer value, called an offset_type. Big
14830 endian machines must byte-swap the values before using them.
14831 Exceptions to this rule are noted. The data is laid out such that
14832 alignment is always respected.
14834 A mapped index consists of several sections.
14836 1. The file header. This is a sequence of values, of offset_type
14837 unless otherwise noted:
14838 [0] The version number. Currently 1 or 2. The differences are
14839 noted below. Version 1 did not account for .debug_types sections;
14840 the presence of a .debug_types section invalidates any version 1
14841 index that may exist.
14842 [1] The offset, from the start of the file, of the CU list.
14843 [1.5] In version 2, the offset, from the start of the file, of the
14844 types CU list. This offset does not appear in version 1. Note
14845 that this can be empty, in which case this offset will be equal to
14847 [2] The offset, from the start of the file, of the address section.
14848 [3] The offset, from the start of the file, of the symbol table.
14849 [4] The offset, from the start of the file, of the constant pool.
14851 2. The CU list. This is a sequence of pairs of 64-bit
14852 little-endian values, sorted by the CU offset. The first element
14853 in each pair is the offset of a CU in the .debug_info section. The
14854 second element in each pair is the length of that CU. References
14855 to a CU elsewhere in the map are done using a CU index, which is
14856 just the 0-based index into this table. Note that if there are
14857 type CUs, then conceptually CUs and type CUs form a single list for
14858 the purposes of CU indices.
14860 2.5 The types CU list. This does not appear in a version 1 index.
14861 This is a sequence of triplets of 64-bit little-endian values. In
14862 a triplet, the first value is the CU offset, the second value is
14863 the type offset in the CU, and the third value is the type
14864 signature. The types CU list is not sorted.
14866 3. The address section. The address section consists of a sequence
14867 of address entries. Each address entry has three elements.
14868 [0] The low address. This is a 64-bit little-endian value.
14869 [1] The high address. This is a 64-bit little-endian value.
14870 [2] The CU index. This is an offset_type value.
14872 4. The symbol table. This is a hash table. The size of the hash
14873 table is always a power of 2. The initial hash and the step are
14874 currently defined by the `find_slot' function.
14876 Each slot in the hash table consists of a pair of offset_type
14877 values. The first value is the offset of the symbol's name in the
14878 constant pool. The second value is the offset of the CU vector in
14881 If both values are 0, then this slot in the hash table is empty.
14882 This is ok because while 0 is a valid constant pool index, it
14883 cannot be a valid index for both a string and a CU vector.
14885 A string in the constant pool is stored as a \0-terminated string,
14888 A CU vector in the constant pool is a sequence of offset_type
14889 values. The first value is the number of CU indices in the vector.
14890 Each subsequent value is the index of a CU in the CU list. This
14891 element in the hash table is used to indicate which CUs define the
14894 5. The constant pool. This is simply a bunch of bytes. It is
14895 organized so that alignment is correct: CU vectors are stored
14896 first, followed by strings. */
14898 save_gdb_index_command (char *arg
, int from_tty
)
14900 struct objfile
*objfile
;
14903 error (_("usage: save gdb-index DIRECTORY"));
14905 ALL_OBJFILES (objfile
)
14909 /* If the objfile does not correspond to an actual file, skip it. */
14910 if (stat (objfile
->name
, &st
) < 0)
14913 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14914 if (dwarf2_per_objfile
)
14916 volatile struct gdb_exception except
;
14918 TRY_CATCH (except
, RETURN_MASK_ERROR
)
14920 write_psymtabs_to_index (objfile
, arg
);
14922 if (except
.reason
< 0)
14923 exception_fprintf (gdb_stderr
, except
,
14924 _("Error while writing index for `%s': "),
14932 int dwarf2_always_disassemble
;
14935 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
14936 struct cmd_list_element
*c
, const char *value
)
14938 fprintf_filtered (file
, _("\
14939 Whether to always disassemble DWARF expressions is %s.\n"),
14943 void _initialize_dwarf2_read (void);
14946 _initialize_dwarf2_read (void)
14948 struct cmd_list_element
*c
;
14950 dwarf2_objfile_data_key
14951 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
14953 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
14954 Set DWARF 2 specific variables.\n\
14955 Configure DWARF 2 variables such as the cache size"),
14956 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
14957 0/*allow-unknown*/, &maintenance_set_cmdlist
);
14959 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
14960 Show DWARF 2 specific variables\n\
14961 Show DWARF 2 variables such as the cache size"),
14962 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
14963 0/*allow-unknown*/, &maintenance_show_cmdlist
);
14965 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
14966 &dwarf2_max_cache_age
, _("\
14967 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
14968 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
14969 A higher limit means that cached compilation units will be stored\n\
14970 in memory longer, and more total memory will be used. Zero disables\n\
14971 caching, which can slow down startup."),
14973 show_dwarf2_max_cache_age
,
14974 &set_dwarf2_cmdlist
,
14975 &show_dwarf2_cmdlist
);
14977 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
14978 &dwarf2_always_disassemble
, _("\
14979 Set whether `info address' always disassembles DWARF expressions."), _("\
14980 Show whether `info address' always disassembles DWARF expressions."), _("\
14981 When enabled, DWARF expressions are always printed in an assembly-like\n\
14982 syntax. When disabled, expressions will be printed in a more\n\
14983 conversational style, when possible."),
14985 show_dwarf2_always_disassemble
,
14986 &set_dwarf2_cmdlist
,
14987 &show_dwarf2_cmdlist
);
14989 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
14990 Set debugging of the dwarf2 DIE reader."), _("\
14991 Show debugging of the dwarf2 DIE reader."), _("\
14992 When enabled (non-zero), DIEs are dumped after they are read in.\n\
14993 The value is the maximum depth to print."),
14996 &setdebuglist
, &showdebuglist
);
14998 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
14999 _("Save a .gdb-index file"),
15001 set_cmd_completer (c
, filename_completer
);