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 symbol table, implemented as a hash table. */
158 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_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 or we are faking it for OBJF_READNOW's sake. */
209 unsigned char using_index
;
211 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
212 struct mapped_index
*index_table
;
214 /* When using index_table, this keeps track of all quick_file_names entries.
215 TUs can share line table entries with CUs or other TUs, and there can be
216 a lot more TUs than unique line tables, so we maintain a separate table
217 of all line table entries to support the sharing. */
218 htab_t quick_file_names_table
;
220 /* Set during partial symbol reading, to prevent queueing of full
222 int reading_partial_symbols
;
224 /* Table mapping type .debug_info DIE offsets to types.
225 This is NULL if not allocated yet.
226 It (currently) makes sense to allocate debug_types_type_hash lazily.
227 To keep things simple we allocate both lazily. */
228 htab_t debug_info_type_hash
;
230 /* Table mapping type .debug_types DIE offsets to types.
231 This is NULL if not allocated yet. */
232 htab_t debug_types_type_hash
;
235 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
237 /* names of the debugging sections */
239 /* Note that if the debugging section has been compressed, it might
240 have a name like .zdebug_info. */
242 #define INFO_SECTION "debug_info"
243 #define ABBREV_SECTION "debug_abbrev"
244 #define LINE_SECTION "debug_line"
245 #define LOC_SECTION "debug_loc"
246 #define MACINFO_SECTION "debug_macinfo"
247 #define STR_SECTION "debug_str"
248 #define RANGES_SECTION "debug_ranges"
249 #define TYPES_SECTION "debug_types"
250 #define FRAME_SECTION "debug_frame"
251 #define EH_FRAME_SECTION "eh_frame"
252 #define GDB_INDEX_SECTION "gdb_index"
254 /* local data types */
256 /* We hold several abbreviation tables in memory at the same time. */
257 #ifndef ABBREV_HASH_SIZE
258 #define ABBREV_HASH_SIZE 121
261 /* The data in a compilation unit header, after target2host
262 translation, looks like this. */
263 struct comp_unit_head
267 unsigned char addr_size
;
268 unsigned char signed_addr_p
;
269 unsigned int abbrev_offset
;
271 /* Size of file offsets; either 4 or 8. */
272 unsigned int offset_size
;
274 /* Size of the length field; either 4 or 12. */
275 unsigned int initial_length_size
;
277 /* Offset to the first byte of this compilation unit header in the
278 .debug_info section, for resolving relative reference dies. */
281 /* Offset to first die in this cu from the start of the cu.
282 This will be the first byte following the compilation unit header. */
283 unsigned int first_die_offset
;
286 /* Type used for delaying computation of method physnames.
287 See comments for compute_delayed_physnames. */
288 struct delayed_method_info
290 /* The type to which the method is attached, i.e., its parent class. */
293 /* The index of the method in the type's function fieldlists. */
296 /* The index of the method in the fieldlist. */
299 /* The name of the DIE. */
302 /* The DIE associated with this method. */
303 struct die_info
*die
;
306 typedef struct delayed_method_info delayed_method_info
;
307 DEF_VEC_O (delayed_method_info
);
309 /* Internal state when decoding a particular compilation unit. */
312 /* The objfile containing this compilation unit. */
313 struct objfile
*objfile
;
315 /* The header of the compilation unit. */
316 struct comp_unit_head header
;
318 /* Base address of this compilation unit. */
319 CORE_ADDR base_address
;
321 /* Non-zero if base_address has been set. */
324 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
326 /* The language we are debugging. */
327 enum language language
;
328 const struct language_defn
*language_defn
;
330 const char *producer
;
332 /* The generic symbol table building routines have separate lists for
333 file scope symbols and all all other scopes (local scopes). So
334 we need to select the right one to pass to add_symbol_to_list().
335 We do it by keeping a pointer to the correct list in list_in_scope.
337 FIXME: The original dwarf code just treated the file scope as the
338 first local scope, and all other local scopes as nested local
339 scopes, and worked fine. Check to see if we really need to
340 distinguish these in buildsym.c. */
341 struct pending
**list_in_scope
;
343 /* DWARF abbreviation table associated with this compilation unit. */
344 struct abbrev_info
**dwarf2_abbrevs
;
346 /* Storage for the abbrev table. */
347 struct obstack abbrev_obstack
;
349 /* Hash table holding all the loaded partial DIEs. */
352 /* Storage for things with the same lifetime as this read-in compilation
353 unit, including partial DIEs. */
354 struct obstack comp_unit_obstack
;
356 /* When multiple dwarf2_cu structures are living in memory, this field
357 chains them all together, so that they can be released efficiently.
358 We will probably also want a generation counter so that most-recently-used
359 compilation units are cached... */
360 struct dwarf2_per_cu_data
*read_in_chain
;
362 /* Backchain to our per_cu entry if the tree has been built. */
363 struct dwarf2_per_cu_data
*per_cu
;
365 /* How many compilation units ago was this CU last referenced? */
368 /* A hash table of die offsets for following references. */
371 /* Full DIEs if read in. */
372 struct die_info
*dies
;
374 /* A set of pointers to dwarf2_per_cu_data objects for compilation
375 units referenced by this one. Only set during full symbol processing;
376 partial symbol tables do not have dependencies. */
379 /* Header data from the line table, during full symbol processing. */
380 struct line_header
*line_header
;
382 /* A list of methods which need to have physnames computed
383 after all type information has been read. */
384 VEC (delayed_method_info
) *method_list
;
386 /* Mark used when releasing cached dies. */
387 unsigned int mark
: 1;
389 /* This flag will be set if this compilation unit might include
390 inter-compilation-unit references. */
391 unsigned int has_form_ref_addr
: 1;
393 /* This flag will be set if this compilation unit includes any
394 DW_TAG_namespace DIEs. If we know that there are explicit
395 DIEs for namespaces, we don't need to try to infer them
396 from mangled names. */
397 unsigned int has_namespace_info
: 1;
400 /* Persistent data held for a compilation unit, even when not
401 processing it. We put a pointer to this structure in the
402 read_symtab_private field of the psymtab. If we encounter
403 inter-compilation-unit references, we also maintain a sorted
404 list of all compilation units. */
406 struct dwarf2_per_cu_data
408 /* The start offset and length of this compilation unit. 2**29-1
409 bytes should suffice to store the length of any compilation unit
410 - if it doesn't, GDB will fall over anyway.
411 NOTE: Unlike comp_unit_head.length, this length includes
412 initial_length_size. */
414 unsigned int length
: 29;
416 /* Flag indicating this compilation unit will be read in before
417 any of the current compilation units are processed. */
418 unsigned int queued
: 1;
420 /* This flag will be set if we need to load absolutely all DIEs
421 for this compilation unit, instead of just the ones we think
422 are interesting. It gets set if we look for a DIE in the
423 hash table and don't find it. */
424 unsigned int load_all_dies
: 1;
426 /* Non-zero if this CU is from .debug_types.
427 Otherwise it's from .debug_info. */
428 unsigned int from_debug_types
: 1;
430 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
431 of the CU cache it gets reset to NULL again. */
432 struct dwarf2_cu
*cu
;
434 /* The corresponding objfile. */
435 struct objfile
*objfile
;
437 /* When using partial symbol tables, the 'psymtab' field is active.
438 Otherwise the 'quick' field is active. */
441 /* The partial symbol table associated with this compilation unit,
442 or NULL for partial units (which do not have an associated
444 struct partial_symtab
*psymtab
;
446 /* Data needed by the "quick" functions. */
447 struct dwarf2_per_cu_quick_data
*quick
;
451 /* Entry in the signatured_types hash table. */
453 struct signatured_type
457 /* Offset in .debug_types of the TU (type_unit) for this type. */
460 /* Offset in .debug_types of the type defined by this TU. */
461 unsigned int type_offset
;
463 /* The CU(/TU) of this type. */
464 struct dwarf2_per_cu_data per_cu
;
467 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
468 which are used for both .debug_info and .debug_types dies.
469 All parameters here are unchanging for the life of the call.
470 This struct exists to abstract away the constant parameters of
473 struct die_reader_specs
475 /* The bfd of this objfile. */
478 /* The CU of the DIE we are parsing. */
479 struct dwarf2_cu
*cu
;
481 /* Pointer to start of section buffer.
482 This is either the start of .debug_info or .debug_types. */
483 const gdb_byte
*buffer
;
486 /* The line number information for a compilation unit (found in the
487 .debug_line section) begins with a "statement program header",
488 which contains the following information. */
491 unsigned int total_length
;
492 unsigned short version
;
493 unsigned int header_length
;
494 unsigned char minimum_instruction_length
;
495 unsigned char maximum_ops_per_instruction
;
496 unsigned char default_is_stmt
;
498 unsigned char line_range
;
499 unsigned char opcode_base
;
501 /* standard_opcode_lengths[i] is the number of operands for the
502 standard opcode whose value is i. This means that
503 standard_opcode_lengths[0] is unused, and the last meaningful
504 element is standard_opcode_lengths[opcode_base - 1]. */
505 unsigned char *standard_opcode_lengths
;
507 /* The include_directories table. NOTE! These strings are not
508 allocated with xmalloc; instead, they are pointers into
509 debug_line_buffer. If you try to free them, `free' will get
511 unsigned int num_include_dirs
, include_dirs_size
;
514 /* The file_names table. NOTE! These strings are not allocated
515 with xmalloc; instead, they are pointers into debug_line_buffer.
516 Don't try to free them directly. */
517 unsigned int num_file_names
, file_names_size
;
521 unsigned int dir_index
;
522 unsigned int mod_time
;
524 int included_p
; /* Non-zero if referenced by the Line Number Program. */
525 struct symtab
*symtab
; /* The associated symbol table, if any. */
528 /* The start and end of the statement program following this
529 header. These point into dwarf2_per_objfile->line_buffer. */
530 gdb_byte
*statement_program_start
, *statement_program_end
;
533 /* When we construct a partial symbol table entry we only
534 need this much information. */
535 struct partial_die_info
537 /* Offset of this DIE. */
540 /* DWARF-2 tag for this DIE. */
541 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
543 /* Assorted flags describing the data found in this DIE. */
544 unsigned int has_children
: 1;
545 unsigned int is_external
: 1;
546 unsigned int is_declaration
: 1;
547 unsigned int has_type
: 1;
548 unsigned int has_specification
: 1;
549 unsigned int has_pc_info
: 1;
551 /* Flag set if the SCOPE field of this structure has been
553 unsigned int scope_set
: 1;
555 /* Flag set if the DIE has a byte_size attribute. */
556 unsigned int has_byte_size
: 1;
558 /* Flag set if any of the DIE's children are template arguments. */
559 unsigned int has_template_arguments
: 1;
561 /* Flag set if fixup_partial_die has been called on this die. */
562 unsigned int fixup_called
: 1;
564 /* The name of this DIE. Normally the value of DW_AT_name, but
565 sometimes a default name for unnamed DIEs. */
568 /* The linkage name, if present. */
569 const char *linkage_name
;
571 /* The scope to prepend to our children. This is generally
572 allocated on the comp_unit_obstack, so will disappear
573 when this compilation unit leaves the cache. */
576 /* The location description associated with this DIE, if any. */
577 struct dwarf_block
*locdesc
;
579 /* If HAS_PC_INFO, the PC range associated with this DIE. */
583 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
584 DW_AT_sibling, if any. */
585 /* NOTE: This member isn't strictly necessary, read_partial_die could
586 return DW_AT_sibling values to its caller load_partial_dies. */
589 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
590 DW_AT_specification (or DW_AT_abstract_origin or
592 unsigned int spec_offset
;
594 /* Pointers to this DIE's parent, first child, and next sibling,
596 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
599 /* This data structure holds the information of an abbrev. */
602 unsigned int number
; /* number identifying abbrev */
603 enum dwarf_tag tag
; /* dwarf tag */
604 unsigned short has_children
; /* boolean */
605 unsigned short num_attrs
; /* number of attributes */
606 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
607 struct abbrev_info
*next
; /* next in chain */
612 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
613 ENUM_BITFIELD(dwarf_form
) form
: 16;
616 /* Attributes have a name and a value */
619 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
620 ENUM_BITFIELD(dwarf_form
) form
: 15;
622 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
623 field should be in u.str (existing only for DW_STRING) but it is kept
624 here for better struct attribute alignment. */
625 unsigned int string_is_canonical
: 1;
630 struct dwarf_block
*blk
;
634 struct signatured_type
*signatured_type
;
639 /* This data structure holds a complete die structure. */
642 /* DWARF-2 tag for this DIE. */
643 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
645 /* Number of attributes */
646 unsigned char num_attrs
;
648 /* True if we're presently building the full type name for the
649 type derived from this DIE. */
650 unsigned char building_fullname
: 1;
655 /* Offset in .debug_info or .debug_types section. */
658 /* The dies in a compilation unit form an n-ary tree. PARENT
659 points to this die's parent; CHILD points to the first child of
660 this node; and all the children of a given node are chained
661 together via their SIBLING fields. */
662 struct die_info
*child
; /* Its first child, if any. */
663 struct die_info
*sibling
; /* Its next sibling, if any. */
664 struct die_info
*parent
; /* Its parent, if any. */
666 /* An array of attributes, with NUM_ATTRS elements. There may be
667 zero, but it's not common and zero-sized arrays are not
668 sufficiently portable C. */
669 struct attribute attrs
[1];
672 struct function_range
675 CORE_ADDR lowpc
, highpc
;
677 struct function_range
*next
;
680 /* Get at parts of an attribute structure */
682 #define DW_STRING(attr) ((attr)->u.str)
683 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
684 #define DW_UNSND(attr) ((attr)->u.unsnd)
685 #define DW_BLOCK(attr) ((attr)->u.blk)
686 #define DW_SND(attr) ((attr)->u.snd)
687 #define DW_ADDR(attr) ((attr)->u.addr)
688 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
690 /* Blocks are a bunch of untyped bytes. */
697 #ifndef ATTR_ALLOC_CHUNK
698 #define ATTR_ALLOC_CHUNK 4
701 /* Allocate fields for structs, unions and enums in this size. */
702 #ifndef DW_FIELD_ALLOC_CHUNK
703 #define DW_FIELD_ALLOC_CHUNK 4
706 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
707 but this would require a corresponding change in unpack_field_as_long
709 static int bits_per_byte
= 8;
711 /* The routines that read and process dies for a C struct or C++ class
712 pass lists of data member fields and lists of member function fields
713 in an instance of a field_info structure, as defined below. */
716 /* List of data member and baseclasses fields. */
719 struct nextfield
*next
;
724 *fields
, *baseclasses
;
726 /* Number of fields (including baseclasses). */
729 /* Number of baseclasses. */
732 /* Set if the accesibility of one of the fields is not public. */
733 int non_public_fields
;
735 /* Member function fields array, entries are allocated in the order they
736 are encountered in the object file. */
739 struct nextfnfield
*next
;
740 struct fn_field fnfield
;
744 /* Member function fieldlist array, contains name of possibly overloaded
745 member function, number of overloaded member functions and a pointer
746 to the head of the member function field chain. */
751 struct nextfnfield
*head
;
755 /* Number of entries in the fnfieldlists array. */
758 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
759 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
760 struct typedef_field_list
762 struct typedef_field field
;
763 struct typedef_field_list
*next
;
766 unsigned typedef_field_list_count
;
769 /* One item on the queue of compilation units to read in full symbols
771 struct dwarf2_queue_item
773 struct dwarf2_per_cu_data
*per_cu
;
774 struct dwarf2_queue_item
*next
;
777 /* The current queue. */
778 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
780 /* Loaded secondary compilation units are kept in memory until they
781 have not been referenced for the processing of this many
782 compilation units. Set this to zero to disable caching. Cache
783 sizes of up to at least twenty will improve startup time for
784 typical inter-CU-reference binaries, at an obvious memory cost. */
785 static int dwarf2_max_cache_age
= 5;
787 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
788 struct cmd_list_element
*c
, const char *value
)
790 fprintf_filtered (file
, _("\
791 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
796 /* Various complaints about symbol reading that don't abort the process */
799 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
801 complaint (&symfile_complaints
,
802 _("statement list doesn't fit in .debug_line section"));
806 dwarf2_debug_line_missing_file_complaint (void)
808 complaint (&symfile_complaints
,
809 _(".debug_line section has line data without a file"));
813 dwarf2_debug_line_missing_end_sequence_complaint (void)
815 complaint (&symfile_complaints
,
816 _(".debug_line section has line program sequence without an end"));
820 dwarf2_complex_location_expr_complaint (void)
822 complaint (&symfile_complaints
, _("location expression too complex"));
826 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
829 complaint (&symfile_complaints
,
830 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
835 dwarf2_macros_too_long_complaint (void)
837 complaint (&symfile_complaints
,
838 _("macro info runs off end of `.debug_macinfo' section"));
842 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
844 complaint (&symfile_complaints
,
845 _("macro debug info contains a malformed macro definition:\n`%s'"),
850 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
852 complaint (&symfile_complaints
,
853 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
856 /* local function prototypes */
858 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
860 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
863 static void dwarf2_build_psymtabs_hard (struct objfile
*);
865 static void scan_partial_symbols (struct partial_die_info
*,
866 CORE_ADDR
*, CORE_ADDR
*,
867 int, struct dwarf2_cu
*);
869 static void add_partial_symbol (struct partial_die_info
*,
872 static void add_partial_namespace (struct partial_die_info
*pdi
,
873 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
874 int need_pc
, struct dwarf2_cu
*cu
);
876 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
877 CORE_ADDR
*highpc
, int need_pc
,
878 struct dwarf2_cu
*cu
);
880 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
881 struct dwarf2_cu
*cu
);
883 static void add_partial_subprogram (struct partial_die_info
*pdi
,
884 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
885 int need_pc
, struct dwarf2_cu
*cu
);
887 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
888 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
889 bfd
*abfd
, struct dwarf2_cu
*cu
);
891 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
893 static void psymtab_to_symtab_1 (struct partial_symtab
*);
895 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
897 static void dwarf2_free_abbrev_table (void *);
899 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
902 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
905 static struct partial_die_info
*load_partial_dies (bfd
*,
906 gdb_byte
*, gdb_byte
*,
907 int, struct dwarf2_cu
*);
909 static gdb_byte
*read_partial_die (struct partial_die_info
*,
910 struct abbrev_info
*abbrev
,
912 gdb_byte
*, gdb_byte
*,
915 static struct partial_die_info
*find_partial_die (unsigned int,
918 static void fixup_partial_die (struct partial_die_info
*,
921 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
922 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
924 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
925 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
927 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
929 static int read_1_signed_byte (bfd
*, gdb_byte
*);
931 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
933 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
935 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
937 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
940 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
942 static LONGEST read_checked_initial_length_and_offset
943 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
944 unsigned int *, unsigned int *);
946 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
949 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
951 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
953 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
955 static char *read_indirect_string (bfd
*, gdb_byte
*,
956 const struct comp_unit_head
*,
959 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
961 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
963 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
965 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
967 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
970 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
974 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
975 struct dwarf2_cu
*cu
);
977 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
979 static struct die_info
*die_specification (struct die_info
*die
,
980 struct dwarf2_cu
**);
982 static void free_line_header (struct line_header
*lh
);
984 static void add_file_name (struct line_header
*, char *, unsigned int,
985 unsigned int, unsigned int);
987 static struct line_header
*(dwarf_decode_line_header
988 (unsigned int offset
,
989 bfd
*abfd
, struct dwarf2_cu
*cu
));
991 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
992 struct dwarf2_cu
*, struct partial_symtab
*);
994 static void dwarf2_start_subfile (char *, const char *, const char *);
996 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
999 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1000 struct dwarf2_cu
*, struct symbol
*);
1002 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1003 struct dwarf2_cu
*);
1005 static void dwarf2_const_value_attr (struct attribute
*attr
,
1008 struct obstack
*obstack
,
1009 struct dwarf2_cu
*cu
, long *value
,
1011 struct dwarf2_locexpr_baton
**baton
);
1013 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1015 static int need_gnat_info (struct dwarf2_cu
*);
1017 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
1019 static void set_descriptive_type (struct type
*, struct die_info
*,
1020 struct dwarf2_cu
*);
1022 static struct type
*die_containing_type (struct die_info
*,
1023 struct dwarf2_cu
*);
1025 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1026 struct dwarf2_cu
*);
1028 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1030 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1032 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1034 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1035 const char *suffix
, int physname
,
1036 struct dwarf2_cu
*cu
);
1038 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1040 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1042 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1044 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1046 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1047 struct dwarf2_cu
*, struct partial_symtab
*);
1049 static int dwarf2_get_pc_bounds (struct die_info
*,
1050 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1051 struct partial_symtab
*);
1053 static void get_scope_pc_bounds (struct die_info
*,
1054 CORE_ADDR
*, CORE_ADDR
*,
1055 struct dwarf2_cu
*);
1057 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1058 CORE_ADDR
, struct dwarf2_cu
*);
1060 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1061 struct dwarf2_cu
*);
1063 static void dwarf2_attach_fields_to_type (struct field_info
*,
1064 struct type
*, struct dwarf2_cu
*);
1066 static void dwarf2_add_member_fn (struct field_info
*,
1067 struct die_info
*, struct type
*,
1068 struct dwarf2_cu
*);
1070 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1071 struct type
*, struct dwarf2_cu
*);
1073 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1075 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1077 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1079 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1081 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1083 static struct type
*read_module_type (struct die_info
*die
,
1084 struct dwarf2_cu
*cu
);
1086 static const char *namespace_name (struct die_info
*die
,
1087 int *is_anonymous
, struct dwarf2_cu
*);
1089 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1091 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1093 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1094 struct dwarf2_cu
*);
1096 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1098 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1100 gdb_byte
**new_info_ptr
,
1101 struct die_info
*parent
);
1103 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1105 gdb_byte
**new_info_ptr
,
1106 struct die_info
*parent
);
1108 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1110 gdb_byte
**new_info_ptr
,
1111 struct die_info
*parent
);
1113 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1114 struct die_info
**, gdb_byte
*,
1117 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1119 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1122 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1124 static const char *dwarf2_full_name (char *name
,
1125 struct die_info
*die
,
1126 struct dwarf2_cu
*cu
);
1128 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1129 struct dwarf2_cu
**);
1131 static char *dwarf_tag_name (unsigned int);
1133 static char *dwarf_attr_name (unsigned int);
1135 static char *dwarf_form_name (unsigned int);
1137 static char *dwarf_bool_name (unsigned int);
1139 static char *dwarf_type_encoding_name (unsigned int);
1142 static char *dwarf_cfi_name (unsigned int);
1145 static struct die_info
*sibling_die (struct die_info
*);
1147 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1149 static void dump_die_for_error (struct die_info
*);
1151 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1154 /*static*/ void dump_die (struct die_info
*, int max_level
);
1156 static void store_in_ref_table (struct die_info
*,
1157 struct dwarf2_cu
*);
1159 static int is_ref_attr (struct attribute
*);
1161 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1163 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1165 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1167 struct dwarf2_cu
**);
1169 static struct die_info
*follow_die_ref (struct die_info
*,
1171 struct dwarf2_cu
**);
1173 static struct die_info
*follow_die_sig (struct die_info
*,
1175 struct dwarf2_cu
**);
1177 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1178 unsigned int offset
);
1180 static void read_signatured_type (struct objfile
*,
1181 struct signatured_type
*type_sig
);
1183 /* memory allocation interface */
1185 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1187 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1189 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1191 static void initialize_cu_func_list (struct dwarf2_cu
*);
1193 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1194 struct dwarf2_cu
*);
1196 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1197 char *, bfd
*, struct dwarf2_cu
*);
1199 static int attr_form_is_block (struct attribute
*);
1201 static int attr_form_is_section_offset (struct attribute
*);
1203 static int attr_form_is_constant (struct attribute
*);
1205 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1206 struct dwarf2_loclist_baton
*baton
,
1207 struct attribute
*attr
);
1209 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1211 struct dwarf2_cu
*cu
);
1213 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1214 struct abbrev_info
*abbrev
,
1215 struct dwarf2_cu
*cu
);
1217 static void free_stack_comp_unit (void *);
1219 static hashval_t
partial_die_hash (const void *item
);
1221 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1223 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1224 (unsigned int offset
, struct objfile
*objfile
);
1226 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1227 (unsigned int offset
, struct objfile
*objfile
);
1229 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1230 struct objfile
*objfile
);
1232 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1233 struct die_info
*comp_unit_die
);
1235 static void free_one_comp_unit (void *);
1237 static void free_cached_comp_units (void *);
1239 static void age_cached_comp_units (void);
1241 static void free_one_cached_comp_unit (void *);
1243 static struct type
*set_die_type (struct die_info
*, struct type
*,
1244 struct dwarf2_cu
*);
1246 static void create_all_comp_units (struct objfile
*);
1248 static int create_debug_types_hash_table (struct objfile
*objfile
);
1250 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1253 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1255 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1256 struct dwarf2_per_cu_data
*);
1258 static void dwarf2_mark (struct dwarf2_cu
*);
1260 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1262 static struct type
*get_die_type_at_offset (unsigned int,
1263 struct dwarf2_per_cu_data
*per_cu
);
1265 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1267 static void dwarf2_release_queue (void *dummy
);
1269 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1270 struct objfile
*objfile
);
1272 static void process_queue (struct objfile
*objfile
);
1274 static void find_file_and_directory (struct die_info
*die
,
1275 struct dwarf2_cu
*cu
,
1276 char **name
, char **comp_dir
);
1278 static char *file_full_name (int file
, struct line_header
*lh
,
1279 const char *comp_dir
);
1281 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1284 unsigned int buffer_size
,
1287 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1288 struct dwarf2_cu
*cu
);
1290 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1294 /* Convert VALUE between big- and little-endian. */
1296 byte_swap (offset_type value
)
1300 result
= (value
& 0xff) << 24;
1301 result
|= (value
& 0xff00) << 8;
1302 result
|= (value
& 0xff0000) >> 8;
1303 result
|= (value
& 0xff000000) >> 24;
1307 #define MAYBE_SWAP(V) byte_swap (V)
1310 #define MAYBE_SWAP(V) (V)
1311 #endif /* WORDS_BIGENDIAN */
1313 /* The suffix for an index file. */
1314 #define INDEX_SUFFIX ".gdb-index"
1316 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1317 struct dwarf2_cu
*cu
);
1319 /* Try to locate the sections we need for DWARF 2 debugging
1320 information and return true if we have enough to do something. */
1323 dwarf2_has_info (struct objfile
*objfile
)
1325 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1326 if (!dwarf2_per_objfile
)
1328 /* Initialize per-objfile state. */
1329 struct dwarf2_per_objfile
*data
1330 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1332 memset (data
, 0, sizeof (*data
));
1333 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1334 dwarf2_per_objfile
= data
;
1336 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1337 dwarf2_per_objfile
->objfile
= objfile
;
1339 return (dwarf2_per_objfile
->info
.asection
!= NULL
1340 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1343 /* When loading sections, we can either look for ".<name>", or for
1344 * ".z<name>", which indicates a compressed section. */
1347 section_is_p (const char *section_name
, const char *name
)
1349 return (section_name
[0] == '.'
1350 && (strcmp (section_name
+ 1, name
) == 0
1351 || (section_name
[1] == 'z'
1352 && strcmp (section_name
+ 2, name
) == 0)));
1355 /* This function is mapped across the sections and remembers the
1356 offset and size of each of the debugging sections we are interested
1360 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1362 if (section_is_p (sectp
->name
, INFO_SECTION
))
1364 dwarf2_per_objfile
->info
.asection
= sectp
;
1365 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1367 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1369 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1370 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1372 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1374 dwarf2_per_objfile
->line
.asection
= sectp
;
1375 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1377 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1379 dwarf2_per_objfile
->loc
.asection
= sectp
;
1380 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1382 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1384 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1385 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1387 else if (section_is_p (sectp
->name
, STR_SECTION
))
1389 dwarf2_per_objfile
->str
.asection
= sectp
;
1390 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1392 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1394 dwarf2_per_objfile
->frame
.asection
= sectp
;
1395 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1397 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1399 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1401 if (aflag
& SEC_HAS_CONTENTS
)
1403 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1404 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1407 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1409 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1410 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1412 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1414 dwarf2_per_objfile
->types
.asection
= sectp
;
1415 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1417 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1419 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1420 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1423 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1424 && bfd_section_vma (abfd
, sectp
) == 0)
1425 dwarf2_per_objfile
->has_section_at_zero
= 1;
1428 /* Decompress a section that was compressed using zlib. Store the
1429 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1432 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1433 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1435 bfd
*abfd
= objfile
->obfd
;
1437 error (_("Support for zlib-compressed DWARF data (from '%s') "
1438 "is disabled in this copy of GDB"),
1439 bfd_get_filename (abfd
));
1441 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1442 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1443 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1444 bfd_size_type uncompressed_size
;
1445 gdb_byte
*uncompressed_buffer
;
1448 int header_size
= 12;
1450 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1451 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1452 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1453 bfd_get_filename (abfd
));
1455 /* Read the zlib header. In this case, it should be "ZLIB" followed
1456 by the uncompressed section size, 8 bytes in big-endian order. */
1457 if (compressed_size
< header_size
1458 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1459 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1460 bfd_get_filename (abfd
));
1461 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1462 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1463 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1464 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1465 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1466 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1467 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1468 uncompressed_size
+= compressed_buffer
[11];
1470 /* It is possible the section consists of several compressed
1471 buffers concatenated together, so we uncompress in a loop. */
1475 strm
.avail_in
= compressed_size
- header_size
;
1476 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1477 strm
.avail_out
= uncompressed_size
;
1478 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1480 rc
= inflateInit (&strm
);
1481 while (strm
.avail_in
> 0)
1484 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1485 bfd_get_filename (abfd
), rc
);
1486 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1487 + (uncompressed_size
- strm
.avail_out
));
1488 rc
= inflate (&strm
, Z_FINISH
);
1489 if (rc
!= Z_STREAM_END
)
1490 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1491 bfd_get_filename (abfd
), rc
);
1492 rc
= inflateReset (&strm
);
1494 rc
= inflateEnd (&strm
);
1496 || strm
.avail_out
!= 0)
1497 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1498 bfd_get_filename (abfd
), rc
);
1500 do_cleanups (cleanup
);
1501 *outbuf
= uncompressed_buffer
;
1502 *outsize
= uncompressed_size
;
1506 /* Read the contents of the section SECTP from object file specified by
1507 OBJFILE, store info about the section into INFO.
1508 If the section is compressed, uncompress it before returning. */
1511 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1513 bfd
*abfd
= objfile
->obfd
;
1514 asection
*sectp
= info
->asection
;
1515 gdb_byte
*buf
, *retbuf
;
1516 unsigned char header
[4];
1520 info
->buffer
= NULL
;
1521 info
->was_mmapped
= 0;
1524 if (info
->asection
== NULL
|| info
->size
== 0)
1527 /* Check if the file has a 4-byte header indicating compression. */
1528 if (info
->size
> sizeof (header
)
1529 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1530 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1532 /* Upon decompression, update the buffer and its size. */
1533 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1535 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1543 pagesize
= getpagesize ();
1545 /* Only try to mmap sections which are large enough: we don't want to
1546 waste space due to fragmentation. Also, only try mmap for sections
1547 without relocations. */
1549 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1551 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1552 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1553 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1554 MAP_PRIVATE
, pg_offset
);
1556 if (retbuf
!= MAP_FAILED
)
1558 info
->was_mmapped
= 1;
1559 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1560 #if HAVE_POSIX_MADVISE
1561 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1568 /* If we get here, we are a normal, not-compressed section. */
1570 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1572 /* When debugging .o files, we may need to apply relocations; see
1573 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1574 We never compress sections in .o files, so we only need to
1575 try this when the section is not compressed. */
1576 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1579 info
->buffer
= retbuf
;
1583 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1584 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1585 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1586 bfd_get_filename (abfd
));
1589 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1593 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1594 asection
**sectp
, gdb_byte
**bufp
,
1595 bfd_size_type
*sizep
)
1597 struct dwarf2_per_objfile
*data
1598 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1599 struct dwarf2_section_info
*info
;
1601 /* We may see an objfile without any DWARF, in which case we just
1610 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1611 info
= &data
->eh_frame
;
1612 else if (section_is_p (section_name
, FRAME_SECTION
))
1613 info
= &data
->frame
;
1615 gdb_assert_not_reached ("unexpected section");
1617 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1618 /* We haven't read this section in yet. Do it now. */
1619 dwarf2_read_section (objfile
, info
);
1621 *sectp
= info
->asection
;
1622 *bufp
= info
->buffer
;
1623 *sizep
= info
->size
;
1627 /* DWARF quick_symbols_functions support. */
1629 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1630 unique line tables, so we maintain a separate table of all .debug_line
1631 derived entries to support the sharing.
1632 All the quick functions need is the list of file names. We discard the
1633 line_header when we're done and don't need to record it here. */
1634 struct quick_file_names
1636 /* The offset in .debug_line of the line table. We hash on this. */
1637 unsigned int offset
;
1639 /* The number of entries in file_names, real_names. */
1640 unsigned int num_file_names
;
1642 /* The file names from the line table, after being run through
1644 const char **file_names
;
1646 /* The file names from the line table after being run through
1647 gdb_realpath. These are computed lazily. */
1648 const char **real_names
;
1651 /* When using the index (and thus not using psymtabs), each CU has an
1652 object of this type. This is used to hold information needed by
1653 the various "quick" methods. */
1654 struct dwarf2_per_cu_quick_data
1656 /* The file table. This can be NULL if there was no file table
1657 or it's currently not read in.
1658 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1659 struct quick_file_names
*file_names
;
1661 /* The corresponding symbol table. This is NULL if symbols for this
1662 CU have not yet been read. */
1663 struct symtab
*symtab
;
1665 /* A temporary mark bit used when iterating over all CUs in
1666 expand_symtabs_matching. */
1667 unsigned int mark
: 1;
1669 /* True if we've tried to read the file table and found there isn't one.
1670 There will be no point in trying to read it again next time. */
1671 unsigned int no_file_data
: 1;
1674 /* Hash function for a quick_file_names. */
1677 hash_file_name_entry (const void *e
)
1679 const struct quick_file_names
*file_data
= e
;
1681 return file_data
->offset
;
1684 /* Equality function for a quick_file_names. */
1687 eq_file_name_entry (const void *a
, const void *b
)
1689 const struct quick_file_names
*ea
= a
;
1690 const struct quick_file_names
*eb
= b
;
1692 return ea
->offset
== eb
->offset
;
1695 /* Delete function for a quick_file_names. */
1698 delete_file_name_entry (void *e
)
1700 struct quick_file_names
*file_data
= e
;
1703 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1705 xfree ((void*) file_data
->file_names
[i
]);
1706 if (file_data
->real_names
)
1707 xfree ((void*) file_data
->real_names
[i
]);
1710 /* The space for the struct itself lives on objfile_obstack,
1711 so we don't free it here. */
1714 /* Create a quick_file_names hash table. */
1717 create_quick_file_names_table (unsigned int nr_initial_entries
)
1719 return htab_create_alloc (nr_initial_entries
,
1720 hash_file_name_entry
, eq_file_name_entry
,
1721 delete_file_name_entry
, xcalloc
, xfree
);
1724 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1728 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1729 struct dwarf2_per_cu_data
*per_cu
)
1731 struct cleanup
*back_to
;
1733 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1735 queue_comp_unit (per_cu
, objfile
);
1737 if (per_cu
->from_debug_types
)
1738 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1740 load_full_comp_unit (per_cu
, objfile
);
1742 process_queue (objfile
);
1744 /* Age the cache, releasing compilation units that have not
1745 been used recently. */
1746 age_cached_comp_units ();
1748 do_cleanups (back_to
);
1751 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1752 the objfile from which this CU came. Returns the resulting symbol
1755 static struct symtab
*
1756 dw2_instantiate_symtab (struct objfile
*objfile
,
1757 struct dwarf2_per_cu_data
*per_cu
)
1759 if (!per_cu
->v
.quick
->symtab
)
1761 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1762 increment_reading_symtab ();
1763 dw2_do_instantiate_symtab (objfile
, per_cu
);
1764 do_cleanups (back_to
);
1766 return per_cu
->v
.quick
->symtab
;
1769 /* Return the CU given its index. */
1771 static struct dwarf2_per_cu_data
*
1772 dw2_get_cu (int index
)
1774 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1776 index
-= dwarf2_per_objfile
->n_comp_units
;
1777 return dwarf2_per_objfile
->type_comp_units
[index
];
1779 return dwarf2_per_objfile
->all_comp_units
[index
];
1782 /* A helper function that knows how to read a 64-bit value in a way
1783 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1787 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1789 if (sizeof (ULONGEST
) < 8)
1793 /* Ignore the upper 4 bytes if they are all zero. */
1794 for (i
= 0; i
< 4; ++i
)
1795 if (bytes
[i
+ 4] != 0)
1798 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1801 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1805 /* Read the CU list from the mapped index, and use it to create all
1806 the CU objects for this objfile. Return 0 if something went wrong,
1807 1 if everything went ok. */
1810 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1811 offset_type cu_list_elements
)
1815 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1816 dwarf2_per_objfile
->all_comp_units
1817 = obstack_alloc (&objfile
->objfile_obstack
,
1818 dwarf2_per_objfile
->n_comp_units
1819 * sizeof (struct dwarf2_per_cu_data
*));
1821 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1823 struct dwarf2_per_cu_data
*the_cu
;
1824 ULONGEST offset
, length
;
1826 if (!extract_cu_value (cu_list
, &offset
)
1827 || !extract_cu_value (cu_list
+ 8, &length
))
1831 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1832 struct dwarf2_per_cu_data
);
1833 the_cu
->offset
= offset
;
1834 the_cu
->length
= length
;
1835 the_cu
->objfile
= objfile
;
1836 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1837 struct dwarf2_per_cu_quick_data
);
1838 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1844 /* Create the signatured type hash table from the index. */
1847 create_signatured_type_table_from_index (struct objfile
*objfile
,
1848 const gdb_byte
*bytes
,
1849 offset_type elements
)
1852 htab_t sig_types_hash
;
1854 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1855 dwarf2_per_objfile
->type_comp_units
1856 = obstack_alloc (&objfile
->objfile_obstack
,
1857 dwarf2_per_objfile
->n_type_comp_units
1858 * sizeof (struct dwarf2_per_cu_data
*));
1860 sig_types_hash
= allocate_signatured_type_table (objfile
);
1862 for (i
= 0; i
< elements
; i
+= 3)
1864 struct signatured_type
*type_sig
;
1865 ULONGEST offset
, type_offset
, signature
;
1868 if (!extract_cu_value (bytes
, &offset
)
1869 || !extract_cu_value (bytes
+ 8, &type_offset
))
1871 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1874 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1875 struct signatured_type
);
1876 type_sig
->signature
= signature
;
1877 type_sig
->offset
= offset
;
1878 type_sig
->type_offset
= type_offset
;
1879 type_sig
->per_cu
.from_debug_types
= 1;
1880 type_sig
->per_cu
.offset
= offset
;
1881 type_sig
->per_cu
.objfile
= objfile
;
1882 type_sig
->per_cu
.v
.quick
1883 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1884 struct dwarf2_per_cu_quick_data
);
1886 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1889 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1892 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1897 /* Read the address map data from the mapped index, and use it to
1898 populate the objfile's psymtabs_addrmap. */
1901 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1903 const gdb_byte
*iter
, *end
;
1904 struct obstack temp_obstack
;
1905 struct addrmap
*mutable_map
;
1906 struct cleanup
*cleanup
;
1909 obstack_init (&temp_obstack
);
1910 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1911 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1913 iter
= index
->address_table
;
1914 end
= iter
+ index
->address_table_size
;
1916 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1920 ULONGEST hi
, lo
, cu_index
;
1921 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1923 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1925 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1928 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1929 dw2_get_cu (cu_index
));
1932 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1933 &objfile
->objfile_obstack
);
1934 do_cleanups (cleanup
);
1937 /* The hash function for strings in the mapped index. This is the
1938 same as the hashtab.c hash function, but we keep a separate copy to
1939 maintain control over the implementation. This is necessary
1940 because the hash function is tied to the format of the mapped index
1944 mapped_index_string_hash (const void *p
)
1946 const unsigned char *str
= (const unsigned char *) p
;
1950 while ((c
= *str
++) != 0)
1951 r
= r
* 67 + c
- 113;
1956 /* Find a slot in the mapped index INDEX for the object named NAME.
1957 If NAME is found, set *VEC_OUT to point to the CU vector in the
1958 constant pool and return 1. If NAME cannot be found, return 0. */
1961 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1962 offset_type
**vec_out
)
1964 offset_type hash
= mapped_index_string_hash (name
);
1965 offset_type slot
, step
;
1967 slot
= hash
& (index
->symbol_table_slots
- 1);
1968 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
1972 /* Convert a slot number to an offset into the table. */
1973 offset_type i
= 2 * slot
;
1975 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
1978 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
1979 if (!strcmp (name
, str
))
1981 *vec_out
= (offset_type
*) (index
->constant_pool
1982 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
1986 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
1990 /* Read the index file. If everything went ok, initialize the "quick"
1991 elements of all the CUs and return 1. Otherwise, return 0. */
1994 dwarf2_read_index (struct objfile
*objfile
)
1997 struct mapped_index
*map
;
1998 offset_type
*metadata
;
1999 const gdb_byte
*cu_list
;
2000 const gdb_byte
*types_list
= NULL
;
2001 offset_type version
, cu_list_elements
;
2002 offset_type types_list_elements
= 0;
2005 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
2006 || dwarf2_per_objfile
->gdb_index
.size
== 0)
2009 /* Older elfutils strip versions could keep the section in the main
2010 executable while splitting it for the separate debug info file. */
2011 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2012 & SEC_HAS_CONTENTS
) == 0)
2015 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2017 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2018 /* Version check. */
2019 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2020 /* Versions earlier than 3 emitted every copy of a psymbol. This
2021 causes the index to behave very poorly for certain requests. So,
2022 it seems better to just ignore such indices. */
2025 /* Indexes with higher version than the one supported by GDB may be no
2026 longer backward compatible. */
2030 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2031 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2033 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2036 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2037 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2041 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2042 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2043 - MAYBE_SWAP (metadata
[i
]))
2047 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2048 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2049 - MAYBE_SWAP (metadata
[i
]));
2052 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2053 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2054 - MAYBE_SWAP (metadata
[i
]))
2055 / (2 * sizeof (offset_type
)));
2058 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2060 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2063 if (types_list_elements
2064 && !create_signatured_type_table_from_index (objfile
, types_list
,
2065 types_list_elements
))
2068 create_addrmap_from_index (objfile
, map
);
2070 dwarf2_per_objfile
->index_table
= map
;
2071 dwarf2_per_objfile
->using_index
= 1;
2072 dwarf2_per_objfile
->quick_file_names_table
=
2073 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2078 /* A helper for the "quick" functions which sets the global
2079 dwarf2_per_objfile according to OBJFILE. */
2082 dw2_setup (struct objfile
*objfile
)
2084 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2085 gdb_assert (dwarf2_per_objfile
);
2088 /* A helper for the "quick" functions which attempts to read the line
2089 table for THIS_CU. */
2091 static struct quick_file_names
*
2092 dw2_get_file_names (struct objfile
*objfile
,
2093 struct dwarf2_per_cu_data
*this_cu
)
2095 bfd
*abfd
= objfile
->obfd
;
2096 struct line_header
*lh
;
2097 struct attribute
*attr
;
2098 struct cleanup
*cleanups
;
2099 struct die_info
*comp_unit_die
;
2100 struct dwarf2_section_info
* sec
;
2101 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2102 int has_children
, i
;
2103 struct dwarf2_cu cu
;
2104 unsigned int bytes_read
, buffer_size
;
2105 struct die_reader_specs reader_specs
;
2106 char *name
, *comp_dir
;
2108 struct quick_file_names
*qfn
;
2109 unsigned int line_offset
;
2111 if (this_cu
->v
.quick
->file_names
!= NULL
)
2112 return this_cu
->v
.quick
->file_names
;
2113 /* If we know there is no line data, no point in looking again. */
2114 if (this_cu
->v
.quick
->no_file_data
)
2117 init_one_comp_unit (&cu
, objfile
);
2118 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2120 if (this_cu
->from_debug_types
)
2121 sec
= &dwarf2_per_objfile
->types
;
2123 sec
= &dwarf2_per_objfile
->info
;
2124 dwarf2_read_section (objfile
, sec
);
2125 buffer_size
= sec
->size
;
2126 buffer
= sec
->buffer
;
2127 info_ptr
= buffer
+ this_cu
->offset
;
2128 beg_of_comp_unit
= info_ptr
;
2130 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2131 buffer
, buffer_size
,
2134 /* Complete the cu_header. */
2135 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2136 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2139 cu
.per_cu
= this_cu
;
2141 dwarf2_read_abbrevs (abfd
, &cu
);
2142 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2144 if (this_cu
->from_debug_types
)
2145 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2146 init_cu_die_reader (&reader_specs
, &cu
);
2147 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2153 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2156 struct quick_file_names find_entry
;
2158 line_offset
= DW_UNSND (attr
);
2160 /* We may have already read in this line header (TU line header sharing).
2161 If we have we're done. */
2162 find_entry
.offset
= line_offset
;
2163 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2164 &find_entry
, INSERT
);
2167 do_cleanups (cleanups
);
2168 this_cu
->v
.quick
->file_names
= *slot
;
2172 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2176 do_cleanups (cleanups
);
2177 this_cu
->v
.quick
->no_file_data
= 1;
2181 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2182 qfn
->offset
= line_offset
;
2183 gdb_assert (slot
!= NULL
);
2186 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2188 qfn
->num_file_names
= lh
->num_file_names
;
2189 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2190 lh
->num_file_names
* sizeof (char *));
2191 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2192 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2193 qfn
->real_names
= NULL
;
2195 free_line_header (lh
);
2196 do_cleanups (cleanups
);
2198 this_cu
->v
.quick
->file_names
= qfn
;
2202 /* A helper for the "quick" functions which computes and caches the
2203 real path for a given file name from the line table. */
2206 dw2_get_real_path (struct objfile
*objfile
,
2207 struct quick_file_names
*qfn
, int index
)
2209 if (qfn
->real_names
== NULL
)
2210 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2211 qfn
->num_file_names
, sizeof (char *));
2213 if (qfn
->real_names
[index
] == NULL
)
2214 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2216 return qfn
->real_names
[index
];
2219 static struct symtab
*
2220 dw2_find_last_source_symtab (struct objfile
*objfile
)
2224 dw2_setup (objfile
);
2225 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2226 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2229 /* Traversal function for dw2_forget_cached_source_info. */
2232 dw2_free_cached_file_names (void **slot
, void *info
)
2234 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2236 if (file_data
->real_names
)
2240 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2242 xfree ((void*) file_data
->real_names
[i
]);
2243 file_data
->real_names
[i
] = NULL
;
2251 dw2_forget_cached_source_info (struct objfile
*objfile
)
2253 dw2_setup (objfile
);
2255 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2256 dw2_free_cached_file_names
, NULL
);
2260 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2261 const char *full_path
, const char *real_path
,
2262 struct symtab
**result
)
2265 int check_basename
= lbasename (name
) == name
;
2266 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2268 dw2_setup (objfile
);
2270 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2271 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2274 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2275 struct quick_file_names
*file_data
;
2277 if (per_cu
->v
.quick
->symtab
)
2280 file_data
= dw2_get_file_names (objfile
, per_cu
);
2281 if (file_data
== NULL
)
2284 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2286 const char *this_name
= file_data
->file_names
[j
];
2288 if (FILENAME_CMP (name
, this_name
) == 0)
2290 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2294 if (check_basename
&& ! base_cu
2295 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2298 if (full_path
!= NULL
)
2300 const char *this_real_name
= dw2_get_real_path (objfile
,
2303 if (this_real_name
!= NULL
2304 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2306 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2311 if (real_path
!= NULL
)
2313 const char *this_real_name
= dw2_get_real_path (objfile
,
2316 if (this_real_name
!= NULL
2317 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2319 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2328 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2335 static struct symtab
*
2336 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2337 const char *name
, domain_enum domain
)
2339 /* We do all the work in the pre_expand_symtabs_matching hook
2344 /* A helper function that expands all symtabs that hold an object
2348 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2350 dw2_setup (objfile
);
2352 /* index_table is NULL if OBJF_READNOW. */
2353 if (dwarf2_per_objfile
->index_table
)
2357 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2360 offset_type i
, len
= MAYBE_SWAP (*vec
);
2361 for (i
= 0; i
< len
; ++i
)
2363 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2364 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2366 dw2_instantiate_symtab (objfile
, per_cu
);
2373 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2374 int kind
, const char *name
,
2377 dw2_do_expand_symtabs_matching (objfile
, name
);
2381 dw2_print_stats (struct objfile
*objfile
)
2385 dw2_setup (objfile
);
2387 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2388 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2390 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2392 if (!per_cu
->v
.quick
->symtab
)
2395 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2399 dw2_dump (struct objfile
*objfile
)
2401 /* Nothing worth printing. */
2405 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2406 struct section_offsets
*delta
)
2408 /* There's nothing to relocate here. */
2412 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2413 const char *func_name
)
2415 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2419 dw2_expand_all_symtabs (struct objfile
*objfile
)
2423 dw2_setup (objfile
);
2425 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2426 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2428 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2430 dw2_instantiate_symtab (objfile
, per_cu
);
2435 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2436 const char *filename
)
2440 dw2_setup (objfile
);
2442 /* We don't need to consider type units here.
2443 This is only called for examining code, e.g. expand_line_sal.
2444 There can be an order of magnitude (or more) more type units
2445 than comp units, and we avoid them if we can. */
2447 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2450 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2451 struct quick_file_names
*file_data
;
2453 if (per_cu
->v
.quick
->symtab
)
2456 file_data
= dw2_get_file_names (objfile
, per_cu
);
2457 if (file_data
== NULL
)
2460 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2462 const char *this_name
= file_data
->file_names
[j
];
2463 if (FILENAME_CMP (this_name
, filename
) == 0)
2465 dw2_instantiate_symtab (objfile
, per_cu
);
2473 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2475 struct dwarf2_per_cu_data
*per_cu
;
2477 struct quick_file_names
*file_data
;
2479 dw2_setup (objfile
);
2481 /* index_table is NULL if OBJF_READNOW. */
2482 if (!dwarf2_per_objfile
->index_table
)
2485 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2489 /* Note that this just looks at the very first one named NAME -- but
2490 actually we are looking for a function. find_main_filename
2491 should be rewritten so that it doesn't require a custom hook. It
2492 could just use the ordinary symbol tables. */
2493 /* vec[0] is the length, which must always be >0. */
2494 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2496 file_data
= dw2_get_file_names (objfile
, per_cu
);
2497 if (file_data
== NULL
)
2500 return file_data
->file_names
[file_data
->num_file_names
- 1];
2504 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2505 struct objfile
*objfile
, int global
,
2506 int (*callback
) (struct block
*,
2507 struct symbol
*, void *),
2508 void *data
, symbol_compare_ftype
*match
,
2509 symbol_compare_ftype
*ordered_compare
)
2511 /* Currently unimplemented; used for Ada. The function can be called if the
2512 current language is Ada for a non-Ada objfile using GNU index. As Ada
2513 does not look for non-Ada symbols this function should just return. */
2517 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2518 int (*file_matcher
) (const char *, void *),
2519 int (*name_matcher
) (const char *, void *),
2525 struct mapped_index
*index
;
2527 dw2_setup (objfile
);
2529 /* index_table is NULL if OBJF_READNOW. */
2530 if (!dwarf2_per_objfile
->index_table
)
2532 index
= dwarf2_per_objfile
->index_table
;
2534 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2535 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2538 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2539 struct quick_file_names
*file_data
;
2541 per_cu
->v
.quick
->mark
= 0;
2542 if (per_cu
->v
.quick
->symtab
)
2545 file_data
= dw2_get_file_names (objfile
, per_cu
);
2546 if (file_data
== NULL
)
2549 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2551 if (file_matcher (file_data
->file_names
[j
], data
))
2553 per_cu
->v
.quick
->mark
= 1;
2559 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2561 offset_type idx
= 2 * iter
;
2563 offset_type
*vec
, vec_len
, vec_idx
;
2565 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2568 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2570 if (! (*name_matcher
) (name
, data
))
2573 /* The name was matched, now expand corresponding CUs that were
2575 vec
= (offset_type
*) (index
->constant_pool
2576 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2577 vec_len
= MAYBE_SWAP (vec
[0]);
2578 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2580 struct dwarf2_per_cu_data
*per_cu
;
2582 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2583 if (per_cu
->v
.quick
->mark
)
2584 dw2_instantiate_symtab (objfile
, per_cu
);
2589 static struct symtab
*
2590 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2591 struct minimal_symbol
*msymbol
,
2593 struct obj_section
*section
,
2596 struct dwarf2_per_cu_data
*data
;
2598 dw2_setup (objfile
);
2600 if (!objfile
->psymtabs_addrmap
)
2603 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2607 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2608 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2609 paddress (get_objfile_arch (objfile
), pc
));
2611 return dw2_instantiate_symtab (objfile
, data
);
2615 dw2_map_symbol_names (struct objfile
*objfile
,
2616 void (*fun
) (const char *, void *),
2620 struct mapped_index
*index
;
2622 dw2_setup (objfile
);
2624 /* index_table is NULL if OBJF_READNOW. */
2625 if (!dwarf2_per_objfile
->index_table
)
2627 index
= dwarf2_per_objfile
->index_table
;
2629 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2631 offset_type idx
= 2 * iter
;
2633 offset_type
*vec
, vec_len
, vec_idx
;
2635 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2638 name
= (index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]));
2640 (*fun
) (name
, data
);
2645 dw2_map_symbol_filenames (struct objfile
*objfile
,
2646 void (*fun
) (const char *, const char *, void *),
2651 dw2_setup (objfile
);
2653 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2654 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2657 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2658 struct quick_file_names
*file_data
;
2660 if (per_cu
->v
.quick
->symtab
)
2663 file_data
= dw2_get_file_names (objfile
, per_cu
);
2664 if (file_data
== NULL
)
2667 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2669 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2671 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2677 dw2_has_symbols (struct objfile
*objfile
)
2682 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2685 dw2_find_last_source_symtab
,
2686 dw2_forget_cached_source_info
,
2689 dw2_pre_expand_symtabs_matching
,
2693 dw2_expand_symtabs_for_function
,
2694 dw2_expand_all_symtabs
,
2695 dw2_expand_symtabs_with_filename
,
2696 dw2_find_symbol_file
,
2697 dw2_map_matching_symbols
,
2698 dw2_expand_symtabs_matching
,
2699 dw2_find_pc_sect_symtab
,
2700 dw2_map_symbol_names
,
2701 dw2_map_symbol_filenames
2704 /* Initialize for reading DWARF for this objfile. Return 0 if this
2705 file will use psymtabs, or 1 if using the GNU index. */
2708 dwarf2_initialize_objfile (struct objfile
*objfile
)
2710 /* If we're about to read full symbols, don't bother with the
2711 indices. In this case we also don't care if some other debug
2712 format is making psymtabs, because they are all about to be
2714 if ((objfile
->flags
& OBJF_READNOW
))
2718 dwarf2_per_objfile
->using_index
= 1;
2719 create_all_comp_units (objfile
);
2720 create_debug_types_hash_table (objfile
);
2721 dwarf2_per_objfile
->quick_file_names_table
=
2722 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2724 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2725 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2727 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2729 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2730 struct dwarf2_per_cu_quick_data
);
2733 /* Return 1 so that gdb sees the "quick" functions. However,
2734 these functions will be no-ops because we will have expanded
2739 if (dwarf2_read_index (objfile
))
2742 dwarf2_build_psymtabs (objfile
);
2748 /* Build a partial symbol table. */
2751 dwarf2_build_psymtabs (struct objfile
*objfile
)
2753 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2755 init_psymbol_list (objfile
, 1024);
2758 dwarf2_build_psymtabs_hard (objfile
);
2761 /* Return TRUE if OFFSET is within CU_HEADER. */
2764 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2766 unsigned int bottom
= cu_header
->offset
;
2767 unsigned int top
= (cu_header
->offset
2769 + cu_header
->initial_length_size
);
2771 return (offset
>= bottom
&& offset
< top
);
2774 /* Read in the comp unit header information from the debug_info at info_ptr.
2775 NOTE: This leaves members offset, first_die_offset to be filled in
2779 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2780 gdb_byte
*info_ptr
, bfd
*abfd
)
2783 unsigned int bytes_read
;
2785 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2786 cu_header
->initial_length_size
= bytes_read
;
2787 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2788 info_ptr
+= bytes_read
;
2789 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2791 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2793 info_ptr
+= bytes_read
;
2794 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2796 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2797 if (signed_addr
< 0)
2798 internal_error (__FILE__
, __LINE__
,
2799 _("read_comp_unit_head: dwarf from non elf file"));
2800 cu_header
->signed_addr_p
= signed_addr
;
2806 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2807 gdb_byte
*buffer
, unsigned int buffer_size
,
2810 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2812 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2814 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2815 error (_("Dwarf Error: wrong version in compilation unit header "
2816 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2817 bfd_get_filename (abfd
));
2819 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2820 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2821 "(offset 0x%lx + 6) [in module %s]"),
2822 (long) header
->abbrev_offset
,
2823 (long) (beg_of_comp_unit
- buffer
),
2824 bfd_get_filename (abfd
));
2826 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2827 > buffer
+ buffer_size
)
2828 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2829 "(offset 0x%lx + 0) [in module %s]"),
2830 (long) header
->length
,
2831 (long) (beg_of_comp_unit
- buffer
),
2832 bfd_get_filename (abfd
));
2837 /* Read in the types comp unit header information from .debug_types entry at
2838 types_ptr. The result is a pointer to one past the end of the header. */
2841 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2842 ULONGEST
*signature
,
2843 gdb_byte
*types_ptr
, bfd
*abfd
)
2845 gdb_byte
*initial_types_ptr
= types_ptr
;
2847 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2848 &dwarf2_per_objfile
->types
);
2849 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2851 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2853 *signature
= read_8_bytes (abfd
, types_ptr
);
2855 types_ptr
+= cu_header
->offset_size
;
2856 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2861 /* Allocate a new partial symtab for file named NAME and mark this new
2862 partial symtab as being an include of PST. */
2865 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2866 struct objfile
*objfile
)
2868 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2870 subpst
->section_offsets
= pst
->section_offsets
;
2871 subpst
->textlow
= 0;
2872 subpst
->texthigh
= 0;
2874 subpst
->dependencies
= (struct partial_symtab
**)
2875 obstack_alloc (&objfile
->objfile_obstack
,
2876 sizeof (struct partial_symtab
*));
2877 subpst
->dependencies
[0] = pst
;
2878 subpst
->number_of_dependencies
= 1;
2880 subpst
->globals_offset
= 0;
2881 subpst
->n_global_syms
= 0;
2882 subpst
->statics_offset
= 0;
2883 subpst
->n_static_syms
= 0;
2884 subpst
->symtab
= NULL
;
2885 subpst
->read_symtab
= pst
->read_symtab
;
2888 /* No private part is necessary for include psymtabs. This property
2889 can be used to differentiate between such include psymtabs and
2890 the regular ones. */
2891 subpst
->read_symtab_private
= NULL
;
2894 /* Read the Line Number Program data and extract the list of files
2895 included by the source file represented by PST. Build an include
2896 partial symtab for each of these included files. */
2899 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2900 struct die_info
*die
,
2901 struct partial_symtab
*pst
)
2903 struct objfile
*objfile
= cu
->objfile
;
2904 bfd
*abfd
= objfile
->obfd
;
2905 struct line_header
*lh
= NULL
;
2906 struct attribute
*attr
;
2908 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2911 unsigned int line_offset
= DW_UNSND (attr
);
2913 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2916 return; /* No linetable, so no includes. */
2918 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2919 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2921 free_line_header (lh
);
2925 hash_type_signature (const void *item
)
2927 const struct signatured_type
*type_sig
= item
;
2929 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2930 return type_sig
->signature
;
2934 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2936 const struct signatured_type
*lhs
= item_lhs
;
2937 const struct signatured_type
*rhs
= item_rhs
;
2939 return lhs
->signature
== rhs
->signature
;
2942 /* Allocate a hash table for signatured types. */
2945 allocate_signatured_type_table (struct objfile
*objfile
)
2947 return htab_create_alloc_ex (41,
2948 hash_type_signature
,
2951 &objfile
->objfile_obstack
,
2952 hashtab_obstack_allocate
,
2953 dummy_obstack_deallocate
);
2956 /* A helper function to add a signatured type CU to a list. */
2959 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2961 struct signatured_type
*sigt
= *slot
;
2962 struct dwarf2_per_cu_data
***datap
= datum
;
2964 **datap
= &sigt
->per_cu
;
2970 /* Create the hash table of all entries in the .debug_types section.
2971 The result is zero if there is an error (e.g. missing .debug_types section),
2972 otherwise non-zero. */
2975 create_debug_types_hash_table (struct objfile
*objfile
)
2979 struct dwarf2_per_cu_data
**iter
;
2981 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2982 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2984 if (info_ptr
== NULL
)
2986 dwarf2_per_objfile
->signatured_types
= NULL
;
2990 types_htab
= allocate_signatured_type_table (objfile
);
2992 if (dwarf2_die_debug
)
2993 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2995 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2997 unsigned int offset
;
2998 unsigned int offset_size
;
2999 unsigned int type_offset
;
3000 unsigned int length
, initial_length_size
;
3001 unsigned short version
;
3003 struct signatured_type
*type_sig
;
3005 gdb_byte
*ptr
= info_ptr
;
3007 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3009 /* We need to read the type's signature in order to build the hash
3010 table, but we don't need to read anything else just yet. */
3012 /* Sanity check to ensure entire cu is present. */
3013 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3014 if (ptr
+ length
+ initial_length_size
3015 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3017 complaint (&symfile_complaints
,
3018 _("debug type entry runs off end of `.debug_types' section, ignored"));
3022 offset_size
= initial_length_size
== 4 ? 4 : 8;
3023 ptr
+= initial_length_size
;
3024 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3026 ptr
+= offset_size
; /* abbrev offset */
3027 ptr
+= 1; /* address size */
3028 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3030 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3032 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3033 memset (type_sig
, 0, sizeof (*type_sig
));
3034 type_sig
->signature
= signature
;
3035 type_sig
->offset
= offset
;
3036 type_sig
->type_offset
= type_offset
;
3037 type_sig
->per_cu
.objfile
= objfile
;
3038 type_sig
->per_cu
.from_debug_types
= 1;
3040 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3041 gdb_assert (slot
!= NULL
);
3044 if (dwarf2_die_debug
)
3045 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3046 offset
, phex (signature
, sizeof (signature
)));
3048 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3051 dwarf2_per_objfile
->signatured_types
= types_htab
;
3053 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3054 dwarf2_per_objfile
->type_comp_units
3055 = obstack_alloc (&objfile
->objfile_obstack
,
3056 dwarf2_per_objfile
->n_type_comp_units
3057 * sizeof (struct dwarf2_per_cu_data
*));
3058 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3059 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3060 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3061 == dwarf2_per_objfile
->n_type_comp_units
);
3066 /* Lookup a signature based type.
3067 Returns NULL if SIG is not present in the table. */
3069 static struct signatured_type
*
3070 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3072 struct signatured_type find_entry
, *entry
;
3074 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3076 complaint (&symfile_complaints
,
3077 _("missing `.debug_types' section for DW_FORM_sig8 die"));
3081 find_entry
.signature
= sig
;
3082 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3086 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3089 init_cu_die_reader (struct die_reader_specs
*reader
,
3090 struct dwarf2_cu
*cu
)
3092 reader
->abfd
= cu
->objfile
->obfd
;
3094 if (cu
->per_cu
->from_debug_types
)
3096 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3097 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3101 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3102 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3106 /* Find the base address of the compilation unit for range lists and
3107 location lists. It will normally be specified by DW_AT_low_pc.
3108 In DWARF-3 draft 4, the base address could be overridden by
3109 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3110 compilation units with discontinuous ranges. */
3113 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3115 struct attribute
*attr
;
3118 cu
->base_address
= 0;
3120 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3123 cu
->base_address
= DW_ADDR (attr
);
3128 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3131 cu
->base_address
= DW_ADDR (attr
);
3137 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3138 to combine the common parts.
3139 Process a compilation unit for a psymtab.
3140 BUFFER is a pointer to the beginning of the dwarf section buffer,
3141 either .debug_info or debug_types.
3142 INFO_PTR is a pointer to the start of the CU.
3143 Returns a pointer to the next CU. */
3146 process_psymtab_comp_unit (struct objfile
*objfile
,
3147 struct dwarf2_per_cu_data
*this_cu
,
3148 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3149 unsigned int buffer_size
)
3151 bfd
*abfd
= objfile
->obfd
;
3152 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3153 struct die_info
*comp_unit_die
;
3154 struct partial_symtab
*pst
;
3156 struct cleanup
*back_to_inner
;
3157 struct dwarf2_cu cu
;
3158 int has_children
, has_pc_info
;
3159 struct attribute
*attr
;
3160 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3161 struct die_reader_specs reader_specs
;
3163 init_one_comp_unit (&cu
, objfile
);
3164 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3166 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3167 buffer
, buffer_size
,
3170 /* Complete the cu_header. */
3171 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3172 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3174 cu
.list_in_scope
= &file_symbols
;
3176 /* If this compilation unit was already read in, free the
3177 cached copy in order to read it in again. This is
3178 necessary because we skipped some symbols when we first
3179 read in the compilation unit (see load_partial_dies).
3180 This problem could be avoided, but the benefit is
3182 if (this_cu
->cu
!= NULL
)
3183 free_one_cached_comp_unit (this_cu
->cu
);
3185 /* Note that this is a pointer to our stack frame, being
3186 added to a global data structure. It will be cleaned up
3187 in free_stack_comp_unit when we finish with this
3188 compilation unit. */
3190 cu
.per_cu
= this_cu
;
3192 /* Read the abbrevs for this compilation unit into a table. */
3193 dwarf2_read_abbrevs (abfd
, &cu
);
3194 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3196 /* Read the compilation unit die. */
3197 if (this_cu
->from_debug_types
)
3198 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3199 init_cu_die_reader (&reader_specs
, &cu
);
3200 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3203 if (this_cu
->from_debug_types
)
3205 /* offset,length haven't been set yet for type units. */
3206 this_cu
->offset
= cu
.header
.offset
;
3207 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3209 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3211 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3212 + cu
.header
.initial_length_size
);
3213 do_cleanups (back_to_inner
);
3217 prepare_one_comp_unit (&cu
, comp_unit_die
);
3219 /* Allocate a new partial symbol table structure. */
3220 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3221 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3222 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3223 /* TEXTLOW and TEXTHIGH are set below. */
3225 objfile
->global_psymbols
.next
,
3226 objfile
->static_psymbols
.next
);
3228 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3230 pst
->dirname
= DW_STRING (attr
);
3232 pst
->read_symtab_private
= this_cu
;
3234 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3236 /* Store the function that reads in the rest of the symbol table */
3237 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3239 this_cu
->v
.psymtab
= pst
;
3241 dwarf2_find_base_address (comp_unit_die
, &cu
);
3243 /* Possibly set the default values of LOWPC and HIGHPC from
3245 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3246 &best_highpc
, &cu
, pst
);
3247 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3248 /* Store the contiguous range if it is not empty; it can be empty for
3249 CUs with no code. */
3250 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3251 best_lowpc
+ baseaddr
,
3252 best_highpc
+ baseaddr
- 1, pst
);
3254 /* Check if comp unit has_children.
3255 If so, read the rest of the partial symbols from this comp unit.
3256 If not, there's no more debug_info for this comp unit. */
3259 struct partial_die_info
*first_die
;
3260 CORE_ADDR lowpc
, highpc
;
3262 lowpc
= ((CORE_ADDR
) -1);
3263 highpc
= ((CORE_ADDR
) 0);
3265 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3267 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3268 ! has_pc_info
, &cu
);
3270 /* If we didn't find a lowpc, set it to highpc to avoid
3271 complaints from `maint check'. */
3272 if (lowpc
== ((CORE_ADDR
) -1))
3275 /* If the compilation unit didn't have an explicit address range,
3276 then use the information extracted from its child dies. */
3280 best_highpc
= highpc
;
3283 pst
->textlow
= best_lowpc
+ baseaddr
;
3284 pst
->texthigh
= best_highpc
+ baseaddr
;
3286 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3287 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3288 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3289 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3290 sort_pst_symbols (pst
);
3292 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3293 + cu
.header
.initial_length_size
);
3295 if (this_cu
->from_debug_types
)
3297 /* It's not clear we want to do anything with stmt lists here.
3298 Waiting to see what gcc ultimately does. */
3302 /* Get the list of files included in the current compilation unit,
3303 and build a psymtab for each of them. */
3304 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3307 do_cleanups (back_to_inner
);
3312 /* Traversal function for htab_traverse_noresize.
3313 Process one .debug_types comp-unit. */
3316 process_type_comp_unit (void **slot
, void *info
)
3318 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3319 struct objfile
*objfile
= (struct objfile
*) info
;
3320 struct dwarf2_per_cu_data
*this_cu
;
3322 this_cu
= &entry
->per_cu
;
3324 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3325 process_psymtab_comp_unit (objfile
, this_cu
,
3326 dwarf2_per_objfile
->types
.buffer
,
3327 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3328 dwarf2_per_objfile
->types
.size
);
3333 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3334 Build partial symbol tables for the .debug_types comp-units. */
3337 build_type_psymtabs (struct objfile
*objfile
)
3339 if (! create_debug_types_hash_table (objfile
))
3342 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3343 process_type_comp_unit
, objfile
);
3346 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3349 psymtabs_addrmap_cleanup (void *o
)
3351 struct objfile
*objfile
= o
;
3353 objfile
->psymtabs_addrmap
= NULL
;
3356 /* Build the partial symbol table by doing a quick pass through the
3357 .debug_info and .debug_abbrev sections. */
3360 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3363 struct cleanup
*back_to
, *addrmap_cleanup
;
3364 struct obstack temp_obstack
;
3366 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3368 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3369 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3371 /* Any cached compilation units will be linked by the per-objfile
3372 read_in_chain. Make sure to free them when we're done. */
3373 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3375 build_type_psymtabs (objfile
);
3377 create_all_comp_units (objfile
);
3379 /* Create a temporary address map on a temporary obstack. We later
3380 copy this to the final obstack. */
3381 obstack_init (&temp_obstack
);
3382 make_cleanup_obstack_free (&temp_obstack
);
3383 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3384 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3386 /* Since the objects we're extracting from .debug_info vary in
3387 length, only the individual functions to extract them (like
3388 read_comp_unit_head and load_partial_die) can really know whether
3389 the buffer is large enough to hold another complete object.
3391 At the moment, they don't actually check that. If .debug_info
3392 holds just one extra byte after the last compilation unit's dies,
3393 then read_comp_unit_head will happily read off the end of the
3394 buffer. read_partial_die is similarly casual. Those functions
3397 For this loop condition, simply checking whether there's any data
3398 left at all should be sufficient. */
3400 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3401 + dwarf2_per_objfile
->info
.size
))
3403 struct dwarf2_per_cu_data
*this_cu
;
3405 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3408 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3409 dwarf2_per_objfile
->info
.buffer
,
3411 dwarf2_per_objfile
->info
.size
);
3414 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3415 &objfile
->objfile_obstack
);
3416 discard_cleanups (addrmap_cleanup
);
3418 do_cleanups (back_to
);
3421 /* Load the partial DIEs for a secondary CU into memory. */
3424 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3425 struct objfile
*objfile
)
3427 bfd
*abfd
= objfile
->obfd
;
3428 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3429 struct die_info
*comp_unit_die
;
3430 struct dwarf2_cu
*cu
;
3431 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3433 struct die_reader_specs reader_specs
;
3436 gdb_assert (! this_cu
->from_debug_types
);
3438 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3439 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3440 beg_of_comp_unit
= info_ptr
;
3442 if (this_cu
->cu
== NULL
)
3444 cu
= xmalloc (sizeof (*cu
));
3445 init_one_comp_unit (cu
, objfile
);
3449 /* If an error occurs while loading, release our storage. */
3450 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3452 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3453 dwarf2_per_objfile
->info
.buffer
,
3454 dwarf2_per_objfile
->info
.size
,
3457 /* Complete the cu_header. */
3458 cu
->header
.offset
= this_cu
->offset
;
3459 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3461 /* Link this compilation unit into the compilation unit tree. */
3463 cu
->per_cu
= this_cu
;
3465 /* Link this CU into read_in_chain. */
3466 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3467 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3472 info_ptr
+= cu
->header
.first_die_offset
;
3475 /* Read the abbrevs for this compilation unit into a table. */
3476 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3477 dwarf2_read_abbrevs (abfd
, cu
);
3478 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3480 /* Read the compilation unit die. */
3481 init_cu_die_reader (&reader_specs
, cu
);
3482 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3485 prepare_one_comp_unit (cu
, comp_unit_die
);
3487 /* Check if comp unit has_children.
3488 If so, read the rest of the partial symbols from this comp unit.
3489 If not, there's no more debug_info for this comp unit. */
3491 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3493 do_cleanups (free_abbrevs_cleanup
);
3497 /* We've successfully allocated this compilation unit. Let our
3498 caller clean it up when finished with it. */
3499 discard_cleanups (free_cu_cleanup
);
3503 /* Create a list of all compilation units in OBJFILE. We do this only
3504 if an inter-comp-unit reference is found; presumably if there is one,
3505 there will be many, and one will occur early in the .debug_info section.
3506 So there's no point in building this list incrementally. */
3509 create_all_comp_units (struct objfile
*objfile
)
3513 struct dwarf2_per_cu_data
**all_comp_units
;
3516 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3517 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3521 all_comp_units
= xmalloc (n_allocated
3522 * sizeof (struct dwarf2_per_cu_data
*));
3524 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3526 unsigned int length
, initial_length_size
;
3527 struct dwarf2_per_cu_data
*this_cu
;
3528 unsigned int offset
;
3530 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3532 /* Read just enough information to find out where the next
3533 compilation unit is. */
3534 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3535 &initial_length_size
);
3537 /* Save the compilation unit for later lookup. */
3538 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3539 sizeof (struct dwarf2_per_cu_data
));
3540 memset (this_cu
, 0, sizeof (*this_cu
));
3541 this_cu
->offset
= offset
;
3542 this_cu
->length
= length
+ initial_length_size
;
3543 this_cu
->objfile
= objfile
;
3545 if (n_comp_units
== n_allocated
)
3548 all_comp_units
= xrealloc (all_comp_units
,
3550 * sizeof (struct dwarf2_per_cu_data
*));
3552 all_comp_units
[n_comp_units
++] = this_cu
;
3554 info_ptr
= info_ptr
+ this_cu
->length
;
3557 dwarf2_per_objfile
->all_comp_units
3558 = obstack_alloc (&objfile
->objfile_obstack
,
3559 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3560 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3561 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3562 xfree (all_comp_units
);
3563 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3566 /* Process all loaded DIEs for compilation unit CU, starting at
3567 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3568 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3569 DW_AT_ranges). If NEED_PC is set, then this function will set
3570 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3571 and record the covered ranges in the addrmap. */
3574 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3575 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3577 struct partial_die_info
*pdi
;
3579 /* Now, march along the PDI's, descending into ones which have
3580 interesting children but skipping the children of the other ones,
3581 until we reach the end of the compilation unit. */
3587 fixup_partial_die (pdi
, cu
);
3589 /* Anonymous namespaces or modules have no name but have interesting
3590 children, so we need to look at them. Ditto for anonymous
3593 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3594 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3598 case DW_TAG_subprogram
:
3599 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3601 case DW_TAG_constant
:
3602 case DW_TAG_variable
:
3603 case DW_TAG_typedef
:
3604 case DW_TAG_union_type
:
3605 if (!pdi
->is_declaration
)
3607 add_partial_symbol (pdi
, cu
);
3610 case DW_TAG_class_type
:
3611 case DW_TAG_interface_type
:
3612 case DW_TAG_structure_type
:
3613 if (!pdi
->is_declaration
)
3615 add_partial_symbol (pdi
, cu
);
3618 case DW_TAG_enumeration_type
:
3619 if (!pdi
->is_declaration
)
3620 add_partial_enumeration (pdi
, cu
);
3622 case DW_TAG_base_type
:
3623 case DW_TAG_subrange_type
:
3624 /* File scope base type definitions are added to the partial
3626 add_partial_symbol (pdi
, cu
);
3628 case DW_TAG_namespace
:
3629 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3632 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3639 /* If the die has a sibling, skip to the sibling. */
3641 pdi
= pdi
->die_sibling
;
3645 /* Functions used to compute the fully scoped name of a partial DIE.
3647 Normally, this is simple. For C++, the parent DIE's fully scoped
3648 name is concatenated with "::" and the partial DIE's name. For
3649 Java, the same thing occurs except that "." is used instead of "::".
3650 Enumerators are an exception; they use the scope of their parent
3651 enumeration type, i.e. the name of the enumeration type is not
3652 prepended to the enumerator.
3654 There are two complexities. One is DW_AT_specification; in this
3655 case "parent" means the parent of the target of the specification,
3656 instead of the direct parent of the DIE. The other is compilers
3657 which do not emit DW_TAG_namespace; in this case we try to guess
3658 the fully qualified name of structure types from their members'
3659 linkage names. This must be done using the DIE's children rather
3660 than the children of any DW_AT_specification target. We only need
3661 to do this for structures at the top level, i.e. if the target of
3662 any DW_AT_specification (if any; otherwise the DIE itself) does not
3665 /* Compute the scope prefix associated with PDI's parent, in
3666 compilation unit CU. The result will be allocated on CU's
3667 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3668 field. NULL is returned if no prefix is necessary. */
3670 partial_die_parent_scope (struct partial_die_info
*pdi
,
3671 struct dwarf2_cu
*cu
)
3673 char *grandparent_scope
;
3674 struct partial_die_info
*parent
, *real_pdi
;
3676 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3677 then this means the parent of the specification DIE. */
3680 while (real_pdi
->has_specification
)
3681 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3683 parent
= real_pdi
->die_parent
;
3687 if (parent
->scope_set
)
3688 return parent
->scope
;
3690 fixup_partial_die (parent
, cu
);
3692 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3694 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3695 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3696 Work around this problem here. */
3697 if (cu
->language
== language_cplus
3698 && parent
->tag
== DW_TAG_namespace
3699 && strcmp (parent
->name
, "::") == 0
3700 && grandparent_scope
== NULL
)
3702 parent
->scope
= NULL
;
3703 parent
->scope_set
= 1;
3707 if (parent
->tag
== DW_TAG_namespace
3708 || parent
->tag
== DW_TAG_module
3709 || parent
->tag
== DW_TAG_structure_type
3710 || parent
->tag
== DW_TAG_class_type
3711 || parent
->tag
== DW_TAG_interface_type
3712 || parent
->tag
== DW_TAG_union_type
3713 || parent
->tag
== DW_TAG_enumeration_type
)
3715 if (grandparent_scope
== NULL
)
3716 parent
->scope
= parent
->name
;
3718 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3719 parent
->name
, 0, cu
);
3721 else if (parent
->tag
== DW_TAG_enumerator
)
3722 /* Enumerators should not get the name of the enumeration as a prefix. */
3723 parent
->scope
= grandparent_scope
;
3726 /* FIXME drow/2004-04-01: What should we be doing with
3727 function-local names? For partial symbols, we should probably be
3729 complaint (&symfile_complaints
,
3730 _("unhandled containing DIE tag %d for DIE at %d"),
3731 parent
->tag
, pdi
->offset
);
3732 parent
->scope
= grandparent_scope
;
3735 parent
->scope_set
= 1;
3736 return parent
->scope
;
3739 /* Return the fully scoped name associated with PDI, from compilation unit
3740 CU. The result will be allocated with malloc. */
3742 partial_die_full_name (struct partial_die_info
*pdi
,
3743 struct dwarf2_cu
*cu
)
3747 /* If this is a template instantiation, we can not work out the
3748 template arguments from partial DIEs. So, unfortunately, we have
3749 to go through the full DIEs. At least any work we do building
3750 types here will be reused if full symbols are loaded later. */
3751 if (pdi
->has_template_arguments
)
3753 fixup_partial_die (pdi
, cu
);
3755 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3757 struct die_info
*die
;
3758 struct attribute attr
;
3759 struct dwarf2_cu
*ref_cu
= cu
;
3762 attr
.form
= DW_FORM_ref_addr
;
3763 attr
.u
.addr
= pdi
->offset
;
3764 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3766 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3770 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3771 if (parent_scope
== NULL
)
3774 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3778 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3780 struct objfile
*objfile
= cu
->objfile
;
3782 char *actual_name
= NULL
;
3783 const struct partial_symbol
*psym
= NULL
;
3785 int built_actual_name
= 0;
3787 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3789 actual_name
= partial_die_full_name (pdi
, cu
);
3791 built_actual_name
= 1;
3793 if (actual_name
== NULL
)
3794 actual_name
= pdi
->name
;
3798 case DW_TAG_subprogram
:
3799 if (pdi
->is_external
|| cu
->language
== language_ada
)
3801 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3802 of the global scope. But in Ada, we want to be able to access
3803 nested procedures globally. So all Ada subprograms are stored
3804 in the global scope. */
3805 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3806 mst_text, objfile); */
3807 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3809 VAR_DOMAIN
, LOC_BLOCK
,
3810 &objfile
->global_psymbols
,
3811 0, pdi
->lowpc
+ baseaddr
,
3812 cu
->language
, objfile
);
3816 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3817 mst_file_text, objfile); */
3818 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3820 VAR_DOMAIN
, LOC_BLOCK
,
3821 &objfile
->static_psymbols
,
3822 0, pdi
->lowpc
+ baseaddr
,
3823 cu
->language
, objfile
);
3826 case DW_TAG_constant
:
3828 struct psymbol_allocation_list
*list
;
3830 if (pdi
->is_external
)
3831 list
= &objfile
->global_psymbols
;
3833 list
= &objfile
->static_psymbols
;
3834 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3835 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3836 list
, 0, 0, cu
->language
, objfile
);
3840 case DW_TAG_variable
:
3842 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3846 && !dwarf2_per_objfile
->has_section_at_zero
)
3848 /* A global or static variable may also have been stripped
3849 out by the linker if unused, in which case its address
3850 will be nullified; do not add such variables into partial
3851 symbol table then. */
3853 else if (pdi
->is_external
)
3856 Don't enter into the minimal symbol tables as there is
3857 a minimal symbol table entry from the ELF symbols already.
3858 Enter into partial symbol table if it has a location
3859 descriptor or a type.
3860 If the location descriptor is missing, new_symbol will create
3861 a LOC_UNRESOLVED symbol, the address of the variable will then
3862 be determined from the minimal symbol table whenever the variable
3864 The address for the partial symbol table entry is not
3865 used by GDB, but it comes in handy for debugging partial symbol
3868 if (pdi
->locdesc
|| pdi
->has_type
)
3869 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3871 VAR_DOMAIN
, LOC_STATIC
,
3872 &objfile
->global_psymbols
,
3874 cu
->language
, objfile
);
3878 /* Static Variable. Skip symbols without location descriptors. */
3879 if (pdi
->locdesc
== NULL
)
3881 if (built_actual_name
)
3882 xfree (actual_name
);
3885 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3886 mst_file_data, objfile); */
3887 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3889 VAR_DOMAIN
, LOC_STATIC
,
3890 &objfile
->static_psymbols
,
3892 cu
->language
, objfile
);
3895 case DW_TAG_typedef
:
3896 case DW_TAG_base_type
:
3897 case DW_TAG_subrange_type
:
3898 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3900 VAR_DOMAIN
, LOC_TYPEDEF
,
3901 &objfile
->static_psymbols
,
3902 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3904 case DW_TAG_namespace
:
3905 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3907 VAR_DOMAIN
, LOC_TYPEDEF
,
3908 &objfile
->global_psymbols
,
3909 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3911 case DW_TAG_class_type
:
3912 case DW_TAG_interface_type
:
3913 case DW_TAG_structure_type
:
3914 case DW_TAG_union_type
:
3915 case DW_TAG_enumeration_type
:
3916 /* Skip external references. The DWARF standard says in the section
3917 about "Structure, Union, and Class Type Entries": "An incomplete
3918 structure, union or class type is represented by a structure,
3919 union or class entry that does not have a byte size attribute
3920 and that has a DW_AT_declaration attribute." */
3921 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3923 if (built_actual_name
)
3924 xfree (actual_name
);
3928 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3929 static vs. global. */
3930 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3932 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3933 (cu
->language
== language_cplus
3934 || cu
->language
== language_java
)
3935 ? &objfile
->global_psymbols
3936 : &objfile
->static_psymbols
,
3937 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3940 case DW_TAG_enumerator
:
3941 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3943 VAR_DOMAIN
, LOC_CONST
,
3944 (cu
->language
== language_cplus
3945 || cu
->language
== language_java
)
3946 ? &objfile
->global_psymbols
3947 : &objfile
->static_psymbols
,
3948 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3954 if (built_actual_name
)
3955 xfree (actual_name
);
3958 /* Read a partial die corresponding to a namespace; also, add a symbol
3959 corresponding to that namespace to the symbol table. NAMESPACE is
3960 the name of the enclosing namespace. */
3963 add_partial_namespace (struct partial_die_info
*pdi
,
3964 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3965 int need_pc
, struct dwarf2_cu
*cu
)
3967 /* Add a symbol for the namespace. */
3969 add_partial_symbol (pdi
, cu
);
3971 /* Now scan partial symbols in that namespace. */
3973 if (pdi
->has_children
)
3974 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3977 /* Read a partial die corresponding to a Fortran module. */
3980 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3981 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3983 /* Now scan partial symbols in that module. */
3985 if (pdi
->has_children
)
3986 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3989 /* Read a partial die corresponding to a subprogram and create a partial
3990 symbol for that subprogram. When the CU language allows it, this
3991 routine also defines a partial symbol for each nested subprogram
3992 that this subprogram contains.
3994 DIE my also be a lexical block, in which case we simply search
3995 recursively for suprograms defined inside that lexical block.
3996 Again, this is only performed when the CU language allows this
3997 type of definitions. */
4000 add_partial_subprogram (struct partial_die_info
*pdi
,
4001 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4002 int need_pc
, struct dwarf2_cu
*cu
)
4004 if (pdi
->tag
== DW_TAG_subprogram
)
4006 if (pdi
->has_pc_info
)
4008 if (pdi
->lowpc
< *lowpc
)
4009 *lowpc
= pdi
->lowpc
;
4010 if (pdi
->highpc
> *highpc
)
4011 *highpc
= pdi
->highpc
;
4015 struct objfile
*objfile
= cu
->objfile
;
4017 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4018 SECT_OFF_TEXT (objfile
));
4019 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4020 pdi
->lowpc
+ baseaddr
,
4021 pdi
->highpc
- 1 + baseaddr
,
4022 cu
->per_cu
->v
.psymtab
);
4024 if (!pdi
->is_declaration
)
4025 /* Ignore subprogram DIEs that do not have a name, they are
4026 illegal. Do not emit a complaint at this point, we will
4027 do so when we convert this psymtab into a symtab. */
4029 add_partial_symbol (pdi
, cu
);
4033 if (! pdi
->has_children
)
4036 if (cu
->language
== language_ada
)
4038 pdi
= pdi
->die_child
;
4041 fixup_partial_die (pdi
, cu
);
4042 if (pdi
->tag
== DW_TAG_subprogram
4043 || pdi
->tag
== DW_TAG_lexical_block
)
4044 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4045 pdi
= pdi
->die_sibling
;
4050 /* Read a partial die corresponding to an enumeration type. */
4053 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4054 struct dwarf2_cu
*cu
)
4056 struct partial_die_info
*pdi
;
4058 if (enum_pdi
->name
!= NULL
)
4059 add_partial_symbol (enum_pdi
, cu
);
4061 pdi
= enum_pdi
->die_child
;
4064 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4065 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4067 add_partial_symbol (pdi
, cu
);
4068 pdi
= pdi
->die_sibling
;
4072 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4073 Return the corresponding abbrev, or NULL if the number is zero (indicating
4074 an empty DIE). In either case *BYTES_READ will be set to the length of
4075 the initial number. */
4077 static struct abbrev_info
*
4078 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4079 struct dwarf2_cu
*cu
)
4081 bfd
*abfd
= cu
->objfile
->obfd
;
4082 unsigned int abbrev_number
;
4083 struct abbrev_info
*abbrev
;
4085 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4087 if (abbrev_number
== 0)
4090 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4093 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
4094 bfd_get_filename (abfd
));
4100 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4101 Returns a pointer to the end of a series of DIEs, terminated by an empty
4102 DIE. Any children of the skipped DIEs will also be skipped. */
4105 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4107 struct abbrev_info
*abbrev
;
4108 unsigned int bytes_read
;
4112 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4114 return info_ptr
+ bytes_read
;
4116 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4120 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4121 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4122 abbrev corresponding to that skipped uleb128 should be passed in
4123 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4127 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4128 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4130 unsigned int bytes_read
;
4131 struct attribute attr
;
4132 bfd
*abfd
= cu
->objfile
->obfd
;
4133 unsigned int form
, i
;
4135 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4137 /* The only abbrev we care about is DW_AT_sibling. */
4138 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4140 read_attribute (&attr
, &abbrev
->attrs
[i
],
4141 abfd
, info_ptr
, cu
);
4142 if (attr
.form
== DW_FORM_ref_addr
)
4143 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4145 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4148 /* If it isn't DW_AT_sibling, skip this attribute. */
4149 form
= abbrev
->attrs
[i
].form
;
4153 case DW_FORM_ref_addr
:
4154 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4155 and later it is offset sized. */
4156 if (cu
->header
.version
== 2)
4157 info_ptr
+= cu
->header
.addr_size
;
4159 info_ptr
+= cu
->header
.offset_size
;
4162 info_ptr
+= cu
->header
.addr_size
;
4169 case DW_FORM_flag_present
:
4184 case DW_FORM_string
:
4185 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4186 info_ptr
+= bytes_read
;
4188 case DW_FORM_sec_offset
:
4190 info_ptr
+= cu
->header
.offset_size
;
4192 case DW_FORM_exprloc
:
4194 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4195 info_ptr
+= bytes_read
;
4197 case DW_FORM_block1
:
4198 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4200 case DW_FORM_block2
:
4201 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4203 case DW_FORM_block4
:
4204 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4208 case DW_FORM_ref_udata
:
4209 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4211 case DW_FORM_indirect
:
4212 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4213 info_ptr
+= bytes_read
;
4214 /* We need to continue parsing from here, so just go back to
4216 goto skip_attribute
;
4219 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4220 dwarf_form_name (form
),
4221 bfd_get_filename (abfd
));
4225 if (abbrev
->has_children
)
4226 return skip_children (buffer
, info_ptr
, cu
);
4231 /* Locate ORIG_PDI's sibling.
4232 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4236 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4237 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4238 bfd
*abfd
, struct dwarf2_cu
*cu
)
4240 /* Do we know the sibling already? */
4242 if (orig_pdi
->sibling
)
4243 return orig_pdi
->sibling
;
4245 /* Are there any children to deal with? */
4247 if (!orig_pdi
->has_children
)
4250 /* Skip the children the long way. */
4252 return skip_children (buffer
, info_ptr
, cu
);
4255 /* Expand this partial symbol table into a full symbol table. */
4258 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4264 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4270 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4271 gdb_flush (gdb_stdout
);
4274 /* Restore our global data. */
4275 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4276 dwarf2_objfile_data_key
);
4278 /* If this psymtab is constructed from a debug-only objfile, the
4279 has_section_at_zero flag will not necessarily be correct. We
4280 can get the correct value for this flag by looking at the data
4281 associated with the (presumably stripped) associated objfile. */
4282 if (pst
->objfile
->separate_debug_objfile_backlink
)
4284 struct dwarf2_per_objfile
*dpo_backlink
4285 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4286 dwarf2_objfile_data_key
);
4288 dwarf2_per_objfile
->has_section_at_zero
4289 = dpo_backlink
->has_section_at_zero
;
4292 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4294 psymtab_to_symtab_1 (pst
);
4296 /* Finish up the debug error message. */
4298 printf_filtered (_("done.\n"));
4303 /* Add PER_CU to the queue. */
4306 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4308 struct dwarf2_queue_item
*item
;
4311 item
= xmalloc (sizeof (*item
));
4312 item
->per_cu
= per_cu
;
4315 if (dwarf2_queue
== NULL
)
4316 dwarf2_queue
= item
;
4318 dwarf2_queue_tail
->next
= item
;
4320 dwarf2_queue_tail
= item
;
4323 /* Process the queue. */
4326 process_queue (struct objfile
*objfile
)
4328 struct dwarf2_queue_item
*item
, *next_item
;
4330 /* The queue starts out with one item, but following a DIE reference
4331 may load a new CU, adding it to the end of the queue. */
4332 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4334 if (dwarf2_per_objfile
->using_index
4335 ? !item
->per_cu
->v
.quick
->symtab
4336 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4337 process_full_comp_unit (item
->per_cu
);
4339 item
->per_cu
->queued
= 0;
4340 next_item
= item
->next
;
4344 dwarf2_queue_tail
= NULL
;
4347 /* Free all allocated queue entries. This function only releases anything if
4348 an error was thrown; if the queue was processed then it would have been
4349 freed as we went along. */
4352 dwarf2_release_queue (void *dummy
)
4354 struct dwarf2_queue_item
*item
, *last
;
4356 item
= dwarf2_queue
;
4359 /* Anything still marked queued is likely to be in an
4360 inconsistent state, so discard it. */
4361 if (item
->per_cu
->queued
)
4363 if (item
->per_cu
->cu
!= NULL
)
4364 free_one_cached_comp_unit (item
->per_cu
->cu
);
4365 item
->per_cu
->queued
= 0;
4373 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4376 /* Read in full symbols for PST, and anything it depends on. */
4379 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4381 struct dwarf2_per_cu_data
*per_cu
;
4382 struct cleanup
*back_to
;
4385 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4386 if (!pst
->dependencies
[i
]->readin
)
4388 /* Inform about additional files that need to be read in. */
4391 /* FIXME: i18n: Need to make this a single string. */
4392 fputs_filtered (" ", gdb_stdout
);
4394 fputs_filtered ("and ", gdb_stdout
);
4396 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4397 wrap_here (""); /* Flush output */
4398 gdb_flush (gdb_stdout
);
4400 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4403 per_cu
= pst
->read_symtab_private
;
4407 /* It's an include file, no symbols to read for it.
4408 Everything is in the parent symtab. */
4413 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4416 /* Load the DIEs associated with PER_CU into memory. */
4419 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4421 bfd
*abfd
= objfile
->obfd
;
4422 struct dwarf2_cu
*cu
;
4423 unsigned int offset
;
4424 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4425 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4426 struct attribute
*attr
;
4429 gdb_assert (! per_cu
->from_debug_types
);
4431 /* Set local variables from the partial symbol table info. */
4432 offset
= per_cu
->offset
;
4434 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4435 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4436 beg_of_comp_unit
= info_ptr
;
4438 if (per_cu
->cu
== NULL
)
4440 cu
= xmalloc (sizeof (*cu
));
4441 init_one_comp_unit (cu
, objfile
);
4445 /* If an error occurs while loading, release our storage. */
4446 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4448 /* Read in the comp_unit header. */
4449 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4451 /* Complete the cu_header. */
4452 cu
->header
.offset
= offset
;
4453 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4455 /* Read the abbrevs for this compilation unit. */
4456 dwarf2_read_abbrevs (abfd
, cu
);
4457 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4459 /* Link this compilation unit into the compilation unit tree. */
4461 cu
->per_cu
= per_cu
;
4463 /* Link this CU into read_in_chain. */
4464 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4465 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4470 info_ptr
+= cu
->header
.first_die_offset
;
4473 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4475 /* We try not to read any attributes in this function, because not
4476 all objfiles needed for references have been loaded yet, and symbol
4477 table processing isn't initialized. But we have to set the CU language,
4478 or we won't be able to build types correctly. */
4479 prepare_one_comp_unit (cu
, cu
->dies
);
4481 /* Similarly, if we do not read the producer, we can not apply
4482 producer-specific interpretation. */
4483 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4485 cu
->producer
= DW_STRING (attr
);
4489 do_cleanups (free_abbrevs_cleanup
);
4491 /* We've successfully allocated this compilation unit. Let our
4492 caller clean it up when finished with it. */
4493 discard_cleanups (free_cu_cleanup
);
4497 /* Add a DIE to the delayed physname list. */
4500 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4501 const char *name
, struct die_info
*die
,
4502 struct dwarf2_cu
*cu
)
4504 struct delayed_method_info mi
;
4506 mi
.fnfield_index
= fnfield_index
;
4510 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4513 /* A cleanup for freeing the delayed method list. */
4516 free_delayed_list (void *ptr
)
4518 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4519 if (cu
->method_list
!= NULL
)
4521 VEC_free (delayed_method_info
, cu
->method_list
);
4522 cu
->method_list
= NULL
;
4526 /* Compute the physnames of any methods on the CU's method list.
4528 The computation of method physnames is delayed in order to avoid the
4529 (bad) condition that one of the method's formal parameters is of an as yet
4533 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4536 struct delayed_method_info
*mi
;
4537 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4540 struct fn_fieldlist
*fn_flp
4541 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4542 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4543 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4547 /* Generate full symbol information for PST and CU, whose DIEs have
4548 already been loaded into memory. */
4551 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4553 struct dwarf2_cu
*cu
= per_cu
->cu
;
4554 struct objfile
*objfile
= per_cu
->objfile
;
4555 CORE_ADDR lowpc
, highpc
;
4556 struct symtab
*symtab
;
4557 struct cleanup
*back_to
, *delayed_list_cleanup
;
4560 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4563 back_to
= make_cleanup (really_free_pendings
, NULL
);
4564 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4566 cu
->list_in_scope
= &file_symbols
;
4568 dwarf2_find_base_address (cu
->dies
, cu
);
4570 /* Do line number decoding in read_file_scope () */
4571 process_die (cu
->dies
, cu
);
4573 /* Now that we have processed all the DIEs in the CU, all the types
4574 should be complete, and it should now be safe to compute all of the
4576 compute_delayed_physnames (cu
);
4577 do_cleanups (delayed_list_cleanup
);
4579 /* Some compilers don't define a DW_AT_high_pc attribute for the
4580 compilation unit. If the DW_AT_high_pc is missing, synthesize
4581 it, by scanning the DIE's below the compilation unit. */
4582 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4584 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4586 /* Set symtab language to language from DW_AT_language.
4587 If the compilation is from a C file generated by language preprocessors,
4588 do not set the language if it was already deduced by start_subfile. */
4590 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4592 symtab
->language
= cu
->language
;
4595 if (dwarf2_per_objfile
->using_index
)
4596 per_cu
->v
.quick
->symtab
= symtab
;
4599 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4600 pst
->symtab
= symtab
;
4604 do_cleanups (back_to
);
4607 /* Process a die and its children. */
4610 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4614 case DW_TAG_padding
:
4616 case DW_TAG_compile_unit
:
4617 read_file_scope (die
, cu
);
4619 case DW_TAG_type_unit
:
4620 read_type_unit_scope (die
, cu
);
4622 case DW_TAG_subprogram
:
4623 case DW_TAG_inlined_subroutine
:
4624 read_func_scope (die
, cu
);
4626 case DW_TAG_lexical_block
:
4627 case DW_TAG_try_block
:
4628 case DW_TAG_catch_block
:
4629 read_lexical_block_scope (die
, cu
);
4631 case DW_TAG_class_type
:
4632 case DW_TAG_interface_type
:
4633 case DW_TAG_structure_type
:
4634 case DW_TAG_union_type
:
4635 process_structure_scope (die
, cu
);
4637 case DW_TAG_enumeration_type
:
4638 process_enumeration_scope (die
, cu
);
4641 /* These dies have a type, but processing them does not create
4642 a symbol or recurse to process the children. Therefore we can
4643 read them on-demand through read_type_die. */
4644 case DW_TAG_subroutine_type
:
4645 case DW_TAG_set_type
:
4646 case DW_TAG_array_type
:
4647 case DW_TAG_pointer_type
:
4648 case DW_TAG_ptr_to_member_type
:
4649 case DW_TAG_reference_type
:
4650 case DW_TAG_string_type
:
4653 case DW_TAG_base_type
:
4654 case DW_TAG_subrange_type
:
4655 case DW_TAG_typedef
:
4656 /* Add a typedef symbol for the type definition, if it has a
4658 new_symbol (die
, read_type_die (die
, cu
), cu
);
4660 case DW_TAG_common_block
:
4661 read_common_block (die
, cu
);
4663 case DW_TAG_common_inclusion
:
4665 case DW_TAG_namespace
:
4666 processing_has_namespace_info
= 1;
4667 read_namespace (die
, cu
);
4670 processing_has_namespace_info
= 1;
4671 read_module (die
, cu
);
4673 case DW_TAG_imported_declaration
:
4674 case DW_TAG_imported_module
:
4675 processing_has_namespace_info
= 1;
4676 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4677 || cu
->language
!= language_fortran
))
4678 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4679 dwarf_tag_name (die
->tag
));
4680 read_import_statement (die
, cu
);
4683 new_symbol (die
, NULL
, cu
);
4688 /* A helper function for dwarf2_compute_name which determines whether DIE
4689 needs to have the name of the scope prepended to the name listed in the
4693 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4695 struct attribute
*attr
;
4699 case DW_TAG_namespace
:
4700 case DW_TAG_typedef
:
4701 case DW_TAG_class_type
:
4702 case DW_TAG_interface_type
:
4703 case DW_TAG_structure_type
:
4704 case DW_TAG_union_type
:
4705 case DW_TAG_enumeration_type
:
4706 case DW_TAG_enumerator
:
4707 case DW_TAG_subprogram
:
4711 case DW_TAG_variable
:
4712 case DW_TAG_constant
:
4713 /* We only need to prefix "globally" visible variables. These include
4714 any variable marked with DW_AT_external or any variable that
4715 lives in a namespace. [Variables in anonymous namespaces
4716 require prefixing, but they are not DW_AT_external.] */
4718 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4720 struct dwarf2_cu
*spec_cu
= cu
;
4722 return die_needs_namespace (die_specification (die
, &spec_cu
),
4726 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4727 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4728 && die
->parent
->tag
!= DW_TAG_module
)
4730 /* A variable in a lexical block of some kind does not need a
4731 namespace, even though in C++ such variables may be external
4732 and have a mangled name. */
4733 if (die
->parent
->tag
== DW_TAG_lexical_block
4734 || die
->parent
->tag
== DW_TAG_try_block
4735 || die
->parent
->tag
== DW_TAG_catch_block
4736 || die
->parent
->tag
== DW_TAG_subprogram
)
4745 /* Retrieve the last character from a mem_file. */
4748 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4750 char *last_char_p
= (char *) object
;
4753 *last_char_p
= buffer
[length
- 1];
4756 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4757 compute the physname for the object, which include a method's
4758 formal parameters (C++/Java) and return type (Java).
4760 For Ada, return the DIE's linkage name rather than the fully qualified
4761 name. PHYSNAME is ignored..
4763 The result is allocated on the objfile_obstack and canonicalized. */
4766 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4770 name
= dwarf2_name (die
, cu
);
4772 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4773 compute it by typename_concat inside GDB. */
4774 if (cu
->language
== language_ada
4775 || (cu
->language
== language_fortran
&& physname
))
4777 /* For Ada unit, we prefer the linkage name over the name, as
4778 the former contains the exported name, which the user expects
4779 to be able to reference. Ideally, we want the user to be able
4780 to reference this entity using either natural or linkage name,
4781 but we haven't started looking at this enhancement yet. */
4782 struct attribute
*attr
;
4784 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4786 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4787 if (attr
&& DW_STRING (attr
))
4788 return DW_STRING (attr
);
4791 /* These are the only languages we know how to qualify names in. */
4793 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4794 || cu
->language
== language_fortran
))
4796 if (die_needs_namespace (die
, cu
))
4800 struct ui_file
*buf
;
4802 prefix
= determine_prefix (die
, cu
);
4803 buf
= mem_fileopen ();
4804 if (*prefix
!= '\0')
4806 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4809 fputs_unfiltered (prefixed_name
, buf
);
4810 xfree (prefixed_name
);
4813 fputs_unfiltered (name
? name
: "", buf
);
4815 /* Template parameters may be specified in the DIE's DW_AT_name, or
4816 as children with DW_TAG_template_type_param or
4817 DW_TAG_value_type_param. If the latter, add them to the name
4818 here. If the name already has template parameters, then
4819 skip this step; some versions of GCC emit both, and
4820 it is more efficient to use the pre-computed name.
4822 Something to keep in mind about this process: it is very
4823 unlikely, or in some cases downright impossible, to produce
4824 something that will match the mangled name of a function.
4825 If the definition of the function has the same debug info,
4826 we should be able to match up with it anyway. But fallbacks
4827 using the minimal symbol, for instance to find a method
4828 implemented in a stripped copy of libstdc++, will not work.
4829 If we do not have debug info for the definition, we will have to
4830 match them up some other way.
4832 When we do name matching there is a related problem with function
4833 templates; two instantiated function templates are allowed to
4834 differ only by their return types, which we do not add here. */
4836 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4838 struct attribute
*attr
;
4839 struct die_info
*child
;
4842 die
->building_fullname
= 1;
4844 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4849 struct dwarf2_locexpr_baton
*baton
;
4852 if (child
->tag
!= DW_TAG_template_type_param
4853 && child
->tag
!= DW_TAG_template_value_param
)
4858 fputs_unfiltered ("<", buf
);
4862 fputs_unfiltered (", ", buf
);
4864 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4867 complaint (&symfile_complaints
,
4868 _("template parameter missing DW_AT_type"));
4869 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4872 type
= die_type (child
, cu
);
4874 if (child
->tag
== DW_TAG_template_type_param
)
4876 c_print_type (type
, "", buf
, -1, 0);
4880 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4883 complaint (&symfile_complaints
,
4884 _("template parameter missing DW_AT_const_value"));
4885 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4889 dwarf2_const_value_attr (attr
, type
, name
,
4890 &cu
->comp_unit_obstack
, cu
,
4891 &value
, &bytes
, &baton
);
4893 if (TYPE_NOSIGN (type
))
4894 /* GDB prints characters as NUMBER 'CHAR'. If that's
4895 changed, this can use value_print instead. */
4896 c_printchar (value
, type
, buf
);
4899 struct value_print_options opts
;
4902 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4906 else if (bytes
!= NULL
)
4908 v
= allocate_value (type
);
4909 memcpy (value_contents_writeable (v
), bytes
,
4910 TYPE_LENGTH (type
));
4913 v
= value_from_longest (type
, value
);
4915 /* Specify decimal so that we do not depend on the radix. */
4916 get_formatted_print_options (&opts
, 'd');
4918 value_print (v
, buf
, &opts
);
4924 die
->building_fullname
= 0;
4928 /* Close the argument list, with a space if necessary
4929 (nested templates). */
4930 char last_char
= '\0';
4931 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4932 if (last_char
== '>')
4933 fputs_unfiltered (" >", buf
);
4935 fputs_unfiltered (">", buf
);
4939 /* For Java and C++ methods, append formal parameter type
4940 information, if PHYSNAME. */
4942 if (physname
&& die
->tag
== DW_TAG_subprogram
4943 && (cu
->language
== language_cplus
4944 || cu
->language
== language_java
))
4946 struct type
*type
= read_type_die (die
, cu
);
4948 c_type_print_args (type
, buf
, 0, cu
->language
);
4950 if (cu
->language
== language_java
)
4952 /* For java, we must append the return type to method
4954 if (die
->tag
== DW_TAG_subprogram
)
4955 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4958 else if (cu
->language
== language_cplus
)
4960 /* Assume that an artificial first parameter is
4961 "this", but do not crash if it is not. RealView
4962 marks unnamed (and thus unused) parameters as
4963 artificial; there is no way to differentiate
4965 if (TYPE_NFIELDS (type
) > 0
4966 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4967 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4968 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4969 fputs_unfiltered (" const", buf
);
4973 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4975 ui_file_delete (buf
);
4977 if (cu
->language
== language_cplus
)
4980 = dwarf2_canonicalize_name (name
, cu
,
4981 &cu
->objfile
->objfile_obstack
);
4992 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4993 If scope qualifiers are appropriate they will be added. The result
4994 will be allocated on the objfile_obstack, or NULL if the DIE does
4995 not have a name. NAME may either be from a previous call to
4996 dwarf2_name or NULL.
4998 The output string will be canonicalized (if C++/Java). */
5001 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5003 return dwarf2_compute_name (name
, die
, cu
, 0);
5006 /* Construct a physname for the given DIE in CU. NAME may either be
5007 from a previous call to dwarf2_name or NULL. The result will be
5008 allocated on the objfile_objstack or NULL if the DIE does not have a
5011 The output string will be canonicalized (if C++/Java). */
5014 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5016 return dwarf2_compute_name (name
, die
, cu
, 1);
5019 /* Read the import statement specified by the given die and record it. */
5022 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5024 struct attribute
*import_attr
;
5025 struct die_info
*imported_die
;
5026 struct dwarf2_cu
*imported_cu
;
5027 const char *imported_name
;
5028 const char *imported_name_prefix
;
5029 const char *canonical_name
;
5030 const char *import_alias
;
5031 const char *imported_declaration
= NULL
;
5032 const char *import_prefix
;
5036 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5037 if (import_attr
== NULL
)
5039 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5040 dwarf_tag_name (die
->tag
));
5045 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5046 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5047 if (imported_name
== NULL
)
5049 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5051 The import in the following code:
5065 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5066 <52> DW_AT_decl_file : 1
5067 <53> DW_AT_decl_line : 6
5068 <54> DW_AT_import : <0x75>
5069 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5071 <5b> DW_AT_decl_file : 1
5072 <5c> DW_AT_decl_line : 2
5073 <5d> DW_AT_type : <0x6e>
5075 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5076 <76> DW_AT_byte_size : 4
5077 <77> DW_AT_encoding : 5 (signed)
5079 imports the wrong die ( 0x75 instead of 0x58 ).
5080 This case will be ignored until the gcc bug is fixed. */
5084 /* Figure out the local name after import. */
5085 import_alias
= dwarf2_name (die
, cu
);
5087 /* Figure out where the statement is being imported to. */
5088 import_prefix
= determine_prefix (die
, cu
);
5090 /* Figure out what the scope of the imported die is and prepend it
5091 to the name of the imported die. */
5092 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5094 if (imported_die
->tag
!= DW_TAG_namespace
5095 && imported_die
->tag
!= DW_TAG_module
)
5097 imported_declaration
= imported_name
;
5098 canonical_name
= imported_name_prefix
;
5100 else if (strlen (imported_name_prefix
) > 0)
5102 temp
= alloca (strlen (imported_name_prefix
)
5103 + 2 + strlen (imported_name
) + 1);
5104 strcpy (temp
, imported_name_prefix
);
5105 strcat (temp
, "::");
5106 strcat (temp
, imported_name
);
5107 canonical_name
= temp
;
5110 canonical_name
= imported_name
;
5112 cp_add_using_directive (import_prefix
,
5115 imported_declaration
,
5116 &cu
->objfile
->objfile_obstack
);
5120 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5122 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5125 /* Cleanup function for read_file_scope. */
5128 free_cu_line_header (void *arg
)
5130 struct dwarf2_cu
*cu
= arg
;
5132 free_line_header (cu
->line_header
);
5133 cu
->line_header
= NULL
;
5137 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5138 char **name
, char **comp_dir
)
5140 struct attribute
*attr
;
5145 /* Find the filename. Do not use dwarf2_name here, since the filename
5146 is not a source language identifier. */
5147 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5150 *name
= DW_STRING (attr
);
5153 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5155 *comp_dir
= DW_STRING (attr
);
5156 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5158 *comp_dir
= ldirname (*name
);
5159 if (*comp_dir
!= NULL
)
5160 make_cleanup (xfree
, *comp_dir
);
5162 if (*comp_dir
!= NULL
)
5164 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5165 directory, get rid of it. */
5166 char *cp
= strchr (*comp_dir
, ':');
5168 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5173 *name
= "<unknown>";
5176 /* Process DW_TAG_compile_unit. */
5179 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5181 struct objfile
*objfile
= cu
->objfile
;
5182 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5183 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5184 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5185 struct attribute
*attr
;
5187 char *comp_dir
= NULL
;
5188 struct die_info
*child_die
;
5189 bfd
*abfd
= objfile
->obfd
;
5190 struct line_header
*line_header
= 0;
5193 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5195 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5197 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5198 from finish_block. */
5199 if (lowpc
== ((CORE_ADDR
) -1))
5204 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5206 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5209 set_cu_language (DW_UNSND (attr
), cu
);
5212 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5214 cu
->producer
= DW_STRING (attr
);
5216 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5217 standardised yet. As a workaround for the language detection we fall
5218 back to the DW_AT_producer string. */
5219 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5220 cu
->language
= language_opencl
;
5222 /* We assume that we're processing GCC output. */
5223 processing_gcc_compilation
= 2;
5225 processing_has_namespace_info
= 0;
5227 start_symtab (name
, comp_dir
, lowpc
);
5228 record_debugformat ("DWARF 2");
5229 record_producer (cu
->producer
);
5231 initialize_cu_func_list (cu
);
5233 /* Decode line number information if present. We do this before
5234 processing child DIEs, so that the line header table is available
5235 for DW_AT_decl_file. */
5236 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5239 unsigned int line_offset
= DW_UNSND (attr
);
5240 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5243 cu
->line_header
= line_header
;
5244 make_cleanup (free_cu_line_header
, cu
);
5245 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5249 /* Process all dies in compilation unit. */
5250 if (die
->child
!= NULL
)
5252 child_die
= die
->child
;
5253 while (child_die
&& child_die
->tag
)
5255 process_die (child_die
, cu
);
5256 child_die
= sibling_die (child_die
);
5260 /* Decode macro information, if present. Dwarf 2 macro information
5261 refers to information in the line number info statement program
5262 header, so we can only read it if we've read the header
5264 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5265 if (attr
&& line_header
)
5267 unsigned int macro_offset
= DW_UNSND (attr
);
5269 dwarf_decode_macros (line_header
, macro_offset
,
5270 comp_dir
, abfd
, cu
);
5272 do_cleanups (back_to
);
5275 /* Process DW_TAG_type_unit.
5276 For TUs we want to skip the first top level sibling if it's not the
5277 actual type being defined by this TU. In this case the first top
5278 level sibling is there to provide context only. */
5281 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5283 struct objfile
*objfile
= cu
->objfile
;
5284 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5286 struct attribute
*attr
;
5288 char *comp_dir
= NULL
;
5289 struct die_info
*child_die
;
5290 bfd
*abfd
= objfile
->obfd
;
5292 /* start_symtab needs a low pc, but we don't really have one.
5293 Do what read_file_scope would do in the absence of such info. */
5294 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5296 /* Find the filename. Do not use dwarf2_name here, since the filename
5297 is not a source language identifier. */
5298 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5300 name
= DW_STRING (attr
);
5302 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5304 comp_dir
= DW_STRING (attr
);
5305 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5307 comp_dir
= ldirname (name
);
5308 if (comp_dir
!= NULL
)
5309 make_cleanup (xfree
, comp_dir
);
5315 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5317 set_cu_language (DW_UNSND (attr
), cu
);
5319 /* This isn't technically needed today. It is done for symmetry
5320 with read_file_scope. */
5321 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5323 cu
->producer
= DW_STRING (attr
);
5325 /* We assume that we're processing GCC output. */
5326 processing_gcc_compilation
= 2;
5328 processing_has_namespace_info
= 0;
5330 start_symtab (name
, comp_dir
, lowpc
);
5331 record_debugformat ("DWARF 2");
5332 record_producer (cu
->producer
);
5334 /* Process the dies in the type unit. */
5335 if (die
->child
== NULL
)
5337 dump_die_for_error (die
);
5338 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5339 bfd_get_filename (abfd
));
5342 child_die
= die
->child
;
5344 while (child_die
&& child_die
->tag
)
5346 process_die (child_die
, cu
);
5348 child_die
= sibling_die (child_die
);
5351 do_cleanups (back_to
);
5355 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5356 struct dwarf2_cu
*cu
)
5358 struct function_range
*thisfn
;
5360 thisfn
= (struct function_range
*)
5361 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5362 thisfn
->name
= name
;
5363 thisfn
->lowpc
= lowpc
;
5364 thisfn
->highpc
= highpc
;
5365 thisfn
->seen_line
= 0;
5366 thisfn
->next
= NULL
;
5368 if (cu
->last_fn
== NULL
)
5369 cu
->first_fn
= thisfn
;
5371 cu
->last_fn
->next
= thisfn
;
5373 cu
->last_fn
= thisfn
;
5376 /* qsort helper for inherit_abstract_dies. */
5379 unsigned_int_compar (const void *ap
, const void *bp
)
5381 unsigned int a
= *(unsigned int *) ap
;
5382 unsigned int b
= *(unsigned int *) bp
;
5384 return (a
> b
) - (b
> a
);
5387 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5388 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5389 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5392 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5394 struct die_info
*child_die
;
5395 unsigned die_children_count
;
5396 /* CU offsets which were referenced by children of the current DIE. */
5398 unsigned *offsets_end
, *offsetp
;
5399 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5400 struct die_info
*origin_die
;
5401 /* Iterator of the ORIGIN_DIE children. */
5402 struct die_info
*origin_child_die
;
5403 struct cleanup
*cleanups
;
5404 struct attribute
*attr
;
5405 struct dwarf2_cu
*origin_cu
;
5406 struct pending
**origin_previous_list_in_scope
;
5408 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5412 /* Note that following die references may follow to a die in a
5416 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5418 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5420 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5421 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5423 if (die
->tag
!= origin_die
->tag
5424 && !(die
->tag
== DW_TAG_inlined_subroutine
5425 && origin_die
->tag
== DW_TAG_subprogram
))
5426 complaint (&symfile_complaints
,
5427 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5428 die
->offset
, origin_die
->offset
);
5430 child_die
= die
->child
;
5431 die_children_count
= 0;
5432 while (child_die
&& child_die
->tag
)
5434 child_die
= sibling_die (child_die
);
5435 die_children_count
++;
5437 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5438 cleanups
= make_cleanup (xfree
, offsets
);
5440 offsets_end
= offsets
;
5441 child_die
= die
->child
;
5442 while (child_die
&& child_die
->tag
)
5444 /* For each CHILD_DIE, find the corresponding child of
5445 ORIGIN_DIE. If there is more than one layer of
5446 DW_AT_abstract_origin, follow them all; there shouldn't be,
5447 but GCC versions at least through 4.4 generate this (GCC PR
5449 struct die_info
*child_origin_die
= child_die
;
5450 struct dwarf2_cu
*child_origin_cu
= cu
;
5454 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5458 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5462 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5463 counterpart may exist. */
5464 if (child_origin_die
!= child_die
)
5466 if (child_die
->tag
!= child_origin_die
->tag
5467 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5468 && child_origin_die
->tag
== DW_TAG_subprogram
))
5469 complaint (&symfile_complaints
,
5470 _("Child DIE 0x%x and its abstract origin 0x%x have "
5471 "different tags"), child_die
->offset
,
5472 child_origin_die
->offset
);
5473 if (child_origin_die
->parent
!= origin_die
)
5474 complaint (&symfile_complaints
,
5475 _("Child DIE 0x%x and its abstract origin 0x%x have "
5476 "different parents"), child_die
->offset
,
5477 child_origin_die
->offset
);
5479 *offsets_end
++ = child_origin_die
->offset
;
5481 child_die
= sibling_die (child_die
);
5483 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5484 unsigned_int_compar
);
5485 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5486 if (offsetp
[-1] == *offsetp
)
5487 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5488 "to DIE 0x%x as their abstract origin"),
5489 die
->offset
, *offsetp
);
5492 origin_child_die
= origin_die
->child
;
5493 while (origin_child_die
&& origin_child_die
->tag
)
5495 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5496 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5498 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5500 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5501 process_die (origin_child_die
, origin_cu
);
5503 origin_child_die
= sibling_die (origin_child_die
);
5505 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5507 do_cleanups (cleanups
);
5511 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5513 struct objfile
*objfile
= cu
->objfile
;
5514 struct context_stack
*new;
5517 struct die_info
*child_die
;
5518 struct attribute
*attr
, *call_line
, *call_file
;
5521 struct block
*block
;
5522 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5523 VEC (symbolp
) *template_args
= NULL
;
5524 struct template_symbol
*templ_func
= NULL
;
5528 /* If we do not have call site information, we can't show the
5529 caller of this inlined function. That's too confusing, so
5530 only use the scope for local variables. */
5531 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5532 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5533 if (call_line
== NULL
|| call_file
== NULL
)
5535 read_lexical_block_scope (die
, cu
);
5540 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5542 name
= dwarf2_name (die
, cu
);
5544 /* Ignore functions with missing or empty names. These are actually
5545 illegal according to the DWARF standard. */
5548 complaint (&symfile_complaints
,
5549 _("missing name for subprogram DIE at %d"), die
->offset
);
5553 /* Ignore functions with missing or invalid low and high pc attributes. */
5554 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5556 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5557 if (!attr
|| !DW_UNSND (attr
))
5558 complaint (&symfile_complaints
,
5559 _("cannot get low and high bounds for subprogram DIE at %d"),
5567 /* Record the function range for dwarf_decode_lines. */
5568 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5570 /* If we have any template arguments, then we must allocate a
5571 different sort of symbol. */
5572 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5574 if (child_die
->tag
== DW_TAG_template_type_param
5575 || child_die
->tag
== DW_TAG_template_value_param
)
5577 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5578 struct template_symbol
);
5579 templ_func
->base
.is_cplus_template_function
= 1;
5584 new = push_context (0, lowpc
);
5585 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5586 (struct symbol
*) templ_func
);
5588 /* If there is a location expression for DW_AT_frame_base, record
5590 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5592 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5593 expression is being recorded directly in the function's symbol
5594 and not in a separate frame-base object. I guess this hack is
5595 to avoid adding some sort of frame-base adjunct/annex to the
5596 function's symbol :-(. The problem with doing this is that it
5597 results in a function symbol with a location expression that
5598 has nothing to do with the location of the function, ouch! The
5599 relationship should be: a function's symbol has-a frame base; a
5600 frame-base has-a location expression. */
5601 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5603 cu
->list_in_scope
= &local_symbols
;
5605 if (die
->child
!= NULL
)
5607 child_die
= die
->child
;
5608 while (child_die
&& child_die
->tag
)
5610 if (child_die
->tag
== DW_TAG_template_type_param
5611 || child_die
->tag
== DW_TAG_template_value_param
)
5613 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5616 VEC_safe_push (symbolp
, template_args
, arg
);
5619 process_die (child_die
, cu
);
5620 child_die
= sibling_die (child_die
);
5624 inherit_abstract_dies (die
, cu
);
5626 /* If we have a DW_AT_specification, we might need to import using
5627 directives from the context of the specification DIE. See the
5628 comment in determine_prefix. */
5629 if (cu
->language
== language_cplus
5630 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5632 struct dwarf2_cu
*spec_cu
= cu
;
5633 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5637 child_die
= spec_die
->child
;
5638 while (child_die
&& child_die
->tag
)
5640 if (child_die
->tag
== DW_TAG_imported_module
)
5641 process_die (child_die
, spec_cu
);
5642 child_die
= sibling_die (child_die
);
5645 /* In some cases, GCC generates specification DIEs that
5646 themselves contain DW_AT_specification attributes. */
5647 spec_die
= die_specification (spec_die
, &spec_cu
);
5651 new = pop_context ();
5652 /* Make a block for the local symbols within. */
5653 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5654 lowpc
, highpc
, objfile
);
5656 /* For C++, set the block's scope. */
5657 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5658 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5659 determine_prefix (die
, cu
),
5660 processing_has_namespace_info
);
5662 /* If we have address ranges, record them. */
5663 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5665 /* Attach template arguments to function. */
5666 if (! VEC_empty (symbolp
, template_args
))
5668 gdb_assert (templ_func
!= NULL
);
5670 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5671 templ_func
->template_arguments
5672 = obstack_alloc (&objfile
->objfile_obstack
,
5673 (templ_func
->n_template_arguments
5674 * sizeof (struct symbol
*)));
5675 memcpy (templ_func
->template_arguments
,
5676 VEC_address (symbolp
, template_args
),
5677 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5678 VEC_free (symbolp
, template_args
);
5681 /* In C++, we can have functions nested inside functions (e.g., when
5682 a function declares a class that has methods). This means that
5683 when we finish processing a function scope, we may need to go
5684 back to building a containing block's symbol lists. */
5685 local_symbols
= new->locals
;
5686 param_symbols
= new->params
;
5687 using_directives
= new->using_directives
;
5689 /* If we've finished processing a top-level function, subsequent
5690 symbols go in the file symbol list. */
5691 if (outermost_context_p ())
5692 cu
->list_in_scope
= &file_symbols
;
5695 /* Process all the DIES contained within a lexical block scope. Start
5696 a new scope, process the dies, and then close the scope. */
5699 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5701 struct objfile
*objfile
= cu
->objfile
;
5702 struct context_stack
*new;
5703 CORE_ADDR lowpc
, highpc
;
5704 struct die_info
*child_die
;
5707 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5709 /* Ignore blocks with missing or invalid low and high pc attributes. */
5710 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5711 as multiple lexical blocks? Handling children in a sane way would
5712 be nasty. Might be easier to properly extend generic blocks to
5714 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5719 push_context (0, lowpc
);
5720 if (die
->child
!= NULL
)
5722 child_die
= die
->child
;
5723 while (child_die
&& child_die
->tag
)
5725 process_die (child_die
, cu
);
5726 child_die
= sibling_die (child_die
);
5729 new = pop_context ();
5731 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5734 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5737 /* Note that recording ranges after traversing children, as we
5738 do here, means that recording a parent's ranges entails
5739 walking across all its children's ranges as they appear in
5740 the address map, which is quadratic behavior.
5742 It would be nicer to record the parent's ranges before
5743 traversing its children, simply overriding whatever you find
5744 there. But since we don't even decide whether to create a
5745 block until after we've traversed its children, that's hard
5747 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5749 local_symbols
= new->locals
;
5750 using_directives
= new->using_directives
;
5753 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5754 Return 1 if the attributes are present and valid, otherwise, return 0.
5755 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5758 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5759 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5760 struct partial_symtab
*ranges_pst
)
5762 struct objfile
*objfile
= cu
->objfile
;
5763 struct comp_unit_head
*cu_header
= &cu
->header
;
5764 bfd
*obfd
= objfile
->obfd
;
5765 unsigned int addr_size
= cu_header
->addr_size
;
5766 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5767 /* Base address selection entry. */
5778 found_base
= cu
->base_known
;
5779 base
= cu
->base_address
;
5781 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5782 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5784 complaint (&symfile_complaints
,
5785 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5789 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5791 /* Read in the largest possible address. */
5792 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5793 if ((marker
& mask
) == mask
)
5795 /* If we found the largest possible address, then
5796 read the base address. */
5797 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5798 buffer
+= 2 * addr_size
;
5799 offset
+= 2 * addr_size
;
5805 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5809 CORE_ADDR range_beginning
, range_end
;
5811 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5812 buffer
+= addr_size
;
5813 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5814 buffer
+= addr_size
;
5815 offset
+= 2 * addr_size
;
5817 /* An end of list marker is a pair of zero addresses. */
5818 if (range_beginning
== 0 && range_end
== 0)
5819 /* Found the end of list entry. */
5822 /* Each base address selection entry is a pair of 2 values.
5823 The first is the largest possible address, the second is
5824 the base address. Check for a base address here. */
5825 if ((range_beginning
& mask
) == mask
)
5827 /* If we found the largest possible address, then
5828 read the base address. */
5829 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5836 /* We have no valid base address for the ranges
5838 complaint (&symfile_complaints
,
5839 _("Invalid .debug_ranges data (no base address)"));
5843 range_beginning
+= base
;
5846 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5847 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5848 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5851 /* FIXME: This is recording everything as a low-high
5852 segment of consecutive addresses. We should have a
5853 data structure for discontiguous block ranges
5857 low
= range_beginning
;
5863 if (range_beginning
< low
)
5864 low
= range_beginning
;
5865 if (range_end
> high
)
5871 /* If the first entry is an end-of-list marker, the range
5872 describes an empty scope, i.e. no instructions. */
5878 *high_return
= high
;
5882 /* Get low and high pc attributes from a die. Return 1 if the attributes
5883 are present and valid, otherwise, return 0. Return -1 if the range is
5884 discontinuous, i.e. derived from DW_AT_ranges information. */
5886 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5887 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5888 struct partial_symtab
*pst
)
5890 struct attribute
*attr
;
5895 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5898 high
= DW_ADDR (attr
);
5899 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5901 low
= DW_ADDR (attr
);
5903 /* Found high w/o low attribute. */
5906 /* Found consecutive range of addresses. */
5911 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5914 /* Value of the DW_AT_ranges attribute is the offset in the
5915 .debug_ranges section. */
5916 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5918 /* Found discontinuous range of addresses. */
5926 /* When using the GNU linker, .gnu.linkonce. sections are used to
5927 eliminate duplicate copies of functions and vtables and such.
5928 The linker will arbitrarily choose one and discard the others.
5929 The AT_*_pc values for such functions refer to local labels in
5930 these sections. If the section from that file was discarded, the
5931 labels are not in the output, so the relocs get a value of 0.
5932 If this is a discarded function, mark the pc bounds as invalid,
5933 so that GDB will ignore it. */
5934 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5942 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5943 its low and high PC addresses. Do nothing if these addresses could not
5944 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5945 and HIGHPC to the high address if greater than HIGHPC. */
5948 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5949 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5950 struct dwarf2_cu
*cu
)
5952 CORE_ADDR low
, high
;
5953 struct die_info
*child
= die
->child
;
5955 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5957 *lowpc
= min (*lowpc
, low
);
5958 *highpc
= max (*highpc
, high
);
5961 /* If the language does not allow nested subprograms (either inside
5962 subprograms or lexical blocks), we're done. */
5963 if (cu
->language
!= language_ada
)
5966 /* Check all the children of the given DIE. If it contains nested
5967 subprograms, then check their pc bounds. Likewise, we need to
5968 check lexical blocks as well, as they may also contain subprogram
5970 while (child
&& child
->tag
)
5972 if (child
->tag
== DW_TAG_subprogram
5973 || child
->tag
== DW_TAG_lexical_block
)
5974 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5975 child
= sibling_die (child
);
5979 /* Get the low and high pc's represented by the scope DIE, and store
5980 them in *LOWPC and *HIGHPC. If the correct values can't be
5981 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5984 get_scope_pc_bounds (struct die_info
*die
,
5985 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5986 struct dwarf2_cu
*cu
)
5988 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5989 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5990 CORE_ADDR current_low
, current_high
;
5992 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5994 best_low
= current_low
;
5995 best_high
= current_high
;
5999 struct die_info
*child
= die
->child
;
6001 while (child
&& child
->tag
)
6003 switch (child
->tag
) {
6004 case DW_TAG_subprogram
:
6005 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6007 case DW_TAG_namespace
:
6009 /* FIXME: carlton/2004-01-16: Should we do this for
6010 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6011 that current GCC's always emit the DIEs corresponding
6012 to definitions of methods of classes as children of a
6013 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6014 the DIEs giving the declarations, which could be
6015 anywhere). But I don't see any reason why the
6016 standards says that they have to be there. */
6017 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6019 if (current_low
!= ((CORE_ADDR
) -1))
6021 best_low
= min (best_low
, current_low
);
6022 best_high
= max (best_high
, current_high
);
6030 child
= sibling_die (child
);
6035 *highpc
= best_high
;
6038 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6041 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6042 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6044 struct attribute
*attr
;
6046 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6049 CORE_ADDR high
= DW_ADDR (attr
);
6051 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6054 CORE_ADDR low
= DW_ADDR (attr
);
6056 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6060 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6063 bfd
*obfd
= cu
->objfile
->obfd
;
6065 /* The value of the DW_AT_ranges attribute is the offset of the
6066 address range list in the .debug_ranges section. */
6067 unsigned long offset
= DW_UNSND (attr
);
6068 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6070 /* For some target architectures, but not others, the
6071 read_address function sign-extends the addresses it returns.
6072 To recognize base address selection entries, we need a
6074 unsigned int addr_size
= cu
->header
.addr_size
;
6075 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6077 /* The base address, to which the next pair is relative. Note
6078 that this 'base' is a DWARF concept: most entries in a range
6079 list are relative, to reduce the number of relocs against the
6080 debugging information. This is separate from this function's
6081 'baseaddr' argument, which GDB uses to relocate debugging
6082 information from a shared library based on the address at
6083 which the library was loaded. */
6084 CORE_ADDR base
= cu
->base_address
;
6085 int base_known
= cu
->base_known
;
6087 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6088 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6090 complaint (&symfile_complaints
,
6091 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6098 unsigned int bytes_read
;
6099 CORE_ADDR start
, end
;
6101 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6102 buffer
+= bytes_read
;
6103 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6104 buffer
+= bytes_read
;
6106 /* Did we find the end of the range list? */
6107 if (start
== 0 && end
== 0)
6110 /* Did we find a base address selection entry? */
6111 else if ((start
& base_select_mask
) == base_select_mask
)
6117 /* We found an ordinary address range. */
6122 complaint (&symfile_complaints
,
6123 _("Invalid .debug_ranges data (no base address)"));
6127 record_block_range (block
,
6128 baseaddr
+ base
+ start
,
6129 baseaddr
+ base
+ end
- 1);
6135 /* Add an aggregate field to the field list. */
6138 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6139 struct dwarf2_cu
*cu
)
6141 struct objfile
*objfile
= cu
->objfile
;
6142 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6143 struct nextfield
*new_field
;
6144 struct attribute
*attr
;
6146 char *fieldname
= "";
6148 /* Allocate a new field list entry and link it in. */
6149 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6150 make_cleanup (xfree
, new_field
);
6151 memset (new_field
, 0, sizeof (struct nextfield
));
6153 if (die
->tag
== DW_TAG_inheritance
)
6155 new_field
->next
= fip
->baseclasses
;
6156 fip
->baseclasses
= new_field
;
6160 new_field
->next
= fip
->fields
;
6161 fip
->fields
= new_field
;
6165 /* Handle accessibility and virtuality of field.
6166 The default accessibility for members is public, the default
6167 accessibility for inheritance is private. */
6168 if (die
->tag
!= DW_TAG_inheritance
)
6169 new_field
->accessibility
= DW_ACCESS_public
;
6171 new_field
->accessibility
= DW_ACCESS_private
;
6172 new_field
->virtuality
= DW_VIRTUALITY_none
;
6174 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6176 new_field
->accessibility
= DW_UNSND (attr
);
6177 if (new_field
->accessibility
!= DW_ACCESS_public
)
6178 fip
->non_public_fields
= 1;
6179 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6181 new_field
->virtuality
= DW_UNSND (attr
);
6183 fp
= &new_field
->field
;
6185 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6187 /* Data member other than a C++ static data member. */
6189 /* Get type of field. */
6190 fp
->type
= die_type (die
, cu
);
6192 SET_FIELD_BITPOS (*fp
, 0);
6194 /* Get bit size of field (zero if none). */
6195 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6198 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6202 FIELD_BITSIZE (*fp
) = 0;
6205 /* Get bit offset of field. */
6206 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6209 int byte_offset
= 0;
6211 if (attr_form_is_section_offset (attr
))
6212 dwarf2_complex_location_expr_complaint ();
6213 else if (attr_form_is_constant (attr
))
6214 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6215 else if (attr_form_is_block (attr
))
6216 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6218 dwarf2_complex_location_expr_complaint ();
6220 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6222 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6225 if (gdbarch_bits_big_endian (gdbarch
))
6227 /* For big endian bits, the DW_AT_bit_offset gives the
6228 additional bit offset from the MSB of the containing
6229 anonymous object to the MSB of the field. We don't
6230 have to do anything special since we don't need to
6231 know the size of the anonymous object. */
6232 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6236 /* For little endian bits, compute the bit offset to the
6237 MSB of the anonymous object, subtract off the number of
6238 bits from the MSB of the field to the MSB of the
6239 object, and then subtract off the number of bits of
6240 the field itself. The result is the bit offset of
6241 the LSB of the field. */
6243 int bit_offset
= DW_UNSND (attr
);
6245 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6248 /* The size of the anonymous object containing
6249 the bit field is explicit, so use the
6250 indicated size (in bytes). */
6251 anonymous_size
= DW_UNSND (attr
);
6255 /* The size of the anonymous object containing
6256 the bit field must be inferred from the type
6257 attribute of the data member containing the
6259 anonymous_size
= TYPE_LENGTH (fp
->type
);
6261 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6262 - bit_offset
- FIELD_BITSIZE (*fp
);
6266 /* Get name of field. */
6267 fieldname
= dwarf2_name (die
, cu
);
6268 if (fieldname
== NULL
)
6271 /* The name is already allocated along with this objfile, so we don't
6272 need to duplicate it for the type. */
6273 fp
->name
= fieldname
;
6275 /* Change accessibility for artificial fields (e.g. virtual table
6276 pointer or virtual base class pointer) to private. */
6277 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6279 FIELD_ARTIFICIAL (*fp
) = 1;
6280 new_field
->accessibility
= DW_ACCESS_private
;
6281 fip
->non_public_fields
= 1;
6284 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6286 /* C++ static member. */
6288 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6289 is a declaration, but all versions of G++ as of this writing
6290 (so through at least 3.2.1) incorrectly generate
6291 DW_TAG_variable tags. */
6295 /* Get name of field. */
6296 fieldname
= dwarf2_name (die
, cu
);
6297 if (fieldname
== NULL
)
6300 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6302 /* Only create a symbol if this is an external value.
6303 new_symbol checks this and puts the value in the global symbol
6304 table, which we want. If it is not external, new_symbol
6305 will try to put the value in cu->list_in_scope which is wrong. */
6306 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6308 /* A static const member, not much different than an enum as far as
6309 we're concerned, except that we can support more types. */
6310 new_symbol (die
, NULL
, cu
);
6313 /* Get physical name. */
6314 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6316 /* The name is already allocated along with this objfile, so we don't
6317 need to duplicate it for the type. */
6318 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6319 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6320 FIELD_NAME (*fp
) = fieldname
;
6322 else if (die
->tag
== DW_TAG_inheritance
)
6324 /* C++ base class field. */
6325 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6328 int byte_offset
= 0;
6330 if (attr_form_is_section_offset (attr
))
6331 dwarf2_complex_location_expr_complaint ();
6332 else if (attr_form_is_constant (attr
))
6333 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6334 else if (attr_form_is_block (attr
))
6335 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6337 dwarf2_complex_location_expr_complaint ();
6339 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6341 FIELD_BITSIZE (*fp
) = 0;
6342 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6343 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6344 fip
->nbaseclasses
++;
6348 /* Add a typedef defined in the scope of the FIP's class. */
6351 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6352 struct dwarf2_cu
*cu
)
6354 struct objfile
*objfile
= cu
->objfile
;
6355 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6356 struct typedef_field_list
*new_field
;
6357 struct attribute
*attr
;
6358 struct typedef_field
*fp
;
6359 char *fieldname
= "";
6361 /* Allocate a new field list entry and link it in. */
6362 new_field
= xzalloc (sizeof (*new_field
));
6363 make_cleanup (xfree
, new_field
);
6365 gdb_assert (die
->tag
== DW_TAG_typedef
);
6367 fp
= &new_field
->field
;
6369 /* Get name of field. */
6370 fp
->name
= dwarf2_name (die
, cu
);
6371 if (fp
->name
== NULL
)
6374 fp
->type
= read_type_die (die
, cu
);
6376 new_field
->next
= fip
->typedef_field_list
;
6377 fip
->typedef_field_list
= new_field
;
6378 fip
->typedef_field_list_count
++;
6381 /* Create the vector of fields, and attach it to the type. */
6384 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6385 struct dwarf2_cu
*cu
)
6387 int nfields
= fip
->nfields
;
6389 /* Record the field count, allocate space for the array of fields,
6390 and create blank accessibility bitfields if necessary. */
6391 TYPE_NFIELDS (type
) = nfields
;
6392 TYPE_FIELDS (type
) = (struct field
*)
6393 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6394 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6396 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6398 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6400 TYPE_FIELD_PRIVATE_BITS (type
) =
6401 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6402 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6404 TYPE_FIELD_PROTECTED_BITS (type
) =
6405 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6406 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6408 TYPE_FIELD_IGNORE_BITS (type
) =
6409 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6410 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6413 /* If the type has baseclasses, allocate and clear a bit vector for
6414 TYPE_FIELD_VIRTUAL_BITS. */
6415 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6417 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6418 unsigned char *pointer
;
6420 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6421 pointer
= TYPE_ALLOC (type
, num_bytes
);
6422 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6423 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6424 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6427 /* Copy the saved-up fields into the field vector. Start from the head
6428 of the list, adding to the tail of the field array, so that they end
6429 up in the same order in the array in which they were added to the list. */
6430 while (nfields
-- > 0)
6432 struct nextfield
*fieldp
;
6436 fieldp
= fip
->fields
;
6437 fip
->fields
= fieldp
->next
;
6441 fieldp
= fip
->baseclasses
;
6442 fip
->baseclasses
= fieldp
->next
;
6445 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6446 switch (fieldp
->accessibility
)
6448 case DW_ACCESS_private
:
6449 if (cu
->language
!= language_ada
)
6450 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6453 case DW_ACCESS_protected
:
6454 if (cu
->language
!= language_ada
)
6455 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6458 case DW_ACCESS_public
:
6462 /* Unknown accessibility. Complain and treat it as public. */
6464 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6465 fieldp
->accessibility
);
6469 if (nfields
< fip
->nbaseclasses
)
6471 switch (fieldp
->virtuality
)
6473 case DW_VIRTUALITY_virtual
:
6474 case DW_VIRTUALITY_pure_virtual
:
6475 if (cu
->language
== language_ada
)
6476 error ("unexpected virtuality in component of Ada type");
6477 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6484 /* Add a member function to the proper fieldlist. */
6487 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6488 struct type
*type
, struct dwarf2_cu
*cu
)
6490 struct objfile
*objfile
= cu
->objfile
;
6491 struct attribute
*attr
;
6492 struct fnfieldlist
*flp
;
6494 struct fn_field
*fnp
;
6496 struct nextfnfield
*new_fnfield
;
6497 struct type
*this_type
;
6499 if (cu
->language
== language_ada
)
6500 error ("unexpected member function in Ada type");
6502 /* Get name of member function. */
6503 fieldname
= dwarf2_name (die
, cu
);
6504 if (fieldname
== NULL
)
6507 /* Look up member function name in fieldlist. */
6508 for (i
= 0; i
< fip
->nfnfields
; i
++)
6510 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6514 /* Create new list element if necessary. */
6515 if (i
< fip
->nfnfields
)
6516 flp
= &fip
->fnfieldlists
[i
];
6519 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6521 fip
->fnfieldlists
= (struct fnfieldlist
*)
6522 xrealloc (fip
->fnfieldlists
,
6523 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6524 * sizeof (struct fnfieldlist
));
6525 if (fip
->nfnfields
== 0)
6526 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6528 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6529 flp
->name
= fieldname
;
6532 i
= fip
->nfnfields
++;
6535 /* Create a new member function field and chain it to the field list
6537 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6538 make_cleanup (xfree
, new_fnfield
);
6539 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6540 new_fnfield
->next
= flp
->head
;
6541 flp
->head
= new_fnfield
;
6544 /* Fill in the member function field info. */
6545 fnp
= &new_fnfield
->fnfield
;
6547 /* Delay processing of the physname until later. */
6548 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6550 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6555 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6556 fnp
->physname
= physname
? physname
: "";
6559 fnp
->type
= alloc_type (objfile
);
6560 this_type
= read_type_die (die
, cu
);
6561 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6563 int nparams
= TYPE_NFIELDS (this_type
);
6565 /* TYPE is the domain of this method, and THIS_TYPE is the type
6566 of the method itself (TYPE_CODE_METHOD). */
6567 smash_to_method_type (fnp
->type
, type
,
6568 TYPE_TARGET_TYPE (this_type
),
6569 TYPE_FIELDS (this_type
),
6570 TYPE_NFIELDS (this_type
),
6571 TYPE_VARARGS (this_type
));
6573 /* Handle static member functions.
6574 Dwarf2 has no clean way to discern C++ static and non-static
6575 member functions. G++ helps GDB by marking the first
6576 parameter for non-static member functions (which is the
6577 this pointer) as artificial. We obtain this information
6578 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6579 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6580 fnp
->voffset
= VOFFSET_STATIC
;
6583 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6584 dwarf2_full_name (fieldname
, die
, cu
));
6586 /* Get fcontext from DW_AT_containing_type if present. */
6587 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6588 fnp
->fcontext
= die_containing_type (die
, cu
);
6590 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6591 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6593 /* Get accessibility. */
6594 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6597 switch (DW_UNSND (attr
))
6599 case DW_ACCESS_private
:
6600 fnp
->is_private
= 1;
6602 case DW_ACCESS_protected
:
6603 fnp
->is_protected
= 1;
6608 /* Check for artificial methods. */
6609 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6610 if (attr
&& DW_UNSND (attr
) != 0)
6611 fnp
->is_artificial
= 1;
6613 /* Get index in virtual function table if it is a virtual member
6614 function. For older versions of GCC, this is an offset in the
6615 appropriate virtual table, as specified by DW_AT_containing_type.
6616 For everyone else, it is an expression to be evaluated relative
6617 to the object address. */
6619 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6622 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6624 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6626 /* Old-style GCC. */
6627 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6629 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6630 || (DW_BLOCK (attr
)->size
> 1
6631 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6632 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6634 struct dwarf_block blk
;
6637 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6639 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6640 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6641 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6642 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6643 dwarf2_complex_location_expr_complaint ();
6645 fnp
->voffset
/= cu
->header
.addr_size
;
6649 dwarf2_complex_location_expr_complaint ();
6652 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6654 else if (attr_form_is_section_offset (attr
))
6656 dwarf2_complex_location_expr_complaint ();
6660 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6666 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6667 if (attr
&& DW_UNSND (attr
))
6669 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6670 complaint (&symfile_complaints
,
6671 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6672 fieldname
, die
->offset
);
6673 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6674 TYPE_CPLUS_DYNAMIC (type
) = 1;
6679 /* Create the vector of member function fields, and attach it to the type. */
6682 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6683 struct dwarf2_cu
*cu
)
6685 struct fnfieldlist
*flp
;
6686 int total_length
= 0;
6689 if (cu
->language
== language_ada
)
6690 error ("unexpected member functions in Ada type");
6692 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6693 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6694 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6696 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6698 struct nextfnfield
*nfp
= flp
->head
;
6699 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6702 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6703 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6704 fn_flp
->fn_fields
= (struct fn_field
*)
6705 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6706 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6707 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6709 total_length
+= flp
->length
;
6712 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6713 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6716 /* Returns non-zero if NAME is the name of a vtable member in CU's
6717 language, zero otherwise. */
6719 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6721 static const char vptr
[] = "_vptr";
6722 static const char vtable
[] = "vtable";
6724 /* Look for the C++ and Java forms of the vtable. */
6725 if ((cu
->language
== language_java
6726 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6727 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6728 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6734 /* GCC outputs unnamed structures that are really pointers to member
6735 functions, with the ABI-specified layout. If TYPE describes
6736 such a structure, smash it into a member function type.
6738 GCC shouldn't do this; it should just output pointer to member DIEs.
6739 This is GCC PR debug/28767. */
6742 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6744 struct type
*pfn_type
, *domain_type
, *new_type
;
6746 /* Check for a structure with no name and two children. */
6747 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6750 /* Check for __pfn and __delta members. */
6751 if (TYPE_FIELD_NAME (type
, 0) == NULL
6752 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6753 || TYPE_FIELD_NAME (type
, 1) == NULL
6754 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6757 /* Find the type of the method. */
6758 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6759 if (pfn_type
== NULL
6760 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6761 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6764 /* Look for the "this" argument. */
6765 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6766 if (TYPE_NFIELDS (pfn_type
) == 0
6767 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6768 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6771 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6772 new_type
= alloc_type (objfile
);
6773 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6774 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6775 TYPE_VARARGS (pfn_type
));
6776 smash_to_methodptr_type (type
, new_type
);
6779 /* Called when we find the DIE that starts a structure or union scope
6780 (definition) to create a type for the structure or union. Fill in
6781 the type's name and general properties; the members will not be
6782 processed until process_structure_type.
6784 NOTE: we need to call these functions regardless of whether or not the
6785 DIE has a DW_AT_name attribute, since it might be an anonymous
6786 structure or union. This gets the type entered into our set of
6789 However, if the structure is incomplete (an opaque struct/union)
6790 then suppress creating a symbol table entry for it since gdb only
6791 wants to find the one with the complete definition. Note that if
6792 it is complete, we just call new_symbol, which does it's own
6793 checking about whether the struct/union is anonymous or not (and
6794 suppresses creating a symbol table entry itself). */
6796 static struct type
*
6797 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6799 struct objfile
*objfile
= cu
->objfile
;
6801 struct attribute
*attr
;
6804 /* If the definition of this type lives in .debug_types, read that type.
6805 Don't follow DW_AT_specification though, that will take us back up
6806 the chain and we want to go down. */
6807 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6810 struct dwarf2_cu
*type_cu
= cu
;
6811 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6813 /* We could just recurse on read_structure_type, but we need to call
6814 get_die_type to ensure only one type for this DIE is created.
6815 This is important, for example, because for c++ classes we need
6816 TYPE_NAME set which is only done by new_symbol. Blech. */
6817 type
= read_type_die (type_die
, type_cu
);
6819 /* TYPE_CU may not be the same as CU.
6820 Ensure TYPE is recorded in CU's type_hash table. */
6821 return set_die_type (die
, type
, cu
);
6824 type
= alloc_type (objfile
);
6825 INIT_CPLUS_SPECIFIC (type
);
6827 name
= dwarf2_name (die
, cu
);
6830 if (cu
->language
== language_cplus
6831 || cu
->language
== language_java
)
6833 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6835 /* dwarf2_full_name might have already finished building the DIE's
6836 type. If so, there is no need to continue. */
6837 if (get_die_type (die
, cu
) != NULL
)
6838 return get_die_type (die
, cu
);
6840 TYPE_TAG_NAME (type
) = full_name
;
6841 if (die
->tag
== DW_TAG_structure_type
6842 || die
->tag
== DW_TAG_class_type
)
6843 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6847 /* The name is already allocated along with this objfile, so
6848 we don't need to duplicate it for the type. */
6849 TYPE_TAG_NAME (type
) = (char *) name
;
6850 if (die
->tag
== DW_TAG_class_type
)
6851 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6855 if (die
->tag
== DW_TAG_structure_type
)
6857 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6859 else if (die
->tag
== DW_TAG_union_type
)
6861 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6865 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6868 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6869 TYPE_DECLARED_CLASS (type
) = 1;
6871 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6874 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6878 TYPE_LENGTH (type
) = 0;
6881 TYPE_STUB_SUPPORTED (type
) = 1;
6882 if (die_is_declaration (die
, cu
))
6883 TYPE_STUB (type
) = 1;
6884 else if (attr
== NULL
&& die
->child
== NULL
6885 && producer_is_realview (cu
->producer
))
6886 /* RealView does not output the required DW_AT_declaration
6887 on incomplete types. */
6888 TYPE_STUB (type
) = 1;
6890 /* We need to add the type field to the die immediately so we don't
6891 infinitely recurse when dealing with pointers to the structure
6892 type within the structure itself. */
6893 set_die_type (die
, type
, cu
);
6895 /* set_die_type should be already done. */
6896 set_descriptive_type (type
, die
, cu
);
6901 /* Finish creating a structure or union type, including filling in
6902 its members and creating a symbol for it. */
6905 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6907 struct objfile
*objfile
= cu
->objfile
;
6908 struct die_info
*child_die
= die
->child
;
6911 type
= get_die_type (die
, cu
);
6913 type
= read_structure_type (die
, cu
);
6915 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6917 struct field_info fi
;
6918 struct die_info
*child_die
;
6919 VEC (symbolp
) *template_args
= NULL
;
6920 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6922 memset (&fi
, 0, sizeof (struct field_info
));
6924 child_die
= die
->child
;
6926 while (child_die
&& child_die
->tag
)
6928 if (child_die
->tag
== DW_TAG_member
6929 || child_die
->tag
== DW_TAG_variable
)
6931 /* NOTE: carlton/2002-11-05: A C++ static data member
6932 should be a DW_TAG_member that is a declaration, but
6933 all versions of G++ as of this writing (so through at
6934 least 3.2.1) incorrectly generate DW_TAG_variable
6935 tags for them instead. */
6936 dwarf2_add_field (&fi
, child_die
, cu
);
6938 else if (child_die
->tag
== DW_TAG_subprogram
)
6940 /* C++ member function. */
6941 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6943 else if (child_die
->tag
== DW_TAG_inheritance
)
6945 /* C++ base class field. */
6946 dwarf2_add_field (&fi
, child_die
, cu
);
6948 else if (child_die
->tag
== DW_TAG_typedef
)
6949 dwarf2_add_typedef (&fi
, child_die
, cu
);
6950 else if (child_die
->tag
== DW_TAG_template_type_param
6951 || child_die
->tag
== DW_TAG_template_value_param
)
6953 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6956 VEC_safe_push (symbolp
, template_args
, arg
);
6959 child_die
= sibling_die (child_die
);
6962 /* Attach template arguments to type. */
6963 if (! VEC_empty (symbolp
, template_args
))
6965 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6966 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6967 = VEC_length (symbolp
, template_args
);
6968 TYPE_TEMPLATE_ARGUMENTS (type
)
6969 = obstack_alloc (&objfile
->objfile_obstack
,
6970 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6971 * sizeof (struct symbol
*)));
6972 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6973 VEC_address (symbolp
, template_args
),
6974 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6975 * sizeof (struct symbol
*)));
6976 VEC_free (symbolp
, template_args
);
6979 /* Attach fields and member functions to the type. */
6981 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6984 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6986 /* Get the type which refers to the base class (possibly this
6987 class itself) which contains the vtable pointer for the current
6988 class from the DW_AT_containing_type attribute. This use of
6989 DW_AT_containing_type is a GNU extension. */
6991 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6993 struct type
*t
= die_containing_type (die
, cu
);
6995 TYPE_VPTR_BASETYPE (type
) = t
;
7000 /* Our own class provides vtbl ptr. */
7001 for (i
= TYPE_NFIELDS (t
) - 1;
7002 i
>= TYPE_N_BASECLASSES (t
);
7005 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7007 if (is_vtable_name (fieldname
, cu
))
7009 TYPE_VPTR_FIELDNO (type
) = i
;
7014 /* Complain if virtual function table field not found. */
7015 if (i
< TYPE_N_BASECLASSES (t
))
7016 complaint (&symfile_complaints
,
7017 _("virtual function table pointer not found when defining class '%s'"),
7018 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7023 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7026 else if (cu
->producer
7027 && strncmp (cu
->producer
,
7028 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7030 /* The IBM XLC compiler does not provide direct indication
7031 of the containing type, but the vtable pointer is
7032 always named __vfp. */
7036 for (i
= TYPE_NFIELDS (type
) - 1;
7037 i
>= TYPE_N_BASECLASSES (type
);
7040 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7042 TYPE_VPTR_FIELDNO (type
) = i
;
7043 TYPE_VPTR_BASETYPE (type
) = type
;
7050 /* Copy fi.typedef_field_list linked list elements content into the
7051 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7052 if (fi
.typedef_field_list
)
7054 int i
= fi
.typedef_field_list_count
;
7056 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7057 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7058 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7059 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7061 /* Reverse the list order to keep the debug info elements order. */
7064 struct typedef_field
*dest
, *src
;
7066 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7067 src
= &fi
.typedef_field_list
->field
;
7068 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7073 do_cleanups (back_to
);
7076 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7078 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7079 snapshots) has been known to create a die giving a declaration
7080 for a class that has, as a child, a die giving a definition for a
7081 nested class. So we have to process our children even if the
7082 current die is a declaration. Normally, of course, a declaration
7083 won't have any children at all. */
7085 while (child_die
!= NULL
&& child_die
->tag
)
7087 if (child_die
->tag
== DW_TAG_member
7088 || child_die
->tag
== DW_TAG_variable
7089 || child_die
->tag
== DW_TAG_inheritance
7090 || child_die
->tag
== DW_TAG_template_value_param
7091 || child_die
->tag
== DW_TAG_template_type_param
)
7096 process_die (child_die
, cu
);
7098 child_die
= sibling_die (child_die
);
7101 /* Do not consider external references. According to the DWARF standard,
7102 these DIEs are identified by the fact that they have no byte_size
7103 attribute, and a declaration attribute. */
7104 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7105 || !die_is_declaration (die
, cu
))
7106 new_symbol (die
, type
, cu
);
7109 /* Given a DW_AT_enumeration_type die, set its type. We do not
7110 complete the type's fields yet, or create any symbols. */
7112 static struct type
*
7113 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7115 struct objfile
*objfile
= cu
->objfile
;
7117 struct attribute
*attr
;
7120 /* If the definition of this type lives in .debug_types, read that type.
7121 Don't follow DW_AT_specification though, that will take us back up
7122 the chain and we want to go down. */
7123 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7126 struct dwarf2_cu
*type_cu
= cu
;
7127 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7129 type
= read_type_die (type_die
, type_cu
);
7131 /* TYPE_CU may not be the same as CU.
7132 Ensure TYPE is recorded in CU's type_hash table. */
7133 return set_die_type (die
, type
, cu
);
7136 type
= alloc_type (objfile
);
7138 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7139 name
= dwarf2_full_name (NULL
, die
, cu
);
7141 TYPE_TAG_NAME (type
) = (char *) name
;
7143 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7146 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7150 TYPE_LENGTH (type
) = 0;
7153 /* The enumeration DIE can be incomplete. In Ada, any type can be
7154 declared as private in the package spec, and then defined only
7155 inside the package body. Such types are known as Taft Amendment
7156 Types. When another package uses such a type, an incomplete DIE
7157 may be generated by the compiler. */
7158 if (die_is_declaration (die
, cu
))
7159 TYPE_STUB (type
) = 1;
7161 return set_die_type (die
, type
, cu
);
7164 /* Given a pointer to a die which begins an enumeration, process all
7165 the dies that define the members of the enumeration, and create the
7166 symbol for the enumeration type.
7168 NOTE: We reverse the order of the element list. */
7171 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7173 struct type
*this_type
;
7175 this_type
= get_die_type (die
, cu
);
7176 if (this_type
== NULL
)
7177 this_type
= read_enumeration_type (die
, cu
);
7179 if (die
->child
!= NULL
)
7181 struct die_info
*child_die
;
7183 struct field
*fields
= NULL
;
7185 int unsigned_enum
= 1;
7188 child_die
= die
->child
;
7189 while (child_die
&& child_die
->tag
)
7191 if (child_die
->tag
!= DW_TAG_enumerator
)
7193 process_die (child_die
, cu
);
7197 name
= dwarf2_name (child_die
, cu
);
7200 sym
= new_symbol (child_die
, this_type
, cu
);
7201 if (SYMBOL_VALUE (sym
) < 0)
7204 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7206 fields
= (struct field
*)
7208 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7209 * sizeof (struct field
));
7212 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7213 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7214 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7215 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7221 child_die
= sibling_die (child_die
);
7226 TYPE_NFIELDS (this_type
) = num_fields
;
7227 TYPE_FIELDS (this_type
) = (struct field
*)
7228 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7229 memcpy (TYPE_FIELDS (this_type
), fields
,
7230 sizeof (struct field
) * num_fields
);
7234 TYPE_UNSIGNED (this_type
) = 1;
7237 new_symbol (die
, this_type
, cu
);
7240 /* Extract all information from a DW_TAG_array_type DIE and put it in
7241 the DIE's type field. For now, this only handles one dimensional
7244 static struct type
*
7245 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7247 struct objfile
*objfile
= cu
->objfile
;
7248 struct die_info
*child_die
;
7250 struct type
*element_type
, *range_type
, *index_type
;
7251 struct type
**range_types
= NULL
;
7252 struct attribute
*attr
;
7254 struct cleanup
*back_to
;
7257 element_type
= die_type (die
, cu
);
7259 /* The die_type call above may have already set the type for this DIE. */
7260 type
= get_die_type (die
, cu
);
7264 /* Irix 6.2 native cc creates array types without children for
7265 arrays with unspecified length. */
7266 if (die
->child
== NULL
)
7268 index_type
= objfile_type (objfile
)->builtin_int
;
7269 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7270 type
= create_array_type (NULL
, element_type
, range_type
);
7271 return set_die_type (die
, type
, cu
);
7274 back_to
= make_cleanup (null_cleanup
, NULL
);
7275 child_die
= die
->child
;
7276 while (child_die
&& child_die
->tag
)
7278 if (child_die
->tag
== DW_TAG_subrange_type
)
7280 struct type
*child_type
= read_type_die (child_die
, cu
);
7282 if (child_type
!= NULL
)
7284 /* The range type was succesfully read. Save it for
7285 the array type creation. */
7286 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7288 range_types
= (struct type
**)
7289 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7290 * sizeof (struct type
*));
7292 make_cleanup (free_current_contents
, &range_types
);
7294 range_types
[ndim
++] = child_type
;
7297 child_die
= sibling_die (child_die
);
7300 /* Dwarf2 dimensions are output from left to right, create the
7301 necessary array types in backwards order. */
7303 type
= element_type
;
7305 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7310 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7315 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7318 /* Understand Dwarf2 support for vector types (like they occur on
7319 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7320 array type. This is not part of the Dwarf2/3 standard yet, but a
7321 custom vendor extension. The main difference between a regular
7322 array and the vector variant is that vectors are passed by value
7324 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7326 make_vector_type (type
);
7328 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7329 implementation may choose to implement triple vectors using this
7331 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7334 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7335 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7337 complaint (&symfile_complaints
, _("\
7338 DW_AT_byte_size for array type smaller than the total size of elements"));
7341 name
= dwarf2_name (die
, cu
);
7343 TYPE_NAME (type
) = name
;
7345 /* Install the type in the die. */
7346 set_die_type (die
, type
, cu
);
7348 /* set_die_type should be already done. */
7349 set_descriptive_type (type
, die
, cu
);
7351 do_cleanups (back_to
);
7356 static enum dwarf_array_dim_ordering
7357 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7359 struct attribute
*attr
;
7361 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7363 if (attr
) return DW_SND (attr
);
7366 GNU F77 is a special case, as at 08/2004 array type info is the
7367 opposite order to the dwarf2 specification, but data is still
7368 laid out as per normal fortran.
7370 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7374 if (cu
->language
== language_fortran
7375 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7377 return DW_ORD_row_major
;
7380 switch (cu
->language_defn
->la_array_ordering
)
7382 case array_column_major
:
7383 return DW_ORD_col_major
;
7384 case array_row_major
:
7386 return DW_ORD_row_major
;
7390 /* Extract all information from a DW_TAG_set_type DIE and put it in
7391 the DIE's type field. */
7393 static struct type
*
7394 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7396 struct type
*domain_type
, *set_type
;
7397 struct attribute
*attr
;
7399 domain_type
= die_type (die
, cu
);
7401 /* The die_type call above may have already set the type for this DIE. */
7402 set_type
= get_die_type (die
, cu
);
7406 set_type
= create_set_type (NULL
, domain_type
);
7408 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7410 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7412 return set_die_type (die
, set_type
, cu
);
7415 /* First cut: install each common block member as a global variable. */
7418 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7420 struct die_info
*child_die
;
7421 struct attribute
*attr
;
7423 CORE_ADDR base
= (CORE_ADDR
) 0;
7425 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7428 /* Support the .debug_loc offsets */
7429 if (attr_form_is_block (attr
))
7431 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7433 else if (attr_form_is_section_offset (attr
))
7435 dwarf2_complex_location_expr_complaint ();
7439 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7440 "common block member");
7443 if (die
->child
!= NULL
)
7445 child_die
= die
->child
;
7446 while (child_die
&& child_die
->tag
)
7448 sym
= new_symbol (child_die
, NULL
, cu
);
7449 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7450 if (sym
!= NULL
&& attr
!= NULL
)
7452 CORE_ADDR byte_offset
= 0;
7454 if (attr_form_is_section_offset (attr
))
7455 dwarf2_complex_location_expr_complaint ();
7456 else if (attr_form_is_constant (attr
))
7457 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7458 else if (attr_form_is_block (attr
))
7459 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7461 dwarf2_complex_location_expr_complaint ();
7463 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7464 add_symbol_to_list (sym
, &global_symbols
);
7466 child_die
= sibling_die (child_die
);
7471 /* Create a type for a C++ namespace. */
7473 static struct type
*
7474 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7476 struct objfile
*objfile
= cu
->objfile
;
7477 const char *previous_prefix
, *name
;
7481 /* For extensions, reuse the type of the original namespace. */
7482 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7484 struct die_info
*ext_die
;
7485 struct dwarf2_cu
*ext_cu
= cu
;
7487 ext_die
= dwarf2_extension (die
, &ext_cu
);
7488 type
= read_type_die (ext_die
, ext_cu
);
7490 /* EXT_CU may not be the same as CU.
7491 Ensure TYPE is recorded in CU's type_hash table. */
7492 return set_die_type (die
, type
, cu
);
7495 name
= namespace_name (die
, &is_anonymous
, cu
);
7497 /* Now build the name of the current namespace. */
7499 previous_prefix
= determine_prefix (die
, cu
);
7500 if (previous_prefix
[0] != '\0')
7501 name
= typename_concat (&objfile
->objfile_obstack
,
7502 previous_prefix
, name
, 0, cu
);
7504 /* Create the type. */
7505 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7507 TYPE_NAME (type
) = (char *) name
;
7508 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7510 return set_die_type (die
, type
, cu
);
7513 /* Read a C++ namespace. */
7516 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7518 struct objfile
*objfile
= cu
->objfile
;
7522 /* Add a symbol associated to this if we haven't seen the namespace
7523 before. Also, add a using directive if it's an anonymous
7526 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7530 type
= read_type_die (die
, cu
);
7531 new_symbol (die
, type
, cu
);
7533 name
= namespace_name (die
, &is_anonymous
, cu
);
7536 const char *previous_prefix
= determine_prefix (die
, cu
);
7538 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7539 NULL
, &objfile
->objfile_obstack
);
7543 if (die
->child
!= NULL
)
7545 struct die_info
*child_die
= die
->child
;
7547 while (child_die
&& child_die
->tag
)
7549 process_die (child_die
, cu
);
7550 child_die
= sibling_die (child_die
);
7555 /* Read a Fortran module as type. This DIE can be only a declaration used for
7556 imported module. Still we need that type as local Fortran "use ... only"
7557 declaration imports depend on the created type in determine_prefix. */
7559 static struct type
*
7560 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7562 struct objfile
*objfile
= cu
->objfile
;
7566 module_name
= dwarf2_name (die
, cu
);
7568 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7570 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7572 /* determine_prefix uses TYPE_TAG_NAME. */
7573 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7575 return set_die_type (die
, type
, cu
);
7578 /* Read a Fortran module. */
7581 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7583 struct die_info
*child_die
= die
->child
;
7585 while (child_die
&& child_die
->tag
)
7587 process_die (child_die
, cu
);
7588 child_die
= sibling_die (child_die
);
7592 /* Return the name of the namespace represented by DIE. Set
7593 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7597 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7599 struct die_info
*current_die
;
7600 const char *name
= NULL
;
7602 /* Loop through the extensions until we find a name. */
7604 for (current_die
= die
;
7605 current_die
!= NULL
;
7606 current_die
= dwarf2_extension (die
, &cu
))
7608 name
= dwarf2_name (current_die
, cu
);
7613 /* Is it an anonymous namespace? */
7615 *is_anonymous
= (name
== NULL
);
7617 name
= "(anonymous namespace)";
7622 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7623 the user defined type vector. */
7625 static struct type
*
7626 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7628 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7629 struct comp_unit_head
*cu_header
= &cu
->header
;
7631 struct attribute
*attr_byte_size
;
7632 struct attribute
*attr_address_class
;
7633 int byte_size
, addr_class
;
7634 struct type
*target_type
;
7636 target_type
= die_type (die
, cu
);
7638 /* The die_type call above may have already set the type for this DIE. */
7639 type
= get_die_type (die
, cu
);
7643 type
= lookup_pointer_type (target_type
);
7645 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7647 byte_size
= DW_UNSND (attr_byte_size
);
7649 byte_size
= cu_header
->addr_size
;
7651 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7652 if (attr_address_class
)
7653 addr_class
= DW_UNSND (attr_address_class
);
7655 addr_class
= DW_ADDR_none
;
7657 /* If the pointer size or address class is different than the
7658 default, create a type variant marked as such and set the
7659 length accordingly. */
7660 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7662 if (gdbarch_address_class_type_flags_p (gdbarch
))
7666 type_flags
= gdbarch_address_class_type_flags
7667 (gdbarch
, byte_size
, addr_class
);
7668 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7670 type
= make_type_with_address_space (type
, type_flags
);
7672 else if (TYPE_LENGTH (type
) != byte_size
)
7674 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7678 /* Should we also complain about unhandled address classes? */
7682 TYPE_LENGTH (type
) = byte_size
;
7683 return set_die_type (die
, type
, cu
);
7686 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7687 the user defined type vector. */
7689 static struct type
*
7690 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7693 struct type
*to_type
;
7694 struct type
*domain
;
7696 to_type
= die_type (die
, cu
);
7697 domain
= die_containing_type (die
, cu
);
7699 /* The calls above may have already set the type for this DIE. */
7700 type
= get_die_type (die
, cu
);
7704 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7705 type
= lookup_methodptr_type (to_type
);
7707 type
= lookup_memberptr_type (to_type
, domain
);
7709 return set_die_type (die
, type
, cu
);
7712 /* Extract all information from a DW_TAG_reference_type DIE and add to
7713 the user defined type vector. */
7715 static struct type
*
7716 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7718 struct comp_unit_head
*cu_header
= &cu
->header
;
7719 struct type
*type
, *target_type
;
7720 struct attribute
*attr
;
7722 target_type
= die_type (die
, cu
);
7724 /* The die_type call above may have already set the type for this DIE. */
7725 type
= get_die_type (die
, cu
);
7729 type
= lookup_reference_type (target_type
);
7730 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7733 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7737 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7739 return set_die_type (die
, type
, cu
);
7742 static struct type
*
7743 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7745 struct type
*base_type
, *cv_type
;
7747 base_type
= die_type (die
, cu
);
7749 /* The die_type call above may have already set the type for this DIE. */
7750 cv_type
= get_die_type (die
, cu
);
7754 /* In case the const qualifier is applied to an array type, the element type
7755 is so qualified, not the array type (section 6.7.3 of C99). */
7756 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7758 struct type
*el_type
, *inner_array
;
7760 base_type
= copy_type (base_type
);
7761 inner_array
= base_type
;
7763 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7765 TYPE_TARGET_TYPE (inner_array
) =
7766 copy_type (TYPE_TARGET_TYPE (inner_array
));
7767 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7770 el_type
= TYPE_TARGET_TYPE (inner_array
);
7771 TYPE_TARGET_TYPE (inner_array
) =
7772 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7774 return set_die_type (die
, base_type
, cu
);
7777 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7778 return set_die_type (die
, cv_type
, cu
);
7781 static struct type
*
7782 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7784 struct type
*base_type
, *cv_type
;
7786 base_type
= die_type (die
, cu
);
7788 /* The die_type call above may have already set the type for this DIE. */
7789 cv_type
= get_die_type (die
, cu
);
7793 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7794 return set_die_type (die
, cv_type
, cu
);
7797 /* Extract all information from a DW_TAG_string_type DIE and add to
7798 the user defined type vector. It isn't really a user defined type,
7799 but it behaves like one, with other DIE's using an AT_user_def_type
7800 attribute to reference it. */
7802 static struct type
*
7803 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7805 struct objfile
*objfile
= cu
->objfile
;
7806 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7807 struct type
*type
, *range_type
, *index_type
, *char_type
;
7808 struct attribute
*attr
;
7809 unsigned int length
;
7811 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7814 length
= DW_UNSND (attr
);
7818 /* check for the DW_AT_byte_size attribute */
7819 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7822 length
= DW_UNSND (attr
);
7830 index_type
= objfile_type (objfile
)->builtin_int
;
7831 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7832 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7833 type
= create_string_type (NULL
, char_type
, range_type
);
7835 return set_die_type (die
, type
, cu
);
7838 /* Handle DIES due to C code like:
7842 int (*funcp)(int a, long l);
7846 ('funcp' generates a DW_TAG_subroutine_type DIE)
7849 static struct type
*
7850 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7852 struct type
*type
; /* Type that this function returns */
7853 struct type
*ftype
; /* Function that returns above type */
7854 struct attribute
*attr
;
7856 type
= die_type (die
, cu
);
7858 /* The die_type call above may have already set the type for this DIE. */
7859 ftype
= get_die_type (die
, cu
);
7863 ftype
= lookup_function_type (type
);
7865 /* All functions in C++, Pascal and Java have prototypes. */
7866 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7867 if ((attr
&& (DW_UNSND (attr
) != 0))
7868 || cu
->language
== language_cplus
7869 || cu
->language
== language_java
7870 || cu
->language
== language_pascal
)
7871 TYPE_PROTOTYPED (ftype
) = 1;
7872 else if (producer_is_realview (cu
->producer
))
7873 /* RealView does not emit DW_AT_prototyped. We can not
7874 distinguish prototyped and unprototyped functions; default to
7875 prototyped, since that is more common in modern code (and
7876 RealView warns about unprototyped functions). */
7877 TYPE_PROTOTYPED (ftype
) = 1;
7879 /* Store the calling convention in the type if it's available in
7880 the subroutine die. Otherwise set the calling convention to
7881 the default value DW_CC_normal. */
7882 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7883 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7885 /* We need to add the subroutine type to the die immediately so
7886 we don't infinitely recurse when dealing with parameters
7887 declared as the same subroutine type. */
7888 set_die_type (die
, ftype
, cu
);
7890 if (die
->child
!= NULL
)
7892 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7893 struct die_info
*child_die
;
7894 int nparams
, iparams
;
7896 /* Count the number of parameters.
7897 FIXME: GDB currently ignores vararg functions, but knows about
7898 vararg member functions. */
7900 child_die
= die
->child
;
7901 while (child_die
&& child_die
->tag
)
7903 if (child_die
->tag
== DW_TAG_formal_parameter
)
7905 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7906 TYPE_VARARGS (ftype
) = 1;
7907 child_die
= sibling_die (child_die
);
7910 /* Allocate storage for parameters and fill them in. */
7911 TYPE_NFIELDS (ftype
) = nparams
;
7912 TYPE_FIELDS (ftype
) = (struct field
*)
7913 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7915 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7916 even if we error out during the parameters reading below. */
7917 for (iparams
= 0; iparams
< nparams
; iparams
++)
7918 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7921 child_die
= die
->child
;
7922 while (child_die
&& child_die
->tag
)
7924 if (child_die
->tag
== DW_TAG_formal_parameter
)
7926 struct type
*arg_type
;
7928 /* DWARF version 2 has no clean way to discern C++
7929 static and non-static member functions. G++ helps
7930 GDB by marking the first parameter for non-static
7931 member functions (which is the this pointer) as
7932 artificial. We pass this information to
7933 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7935 DWARF version 3 added DW_AT_object_pointer, which GCC
7936 4.5 does not yet generate. */
7937 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7939 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7942 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7944 /* GCC/43521: In java, the formal parameter
7945 "this" is sometimes not marked with DW_AT_artificial. */
7946 if (cu
->language
== language_java
)
7948 const char *name
= dwarf2_name (child_die
, cu
);
7950 if (name
&& !strcmp (name
, "this"))
7951 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7954 arg_type
= die_type (child_die
, cu
);
7956 /* RealView does not mark THIS as const, which the testsuite
7957 expects. GCC marks THIS as const in method definitions,
7958 but not in the class specifications (GCC PR 43053). */
7959 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7960 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7963 struct dwarf2_cu
*arg_cu
= cu
;
7964 const char *name
= dwarf2_name (child_die
, cu
);
7966 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7969 /* If the compiler emits this, use it. */
7970 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7973 else if (name
&& strcmp (name
, "this") == 0)
7974 /* Function definitions will have the argument names. */
7976 else if (name
== NULL
&& iparams
== 0)
7977 /* Declarations may not have the names, so like
7978 elsewhere in GDB, assume an artificial first
7979 argument is "this". */
7983 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7987 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7990 child_die
= sibling_die (child_die
);
7997 static struct type
*
7998 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8000 struct objfile
*objfile
= cu
->objfile
;
8001 const char *name
= NULL
;
8002 struct type
*this_type
;
8004 name
= dwarf2_full_name (NULL
, die
, cu
);
8005 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8006 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8007 TYPE_NAME (this_type
) = (char *) name
;
8008 set_die_type (die
, this_type
, cu
);
8009 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8013 /* Find a representation of a given base type and install
8014 it in the TYPE field of the die. */
8016 static struct type
*
8017 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8019 struct objfile
*objfile
= cu
->objfile
;
8021 struct attribute
*attr
;
8022 int encoding
= 0, size
= 0;
8024 enum type_code code
= TYPE_CODE_INT
;
8026 struct type
*target_type
= NULL
;
8028 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8031 encoding
= DW_UNSND (attr
);
8033 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8036 size
= DW_UNSND (attr
);
8038 name
= dwarf2_name (die
, cu
);
8041 complaint (&symfile_complaints
,
8042 _("DW_AT_name missing from DW_TAG_base_type"));
8047 case DW_ATE_address
:
8048 /* Turn DW_ATE_address into a void * pointer. */
8049 code
= TYPE_CODE_PTR
;
8050 type_flags
|= TYPE_FLAG_UNSIGNED
;
8051 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8053 case DW_ATE_boolean
:
8054 code
= TYPE_CODE_BOOL
;
8055 type_flags
|= TYPE_FLAG_UNSIGNED
;
8057 case DW_ATE_complex_float
:
8058 code
= TYPE_CODE_COMPLEX
;
8059 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8061 case DW_ATE_decimal_float
:
8062 code
= TYPE_CODE_DECFLOAT
;
8065 code
= TYPE_CODE_FLT
;
8069 case DW_ATE_unsigned
:
8070 type_flags
|= TYPE_FLAG_UNSIGNED
;
8072 case DW_ATE_signed_char
:
8073 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8074 || cu
->language
== language_pascal
)
8075 code
= TYPE_CODE_CHAR
;
8077 case DW_ATE_unsigned_char
:
8078 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8079 || cu
->language
== language_pascal
)
8080 code
= TYPE_CODE_CHAR
;
8081 type_flags
|= TYPE_FLAG_UNSIGNED
;
8084 /* We just treat this as an integer and then recognize the
8085 type by name elsewhere. */
8089 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8090 dwarf_type_encoding_name (encoding
));
8094 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8095 TYPE_NAME (type
) = name
;
8096 TYPE_TARGET_TYPE (type
) = target_type
;
8098 if (name
&& strcmp (name
, "char") == 0)
8099 TYPE_NOSIGN (type
) = 1;
8101 return set_die_type (die
, type
, cu
);
8104 /* Read the given DW_AT_subrange DIE. */
8106 static struct type
*
8107 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8109 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
8110 struct type
*base_type
;
8111 struct type
*range_type
;
8112 struct attribute
*attr
;
8116 LONGEST negative_mask
;
8118 base_type
= die_type (die
, cu
);
8119 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8120 check_typedef (base_type
);
8122 /* The die_type call above may have already set the type for this DIE. */
8123 range_type
= get_die_type (die
, cu
);
8127 if (cu
->language
== language_fortran
)
8129 /* FORTRAN implies a lower bound of 1, if not given. */
8133 /* FIXME: For variable sized arrays either of these could be
8134 a variable rather than a constant value. We'll allow it,
8135 but we don't know how to handle it. */
8136 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8138 low
= dwarf2_get_attr_constant_value (attr
, 0);
8140 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8143 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8145 /* GCC encodes arrays with unspecified or dynamic length
8146 with a DW_FORM_block1 attribute or a reference attribute.
8147 FIXME: GDB does not yet know how to handle dynamic
8148 arrays properly, treat them as arrays with unspecified
8151 FIXME: jimb/2003-09-22: GDB does not really know
8152 how to handle arrays of unspecified length
8153 either; we just represent them as zero-length
8154 arrays. Choose an appropriate upper bound given
8155 the lower bound we've computed above. */
8159 high
= dwarf2_get_attr_constant_value (attr
, 1);
8163 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8166 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8167 high
= low
+ count
- 1;
8171 /* Dwarf-2 specifications explicitly allows to create subrange types
8172 without specifying a base type.
8173 In that case, the base type must be set to the type of
8174 the lower bound, upper bound or count, in that order, if any of these
8175 three attributes references an object that has a type.
8176 If no base type is found, the Dwarf-2 specifications say that
8177 a signed integer type of size equal to the size of an address should
8179 For the following C code: `extern char gdb_int [];'
8180 GCC produces an empty range DIE.
8181 FIXME: muller/2010-05-28: Possible references to object for low bound,
8182 high bound or count are not yet handled by this code.
8184 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8186 struct objfile
*objfile
= cu
->objfile
;
8187 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8188 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8189 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8191 /* Test "int", "long int", and "long long int" objfile types,
8192 and select the first one having a size above or equal to the
8193 architecture address size. */
8194 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8195 base_type
= int_type
;
8198 int_type
= objfile_type (objfile
)->builtin_long
;
8199 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8200 base_type
= int_type
;
8203 int_type
= objfile_type (objfile
)->builtin_long_long
;
8204 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8205 base_type
= int_type
;
8211 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8212 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8213 low
|= negative_mask
;
8214 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8215 high
|= negative_mask
;
8217 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8219 /* Mark arrays with dynamic length at least as an array of unspecified
8220 length. GDB could check the boundary but before it gets implemented at
8221 least allow accessing the array elements. */
8222 if (attr
&& attr
->form
== DW_FORM_block1
)
8223 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8225 name
= dwarf2_name (die
, cu
);
8227 TYPE_NAME (range_type
) = name
;
8229 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8231 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8233 set_die_type (die
, range_type
, cu
);
8235 /* set_die_type should be already done. */
8236 set_descriptive_type (range_type
, die
, cu
);
8241 static struct type
*
8242 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8246 /* For now, we only support the C meaning of an unspecified type: void. */
8248 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8249 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8251 return set_die_type (die
, type
, cu
);
8254 /* Trivial hash function for die_info: the hash value of a DIE
8255 is its offset in .debug_info for this objfile. */
8258 die_hash (const void *item
)
8260 const struct die_info
*die
= item
;
8265 /* Trivial comparison function for die_info structures: two DIEs
8266 are equal if they have the same offset. */
8269 die_eq (const void *item_lhs
, const void *item_rhs
)
8271 const struct die_info
*die_lhs
= item_lhs
;
8272 const struct die_info
*die_rhs
= item_rhs
;
8274 return die_lhs
->offset
== die_rhs
->offset
;
8277 /* Read a whole compilation unit into a linked list of dies. */
8279 static struct die_info
*
8280 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8282 struct die_reader_specs reader_specs
;
8283 int read_abbrevs
= 0;
8284 struct cleanup
*back_to
= NULL
;
8285 struct die_info
*die
;
8287 if (cu
->dwarf2_abbrevs
== NULL
)
8289 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8290 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8294 gdb_assert (cu
->die_hash
== NULL
);
8296 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8300 &cu
->comp_unit_obstack
,
8301 hashtab_obstack_allocate
,
8302 dummy_obstack_deallocate
);
8304 init_cu_die_reader (&reader_specs
, cu
);
8306 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8309 do_cleanups (back_to
);
8314 /* Main entry point for reading a DIE and all children.
8315 Read the DIE and dump it if requested. */
8317 static struct die_info
*
8318 read_die_and_children (const struct die_reader_specs
*reader
,
8320 gdb_byte
**new_info_ptr
,
8321 struct die_info
*parent
)
8323 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8324 new_info_ptr
, parent
);
8326 if (dwarf2_die_debug
)
8328 fprintf_unfiltered (gdb_stdlog
,
8329 "\nRead die from %s of %s:\n",
8330 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8332 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8334 : "unknown section",
8335 reader
->abfd
->filename
);
8336 dump_die (result
, dwarf2_die_debug
);
8342 /* Read a single die and all its descendents. Set the die's sibling
8343 field to NULL; set other fields in the die correctly, and set all
8344 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8345 location of the info_ptr after reading all of those dies. PARENT
8346 is the parent of the die in question. */
8348 static struct die_info
*
8349 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8351 gdb_byte
**new_info_ptr
,
8352 struct die_info
*parent
)
8354 struct die_info
*die
;
8358 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8361 *new_info_ptr
= cur_ptr
;
8364 store_in_ref_table (die
, reader
->cu
);
8367 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8371 *new_info_ptr
= cur_ptr
;
8374 die
->sibling
= NULL
;
8375 die
->parent
= parent
;
8379 /* Read a die, all of its descendents, and all of its siblings; set
8380 all of the fields of all of the dies correctly. Arguments are as
8381 in read_die_and_children. */
8383 static struct die_info
*
8384 read_die_and_siblings (const struct die_reader_specs
*reader
,
8386 gdb_byte
**new_info_ptr
,
8387 struct die_info
*parent
)
8389 struct die_info
*first_die
, *last_sibling
;
8393 first_die
= last_sibling
= NULL
;
8397 struct die_info
*die
8398 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8402 *new_info_ptr
= cur_ptr
;
8409 last_sibling
->sibling
= die
;
8415 /* Read the die from the .debug_info section buffer. Set DIEP to
8416 point to a newly allocated die with its information, except for its
8417 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8418 whether the die has children or not. */
8421 read_full_die (const struct die_reader_specs
*reader
,
8422 struct die_info
**diep
, gdb_byte
*info_ptr
,
8425 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8426 struct abbrev_info
*abbrev
;
8427 struct die_info
*die
;
8428 struct dwarf2_cu
*cu
= reader
->cu
;
8429 bfd
*abfd
= reader
->abfd
;
8431 offset
= info_ptr
- reader
->buffer
;
8432 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8433 info_ptr
+= bytes_read
;
8441 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8443 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8445 bfd_get_filename (abfd
));
8447 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8448 die
->offset
= offset
;
8449 die
->tag
= abbrev
->tag
;
8450 die
->abbrev
= abbrev_number
;
8452 die
->num_attrs
= abbrev
->num_attrs
;
8454 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8455 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8456 abfd
, info_ptr
, cu
);
8459 *has_children
= abbrev
->has_children
;
8463 /* In DWARF version 2, the description of the debugging information is
8464 stored in a separate .debug_abbrev section. Before we read any
8465 dies from a section we read in all abbreviations and install them
8466 in a hash table. This function also sets flags in CU describing
8467 the data found in the abbrev table. */
8470 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8472 struct comp_unit_head
*cu_header
= &cu
->header
;
8473 gdb_byte
*abbrev_ptr
;
8474 struct abbrev_info
*cur_abbrev
;
8475 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8476 unsigned int abbrev_form
, hash_number
;
8477 struct attr_abbrev
*cur_attrs
;
8478 unsigned int allocated_attrs
;
8480 /* Initialize dwarf2 abbrevs */
8481 obstack_init (&cu
->abbrev_obstack
);
8482 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8484 * sizeof (struct abbrev_info
*)));
8485 memset (cu
->dwarf2_abbrevs
, 0,
8486 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8488 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8489 &dwarf2_per_objfile
->abbrev
);
8490 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8491 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8492 abbrev_ptr
+= bytes_read
;
8494 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8495 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8497 /* loop until we reach an abbrev number of 0 */
8498 while (abbrev_number
)
8500 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8502 /* read in abbrev header */
8503 cur_abbrev
->number
= abbrev_number
;
8504 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8505 abbrev_ptr
+= bytes_read
;
8506 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8509 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8510 cu
->has_namespace_info
= 1;
8512 /* now read in declarations */
8513 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8514 abbrev_ptr
+= bytes_read
;
8515 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8516 abbrev_ptr
+= bytes_read
;
8519 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8521 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8523 = xrealloc (cur_attrs
, (allocated_attrs
8524 * sizeof (struct attr_abbrev
)));
8527 /* Record whether this compilation unit might have
8528 inter-compilation-unit references. If we don't know what form
8529 this attribute will have, then it might potentially be a
8530 DW_FORM_ref_addr, so we conservatively expect inter-CU
8533 if (abbrev_form
== DW_FORM_ref_addr
8534 || abbrev_form
== DW_FORM_indirect
)
8535 cu
->has_form_ref_addr
= 1;
8537 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8538 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8539 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8540 abbrev_ptr
+= bytes_read
;
8541 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8542 abbrev_ptr
+= bytes_read
;
8545 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8546 (cur_abbrev
->num_attrs
8547 * sizeof (struct attr_abbrev
)));
8548 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8549 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8551 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8552 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8553 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8555 /* Get next abbreviation.
8556 Under Irix6 the abbreviations for a compilation unit are not
8557 always properly terminated with an abbrev number of 0.
8558 Exit loop if we encounter an abbreviation which we have
8559 already read (which means we are about to read the abbreviations
8560 for the next compile unit) or if the end of the abbreviation
8561 table is reached. */
8562 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8563 >= dwarf2_per_objfile
->abbrev
.size
)
8565 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8566 abbrev_ptr
+= bytes_read
;
8567 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8574 /* Release the memory used by the abbrev table for a compilation unit. */
8577 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8579 struct dwarf2_cu
*cu
= ptr_to_cu
;
8581 obstack_free (&cu
->abbrev_obstack
, NULL
);
8582 cu
->dwarf2_abbrevs
= NULL
;
8585 /* Lookup an abbrev_info structure in the abbrev hash table. */
8587 static struct abbrev_info
*
8588 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8590 unsigned int hash_number
;
8591 struct abbrev_info
*abbrev
;
8593 hash_number
= number
% ABBREV_HASH_SIZE
;
8594 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8598 if (abbrev
->number
== number
)
8601 abbrev
= abbrev
->next
;
8606 /* Returns nonzero if TAG represents a type that we might generate a partial
8610 is_type_tag_for_partial (int tag
)
8615 /* Some types that would be reasonable to generate partial symbols for,
8616 that we don't at present. */
8617 case DW_TAG_array_type
:
8618 case DW_TAG_file_type
:
8619 case DW_TAG_ptr_to_member_type
:
8620 case DW_TAG_set_type
:
8621 case DW_TAG_string_type
:
8622 case DW_TAG_subroutine_type
:
8624 case DW_TAG_base_type
:
8625 case DW_TAG_class_type
:
8626 case DW_TAG_interface_type
:
8627 case DW_TAG_enumeration_type
:
8628 case DW_TAG_structure_type
:
8629 case DW_TAG_subrange_type
:
8630 case DW_TAG_typedef
:
8631 case DW_TAG_union_type
:
8638 /* Load all DIEs that are interesting for partial symbols into memory. */
8640 static struct partial_die_info
*
8641 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8642 int building_psymtab
, struct dwarf2_cu
*cu
)
8644 struct partial_die_info
*part_die
;
8645 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8646 struct abbrev_info
*abbrev
;
8647 unsigned int bytes_read
;
8648 unsigned int load_all
= 0;
8650 int nesting_level
= 1;
8655 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8659 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8663 &cu
->comp_unit_obstack
,
8664 hashtab_obstack_allocate
,
8665 dummy_obstack_deallocate
);
8667 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8668 sizeof (struct partial_die_info
));
8672 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8674 /* A NULL abbrev means the end of a series of children. */
8677 if (--nesting_level
== 0)
8679 /* PART_DIE was probably the last thing allocated on the
8680 comp_unit_obstack, so we could call obstack_free
8681 here. We don't do that because the waste is small,
8682 and will be cleaned up when we're done with this
8683 compilation unit. This way, we're also more robust
8684 against other users of the comp_unit_obstack. */
8687 info_ptr
+= bytes_read
;
8688 last_die
= parent_die
;
8689 parent_die
= parent_die
->die_parent
;
8693 /* Check for template arguments. We never save these; if
8694 they're seen, we just mark the parent, and go on our way. */
8695 if (parent_die
!= NULL
8696 && cu
->language
== language_cplus
8697 && (abbrev
->tag
== DW_TAG_template_type_param
8698 || abbrev
->tag
== DW_TAG_template_value_param
))
8700 parent_die
->has_template_arguments
= 1;
8704 /* We don't need a partial DIE for the template argument. */
8705 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8711 /* We only recurse into subprograms looking for template arguments.
8712 Skip their other children. */
8714 && cu
->language
== language_cplus
8715 && parent_die
!= NULL
8716 && parent_die
->tag
== DW_TAG_subprogram
)
8718 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8722 /* Check whether this DIE is interesting enough to save. Normally
8723 we would not be interested in members here, but there may be
8724 later variables referencing them via DW_AT_specification (for
8727 && !is_type_tag_for_partial (abbrev
->tag
)
8728 && abbrev
->tag
!= DW_TAG_constant
8729 && abbrev
->tag
!= DW_TAG_enumerator
8730 && abbrev
->tag
!= DW_TAG_subprogram
8731 && abbrev
->tag
!= DW_TAG_lexical_block
8732 && abbrev
->tag
!= DW_TAG_variable
8733 && abbrev
->tag
!= DW_TAG_namespace
8734 && abbrev
->tag
!= DW_TAG_module
8735 && abbrev
->tag
!= DW_TAG_member
)
8737 /* Otherwise we skip to the next sibling, if any. */
8738 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8742 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8743 buffer
, info_ptr
, cu
);
8745 /* This two-pass algorithm for processing partial symbols has a
8746 high cost in cache pressure. Thus, handle some simple cases
8747 here which cover the majority of C partial symbols. DIEs
8748 which neither have specification tags in them, nor could have
8749 specification tags elsewhere pointing at them, can simply be
8750 processed and discarded.
8752 This segment is also optional; scan_partial_symbols and
8753 add_partial_symbol will handle these DIEs if we chain
8754 them in normally. When compilers which do not emit large
8755 quantities of duplicate debug information are more common,
8756 this code can probably be removed. */
8758 /* Any complete simple types at the top level (pretty much all
8759 of them, for a language without namespaces), can be processed
8761 if (parent_die
== NULL
8762 && part_die
->has_specification
== 0
8763 && part_die
->is_declaration
== 0
8764 && (part_die
->tag
== DW_TAG_typedef
8765 || part_die
->tag
== DW_TAG_base_type
8766 || part_die
->tag
== DW_TAG_subrange_type
))
8768 if (building_psymtab
&& part_die
->name
!= NULL
)
8769 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8770 VAR_DOMAIN
, LOC_TYPEDEF
,
8771 &cu
->objfile
->static_psymbols
,
8772 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8773 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8777 /* If we're at the second level, and we're an enumerator, and
8778 our parent has no specification (meaning possibly lives in a
8779 namespace elsewhere), then we can add the partial symbol now
8780 instead of queueing it. */
8781 if (part_die
->tag
== DW_TAG_enumerator
8782 && parent_die
!= NULL
8783 && parent_die
->die_parent
== NULL
8784 && parent_die
->tag
== DW_TAG_enumeration_type
8785 && parent_die
->has_specification
== 0)
8787 if (part_die
->name
== NULL
)
8788 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8789 else if (building_psymtab
)
8790 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8791 VAR_DOMAIN
, LOC_CONST
,
8792 (cu
->language
== language_cplus
8793 || cu
->language
== language_java
)
8794 ? &cu
->objfile
->global_psymbols
8795 : &cu
->objfile
->static_psymbols
,
8796 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8798 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8802 /* We'll save this DIE so link it in. */
8803 part_die
->die_parent
= parent_die
;
8804 part_die
->die_sibling
= NULL
;
8805 part_die
->die_child
= NULL
;
8807 if (last_die
&& last_die
== parent_die
)
8808 last_die
->die_child
= part_die
;
8810 last_die
->die_sibling
= part_die
;
8812 last_die
= part_die
;
8814 if (first_die
== NULL
)
8815 first_die
= part_die
;
8817 /* Maybe add the DIE to the hash table. Not all DIEs that we
8818 find interesting need to be in the hash table, because we
8819 also have the parent/sibling/child chains; only those that we
8820 might refer to by offset later during partial symbol reading.
8822 For now this means things that might have be the target of a
8823 DW_AT_specification, DW_AT_abstract_origin, or
8824 DW_AT_extension. DW_AT_extension will refer only to
8825 namespaces; DW_AT_abstract_origin refers to functions (and
8826 many things under the function DIE, but we do not recurse
8827 into function DIEs during partial symbol reading) and
8828 possibly variables as well; DW_AT_specification refers to
8829 declarations. Declarations ought to have the DW_AT_declaration
8830 flag. It happens that GCC forgets to put it in sometimes, but
8831 only for functions, not for types.
8833 Adding more things than necessary to the hash table is harmless
8834 except for the performance cost. Adding too few will result in
8835 wasted time in find_partial_die, when we reread the compilation
8836 unit with load_all_dies set. */
8839 || abbrev
->tag
== DW_TAG_constant
8840 || abbrev
->tag
== DW_TAG_subprogram
8841 || abbrev
->tag
== DW_TAG_variable
8842 || abbrev
->tag
== DW_TAG_namespace
8843 || part_die
->is_declaration
)
8847 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8848 part_die
->offset
, INSERT
);
8852 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8853 sizeof (struct partial_die_info
));
8855 /* For some DIEs we want to follow their children (if any). For C
8856 we have no reason to follow the children of structures; for other
8857 languages we have to, so that we can get at method physnames
8858 to infer fully qualified class names, for DW_AT_specification,
8859 and for C++ template arguments. For C++, we also look one level
8860 inside functions to find template arguments (if the name of the
8861 function does not already contain the template arguments).
8863 For Ada, we need to scan the children of subprograms and lexical
8864 blocks as well because Ada allows the definition of nested
8865 entities that could be interesting for the debugger, such as
8866 nested subprograms for instance. */
8867 if (last_die
->has_children
8869 || last_die
->tag
== DW_TAG_namespace
8870 || last_die
->tag
== DW_TAG_module
8871 || last_die
->tag
== DW_TAG_enumeration_type
8872 || (cu
->language
== language_cplus
8873 && last_die
->tag
== DW_TAG_subprogram
8874 && (last_die
->name
== NULL
8875 || strchr (last_die
->name
, '<') == NULL
))
8876 || (cu
->language
!= language_c
8877 && (last_die
->tag
== DW_TAG_class_type
8878 || last_die
->tag
== DW_TAG_interface_type
8879 || last_die
->tag
== DW_TAG_structure_type
8880 || last_die
->tag
== DW_TAG_union_type
))
8881 || (cu
->language
== language_ada
8882 && (last_die
->tag
== DW_TAG_subprogram
8883 || last_die
->tag
== DW_TAG_lexical_block
))))
8886 parent_die
= last_die
;
8890 /* Otherwise we skip to the next sibling, if any. */
8891 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8893 /* Back to the top, do it again. */
8897 /* Read a minimal amount of information into the minimal die structure. */
8900 read_partial_die (struct partial_die_info
*part_die
,
8901 struct abbrev_info
*abbrev
,
8902 unsigned int abbrev_len
, bfd
*abfd
,
8903 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8904 struct dwarf2_cu
*cu
)
8907 struct attribute attr
;
8908 int has_low_pc_attr
= 0;
8909 int has_high_pc_attr
= 0;
8911 memset (part_die
, 0, sizeof (struct partial_die_info
));
8913 part_die
->offset
= info_ptr
- buffer
;
8915 info_ptr
+= abbrev_len
;
8920 part_die
->tag
= abbrev
->tag
;
8921 part_die
->has_children
= abbrev
->has_children
;
8923 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8925 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8927 /* Store the data if it is of an attribute we want to keep in a
8928 partial symbol table. */
8932 switch (part_die
->tag
)
8934 case DW_TAG_compile_unit
:
8935 case DW_TAG_type_unit
:
8936 /* Compilation units have a DW_AT_name that is a filename, not
8937 a source language identifier. */
8938 case DW_TAG_enumeration_type
:
8939 case DW_TAG_enumerator
:
8940 /* These tags always have simple identifiers already; no need
8941 to canonicalize them. */
8942 part_die
->name
= DW_STRING (&attr
);
8946 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8947 &cu
->objfile
->objfile_obstack
);
8951 case DW_AT_linkage_name
:
8952 case DW_AT_MIPS_linkage_name
:
8953 /* Note that both forms of linkage name might appear. We
8954 assume they will be the same, and we only store the last
8956 if (cu
->language
== language_ada
)
8957 part_die
->name
= DW_STRING (&attr
);
8958 part_die
->linkage_name
= DW_STRING (&attr
);
8961 has_low_pc_attr
= 1;
8962 part_die
->lowpc
= DW_ADDR (&attr
);
8965 has_high_pc_attr
= 1;
8966 part_die
->highpc
= DW_ADDR (&attr
);
8968 case DW_AT_location
:
8969 /* Support the .debug_loc offsets */
8970 if (attr_form_is_block (&attr
))
8972 part_die
->locdesc
= DW_BLOCK (&attr
);
8974 else if (attr_form_is_section_offset (&attr
))
8976 dwarf2_complex_location_expr_complaint ();
8980 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8981 "partial symbol information");
8984 case DW_AT_external
:
8985 part_die
->is_external
= DW_UNSND (&attr
);
8987 case DW_AT_declaration
:
8988 part_die
->is_declaration
= DW_UNSND (&attr
);
8991 part_die
->has_type
= 1;
8993 case DW_AT_abstract_origin
:
8994 case DW_AT_specification
:
8995 case DW_AT_extension
:
8996 part_die
->has_specification
= 1;
8997 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9000 /* Ignore absolute siblings, they might point outside of
9001 the current compile unit. */
9002 if (attr
.form
== DW_FORM_ref_addr
)
9003 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
9005 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9007 case DW_AT_byte_size
:
9008 part_die
->has_byte_size
= 1;
9010 case DW_AT_calling_convention
:
9011 /* DWARF doesn't provide a way to identify a program's source-level
9012 entry point. DW_AT_calling_convention attributes are only meant
9013 to describe functions' calling conventions.
9015 However, because it's a necessary piece of information in
9016 Fortran, and because DW_CC_program is the only piece of debugging
9017 information whose definition refers to a 'main program' at all,
9018 several compilers have begun marking Fortran main programs with
9019 DW_CC_program --- even when those functions use the standard
9020 calling conventions.
9022 So until DWARF specifies a way to provide this information and
9023 compilers pick up the new representation, we'll support this
9025 if (DW_UNSND (&attr
) == DW_CC_program
9026 && cu
->language
== language_fortran
)
9028 set_main_name (part_die
->name
);
9030 /* As this DIE has a static linkage the name would be difficult
9031 to look up later. */
9032 language_of_main
= language_fortran
;
9040 /* When using the GNU linker, .gnu.linkonce. sections are used to
9041 eliminate duplicate copies of functions and vtables and such.
9042 The linker will arbitrarily choose one and discard the others.
9043 The AT_*_pc values for such functions refer to local labels in
9044 these sections. If the section from that file was discarded, the
9045 labels are not in the output, so the relocs get a value of 0.
9046 If this is a discarded function, mark the pc bounds as invalid,
9047 so that GDB will ignore it. */
9048 if (has_low_pc_attr
&& has_high_pc_attr
9049 && part_die
->lowpc
< part_die
->highpc
9050 && (part_die
->lowpc
!= 0
9051 || dwarf2_per_objfile
->has_section_at_zero
))
9052 part_die
->has_pc_info
= 1;
9057 /* Find a cached partial DIE at OFFSET in CU. */
9059 static struct partial_die_info
*
9060 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9062 struct partial_die_info
*lookup_die
= NULL
;
9063 struct partial_die_info part_die
;
9065 part_die
.offset
= offset
;
9066 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9071 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9072 except in the case of .debug_types DIEs which do not reference
9073 outside their CU (they do however referencing other types via
9076 static struct partial_die_info
*
9077 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9079 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9080 struct partial_die_info
*pd
= NULL
;
9082 if (cu
->per_cu
->from_debug_types
)
9084 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9090 if (offset_in_cu_p (&cu
->header
, offset
))
9092 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9097 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9099 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9100 load_partial_comp_unit (per_cu
, cu
->objfile
);
9102 per_cu
->cu
->last_used
= 0;
9103 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9105 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9107 struct cleanup
*back_to
;
9108 struct partial_die_info comp_unit_die
;
9109 struct abbrev_info
*abbrev
;
9110 unsigned int bytes_read
;
9113 per_cu
->load_all_dies
= 1;
9115 /* Re-read the DIEs. */
9116 back_to
= make_cleanup (null_cleanup
, 0);
9117 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9119 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9120 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9122 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9123 + per_cu
->cu
->header
.offset
9124 + per_cu
->cu
->header
.first_die_offset
);
9125 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9126 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9127 per_cu
->cu
->objfile
->obfd
,
9128 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9130 if (comp_unit_die
.has_children
)
9131 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9132 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9134 do_cleanups (back_to
);
9136 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9142 internal_error (__FILE__
, __LINE__
,
9143 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
9144 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9148 /* See if we can figure out if the class lives in a namespace. We do
9149 this by looking for a member function; its demangled name will
9150 contain namespace info, if there is any. */
9153 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9154 struct dwarf2_cu
*cu
)
9156 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9157 what template types look like, because the demangler
9158 frequently doesn't give the same name as the debug info. We
9159 could fix this by only using the demangled name to get the
9160 prefix (but see comment in read_structure_type). */
9162 struct partial_die_info
*real_pdi
;
9163 struct partial_die_info
*child_pdi
;
9165 /* If this DIE (this DIE's specification, if any) has a parent, then
9166 we should not do this. We'll prepend the parent's fully qualified
9167 name when we create the partial symbol. */
9169 real_pdi
= struct_pdi
;
9170 while (real_pdi
->has_specification
)
9171 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9173 if (real_pdi
->die_parent
!= NULL
)
9176 for (child_pdi
= struct_pdi
->die_child
;
9178 child_pdi
= child_pdi
->die_sibling
)
9180 if (child_pdi
->tag
== DW_TAG_subprogram
9181 && child_pdi
->linkage_name
!= NULL
)
9183 char *actual_class_name
9184 = language_class_name_from_physname (cu
->language_defn
,
9185 child_pdi
->linkage_name
);
9186 if (actual_class_name
!= NULL
)
9189 = obsavestring (actual_class_name
,
9190 strlen (actual_class_name
),
9191 &cu
->objfile
->objfile_obstack
);
9192 xfree (actual_class_name
);
9199 /* Adjust PART_DIE before generating a symbol for it. This function
9200 may set the is_external flag or change the DIE's name. */
9203 fixup_partial_die (struct partial_die_info
*part_die
,
9204 struct dwarf2_cu
*cu
)
9206 /* Once we've fixed up a die, there's no point in doing so again.
9207 This also avoids a memory leak if we were to call
9208 guess_partial_die_structure_name multiple times. */
9209 if (part_die
->fixup_called
)
9212 /* If we found a reference attribute and the DIE has no name, try
9213 to find a name in the referred to DIE. */
9215 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9217 struct partial_die_info
*spec_die
;
9219 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9221 fixup_partial_die (spec_die
, cu
);
9225 part_die
->name
= spec_die
->name
;
9227 /* Copy DW_AT_external attribute if it is set. */
9228 if (spec_die
->is_external
)
9229 part_die
->is_external
= spec_die
->is_external
;
9233 /* Set default names for some unnamed DIEs. */
9235 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9236 part_die
->name
= "(anonymous namespace)";
9238 /* If there is no parent die to provide a namespace, and there are
9239 children, see if we can determine the namespace from their linkage
9241 NOTE: We need to do this even if cu->has_namespace_info != 0.
9242 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9243 if (cu
->language
== language_cplus
9244 && dwarf2_per_objfile
->types
.asection
!= NULL
9245 && part_die
->die_parent
== NULL
9246 && part_die
->has_children
9247 && (part_die
->tag
== DW_TAG_class_type
9248 || part_die
->tag
== DW_TAG_structure_type
9249 || part_die
->tag
== DW_TAG_union_type
))
9250 guess_partial_die_structure_name (part_die
, cu
);
9252 part_die
->fixup_called
= 1;
9255 /* Read an attribute value described by an attribute form. */
9258 read_attribute_value (struct attribute
*attr
, unsigned form
,
9259 bfd
*abfd
, gdb_byte
*info_ptr
,
9260 struct dwarf2_cu
*cu
)
9262 struct comp_unit_head
*cu_header
= &cu
->header
;
9263 unsigned int bytes_read
;
9264 struct dwarf_block
*blk
;
9269 case DW_FORM_ref_addr
:
9270 if (cu
->header
.version
== 2)
9271 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9273 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9274 info_ptr
+= bytes_read
;
9277 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9278 info_ptr
+= bytes_read
;
9280 case DW_FORM_block2
:
9281 blk
= dwarf_alloc_block (cu
);
9282 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9284 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9285 info_ptr
+= blk
->size
;
9286 DW_BLOCK (attr
) = blk
;
9288 case DW_FORM_block4
:
9289 blk
= dwarf_alloc_block (cu
);
9290 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9292 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9293 info_ptr
+= blk
->size
;
9294 DW_BLOCK (attr
) = blk
;
9297 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9301 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9305 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9308 case DW_FORM_sec_offset
:
9309 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9310 info_ptr
+= bytes_read
;
9312 case DW_FORM_string
:
9313 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9314 DW_STRING_IS_CANONICAL (attr
) = 0;
9315 info_ptr
+= bytes_read
;
9318 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9320 DW_STRING_IS_CANONICAL (attr
) = 0;
9321 info_ptr
+= bytes_read
;
9323 case DW_FORM_exprloc
:
9325 blk
= dwarf_alloc_block (cu
);
9326 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9327 info_ptr
+= bytes_read
;
9328 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9329 info_ptr
+= blk
->size
;
9330 DW_BLOCK (attr
) = blk
;
9332 case DW_FORM_block1
:
9333 blk
= dwarf_alloc_block (cu
);
9334 blk
->size
= read_1_byte (abfd
, info_ptr
);
9336 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9337 info_ptr
+= blk
->size
;
9338 DW_BLOCK (attr
) = blk
;
9341 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9345 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9348 case DW_FORM_flag_present
:
9349 DW_UNSND (attr
) = 1;
9352 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9353 info_ptr
+= bytes_read
;
9356 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9357 info_ptr
+= bytes_read
;
9360 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9364 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9368 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9372 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9376 /* Convert the signature to something we can record in DW_UNSND
9378 NOTE: This is NULL if the type wasn't found. */
9379 DW_SIGNATURED_TYPE (attr
) =
9380 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9383 case DW_FORM_ref_udata
:
9384 DW_ADDR (attr
) = (cu
->header
.offset
9385 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9386 info_ptr
+= bytes_read
;
9388 case DW_FORM_indirect
:
9389 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9390 info_ptr
+= bytes_read
;
9391 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9394 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9395 dwarf_form_name (form
),
9396 bfd_get_filename (abfd
));
9399 /* We have seen instances where the compiler tried to emit a byte
9400 size attribute of -1 which ended up being encoded as an unsigned
9401 0xffffffff. Although 0xffffffff is technically a valid size value,
9402 an object of this size seems pretty unlikely so we can relatively
9403 safely treat these cases as if the size attribute was invalid and
9404 treat them as zero by default. */
9405 if (attr
->name
== DW_AT_byte_size
9406 && form
== DW_FORM_data4
9407 && DW_UNSND (attr
) >= 0xffffffff)
9410 (&symfile_complaints
,
9411 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9412 hex_string (DW_UNSND (attr
)));
9413 DW_UNSND (attr
) = 0;
9419 /* Read an attribute described by an abbreviated attribute. */
9422 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9423 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9425 attr
->name
= abbrev
->name
;
9426 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9429 /* read dwarf information from a buffer */
9432 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9434 return bfd_get_8 (abfd
, buf
);
9438 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9440 return bfd_get_signed_8 (abfd
, buf
);
9444 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9446 return bfd_get_16 (abfd
, buf
);
9450 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9452 return bfd_get_signed_16 (abfd
, buf
);
9456 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9458 return bfd_get_32 (abfd
, buf
);
9462 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9464 return bfd_get_signed_32 (abfd
, buf
);
9468 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9470 return bfd_get_64 (abfd
, buf
);
9474 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9475 unsigned int *bytes_read
)
9477 struct comp_unit_head
*cu_header
= &cu
->header
;
9478 CORE_ADDR retval
= 0;
9480 if (cu_header
->signed_addr_p
)
9482 switch (cu_header
->addr_size
)
9485 retval
= bfd_get_signed_16 (abfd
, buf
);
9488 retval
= bfd_get_signed_32 (abfd
, buf
);
9491 retval
= bfd_get_signed_64 (abfd
, buf
);
9494 internal_error (__FILE__
, __LINE__
,
9495 _("read_address: bad switch, signed [in module %s]"),
9496 bfd_get_filename (abfd
));
9501 switch (cu_header
->addr_size
)
9504 retval
= bfd_get_16 (abfd
, buf
);
9507 retval
= bfd_get_32 (abfd
, buf
);
9510 retval
= bfd_get_64 (abfd
, buf
);
9513 internal_error (__FILE__
, __LINE__
,
9514 _("read_address: bad switch, unsigned [in module %s]"),
9515 bfd_get_filename (abfd
));
9519 *bytes_read
= cu_header
->addr_size
;
9523 /* Read the initial length from a section. The (draft) DWARF 3
9524 specification allows the initial length to take up either 4 bytes
9525 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9526 bytes describe the length and all offsets will be 8 bytes in length
9529 An older, non-standard 64-bit format is also handled by this
9530 function. The older format in question stores the initial length
9531 as an 8-byte quantity without an escape value. Lengths greater
9532 than 2^32 aren't very common which means that the initial 4 bytes
9533 is almost always zero. Since a length value of zero doesn't make
9534 sense for the 32-bit format, this initial zero can be considered to
9535 be an escape value which indicates the presence of the older 64-bit
9536 format. As written, the code can't detect (old format) lengths
9537 greater than 4GB. If it becomes necessary to handle lengths
9538 somewhat larger than 4GB, we could allow other small values (such
9539 as the non-sensical values of 1, 2, and 3) to also be used as
9540 escape values indicating the presence of the old format.
9542 The value returned via bytes_read should be used to increment the
9543 relevant pointer after calling read_initial_length().
9545 [ Note: read_initial_length() and read_offset() are based on the
9546 document entitled "DWARF Debugging Information Format", revision
9547 3, draft 8, dated November 19, 2001. This document was obtained
9550 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9552 This document is only a draft and is subject to change. (So beware.)
9554 Details regarding the older, non-standard 64-bit format were
9555 determined empirically by examining 64-bit ELF files produced by
9556 the SGI toolchain on an IRIX 6.5 machine.
9558 - Kevin, July 16, 2002
9562 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9564 LONGEST length
= bfd_get_32 (abfd
, buf
);
9566 if (length
== 0xffffffff)
9568 length
= bfd_get_64 (abfd
, buf
+ 4);
9571 else if (length
== 0)
9573 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9574 length
= bfd_get_64 (abfd
, buf
);
9585 /* Cover function for read_initial_length.
9586 Returns the length of the object at BUF, and stores the size of the
9587 initial length in *BYTES_READ and stores the size that offsets will be in
9589 If the initial length size is not equivalent to that specified in
9590 CU_HEADER then issue a complaint.
9591 This is useful when reading non-comp-unit headers. */
9594 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9595 const struct comp_unit_head
*cu_header
,
9596 unsigned int *bytes_read
,
9597 unsigned int *offset_size
)
9599 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9601 gdb_assert (cu_header
->initial_length_size
== 4
9602 || cu_header
->initial_length_size
== 8
9603 || cu_header
->initial_length_size
== 12);
9605 if (cu_header
->initial_length_size
!= *bytes_read
)
9606 complaint (&symfile_complaints
,
9607 _("intermixed 32-bit and 64-bit DWARF sections"));
9609 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9613 /* Read an offset from the data stream. The size of the offset is
9614 given by cu_header->offset_size. */
9617 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9618 unsigned int *bytes_read
)
9620 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9622 *bytes_read
= cu_header
->offset_size
;
9626 /* Read an offset from the data stream. */
9629 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9633 switch (offset_size
)
9636 retval
= bfd_get_32 (abfd
, buf
);
9639 retval
= bfd_get_64 (abfd
, buf
);
9642 internal_error (__FILE__
, __LINE__
,
9643 _("read_offset_1: bad switch [in module %s]"),
9644 bfd_get_filename (abfd
));
9651 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9653 /* If the size of a host char is 8 bits, we can return a pointer
9654 to the buffer, otherwise we have to copy the data to a buffer
9655 allocated on the temporary obstack. */
9656 gdb_assert (HOST_CHAR_BIT
== 8);
9661 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9663 /* If the size of a host char is 8 bits, we can return a pointer
9664 to the string, otherwise we have to copy the string to a buffer
9665 allocated on the temporary obstack. */
9666 gdb_assert (HOST_CHAR_BIT
== 8);
9669 *bytes_read_ptr
= 1;
9672 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9673 return (char *) buf
;
9677 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9678 const struct comp_unit_head
*cu_header
,
9679 unsigned int *bytes_read_ptr
)
9681 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9683 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9684 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9686 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9687 bfd_get_filename (abfd
));
9690 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9692 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9693 bfd_get_filename (abfd
));
9696 gdb_assert (HOST_CHAR_BIT
== 8);
9697 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9699 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9702 static unsigned long
9703 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9705 unsigned long result
;
9706 unsigned int num_read
;
9716 byte
= bfd_get_8 (abfd
, buf
);
9719 result
|= ((unsigned long)(byte
& 127) << shift
);
9720 if ((byte
& 128) == 0)
9726 *bytes_read_ptr
= num_read
;
9731 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9734 int i
, shift
, num_read
;
9743 byte
= bfd_get_8 (abfd
, buf
);
9746 result
|= ((long)(byte
& 127) << shift
);
9748 if ((byte
& 128) == 0)
9753 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9754 result
|= -(((long)1) << shift
);
9755 *bytes_read_ptr
= num_read
;
9759 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9762 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9768 byte
= bfd_get_8 (abfd
, buf
);
9770 if ((byte
& 128) == 0)
9776 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9783 cu
->language
= language_c
;
9785 case DW_LANG_C_plus_plus
:
9786 cu
->language
= language_cplus
;
9789 cu
->language
= language_d
;
9791 case DW_LANG_Fortran77
:
9792 case DW_LANG_Fortran90
:
9793 case DW_LANG_Fortran95
:
9794 cu
->language
= language_fortran
;
9796 case DW_LANG_Mips_Assembler
:
9797 cu
->language
= language_asm
;
9800 cu
->language
= language_java
;
9804 cu
->language
= language_ada
;
9806 case DW_LANG_Modula2
:
9807 cu
->language
= language_m2
;
9809 case DW_LANG_Pascal83
:
9810 cu
->language
= language_pascal
;
9813 cu
->language
= language_objc
;
9815 case DW_LANG_Cobol74
:
9816 case DW_LANG_Cobol85
:
9818 cu
->language
= language_minimal
;
9821 cu
->language_defn
= language_def (cu
->language
);
9824 /* Return the named attribute or NULL if not there. */
9826 static struct attribute
*
9827 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9830 struct attribute
*spec
= NULL
;
9832 for (i
= 0; i
< die
->num_attrs
; ++i
)
9834 if (die
->attrs
[i
].name
== name
)
9835 return &die
->attrs
[i
];
9836 if (die
->attrs
[i
].name
== DW_AT_specification
9837 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9838 spec
= &die
->attrs
[i
];
9843 die
= follow_die_ref (die
, spec
, &cu
);
9844 return dwarf2_attr (die
, name
, cu
);
9850 /* Return the named attribute or NULL if not there,
9851 but do not follow DW_AT_specification, etc.
9852 This is for use in contexts where we're reading .debug_types dies.
9853 Following DW_AT_specification, DW_AT_abstract_origin will take us
9854 back up the chain, and we want to go down. */
9856 static struct attribute
*
9857 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9858 struct dwarf2_cu
*cu
)
9862 for (i
= 0; i
< die
->num_attrs
; ++i
)
9863 if (die
->attrs
[i
].name
== name
)
9864 return &die
->attrs
[i
];
9869 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9870 and holds a non-zero value. This function should only be used for
9871 DW_FORM_flag or DW_FORM_flag_present attributes. */
9874 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9876 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9878 return (attr
&& DW_UNSND (attr
));
9882 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9884 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9885 which value is non-zero. However, we have to be careful with
9886 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9887 (via dwarf2_flag_true_p) follows this attribute. So we may
9888 end up accidently finding a declaration attribute that belongs
9889 to a different DIE referenced by the specification attribute,
9890 even though the given DIE does not have a declaration attribute. */
9891 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9892 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9895 /* Return the die giving the specification for DIE, if there is
9896 one. *SPEC_CU is the CU containing DIE on input, and the CU
9897 containing the return value on output. If there is no
9898 specification, but there is an abstract origin, that is
9901 static struct die_info
*
9902 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9904 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9907 if (spec_attr
== NULL
)
9908 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9910 if (spec_attr
== NULL
)
9913 return follow_die_ref (die
, spec_attr
, spec_cu
);
9916 /* Free the line_header structure *LH, and any arrays and strings it
9918 NOTE: This is also used as a "cleanup" function. */
9921 free_line_header (struct line_header
*lh
)
9923 if (lh
->standard_opcode_lengths
)
9924 xfree (lh
->standard_opcode_lengths
);
9926 /* Remember that all the lh->file_names[i].name pointers are
9927 pointers into debug_line_buffer, and don't need to be freed. */
9929 xfree (lh
->file_names
);
9931 /* Similarly for the include directory names. */
9932 if (lh
->include_dirs
)
9933 xfree (lh
->include_dirs
);
9938 /* Add an entry to LH's include directory table. */
9941 add_include_dir (struct line_header
*lh
, char *include_dir
)
9943 /* Grow the array if necessary. */
9944 if (lh
->include_dirs_size
== 0)
9946 lh
->include_dirs_size
= 1; /* for testing */
9947 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9948 * sizeof (*lh
->include_dirs
));
9950 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9952 lh
->include_dirs_size
*= 2;
9953 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9954 (lh
->include_dirs_size
9955 * sizeof (*lh
->include_dirs
)));
9958 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9961 /* Add an entry to LH's file name table. */
9964 add_file_name (struct line_header
*lh
,
9966 unsigned int dir_index
,
9967 unsigned int mod_time
,
9968 unsigned int length
)
9970 struct file_entry
*fe
;
9972 /* Grow the array if necessary. */
9973 if (lh
->file_names_size
== 0)
9975 lh
->file_names_size
= 1; /* for testing */
9976 lh
->file_names
= xmalloc (lh
->file_names_size
9977 * sizeof (*lh
->file_names
));
9979 else if (lh
->num_file_names
>= lh
->file_names_size
)
9981 lh
->file_names_size
*= 2;
9982 lh
->file_names
= xrealloc (lh
->file_names
,
9983 (lh
->file_names_size
9984 * sizeof (*lh
->file_names
)));
9987 fe
= &lh
->file_names
[lh
->num_file_names
++];
9989 fe
->dir_index
= dir_index
;
9990 fe
->mod_time
= mod_time
;
9991 fe
->length
= length
;
9996 /* Read the statement program header starting at OFFSET in
9997 .debug_line, according to the endianness of ABFD. Return a pointer
9998 to a struct line_header, allocated using xmalloc.
10000 NOTE: the strings in the include directory and file name tables of
10001 the returned object point into debug_line_buffer, and must not be
10004 static struct line_header
*
10005 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10006 struct dwarf2_cu
*cu
)
10008 struct cleanup
*back_to
;
10009 struct line_header
*lh
;
10010 gdb_byte
*line_ptr
;
10011 unsigned int bytes_read
, offset_size
;
10013 char *cur_dir
, *cur_file
;
10015 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10016 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10018 complaint (&symfile_complaints
, _("missing .debug_line section"));
10022 /* Make sure that at least there's room for the total_length field.
10023 That could be 12 bytes long, but we're just going to fudge that. */
10024 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10026 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10030 lh
= xmalloc (sizeof (*lh
));
10031 memset (lh
, 0, sizeof (*lh
));
10032 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10035 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10037 /* Read in the header. */
10039 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10040 &bytes_read
, &offset_size
);
10041 line_ptr
+= bytes_read
;
10042 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10043 + dwarf2_per_objfile
->line
.size
))
10045 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10048 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10049 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10051 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10052 line_ptr
+= offset_size
;
10053 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10055 if (lh
->version
>= 4)
10057 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10061 lh
->maximum_ops_per_instruction
= 1;
10063 if (lh
->maximum_ops_per_instruction
== 0)
10065 lh
->maximum_ops_per_instruction
= 1;
10066 complaint (&symfile_complaints
,
10067 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
10070 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10072 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10074 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10076 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10078 lh
->standard_opcode_lengths
10079 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10081 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10082 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10084 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10088 /* Read directory table. */
10089 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10091 line_ptr
+= bytes_read
;
10092 add_include_dir (lh
, cur_dir
);
10094 line_ptr
+= bytes_read
;
10096 /* Read file name table. */
10097 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10099 unsigned int dir_index
, mod_time
, length
;
10101 line_ptr
+= bytes_read
;
10102 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10103 line_ptr
+= bytes_read
;
10104 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10105 line_ptr
+= bytes_read
;
10106 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10107 line_ptr
+= bytes_read
;
10109 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10111 line_ptr
+= bytes_read
;
10112 lh
->statement_program_start
= line_ptr
;
10114 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10115 + dwarf2_per_objfile
->line
.size
))
10116 complaint (&symfile_complaints
,
10117 _("line number info header doesn't fit in `.debug_line' section"));
10119 discard_cleanups (back_to
);
10123 /* This function exists to work around a bug in certain compilers
10124 (particularly GCC 2.95), in which the first line number marker of a
10125 function does not show up until after the prologue, right before
10126 the second line number marker. This function shifts ADDRESS down
10127 to the beginning of the function if necessary, and is called on
10128 addresses passed to record_line. */
10131 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10133 struct function_range
*fn
;
10135 /* Find the function_range containing address. */
10139 if (!cu
->cached_fn
)
10140 cu
->cached_fn
= cu
->first_fn
;
10142 fn
= cu
->cached_fn
;
10144 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10150 while (fn
&& fn
!= cu
->cached_fn
)
10151 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10161 if (address
!= fn
->lowpc
)
10162 complaint (&symfile_complaints
,
10163 _("misplaced first line number at 0x%lx for '%s'"),
10164 (unsigned long) address
, fn
->name
);
10169 /* Subroutine of dwarf_decode_lines to simplify it.
10170 Return the file name of the psymtab for included file FILE_INDEX
10171 in line header LH of PST.
10172 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10173 If space for the result is malloc'd, it will be freed by a cleanup.
10174 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10177 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10178 const struct partial_symtab
*pst
,
10179 const char *comp_dir
)
10181 const struct file_entry fe
= lh
->file_names
[file_index
];
10182 char *include_name
= fe
.name
;
10183 char *include_name_to_compare
= include_name
;
10184 char *dir_name
= NULL
;
10185 const char *pst_filename
;
10186 char *copied_name
= NULL
;
10190 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10192 if (!IS_ABSOLUTE_PATH (include_name
)
10193 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10195 /* Avoid creating a duplicate psymtab for PST.
10196 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10197 Before we do the comparison, however, we need to account
10198 for DIR_NAME and COMP_DIR.
10199 First prepend dir_name (if non-NULL). If we still don't
10200 have an absolute path prepend comp_dir (if non-NULL).
10201 However, the directory we record in the include-file's
10202 psymtab does not contain COMP_DIR (to match the
10203 corresponding symtab(s)).
10208 bash$ gcc -g ./hello.c
10209 include_name = "hello.c"
10211 DW_AT_comp_dir = comp_dir = "/tmp"
10212 DW_AT_name = "./hello.c" */
10214 if (dir_name
!= NULL
)
10216 include_name
= concat (dir_name
, SLASH_STRING
,
10217 include_name
, (char *)NULL
);
10218 include_name_to_compare
= include_name
;
10219 make_cleanup (xfree
, include_name
);
10221 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10223 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10224 include_name
, (char *)NULL
);
10228 pst_filename
= pst
->filename
;
10229 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10231 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10232 pst_filename
, (char *)NULL
);
10233 pst_filename
= copied_name
;
10236 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10238 if (include_name_to_compare
!= include_name
)
10239 xfree (include_name_to_compare
);
10240 if (copied_name
!= NULL
)
10241 xfree (copied_name
);
10245 return include_name
;
10248 /* Decode the Line Number Program (LNP) for the given line_header
10249 structure and CU. The actual information extracted and the type
10250 of structures created from the LNP depends on the value of PST.
10252 1. If PST is NULL, then this procedure uses the data from the program
10253 to create all necessary symbol tables, and their linetables.
10255 2. If PST is not NULL, this procedure reads the program to determine
10256 the list of files included by the unit represented by PST, and
10257 builds all the associated partial symbol tables.
10259 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10260 It is used for relative paths in the line table.
10261 NOTE: When processing partial symtabs (pst != NULL),
10262 comp_dir == pst->dirname.
10264 NOTE: It is important that psymtabs have the same file name (via strcmp)
10265 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10266 symtab we don't use it in the name of the psymtabs we create.
10267 E.g. expand_line_sal requires this when finding psymtabs to expand.
10268 A good testcase for this is mb-inline.exp. */
10271 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10272 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10274 gdb_byte
*line_ptr
, *extended_end
;
10275 gdb_byte
*line_end
;
10276 unsigned int bytes_read
, extended_len
;
10277 unsigned char op_code
, extended_op
, adj_opcode
;
10278 CORE_ADDR baseaddr
;
10279 struct objfile
*objfile
= cu
->objfile
;
10280 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10281 const int decode_for_pst_p
= (pst
!= NULL
);
10282 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10284 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10286 line_ptr
= lh
->statement_program_start
;
10287 line_end
= lh
->statement_program_end
;
10289 /* Read the statement sequences until there's nothing left. */
10290 while (line_ptr
< line_end
)
10292 /* state machine registers */
10293 CORE_ADDR address
= 0;
10294 unsigned int file
= 1;
10295 unsigned int line
= 1;
10296 unsigned int column
= 0;
10297 int is_stmt
= lh
->default_is_stmt
;
10298 int basic_block
= 0;
10299 int end_sequence
= 0;
10301 unsigned char op_index
= 0;
10303 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10305 /* Start a subfile for the current file of the state machine. */
10306 /* lh->include_dirs and lh->file_names are 0-based, but the
10307 directory and file name numbers in the statement program
10309 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10313 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10315 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10318 /* Decode the table. */
10319 while (!end_sequence
)
10321 op_code
= read_1_byte (abfd
, line_ptr
);
10323 if (line_ptr
> line_end
)
10325 dwarf2_debug_line_missing_end_sequence_complaint ();
10329 if (op_code
>= lh
->opcode_base
)
10331 /* Special operand. */
10332 adj_opcode
= op_code
- lh
->opcode_base
;
10333 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10334 / lh
->maximum_ops_per_instruction
)
10335 * lh
->minimum_instruction_length
);
10336 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10337 % lh
->maximum_ops_per_instruction
);
10338 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10339 if (lh
->num_file_names
< file
|| file
== 0)
10340 dwarf2_debug_line_missing_file_complaint ();
10341 /* For now we ignore lines not starting on an
10342 instruction boundary. */
10343 else if (op_index
== 0)
10345 lh
->file_names
[file
- 1].included_p
= 1;
10346 if (!decode_for_pst_p
&& is_stmt
)
10348 if (last_subfile
!= current_subfile
)
10350 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10352 record_line (last_subfile
, 0, addr
);
10353 last_subfile
= current_subfile
;
10355 /* Append row to matrix using current values. */
10356 addr
= check_cu_functions (address
, cu
);
10357 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10358 record_line (current_subfile
, line
, addr
);
10363 else switch (op_code
)
10365 case DW_LNS_extended_op
:
10366 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10367 line_ptr
+= bytes_read
;
10368 extended_end
= line_ptr
+ extended_len
;
10369 extended_op
= read_1_byte (abfd
, line_ptr
);
10371 switch (extended_op
)
10373 case DW_LNE_end_sequence
:
10376 case DW_LNE_set_address
:
10377 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10379 line_ptr
+= bytes_read
;
10380 address
+= baseaddr
;
10382 case DW_LNE_define_file
:
10385 unsigned int dir_index
, mod_time
, length
;
10387 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10388 line_ptr
+= bytes_read
;
10390 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10391 line_ptr
+= bytes_read
;
10393 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10394 line_ptr
+= bytes_read
;
10396 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10397 line_ptr
+= bytes_read
;
10398 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10401 case DW_LNE_set_discriminator
:
10402 /* The discriminator is not interesting to the debugger;
10404 line_ptr
= extended_end
;
10407 complaint (&symfile_complaints
,
10408 _("mangled .debug_line section"));
10411 /* Make sure that we parsed the extended op correctly. If e.g.
10412 we expected a different address size than the producer used,
10413 we may have read the wrong number of bytes. */
10414 if (line_ptr
!= extended_end
)
10416 complaint (&symfile_complaints
,
10417 _("mangled .debug_line section"));
10422 if (lh
->num_file_names
< file
|| file
== 0)
10423 dwarf2_debug_line_missing_file_complaint ();
10426 lh
->file_names
[file
- 1].included_p
= 1;
10427 if (!decode_for_pst_p
&& is_stmt
)
10429 if (last_subfile
!= current_subfile
)
10431 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10433 record_line (last_subfile
, 0, addr
);
10434 last_subfile
= current_subfile
;
10436 addr
= check_cu_functions (address
, cu
);
10437 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10438 record_line (current_subfile
, line
, addr
);
10443 case DW_LNS_advance_pc
:
10446 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10448 address
+= (((op_index
+ adjust
)
10449 / lh
->maximum_ops_per_instruction
)
10450 * lh
->minimum_instruction_length
);
10451 op_index
= ((op_index
+ adjust
)
10452 % lh
->maximum_ops_per_instruction
);
10453 line_ptr
+= bytes_read
;
10456 case DW_LNS_advance_line
:
10457 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10458 line_ptr
+= bytes_read
;
10460 case DW_LNS_set_file
:
10462 /* The arrays lh->include_dirs and lh->file_names are
10463 0-based, but the directory and file name numbers in
10464 the statement program are 1-based. */
10465 struct file_entry
*fe
;
10468 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10469 line_ptr
+= bytes_read
;
10470 if (lh
->num_file_names
< file
|| file
== 0)
10471 dwarf2_debug_line_missing_file_complaint ();
10474 fe
= &lh
->file_names
[file
- 1];
10476 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10477 if (!decode_for_pst_p
)
10479 last_subfile
= current_subfile
;
10480 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10485 case DW_LNS_set_column
:
10486 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10487 line_ptr
+= bytes_read
;
10489 case DW_LNS_negate_stmt
:
10490 is_stmt
= (!is_stmt
);
10492 case DW_LNS_set_basic_block
:
10495 /* Add to the address register of the state machine the
10496 address increment value corresponding to special opcode
10497 255. I.e., this value is scaled by the minimum
10498 instruction length since special opcode 255 would have
10499 scaled the the increment. */
10500 case DW_LNS_const_add_pc
:
10502 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10504 address
+= (((op_index
+ adjust
)
10505 / lh
->maximum_ops_per_instruction
)
10506 * lh
->minimum_instruction_length
);
10507 op_index
= ((op_index
+ adjust
)
10508 % lh
->maximum_ops_per_instruction
);
10511 case DW_LNS_fixed_advance_pc
:
10512 address
+= read_2_bytes (abfd
, line_ptr
);
10518 /* Unknown standard opcode, ignore it. */
10521 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10523 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10524 line_ptr
+= bytes_read
;
10529 if (lh
->num_file_names
< file
|| file
== 0)
10530 dwarf2_debug_line_missing_file_complaint ();
10533 lh
->file_names
[file
- 1].included_p
= 1;
10534 if (!decode_for_pst_p
)
10536 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10537 record_line (current_subfile
, 0, addr
);
10542 if (decode_for_pst_p
)
10546 /* Now that we're done scanning the Line Header Program, we can
10547 create the psymtab of each included file. */
10548 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10549 if (lh
->file_names
[file_index
].included_p
== 1)
10551 char *include_name
=
10552 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10553 if (include_name
!= NULL
)
10554 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10559 /* Make sure a symtab is created for every file, even files
10560 which contain only variables (i.e. no code with associated
10564 struct file_entry
*fe
;
10566 for (i
= 0; i
< lh
->num_file_names
; i
++)
10570 fe
= &lh
->file_names
[i
];
10572 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10573 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10575 /* Skip the main file; we don't need it, and it must be
10576 allocated last, so that it will show up before the
10577 non-primary symtabs in the objfile's symtab list. */
10578 if (current_subfile
== first_subfile
)
10581 if (current_subfile
->symtab
== NULL
)
10582 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10584 fe
->symtab
= current_subfile
->symtab
;
10589 /* Start a subfile for DWARF. FILENAME is the name of the file and
10590 DIRNAME the name of the source directory which contains FILENAME
10591 or NULL if not known. COMP_DIR is the compilation directory for the
10592 linetable's compilation unit or NULL if not known.
10593 This routine tries to keep line numbers from identical absolute and
10594 relative file names in a common subfile.
10596 Using the `list' example from the GDB testsuite, which resides in
10597 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10598 of /srcdir/list0.c yields the following debugging information for list0.c:
10600 DW_AT_name: /srcdir/list0.c
10601 DW_AT_comp_dir: /compdir
10602 files.files[0].name: list0.h
10603 files.files[0].dir: /srcdir
10604 files.files[1].name: list0.c
10605 files.files[1].dir: /srcdir
10607 The line number information for list0.c has to end up in a single
10608 subfile, so that `break /srcdir/list0.c:1' works as expected.
10609 start_subfile will ensure that this happens provided that we pass the
10610 concatenation of files.files[1].dir and files.files[1].name as the
10614 dwarf2_start_subfile (char *filename
, const char *dirname
, const char *comp_dir
)
10618 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10619 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10620 second argument to start_subfile. To be consistent, we do the
10621 same here. In order not to lose the line information directory,
10622 we concatenate it to the filename when it makes sense.
10623 Note that the Dwarf3 standard says (speaking of filenames in line
10624 information): ``The directory index is ignored for file names
10625 that represent full path names''. Thus ignoring dirname in the
10626 `else' branch below isn't an issue. */
10628 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10629 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10631 fullname
= filename
;
10633 start_subfile (fullname
, comp_dir
);
10635 if (fullname
!= filename
)
10640 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10641 struct dwarf2_cu
*cu
)
10643 struct objfile
*objfile
= cu
->objfile
;
10644 struct comp_unit_head
*cu_header
= &cu
->header
;
10646 /* NOTE drow/2003-01-30: There used to be a comment and some special
10647 code here to turn a symbol with DW_AT_external and a
10648 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10649 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10650 with some versions of binutils) where shared libraries could have
10651 relocations against symbols in their debug information - the
10652 minimal symbol would have the right address, but the debug info
10653 would not. It's no longer necessary, because we will explicitly
10654 apply relocations when we read in the debug information now. */
10656 /* A DW_AT_location attribute with no contents indicates that a
10657 variable has been optimized away. */
10658 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10660 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10664 /* Handle one degenerate form of location expression specially, to
10665 preserve GDB's previous behavior when section offsets are
10666 specified. If this is just a DW_OP_addr then mark this symbol
10669 if (attr_form_is_block (attr
)
10670 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10671 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10673 unsigned int dummy
;
10675 SYMBOL_VALUE_ADDRESS (sym
) =
10676 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10677 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10678 fixup_symbol_section (sym
, objfile
);
10679 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10680 SYMBOL_SECTION (sym
));
10684 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10685 expression evaluator, and use LOC_COMPUTED only when necessary
10686 (i.e. when the value of a register or memory location is
10687 referenced, or a thread-local block, etc.). Then again, it might
10688 not be worthwhile. I'm assuming that it isn't unless performance
10689 or memory numbers show me otherwise. */
10691 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10692 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10695 /* Given a pointer to a DWARF information entry, figure out if we need
10696 to make a symbol table entry for it, and if so, create a new entry
10697 and return a pointer to it.
10698 If TYPE is NULL, determine symbol type from the die, otherwise
10699 used the passed type.
10700 If SPACE is not NULL, use it to hold the new symbol. If it is
10701 NULL, allocate a new symbol on the objfile's obstack. */
10703 static struct symbol
*
10704 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10705 struct symbol
*space
)
10707 struct objfile
*objfile
= cu
->objfile
;
10708 struct symbol
*sym
= NULL
;
10710 struct attribute
*attr
= NULL
;
10711 struct attribute
*attr2
= NULL
;
10712 CORE_ADDR baseaddr
;
10713 struct pending
**list_to_add
= NULL
;
10715 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10717 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10719 name
= dwarf2_name (die
, cu
);
10722 const char *linkagename
;
10723 int suppress_add
= 0;
10728 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10729 OBJSTAT (objfile
, n_syms
++);
10731 /* Cache this symbol's name and the name's demangled form (if any). */
10732 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10733 linkagename
= dwarf2_physname (name
, die
, cu
);
10734 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10736 /* Fortran does not have mangling standard and the mangling does differ
10737 between gfortran, iFort etc. */
10738 if (cu
->language
== language_fortran
10739 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10740 symbol_set_demangled_name (&(sym
->ginfo
),
10741 (char *) dwarf2_full_name (name
, die
, cu
),
10744 /* Default assumptions.
10745 Use the passed type or decode it from the die. */
10746 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10747 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10749 SYMBOL_TYPE (sym
) = type
;
10751 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10752 attr
= dwarf2_attr (die
,
10753 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10757 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10760 attr
= dwarf2_attr (die
,
10761 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10765 int file_index
= DW_UNSND (attr
);
10767 if (cu
->line_header
== NULL
10768 || file_index
> cu
->line_header
->num_file_names
)
10769 complaint (&symfile_complaints
,
10770 _("file index out of range"));
10771 else if (file_index
> 0)
10773 struct file_entry
*fe
;
10775 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10776 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10783 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10786 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10788 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10789 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10790 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10791 add_symbol_to_list (sym
, cu
->list_in_scope
);
10793 case DW_TAG_subprogram
:
10794 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10796 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10797 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10798 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10799 || cu
->language
== language_ada
)
10801 /* Subprograms marked external are stored as a global symbol.
10802 Ada subprograms, whether marked external or not, are always
10803 stored as a global symbol, because we want to be able to
10804 access them globally. For instance, we want to be able
10805 to break on a nested subprogram without having to
10806 specify the context. */
10807 list_to_add
= &global_symbols
;
10811 list_to_add
= cu
->list_in_scope
;
10814 case DW_TAG_inlined_subroutine
:
10815 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10817 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10818 SYMBOL_INLINED (sym
) = 1;
10819 /* Do not add the symbol to any lists. It will be found via
10820 BLOCK_FUNCTION from the blockvector. */
10822 case DW_TAG_template_value_param
:
10824 /* Fall through. */
10825 case DW_TAG_constant
:
10826 case DW_TAG_variable
:
10827 case DW_TAG_member
:
10828 /* Compilation with minimal debug info may result in variables
10829 with missing type entries. Change the misleading `void' type
10830 to something sensible. */
10831 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10833 = objfile_type (objfile
)->nodebug_data_symbol
;
10835 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10836 /* In the case of DW_TAG_member, we should only be called for
10837 static const members. */
10838 if (die
->tag
== DW_TAG_member
)
10840 /* dwarf2_add_field uses die_is_declaration,
10841 so we do the same. */
10842 gdb_assert (die_is_declaration (die
, cu
));
10847 dwarf2_const_value (attr
, sym
, cu
);
10848 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10851 if (attr2
&& (DW_UNSND (attr2
) != 0))
10852 list_to_add
= &global_symbols
;
10854 list_to_add
= cu
->list_in_scope
;
10858 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10861 var_decode_location (attr
, sym
, cu
);
10862 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10863 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10864 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10865 && !dwarf2_per_objfile
->has_section_at_zero
)
10867 /* When a static variable is eliminated by the linker,
10868 the corresponding debug information is not stripped
10869 out, but the variable address is set to null;
10870 do not add such variables into symbol table. */
10872 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10874 /* Workaround gfortran PR debug/40040 - it uses
10875 DW_AT_location for variables in -fPIC libraries which may
10876 get overriden by other libraries/executable and get
10877 a different address. Resolve it by the minimal symbol
10878 which may come from inferior's executable using copy
10879 relocation. Make this workaround only for gfortran as for
10880 other compilers GDB cannot guess the minimal symbol
10881 Fortran mangling kind. */
10882 if (cu
->language
== language_fortran
&& die
->parent
10883 && die
->parent
->tag
== DW_TAG_module
10885 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10886 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10888 /* A variable with DW_AT_external is never static,
10889 but it may be block-scoped. */
10890 list_to_add
= (cu
->list_in_scope
== &file_symbols
10891 ? &global_symbols
: cu
->list_in_scope
);
10894 list_to_add
= cu
->list_in_scope
;
10898 /* We do not know the address of this symbol.
10899 If it is an external symbol and we have type information
10900 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10901 The address of the variable will then be determined from
10902 the minimal symbol table whenever the variable is
10904 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10905 if (attr2
&& (DW_UNSND (attr2
) != 0)
10906 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10908 /* A variable with DW_AT_external is never static, but it
10909 may be block-scoped. */
10910 list_to_add
= (cu
->list_in_scope
== &file_symbols
10911 ? &global_symbols
: cu
->list_in_scope
);
10913 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10915 else if (!die_is_declaration (die
, cu
))
10917 /* Use the default LOC_OPTIMIZED_OUT class. */
10918 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10920 list_to_add
= cu
->list_in_scope
;
10924 case DW_TAG_formal_parameter
:
10925 /* If we are inside a function, mark this as an argument. If
10926 not, we might be looking at an argument to an inlined function
10927 when we do not have enough information to show inlined frames;
10928 pretend it's a local variable in that case so that the user can
10930 if (context_stack_depth
> 0
10931 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10932 SYMBOL_IS_ARGUMENT (sym
) = 1;
10933 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10936 var_decode_location (attr
, sym
, cu
);
10938 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10941 dwarf2_const_value (attr
, sym
, cu
);
10943 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10944 if (attr
&& DW_UNSND (attr
))
10946 struct type
*ref_type
;
10948 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10949 SYMBOL_TYPE (sym
) = ref_type
;
10952 list_to_add
= cu
->list_in_scope
;
10954 case DW_TAG_unspecified_parameters
:
10955 /* From varargs functions; gdb doesn't seem to have any
10956 interest in this information, so just ignore it for now.
10959 case DW_TAG_template_type_param
:
10961 /* Fall through. */
10962 case DW_TAG_class_type
:
10963 case DW_TAG_interface_type
:
10964 case DW_TAG_structure_type
:
10965 case DW_TAG_union_type
:
10966 case DW_TAG_set_type
:
10967 case DW_TAG_enumeration_type
:
10968 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10969 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10972 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10973 really ever be static objects: otherwise, if you try
10974 to, say, break of a class's method and you're in a file
10975 which doesn't mention that class, it won't work unless
10976 the check for all static symbols in lookup_symbol_aux
10977 saves you. See the OtherFileClass tests in
10978 gdb.c++/namespace.exp. */
10982 list_to_add
= (cu
->list_in_scope
== &file_symbols
10983 && (cu
->language
== language_cplus
10984 || cu
->language
== language_java
)
10985 ? &global_symbols
: cu
->list_in_scope
);
10987 /* The semantics of C++ state that "struct foo {
10988 ... }" also defines a typedef for "foo". A Java
10989 class declaration also defines a typedef for the
10991 if (cu
->language
== language_cplus
10992 || cu
->language
== language_java
10993 || cu
->language
== language_ada
)
10995 /* The symbol's name is already allocated along
10996 with this objfile, so we don't need to
10997 duplicate it for the type. */
10998 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10999 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11004 case DW_TAG_typedef
:
11005 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11006 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11007 list_to_add
= cu
->list_in_scope
;
11009 case DW_TAG_base_type
:
11010 case DW_TAG_subrange_type
:
11011 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11012 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11013 list_to_add
= cu
->list_in_scope
;
11015 case DW_TAG_enumerator
:
11016 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11019 dwarf2_const_value (attr
, sym
, cu
);
11022 /* NOTE: carlton/2003-11-10: See comment above in the
11023 DW_TAG_class_type, etc. block. */
11025 list_to_add
= (cu
->list_in_scope
== &file_symbols
11026 && (cu
->language
== language_cplus
11027 || cu
->language
== language_java
)
11028 ? &global_symbols
: cu
->list_in_scope
);
11031 case DW_TAG_namespace
:
11032 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11033 list_to_add
= &global_symbols
;
11036 /* Not a tag we recognize. Hopefully we aren't processing
11037 trash data, but since we must specifically ignore things
11038 we don't recognize, there is nothing else we should do at
11040 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11041 dwarf_tag_name (die
->tag
));
11047 sym
->hash_next
= objfile
->template_symbols
;
11048 objfile
->template_symbols
= sym
;
11049 list_to_add
= NULL
;
11052 if (list_to_add
!= NULL
)
11053 add_symbol_to_list (sym
, list_to_add
);
11055 /* For the benefit of old versions of GCC, check for anonymous
11056 namespaces based on the demangled name. */
11057 if (!processing_has_namespace_info
11058 && cu
->language
== language_cplus
)
11059 cp_scan_for_anonymous_namespaces (sym
);
11064 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11066 static struct symbol
*
11067 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11069 return new_symbol_full (die
, type
, cu
, NULL
);
11072 /* Given an attr with a DW_FORM_dataN value in host byte order,
11073 zero-extend it as appropriate for the symbol's type. The DWARF
11074 standard (v4) is not entirely clear about the meaning of using
11075 DW_FORM_dataN for a constant with a signed type, where the type is
11076 wider than the data. The conclusion of a discussion on the DWARF
11077 list was that this is unspecified. We choose to always zero-extend
11078 because that is the interpretation long in use by GCC. */
11081 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11082 const char *name
, struct obstack
*obstack
,
11083 struct dwarf2_cu
*cu
, long *value
, int bits
)
11085 struct objfile
*objfile
= cu
->objfile
;
11086 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11087 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11088 LONGEST l
= DW_UNSND (attr
);
11090 if (bits
< sizeof (*value
) * 8)
11092 l
&= ((LONGEST
) 1 << bits
) - 1;
11095 else if (bits
== sizeof (*value
) * 8)
11099 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11100 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11107 /* Read a constant value from an attribute. Either set *VALUE, or if
11108 the value does not fit in *VALUE, set *BYTES - either already
11109 allocated on the objfile obstack, or newly allocated on OBSTACK,
11110 or, set *BATON, if we translated the constant to a location
11114 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11115 const char *name
, struct obstack
*obstack
,
11116 struct dwarf2_cu
*cu
,
11117 long *value
, gdb_byte
**bytes
,
11118 struct dwarf2_locexpr_baton
**baton
)
11120 struct objfile
*objfile
= cu
->objfile
;
11121 struct comp_unit_head
*cu_header
= &cu
->header
;
11122 struct dwarf_block
*blk
;
11123 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11124 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11130 switch (attr
->form
)
11136 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11137 dwarf2_const_value_length_mismatch_complaint (name
,
11138 cu_header
->addr_size
,
11139 TYPE_LENGTH (type
));
11140 /* Symbols of this form are reasonably rare, so we just
11141 piggyback on the existing location code rather than writing
11142 a new implementation of symbol_computed_ops. */
11143 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11144 sizeof (struct dwarf2_locexpr_baton
));
11145 (*baton
)->per_cu
= cu
->per_cu
;
11146 gdb_assert ((*baton
)->per_cu
);
11148 (*baton
)->size
= 2 + cu_header
->addr_size
;
11149 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11150 (*baton
)->data
= data
;
11152 data
[0] = DW_OP_addr
;
11153 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11154 byte_order
, DW_ADDR (attr
));
11155 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11158 case DW_FORM_string
:
11160 /* DW_STRING is already allocated on the objfile obstack, point
11162 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11164 case DW_FORM_block1
:
11165 case DW_FORM_block2
:
11166 case DW_FORM_block4
:
11167 case DW_FORM_block
:
11168 case DW_FORM_exprloc
:
11169 blk
= DW_BLOCK (attr
);
11170 if (TYPE_LENGTH (type
) != blk
->size
)
11171 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11172 TYPE_LENGTH (type
));
11173 *bytes
= blk
->data
;
11176 /* The DW_AT_const_value attributes are supposed to carry the
11177 symbol's value "represented as it would be on the target
11178 architecture." By the time we get here, it's already been
11179 converted to host endianness, so we just need to sign- or
11180 zero-extend it as appropriate. */
11181 case DW_FORM_data1
:
11182 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
11184 case DW_FORM_data2
:
11185 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
11187 case DW_FORM_data4
:
11188 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
11190 case DW_FORM_data8
:
11191 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
11194 case DW_FORM_sdata
:
11195 *value
= DW_SND (attr
);
11198 case DW_FORM_udata
:
11199 *value
= DW_UNSND (attr
);
11203 complaint (&symfile_complaints
,
11204 _("unsupported const value attribute form: '%s'"),
11205 dwarf_form_name (attr
->form
));
11212 /* Copy constant value from an attribute to a symbol. */
11215 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11216 struct dwarf2_cu
*cu
)
11218 struct objfile
*objfile
= cu
->objfile
;
11219 struct comp_unit_head
*cu_header
= &cu
->header
;
11222 struct dwarf2_locexpr_baton
*baton
;
11224 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11225 SYMBOL_PRINT_NAME (sym
),
11226 &objfile
->objfile_obstack
, cu
,
11227 &value
, &bytes
, &baton
);
11231 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11232 SYMBOL_LOCATION_BATON (sym
) = baton
;
11233 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11235 else if (bytes
!= NULL
)
11237 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11238 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11242 SYMBOL_VALUE (sym
) = value
;
11243 SYMBOL_CLASS (sym
) = LOC_CONST
;
11247 /* Return the type of the die in question using its DW_AT_type attribute. */
11249 static struct type
*
11250 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11252 struct attribute
*type_attr
;
11254 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11257 /* A missing DW_AT_type represents a void type. */
11258 return objfile_type (cu
->objfile
)->builtin_void
;
11261 return lookup_die_type (die
, type_attr
, cu
);
11264 /* True iff CU's producer generates GNAT Ada auxiliary information
11265 that allows to find parallel types through that information instead
11266 of having to do expensive parallel lookups by type name. */
11269 need_gnat_info (struct dwarf2_cu
*cu
)
11271 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11272 of GNAT produces this auxiliary information, without any indication
11273 that it is produced. Part of enhancing the FSF version of GNAT
11274 to produce that information will be to put in place an indicator
11275 that we can use in order to determine whether the descriptive type
11276 info is available or not. One suggestion that has been made is
11277 to use a new attribute, attached to the CU die. For now, assume
11278 that the descriptive type info is not available. */
11282 /* Return the auxiliary type of the die in question using its
11283 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11284 attribute is not present. */
11286 static struct type
*
11287 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11289 struct attribute
*type_attr
;
11291 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11295 return lookup_die_type (die
, type_attr
, cu
);
11298 /* If DIE has a descriptive_type attribute, then set the TYPE's
11299 descriptive type accordingly. */
11302 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11303 struct dwarf2_cu
*cu
)
11305 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11307 if (descriptive_type
)
11309 ALLOCATE_GNAT_AUX_TYPE (type
);
11310 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11314 /* Return the containing type of the die in question using its
11315 DW_AT_containing_type attribute. */
11317 static struct type
*
11318 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11320 struct attribute
*type_attr
;
11322 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11324 error (_("Dwarf Error: Problem turning containing type into gdb type "
11325 "[in module %s]"), cu
->objfile
->name
);
11327 return lookup_die_type (die
, type_attr
, cu
);
11330 /* Look up the type of DIE in CU using its type attribute ATTR.
11331 If there is no type substitute an error marker. */
11333 static struct type
*
11334 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11335 struct dwarf2_cu
*cu
)
11337 struct type
*this_type
;
11339 /* First see if we have it cached. */
11341 if (is_ref_attr (attr
))
11343 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11345 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11347 else if (attr
->form
== DW_FORM_sig8
)
11349 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11350 struct dwarf2_cu
*sig_cu
;
11351 unsigned int offset
;
11353 /* sig_type will be NULL if the signatured type is missing from
11355 if (sig_type
== NULL
)
11356 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11357 "at 0x%x [in module %s]"),
11358 die
->offset
, cu
->objfile
->name
);
11360 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11361 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11362 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11366 dump_die_for_error (die
);
11367 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11368 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11371 /* If not cached we need to read it in. */
11373 if (this_type
== NULL
)
11375 struct die_info
*type_die
;
11376 struct dwarf2_cu
*type_cu
= cu
;
11378 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11379 /* If the type is cached, we should have found it above. */
11380 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11381 this_type
= read_type_die_1 (type_die
, type_cu
);
11384 /* If we still don't have a type use an error marker. */
11386 if (this_type
== NULL
)
11388 char *message
, *saved
;
11390 /* read_type_die already issued a complaint. */
11391 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11395 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11396 message
, strlen (message
));
11399 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11405 /* Return the type in DIE, CU.
11406 Returns NULL for invalid types.
11408 This first does a lookup in the appropriate type_hash table,
11409 and only reads the die in if necessary.
11411 NOTE: This can be called when reading in partial or full symbols. */
11413 static struct type
*
11414 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11416 struct type
*this_type
;
11418 this_type
= get_die_type (die
, cu
);
11422 return read_type_die_1 (die
, cu
);
11425 /* Read the type in DIE, CU.
11426 Returns NULL for invalid types. */
11428 static struct type
*
11429 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11431 struct type
*this_type
= NULL
;
11435 case DW_TAG_class_type
:
11436 case DW_TAG_interface_type
:
11437 case DW_TAG_structure_type
:
11438 case DW_TAG_union_type
:
11439 this_type
= read_structure_type (die
, cu
);
11441 case DW_TAG_enumeration_type
:
11442 this_type
= read_enumeration_type (die
, cu
);
11444 case DW_TAG_subprogram
:
11445 case DW_TAG_subroutine_type
:
11446 case DW_TAG_inlined_subroutine
:
11447 this_type
= read_subroutine_type (die
, cu
);
11449 case DW_TAG_array_type
:
11450 this_type
= read_array_type (die
, cu
);
11452 case DW_TAG_set_type
:
11453 this_type
= read_set_type (die
, cu
);
11455 case DW_TAG_pointer_type
:
11456 this_type
= read_tag_pointer_type (die
, cu
);
11458 case DW_TAG_ptr_to_member_type
:
11459 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11461 case DW_TAG_reference_type
:
11462 this_type
= read_tag_reference_type (die
, cu
);
11464 case DW_TAG_const_type
:
11465 this_type
= read_tag_const_type (die
, cu
);
11467 case DW_TAG_volatile_type
:
11468 this_type
= read_tag_volatile_type (die
, cu
);
11470 case DW_TAG_string_type
:
11471 this_type
= read_tag_string_type (die
, cu
);
11473 case DW_TAG_typedef
:
11474 this_type
= read_typedef (die
, cu
);
11476 case DW_TAG_subrange_type
:
11477 this_type
= read_subrange_type (die
, cu
);
11479 case DW_TAG_base_type
:
11480 this_type
= read_base_type (die
, cu
);
11482 case DW_TAG_unspecified_type
:
11483 this_type
= read_unspecified_type (die
, cu
);
11485 case DW_TAG_namespace
:
11486 this_type
= read_namespace_type (die
, cu
);
11488 case DW_TAG_module
:
11489 this_type
= read_module_type (die
, cu
);
11492 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11493 dwarf_tag_name (die
->tag
));
11500 /* See if we can figure out if the class lives in a namespace. We do
11501 this by looking for a member function; its demangled name will
11502 contain namespace info, if there is any.
11503 Return the computed name or NULL.
11504 Space for the result is allocated on the objfile's obstack.
11505 This is the full-die version of guess_partial_die_structure_name.
11506 In this case we know DIE has no useful parent. */
11509 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11511 struct die_info
*spec_die
;
11512 struct dwarf2_cu
*spec_cu
;
11513 struct die_info
*child
;
11516 spec_die
= die_specification (die
, &spec_cu
);
11517 if (spec_die
!= NULL
)
11523 for (child
= die
->child
;
11525 child
= child
->sibling
)
11527 if (child
->tag
== DW_TAG_subprogram
)
11529 struct attribute
*attr
;
11531 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11533 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11537 = language_class_name_from_physname (cu
->language_defn
,
11541 if (actual_name
!= NULL
)
11543 char *die_name
= dwarf2_name (die
, cu
);
11545 if (die_name
!= NULL
11546 && strcmp (die_name
, actual_name
) != 0)
11548 /* Strip off the class name from the full name.
11549 We want the prefix. */
11550 int die_name_len
= strlen (die_name
);
11551 int actual_name_len
= strlen (actual_name
);
11553 /* Test for '::' as a sanity check. */
11554 if (actual_name_len
> die_name_len
+ 2
11555 && actual_name
[actual_name_len
- die_name_len
- 1] == ':')
11557 obsavestring (actual_name
,
11558 actual_name_len
- die_name_len
- 2,
11559 &cu
->objfile
->objfile_obstack
);
11562 xfree (actual_name
);
11571 /* Return the name of the namespace/class that DIE is defined within,
11572 or "" if we can't tell. The caller should not xfree the result.
11574 For example, if we're within the method foo() in the following
11584 then determine_prefix on foo's die will return "N::C". */
11587 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11589 struct die_info
*parent
, *spec_die
;
11590 struct dwarf2_cu
*spec_cu
;
11591 struct type
*parent_type
;
11593 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11594 && cu
->language
!= language_fortran
)
11597 /* We have to be careful in the presence of DW_AT_specification.
11598 For example, with GCC 3.4, given the code
11602 // Definition of N::foo.
11606 then we'll have a tree of DIEs like this:
11608 1: DW_TAG_compile_unit
11609 2: DW_TAG_namespace // N
11610 3: DW_TAG_subprogram // declaration of N::foo
11611 4: DW_TAG_subprogram // definition of N::foo
11612 DW_AT_specification // refers to die #3
11614 Thus, when processing die #4, we have to pretend that we're in
11615 the context of its DW_AT_specification, namely the contex of die
11618 spec_die
= die_specification (die
, &spec_cu
);
11619 if (spec_die
== NULL
)
11620 parent
= die
->parent
;
11623 parent
= spec_die
->parent
;
11627 if (parent
== NULL
)
11629 else if (parent
->building_fullname
)
11632 const char *parent_name
;
11634 /* It has been seen on RealView 2.2 built binaries,
11635 DW_TAG_template_type_param types actually _defined_ as
11636 children of the parent class:
11639 template class <class Enum> Class{};
11640 Class<enum E> class_e;
11642 1: DW_TAG_class_type (Class)
11643 2: DW_TAG_enumeration_type (E)
11644 3: DW_TAG_enumerator (enum1:0)
11645 3: DW_TAG_enumerator (enum2:1)
11647 2: DW_TAG_template_type_param
11648 DW_AT_type DW_FORM_ref_udata (E)
11650 Besides being broken debug info, it can put GDB into an
11651 infinite loop. Consider:
11653 When we're building the full name for Class<E>, we'll start
11654 at Class, and go look over its template type parameters,
11655 finding E. We'll then try to build the full name of E, and
11656 reach here. We're now trying to build the full name of E,
11657 and look over the parent DIE for containing scope. In the
11658 broken case, if we followed the parent DIE of E, we'd again
11659 find Class, and once again go look at its template type
11660 arguments, etc., etc. Simply don't consider such parent die
11661 as source-level parent of this die (it can't be, the language
11662 doesn't allow it), and break the loop here. */
11663 name
= dwarf2_name (die
, cu
);
11664 parent_name
= dwarf2_name (parent
, cu
);
11665 complaint (&symfile_complaints
,
11666 _("template param type '%s' defined within parent '%s'"),
11667 name
? name
: "<unknown>",
11668 parent_name
? parent_name
: "<unknown>");
11672 switch (parent
->tag
)
11674 case DW_TAG_namespace
:
11675 parent_type
= read_type_die (parent
, cu
);
11676 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11677 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11678 Work around this problem here. */
11679 if (cu
->language
== language_cplus
11680 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11682 /* We give a name to even anonymous namespaces. */
11683 return TYPE_TAG_NAME (parent_type
);
11684 case DW_TAG_class_type
:
11685 case DW_TAG_interface_type
:
11686 case DW_TAG_structure_type
:
11687 case DW_TAG_union_type
:
11688 case DW_TAG_module
:
11689 parent_type
= read_type_die (parent
, cu
);
11690 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11691 return TYPE_TAG_NAME (parent_type
);
11693 /* An anonymous structure is only allowed non-static data
11694 members; no typedefs, no member functions, et cetera.
11695 So it does not need a prefix. */
11697 case DW_TAG_compile_unit
:
11698 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11699 if (cu
->language
== language_cplus
11700 && dwarf2_per_objfile
->types
.asection
!= NULL
11701 && die
->child
!= NULL
11702 && (die
->tag
== DW_TAG_class_type
11703 || die
->tag
== DW_TAG_structure_type
11704 || die
->tag
== DW_TAG_union_type
))
11706 char *name
= guess_full_die_structure_name (die
, cu
);
11712 return determine_prefix (parent
, cu
);
11716 /* Return a newly-allocated string formed by concatenating PREFIX and
11717 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11718 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11719 perform an obconcat, otherwise allocate storage for the result. The CU argument
11720 is used to determine the language and hence, the appropriate separator. */
11722 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11725 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11726 int physname
, struct dwarf2_cu
*cu
)
11728 const char *lead
= "";
11731 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11733 else if (cu
->language
== language_java
)
11735 else if (cu
->language
== language_fortran
&& physname
)
11737 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11738 DW_AT_MIPS_linkage_name is preferred and used instead. */
11746 if (prefix
== NULL
)
11748 if (suffix
== NULL
)
11753 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11755 strcpy (retval
, lead
);
11756 strcat (retval
, prefix
);
11757 strcat (retval
, sep
);
11758 strcat (retval
, suffix
);
11763 /* We have an obstack. */
11764 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11768 /* Return sibling of die, NULL if no sibling. */
11770 static struct die_info
*
11771 sibling_die (struct die_info
*die
)
11773 return die
->sibling
;
11776 /* Get name of a die, return NULL if not found. */
11779 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11780 struct obstack
*obstack
)
11782 if (name
&& cu
->language
== language_cplus
)
11784 char *canon_name
= cp_canonicalize_string (name
);
11786 if (canon_name
!= NULL
)
11788 if (strcmp (canon_name
, name
) != 0)
11789 name
= obsavestring (canon_name
, strlen (canon_name
),
11791 xfree (canon_name
);
11798 /* Get name of a die, return NULL if not found. */
11801 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11803 struct attribute
*attr
;
11805 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11806 if (!attr
|| !DW_STRING (attr
))
11811 case DW_TAG_compile_unit
:
11812 /* Compilation units have a DW_AT_name that is a filename, not
11813 a source language identifier. */
11814 case DW_TAG_enumeration_type
:
11815 case DW_TAG_enumerator
:
11816 /* These tags always have simple identifiers already; no need
11817 to canonicalize them. */
11818 return DW_STRING (attr
);
11820 case DW_TAG_subprogram
:
11821 /* Java constructors will all be named "<init>", so return
11822 the class name when we see this special case. */
11823 if (cu
->language
== language_java
11824 && DW_STRING (attr
) != NULL
11825 && strcmp (DW_STRING (attr
), "<init>") == 0)
11827 struct dwarf2_cu
*spec_cu
= cu
;
11828 struct die_info
*spec_die
;
11830 /* GCJ will output '<init>' for Java constructor names.
11831 For this special case, return the name of the parent class. */
11833 /* GCJ may output suprogram DIEs with AT_specification set.
11834 If so, use the name of the specified DIE. */
11835 spec_die
= die_specification (die
, &spec_cu
);
11836 if (spec_die
!= NULL
)
11837 return dwarf2_name (spec_die
, spec_cu
);
11842 if (die
->tag
== DW_TAG_class_type
)
11843 return dwarf2_name (die
, cu
);
11845 while (die
->tag
!= DW_TAG_compile_unit
);
11849 case DW_TAG_class_type
:
11850 case DW_TAG_interface_type
:
11851 case DW_TAG_structure_type
:
11852 case DW_TAG_union_type
:
11853 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11854 structures or unions. These were of the form "._%d" in GCC 4.1,
11855 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11856 and GCC 4.4. We work around this problem by ignoring these. */
11857 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11858 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11866 if (!DW_STRING_IS_CANONICAL (attr
))
11869 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11870 &cu
->objfile
->objfile_obstack
);
11871 DW_STRING_IS_CANONICAL (attr
) = 1;
11873 return DW_STRING (attr
);
11876 /* Return the die that this die in an extension of, or NULL if there
11877 is none. *EXT_CU is the CU containing DIE on input, and the CU
11878 containing the return value on output. */
11880 static struct die_info
*
11881 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11883 struct attribute
*attr
;
11885 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11889 return follow_die_ref (die
, attr
, ext_cu
);
11892 /* Convert a DIE tag into its string name. */
11895 dwarf_tag_name (unsigned tag
)
11899 case DW_TAG_padding
:
11900 return "DW_TAG_padding";
11901 case DW_TAG_array_type
:
11902 return "DW_TAG_array_type";
11903 case DW_TAG_class_type
:
11904 return "DW_TAG_class_type";
11905 case DW_TAG_entry_point
:
11906 return "DW_TAG_entry_point";
11907 case DW_TAG_enumeration_type
:
11908 return "DW_TAG_enumeration_type";
11909 case DW_TAG_formal_parameter
:
11910 return "DW_TAG_formal_parameter";
11911 case DW_TAG_imported_declaration
:
11912 return "DW_TAG_imported_declaration";
11914 return "DW_TAG_label";
11915 case DW_TAG_lexical_block
:
11916 return "DW_TAG_lexical_block";
11917 case DW_TAG_member
:
11918 return "DW_TAG_member";
11919 case DW_TAG_pointer_type
:
11920 return "DW_TAG_pointer_type";
11921 case DW_TAG_reference_type
:
11922 return "DW_TAG_reference_type";
11923 case DW_TAG_compile_unit
:
11924 return "DW_TAG_compile_unit";
11925 case DW_TAG_string_type
:
11926 return "DW_TAG_string_type";
11927 case DW_TAG_structure_type
:
11928 return "DW_TAG_structure_type";
11929 case DW_TAG_subroutine_type
:
11930 return "DW_TAG_subroutine_type";
11931 case DW_TAG_typedef
:
11932 return "DW_TAG_typedef";
11933 case DW_TAG_union_type
:
11934 return "DW_TAG_union_type";
11935 case DW_TAG_unspecified_parameters
:
11936 return "DW_TAG_unspecified_parameters";
11937 case DW_TAG_variant
:
11938 return "DW_TAG_variant";
11939 case DW_TAG_common_block
:
11940 return "DW_TAG_common_block";
11941 case DW_TAG_common_inclusion
:
11942 return "DW_TAG_common_inclusion";
11943 case DW_TAG_inheritance
:
11944 return "DW_TAG_inheritance";
11945 case DW_TAG_inlined_subroutine
:
11946 return "DW_TAG_inlined_subroutine";
11947 case DW_TAG_module
:
11948 return "DW_TAG_module";
11949 case DW_TAG_ptr_to_member_type
:
11950 return "DW_TAG_ptr_to_member_type";
11951 case DW_TAG_set_type
:
11952 return "DW_TAG_set_type";
11953 case DW_TAG_subrange_type
:
11954 return "DW_TAG_subrange_type";
11955 case DW_TAG_with_stmt
:
11956 return "DW_TAG_with_stmt";
11957 case DW_TAG_access_declaration
:
11958 return "DW_TAG_access_declaration";
11959 case DW_TAG_base_type
:
11960 return "DW_TAG_base_type";
11961 case DW_TAG_catch_block
:
11962 return "DW_TAG_catch_block";
11963 case DW_TAG_const_type
:
11964 return "DW_TAG_const_type";
11965 case DW_TAG_constant
:
11966 return "DW_TAG_constant";
11967 case DW_TAG_enumerator
:
11968 return "DW_TAG_enumerator";
11969 case DW_TAG_file_type
:
11970 return "DW_TAG_file_type";
11971 case DW_TAG_friend
:
11972 return "DW_TAG_friend";
11973 case DW_TAG_namelist
:
11974 return "DW_TAG_namelist";
11975 case DW_TAG_namelist_item
:
11976 return "DW_TAG_namelist_item";
11977 case DW_TAG_packed_type
:
11978 return "DW_TAG_packed_type";
11979 case DW_TAG_subprogram
:
11980 return "DW_TAG_subprogram";
11981 case DW_TAG_template_type_param
:
11982 return "DW_TAG_template_type_param";
11983 case DW_TAG_template_value_param
:
11984 return "DW_TAG_template_value_param";
11985 case DW_TAG_thrown_type
:
11986 return "DW_TAG_thrown_type";
11987 case DW_TAG_try_block
:
11988 return "DW_TAG_try_block";
11989 case DW_TAG_variant_part
:
11990 return "DW_TAG_variant_part";
11991 case DW_TAG_variable
:
11992 return "DW_TAG_variable";
11993 case DW_TAG_volatile_type
:
11994 return "DW_TAG_volatile_type";
11995 case DW_TAG_dwarf_procedure
:
11996 return "DW_TAG_dwarf_procedure";
11997 case DW_TAG_restrict_type
:
11998 return "DW_TAG_restrict_type";
11999 case DW_TAG_interface_type
:
12000 return "DW_TAG_interface_type";
12001 case DW_TAG_namespace
:
12002 return "DW_TAG_namespace";
12003 case DW_TAG_imported_module
:
12004 return "DW_TAG_imported_module";
12005 case DW_TAG_unspecified_type
:
12006 return "DW_TAG_unspecified_type";
12007 case DW_TAG_partial_unit
:
12008 return "DW_TAG_partial_unit";
12009 case DW_TAG_imported_unit
:
12010 return "DW_TAG_imported_unit";
12011 case DW_TAG_condition
:
12012 return "DW_TAG_condition";
12013 case DW_TAG_shared_type
:
12014 return "DW_TAG_shared_type";
12015 case DW_TAG_type_unit
:
12016 return "DW_TAG_type_unit";
12017 case DW_TAG_MIPS_loop
:
12018 return "DW_TAG_MIPS_loop";
12019 case DW_TAG_HP_array_descriptor
:
12020 return "DW_TAG_HP_array_descriptor";
12021 case DW_TAG_format_label
:
12022 return "DW_TAG_format_label";
12023 case DW_TAG_function_template
:
12024 return "DW_TAG_function_template";
12025 case DW_TAG_class_template
:
12026 return "DW_TAG_class_template";
12027 case DW_TAG_GNU_BINCL
:
12028 return "DW_TAG_GNU_BINCL";
12029 case DW_TAG_GNU_EINCL
:
12030 return "DW_TAG_GNU_EINCL";
12031 case DW_TAG_upc_shared_type
:
12032 return "DW_TAG_upc_shared_type";
12033 case DW_TAG_upc_strict_type
:
12034 return "DW_TAG_upc_strict_type";
12035 case DW_TAG_upc_relaxed_type
:
12036 return "DW_TAG_upc_relaxed_type";
12037 case DW_TAG_PGI_kanji_type
:
12038 return "DW_TAG_PGI_kanji_type";
12039 case DW_TAG_PGI_interface_block
:
12040 return "DW_TAG_PGI_interface_block";
12042 return "DW_TAG_<unknown>";
12046 /* Convert a DWARF attribute code into its string name. */
12049 dwarf_attr_name (unsigned attr
)
12053 case DW_AT_sibling
:
12054 return "DW_AT_sibling";
12055 case DW_AT_location
:
12056 return "DW_AT_location";
12058 return "DW_AT_name";
12059 case DW_AT_ordering
:
12060 return "DW_AT_ordering";
12061 case DW_AT_subscr_data
:
12062 return "DW_AT_subscr_data";
12063 case DW_AT_byte_size
:
12064 return "DW_AT_byte_size";
12065 case DW_AT_bit_offset
:
12066 return "DW_AT_bit_offset";
12067 case DW_AT_bit_size
:
12068 return "DW_AT_bit_size";
12069 case DW_AT_element_list
:
12070 return "DW_AT_element_list";
12071 case DW_AT_stmt_list
:
12072 return "DW_AT_stmt_list";
12074 return "DW_AT_low_pc";
12075 case DW_AT_high_pc
:
12076 return "DW_AT_high_pc";
12077 case DW_AT_language
:
12078 return "DW_AT_language";
12080 return "DW_AT_member";
12082 return "DW_AT_discr";
12083 case DW_AT_discr_value
:
12084 return "DW_AT_discr_value";
12085 case DW_AT_visibility
:
12086 return "DW_AT_visibility";
12088 return "DW_AT_import";
12089 case DW_AT_string_length
:
12090 return "DW_AT_string_length";
12091 case DW_AT_common_reference
:
12092 return "DW_AT_common_reference";
12093 case DW_AT_comp_dir
:
12094 return "DW_AT_comp_dir";
12095 case DW_AT_const_value
:
12096 return "DW_AT_const_value";
12097 case DW_AT_containing_type
:
12098 return "DW_AT_containing_type";
12099 case DW_AT_default_value
:
12100 return "DW_AT_default_value";
12102 return "DW_AT_inline";
12103 case DW_AT_is_optional
:
12104 return "DW_AT_is_optional";
12105 case DW_AT_lower_bound
:
12106 return "DW_AT_lower_bound";
12107 case DW_AT_producer
:
12108 return "DW_AT_producer";
12109 case DW_AT_prototyped
:
12110 return "DW_AT_prototyped";
12111 case DW_AT_return_addr
:
12112 return "DW_AT_return_addr";
12113 case DW_AT_start_scope
:
12114 return "DW_AT_start_scope";
12115 case DW_AT_bit_stride
:
12116 return "DW_AT_bit_stride";
12117 case DW_AT_upper_bound
:
12118 return "DW_AT_upper_bound";
12119 case DW_AT_abstract_origin
:
12120 return "DW_AT_abstract_origin";
12121 case DW_AT_accessibility
:
12122 return "DW_AT_accessibility";
12123 case DW_AT_address_class
:
12124 return "DW_AT_address_class";
12125 case DW_AT_artificial
:
12126 return "DW_AT_artificial";
12127 case DW_AT_base_types
:
12128 return "DW_AT_base_types";
12129 case DW_AT_calling_convention
:
12130 return "DW_AT_calling_convention";
12132 return "DW_AT_count";
12133 case DW_AT_data_member_location
:
12134 return "DW_AT_data_member_location";
12135 case DW_AT_decl_column
:
12136 return "DW_AT_decl_column";
12137 case DW_AT_decl_file
:
12138 return "DW_AT_decl_file";
12139 case DW_AT_decl_line
:
12140 return "DW_AT_decl_line";
12141 case DW_AT_declaration
:
12142 return "DW_AT_declaration";
12143 case DW_AT_discr_list
:
12144 return "DW_AT_discr_list";
12145 case DW_AT_encoding
:
12146 return "DW_AT_encoding";
12147 case DW_AT_external
:
12148 return "DW_AT_external";
12149 case DW_AT_frame_base
:
12150 return "DW_AT_frame_base";
12152 return "DW_AT_friend";
12153 case DW_AT_identifier_case
:
12154 return "DW_AT_identifier_case";
12155 case DW_AT_macro_info
:
12156 return "DW_AT_macro_info";
12157 case DW_AT_namelist_items
:
12158 return "DW_AT_namelist_items";
12159 case DW_AT_priority
:
12160 return "DW_AT_priority";
12161 case DW_AT_segment
:
12162 return "DW_AT_segment";
12163 case DW_AT_specification
:
12164 return "DW_AT_specification";
12165 case DW_AT_static_link
:
12166 return "DW_AT_static_link";
12168 return "DW_AT_type";
12169 case DW_AT_use_location
:
12170 return "DW_AT_use_location";
12171 case DW_AT_variable_parameter
:
12172 return "DW_AT_variable_parameter";
12173 case DW_AT_virtuality
:
12174 return "DW_AT_virtuality";
12175 case DW_AT_vtable_elem_location
:
12176 return "DW_AT_vtable_elem_location";
12177 /* DWARF 3 values. */
12178 case DW_AT_allocated
:
12179 return "DW_AT_allocated";
12180 case DW_AT_associated
:
12181 return "DW_AT_associated";
12182 case DW_AT_data_location
:
12183 return "DW_AT_data_location";
12184 case DW_AT_byte_stride
:
12185 return "DW_AT_byte_stride";
12186 case DW_AT_entry_pc
:
12187 return "DW_AT_entry_pc";
12188 case DW_AT_use_UTF8
:
12189 return "DW_AT_use_UTF8";
12190 case DW_AT_extension
:
12191 return "DW_AT_extension";
12193 return "DW_AT_ranges";
12194 case DW_AT_trampoline
:
12195 return "DW_AT_trampoline";
12196 case DW_AT_call_column
:
12197 return "DW_AT_call_column";
12198 case DW_AT_call_file
:
12199 return "DW_AT_call_file";
12200 case DW_AT_call_line
:
12201 return "DW_AT_call_line";
12202 case DW_AT_description
:
12203 return "DW_AT_description";
12204 case DW_AT_binary_scale
:
12205 return "DW_AT_binary_scale";
12206 case DW_AT_decimal_scale
:
12207 return "DW_AT_decimal_scale";
12209 return "DW_AT_small";
12210 case DW_AT_decimal_sign
:
12211 return "DW_AT_decimal_sign";
12212 case DW_AT_digit_count
:
12213 return "DW_AT_digit_count";
12214 case DW_AT_picture_string
:
12215 return "DW_AT_picture_string";
12216 case DW_AT_mutable
:
12217 return "DW_AT_mutable";
12218 case DW_AT_threads_scaled
:
12219 return "DW_AT_threads_scaled";
12220 case DW_AT_explicit
:
12221 return "DW_AT_explicit";
12222 case DW_AT_object_pointer
:
12223 return "DW_AT_object_pointer";
12224 case DW_AT_endianity
:
12225 return "DW_AT_endianity";
12226 case DW_AT_elemental
:
12227 return "DW_AT_elemental";
12229 return "DW_AT_pure";
12230 case DW_AT_recursive
:
12231 return "DW_AT_recursive";
12232 /* DWARF 4 values. */
12233 case DW_AT_signature
:
12234 return "DW_AT_signature";
12235 case DW_AT_linkage_name
:
12236 return "DW_AT_linkage_name";
12237 /* SGI/MIPS extensions. */
12238 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12239 case DW_AT_MIPS_fde
:
12240 return "DW_AT_MIPS_fde";
12242 case DW_AT_MIPS_loop_begin
:
12243 return "DW_AT_MIPS_loop_begin";
12244 case DW_AT_MIPS_tail_loop_begin
:
12245 return "DW_AT_MIPS_tail_loop_begin";
12246 case DW_AT_MIPS_epilog_begin
:
12247 return "DW_AT_MIPS_epilog_begin";
12248 case DW_AT_MIPS_loop_unroll_factor
:
12249 return "DW_AT_MIPS_loop_unroll_factor";
12250 case DW_AT_MIPS_software_pipeline_depth
:
12251 return "DW_AT_MIPS_software_pipeline_depth";
12252 case DW_AT_MIPS_linkage_name
:
12253 return "DW_AT_MIPS_linkage_name";
12254 case DW_AT_MIPS_stride
:
12255 return "DW_AT_MIPS_stride";
12256 case DW_AT_MIPS_abstract_name
:
12257 return "DW_AT_MIPS_abstract_name";
12258 case DW_AT_MIPS_clone_origin
:
12259 return "DW_AT_MIPS_clone_origin";
12260 case DW_AT_MIPS_has_inlines
:
12261 return "DW_AT_MIPS_has_inlines";
12262 /* HP extensions. */
12263 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12264 case DW_AT_HP_block_index
:
12265 return "DW_AT_HP_block_index";
12267 case DW_AT_HP_unmodifiable
:
12268 return "DW_AT_HP_unmodifiable";
12269 case DW_AT_HP_actuals_stmt_list
:
12270 return "DW_AT_HP_actuals_stmt_list";
12271 case DW_AT_HP_proc_per_section
:
12272 return "DW_AT_HP_proc_per_section";
12273 case DW_AT_HP_raw_data_ptr
:
12274 return "DW_AT_HP_raw_data_ptr";
12275 case DW_AT_HP_pass_by_reference
:
12276 return "DW_AT_HP_pass_by_reference";
12277 case DW_AT_HP_opt_level
:
12278 return "DW_AT_HP_opt_level";
12279 case DW_AT_HP_prof_version_id
:
12280 return "DW_AT_HP_prof_version_id";
12281 case DW_AT_HP_opt_flags
:
12282 return "DW_AT_HP_opt_flags";
12283 case DW_AT_HP_cold_region_low_pc
:
12284 return "DW_AT_HP_cold_region_low_pc";
12285 case DW_AT_HP_cold_region_high_pc
:
12286 return "DW_AT_HP_cold_region_high_pc";
12287 case DW_AT_HP_all_variables_modifiable
:
12288 return "DW_AT_HP_all_variables_modifiable";
12289 case DW_AT_HP_linkage_name
:
12290 return "DW_AT_HP_linkage_name";
12291 case DW_AT_HP_prof_flags
:
12292 return "DW_AT_HP_prof_flags";
12293 /* GNU extensions. */
12294 case DW_AT_sf_names
:
12295 return "DW_AT_sf_names";
12296 case DW_AT_src_info
:
12297 return "DW_AT_src_info";
12298 case DW_AT_mac_info
:
12299 return "DW_AT_mac_info";
12300 case DW_AT_src_coords
:
12301 return "DW_AT_src_coords";
12302 case DW_AT_body_begin
:
12303 return "DW_AT_body_begin";
12304 case DW_AT_body_end
:
12305 return "DW_AT_body_end";
12306 case DW_AT_GNU_vector
:
12307 return "DW_AT_GNU_vector";
12308 case DW_AT_GNU_odr_signature
:
12309 return "DW_AT_GNU_odr_signature";
12310 /* VMS extensions. */
12311 case DW_AT_VMS_rtnbeg_pd_address
:
12312 return "DW_AT_VMS_rtnbeg_pd_address";
12313 /* UPC extension. */
12314 case DW_AT_upc_threads_scaled
:
12315 return "DW_AT_upc_threads_scaled";
12316 /* PGI (STMicroelectronics) extensions. */
12317 case DW_AT_PGI_lbase
:
12318 return "DW_AT_PGI_lbase";
12319 case DW_AT_PGI_soffset
:
12320 return "DW_AT_PGI_soffset";
12321 case DW_AT_PGI_lstride
:
12322 return "DW_AT_PGI_lstride";
12324 return "DW_AT_<unknown>";
12328 /* Convert a DWARF value form code into its string name. */
12331 dwarf_form_name (unsigned form
)
12336 return "DW_FORM_addr";
12337 case DW_FORM_block2
:
12338 return "DW_FORM_block2";
12339 case DW_FORM_block4
:
12340 return "DW_FORM_block4";
12341 case DW_FORM_data2
:
12342 return "DW_FORM_data2";
12343 case DW_FORM_data4
:
12344 return "DW_FORM_data4";
12345 case DW_FORM_data8
:
12346 return "DW_FORM_data8";
12347 case DW_FORM_string
:
12348 return "DW_FORM_string";
12349 case DW_FORM_block
:
12350 return "DW_FORM_block";
12351 case DW_FORM_block1
:
12352 return "DW_FORM_block1";
12353 case DW_FORM_data1
:
12354 return "DW_FORM_data1";
12356 return "DW_FORM_flag";
12357 case DW_FORM_sdata
:
12358 return "DW_FORM_sdata";
12360 return "DW_FORM_strp";
12361 case DW_FORM_udata
:
12362 return "DW_FORM_udata";
12363 case DW_FORM_ref_addr
:
12364 return "DW_FORM_ref_addr";
12366 return "DW_FORM_ref1";
12368 return "DW_FORM_ref2";
12370 return "DW_FORM_ref4";
12372 return "DW_FORM_ref8";
12373 case DW_FORM_ref_udata
:
12374 return "DW_FORM_ref_udata";
12375 case DW_FORM_indirect
:
12376 return "DW_FORM_indirect";
12377 case DW_FORM_sec_offset
:
12378 return "DW_FORM_sec_offset";
12379 case DW_FORM_exprloc
:
12380 return "DW_FORM_exprloc";
12381 case DW_FORM_flag_present
:
12382 return "DW_FORM_flag_present";
12384 return "DW_FORM_sig8";
12386 return "DW_FORM_<unknown>";
12390 /* Convert a DWARF stack opcode into its string name. */
12393 dwarf_stack_op_name (unsigned op
, int def
)
12398 return "DW_OP_addr";
12400 return "DW_OP_deref";
12401 case DW_OP_const1u
:
12402 return "DW_OP_const1u";
12403 case DW_OP_const1s
:
12404 return "DW_OP_const1s";
12405 case DW_OP_const2u
:
12406 return "DW_OP_const2u";
12407 case DW_OP_const2s
:
12408 return "DW_OP_const2s";
12409 case DW_OP_const4u
:
12410 return "DW_OP_const4u";
12411 case DW_OP_const4s
:
12412 return "DW_OP_const4s";
12413 case DW_OP_const8u
:
12414 return "DW_OP_const8u";
12415 case DW_OP_const8s
:
12416 return "DW_OP_const8s";
12418 return "DW_OP_constu";
12420 return "DW_OP_consts";
12422 return "DW_OP_dup";
12424 return "DW_OP_drop";
12426 return "DW_OP_over";
12428 return "DW_OP_pick";
12430 return "DW_OP_swap";
12432 return "DW_OP_rot";
12434 return "DW_OP_xderef";
12436 return "DW_OP_abs";
12438 return "DW_OP_and";
12440 return "DW_OP_div";
12442 return "DW_OP_minus";
12444 return "DW_OP_mod";
12446 return "DW_OP_mul";
12448 return "DW_OP_neg";
12450 return "DW_OP_not";
12454 return "DW_OP_plus";
12455 case DW_OP_plus_uconst
:
12456 return "DW_OP_plus_uconst";
12458 return "DW_OP_shl";
12460 return "DW_OP_shr";
12462 return "DW_OP_shra";
12464 return "DW_OP_xor";
12466 return "DW_OP_bra";
12480 return "DW_OP_skip";
12482 return "DW_OP_lit0";
12484 return "DW_OP_lit1";
12486 return "DW_OP_lit2";
12488 return "DW_OP_lit3";
12490 return "DW_OP_lit4";
12492 return "DW_OP_lit5";
12494 return "DW_OP_lit6";
12496 return "DW_OP_lit7";
12498 return "DW_OP_lit8";
12500 return "DW_OP_lit9";
12502 return "DW_OP_lit10";
12504 return "DW_OP_lit11";
12506 return "DW_OP_lit12";
12508 return "DW_OP_lit13";
12510 return "DW_OP_lit14";
12512 return "DW_OP_lit15";
12514 return "DW_OP_lit16";
12516 return "DW_OP_lit17";
12518 return "DW_OP_lit18";
12520 return "DW_OP_lit19";
12522 return "DW_OP_lit20";
12524 return "DW_OP_lit21";
12526 return "DW_OP_lit22";
12528 return "DW_OP_lit23";
12530 return "DW_OP_lit24";
12532 return "DW_OP_lit25";
12534 return "DW_OP_lit26";
12536 return "DW_OP_lit27";
12538 return "DW_OP_lit28";
12540 return "DW_OP_lit29";
12542 return "DW_OP_lit30";
12544 return "DW_OP_lit31";
12546 return "DW_OP_reg0";
12548 return "DW_OP_reg1";
12550 return "DW_OP_reg2";
12552 return "DW_OP_reg3";
12554 return "DW_OP_reg4";
12556 return "DW_OP_reg5";
12558 return "DW_OP_reg6";
12560 return "DW_OP_reg7";
12562 return "DW_OP_reg8";
12564 return "DW_OP_reg9";
12566 return "DW_OP_reg10";
12568 return "DW_OP_reg11";
12570 return "DW_OP_reg12";
12572 return "DW_OP_reg13";
12574 return "DW_OP_reg14";
12576 return "DW_OP_reg15";
12578 return "DW_OP_reg16";
12580 return "DW_OP_reg17";
12582 return "DW_OP_reg18";
12584 return "DW_OP_reg19";
12586 return "DW_OP_reg20";
12588 return "DW_OP_reg21";
12590 return "DW_OP_reg22";
12592 return "DW_OP_reg23";
12594 return "DW_OP_reg24";
12596 return "DW_OP_reg25";
12598 return "DW_OP_reg26";
12600 return "DW_OP_reg27";
12602 return "DW_OP_reg28";
12604 return "DW_OP_reg29";
12606 return "DW_OP_reg30";
12608 return "DW_OP_reg31";
12610 return "DW_OP_breg0";
12612 return "DW_OP_breg1";
12614 return "DW_OP_breg2";
12616 return "DW_OP_breg3";
12618 return "DW_OP_breg4";
12620 return "DW_OP_breg5";
12622 return "DW_OP_breg6";
12624 return "DW_OP_breg7";
12626 return "DW_OP_breg8";
12628 return "DW_OP_breg9";
12630 return "DW_OP_breg10";
12632 return "DW_OP_breg11";
12634 return "DW_OP_breg12";
12636 return "DW_OP_breg13";
12638 return "DW_OP_breg14";
12640 return "DW_OP_breg15";
12642 return "DW_OP_breg16";
12644 return "DW_OP_breg17";
12646 return "DW_OP_breg18";
12648 return "DW_OP_breg19";
12650 return "DW_OP_breg20";
12652 return "DW_OP_breg21";
12654 return "DW_OP_breg22";
12656 return "DW_OP_breg23";
12658 return "DW_OP_breg24";
12660 return "DW_OP_breg25";
12662 return "DW_OP_breg26";
12664 return "DW_OP_breg27";
12666 return "DW_OP_breg28";
12668 return "DW_OP_breg29";
12670 return "DW_OP_breg30";
12672 return "DW_OP_breg31";
12674 return "DW_OP_regx";
12676 return "DW_OP_fbreg";
12678 return "DW_OP_bregx";
12680 return "DW_OP_piece";
12681 case DW_OP_deref_size
:
12682 return "DW_OP_deref_size";
12683 case DW_OP_xderef_size
:
12684 return "DW_OP_xderef_size";
12686 return "DW_OP_nop";
12687 /* DWARF 3 extensions. */
12688 case DW_OP_push_object_address
:
12689 return "DW_OP_push_object_address";
12691 return "DW_OP_call2";
12693 return "DW_OP_call4";
12694 case DW_OP_call_ref
:
12695 return "DW_OP_call_ref";
12696 case DW_OP_form_tls_address
:
12697 return "DW_OP_form_tls_address";
12698 case DW_OP_call_frame_cfa
:
12699 return "DW_OP_call_frame_cfa";
12700 case DW_OP_bit_piece
:
12701 return "DW_OP_bit_piece";
12702 /* DWARF 4 extensions. */
12703 case DW_OP_implicit_value
:
12704 return "DW_OP_implicit_value";
12705 case DW_OP_stack_value
:
12706 return "DW_OP_stack_value";
12707 /* GNU extensions. */
12708 case DW_OP_GNU_push_tls_address
:
12709 return "DW_OP_GNU_push_tls_address";
12710 case DW_OP_GNU_uninit
:
12711 return "DW_OP_GNU_uninit";
12712 case DW_OP_GNU_implicit_pointer
:
12713 return "DW_OP_GNU_implicit_pointer";
12715 return def
? "OP_<unknown>" : NULL
;
12720 dwarf_bool_name (unsigned mybool
)
12728 /* Convert a DWARF type code into its string name. */
12731 dwarf_type_encoding_name (unsigned enc
)
12736 return "DW_ATE_void";
12737 case DW_ATE_address
:
12738 return "DW_ATE_address";
12739 case DW_ATE_boolean
:
12740 return "DW_ATE_boolean";
12741 case DW_ATE_complex_float
:
12742 return "DW_ATE_complex_float";
12744 return "DW_ATE_float";
12745 case DW_ATE_signed
:
12746 return "DW_ATE_signed";
12747 case DW_ATE_signed_char
:
12748 return "DW_ATE_signed_char";
12749 case DW_ATE_unsigned
:
12750 return "DW_ATE_unsigned";
12751 case DW_ATE_unsigned_char
:
12752 return "DW_ATE_unsigned_char";
12754 case DW_ATE_imaginary_float
:
12755 return "DW_ATE_imaginary_float";
12756 case DW_ATE_packed_decimal
:
12757 return "DW_ATE_packed_decimal";
12758 case DW_ATE_numeric_string
:
12759 return "DW_ATE_numeric_string";
12760 case DW_ATE_edited
:
12761 return "DW_ATE_edited";
12762 case DW_ATE_signed_fixed
:
12763 return "DW_ATE_signed_fixed";
12764 case DW_ATE_unsigned_fixed
:
12765 return "DW_ATE_unsigned_fixed";
12766 case DW_ATE_decimal_float
:
12767 return "DW_ATE_decimal_float";
12770 return "DW_ATE_UTF";
12771 /* HP extensions. */
12772 case DW_ATE_HP_float80
:
12773 return "DW_ATE_HP_float80";
12774 case DW_ATE_HP_complex_float80
:
12775 return "DW_ATE_HP_complex_float80";
12776 case DW_ATE_HP_float128
:
12777 return "DW_ATE_HP_float128";
12778 case DW_ATE_HP_complex_float128
:
12779 return "DW_ATE_HP_complex_float128";
12780 case DW_ATE_HP_floathpintel
:
12781 return "DW_ATE_HP_floathpintel";
12782 case DW_ATE_HP_imaginary_float80
:
12783 return "DW_ATE_HP_imaginary_float80";
12784 case DW_ATE_HP_imaginary_float128
:
12785 return "DW_ATE_HP_imaginary_float128";
12787 return "DW_ATE_<unknown>";
12791 /* Convert a DWARF call frame info operation to its string name. */
12795 dwarf_cfi_name (unsigned cfi_opc
)
12799 case DW_CFA_advance_loc
:
12800 return "DW_CFA_advance_loc";
12801 case DW_CFA_offset
:
12802 return "DW_CFA_offset";
12803 case DW_CFA_restore
:
12804 return "DW_CFA_restore";
12806 return "DW_CFA_nop";
12807 case DW_CFA_set_loc
:
12808 return "DW_CFA_set_loc";
12809 case DW_CFA_advance_loc1
:
12810 return "DW_CFA_advance_loc1";
12811 case DW_CFA_advance_loc2
:
12812 return "DW_CFA_advance_loc2";
12813 case DW_CFA_advance_loc4
:
12814 return "DW_CFA_advance_loc4";
12815 case DW_CFA_offset_extended
:
12816 return "DW_CFA_offset_extended";
12817 case DW_CFA_restore_extended
:
12818 return "DW_CFA_restore_extended";
12819 case DW_CFA_undefined
:
12820 return "DW_CFA_undefined";
12821 case DW_CFA_same_value
:
12822 return "DW_CFA_same_value";
12823 case DW_CFA_register
:
12824 return "DW_CFA_register";
12825 case DW_CFA_remember_state
:
12826 return "DW_CFA_remember_state";
12827 case DW_CFA_restore_state
:
12828 return "DW_CFA_restore_state";
12829 case DW_CFA_def_cfa
:
12830 return "DW_CFA_def_cfa";
12831 case DW_CFA_def_cfa_register
:
12832 return "DW_CFA_def_cfa_register";
12833 case DW_CFA_def_cfa_offset
:
12834 return "DW_CFA_def_cfa_offset";
12836 case DW_CFA_def_cfa_expression
:
12837 return "DW_CFA_def_cfa_expression";
12838 case DW_CFA_expression
:
12839 return "DW_CFA_expression";
12840 case DW_CFA_offset_extended_sf
:
12841 return "DW_CFA_offset_extended_sf";
12842 case DW_CFA_def_cfa_sf
:
12843 return "DW_CFA_def_cfa_sf";
12844 case DW_CFA_def_cfa_offset_sf
:
12845 return "DW_CFA_def_cfa_offset_sf";
12846 case DW_CFA_val_offset
:
12847 return "DW_CFA_val_offset";
12848 case DW_CFA_val_offset_sf
:
12849 return "DW_CFA_val_offset_sf";
12850 case DW_CFA_val_expression
:
12851 return "DW_CFA_val_expression";
12852 /* SGI/MIPS specific. */
12853 case DW_CFA_MIPS_advance_loc8
:
12854 return "DW_CFA_MIPS_advance_loc8";
12855 /* GNU extensions. */
12856 case DW_CFA_GNU_window_save
:
12857 return "DW_CFA_GNU_window_save";
12858 case DW_CFA_GNU_args_size
:
12859 return "DW_CFA_GNU_args_size";
12860 case DW_CFA_GNU_negative_offset_extended
:
12861 return "DW_CFA_GNU_negative_offset_extended";
12863 return "DW_CFA_<unknown>";
12869 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12873 print_spaces (indent
, f
);
12874 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12875 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12877 if (die
->parent
!= NULL
)
12879 print_spaces (indent
, f
);
12880 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12881 die
->parent
->offset
);
12884 print_spaces (indent
, f
);
12885 fprintf_unfiltered (f
, " has children: %s\n",
12886 dwarf_bool_name (die
->child
!= NULL
));
12888 print_spaces (indent
, f
);
12889 fprintf_unfiltered (f
, " attributes:\n");
12891 for (i
= 0; i
< die
->num_attrs
; ++i
)
12893 print_spaces (indent
, f
);
12894 fprintf_unfiltered (f
, " %s (%s) ",
12895 dwarf_attr_name (die
->attrs
[i
].name
),
12896 dwarf_form_name (die
->attrs
[i
].form
));
12898 switch (die
->attrs
[i
].form
)
12900 case DW_FORM_ref_addr
:
12902 fprintf_unfiltered (f
, "address: ");
12903 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12905 case DW_FORM_block2
:
12906 case DW_FORM_block4
:
12907 case DW_FORM_block
:
12908 case DW_FORM_block1
:
12909 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12911 case DW_FORM_exprloc
:
12912 fprintf_unfiltered (f
, "expression: size %u",
12913 DW_BLOCK (&die
->attrs
[i
])->size
);
12918 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12919 (long) (DW_ADDR (&die
->attrs
[i
])));
12921 case DW_FORM_data1
:
12922 case DW_FORM_data2
:
12923 case DW_FORM_data4
:
12924 case DW_FORM_data8
:
12925 case DW_FORM_udata
:
12926 case DW_FORM_sdata
:
12927 fprintf_unfiltered (f
, "constant: %s",
12928 pulongest (DW_UNSND (&die
->attrs
[i
])));
12930 case DW_FORM_sec_offset
:
12931 fprintf_unfiltered (f
, "section offset: %s",
12932 pulongest (DW_UNSND (&die
->attrs
[i
])));
12935 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12936 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12937 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12939 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12941 case DW_FORM_string
:
12943 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12944 DW_STRING (&die
->attrs
[i
])
12945 ? DW_STRING (&die
->attrs
[i
]) : "",
12946 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12949 if (DW_UNSND (&die
->attrs
[i
]))
12950 fprintf_unfiltered (f
, "flag: TRUE");
12952 fprintf_unfiltered (f
, "flag: FALSE");
12954 case DW_FORM_flag_present
:
12955 fprintf_unfiltered (f
, "flag: TRUE");
12957 case DW_FORM_indirect
:
12958 /* the reader will have reduced the indirect form to
12959 the "base form" so this form should not occur */
12960 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12963 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12964 die
->attrs
[i
].form
);
12967 fprintf_unfiltered (f
, "\n");
12972 dump_die_for_error (struct die_info
*die
)
12974 dump_die_shallow (gdb_stderr
, 0, die
);
12978 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12980 int indent
= level
* 4;
12982 gdb_assert (die
!= NULL
);
12984 if (level
>= max_level
)
12987 dump_die_shallow (f
, indent
, die
);
12989 if (die
->child
!= NULL
)
12991 print_spaces (indent
, f
);
12992 fprintf_unfiltered (f
, " Children:");
12993 if (level
+ 1 < max_level
)
12995 fprintf_unfiltered (f
, "\n");
12996 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13000 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
13004 if (die
->sibling
!= NULL
&& level
> 0)
13006 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13010 /* This is called from the pdie macro in gdbinit.in.
13011 It's not static so gcc will keep a copy callable from gdb. */
13014 dump_die (struct die_info
*die
, int max_level
)
13016 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13020 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13024 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13030 is_ref_attr (struct attribute
*attr
)
13032 switch (attr
->form
)
13034 case DW_FORM_ref_addr
:
13039 case DW_FORM_ref_udata
:
13046 static unsigned int
13047 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13049 if (is_ref_attr (attr
))
13050 return DW_ADDR (attr
);
13052 complaint (&symfile_complaints
,
13053 _("unsupported die ref attribute form: '%s'"),
13054 dwarf_form_name (attr
->form
));
13058 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13059 * the value held by the attribute is not constant. */
13062 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13064 if (attr
->form
== DW_FORM_sdata
)
13065 return DW_SND (attr
);
13066 else if (attr
->form
== DW_FORM_udata
13067 || attr
->form
== DW_FORM_data1
13068 || attr
->form
== DW_FORM_data2
13069 || attr
->form
== DW_FORM_data4
13070 || attr
->form
== DW_FORM_data8
)
13071 return DW_UNSND (attr
);
13074 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
13075 dwarf_form_name (attr
->form
));
13076 return default_value
;
13080 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13081 unit and add it to our queue.
13082 The result is non-zero if PER_CU was queued, otherwise the result is zero
13083 meaning either PER_CU is already queued or it is already loaded. */
13086 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13087 struct dwarf2_per_cu_data
*per_cu
)
13089 /* We may arrive here during partial symbol reading, if we need full
13090 DIEs to process an unusual case (e.g. template arguments). Do
13091 not queue PER_CU, just tell our caller to load its DIEs. */
13092 if (dwarf2_per_objfile
->reading_partial_symbols
)
13094 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13099 /* Mark the dependence relation so that we don't flush PER_CU
13101 dwarf2_add_dependence (this_cu
, per_cu
);
13103 /* If it's already on the queue, we have nothing to do. */
13104 if (per_cu
->queued
)
13107 /* If the compilation unit is already loaded, just mark it as
13109 if (per_cu
->cu
!= NULL
)
13111 per_cu
->cu
->last_used
= 0;
13115 /* Add it to the queue. */
13116 queue_comp_unit (per_cu
, this_cu
->objfile
);
13121 /* Follow reference or signature attribute ATTR of SRC_DIE.
13122 On entry *REF_CU is the CU of SRC_DIE.
13123 On exit *REF_CU is the CU of the result. */
13125 static struct die_info
*
13126 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13127 struct dwarf2_cu
**ref_cu
)
13129 struct die_info
*die
;
13131 if (is_ref_attr (attr
))
13132 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13133 else if (attr
->form
== DW_FORM_sig8
)
13134 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13137 dump_die_for_error (src_die
);
13138 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13139 (*ref_cu
)->objfile
->name
);
13145 /* Follow reference OFFSET.
13146 On entry *REF_CU is the CU of the source die referencing OFFSET.
13147 On exit *REF_CU is the CU of the result.
13148 Returns NULL if OFFSET is invalid. */
13150 static struct die_info
*
13151 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13153 struct die_info temp_die
;
13154 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13156 gdb_assert (cu
->per_cu
!= NULL
);
13160 if (cu
->per_cu
->from_debug_types
)
13162 /* .debug_types CUs cannot reference anything outside their CU.
13163 If they need to, they have to reference a signatured type via
13165 if (! offset_in_cu_p (&cu
->header
, offset
))
13168 else if (! offset_in_cu_p (&cu
->header
, offset
))
13170 struct dwarf2_per_cu_data
*per_cu
;
13172 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13174 /* If necessary, add it to the queue and load its DIEs. */
13175 if (maybe_queue_comp_unit (cu
, per_cu
))
13176 load_full_comp_unit (per_cu
, cu
->objfile
);
13178 target_cu
= per_cu
->cu
;
13180 else if (cu
->dies
== NULL
)
13182 /* We're loading full DIEs during partial symbol reading. */
13183 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13184 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13187 *ref_cu
= target_cu
;
13188 temp_die
.offset
= offset
;
13189 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13192 /* Follow reference attribute ATTR of SRC_DIE.
13193 On entry *REF_CU is the CU of SRC_DIE.
13194 On exit *REF_CU is the CU of the result. */
13196 static struct die_info
*
13197 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13198 struct dwarf2_cu
**ref_cu
)
13200 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13201 struct dwarf2_cu
*cu
= *ref_cu
;
13202 struct die_info
*die
;
13204 die
= follow_die_offset (offset
, ref_cu
);
13206 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13207 "at 0x%x [in module %s]"),
13208 offset
, src_die
->offset
, cu
->objfile
->name
);
13213 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13214 value is intended for DW_OP_call*. */
13216 struct dwarf2_locexpr_baton
13217 dwarf2_fetch_die_location_block (unsigned int offset
,
13218 struct dwarf2_per_cu_data
*per_cu
,
13219 CORE_ADDR (*get_frame_pc
) (void *baton
),
13222 struct dwarf2_cu
*cu
= per_cu
->cu
;
13223 struct die_info
*die
;
13224 struct attribute
*attr
;
13225 struct dwarf2_locexpr_baton retval
;
13227 dw2_setup (per_cu
->objfile
);
13229 die
= follow_die_offset (offset
, &cu
);
13231 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13232 offset
, per_cu
->cu
->objfile
->name
);
13234 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13237 /* DWARF: "If there is no such attribute, then there is no effect.". */
13239 retval
.data
= NULL
;
13242 else if (attr_form_is_section_offset (attr
))
13244 struct dwarf2_loclist_baton loclist_baton
;
13245 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13248 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13250 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13252 retval
.size
= size
;
13256 if (!attr_form_is_block (attr
))
13257 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13258 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13259 offset
, per_cu
->cu
->objfile
->name
);
13261 retval
.data
= DW_BLOCK (attr
)->data
;
13262 retval
.size
= DW_BLOCK (attr
)->size
;
13264 retval
.per_cu
= cu
->per_cu
;
13268 /* Follow the signature attribute ATTR in SRC_DIE.
13269 On entry *REF_CU is the CU of SRC_DIE.
13270 On exit *REF_CU is the CU of the result. */
13272 static struct die_info
*
13273 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13274 struct dwarf2_cu
**ref_cu
)
13276 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13277 struct die_info temp_die
;
13278 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13279 struct dwarf2_cu
*sig_cu
;
13280 struct die_info
*die
;
13282 /* sig_type will be NULL if the signatured type is missing from
13284 if (sig_type
== NULL
)
13285 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13286 "at 0x%x [in module %s]"),
13287 src_die
->offset
, objfile
->name
);
13289 /* If necessary, add it to the queue and load its DIEs. */
13291 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13292 read_signatured_type (objfile
, sig_type
);
13294 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13296 sig_cu
= sig_type
->per_cu
.cu
;
13297 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13298 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13305 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
13306 "at 0x%x [in module %s]"),
13307 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13310 /* Given an offset of a signatured type, return its signatured_type. */
13312 static struct signatured_type
*
13313 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13315 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13316 unsigned int length
, initial_length_size
;
13317 unsigned int sig_offset
;
13318 struct signatured_type find_entry
, *type_sig
;
13320 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13321 sig_offset
= (initial_length_size
13323 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13324 + 1 /*address_size*/);
13325 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13326 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13328 /* This is only used to lookup previously recorded types.
13329 If we didn't find it, it's our bug. */
13330 gdb_assert (type_sig
!= NULL
);
13331 gdb_assert (offset
== type_sig
->offset
);
13336 /* Read in signatured type at OFFSET and build its CU and die(s). */
13339 read_signatured_type_at_offset (struct objfile
*objfile
,
13340 unsigned int offset
)
13342 struct signatured_type
*type_sig
;
13344 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13346 /* We have the section offset, but we need the signature to do the
13347 hash table lookup. */
13348 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13350 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13352 read_signatured_type (objfile
, type_sig
);
13354 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13357 /* Read in a signatured type and build its CU and DIEs. */
13360 read_signatured_type (struct objfile
*objfile
,
13361 struct signatured_type
*type_sig
)
13363 gdb_byte
*types_ptr
;
13364 struct die_reader_specs reader_specs
;
13365 struct dwarf2_cu
*cu
;
13366 ULONGEST signature
;
13367 struct cleanup
*back_to
, *free_cu_cleanup
;
13369 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13370 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13372 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13374 cu
= xmalloc (sizeof (*cu
));
13375 init_one_comp_unit (cu
, objfile
);
13377 type_sig
->per_cu
.cu
= cu
;
13378 cu
->per_cu
= &type_sig
->per_cu
;
13380 /* If an error occurs while loading, release our storage. */
13381 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13383 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13384 types_ptr
, objfile
->obfd
);
13385 gdb_assert (signature
== type_sig
->signature
);
13388 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13392 &cu
->comp_unit_obstack
,
13393 hashtab_obstack_allocate
,
13394 dummy_obstack_deallocate
);
13396 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13397 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13399 init_cu_die_reader (&reader_specs
, cu
);
13401 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13404 /* We try not to read any attributes in this function, because not
13405 all objfiles needed for references have been loaded yet, and symbol
13406 table processing isn't initialized. But we have to set the CU language,
13407 or we won't be able to build types correctly. */
13408 prepare_one_comp_unit (cu
, cu
->dies
);
13410 do_cleanups (back_to
);
13412 /* We've successfully allocated this compilation unit. Let our caller
13413 clean it up when finished with it. */
13414 discard_cleanups (free_cu_cleanup
);
13416 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13417 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13420 /* Decode simple location descriptions.
13421 Given a pointer to a dwarf block that defines a location, compute
13422 the location and return the value.
13424 NOTE drow/2003-11-18: This function is called in two situations
13425 now: for the address of static or global variables (partial symbols
13426 only) and for offsets into structures which are expected to be
13427 (more or less) constant. The partial symbol case should go away,
13428 and only the constant case should remain. That will let this
13429 function complain more accurately. A few special modes are allowed
13430 without complaint for global variables (for instance, global
13431 register values and thread-local values).
13433 A location description containing no operations indicates that the
13434 object is optimized out. The return value is 0 for that case.
13435 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13436 callers will only want a very basic result and this can become a
13439 Note that stack[0] is unused except as a default error return. */
13442 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13444 struct objfile
*objfile
= cu
->objfile
;
13446 int size
= blk
->size
;
13447 gdb_byte
*data
= blk
->data
;
13448 CORE_ADDR stack
[64];
13450 unsigned int bytes_read
, unsnd
;
13456 stack
[++stacki
] = 0;
13495 stack
[++stacki
] = op
- DW_OP_lit0
;
13530 stack
[++stacki
] = op
- DW_OP_reg0
;
13532 dwarf2_complex_location_expr_complaint ();
13536 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13538 stack
[++stacki
] = unsnd
;
13540 dwarf2_complex_location_expr_complaint ();
13544 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13549 case DW_OP_const1u
:
13550 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13554 case DW_OP_const1s
:
13555 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13559 case DW_OP_const2u
:
13560 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13564 case DW_OP_const2s
:
13565 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13569 case DW_OP_const4u
:
13570 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13574 case DW_OP_const4s
:
13575 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13580 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13586 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13591 stack
[stacki
+ 1] = stack
[stacki
];
13596 stack
[stacki
- 1] += stack
[stacki
];
13600 case DW_OP_plus_uconst
:
13601 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13606 stack
[stacki
- 1] -= stack
[stacki
];
13611 /* If we're not the last op, then we definitely can't encode
13612 this using GDB's address_class enum. This is valid for partial
13613 global symbols, although the variable's address will be bogus
13616 dwarf2_complex_location_expr_complaint ();
13619 case DW_OP_GNU_push_tls_address
:
13620 /* The top of the stack has the offset from the beginning
13621 of the thread control block at which the variable is located. */
13622 /* Nothing should follow this operator, so the top of stack would
13624 /* This is valid for partial global symbols, but the variable's
13625 address will be bogus in the psymtab. */
13627 dwarf2_complex_location_expr_complaint ();
13630 case DW_OP_GNU_uninit
:
13634 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13635 dwarf_stack_op_name (op
, 1));
13636 return (stack
[stacki
]);
13639 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13640 outside of the allocated space. Also enforce minimum>0. */
13641 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13643 complaint (&symfile_complaints
,
13644 _("location description stack overflow"));
13650 complaint (&symfile_complaints
,
13651 _("location description stack underflow"));
13655 return (stack
[stacki
]);
13658 /* memory allocation interface */
13660 static struct dwarf_block
*
13661 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13663 struct dwarf_block
*blk
;
13665 blk
= (struct dwarf_block
*)
13666 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13670 static struct abbrev_info
*
13671 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13673 struct abbrev_info
*abbrev
;
13675 abbrev
= (struct abbrev_info
*)
13676 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13677 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13681 static struct die_info
*
13682 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13684 struct die_info
*die
;
13685 size_t size
= sizeof (struct die_info
);
13688 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13690 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13691 memset (die
, 0, sizeof (struct die_info
));
13696 /* Macro support. */
13698 /* Return the full name of file number I in *LH's file name table.
13699 Use COMP_DIR as the name of the current directory of the
13700 compilation. The result is allocated using xmalloc; the caller is
13701 responsible for freeing it. */
13703 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13705 /* Is the file number a valid index into the line header's file name
13706 table? Remember that file numbers start with one, not zero. */
13707 if (1 <= file
&& file
<= lh
->num_file_names
)
13709 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13711 if (IS_ABSOLUTE_PATH (fe
->name
))
13712 return xstrdup (fe
->name
);
13720 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13726 dir_len
= strlen (dir
);
13727 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13728 strcpy (full_name
, dir
);
13729 full_name
[dir_len
] = '/';
13730 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13734 return xstrdup (fe
->name
);
13739 /* The compiler produced a bogus file number. We can at least
13740 record the macro definitions made in the file, even if we
13741 won't be able to find the file by name. */
13742 char fake_name
[80];
13744 sprintf (fake_name
, "<bad macro file number %d>", file
);
13746 complaint (&symfile_complaints
,
13747 _("bad file number in macro information (%d)"),
13750 return xstrdup (fake_name
);
13755 static struct macro_source_file
*
13756 macro_start_file (int file
, int line
,
13757 struct macro_source_file
*current_file
,
13758 const char *comp_dir
,
13759 struct line_header
*lh
, struct objfile
*objfile
)
13761 /* The full name of this source file. */
13762 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13764 /* We don't create a macro table for this compilation unit
13765 at all until we actually get a filename. */
13766 if (! pending_macros
)
13767 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13768 objfile
->macro_cache
);
13770 if (! current_file
)
13771 /* If we have no current file, then this must be the start_file
13772 directive for the compilation unit's main source file. */
13773 current_file
= macro_set_main (pending_macros
, full_name
);
13775 current_file
= macro_include (current_file
, line
, full_name
);
13779 return current_file
;
13783 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13784 followed by a null byte. */
13786 copy_string (const char *buf
, int len
)
13788 char *s
= xmalloc (len
+ 1);
13790 memcpy (s
, buf
, len
);
13796 static const char *
13797 consume_improper_spaces (const char *p
, const char *body
)
13801 complaint (&symfile_complaints
,
13802 _("macro definition contains spaces in formal argument list:\n`%s'"),
13814 parse_macro_definition (struct macro_source_file
*file
, int line
,
13819 /* The body string takes one of two forms. For object-like macro
13820 definitions, it should be:
13822 <macro name> " " <definition>
13824 For function-like macro definitions, it should be:
13826 <macro name> "() " <definition>
13828 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13830 Spaces may appear only where explicitly indicated, and in the
13833 The Dwarf 2 spec says that an object-like macro's name is always
13834 followed by a space, but versions of GCC around March 2002 omit
13835 the space when the macro's definition is the empty string.
13837 The Dwarf 2 spec says that there should be no spaces between the
13838 formal arguments in a function-like macro's formal argument list,
13839 but versions of GCC around March 2002 include spaces after the
13843 /* Find the extent of the macro name. The macro name is terminated
13844 by either a space or null character (for an object-like macro) or
13845 an opening paren (for a function-like macro). */
13846 for (p
= body
; *p
; p
++)
13847 if (*p
== ' ' || *p
== '(')
13850 if (*p
== ' ' || *p
== '\0')
13852 /* It's an object-like macro. */
13853 int name_len
= p
- body
;
13854 char *name
= copy_string (body
, name_len
);
13855 const char *replacement
;
13858 replacement
= body
+ name_len
+ 1;
13861 dwarf2_macro_malformed_definition_complaint (body
);
13862 replacement
= body
+ name_len
;
13865 macro_define_object (file
, line
, name
, replacement
);
13869 else if (*p
== '(')
13871 /* It's a function-like macro. */
13872 char *name
= copy_string (body
, p
- body
);
13875 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13879 p
= consume_improper_spaces (p
, body
);
13881 /* Parse the formal argument list. */
13882 while (*p
&& *p
!= ')')
13884 /* Find the extent of the current argument name. */
13885 const char *arg_start
= p
;
13887 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13890 if (! *p
|| p
== arg_start
)
13891 dwarf2_macro_malformed_definition_complaint (body
);
13894 /* Make sure argv has room for the new argument. */
13895 if (argc
>= argv_size
)
13898 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13901 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13904 p
= consume_improper_spaces (p
, body
);
13906 /* Consume the comma, if present. */
13911 p
= consume_improper_spaces (p
, body
);
13920 /* Perfectly formed definition, no complaints. */
13921 macro_define_function (file
, line
, name
,
13922 argc
, (const char **) argv
,
13924 else if (*p
== '\0')
13926 /* Complain, but do define it. */
13927 dwarf2_macro_malformed_definition_complaint (body
);
13928 macro_define_function (file
, line
, name
,
13929 argc
, (const char **) argv
,
13933 /* Just complain. */
13934 dwarf2_macro_malformed_definition_complaint (body
);
13937 /* Just complain. */
13938 dwarf2_macro_malformed_definition_complaint (body
);
13944 for (i
= 0; i
< argc
; i
++)
13950 dwarf2_macro_malformed_definition_complaint (body
);
13955 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13956 char *comp_dir
, bfd
*abfd
,
13957 struct dwarf2_cu
*cu
)
13959 gdb_byte
*mac_ptr
, *mac_end
;
13960 struct macro_source_file
*current_file
= 0;
13961 enum dwarf_macinfo_record_type macinfo_type
;
13962 int at_commandline
;
13964 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13965 &dwarf2_per_objfile
->macinfo
);
13966 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13968 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13972 /* First pass: Find the name of the base filename.
13973 This filename is needed in order to process all macros whose definition
13974 (or undefinition) comes from the command line. These macros are defined
13975 before the first DW_MACINFO_start_file entry, and yet still need to be
13976 associated to the base file.
13978 To determine the base file name, we scan the macro definitions until we
13979 reach the first DW_MACINFO_start_file entry. We then initialize
13980 CURRENT_FILE accordingly so that any macro definition found before the
13981 first DW_MACINFO_start_file can still be associated to the base file. */
13983 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13984 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13985 + dwarf2_per_objfile
->macinfo
.size
;
13989 /* Do we at least have room for a macinfo type byte? */
13990 if (mac_ptr
>= mac_end
)
13992 /* Complaint is printed during the second pass as GDB will probably
13993 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13997 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14000 switch (macinfo_type
)
14002 /* A zero macinfo type indicates the end of the macro
14007 case DW_MACINFO_define
:
14008 case DW_MACINFO_undef
:
14009 /* Only skip the data by MAC_PTR. */
14011 unsigned int bytes_read
;
14013 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14014 mac_ptr
+= bytes_read
;
14015 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14016 mac_ptr
+= bytes_read
;
14020 case DW_MACINFO_start_file
:
14022 unsigned int bytes_read
;
14025 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14026 mac_ptr
+= bytes_read
;
14027 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14028 mac_ptr
+= bytes_read
;
14030 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
14035 case DW_MACINFO_end_file
:
14036 /* No data to skip by MAC_PTR. */
14039 case DW_MACINFO_vendor_ext
:
14040 /* Only skip the data by MAC_PTR. */
14042 unsigned int bytes_read
;
14044 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14045 mac_ptr
+= bytes_read
;
14046 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14047 mac_ptr
+= bytes_read
;
14054 } while (macinfo_type
!= 0 && current_file
== NULL
);
14056 /* Second pass: Process all entries.
14058 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14059 command-line macro definitions/undefinitions. This flag is unset when we
14060 reach the first DW_MACINFO_start_file entry. */
14062 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14064 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14065 GDB is still reading the definitions from command line. First
14066 DW_MACINFO_start_file will need to be ignored as it was already executed
14067 to create CURRENT_FILE for the main source holding also the command line
14068 definitions. On first met DW_MACINFO_start_file this flag is reset to
14069 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14071 at_commandline
= 1;
14075 /* Do we at least have room for a macinfo type byte? */
14076 if (mac_ptr
>= mac_end
)
14078 dwarf2_macros_too_long_complaint ();
14082 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14085 switch (macinfo_type
)
14087 /* A zero macinfo type indicates the end of the macro
14092 case DW_MACINFO_define
:
14093 case DW_MACINFO_undef
:
14095 unsigned int bytes_read
;
14099 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14100 mac_ptr
+= bytes_read
;
14101 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14102 mac_ptr
+= bytes_read
;
14104 if (! current_file
)
14106 /* DWARF violation as no main source is present. */
14107 complaint (&symfile_complaints
,
14108 _("debug info with no main source gives macro %s "
14110 macinfo_type
== DW_MACINFO_define
?
14112 macinfo_type
== DW_MACINFO_undef
?
14113 _("undefinition") :
14114 _("something-or-other"), line
, body
);
14117 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
14118 complaint (&symfile_complaints
,
14119 _("debug info gives %s macro %s with %s line %d: %s"),
14120 at_commandline
? _("command-line") : _("in-file"),
14121 macinfo_type
== DW_MACINFO_define
?
14123 macinfo_type
== DW_MACINFO_undef
?
14124 _("undefinition") :
14125 _("something-or-other"),
14126 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14128 if (macinfo_type
== DW_MACINFO_define
)
14129 parse_macro_definition (current_file
, line
, body
);
14130 else if (macinfo_type
== DW_MACINFO_undef
)
14131 macro_undef (current_file
, line
, body
);
14135 case DW_MACINFO_start_file
:
14137 unsigned int bytes_read
;
14140 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14141 mac_ptr
+= bytes_read
;
14142 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14143 mac_ptr
+= bytes_read
;
14145 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
14146 complaint (&symfile_complaints
,
14147 _("debug info gives source %d included "
14148 "from %s at %s line %d"),
14149 file
, at_commandline
? _("command-line") : _("file"),
14150 line
== 0 ? _("zero") : _("non-zero"), line
);
14152 if (at_commandline
)
14154 /* This DW_MACINFO_start_file was executed in the pass one. */
14155 at_commandline
= 0;
14158 current_file
= macro_start_file (file
, line
,
14159 current_file
, comp_dir
,
14164 case DW_MACINFO_end_file
:
14165 if (! current_file
)
14166 complaint (&symfile_complaints
,
14167 _("macro debug info has an unmatched `close_file' directive"));
14170 current_file
= current_file
->included_by
;
14171 if (! current_file
)
14173 enum dwarf_macinfo_record_type next_type
;
14175 /* GCC circa March 2002 doesn't produce the zero
14176 type byte marking the end of the compilation
14177 unit. Complain if it's not there, but exit no
14180 /* Do we at least have room for a macinfo type byte? */
14181 if (mac_ptr
>= mac_end
)
14183 dwarf2_macros_too_long_complaint ();
14187 /* We don't increment mac_ptr here, so this is just
14189 next_type
= read_1_byte (abfd
, mac_ptr
);
14190 if (next_type
!= 0)
14191 complaint (&symfile_complaints
,
14192 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
14199 case DW_MACINFO_vendor_ext
:
14201 unsigned int bytes_read
;
14205 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14206 mac_ptr
+= bytes_read
;
14207 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14208 mac_ptr
+= bytes_read
;
14210 /* We don't recognize any vendor extensions. */
14214 } while (macinfo_type
!= 0);
14217 /* Check if the attribute's form is a DW_FORM_block*
14218 if so return true else false. */
14220 attr_form_is_block (struct attribute
*attr
)
14222 return (attr
== NULL
? 0 :
14223 attr
->form
== DW_FORM_block1
14224 || attr
->form
== DW_FORM_block2
14225 || attr
->form
== DW_FORM_block4
14226 || attr
->form
== DW_FORM_block
14227 || attr
->form
== DW_FORM_exprloc
);
14230 /* Return non-zero if ATTR's value is a section offset --- classes
14231 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14232 You may use DW_UNSND (attr) to retrieve such offsets.
14234 Section 7.5.4, "Attribute Encodings", explains that no attribute
14235 may have a value that belongs to more than one of these classes; it
14236 would be ambiguous if we did, because we use the same forms for all
14239 attr_form_is_section_offset (struct attribute
*attr
)
14241 return (attr
->form
== DW_FORM_data4
14242 || attr
->form
== DW_FORM_data8
14243 || attr
->form
== DW_FORM_sec_offset
);
14247 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14248 zero otherwise. When this function returns true, you can apply
14249 dwarf2_get_attr_constant_value to it.
14251 However, note that for some attributes you must check
14252 attr_form_is_section_offset before using this test. DW_FORM_data4
14253 and DW_FORM_data8 are members of both the constant class, and of
14254 the classes that contain offsets into other debug sections
14255 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14256 that, if an attribute's can be either a constant or one of the
14257 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14258 taken as section offsets, not constants. */
14260 attr_form_is_constant (struct attribute
*attr
)
14262 switch (attr
->form
)
14264 case DW_FORM_sdata
:
14265 case DW_FORM_udata
:
14266 case DW_FORM_data1
:
14267 case DW_FORM_data2
:
14268 case DW_FORM_data4
:
14269 case DW_FORM_data8
:
14276 /* A helper function that fills in a dwarf2_loclist_baton. */
14279 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14280 struct dwarf2_loclist_baton
*baton
,
14281 struct attribute
*attr
)
14283 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14284 &dwarf2_per_objfile
->loc
);
14286 baton
->per_cu
= cu
->per_cu
;
14287 gdb_assert (baton
->per_cu
);
14288 /* We don't know how long the location list is, but make sure we
14289 don't run off the edge of the section. */
14290 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14291 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14292 baton
->base_address
= cu
->base_address
;
14296 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14297 struct dwarf2_cu
*cu
)
14299 if (attr_form_is_section_offset (attr
)
14300 /* ".debug_loc" may not exist at all, or the offset may be outside
14301 the section. If so, fall through to the complaint in the
14303 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
14305 struct dwarf2_loclist_baton
*baton
;
14307 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14308 sizeof (struct dwarf2_loclist_baton
));
14310 fill_in_loclist_baton (cu
, baton
, attr
);
14312 if (cu
->base_known
== 0)
14313 complaint (&symfile_complaints
,
14314 _("Location list used without specifying the CU base address."));
14316 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14317 SYMBOL_LOCATION_BATON (sym
) = baton
;
14321 struct dwarf2_locexpr_baton
*baton
;
14323 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14324 sizeof (struct dwarf2_locexpr_baton
));
14325 baton
->per_cu
= cu
->per_cu
;
14326 gdb_assert (baton
->per_cu
);
14328 if (attr_form_is_block (attr
))
14330 /* Note that we're just copying the block's data pointer
14331 here, not the actual data. We're still pointing into the
14332 info_buffer for SYM's objfile; right now we never release
14333 that buffer, but when we do clean up properly this may
14335 baton
->size
= DW_BLOCK (attr
)->size
;
14336 baton
->data
= DW_BLOCK (attr
)->data
;
14340 dwarf2_invalid_attrib_class_complaint ("location description",
14341 SYMBOL_NATURAL_NAME (sym
));
14343 baton
->data
= NULL
;
14346 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14347 SYMBOL_LOCATION_BATON (sym
) = baton
;
14351 /* Return the OBJFILE associated with the compilation unit CU. If CU
14352 came from a separate debuginfo file, then the master objfile is
14356 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14358 struct objfile
*objfile
= per_cu
->objfile
;
14360 /* Return the master objfile, so that we can report and look up the
14361 correct file containing this variable. */
14362 if (objfile
->separate_debug_objfile_backlink
)
14363 objfile
= objfile
->separate_debug_objfile_backlink
;
14368 /* Return the address size given in the compilation unit header for CU. */
14371 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14374 return per_cu
->cu
->header
.addr_size
;
14377 /* If the CU is not currently read in, we re-read its header. */
14378 struct objfile
*objfile
= per_cu
->objfile
;
14379 struct dwarf2_per_objfile
*per_objfile
14380 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14381 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14382 struct comp_unit_head cu_header
;
14384 memset (&cu_header
, 0, sizeof cu_header
);
14385 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14386 return cu_header
.addr_size
;
14390 /* Return the offset size given in the compilation unit header for CU. */
14393 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14396 return per_cu
->cu
->header
.offset_size
;
14399 /* If the CU is not currently read in, we re-read its header. */
14400 struct objfile
*objfile
= per_cu
->objfile
;
14401 struct dwarf2_per_objfile
*per_objfile
14402 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14403 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14404 struct comp_unit_head cu_header
;
14406 memset (&cu_header
, 0, sizeof cu_header
);
14407 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14408 return cu_header
.offset_size
;
14412 /* Return the text offset of the CU. The returned offset comes from
14413 this CU's objfile. If this objfile came from a separate debuginfo
14414 file, then the offset may be different from the corresponding
14415 offset in the parent objfile. */
14418 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14420 struct objfile
*objfile
= per_cu
->objfile
;
14422 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14425 /* Locate the .debug_info compilation unit from CU's objfile which contains
14426 the DIE at OFFSET. Raises an error on failure. */
14428 static struct dwarf2_per_cu_data
*
14429 dwarf2_find_containing_comp_unit (unsigned int offset
,
14430 struct objfile
*objfile
)
14432 struct dwarf2_per_cu_data
*this_cu
;
14436 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14439 int mid
= low
+ (high
- low
) / 2;
14441 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14446 gdb_assert (low
== high
);
14447 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14450 error (_("Dwarf Error: could not find partial DIE containing "
14451 "offset 0x%lx [in module %s]"),
14452 (long) offset
, bfd_get_filename (objfile
->obfd
));
14454 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14455 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14459 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14460 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14461 && offset
>= this_cu
->offset
+ this_cu
->length
)
14462 error (_("invalid dwarf2 offset %u"), offset
);
14463 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14468 /* Locate the compilation unit from OBJFILE which is located at exactly
14469 OFFSET. Raises an error on failure. */
14471 static struct dwarf2_per_cu_data
*
14472 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14474 struct dwarf2_per_cu_data
*this_cu
;
14476 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14477 if (this_cu
->offset
!= offset
)
14478 error (_("no compilation unit with offset %u."), offset
);
14482 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14485 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14487 memset (cu
, 0, sizeof (*cu
));
14488 cu
->objfile
= objfile
;
14489 obstack_init (&cu
->comp_unit_obstack
);
14492 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14495 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14497 struct attribute
*attr
;
14499 /* Set the language we're debugging. */
14500 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14502 set_cu_language (DW_UNSND (attr
), cu
);
14504 set_cu_language (language_minimal
, cu
);
14507 /* Release one cached compilation unit, CU. We unlink it from the tree
14508 of compilation units, but we don't remove it from the read_in_chain;
14509 the caller is responsible for that.
14510 NOTE: DATA is a void * because this function is also used as a
14511 cleanup routine. */
14514 free_one_comp_unit (void *data
)
14516 struct dwarf2_cu
*cu
= data
;
14518 if (cu
->per_cu
!= NULL
)
14519 cu
->per_cu
->cu
= NULL
;
14522 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14527 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14528 when we're finished with it. We can't free the pointer itself, but be
14529 sure to unlink it from the cache. Also release any associated storage
14530 and perform cache maintenance.
14532 Only used during partial symbol parsing. */
14535 free_stack_comp_unit (void *data
)
14537 struct dwarf2_cu
*cu
= data
;
14539 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14540 cu
->partial_dies
= NULL
;
14542 if (cu
->per_cu
!= NULL
)
14544 /* This compilation unit is on the stack in our caller, so we
14545 should not xfree it. Just unlink it. */
14546 cu
->per_cu
->cu
= NULL
;
14549 /* If we had a per-cu pointer, then we may have other compilation
14550 units loaded, so age them now. */
14551 age_cached_comp_units ();
14555 /* Free all cached compilation units. */
14558 free_cached_comp_units (void *data
)
14560 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14562 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14563 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14564 while (per_cu
!= NULL
)
14566 struct dwarf2_per_cu_data
*next_cu
;
14568 next_cu
= per_cu
->cu
->read_in_chain
;
14570 free_one_comp_unit (per_cu
->cu
);
14571 *last_chain
= next_cu
;
14577 /* Increase the age counter on each cached compilation unit, and free
14578 any that are too old. */
14581 age_cached_comp_units (void)
14583 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14585 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14586 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14587 while (per_cu
!= NULL
)
14589 per_cu
->cu
->last_used
++;
14590 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14591 dwarf2_mark (per_cu
->cu
);
14592 per_cu
= per_cu
->cu
->read_in_chain
;
14595 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14596 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14597 while (per_cu
!= NULL
)
14599 struct dwarf2_per_cu_data
*next_cu
;
14601 next_cu
= per_cu
->cu
->read_in_chain
;
14603 if (!per_cu
->cu
->mark
)
14605 free_one_comp_unit (per_cu
->cu
);
14606 *last_chain
= next_cu
;
14609 last_chain
= &per_cu
->cu
->read_in_chain
;
14615 /* Remove a single compilation unit from the cache. */
14618 free_one_cached_comp_unit (void *target_cu
)
14620 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14622 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14623 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14624 while (per_cu
!= NULL
)
14626 struct dwarf2_per_cu_data
*next_cu
;
14628 next_cu
= per_cu
->cu
->read_in_chain
;
14630 if (per_cu
->cu
== target_cu
)
14632 free_one_comp_unit (per_cu
->cu
);
14633 *last_chain
= next_cu
;
14637 last_chain
= &per_cu
->cu
->read_in_chain
;
14643 /* Release all extra memory associated with OBJFILE. */
14646 dwarf2_free_objfile (struct objfile
*objfile
)
14648 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14650 if (dwarf2_per_objfile
== NULL
)
14653 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14654 free_cached_comp_units (NULL
);
14656 if (dwarf2_per_objfile
->quick_file_names_table
)
14657 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14659 /* Everything else should be on the objfile obstack. */
14662 /* A pair of DIE offset and GDB type pointer. We store these
14663 in a hash table separate from the DIEs, and preserve them
14664 when the DIEs are flushed out of cache. */
14666 struct dwarf2_offset_and_type
14668 unsigned int offset
;
14672 /* Hash function for a dwarf2_offset_and_type. */
14675 offset_and_type_hash (const void *item
)
14677 const struct dwarf2_offset_and_type
*ofs
= item
;
14679 return ofs
->offset
;
14682 /* Equality function for a dwarf2_offset_and_type. */
14685 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14687 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14688 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14690 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14693 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14694 table if necessary. For convenience, return TYPE.
14696 The DIEs reading must have careful ordering to:
14697 * Not cause infite loops trying to read in DIEs as a prerequisite for
14698 reading current DIE.
14699 * Not trying to dereference contents of still incompletely read in types
14700 while reading in other DIEs.
14701 * Enable referencing still incompletely read in types just by a pointer to
14702 the type without accessing its fields.
14704 Therefore caller should follow these rules:
14705 * Try to fetch any prerequisite types we may need to build this DIE type
14706 before building the type and calling set_die_type.
14707 * After building type call set_die_type for current DIE as soon as
14708 possible before fetching more types to complete the current type.
14709 * Make the type as complete as possible before fetching more types. */
14711 static struct type
*
14712 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14714 struct dwarf2_offset_and_type
**slot
, ofs
;
14715 struct objfile
*objfile
= cu
->objfile
;
14716 htab_t
*type_hash_ptr
;
14718 /* For Ada types, make sure that the gnat-specific data is always
14719 initialized (if not already set). There are a few types where
14720 we should not be doing so, because the type-specific area is
14721 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14722 where the type-specific area is used to store the floatformat).
14723 But this is not a problem, because the gnat-specific information
14724 is actually not needed for these types. */
14725 if (need_gnat_info (cu
)
14726 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14727 && TYPE_CODE (type
) != TYPE_CODE_FLT
14728 && !HAVE_GNAT_AUX_INFO (type
))
14729 INIT_GNAT_SPECIFIC (type
);
14731 if (cu
->per_cu
->from_debug_types
)
14732 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14734 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14736 if (*type_hash_ptr
== NULL
)
14739 = htab_create_alloc_ex (127,
14740 offset_and_type_hash
,
14741 offset_and_type_eq
,
14743 &objfile
->objfile_obstack
,
14744 hashtab_obstack_allocate
,
14745 dummy_obstack_deallocate
);
14748 ofs
.offset
= die
->offset
;
14750 slot
= (struct dwarf2_offset_and_type
**)
14751 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14753 complaint (&symfile_complaints
,
14754 _("A problem internal to GDB: DIE 0x%x has type already set"),
14756 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14761 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14762 table, or return NULL if the die does not have a saved type. */
14764 static struct type
*
14765 get_die_type_at_offset (unsigned int offset
,
14766 struct dwarf2_per_cu_data
*per_cu
)
14768 struct dwarf2_offset_and_type
*slot
, ofs
;
14771 if (per_cu
->from_debug_types
)
14772 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14774 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14775 if (type_hash
== NULL
)
14778 ofs
.offset
= offset
;
14779 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14786 /* Look up the type for DIE in the appropriate type_hash table,
14787 or return NULL if DIE does not have a saved type. */
14789 static struct type
*
14790 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14792 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14795 /* Add a dependence relationship from CU to REF_PER_CU. */
14798 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14799 struct dwarf2_per_cu_data
*ref_per_cu
)
14803 if (cu
->dependencies
== NULL
)
14805 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14806 NULL
, &cu
->comp_unit_obstack
,
14807 hashtab_obstack_allocate
,
14808 dummy_obstack_deallocate
);
14810 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14812 *slot
= ref_per_cu
;
14815 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14816 Set the mark field in every compilation unit in the
14817 cache that we must keep because we are keeping CU. */
14820 dwarf2_mark_helper (void **slot
, void *data
)
14822 struct dwarf2_per_cu_data
*per_cu
;
14824 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14825 if (per_cu
->cu
->mark
)
14827 per_cu
->cu
->mark
= 1;
14829 if (per_cu
->cu
->dependencies
!= NULL
)
14830 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14835 /* Set the mark field in CU and in every other compilation unit in the
14836 cache that we must keep because we are keeping CU. */
14839 dwarf2_mark (struct dwarf2_cu
*cu
)
14844 if (cu
->dependencies
!= NULL
)
14845 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14849 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14853 per_cu
->cu
->mark
= 0;
14854 per_cu
= per_cu
->cu
->read_in_chain
;
14858 /* Trivial hash function for partial_die_info: the hash value of a DIE
14859 is its offset in .debug_info for this objfile. */
14862 partial_die_hash (const void *item
)
14864 const struct partial_die_info
*part_die
= item
;
14866 return part_die
->offset
;
14869 /* Trivial comparison function for partial_die_info structures: two DIEs
14870 are equal if they have the same offset. */
14873 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14875 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14876 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14878 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14881 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14882 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14885 set_dwarf2_cmd (char *args
, int from_tty
)
14887 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14891 show_dwarf2_cmd (char *args
, int from_tty
)
14893 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14896 /* If section described by INFO was mmapped, munmap it now. */
14899 munmap_section_buffer (struct dwarf2_section_info
*info
)
14901 if (info
->was_mmapped
)
14904 intptr_t begin
= (intptr_t) info
->buffer
;
14905 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14906 size_t map_length
= info
->size
+ begin
- map_begin
;
14908 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14910 /* Without HAVE_MMAP, we should never be here to begin with. */
14911 gdb_assert_not_reached ("no mmap support");
14916 /* munmap debug sections for OBJFILE, if necessary. */
14919 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14921 struct dwarf2_per_objfile
*data
= d
;
14923 /* This is sorted according to the order they're defined in to make it easier
14924 to keep in sync. */
14925 munmap_section_buffer (&data
->info
);
14926 munmap_section_buffer (&data
->abbrev
);
14927 munmap_section_buffer (&data
->line
);
14928 munmap_section_buffer (&data
->loc
);
14929 munmap_section_buffer (&data
->macinfo
);
14930 munmap_section_buffer (&data
->str
);
14931 munmap_section_buffer (&data
->ranges
);
14932 munmap_section_buffer (&data
->types
);
14933 munmap_section_buffer (&data
->frame
);
14934 munmap_section_buffer (&data
->eh_frame
);
14935 munmap_section_buffer (&data
->gdb_index
);
14939 /* The "save gdb-index" command. */
14941 /* The contents of the hash table we create when building the string
14943 struct strtab_entry
14945 offset_type offset
;
14949 /* Hash function for a strtab_entry. */
14952 hash_strtab_entry (const void *e
)
14954 const struct strtab_entry
*entry
= e
;
14955 return mapped_index_string_hash (entry
->str
);
14958 /* Equality function for a strtab_entry. */
14961 eq_strtab_entry (const void *a
, const void *b
)
14963 const struct strtab_entry
*ea
= a
;
14964 const struct strtab_entry
*eb
= b
;
14965 return !strcmp (ea
->str
, eb
->str
);
14968 /* Create a strtab_entry hash table. */
14971 create_strtab (void)
14973 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14974 xfree
, xcalloc
, xfree
);
14977 /* Add a string to the constant pool. Return the string's offset in
14981 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14984 struct strtab_entry entry
;
14985 struct strtab_entry
*result
;
14988 slot
= htab_find_slot (table
, &entry
, INSERT
);
14993 result
= XNEW (struct strtab_entry
);
14994 result
->offset
= obstack_object_size (cpool
);
14996 obstack_grow_str0 (cpool
, str
);
14999 return result
->offset
;
15002 /* An entry in the symbol table. */
15003 struct symtab_index_entry
15005 /* The name of the symbol. */
15007 /* The offset of the name in the constant pool. */
15008 offset_type index_offset
;
15009 /* A sorted vector of the indices of all the CUs that hold an object
15011 VEC (offset_type
) *cu_indices
;
15014 /* The symbol table. This is a power-of-2-sized hash table. */
15015 struct mapped_symtab
15017 offset_type n_elements
;
15019 struct symtab_index_entry
**data
;
15022 /* Hash function for a symtab_index_entry. */
15025 hash_symtab_entry (const void *e
)
15027 const struct symtab_index_entry
*entry
= e
;
15028 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15029 sizeof (offset_type
) * VEC_length (offset_type
,
15030 entry
->cu_indices
),
15034 /* Equality function for a symtab_index_entry. */
15037 eq_symtab_entry (const void *a
, const void *b
)
15039 const struct symtab_index_entry
*ea
= a
;
15040 const struct symtab_index_entry
*eb
= b
;
15041 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15042 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15044 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15045 VEC_address (offset_type
, eb
->cu_indices
),
15046 sizeof (offset_type
) * len
);
15049 /* Destroy a symtab_index_entry. */
15052 delete_symtab_entry (void *p
)
15054 struct symtab_index_entry
*entry
= p
;
15055 VEC_free (offset_type
, entry
->cu_indices
);
15059 /* Create a hash table holding symtab_index_entry objects. */
15062 create_symbol_hash_table (void)
15064 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15065 delete_symtab_entry
, xcalloc
, xfree
);
15068 /* Create a new mapped symtab object. */
15070 static struct mapped_symtab
*
15071 create_mapped_symtab (void)
15073 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15074 symtab
->n_elements
= 0;
15075 symtab
->size
= 1024;
15076 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15080 /* Destroy a mapped_symtab. */
15083 cleanup_mapped_symtab (void *p
)
15085 struct mapped_symtab
*symtab
= p
;
15086 /* The contents of the array are freed when the other hash table is
15088 xfree (symtab
->data
);
15092 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15095 static struct symtab_index_entry
**
15096 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15098 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
15100 index
= hash
& (symtab
->size
- 1);
15101 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15105 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15106 return &symtab
->data
[index
];
15107 index
= (index
+ step
) & (symtab
->size
- 1);
15111 /* Expand SYMTAB's hash table. */
15114 hash_expand (struct mapped_symtab
*symtab
)
15116 offset_type old_size
= symtab
->size
;
15118 struct symtab_index_entry
**old_entries
= symtab
->data
;
15121 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15123 for (i
= 0; i
< old_size
; ++i
)
15125 if (old_entries
[i
])
15127 struct symtab_index_entry
**slot
= find_slot (symtab
,
15128 old_entries
[i
]->name
);
15129 *slot
= old_entries
[i
];
15133 xfree (old_entries
);
15136 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15137 is the index of the CU in which the symbol appears. */
15140 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15141 offset_type cu_index
)
15143 struct symtab_index_entry
**slot
;
15145 ++symtab
->n_elements
;
15146 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15147 hash_expand (symtab
);
15149 slot
= find_slot (symtab
, name
);
15152 *slot
= XNEW (struct symtab_index_entry
);
15153 (*slot
)->name
= name
;
15154 (*slot
)->cu_indices
= NULL
;
15156 /* Don't push an index twice. Due to how we add entries we only
15157 have to check the last one. */
15158 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15159 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15160 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15163 /* Add a vector of indices to the constant pool. */
15166 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15167 struct symtab_index_entry
*entry
)
15171 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15174 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15175 offset_type val
= MAYBE_SWAP (len
);
15180 entry
->index_offset
= obstack_object_size (cpool
);
15182 obstack_grow (cpool
, &val
, sizeof (val
));
15184 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15187 val
= MAYBE_SWAP (iter
);
15188 obstack_grow (cpool
, &val
, sizeof (val
));
15193 struct symtab_index_entry
*old_entry
= *slot
;
15194 entry
->index_offset
= old_entry
->index_offset
;
15197 return entry
->index_offset
;
15200 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15201 constant pool entries going into the obstack CPOOL. */
15204 write_hash_table (struct mapped_symtab
*symtab
,
15205 struct obstack
*output
, struct obstack
*cpool
)
15208 htab_t symbol_hash_table
;
15211 symbol_hash_table
= create_symbol_hash_table ();
15212 str_table
= create_strtab ();
15214 /* We add all the index vectors to the constant pool first, to
15215 ensure alignment is ok. */
15216 for (i
= 0; i
< symtab
->size
; ++i
)
15218 if (symtab
->data
[i
])
15219 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15222 /* Now write out the hash table. */
15223 for (i
= 0; i
< symtab
->size
; ++i
)
15225 offset_type str_off
, vec_off
;
15227 if (symtab
->data
[i
])
15229 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15230 vec_off
= symtab
->data
[i
]->index_offset
;
15234 /* While 0 is a valid constant pool index, it is not valid
15235 to have 0 for both offsets. */
15240 str_off
= MAYBE_SWAP (str_off
);
15241 vec_off
= MAYBE_SWAP (vec_off
);
15243 obstack_grow (output
, &str_off
, sizeof (str_off
));
15244 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15247 htab_delete (str_table
);
15248 htab_delete (symbol_hash_table
);
15251 /* Struct to map psymtab to CU index in the index file. */
15252 struct psymtab_cu_index_map
15254 struct partial_symtab
*psymtab
;
15255 unsigned int cu_index
;
15259 hash_psymtab_cu_index (const void *item
)
15261 const struct psymtab_cu_index_map
*map
= item
;
15263 return htab_hash_pointer (map
->psymtab
);
15267 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15269 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15270 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15272 return lhs
->psymtab
== rhs
->psymtab
;
15275 /* Helper struct for building the address table. */
15276 struct addrmap_index_data
15278 struct objfile
*objfile
;
15279 struct obstack
*addr_obstack
;
15280 htab_t cu_index_htab
;
15282 /* Non-zero if the previous_* fields are valid.
15283 We can't write an entry until we see the next entry (since it is only then
15284 that we know the end of the entry). */
15285 int previous_valid
;
15286 /* Index of the CU in the table of all CUs in the index file. */
15287 unsigned int previous_cu_index
;
15288 /* Start address of the CU. */
15289 CORE_ADDR previous_cu_start
;
15292 /* Write an address entry to OBSTACK. */
15295 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15296 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15298 offset_type cu_index_to_write
;
15300 CORE_ADDR baseaddr
;
15302 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15304 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15305 obstack_grow (obstack
, addr
, 8);
15306 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15307 obstack_grow (obstack
, addr
, 8);
15308 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15309 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15312 /* Worker function for traversing an addrmap to build the address table. */
15315 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15317 struct addrmap_index_data
*data
= datap
;
15318 struct partial_symtab
*pst
= obj
;
15319 offset_type cu_index
;
15322 if (data
->previous_valid
)
15323 add_address_entry (data
->objfile
, data
->addr_obstack
,
15324 data
->previous_cu_start
, start_addr
,
15325 data
->previous_cu_index
);
15327 data
->previous_cu_start
= start_addr
;
15330 struct psymtab_cu_index_map find_map
, *map
;
15331 find_map
.psymtab
= pst
;
15332 map
= htab_find (data
->cu_index_htab
, &find_map
);
15333 gdb_assert (map
!= NULL
);
15334 data
->previous_cu_index
= map
->cu_index
;
15335 data
->previous_valid
= 1;
15338 data
->previous_valid
= 0;
15343 /* Write OBJFILE's address map to OBSTACK.
15344 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15345 in the index file. */
15348 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15349 htab_t cu_index_htab
)
15351 struct addrmap_index_data addrmap_index_data
;
15353 /* When writing the address table, we have to cope with the fact that
15354 the addrmap iterator only provides the start of a region; we have to
15355 wait until the next invocation to get the start of the next region. */
15357 addrmap_index_data
.objfile
= objfile
;
15358 addrmap_index_data
.addr_obstack
= obstack
;
15359 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15360 addrmap_index_data
.previous_valid
= 0;
15362 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15363 &addrmap_index_data
);
15365 /* It's highly unlikely the last entry (end address = 0xff...ff)
15366 is valid, but we should still handle it.
15367 The end address is recorded as the start of the next region, but that
15368 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15370 if (addrmap_index_data
.previous_valid
)
15371 add_address_entry (objfile
, obstack
,
15372 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15373 addrmap_index_data
.previous_cu_index
);
15376 /* Add a list of partial symbols to SYMTAB. */
15379 write_psymbols (struct mapped_symtab
*symtab
,
15381 struct partial_symbol
**psymp
,
15383 offset_type cu_index
,
15386 for (; count
-- > 0; ++psymp
)
15388 void **slot
, *lookup
;
15390 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15391 error (_("Ada is not currently supported by the index"));
15393 /* We only want to add a given psymbol once. However, we also
15394 want to account for whether it is global or static. So, we
15395 may add it twice, using slightly different values. */
15398 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15400 lookup
= (void *) val
;
15405 /* Only add a given psymbol once. */
15406 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15410 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15415 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15416 exception if there is an error. */
15419 write_obstack (FILE *file
, struct obstack
*obstack
)
15421 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15423 != obstack_object_size (obstack
))
15424 error (_("couldn't data write to file"));
15427 /* Unlink a file if the argument is not NULL. */
15430 unlink_if_set (void *p
)
15432 char **filename
= p
;
15434 unlink (*filename
);
15437 /* A helper struct used when iterating over debug_types. */
15438 struct signatured_type_index_data
15440 struct objfile
*objfile
;
15441 struct mapped_symtab
*symtab
;
15442 struct obstack
*types_list
;
15447 /* A helper function that writes a single signatured_type to an
15451 write_one_signatured_type (void **slot
, void *d
)
15453 struct signatured_type_index_data
*info
= d
;
15454 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15455 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15456 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15459 write_psymbols (info
->symtab
,
15461 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15462 psymtab
->n_global_syms
, info
->cu_index
,
15464 write_psymbols (info
->symtab
,
15466 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15467 psymtab
->n_static_syms
, info
->cu_index
,
15470 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15471 obstack_grow (info
->types_list
, val
, 8);
15472 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15473 obstack_grow (info
->types_list
, val
, 8);
15474 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15475 obstack_grow (info
->types_list
, val
, 8);
15482 /* A cleanup function for an htab_t. */
15485 cleanup_htab (void *arg
)
15490 /* Create an index file for OBJFILE in the directory DIR. */
15493 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15495 struct cleanup
*cleanup
;
15496 char *filename
, *cleanup_filename
;
15497 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15498 struct obstack cu_list
, types_cu_list
;
15501 struct mapped_symtab
*symtab
;
15502 offset_type val
, size_of_contents
, total_len
;
15506 htab_t cu_index_htab
;
15507 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15509 if (!objfile
->psymtabs
)
15511 if (dwarf2_per_objfile
->using_index
)
15512 error (_("Cannot use an index to create the index"));
15514 if (stat (objfile
->name
, &st
) < 0)
15515 perror_with_name (objfile
->name
);
15517 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15518 INDEX_SUFFIX
, (char *) NULL
);
15519 cleanup
= make_cleanup (xfree
, filename
);
15521 out_file
= fopen (filename
, "wb");
15523 error (_("Can't open `%s' for writing"), filename
);
15525 cleanup_filename
= filename
;
15526 make_cleanup (unlink_if_set
, &cleanup_filename
);
15528 symtab
= create_mapped_symtab ();
15529 make_cleanup (cleanup_mapped_symtab
, symtab
);
15531 obstack_init (&addr_obstack
);
15532 make_cleanup_obstack_free (&addr_obstack
);
15534 obstack_init (&cu_list
);
15535 make_cleanup_obstack_free (&cu_list
);
15537 obstack_init (&types_cu_list
);
15538 make_cleanup_obstack_free (&types_cu_list
);
15540 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15541 NULL
, xcalloc
, xfree
);
15542 make_cleanup (cleanup_htab
, psyms_seen
);
15544 /* While we're scanning CU's create a table that maps a psymtab pointer
15545 (which is what addrmap records) to its index (which is what is recorded
15546 in the index file). This will later be needed to write the address
15548 cu_index_htab
= htab_create_alloc (100,
15549 hash_psymtab_cu_index
,
15550 eq_psymtab_cu_index
,
15551 NULL
, xcalloc
, xfree
);
15552 make_cleanup (cleanup_htab
, cu_index_htab
);
15553 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15554 xmalloc (sizeof (struct psymtab_cu_index_map
)
15555 * dwarf2_per_objfile
->n_comp_units
);
15556 make_cleanup (xfree
, psymtab_cu_index_map
);
15558 /* The CU list is already sorted, so we don't need to do additional
15559 work here. Also, the debug_types entries do not appear in
15560 all_comp_units, but only in their own hash table. */
15561 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15563 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15564 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15566 struct psymtab_cu_index_map
*map
;
15569 write_psymbols (symtab
,
15571 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15572 psymtab
->n_global_syms
, i
,
15574 write_psymbols (symtab
,
15576 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15577 psymtab
->n_static_syms
, i
,
15580 map
= &psymtab_cu_index_map
[i
];
15581 map
->psymtab
= psymtab
;
15583 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15584 gdb_assert (slot
!= NULL
);
15585 gdb_assert (*slot
== NULL
);
15588 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15589 obstack_grow (&cu_list
, val
, 8);
15590 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15591 obstack_grow (&cu_list
, val
, 8);
15594 /* Dump the address map. */
15595 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15597 /* Write out the .debug_type entries, if any. */
15598 if (dwarf2_per_objfile
->signatured_types
)
15600 struct signatured_type_index_data sig_data
;
15602 sig_data
.objfile
= objfile
;
15603 sig_data
.symtab
= symtab
;
15604 sig_data
.types_list
= &types_cu_list
;
15605 sig_data
.psyms_seen
= psyms_seen
;
15606 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15607 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15608 write_one_signatured_type
, &sig_data
);
15611 obstack_init (&constant_pool
);
15612 make_cleanup_obstack_free (&constant_pool
);
15613 obstack_init (&symtab_obstack
);
15614 make_cleanup_obstack_free (&symtab_obstack
);
15615 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15617 obstack_init (&contents
);
15618 make_cleanup_obstack_free (&contents
);
15619 size_of_contents
= 6 * sizeof (offset_type
);
15620 total_len
= size_of_contents
;
15622 /* The version number. */
15623 val
= MAYBE_SWAP (3);
15624 obstack_grow (&contents
, &val
, sizeof (val
));
15626 /* The offset of the CU list from the start of the file. */
15627 val
= MAYBE_SWAP (total_len
);
15628 obstack_grow (&contents
, &val
, sizeof (val
));
15629 total_len
+= obstack_object_size (&cu_list
);
15631 /* The offset of the types CU list from the start of the file. */
15632 val
= MAYBE_SWAP (total_len
);
15633 obstack_grow (&contents
, &val
, sizeof (val
));
15634 total_len
+= obstack_object_size (&types_cu_list
);
15636 /* The offset of the address table from the start of the file. */
15637 val
= MAYBE_SWAP (total_len
);
15638 obstack_grow (&contents
, &val
, sizeof (val
));
15639 total_len
+= obstack_object_size (&addr_obstack
);
15641 /* The offset of the symbol table from the start of the file. */
15642 val
= MAYBE_SWAP (total_len
);
15643 obstack_grow (&contents
, &val
, sizeof (val
));
15644 total_len
+= obstack_object_size (&symtab_obstack
);
15646 /* The offset of the constant pool from the start of the file. */
15647 val
= MAYBE_SWAP (total_len
);
15648 obstack_grow (&contents
, &val
, sizeof (val
));
15649 total_len
+= obstack_object_size (&constant_pool
);
15651 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15653 write_obstack (out_file
, &contents
);
15654 write_obstack (out_file
, &cu_list
);
15655 write_obstack (out_file
, &types_cu_list
);
15656 write_obstack (out_file
, &addr_obstack
);
15657 write_obstack (out_file
, &symtab_obstack
);
15658 write_obstack (out_file
, &constant_pool
);
15662 /* We want to keep the file, so we set cleanup_filename to NULL
15663 here. See unlink_if_set. */
15664 cleanup_filename
= NULL
;
15666 do_cleanups (cleanup
);
15669 /* The mapped index file format is designed to be directly mmap()able
15670 on any architecture. In most cases, a datum is represented using a
15671 little-endian 32-bit integer value, called an offset_type. Big
15672 endian machines must byte-swap the values before using them.
15673 Exceptions to this rule are noted. The data is laid out such that
15674 alignment is always respected.
15676 A mapped index consists of several sections.
15678 1. The file header. This is a sequence of values, of offset_type
15679 unless otherwise noted:
15681 [0] The version number, currently 3. Versions 1 and 2 are
15683 [1] The offset, from the start of the file, of the CU list.
15684 [2] The offset, from the start of the file, of the types CU list.
15685 Note that this section can be empty, in which case this offset will
15686 be equal to the next offset.
15687 [3] The offset, from the start of the file, of the address section.
15688 [4] The offset, from the start of the file, of the symbol table.
15689 [5] The offset, from the start of the file, of the constant pool.
15691 2. The CU list. This is a sequence of pairs of 64-bit
15692 little-endian values, sorted by the CU offset. The first element
15693 in each pair is the offset of a CU in the .debug_info section. The
15694 second element in each pair is the length of that CU. References
15695 to a CU elsewhere in the map are done using a CU index, which is
15696 just the 0-based index into this table. Note that if there are
15697 type CUs, then conceptually CUs and type CUs form a single list for
15698 the purposes of CU indices.
15700 3. The types CU list. This is a sequence of triplets of 64-bit
15701 little-endian values. In a triplet, the first value is the CU
15702 offset, the second value is the type offset in the CU, and the
15703 third value is the type signature. The types CU list is not
15706 4. The address section. The address section consists of a sequence
15707 of address entries. Each address entry has three elements.
15708 [0] The low address. This is a 64-bit little-endian value.
15709 [1] The high address. This is a 64-bit little-endian value.
15710 Like DW_AT_high_pc, the value is one byte beyond the end.
15711 [2] The CU index. This is an offset_type value.
15713 5. The symbol table. This is a hash table. The size of the hash
15714 table is always a power of 2. The initial hash and the step are
15715 currently defined by the `find_slot' function.
15717 Each slot in the hash table consists of a pair of offset_type
15718 values. The first value is the offset of the symbol's name in the
15719 constant pool. The second value is the offset of the CU vector in
15722 If both values are 0, then this slot in the hash table is empty.
15723 This is ok because while 0 is a valid constant pool index, it
15724 cannot be a valid index for both a string and a CU vector.
15726 A string in the constant pool is stored as a \0-terminated string,
15729 A CU vector in the constant pool is a sequence of offset_type
15730 values. The first value is the number of CU indices in the vector.
15731 Each subsequent value is the index of a CU in the CU list. This
15732 element in the hash table is used to indicate which CUs define the
15735 6. The constant pool. This is simply a bunch of bytes. It is
15736 organized so that alignment is correct: CU vectors are stored
15737 first, followed by strings. */
15740 save_gdb_index_command (char *arg
, int from_tty
)
15742 struct objfile
*objfile
;
15745 error (_("usage: save gdb-index DIRECTORY"));
15747 ALL_OBJFILES (objfile
)
15751 /* If the objfile does not correspond to an actual file, skip it. */
15752 if (stat (objfile
->name
, &st
) < 0)
15755 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15756 if (dwarf2_per_objfile
)
15758 volatile struct gdb_exception except
;
15760 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15762 write_psymtabs_to_index (objfile
, arg
);
15764 if (except
.reason
< 0)
15765 exception_fprintf (gdb_stderr
, except
,
15766 _("Error while writing index for `%s': "),
15774 int dwarf2_always_disassemble
;
15777 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15778 struct cmd_list_element
*c
, const char *value
)
15780 fprintf_filtered (file
, _("\
15781 Whether to always disassemble DWARF expressions is %s.\n"),
15785 void _initialize_dwarf2_read (void);
15788 _initialize_dwarf2_read (void)
15790 struct cmd_list_element
*c
;
15792 dwarf2_objfile_data_key
15793 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15795 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15796 Set DWARF 2 specific variables.\n\
15797 Configure DWARF 2 variables such as the cache size"),
15798 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15799 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15801 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15802 Show DWARF 2 specific variables\n\
15803 Show DWARF 2 variables such as the cache size"),
15804 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15805 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15807 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15808 &dwarf2_max_cache_age
, _("\
15809 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15810 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15811 A higher limit means that cached compilation units will be stored\n\
15812 in memory longer, and more total memory will be used. Zero disables\n\
15813 caching, which can slow down startup."),
15815 show_dwarf2_max_cache_age
,
15816 &set_dwarf2_cmdlist
,
15817 &show_dwarf2_cmdlist
);
15819 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15820 &dwarf2_always_disassemble
, _("\
15821 Set whether `info address' always disassembles DWARF expressions."), _("\
15822 Show whether `info address' always disassembles DWARF expressions."), _("\
15823 When enabled, DWARF expressions are always printed in an assembly-like\n\
15824 syntax. When disabled, expressions will be printed in a more\n\
15825 conversational style, when possible."),
15827 show_dwarf2_always_disassemble
,
15828 &set_dwarf2_cmdlist
,
15829 &show_dwarf2_cmdlist
);
15831 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15832 Set debugging of the dwarf2 DIE reader."), _("\
15833 Show debugging of the dwarf2 DIE reader."), _("\
15834 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15835 The value is the maximum depth to print."),
15838 &setdebuglist
, &showdebuglist
);
15840 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15842 Save a gdb-index file.\n\
15843 Usage: save gdb-index DIRECTORY"),
15845 set_cmd_completer (c
, filename_completer
);