1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb_string.h"
69 #include "gdb_assert.h"
70 #include <sys/types.h>
77 #define MAP_FAILED ((void *) -1)
81 typedef struct symbol
*symbolp
;
84 /* When non-zero, dump DIEs after they are read in. */
85 static int dwarf2_die_debug
= 0;
87 /* When non-zero, cross-check physname against demangler. */
88 static int check_physname
= 0;
90 /* When non-zero, do not reject deprecated .gdb_index sections. */
91 int use_deprecated_index_sections
= 0;
95 /* When set, the file that we're processing is known to have debugging
96 info for C++ namespaces. GCC 3.3.x did not produce this information,
97 but later versions do. */
99 static int processing_has_namespace_info
;
101 static const struct objfile_data
*dwarf2_objfile_data_key
;
103 struct dwarf2_section_info
108 /* Not NULL if the section was actually mmapped. */
110 /* Page aligned size of mmapped area. */
111 bfd_size_type map_len
;
112 /* True if we have tried to read this section. */
116 typedef struct dwarf2_section_info dwarf2_section_info_def
;
117 DEF_VEC_O (dwarf2_section_info_def
);
119 /* All offsets in the index are of this type. It must be
120 architecture-independent. */
121 typedef uint32_t offset_type
;
123 DEF_VEC_I (offset_type
);
125 /* A description of the mapped index. The file format is described in
126 a comment by the code that writes the index. */
129 /* Index data format version. */
132 /* The total length of the buffer. */
135 /* A pointer to the address table data. */
136 const gdb_byte
*address_table
;
138 /* Size of the address table data in bytes. */
139 offset_type address_table_size
;
141 /* The symbol table, implemented as a hash table. */
142 const offset_type
*symbol_table
;
144 /* Size in slots, each slot is 2 offset_types. */
145 offset_type symbol_table_slots
;
147 /* A pointer to the constant pool. */
148 const char *constant_pool
;
151 /* Collection of data recorded per objfile.
152 This hangs off of dwarf2_objfile_data_key. */
154 struct dwarf2_per_objfile
156 struct dwarf2_section_info info
;
157 struct dwarf2_section_info abbrev
;
158 struct dwarf2_section_info line
;
159 struct dwarf2_section_info loc
;
160 struct dwarf2_section_info macinfo
;
161 struct dwarf2_section_info macro
;
162 struct dwarf2_section_info str
;
163 struct dwarf2_section_info ranges
;
164 struct dwarf2_section_info addr
;
165 struct dwarf2_section_info frame
;
166 struct dwarf2_section_info eh_frame
;
167 struct dwarf2_section_info gdb_index
;
169 VEC (dwarf2_section_info_def
) *types
;
172 struct objfile
*objfile
;
174 /* Table of all the compilation units. This is used to locate
175 the target compilation unit of a particular reference. */
176 struct dwarf2_per_cu_data
**all_comp_units
;
178 /* The number of compilation units in ALL_COMP_UNITS. */
181 /* The number of .debug_types-related CUs. */
184 /* The .debug_types-related CUs (TUs). */
185 struct dwarf2_per_cu_data
**all_type_units
;
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data
*read_in_chain
;
191 /* A table mapping .debug_types signatures to its signatured_type entry.
192 This is NULL if the .debug_types section hasn't been read in yet. */
193 htab_t signatured_types
;
195 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
196 This is NULL if the table hasn't been allocated yet. */
199 /* A flag indicating wether this objfile has a section loaded at a
201 int has_section_at_zero
;
203 /* True if we are using the mapped index,
204 or we are faking it for OBJF_READNOW's sake. */
205 unsigned char using_index
;
207 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
208 struct mapped_index
*index_table
;
210 /* When using index_table, this keeps track of all quick_file_names entries.
211 TUs can share line table entries with CUs or other TUs, and there can be
212 a lot more TUs than unique line tables, so we maintain a separate table
213 of all line table entries to support the sharing. */
214 htab_t quick_file_names_table
;
216 /* Set during partial symbol reading, to prevent queueing of full
218 int reading_partial_symbols
;
220 /* Table mapping type DIEs to their struct type *.
221 This is NULL if not allocated yet.
222 The mapping is done via (CU/TU signature + DIE offset) -> type. */
223 htab_t die_type_hash
;
226 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
228 /* Default names of the debugging sections. */
230 /* Note that if the debugging section has been compressed, it might
231 have a name like .zdebug_info. */
233 static const struct dwarf2_debug_sections dwarf2_elf_names
=
235 { ".debug_info", ".zdebug_info" },
236 { ".debug_abbrev", ".zdebug_abbrev" },
237 { ".debug_line", ".zdebug_line" },
238 { ".debug_loc", ".zdebug_loc" },
239 { ".debug_macinfo", ".zdebug_macinfo" },
240 { ".debug_macro", ".zdebug_macro" },
241 { ".debug_str", ".zdebug_str" },
242 { ".debug_ranges", ".zdebug_ranges" },
243 { ".debug_types", ".zdebug_types" },
244 { ".debug_addr", ".zdebug_addr" },
245 { ".debug_frame", ".zdebug_frame" },
246 { ".eh_frame", NULL
},
247 { ".gdb_index", ".zgdb_index" },
251 /* List of DWO sections. */
253 static const struct dwo_section_names
255 struct dwarf2_section_names abbrev_dwo
;
256 struct dwarf2_section_names info_dwo
;
257 struct dwarf2_section_names line_dwo
;
258 struct dwarf2_section_names loc_dwo
;
259 struct dwarf2_section_names str_dwo
;
260 struct dwarf2_section_names str_offsets_dwo
;
261 struct dwarf2_section_names types_dwo
;
265 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
266 { ".debug_info.dwo", ".zdebug_info.dwo" },
267 { ".debug_line.dwo", ".zdebug_line.dwo" },
268 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
269 { ".debug_str.dwo", ".zdebug_str.dwo" },
270 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
271 { ".debug_types.dwo", ".zdebug_types.dwo" },
274 /* local data types */
276 /* We hold several abbreviation tables in memory at the same time. */
277 #ifndef ABBREV_HASH_SIZE
278 #define ABBREV_HASH_SIZE 121
281 /* The data in a compilation unit header, after target2host
282 translation, looks like this. */
283 struct comp_unit_head
287 unsigned char addr_size
;
288 unsigned char signed_addr_p
;
289 sect_offset abbrev_offset
;
291 /* Size of file offsets; either 4 or 8. */
292 unsigned int offset_size
;
294 /* Size of the length field; either 4 or 12. */
295 unsigned int initial_length_size
;
297 /* Offset to the first byte of this compilation unit header in the
298 .debug_info section, for resolving relative reference dies. */
301 /* Offset to first die in this cu from the start of the cu.
302 This will be the first byte following the compilation unit header. */
303 cu_offset first_die_offset
;
306 /* Type used for delaying computation of method physnames.
307 See comments for compute_delayed_physnames. */
308 struct delayed_method_info
310 /* The type to which the method is attached, i.e., its parent class. */
313 /* The index of the method in the type's function fieldlists. */
316 /* The index of the method in the fieldlist. */
319 /* The name of the DIE. */
322 /* The DIE associated with this method. */
323 struct die_info
*die
;
326 typedef struct delayed_method_info delayed_method_info
;
327 DEF_VEC_O (delayed_method_info
);
329 /* Internal state when decoding a particular compilation unit. */
332 /* The objfile containing this compilation unit. */
333 struct objfile
*objfile
;
335 /* The header of the compilation unit. */
336 struct comp_unit_head header
;
338 /* Base address of this compilation unit. */
339 CORE_ADDR base_address
;
341 /* Non-zero if base_address has been set. */
344 /* The language we are debugging. */
345 enum language language
;
346 const struct language_defn
*language_defn
;
348 const char *producer
;
350 /* The generic symbol table building routines have separate lists for
351 file scope symbols and all all other scopes (local scopes). So
352 we need to select the right one to pass to add_symbol_to_list().
353 We do it by keeping a pointer to the correct list in list_in_scope.
355 FIXME: The original dwarf code just treated the file scope as the
356 first local scope, and all other local scopes as nested local
357 scopes, and worked fine. Check to see if we really need to
358 distinguish these in buildsym.c. */
359 struct pending
**list_in_scope
;
361 /* DWARF abbreviation table associated with this compilation unit. */
362 struct abbrev_info
**dwarf2_abbrevs
;
364 /* Storage for the abbrev table. */
365 struct obstack abbrev_obstack
;
367 /* Hash table holding all the loaded partial DIEs
368 with partial_die->offset.SECT_OFF as hash. */
371 /* Storage for things with the same lifetime as this read-in compilation
372 unit, including partial DIEs. */
373 struct obstack comp_unit_obstack
;
375 /* When multiple dwarf2_cu structures are living in memory, this field
376 chains them all together, so that they can be released efficiently.
377 We will probably also want a generation counter so that most-recently-used
378 compilation units are cached... */
379 struct dwarf2_per_cu_data
*read_in_chain
;
381 /* Backchain to our per_cu entry if the tree has been built. */
382 struct dwarf2_per_cu_data
*per_cu
;
384 /* How many compilation units ago was this CU last referenced? */
387 /* A hash table of DIE cu_offset for following references with
388 die_info->offset.sect_off as hash. */
391 /* Full DIEs if read in. */
392 struct die_info
*dies
;
394 /* A set of pointers to dwarf2_per_cu_data objects for compilation
395 units referenced by this one. Only set during full symbol processing;
396 partial symbol tables do not have dependencies. */
399 /* Header data from the line table, during full symbol processing. */
400 struct line_header
*line_header
;
402 /* A list of methods which need to have physnames computed
403 after all type information has been read. */
404 VEC (delayed_method_info
) *method_list
;
406 /* To be copied to symtab->call_site_htab. */
407 htab_t call_site_htab
;
409 /* Non-NULL if this CU came from a DWO file. */
410 struct dwo_unit
*dwo_unit
;
412 /* The DW_AT_addr_base attribute if present, zero otherwise
413 (zero is a valid value though).
414 Note this value comes from the stub CU/TU's DIE. */
417 /* Mark used when releasing cached dies. */
418 unsigned int mark
: 1;
420 /* This CU references .debug_loc. See the symtab->locations_valid field.
421 This test is imperfect as there may exist optimized debug code not using
422 any location list and still facing inlining issues if handled as
423 unoptimized code. For a future better test see GCC PR other/32998. */
424 unsigned int has_loclist
: 1;
426 /* These cache the results of producer_is_gxx_lt_4_6.
427 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
428 information is cached because profiling CU expansion showed
429 excessive time spent in producer_is_gxx_lt_4_6. */
430 unsigned int checked_producer
: 1;
431 unsigned int producer_is_gxx_lt_4_6
: 1;
433 /* Non-zero if DW_AT_addr_base was found.
434 Used when processing DWO files. */
435 unsigned int have_addr_base
: 1;
438 /* Persistent data held for a compilation unit, even when not
439 processing it. We put a pointer to this structure in the
440 read_symtab_private field of the psymtab. */
442 struct dwarf2_per_cu_data
444 /* The start offset and length of this compilation unit. 2**29-1
445 bytes should suffice to store the length of any compilation unit
446 - if it doesn't, GDB will fall over anyway.
447 NOTE: Unlike comp_unit_head.length, this length includes
449 If the DIE refers to a DWO file, this is always of the original die,
452 unsigned int length
: 29;
454 /* Flag indicating this compilation unit will be read in before
455 any of the current compilation units are processed. */
456 unsigned int queued
: 1;
458 /* This flag will be set when reading partial DIEs if we need to load
459 absolutely all DIEs for this compilation unit, instead of just the ones
460 we think are interesting. It gets set if we look for a DIE in the
461 hash table and don't find it. */
462 unsigned int load_all_dies
: 1;
464 /* Non-zero if this CU is from .debug_types. */
465 unsigned int is_debug_types
: 1;
467 /* The section this CU/TU lives in.
468 If the DIE refers to a DWO file, this is always the original die,
470 struct dwarf2_section_info
*info_or_types_section
;
472 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
473 of the CU cache it gets reset to NULL again. */
474 struct dwarf2_cu
*cu
;
476 /* The corresponding objfile.
477 Normally we can get the objfile from dwarf2_per_objfile.
478 However we can enter this file with just a "per_cu" handle. */
479 struct objfile
*objfile
;
481 /* When using partial symbol tables, the 'psymtab' field is active.
482 Otherwise the 'quick' field is active. */
485 /* The partial symbol table associated with this compilation unit,
486 or NULL for partial units (which do not have an associated
488 struct partial_symtab
*psymtab
;
490 /* Data needed by the "quick" functions. */
491 struct dwarf2_per_cu_quick_data
*quick
;
495 /* Entry in the signatured_types hash table. */
497 struct signatured_type
499 /* The type's signature. */
502 /* Offset in the TU of the type's DIE, as read from the TU header.
503 If the definition lives in a DWO file, this value is unusable. */
504 cu_offset type_offset_in_tu
;
506 /* Offset in the section of the type's DIE.
507 If the definition lives in a DWO file, this is the offset in the
508 .debug_types.dwo section.
509 The value is zero until the actual value is known.
510 Zero is otherwise not a valid section offset. */
511 sect_offset type_offset_in_section
;
513 /* The CU(/TU) of this type. */
514 struct dwarf2_per_cu_data per_cu
;
517 /* These sections are what may appear in a "dwo" file. */
521 struct dwarf2_section_info abbrev
;
522 struct dwarf2_section_info info
;
523 struct dwarf2_section_info line
;
524 struct dwarf2_section_info loc
;
525 struct dwarf2_section_info str
;
526 struct dwarf2_section_info str_offsets
;
527 VEC (dwarf2_section_info_def
) *types
;
530 /* Common bits of DWO CUs/TUs. */
534 /* Backlink to the containing struct dwo_file. */
535 struct dwo_file
*dwo_file
;
537 /* The "id" that distinguishes this CU/TU.
538 .debug_info calls this "dwo_id", .debug_types calls this "signature".
539 Since signatures came first, we stick with it for consistency. */
542 /* The section this CU/TU lives in, in the DWO file. */
543 struct dwarf2_section_info
*info_or_types_section
;
545 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
549 /* For types, offset in the type's DIE of the type defined by this TU. */
550 cu_offset type_offset_in_tu
;
553 /* Data for one DWO file. */
557 /* The DW_AT_GNU_dwo_name attribute.
558 We don't manage space for this, it's an attribute. */
559 const char *dwo_name
;
561 /* The bfd, when the file is open. Otherwise this is NULL. */
564 /* Section info for this file. */
565 struct dwo_sections sections
;
567 /* Table of CUs in the file.
568 Each element is a struct dwo_unit. */
571 /* Table of TUs in the file.
572 Each element is a struct dwo_unit. */
576 /* Struct used to pass misc. parameters to read_die_and_children, et
577 al. which are used for both .debug_info and .debug_types dies.
578 All parameters here are unchanging for the life of the call. This
579 struct exists to abstract away the constant parameters of die reading. */
581 struct die_reader_specs
583 /* die_section->asection->owner. */
586 /* The CU of the DIE we are parsing. */
587 struct dwarf2_cu
*cu
;
589 /* Non-NULL if reading a DWO file. */
590 struct dwo_file
*dwo_file
;
592 /* The section the die comes from.
593 This is either .debug_info or .debug_types, or the .dwo variants. */
594 struct dwarf2_section_info
*die_section
;
596 /* die_section->buffer. */
600 /* Type of function passed to init_cutu_and_read_dies, et.al. */
601 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
603 struct die_info
*comp_unit_die
,
607 /* The line number information for a compilation unit (found in the
608 .debug_line section) begins with a "statement program header",
609 which contains the following information. */
612 unsigned int total_length
;
613 unsigned short version
;
614 unsigned int header_length
;
615 unsigned char minimum_instruction_length
;
616 unsigned char maximum_ops_per_instruction
;
617 unsigned char default_is_stmt
;
619 unsigned char line_range
;
620 unsigned char opcode_base
;
622 /* standard_opcode_lengths[i] is the number of operands for the
623 standard opcode whose value is i. This means that
624 standard_opcode_lengths[0] is unused, and the last meaningful
625 element is standard_opcode_lengths[opcode_base - 1]. */
626 unsigned char *standard_opcode_lengths
;
628 /* The include_directories table. NOTE! These strings are not
629 allocated with xmalloc; instead, they are pointers into
630 debug_line_buffer. If you try to free them, `free' will get
632 unsigned int num_include_dirs
, include_dirs_size
;
635 /* The file_names table. NOTE! These strings are not allocated
636 with xmalloc; instead, they are pointers into debug_line_buffer.
637 Don't try to free them directly. */
638 unsigned int num_file_names
, file_names_size
;
642 unsigned int dir_index
;
643 unsigned int mod_time
;
645 int included_p
; /* Non-zero if referenced by the Line Number Program. */
646 struct symtab
*symtab
; /* The associated symbol table, if any. */
649 /* The start and end of the statement program following this
650 header. These point into dwarf2_per_objfile->line_buffer. */
651 gdb_byte
*statement_program_start
, *statement_program_end
;
654 /* When we construct a partial symbol table entry we only
655 need this much information. */
656 struct partial_die_info
658 /* Offset of this DIE. */
661 /* DWARF-2 tag for this DIE. */
662 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
664 /* Assorted flags describing the data found in this DIE. */
665 unsigned int has_children
: 1;
666 unsigned int is_external
: 1;
667 unsigned int is_declaration
: 1;
668 unsigned int has_type
: 1;
669 unsigned int has_specification
: 1;
670 unsigned int has_pc_info
: 1;
671 unsigned int may_be_inlined
: 1;
673 /* Flag set if the SCOPE field of this structure has been
675 unsigned int scope_set
: 1;
677 /* Flag set if the DIE has a byte_size attribute. */
678 unsigned int has_byte_size
: 1;
680 /* Flag set if any of the DIE's children are template arguments. */
681 unsigned int has_template_arguments
: 1;
683 /* Flag set if fixup_partial_die has been called on this die. */
684 unsigned int fixup_called
: 1;
686 /* The name of this DIE. Normally the value of DW_AT_name, but
687 sometimes a default name for unnamed DIEs. */
690 /* The linkage name, if present. */
691 const char *linkage_name
;
693 /* The scope to prepend to our children. This is generally
694 allocated on the comp_unit_obstack, so will disappear
695 when this compilation unit leaves the cache. */
698 /* The location description associated with this DIE, if any. */
699 struct dwarf_block
*locdesc
;
701 /* If HAS_PC_INFO, the PC range associated with this DIE. */
705 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
706 DW_AT_sibling, if any. */
707 /* NOTE: This member isn't strictly necessary, read_partial_die could
708 return DW_AT_sibling values to its caller load_partial_dies. */
711 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
712 DW_AT_specification (or DW_AT_abstract_origin or
714 sect_offset spec_offset
;
716 /* Pointers to this DIE's parent, first child, and next sibling,
718 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
721 /* This data structure holds the information of an abbrev. */
724 unsigned int number
; /* number identifying abbrev */
725 enum dwarf_tag tag
; /* dwarf tag */
726 unsigned short has_children
; /* boolean */
727 unsigned short num_attrs
; /* number of attributes */
728 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
729 struct abbrev_info
*next
; /* next in chain */
734 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
735 ENUM_BITFIELD(dwarf_form
) form
: 16;
738 /* Attributes have a name and a value. */
741 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
742 ENUM_BITFIELD(dwarf_form
) form
: 15;
744 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
745 field should be in u.str (existing only for DW_STRING) but it is kept
746 here for better struct attribute alignment. */
747 unsigned int string_is_canonical
: 1;
752 struct dwarf_block
*blk
;
756 struct signatured_type
*signatured_type
;
761 /* This data structure holds a complete die structure. */
764 /* DWARF-2 tag for this DIE. */
765 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
767 /* Number of attributes */
768 unsigned char num_attrs
;
770 /* True if we're presently building the full type name for the
771 type derived from this DIE. */
772 unsigned char building_fullname
: 1;
777 /* Offset in .debug_info or .debug_types section. */
780 /* The dies in a compilation unit form an n-ary tree. PARENT
781 points to this die's parent; CHILD points to the first child of
782 this node; and all the children of a given node are chained
783 together via their SIBLING fields. */
784 struct die_info
*child
; /* Its first child, if any. */
785 struct die_info
*sibling
; /* Its next sibling, if any. */
786 struct die_info
*parent
; /* Its parent, if any. */
788 /* An array of attributes, with NUM_ATTRS elements. There may be
789 zero, but it's not common and zero-sized arrays are not
790 sufficiently portable C. */
791 struct attribute attrs
[1];
794 /* Get at parts of an attribute structure. */
796 #define DW_STRING(attr) ((attr)->u.str)
797 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
798 #define DW_UNSND(attr) ((attr)->u.unsnd)
799 #define DW_BLOCK(attr) ((attr)->u.blk)
800 #define DW_SND(attr) ((attr)->u.snd)
801 #define DW_ADDR(attr) ((attr)->u.addr)
802 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
804 /* Blocks are a bunch of untyped bytes. */
809 /* Valid only if SIZE is not zero. */
813 #ifndef ATTR_ALLOC_CHUNK
814 #define ATTR_ALLOC_CHUNK 4
817 /* Allocate fields for structs, unions and enums in this size. */
818 #ifndef DW_FIELD_ALLOC_CHUNK
819 #define DW_FIELD_ALLOC_CHUNK 4
822 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
823 but this would require a corresponding change in unpack_field_as_long
825 static int bits_per_byte
= 8;
827 /* The routines that read and process dies for a C struct or C++ class
828 pass lists of data member fields and lists of member function fields
829 in an instance of a field_info structure, as defined below. */
832 /* List of data member and baseclasses fields. */
835 struct nextfield
*next
;
840 *fields
, *baseclasses
;
842 /* Number of fields (including baseclasses). */
845 /* Number of baseclasses. */
848 /* Set if the accesibility of one of the fields is not public. */
849 int non_public_fields
;
851 /* Member function fields array, entries are allocated in the order they
852 are encountered in the object file. */
855 struct nextfnfield
*next
;
856 struct fn_field fnfield
;
860 /* Member function fieldlist array, contains name of possibly overloaded
861 member function, number of overloaded member functions and a pointer
862 to the head of the member function field chain. */
867 struct nextfnfield
*head
;
871 /* Number of entries in the fnfieldlists array. */
874 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
875 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
876 struct typedef_field_list
878 struct typedef_field field
;
879 struct typedef_field_list
*next
;
882 unsigned typedef_field_list_count
;
885 /* One item on the queue of compilation units to read in full symbols
887 struct dwarf2_queue_item
889 struct dwarf2_per_cu_data
*per_cu
;
890 struct dwarf2_queue_item
*next
;
893 /* The current queue. */
894 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
896 /* Loaded secondary compilation units are kept in memory until they
897 have not been referenced for the processing of this many
898 compilation units. Set this to zero to disable caching. Cache
899 sizes of up to at least twenty will improve startup time for
900 typical inter-CU-reference binaries, at an obvious memory cost. */
901 static int dwarf2_max_cache_age
= 5;
903 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
904 struct cmd_list_element
*c
, const char *value
)
906 fprintf_filtered (file
, _("The upper bound on the age of cached "
907 "dwarf2 compilation units is %s.\n"),
912 /* Various complaints about symbol reading that don't abort the process. */
915 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
917 complaint (&symfile_complaints
,
918 _("statement list doesn't fit in .debug_line section"));
922 dwarf2_debug_line_missing_file_complaint (void)
924 complaint (&symfile_complaints
,
925 _(".debug_line section has line data without a file"));
929 dwarf2_debug_line_missing_end_sequence_complaint (void)
931 complaint (&symfile_complaints
,
932 _(".debug_line section has line "
933 "program sequence without an end"));
937 dwarf2_complex_location_expr_complaint (void)
939 complaint (&symfile_complaints
, _("location expression too complex"));
943 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
946 complaint (&symfile_complaints
,
947 _("const value length mismatch for '%s', got %d, expected %d"),
952 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
954 complaint (&symfile_complaints
,
955 _("macro info runs off end of `%s' section"),
956 section
->asection
->name
);
960 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
962 complaint (&symfile_complaints
,
963 _("macro debug info contains a "
964 "malformed macro definition:\n`%s'"),
969 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
971 complaint (&symfile_complaints
,
972 _("invalid attribute class or form for '%s' in '%s'"),
976 /* local function prototypes */
978 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
980 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
983 static void dwarf2_find_base_address (struct die_info
*die
,
984 struct dwarf2_cu
*cu
);
986 static void dwarf2_build_psymtabs_hard (struct objfile
*);
988 static void scan_partial_symbols (struct partial_die_info
*,
989 CORE_ADDR
*, CORE_ADDR
*,
990 int, struct dwarf2_cu
*);
992 static void add_partial_symbol (struct partial_die_info
*,
995 static void add_partial_namespace (struct partial_die_info
*pdi
,
996 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
997 int need_pc
, struct dwarf2_cu
*cu
);
999 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1000 CORE_ADDR
*highpc
, int need_pc
,
1001 struct dwarf2_cu
*cu
);
1003 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1004 struct dwarf2_cu
*cu
);
1006 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1007 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1008 int need_pc
, struct dwarf2_cu
*cu
);
1010 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1012 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1014 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1015 struct dwarf2_section_info
*);
1017 static void dwarf2_free_abbrev_table (void *);
1019 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1021 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1022 struct dwarf2_cu
*);
1024 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1025 struct dwarf2_cu
*);
1027 static struct partial_die_info
*load_partial_dies
1028 (const struct die_reader_specs
*, gdb_byte
*, int);
1030 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1031 struct partial_die_info
*,
1032 struct abbrev_info
*,
1036 static struct partial_die_info
*find_partial_die (sect_offset
,
1037 struct dwarf2_cu
*);
1039 static void fixup_partial_die (struct partial_die_info
*,
1040 struct dwarf2_cu
*);
1042 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1043 struct attribute
*, struct attr_abbrev
*,
1046 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1048 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1050 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1052 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1054 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1056 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1059 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1061 static LONGEST read_checked_initial_length_and_offset
1062 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1063 unsigned int *, unsigned int *);
1065 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1068 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1070 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1072 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1074 static char *read_indirect_string (bfd
*, gdb_byte
*,
1075 const struct comp_unit_head
*,
1078 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1080 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1082 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1085 static char *read_str_index (const struct die_reader_specs
*reader
,
1086 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1088 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1090 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1092 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1093 struct dwarf2_cu
*);
1095 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1100 struct dwarf2_cu
*cu
);
1102 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1104 static struct die_info
*die_specification (struct die_info
*die
,
1105 struct dwarf2_cu
**);
1107 static void free_line_header (struct line_header
*lh
);
1109 static void add_file_name (struct line_header
*, char *, unsigned int,
1110 unsigned int, unsigned int);
1112 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1113 struct dwarf2_cu
*cu
);
1115 static void dwarf_decode_lines (struct line_header
*, const char *,
1116 struct dwarf2_cu
*, struct partial_symtab
*,
1119 static void dwarf2_start_subfile (char *, const char *, const char *);
1121 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1122 struct dwarf2_cu
*);
1124 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1125 struct dwarf2_cu
*, struct symbol
*);
1127 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1128 struct dwarf2_cu
*);
1130 static void dwarf2_const_value_attr (struct attribute
*attr
,
1133 struct obstack
*obstack
,
1134 struct dwarf2_cu
*cu
, LONGEST
*value
,
1136 struct dwarf2_locexpr_baton
**baton
);
1138 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1140 static int need_gnat_info (struct dwarf2_cu
*);
1142 static struct type
*die_descriptive_type (struct die_info
*,
1143 struct dwarf2_cu
*);
1145 static void set_descriptive_type (struct type
*, struct die_info
*,
1146 struct dwarf2_cu
*);
1148 static struct type
*die_containing_type (struct die_info
*,
1149 struct dwarf2_cu
*);
1151 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1152 struct dwarf2_cu
*);
1154 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1156 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1158 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1160 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1161 const char *suffix
, int physname
,
1162 struct dwarf2_cu
*cu
);
1164 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1166 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1168 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1170 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1172 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1174 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1175 struct dwarf2_cu
*, struct partial_symtab
*);
1177 static int dwarf2_get_pc_bounds (struct die_info
*,
1178 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1179 struct partial_symtab
*);
1181 static void get_scope_pc_bounds (struct die_info
*,
1182 CORE_ADDR
*, CORE_ADDR
*,
1183 struct dwarf2_cu
*);
1185 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1186 CORE_ADDR
, struct dwarf2_cu
*);
1188 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1189 struct dwarf2_cu
*);
1191 static void dwarf2_attach_fields_to_type (struct field_info
*,
1192 struct type
*, struct dwarf2_cu
*);
1194 static void dwarf2_add_member_fn (struct field_info
*,
1195 struct die_info
*, struct type
*,
1196 struct dwarf2_cu
*);
1198 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1200 struct dwarf2_cu
*);
1202 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1204 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1206 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1208 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1210 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1212 static struct type
*read_module_type (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static const char *namespace_name (struct die_info
*die
,
1216 int *is_anonymous
, struct dwarf2_cu
*);
1218 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1220 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1222 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1223 struct dwarf2_cu
*);
1225 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1227 gdb_byte
**new_info_ptr
,
1228 struct die_info
*parent
);
1230 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1232 gdb_byte
**new_info_ptr
,
1233 struct die_info
*parent
);
1235 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1236 struct die_info
**, gdb_byte
*, int *, int);
1238 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1239 struct die_info
**, gdb_byte
*, int *);
1241 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1243 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1246 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1248 static const char *dwarf2_full_name (char *name
,
1249 struct die_info
*die
,
1250 struct dwarf2_cu
*cu
);
1252 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1253 struct dwarf2_cu
**);
1255 static const char *dwarf_tag_name (unsigned int);
1257 static const char *dwarf_attr_name (unsigned int);
1259 static const char *dwarf_form_name (unsigned int);
1261 static char *dwarf_bool_name (unsigned int);
1263 static const char *dwarf_type_encoding_name (unsigned int);
1265 static struct die_info
*sibling_die (struct die_info
*);
1267 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1269 static void dump_die_for_error (struct die_info
*);
1271 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1274 /*static*/ void dump_die (struct die_info
*, int max_level
);
1276 static void store_in_ref_table (struct die_info
*,
1277 struct dwarf2_cu
*);
1279 static int is_ref_attr (struct attribute
*);
1281 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1283 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1285 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1287 struct dwarf2_cu
**);
1289 static struct die_info
*follow_die_ref (struct die_info
*,
1291 struct dwarf2_cu
**);
1293 static struct die_info
*follow_die_sig (struct die_info
*,
1295 struct dwarf2_cu
**);
1297 static struct signatured_type
*lookup_signatured_type_at_offset
1298 (struct objfile
*objfile
,
1299 struct dwarf2_section_info
*section
, sect_offset offset
);
1301 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1303 static void read_signatured_type (struct signatured_type
*);
1305 /* memory allocation interface */
1307 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1309 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1311 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1313 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1314 char *, bfd
*, struct dwarf2_cu
*,
1315 struct dwarf2_section_info
*,
1318 static int attr_form_is_block (struct attribute
*);
1320 static int attr_form_is_section_offset (struct attribute
*);
1322 static int attr_form_is_constant (struct attribute
*);
1324 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1325 struct dwarf2_loclist_baton
*baton
,
1326 struct attribute
*attr
);
1328 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1330 struct dwarf2_cu
*cu
);
1332 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1334 struct abbrev_info
*abbrev
);
1336 static void free_stack_comp_unit (void *);
1338 static hashval_t
partial_die_hash (const void *item
);
1340 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1342 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1343 (sect_offset offset
, struct objfile
*objfile
);
1345 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1346 struct dwarf2_per_cu_data
*per_cu
);
1348 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1349 struct die_info
*comp_unit_die
);
1351 static void free_heap_comp_unit (void *);
1353 static void free_cached_comp_units (void *);
1355 static void age_cached_comp_units (void);
1357 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1359 static struct type
*set_die_type (struct die_info
*, struct type
*,
1360 struct dwarf2_cu
*);
1362 static void create_all_comp_units (struct objfile
*);
1364 static int create_all_type_units (struct objfile
*);
1366 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1368 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1370 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1371 struct dwarf2_per_cu_data
*);
1373 static void dwarf2_mark (struct dwarf2_cu
*);
1375 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1377 static struct type
*get_die_type_at_offset (sect_offset
,
1378 struct dwarf2_per_cu_data
*per_cu
);
1380 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1382 static void dwarf2_release_queue (void *dummy
);
1384 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1386 static void process_queue (void);
1388 static void find_file_and_directory (struct die_info
*die
,
1389 struct dwarf2_cu
*cu
,
1390 char **name
, char **comp_dir
);
1392 static char *file_full_name (int file
, struct line_header
*lh
,
1393 const char *comp_dir
);
1395 static gdb_byte
*read_and_check_comp_unit_head
1396 (struct comp_unit_head
*header
,
1397 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1398 int is_debug_types_section
);
1400 static void init_cutu_and_read_dies
1401 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1402 die_reader_func_ftype
*die_reader_func
, void *data
);
1404 static void init_cutu_and_read_dies_simple
1405 (struct dwarf2_per_cu_data
*this_cu
,
1406 die_reader_func_ftype
*die_reader_func
, void *data
);
1408 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1410 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*);
1412 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1414 static struct dwo_unit
*lookup_dwo_comp_unit
1415 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1417 static struct dwo_unit
*lookup_dwo_type_unit
1418 (struct signatured_type
*, char *, const char *);
1420 static void free_dwo_file_cleanup (void *);
1422 static void munmap_section_buffer (struct dwarf2_section_info
*);
1426 /* Convert VALUE between big- and little-endian. */
1428 byte_swap (offset_type value
)
1432 result
= (value
& 0xff) << 24;
1433 result
|= (value
& 0xff00) << 8;
1434 result
|= (value
& 0xff0000) >> 8;
1435 result
|= (value
& 0xff000000) >> 24;
1439 #define MAYBE_SWAP(V) byte_swap (V)
1442 #define MAYBE_SWAP(V) (V)
1443 #endif /* WORDS_BIGENDIAN */
1445 /* The suffix for an index file. */
1446 #define INDEX_SUFFIX ".gdb-index"
1448 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1449 struct dwarf2_cu
*cu
);
1451 /* Try to locate the sections we need for DWARF 2 debugging
1452 information and return true if we have enough to do something.
1453 NAMES points to the dwarf2 section names, or is NULL if the standard
1454 ELF names are used. */
1457 dwarf2_has_info (struct objfile
*objfile
,
1458 const struct dwarf2_debug_sections
*names
)
1460 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1461 if (!dwarf2_per_objfile
)
1463 /* Initialize per-objfile state. */
1464 struct dwarf2_per_objfile
*data
1465 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1467 memset (data
, 0, sizeof (*data
));
1468 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1469 dwarf2_per_objfile
= data
;
1471 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1473 dwarf2_per_objfile
->objfile
= objfile
;
1475 return (dwarf2_per_objfile
->info
.asection
!= NULL
1476 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1479 /* When loading sections, we look either for uncompressed section or for
1480 compressed section names. */
1483 section_is_p (const char *section_name
,
1484 const struct dwarf2_section_names
*names
)
1486 if (names
->normal
!= NULL
1487 && strcmp (section_name
, names
->normal
) == 0)
1489 if (names
->compressed
!= NULL
1490 && strcmp (section_name
, names
->compressed
) == 0)
1495 /* This function is mapped across the sections and remembers the
1496 offset and size of each of the debugging sections we are interested
1500 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1502 const struct dwarf2_debug_sections
*names
;
1505 names
= &dwarf2_elf_names
;
1507 names
= (const struct dwarf2_debug_sections
*) vnames
;
1509 if (section_is_p (sectp
->name
, &names
->info
))
1511 dwarf2_per_objfile
->info
.asection
= sectp
;
1512 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1514 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1516 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1517 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1519 else if (section_is_p (sectp
->name
, &names
->line
))
1521 dwarf2_per_objfile
->line
.asection
= sectp
;
1522 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1524 else if (section_is_p (sectp
->name
, &names
->loc
))
1526 dwarf2_per_objfile
->loc
.asection
= sectp
;
1527 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1529 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1531 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1532 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1534 else if (section_is_p (sectp
->name
, &names
->macro
))
1536 dwarf2_per_objfile
->macro
.asection
= sectp
;
1537 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1539 else if (section_is_p (sectp
->name
, &names
->str
))
1541 dwarf2_per_objfile
->str
.asection
= sectp
;
1542 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1544 else if (section_is_p (sectp
->name
, &names
->addr
))
1546 dwarf2_per_objfile
->addr
.asection
= sectp
;
1547 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1549 else if (section_is_p (sectp
->name
, &names
->frame
))
1551 dwarf2_per_objfile
->frame
.asection
= sectp
;
1552 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1554 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1556 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1558 if (aflag
& SEC_HAS_CONTENTS
)
1560 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1561 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1564 else if (section_is_p (sectp
->name
, &names
->ranges
))
1566 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1567 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1569 else if (section_is_p (sectp
->name
, &names
->types
))
1571 struct dwarf2_section_info type_section
;
1573 memset (&type_section
, 0, sizeof (type_section
));
1574 type_section
.asection
= sectp
;
1575 type_section
.size
= bfd_get_section_size (sectp
);
1577 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1580 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1582 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1583 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1586 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1587 && bfd_section_vma (abfd
, sectp
) == 0)
1588 dwarf2_per_objfile
->has_section_at_zero
= 1;
1591 /* Decompress a section that was compressed using zlib. Store the
1592 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1595 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1596 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1598 bfd
*abfd
= sectp
->owner
;
1600 error (_("Support for zlib-compressed DWARF data (from '%s') "
1601 "is disabled in this copy of GDB"),
1602 bfd_get_filename (abfd
));
1604 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1605 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1606 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1607 bfd_size_type uncompressed_size
;
1608 gdb_byte
*uncompressed_buffer
;
1611 int header_size
= 12;
1613 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1614 || bfd_bread (compressed_buffer
,
1615 compressed_size
, abfd
) != compressed_size
)
1616 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1617 bfd_get_filename (abfd
));
1619 /* Read the zlib header. In this case, it should be "ZLIB" followed
1620 by the uncompressed section size, 8 bytes in big-endian order. */
1621 if (compressed_size
< header_size
1622 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1623 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1624 bfd_get_filename (abfd
));
1625 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1626 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1627 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1628 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1629 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1630 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1631 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1632 uncompressed_size
+= compressed_buffer
[11];
1634 /* It is possible the section consists of several compressed
1635 buffers concatenated together, so we uncompress in a loop. */
1639 strm
.avail_in
= compressed_size
- header_size
;
1640 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1641 strm
.avail_out
= uncompressed_size
;
1642 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1644 rc
= inflateInit (&strm
);
1645 while (strm
.avail_in
> 0)
1648 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1649 bfd_get_filename (abfd
), rc
);
1650 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1651 + (uncompressed_size
- strm
.avail_out
));
1652 rc
= inflate (&strm
, Z_FINISH
);
1653 if (rc
!= Z_STREAM_END
)
1654 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1655 bfd_get_filename (abfd
), rc
);
1656 rc
= inflateReset (&strm
);
1658 rc
= inflateEnd (&strm
);
1660 || strm
.avail_out
!= 0)
1661 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1662 bfd_get_filename (abfd
), rc
);
1664 do_cleanups (cleanup
);
1665 *outbuf
= uncompressed_buffer
;
1666 *outsize
= uncompressed_size
;
1670 /* A helper function that decides whether a section is empty,
1674 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1676 return info
->asection
== NULL
|| info
->size
== 0;
1679 /* Read the contents of the section INFO.
1680 OBJFILE is the main object file, but not necessarily the file where
1681 the section comes from. E.g., for DWO files INFO->asection->owner
1682 is the bfd of the DWO file.
1683 If the section is compressed, uncompress it before returning. */
1686 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1688 asection
*sectp
= info
->asection
;
1690 gdb_byte
*buf
, *retbuf
;
1691 unsigned char header
[4];
1695 info
->buffer
= NULL
;
1696 info
->map_addr
= NULL
;
1699 if (dwarf2_section_empty_p (info
))
1702 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1703 abfd
= sectp
->owner
;
1705 /* Check if the file has a 4-byte header indicating compression. */
1706 if (info
->size
> sizeof (header
)
1707 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1708 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1710 /* Upon decompression, update the buffer and its size. */
1711 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1713 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1721 pagesize
= getpagesize ();
1723 /* Only try to mmap sections which are large enough: we don't want to
1724 waste space due to fragmentation. Also, only try mmap for sections
1725 without relocations. */
1727 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1729 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1730 MAP_PRIVATE
, sectp
->filepos
,
1731 &info
->map_addr
, &info
->map_len
);
1733 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1735 #if HAVE_POSIX_MADVISE
1736 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1743 /* If we get here, we are a normal, not-compressed section. */
1745 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1747 /* When debugging .o files, we may need to apply relocations; see
1748 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1749 We never compress sections in .o files, so we only need to
1750 try this when the section is not compressed. */
1751 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1754 info
->buffer
= retbuf
;
1758 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1759 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1760 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1761 bfd_get_filename (abfd
));
1764 /* A helper function that returns the size of a section in a safe way.
1765 If you are positive that the section has been read before using the
1766 size, then it is safe to refer to the dwarf2_section_info object's
1767 "size" field directly. In other cases, you must call this
1768 function, because for compressed sections the size field is not set
1769 correctly until the section has been read. */
1771 static bfd_size_type
1772 dwarf2_section_size (struct objfile
*objfile
,
1773 struct dwarf2_section_info
*info
)
1776 dwarf2_read_section (objfile
, info
);
1780 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1784 dwarf2_get_section_info (struct objfile
*objfile
,
1785 enum dwarf2_section_enum sect
,
1786 asection
**sectp
, gdb_byte
**bufp
,
1787 bfd_size_type
*sizep
)
1789 struct dwarf2_per_objfile
*data
1790 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1791 struct dwarf2_section_info
*info
;
1793 /* We may see an objfile without any DWARF, in which case we just
1804 case DWARF2_DEBUG_FRAME
:
1805 info
= &data
->frame
;
1807 case DWARF2_EH_FRAME
:
1808 info
= &data
->eh_frame
;
1811 gdb_assert_not_reached ("unexpected section");
1814 dwarf2_read_section (objfile
, info
);
1816 *sectp
= info
->asection
;
1817 *bufp
= info
->buffer
;
1818 *sizep
= info
->size
;
1822 /* DWARF quick_symbols_functions support. */
1824 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1825 unique line tables, so we maintain a separate table of all .debug_line
1826 derived entries to support the sharing.
1827 All the quick functions need is the list of file names. We discard the
1828 line_header when we're done and don't need to record it here. */
1829 struct quick_file_names
1831 /* The offset in .debug_line of the line table. We hash on this. */
1832 unsigned int offset
;
1834 /* The number of entries in file_names, real_names. */
1835 unsigned int num_file_names
;
1837 /* The file names from the line table, after being run through
1839 const char **file_names
;
1841 /* The file names from the line table after being run through
1842 gdb_realpath. These are computed lazily. */
1843 const char **real_names
;
1846 /* When using the index (and thus not using psymtabs), each CU has an
1847 object of this type. This is used to hold information needed by
1848 the various "quick" methods. */
1849 struct dwarf2_per_cu_quick_data
1851 /* The file table. This can be NULL if there was no file table
1852 or it's currently not read in.
1853 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1854 struct quick_file_names
*file_names
;
1856 /* The corresponding symbol table. This is NULL if symbols for this
1857 CU have not yet been read. */
1858 struct symtab
*symtab
;
1860 /* A temporary mark bit used when iterating over all CUs in
1861 expand_symtabs_matching. */
1862 unsigned int mark
: 1;
1864 /* True if we've tried to read the file table and found there isn't one.
1865 There will be no point in trying to read it again next time. */
1866 unsigned int no_file_data
: 1;
1869 /* Hash function for a quick_file_names. */
1872 hash_file_name_entry (const void *e
)
1874 const struct quick_file_names
*file_data
= e
;
1876 return file_data
->offset
;
1879 /* Equality function for a quick_file_names. */
1882 eq_file_name_entry (const void *a
, const void *b
)
1884 const struct quick_file_names
*ea
= a
;
1885 const struct quick_file_names
*eb
= b
;
1887 return ea
->offset
== eb
->offset
;
1890 /* Delete function for a quick_file_names. */
1893 delete_file_name_entry (void *e
)
1895 struct quick_file_names
*file_data
= e
;
1898 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1900 xfree ((void*) file_data
->file_names
[i
]);
1901 if (file_data
->real_names
)
1902 xfree ((void*) file_data
->real_names
[i
]);
1905 /* The space for the struct itself lives on objfile_obstack,
1906 so we don't free it here. */
1909 /* Create a quick_file_names hash table. */
1912 create_quick_file_names_table (unsigned int nr_initial_entries
)
1914 return htab_create_alloc (nr_initial_entries
,
1915 hash_file_name_entry
, eq_file_name_entry
,
1916 delete_file_name_entry
, xcalloc
, xfree
);
1919 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1920 have to be created afterwards. You should call age_cached_comp_units after
1921 processing PER_CU->CU. dw2_setup must have been already called. */
1924 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1926 if (per_cu
->is_debug_types
)
1927 load_full_type_unit (per_cu
);
1929 load_full_comp_unit (per_cu
);
1931 gdb_assert (per_cu
->cu
!= NULL
);
1933 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1936 /* Read in the symbols for PER_CU. */
1939 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1941 struct cleanup
*back_to
;
1943 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1945 queue_comp_unit (per_cu
);
1951 /* Age the cache, releasing compilation units that have not
1952 been used recently. */
1953 age_cached_comp_units ();
1955 do_cleanups (back_to
);
1958 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1959 the objfile from which this CU came. Returns the resulting symbol
1962 static struct symtab
*
1963 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1965 if (!per_cu
->v
.quick
->symtab
)
1967 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1968 increment_reading_symtab ();
1969 dw2_do_instantiate_symtab (per_cu
);
1970 do_cleanups (back_to
);
1972 return per_cu
->v
.quick
->symtab
;
1975 /* Return the CU given its index. */
1977 static struct dwarf2_per_cu_data
*
1978 dw2_get_cu (int index
)
1980 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1982 index
-= dwarf2_per_objfile
->n_comp_units
;
1983 return dwarf2_per_objfile
->all_type_units
[index
];
1985 return dwarf2_per_objfile
->all_comp_units
[index
];
1988 /* A helper function that knows how to read a 64-bit value in a way
1989 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1993 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1995 if (sizeof (ULONGEST
) < 8)
1999 /* Ignore the upper 4 bytes if they are all zero. */
2000 for (i
= 0; i
< 4; ++i
)
2001 if (bytes
[i
+ 4] != 0)
2004 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2007 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2011 /* Read the CU list from the mapped index, and use it to create all
2012 the CU objects for this objfile. Return 0 if something went wrong,
2013 1 if everything went ok. */
2016 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2017 offset_type cu_list_elements
)
2021 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2022 dwarf2_per_objfile
->all_comp_units
2023 = obstack_alloc (&objfile
->objfile_obstack
,
2024 dwarf2_per_objfile
->n_comp_units
2025 * sizeof (struct dwarf2_per_cu_data
*));
2027 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2029 struct dwarf2_per_cu_data
*the_cu
;
2030 ULONGEST offset
, length
;
2032 if (!extract_cu_value (cu_list
, &offset
)
2033 || !extract_cu_value (cu_list
+ 8, &length
))
2037 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2038 struct dwarf2_per_cu_data
);
2039 the_cu
->offset
.sect_off
= offset
;
2040 the_cu
->length
= length
;
2041 the_cu
->objfile
= objfile
;
2042 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2043 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2044 struct dwarf2_per_cu_quick_data
);
2045 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2051 /* Create the signatured type hash table from the index. */
2054 create_signatured_type_table_from_index (struct objfile
*objfile
,
2055 struct dwarf2_section_info
*section
,
2056 const gdb_byte
*bytes
,
2057 offset_type elements
)
2060 htab_t sig_types_hash
;
2062 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2063 dwarf2_per_objfile
->all_type_units
2064 = obstack_alloc (&objfile
->objfile_obstack
,
2065 dwarf2_per_objfile
->n_type_units
2066 * sizeof (struct dwarf2_per_cu_data
*));
2068 sig_types_hash
= allocate_signatured_type_table (objfile
);
2070 for (i
= 0; i
< elements
; i
+= 3)
2072 struct signatured_type
*sig_type
;
2073 ULONGEST offset
, type_offset_in_tu
, signature
;
2076 if (!extract_cu_value (bytes
, &offset
)
2077 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2079 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2082 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2083 struct signatured_type
);
2084 sig_type
->signature
= signature
;
2085 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2086 sig_type
->per_cu
.is_debug_types
= 1;
2087 sig_type
->per_cu
.info_or_types_section
= section
;
2088 sig_type
->per_cu
.offset
.sect_off
= offset
;
2089 sig_type
->per_cu
.objfile
= objfile
;
2090 sig_type
->per_cu
.v
.quick
2091 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2092 struct dwarf2_per_cu_quick_data
);
2094 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2097 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2100 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2105 /* Read the address map data from the mapped index, and use it to
2106 populate the objfile's psymtabs_addrmap. */
2109 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2111 const gdb_byte
*iter
, *end
;
2112 struct obstack temp_obstack
;
2113 struct addrmap
*mutable_map
;
2114 struct cleanup
*cleanup
;
2117 obstack_init (&temp_obstack
);
2118 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2119 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2121 iter
= index
->address_table
;
2122 end
= iter
+ index
->address_table_size
;
2124 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2128 ULONGEST hi
, lo
, cu_index
;
2129 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2131 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2133 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2136 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2137 dw2_get_cu (cu_index
));
2140 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2141 &objfile
->objfile_obstack
);
2142 do_cleanups (cleanup
);
2145 /* The hash function for strings in the mapped index. This is the same as
2146 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2147 implementation. This is necessary because the hash function is tied to the
2148 format of the mapped index file. The hash values do not have to match with
2151 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2154 mapped_index_string_hash (int index_version
, const void *p
)
2156 const unsigned char *str
= (const unsigned char *) p
;
2160 while ((c
= *str
++) != 0)
2162 if (index_version
>= 5)
2164 r
= r
* 67 + c
- 113;
2170 /* Find a slot in the mapped index INDEX for the object named NAME.
2171 If NAME is found, set *VEC_OUT to point to the CU vector in the
2172 constant pool and return 1. If NAME cannot be found, return 0. */
2175 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2176 offset_type
**vec_out
)
2178 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2180 offset_type slot
, step
;
2181 int (*cmp
) (const char *, const char *);
2183 if (current_language
->la_language
== language_cplus
2184 || current_language
->la_language
== language_java
2185 || current_language
->la_language
== language_fortran
)
2187 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2189 const char *paren
= strchr (name
, '(');
2195 dup
= xmalloc (paren
- name
+ 1);
2196 memcpy (dup
, name
, paren
- name
);
2197 dup
[paren
- name
] = 0;
2199 make_cleanup (xfree
, dup
);
2204 /* Index version 4 did not support case insensitive searches. But the
2205 indices for case insensitive languages are built in lowercase, therefore
2206 simulate our NAME being searched is also lowercased. */
2207 hash
= mapped_index_string_hash ((index
->version
== 4
2208 && case_sensitivity
== case_sensitive_off
2209 ? 5 : index
->version
),
2212 slot
= hash
& (index
->symbol_table_slots
- 1);
2213 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2214 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2218 /* Convert a slot number to an offset into the table. */
2219 offset_type i
= 2 * slot
;
2221 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2223 do_cleanups (back_to
);
2227 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2228 if (!cmp (name
, str
))
2230 *vec_out
= (offset_type
*) (index
->constant_pool
2231 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2232 do_cleanups (back_to
);
2236 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2240 /* Read the index file. If everything went ok, initialize the "quick"
2241 elements of all the CUs and return 1. Otherwise, return 0. */
2244 dwarf2_read_index (struct objfile
*objfile
)
2247 struct mapped_index
*map
;
2248 offset_type
*metadata
;
2249 const gdb_byte
*cu_list
;
2250 const gdb_byte
*types_list
= NULL
;
2251 offset_type version
, cu_list_elements
;
2252 offset_type types_list_elements
= 0;
2255 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2258 /* Older elfutils strip versions could keep the section in the main
2259 executable while splitting it for the separate debug info file. */
2260 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2261 & SEC_HAS_CONTENTS
) == 0)
2264 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2266 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2267 /* Version check. */
2268 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2269 /* Versions earlier than 3 emitted every copy of a psymbol. This
2270 causes the index to behave very poorly for certain requests. Version 3
2271 contained incomplete addrmap. So, it seems better to just ignore such
2275 static int warning_printed
= 0;
2276 if (!warning_printed
)
2278 warning (_("Skipping obsolete .gdb_index section in %s."),
2280 warning_printed
= 1;
2284 /* Index version 4 uses a different hash function than index version
2287 Versions earlier than 6 did not emit psymbols for inlined
2288 functions. Using these files will cause GDB not to be able to
2289 set breakpoints on inlined functions by name, so we ignore these
2290 indices unless the --use-deprecated-index-sections command line
2291 option was supplied. */
2292 if (version
< 6 && !use_deprecated_index_sections
)
2294 static int warning_printed
= 0;
2295 if (!warning_printed
)
2297 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2298 "--use-deprecated-index-sections to use them anyway"),
2300 warning_printed
= 1;
2304 /* Indexes with higher version than the one supported by GDB may be no
2305 longer backward compatible. */
2309 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2310 map
->version
= version
;
2311 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2313 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2316 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2317 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2321 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2322 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2323 - MAYBE_SWAP (metadata
[i
]))
2327 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2328 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2329 - MAYBE_SWAP (metadata
[i
]));
2332 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2333 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2334 - MAYBE_SWAP (metadata
[i
]))
2335 / (2 * sizeof (offset_type
)));
2338 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2340 /* Don't use the index if it's empty. */
2341 if (map
->symbol_table_slots
== 0)
2344 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2347 if (types_list_elements
)
2349 struct dwarf2_section_info
*section
;
2351 /* We can only handle a single .debug_types when we have an
2353 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2356 section
= VEC_index (dwarf2_section_info_def
,
2357 dwarf2_per_objfile
->types
, 0);
2359 if (!create_signatured_type_table_from_index (objfile
, section
,
2361 types_list_elements
))
2365 create_addrmap_from_index (objfile
, map
);
2367 dwarf2_per_objfile
->index_table
= map
;
2368 dwarf2_per_objfile
->using_index
= 1;
2369 dwarf2_per_objfile
->quick_file_names_table
=
2370 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2375 /* A helper for the "quick" functions which sets the global
2376 dwarf2_per_objfile according to OBJFILE. */
2379 dw2_setup (struct objfile
*objfile
)
2381 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2382 gdb_assert (dwarf2_per_objfile
);
2385 /* die_reader_func for dw2_get_file_names. */
2388 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2390 struct die_info
*comp_unit_die
,
2394 struct dwarf2_cu
*cu
= reader
->cu
;
2395 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2396 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2397 struct line_header
*lh
;
2398 struct attribute
*attr
;
2400 unsigned int bytes_read
;
2401 char *name
, *comp_dir
;
2403 struct quick_file_names
*qfn
;
2404 unsigned int line_offset
;
2410 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2413 struct quick_file_names find_entry
;
2415 line_offset
= DW_UNSND (attr
);
2417 /* We may have already read in this line header (TU line header sharing).
2418 If we have we're done. */
2419 find_entry
.offset
= line_offset
;
2420 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2421 &find_entry
, INSERT
);
2424 this_cu
->v
.quick
->file_names
= *slot
;
2428 lh
= dwarf_decode_line_header (line_offset
, cu
);
2432 this_cu
->v
.quick
->no_file_data
= 1;
2436 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2437 qfn
->offset
= line_offset
;
2438 gdb_assert (slot
!= NULL
);
2441 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2443 qfn
->num_file_names
= lh
->num_file_names
;
2444 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2445 lh
->num_file_names
* sizeof (char *));
2446 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2447 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2448 qfn
->real_names
= NULL
;
2450 free_line_header (lh
);
2452 this_cu
->v
.quick
->file_names
= qfn
;
2455 /* A helper for the "quick" functions which attempts to read the line
2456 table for THIS_CU. */
2458 static struct quick_file_names
*
2459 dw2_get_file_names (struct objfile
*objfile
,
2460 struct dwarf2_per_cu_data
*this_cu
)
2462 if (this_cu
->v
.quick
->file_names
!= NULL
)
2463 return this_cu
->v
.quick
->file_names
;
2464 /* If we know there is no line data, no point in looking again. */
2465 if (this_cu
->v
.quick
->no_file_data
)
2468 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2469 in the stub for CUs, there's is no need to lookup the DWO file.
2470 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2472 if (this_cu
->is_debug_types
)
2473 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2475 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2477 if (this_cu
->v
.quick
->no_file_data
)
2479 return this_cu
->v
.quick
->file_names
;
2482 /* A helper for the "quick" functions which computes and caches the
2483 real path for a given file name from the line table. */
2486 dw2_get_real_path (struct objfile
*objfile
,
2487 struct quick_file_names
*qfn
, int index
)
2489 if (qfn
->real_names
== NULL
)
2490 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2491 qfn
->num_file_names
, sizeof (char *));
2493 if (qfn
->real_names
[index
] == NULL
)
2494 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2496 return qfn
->real_names
[index
];
2499 static struct symtab
*
2500 dw2_find_last_source_symtab (struct objfile
*objfile
)
2504 dw2_setup (objfile
);
2505 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2506 return dw2_instantiate_symtab (dw2_get_cu (index
));
2509 /* Traversal function for dw2_forget_cached_source_info. */
2512 dw2_free_cached_file_names (void **slot
, void *info
)
2514 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2516 if (file_data
->real_names
)
2520 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2522 xfree ((void*) file_data
->real_names
[i
]);
2523 file_data
->real_names
[i
] = NULL
;
2531 dw2_forget_cached_source_info (struct objfile
*objfile
)
2533 dw2_setup (objfile
);
2535 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2536 dw2_free_cached_file_names
, NULL
);
2539 /* Helper function for dw2_map_symtabs_matching_filename that expands
2540 the symtabs and calls the iterator. */
2543 dw2_map_expand_apply (struct objfile
*objfile
,
2544 struct dwarf2_per_cu_data
*per_cu
,
2546 const char *full_path
, const char *real_path
,
2547 int (*callback
) (struct symtab
*, void *),
2550 struct symtab
*last_made
= objfile
->symtabs
;
2552 /* Don't visit already-expanded CUs. */
2553 if (per_cu
->v
.quick
->symtab
)
2556 /* This may expand more than one symtab, and we want to iterate over
2558 dw2_instantiate_symtab (per_cu
);
2560 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2561 objfile
->symtabs
, last_made
);
2564 /* Implementation of the map_symtabs_matching_filename method. */
2567 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2568 const char *full_path
, const char *real_path
,
2569 int (*callback
) (struct symtab
*, void *),
2573 const char *name_basename
= lbasename (name
);
2574 int name_len
= strlen (name
);
2575 int is_abs
= IS_ABSOLUTE_PATH (name
);
2577 dw2_setup (objfile
);
2579 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2580 + dwarf2_per_objfile
->n_type_units
); ++i
)
2583 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2584 struct quick_file_names
*file_data
;
2586 /* We only need to look at symtabs not already expanded. */
2587 if (per_cu
->v
.quick
->symtab
)
2590 file_data
= dw2_get_file_names (objfile
, per_cu
);
2591 if (file_data
== NULL
)
2594 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2596 const char *this_name
= file_data
->file_names
[j
];
2598 if (FILENAME_CMP (name
, this_name
) == 0
2599 || (!is_abs
&& compare_filenames_for_search (this_name
,
2602 if (dw2_map_expand_apply (objfile
, per_cu
,
2603 name
, full_path
, real_path
,
2608 /* Before we invoke realpath, which can get expensive when many
2609 files are involved, do a quick comparison of the basenames. */
2610 if (! basenames_may_differ
2611 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2614 if (full_path
!= NULL
)
2616 const char *this_real_name
= dw2_get_real_path (objfile
,
2619 if (this_real_name
!= NULL
2620 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2622 && compare_filenames_for_search (this_real_name
,
2625 if (dw2_map_expand_apply (objfile
, per_cu
,
2626 name
, full_path
, real_path
,
2632 if (real_path
!= NULL
)
2634 const char *this_real_name
= dw2_get_real_path (objfile
,
2637 if (this_real_name
!= NULL
2638 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2640 && compare_filenames_for_search (this_real_name
,
2643 if (dw2_map_expand_apply (objfile
, per_cu
,
2644 name
, full_path
, real_path
,
2655 static struct symtab
*
2656 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2657 const char *name
, domain_enum domain
)
2659 /* We do all the work in the pre_expand_symtabs_matching hook
2664 /* A helper function that expands all symtabs that hold an object
2668 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2670 dw2_setup (objfile
);
2672 /* index_table is NULL if OBJF_READNOW. */
2673 if (dwarf2_per_objfile
->index_table
)
2677 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2680 offset_type i
, len
= MAYBE_SWAP (*vec
);
2681 for (i
= 0; i
< len
; ++i
)
2683 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2684 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2686 dw2_instantiate_symtab (per_cu
);
2693 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2694 enum block_enum block_kind
, const char *name
,
2697 dw2_do_expand_symtabs_matching (objfile
, name
);
2701 dw2_print_stats (struct objfile
*objfile
)
2705 dw2_setup (objfile
);
2707 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2708 + dwarf2_per_objfile
->n_type_units
); ++i
)
2710 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2712 if (!per_cu
->v
.quick
->symtab
)
2715 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2719 dw2_dump (struct objfile
*objfile
)
2721 /* Nothing worth printing. */
2725 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2726 struct section_offsets
*delta
)
2728 /* There's nothing to relocate here. */
2732 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2733 const char *func_name
)
2735 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2739 dw2_expand_all_symtabs (struct objfile
*objfile
)
2743 dw2_setup (objfile
);
2745 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2746 + dwarf2_per_objfile
->n_type_units
); ++i
)
2748 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2750 dw2_instantiate_symtab (per_cu
);
2755 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2756 const char *filename
)
2760 dw2_setup (objfile
);
2762 /* We don't need to consider type units here.
2763 This is only called for examining code, e.g. expand_line_sal.
2764 There can be an order of magnitude (or more) more type units
2765 than comp units, and we avoid them if we can. */
2767 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2770 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2771 struct quick_file_names
*file_data
;
2773 /* We only need to look at symtabs not already expanded. */
2774 if (per_cu
->v
.quick
->symtab
)
2777 file_data
= dw2_get_file_names (objfile
, per_cu
);
2778 if (file_data
== NULL
)
2781 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2783 const char *this_name
= file_data
->file_names
[j
];
2784 if (FILENAME_CMP (this_name
, filename
) == 0)
2786 dw2_instantiate_symtab (per_cu
);
2794 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2796 struct dwarf2_per_cu_data
*per_cu
;
2798 struct quick_file_names
*file_data
;
2800 dw2_setup (objfile
);
2802 /* index_table is NULL if OBJF_READNOW. */
2803 if (!dwarf2_per_objfile
->index_table
)
2807 ALL_OBJFILE_SYMTABS (objfile
, s
)
2810 struct blockvector
*bv
= BLOCKVECTOR (s
);
2811 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2812 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2815 return sym
->symtab
->filename
;
2820 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2824 /* Note that this just looks at the very first one named NAME -- but
2825 actually we are looking for a function. find_main_filename
2826 should be rewritten so that it doesn't require a custom hook. It
2827 could just use the ordinary symbol tables. */
2828 /* vec[0] is the length, which must always be >0. */
2829 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2831 file_data
= dw2_get_file_names (objfile
, per_cu
);
2832 if (file_data
== NULL
2833 || file_data
->num_file_names
== 0)
2836 return file_data
->file_names
[file_data
->num_file_names
- 1];
2840 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2841 struct objfile
*objfile
, int global
,
2842 int (*callback
) (struct block
*,
2843 struct symbol
*, void *),
2844 void *data
, symbol_compare_ftype
*match
,
2845 symbol_compare_ftype
*ordered_compare
)
2847 /* Currently unimplemented; used for Ada. The function can be called if the
2848 current language is Ada for a non-Ada objfile using GNU index. As Ada
2849 does not look for non-Ada symbols this function should just return. */
2853 dw2_expand_symtabs_matching
2854 (struct objfile
*objfile
,
2855 int (*file_matcher
) (const char *, void *),
2856 int (*name_matcher
) (const char *, void *),
2857 enum search_domain kind
,
2862 struct mapped_index
*index
;
2864 dw2_setup (objfile
);
2866 /* index_table is NULL if OBJF_READNOW. */
2867 if (!dwarf2_per_objfile
->index_table
)
2869 index
= dwarf2_per_objfile
->index_table
;
2871 if (file_matcher
!= NULL
)
2873 struct cleanup
*cleanup
;
2874 htab_t visited_found
, visited_not_found
;
2876 visited_found
= htab_create_alloc (10,
2877 htab_hash_pointer
, htab_eq_pointer
,
2878 NULL
, xcalloc
, xfree
);
2879 cleanup
= make_cleanup_htab_delete (visited_found
);
2880 visited_not_found
= htab_create_alloc (10,
2881 htab_hash_pointer
, htab_eq_pointer
,
2882 NULL
, xcalloc
, xfree
);
2883 make_cleanup_htab_delete (visited_not_found
);
2885 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2886 + dwarf2_per_objfile
->n_type_units
); ++i
)
2889 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2890 struct quick_file_names
*file_data
;
2893 per_cu
->v
.quick
->mark
= 0;
2895 /* We only need to look at symtabs not already expanded. */
2896 if (per_cu
->v
.quick
->symtab
)
2899 file_data
= dw2_get_file_names (objfile
, per_cu
);
2900 if (file_data
== NULL
)
2903 if (htab_find (visited_not_found
, file_data
) != NULL
)
2905 else if (htab_find (visited_found
, file_data
) != NULL
)
2907 per_cu
->v
.quick
->mark
= 1;
2911 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2913 if (file_matcher (file_data
->file_names
[j
], data
))
2915 per_cu
->v
.quick
->mark
= 1;
2920 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2922 : visited_not_found
,
2927 do_cleanups (cleanup
);
2930 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2932 offset_type idx
= 2 * iter
;
2934 offset_type
*vec
, vec_len
, vec_idx
;
2936 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2939 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2941 if (! (*name_matcher
) (name
, data
))
2944 /* The name was matched, now expand corresponding CUs that were
2946 vec
= (offset_type
*) (index
->constant_pool
2947 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2948 vec_len
= MAYBE_SWAP (vec
[0]);
2949 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2951 struct dwarf2_per_cu_data
*per_cu
;
2953 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2954 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2955 dw2_instantiate_symtab (per_cu
);
2960 static struct symtab
*
2961 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2962 struct minimal_symbol
*msymbol
,
2964 struct obj_section
*section
,
2967 struct dwarf2_per_cu_data
*data
;
2969 dw2_setup (objfile
);
2971 if (!objfile
->psymtabs_addrmap
)
2974 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2978 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2979 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2980 paddress (get_objfile_arch (objfile
), pc
));
2982 return dw2_instantiate_symtab (data
);
2986 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2987 void *data
, int need_fullname
)
2990 struct cleanup
*cleanup
;
2991 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2992 NULL
, xcalloc
, xfree
);
2994 cleanup
= make_cleanup_htab_delete (visited
);
2995 dw2_setup (objfile
);
2997 /* We can ignore file names coming from already-expanded CUs. */
2998 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2999 + dwarf2_per_objfile
->n_type_units
); ++i
)
3001 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3003 if (per_cu
->v
.quick
->symtab
)
3005 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3008 *slot
= per_cu
->v
.quick
->file_names
;
3012 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3013 + dwarf2_per_objfile
->n_type_units
); ++i
)
3016 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3017 struct quick_file_names
*file_data
;
3020 /* We only need to look at symtabs not already expanded. */
3021 if (per_cu
->v
.quick
->symtab
)
3024 file_data
= dw2_get_file_names (objfile
, per_cu
);
3025 if (file_data
== NULL
)
3028 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3031 /* Already visited. */
3036 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3038 const char *this_real_name
;
3041 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3043 this_real_name
= NULL
;
3044 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3048 do_cleanups (cleanup
);
3052 dw2_has_symbols (struct objfile
*objfile
)
3057 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3060 dw2_find_last_source_symtab
,
3061 dw2_forget_cached_source_info
,
3062 dw2_map_symtabs_matching_filename
,
3064 dw2_pre_expand_symtabs_matching
,
3068 dw2_expand_symtabs_for_function
,
3069 dw2_expand_all_symtabs
,
3070 dw2_expand_symtabs_with_filename
,
3071 dw2_find_symbol_file
,
3072 dw2_map_matching_symbols
,
3073 dw2_expand_symtabs_matching
,
3074 dw2_find_pc_sect_symtab
,
3075 dw2_map_symbol_filenames
3078 /* Initialize for reading DWARF for this objfile. Return 0 if this
3079 file will use psymtabs, or 1 if using the GNU index. */
3082 dwarf2_initialize_objfile (struct objfile
*objfile
)
3084 /* If we're about to read full symbols, don't bother with the
3085 indices. In this case we also don't care if some other debug
3086 format is making psymtabs, because they are all about to be
3088 if ((objfile
->flags
& OBJF_READNOW
))
3092 dwarf2_per_objfile
->using_index
= 1;
3093 create_all_comp_units (objfile
);
3094 create_all_type_units (objfile
);
3095 dwarf2_per_objfile
->quick_file_names_table
=
3096 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3098 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3099 + dwarf2_per_objfile
->n_type_units
); ++i
)
3101 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3103 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3104 struct dwarf2_per_cu_quick_data
);
3107 /* Return 1 so that gdb sees the "quick" functions. However,
3108 these functions will be no-ops because we will have expanded
3113 if (dwarf2_read_index (objfile
))
3121 /* Build a partial symbol table. */
3124 dwarf2_build_psymtabs (struct objfile
*objfile
)
3126 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3128 init_psymbol_list (objfile
, 1024);
3131 dwarf2_build_psymtabs_hard (objfile
);
3134 /* Return TRUE if OFFSET is within CU_HEADER. */
3137 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3139 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3140 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3141 + cu_header
->initial_length_size
) };
3143 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3146 /* Read in the comp unit header information from the debug_info at info_ptr.
3147 NOTE: This leaves members offset, first_die_offset to be filled in
3151 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3152 gdb_byte
*info_ptr
, bfd
*abfd
)
3155 unsigned int bytes_read
;
3157 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3158 cu_header
->initial_length_size
= bytes_read
;
3159 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3160 info_ptr
+= bytes_read
;
3161 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3163 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3165 info_ptr
+= bytes_read
;
3166 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3168 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3169 if (signed_addr
< 0)
3170 internal_error (__FILE__
, __LINE__
,
3171 _("read_comp_unit_head: dwarf from non elf file"));
3172 cu_header
->signed_addr_p
= signed_addr
;
3177 /* Subroutine of read_and_check_comp_unit_head and
3178 read_and_check_type_unit_head to simplify them.
3179 Perform various error checking on the header. */
3182 error_check_comp_unit_head (struct comp_unit_head
*header
,
3183 struct dwarf2_section_info
*section
)
3185 bfd
*abfd
= section
->asection
->owner
;
3186 const char *filename
= bfd_get_filename (abfd
);
3188 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3189 error (_("Dwarf Error: wrong version in compilation unit header "
3190 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3193 if (header
->abbrev_offset
.sect_off
3194 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3195 &dwarf2_per_objfile
->abbrev
))
3196 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3197 "(offset 0x%lx + 6) [in module %s]"),
3198 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3201 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3202 avoid potential 32-bit overflow. */
3203 if (((unsigned long) header
->offset
.sect_off
3204 + header
->length
+ header
->initial_length_size
)
3206 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3207 "(offset 0x%lx + 0) [in module %s]"),
3208 (long) header
->length
, (long) header
->offset
.sect_off
,
3212 /* Read in a CU/TU header and perform some basic error checking.
3213 The contents of the header are stored in HEADER.
3214 The result is a pointer to the start of the first DIE. */
3217 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3218 struct dwarf2_section_info
*section
,
3220 int is_debug_types_section
)
3222 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3223 bfd
*abfd
= section
->asection
->owner
;
3225 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3227 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3229 /* If we're reading a type unit, skip over the signature and
3230 type_offset fields. */
3231 if (is_debug_types_section
)
3232 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3234 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3236 error_check_comp_unit_head (header
, section
);
3241 /* Read in the types comp unit header information from .debug_types entry at
3242 types_ptr. The result is a pointer to one past the end of the header. */
3245 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3246 struct dwarf2_section_info
*section
,
3248 ULONGEST
*signature
,
3249 cu_offset
*type_offset_in_tu
)
3251 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3252 bfd
*abfd
= section
->asection
->owner
;
3254 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3256 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3258 /* If we're reading a type unit, skip over the signature and
3259 type_offset fields. */
3260 if (signature
!= NULL
)
3261 *signature
= read_8_bytes (abfd
, info_ptr
);
3263 if (type_offset_in_tu
!= NULL
)
3264 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3265 header
->offset_size
);
3266 info_ptr
+= header
->offset_size
;
3268 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3270 error_check_comp_unit_head (header
, section
);
3275 /* Allocate a new partial symtab for file named NAME and mark this new
3276 partial symtab as being an include of PST. */
3279 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3280 struct objfile
*objfile
)
3282 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3284 subpst
->section_offsets
= pst
->section_offsets
;
3285 subpst
->textlow
= 0;
3286 subpst
->texthigh
= 0;
3288 subpst
->dependencies
= (struct partial_symtab
**)
3289 obstack_alloc (&objfile
->objfile_obstack
,
3290 sizeof (struct partial_symtab
*));
3291 subpst
->dependencies
[0] = pst
;
3292 subpst
->number_of_dependencies
= 1;
3294 subpst
->globals_offset
= 0;
3295 subpst
->n_global_syms
= 0;
3296 subpst
->statics_offset
= 0;
3297 subpst
->n_static_syms
= 0;
3298 subpst
->symtab
= NULL
;
3299 subpst
->read_symtab
= pst
->read_symtab
;
3302 /* No private part is necessary for include psymtabs. This property
3303 can be used to differentiate between such include psymtabs and
3304 the regular ones. */
3305 subpst
->read_symtab_private
= NULL
;
3308 /* Read the Line Number Program data and extract the list of files
3309 included by the source file represented by PST. Build an include
3310 partial symtab for each of these included files. */
3313 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3314 struct die_info
*die
,
3315 struct partial_symtab
*pst
)
3317 struct line_header
*lh
= NULL
;
3318 struct attribute
*attr
;
3320 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3322 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3324 return; /* No linetable, so no includes. */
3326 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3327 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3329 free_line_header (lh
);
3333 hash_signatured_type (const void *item
)
3335 const struct signatured_type
*sig_type
= item
;
3337 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3338 return sig_type
->signature
;
3342 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3344 const struct signatured_type
*lhs
= item_lhs
;
3345 const struct signatured_type
*rhs
= item_rhs
;
3347 return lhs
->signature
== rhs
->signature
;
3350 /* Allocate a hash table for signatured types. */
3353 allocate_signatured_type_table (struct objfile
*objfile
)
3355 return htab_create_alloc_ex (41,
3356 hash_signatured_type
,
3359 &objfile
->objfile_obstack
,
3360 hashtab_obstack_allocate
,
3361 dummy_obstack_deallocate
);
3364 /* A helper function to add a signatured type CU to a table. */
3367 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3369 struct signatured_type
*sigt
= *slot
;
3370 struct dwarf2_per_cu_data
***datap
= datum
;
3372 **datap
= &sigt
->per_cu
;
3378 /* Create the hash table of all entries in the .debug_types section.
3379 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3380 The result is a pointer to the hash table or NULL if there are
3384 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3385 VEC (dwarf2_section_info_def
) *types
)
3387 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3388 htab_t types_htab
= NULL
;
3390 struct dwarf2_section_info
*section
;
3392 if (VEC_empty (dwarf2_section_info_def
, types
))
3396 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3400 gdb_byte
*info_ptr
, *end_ptr
;
3402 dwarf2_read_section (objfile
, section
);
3403 info_ptr
= section
->buffer
;
3405 if (info_ptr
== NULL
)
3408 /* We can't set abfd until now because the section may be empty or
3409 not present, in which case section->asection will be NULL. */
3410 abfd
= section
->asection
->owner
;
3412 if (types_htab
== NULL
)
3415 types_htab
= allocate_dwo_unit_table (objfile
);
3417 types_htab
= allocate_signatured_type_table (objfile
);
3420 if (dwarf2_die_debug
)
3421 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3422 bfd_get_filename (abfd
));
3424 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3425 because we don't need to read any dies: the signature is in the
3428 end_ptr
= info_ptr
+ section
->size
;
3429 while (info_ptr
< end_ptr
)
3432 cu_offset type_offset_in_tu
;
3434 struct signatured_type
*sig_type
;
3435 struct dwo_unit
*dwo_tu
;
3437 gdb_byte
*ptr
= info_ptr
;
3438 struct comp_unit_head header
;
3439 unsigned int length
;
3441 offset
.sect_off
= ptr
- section
->buffer
;
3443 /* We need to read the type's signature in order to build the hash
3444 table, but we don't need anything else just yet. */
3446 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3447 &signature
, &type_offset_in_tu
);
3449 length
= header
.initial_length_size
+ header
.length
;
3451 /* Skip dummy type units. */
3452 if (ptr
>= info_ptr
+ length
3453 || peek_abbrev_code (abfd
, ptr
) == 0)
3455 info_ptr
+= header
.initial_length_size
+ header
.length
;
3462 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3464 dwo_tu
->dwo_file
= dwo_file
;
3465 dwo_tu
->signature
= signature
;
3466 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3467 dwo_tu
->info_or_types_section
= section
;
3468 dwo_tu
->offset
= offset
;
3469 dwo_tu
->length
= length
;
3473 /* N.B.: type_offset is not usable if this type uses a DWO file.
3474 The real type_offset is in the DWO file. */
3476 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3477 struct signatured_type
);
3478 sig_type
->signature
= signature
;
3479 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3480 sig_type
->per_cu
.objfile
= objfile
;
3481 sig_type
->per_cu
.is_debug_types
= 1;
3482 sig_type
->per_cu
.info_or_types_section
= section
;
3483 sig_type
->per_cu
.offset
= offset
;
3484 sig_type
->per_cu
.length
= length
;
3487 slot
= htab_find_slot (types_htab
,
3488 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3490 gdb_assert (slot
!= NULL
);
3493 sect_offset dup_offset
;
3497 const struct dwo_unit
*dup_tu
= *slot
;
3499 dup_offset
= dup_tu
->offset
;
3503 const struct signatured_type
*dup_tu
= *slot
;
3505 dup_offset
= dup_tu
->per_cu
.offset
;
3508 complaint (&symfile_complaints
,
3509 _("debug type entry at offset 0x%x is duplicate to the "
3510 "entry at offset 0x%x, signature 0x%s"),
3511 offset
.sect_off
, dup_offset
.sect_off
,
3512 phex (signature
, sizeof (signature
)));
3514 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3516 if (dwarf2_die_debug
)
3517 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3519 phex (signature
, sizeof (signature
)));
3528 /* Create the hash table of all entries in the .debug_types section,
3529 and initialize all_type_units.
3530 The result is zero if there is an error (e.g. missing .debug_types section),
3531 otherwise non-zero. */
3534 create_all_type_units (struct objfile
*objfile
)
3537 struct dwarf2_per_cu_data
**iter
;
3539 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3540 if (types_htab
== NULL
)
3542 dwarf2_per_objfile
->signatured_types
= NULL
;
3546 dwarf2_per_objfile
->signatured_types
= types_htab
;
3548 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3549 dwarf2_per_objfile
->all_type_units
3550 = obstack_alloc (&objfile
->objfile_obstack
,
3551 dwarf2_per_objfile
->n_type_units
3552 * sizeof (struct dwarf2_per_cu_data
*));
3553 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3554 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3555 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3556 == dwarf2_per_objfile
->n_type_units
);
3561 /* Lookup a signature based type for DW_FORM_ref_sig8.
3562 Returns NULL if signature SIG is not present in the table. */
3564 static struct signatured_type
*
3565 lookup_signatured_type (ULONGEST sig
)
3567 struct signatured_type find_entry
, *entry
;
3569 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3571 complaint (&symfile_complaints
,
3572 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3576 find_entry
.signature
= sig
;
3577 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3581 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3584 init_cu_die_reader (struct die_reader_specs
*reader
,
3585 struct dwarf2_cu
*cu
,
3586 struct dwarf2_section_info
*section
,
3587 struct dwo_file
*dwo_file
)
3589 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3590 reader
->abfd
= section
->asection
->owner
;
3592 reader
->dwo_file
= dwo_file
;
3593 reader
->die_section
= section
;
3594 reader
->buffer
= section
->buffer
;
3597 /* Find the base address of the compilation unit for range lists and
3598 location lists. It will normally be specified by DW_AT_low_pc.
3599 In DWARF-3 draft 4, the base address could be overridden by
3600 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3601 compilation units with discontinuous ranges. */
3604 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3606 struct attribute
*attr
;
3609 cu
->base_address
= 0;
3611 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3614 cu
->base_address
= DW_ADDR (attr
);
3619 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3622 cu
->base_address
= DW_ADDR (attr
);
3628 /* Initialize a CU (or TU) and read its DIEs.
3629 If the CU defers to a DWO file, read the DWO file as well.
3631 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3632 Otherwise, a new CU is allocated with xmalloc.
3634 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3635 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3637 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3638 linker) then DIE_READER_FUNC will not get called. */
3641 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3642 int use_existing_cu
, int keep
,
3643 die_reader_func_ftype
*die_reader_func
,
3646 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3647 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3648 bfd
*abfd
= section
->asection
->owner
;
3649 struct dwarf2_cu
*cu
;
3650 gdb_byte
*begin_info_ptr
, *info_ptr
;
3651 struct die_reader_specs reader
;
3652 struct die_info
*comp_unit_die
;
3654 struct attribute
*attr
;
3655 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3656 struct signatured_type
*sig_type
= NULL
;
3658 if (use_existing_cu
)
3661 cleanups
= make_cleanup (null_cleanup
, NULL
);
3663 /* This is cheap if the section is already read in. */
3664 dwarf2_read_section (objfile
, section
);
3666 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3668 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3671 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3675 /* If !use_existing_cu, this_cu->cu must be NULL. */
3676 gdb_assert (this_cu
->cu
== NULL
);
3678 cu
= xmalloc (sizeof (*cu
));
3679 init_one_comp_unit (cu
, this_cu
);
3681 /* If an error occurs while loading, release our storage. */
3682 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3684 if (this_cu
->is_debug_types
)
3688 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3692 /* There's no way to get from PER_CU to its containing
3693 struct signatured_type.
3694 But we have the signature so we can use that. */
3695 sig_type
= lookup_signatured_type (signature
);
3696 /* We've already scanned all the signatured types,
3697 this must succeed. */
3698 gdb_assert (sig_type
!= NULL
);
3699 gdb_assert (&sig_type
->per_cu
== this_cu
);
3700 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3702 /* LENGTH has not been set yet for type units. */
3703 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3705 /* Establish the type offset that can be used to lookup the type. */
3706 sig_type
->type_offset_in_section
.sect_off
=
3707 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3711 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3712 section
, info_ptr
, 0);
3714 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3715 gdb_assert (this_cu
->length
3716 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3720 /* Skip dummy compilation units. */
3721 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3722 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3724 do_cleanups (cleanups
);
3728 /* Read the abbrevs for this compilation unit into a table. */
3729 if (cu
->dwarf2_abbrevs
== NULL
)
3731 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3732 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3735 /* Read the top level CU/TU die. */
3736 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3737 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3739 /* If we have a DWO stub, process it and then read in the DWO file.
3740 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3741 a DWO CU, that this test will fail. */
3742 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3745 char *dwo_name
= DW_STRING (attr
);
3746 const char *comp_dir
;
3747 struct dwo_unit
*dwo_unit
;
3748 ULONGEST signature
; /* Or dwo_id. */
3749 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3750 int i
,num_extra_attrs
;
3753 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3754 " has children (offset 0x%x) [in module %s]"),
3755 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3757 /* These attributes aren't processed until later:
3758 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3759 However, the attribute is found in the stub which we won't have later.
3760 In order to not impose this complication on the rest of the code,
3761 we read them here and copy them to the DWO CU/TU die. */
3762 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3764 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3766 if (! this_cu
->is_debug_types
)
3767 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3768 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3769 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3770 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3772 /* There should be a DW_AT_addr_base attribute here (if needed).
3773 We need the value before we can process DW_FORM_GNU_addr_index. */
3775 cu
->have_addr_base
= 0;
3776 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3779 cu
->addr_base
= DW_UNSND (attr
);
3780 cu
->have_addr_base
= 1;
3783 if (this_cu
->is_debug_types
)
3785 gdb_assert (sig_type
!= NULL
);
3786 signature
= sig_type
->signature
;
3790 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
3792 error (_("Dwarf Error: missing dwo_id [in module %s]"),
3794 signature
= DW_UNSND (attr
);
3797 /* We may need the comp_dir in order to find the DWO file. */
3799 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3801 comp_dir
= DW_STRING (attr
);
3803 if (this_cu
->is_debug_types
)
3804 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
3806 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
3809 if (dwo_unit
== NULL
)
3811 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
3812 " with ID %s [in module %s]"),
3813 this_cu
->offset
.sect_off
,
3814 phex (signature
, sizeof (signature
)),
3818 /* Set up for reading the DWO CU/TU. */
3819 cu
->dwo_unit
= dwo_unit
;
3820 section
= dwo_unit
->info_or_types_section
;
3821 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
3822 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
3824 if (this_cu
->is_debug_types
)
3828 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3831 gdb_assert (sig_type
->signature
== signature
);
3832 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3833 gdb_assert (dwo_unit
->length
3834 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3836 /* Establish the type offset that can be used to lookup the type.
3837 For DWO files, we don't know it until now. */
3838 sig_type
->type_offset_in_section
.sect_off
=
3839 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
3843 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3844 section
, info_ptr
, 0);
3845 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3846 gdb_assert (dwo_unit
->length
3847 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3850 /* Discard the original CU's abbrev table, and read the DWO's. */
3851 dwarf2_free_abbrev_table (cu
);
3852 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
3854 /* Read in the die, but leave space to copy over the attributes
3855 from the stub. This has the benefit of simplifying the rest of
3856 the code - all the real work is done here. */
3857 num_extra_attrs
= ((stmt_list
!= NULL
)
3860 + (ranges
!= NULL
));
3861 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
3862 &has_children
, num_extra_attrs
);
3864 /* Copy over the attributes from the stub to the DWO die. */
3865 i
= comp_unit_die
->num_attrs
;
3866 if (stmt_list
!= NULL
)
3867 comp_unit_die
->attrs
[i
++] = *stmt_list
;
3869 comp_unit_die
->attrs
[i
++] = *low_pc
;
3870 if (high_pc
!= NULL
)
3871 comp_unit_die
->attrs
[i
++] = *high_pc
;
3873 comp_unit_die
->attrs
[i
++] = *ranges
;
3874 comp_unit_die
->num_attrs
+= num_extra_attrs
;
3876 /* Skip dummy compilation units. */
3877 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
3878 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3880 do_cleanups (cleanups
);
3885 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3887 if (free_cu_cleanup
!= NULL
)
3891 /* We've successfully allocated this compilation unit. Let our
3892 caller clean it up when finished with it. */
3893 discard_cleanups (free_cu_cleanup
);
3895 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3896 So we have to manually free the abbrev table. */
3897 dwarf2_free_abbrev_table (cu
);
3899 /* Link this CU into read_in_chain. */
3900 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3901 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3904 do_cleanups (free_cu_cleanup
);
3907 do_cleanups (cleanups
);
3910 /* Read CU/TU THIS_CU in section SECTION,
3911 but do not follow DW_AT_GNU_dwo_name if present.
3912 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
3913 have already done the lookup to find the DWO file).
3915 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3916 THIS_CU->is_debug_types, but nothing else.
3918 We fill in THIS_CU->length.
3920 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3921 linker) then DIE_READER_FUNC will not get called.
3923 THIS_CU->cu is always freed when done.
3924 This is done in order to not leave THIS_CU->cu in a state where we have
3925 to care whether it refers to the "main" CU or the DWO CU. */
3928 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3929 struct dwarf2_section_info
*abbrev_section
,
3930 struct dwo_file
*dwo_file
,
3931 die_reader_func_ftype
*die_reader_func
,
3934 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3935 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3936 bfd
*abfd
= section
->asection
->owner
;
3937 struct dwarf2_cu cu
;
3938 gdb_byte
*begin_info_ptr
, *info_ptr
;
3939 struct die_reader_specs reader
;
3940 struct cleanup
*cleanups
;
3941 struct die_info
*comp_unit_die
;
3944 gdb_assert (this_cu
->cu
== NULL
);
3946 /* This is cheap if the section is already read in. */
3947 dwarf2_read_section (objfile
, section
);
3949 init_one_comp_unit (&cu
, this_cu
);
3951 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
3953 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3954 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3955 this_cu
->is_debug_types
);
3957 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3959 /* Skip dummy compilation units. */
3960 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3961 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3963 do_cleanups (cleanups
);
3967 dwarf2_read_abbrevs (&cu
, abbrev_section
);
3968 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3970 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
3971 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3973 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3975 do_cleanups (cleanups
);
3978 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
3979 does not lookup the specified DWO file.
3980 This cannot be used to read DWO files.
3982 THIS_CU->cu is always freed when done.
3983 This is done in order to not leave THIS_CU->cu in a state where we have
3984 to care whether it refers to the "main" CU or the DWO CU.
3985 We can revisit this if the data shows there's a performance issue. */
3988 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
3989 die_reader_func_ftype
*die_reader_func
,
3992 init_cutu_and_read_dies_no_follow (this_cu
,
3993 &dwarf2_per_objfile
->abbrev
,
3995 die_reader_func
, data
);
3998 /* die_reader_func for process_psymtab_comp_unit. */
4001 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4003 struct die_info
*comp_unit_die
,
4007 struct dwarf2_cu
*cu
= reader
->cu
;
4008 struct objfile
*objfile
= cu
->objfile
;
4009 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4010 bfd
*abfd
= objfile
->obfd
;
4011 struct attribute
*attr
;
4013 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4014 struct partial_symtab
*pst
;
4016 const char *filename
;
4018 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4021 prepare_one_comp_unit (cu
, comp_unit_die
);
4023 cu
->list_in_scope
= &file_symbols
;
4025 /* Allocate a new partial symbol table structure. */
4026 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4027 if (attr
== NULL
|| !DW_STRING (attr
))
4030 filename
= DW_STRING (attr
);
4031 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4033 /* TEXTLOW and TEXTHIGH are set below. */
4035 objfile
->global_psymbols
.next
,
4036 objfile
->static_psymbols
.next
);
4037 pst
->psymtabs_addrmap_supported
= 1;
4039 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4041 pst
->dirname
= DW_STRING (attr
);
4043 pst
->read_symtab_private
= per_cu
;
4045 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4047 /* Store the function that reads in the rest of the symbol table. */
4048 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4050 per_cu
->v
.psymtab
= pst
;
4052 dwarf2_find_base_address (comp_unit_die
, cu
);
4054 /* Possibly set the default values of LOWPC and HIGHPC from
4056 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4057 &best_highpc
, cu
, pst
);
4058 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4059 /* Store the contiguous range if it is not empty; it can be empty for
4060 CUs with no code. */
4061 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4062 best_lowpc
+ baseaddr
,
4063 best_highpc
+ baseaddr
- 1, pst
);
4065 /* Check if comp unit has_children.
4066 If so, read the rest of the partial symbols from this comp unit.
4067 If not, there's no more debug_info for this comp unit. */
4070 struct partial_die_info
*first_die
;
4071 CORE_ADDR lowpc
, highpc
;
4073 lowpc
= ((CORE_ADDR
) -1);
4074 highpc
= ((CORE_ADDR
) 0);
4076 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4078 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4081 /* If we didn't find a lowpc, set it to highpc to avoid
4082 complaints from `maint check'. */
4083 if (lowpc
== ((CORE_ADDR
) -1))
4086 /* If the compilation unit didn't have an explicit address range,
4087 then use the information extracted from its child dies. */
4091 best_highpc
= highpc
;
4094 pst
->textlow
= best_lowpc
+ baseaddr
;
4095 pst
->texthigh
= best_highpc
+ baseaddr
;
4097 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4098 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4099 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4100 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4101 sort_pst_symbols (pst
);
4103 if (per_cu
->is_debug_types
)
4105 /* It's not clear we want to do anything with stmt lists here.
4106 Waiting to see what gcc ultimately does. */
4110 /* Get the list of files included in the current compilation unit,
4111 and build a psymtab for each of them. */
4112 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4116 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4117 Process compilation unit THIS_CU for a psymtab. */
4120 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4122 /* If this compilation unit was already read in, free the
4123 cached copy in order to read it in again. This is
4124 necessary because we skipped some symbols when we first
4125 read in the compilation unit (see load_partial_dies).
4126 This problem could be avoided, but the benefit is unclear. */
4127 if (this_cu
->cu
!= NULL
)
4128 free_one_cached_comp_unit (this_cu
);
4130 gdb_assert (! this_cu
->is_debug_types
);
4131 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4134 /* Age out any secondary CUs. */
4135 age_cached_comp_units ();
4138 /* Traversal function for htab_traverse_noresize.
4139 Process one .debug_types comp-unit. */
4142 process_psymtab_type_unit (void **slot
, void *info
)
4144 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4145 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4147 gdb_assert (per_cu
->is_debug_types
);
4148 gdb_assert (info
== NULL
);
4150 /* If this compilation unit was already read in, free the
4151 cached copy in order to read it in again. This is
4152 necessary because we skipped some symbols when we first
4153 read in the compilation unit (see load_partial_dies).
4154 This problem could be avoided, but the benefit is unclear. */
4155 if (per_cu
->cu
!= NULL
)
4156 free_one_cached_comp_unit (per_cu
);
4158 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4161 /* Age out any secondary CUs. */
4162 age_cached_comp_units ();
4167 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4168 Build partial symbol tables for the .debug_types comp-units. */
4171 build_type_psymtabs (struct objfile
*objfile
)
4173 if (! create_all_type_units (objfile
))
4176 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4177 process_psymtab_type_unit
, NULL
);
4180 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4183 psymtabs_addrmap_cleanup (void *o
)
4185 struct objfile
*objfile
= o
;
4187 objfile
->psymtabs_addrmap
= NULL
;
4190 /* Build the partial symbol table by doing a quick pass through the
4191 .debug_info and .debug_abbrev sections. */
4194 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4196 struct cleanup
*back_to
, *addrmap_cleanup
;
4197 struct obstack temp_obstack
;
4200 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4202 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4204 /* Any cached compilation units will be linked by the per-objfile
4205 read_in_chain. Make sure to free them when we're done. */
4206 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4208 build_type_psymtabs (objfile
);
4210 create_all_comp_units (objfile
);
4212 /* Create a temporary address map on a temporary obstack. We later
4213 copy this to the final obstack. */
4214 obstack_init (&temp_obstack
);
4215 make_cleanup_obstack_free (&temp_obstack
);
4216 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4217 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4219 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4221 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4223 process_psymtab_comp_unit (per_cu
);
4226 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4227 &objfile
->objfile_obstack
);
4228 discard_cleanups (addrmap_cleanup
);
4230 do_cleanups (back_to
);
4233 /* die_reader_func for load_partial_comp_unit. */
4236 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4238 struct die_info
*comp_unit_die
,
4242 struct dwarf2_cu
*cu
= reader
->cu
;
4244 prepare_one_comp_unit (cu
, comp_unit_die
);
4246 /* Check if comp unit has_children.
4247 If so, read the rest of the partial symbols from this comp unit.
4248 If not, there's no more debug_info for this comp unit. */
4250 load_partial_dies (reader
, info_ptr
, 0);
4253 /* Load the partial DIEs for a secondary CU into memory.
4254 This is also used when rereading a primary CU with load_all_dies. */
4257 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4259 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4262 /* Create a list of all compilation units in OBJFILE.
4263 This is only done for -readnow and building partial symtabs. */
4266 create_all_comp_units (struct objfile
*objfile
)
4270 struct dwarf2_per_cu_data
**all_comp_units
;
4273 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4274 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4278 all_comp_units
= xmalloc (n_allocated
4279 * sizeof (struct dwarf2_per_cu_data
*));
4281 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4282 + dwarf2_per_objfile
->info
.size
)
4284 unsigned int length
, initial_length_size
;
4285 struct dwarf2_per_cu_data
*this_cu
;
4288 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4290 /* Read just enough information to find out where the next
4291 compilation unit is. */
4292 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4293 &initial_length_size
);
4295 /* Save the compilation unit for later lookup. */
4296 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4297 sizeof (struct dwarf2_per_cu_data
));
4298 memset (this_cu
, 0, sizeof (*this_cu
));
4299 this_cu
->offset
= offset
;
4300 this_cu
->length
= length
+ initial_length_size
;
4301 this_cu
->objfile
= objfile
;
4302 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4304 if (n_comp_units
== n_allocated
)
4307 all_comp_units
= xrealloc (all_comp_units
,
4309 * sizeof (struct dwarf2_per_cu_data
*));
4311 all_comp_units
[n_comp_units
++] = this_cu
;
4313 info_ptr
= info_ptr
+ this_cu
->length
;
4316 dwarf2_per_objfile
->all_comp_units
4317 = obstack_alloc (&objfile
->objfile_obstack
,
4318 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4319 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4320 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4321 xfree (all_comp_units
);
4322 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4325 /* Process all loaded DIEs for compilation unit CU, starting at
4326 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4327 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4328 DW_AT_ranges). If NEED_PC is set, then this function will set
4329 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4330 and record the covered ranges in the addrmap. */
4333 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4334 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4336 struct partial_die_info
*pdi
;
4338 /* Now, march along the PDI's, descending into ones which have
4339 interesting children but skipping the children of the other ones,
4340 until we reach the end of the compilation unit. */
4346 fixup_partial_die (pdi
, cu
);
4348 /* Anonymous namespaces or modules have no name but have interesting
4349 children, so we need to look at them. Ditto for anonymous
4352 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4353 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
4357 case DW_TAG_subprogram
:
4358 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4360 case DW_TAG_constant
:
4361 case DW_TAG_variable
:
4362 case DW_TAG_typedef
:
4363 case DW_TAG_union_type
:
4364 if (!pdi
->is_declaration
)
4366 add_partial_symbol (pdi
, cu
);
4369 case DW_TAG_class_type
:
4370 case DW_TAG_interface_type
:
4371 case DW_TAG_structure_type
:
4372 if (!pdi
->is_declaration
)
4374 add_partial_symbol (pdi
, cu
);
4377 case DW_TAG_enumeration_type
:
4378 if (!pdi
->is_declaration
)
4379 add_partial_enumeration (pdi
, cu
);
4381 case DW_TAG_base_type
:
4382 case DW_TAG_subrange_type
:
4383 /* File scope base type definitions are added to the partial
4385 add_partial_symbol (pdi
, cu
);
4387 case DW_TAG_namespace
:
4388 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4391 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4398 /* If the die has a sibling, skip to the sibling. */
4400 pdi
= pdi
->die_sibling
;
4404 /* Functions used to compute the fully scoped name of a partial DIE.
4406 Normally, this is simple. For C++, the parent DIE's fully scoped
4407 name is concatenated with "::" and the partial DIE's name. For
4408 Java, the same thing occurs except that "." is used instead of "::".
4409 Enumerators are an exception; they use the scope of their parent
4410 enumeration type, i.e. the name of the enumeration type is not
4411 prepended to the enumerator.
4413 There are two complexities. One is DW_AT_specification; in this
4414 case "parent" means the parent of the target of the specification,
4415 instead of the direct parent of the DIE. The other is compilers
4416 which do not emit DW_TAG_namespace; in this case we try to guess
4417 the fully qualified name of structure types from their members'
4418 linkage names. This must be done using the DIE's children rather
4419 than the children of any DW_AT_specification target. We only need
4420 to do this for structures at the top level, i.e. if the target of
4421 any DW_AT_specification (if any; otherwise the DIE itself) does not
4424 /* Compute the scope prefix associated with PDI's parent, in
4425 compilation unit CU. The result will be allocated on CU's
4426 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4427 field. NULL is returned if no prefix is necessary. */
4429 partial_die_parent_scope (struct partial_die_info
*pdi
,
4430 struct dwarf2_cu
*cu
)
4432 char *grandparent_scope
;
4433 struct partial_die_info
*parent
, *real_pdi
;
4435 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4436 then this means the parent of the specification DIE. */
4439 while (real_pdi
->has_specification
)
4440 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4442 parent
= real_pdi
->die_parent
;
4446 if (parent
->scope_set
)
4447 return parent
->scope
;
4449 fixup_partial_die (parent
, cu
);
4451 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4453 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4454 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4455 Work around this problem here. */
4456 if (cu
->language
== language_cplus
4457 && parent
->tag
== DW_TAG_namespace
4458 && strcmp (parent
->name
, "::") == 0
4459 && grandparent_scope
== NULL
)
4461 parent
->scope
= NULL
;
4462 parent
->scope_set
= 1;
4466 if (pdi
->tag
== DW_TAG_enumerator
)
4467 /* Enumerators should not get the name of the enumeration as a prefix. */
4468 parent
->scope
= grandparent_scope
;
4469 else if (parent
->tag
== DW_TAG_namespace
4470 || parent
->tag
== DW_TAG_module
4471 || parent
->tag
== DW_TAG_structure_type
4472 || parent
->tag
== DW_TAG_class_type
4473 || parent
->tag
== DW_TAG_interface_type
4474 || parent
->tag
== DW_TAG_union_type
4475 || parent
->tag
== DW_TAG_enumeration_type
)
4477 if (grandparent_scope
== NULL
)
4478 parent
->scope
= parent
->name
;
4480 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4482 parent
->name
, 0, cu
);
4486 /* FIXME drow/2004-04-01: What should we be doing with
4487 function-local names? For partial symbols, we should probably be
4489 complaint (&symfile_complaints
,
4490 _("unhandled containing DIE tag %d for DIE at %d"),
4491 parent
->tag
, pdi
->offset
.sect_off
);
4492 parent
->scope
= grandparent_scope
;
4495 parent
->scope_set
= 1;
4496 return parent
->scope
;
4499 /* Return the fully scoped name associated with PDI, from compilation unit
4500 CU. The result will be allocated with malloc. */
4503 partial_die_full_name (struct partial_die_info
*pdi
,
4504 struct dwarf2_cu
*cu
)
4508 /* If this is a template instantiation, we can not work out the
4509 template arguments from partial DIEs. So, unfortunately, we have
4510 to go through the full DIEs. At least any work we do building
4511 types here will be reused if full symbols are loaded later. */
4512 if (pdi
->has_template_arguments
)
4514 fixup_partial_die (pdi
, cu
);
4516 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4518 struct die_info
*die
;
4519 struct attribute attr
;
4520 struct dwarf2_cu
*ref_cu
= cu
;
4522 /* DW_FORM_ref_addr is using section offset. */
4524 attr
.form
= DW_FORM_ref_addr
;
4525 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4526 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4528 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4532 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4533 if (parent_scope
== NULL
)
4536 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4540 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4542 struct objfile
*objfile
= cu
->objfile
;
4544 char *actual_name
= NULL
;
4546 int built_actual_name
= 0;
4548 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4550 actual_name
= partial_die_full_name (pdi
, cu
);
4552 built_actual_name
= 1;
4554 if (actual_name
== NULL
)
4555 actual_name
= pdi
->name
;
4559 case DW_TAG_subprogram
:
4560 if (pdi
->is_external
|| cu
->language
== language_ada
)
4562 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4563 of the global scope. But in Ada, we want to be able to access
4564 nested procedures globally. So all Ada subprograms are stored
4565 in the global scope. */
4566 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4567 mst_text, objfile); */
4568 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4570 VAR_DOMAIN
, LOC_BLOCK
,
4571 &objfile
->global_psymbols
,
4572 0, pdi
->lowpc
+ baseaddr
,
4573 cu
->language
, objfile
);
4577 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4578 mst_file_text, objfile); */
4579 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4581 VAR_DOMAIN
, LOC_BLOCK
,
4582 &objfile
->static_psymbols
,
4583 0, pdi
->lowpc
+ baseaddr
,
4584 cu
->language
, objfile
);
4587 case DW_TAG_constant
:
4589 struct psymbol_allocation_list
*list
;
4591 if (pdi
->is_external
)
4592 list
= &objfile
->global_psymbols
;
4594 list
= &objfile
->static_psymbols
;
4595 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4596 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4597 list
, 0, 0, cu
->language
, objfile
);
4600 case DW_TAG_variable
:
4602 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4606 && !dwarf2_per_objfile
->has_section_at_zero
)
4608 /* A global or static variable may also have been stripped
4609 out by the linker if unused, in which case its address
4610 will be nullified; do not add such variables into partial
4611 symbol table then. */
4613 else if (pdi
->is_external
)
4616 Don't enter into the minimal symbol tables as there is
4617 a minimal symbol table entry from the ELF symbols already.
4618 Enter into partial symbol table if it has a location
4619 descriptor or a type.
4620 If the location descriptor is missing, new_symbol will create
4621 a LOC_UNRESOLVED symbol, the address of the variable will then
4622 be determined from the minimal symbol table whenever the variable
4624 The address for the partial symbol table entry is not
4625 used by GDB, but it comes in handy for debugging partial symbol
4628 if (pdi
->locdesc
|| pdi
->has_type
)
4629 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4631 VAR_DOMAIN
, LOC_STATIC
,
4632 &objfile
->global_psymbols
,
4634 cu
->language
, objfile
);
4638 /* Static Variable. Skip symbols without location descriptors. */
4639 if (pdi
->locdesc
== NULL
)
4641 if (built_actual_name
)
4642 xfree (actual_name
);
4645 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4646 mst_file_data, objfile); */
4647 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4649 VAR_DOMAIN
, LOC_STATIC
,
4650 &objfile
->static_psymbols
,
4652 cu
->language
, objfile
);
4655 case DW_TAG_typedef
:
4656 case DW_TAG_base_type
:
4657 case DW_TAG_subrange_type
:
4658 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4660 VAR_DOMAIN
, LOC_TYPEDEF
,
4661 &objfile
->static_psymbols
,
4662 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4664 case DW_TAG_namespace
:
4665 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4667 VAR_DOMAIN
, LOC_TYPEDEF
,
4668 &objfile
->global_psymbols
,
4669 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4671 case DW_TAG_class_type
:
4672 case DW_TAG_interface_type
:
4673 case DW_TAG_structure_type
:
4674 case DW_TAG_union_type
:
4675 case DW_TAG_enumeration_type
:
4676 /* Skip external references. The DWARF standard says in the section
4677 about "Structure, Union, and Class Type Entries": "An incomplete
4678 structure, union or class type is represented by a structure,
4679 union or class entry that does not have a byte size attribute
4680 and that has a DW_AT_declaration attribute." */
4681 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4683 if (built_actual_name
)
4684 xfree (actual_name
);
4688 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4689 static vs. global. */
4690 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4692 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4693 (cu
->language
== language_cplus
4694 || cu
->language
== language_java
)
4695 ? &objfile
->global_psymbols
4696 : &objfile
->static_psymbols
,
4697 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4700 case DW_TAG_enumerator
:
4701 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4703 VAR_DOMAIN
, LOC_CONST
,
4704 (cu
->language
== language_cplus
4705 || cu
->language
== language_java
)
4706 ? &objfile
->global_psymbols
4707 : &objfile
->static_psymbols
,
4708 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4714 if (built_actual_name
)
4715 xfree (actual_name
);
4718 /* Read a partial die corresponding to a namespace; also, add a symbol
4719 corresponding to that namespace to the symbol table. NAMESPACE is
4720 the name of the enclosing namespace. */
4723 add_partial_namespace (struct partial_die_info
*pdi
,
4724 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4725 int need_pc
, struct dwarf2_cu
*cu
)
4727 /* Add a symbol for the namespace. */
4729 add_partial_symbol (pdi
, cu
);
4731 /* Now scan partial symbols in that namespace. */
4733 if (pdi
->has_children
)
4734 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4737 /* Read a partial die corresponding to a Fortran module. */
4740 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4741 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4743 /* Now scan partial symbols in that module. */
4745 if (pdi
->has_children
)
4746 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4749 /* Read a partial die corresponding to a subprogram and create a partial
4750 symbol for that subprogram. When the CU language allows it, this
4751 routine also defines a partial symbol for each nested subprogram
4752 that this subprogram contains.
4754 DIE my also be a lexical block, in which case we simply search
4755 recursively for suprograms defined inside that lexical block.
4756 Again, this is only performed when the CU language allows this
4757 type of definitions. */
4760 add_partial_subprogram (struct partial_die_info
*pdi
,
4761 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4762 int need_pc
, struct dwarf2_cu
*cu
)
4764 if (pdi
->tag
== DW_TAG_subprogram
)
4766 if (pdi
->has_pc_info
)
4768 if (pdi
->lowpc
< *lowpc
)
4769 *lowpc
= pdi
->lowpc
;
4770 if (pdi
->highpc
> *highpc
)
4771 *highpc
= pdi
->highpc
;
4775 struct objfile
*objfile
= cu
->objfile
;
4777 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4778 SECT_OFF_TEXT (objfile
));
4779 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4780 pdi
->lowpc
+ baseaddr
,
4781 pdi
->highpc
- 1 + baseaddr
,
4782 cu
->per_cu
->v
.psymtab
);
4786 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4788 if (!pdi
->is_declaration
)
4789 /* Ignore subprogram DIEs that do not have a name, they are
4790 illegal. Do not emit a complaint at this point, we will
4791 do so when we convert this psymtab into a symtab. */
4793 add_partial_symbol (pdi
, cu
);
4797 if (! pdi
->has_children
)
4800 if (cu
->language
== language_ada
)
4802 pdi
= pdi
->die_child
;
4805 fixup_partial_die (pdi
, cu
);
4806 if (pdi
->tag
== DW_TAG_subprogram
4807 || pdi
->tag
== DW_TAG_lexical_block
)
4808 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4809 pdi
= pdi
->die_sibling
;
4814 /* Read a partial die corresponding to an enumeration type. */
4817 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4818 struct dwarf2_cu
*cu
)
4820 struct partial_die_info
*pdi
;
4822 if (enum_pdi
->name
!= NULL
)
4823 add_partial_symbol (enum_pdi
, cu
);
4825 pdi
= enum_pdi
->die_child
;
4828 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4829 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4831 add_partial_symbol (pdi
, cu
);
4832 pdi
= pdi
->die_sibling
;
4836 /* Return the initial uleb128 in the die at INFO_PTR. */
4839 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4841 unsigned int bytes_read
;
4843 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4846 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4847 Return the corresponding abbrev, or NULL if the number is zero (indicating
4848 an empty DIE). In either case *BYTES_READ will be set to the length of
4849 the initial number. */
4851 static struct abbrev_info
*
4852 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4853 struct dwarf2_cu
*cu
)
4855 bfd
*abfd
= cu
->objfile
->obfd
;
4856 unsigned int abbrev_number
;
4857 struct abbrev_info
*abbrev
;
4859 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4861 if (abbrev_number
== 0)
4864 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4867 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4868 abbrev_number
, bfd_get_filename (abfd
));
4874 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4875 Returns a pointer to the end of a series of DIEs, terminated by an empty
4876 DIE. Any children of the skipped DIEs will also be skipped. */
4879 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
4881 struct dwarf2_cu
*cu
= reader
->cu
;
4882 struct abbrev_info
*abbrev
;
4883 unsigned int bytes_read
;
4887 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4889 return info_ptr
+ bytes_read
;
4891 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
4895 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4896 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4897 abbrev corresponding to that skipped uleb128 should be passed in
4898 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4902 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
4903 struct abbrev_info
*abbrev
)
4905 unsigned int bytes_read
;
4906 struct attribute attr
;
4907 bfd
*abfd
= reader
->abfd
;
4908 struct dwarf2_cu
*cu
= reader
->cu
;
4909 gdb_byte
*buffer
= reader
->buffer
;
4910 unsigned int form
, i
;
4912 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4914 /* The only abbrev we care about is DW_AT_sibling. */
4915 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4917 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
4918 if (attr
.form
== DW_FORM_ref_addr
)
4919 complaint (&symfile_complaints
,
4920 _("ignoring absolute DW_AT_sibling"));
4922 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4925 /* If it isn't DW_AT_sibling, skip this attribute. */
4926 form
= abbrev
->attrs
[i
].form
;
4930 case DW_FORM_ref_addr
:
4931 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4932 and later it is offset sized. */
4933 if (cu
->header
.version
== 2)
4934 info_ptr
+= cu
->header
.addr_size
;
4936 info_ptr
+= cu
->header
.offset_size
;
4939 info_ptr
+= cu
->header
.addr_size
;
4946 case DW_FORM_flag_present
:
4958 case DW_FORM_ref_sig8
:
4961 case DW_FORM_string
:
4962 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4963 info_ptr
+= bytes_read
;
4965 case DW_FORM_sec_offset
:
4967 info_ptr
+= cu
->header
.offset_size
;
4969 case DW_FORM_exprloc
:
4971 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4972 info_ptr
+= bytes_read
;
4974 case DW_FORM_block1
:
4975 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4977 case DW_FORM_block2
:
4978 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4980 case DW_FORM_block4
:
4981 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4985 case DW_FORM_ref_udata
:
4986 case DW_FORM_GNU_addr_index
:
4987 case DW_FORM_GNU_str_index
:
4988 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4990 case DW_FORM_indirect
:
4991 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4992 info_ptr
+= bytes_read
;
4993 /* We need to continue parsing from here, so just go back to
4995 goto skip_attribute
;
4998 error (_("Dwarf Error: Cannot handle %s "
4999 "in DWARF reader [in module %s]"),
5000 dwarf_form_name (form
),
5001 bfd_get_filename (abfd
));
5005 if (abbrev
->has_children
)
5006 return skip_children (reader
, info_ptr
);
5011 /* Locate ORIG_PDI's sibling.
5012 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5015 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5016 struct partial_die_info
*orig_pdi
,
5019 /* Do we know the sibling already? */
5021 if (orig_pdi
->sibling
)
5022 return orig_pdi
->sibling
;
5024 /* Are there any children to deal with? */
5026 if (!orig_pdi
->has_children
)
5029 /* Skip the children the long way. */
5031 return skip_children (reader
, info_ptr
);
5034 /* Expand this partial symbol table into a full symbol table. */
5037 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5043 warning (_("bug: psymtab for %s is already read in."),
5050 printf_filtered (_("Reading in symbols for %s..."),
5052 gdb_flush (gdb_stdout
);
5055 /* Restore our global data. */
5056 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5057 dwarf2_objfile_data_key
);
5059 /* If this psymtab is constructed from a debug-only objfile, the
5060 has_section_at_zero flag will not necessarily be correct. We
5061 can get the correct value for this flag by looking at the data
5062 associated with the (presumably stripped) associated objfile. */
5063 if (pst
->objfile
->separate_debug_objfile_backlink
)
5065 struct dwarf2_per_objfile
*dpo_backlink
5066 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5067 dwarf2_objfile_data_key
);
5069 dwarf2_per_objfile
->has_section_at_zero
5070 = dpo_backlink
->has_section_at_zero
;
5073 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5075 psymtab_to_symtab_1 (pst
);
5077 /* Finish up the debug error message. */
5079 printf_filtered (_("done.\n"));
5084 /* Reading in full CUs. */
5086 /* Add PER_CU to the queue. */
5089 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5091 struct dwarf2_queue_item
*item
;
5094 item
= xmalloc (sizeof (*item
));
5095 item
->per_cu
= per_cu
;
5098 if (dwarf2_queue
== NULL
)
5099 dwarf2_queue
= item
;
5101 dwarf2_queue_tail
->next
= item
;
5103 dwarf2_queue_tail
= item
;
5106 /* Process the queue. */
5109 process_queue (void)
5111 struct dwarf2_queue_item
*item
, *next_item
;
5113 /* The queue starts out with one item, but following a DIE reference
5114 may load a new CU, adding it to the end of the queue. */
5115 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5117 if (dwarf2_per_objfile
->using_index
5118 ? !item
->per_cu
->v
.quick
->symtab
5119 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5120 process_full_comp_unit (item
->per_cu
);
5122 item
->per_cu
->queued
= 0;
5123 next_item
= item
->next
;
5127 dwarf2_queue_tail
= NULL
;
5130 /* Free all allocated queue entries. This function only releases anything if
5131 an error was thrown; if the queue was processed then it would have been
5132 freed as we went along. */
5135 dwarf2_release_queue (void *dummy
)
5137 struct dwarf2_queue_item
*item
, *last
;
5139 item
= dwarf2_queue
;
5142 /* Anything still marked queued is likely to be in an
5143 inconsistent state, so discard it. */
5144 if (item
->per_cu
->queued
)
5146 if (item
->per_cu
->cu
!= NULL
)
5147 free_one_cached_comp_unit (item
->per_cu
);
5148 item
->per_cu
->queued
= 0;
5156 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5159 /* Read in full symbols for PST, and anything it depends on. */
5162 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5164 struct dwarf2_per_cu_data
*per_cu
;
5165 struct cleanup
*back_to
;
5168 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5169 if (!pst
->dependencies
[i
]->readin
)
5171 /* Inform about additional files that need to be read in. */
5174 /* FIXME: i18n: Need to make this a single string. */
5175 fputs_filtered (" ", gdb_stdout
);
5177 fputs_filtered ("and ", gdb_stdout
);
5179 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5180 wrap_here (""); /* Flush output. */
5181 gdb_flush (gdb_stdout
);
5183 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5186 per_cu
= pst
->read_symtab_private
;
5190 /* It's an include file, no symbols to read for it.
5191 Everything is in the parent symtab. */
5196 dw2_do_instantiate_symtab (per_cu
);
5199 /* Trivial hash function for die_info: the hash value of a DIE
5200 is its offset in .debug_info for this objfile. */
5203 die_hash (const void *item
)
5205 const struct die_info
*die
= item
;
5207 return die
->offset
.sect_off
;
5210 /* Trivial comparison function for die_info structures: two DIEs
5211 are equal if they have the same offset. */
5214 die_eq (const void *item_lhs
, const void *item_rhs
)
5216 const struct die_info
*die_lhs
= item_lhs
;
5217 const struct die_info
*die_rhs
= item_rhs
;
5219 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5222 /* die_reader_func for load_full_comp_unit.
5223 This is identical to read_signatured_type_reader,
5224 but is kept separate for now. */
5227 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5229 struct die_info
*comp_unit_die
,
5233 struct dwarf2_cu
*cu
= reader
->cu
;
5234 struct attribute
*attr
;
5236 gdb_assert (cu
->die_hash
== NULL
);
5238 htab_create_alloc_ex (cu
->header
.length
/ 12,
5242 &cu
->comp_unit_obstack
,
5243 hashtab_obstack_allocate
,
5244 dummy_obstack_deallocate
);
5247 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5248 &info_ptr
, comp_unit_die
);
5249 cu
->dies
= comp_unit_die
;
5250 /* comp_unit_die is not stored in die_hash, no need. */
5252 /* We try not to read any attributes in this function, because not
5253 all CUs needed for references have been loaded yet, and symbol
5254 table processing isn't initialized. But we have to set the CU language,
5255 or we won't be able to build types correctly.
5256 Similarly, if we do not read the producer, we can not apply
5257 producer-specific interpretation. */
5258 prepare_one_comp_unit (cu
, cu
->dies
);
5261 /* Load the DIEs associated with PER_CU into memory. */
5264 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5266 gdb_assert (! this_cu
->is_debug_types
);
5268 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
, NULL
);
5271 /* Add a DIE to the delayed physname list. */
5274 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5275 const char *name
, struct die_info
*die
,
5276 struct dwarf2_cu
*cu
)
5278 struct delayed_method_info mi
;
5280 mi
.fnfield_index
= fnfield_index
;
5284 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5287 /* A cleanup for freeing the delayed method list. */
5290 free_delayed_list (void *ptr
)
5292 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5293 if (cu
->method_list
!= NULL
)
5295 VEC_free (delayed_method_info
, cu
->method_list
);
5296 cu
->method_list
= NULL
;
5300 /* Compute the physnames of any methods on the CU's method list.
5302 The computation of method physnames is delayed in order to avoid the
5303 (bad) condition that one of the method's formal parameters is of an as yet
5307 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5310 struct delayed_method_info
*mi
;
5311 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5313 const char *physname
;
5314 struct fn_fieldlist
*fn_flp
5315 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5316 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5317 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5321 /* Go objects should be embedded in a DW_TAG_module DIE,
5322 and it's not clear if/how imported objects will appear.
5323 To keep Go support simple until that's worked out,
5324 go back through what we've read and create something usable.
5325 We could do this while processing each DIE, and feels kinda cleaner,
5326 but that way is more invasive.
5327 This is to, for example, allow the user to type "p var" or "b main"
5328 without having to specify the package name, and allow lookups
5329 of module.object to work in contexts that use the expression
5333 fixup_go_packaging (struct dwarf2_cu
*cu
)
5335 char *package_name
= NULL
;
5336 struct pending
*list
;
5339 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5341 for (i
= 0; i
< list
->nsyms
; ++i
)
5343 struct symbol
*sym
= list
->symbol
[i
];
5345 if (SYMBOL_LANGUAGE (sym
) == language_go
5346 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5348 char *this_package_name
= go_symbol_package_name (sym
);
5350 if (this_package_name
== NULL
)
5352 if (package_name
== NULL
)
5353 package_name
= this_package_name
;
5356 if (strcmp (package_name
, this_package_name
) != 0)
5357 complaint (&symfile_complaints
,
5358 _("Symtab %s has objects from two different Go packages: %s and %s"),
5359 (sym
->symtab
&& sym
->symtab
->filename
5360 ? sym
->symtab
->filename
5361 : cu
->objfile
->name
),
5362 this_package_name
, package_name
);
5363 xfree (this_package_name
);
5369 if (package_name
!= NULL
)
5371 struct objfile
*objfile
= cu
->objfile
;
5372 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5373 package_name
, objfile
);
5376 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5378 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5379 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5380 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5381 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5382 e.g., "main" finds the "main" module and not C's main(). */
5383 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5384 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5385 SYMBOL_TYPE (sym
) = type
;
5387 add_symbol_to_list (sym
, &global_symbols
);
5389 xfree (package_name
);
5393 /* Generate full symbol information for PER_CU, whose DIEs have
5394 already been loaded into memory. */
5397 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5399 struct dwarf2_cu
*cu
= per_cu
->cu
;
5400 struct objfile
*objfile
= per_cu
->objfile
;
5401 CORE_ADDR lowpc
, highpc
;
5402 struct symtab
*symtab
;
5403 struct cleanup
*back_to
, *delayed_list_cleanup
;
5406 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5409 back_to
= make_cleanup (really_free_pendings
, NULL
);
5410 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5412 cu
->list_in_scope
= &file_symbols
;
5414 /* Do line number decoding in read_file_scope () */
5415 process_die (cu
->dies
, cu
);
5417 /* For now fudge the Go package. */
5418 if (cu
->language
== language_go
)
5419 fixup_go_packaging (cu
);
5421 /* Now that we have processed all the DIEs in the CU, all the types
5422 should be complete, and it should now be safe to compute all of the
5424 compute_delayed_physnames (cu
);
5425 do_cleanups (delayed_list_cleanup
);
5427 /* Some compilers don't define a DW_AT_high_pc attribute for the
5428 compilation unit. If the DW_AT_high_pc is missing, synthesize
5429 it, by scanning the DIE's below the compilation unit. */
5430 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5432 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5436 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5438 /* Set symtab language to language from DW_AT_language. If the
5439 compilation is from a C file generated by language preprocessors, do
5440 not set the language if it was already deduced by start_subfile. */
5441 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5442 symtab
->language
= cu
->language
;
5444 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5445 produce DW_AT_location with location lists but it can be possibly
5446 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5447 there were bugs in prologue debug info, fixed later in GCC-4.5
5448 by "unwind info for epilogues" patch (which is not directly related).
5450 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5451 needed, it would be wrong due to missing DW_AT_producer there.
5453 Still one can confuse GDB by using non-standard GCC compilation
5454 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5456 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5457 symtab
->locations_valid
= 1;
5459 if (gcc_4_minor
>= 5)
5460 symtab
->epilogue_unwind_valid
= 1;
5462 symtab
->call_site_htab
= cu
->call_site_htab
;
5465 if (dwarf2_per_objfile
->using_index
)
5466 per_cu
->v
.quick
->symtab
= symtab
;
5469 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5470 pst
->symtab
= symtab
;
5474 do_cleanups (back_to
);
5477 /* Process a die and its children. */
5480 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5484 case DW_TAG_padding
:
5486 case DW_TAG_compile_unit
:
5487 read_file_scope (die
, cu
);
5489 case DW_TAG_type_unit
:
5490 read_type_unit_scope (die
, cu
);
5492 case DW_TAG_subprogram
:
5493 case DW_TAG_inlined_subroutine
:
5494 read_func_scope (die
, cu
);
5496 case DW_TAG_lexical_block
:
5497 case DW_TAG_try_block
:
5498 case DW_TAG_catch_block
:
5499 read_lexical_block_scope (die
, cu
);
5501 case DW_TAG_GNU_call_site
:
5502 read_call_site_scope (die
, cu
);
5504 case DW_TAG_class_type
:
5505 case DW_TAG_interface_type
:
5506 case DW_TAG_structure_type
:
5507 case DW_TAG_union_type
:
5508 process_structure_scope (die
, cu
);
5510 case DW_TAG_enumeration_type
:
5511 process_enumeration_scope (die
, cu
);
5514 /* These dies have a type, but processing them does not create
5515 a symbol or recurse to process the children. Therefore we can
5516 read them on-demand through read_type_die. */
5517 case DW_TAG_subroutine_type
:
5518 case DW_TAG_set_type
:
5519 case DW_TAG_array_type
:
5520 case DW_TAG_pointer_type
:
5521 case DW_TAG_ptr_to_member_type
:
5522 case DW_TAG_reference_type
:
5523 case DW_TAG_string_type
:
5526 case DW_TAG_base_type
:
5527 case DW_TAG_subrange_type
:
5528 case DW_TAG_typedef
:
5529 /* Add a typedef symbol for the type definition, if it has a
5531 new_symbol (die
, read_type_die (die
, cu
), cu
);
5533 case DW_TAG_common_block
:
5534 read_common_block (die
, cu
);
5536 case DW_TAG_common_inclusion
:
5538 case DW_TAG_namespace
:
5539 processing_has_namespace_info
= 1;
5540 read_namespace (die
, cu
);
5543 processing_has_namespace_info
= 1;
5544 read_module (die
, cu
);
5546 case DW_TAG_imported_declaration
:
5547 case DW_TAG_imported_module
:
5548 processing_has_namespace_info
= 1;
5549 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5550 || cu
->language
!= language_fortran
))
5551 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5552 dwarf_tag_name (die
->tag
));
5553 read_import_statement (die
, cu
);
5556 new_symbol (die
, NULL
, cu
);
5561 /* A helper function for dwarf2_compute_name which determines whether DIE
5562 needs to have the name of the scope prepended to the name listed in the
5566 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5568 struct attribute
*attr
;
5572 case DW_TAG_namespace
:
5573 case DW_TAG_typedef
:
5574 case DW_TAG_class_type
:
5575 case DW_TAG_interface_type
:
5576 case DW_TAG_structure_type
:
5577 case DW_TAG_union_type
:
5578 case DW_TAG_enumeration_type
:
5579 case DW_TAG_enumerator
:
5580 case DW_TAG_subprogram
:
5584 case DW_TAG_variable
:
5585 case DW_TAG_constant
:
5586 /* We only need to prefix "globally" visible variables. These include
5587 any variable marked with DW_AT_external or any variable that
5588 lives in a namespace. [Variables in anonymous namespaces
5589 require prefixing, but they are not DW_AT_external.] */
5591 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5593 struct dwarf2_cu
*spec_cu
= cu
;
5595 return die_needs_namespace (die_specification (die
, &spec_cu
),
5599 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5600 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5601 && die
->parent
->tag
!= DW_TAG_module
)
5603 /* A variable in a lexical block of some kind does not need a
5604 namespace, even though in C++ such variables may be external
5605 and have a mangled name. */
5606 if (die
->parent
->tag
== DW_TAG_lexical_block
5607 || die
->parent
->tag
== DW_TAG_try_block
5608 || die
->parent
->tag
== DW_TAG_catch_block
5609 || die
->parent
->tag
== DW_TAG_subprogram
)
5618 /* Retrieve the last character from a mem_file. */
5621 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5623 char *last_char_p
= (char *) object
;
5626 *last_char_p
= buffer
[length
- 1];
5629 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5630 compute the physname for the object, which include a method's:
5631 - formal parameters (C++/Java),
5632 - receiver type (Go),
5633 - return type (Java).
5635 The term "physname" is a bit confusing.
5636 For C++, for example, it is the demangled name.
5637 For Go, for example, it's the mangled name.
5639 For Ada, return the DIE's linkage name rather than the fully qualified
5640 name. PHYSNAME is ignored..
5642 The result is allocated on the objfile_obstack and canonicalized. */
5645 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5648 struct objfile
*objfile
= cu
->objfile
;
5651 name
= dwarf2_name (die
, cu
);
5653 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5654 compute it by typename_concat inside GDB. */
5655 if (cu
->language
== language_ada
5656 || (cu
->language
== language_fortran
&& physname
))
5658 /* For Ada unit, we prefer the linkage name over the name, as
5659 the former contains the exported name, which the user expects
5660 to be able to reference. Ideally, we want the user to be able
5661 to reference this entity using either natural or linkage name,
5662 but we haven't started looking at this enhancement yet. */
5663 struct attribute
*attr
;
5665 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5667 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5668 if (attr
&& DW_STRING (attr
))
5669 return DW_STRING (attr
);
5672 /* These are the only languages we know how to qualify names in. */
5674 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5675 || cu
->language
== language_fortran
))
5677 if (die_needs_namespace (die
, cu
))
5681 struct ui_file
*buf
;
5683 prefix
= determine_prefix (die
, cu
);
5684 buf
= mem_fileopen ();
5685 if (*prefix
!= '\0')
5687 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5690 fputs_unfiltered (prefixed_name
, buf
);
5691 xfree (prefixed_name
);
5694 fputs_unfiltered (name
, buf
);
5696 /* Template parameters may be specified in the DIE's DW_AT_name, or
5697 as children with DW_TAG_template_type_param or
5698 DW_TAG_value_type_param. If the latter, add them to the name
5699 here. If the name already has template parameters, then
5700 skip this step; some versions of GCC emit both, and
5701 it is more efficient to use the pre-computed name.
5703 Something to keep in mind about this process: it is very
5704 unlikely, or in some cases downright impossible, to produce
5705 something that will match the mangled name of a function.
5706 If the definition of the function has the same debug info,
5707 we should be able to match up with it anyway. But fallbacks
5708 using the minimal symbol, for instance to find a method
5709 implemented in a stripped copy of libstdc++, will not work.
5710 If we do not have debug info for the definition, we will have to
5711 match them up some other way.
5713 When we do name matching there is a related problem with function
5714 templates; two instantiated function templates are allowed to
5715 differ only by their return types, which we do not add here. */
5717 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5719 struct attribute
*attr
;
5720 struct die_info
*child
;
5723 die
->building_fullname
= 1;
5725 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5730 struct dwarf2_locexpr_baton
*baton
;
5733 if (child
->tag
!= DW_TAG_template_type_param
5734 && child
->tag
!= DW_TAG_template_value_param
)
5739 fputs_unfiltered ("<", buf
);
5743 fputs_unfiltered (", ", buf
);
5745 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5748 complaint (&symfile_complaints
,
5749 _("template parameter missing DW_AT_type"));
5750 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5753 type
= die_type (child
, cu
);
5755 if (child
->tag
== DW_TAG_template_type_param
)
5757 c_print_type (type
, "", buf
, -1, 0);
5761 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5764 complaint (&symfile_complaints
,
5765 _("template parameter missing "
5766 "DW_AT_const_value"));
5767 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5771 dwarf2_const_value_attr (attr
, type
, name
,
5772 &cu
->comp_unit_obstack
, cu
,
5773 &value
, &bytes
, &baton
);
5775 if (TYPE_NOSIGN (type
))
5776 /* GDB prints characters as NUMBER 'CHAR'. If that's
5777 changed, this can use value_print instead. */
5778 c_printchar (value
, type
, buf
);
5781 struct value_print_options opts
;
5784 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5788 else if (bytes
!= NULL
)
5790 v
= allocate_value (type
);
5791 memcpy (value_contents_writeable (v
), bytes
,
5792 TYPE_LENGTH (type
));
5795 v
= value_from_longest (type
, value
);
5797 /* Specify decimal so that we do not depend on
5799 get_formatted_print_options (&opts
, 'd');
5801 value_print (v
, buf
, &opts
);
5807 die
->building_fullname
= 0;
5811 /* Close the argument list, with a space if necessary
5812 (nested templates). */
5813 char last_char
= '\0';
5814 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5815 if (last_char
== '>')
5816 fputs_unfiltered (" >", buf
);
5818 fputs_unfiltered (">", buf
);
5822 /* For Java and C++ methods, append formal parameter type
5823 information, if PHYSNAME. */
5825 if (physname
&& die
->tag
== DW_TAG_subprogram
5826 && (cu
->language
== language_cplus
5827 || cu
->language
== language_java
))
5829 struct type
*type
= read_type_die (die
, cu
);
5831 c_type_print_args (type
, buf
, 1, cu
->language
);
5833 if (cu
->language
== language_java
)
5835 /* For java, we must append the return type to method
5837 if (die
->tag
== DW_TAG_subprogram
)
5838 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5841 else if (cu
->language
== language_cplus
)
5843 /* Assume that an artificial first parameter is
5844 "this", but do not crash if it is not. RealView
5845 marks unnamed (and thus unused) parameters as
5846 artificial; there is no way to differentiate
5848 if (TYPE_NFIELDS (type
) > 0
5849 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5850 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5851 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5853 fputs_unfiltered (" const", buf
);
5857 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5859 ui_file_delete (buf
);
5861 if (cu
->language
== language_cplus
)
5864 = dwarf2_canonicalize_name (name
, cu
,
5865 &objfile
->objfile_obstack
);
5876 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5877 If scope qualifiers are appropriate they will be added. The result
5878 will be allocated on the objfile_obstack, or NULL if the DIE does
5879 not have a name. NAME may either be from a previous call to
5880 dwarf2_name or NULL.
5882 The output string will be canonicalized (if C++/Java). */
5885 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5887 return dwarf2_compute_name (name
, die
, cu
, 0);
5890 /* Construct a physname for the given DIE in CU. NAME may either be
5891 from a previous call to dwarf2_name or NULL. The result will be
5892 allocated on the objfile_objstack or NULL if the DIE does not have a
5895 The output string will be canonicalized (if C++/Java). */
5898 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5900 struct objfile
*objfile
= cu
->objfile
;
5901 struct attribute
*attr
;
5902 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5903 struct cleanup
*back_to
;
5906 /* In this case dwarf2_compute_name is just a shortcut not building anything
5908 if (!die_needs_namespace (die
, cu
))
5909 return dwarf2_compute_name (name
, die
, cu
, 1);
5911 back_to
= make_cleanup (null_cleanup
, NULL
);
5913 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5915 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5917 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5919 if (attr
&& DW_STRING (attr
))
5923 mangled
= DW_STRING (attr
);
5925 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5926 type. It is easier for GDB users to search for such functions as
5927 `name(params)' than `long name(params)'. In such case the minimal
5928 symbol names do not match the full symbol names but for template
5929 functions there is never a need to look up their definition from their
5930 declaration so the only disadvantage remains the minimal symbol
5931 variant `long name(params)' does not have the proper inferior type.
5934 if (cu
->language
== language_go
)
5936 /* This is a lie, but we already lie to the caller new_symbol_full.
5937 new_symbol_full assumes we return the mangled name.
5938 This just undoes that lie until things are cleaned up. */
5943 demangled
= cplus_demangle (mangled
,
5944 (DMGL_PARAMS
| DMGL_ANSI
5945 | (cu
->language
== language_java
5946 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5951 make_cleanup (xfree
, demangled
);
5961 if (canon
== NULL
|| check_physname
)
5963 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5965 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5967 /* It may not mean a bug in GDB. The compiler could also
5968 compute DW_AT_linkage_name incorrectly. But in such case
5969 GDB would need to be bug-to-bug compatible. */
5971 complaint (&symfile_complaints
,
5972 _("Computed physname <%s> does not match demangled <%s> "
5973 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5974 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
5976 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5977 is available here - over computed PHYSNAME. It is safer
5978 against both buggy GDB and buggy compilers. */
5992 retval
= obsavestring (retval
, strlen (retval
),
5993 &objfile
->objfile_obstack
);
5995 do_cleanups (back_to
);
5999 /* Read the import statement specified by the given die and record it. */
6002 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6004 struct objfile
*objfile
= cu
->objfile
;
6005 struct attribute
*import_attr
;
6006 struct die_info
*imported_die
, *child_die
;
6007 struct dwarf2_cu
*imported_cu
;
6008 const char *imported_name
;
6009 const char *imported_name_prefix
;
6010 const char *canonical_name
;
6011 const char *import_alias
;
6012 const char *imported_declaration
= NULL
;
6013 const char *import_prefix
;
6014 VEC (const_char_ptr
) *excludes
= NULL
;
6015 struct cleanup
*cleanups
;
6019 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6020 if (import_attr
== NULL
)
6022 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6023 dwarf_tag_name (die
->tag
));
6028 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6029 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6030 if (imported_name
== NULL
)
6032 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6034 The import in the following code:
6048 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6049 <52> DW_AT_decl_file : 1
6050 <53> DW_AT_decl_line : 6
6051 <54> DW_AT_import : <0x75>
6052 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6054 <5b> DW_AT_decl_file : 1
6055 <5c> DW_AT_decl_line : 2
6056 <5d> DW_AT_type : <0x6e>
6058 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6059 <76> DW_AT_byte_size : 4
6060 <77> DW_AT_encoding : 5 (signed)
6062 imports the wrong die ( 0x75 instead of 0x58 ).
6063 This case will be ignored until the gcc bug is fixed. */
6067 /* Figure out the local name after import. */
6068 import_alias
= dwarf2_name (die
, cu
);
6070 /* Figure out where the statement is being imported to. */
6071 import_prefix
= determine_prefix (die
, cu
);
6073 /* Figure out what the scope of the imported die is and prepend it
6074 to the name of the imported die. */
6075 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6077 if (imported_die
->tag
!= DW_TAG_namespace
6078 && imported_die
->tag
!= DW_TAG_module
)
6080 imported_declaration
= imported_name
;
6081 canonical_name
= imported_name_prefix
;
6083 else if (strlen (imported_name_prefix
) > 0)
6085 temp
= alloca (strlen (imported_name_prefix
)
6086 + 2 + strlen (imported_name
) + 1);
6087 strcpy (temp
, imported_name_prefix
);
6088 strcat (temp
, "::");
6089 strcat (temp
, imported_name
);
6090 canonical_name
= temp
;
6093 canonical_name
= imported_name
;
6095 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6097 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6098 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6099 child_die
= sibling_die (child_die
))
6101 /* DWARF-4: A Fortran use statement with a “rename list” may be
6102 represented by an imported module entry with an import attribute
6103 referring to the module and owned entries corresponding to those
6104 entities that are renamed as part of being imported. */
6106 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6108 complaint (&symfile_complaints
,
6109 _("child DW_TAG_imported_declaration expected "
6110 "- DIE at 0x%x [in module %s]"),
6111 child_die
->offset
.sect_off
, objfile
->name
);
6115 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6116 if (import_attr
== NULL
)
6118 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6119 dwarf_tag_name (child_die
->tag
));
6124 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6126 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6127 if (imported_name
== NULL
)
6129 complaint (&symfile_complaints
,
6130 _("child DW_TAG_imported_declaration has unknown "
6131 "imported name - DIE at 0x%x [in module %s]"),
6132 child_die
->offset
.sect_off
, objfile
->name
);
6136 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6138 process_die (child_die
, cu
);
6141 cp_add_using_directive (import_prefix
,
6144 imported_declaration
,
6146 &objfile
->objfile_obstack
);
6148 do_cleanups (cleanups
);
6151 /* Cleanup function for read_file_scope. */
6154 free_cu_line_header (void *arg
)
6156 struct dwarf2_cu
*cu
= arg
;
6158 free_line_header (cu
->line_header
);
6159 cu
->line_header
= NULL
;
6163 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6164 char **name
, char **comp_dir
)
6166 struct attribute
*attr
;
6171 /* Find the filename. Do not use dwarf2_name here, since the filename
6172 is not a source language identifier. */
6173 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6176 *name
= DW_STRING (attr
);
6179 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6181 *comp_dir
= DW_STRING (attr
);
6182 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6184 *comp_dir
= ldirname (*name
);
6185 if (*comp_dir
!= NULL
)
6186 make_cleanup (xfree
, *comp_dir
);
6188 if (*comp_dir
!= NULL
)
6190 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6191 directory, get rid of it. */
6192 char *cp
= strchr (*comp_dir
, ':');
6194 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6199 *name
= "<unknown>";
6202 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6203 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6204 COMP_DIR is the compilation directory.
6205 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6208 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6209 const char *comp_dir
, int want_line_info
)
6211 struct attribute
*attr
;
6213 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6216 unsigned int line_offset
= DW_UNSND (attr
);
6217 struct line_header
*line_header
6218 = dwarf_decode_line_header (line_offset
, cu
);
6222 cu
->line_header
= line_header
;
6223 make_cleanup (free_cu_line_header
, cu
);
6224 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6229 /* Process DW_TAG_compile_unit. */
6232 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6235 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6236 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6237 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6238 struct attribute
*attr
;
6240 char *comp_dir
= NULL
;
6241 struct die_info
*child_die
;
6242 bfd
*abfd
= objfile
->obfd
;
6245 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6247 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6249 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6250 from finish_block. */
6251 if (lowpc
== ((CORE_ADDR
) -1))
6256 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6258 prepare_one_comp_unit (cu
, die
);
6260 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6261 standardised yet. As a workaround for the language detection we fall
6262 back to the DW_AT_producer string. */
6263 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6264 cu
->language
= language_opencl
;
6266 /* Similar hack for Go. */
6267 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6268 set_cu_language (DW_LANG_Go
, cu
);
6270 /* We assume that we're processing GCC output. */
6271 processing_gcc_compilation
= 2;
6273 processing_has_namespace_info
= 0;
6275 start_symtab (name
, comp_dir
, lowpc
);
6276 record_debugformat ("DWARF 2");
6277 record_producer (cu
->producer
);
6279 /* Decode line number information if present. We do this before
6280 processing child DIEs, so that the line header table is available
6281 for DW_AT_decl_file. */
6282 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6284 /* Process all dies in compilation unit. */
6285 if (die
->child
!= NULL
)
6287 child_die
= die
->child
;
6288 while (child_die
&& child_die
->tag
)
6290 process_die (child_die
, cu
);
6291 child_die
= sibling_die (child_die
);
6295 /* Decode macro information, if present. Dwarf 2 macro information
6296 refers to information in the line number info statement program
6297 header, so we can only read it if we've read the header
6299 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6300 if (attr
&& cu
->line_header
)
6302 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6303 complaint (&symfile_complaints
,
6304 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6306 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6308 &dwarf2_per_objfile
->macro
, 1,
6313 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6314 if (attr
&& cu
->line_header
)
6316 unsigned int macro_offset
= DW_UNSND (attr
);
6318 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6320 &dwarf2_per_objfile
->macinfo
, 0,
6325 do_cleanups (back_to
);
6328 /* Process DW_TAG_type_unit.
6329 For TUs we want to skip the first top level sibling if it's not the
6330 actual type being defined by this TU. In this case the first top
6331 level sibling is there to provide context only. */
6334 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6336 struct objfile
*objfile
= cu
->objfile
;
6337 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6339 struct attribute
*attr
;
6341 char *comp_dir
= NULL
;
6342 struct die_info
*child_die
;
6343 bfd
*abfd
= objfile
->obfd
;
6345 /* start_symtab needs a low pc, but we don't really have one.
6346 Do what read_file_scope would do in the absence of such info. */
6347 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6349 /* Find the filename. Do not use dwarf2_name here, since the filename
6350 is not a source language identifier. */
6351 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6353 name
= DW_STRING (attr
);
6355 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6357 comp_dir
= DW_STRING (attr
);
6358 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6360 comp_dir
= ldirname (name
);
6361 if (comp_dir
!= NULL
)
6362 make_cleanup (xfree
, comp_dir
);
6368 prepare_one_comp_unit (cu
, die
);
6370 /* We assume that we're processing GCC output. */
6371 processing_gcc_compilation
= 2;
6373 processing_has_namespace_info
= 0;
6375 start_symtab (name
, comp_dir
, lowpc
);
6376 record_debugformat ("DWARF 2");
6377 record_producer (cu
->producer
);
6379 /* Decode line number information if present. We do this before
6380 processing child DIEs, so that the line header table is available
6381 for DW_AT_decl_file.
6382 We don't need the pc/line-number mapping for type units. */
6383 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6385 /* Process the dies in the type unit. */
6386 if (die
->child
== NULL
)
6388 dump_die_for_error (die
);
6389 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6390 bfd_get_filename (abfd
));
6393 child_die
= die
->child
;
6395 while (child_die
&& child_die
->tag
)
6397 process_die (child_die
, cu
);
6399 child_die
= sibling_die (child_die
);
6402 do_cleanups (back_to
);
6408 hash_dwo_file (const void *item
)
6410 const struct dwo_file
*dwo_file
= item
;
6412 return htab_hash_string (dwo_file
->dwo_name
);
6416 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6418 const struct dwo_file
*lhs
= item_lhs
;
6419 const struct dwo_file
*rhs
= item_rhs
;
6421 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6424 /* Allocate a hash table for DWO files. */
6427 allocate_dwo_file_hash_table (void)
6429 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6431 return htab_create_alloc_ex (41,
6435 &objfile
->objfile_obstack
,
6436 hashtab_obstack_allocate
,
6437 dummy_obstack_deallocate
);
6441 hash_dwo_unit (const void *item
)
6443 const struct dwo_unit
*dwo_unit
= item
;
6445 /* This drops the top 32 bits of the id, but is ok for a hash. */
6446 return dwo_unit
->signature
;
6450 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6452 const struct dwo_unit
*lhs
= item_lhs
;
6453 const struct dwo_unit
*rhs
= item_rhs
;
6455 /* The signature is assumed to be unique within the DWO file.
6456 So while object file CU dwo_id's always have the value zero,
6457 that's OK, assuming each object file DWO file has only one CU,
6458 and that's the rule for now. */
6459 return lhs
->signature
== rhs
->signature
;
6462 /* Allocate a hash table for DWO CUs,TUs.
6463 There is one of these tables for each of CUs,TUs for each DWO file. */
6466 allocate_dwo_unit_table (struct objfile
*objfile
)
6468 /* Start out with a pretty small number.
6469 Generally DWO files contain only one CU and maybe some TUs. */
6470 return htab_create_alloc_ex (3,
6474 &objfile
->objfile_obstack
,
6475 hashtab_obstack_allocate
,
6476 dummy_obstack_deallocate
);
6479 /* This function is mapped across the sections and remembers the offset and
6480 size of each of the DWO debugging sections we are interested in. */
6483 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6485 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6486 const struct dwo_section_names
*names
= &dwo_section_names
;
6488 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6490 dwo_file
->sections
.abbrev
.asection
= sectp
;
6491 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6493 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6495 dwo_file
->sections
.info
.asection
= sectp
;
6496 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6498 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6500 dwo_file
->sections
.line
.asection
= sectp
;
6501 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6503 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6505 dwo_file
->sections
.loc
.asection
= sectp
;
6506 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6508 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6510 dwo_file
->sections
.str
.asection
= sectp
;
6511 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6513 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6515 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6516 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6518 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6520 struct dwarf2_section_info type_section
;
6522 memset (&type_section
, 0, sizeof (type_section
));
6523 type_section
.asection
= sectp
;
6524 type_section
.size
= bfd_get_section_size (sectp
);
6525 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6530 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6532 struct create_dwo_info_table_data
6534 struct dwo_file
*dwo_file
;
6538 /* die_reader_func for create_debug_info_hash_table. */
6541 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6543 struct die_info
*comp_unit_die
,
6547 struct dwarf2_cu
*cu
= reader
->cu
;
6548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6549 sect_offset offset
= cu
->per_cu
->offset
;
6550 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6551 struct create_dwo_info_table_data
*data
= datap
;
6552 struct dwo_file
*dwo_file
= data
->dwo_file
;
6553 htab_t cu_htab
= data
->cu_htab
;
6555 struct attribute
*attr
;
6556 struct dwo_unit
*dwo_unit
;
6558 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6561 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6562 " its dwo_id [in module %s]"),
6563 offset
.sect_off
, dwo_file
->dwo_name
);
6567 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6568 dwo_unit
->dwo_file
= dwo_file
;
6569 dwo_unit
->signature
= DW_UNSND (attr
);
6570 dwo_unit
->info_or_types_section
= section
;
6571 dwo_unit
->offset
= offset
;
6572 dwo_unit
->length
= cu
->per_cu
->length
;
6574 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
6575 gdb_assert (slot
!= NULL
);
6578 const struct dwo_unit
*dup_dwo_unit
= *slot
;
6580 complaint (&symfile_complaints
,
6581 _("debug entry at offset 0x%x is duplicate to the entry at"
6582 " offset 0x%x, dwo_id 0x%s [in module %s]"),
6583 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
6584 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
6585 dwo_file
->dwo_name
);
6590 if (dwarf2_die_debug
)
6591 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
6593 phex (dwo_unit
->signature
,
6594 sizeof (dwo_unit
->signature
)));
6597 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
6600 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
6602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6603 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
6606 gdb_byte
*info_ptr
, *end_ptr
;
6607 struct create_dwo_info_table_data create_dwo_info_table_data
;
6609 dwarf2_read_section (objfile
, section
);
6610 info_ptr
= section
->buffer
;
6612 if (info_ptr
== NULL
)
6615 /* We can't set abfd until now because the section may be empty or
6616 not present, in which case section->asection will be NULL. */
6617 abfd
= section
->asection
->owner
;
6619 if (dwarf2_die_debug
)
6620 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
6621 bfd_get_filename (abfd
));
6623 cu_htab
= allocate_dwo_unit_table (objfile
);
6625 create_dwo_info_table_data
.dwo_file
= dwo_file
;
6626 create_dwo_info_table_data
.cu_htab
= cu_htab
;
6628 end_ptr
= info_ptr
+ section
->size
;
6629 while (info_ptr
< end_ptr
)
6631 struct dwarf2_per_cu_data per_cu
;
6633 memset (&per_cu
, 0, sizeof (per_cu
));
6634 per_cu
.objfile
= objfile
;
6635 per_cu
.is_debug_types
= 0;
6636 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
6637 per_cu
.info_or_types_section
= section
;
6639 init_cutu_and_read_dies_no_follow (&per_cu
,
6640 &dwo_file
->sections
.abbrev
,
6642 create_debug_info_hash_table_reader
,
6643 &create_dwo_info_table_data
);
6645 info_ptr
+= per_cu
.length
;
6651 /* Subroutine of open_dwo_file to simplify it.
6652 Open the file specified by FILE_NAME and hand it off to BFD for
6653 preliminary analysis. Return a newly initialized bfd *, which
6654 includes a canonicalized copy of FILE_NAME.
6655 In case of trouble, return NULL.
6656 NOTE: This function is derived from symfile_bfd_open. */
6659 try_open_dwo_file (const char *file_name
)
6663 char *absolute_name
;
6666 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
6667 O_RDONLY
| O_BINARY
, &absolute_name
);
6671 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
6675 xfree (absolute_name
);
6678 bfd_set_cacheable (sym_bfd
, 1);
6680 if (!bfd_check_format (sym_bfd
, bfd_object
))
6682 bfd_close (sym_bfd
); /* This also closes desc. */
6683 xfree (absolute_name
);
6687 /* bfd_usrdata exists for applications and libbfd must not touch it. */
6688 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
6693 /* Try to open DWO file DWO_NAME.
6694 COMP_DIR is the DW_AT_comp_dir attribute.
6695 The result is the bfd handle of the file.
6696 If there is a problem finding or opening the file, return NULL.
6697 Upon success, the canonicalized path of the file is stored in the bfd,
6698 same as symfile_bfd_open. */
6701 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
6704 char *path_to_try
, *debug_dir
;
6706 if (IS_ABSOLUTE_PATH (dwo_name
))
6707 return try_open_dwo_file (dwo_name
);
6709 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
6711 if (comp_dir
!= NULL
)
6713 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
6715 /* NOTE: If comp_dir is a relative path, this will also try the
6716 search path, which seems useful. */
6717 abfd
= try_open_dwo_file (path_to_try
);
6718 xfree (path_to_try
);
6723 /* That didn't work, try debug-file-directory, which, despite its name,
6724 is a list of paths. */
6726 if (*debug_file_directory
== '\0')
6729 return try_open_dwo_file (dwo_name
);
6732 /* Initialize the use of the DWO file specified by DWO_NAME. */
6734 static struct dwo_file
*
6735 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
6737 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6738 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6741 struct cleanup
*cleanups
;
6743 if (dwarf2_die_debug
)
6744 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
6746 abfd
= open_dwo_file (dwo_name
, comp_dir
);
6749 dwo_file
->dwo_name
= dwo_name
;
6750 dwo_file
->dwo_bfd
= abfd
;
6752 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
6754 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
6756 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
6758 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
6759 dwo_file
->sections
.types
);
6761 discard_cleanups (cleanups
);
6766 /* Lookup DWO file DWO_NAME. */
6768 static struct dwo_file
*
6769 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
6771 struct dwo_file
*dwo_file
;
6772 struct dwo_file find_entry
;
6775 if (dwarf2_per_objfile
->dwo_files
== NULL
)
6776 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
6778 /* Have we already seen this DWO file? */
6779 find_entry
.dwo_name
= dwo_name
;
6780 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
6782 /* If not, read it in and build a table of the DWOs it contains. */
6784 *slot
= init_dwo_file (dwo_name
, comp_dir
);
6786 /* NOTE: This will be NULL if unable to open the file. */
6792 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
6793 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
6794 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
6795 nomenclature as TUs).
6796 The result is the DWO CU or NULL if we didn't find it
6797 (dwo_id mismatch or couldn't find the DWO file). */
6799 static struct dwo_unit
*
6800 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6801 char *dwo_name
, const char *comp_dir
,
6804 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6805 struct dwo_file
*dwo_file
;
6807 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
6808 if (dwo_file
== NULL
)
6811 /* Look up the DWO using its signature(dwo_id). */
6813 if (dwo_file
->cus
!= NULL
)
6815 struct dwo_unit find_dwo_cu
, *dwo_cu
;
6817 find_dwo_cu
.signature
= signature
;
6818 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
6824 /* We didn't find it. This must mean a dwo_id mismatch. */
6826 complaint (&symfile_complaints
,
6827 _("Could not find DWO CU referenced by CU at offset 0x%x"
6829 this_cu
->offset
.sect_off
, objfile
->name
);
6833 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
6834 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
6835 The result is the DWO CU or NULL if we didn't find it
6836 (dwo_id mismatch or couldn't find the DWO file). */
6838 static struct dwo_unit
*
6839 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
6840 char *dwo_name
, const char *comp_dir
)
6842 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6843 struct dwo_file
*dwo_file
;
6844 struct dwo_unit find_dwo_tu
, *dwo_tu
;
6846 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
6847 if (dwo_file
== NULL
)
6850 /* Look up the DWO using its signature(dwo_id). */
6852 if (dwo_file
->tus
!= NULL
)
6854 struct dwo_unit find_dwo_tu
, *dwo_tu
;
6856 find_dwo_tu
.signature
= this_tu
->signature
;
6857 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
6863 /* We didn't find it. This must mean a dwo_id mismatch. */
6865 complaint (&symfile_complaints
,
6866 _("Could not find DWO TU referenced by TU at offset 0x%x"
6868 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
6872 /* Free all resources associated with DWO_FILE.
6873 Close the DWO file and munmap the sections.
6874 All memory should be on the objfile obstack. */
6877 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
6880 struct dwarf2_section_info
*section
;
6882 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
6883 bfd_close (dwo_file
->dwo_bfd
);
6885 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
6886 munmap_section_buffer (&dwo_file
->sections
.info
);
6887 munmap_section_buffer (&dwo_file
->sections
.line
);
6888 munmap_section_buffer (&dwo_file
->sections
.loc
);
6889 munmap_section_buffer (&dwo_file
->sections
.str
);
6890 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
6893 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6896 munmap_section_buffer (section
);
6898 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
6901 /* Wrapper for free_dwo_file for use in cleanups. */
6904 free_dwo_file_cleanup (void *arg
)
6906 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
6907 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6909 free_dwo_file (dwo_file
, objfile
);
6912 /* Traversal function for free_dwo_files. */
6915 free_dwo_file_from_slot (void **slot
, void *info
)
6917 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6918 struct objfile
*objfile
= (struct objfile
*) info
;
6920 free_dwo_file (dwo_file
, objfile
);
6925 /* Free all resources associated with DWO_FILES. */
6928 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
6930 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
6933 /* Read in various DIEs. */
6935 /* qsort helper for inherit_abstract_dies. */
6938 unsigned_int_compar (const void *ap
, const void *bp
)
6940 unsigned int a
= *(unsigned int *) ap
;
6941 unsigned int b
= *(unsigned int *) bp
;
6943 return (a
> b
) - (b
> a
);
6946 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
6947 Inherit only the children of the DW_AT_abstract_origin DIE not being
6948 already referenced by DW_AT_abstract_origin from the children of the
6952 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
6954 struct die_info
*child_die
;
6955 unsigned die_children_count
;
6956 /* CU offsets which were referenced by children of the current DIE. */
6957 sect_offset
*offsets
;
6958 sect_offset
*offsets_end
, *offsetp
;
6959 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
6960 struct die_info
*origin_die
;
6961 /* Iterator of the ORIGIN_DIE children. */
6962 struct die_info
*origin_child_die
;
6963 struct cleanup
*cleanups
;
6964 struct attribute
*attr
;
6965 struct dwarf2_cu
*origin_cu
;
6966 struct pending
**origin_previous_list_in_scope
;
6968 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6972 /* Note that following die references may follow to a die in a
6976 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
6978 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
6980 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
6981 origin_cu
->list_in_scope
= cu
->list_in_scope
;
6983 if (die
->tag
!= origin_die
->tag
6984 && !(die
->tag
== DW_TAG_inlined_subroutine
6985 && origin_die
->tag
== DW_TAG_subprogram
))
6986 complaint (&symfile_complaints
,
6987 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
6988 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
6990 child_die
= die
->child
;
6991 die_children_count
= 0;
6992 while (child_die
&& child_die
->tag
)
6994 child_die
= sibling_die (child_die
);
6995 die_children_count
++;
6997 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
6998 cleanups
= make_cleanup (xfree
, offsets
);
7000 offsets_end
= offsets
;
7001 child_die
= die
->child
;
7002 while (child_die
&& child_die
->tag
)
7004 /* For each CHILD_DIE, find the corresponding child of
7005 ORIGIN_DIE. If there is more than one layer of
7006 DW_AT_abstract_origin, follow them all; there shouldn't be,
7007 but GCC versions at least through 4.4 generate this (GCC PR
7009 struct die_info
*child_origin_die
= child_die
;
7010 struct dwarf2_cu
*child_origin_cu
= cu
;
7014 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7018 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7022 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7023 counterpart may exist. */
7024 if (child_origin_die
!= child_die
)
7026 if (child_die
->tag
!= child_origin_die
->tag
7027 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7028 && child_origin_die
->tag
== DW_TAG_subprogram
))
7029 complaint (&symfile_complaints
,
7030 _("Child DIE 0x%x and its abstract origin 0x%x have "
7031 "different tags"), child_die
->offset
.sect_off
,
7032 child_origin_die
->offset
.sect_off
);
7033 if (child_origin_die
->parent
!= origin_die
)
7034 complaint (&symfile_complaints
,
7035 _("Child DIE 0x%x and its abstract origin 0x%x have "
7036 "different parents"), child_die
->offset
.sect_off
,
7037 child_origin_die
->offset
.sect_off
);
7039 *offsets_end
++ = child_origin_die
->offset
;
7041 child_die
= sibling_die (child_die
);
7043 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7044 unsigned_int_compar
);
7045 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7046 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7047 complaint (&symfile_complaints
,
7048 _("Multiple children of DIE 0x%x refer "
7049 "to DIE 0x%x as their abstract origin"),
7050 die
->offset
.sect_off
, offsetp
->sect_off
);
7053 origin_child_die
= origin_die
->child
;
7054 while (origin_child_die
&& origin_child_die
->tag
)
7056 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7057 while (offsetp
< offsets_end
7058 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7060 if (offsetp
>= offsets_end
7061 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7063 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7064 process_die (origin_child_die
, origin_cu
);
7066 origin_child_die
= sibling_die (origin_child_die
);
7068 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7070 do_cleanups (cleanups
);
7074 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7076 struct objfile
*objfile
= cu
->objfile
;
7077 struct context_stack
*new;
7080 struct die_info
*child_die
;
7081 struct attribute
*attr
, *call_line
, *call_file
;
7084 struct block
*block
;
7085 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7086 VEC (symbolp
) *template_args
= NULL
;
7087 struct template_symbol
*templ_func
= NULL
;
7091 /* If we do not have call site information, we can't show the
7092 caller of this inlined function. That's too confusing, so
7093 only use the scope for local variables. */
7094 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7095 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7096 if (call_line
== NULL
|| call_file
== NULL
)
7098 read_lexical_block_scope (die
, cu
);
7103 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7105 name
= dwarf2_name (die
, cu
);
7107 /* Ignore functions with missing or empty names. These are actually
7108 illegal according to the DWARF standard. */
7111 complaint (&symfile_complaints
,
7112 _("missing name for subprogram DIE at %d"),
7113 die
->offset
.sect_off
);
7117 /* Ignore functions with missing or invalid low and high pc attributes. */
7118 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7120 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7121 if (!attr
|| !DW_UNSND (attr
))
7122 complaint (&symfile_complaints
,
7123 _("cannot get low and high bounds "
7124 "for subprogram DIE at %d"),
7125 die
->offset
.sect_off
);
7132 /* If we have any template arguments, then we must allocate a
7133 different sort of symbol. */
7134 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7136 if (child_die
->tag
== DW_TAG_template_type_param
7137 || child_die
->tag
== DW_TAG_template_value_param
)
7139 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7140 struct template_symbol
);
7141 templ_func
->base
.is_cplus_template_function
= 1;
7146 new = push_context (0, lowpc
);
7147 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7148 (struct symbol
*) templ_func
);
7150 /* If there is a location expression for DW_AT_frame_base, record
7152 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7154 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7155 expression is being recorded directly in the function's symbol
7156 and not in a separate frame-base object. I guess this hack is
7157 to avoid adding some sort of frame-base adjunct/annex to the
7158 function's symbol :-(. The problem with doing this is that it
7159 results in a function symbol with a location expression that
7160 has nothing to do with the location of the function, ouch! The
7161 relationship should be: a function's symbol has-a frame base; a
7162 frame-base has-a location expression. */
7163 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7165 cu
->list_in_scope
= &local_symbols
;
7167 if (die
->child
!= NULL
)
7169 child_die
= die
->child
;
7170 while (child_die
&& child_die
->tag
)
7172 if (child_die
->tag
== DW_TAG_template_type_param
7173 || child_die
->tag
== DW_TAG_template_value_param
)
7175 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7178 VEC_safe_push (symbolp
, template_args
, arg
);
7181 process_die (child_die
, cu
);
7182 child_die
= sibling_die (child_die
);
7186 inherit_abstract_dies (die
, cu
);
7188 /* If we have a DW_AT_specification, we might need to import using
7189 directives from the context of the specification DIE. See the
7190 comment in determine_prefix. */
7191 if (cu
->language
== language_cplus
7192 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7194 struct dwarf2_cu
*spec_cu
= cu
;
7195 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7199 child_die
= spec_die
->child
;
7200 while (child_die
&& child_die
->tag
)
7202 if (child_die
->tag
== DW_TAG_imported_module
)
7203 process_die (child_die
, spec_cu
);
7204 child_die
= sibling_die (child_die
);
7207 /* In some cases, GCC generates specification DIEs that
7208 themselves contain DW_AT_specification attributes. */
7209 spec_die
= die_specification (spec_die
, &spec_cu
);
7213 new = pop_context ();
7214 /* Make a block for the local symbols within. */
7215 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7216 lowpc
, highpc
, objfile
);
7218 /* For C++, set the block's scope. */
7219 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7220 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7221 determine_prefix (die
, cu
),
7222 processing_has_namespace_info
);
7224 /* If we have address ranges, record them. */
7225 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7227 /* Attach template arguments to function. */
7228 if (! VEC_empty (symbolp
, template_args
))
7230 gdb_assert (templ_func
!= NULL
);
7232 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7233 templ_func
->template_arguments
7234 = obstack_alloc (&objfile
->objfile_obstack
,
7235 (templ_func
->n_template_arguments
7236 * sizeof (struct symbol
*)));
7237 memcpy (templ_func
->template_arguments
,
7238 VEC_address (symbolp
, template_args
),
7239 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7240 VEC_free (symbolp
, template_args
);
7243 /* In C++, we can have functions nested inside functions (e.g., when
7244 a function declares a class that has methods). This means that
7245 when we finish processing a function scope, we may need to go
7246 back to building a containing block's symbol lists. */
7247 local_symbols
= new->locals
;
7248 param_symbols
= new->params
;
7249 using_directives
= new->using_directives
;
7251 /* If we've finished processing a top-level function, subsequent
7252 symbols go in the file symbol list. */
7253 if (outermost_context_p ())
7254 cu
->list_in_scope
= &file_symbols
;
7257 /* Process all the DIES contained within a lexical block scope. Start
7258 a new scope, process the dies, and then close the scope. */
7261 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7263 struct objfile
*objfile
= cu
->objfile
;
7264 struct context_stack
*new;
7265 CORE_ADDR lowpc
, highpc
;
7266 struct die_info
*child_die
;
7269 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7271 /* Ignore blocks with missing or invalid low and high pc attributes. */
7272 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7273 as multiple lexical blocks? Handling children in a sane way would
7274 be nasty. Might be easier to properly extend generic blocks to
7276 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7281 push_context (0, lowpc
);
7282 if (die
->child
!= NULL
)
7284 child_die
= die
->child
;
7285 while (child_die
&& child_die
->tag
)
7287 process_die (child_die
, cu
);
7288 child_die
= sibling_die (child_die
);
7291 new = pop_context ();
7293 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7296 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7299 /* Note that recording ranges after traversing children, as we
7300 do here, means that recording a parent's ranges entails
7301 walking across all its children's ranges as they appear in
7302 the address map, which is quadratic behavior.
7304 It would be nicer to record the parent's ranges before
7305 traversing its children, simply overriding whatever you find
7306 there. But since we don't even decide whether to create a
7307 block until after we've traversed its children, that's hard
7309 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7311 local_symbols
= new->locals
;
7312 using_directives
= new->using_directives
;
7315 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7318 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7320 struct objfile
*objfile
= cu
->objfile
;
7321 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7322 CORE_ADDR pc
, baseaddr
;
7323 struct attribute
*attr
;
7324 struct call_site
*call_site
, call_site_local
;
7327 struct die_info
*child_die
;
7329 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7331 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7334 complaint (&symfile_complaints
,
7335 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7336 "DIE 0x%x [in module %s]"),
7337 die
->offset
.sect_off
, objfile
->name
);
7340 pc
= DW_ADDR (attr
) + baseaddr
;
7342 if (cu
->call_site_htab
== NULL
)
7343 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7344 NULL
, &objfile
->objfile_obstack
,
7345 hashtab_obstack_allocate
, NULL
);
7346 call_site_local
.pc
= pc
;
7347 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7350 complaint (&symfile_complaints
,
7351 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7352 "DIE 0x%x [in module %s]"),
7353 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7357 /* Count parameters at the caller. */
7360 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7361 child_die
= sibling_die (child_die
))
7363 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7365 complaint (&symfile_complaints
,
7366 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7367 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7368 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7375 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7376 (sizeof (*call_site
)
7377 + (sizeof (*call_site
->parameter
)
7380 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7383 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7385 struct die_info
*func_die
;
7387 /* Skip also over DW_TAG_inlined_subroutine. */
7388 for (func_die
= die
->parent
;
7389 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7390 && func_die
->tag
!= DW_TAG_subroutine_type
;
7391 func_die
= func_die
->parent
);
7393 /* DW_AT_GNU_all_call_sites is a superset
7394 of DW_AT_GNU_all_tail_call_sites. */
7396 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7397 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7399 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7400 not complete. But keep CALL_SITE for look ups via call_site_htab,
7401 both the initial caller containing the real return address PC and
7402 the final callee containing the current PC of a chain of tail
7403 calls do not need to have the tail call list complete. But any
7404 function candidate for a virtual tail call frame searched via
7405 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7406 determined unambiguously. */
7410 struct type
*func_type
= NULL
;
7413 func_type
= get_die_type (func_die
, cu
);
7414 if (func_type
!= NULL
)
7416 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7418 /* Enlist this call site to the function. */
7419 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7420 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7423 complaint (&symfile_complaints
,
7424 _("Cannot find function owning DW_TAG_GNU_call_site "
7425 "DIE 0x%x [in module %s]"),
7426 die
->offset
.sect_off
, objfile
->name
);
7430 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7432 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7433 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7434 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7435 /* Keep NULL DWARF_BLOCK. */;
7436 else if (attr_form_is_block (attr
))
7438 struct dwarf2_locexpr_baton
*dlbaton
;
7440 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7441 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7442 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7443 dlbaton
->per_cu
= cu
->per_cu
;
7445 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7447 else if (is_ref_attr (attr
))
7449 struct dwarf2_cu
*target_cu
= cu
;
7450 struct die_info
*target_die
;
7452 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7453 gdb_assert (target_cu
->objfile
== objfile
);
7454 if (die_is_declaration (target_die
, target_cu
))
7456 const char *target_physname
;
7458 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7459 if (target_physname
== NULL
)
7460 complaint (&symfile_complaints
,
7461 _("DW_AT_GNU_call_site_target target DIE has invalid "
7462 "physname, for referencing DIE 0x%x [in module %s]"),
7463 die
->offset
.sect_off
, objfile
->name
);
7465 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7471 /* DW_AT_entry_pc should be preferred. */
7472 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7473 complaint (&symfile_complaints
,
7474 _("DW_AT_GNU_call_site_target target DIE has invalid "
7475 "low pc, for referencing DIE 0x%x [in module %s]"),
7476 die
->offset
.sect_off
, objfile
->name
);
7478 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7482 complaint (&symfile_complaints
,
7483 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7484 "block nor reference, for DIE 0x%x [in module %s]"),
7485 die
->offset
.sect_off
, objfile
->name
);
7487 call_site
->per_cu
= cu
->per_cu
;
7489 for (child_die
= die
->child
;
7490 child_die
&& child_die
->tag
;
7491 child_die
= sibling_die (child_die
))
7493 struct dwarf2_locexpr_baton
*dlbaton
;
7494 struct call_site_parameter
*parameter
;
7496 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7498 /* Already printed the complaint above. */
7502 gdb_assert (call_site
->parameter_count
< nparams
);
7503 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7505 /* DW_AT_location specifies the register number. Value of the data
7506 assumed for the register is contained in DW_AT_GNU_call_site_value. */
7508 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7509 if (!attr
|| !attr_form_is_block (attr
))
7511 complaint (&symfile_complaints
,
7512 _("No DW_FORM_block* DW_AT_location for "
7513 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7514 child_die
->offset
.sect_off
, objfile
->name
);
7517 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
7518 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
7519 if (parameter
->dwarf_reg
== -1
7520 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
7521 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
7522 ¶meter
->fb_offset
))
7524 complaint (&symfile_complaints
,
7525 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7526 "for DW_FORM_block* DW_AT_location for "
7527 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7528 child_die
->offset
.sect_off
, objfile
->name
);
7532 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7533 if (!attr_form_is_block (attr
))
7535 complaint (&symfile_complaints
,
7536 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7537 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7538 child_die
->offset
.sect_off
, objfile
->name
);
7541 parameter
->value
= DW_BLOCK (attr
)->data
;
7542 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7544 /* Parameters are not pre-cleared by memset above. */
7545 parameter
->data_value
= NULL
;
7546 parameter
->data_value_size
= 0;
7547 call_site
->parameter_count
++;
7549 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7552 if (!attr_form_is_block (attr
))
7553 complaint (&symfile_complaints
,
7554 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7555 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7556 child_die
->offset
.sect_off
, objfile
->name
);
7559 parameter
->data_value
= DW_BLOCK (attr
)->data
;
7560 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
7566 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
7567 Return 1 if the attributes are present and valid, otherwise, return 0.
7568 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
7571 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
7572 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
7573 struct partial_symtab
*ranges_pst
)
7575 struct objfile
*objfile
= cu
->objfile
;
7576 struct comp_unit_head
*cu_header
= &cu
->header
;
7577 bfd
*obfd
= objfile
->obfd
;
7578 unsigned int addr_size
= cu_header
->addr_size
;
7579 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7580 /* Base address selection entry. */
7591 found_base
= cu
->base_known
;
7592 base
= cu
->base_address
;
7594 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
7595 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7597 complaint (&symfile_complaints
,
7598 _("Offset %d out of bounds for DW_AT_ranges attribute"),
7602 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7604 /* Read in the largest possible address. */
7605 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
7606 if ((marker
& mask
) == mask
)
7608 /* If we found the largest possible address, then
7609 read the base address. */
7610 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7611 buffer
+= 2 * addr_size
;
7612 offset
+= 2 * addr_size
;
7618 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7622 CORE_ADDR range_beginning
, range_end
;
7624 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
7625 buffer
+= addr_size
;
7626 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
7627 buffer
+= addr_size
;
7628 offset
+= 2 * addr_size
;
7630 /* An end of list marker is a pair of zero addresses. */
7631 if (range_beginning
== 0 && range_end
== 0)
7632 /* Found the end of list entry. */
7635 /* Each base address selection entry is a pair of 2 values.
7636 The first is the largest possible address, the second is
7637 the base address. Check for a base address here. */
7638 if ((range_beginning
& mask
) == mask
)
7640 /* If we found the largest possible address, then
7641 read the base address. */
7642 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7649 /* We have no valid base address for the ranges
7651 complaint (&symfile_complaints
,
7652 _("Invalid .debug_ranges data (no base address)"));
7656 if (range_beginning
> range_end
)
7658 /* Inverted range entries are invalid. */
7659 complaint (&symfile_complaints
,
7660 _("Invalid .debug_ranges data (inverted range)"));
7664 /* Empty range entries have no effect. */
7665 if (range_beginning
== range_end
)
7668 range_beginning
+= base
;
7671 if (ranges_pst
!= NULL
)
7672 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7673 range_beginning
+ baseaddr
,
7674 range_end
- 1 + baseaddr
,
7677 /* FIXME: This is recording everything as a low-high
7678 segment of consecutive addresses. We should have a
7679 data structure for discontiguous block ranges
7683 low
= range_beginning
;
7689 if (range_beginning
< low
)
7690 low
= range_beginning
;
7691 if (range_end
> high
)
7697 /* If the first entry is an end-of-list marker, the range
7698 describes an empty scope, i.e. no instructions. */
7704 *high_return
= high
;
7708 /* Get low and high pc attributes from a die. Return 1 if the attributes
7709 are present and valid, otherwise, return 0. Return -1 if the range is
7710 discontinuous, i.e. derived from DW_AT_ranges information. */
7713 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
7714 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
7715 struct partial_symtab
*pst
)
7717 struct attribute
*attr
;
7718 struct attribute
*attr_high
;
7723 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7726 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7729 low
= DW_ADDR (attr
);
7730 if (attr_high
->form
== DW_FORM_addr
7731 || attr_high
->form
== DW_FORM_GNU_addr_index
)
7732 high
= DW_ADDR (attr_high
);
7734 high
= low
+ DW_UNSND (attr_high
);
7737 /* Found high w/o low attribute. */
7740 /* Found consecutive range of addresses. */
7745 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7748 /* Value of the DW_AT_ranges attribute is the offset in the
7749 .debug_ranges section. */
7750 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
7752 /* Found discontinuous range of addresses. */
7757 /* read_partial_die has also the strict LOW < HIGH requirement. */
7761 /* When using the GNU linker, .gnu.linkonce. sections are used to
7762 eliminate duplicate copies of functions and vtables and such.
7763 The linker will arbitrarily choose one and discard the others.
7764 The AT_*_pc values for such functions refer to local labels in
7765 these sections. If the section from that file was discarded, the
7766 labels are not in the output, so the relocs get a value of 0.
7767 If this is a discarded function, mark the pc bounds as invalid,
7768 so that GDB will ignore it. */
7769 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
7778 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
7779 its low and high PC addresses. Do nothing if these addresses could not
7780 be determined. Otherwise, set LOWPC to the low address if it is smaller,
7781 and HIGHPC to the high address if greater than HIGHPC. */
7784 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
7785 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7786 struct dwarf2_cu
*cu
)
7788 CORE_ADDR low
, high
;
7789 struct die_info
*child
= die
->child
;
7791 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
7793 *lowpc
= min (*lowpc
, low
);
7794 *highpc
= max (*highpc
, high
);
7797 /* If the language does not allow nested subprograms (either inside
7798 subprograms or lexical blocks), we're done. */
7799 if (cu
->language
!= language_ada
)
7802 /* Check all the children of the given DIE. If it contains nested
7803 subprograms, then check their pc bounds. Likewise, we need to
7804 check lexical blocks as well, as they may also contain subprogram
7806 while (child
&& child
->tag
)
7808 if (child
->tag
== DW_TAG_subprogram
7809 || child
->tag
== DW_TAG_lexical_block
)
7810 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
7811 child
= sibling_die (child
);
7815 /* Get the low and high pc's represented by the scope DIE, and store
7816 them in *LOWPC and *HIGHPC. If the correct values can't be
7817 determined, set *LOWPC to -1 and *HIGHPC to 0. */
7820 get_scope_pc_bounds (struct die_info
*die
,
7821 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7822 struct dwarf2_cu
*cu
)
7824 CORE_ADDR best_low
= (CORE_ADDR
) -1;
7825 CORE_ADDR best_high
= (CORE_ADDR
) 0;
7826 CORE_ADDR current_low
, current_high
;
7828 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
7830 best_low
= current_low
;
7831 best_high
= current_high
;
7835 struct die_info
*child
= die
->child
;
7837 while (child
&& child
->tag
)
7839 switch (child
->tag
) {
7840 case DW_TAG_subprogram
:
7841 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
7843 case DW_TAG_namespace
:
7845 /* FIXME: carlton/2004-01-16: Should we do this for
7846 DW_TAG_class_type/DW_TAG_structure_type, too? I think
7847 that current GCC's always emit the DIEs corresponding
7848 to definitions of methods of classes as children of a
7849 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
7850 the DIEs giving the declarations, which could be
7851 anywhere). But I don't see any reason why the
7852 standards says that they have to be there. */
7853 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
7855 if (current_low
!= ((CORE_ADDR
) -1))
7857 best_low
= min (best_low
, current_low
);
7858 best_high
= max (best_high
, current_high
);
7866 child
= sibling_die (child
);
7871 *highpc
= best_high
;
7874 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
7878 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
7879 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
7881 struct objfile
*objfile
= cu
->objfile
;
7882 struct attribute
*attr
;
7883 struct attribute
*attr_high
;
7885 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7888 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7891 CORE_ADDR low
= DW_ADDR (attr
);
7893 if (attr_high
->form
== DW_FORM_addr
7894 || attr_high
->form
== DW_FORM_GNU_addr_index
)
7895 high
= DW_ADDR (attr_high
);
7897 high
= low
+ DW_UNSND (attr_high
);
7899 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
7903 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7906 bfd
*obfd
= objfile
->obfd
;
7908 /* The value of the DW_AT_ranges attribute is the offset of the
7909 address range list in the .debug_ranges section. */
7910 unsigned long offset
= DW_UNSND (attr
);
7911 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7913 /* For some target architectures, but not others, the
7914 read_address function sign-extends the addresses it returns.
7915 To recognize base address selection entries, we need a
7917 unsigned int addr_size
= cu
->header
.addr_size
;
7918 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7920 /* The base address, to which the next pair is relative. Note
7921 that this 'base' is a DWARF concept: most entries in a range
7922 list are relative, to reduce the number of relocs against the
7923 debugging information. This is separate from this function's
7924 'baseaddr' argument, which GDB uses to relocate debugging
7925 information from a shared library based on the address at
7926 which the library was loaded. */
7927 CORE_ADDR base
= cu
->base_address
;
7928 int base_known
= cu
->base_known
;
7930 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
7931 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7933 complaint (&symfile_complaints
,
7934 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
7941 unsigned int bytes_read
;
7942 CORE_ADDR start
, end
;
7944 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7945 buffer
+= bytes_read
;
7946 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7947 buffer
+= bytes_read
;
7949 /* Did we find the end of the range list? */
7950 if (start
== 0 && end
== 0)
7953 /* Did we find a base address selection entry? */
7954 else if ((start
& base_select_mask
) == base_select_mask
)
7960 /* We found an ordinary address range. */
7965 complaint (&symfile_complaints
,
7966 _("Invalid .debug_ranges data "
7967 "(no base address)"));
7973 /* Inverted range entries are invalid. */
7974 complaint (&symfile_complaints
,
7975 _("Invalid .debug_ranges data "
7976 "(inverted range)"));
7980 /* Empty range entries have no effect. */
7984 record_block_range (block
,
7985 baseaddr
+ base
+ start
,
7986 baseaddr
+ base
+ end
- 1);
7992 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
7993 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
7994 during 4.6.0 experimental. */
7997 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8000 int major
, minor
, release
;
8003 if (cu
->producer
== NULL
)
8005 /* For unknown compilers expect their behavior is DWARF version
8008 GCC started to support .debug_types sections by -gdwarf-4 since
8009 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8010 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8011 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8012 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8017 if (cu
->checked_producer
)
8018 return cu
->producer_is_gxx_lt_4_6
;
8020 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8022 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
8024 /* For non-GCC compilers expect their behavior is DWARF version
8029 cs
= &cu
->producer
[strlen ("GNU ")];
8030 while (*cs
&& !isdigit (*cs
))
8032 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8034 /* Not recognized as GCC. */
8037 result
= major
< 4 || (major
== 4 && minor
< 6);
8040 cu
->checked_producer
= 1;
8041 cu
->producer_is_gxx_lt_4_6
= result
;
8046 /* Return the default accessibility type if it is not overriden by
8047 DW_AT_accessibility. */
8049 static enum dwarf_access_attribute
8050 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8052 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8054 /* The default DWARF 2 accessibility for members is public, the default
8055 accessibility for inheritance is private. */
8057 if (die
->tag
!= DW_TAG_inheritance
)
8058 return DW_ACCESS_public
;
8060 return DW_ACCESS_private
;
8064 /* DWARF 3+ defines the default accessibility a different way. The same
8065 rules apply now for DW_TAG_inheritance as for the members and it only
8066 depends on the container kind. */
8068 if (die
->parent
->tag
== DW_TAG_class_type
)
8069 return DW_ACCESS_private
;
8071 return DW_ACCESS_public
;
8075 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8076 offset. If the attribute was not found return 0, otherwise return
8077 1. If it was found but could not properly be handled, set *OFFSET
8081 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8084 struct attribute
*attr
;
8086 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8091 /* Note that we do not check for a section offset first here.
8092 This is because DW_AT_data_member_location is new in DWARF 4,
8093 so if we see it, we can assume that a constant form is really
8094 a constant and not a section offset. */
8095 if (attr_form_is_constant (attr
))
8096 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8097 else if (attr_form_is_section_offset (attr
))
8098 dwarf2_complex_location_expr_complaint ();
8099 else if (attr_form_is_block (attr
))
8100 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8102 dwarf2_complex_location_expr_complaint ();
8110 /* Add an aggregate field to the field list. */
8113 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8114 struct dwarf2_cu
*cu
)
8116 struct objfile
*objfile
= cu
->objfile
;
8117 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8118 struct nextfield
*new_field
;
8119 struct attribute
*attr
;
8121 char *fieldname
= "";
8123 /* Allocate a new field list entry and link it in. */
8124 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8125 make_cleanup (xfree
, new_field
);
8126 memset (new_field
, 0, sizeof (struct nextfield
));
8128 if (die
->tag
== DW_TAG_inheritance
)
8130 new_field
->next
= fip
->baseclasses
;
8131 fip
->baseclasses
= new_field
;
8135 new_field
->next
= fip
->fields
;
8136 fip
->fields
= new_field
;
8140 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8142 new_field
->accessibility
= DW_UNSND (attr
);
8144 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8145 if (new_field
->accessibility
!= DW_ACCESS_public
)
8146 fip
->non_public_fields
= 1;
8148 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8150 new_field
->virtuality
= DW_UNSND (attr
);
8152 new_field
->virtuality
= DW_VIRTUALITY_none
;
8154 fp
= &new_field
->field
;
8156 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8160 /* Data member other than a C++ static data member. */
8162 /* Get type of field. */
8163 fp
->type
= die_type (die
, cu
);
8165 SET_FIELD_BITPOS (*fp
, 0);
8167 /* Get bit size of field (zero if none). */
8168 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8171 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8175 FIELD_BITSIZE (*fp
) = 0;
8178 /* Get bit offset of field. */
8179 if (handle_data_member_location (die
, cu
, &offset
))
8180 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8181 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8184 if (gdbarch_bits_big_endian (gdbarch
))
8186 /* For big endian bits, the DW_AT_bit_offset gives the
8187 additional bit offset from the MSB of the containing
8188 anonymous object to the MSB of the field. We don't
8189 have to do anything special since we don't need to
8190 know the size of the anonymous object. */
8191 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8195 /* For little endian bits, compute the bit offset to the
8196 MSB of the anonymous object, subtract off the number of
8197 bits from the MSB of the field to the MSB of the
8198 object, and then subtract off the number of bits of
8199 the field itself. The result is the bit offset of
8200 the LSB of the field. */
8202 int bit_offset
= DW_UNSND (attr
);
8204 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8207 /* The size of the anonymous object containing
8208 the bit field is explicit, so use the
8209 indicated size (in bytes). */
8210 anonymous_size
= DW_UNSND (attr
);
8214 /* The size of the anonymous object containing
8215 the bit field must be inferred from the type
8216 attribute of the data member containing the
8218 anonymous_size
= TYPE_LENGTH (fp
->type
);
8220 SET_FIELD_BITPOS (*fp
,
8222 + anonymous_size
* bits_per_byte
8223 - bit_offset
- FIELD_BITSIZE (*fp
)));
8227 /* Get name of field. */
8228 fieldname
= dwarf2_name (die
, cu
);
8229 if (fieldname
== NULL
)
8232 /* The name is already allocated along with this objfile, so we don't
8233 need to duplicate it for the type. */
8234 fp
->name
= fieldname
;
8236 /* Change accessibility for artificial fields (e.g. virtual table
8237 pointer or virtual base class pointer) to private. */
8238 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8240 FIELD_ARTIFICIAL (*fp
) = 1;
8241 new_field
->accessibility
= DW_ACCESS_private
;
8242 fip
->non_public_fields
= 1;
8245 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8247 /* C++ static member. */
8249 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8250 is a declaration, but all versions of G++ as of this writing
8251 (so through at least 3.2.1) incorrectly generate
8252 DW_TAG_variable tags. */
8254 const char *physname
;
8256 /* Get name of field. */
8257 fieldname
= dwarf2_name (die
, cu
);
8258 if (fieldname
== NULL
)
8261 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8263 /* Only create a symbol if this is an external value.
8264 new_symbol checks this and puts the value in the global symbol
8265 table, which we want. If it is not external, new_symbol
8266 will try to put the value in cu->list_in_scope which is wrong. */
8267 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8269 /* A static const member, not much different than an enum as far as
8270 we're concerned, except that we can support more types. */
8271 new_symbol (die
, NULL
, cu
);
8274 /* Get physical name. */
8275 physname
= dwarf2_physname (fieldname
, die
, cu
);
8277 /* The name is already allocated along with this objfile, so we don't
8278 need to duplicate it for the type. */
8279 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8280 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8281 FIELD_NAME (*fp
) = fieldname
;
8283 else if (die
->tag
== DW_TAG_inheritance
)
8287 /* C++ base class field. */
8288 if (handle_data_member_location (die
, cu
, &offset
))
8289 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8290 FIELD_BITSIZE (*fp
) = 0;
8291 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8292 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8293 fip
->nbaseclasses
++;
8297 /* Add a typedef defined in the scope of the FIP's class. */
8300 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8301 struct dwarf2_cu
*cu
)
8303 struct objfile
*objfile
= cu
->objfile
;
8304 struct typedef_field_list
*new_field
;
8305 struct attribute
*attr
;
8306 struct typedef_field
*fp
;
8307 char *fieldname
= "";
8309 /* Allocate a new field list entry and link it in. */
8310 new_field
= xzalloc (sizeof (*new_field
));
8311 make_cleanup (xfree
, new_field
);
8313 gdb_assert (die
->tag
== DW_TAG_typedef
);
8315 fp
= &new_field
->field
;
8317 /* Get name of field. */
8318 fp
->name
= dwarf2_name (die
, cu
);
8319 if (fp
->name
== NULL
)
8322 fp
->type
= read_type_die (die
, cu
);
8324 new_field
->next
= fip
->typedef_field_list
;
8325 fip
->typedef_field_list
= new_field
;
8326 fip
->typedef_field_list_count
++;
8329 /* Create the vector of fields, and attach it to the type. */
8332 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8333 struct dwarf2_cu
*cu
)
8335 int nfields
= fip
->nfields
;
8337 /* Record the field count, allocate space for the array of fields,
8338 and create blank accessibility bitfields if necessary. */
8339 TYPE_NFIELDS (type
) = nfields
;
8340 TYPE_FIELDS (type
) = (struct field
*)
8341 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8342 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8344 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8346 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8348 TYPE_FIELD_PRIVATE_BITS (type
) =
8349 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8350 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8352 TYPE_FIELD_PROTECTED_BITS (type
) =
8353 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8354 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8356 TYPE_FIELD_IGNORE_BITS (type
) =
8357 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8358 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8361 /* If the type has baseclasses, allocate and clear a bit vector for
8362 TYPE_FIELD_VIRTUAL_BITS. */
8363 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8365 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8366 unsigned char *pointer
;
8368 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8369 pointer
= TYPE_ALLOC (type
, num_bytes
);
8370 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8371 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8372 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8375 /* Copy the saved-up fields into the field vector. Start from the head of
8376 the list, adding to the tail of the field array, so that they end up in
8377 the same order in the array in which they were added to the list. */
8378 while (nfields
-- > 0)
8380 struct nextfield
*fieldp
;
8384 fieldp
= fip
->fields
;
8385 fip
->fields
= fieldp
->next
;
8389 fieldp
= fip
->baseclasses
;
8390 fip
->baseclasses
= fieldp
->next
;
8393 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8394 switch (fieldp
->accessibility
)
8396 case DW_ACCESS_private
:
8397 if (cu
->language
!= language_ada
)
8398 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8401 case DW_ACCESS_protected
:
8402 if (cu
->language
!= language_ada
)
8403 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8406 case DW_ACCESS_public
:
8410 /* Unknown accessibility. Complain and treat it as public. */
8412 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8413 fieldp
->accessibility
);
8417 if (nfields
< fip
->nbaseclasses
)
8419 switch (fieldp
->virtuality
)
8421 case DW_VIRTUALITY_virtual
:
8422 case DW_VIRTUALITY_pure_virtual
:
8423 if (cu
->language
== language_ada
)
8424 error (_("unexpected virtuality in component of Ada type"));
8425 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8432 /* Add a member function to the proper fieldlist. */
8435 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8436 struct type
*type
, struct dwarf2_cu
*cu
)
8438 struct objfile
*objfile
= cu
->objfile
;
8439 struct attribute
*attr
;
8440 struct fnfieldlist
*flp
;
8442 struct fn_field
*fnp
;
8444 struct nextfnfield
*new_fnfield
;
8445 struct type
*this_type
;
8446 enum dwarf_access_attribute accessibility
;
8448 if (cu
->language
== language_ada
)
8449 error (_("unexpected member function in Ada type"));
8451 /* Get name of member function. */
8452 fieldname
= dwarf2_name (die
, cu
);
8453 if (fieldname
== NULL
)
8456 /* Look up member function name in fieldlist. */
8457 for (i
= 0; i
< fip
->nfnfields
; i
++)
8459 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8463 /* Create new list element if necessary. */
8464 if (i
< fip
->nfnfields
)
8465 flp
= &fip
->fnfieldlists
[i
];
8468 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8470 fip
->fnfieldlists
= (struct fnfieldlist
*)
8471 xrealloc (fip
->fnfieldlists
,
8472 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8473 * sizeof (struct fnfieldlist
));
8474 if (fip
->nfnfields
== 0)
8475 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8477 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8478 flp
->name
= fieldname
;
8481 i
= fip
->nfnfields
++;
8484 /* Create a new member function field and chain it to the field list
8486 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8487 make_cleanup (xfree
, new_fnfield
);
8488 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8489 new_fnfield
->next
= flp
->head
;
8490 flp
->head
= new_fnfield
;
8493 /* Fill in the member function field info. */
8494 fnp
= &new_fnfield
->fnfield
;
8496 /* Delay processing of the physname until later. */
8497 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8499 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8504 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8505 fnp
->physname
= physname
? physname
: "";
8508 fnp
->type
= alloc_type (objfile
);
8509 this_type
= read_type_die (die
, cu
);
8510 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8512 int nparams
= TYPE_NFIELDS (this_type
);
8514 /* TYPE is the domain of this method, and THIS_TYPE is the type
8515 of the method itself (TYPE_CODE_METHOD). */
8516 smash_to_method_type (fnp
->type
, type
,
8517 TYPE_TARGET_TYPE (this_type
),
8518 TYPE_FIELDS (this_type
),
8519 TYPE_NFIELDS (this_type
),
8520 TYPE_VARARGS (this_type
));
8522 /* Handle static member functions.
8523 Dwarf2 has no clean way to discern C++ static and non-static
8524 member functions. G++ helps GDB by marking the first
8525 parameter for non-static member functions (which is the this
8526 pointer) as artificial. We obtain this information from
8527 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8528 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8529 fnp
->voffset
= VOFFSET_STATIC
;
8532 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8533 dwarf2_full_name (fieldname
, die
, cu
));
8535 /* Get fcontext from DW_AT_containing_type if present. */
8536 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8537 fnp
->fcontext
= die_containing_type (die
, cu
);
8539 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8540 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8542 /* Get accessibility. */
8543 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8545 accessibility
= DW_UNSND (attr
);
8547 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8548 switch (accessibility
)
8550 case DW_ACCESS_private
:
8551 fnp
->is_private
= 1;
8553 case DW_ACCESS_protected
:
8554 fnp
->is_protected
= 1;
8558 /* Check for artificial methods. */
8559 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
8560 if (attr
&& DW_UNSND (attr
) != 0)
8561 fnp
->is_artificial
= 1;
8563 /* Get index in virtual function table if it is a virtual member
8564 function. For older versions of GCC, this is an offset in the
8565 appropriate virtual table, as specified by DW_AT_containing_type.
8566 For everyone else, it is an expression to be evaluated relative
8567 to the object address. */
8569 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
8572 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
8574 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
8576 /* Old-style GCC. */
8577 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
8579 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8580 || (DW_BLOCK (attr
)->size
> 1
8581 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
8582 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
8584 struct dwarf_block blk
;
8587 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8589 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
8590 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
8591 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8592 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
8593 dwarf2_complex_location_expr_complaint ();
8595 fnp
->voffset
/= cu
->header
.addr_size
;
8599 dwarf2_complex_location_expr_complaint ();
8602 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
8604 else if (attr_form_is_section_offset (attr
))
8606 dwarf2_complex_location_expr_complaint ();
8610 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
8616 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8617 if (attr
&& DW_UNSND (attr
))
8619 /* GCC does this, as of 2008-08-25; PR debug/37237. */
8620 complaint (&symfile_complaints
,
8621 _("Member function \"%s\" (offset %d) is virtual "
8622 "but the vtable offset is not specified"),
8623 fieldname
, die
->offset
.sect_off
);
8624 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8625 TYPE_CPLUS_DYNAMIC (type
) = 1;
8630 /* Create the vector of member function fields, and attach it to the type. */
8633 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
8634 struct dwarf2_cu
*cu
)
8636 struct fnfieldlist
*flp
;
8639 if (cu
->language
== language_ada
)
8640 error (_("unexpected member functions in Ada type"));
8642 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8643 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
8644 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
8646 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
8648 struct nextfnfield
*nfp
= flp
->head
;
8649 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
8652 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
8653 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
8654 fn_flp
->fn_fields
= (struct fn_field
*)
8655 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
8656 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
8657 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
8660 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
8663 /* Returns non-zero if NAME is the name of a vtable member in CU's
8664 language, zero otherwise. */
8666 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
8668 static const char vptr
[] = "_vptr";
8669 static const char vtable
[] = "vtable";
8671 /* Look for the C++ and Java forms of the vtable. */
8672 if ((cu
->language
== language_java
8673 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
8674 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
8675 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
8681 /* GCC outputs unnamed structures that are really pointers to member
8682 functions, with the ABI-specified layout. If TYPE describes
8683 such a structure, smash it into a member function type.
8685 GCC shouldn't do this; it should just output pointer to member DIEs.
8686 This is GCC PR debug/28767. */
8689 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
8691 struct type
*pfn_type
, *domain_type
, *new_type
;
8693 /* Check for a structure with no name and two children. */
8694 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
8697 /* Check for __pfn and __delta members. */
8698 if (TYPE_FIELD_NAME (type
, 0) == NULL
8699 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
8700 || TYPE_FIELD_NAME (type
, 1) == NULL
8701 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
8704 /* Find the type of the method. */
8705 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
8706 if (pfn_type
== NULL
8707 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
8708 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
8711 /* Look for the "this" argument. */
8712 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
8713 if (TYPE_NFIELDS (pfn_type
) == 0
8714 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
8715 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
8718 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
8719 new_type
= alloc_type (objfile
);
8720 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
8721 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
8722 TYPE_VARARGS (pfn_type
));
8723 smash_to_methodptr_type (type
, new_type
);
8726 /* Called when we find the DIE that starts a structure or union scope
8727 (definition) to create a type for the structure or union. Fill in
8728 the type's name and general properties; the members will not be
8729 processed until process_structure_type.
8731 NOTE: we need to call these functions regardless of whether or not the
8732 DIE has a DW_AT_name attribute, since it might be an anonymous
8733 structure or union. This gets the type entered into our set of
8736 However, if the structure is incomplete (an opaque struct/union)
8737 then suppress creating a symbol table entry for it since gdb only
8738 wants to find the one with the complete definition. Note that if
8739 it is complete, we just call new_symbol, which does it's own
8740 checking about whether the struct/union is anonymous or not (and
8741 suppresses creating a symbol table entry itself). */
8743 static struct type
*
8744 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8746 struct objfile
*objfile
= cu
->objfile
;
8748 struct attribute
*attr
;
8751 /* If the definition of this type lives in .debug_types, read that type.
8752 Don't follow DW_AT_specification though, that will take us back up
8753 the chain and we want to go down. */
8754 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8757 struct dwarf2_cu
*type_cu
= cu
;
8758 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8760 /* We could just recurse on read_structure_type, but we need to call
8761 get_die_type to ensure only one type for this DIE is created.
8762 This is important, for example, because for c++ classes we need
8763 TYPE_NAME set which is only done by new_symbol. Blech. */
8764 type
= read_type_die (type_die
, type_cu
);
8766 /* TYPE_CU may not be the same as CU.
8767 Ensure TYPE is recorded in CU's type_hash table. */
8768 return set_die_type (die
, type
, cu
);
8771 type
= alloc_type (objfile
);
8772 INIT_CPLUS_SPECIFIC (type
);
8774 name
= dwarf2_name (die
, cu
);
8777 if (cu
->language
== language_cplus
8778 || cu
->language
== language_java
)
8780 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
8782 /* dwarf2_full_name might have already finished building the DIE's
8783 type. If so, there is no need to continue. */
8784 if (get_die_type (die
, cu
) != NULL
)
8785 return get_die_type (die
, cu
);
8787 TYPE_TAG_NAME (type
) = full_name
;
8788 if (die
->tag
== DW_TAG_structure_type
8789 || die
->tag
== DW_TAG_class_type
)
8790 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
8794 /* The name is already allocated along with this objfile, so
8795 we don't need to duplicate it for the type. */
8796 TYPE_TAG_NAME (type
) = (char *) name
;
8797 if (die
->tag
== DW_TAG_class_type
)
8798 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
8802 if (die
->tag
== DW_TAG_structure_type
)
8804 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
8806 else if (die
->tag
== DW_TAG_union_type
)
8808 TYPE_CODE (type
) = TYPE_CODE_UNION
;
8812 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
8815 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
8816 TYPE_DECLARED_CLASS (type
) = 1;
8818 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8821 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8825 TYPE_LENGTH (type
) = 0;
8828 TYPE_STUB_SUPPORTED (type
) = 1;
8829 if (die_is_declaration (die
, cu
))
8830 TYPE_STUB (type
) = 1;
8831 else if (attr
== NULL
&& die
->child
== NULL
8832 && producer_is_realview (cu
->producer
))
8833 /* RealView does not output the required DW_AT_declaration
8834 on incomplete types. */
8835 TYPE_STUB (type
) = 1;
8837 /* We need to add the type field to the die immediately so we don't
8838 infinitely recurse when dealing with pointers to the structure
8839 type within the structure itself. */
8840 set_die_type (die
, type
, cu
);
8842 /* set_die_type should be already done. */
8843 set_descriptive_type (type
, die
, cu
);
8848 /* Finish creating a structure or union type, including filling in
8849 its members and creating a symbol for it. */
8852 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8854 struct objfile
*objfile
= cu
->objfile
;
8855 struct die_info
*child_die
= die
->child
;
8858 type
= get_die_type (die
, cu
);
8860 type
= read_structure_type (die
, cu
);
8862 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
8864 struct field_info fi
;
8865 struct die_info
*child_die
;
8866 VEC (symbolp
) *template_args
= NULL
;
8867 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8869 memset (&fi
, 0, sizeof (struct field_info
));
8871 child_die
= die
->child
;
8873 while (child_die
&& child_die
->tag
)
8875 if (child_die
->tag
== DW_TAG_member
8876 || child_die
->tag
== DW_TAG_variable
)
8878 /* NOTE: carlton/2002-11-05: A C++ static data member
8879 should be a DW_TAG_member that is a declaration, but
8880 all versions of G++ as of this writing (so through at
8881 least 3.2.1) incorrectly generate DW_TAG_variable
8882 tags for them instead. */
8883 dwarf2_add_field (&fi
, child_die
, cu
);
8885 else if (child_die
->tag
== DW_TAG_subprogram
)
8887 /* C++ member function. */
8888 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
8890 else if (child_die
->tag
== DW_TAG_inheritance
)
8892 /* C++ base class field. */
8893 dwarf2_add_field (&fi
, child_die
, cu
);
8895 else if (child_die
->tag
== DW_TAG_typedef
)
8896 dwarf2_add_typedef (&fi
, child_die
, cu
);
8897 else if (child_die
->tag
== DW_TAG_template_type_param
8898 || child_die
->tag
== DW_TAG_template_value_param
)
8900 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8903 VEC_safe_push (symbolp
, template_args
, arg
);
8906 child_die
= sibling_die (child_die
);
8909 /* Attach template arguments to type. */
8910 if (! VEC_empty (symbolp
, template_args
))
8912 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8913 TYPE_N_TEMPLATE_ARGUMENTS (type
)
8914 = VEC_length (symbolp
, template_args
);
8915 TYPE_TEMPLATE_ARGUMENTS (type
)
8916 = obstack_alloc (&objfile
->objfile_obstack
,
8917 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8918 * sizeof (struct symbol
*)));
8919 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
8920 VEC_address (symbolp
, template_args
),
8921 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8922 * sizeof (struct symbol
*)));
8923 VEC_free (symbolp
, template_args
);
8926 /* Attach fields and member functions to the type. */
8928 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
8931 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
8933 /* Get the type which refers to the base class (possibly this
8934 class itself) which contains the vtable pointer for the current
8935 class from the DW_AT_containing_type attribute. This use of
8936 DW_AT_containing_type is a GNU extension. */
8938 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8940 struct type
*t
= die_containing_type (die
, cu
);
8942 TYPE_VPTR_BASETYPE (type
) = t
;
8947 /* Our own class provides vtbl ptr. */
8948 for (i
= TYPE_NFIELDS (t
) - 1;
8949 i
>= TYPE_N_BASECLASSES (t
);
8952 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
8954 if (is_vtable_name (fieldname
, cu
))
8956 TYPE_VPTR_FIELDNO (type
) = i
;
8961 /* Complain if virtual function table field not found. */
8962 if (i
< TYPE_N_BASECLASSES (t
))
8963 complaint (&symfile_complaints
,
8964 _("virtual function table pointer "
8965 "not found when defining class '%s'"),
8966 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
8971 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
8974 else if (cu
->producer
8975 && strncmp (cu
->producer
,
8976 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
8978 /* The IBM XLC compiler does not provide direct indication
8979 of the containing type, but the vtable pointer is
8980 always named __vfp. */
8984 for (i
= TYPE_NFIELDS (type
) - 1;
8985 i
>= TYPE_N_BASECLASSES (type
);
8988 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
8990 TYPE_VPTR_FIELDNO (type
) = i
;
8991 TYPE_VPTR_BASETYPE (type
) = type
;
8998 /* Copy fi.typedef_field_list linked list elements content into the
8999 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9000 if (fi
.typedef_field_list
)
9002 int i
= fi
.typedef_field_list_count
;
9004 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9005 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9006 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9007 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9009 /* Reverse the list order to keep the debug info elements order. */
9012 struct typedef_field
*dest
, *src
;
9014 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9015 src
= &fi
.typedef_field_list
->field
;
9016 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9021 do_cleanups (back_to
);
9023 if (HAVE_CPLUS_STRUCT (type
))
9024 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9027 quirk_gcc_member_function_pointer (type
, objfile
);
9029 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9030 snapshots) has been known to create a die giving a declaration
9031 for a class that has, as a child, a die giving a definition for a
9032 nested class. So we have to process our children even if the
9033 current die is a declaration. Normally, of course, a declaration
9034 won't have any children at all. */
9036 while (child_die
!= NULL
&& child_die
->tag
)
9038 if (child_die
->tag
== DW_TAG_member
9039 || child_die
->tag
== DW_TAG_variable
9040 || child_die
->tag
== DW_TAG_inheritance
9041 || child_die
->tag
== DW_TAG_template_value_param
9042 || child_die
->tag
== DW_TAG_template_type_param
)
9047 process_die (child_die
, cu
);
9049 child_die
= sibling_die (child_die
);
9052 /* Do not consider external references. According to the DWARF standard,
9053 these DIEs are identified by the fact that they have no byte_size
9054 attribute, and a declaration attribute. */
9055 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9056 || !die_is_declaration (die
, cu
))
9057 new_symbol (die
, type
, cu
);
9060 /* Given a DW_AT_enumeration_type die, set its type. We do not
9061 complete the type's fields yet, or create any symbols. */
9063 static struct type
*
9064 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9066 struct objfile
*objfile
= cu
->objfile
;
9068 struct attribute
*attr
;
9071 /* If the definition of this type lives in .debug_types, read that type.
9072 Don't follow DW_AT_specification though, that will take us back up
9073 the chain and we want to go down. */
9074 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9077 struct dwarf2_cu
*type_cu
= cu
;
9078 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9080 type
= read_type_die (type_die
, type_cu
);
9082 /* TYPE_CU may not be the same as CU.
9083 Ensure TYPE is recorded in CU's type_hash table. */
9084 return set_die_type (die
, type
, cu
);
9087 type
= alloc_type (objfile
);
9089 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9090 name
= dwarf2_full_name (NULL
, die
, cu
);
9092 TYPE_TAG_NAME (type
) = (char *) name
;
9094 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9097 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9101 TYPE_LENGTH (type
) = 0;
9104 /* The enumeration DIE can be incomplete. In Ada, any type can be
9105 declared as private in the package spec, and then defined only
9106 inside the package body. Such types are known as Taft Amendment
9107 Types. When another package uses such a type, an incomplete DIE
9108 may be generated by the compiler. */
9109 if (die_is_declaration (die
, cu
))
9110 TYPE_STUB (type
) = 1;
9112 return set_die_type (die
, type
, cu
);
9115 /* Given a pointer to a die which begins an enumeration, process all
9116 the dies that define the members of the enumeration, and create the
9117 symbol for the enumeration type.
9119 NOTE: We reverse the order of the element list. */
9122 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9124 struct type
*this_type
;
9126 this_type
= get_die_type (die
, cu
);
9127 if (this_type
== NULL
)
9128 this_type
= read_enumeration_type (die
, cu
);
9130 if (die
->child
!= NULL
)
9132 struct die_info
*child_die
;
9134 struct field
*fields
= NULL
;
9136 int unsigned_enum
= 1;
9141 child_die
= die
->child
;
9142 while (child_die
&& child_die
->tag
)
9144 if (child_die
->tag
!= DW_TAG_enumerator
)
9146 process_die (child_die
, cu
);
9150 name
= dwarf2_name (child_die
, cu
);
9153 sym
= new_symbol (child_die
, this_type
, cu
);
9154 if (SYMBOL_VALUE (sym
) < 0)
9159 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9162 mask
|= SYMBOL_VALUE (sym
);
9164 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9166 fields
= (struct field
*)
9168 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9169 * sizeof (struct field
));
9172 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9173 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9174 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9175 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9181 child_die
= sibling_die (child_die
);
9186 TYPE_NFIELDS (this_type
) = num_fields
;
9187 TYPE_FIELDS (this_type
) = (struct field
*)
9188 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9189 memcpy (TYPE_FIELDS (this_type
), fields
,
9190 sizeof (struct field
) * num_fields
);
9194 TYPE_UNSIGNED (this_type
) = 1;
9196 TYPE_FLAG_ENUM (this_type
) = 1;
9199 /* If we are reading an enum from a .debug_types unit, and the enum
9200 is a declaration, and the enum is not the signatured type in the
9201 unit, then we do not want to add a symbol for it. Adding a
9202 symbol would in some cases obscure the true definition of the
9203 enum, giving users an incomplete type when the definition is
9204 actually available. Note that we do not want to do this for all
9205 enums which are just declarations, because C++0x allows forward
9206 enum declarations. */
9207 if (cu
->per_cu
->is_debug_types
9208 && die_is_declaration (die
, cu
))
9210 struct signatured_type
*sig_type
;
9213 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9214 cu
->per_cu
->info_or_types_section
,
9215 cu
->per_cu
->offset
);
9216 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9217 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9221 new_symbol (die
, this_type
, cu
);
9224 /* Extract all information from a DW_TAG_array_type DIE and put it in
9225 the DIE's type field. For now, this only handles one dimensional
9228 static struct type
*
9229 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9231 struct objfile
*objfile
= cu
->objfile
;
9232 struct die_info
*child_die
;
9234 struct type
*element_type
, *range_type
, *index_type
;
9235 struct type
**range_types
= NULL
;
9236 struct attribute
*attr
;
9238 struct cleanup
*back_to
;
9241 element_type
= die_type (die
, cu
);
9243 /* The die_type call above may have already set the type for this DIE. */
9244 type
= get_die_type (die
, cu
);
9248 /* Irix 6.2 native cc creates array types without children for
9249 arrays with unspecified length. */
9250 if (die
->child
== NULL
)
9252 index_type
= objfile_type (objfile
)->builtin_int
;
9253 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9254 type
= create_array_type (NULL
, element_type
, range_type
);
9255 return set_die_type (die
, type
, cu
);
9258 back_to
= make_cleanup (null_cleanup
, NULL
);
9259 child_die
= die
->child
;
9260 while (child_die
&& child_die
->tag
)
9262 if (child_die
->tag
== DW_TAG_subrange_type
)
9264 struct type
*child_type
= read_type_die (child_die
, cu
);
9266 if (child_type
!= NULL
)
9268 /* The range type was succesfully read. Save it for the
9269 array type creation. */
9270 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9272 range_types
= (struct type
**)
9273 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9274 * sizeof (struct type
*));
9276 make_cleanup (free_current_contents
, &range_types
);
9278 range_types
[ndim
++] = child_type
;
9281 child_die
= sibling_die (child_die
);
9284 /* Dwarf2 dimensions are output from left to right, create the
9285 necessary array types in backwards order. */
9287 type
= element_type
;
9289 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9294 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9299 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9302 /* Understand Dwarf2 support for vector types (like they occur on
9303 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9304 array type. This is not part of the Dwarf2/3 standard yet, but a
9305 custom vendor extension. The main difference between a regular
9306 array and the vector variant is that vectors are passed by value
9308 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9310 make_vector_type (type
);
9312 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9313 implementation may choose to implement triple vectors using this
9315 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9318 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9319 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9321 complaint (&symfile_complaints
,
9322 _("DW_AT_byte_size for array type smaller "
9323 "than the total size of elements"));
9326 name
= dwarf2_name (die
, cu
);
9328 TYPE_NAME (type
) = name
;
9330 /* Install the type in the die. */
9331 set_die_type (die
, type
, cu
);
9333 /* set_die_type should be already done. */
9334 set_descriptive_type (type
, die
, cu
);
9336 do_cleanups (back_to
);
9341 static enum dwarf_array_dim_ordering
9342 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9344 struct attribute
*attr
;
9346 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9348 if (attr
) return DW_SND (attr
);
9350 /* GNU F77 is a special case, as at 08/2004 array type info is the
9351 opposite order to the dwarf2 specification, but data is still
9352 laid out as per normal fortran.
9354 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9355 version checking. */
9357 if (cu
->language
== language_fortran
9358 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9360 return DW_ORD_row_major
;
9363 switch (cu
->language_defn
->la_array_ordering
)
9365 case array_column_major
:
9366 return DW_ORD_col_major
;
9367 case array_row_major
:
9369 return DW_ORD_row_major
;
9373 /* Extract all information from a DW_TAG_set_type DIE and put it in
9374 the DIE's type field. */
9376 static struct type
*
9377 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9379 struct type
*domain_type
, *set_type
;
9380 struct attribute
*attr
;
9382 domain_type
= die_type (die
, cu
);
9384 /* The die_type call above may have already set the type for this DIE. */
9385 set_type
= get_die_type (die
, cu
);
9389 set_type
= create_set_type (NULL
, domain_type
);
9391 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9393 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9395 return set_die_type (die
, set_type
, cu
);
9398 /* First cut: install each common block member as a global variable. */
9401 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9403 struct die_info
*child_die
;
9404 struct attribute
*attr
;
9406 CORE_ADDR base
= (CORE_ADDR
) 0;
9408 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9411 /* Support the .debug_loc offsets. */
9412 if (attr_form_is_block (attr
))
9414 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9416 else if (attr_form_is_section_offset (attr
))
9418 dwarf2_complex_location_expr_complaint ();
9422 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9423 "common block member");
9426 if (die
->child
!= NULL
)
9428 child_die
= die
->child
;
9429 while (child_die
&& child_die
->tag
)
9433 sym
= new_symbol (child_die
, NULL
, cu
);
9435 && handle_data_member_location (child_die
, cu
, &offset
))
9437 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9438 add_symbol_to_list (sym
, &global_symbols
);
9440 child_die
= sibling_die (child_die
);
9445 /* Create a type for a C++ namespace. */
9447 static struct type
*
9448 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9450 struct objfile
*objfile
= cu
->objfile
;
9451 const char *previous_prefix
, *name
;
9455 /* For extensions, reuse the type of the original namespace. */
9456 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9458 struct die_info
*ext_die
;
9459 struct dwarf2_cu
*ext_cu
= cu
;
9461 ext_die
= dwarf2_extension (die
, &ext_cu
);
9462 type
= read_type_die (ext_die
, ext_cu
);
9464 /* EXT_CU may not be the same as CU.
9465 Ensure TYPE is recorded in CU's type_hash table. */
9466 return set_die_type (die
, type
, cu
);
9469 name
= namespace_name (die
, &is_anonymous
, cu
);
9471 /* Now build the name of the current namespace. */
9473 previous_prefix
= determine_prefix (die
, cu
);
9474 if (previous_prefix
[0] != '\0')
9475 name
= typename_concat (&objfile
->objfile_obstack
,
9476 previous_prefix
, name
, 0, cu
);
9478 /* Create the type. */
9479 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9481 TYPE_NAME (type
) = (char *) name
;
9482 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9484 return set_die_type (die
, type
, cu
);
9487 /* Read a C++ namespace. */
9490 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9492 struct objfile
*objfile
= cu
->objfile
;
9495 /* Add a symbol associated to this if we haven't seen the namespace
9496 before. Also, add a using directive if it's an anonymous
9499 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9503 type
= read_type_die (die
, cu
);
9504 new_symbol (die
, type
, cu
);
9506 namespace_name (die
, &is_anonymous
, cu
);
9509 const char *previous_prefix
= determine_prefix (die
, cu
);
9511 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9512 NULL
, NULL
, &objfile
->objfile_obstack
);
9516 if (die
->child
!= NULL
)
9518 struct die_info
*child_die
= die
->child
;
9520 while (child_die
&& child_die
->tag
)
9522 process_die (child_die
, cu
);
9523 child_die
= sibling_die (child_die
);
9528 /* Read a Fortran module as type. This DIE can be only a declaration used for
9529 imported module. Still we need that type as local Fortran "use ... only"
9530 declaration imports depend on the created type in determine_prefix. */
9532 static struct type
*
9533 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9535 struct objfile
*objfile
= cu
->objfile
;
9539 module_name
= dwarf2_name (die
, cu
);
9541 complaint (&symfile_complaints
,
9542 _("DW_TAG_module has no name, offset 0x%x"),
9543 die
->offset
.sect_off
);
9544 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
9546 /* determine_prefix uses TYPE_TAG_NAME. */
9547 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9549 return set_die_type (die
, type
, cu
);
9552 /* Read a Fortran module. */
9555 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
9557 struct die_info
*child_die
= die
->child
;
9559 while (child_die
&& child_die
->tag
)
9561 process_die (child_die
, cu
);
9562 child_die
= sibling_die (child_die
);
9566 /* Return the name of the namespace represented by DIE. Set
9567 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
9571 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
9573 struct die_info
*current_die
;
9574 const char *name
= NULL
;
9576 /* Loop through the extensions until we find a name. */
9578 for (current_die
= die
;
9579 current_die
!= NULL
;
9580 current_die
= dwarf2_extension (die
, &cu
))
9582 name
= dwarf2_name (current_die
, cu
);
9587 /* Is it an anonymous namespace? */
9589 *is_anonymous
= (name
== NULL
);
9591 name
= CP_ANONYMOUS_NAMESPACE_STR
;
9596 /* Extract all information from a DW_TAG_pointer_type DIE and add to
9597 the user defined type vector. */
9599 static struct type
*
9600 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9602 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9603 struct comp_unit_head
*cu_header
= &cu
->header
;
9605 struct attribute
*attr_byte_size
;
9606 struct attribute
*attr_address_class
;
9607 int byte_size
, addr_class
;
9608 struct type
*target_type
;
9610 target_type
= die_type (die
, cu
);
9612 /* The die_type call above may have already set the type for this DIE. */
9613 type
= get_die_type (die
, cu
);
9617 type
= lookup_pointer_type (target_type
);
9619 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9621 byte_size
= DW_UNSND (attr_byte_size
);
9623 byte_size
= cu_header
->addr_size
;
9625 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
9626 if (attr_address_class
)
9627 addr_class
= DW_UNSND (attr_address_class
);
9629 addr_class
= DW_ADDR_none
;
9631 /* If the pointer size or address class is different than the
9632 default, create a type variant marked as such and set the
9633 length accordingly. */
9634 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
9636 if (gdbarch_address_class_type_flags_p (gdbarch
))
9640 type_flags
= gdbarch_address_class_type_flags
9641 (gdbarch
, byte_size
, addr_class
);
9642 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
9644 type
= make_type_with_address_space (type
, type_flags
);
9646 else if (TYPE_LENGTH (type
) != byte_size
)
9648 complaint (&symfile_complaints
,
9649 _("invalid pointer size %d"), byte_size
);
9653 /* Should we also complain about unhandled address classes? */
9657 TYPE_LENGTH (type
) = byte_size
;
9658 return set_die_type (die
, type
, cu
);
9661 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
9662 the user defined type vector. */
9664 static struct type
*
9665 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9668 struct type
*to_type
;
9669 struct type
*domain
;
9671 to_type
= die_type (die
, cu
);
9672 domain
= die_containing_type (die
, cu
);
9674 /* The calls above may have already set the type for this DIE. */
9675 type
= get_die_type (die
, cu
);
9679 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
9680 type
= lookup_methodptr_type (to_type
);
9682 type
= lookup_memberptr_type (to_type
, domain
);
9684 return set_die_type (die
, type
, cu
);
9687 /* Extract all information from a DW_TAG_reference_type DIE and add to
9688 the user defined type vector. */
9690 static struct type
*
9691 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9693 struct comp_unit_head
*cu_header
= &cu
->header
;
9694 struct type
*type
, *target_type
;
9695 struct attribute
*attr
;
9697 target_type
= die_type (die
, cu
);
9699 /* The die_type call above may have already set the type for this DIE. */
9700 type
= get_die_type (die
, cu
);
9704 type
= lookup_reference_type (target_type
);
9705 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9708 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9712 TYPE_LENGTH (type
) = cu_header
->addr_size
;
9714 return set_die_type (die
, type
, cu
);
9717 static struct type
*
9718 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9720 struct type
*base_type
, *cv_type
;
9722 base_type
= die_type (die
, cu
);
9724 /* The die_type call above may have already set the type for this DIE. */
9725 cv_type
= get_die_type (die
, cu
);
9729 /* In case the const qualifier is applied to an array type, the element type
9730 is so qualified, not the array type (section 6.7.3 of C99). */
9731 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
9733 struct type
*el_type
, *inner_array
;
9735 base_type
= copy_type (base_type
);
9736 inner_array
= base_type
;
9738 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
9740 TYPE_TARGET_TYPE (inner_array
) =
9741 copy_type (TYPE_TARGET_TYPE (inner_array
));
9742 inner_array
= TYPE_TARGET_TYPE (inner_array
);
9745 el_type
= TYPE_TARGET_TYPE (inner_array
);
9746 TYPE_TARGET_TYPE (inner_array
) =
9747 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
9749 return set_die_type (die
, base_type
, cu
);
9752 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
9753 return set_die_type (die
, cv_type
, cu
);
9756 static struct type
*
9757 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9759 struct type
*base_type
, *cv_type
;
9761 base_type
= die_type (die
, cu
);
9763 /* The die_type call above may have already set the type for this DIE. */
9764 cv_type
= get_die_type (die
, cu
);
9768 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
9769 return set_die_type (die
, cv_type
, cu
);
9772 /* Extract all information from a DW_TAG_string_type DIE and add to
9773 the user defined type vector. It isn't really a user defined type,
9774 but it behaves like one, with other DIE's using an AT_user_def_type
9775 attribute to reference it. */
9777 static struct type
*
9778 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9780 struct objfile
*objfile
= cu
->objfile
;
9781 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9782 struct type
*type
, *range_type
, *index_type
, *char_type
;
9783 struct attribute
*attr
;
9784 unsigned int length
;
9786 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
9789 length
= DW_UNSND (attr
);
9793 /* Check for the DW_AT_byte_size attribute. */
9794 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9797 length
= DW_UNSND (attr
);
9805 index_type
= objfile_type (objfile
)->builtin_int
;
9806 range_type
= create_range_type (NULL
, index_type
, 1, length
);
9807 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
9808 type
= create_string_type (NULL
, char_type
, range_type
);
9810 return set_die_type (die
, type
, cu
);
9813 /* Handle DIES due to C code like:
9817 int (*funcp)(int a, long l);
9821 ('funcp' generates a DW_TAG_subroutine_type DIE). */
9823 static struct type
*
9824 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9826 struct objfile
*objfile
= cu
->objfile
;
9827 struct type
*type
; /* Type that this function returns. */
9828 struct type
*ftype
; /* Function that returns above type. */
9829 struct attribute
*attr
;
9831 type
= die_type (die
, cu
);
9833 /* The die_type call above may have already set the type for this DIE. */
9834 ftype
= get_die_type (die
, cu
);
9838 ftype
= lookup_function_type (type
);
9840 /* All functions in C++, Pascal and Java have prototypes. */
9841 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
9842 if ((attr
&& (DW_UNSND (attr
) != 0))
9843 || cu
->language
== language_cplus
9844 || cu
->language
== language_java
9845 || cu
->language
== language_pascal
)
9846 TYPE_PROTOTYPED (ftype
) = 1;
9847 else if (producer_is_realview (cu
->producer
))
9848 /* RealView does not emit DW_AT_prototyped. We can not
9849 distinguish prototyped and unprototyped functions; default to
9850 prototyped, since that is more common in modern code (and
9851 RealView warns about unprototyped functions). */
9852 TYPE_PROTOTYPED (ftype
) = 1;
9854 /* Store the calling convention in the type if it's available in
9855 the subroutine die. Otherwise set the calling convention to
9856 the default value DW_CC_normal. */
9857 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
9859 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
9860 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
9861 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
9863 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
9865 /* We need to add the subroutine type to the die immediately so
9866 we don't infinitely recurse when dealing with parameters
9867 declared as the same subroutine type. */
9868 set_die_type (die
, ftype
, cu
);
9870 if (die
->child
!= NULL
)
9872 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
9873 struct die_info
*child_die
;
9874 int nparams
, iparams
;
9876 /* Count the number of parameters.
9877 FIXME: GDB currently ignores vararg functions, but knows about
9878 vararg member functions. */
9880 child_die
= die
->child
;
9881 while (child_die
&& child_die
->tag
)
9883 if (child_die
->tag
== DW_TAG_formal_parameter
)
9885 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
9886 TYPE_VARARGS (ftype
) = 1;
9887 child_die
= sibling_die (child_die
);
9890 /* Allocate storage for parameters and fill them in. */
9891 TYPE_NFIELDS (ftype
) = nparams
;
9892 TYPE_FIELDS (ftype
) = (struct field
*)
9893 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
9895 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
9896 even if we error out during the parameters reading below. */
9897 for (iparams
= 0; iparams
< nparams
; iparams
++)
9898 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
9901 child_die
= die
->child
;
9902 while (child_die
&& child_die
->tag
)
9904 if (child_die
->tag
== DW_TAG_formal_parameter
)
9906 struct type
*arg_type
;
9908 /* DWARF version 2 has no clean way to discern C++
9909 static and non-static member functions. G++ helps
9910 GDB by marking the first parameter for non-static
9911 member functions (which is the this pointer) as
9912 artificial. We pass this information to
9913 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
9915 DWARF version 3 added DW_AT_object_pointer, which GCC
9916 4.5 does not yet generate. */
9917 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
9919 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
9922 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
9924 /* GCC/43521: In java, the formal parameter
9925 "this" is sometimes not marked with DW_AT_artificial. */
9926 if (cu
->language
== language_java
)
9928 const char *name
= dwarf2_name (child_die
, cu
);
9930 if (name
&& !strcmp (name
, "this"))
9931 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
9934 arg_type
= die_type (child_die
, cu
);
9936 /* RealView does not mark THIS as const, which the testsuite
9937 expects. GCC marks THIS as const in method definitions,
9938 but not in the class specifications (GCC PR 43053). */
9939 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
9940 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
9943 struct dwarf2_cu
*arg_cu
= cu
;
9944 const char *name
= dwarf2_name (child_die
, cu
);
9946 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
9949 /* If the compiler emits this, use it. */
9950 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
9953 else if (name
&& strcmp (name
, "this") == 0)
9954 /* Function definitions will have the argument names. */
9956 else if (name
== NULL
&& iparams
== 0)
9957 /* Declarations may not have the names, so like
9958 elsewhere in GDB, assume an artificial first
9959 argument is "this". */
9963 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
9967 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
9970 child_die
= sibling_die (child_die
);
9977 static struct type
*
9978 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
9980 struct objfile
*objfile
= cu
->objfile
;
9981 const char *name
= NULL
;
9982 struct type
*this_type
, *target_type
;
9984 name
= dwarf2_full_name (NULL
, die
, cu
);
9985 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
9986 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
9987 TYPE_NAME (this_type
) = (char *) name
;
9988 set_die_type (die
, this_type
, cu
);
9989 target_type
= die_type (die
, cu
);
9990 if (target_type
!= this_type
)
9991 TYPE_TARGET_TYPE (this_type
) = target_type
;
9994 /* Self-referential typedefs are, it seems, not allowed by the DWARF
9995 spec and cause infinite loops in GDB. */
9996 complaint (&symfile_complaints
,
9997 _("Self-referential DW_TAG_typedef "
9998 "- DIE at 0x%x [in module %s]"),
9999 die
->offset
.sect_off
, objfile
->name
);
10000 TYPE_TARGET_TYPE (this_type
) = NULL
;
10005 /* Find a representation of a given base type and install
10006 it in the TYPE field of the die. */
10008 static struct type
*
10009 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10011 struct objfile
*objfile
= cu
->objfile
;
10013 struct attribute
*attr
;
10014 int encoding
= 0, size
= 0;
10016 enum type_code code
= TYPE_CODE_INT
;
10017 int type_flags
= 0;
10018 struct type
*target_type
= NULL
;
10020 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10023 encoding
= DW_UNSND (attr
);
10025 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10028 size
= DW_UNSND (attr
);
10030 name
= dwarf2_name (die
, cu
);
10033 complaint (&symfile_complaints
,
10034 _("DW_AT_name missing from DW_TAG_base_type"));
10039 case DW_ATE_address
:
10040 /* Turn DW_ATE_address into a void * pointer. */
10041 code
= TYPE_CODE_PTR
;
10042 type_flags
|= TYPE_FLAG_UNSIGNED
;
10043 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10045 case DW_ATE_boolean
:
10046 code
= TYPE_CODE_BOOL
;
10047 type_flags
|= TYPE_FLAG_UNSIGNED
;
10049 case DW_ATE_complex_float
:
10050 code
= TYPE_CODE_COMPLEX
;
10051 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10053 case DW_ATE_decimal_float
:
10054 code
= TYPE_CODE_DECFLOAT
;
10057 code
= TYPE_CODE_FLT
;
10059 case DW_ATE_signed
:
10061 case DW_ATE_unsigned
:
10062 type_flags
|= TYPE_FLAG_UNSIGNED
;
10063 if (cu
->language
== language_fortran
10065 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10066 code
= TYPE_CODE_CHAR
;
10068 case DW_ATE_signed_char
:
10069 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10070 || cu
->language
== language_pascal
10071 || cu
->language
== language_fortran
)
10072 code
= TYPE_CODE_CHAR
;
10074 case DW_ATE_unsigned_char
:
10075 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10076 || cu
->language
== language_pascal
10077 || cu
->language
== language_fortran
)
10078 code
= TYPE_CODE_CHAR
;
10079 type_flags
|= TYPE_FLAG_UNSIGNED
;
10082 /* We just treat this as an integer and then recognize the
10083 type by name elsewhere. */
10087 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10088 dwarf_type_encoding_name (encoding
));
10092 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10093 TYPE_NAME (type
) = name
;
10094 TYPE_TARGET_TYPE (type
) = target_type
;
10096 if (name
&& strcmp (name
, "char") == 0)
10097 TYPE_NOSIGN (type
) = 1;
10099 return set_die_type (die
, type
, cu
);
10102 /* Read the given DW_AT_subrange DIE. */
10104 static struct type
*
10105 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10107 struct type
*base_type
;
10108 struct type
*range_type
;
10109 struct attribute
*attr
;
10111 int low_default_is_valid
;
10113 LONGEST negative_mask
;
10115 base_type
= die_type (die
, cu
);
10116 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10117 check_typedef (base_type
);
10119 /* The die_type call above may have already set the type for this DIE. */
10120 range_type
= get_die_type (die
, cu
);
10124 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10125 omitting DW_AT_lower_bound. */
10126 switch (cu
->language
)
10129 case language_cplus
:
10131 low_default_is_valid
= 1;
10133 case language_fortran
:
10135 low_default_is_valid
= 1;
10138 case language_java
:
10139 case language_objc
:
10141 low_default_is_valid
= (cu
->header
.version
>= 4);
10145 case language_pascal
:
10147 low_default_is_valid
= (cu
->header
.version
>= 4);
10151 low_default_is_valid
= 0;
10155 /* FIXME: For variable sized arrays either of these could be
10156 a variable rather than a constant value. We'll allow it,
10157 but we don't know how to handle it. */
10158 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10160 low
= dwarf2_get_attr_constant_value (attr
, low
);
10161 else if (!low_default_is_valid
)
10162 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10163 "- DIE at 0x%x [in module %s]"),
10164 die
->offset
.sect_off
, cu
->objfile
->name
);
10166 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10169 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10171 /* GCC encodes arrays with unspecified or dynamic length
10172 with a DW_FORM_block1 attribute or a reference attribute.
10173 FIXME: GDB does not yet know how to handle dynamic
10174 arrays properly, treat them as arrays with unspecified
10177 FIXME: jimb/2003-09-22: GDB does not really know
10178 how to handle arrays of unspecified length
10179 either; we just represent them as zero-length
10180 arrays. Choose an appropriate upper bound given
10181 the lower bound we've computed above. */
10185 high
= dwarf2_get_attr_constant_value (attr
, 1);
10189 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10192 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10193 high
= low
+ count
- 1;
10197 /* Unspecified array length. */
10202 /* Dwarf-2 specifications explicitly allows to create subrange types
10203 without specifying a base type.
10204 In that case, the base type must be set to the type of
10205 the lower bound, upper bound or count, in that order, if any of these
10206 three attributes references an object that has a type.
10207 If no base type is found, the Dwarf-2 specifications say that
10208 a signed integer type of size equal to the size of an address should
10210 For the following C code: `extern char gdb_int [];'
10211 GCC produces an empty range DIE.
10212 FIXME: muller/2010-05-28: Possible references to object for low bound,
10213 high bound or count are not yet handled by this code. */
10214 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10216 struct objfile
*objfile
= cu
->objfile
;
10217 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10218 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10219 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10221 /* Test "int", "long int", and "long long int" objfile types,
10222 and select the first one having a size above or equal to the
10223 architecture address size. */
10224 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10225 base_type
= int_type
;
10228 int_type
= objfile_type (objfile
)->builtin_long
;
10229 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10230 base_type
= int_type
;
10233 int_type
= objfile_type (objfile
)->builtin_long_long
;
10234 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10235 base_type
= int_type
;
10241 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10242 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10243 low
|= negative_mask
;
10244 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10245 high
|= negative_mask
;
10247 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10249 /* Mark arrays with dynamic length at least as an array of unspecified
10250 length. GDB could check the boundary but before it gets implemented at
10251 least allow accessing the array elements. */
10252 if (attr
&& attr_form_is_block (attr
))
10253 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10255 /* Ada expects an empty array on no boundary attributes. */
10256 if (attr
== NULL
&& cu
->language
!= language_ada
)
10257 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10259 name
= dwarf2_name (die
, cu
);
10261 TYPE_NAME (range_type
) = name
;
10263 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10265 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10267 set_die_type (die
, range_type
, cu
);
10269 /* set_die_type should be already done. */
10270 set_descriptive_type (range_type
, die
, cu
);
10275 static struct type
*
10276 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10280 /* For now, we only support the C meaning of an unspecified type: void. */
10282 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10283 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10285 return set_die_type (die
, type
, cu
);
10288 /* Read a single die and all its descendents. Set the die's sibling
10289 field to NULL; set other fields in the die correctly, and set all
10290 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10291 location of the info_ptr after reading all of those dies. PARENT
10292 is the parent of the die in question. */
10294 static struct die_info
*
10295 read_die_and_children (const struct die_reader_specs
*reader
,
10296 gdb_byte
*info_ptr
,
10297 gdb_byte
**new_info_ptr
,
10298 struct die_info
*parent
)
10300 struct die_info
*die
;
10304 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10307 *new_info_ptr
= cur_ptr
;
10310 store_in_ref_table (die
, reader
->cu
);
10313 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10317 *new_info_ptr
= cur_ptr
;
10320 die
->sibling
= NULL
;
10321 die
->parent
= parent
;
10325 /* Read a die, all of its descendents, and all of its siblings; set
10326 all of the fields of all of the dies correctly. Arguments are as
10327 in read_die_and_children. */
10329 static struct die_info
*
10330 read_die_and_siblings (const struct die_reader_specs
*reader
,
10331 gdb_byte
*info_ptr
,
10332 gdb_byte
**new_info_ptr
,
10333 struct die_info
*parent
)
10335 struct die_info
*first_die
, *last_sibling
;
10338 cur_ptr
= info_ptr
;
10339 first_die
= last_sibling
= NULL
;
10343 struct die_info
*die
10344 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10348 *new_info_ptr
= cur_ptr
;
10355 last_sibling
->sibling
= die
;
10357 last_sibling
= die
;
10361 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10363 The caller is responsible for filling in the extra attributes
10364 and updating (*DIEP)->num_attrs.
10365 Set DIEP to point to a newly allocated die with its information,
10366 except for its child, sibling, and parent fields.
10367 Set HAS_CHILDREN to tell whether the die has children or not. */
10370 read_full_die_1 (const struct die_reader_specs
*reader
,
10371 struct die_info
**diep
, gdb_byte
*info_ptr
,
10372 int *has_children
, int num_extra_attrs
)
10374 unsigned int abbrev_number
, bytes_read
, i
;
10375 sect_offset offset
;
10376 struct abbrev_info
*abbrev
;
10377 struct die_info
*die
;
10378 struct dwarf2_cu
*cu
= reader
->cu
;
10379 bfd
*abfd
= reader
->abfd
;
10381 offset
.sect_off
= info_ptr
- reader
->buffer
;
10382 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10383 info_ptr
+= bytes_read
;
10384 if (!abbrev_number
)
10391 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10393 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10395 bfd_get_filename (abfd
));
10397 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10398 die
->offset
= offset
;
10399 die
->tag
= abbrev
->tag
;
10400 die
->abbrev
= abbrev_number
;
10402 /* Make the result usable.
10403 The caller needs to update num_attrs after adding the extra
10405 die
->num_attrs
= abbrev
->num_attrs
;
10407 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10408 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10412 *has_children
= abbrev
->has_children
;
10416 /* Read a die and all its attributes.
10417 Set DIEP to point to a newly allocated die with its information,
10418 except for its child, sibling, and parent fields.
10419 Set HAS_CHILDREN to tell whether the die has children or not. */
10422 read_full_die (const struct die_reader_specs
*reader
,
10423 struct die_info
**diep
, gdb_byte
*info_ptr
,
10426 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10429 /* In DWARF version 2, the description of the debugging information is
10430 stored in a separate .debug_abbrev section. Before we read any
10431 dies from a section we read in all abbreviations and install them
10432 in a hash table. This function also sets flags in CU describing
10433 the data found in the abbrev table. */
10436 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10437 struct dwarf2_section_info
*abbrev_section
)
10440 bfd
*abfd
= abbrev_section
->asection
->owner
;
10441 struct comp_unit_head
*cu_header
= &cu
->header
;
10442 gdb_byte
*abbrev_ptr
;
10443 struct abbrev_info
*cur_abbrev
;
10444 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10445 unsigned int abbrev_form
, hash_number
;
10446 struct attr_abbrev
*cur_attrs
;
10447 unsigned int allocated_attrs
;
10449 /* Initialize dwarf2 abbrevs. */
10450 obstack_init (&cu
->abbrev_obstack
);
10451 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10453 * sizeof (struct abbrev_info
*)));
10454 memset (cu
->dwarf2_abbrevs
, 0,
10455 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10457 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10458 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10459 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10460 abbrev_ptr
+= bytes_read
;
10462 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10463 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10465 /* Loop until we reach an abbrev number of 0. */
10466 while (abbrev_number
)
10468 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10470 /* read in abbrev header */
10471 cur_abbrev
->number
= abbrev_number
;
10472 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10473 abbrev_ptr
+= bytes_read
;
10474 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10477 /* now read in declarations */
10478 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10479 abbrev_ptr
+= bytes_read
;
10480 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10481 abbrev_ptr
+= bytes_read
;
10482 while (abbrev_name
)
10484 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10486 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10488 = xrealloc (cur_attrs
, (allocated_attrs
10489 * sizeof (struct attr_abbrev
)));
10492 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10493 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10494 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10495 abbrev_ptr
+= bytes_read
;
10496 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10497 abbrev_ptr
+= bytes_read
;
10500 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10501 (cur_abbrev
->num_attrs
10502 * sizeof (struct attr_abbrev
)));
10503 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10504 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10506 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10507 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10508 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10510 /* Get next abbreviation.
10511 Under Irix6 the abbreviations for a compilation unit are not
10512 always properly terminated with an abbrev number of 0.
10513 Exit loop if we encounter an abbreviation which we have
10514 already read (which means we are about to read the abbreviations
10515 for the next compile unit) or if the end of the abbreviation
10516 table is reached. */
10517 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10518 >= abbrev_section
->size
)
10520 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10521 abbrev_ptr
+= bytes_read
;
10522 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10529 /* Release the memory used by the abbrev table for a compilation unit. */
10532 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10534 struct dwarf2_cu
*cu
= ptr_to_cu
;
10536 obstack_free (&cu
->abbrev_obstack
, NULL
);
10537 cu
->dwarf2_abbrevs
= NULL
;
10540 /* Lookup an abbrev_info structure in the abbrev hash table. */
10542 static struct abbrev_info
*
10543 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
10545 unsigned int hash_number
;
10546 struct abbrev_info
*abbrev
;
10548 hash_number
= number
% ABBREV_HASH_SIZE
;
10549 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
10553 if (abbrev
->number
== number
)
10556 abbrev
= abbrev
->next
;
10561 /* Returns nonzero if TAG represents a type that we might generate a partial
10565 is_type_tag_for_partial (int tag
)
10570 /* Some types that would be reasonable to generate partial symbols for,
10571 that we don't at present. */
10572 case DW_TAG_array_type
:
10573 case DW_TAG_file_type
:
10574 case DW_TAG_ptr_to_member_type
:
10575 case DW_TAG_set_type
:
10576 case DW_TAG_string_type
:
10577 case DW_TAG_subroutine_type
:
10579 case DW_TAG_base_type
:
10580 case DW_TAG_class_type
:
10581 case DW_TAG_interface_type
:
10582 case DW_TAG_enumeration_type
:
10583 case DW_TAG_structure_type
:
10584 case DW_TAG_subrange_type
:
10585 case DW_TAG_typedef
:
10586 case DW_TAG_union_type
:
10593 /* Load all DIEs that are interesting for partial symbols into memory. */
10595 static struct partial_die_info
*
10596 load_partial_dies (const struct die_reader_specs
*reader
,
10597 gdb_byte
*info_ptr
, int building_psymtab
)
10599 struct dwarf2_cu
*cu
= reader
->cu
;
10600 struct objfile
*objfile
= cu
->objfile
;
10601 struct partial_die_info
*part_die
;
10602 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
10603 struct abbrev_info
*abbrev
;
10604 unsigned int bytes_read
;
10605 unsigned int load_all
= 0;
10606 int nesting_level
= 1;
10611 gdb_assert (cu
->per_cu
!= NULL
);
10612 if (cu
->per_cu
->load_all_dies
)
10616 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10620 &cu
->comp_unit_obstack
,
10621 hashtab_obstack_allocate
,
10622 dummy_obstack_deallocate
);
10624 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10625 sizeof (struct partial_die_info
));
10629 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
10631 /* A NULL abbrev means the end of a series of children. */
10632 if (abbrev
== NULL
)
10634 if (--nesting_level
== 0)
10636 /* PART_DIE was probably the last thing allocated on the
10637 comp_unit_obstack, so we could call obstack_free
10638 here. We don't do that because the waste is small,
10639 and will be cleaned up when we're done with this
10640 compilation unit. This way, we're also more robust
10641 against other users of the comp_unit_obstack. */
10644 info_ptr
+= bytes_read
;
10645 last_die
= parent_die
;
10646 parent_die
= parent_die
->die_parent
;
10650 /* Check for template arguments. We never save these; if
10651 they're seen, we just mark the parent, and go on our way. */
10652 if (parent_die
!= NULL
10653 && cu
->language
== language_cplus
10654 && (abbrev
->tag
== DW_TAG_template_type_param
10655 || abbrev
->tag
== DW_TAG_template_value_param
))
10657 parent_die
->has_template_arguments
= 1;
10661 /* We don't need a partial DIE for the template argument. */
10662 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10667 /* We only recurse into c++ subprograms looking for template arguments.
10668 Skip their other children. */
10670 && cu
->language
== language_cplus
10671 && parent_die
!= NULL
10672 && parent_die
->tag
== DW_TAG_subprogram
)
10674 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10678 /* Check whether this DIE is interesting enough to save. Normally
10679 we would not be interested in members here, but there may be
10680 later variables referencing them via DW_AT_specification (for
10681 static members). */
10683 && !is_type_tag_for_partial (abbrev
->tag
)
10684 && abbrev
->tag
!= DW_TAG_constant
10685 && abbrev
->tag
!= DW_TAG_enumerator
10686 && abbrev
->tag
!= DW_TAG_subprogram
10687 && abbrev
->tag
!= DW_TAG_lexical_block
10688 && abbrev
->tag
!= DW_TAG_variable
10689 && abbrev
->tag
!= DW_TAG_namespace
10690 && abbrev
->tag
!= DW_TAG_module
10691 && abbrev
->tag
!= DW_TAG_member
)
10693 /* Otherwise we skip to the next sibling, if any. */
10694 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10698 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
10701 /* This two-pass algorithm for processing partial symbols has a
10702 high cost in cache pressure. Thus, handle some simple cases
10703 here which cover the majority of C partial symbols. DIEs
10704 which neither have specification tags in them, nor could have
10705 specification tags elsewhere pointing at them, can simply be
10706 processed and discarded.
10708 This segment is also optional; scan_partial_symbols and
10709 add_partial_symbol will handle these DIEs if we chain
10710 them in normally. When compilers which do not emit large
10711 quantities of duplicate debug information are more common,
10712 this code can probably be removed. */
10714 /* Any complete simple types at the top level (pretty much all
10715 of them, for a language without namespaces), can be processed
10717 if (parent_die
== NULL
10718 && part_die
->has_specification
== 0
10719 && part_die
->is_declaration
== 0
10720 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
10721 || part_die
->tag
== DW_TAG_base_type
10722 || part_die
->tag
== DW_TAG_subrange_type
))
10724 if (building_psymtab
&& part_die
->name
!= NULL
)
10725 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
10726 VAR_DOMAIN
, LOC_TYPEDEF
,
10727 &objfile
->static_psymbols
,
10728 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
10729 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
10733 /* The exception for DW_TAG_typedef with has_children above is
10734 a workaround of GCC PR debug/47510. In the case of this complaint
10735 type_name_no_tag_or_error will error on such types later.
10737 GDB skipped children of DW_TAG_typedef by the shortcut above and then
10738 it could not find the child DIEs referenced later, this is checked
10739 above. In correct DWARF DW_TAG_typedef should have no children. */
10741 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
10742 complaint (&symfile_complaints
,
10743 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
10744 "- DIE at 0x%x [in module %s]"),
10745 part_die
->offset
.sect_off
, objfile
->name
);
10747 /* If we're at the second level, and we're an enumerator, and
10748 our parent has no specification (meaning possibly lives in a
10749 namespace elsewhere), then we can add the partial symbol now
10750 instead of queueing it. */
10751 if (part_die
->tag
== DW_TAG_enumerator
10752 && parent_die
!= NULL
10753 && parent_die
->die_parent
== NULL
10754 && parent_die
->tag
== DW_TAG_enumeration_type
10755 && parent_die
->has_specification
== 0)
10757 if (part_die
->name
== NULL
)
10758 complaint (&symfile_complaints
,
10759 _("malformed enumerator DIE ignored"));
10760 else if (building_psymtab
)
10761 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
10762 VAR_DOMAIN
, LOC_CONST
,
10763 (cu
->language
== language_cplus
10764 || cu
->language
== language_java
)
10765 ? &objfile
->global_psymbols
10766 : &objfile
->static_psymbols
,
10767 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
10769 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
10773 /* We'll save this DIE so link it in. */
10774 part_die
->die_parent
= parent_die
;
10775 part_die
->die_sibling
= NULL
;
10776 part_die
->die_child
= NULL
;
10778 if (last_die
&& last_die
== parent_die
)
10779 last_die
->die_child
= part_die
;
10781 last_die
->die_sibling
= part_die
;
10783 last_die
= part_die
;
10785 if (first_die
== NULL
)
10786 first_die
= part_die
;
10788 /* Maybe add the DIE to the hash table. Not all DIEs that we
10789 find interesting need to be in the hash table, because we
10790 also have the parent/sibling/child chains; only those that we
10791 might refer to by offset later during partial symbol reading.
10793 For now this means things that might have be the target of a
10794 DW_AT_specification, DW_AT_abstract_origin, or
10795 DW_AT_extension. DW_AT_extension will refer only to
10796 namespaces; DW_AT_abstract_origin refers to functions (and
10797 many things under the function DIE, but we do not recurse
10798 into function DIEs during partial symbol reading) and
10799 possibly variables as well; DW_AT_specification refers to
10800 declarations. Declarations ought to have the DW_AT_declaration
10801 flag. It happens that GCC forgets to put it in sometimes, but
10802 only for functions, not for types.
10804 Adding more things than necessary to the hash table is harmless
10805 except for the performance cost. Adding too few will result in
10806 wasted time in find_partial_die, when we reread the compilation
10807 unit with load_all_dies set. */
10810 || abbrev
->tag
== DW_TAG_constant
10811 || abbrev
->tag
== DW_TAG_subprogram
10812 || abbrev
->tag
== DW_TAG_variable
10813 || abbrev
->tag
== DW_TAG_namespace
10814 || part_die
->is_declaration
)
10818 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
10819 part_die
->offset
.sect_off
, INSERT
);
10823 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10824 sizeof (struct partial_die_info
));
10826 /* For some DIEs we want to follow their children (if any). For C
10827 we have no reason to follow the children of structures; for other
10828 languages we have to, so that we can get at method physnames
10829 to infer fully qualified class names, for DW_AT_specification,
10830 and for C++ template arguments. For C++, we also look one level
10831 inside functions to find template arguments (if the name of the
10832 function does not already contain the template arguments).
10834 For Ada, we need to scan the children of subprograms and lexical
10835 blocks as well because Ada allows the definition of nested
10836 entities that could be interesting for the debugger, such as
10837 nested subprograms for instance. */
10838 if (last_die
->has_children
10840 || last_die
->tag
== DW_TAG_namespace
10841 || last_die
->tag
== DW_TAG_module
10842 || last_die
->tag
== DW_TAG_enumeration_type
10843 || (cu
->language
== language_cplus
10844 && last_die
->tag
== DW_TAG_subprogram
10845 && (last_die
->name
== NULL
10846 || strchr (last_die
->name
, '<') == NULL
))
10847 || (cu
->language
!= language_c
10848 && (last_die
->tag
== DW_TAG_class_type
10849 || last_die
->tag
== DW_TAG_interface_type
10850 || last_die
->tag
== DW_TAG_structure_type
10851 || last_die
->tag
== DW_TAG_union_type
))
10852 || (cu
->language
== language_ada
10853 && (last_die
->tag
== DW_TAG_subprogram
10854 || last_die
->tag
== DW_TAG_lexical_block
))))
10857 parent_die
= last_die
;
10861 /* Otherwise we skip to the next sibling, if any. */
10862 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
10864 /* Back to the top, do it again. */
10868 /* Read a minimal amount of information into the minimal die structure. */
10871 read_partial_die (const struct die_reader_specs
*reader
,
10872 struct partial_die_info
*part_die
,
10873 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
10874 gdb_byte
*info_ptr
)
10876 struct dwarf2_cu
*cu
= reader
->cu
;
10877 struct objfile
*objfile
= cu
->objfile
;
10878 gdb_byte
*buffer
= reader
->buffer
;
10880 struct attribute attr
;
10881 int has_low_pc_attr
= 0;
10882 int has_high_pc_attr
= 0;
10883 int high_pc_relative
= 0;
10885 memset (part_die
, 0, sizeof (struct partial_die_info
));
10887 part_die
->offset
.sect_off
= info_ptr
- buffer
;
10889 info_ptr
+= abbrev_len
;
10891 if (abbrev
== NULL
)
10894 part_die
->tag
= abbrev
->tag
;
10895 part_die
->has_children
= abbrev
->has_children
;
10897 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10899 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
10901 /* Store the data if it is of an attribute we want to keep in a
10902 partial symbol table. */
10906 switch (part_die
->tag
)
10908 case DW_TAG_compile_unit
:
10909 case DW_TAG_type_unit
:
10910 /* Compilation units have a DW_AT_name that is a filename, not
10911 a source language identifier. */
10912 case DW_TAG_enumeration_type
:
10913 case DW_TAG_enumerator
:
10914 /* These tags always have simple identifiers already; no need
10915 to canonicalize them. */
10916 part_die
->name
= DW_STRING (&attr
);
10920 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
10921 &objfile
->objfile_obstack
);
10925 case DW_AT_linkage_name
:
10926 case DW_AT_MIPS_linkage_name
:
10927 /* Note that both forms of linkage name might appear. We
10928 assume they will be the same, and we only store the last
10930 if (cu
->language
== language_ada
)
10931 part_die
->name
= DW_STRING (&attr
);
10932 part_die
->linkage_name
= DW_STRING (&attr
);
10935 has_low_pc_attr
= 1;
10936 part_die
->lowpc
= DW_ADDR (&attr
);
10938 case DW_AT_high_pc
:
10939 has_high_pc_attr
= 1;
10940 if (attr
.form
== DW_FORM_addr
10941 || attr
.form
== DW_FORM_GNU_addr_index
)
10942 part_die
->highpc
= DW_ADDR (&attr
);
10945 high_pc_relative
= 1;
10946 part_die
->highpc
= DW_UNSND (&attr
);
10949 case DW_AT_location
:
10950 /* Support the .debug_loc offsets. */
10951 if (attr_form_is_block (&attr
))
10953 part_die
->locdesc
= DW_BLOCK (&attr
);
10955 else if (attr_form_is_section_offset (&attr
))
10957 dwarf2_complex_location_expr_complaint ();
10961 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10962 "partial symbol information");
10965 case DW_AT_external
:
10966 part_die
->is_external
= DW_UNSND (&attr
);
10968 case DW_AT_declaration
:
10969 part_die
->is_declaration
= DW_UNSND (&attr
);
10972 part_die
->has_type
= 1;
10974 case DW_AT_abstract_origin
:
10975 case DW_AT_specification
:
10976 case DW_AT_extension
:
10977 part_die
->has_specification
= 1;
10978 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
10980 case DW_AT_sibling
:
10981 /* Ignore absolute siblings, they might point outside of
10982 the current compile unit. */
10983 if (attr
.form
== DW_FORM_ref_addr
)
10984 complaint (&symfile_complaints
,
10985 _("ignoring absolute DW_AT_sibling"));
10987 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
10989 case DW_AT_byte_size
:
10990 part_die
->has_byte_size
= 1;
10992 case DW_AT_calling_convention
:
10993 /* DWARF doesn't provide a way to identify a program's source-level
10994 entry point. DW_AT_calling_convention attributes are only meant
10995 to describe functions' calling conventions.
10997 However, because it's a necessary piece of information in
10998 Fortran, and because DW_CC_program is the only piece of debugging
10999 information whose definition refers to a 'main program' at all,
11000 several compilers have begun marking Fortran main programs with
11001 DW_CC_program --- even when those functions use the standard
11002 calling conventions.
11004 So until DWARF specifies a way to provide this information and
11005 compilers pick up the new representation, we'll support this
11007 if (DW_UNSND (&attr
) == DW_CC_program
11008 && cu
->language
== language_fortran
)
11010 set_main_name (part_die
->name
);
11012 /* As this DIE has a static linkage the name would be difficult
11013 to look up later. */
11014 language_of_main
= language_fortran
;
11018 if (DW_UNSND (&attr
) == DW_INL_inlined
11019 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11020 part_die
->may_be_inlined
= 1;
11027 if (high_pc_relative
)
11028 part_die
->highpc
+= part_die
->lowpc
;
11030 if (has_low_pc_attr
&& has_high_pc_attr
)
11032 /* When using the GNU linker, .gnu.linkonce. sections are used to
11033 eliminate duplicate copies of functions and vtables and such.
11034 The linker will arbitrarily choose one and discard the others.
11035 The AT_*_pc values for such functions refer to local labels in
11036 these sections. If the section from that file was discarded, the
11037 labels are not in the output, so the relocs get a value of 0.
11038 If this is a discarded function, mark the pc bounds as invalid,
11039 so that GDB will ignore it. */
11040 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11042 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11044 complaint (&symfile_complaints
,
11045 _("DW_AT_low_pc %s is zero "
11046 "for DIE at 0x%x [in module %s]"),
11047 paddress (gdbarch
, part_die
->lowpc
),
11048 part_die
->offset
.sect_off
, objfile
->name
);
11050 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11051 else if (part_die
->lowpc
>= part_die
->highpc
)
11053 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11055 complaint (&symfile_complaints
,
11056 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11057 "for DIE at 0x%x [in module %s]"),
11058 paddress (gdbarch
, part_die
->lowpc
),
11059 paddress (gdbarch
, part_die
->highpc
),
11060 part_die
->offset
.sect_off
, objfile
->name
);
11063 part_die
->has_pc_info
= 1;
11069 /* Find a cached partial DIE at OFFSET in CU. */
11071 static struct partial_die_info
*
11072 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11074 struct partial_die_info
*lookup_die
= NULL
;
11075 struct partial_die_info part_die
;
11077 part_die
.offset
= offset
;
11078 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11084 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11085 except in the case of .debug_types DIEs which do not reference
11086 outside their CU (they do however referencing other types via
11087 DW_FORM_ref_sig8). */
11089 static struct partial_die_info
*
11090 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11092 struct objfile
*objfile
= cu
->objfile
;
11093 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11094 struct partial_die_info
*pd
= NULL
;
11096 if (offset_in_cu_p (&cu
->header
, offset
))
11098 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11101 /* We missed recording what we needed.
11102 Load all dies and try again. */
11103 per_cu
= cu
->per_cu
;
11107 /* TUs don't reference other CUs/TUs (except via type signatures). */
11108 if (cu
->per_cu
->is_debug_types
)
11110 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11111 " external reference to offset 0x%lx [in module %s].\n"),
11112 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11113 bfd_get_filename (objfile
->obfd
));
11115 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11117 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11118 load_partial_comp_unit (per_cu
);
11120 per_cu
->cu
->last_used
= 0;
11121 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11124 /* If we didn't find it, and not all dies have been loaded,
11125 load them all and try again. */
11127 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11129 per_cu
->load_all_dies
= 1;
11131 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11132 THIS_CU->cu may already be in use. So we can't just free it and
11133 replace its DIEs with the ones we read in. Instead, we leave those
11134 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11135 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11137 load_partial_comp_unit (per_cu
);
11139 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11143 internal_error (__FILE__
, __LINE__
,
11144 _("could not find partial DIE 0x%x "
11145 "in cache [from module %s]\n"),
11146 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11150 /* See if we can figure out if the class lives in a namespace. We do
11151 this by looking for a member function; its demangled name will
11152 contain namespace info, if there is any. */
11155 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11156 struct dwarf2_cu
*cu
)
11158 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11159 what template types look like, because the demangler
11160 frequently doesn't give the same name as the debug info. We
11161 could fix this by only using the demangled name to get the
11162 prefix (but see comment in read_structure_type). */
11164 struct partial_die_info
*real_pdi
;
11165 struct partial_die_info
*child_pdi
;
11167 /* If this DIE (this DIE's specification, if any) has a parent, then
11168 we should not do this. We'll prepend the parent's fully qualified
11169 name when we create the partial symbol. */
11171 real_pdi
= struct_pdi
;
11172 while (real_pdi
->has_specification
)
11173 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11175 if (real_pdi
->die_parent
!= NULL
)
11178 for (child_pdi
= struct_pdi
->die_child
;
11180 child_pdi
= child_pdi
->die_sibling
)
11182 if (child_pdi
->tag
== DW_TAG_subprogram
11183 && child_pdi
->linkage_name
!= NULL
)
11185 char *actual_class_name
11186 = language_class_name_from_physname (cu
->language_defn
,
11187 child_pdi
->linkage_name
);
11188 if (actual_class_name
!= NULL
)
11191 = obsavestring (actual_class_name
,
11192 strlen (actual_class_name
),
11193 &cu
->objfile
->objfile_obstack
);
11194 xfree (actual_class_name
);
11201 /* Adjust PART_DIE before generating a symbol for it. This function
11202 may set the is_external flag or change the DIE's name. */
11205 fixup_partial_die (struct partial_die_info
*part_die
,
11206 struct dwarf2_cu
*cu
)
11208 /* Once we've fixed up a die, there's no point in doing so again.
11209 This also avoids a memory leak if we were to call
11210 guess_partial_die_structure_name multiple times. */
11211 if (part_die
->fixup_called
)
11214 /* If we found a reference attribute and the DIE has no name, try
11215 to find a name in the referred to DIE. */
11217 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11219 struct partial_die_info
*spec_die
;
11221 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11223 fixup_partial_die (spec_die
, cu
);
11225 if (spec_die
->name
)
11227 part_die
->name
= spec_die
->name
;
11229 /* Copy DW_AT_external attribute if it is set. */
11230 if (spec_die
->is_external
)
11231 part_die
->is_external
= spec_die
->is_external
;
11235 /* Set default names for some unnamed DIEs. */
11237 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11238 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11240 /* If there is no parent die to provide a namespace, and there are
11241 children, see if we can determine the namespace from their linkage
11243 if (cu
->language
== language_cplus
11244 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11245 && part_die
->die_parent
== NULL
11246 && part_die
->has_children
11247 && (part_die
->tag
== DW_TAG_class_type
11248 || part_die
->tag
== DW_TAG_structure_type
11249 || part_die
->tag
== DW_TAG_union_type
))
11250 guess_partial_die_structure_name (part_die
, cu
);
11252 /* GCC might emit a nameless struct or union that has a linkage
11253 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11254 if (part_die
->name
== NULL
11255 && (part_die
->tag
== DW_TAG_class_type
11256 || part_die
->tag
== DW_TAG_interface_type
11257 || part_die
->tag
== DW_TAG_structure_type
11258 || part_die
->tag
== DW_TAG_union_type
)
11259 && part_die
->linkage_name
!= NULL
)
11263 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11268 /* Strip any leading namespaces/classes, keep only the base name.
11269 DW_AT_name for named DIEs does not contain the prefixes. */
11270 base
= strrchr (demangled
, ':');
11271 if (base
&& base
> demangled
&& base
[-1] == ':')
11276 part_die
->name
= obsavestring (base
, strlen (base
),
11277 &cu
->objfile
->objfile_obstack
);
11282 part_die
->fixup_called
= 1;
11285 /* Read an attribute value described by an attribute form. */
11288 read_attribute_value (const struct die_reader_specs
*reader
,
11289 struct attribute
*attr
, unsigned form
,
11290 gdb_byte
*info_ptr
)
11292 struct dwarf2_cu
*cu
= reader
->cu
;
11293 bfd
*abfd
= reader
->abfd
;
11294 struct comp_unit_head
*cu_header
= &cu
->header
;
11295 unsigned int bytes_read
;
11296 struct dwarf_block
*blk
;
11301 case DW_FORM_ref_addr
:
11302 if (cu
->header
.version
== 2)
11303 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11305 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11306 &cu
->header
, &bytes_read
);
11307 info_ptr
+= bytes_read
;
11310 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11311 info_ptr
+= bytes_read
;
11313 case DW_FORM_block2
:
11314 blk
= dwarf_alloc_block (cu
);
11315 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11317 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11318 info_ptr
+= blk
->size
;
11319 DW_BLOCK (attr
) = blk
;
11321 case DW_FORM_block4
:
11322 blk
= dwarf_alloc_block (cu
);
11323 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11325 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11326 info_ptr
+= blk
->size
;
11327 DW_BLOCK (attr
) = blk
;
11329 case DW_FORM_data2
:
11330 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11333 case DW_FORM_data4
:
11334 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11337 case DW_FORM_data8
:
11338 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11341 case DW_FORM_sec_offset
:
11342 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11343 info_ptr
+= bytes_read
;
11345 case DW_FORM_string
:
11346 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11347 DW_STRING_IS_CANONICAL (attr
) = 0;
11348 info_ptr
+= bytes_read
;
11351 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11353 DW_STRING_IS_CANONICAL (attr
) = 0;
11354 info_ptr
+= bytes_read
;
11356 case DW_FORM_exprloc
:
11357 case DW_FORM_block
:
11358 blk
= dwarf_alloc_block (cu
);
11359 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11360 info_ptr
+= bytes_read
;
11361 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11362 info_ptr
+= blk
->size
;
11363 DW_BLOCK (attr
) = blk
;
11365 case DW_FORM_block1
:
11366 blk
= dwarf_alloc_block (cu
);
11367 blk
->size
= read_1_byte (abfd
, info_ptr
);
11369 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11370 info_ptr
+= blk
->size
;
11371 DW_BLOCK (attr
) = blk
;
11373 case DW_FORM_data1
:
11374 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11378 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11381 case DW_FORM_flag_present
:
11382 DW_UNSND (attr
) = 1;
11384 case DW_FORM_sdata
:
11385 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11386 info_ptr
+= bytes_read
;
11388 case DW_FORM_udata
:
11389 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11390 info_ptr
+= bytes_read
;
11393 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11394 + read_1_byte (abfd
, info_ptr
));
11398 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11399 + read_2_bytes (abfd
, info_ptr
));
11403 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11404 + read_4_bytes (abfd
, info_ptr
));
11408 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11409 + read_8_bytes (abfd
, info_ptr
));
11412 case DW_FORM_ref_sig8
:
11413 /* Convert the signature to something we can record in DW_UNSND
11415 NOTE: This is NULL if the type wasn't found. */
11416 DW_SIGNATURED_TYPE (attr
) =
11417 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11420 case DW_FORM_ref_udata
:
11421 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11422 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11423 info_ptr
+= bytes_read
;
11425 case DW_FORM_indirect
:
11426 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11427 info_ptr
+= bytes_read
;
11428 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11430 case DW_FORM_GNU_addr_index
:
11431 if (reader
->dwo_file
== NULL
)
11433 /* For now flag a hard error.
11434 Later we can turn this into a complaint. */
11435 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11436 dwarf_form_name (form
),
11437 bfd_get_filename (abfd
));
11439 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11440 info_ptr
+= bytes_read
;
11442 case DW_FORM_GNU_str_index
:
11443 if (reader
->dwo_file
== NULL
)
11445 /* For now flag a hard error.
11446 Later we can turn this into a complaint if warranted. */
11447 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11448 dwarf_form_name (form
),
11449 bfd_get_filename (abfd
));
11452 ULONGEST str_index
=
11453 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11455 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11456 DW_STRING_IS_CANONICAL (attr
) = 0;
11457 info_ptr
+= bytes_read
;
11461 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11462 dwarf_form_name (form
),
11463 bfd_get_filename (abfd
));
11466 /* We have seen instances where the compiler tried to emit a byte
11467 size attribute of -1 which ended up being encoded as an unsigned
11468 0xffffffff. Although 0xffffffff is technically a valid size value,
11469 an object of this size seems pretty unlikely so we can relatively
11470 safely treat these cases as if the size attribute was invalid and
11471 treat them as zero by default. */
11472 if (attr
->name
== DW_AT_byte_size
11473 && form
== DW_FORM_data4
11474 && DW_UNSND (attr
) >= 0xffffffff)
11477 (&symfile_complaints
,
11478 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11479 hex_string (DW_UNSND (attr
)));
11480 DW_UNSND (attr
) = 0;
11486 /* Read an attribute described by an abbreviated attribute. */
11489 read_attribute (const struct die_reader_specs
*reader
,
11490 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11491 gdb_byte
*info_ptr
)
11493 attr
->name
= abbrev
->name
;
11494 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11497 /* Read dwarf information from a buffer. */
11499 static unsigned int
11500 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11502 return bfd_get_8 (abfd
, buf
);
11506 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11508 return bfd_get_signed_8 (abfd
, buf
);
11511 static unsigned int
11512 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11514 return bfd_get_16 (abfd
, buf
);
11518 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11520 return bfd_get_signed_16 (abfd
, buf
);
11523 static unsigned int
11524 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11526 return bfd_get_32 (abfd
, buf
);
11530 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11532 return bfd_get_signed_32 (abfd
, buf
);
11536 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
11538 return bfd_get_64 (abfd
, buf
);
11542 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
11543 unsigned int *bytes_read
)
11545 struct comp_unit_head
*cu_header
= &cu
->header
;
11546 CORE_ADDR retval
= 0;
11548 if (cu_header
->signed_addr_p
)
11550 switch (cu_header
->addr_size
)
11553 retval
= bfd_get_signed_16 (abfd
, buf
);
11556 retval
= bfd_get_signed_32 (abfd
, buf
);
11559 retval
= bfd_get_signed_64 (abfd
, buf
);
11562 internal_error (__FILE__
, __LINE__
,
11563 _("read_address: bad switch, signed [in module %s]"),
11564 bfd_get_filename (abfd
));
11569 switch (cu_header
->addr_size
)
11572 retval
= bfd_get_16 (abfd
, buf
);
11575 retval
= bfd_get_32 (abfd
, buf
);
11578 retval
= bfd_get_64 (abfd
, buf
);
11581 internal_error (__FILE__
, __LINE__
,
11582 _("read_address: bad switch, "
11583 "unsigned [in module %s]"),
11584 bfd_get_filename (abfd
));
11588 *bytes_read
= cu_header
->addr_size
;
11592 /* Read the initial length from a section. The (draft) DWARF 3
11593 specification allows the initial length to take up either 4 bytes
11594 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
11595 bytes describe the length and all offsets will be 8 bytes in length
11598 An older, non-standard 64-bit format is also handled by this
11599 function. The older format in question stores the initial length
11600 as an 8-byte quantity without an escape value. Lengths greater
11601 than 2^32 aren't very common which means that the initial 4 bytes
11602 is almost always zero. Since a length value of zero doesn't make
11603 sense for the 32-bit format, this initial zero can be considered to
11604 be an escape value which indicates the presence of the older 64-bit
11605 format. As written, the code can't detect (old format) lengths
11606 greater than 4GB. If it becomes necessary to handle lengths
11607 somewhat larger than 4GB, we could allow other small values (such
11608 as the non-sensical values of 1, 2, and 3) to also be used as
11609 escape values indicating the presence of the old format.
11611 The value returned via bytes_read should be used to increment the
11612 relevant pointer after calling read_initial_length().
11614 [ Note: read_initial_length() and read_offset() are based on the
11615 document entitled "DWARF Debugging Information Format", revision
11616 3, draft 8, dated November 19, 2001. This document was obtained
11619 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
11621 This document is only a draft and is subject to change. (So beware.)
11623 Details regarding the older, non-standard 64-bit format were
11624 determined empirically by examining 64-bit ELF files produced by
11625 the SGI toolchain on an IRIX 6.5 machine.
11627 - Kevin, July 16, 2002
11631 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
11633 LONGEST length
= bfd_get_32 (abfd
, buf
);
11635 if (length
== 0xffffffff)
11637 length
= bfd_get_64 (abfd
, buf
+ 4);
11640 else if (length
== 0)
11642 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
11643 length
= bfd_get_64 (abfd
, buf
);
11654 /* Cover function for read_initial_length.
11655 Returns the length of the object at BUF, and stores the size of the
11656 initial length in *BYTES_READ and stores the size that offsets will be in
11658 If the initial length size is not equivalent to that specified in
11659 CU_HEADER then issue a complaint.
11660 This is useful when reading non-comp-unit headers. */
11663 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
11664 const struct comp_unit_head
*cu_header
,
11665 unsigned int *bytes_read
,
11666 unsigned int *offset_size
)
11668 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
11670 gdb_assert (cu_header
->initial_length_size
== 4
11671 || cu_header
->initial_length_size
== 8
11672 || cu_header
->initial_length_size
== 12);
11674 if (cu_header
->initial_length_size
!= *bytes_read
)
11675 complaint (&symfile_complaints
,
11676 _("intermixed 32-bit and 64-bit DWARF sections"));
11678 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
11682 /* Read an offset from the data stream. The size of the offset is
11683 given by cu_header->offset_size. */
11686 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
11687 unsigned int *bytes_read
)
11689 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
11691 *bytes_read
= cu_header
->offset_size
;
11695 /* Read an offset from the data stream. */
11698 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
11700 LONGEST retval
= 0;
11702 switch (offset_size
)
11705 retval
= bfd_get_32 (abfd
, buf
);
11708 retval
= bfd_get_64 (abfd
, buf
);
11711 internal_error (__FILE__
, __LINE__
,
11712 _("read_offset_1: bad switch [in module %s]"),
11713 bfd_get_filename (abfd
));
11720 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
11722 /* If the size of a host char is 8 bits, we can return a pointer
11723 to the buffer, otherwise we have to copy the data to a buffer
11724 allocated on the temporary obstack. */
11725 gdb_assert (HOST_CHAR_BIT
== 8);
11730 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11732 /* If the size of a host char is 8 bits, we can return a pointer
11733 to the string, otherwise we have to copy the string to a buffer
11734 allocated on the temporary obstack. */
11735 gdb_assert (HOST_CHAR_BIT
== 8);
11738 *bytes_read_ptr
= 1;
11741 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
11742 return (char *) buf
;
11746 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
11748 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
11749 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
11750 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
11751 bfd_get_filename (abfd
));
11752 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
11753 error (_("DW_FORM_strp pointing outside of "
11754 ".debug_str section [in module %s]"),
11755 bfd_get_filename (abfd
));
11756 gdb_assert (HOST_CHAR_BIT
== 8);
11757 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
11759 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
11763 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
11764 const struct comp_unit_head
*cu_header
,
11765 unsigned int *bytes_read_ptr
)
11767 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
11769 return read_indirect_string_at_offset (abfd
, str_offset
);
11773 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11776 unsigned int num_read
;
11778 unsigned char byte
;
11786 byte
= bfd_get_8 (abfd
, buf
);
11789 result
|= ((ULONGEST
) (byte
& 127) << shift
);
11790 if ((byte
& 128) == 0)
11796 *bytes_read_ptr
= num_read
;
11801 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11804 int i
, shift
, num_read
;
11805 unsigned char byte
;
11813 byte
= bfd_get_8 (abfd
, buf
);
11816 result
|= ((LONGEST
) (byte
& 127) << shift
);
11818 if ((byte
& 128) == 0)
11823 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
11824 result
|= -(((LONGEST
) 1) << shift
);
11825 *bytes_read_ptr
= num_read
;
11829 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
11830 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
11831 ADDR_SIZE is the size of addresses from the CU header. */
11834 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
11836 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11837 bfd
*abfd
= objfile
->obfd
;
11838 const gdb_byte
*info_ptr
;
11840 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
11841 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
11842 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
11844 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
11845 error (_("DW_FORM_addr_index pointing outside of "
11846 ".debug_addr section [in module %s]"),
11848 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
11849 + addr_base
+ addr_index
* addr_size
);
11850 if (addr_size
== 4)
11851 return bfd_get_32 (abfd
, info_ptr
);
11853 return bfd_get_64 (abfd
, info_ptr
);
11856 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
11859 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
11861 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
11864 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
11867 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
11868 unsigned int *bytes_read
)
11870 bfd
*abfd
= cu
->objfile
->obfd
;
11871 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
11873 return read_addr_index (cu
, addr_index
);
11876 /* Data structure to pass results from dwarf2_read_addr_index_reader
11877 back to dwarf2_read_addr_index. */
11879 struct dwarf2_read_addr_index_data
11881 ULONGEST addr_base
;
11885 /* die_reader_func for dwarf2_read_addr_index. */
11888 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
11889 gdb_byte
*info_ptr
,
11890 struct die_info
*comp_unit_die
,
11894 struct dwarf2_cu
*cu
= reader
->cu
;
11895 struct dwarf2_read_addr_index_data
*aidata
=
11896 (struct dwarf2_read_addr_index_data
*) data
;
11898 aidata
->addr_base
= cu
->addr_base
;
11899 aidata
->addr_size
= cu
->header
.addr_size
;
11902 /* Given an index in .debug_addr, fetch the value.
11903 NOTE: This can be called during dwarf expression evaluation,
11904 long after the debug information has been read, and thus per_cu->cu
11905 may no longer exist. */
11908 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
11909 unsigned int addr_index
)
11911 struct objfile
*objfile
= per_cu
->objfile
;
11912 struct dwarf2_cu
*cu
= per_cu
->cu
;
11913 ULONGEST addr_base
;
11916 /* This is intended to be called from outside this file. */
11917 dw2_setup (objfile
);
11919 /* We need addr_base and addr_size.
11920 If we don't have PER_CU->cu, we have to get it.
11921 Nasty, but the alternative is storing the needed info in PER_CU,
11922 which at this point doesn't seem justified: it's not clear how frequently
11923 it would get used and it would increase the size of every PER_CU.
11924 Entry points like dwarf2_per_cu_addr_size do a similar thing
11925 so we're not in uncharted territory here.
11926 Alas we need to be a bit more complicated as addr_base is contained
11929 We don't need to read the entire CU(/TU).
11930 We just need the header and top level die.
11931 IWBN to use the aging mechanism to let us lazily later discard the CU.
11932 See however init_cutu_and_read_dies_simple. */
11936 addr_base
= cu
->addr_base
;
11937 addr_size
= cu
->header
.addr_size
;
11941 struct dwarf2_read_addr_index_data aidata
;
11943 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
11945 addr_base
= aidata
.addr_base
;
11946 addr_size
= aidata
.addr_size
;
11949 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
11952 /* Given a DW_AT_str_index, fetch the string. */
11955 read_str_index (const struct die_reader_specs
*reader
,
11956 struct dwarf2_cu
*cu
, ULONGEST str_index
)
11958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11959 const char *dwo_name
= objfile
->name
;
11960 bfd
*abfd
= objfile
->obfd
;
11961 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
11962 gdb_byte
*info_ptr
;
11963 ULONGEST str_offset
;
11965 dwarf2_read_section (objfile
, §ions
->str
);
11966 dwarf2_read_section (objfile
, §ions
->str_offsets
);
11967 if (sections
->str
.buffer
== NULL
)
11968 error (_("DW_FORM_str_index used without .debug_str.dwo section"
11969 " in CU at offset 0x%lx [in module %s]"),
11970 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11971 if (sections
->str_offsets
.buffer
== NULL
)
11972 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
11973 " in CU at offset 0x%lx [in module %s]"),
11974 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11975 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
11976 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
11977 " section in CU at offset 0x%lx [in module %s]"),
11978 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11979 info_ptr
= (sections
->str_offsets
.buffer
11980 + str_index
* cu
->header
.offset_size
);
11981 if (cu
->header
.offset_size
== 4)
11982 str_offset
= bfd_get_32 (abfd
, info_ptr
);
11984 str_offset
= bfd_get_64 (abfd
, info_ptr
);
11985 if (str_offset
>= sections
->str
.size
)
11986 error (_("Offset from DW_FORM_str_index pointing outside of"
11987 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
11988 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11989 return (char *) (sections
->str
.buffer
+ str_offset
);
11992 /* Return a pointer to just past the end of an LEB128 number in BUF. */
11995 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
12001 byte
= bfd_get_8 (abfd
, buf
);
12003 if ((byte
& 128) == 0)
12008 /* Return the length of an LEB128 number in BUF. */
12011 leb128_size (const gdb_byte
*buf
)
12013 const gdb_byte
*begin
= buf
;
12019 if ((byte
& 128) == 0)
12020 return buf
- begin
;
12025 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12032 cu
->language
= language_c
;
12034 case DW_LANG_C_plus_plus
:
12035 cu
->language
= language_cplus
;
12038 cu
->language
= language_d
;
12040 case DW_LANG_Fortran77
:
12041 case DW_LANG_Fortran90
:
12042 case DW_LANG_Fortran95
:
12043 cu
->language
= language_fortran
;
12046 cu
->language
= language_go
;
12048 case DW_LANG_Mips_Assembler
:
12049 cu
->language
= language_asm
;
12052 cu
->language
= language_java
;
12054 case DW_LANG_Ada83
:
12055 case DW_LANG_Ada95
:
12056 cu
->language
= language_ada
;
12058 case DW_LANG_Modula2
:
12059 cu
->language
= language_m2
;
12061 case DW_LANG_Pascal83
:
12062 cu
->language
= language_pascal
;
12065 cu
->language
= language_objc
;
12067 case DW_LANG_Cobol74
:
12068 case DW_LANG_Cobol85
:
12070 cu
->language
= language_minimal
;
12073 cu
->language_defn
= language_def (cu
->language
);
12076 /* Return the named attribute or NULL if not there. */
12078 static struct attribute
*
12079 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12084 struct attribute
*spec
= NULL
;
12086 for (i
= 0; i
< die
->num_attrs
; ++i
)
12088 if (die
->attrs
[i
].name
== name
)
12089 return &die
->attrs
[i
];
12090 if (die
->attrs
[i
].name
== DW_AT_specification
12091 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12092 spec
= &die
->attrs
[i
];
12098 die
= follow_die_ref (die
, spec
, &cu
);
12104 /* Return the named attribute or NULL if not there,
12105 but do not follow DW_AT_specification, etc.
12106 This is for use in contexts where we're reading .debug_types dies.
12107 Following DW_AT_specification, DW_AT_abstract_origin will take us
12108 back up the chain, and we want to go down. */
12110 static struct attribute
*
12111 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12112 struct dwarf2_cu
*cu
)
12116 for (i
= 0; i
< die
->num_attrs
; ++i
)
12117 if (die
->attrs
[i
].name
== name
)
12118 return &die
->attrs
[i
];
12123 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12124 and holds a non-zero value. This function should only be used for
12125 DW_FORM_flag or DW_FORM_flag_present attributes. */
12128 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12130 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12132 return (attr
&& DW_UNSND (attr
));
12136 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12138 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12139 which value is non-zero. However, we have to be careful with
12140 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12141 (via dwarf2_flag_true_p) follows this attribute. So we may
12142 end up accidently finding a declaration attribute that belongs
12143 to a different DIE referenced by the specification attribute,
12144 even though the given DIE does not have a declaration attribute. */
12145 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12146 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12149 /* Return the die giving the specification for DIE, if there is
12150 one. *SPEC_CU is the CU containing DIE on input, and the CU
12151 containing the return value on output. If there is no
12152 specification, but there is an abstract origin, that is
12155 static struct die_info
*
12156 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12158 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12161 if (spec_attr
== NULL
)
12162 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12164 if (spec_attr
== NULL
)
12167 return follow_die_ref (die
, spec_attr
, spec_cu
);
12170 /* Free the line_header structure *LH, and any arrays and strings it
12172 NOTE: This is also used as a "cleanup" function. */
12175 free_line_header (struct line_header
*lh
)
12177 if (lh
->standard_opcode_lengths
)
12178 xfree (lh
->standard_opcode_lengths
);
12180 /* Remember that all the lh->file_names[i].name pointers are
12181 pointers into debug_line_buffer, and don't need to be freed. */
12182 if (lh
->file_names
)
12183 xfree (lh
->file_names
);
12185 /* Similarly for the include directory names. */
12186 if (lh
->include_dirs
)
12187 xfree (lh
->include_dirs
);
12192 /* Add an entry to LH's include directory table. */
12195 add_include_dir (struct line_header
*lh
, char *include_dir
)
12197 /* Grow the array if necessary. */
12198 if (lh
->include_dirs_size
== 0)
12200 lh
->include_dirs_size
= 1; /* for testing */
12201 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12202 * sizeof (*lh
->include_dirs
));
12204 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12206 lh
->include_dirs_size
*= 2;
12207 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12208 (lh
->include_dirs_size
12209 * sizeof (*lh
->include_dirs
)));
12212 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12215 /* Add an entry to LH's file name table. */
12218 add_file_name (struct line_header
*lh
,
12220 unsigned int dir_index
,
12221 unsigned int mod_time
,
12222 unsigned int length
)
12224 struct file_entry
*fe
;
12226 /* Grow the array if necessary. */
12227 if (lh
->file_names_size
== 0)
12229 lh
->file_names_size
= 1; /* for testing */
12230 lh
->file_names
= xmalloc (lh
->file_names_size
12231 * sizeof (*lh
->file_names
));
12233 else if (lh
->num_file_names
>= lh
->file_names_size
)
12235 lh
->file_names_size
*= 2;
12236 lh
->file_names
= xrealloc (lh
->file_names
,
12237 (lh
->file_names_size
12238 * sizeof (*lh
->file_names
)));
12241 fe
= &lh
->file_names
[lh
->num_file_names
++];
12243 fe
->dir_index
= dir_index
;
12244 fe
->mod_time
= mod_time
;
12245 fe
->length
= length
;
12246 fe
->included_p
= 0;
12250 /* Read the statement program header starting at OFFSET in
12251 .debug_line, or .debug_line.dwo. Return a pointer
12252 to a struct line_header, allocated using xmalloc.
12254 NOTE: the strings in the include directory and file name tables of
12255 the returned object point into the dwarf line section buffer,
12256 and must not be freed. */
12258 static struct line_header
*
12259 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12261 struct cleanup
*back_to
;
12262 struct line_header
*lh
;
12263 gdb_byte
*line_ptr
;
12264 unsigned int bytes_read
, offset_size
;
12266 char *cur_dir
, *cur_file
;
12267 struct dwarf2_section_info
*section
;
12270 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12272 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12273 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12275 section
= &dwarf2_per_objfile
->line
;
12277 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12278 if (section
->buffer
== NULL
)
12280 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12281 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12283 complaint (&symfile_complaints
, _("missing .debug_line section"));
12287 /* We can't do this until we know the section is non-empty.
12288 Only then do we know we have such a section. */
12289 abfd
= section
->asection
->owner
;
12291 /* Make sure that at least there's room for the total_length field.
12292 That could be 12 bytes long, but we're just going to fudge that. */
12293 if (offset
+ 4 >= section
->size
)
12295 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12299 lh
= xmalloc (sizeof (*lh
));
12300 memset (lh
, 0, sizeof (*lh
));
12301 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12304 line_ptr
= section
->buffer
+ offset
;
12306 /* Read in the header. */
12308 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12309 &bytes_read
, &offset_size
);
12310 line_ptr
+= bytes_read
;
12311 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12313 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12316 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12317 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12319 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12320 line_ptr
+= offset_size
;
12321 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12323 if (lh
->version
>= 4)
12325 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12329 lh
->maximum_ops_per_instruction
= 1;
12331 if (lh
->maximum_ops_per_instruction
== 0)
12333 lh
->maximum_ops_per_instruction
= 1;
12334 complaint (&symfile_complaints
,
12335 _("invalid maximum_ops_per_instruction "
12336 "in `.debug_line' section"));
12339 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12341 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12343 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12345 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12347 lh
->standard_opcode_lengths
12348 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12350 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12351 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12353 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12357 /* Read directory table. */
12358 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12360 line_ptr
+= bytes_read
;
12361 add_include_dir (lh
, cur_dir
);
12363 line_ptr
+= bytes_read
;
12365 /* Read file name table. */
12366 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12368 unsigned int dir_index
, mod_time
, length
;
12370 line_ptr
+= bytes_read
;
12371 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12372 line_ptr
+= bytes_read
;
12373 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12374 line_ptr
+= bytes_read
;
12375 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12376 line_ptr
+= bytes_read
;
12378 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12380 line_ptr
+= bytes_read
;
12381 lh
->statement_program_start
= line_ptr
;
12383 if (line_ptr
> (section
->buffer
+ section
->size
))
12384 complaint (&symfile_complaints
,
12385 _("line number info header doesn't "
12386 "fit in `.debug_line' section"));
12388 discard_cleanups (back_to
);
12392 /* Subroutine of dwarf_decode_lines to simplify it.
12393 Return the file name of the psymtab for included file FILE_INDEX
12394 in line header LH of PST.
12395 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12396 If space for the result is malloc'd, it will be freed by a cleanup.
12397 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12400 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12401 const struct partial_symtab
*pst
,
12402 const char *comp_dir
)
12404 const struct file_entry fe
= lh
->file_names
[file_index
];
12405 char *include_name
= fe
.name
;
12406 char *include_name_to_compare
= include_name
;
12407 char *dir_name
= NULL
;
12408 const char *pst_filename
;
12409 char *copied_name
= NULL
;
12413 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12415 if (!IS_ABSOLUTE_PATH (include_name
)
12416 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12418 /* Avoid creating a duplicate psymtab for PST.
12419 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12420 Before we do the comparison, however, we need to account
12421 for DIR_NAME and COMP_DIR.
12422 First prepend dir_name (if non-NULL). If we still don't
12423 have an absolute path prepend comp_dir (if non-NULL).
12424 However, the directory we record in the include-file's
12425 psymtab does not contain COMP_DIR (to match the
12426 corresponding symtab(s)).
12431 bash$ gcc -g ./hello.c
12432 include_name = "hello.c"
12434 DW_AT_comp_dir = comp_dir = "/tmp"
12435 DW_AT_name = "./hello.c" */
12437 if (dir_name
!= NULL
)
12439 include_name
= concat (dir_name
, SLASH_STRING
,
12440 include_name
, (char *)NULL
);
12441 include_name_to_compare
= include_name
;
12442 make_cleanup (xfree
, include_name
);
12444 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12446 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12447 include_name
, (char *)NULL
);
12451 pst_filename
= pst
->filename
;
12452 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12454 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12455 pst_filename
, (char *)NULL
);
12456 pst_filename
= copied_name
;
12459 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12461 if (include_name_to_compare
!= include_name
)
12462 xfree (include_name_to_compare
);
12463 if (copied_name
!= NULL
)
12464 xfree (copied_name
);
12468 return include_name
;
12471 /* Ignore this record_line request. */
12474 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12479 /* Subroutine of dwarf_decode_lines to simplify it.
12480 Process the line number information in LH. */
12483 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12484 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12486 gdb_byte
*line_ptr
, *extended_end
;
12487 gdb_byte
*line_end
;
12488 unsigned int bytes_read
, extended_len
;
12489 unsigned char op_code
, extended_op
, adj_opcode
;
12490 CORE_ADDR baseaddr
;
12491 struct objfile
*objfile
= cu
->objfile
;
12492 bfd
*abfd
= objfile
->obfd
;
12493 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12494 const int decode_for_pst_p
= (pst
!= NULL
);
12495 struct subfile
*last_subfile
= NULL
;
12496 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12499 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12501 line_ptr
= lh
->statement_program_start
;
12502 line_end
= lh
->statement_program_end
;
12504 /* Read the statement sequences until there's nothing left. */
12505 while (line_ptr
< line_end
)
12507 /* state machine registers */
12508 CORE_ADDR address
= 0;
12509 unsigned int file
= 1;
12510 unsigned int line
= 1;
12511 unsigned int column
= 0;
12512 int is_stmt
= lh
->default_is_stmt
;
12513 int basic_block
= 0;
12514 int end_sequence
= 0;
12516 unsigned char op_index
= 0;
12518 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12520 /* Start a subfile for the current file of the state machine. */
12521 /* lh->include_dirs and lh->file_names are 0-based, but the
12522 directory and file name numbers in the statement program
12524 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12528 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12530 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12533 /* Decode the table. */
12534 while (!end_sequence
)
12536 op_code
= read_1_byte (abfd
, line_ptr
);
12538 if (line_ptr
> line_end
)
12540 dwarf2_debug_line_missing_end_sequence_complaint ();
12544 if (op_code
>= lh
->opcode_base
)
12546 /* Special operand. */
12547 adj_opcode
= op_code
- lh
->opcode_base
;
12548 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
12549 / lh
->maximum_ops_per_instruction
)
12550 * lh
->minimum_instruction_length
);
12551 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
12552 % lh
->maximum_ops_per_instruction
);
12553 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
12554 if (lh
->num_file_names
< file
|| file
== 0)
12555 dwarf2_debug_line_missing_file_complaint ();
12556 /* For now we ignore lines not starting on an
12557 instruction boundary. */
12558 else if (op_index
== 0)
12560 lh
->file_names
[file
- 1].included_p
= 1;
12561 if (!decode_for_pst_p
&& is_stmt
)
12563 if (last_subfile
!= current_subfile
)
12565 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12567 (*p_record_line
) (last_subfile
, 0, addr
);
12568 last_subfile
= current_subfile
;
12570 /* Append row to matrix using current values. */
12571 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12572 (*p_record_line
) (current_subfile
, line
, addr
);
12577 else switch (op_code
)
12579 case DW_LNS_extended_op
:
12580 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
12582 line_ptr
+= bytes_read
;
12583 extended_end
= line_ptr
+ extended_len
;
12584 extended_op
= read_1_byte (abfd
, line_ptr
);
12586 switch (extended_op
)
12588 case DW_LNE_end_sequence
:
12589 p_record_line
= record_line
;
12592 case DW_LNE_set_address
:
12593 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
12595 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12597 /* This line table is for a function which has been
12598 GCd by the linker. Ignore it. PR gdb/12528 */
12601 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
12603 complaint (&symfile_complaints
,
12604 _(".debug_line address at offset 0x%lx is 0 "
12606 line_offset
, objfile
->name
);
12607 p_record_line
= noop_record_line
;
12611 line_ptr
+= bytes_read
;
12612 address
+= baseaddr
;
12614 case DW_LNE_define_file
:
12617 unsigned int dir_index
, mod_time
, length
;
12619 cur_file
= read_direct_string (abfd
, line_ptr
,
12621 line_ptr
+= bytes_read
;
12623 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12624 line_ptr
+= bytes_read
;
12626 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12627 line_ptr
+= bytes_read
;
12629 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12630 line_ptr
+= bytes_read
;
12631 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12634 case DW_LNE_set_discriminator
:
12635 /* The discriminator is not interesting to the debugger;
12637 line_ptr
= extended_end
;
12640 complaint (&symfile_complaints
,
12641 _("mangled .debug_line section"));
12644 /* Make sure that we parsed the extended op correctly. If e.g.
12645 we expected a different address size than the producer used,
12646 we may have read the wrong number of bytes. */
12647 if (line_ptr
!= extended_end
)
12649 complaint (&symfile_complaints
,
12650 _("mangled .debug_line section"));
12655 if (lh
->num_file_names
< file
|| file
== 0)
12656 dwarf2_debug_line_missing_file_complaint ();
12659 lh
->file_names
[file
- 1].included_p
= 1;
12660 if (!decode_for_pst_p
&& is_stmt
)
12662 if (last_subfile
!= current_subfile
)
12664 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12666 (*p_record_line
) (last_subfile
, 0, addr
);
12667 last_subfile
= current_subfile
;
12669 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12670 (*p_record_line
) (current_subfile
, line
, addr
);
12675 case DW_LNS_advance_pc
:
12678 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12680 address
+= (((op_index
+ adjust
)
12681 / lh
->maximum_ops_per_instruction
)
12682 * lh
->minimum_instruction_length
);
12683 op_index
= ((op_index
+ adjust
)
12684 % lh
->maximum_ops_per_instruction
);
12685 line_ptr
+= bytes_read
;
12688 case DW_LNS_advance_line
:
12689 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
12690 line_ptr
+= bytes_read
;
12692 case DW_LNS_set_file
:
12694 /* The arrays lh->include_dirs and lh->file_names are
12695 0-based, but the directory and file name numbers in
12696 the statement program are 1-based. */
12697 struct file_entry
*fe
;
12700 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12701 line_ptr
+= bytes_read
;
12702 if (lh
->num_file_names
< file
|| file
== 0)
12703 dwarf2_debug_line_missing_file_complaint ();
12706 fe
= &lh
->file_names
[file
- 1];
12708 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12709 if (!decode_for_pst_p
)
12711 last_subfile
= current_subfile
;
12712 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12717 case DW_LNS_set_column
:
12718 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12719 line_ptr
+= bytes_read
;
12721 case DW_LNS_negate_stmt
:
12722 is_stmt
= (!is_stmt
);
12724 case DW_LNS_set_basic_block
:
12727 /* Add to the address register of the state machine the
12728 address increment value corresponding to special opcode
12729 255. I.e., this value is scaled by the minimum
12730 instruction length since special opcode 255 would have
12731 scaled the increment. */
12732 case DW_LNS_const_add_pc
:
12734 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
12736 address
+= (((op_index
+ adjust
)
12737 / lh
->maximum_ops_per_instruction
)
12738 * lh
->minimum_instruction_length
);
12739 op_index
= ((op_index
+ adjust
)
12740 % lh
->maximum_ops_per_instruction
);
12743 case DW_LNS_fixed_advance_pc
:
12744 address
+= read_2_bytes (abfd
, line_ptr
);
12750 /* Unknown standard opcode, ignore it. */
12753 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
12755 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12756 line_ptr
+= bytes_read
;
12761 if (lh
->num_file_names
< file
|| file
== 0)
12762 dwarf2_debug_line_missing_file_complaint ();
12765 lh
->file_names
[file
- 1].included_p
= 1;
12766 if (!decode_for_pst_p
)
12768 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12769 (*p_record_line
) (current_subfile
, 0, addr
);
12775 /* Decode the Line Number Program (LNP) for the given line_header
12776 structure and CU. The actual information extracted and the type
12777 of structures created from the LNP depends on the value of PST.
12779 1. If PST is NULL, then this procedure uses the data from the program
12780 to create all necessary symbol tables, and their linetables.
12782 2. If PST is not NULL, this procedure reads the program to determine
12783 the list of files included by the unit represented by PST, and
12784 builds all the associated partial symbol tables.
12786 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12787 It is used for relative paths in the line table.
12788 NOTE: When processing partial symtabs (pst != NULL),
12789 comp_dir == pst->dirname.
12791 NOTE: It is important that psymtabs have the same file name (via strcmp)
12792 as the corresponding symtab. Since COMP_DIR is not used in the name of the
12793 symtab we don't use it in the name of the psymtabs we create.
12794 E.g. expand_line_sal requires this when finding psymtabs to expand.
12795 A good testcase for this is mb-inline.exp. */
12798 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
12799 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
12800 int want_line_info
)
12802 struct objfile
*objfile
= cu
->objfile
;
12803 const int decode_for_pst_p
= (pst
!= NULL
);
12804 struct subfile
*first_subfile
= current_subfile
;
12806 if (want_line_info
)
12807 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
12809 if (decode_for_pst_p
)
12813 /* Now that we're done scanning the Line Header Program, we can
12814 create the psymtab of each included file. */
12815 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
12816 if (lh
->file_names
[file_index
].included_p
== 1)
12818 char *include_name
=
12819 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
12820 if (include_name
!= NULL
)
12821 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
12826 /* Make sure a symtab is created for every file, even files
12827 which contain only variables (i.e. no code with associated
12831 for (i
= 0; i
< lh
->num_file_names
; i
++)
12834 struct file_entry
*fe
;
12836 fe
= &lh
->file_names
[i
];
12838 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12839 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12841 /* Skip the main file; we don't need it, and it must be
12842 allocated last, so that it will show up before the
12843 non-primary symtabs in the objfile's symtab list. */
12844 if (current_subfile
== first_subfile
)
12847 if (current_subfile
->symtab
== NULL
)
12848 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
12850 fe
->symtab
= current_subfile
->symtab
;
12855 /* Start a subfile for DWARF. FILENAME is the name of the file and
12856 DIRNAME the name of the source directory which contains FILENAME
12857 or NULL if not known. COMP_DIR is the compilation directory for the
12858 linetable's compilation unit or NULL if not known.
12859 This routine tries to keep line numbers from identical absolute and
12860 relative file names in a common subfile.
12862 Using the `list' example from the GDB testsuite, which resides in
12863 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
12864 of /srcdir/list0.c yields the following debugging information for list0.c:
12866 DW_AT_name: /srcdir/list0.c
12867 DW_AT_comp_dir: /compdir
12868 files.files[0].name: list0.h
12869 files.files[0].dir: /srcdir
12870 files.files[1].name: list0.c
12871 files.files[1].dir: /srcdir
12873 The line number information for list0.c has to end up in a single
12874 subfile, so that `break /srcdir/list0.c:1' works as expected.
12875 start_subfile will ensure that this happens provided that we pass the
12876 concatenation of files.files[1].dir and files.files[1].name as the
12880 dwarf2_start_subfile (char *filename
, const char *dirname
,
12881 const char *comp_dir
)
12885 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
12886 `start_symtab' will always pass the contents of DW_AT_comp_dir as
12887 second argument to start_subfile. To be consistent, we do the
12888 same here. In order not to lose the line information directory,
12889 we concatenate it to the filename when it makes sense.
12890 Note that the Dwarf3 standard says (speaking of filenames in line
12891 information): ``The directory index is ignored for file names
12892 that represent full path names''. Thus ignoring dirname in the
12893 `else' branch below isn't an issue. */
12895 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
12896 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
12898 fullname
= filename
;
12900 start_subfile (fullname
, comp_dir
);
12902 if (fullname
!= filename
)
12907 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
12908 struct dwarf2_cu
*cu
)
12910 struct objfile
*objfile
= cu
->objfile
;
12911 struct comp_unit_head
*cu_header
= &cu
->header
;
12913 /* NOTE drow/2003-01-30: There used to be a comment and some special
12914 code here to turn a symbol with DW_AT_external and a
12915 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
12916 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
12917 with some versions of binutils) where shared libraries could have
12918 relocations against symbols in their debug information - the
12919 minimal symbol would have the right address, but the debug info
12920 would not. It's no longer necessary, because we will explicitly
12921 apply relocations when we read in the debug information now. */
12923 /* A DW_AT_location attribute with no contents indicates that a
12924 variable has been optimized away. */
12925 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
12927 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
12931 /* Handle one degenerate form of location expression specially, to
12932 preserve GDB's previous behavior when section offsets are
12933 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
12934 then mark this symbol as LOC_STATIC. */
12936 if (attr_form_is_block (attr
)
12937 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
12938 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
12939 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
12940 && (DW_BLOCK (attr
)->size
12941 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
12943 unsigned int dummy
;
12945 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
12946 SYMBOL_VALUE_ADDRESS (sym
) =
12947 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
12949 SYMBOL_VALUE_ADDRESS (sym
) =
12950 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
12951 SYMBOL_CLASS (sym
) = LOC_STATIC
;
12952 fixup_symbol_section (sym
, objfile
);
12953 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
12954 SYMBOL_SECTION (sym
));
12958 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
12959 expression evaluator, and use LOC_COMPUTED only when necessary
12960 (i.e. when the value of a register or memory location is
12961 referenced, or a thread-local block, etc.). Then again, it might
12962 not be worthwhile. I'm assuming that it isn't unless performance
12963 or memory numbers show me otherwise. */
12965 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
12966 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12968 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
12969 cu
->has_loclist
= 1;
12972 /* Given a pointer to a DWARF information entry, figure out if we need
12973 to make a symbol table entry for it, and if so, create a new entry
12974 and return a pointer to it.
12975 If TYPE is NULL, determine symbol type from the die, otherwise
12976 used the passed type.
12977 If SPACE is not NULL, use it to hold the new symbol. If it is
12978 NULL, allocate a new symbol on the objfile's obstack. */
12980 static struct symbol
*
12981 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
12982 struct symbol
*space
)
12984 struct objfile
*objfile
= cu
->objfile
;
12985 struct symbol
*sym
= NULL
;
12987 struct attribute
*attr
= NULL
;
12988 struct attribute
*attr2
= NULL
;
12989 CORE_ADDR baseaddr
;
12990 struct pending
**list_to_add
= NULL
;
12992 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12994 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12996 name
= dwarf2_name (die
, cu
);
12999 const char *linkagename
;
13000 int suppress_add
= 0;
13005 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13006 OBJSTAT (objfile
, n_syms
++);
13008 /* Cache this symbol's name and the name's demangled form (if any). */
13009 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13010 linkagename
= dwarf2_physname (name
, die
, cu
);
13011 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13013 /* Fortran does not have mangling standard and the mangling does differ
13014 between gfortran, iFort etc. */
13015 if (cu
->language
== language_fortran
13016 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13017 symbol_set_demangled_name (&(sym
->ginfo
),
13018 (char *) dwarf2_full_name (name
, die
, cu
),
13021 /* Default assumptions.
13022 Use the passed type or decode it from the die. */
13023 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13024 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13026 SYMBOL_TYPE (sym
) = type
;
13028 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13029 attr
= dwarf2_attr (die
,
13030 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13034 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13037 attr
= dwarf2_attr (die
,
13038 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13042 int file_index
= DW_UNSND (attr
);
13044 if (cu
->line_header
== NULL
13045 || file_index
> cu
->line_header
->num_file_names
)
13046 complaint (&symfile_complaints
,
13047 _("file index out of range"));
13048 else if (file_index
> 0)
13050 struct file_entry
*fe
;
13052 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13053 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13060 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13063 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13065 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13066 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13067 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13068 add_symbol_to_list (sym
, cu
->list_in_scope
);
13070 case DW_TAG_subprogram
:
13071 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13073 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13074 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13075 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13076 || cu
->language
== language_ada
)
13078 /* Subprograms marked external are stored as a global symbol.
13079 Ada subprograms, whether marked external or not, are always
13080 stored as a global symbol, because we want to be able to
13081 access them globally. For instance, we want to be able
13082 to break on a nested subprogram without having to
13083 specify the context. */
13084 list_to_add
= &global_symbols
;
13088 list_to_add
= cu
->list_in_scope
;
13091 case DW_TAG_inlined_subroutine
:
13092 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13094 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13095 SYMBOL_INLINED (sym
) = 1;
13096 list_to_add
= cu
->list_in_scope
;
13098 case DW_TAG_template_value_param
:
13100 /* Fall through. */
13101 case DW_TAG_constant
:
13102 case DW_TAG_variable
:
13103 case DW_TAG_member
:
13104 /* Compilation with minimal debug info may result in
13105 variables with missing type entries. Change the
13106 misleading `void' type to something sensible. */
13107 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13109 = objfile_type (objfile
)->nodebug_data_symbol
;
13111 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13112 /* In the case of DW_TAG_member, we should only be called for
13113 static const members. */
13114 if (die
->tag
== DW_TAG_member
)
13116 /* dwarf2_add_field uses die_is_declaration,
13117 so we do the same. */
13118 gdb_assert (die_is_declaration (die
, cu
));
13123 dwarf2_const_value (attr
, sym
, cu
);
13124 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13127 if (attr2
&& (DW_UNSND (attr2
) != 0))
13128 list_to_add
= &global_symbols
;
13130 list_to_add
= cu
->list_in_scope
;
13134 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13137 var_decode_location (attr
, sym
, cu
);
13138 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13139 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13140 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13141 && !dwarf2_per_objfile
->has_section_at_zero
)
13143 /* When a static variable is eliminated by the linker,
13144 the corresponding debug information is not stripped
13145 out, but the variable address is set to null;
13146 do not add such variables into symbol table. */
13148 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13150 /* Workaround gfortran PR debug/40040 - it uses
13151 DW_AT_location for variables in -fPIC libraries which may
13152 get overriden by other libraries/executable and get
13153 a different address. Resolve it by the minimal symbol
13154 which may come from inferior's executable using copy
13155 relocation. Make this workaround only for gfortran as for
13156 other compilers GDB cannot guess the minimal symbol
13157 Fortran mangling kind. */
13158 if (cu
->language
== language_fortran
&& die
->parent
13159 && die
->parent
->tag
== DW_TAG_module
13161 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13162 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13164 /* A variable with DW_AT_external is never static,
13165 but it may be block-scoped. */
13166 list_to_add
= (cu
->list_in_scope
== &file_symbols
13167 ? &global_symbols
: cu
->list_in_scope
);
13170 list_to_add
= cu
->list_in_scope
;
13174 /* We do not know the address of this symbol.
13175 If it is an external symbol and we have type information
13176 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13177 The address of the variable will then be determined from
13178 the minimal symbol table whenever the variable is
13180 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13181 if (attr2
&& (DW_UNSND (attr2
) != 0)
13182 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13184 /* A variable with DW_AT_external is never static, but it
13185 may be block-scoped. */
13186 list_to_add
= (cu
->list_in_scope
== &file_symbols
13187 ? &global_symbols
: cu
->list_in_scope
);
13189 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13191 else if (!die_is_declaration (die
, cu
))
13193 /* Use the default LOC_OPTIMIZED_OUT class. */
13194 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13196 list_to_add
= cu
->list_in_scope
;
13200 case DW_TAG_formal_parameter
:
13201 /* If we are inside a function, mark this as an argument. If
13202 not, we might be looking at an argument to an inlined function
13203 when we do not have enough information to show inlined frames;
13204 pretend it's a local variable in that case so that the user can
13206 if (context_stack_depth
> 0
13207 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13208 SYMBOL_IS_ARGUMENT (sym
) = 1;
13209 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13212 var_decode_location (attr
, sym
, cu
);
13214 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13217 dwarf2_const_value (attr
, sym
, cu
);
13220 list_to_add
= cu
->list_in_scope
;
13222 case DW_TAG_unspecified_parameters
:
13223 /* From varargs functions; gdb doesn't seem to have any
13224 interest in this information, so just ignore it for now.
13227 case DW_TAG_template_type_param
:
13229 /* Fall through. */
13230 case DW_TAG_class_type
:
13231 case DW_TAG_interface_type
:
13232 case DW_TAG_structure_type
:
13233 case DW_TAG_union_type
:
13234 case DW_TAG_set_type
:
13235 case DW_TAG_enumeration_type
:
13236 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13237 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13240 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13241 really ever be static objects: otherwise, if you try
13242 to, say, break of a class's method and you're in a file
13243 which doesn't mention that class, it won't work unless
13244 the check for all static symbols in lookup_symbol_aux
13245 saves you. See the OtherFileClass tests in
13246 gdb.c++/namespace.exp. */
13250 list_to_add
= (cu
->list_in_scope
== &file_symbols
13251 && (cu
->language
== language_cplus
13252 || cu
->language
== language_java
)
13253 ? &global_symbols
: cu
->list_in_scope
);
13255 /* The semantics of C++ state that "struct foo {
13256 ... }" also defines a typedef for "foo". A Java
13257 class declaration also defines a typedef for the
13259 if (cu
->language
== language_cplus
13260 || cu
->language
== language_java
13261 || cu
->language
== language_ada
)
13263 /* The symbol's name is already allocated along
13264 with this objfile, so we don't need to
13265 duplicate it for the type. */
13266 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13267 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13272 case DW_TAG_typedef
:
13273 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13274 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13275 list_to_add
= cu
->list_in_scope
;
13277 case DW_TAG_base_type
:
13278 case DW_TAG_subrange_type
:
13279 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13280 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13281 list_to_add
= cu
->list_in_scope
;
13283 case DW_TAG_enumerator
:
13284 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13287 dwarf2_const_value (attr
, sym
, cu
);
13290 /* NOTE: carlton/2003-11-10: See comment above in the
13291 DW_TAG_class_type, etc. block. */
13293 list_to_add
= (cu
->list_in_scope
== &file_symbols
13294 && (cu
->language
== language_cplus
13295 || cu
->language
== language_java
)
13296 ? &global_symbols
: cu
->list_in_scope
);
13299 case DW_TAG_namespace
:
13300 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13301 list_to_add
= &global_symbols
;
13304 /* Not a tag we recognize. Hopefully we aren't processing
13305 trash data, but since we must specifically ignore things
13306 we don't recognize, there is nothing else we should do at
13308 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13309 dwarf_tag_name (die
->tag
));
13315 sym
->hash_next
= objfile
->template_symbols
;
13316 objfile
->template_symbols
= sym
;
13317 list_to_add
= NULL
;
13320 if (list_to_add
!= NULL
)
13321 add_symbol_to_list (sym
, list_to_add
);
13323 /* For the benefit of old versions of GCC, check for anonymous
13324 namespaces based on the demangled name. */
13325 if (!processing_has_namespace_info
13326 && cu
->language
== language_cplus
)
13327 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13332 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13334 static struct symbol
*
13335 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13337 return new_symbol_full (die
, type
, cu
, NULL
);
13340 /* Given an attr with a DW_FORM_dataN value in host byte order,
13341 zero-extend it as appropriate for the symbol's type. The DWARF
13342 standard (v4) is not entirely clear about the meaning of using
13343 DW_FORM_dataN for a constant with a signed type, where the type is
13344 wider than the data. The conclusion of a discussion on the DWARF
13345 list was that this is unspecified. We choose to always zero-extend
13346 because that is the interpretation long in use by GCC. */
13349 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13350 const char *name
, struct obstack
*obstack
,
13351 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13353 struct objfile
*objfile
= cu
->objfile
;
13354 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13355 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13356 LONGEST l
= DW_UNSND (attr
);
13358 if (bits
< sizeof (*value
) * 8)
13360 l
&= ((LONGEST
) 1 << bits
) - 1;
13363 else if (bits
== sizeof (*value
) * 8)
13367 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13368 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13375 /* Read a constant value from an attribute. Either set *VALUE, or if
13376 the value does not fit in *VALUE, set *BYTES - either already
13377 allocated on the objfile obstack, or newly allocated on OBSTACK,
13378 or, set *BATON, if we translated the constant to a location
13382 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13383 const char *name
, struct obstack
*obstack
,
13384 struct dwarf2_cu
*cu
,
13385 LONGEST
*value
, gdb_byte
**bytes
,
13386 struct dwarf2_locexpr_baton
**baton
)
13388 struct objfile
*objfile
= cu
->objfile
;
13389 struct comp_unit_head
*cu_header
= &cu
->header
;
13390 struct dwarf_block
*blk
;
13391 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13392 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13398 switch (attr
->form
)
13401 case DW_FORM_GNU_addr_index
:
13405 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13406 dwarf2_const_value_length_mismatch_complaint (name
,
13407 cu_header
->addr_size
,
13408 TYPE_LENGTH (type
));
13409 /* Symbols of this form are reasonably rare, so we just
13410 piggyback on the existing location code rather than writing
13411 a new implementation of symbol_computed_ops. */
13412 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13413 sizeof (struct dwarf2_locexpr_baton
));
13414 (*baton
)->per_cu
= cu
->per_cu
;
13415 gdb_assert ((*baton
)->per_cu
);
13417 (*baton
)->size
= 2 + cu_header
->addr_size
;
13418 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13419 (*baton
)->data
= data
;
13421 data
[0] = DW_OP_addr
;
13422 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13423 byte_order
, DW_ADDR (attr
));
13424 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13427 case DW_FORM_string
:
13429 case DW_FORM_GNU_str_index
:
13430 /* DW_STRING is already allocated on the objfile obstack, point
13432 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13434 case DW_FORM_block1
:
13435 case DW_FORM_block2
:
13436 case DW_FORM_block4
:
13437 case DW_FORM_block
:
13438 case DW_FORM_exprloc
:
13439 blk
= DW_BLOCK (attr
);
13440 if (TYPE_LENGTH (type
) != blk
->size
)
13441 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13442 TYPE_LENGTH (type
));
13443 *bytes
= blk
->data
;
13446 /* The DW_AT_const_value attributes are supposed to carry the
13447 symbol's value "represented as it would be on the target
13448 architecture." By the time we get here, it's already been
13449 converted to host endianness, so we just need to sign- or
13450 zero-extend it as appropriate. */
13451 case DW_FORM_data1
:
13452 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13453 obstack
, cu
, value
, 8);
13455 case DW_FORM_data2
:
13456 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13457 obstack
, cu
, value
, 16);
13459 case DW_FORM_data4
:
13460 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13461 obstack
, cu
, value
, 32);
13463 case DW_FORM_data8
:
13464 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13465 obstack
, cu
, value
, 64);
13468 case DW_FORM_sdata
:
13469 *value
= DW_SND (attr
);
13472 case DW_FORM_udata
:
13473 *value
= DW_UNSND (attr
);
13477 complaint (&symfile_complaints
,
13478 _("unsupported const value attribute form: '%s'"),
13479 dwarf_form_name (attr
->form
));
13486 /* Copy constant value from an attribute to a symbol. */
13489 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13490 struct dwarf2_cu
*cu
)
13492 struct objfile
*objfile
= cu
->objfile
;
13493 struct comp_unit_head
*cu_header
= &cu
->header
;
13496 struct dwarf2_locexpr_baton
*baton
;
13498 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13499 SYMBOL_PRINT_NAME (sym
),
13500 &objfile
->objfile_obstack
, cu
,
13501 &value
, &bytes
, &baton
);
13505 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13506 SYMBOL_LOCATION_BATON (sym
) = baton
;
13507 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13509 else if (bytes
!= NULL
)
13511 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13512 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13516 SYMBOL_VALUE (sym
) = value
;
13517 SYMBOL_CLASS (sym
) = LOC_CONST
;
13521 /* Return the type of the die in question using its DW_AT_type attribute. */
13523 static struct type
*
13524 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13526 struct attribute
*type_attr
;
13528 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13531 /* A missing DW_AT_type represents a void type. */
13532 return objfile_type (cu
->objfile
)->builtin_void
;
13535 return lookup_die_type (die
, type_attr
, cu
);
13538 /* True iff CU's producer generates GNAT Ada auxiliary information
13539 that allows to find parallel types through that information instead
13540 of having to do expensive parallel lookups by type name. */
13543 need_gnat_info (struct dwarf2_cu
*cu
)
13545 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
13546 of GNAT produces this auxiliary information, without any indication
13547 that it is produced. Part of enhancing the FSF version of GNAT
13548 to produce that information will be to put in place an indicator
13549 that we can use in order to determine whether the descriptive type
13550 info is available or not. One suggestion that has been made is
13551 to use a new attribute, attached to the CU die. For now, assume
13552 that the descriptive type info is not available. */
13556 /* Return the auxiliary type of the die in question using its
13557 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
13558 attribute is not present. */
13560 static struct type
*
13561 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13563 struct attribute
*type_attr
;
13565 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
13569 return lookup_die_type (die
, type_attr
, cu
);
13572 /* If DIE has a descriptive_type attribute, then set the TYPE's
13573 descriptive type accordingly. */
13576 set_descriptive_type (struct type
*type
, struct die_info
*die
,
13577 struct dwarf2_cu
*cu
)
13579 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
13581 if (descriptive_type
)
13583 ALLOCATE_GNAT_AUX_TYPE (type
);
13584 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
13588 /* Return the containing type of the die in question using its
13589 DW_AT_containing_type attribute. */
13591 static struct type
*
13592 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13594 struct attribute
*type_attr
;
13596 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
13598 error (_("Dwarf Error: Problem turning containing type into gdb type "
13599 "[in module %s]"), cu
->objfile
->name
);
13601 return lookup_die_type (die
, type_attr
, cu
);
13604 /* Look up the type of DIE in CU using its type attribute ATTR.
13605 If there is no type substitute an error marker. */
13607 static struct type
*
13608 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
13609 struct dwarf2_cu
*cu
)
13611 struct objfile
*objfile
= cu
->objfile
;
13612 struct type
*this_type
;
13614 /* First see if we have it cached. */
13616 if (is_ref_attr (attr
))
13618 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
13620 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
13622 else if (attr
->form
== DW_FORM_ref_sig8
)
13624 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13626 /* sig_type will be NULL if the signatured type is missing from
13628 if (sig_type
== NULL
)
13629 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13630 "at 0x%x [in module %s]"),
13631 die
->offset
.sect_off
, objfile
->name
);
13633 gdb_assert (sig_type
->per_cu
.is_debug_types
);
13634 /* If we haven't filled in type_offset_in_section yet, then we
13635 haven't read the type in yet. */
13637 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
13640 get_die_type_at_offset (sig_type
->type_offset_in_section
,
13641 &sig_type
->per_cu
);
13646 dump_die_for_error (die
);
13647 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
13648 dwarf_attr_name (attr
->name
), objfile
->name
);
13651 /* If not cached we need to read it in. */
13653 if (this_type
== NULL
)
13655 struct die_info
*type_die
;
13656 struct dwarf2_cu
*type_cu
= cu
;
13658 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
13659 /* If we found the type now, it's probably because the type came
13660 from an inter-CU reference and the type's CU got expanded before
13662 this_type
= get_die_type (type_die
, type_cu
);
13663 if (this_type
== NULL
)
13664 this_type
= read_type_die_1 (type_die
, type_cu
);
13667 /* If we still don't have a type use an error marker. */
13669 if (this_type
== NULL
)
13671 char *message
, *saved
;
13673 /* read_type_die already issued a complaint. */
13674 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
13676 cu
->header
.offset
.sect_off
,
13677 die
->offset
.sect_off
);
13678 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
13679 message
, strlen (message
));
13682 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
13688 /* Return the type in DIE, CU.
13689 Returns NULL for invalid types.
13691 This first does a lookup in the appropriate type_hash table,
13692 and only reads the die in if necessary.
13694 NOTE: This can be called when reading in partial or full symbols. */
13696 static struct type
*
13697 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
13699 struct type
*this_type
;
13701 this_type
= get_die_type (die
, cu
);
13705 return read_type_die_1 (die
, cu
);
13708 /* Read the type in DIE, CU.
13709 Returns NULL for invalid types. */
13711 static struct type
*
13712 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
13714 struct type
*this_type
= NULL
;
13718 case DW_TAG_class_type
:
13719 case DW_TAG_interface_type
:
13720 case DW_TAG_structure_type
:
13721 case DW_TAG_union_type
:
13722 this_type
= read_structure_type (die
, cu
);
13724 case DW_TAG_enumeration_type
:
13725 this_type
= read_enumeration_type (die
, cu
);
13727 case DW_TAG_subprogram
:
13728 case DW_TAG_subroutine_type
:
13729 case DW_TAG_inlined_subroutine
:
13730 this_type
= read_subroutine_type (die
, cu
);
13732 case DW_TAG_array_type
:
13733 this_type
= read_array_type (die
, cu
);
13735 case DW_TAG_set_type
:
13736 this_type
= read_set_type (die
, cu
);
13738 case DW_TAG_pointer_type
:
13739 this_type
= read_tag_pointer_type (die
, cu
);
13741 case DW_TAG_ptr_to_member_type
:
13742 this_type
= read_tag_ptr_to_member_type (die
, cu
);
13744 case DW_TAG_reference_type
:
13745 this_type
= read_tag_reference_type (die
, cu
);
13747 case DW_TAG_const_type
:
13748 this_type
= read_tag_const_type (die
, cu
);
13750 case DW_TAG_volatile_type
:
13751 this_type
= read_tag_volatile_type (die
, cu
);
13753 case DW_TAG_string_type
:
13754 this_type
= read_tag_string_type (die
, cu
);
13756 case DW_TAG_typedef
:
13757 this_type
= read_typedef (die
, cu
);
13759 case DW_TAG_subrange_type
:
13760 this_type
= read_subrange_type (die
, cu
);
13762 case DW_TAG_base_type
:
13763 this_type
= read_base_type (die
, cu
);
13765 case DW_TAG_unspecified_type
:
13766 this_type
= read_unspecified_type (die
, cu
);
13768 case DW_TAG_namespace
:
13769 this_type
= read_namespace_type (die
, cu
);
13771 case DW_TAG_module
:
13772 this_type
= read_module_type (die
, cu
);
13775 complaint (&symfile_complaints
,
13776 _("unexpected tag in read_type_die: '%s'"),
13777 dwarf_tag_name (die
->tag
));
13784 /* See if we can figure out if the class lives in a namespace. We do
13785 this by looking for a member function; its demangled name will
13786 contain namespace info, if there is any.
13787 Return the computed name or NULL.
13788 Space for the result is allocated on the objfile's obstack.
13789 This is the full-die version of guess_partial_die_structure_name.
13790 In this case we know DIE has no useful parent. */
13793 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
13795 struct die_info
*spec_die
;
13796 struct dwarf2_cu
*spec_cu
;
13797 struct die_info
*child
;
13800 spec_die
= die_specification (die
, &spec_cu
);
13801 if (spec_die
!= NULL
)
13807 for (child
= die
->child
;
13809 child
= child
->sibling
)
13811 if (child
->tag
== DW_TAG_subprogram
)
13813 struct attribute
*attr
;
13815 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
13817 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
13821 = language_class_name_from_physname (cu
->language_defn
,
13825 if (actual_name
!= NULL
)
13827 char *die_name
= dwarf2_name (die
, cu
);
13829 if (die_name
!= NULL
13830 && strcmp (die_name
, actual_name
) != 0)
13832 /* Strip off the class name from the full name.
13833 We want the prefix. */
13834 int die_name_len
= strlen (die_name
);
13835 int actual_name_len
= strlen (actual_name
);
13837 /* Test for '::' as a sanity check. */
13838 if (actual_name_len
> die_name_len
+ 2
13839 && actual_name
[actual_name_len
13840 - die_name_len
- 1] == ':')
13842 obsavestring (actual_name
,
13843 actual_name_len
- die_name_len
- 2,
13844 &cu
->objfile
->objfile_obstack
);
13847 xfree (actual_name
);
13856 /* GCC might emit a nameless typedef that has a linkage name. Determine the
13857 prefix part in such case. See
13858 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13861 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
13863 struct attribute
*attr
;
13866 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
13867 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
13870 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
13871 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
13874 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
13876 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
13877 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
13880 /* dwarf2_name had to be already called. */
13881 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
13883 /* Strip the base name, keep any leading namespaces/classes. */
13884 base
= strrchr (DW_STRING (attr
), ':');
13885 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
13888 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
13889 &cu
->objfile
->objfile_obstack
);
13892 /* Return the name of the namespace/class that DIE is defined within,
13893 or "" if we can't tell. The caller should not xfree the result.
13895 For example, if we're within the method foo() in the following
13905 then determine_prefix on foo's die will return "N::C". */
13907 static const char *
13908 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
13910 struct die_info
*parent
, *spec_die
;
13911 struct dwarf2_cu
*spec_cu
;
13912 struct type
*parent_type
;
13915 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
13916 && cu
->language
!= language_fortran
)
13919 retval
= anonymous_struct_prefix (die
, cu
);
13923 /* We have to be careful in the presence of DW_AT_specification.
13924 For example, with GCC 3.4, given the code
13928 // Definition of N::foo.
13932 then we'll have a tree of DIEs like this:
13934 1: DW_TAG_compile_unit
13935 2: DW_TAG_namespace // N
13936 3: DW_TAG_subprogram // declaration of N::foo
13937 4: DW_TAG_subprogram // definition of N::foo
13938 DW_AT_specification // refers to die #3
13940 Thus, when processing die #4, we have to pretend that we're in
13941 the context of its DW_AT_specification, namely the contex of die
13944 spec_die
= die_specification (die
, &spec_cu
);
13945 if (spec_die
== NULL
)
13946 parent
= die
->parent
;
13949 parent
= spec_die
->parent
;
13953 if (parent
== NULL
)
13955 else if (parent
->building_fullname
)
13958 const char *parent_name
;
13960 /* It has been seen on RealView 2.2 built binaries,
13961 DW_TAG_template_type_param types actually _defined_ as
13962 children of the parent class:
13965 template class <class Enum> Class{};
13966 Class<enum E> class_e;
13968 1: DW_TAG_class_type (Class)
13969 2: DW_TAG_enumeration_type (E)
13970 3: DW_TAG_enumerator (enum1:0)
13971 3: DW_TAG_enumerator (enum2:1)
13973 2: DW_TAG_template_type_param
13974 DW_AT_type DW_FORM_ref_udata (E)
13976 Besides being broken debug info, it can put GDB into an
13977 infinite loop. Consider:
13979 When we're building the full name for Class<E>, we'll start
13980 at Class, and go look over its template type parameters,
13981 finding E. We'll then try to build the full name of E, and
13982 reach here. We're now trying to build the full name of E,
13983 and look over the parent DIE for containing scope. In the
13984 broken case, if we followed the parent DIE of E, we'd again
13985 find Class, and once again go look at its template type
13986 arguments, etc., etc. Simply don't consider such parent die
13987 as source-level parent of this die (it can't be, the language
13988 doesn't allow it), and break the loop here. */
13989 name
= dwarf2_name (die
, cu
);
13990 parent_name
= dwarf2_name (parent
, cu
);
13991 complaint (&symfile_complaints
,
13992 _("template param type '%s' defined within parent '%s'"),
13993 name
? name
: "<unknown>",
13994 parent_name
? parent_name
: "<unknown>");
13998 switch (parent
->tag
)
14000 case DW_TAG_namespace
:
14001 parent_type
= read_type_die (parent
, cu
);
14002 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14003 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14004 Work around this problem here. */
14005 if (cu
->language
== language_cplus
14006 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14008 /* We give a name to even anonymous namespaces. */
14009 return TYPE_TAG_NAME (parent_type
);
14010 case DW_TAG_class_type
:
14011 case DW_TAG_interface_type
:
14012 case DW_TAG_structure_type
:
14013 case DW_TAG_union_type
:
14014 case DW_TAG_module
:
14015 parent_type
= read_type_die (parent
, cu
);
14016 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14017 return TYPE_TAG_NAME (parent_type
);
14019 /* An anonymous structure is only allowed non-static data
14020 members; no typedefs, no member functions, et cetera.
14021 So it does not need a prefix. */
14023 case DW_TAG_compile_unit
:
14024 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14025 if (cu
->language
== language_cplus
14026 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14027 && die
->child
!= NULL
14028 && (die
->tag
== DW_TAG_class_type
14029 || die
->tag
== DW_TAG_structure_type
14030 || die
->tag
== DW_TAG_union_type
))
14032 char *name
= guess_full_die_structure_name (die
, cu
);
14038 return determine_prefix (parent
, cu
);
14042 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14043 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14044 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14045 an obconcat, otherwise allocate storage for the result. The CU argument is
14046 used to determine the language and hence, the appropriate separator. */
14048 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14051 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14052 int physname
, struct dwarf2_cu
*cu
)
14054 const char *lead
= "";
14057 if (suffix
== NULL
|| suffix
[0] == '\0'
14058 || prefix
== NULL
|| prefix
[0] == '\0')
14060 else if (cu
->language
== language_java
)
14062 else if (cu
->language
== language_fortran
&& physname
)
14064 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14065 DW_AT_MIPS_linkage_name is preferred and used instead. */
14073 if (prefix
== NULL
)
14075 if (suffix
== NULL
)
14081 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14083 strcpy (retval
, lead
);
14084 strcat (retval
, prefix
);
14085 strcat (retval
, sep
);
14086 strcat (retval
, suffix
);
14091 /* We have an obstack. */
14092 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14096 /* Return sibling of die, NULL if no sibling. */
14098 static struct die_info
*
14099 sibling_die (struct die_info
*die
)
14101 return die
->sibling
;
14104 /* Get name of a die, return NULL if not found. */
14107 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14108 struct obstack
*obstack
)
14110 if (name
&& cu
->language
== language_cplus
)
14112 char *canon_name
= cp_canonicalize_string (name
);
14114 if (canon_name
!= NULL
)
14116 if (strcmp (canon_name
, name
) != 0)
14117 name
= obsavestring (canon_name
, strlen (canon_name
),
14119 xfree (canon_name
);
14126 /* Get name of a die, return NULL if not found. */
14129 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14131 struct attribute
*attr
;
14133 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14134 if ((!attr
|| !DW_STRING (attr
))
14135 && die
->tag
!= DW_TAG_class_type
14136 && die
->tag
!= DW_TAG_interface_type
14137 && die
->tag
!= DW_TAG_structure_type
14138 && die
->tag
!= DW_TAG_union_type
)
14143 case DW_TAG_compile_unit
:
14144 /* Compilation units have a DW_AT_name that is a filename, not
14145 a source language identifier. */
14146 case DW_TAG_enumeration_type
:
14147 case DW_TAG_enumerator
:
14148 /* These tags always have simple identifiers already; no need
14149 to canonicalize them. */
14150 return DW_STRING (attr
);
14152 case DW_TAG_subprogram
:
14153 /* Java constructors will all be named "<init>", so return
14154 the class name when we see this special case. */
14155 if (cu
->language
== language_java
14156 && DW_STRING (attr
) != NULL
14157 && strcmp (DW_STRING (attr
), "<init>") == 0)
14159 struct dwarf2_cu
*spec_cu
= cu
;
14160 struct die_info
*spec_die
;
14162 /* GCJ will output '<init>' for Java constructor names.
14163 For this special case, return the name of the parent class. */
14165 /* GCJ may output suprogram DIEs with AT_specification set.
14166 If so, use the name of the specified DIE. */
14167 spec_die
= die_specification (die
, &spec_cu
);
14168 if (spec_die
!= NULL
)
14169 return dwarf2_name (spec_die
, spec_cu
);
14174 if (die
->tag
== DW_TAG_class_type
)
14175 return dwarf2_name (die
, cu
);
14177 while (die
->tag
!= DW_TAG_compile_unit
);
14181 case DW_TAG_class_type
:
14182 case DW_TAG_interface_type
:
14183 case DW_TAG_structure_type
:
14184 case DW_TAG_union_type
:
14185 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14186 structures or unions. These were of the form "._%d" in GCC 4.1,
14187 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14188 and GCC 4.4. We work around this problem by ignoring these. */
14189 if (attr
&& DW_STRING (attr
)
14190 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14191 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14194 /* GCC might emit a nameless typedef that has a linkage name. See
14195 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14196 if (!attr
|| DW_STRING (attr
) == NULL
)
14198 char *demangled
= NULL
;
14200 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14202 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14204 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14207 /* Avoid demangling DW_STRING (attr) the second time on a second
14208 call for the same DIE. */
14209 if (!DW_STRING_IS_CANONICAL (attr
))
14210 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14216 /* FIXME: we already did this for the partial symbol... */
14217 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14218 &cu
->objfile
->objfile_obstack
);
14219 DW_STRING_IS_CANONICAL (attr
) = 1;
14222 /* Strip any leading namespaces/classes, keep only the base name.
14223 DW_AT_name for named DIEs does not contain the prefixes. */
14224 base
= strrchr (DW_STRING (attr
), ':');
14225 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14228 return DW_STRING (attr
);
14237 if (!DW_STRING_IS_CANONICAL (attr
))
14240 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14241 &cu
->objfile
->objfile_obstack
);
14242 DW_STRING_IS_CANONICAL (attr
) = 1;
14244 return DW_STRING (attr
);
14247 /* Return the die that this die in an extension of, or NULL if there
14248 is none. *EXT_CU is the CU containing DIE on input, and the CU
14249 containing the return value on output. */
14251 static struct die_info
*
14252 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14254 struct attribute
*attr
;
14256 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14260 return follow_die_ref (die
, attr
, ext_cu
);
14263 /* Convert a DIE tag into its string name. */
14265 static const char *
14266 dwarf_tag_name (unsigned tag
)
14268 const char *name
= get_DW_TAG_name (tag
);
14271 return "DW_TAG_<unknown>";
14276 /* Convert a DWARF attribute code into its string name. */
14278 static const char *
14279 dwarf_attr_name (unsigned attr
)
14283 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14284 if (attr
== DW_AT_MIPS_fde
)
14285 return "DW_AT_MIPS_fde";
14287 if (attr
== DW_AT_HP_block_index
)
14288 return "DW_AT_HP_block_index";
14291 name
= get_DW_AT_name (attr
);
14294 return "DW_AT_<unknown>";
14299 /* Convert a DWARF value form code into its string name. */
14301 static const char *
14302 dwarf_form_name (unsigned form
)
14304 const char *name
= get_DW_FORM_name (form
);
14307 return "DW_FORM_<unknown>";
14313 dwarf_bool_name (unsigned mybool
)
14321 /* Convert a DWARF type code into its string name. */
14323 static const char *
14324 dwarf_type_encoding_name (unsigned enc
)
14326 const char *name
= get_DW_ATE_name (enc
);
14329 return "DW_ATE_<unknown>";
14335 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14339 print_spaces (indent
, f
);
14340 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14341 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14343 if (die
->parent
!= NULL
)
14345 print_spaces (indent
, f
);
14346 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14347 die
->parent
->offset
.sect_off
);
14350 print_spaces (indent
, f
);
14351 fprintf_unfiltered (f
, " has children: %s\n",
14352 dwarf_bool_name (die
->child
!= NULL
));
14354 print_spaces (indent
, f
);
14355 fprintf_unfiltered (f
, " attributes:\n");
14357 for (i
= 0; i
< die
->num_attrs
; ++i
)
14359 print_spaces (indent
, f
);
14360 fprintf_unfiltered (f
, " %s (%s) ",
14361 dwarf_attr_name (die
->attrs
[i
].name
),
14362 dwarf_form_name (die
->attrs
[i
].form
));
14364 switch (die
->attrs
[i
].form
)
14367 case DW_FORM_GNU_addr_index
:
14368 fprintf_unfiltered (f
, "address: ");
14369 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14371 case DW_FORM_block2
:
14372 case DW_FORM_block4
:
14373 case DW_FORM_block
:
14374 case DW_FORM_block1
:
14375 fprintf_unfiltered (f
, "block: size %d",
14376 DW_BLOCK (&die
->attrs
[i
])->size
);
14378 case DW_FORM_exprloc
:
14379 fprintf_unfiltered (f
, "expression: size %u",
14380 DW_BLOCK (&die
->attrs
[i
])->size
);
14382 case DW_FORM_ref_addr
:
14383 fprintf_unfiltered (f
, "ref address: ");
14384 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14390 case DW_FORM_ref_udata
:
14391 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14392 (long) (DW_UNSND (&die
->attrs
[i
])));
14394 case DW_FORM_data1
:
14395 case DW_FORM_data2
:
14396 case DW_FORM_data4
:
14397 case DW_FORM_data8
:
14398 case DW_FORM_udata
:
14399 case DW_FORM_sdata
:
14400 fprintf_unfiltered (f
, "constant: %s",
14401 pulongest (DW_UNSND (&die
->attrs
[i
])));
14403 case DW_FORM_sec_offset
:
14404 fprintf_unfiltered (f
, "section offset: %s",
14405 pulongest (DW_UNSND (&die
->attrs
[i
])));
14407 case DW_FORM_ref_sig8
:
14408 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14409 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14410 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14412 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14414 case DW_FORM_string
:
14416 case DW_FORM_GNU_str_index
:
14417 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14418 DW_STRING (&die
->attrs
[i
])
14419 ? DW_STRING (&die
->attrs
[i
]) : "",
14420 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14423 if (DW_UNSND (&die
->attrs
[i
]))
14424 fprintf_unfiltered (f
, "flag: TRUE");
14426 fprintf_unfiltered (f
, "flag: FALSE");
14428 case DW_FORM_flag_present
:
14429 fprintf_unfiltered (f
, "flag: TRUE");
14431 case DW_FORM_indirect
:
14432 /* The reader will have reduced the indirect form to
14433 the "base form" so this form should not occur. */
14434 fprintf_unfiltered (f
,
14435 "unexpected attribute form: DW_FORM_indirect");
14438 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14439 die
->attrs
[i
].form
);
14442 fprintf_unfiltered (f
, "\n");
14447 dump_die_for_error (struct die_info
*die
)
14449 dump_die_shallow (gdb_stderr
, 0, die
);
14453 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14455 int indent
= level
* 4;
14457 gdb_assert (die
!= NULL
);
14459 if (level
>= max_level
)
14462 dump_die_shallow (f
, indent
, die
);
14464 if (die
->child
!= NULL
)
14466 print_spaces (indent
, f
);
14467 fprintf_unfiltered (f
, " Children:");
14468 if (level
+ 1 < max_level
)
14470 fprintf_unfiltered (f
, "\n");
14471 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14475 fprintf_unfiltered (f
,
14476 " [not printed, max nesting level reached]\n");
14480 if (die
->sibling
!= NULL
&& level
> 0)
14482 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14486 /* This is called from the pdie macro in gdbinit.in.
14487 It's not static so gcc will keep a copy callable from gdb. */
14490 dump_die (struct die_info
*die
, int max_level
)
14492 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14496 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14500 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14506 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14507 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14510 is_ref_attr (struct attribute
*attr
)
14512 switch (attr
->form
)
14514 case DW_FORM_ref_addr
:
14519 case DW_FORM_ref_udata
:
14526 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14530 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14532 sect_offset retval
= { DW_UNSND (attr
) };
14534 if (is_ref_attr (attr
))
14537 retval
.sect_off
= 0;
14538 complaint (&symfile_complaints
,
14539 _("unsupported die ref attribute form: '%s'"),
14540 dwarf_form_name (attr
->form
));
14544 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14545 * the value held by the attribute is not constant. */
14548 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14550 if (attr
->form
== DW_FORM_sdata
)
14551 return DW_SND (attr
);
14552 else if (attr
->form
== DW_FORM_udata
14553 || attr
->form
== DW_FORM_data1
14554 || attr
->form
== DW_FORM_data2
14555 || attr
->form
== DW_FORM_data4
14556 || attr
->form
== DW_FORM_data8
)
14557 return DW_UNSND (attr
);
14560 complaint (&symfile_complaints
,
14561 _("Attribute value is not a constant (%s)"),
14562 dwarf_form_name (attr
->form
));
14563 return default_value
;
14567 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14568 unit and add it to our queue.
14569 The result is non-zero if PER_CU was queued, otherwise the result is zero
14570 meaning either PER_CU is already queued or it is already loaded. */
14573 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14574 struct dwarf2_per_cu_data
*per_cu
)
14576 /* We may arrive here during partial symbol reading, if we need full
14577 DIEs to process an unusual case (e.g. template arguments). Do
14578 not queue PER_CU, just tell our caller to load its DIEs. */
14579 if (dwarf2_per_objfile
->reading_partial_symbols
)
14581 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14586 /* Mark the dependence relation so that we don't flush PER_CU
14588 dwarf2_add_dependence (this_cu
, per_cu
);
14590 /* If it's already on the queue, we have nothing to do. */
14591 if (per_cu
->queued
)
14594 /* If the compilation unit is already loaded, just mark it as
14596 if (per_cu
->cu
!= NULL
)
14598 per_cu
->cu
->last_used
= 0;
14602 /* Add it to the queue. */
14603 queue_comp_unit (per_cu
);
14608 /* Follow reference or signature attribute ATTR of SRC_DIE.
14609 On entry *REF_CU is the CU of SRC_DIE.
14610 On exit *REF_CU is the CU of the result. */
14612 static struct die_info
*
14613 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14614 struct dwarf2_cu
**ref_cu
)
14616 struct die_info
*die
;
14618 if (is_ref_attr (attr
))
14619 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14620 else if (attr
->form
== DW_FORM_ref_sig8
)
14621 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14624 dump_die_for_error (src_die
);
14625 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14626 (*ref_cu
)->objfile
->name
);
14632 /* Follow reference OFFSET.
14633 On entry *REF_CU is the CU of the source die referencing OFFSET.
14634 On exit *REF_CU is the CU of the result.
14635 Returns NULL if OFFSET is invalid. */
14637 static struct die_info
*
14638 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14640 struct die_info temp_die
;
14641 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14643 gdb_assert (cu
->per_cu
!= NULL
);
14647 if (cu
->per_cu
->is_debug_types
)
14649 /* .debug_types CUs cannot reference anything outside their CU.
14650 If they need to, they have to reference a signatured type via
14651 DW_FORM_ref_sig8. */
14652 if (! offset_in_cu_p (&cu
->header
, offset
))
14655 else if (! offset_in_cu_p (&cu
->header
, offset
))
14657 struct dwarf2_per_cu_data
*per_cu
;
14659 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14661 /* If necessary, add it to the queue and load its DIEs. */
14662 if (maybe_queue_comp_unit (cu
, per_cu
))
14663 load_full_comp_unit (per_cu
);
14665 target_cu
= per_cu
->cu
;
14667 else if (cu
->dies
== NULL
)
14669 /* We're loading full DIEs during partial symbol reading. */
14670 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14671 load_full_comp_unit (cu
->per_cu
);
14674 *ref_cu
= target_cu
;
14675 temp_die
.offset
= offset
;
14676 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14679 /* Follow reference attribute ATTR of SRC_DIE.
14680 On entry *REF_CU is the CU of SRC_DIE.
14681 On exit *REF_CU is the CU of the result. */
14683 static struct die_info
*
14684 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14685 struct dwarf2_cu
**ref_cu
)
14687 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14688 struct dwarf2_cu
*cu
= *ref_cu
;
14689 struct die_info
*die
;
14691 die
= follow_die_offset (offset
, ref_cu
);
14693 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14694 "at 0x%x [in module %s]"),
14695 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14700 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14701 Returned value is intended for DW_OP_call*. Returned
14702 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14704 struct dwarf2_locexpr_baton
14705 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14706 struct dwarf2_per_cu_data
*per_cu
,
14707 CORE_ADDR (*get_frame_pc
) (void *baton
),
14710 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14711 struct dwarf2_cu
*cu
;
14712 struct die_info
*die
;
14713 struct attribute
*attr
;
14714 struct dwarf2_locexpr_baton retval
;
14716 dw2_setup (per_cu
->objfile
);
14718 if (per_cu
->cu
== NULL
)
14722 die
= follow_die_offset (offset
, &cu
);
14724 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
14725 offset
.sect_off
, per_cu
->objfile
->name
);
14727 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14730 /* DWARF: "If there is no such attribute, then there is no effect.".
14731 DATA is ignored if SIZE is 0. */
14733 retval
.data
= NULL
;
14736 else if (attr_form_is_section_offset (attr
))
14738 struct dwarf2_loclist_baton loclist_baton
;
14739 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
14742 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
14744 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
14746 retval
.size
= size
;
14750 if (!attr_form_is_block (attr
))
14751 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
14752 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
14753 offset
.sect_off
, per_cu
->objfile
->name
);
14755 retval
.data
= DW_BLOCK (attr
)->data
;
14756 retval
.size
= DW_BLOCK (attr
)->size
;
14758 retval
.per_cu
= cu
->per_cu
;
14760 age_cached_comp_units ();
14765 /* Return the type of the DIE at DIE_OFFSET in the CU named by
14769 dwarf2_get_die_type (cu_offset die_offset
,
14770 struct dwarf2_per_cu_data
*per_cu
)
14772 sect_offset die_offset_sect
;
14774 dw2_setup (per_cu
->objfile
);
14776 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
14777 return get_die_type_at_offset (die_offset_sect
, per_cu
);
14780 /* Follow the signature attribute ATTR in SRC_DIE.
14781 On entry *REF_CU is the CU of SRC_DIE.
14782 On exit *REF_CU is the CU of the result. */
14784 static struct die_info
*
14785 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
14786 struct dwarf2_cu
**ref_cu
)
14788 struct objfile
*objfile
= (*ref_cu
)->objfile
;
14789 struct die_info temp_die
;
14790 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14791 struct dwarf2_cu
*sig_cu
;
14792 struct die_info
*die
;
14794 /* sig_type will be NULL if the signatured type is missing from
14796 if (sig_type
== NULL
)
14797 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14798 "at 0x%x [in module %s]"),
14799 src_die
->offset
.sect_off
, objfile
->name
);
14801 /* If necessary, add it to the queue and load its DIEs. */
14803 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
14804 read_signatured_type (sig_type
);
14806 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14808 sig_cu
= sig_type
->per_cu
.cu
;
14809 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
14810 temp_die
.offset
= sig_type
->type_offset_in_section
;
14811 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
14812 temp_die
.offset
.sect_off
);
14819 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
14820 "from DIE at 0x%x [in module %s]"),
14821 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
14824 /* Given an offset of a signatured type, return its signatured_type. */
14826 static struct signatured_type
*
14827 lookup_signatured_type_at_offset (struct objfile
*objfile
,
14828 struct dwarf2_section_info
*section
,
14829 sect_offset offset
)
14831 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
14832 unsigned int length
, initial_length_size
;
14833 unsigned int sig_offset
;
14834 struct signatured_type find_entry
, *sig_type
;
14836 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
14837 sig_offset
= (initial_length_size
14839 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
14840 + 1 /*address_size*/);
14841 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
14842 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
14844 /* This is only used to lookup previously recorded types.
14845 If we didn't find it, it's our bug. */
14846 gdb_assert (sig_type
!= NULL
);
14847 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
14852 /* Load the DIEs associated with type unit PER_CU into memory. */
14855 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
14857 struct objfile
*objfile
= per_cu
->objfile
;
14858 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
14859 sect_offset offset
= per_cu
->offset
;
14860 struct signatured_type
*sig_type
;
14862 dwarf2_read_section (objfile
, sect
);
14864 /* We have the section offset, but we need the signature to do the
14865 hash table lookup. */
14866 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
14867 the signature to assert we found the right one.
14868 Ok, but it's a lot of work. We should simplify things so any needed
14869 assert doesn't require all this clumsiness. */
14870 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
14872 gdb_assert (&sig_type
->per_cu
== per_cu
);
14873 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
14875 read_signatured_type (sig_type
);
14877 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
14880 /* die_reader_func for read_signatured_type.
14881 This is identical to load_full_comp_unit_reader,
14882 but is kept separate for now. */
14885 read_signatured_type_reader (const struct die_reader_specs
*reader
,
14886 gdb_byte
*info_ptr
,
14887 struct die_info
*comp_unit_die
,
14891 struct dwarf2_cu
*cu
= reader
->cu
;
14892 struct attribute
*attr
;
14894 gdb_assert (cu
->die_hash
== NULL
);
14896 htab_create_alloc_ex (cu
->header
.length
/ 12,
14900 &cu
->comp_unit_obstack
,
14901 hashtab_obstack_allocate
,
14902 dummy_obstack_deallocate
);
14905 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
14906 &info_ptr
, comp_unit_die
);
14907 cu
->dies
= comp_unit_die
;
14908 /* comp_unit_die is not stored in die_hash, no need. */
14910 /* We try not to read any attributes in this function, because not
14911 all CUs needed for references have been loaded yet, and symbol
14912 table processing isn't initialized. But we have to set the CU language,
14913 or we won't be able to build types correctly.
14914 Similarly, if we do not read the producer, we can not apply
14915 producer-specific interpretation. */
14916 prepare_one_comp_unit (cu
, cu
->dies
);
14919 /* Read in a signatured type and build its CU and DIEs.
14920 If the type is a stub for the real type in a DWO file,
14921 read in the real type from the DWO file as well. */
14924 read_signatured_type (struct signatured_type
*sig_type
)
14926 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
14928 gdb_assert (per_cu
->is_debug_types
);
14929 gdb_assert (per_cu
->cu
== NULL
);
14931 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
14934 /* Decode simple location descriptions.
14935 Given a pointer to a dwarf block that defines a location, compute
14936 the location and return the value.
14938 NOTE drow/2003-11-18: This function is called in two situations
14939 now: for the address of static or global variables (partial symbols
14940 only) and for offsets into structures which are expected to be
14941 (more or less) constant. The partial symbol case should go away,
14942 and only the constant case should remain. That will let this
14943 function complain more accurately. A few special modes are allowed
14944 without complaint for global variables (for instance, global
14945 register values and thread-local values).
14947 A location description containing no operations indicates that the
14948 object is optimized out. The return value is 0 for that case.
14949 FIXME drow/2003-11-16: No callers check for this case any more; soon all
14950 callers will only want a very basic result and this can become a
14953 Note that stack[0] is unused except as a default error return. */
14956 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
14958 struct objfile
*objfile
= cu
->objfile
;
14960 int size
= blk
->size
;
14961 gdb_byte
*data
= blk
->data
;
14962 CORE_ADDR stack
[64];
14964 unsigned int bytes_read
, unsnd
;
14970 stack
[++stacki
] = 0;
15009 stack
[++stacki
] = op
- DW_OP_lit0
;
15044 stack
[++stacki
] = op
- DW_OP_reg0
;
15046 dwarf2_complex_location_expr_complaint ();
15050 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15052 stack
[++stacki
] = unsnd
;
15054 dwarf2_complex_location_expr_complaint ();
15058 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15063 case DW_OP_const1u
:
15064 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15068 case DW_OP_const1s
:
15069 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15073 case DW_OP_const2u
:
15074 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15078 case DW_OP_const2s
:
15079 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15083 case DW_OP_const4u
:
15084 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15088 case DW_OP_const4s
:
15089 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15093 case DW_OP_const8u
:
15094 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15099 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15105 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15110 stack
[stacki
+ 1] = stack
[stacki
];
15115 stack
[stacki
- 1] += stack
[stacki
];
15119 case DW_OP_plus_uconst
:
15120 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15126 stack
[stacki
- 1] -= stack
[stacki
];
15131 /* If we're not the last op, then we definitely can't encode
15132 this using GDB's address_class enum. This is valid for partial
15133 global symbols, although the variable's address will be bogus
15136 dwarf2_complex_location_expr_complaint ();
15139 case DW_OP_GNU_push_tls_address
:
15140 /* The top of the stack has the offset from the beginning
15141 of the thread control block at which the variable is located. */
15142 /* Nothing should follow this operator, so the top of stack would
15144 /* This is valid for partial global symbols, but the variable's
15145 address will be bogus in the psymtab. Make it always at least
15146 non-zero to not look as a variable garbage collected by linker
15147 which have DW_OP_addr 0. */
15149 dwarf2_complex_location_expr_complaint ();
15153 case DW_OP_GNU_uninit
:
15156 case DW_OP_GNU_addr_index
:
15157 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15164 const char *name
= get_DW_OP_name (op
);
15167 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15170 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15174 return (stack
[stacki
]);
15177 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15178 outside of the allocated space. Also enforce minimum>0. */
15179 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15181 complaint (&symfile_complaints
,
15182 _("location description stack overflow"));
15188 complaint (&symfile_complaints
,
15189 _("location description stack underflow"));
15193 return (stack
[stacki
]);
15196 /* memory allocation interface */
15198 static struct dwarf_block
*
15199 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15201 struct dwarf_block
*blk
;
15203 blk
= (struct dwarf_block
*)
15204 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15208 static struct abbrev_info
*
15209 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15211 struct abbrev_info
*abbrev
;
15213 abbrev
= (struct abbrev_info
*)
15214 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15215 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15219 static struct die_info
*
15220 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15222 struct die_info
*die
;
15223 size_t size
= sizeof (struct die_info
);
15226 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15228 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15229 memset (die
, 0, sizeof (struct die_info
));
15234 /* Macro support. */
15236 /* Return the full name of file number I in *LH's file name table.
15237 Use COMP_DIR as the name of the current directory of the
15238 compilation. The result is allocated using xmalloc; the caller is
15239 responsible for freeing it. */
15241 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15243 /* Is the file number a valid index into the line header's file name
15244 table? Remember that file numbers start with one, not zero. */
15245 if (1 <= file
&& file
<= lh
->num_file_names
)
15247 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15249 if (IS_ABSOLUTE_PATH (fe
->name
))
15250 return xstrdup (fe
->name
);
15258 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15264 dir_len
= strlen (dir
);
15265 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15266 strcpy (full_name
, dir
);
15267 full_name
[dir_len
] = '/';
15268 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15272 return xstrdup (fe
->name
);
15277 /* The compiler produced a bogus file number. We can at least
15278 record the macro definitions made in the file, even if we
15279 won't be able to find the file by name. */
15280 char fake_name
[80];
15282 sprintf (fake_name
, "<bad macro file number %d>", file
);
15284 complaint (&symfile_complaints
,
15285 _("bad file number in macro information (%d)"),
15288 return xstrdup (fake_name
);
15293 static struct macro_source_file
*
15294 macro_start_file (int file
, int line
,
15295 struct macro_source_file
*current_file
,
15296 const char *comp_dir
,
15297 struct line_header
*lh
, struct objfile
*objfile
)
15299 /* The full name of this source file. */
15300 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15302 /* We don't create a macro table for this compilation unit
15303 at all until we actually get a filename. */
15304 if (! pending_macros
)
15305 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15306 objfile
->macro_cache
);
15308 if (! current_file
)
15309 /* If we have no current file, then this must be the start_file
15310 directive for the compilation unit's main source file. */
15311 current_file
= macro_set_main (pending_macros
, full_name
);
15313 current_file
= macro_include (current_file
, line
, full_name
);
15317 return current_file
;
15321 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15322 followed by a null byte. */
15324 copy_string (const char *buf
, int len
)
15326 char *s
= xmalloc (len
+ 1);
15328 memcpy (s
, buf
, len
);
15334 static const char *
15335 consume_improper_spaces (const char *p
, const char *body
)
15339 complaint (&symfile_complaints
,
15340 _("macro definition contains spaces "
15341 "in formal argument list:\n`%s'"),
15353 parse_macro_definition (struct macro_source_file
*file
, int line
,
15358 /* The body string takes one of two forms. For object-like macro
15359 definitions, it should be:
15361 <macro name> " " <definition>
15363 For function-like macro definitions, it should be:
15365 <macro name> "() " <definition>
15367 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15369 Spaces may appear only where explicitly indicated, and in the
15372 The Dwarf 2 spec says that an object-like macro's name is always
15373 followed by a space, but versions of GCC around March 2002 omit
15374 the space when the macro's definition is the empty string.
15376 The Dwarf 2 spec says that there should be no spaces between the
15377 formal arguments in a function-like macro's formal argument list,
15378 but versions of GCC around March 2002 include spaces after the
15382 /* Find the extent of the macro name. The macro name is terminated
15383 by either a space or null character (for an object-like macro) or
15384 an opening paren (for a function-like macro). */
15385 for (p
= body
; *p
; p
++)
15386 if (*p
== ' ' || *p
== '(')
15389 if (*p
== ' ' || *p
== '\0')
15391 /* It's an object-like macro. */
15392 int name_len
= p
- body
;
15393 char *name
= copy_string (body
, name_len
);
15394 const char *replacement
;
15397 replacement
= body
+ name_len
+ 1;
15400 dwarf2_macro_malformed_definition_complaint (body
);
15401 replacement
= body
+ name_len
;
15404 macro_define_object (file
, line
, name
, replacement
);
15408 else if (*p
== '(')
15410 /* It's a function-like macro. */
15411 char *name
= copy_string (body
, p
- body
);
15414 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15418 p
= consume_improper_spaces (p
, body
);
15420 /* Parse the formal argument list. */
15421 while (*p
&& *p
!= ')')
15423 /* Find the extent of the current argument name. */
15424 const char *arg_start
= p
;
15426 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15429 if (! *p
|| p
== arg_start
)
15430 dwarf2_macro_malformed_definition_complaint (body
);
15433 /* Make sure argv has room for the new argument. */
15434 if (argc
>= argv_size
)
15437 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15440 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15443 p
= consume_improper_spaces (p
, body
);
15445 /* Consume the comma, if present. */
15450 p
= consume_improper_spaces (p
, body
);
15459 /* Perfectly formed definition, no complaints. */
15460 macro_define_function (file
, line
, name
,
15461 argc
, (const char **) argv
,
15463 else if (*p
== '\0')
15465 /* Complain, but do define it. */
15466 dwarf2_macro_malformed_definition_complaint (body
);
15467 macro_define_function (file
, line
, name
,
15468 argc
, (const char **) argv
,
15472 /* Just complain. */
15473 dwarf2_macro_malformed_definition_complaint (body
);
15476 /* Just complain. */
15477 dwarf2_macro_malformed_definition_complaint (body
);
15483 for (i
= 0; i
< argc
; i
++)
15489 dwarf2_macro_malformed_definition_complaint (body
);
15492 /* Skip some bytes from BYTES according to the form given in FORM.
15493 Returns the new pointer. */
15496 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
15497 enum dwarf_form form
,
15498 unsigned int offset_size
,
15499 struct dwarf2_section_info
*section
)
15501 unsigned int bytes_read
;
15505 case DW_FORM_data1
:
15510 case DW_FORM_data2
:
15514 case DW_FORM_data4
:
15518 case DW_FORM_data8
:
15522 case DW_FORM_string
:
15523 read_direct_string (abfd
, bytes
, &bytes_read
);
15524 bytes
+= bytes_read
;
15527 case DW_FORM_sec_offset
:
15529 bytes
+= offset_size
;
15532 case DW_FORM_block
:
15533 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15534 bytes
+= bytes_read
;
15537 case DW_FORM_block1
:
15538 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15540 case DW_FORM_block2
:
15541 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15543 case DW_FORM_block4
:
15544 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15547 case DW_FORM_sdata
:
15548 case DW_FORM_udata
:
15549 case DW_FORM_GNU_addr_index
:
15550 case DW_FORM_GNU_str_index
:
15551 bytes
= skip_leb128 (abfd
, bytes
);
15557 complaint (&symfile_complaints
,
15558 _("invalid form 0x%x in `%s'"),
15560 section
->asection
->name
);
15568 /* A helper for dwarf_decode_macros that handles skipping an unknown
15569 opcode. Returns an updated pointer to the macro data buffer; or,
15570 on error, issues a complaint and returns NULL. */
15573 skip_unknown_opcode (unsigned int opcode
,
15574 gdb_byte
**opcode_definitions
,
15577 unsigned int offset_size
,
15578 struct dwarf2_section_info
*section
)
15580 unsigned int bytes_read
, i
;
15584 if (opcode_definitions
[opcode
] == NULL
)
15586 complaint (&symfile_complaints
,
15587 _("unrecognized DW_MACFINO opcode 0x%x"),
15592 defn
= opcode_definitions
[opcode
];
15593 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15594 defn
+= bytes_read
;
15596 for (i
= 0; i
< arg
; ++i
)
15598 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
15599 if (mac_ptr
== NULL
)
15601 /* skip_form_bytes already issued the complaint. */
15609 /* A helper function which parses the header of a macro section.
15610 If the macro section is the extended (for now called "GNU") type,
15611 then this updates *OFFSET_SIZE. Returns a pointer to just after
15612 the header, or issues a complaint and returns NULL on error. */
15615 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15618 unsigned int *offset_size
,
15619 int section_is_gnu
)
15621 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15623 if (section_is_gnu
)
15625 unsigned int version
, flags
;
15627 version
= read_2_bytes (abfd
, mac_ptr
);
15630 complaint (&symfile_complaints
,
15631 _("unrecognized version `%d' in .debug_macro section"),
15637 flags
= read_1_byte (abfd
, mac_ptr
);
15639 *offset_size
= (flags
& 1) ? 8 : 4;
15641 if ((flags
& 2) != 0)
15642 /* We don't need the line table offset. */
15643 mac_ptr
+= *offset_size
;
15645 /* Vendor opcode descriptions. */
15646 if ((flags
& 4) != 0)
15648 unsigned int i
, count
;
15650 count
= read_1_byte (abfd
, mac_ptr
);
15652 for (i
= 0; i
< count
; ++i
)
15654 unsigned int opcode
, bytes_read
;
15657 opcode
= read_1_byte (abfd
, mac_ptr
);
15659 opcode_definitions
[opcode
] = mac_ptr
;
15660 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15661 mac_ptr
+= bytes_read
;
15670 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15671 including DW_MACRO_GNU_transparent_include. */
15674 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15675 struct macro_source_file
*current_file
,
15676 struct line_header
*lh
, char *comp_dir
,
15677 struct dwarf2_section_info
*section
,
15678 int section_is_gnu
,
15679 unsigned int offset_size
,
15680 struct objfile
*objfile
,
15681 htab_t include_hash
)
15683 enum dwarf_macro_record_type macinfo_type
;
15684 int at_commandline
;
15685 gdb_byte
*opcode_definitions
[256];
15687 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15688 &offset_size
, section_is_gnu
);
15689 if (mac_ptr
== NULL
)
15691 /* We already issued a complaint. */
15695 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15696 GDB is still reading the definitions from command line. First
15697 DW_MACINFO_start_file will need to be ignored as it was already executed
15698 to create CURRENT_FILE for the main source holding also the command line
15699 definitions. On first met DW_MACINFO_start_file this flag is reset to
15700 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15702 at_commandline
= 1;
15706 /* Do we at least have room for a macinfo type byte? */
15707 if (mac_ptr
>= mac_end
)
15709 dwarf2_macros_too_long_complaint (section
);
15713 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15716 /* Note that we rely on the fact that the corresponding GNU and
15717 DWARF constants are the same. */
15718 switch (macinfo_type
)
15720 /* A zero macinfo type indicates the end of the macro
15725 case DW_MACRO_GNU_define
:
15726 case DW_MACRO_GNU_undef
:
15727 case DW_MACRO_GNU_define_indirect
:
15728 case DW_MACRO_GNU_undef_indirect
:
15730 unsigned int bytes_read
;
15735 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15736 mac_ptr
+= bytes_read
;
15738 if (macinfo_type
== DW_MACRO_GNU_define
15739 || macinfo_type
== DW_MACRO_GNU_undef
)
15741 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15742 mac_ptr
+= bytes_read
;
15746 LONGEST str_offset
;
15748 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15749 mac_ptr
+= offset_size
;
15751 body
= read_indirect_string_at_offset (abfd
, str_offset
);
15754 is_define
= (macinfo_type
== DW_MACRO_GNU_define
15755 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
15756 if (! current_file
)
15758 /* DWARF violation as no main source is present. */
15759 complaint (&symfile_complaints
,
15760 _("debug info with no main source gives macro %s "
15762 is_define
? _("definition") : _("undefinition"),
15766 if ((line
== 0 && !at_commandline
)
15767 || (line
!= 0 && at_commandline
))
15768 complaint (&symfile_complaints
,
15769 _("debug info gives %s macro %s with %s line %d: %s"),
15770 at_commandline
? _("command-line") : _("in-file"),
15771 is_define
? _("definition") : _("undefinition"),
15772 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
15775 parse_macro_definition (current_file
, line
, body
);
15778 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
15779 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
15780 macro_undef (current_file
, line
, body
);
15785 case DW_MACRO_GNU_start_file
:
15787 unsigned int bytes_read
;
15790 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15791 mac_ptr
+= bytes_read
;
15792 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15793 mac_ptr
+= bytes_read
;
15795 if ((line
== 0 && !at_commandline
)
15796 || (line
!= 0 && at_commandline
))
15797 complaint (&symfile_complaints
,
15798 _("debug info gives source %d included "
15799 "from %s at %s line %d"),
15800 file
, at_commandline
? _("command-line") : _("file"),
15801 line
== 0 ? _("zero") : _("non-zero"), line
);
15803 if (at_commandline
)
15805 /* This DW_MACRO_GNU_start_file was executed in the
15807 at_commandline
= 0;
15810 current_file
= macro_start_file (file
, line
,
15811 current_file
, comp_dir
,
15816 case DW_MACRO_GNU_end_file
:
15817 if (! current_file
)
15818 complaint (&symfile_complaints
,
15819 _("macro debug info has an unmatched "
15820 "`close_file' directive"));
15823 current_file
= current_file
->included_by
;
15824 if (! current_file
)
15826 enum dwarf_macro_record_type next_type
;
15828 /* GCC circa March 2002 doesn't produce the zero
15829 type byte marking the end of the compilation
15830 unit. Complain if it's not there, but exit no
15833 /* Do we at least have room for a macinfo type byte? */
15834 if (mac_ptr
>= mac_end
)
15836 dwarf2_macros_too_long_complaint (section
);
15840 /* We don't increment mac_ptr here, so this is just
15842 next_type
= read_1_byte (abfd
, mac_ptr
);
15843 if (next_type
!= 0)
15844 complaint (&symfile_complaints
,
15845 _("no terminating 0-type entry for "
15846 "macros in `.debug_macinfo' section"));
15853 case DW_MACRO_GNU_transparent_include
:
15858 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
15859 mac_ptr
+= offset_size
;
15861 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
15864 /* This has actually happened; see
15865 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
15866 complaint (&symfile_complaints
,
15867 _("recursive DW_MACRO_GNU_transparent_include in "
15868 ".debug_macro section"));
15874 dwarf_decode_macro_bytes (abfd
,
15875 section
->buffer
+ offset
,
15876 mac_end
, current_file
,
15878 section
, section_is_gnu
,
15879 offset_size
, objfile
, include_hash
);
15881 htab_remove_elt (include_hash
, mac_ptr
);
15886 case DW_MACINFO_vendor_ext
:
15887 if (!section_is_gnu
)
15889 unsigned int bytes_read
;
15892 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15893 mac_ptr
+= bytes_read
;
15894 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15895 mac_ptr
+= bytes_read
;
15897 /* We don't recognize any vendor extensions. */
15903 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
15904 mac_ptr
, abfd
, offset_size
,
15906 if (mac_ptr
== NULL
)
15910 } while (macinfo_type
!= 0);
15914 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
15915 char *comp_dir
, bfd
*abfd
,
15916 struct dwarf2_cu
*cu
,
15917 struct dwarf2_section_info
*section
,
15918 int section_is_gnu
, const char *section_name
)
15920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15921 gdb_byte
*mac_ptr
, *mac_end
;
15922 struct macro_source_file
*current_file
= 0;
15923 enum dwarf_macro_record_type macinfo_type
;
15924 unsigned int offset_size
= cu
->header
.offset_size
;
15925 gdb_byte
*opcode_definitions
[256];
15926 struct cleanup
*cleanup
;
15927 htab_t include_hash
;
15930 dwarf2_read_section (objfile
, section
);
15931 if (section
->buffer
== NULL
)
15933 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
15937 /* First pass: Find the name of the base filename.
15938 This filename is needed in order to process all macros whose definition
15939 (or undefinition) comes from the command line. These macros are defined
15940 before the first DW_MACINFO_start_file entry, and yet still need to be
15941 associated to the base file.
15943 To determine the base file name, we scan the macro definitions until we
15944 reach the first DW_MACINFO_start_file entry. We then initialize
15945 CURRENT_FILE accordingly so that any macro definition found before the
15946 first DW_MACINFO_start_file can still be associated to the base file. */
15948 mac_ptr
= section
->buffer
+ offset
;
15949 mac_end
= section
->buffer
+ section
->size
;
15951 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15952 &offset_size
, section_is_gnu
);
15953 if (mac_ptr
== NULL
)
15955 /* We already issued a complaint. */
15961 /* Do we at least have room for a macinfo type byte? */
15962 if (mac_ptr
>= mac_end
)
15964 /* Complaint is printed during the second pass as GDB will probably
15965 stop the first pass earlier upon finding
15966 DW_MACINFO_start_file. */
15970 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
15973 /* Note that we rely on the fact that the corresponding GNU and
15974 DWARF constants are the same. */
15975 switch (macinfo_type
)
15977 /* A zero macinfo type indicates the end of the macro
15982 case DW_MACRO_GNU_define
:
15983 case DW_MACRO_GNU_undef
:
15984 /* Only skip the data by MAC_PTR. */
15986 unsigned int bytes_read
;
15988 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15989 mac_ptr
+= bytes_read
;
15990 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
15991 mac_ptr
+= bytes_read
;
15995 case DW_MACRO_GNU_start_file
:
15997 unsigned int bytes_read
;
16000 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16001 mac_ptr
+= bytes_read
;
16002 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16003 mac_ptr
+= bytes_read
;
16005 current_file
= macro_start_file (file
, line
, current_file
,
16006 comp_dir
, lh
, objfile
);
16010 case DW_MACRO_GNU_end_file
:
16011 /* No data to skip by MAC_PTR. */
16014 case DW_MACRO_GNU_define_indirect
:
16015 case DW_MACRO_GNU_undef_indirect
:
16017 unsigned int bytes_read
;
16019 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16020 mac_ptr
+= bytes_read
;
16021 mac_ptr
+= offset_size
;
16025 case DW_MACRO_GNU_transparent_include
:
16026 /* Note that, according to the spec, a transparent include
16027 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16028 skip this opcode. */
16029 mac_ptr
+= offset_size
;
16032 case DW_MACINFO_vendor_ext
:
16033 /* Only skip the data by MAC_PTR. */
16034 if (!section_is_gnu
)
16036 unsigned int bytes_read
;
16038 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16039 mac_ptr
+= bytes_read
;
16040 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16041 mac_ptr
+= bytes_read
;
16046 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16047 mac_ptr
, abfd
, offset_size
,
16049 if (mac_ptr
== NULL
)
16053 } while (macinfo_type
!= 0 && current_file
== NULL
);
16055 /* Second pass: Process all entries.
16057 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16058 command-line macro definitions/undefinitions. This flag is unset when we
16059 reach the first DW_MACINFO_start_file entry. */
16061 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16062 NULL
, xcalloc
, xfree
);
16063 cleanup
= make_cleanup_htab_delete (include_hash
);
16064 mac_ptr
= section
->buffer
+ offset
;
16065 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16067 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16068 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16069 offset_size
, objfile
, include_hash
);
16070 do_cleanups (cleanup
);
16073 /* Check if the attribute's form is a DW_FORM_block*
16074 if so return true else false. */
16077 attr_form_is_block (struct attribute
*attr
)
16079 return (attr
== NULL
? 0 :
16080 attr
->form
== DW_FORM_block1
16081 || attr
->form
== DW_FORM_block2
16082 || attr
->form
== DW_FORM_block4
16083 || attr
->form
== DW_FORM_block
16084 || attr
->form
== DW_FORM_exprloc
);
16087 /* Return non-zero if ATTR's value is a section offset --- classes
16088 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16089 You may use DW_UNSND (attr) to retrieve such offsets.
16091 Section 7.5.4, "Attribute Encodings", explains that no attribute
16092 may have a value that belongs to more than one of these classes; it
16093 would be ambiguous if we did, because we use the same forms for all
16097 attr_form_is_section_offset (struct attribute
*attr
)
16099 return (attr
->form
== DW_FORM_data4
16100 || attr
->form
== DW_FORM_data8
16101 || attr
->form
== DW_FORM_sec_offset
);
16104 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16105 zero otherwise. When this function returns true, you can apply
16106 dwarf2_get_attr_constant_value to it.
16108 However, note that for some attributes you must check
16109 attr_form_is_section_offset before using this test. DW_FORM_data4
16110 and DW_FORM_data8 are members of both the constant class, and of
16111 the classes that contain offsets into other debug sections
16112 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16113 that, if an attribute's can be either a constant or one of the
16114 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16115 taken as section offsets, not constants. */
16118 attr_form_is_constant (struct attribute
*attr
)
16120 switch (attr
->form
)
16122 case DW_FORM_sdata
:
16123 case DW_FORM_udata
:
16124 case DW_FORM_data1
:
16125 case DW_FORM_data2
:
16126 case DW_FORM_data4
:
16127 case DW_FORM_data8
:
16134 /* Return the .debug_loc section to use for CU.
16135 For DWO files use .debug_loc.dwo. */
16137 static struct dwarf2_section_info
*
16138 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16141 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16142 return &dwarf2_per_objfile
->loc
;
16145 /* A helper function that fills in a dwarf2_loclist_baton. */
16148 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16149 struct dwarf2_loclist_baton
*baton
,
16150 struct attribute
*attr
)
16152 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16154 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16156 baton
->per_cu
= cu
->per_cu
;
16157 gdb_assert (baton
->per_cu
);
16158 /* We don't know how long the location list is, but make sure we
16159 don't run off the edge of the section. */
16160 baton
->size
= section
->size
- DW_UNSND (attr
);
16161 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16162 baton
->base_address
= cu
->base_address
;
16166 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16167 struct dwarf2_cu
*cu
)
16169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16170 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16172 if (attr_form_is_section_offset (attr
)
16173 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16174 the section. If so, fall through to the complaint in the
16176 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16178 struct dwarf2_loclist_baton
*baton
;
16180 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16181 sizeof (struct dwarf2_loclist_baton
));
16183 fill_in_loclist_baton (cu
, baton
, attr
);
16185 if (cu
->base_known
== 0)
16186 complaint (&symfile_complaints
,
16187 _("Location list used without "
16188 "specifying the CU base address."));
16190 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16191 SYMBOL_LOCATION_BATON (sym
) = baton
;
16195 struct dwarf2_locexpr_baton
*baton
;
16197 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16198 sizeof (struct dwarf2_locexpr_baton
));
16199 baton
->per_cu
= cu
->per_cu
;
16200 gdb_assert (baton
->per_cu
);
16202 if (attr_form_is_block (attr
))
16204 /* Note that we're just copying the block's data pointer
16205 here, not the actual data. We're still pointing into the
16206 info_buffer for SYM's objfile; right now we never release
16207 that buffer, but when we do clean up properly this may
16209 baton
->size
= DW_BLOCK (attr
)->size
;
16210 baton
->data
= DW_BLOCK (attr
)->data
;
16214 dwarf2_invalid_attrib_class_complaint ("location description",
16215 SYMBOL_NATURAL_NAME (sym
));
16219 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16220 SYMBOL_LOCATION_BATON (sym
) = baton
;
16224 /* Return the OBJFILE associated with the compilation unit CU. If CU
16225 came from a separate debuginfo file, then the master objfile is
16229 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16231 struct objfile
*objfile
= per_cu
->objfile
;
16233 /* Return the master objfile, so that we can report and look up the
16234 correct file containing this variable. */
16235 if (objfile
->separate_debug_objfile_backlink
)
16236 objfile
= objfile
->separate_debug_objfile_backlink
;
16241 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16242 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16243 CU_HEADERP first. */
16245 static const struct comp_unit_head
*
16246 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16247 struct dwarf2_per_cu_data
*per_cu
)
16249 struct objfile
*objfile
;
16250 struct dwarf2_per_objfile
*per_objfile
;
16251 gdb_byte
*info_ptr
;
16254 return &per_cu
->cu
->header
;
16256 objfile
= per_cu
->objfile
;
16257 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16258 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16260 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16261 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16266 /* Return the address size given in the compilation unit header for CU. */
16269 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16271 struct comp_unit_head cu_header_local
;
16272 const struct comp_unit_head
*cu_headerp
;
16274 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16276 return cu_headerp
->addr_size
;
16279 /* Return the offset size given in the compilation unit header for CU. */
16282 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16284 struct comp_unit_head cu_header_local
;
16285 const struct comp_unit_head
*cu_headerp
;
16287 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16289 return cu_headerp
->offset_size
;
16292 /* See its dwarf2loc.h declaration. */
16295 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16297 struct comp_unit_head cu_header_local
;
16298 const struct comp_unit_head
*cu_headerp
;
16300 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16302 if (cu_headerp
->version
== 2)
16303 return cu_headerp
->addr_size
;
16305 return cu_headerp
->offset_size
;
16308 /* Return the text offset of the CU. The returned offset comes from
16309 this CU's objfile. If this objfile came from a separate debuginfo
16310 file, then the offset may be different from the corresponding
16311 offset in the parent objfile. */
16314 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16316 struct objfile
*objfile
= per_cu
->objfile
;
16318 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16321 /* Locate the .debug_info compilation unit from CU's objfile which contains
16322 the DIE at OFFSET. Raises an error on failure. */
16324 static struct dwarf2_per_cu_data
*
16325 dwarf2_find_containing_comp_unit (sect_offset offset
,
16326 struct objfile
*objfile
)
16328 struct dwarf2_per_cu_data
*this_cu
;
16332 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16335 int mid
= low
+ (high
- low
) / 2;
16337 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16338 >= offset
.sect_off
)
16343 gdb_assert (low
== high
);
16344 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16348 error (_("Dwarf Error: could not find partial DIE containing "
16349 "offset 0x%lx [in module %s]"),
16350 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16352 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16353 <= offset
.sect_off
);
16354 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16358 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16359 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16360 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16361 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16362 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16367 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16370 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16372 memset (cu
, 0, sizeof (*cu
));
16374 cu
->per_cu
= per_cu
;
16375 cu
->objfile
= per_cu
->objfile
;
16376 obstack_init (&cu
->comp_unit_obstack
);
16379 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16382 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
16384 struct attribute
*attr
;
16386 /* Set the language we're debugging. */
16387 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16389 set_cu_language (DW_UNSND (attr
), cu
);
16392 cu
->language
= language_minimal
;
16393 cu
->language_defn
= language_def (cu
->language
);
16396 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16398 cu
->producer
= DW_STRING (attr
);
16401 /* Release one cached compilation unit, CU. We unlink it from the tree
16402 of compilation units, but we don't remove it from the read_in_chain;
16403 the caller is responsible for that.
16404 NOTE: DATA is a void * because this function is also used as a
16405 cleanup routine. */
16408 free_heap_comp_unit (void *data
)
16410 struct dwarf2_cu
*cu
= data
;
16412 gdb_assert (cu
->per_cu
!= NULL
);
16413 cu
->per_cu
->cu
= NULL
;
16416 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16421 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16422 when we're finished with it. We can't free the pointer itself, but be
16423 sure to unlink it from the cache. Also release any associated storage. */
16426 free_stack_comp_unit (void *data
)
16428 struct dwarf2_cu
*cu
= data
;
16430 gdb_assert (cu
->per_cu
!= NULL
);
16431 cu
->per_cu
->cu
= NULL
;
16434 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16435 cu
->partial_dies
= NULL
;
16438 /* Free all cached compilation units. */
16441 free_cached_comp_units (void *data
)
16443 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16445 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16446 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16447 while (per_cu
!= NULL
)
16449 struct dwarf2_per_cu_data
*next_cu
;
16451 next_cu
= per_cu
->cu
->read_in_chain
;
16453 free_heap_comp_unit (per_cu
->cu
);
16454 *last_chain
= next_cu
;
16460 /* Increase the age counter on each cached compilation unit, and free
16461 any that are too old. */
16464 age_cached_comp_units (void)
16466 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16468 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16469 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16470 while (per_cu
!= NULL
)
16472 per_cu
->cu
->last_used
++;
16473 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16474 dwarf2_mark (per_cu
->cu
);
16475 per_cu
= per_cu
->cu
->read_in_chain
;
16478 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16479 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16480 while (per_cu
!= NULL
)
16482 struct dwarf2_per_cu_data
*next_cu
;
16484 next_cu
= per_cu
->cu
->read_in_chain
;
16486 if (!per_cu
->cu
->mark
)
16488 free_heap_comp_unit (per_cu
->cu
);
16489 *last_chain
= next_cu
;
16492 last_chain
= &per_cu
->cu
->read_in_chain
;
16498 /* Remove a single compilation unit from the cache. */
16501 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
16503 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16505 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16506 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16507 while (per_cu
!= NULL
)
16509 struct dwarf2_per_cu_data
*next_cu
;
16511 next_cu
= per_cu
->cu
->read_in_chain
;
16513 if (per_cu
== target_per_cu
)
16515 free_heap_comp_unit (per_cu
->cu
);
16517 *last_chain
= next_cu
;
16521 last_chain
= &per_cu
->cu
->read_in_chain
;
16527 /* Release all extra memory associated with OBJFILE. */
16530 dwarf2_free_objfile (struct objfile
*objfile
)
16532 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16534 if (dwarf2_per_objfile
== NULL
)
16537 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16538 free_cached_comp_units (NULL
);
16540 if (dwarf2_per_objfile
->quick_file_names_table
)
16541 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16543 /* Everything else should be on the objfile obstack. */
16546 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
16547 We store these in a hash table separate from the DIEs, and preserve them
16548 when the DIEs are flushed out of cache.
16550 The CU "per_cu" pointer is needed because offset alone is not enough to
16551 uniquely identify the type. A file may have multiple .debug_types sections,
16552 or the type may come from a DWO file. We have to use something in
16553 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
16554 routine, get_die_type_at_offset, from outside this file, and thus won't
16555 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
16558 struct dwarf2_per_cu_offset_and_type
16560 const struct dwarf2_per_cu_data
*per_cu
;
16561 sect_offset offset
;
16565 /* Hash function for a dwarf2_per_cu_offset_and_type. */
16568 per_cu_offset_and_type_hash (const void *item
)
16570 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
16572 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
16575 /* Equality function for a dwarf2_per_cu_offset_and_type. */
16578 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16580 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
16581 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
16583 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
16584 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
16587 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16588 table if necessary. For convenience, return TYPE.
16590 The DIEs reading must have careful ordering to:
16591 * Not cause infite loops trying to read in DIEs as a prerequisite for
16592 reading current DIE.
16593 * Not trying to dereference contents of still incompletely read in types
16594 while reading in other DIEs.
16595 * Enable referencing still incompletely read in types just by a pointer to
16596 the type without accessing its fields.
16598 Therefore caller should follow these rules:
16599 * Try to fetch any prerequisite types we may need to build this DIE type
16600 before building the type and calling set_die_type.
16601 * After building type call set_die_type for current DIE as soon as
16602 possible before fetching more types to complete the current type.
16603 * Make the type as complete as possible before fetching more types. */
16605 static struct type
*
16606 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16608 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
16609 struct objfile
*objfile
= cu
->objfile
;
16611 /* For Ada types, make sure that the gnat-specific data is always
16612 initialized (if not already set). There are a few types where
16613 we should not be doing so, because the type-specific area is
16614 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16615 where the type-specific area is used to store the floatformat).
16616 But this is not a problem, because the gnat-specific information
16617 is actually not needed for these types. */
16618 if (need_gnat_info (cu
)
16619 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16620 && TYPE_CODE (type
) != TYPE_CODE_FLT
16621 && !HAVE_GNAT_AUX_INFO (type
))
16622 INIT_GNAT_SPECIFIC (type
);
16624 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16626 dwarf2_per_objfile
->die_type_hash
=
16627 htab_create_alloc_ex (127,
16628 per_cu_offset_and_type_hash
,
16629 per_cu_offset_and_type_eq
,
16631 &objfile
->objfile_obstack
,
16632 hashtab_obstack_allocate
,
16633 dummy_obstack_deallocate
);
16636 ofs
.per_cu
= cu
->per_cu
;
16637 ofs
.offset
= die
->offset
;
16639 slot
= (struct dwarf2_per_cu_offset_and_type
**)
16640 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
16642 complaint (&symfile_complaints
,
16643 _("A problem internal to GDB: DIE 0x%x has type already set"),
16644 die
->offset
.sect_off
);
16645 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16650 /* Look up the type for the die at OFFSET in the appropriate type_hash
16651 table, or return NULL if the die does not have a saved type. */
16653 static struct type
*
16654 get_die_type_at_offset (sect_offset offset
,
16655 struct dwarf2_per_cu_data
*per_cu
)
16657 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
16659 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16662 ofs
.per_cu
= per_cu
;
16663 ofs
.offset
= offset
;
16664 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
16671 /* Look up the type for DIE in the appropriate type_hash table,
16672 or return NULL if DIE does not have a saved type. */
16674 static struct type
*
16675 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16677 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16680 /* Add a dependence relationship from CU to REF_PER_CU. */
16683 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16684 struct dwarf2_per_cu_data
*ref_per_cu
)
16688 if (cu
->dependencies
== NULL
)
16690 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16691 NULL
, &cu
->comp_unit_obstack
,
16692 hashtab_obstack_allocate
,
16693 dummy_obstack_deallocate
);
16695 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16697 *slot
= ref_per_cu
;
16700 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16701 Set the mark field in every compilation unit in the
16702 cache that we must keep because we are keeping CU. */
16705 dwarf2_mark_helper (void **slot
, void *data
)
16707 struct dwarf2_per_cu_data
*per_cu
;
16709 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16711 /* cu->dependencies references may not yet have been ever read if QUIT aborts
16712 reading of the chain. As such dependencies remain valid it is not much
16713 useful to track and undo them during QUIT cleanups. */
16714 if (per_cu
->cu
== NULL
)
16717 if (per_cu
->cu
->mark
)
16719 per_cu
->cu
->mark
= 1;
16721 if (per_cu
->cu
->dependencies
!= NULL
)
16722 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16727 /* Set the mark field in CU and in every other compilation unit in the
16728 cache that we must keep because we are keeping CU. */
16731 dwarf2_mark (struct dwarf2_cu
*cu
)
16736 if (cu
->dependencies
!= NULL
)
16737 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
16741 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
16745 per_cu
->cu
->mark
= 0;
16746 per_cu
= per_cu
->cu
->read_in_chain
;
16750 /* Trivial hash function for partial_die_info: the hash value of a DIE
16751 is its offset in .debug_info for this objfile. */
16754 partial_die_hash (const void *item
)
16756 const struct partial_die_info
*part_die
= item
;
16758 return part_die
->offset
.sect_off
;
16761 /* Trivial comparison function for partial_die_info structures: two DIEs
16762 are equal if they have the same offset. */
16765 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
16767 const struct partial_die_info
*part_die_lhs
= item_lhs
;
16768 const struct partial_die_info
*part_die_rhs
= item_rhs
;
16770 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
16773 static struct cmd_list_element
*set_dwarf2_cmdlist
;
16774 static struct cmd_list_element
*show_dwarf2_cmdlist
;
16777 set_dwarf2_cmd (char *args
, int from_tty
)
16779 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
16783 show_dwarf2_cmd (char *args
, int from_tty
)
16785 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
16788 /* If section described by INFO was mmapped, munmap it now. */
16791 munmap_section_buffer (struct dwarf2_section_info
*info
)
16793 if (info
->map_addr
!= NULL
)
16798 res
= munmap (info
->map_addr
, info
->map_len
);
16799 gdb_assert (res
== 0);
16801 /* Without HAVE_MMAP, we should never be here to begin with. */
16802 gdb_assert_not_reached ("no mmap support");
16807 /* munmap debug sections for OBJFILE, if necessary. */
16810 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
16812 struct dwarf2_per_objfile
*data
= d
;
16814 struct dwarf2_section_info
*section
;
16816 /* This is sorted according to the order they're defined in to make it easier
16817 to keep in sync. */
16818 munmap_section_buffer (&data
->info
);
16819 munmap_section_buffer (&data
->abbrev
);
16820 munmap_section_buffer (&data
->line
);
16821 munmap_section_buffer (&data
->loc
);
16822 munmap_section_buffer (&data
->macinfo
);
16823 munmap_section_buffer (&data
->macro
);
16824 munmap_section_buffer (&data
->str
);
16825 munmap_section_buffer (&data
->ranges
);
16826 munmap_section_buffer (&data
->addr
);
16827 munmap_section_buffer (&data
->frame
);
16828 munmap_section_buffer (&data
->eh_frame
);
16829 munmap_section_buffer (&data
->gdb_index
);
16832 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
16834 munmap_section_buffer (section
);
16836 VEC_free (dwarf2_section_info_def
, data
->types
);
16838 if (data
->dwo_files
)
16839 free_dwo_files (data
->dwo_files
, objfile
);
16843 /* The "save gdb-index" command. */
16845 /* The contents of the hash table we create when building the string
16847 struct strtab_entry
16849 offset_type offset
;
16853 /* Hash function for a strtab_entry.
16855 Function is used only during write_hash_table so no index format backward
16856 compatibility is needed. */
16859 hash_strtab_entry (const void *e
)
16861 const struct strtab_entry
*entry
= e
;
16862 return mapped_index_string_hash (INT_MAX
, entry
->str
);
16865 /* Equality function for a strtab_entry. */
16868 eq_strtab_entry (const void *a
, const void *b
)
16870 const struct strtab_entry
*ea
= a
;
16871 const struct strtab_entry
*eb
= b
;
16872 return !strcmp (ea
->str
, eb
->str
);
16875 /* Create a strtab_entry hash table. */
16878 create_strtab (void)
16880 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
16881 xfree
, xcalloc
, xfree
);
16884 /* Add a string to the constant pool. Return the string's offset in
16888 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
16891 struct strtab_entry entry
;
16892 struct strtab_entry
*result
;
16895 slot
= htab_find_slot (table
, &entry
, INSERT
);
16900 result
= XNEW (struct strtab_entry
);
16901 result
->offset
= obstack_object_size (cpool
);
16903 obstack_grow_str0 (cpool
, str
);
16906 return result
->offset
;
16909 /* An entry in the symbol table. */
16910 struct symtab_index_entry
16912 /* The name of the symbol. */
16914 /* The offset of the name in the constant pool. */
16915 offset_type index_offset
;
16916 /* A sorted vector of the indices of all the CUs that hold an object
16918 VEC (offset_type
) *cu_indices
;
16921 /* The symbol table. This is a power-of-2-sized hash table. */
16922 struct mapped_symtab
16924 offset_type n_elements
;
16926 struct symtab_index_entry
**data
;
16929 /* Hash function for a symtab_index_entry. */
16932 hash_symtab_entry (const void *e
)
16934 const struct symtab_index_entry
*entry
= e
;
16935 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
16936 sizeof (offset_type
) * VEC_length (offset_type
,
16937 entry
->cu_indices
),
16941 /* Equality function for a symtab_index_entry. */
16944 eq_symtab_entry (const void *a
, const void *b
)
16946 const struct symtab_index_entry
*ea
= a
;
16947 const struct symtab_index_entry
*eb
= b
;
16948 int len
= VEC_length (offset_type
, ea
->cu_indices
);
16949 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
16951 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
16952 VEC_address (offset_type
, eb
->cu_indices
),
16953 sizeof (offset_type
) * len
);
16956 /* Destroy a symtab_index_entry. */
16959 delete_symtab_entry (void *p
)
16961 struct symtab_index_entry
*entry
= p
;
16962 VEC_free (offset_type
, entry
->cu_indices
);
16966 /* Create a hash table holding symtab_index_entry objects. */
16969 create_symbol_hash_table (void)
16971 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
16972 delete_symtab_entry
, xcalloc
, xfree
);
16975 /* Create a new mapped symtab object. */
16977 static struct mapped_symtab
*
16978 create_mapped_symtab (void)
16980 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
16981 symtab
->n_elements
= 0;
16982 symtab
->size
= 1024;
16983 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
16987 /* Destroy a mapped_symtab. */
16990 cleanup_mapped_symtab (void *p
)
16992 struct mapped_symtab
*symtab
= p
;
16993 /* The contents of the array are freed when the other hash table is
16995 xfree (symtab
->data
);
16999 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17002 Function is used only during write_hash_table so no index format backward
17003 compatibility is needed. */
17005 static struct symtab_index_entry
**
17006 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17008 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17010 index
= hash
& (symtab
->size
- 1);
17011 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17015 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17016 return &symtab
->data
[index
];
17017 index
= (index
+ step
) & (symtab
->size
- 1);
17021 /* Expand SYMTAB's hash table. */
17024 hash_expand (struct mapped_symtab
*symtab
)
17026 offset_type old_size
= symtab
->size
;
17028 struct symtab_index_entry
**old_entries
= symtab
->data
;
17031 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17033 for (i
= 0; i
< old_size
; ++i
)
17035 if (old_entries
[i
])
17037 struct symtab_index_entry
**slot
= find_slot (symtab
,
17038 old_entries
[i
]->name
);
17039 *slot
= old_entries
[i
];
17043 xfree (old_entries
);
17046 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
17047 is the index of the CU in which the symbol appears. */
17050 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17051 offset_type cu_index
)
17053 struct symtab_index_entry
**slot
;
17055 ++symtab
->n_elements
;
17056 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17057 hash_expand (symtab
);
17059 slot
= find_slot (symtab
, name
);
17062 *slot
= XNEW (struct symtab_index_entry
);
17063 (*slot
)->name
= name
;
17064 (*slot
)->cu_indices
= NULL
;
17066 /* Don't push an index twice. Due to how we add entries we only
17067 have to check the last one. */
17068 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
17069 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
17070 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
17073 /* Add a vector of indices to the constant pool. */
17076 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17077 struct symtab_index_entry
*entry
)
17081 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17084 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17085 offset_type val
= MAYBE_SWAP (len
);
17090 entry
->index_offset
= obstack_object_size (cpool
);
17092 obstack_grow (cpool
, &val
, sizeof (val
));
17094 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17097 val
= MAYBE_SWAP (iter
);
17098 obstack_grow (cpool
, &val
, sizeof (val
));
17103 struct symtab_index_entry
*old_entry
= *slot
;
17104 entry
->index_offset
= old_entry
->index_offset
;
17107 return entry
->index_offset
;
17110 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17111 constant pool entries going into the obstack CPOOL. */
17114 write_hash_table (struct mapped_symtab
*symtab
,
17115 struct obstack
*output
, struct obstack
*cpool
)
17118 htab_t symbol_hash_table
;
17121 symbol_hash_table
= create_symbol_hash_table ();
17122 str_table
= create_strtab ();
17124 /* We add all the index vectors to the constant pool first, to
17125 ensure alignment is ok. */
17126 for (i
= 0; i
< symtab
->size
; ++i
)
17128 if (symtab
->data
[i
])
17129 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17132 /* Now write out the hash table. */
17133 for (i
= 0; i
< symtab
->size
; ++i
)
17135 offset_type str_off
, vec_off
;
17137 if (symtab
->data
[i
])
17139 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17140 vec_off
= symtab
->data
[i
]->index_offset
;
17144 /* While 0 is a valid constant pool index, it is not valid
17145 to have 0 for both offsets. */
17150 str_off
= MAYBE_SWAP (str_off
);
17151 vec_off
= MAYBE_SWAP (vec_off
);
17153 obstack_grow (output
, &str_off
, sizeof (str_off
));
17154 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17157 htab_delete (str_table
);
17158 htab_delete (symbol_hash_table
);
17161 /* Struct to map psymtab to CU index in the index file. */
17162 struct psymtab_cu_index_map
17164 struct partial_symtab
*psymtab
;
17165 unsigned int cu_index
;
17169 hash_psymtab_cu_index (const void *item
)
17171 const struct psymtab_cu_index_map
*map
= item
;
17173 return htab_hash_pointer (map
->psymtab
);
17177 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17179 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17180 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17182 return lhs
->psymtab
== rhs
->psymtab
;
17185 /* Helper struct for building the address table. */
17186 struct addrmap_index_data
17188 struct objfile
*objfile
;
17189 struct obstack
*addr_obstack
;
17190 htab_t cu_index_htab
;
17192 /* Non-zero if the previous_* fields are valid.
17193 We can't write an entry until we see the next entry (since it is only then
17194 that we know the end of the entry). */
17195 int previous_valid
;
17196 /* Index of the CU in the table of all CUs in the index file. */
17197 unsigned int previous_cu_index
;
17198 /* Start address of the CU. */
17199 CORE_ADDR previous_cu_start
;
17202 /* Write an address entry to OBSTACK. */
17205 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17206 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17208 offset_type cu_index_to_write
;
17210 CORE_ADDR baseaddr
;
17212 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17214 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17215 obstack_grow (obstack
, addr
, 8);
17216 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17217 obstack_grow (obstack
, addr
, 8);
17218 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17219 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17222 /* Worker function for traversing an addrmap to build the address table. */
17225 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17227 struct addrmap_index_data
*data
= datap
;
17228 struct partial_symtab
*pst
= obj
;
17229 offset_type cu_index
;
17232 if (data
->previous_valid
)
17233 add_address_entry (data
->objfile
, data
->addr_obstack
,
17234 data
->previous_cu_start
, start_addr
,
17235 data
->previous_cu_index
);
17237 data
->previous_cu_start
= start_addr
;
17240 struct psymtab_cu_index_map find_map
, *map
;
17241 find_map
.psymtab
= pst
;
17242 map
= htab_find (data
->cu_index_htab
, &find_map
);
17243 gdb_assert (map
!= NULL
);
17244 data
->previous_cu_index
= map
->cu_index
;
17245 data
->previous_valid
= 1;
17248 data
->previous_valid
= 0;
17253 /* Write OBJFILE's address map to OBSTACK.
17254 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17255 in the index file. */
17258 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17259 htab_t cu_index_htab
)
17261 struct addrmap_index_data addrmap_index_data
;
17263 /* When writing the address table, we have to cope with the fact that
17264 the addrmap iterator only provides the start of a region; we have to
17265 wait until the next invocation to get the start of the next region. */
17267 addrmap_index_data
.objfile
= objfile
;
17268 addrmap_index_data
.addr_obstack
= obstack
;
17269 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17270 addrmap_index_data
.previous_valid
= 0;
17272 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17273 &addrmap_index_data
);
17275 /* It's highly unlikely the last entry (end address = 0xff...ff)
17276 is valid, but we should still handle it.
17277 The end address is recorded as the start of the next region, but that
17278 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17280 if (addrmap_index_data
.previous_valid
)
17281 add_address_entry (objfile
, obstack
,
17282 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17283 addrmap_index_data
.previous_cu_index
);
17286 /* Add a list of partial symbols to SYMTAB. */
17289 write_psymbols (struct mapped_symtab
*symtab
,
17291 struct partial_symbol
**psymp
,
17293 offset_type cu_index
,
17296 for (; count
-- > 0; ++psymp
)
17298 void **slot
, *lookup
;
17300 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17301 error (_("Ada is not currently supported by the index"));
17303 /* We only want to add a given psymbol once. However, we also
17304 want to account for whether it is global or static. So, we
17305 may add it twice, using slightly different values. */
17308 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17310 lookup
= (void *) val
;
17315 /* Only add a given psymbol once. */
17316 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17320 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17325 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17326 exception if there is an error. */
17329 write_obstack (FILE *file
, struct obstack
*obstack
)
17331 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17333 != obstack_object_size (obstack
))
17334 error (_("couldn't data write to file"));
17337 /* Unlink a file if the argument is not NULL. */
17340 unlink_if_set (void *p
)
17342 char **filename
= p
;
17344 unlink (*filename
);
17347 /* A helper struct used when iterating over debug_types. */
17348 struct signatured_type_index_data
17350 struct objfile
*objfile
;
17351 struct mapped_symtab
*symtab
;
17352 struct obstack
*types_list
;
17357 /* A helper function that writes a single signatured_type to an
17361 write_one_signatured_type (void **slot
, void *d
)
17363 struct signatured_type_index_data
*info
= d
;
17364 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17365 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17366 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17369 write_psymbols (info
->symtab
,
17371 info
->objfile
->global_psymbols
.list
17372 + psymtab
->globals_offset
,
17373 psymtab
->n_global_syms
, info
->cu_index
,
17375 write_psymbols (info
->symtab
,
17377 info
->objfile
->static_psymbols
.list
17378 + psymtab
->statics_offset
,
17379 psymtab
->n_static_syms
, info
->cu_index
,
17382 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17383 entry
->per_cu
.offset
.sect_off
);
17384 obstack_grow (info
->types_list
, val
, 8);
17385 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17386 entry
->type_offset_in_tu
.cu_off
);
17387 obstack_grow (info
->types_list
, val
, 8);
17388 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17389 obstack_grow (info
->types_list
, val
, 8);
17396 /* Create an index file for OBJFILE in the directory DIR. */
17399 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17401 struct cleanup
*cleanup
;
17402 char *filename
, *cleanup_filename
;
17403 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17404 struct obstack cu_list
, types_cu_list
;
17407 struct mapped_symtab
*symtab
;
17408 offset_type val
, size_of_contents
, total_len
;
17412 htab_t cu_index_htab
;
17413 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17415 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17418 if (dwarf2_per_objfile
->using_index
)
17419 error (_("Cannot use an index to create the index"));
17421 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17422 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17424 if (stat (objfile
->name
, &st
) < 0)
17425 perror_with_name (objfile
->name
);
17427 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17428 INDEX_SUFFIX
, (char *) NULL
);
17429 cleanup
= make_cleanup (xfree
, filename
);
17431 out_file
= fopen (filename
, "wb");
17433 error (_("Can't open `%s' for writing"), filename
);
17435 cleanup_filename
= filename
;
17436 make_cleanup (unlink_if_set
, &cleanup_filename
);
17438 symtab
= create_mapped_symtab ();
17439 make_cleanup (cleanup_mapped_symtab
, symtab
);
17441 obstack_init (&addr_obstack
);
17442 make_cleanup_obstack_free (&addr_obstack
);
17444 obstack_init (&cu_list
);
17445 make_cleanup_obstack_free (&cu_list
);
17447 obstack_init (&types_cu_list
);
17448 make_cleanup_obstack_free (&types_cu_list
);
17450 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17451 NULL
, xcalloc
, xfree
);
17452 make_cleanup_htab_delete (psyms_seen
);
17454 /* While we're scanning CU's create a table that maps a psymtab pointer
17455 (which is what addrmap records) to its index (which is what is recorded
17456 in the index file). This will later be needed to write the address
17458 cu_index_htab
= htab_create_alloc (100,
17459 hash_psymtab_cu_index
,
17460 eq_psymtab_cu_index
,
17461 NULL
, xcalloc
, xfree
);
17462 make_cleanup_htab_delete (cu_index_htab
);
17463 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17464 xmalloc (sizeof (struct psymtab_cu_index_map
)
17465 * dwarf2_per_objfile
->n_comp_units
);
17466 make_cleanup (xfree
, psymtab_cu_index_map
);
17468 /* The CU list is already sorted, so we don't need to do additional
17469 work here. Also, the debug_types entries do not appear in
17470 all_comp_units, but only in their own hash table. */
17471 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17473 struct dwarf2_per_cu_data
*per_cu
17474 = dwarf2_per_objfile
->all_comp_units
[i
];
17475 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17477 struct psymtab_cu_index_map
*map
;
17480 write_psymbols (symtab
,
17482 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17483 psymtab
->n_global_syms
, i
,
17485 write_psymbols (symtab
,
17487 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17488 psymtab
->n_static_syms
, i
,
17491 map
= &psymtab_cu_index_map
[i
];
17492 map
->psymtab
= psymtab
;
17494 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17495 gdb_assert (slot
!= NULL
);
17496 gdb_assert (*slot
== NULL
);
17499 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17500 per_cu
->offset
.sect_off
);
17501 obstack_grow (&cu_list
, val
, 8);
17502 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17503 obstack_grow (&cu_list
, val
, 8);
17506 /* Dump the address map. */
17507 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17509 /* Write out the .debug_type entries, if any. */
17510 if (dwarf2_per_objfile
->signatured_types
)
17512 struct signatured_type_index_data sig_data
;
17514 sig_data
.objfile
= objfile
;
17515 sig_data
.symtab
= symtab
;
17516 sig_data
.types_list
= &types_cu_list
;
17517 sig_data
.psyms_seen
= psyms_seen
;
17518 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17519 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17520 write_one_signatured_type
, &sig_data
);
17523 obstack_init (&constant_pool
);
17524 make_cleanup_obstack_free (&constant_pool
);
17525 obstack_init (&symtab_obstack
);
17526 make_cleanup_obstack_free (&symtab_obstack
);
17527 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17529 obstack_init (&contents
);
17530 make_cleanup_obstack_free (&contents
);
17531 size_of_contents
= 6 * sizeof (offset_type
);
17532 total_len
= size_of_contents
;
17534 /* The version number. */
17535 val
= MAYBE_SWAP (6);
17536 obstack_grow (&contents
, &val
, sizeof (val
));
17538 /* The offset of the CU list from the start of the file. */
17539 val
= MAYBE_SWAP (total_len
);
17540 obstack_grow (&contents
, &val
, sizeof (val
));
17541 total_len
+= obstack_object_size (&cu_list
);
17543 /* The offset of the types CU list from the start of the file. */
17544 val
= MAYBE_SWAP (total_len
);
17545 obstack_grow (&contents
, &val
, sizeof (val
));
17546 total_len
+= obstack_object_size (&types_cu_list
);
17548 /* The offset of the address table from the start of the file. */
17549 val
= MAYBE_SWAP (total_len
);
17550 obstack_grow (&contents
, &val
, sizeof (val
));
17551 total_len
+= obstack_object_size (&addr_obstack
);
17553 /* The offset of the symbol table from the start of the file. */
17554 val
= MAYBE_SWAP (total_len
);
17555 obstack_grow (&contents
, &val
, sizeof (val
));
17556 total_len
+= obstack_object_size (&symtab_obstack
);
17558 /* The offset of the constant pool from the start of the file. */
17559 val
= MAYBE_SWAP (total_len
);
17560 obstack_grow (&contents
, &val
, sizeof (val
));
17561 total_len
+= obstack_object_size (&constant_pool
);
17563 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17565 write_obstack (out_file
, &contents
);
17566 write_obstack (out_file
, &cu_list
);
17567 write_obstack (out_file
, &types_cu_list
);
17568 write_obstack (out_file
, &addr_obstack
);
17569 write_obstack (out_file
, &symtab_obstack
);
17570 write_obstack (out_file
, &constant_pool
);
17574 /* We want to keep the file, so we set cleanup_filename to NULL
17575 here. See unlink_if_set. */
17576 cleanup_filename
= NULL
;
17578 do_cleanups (cleanup
);
17581 /* Implementation of the `save gdb-index' command.
17583 Note that the file format used by this command is documented in the
17584 GDB manual. Any changes here must be documented there. */
17587 save_gdb_index_command (char *arg
, int from_tty
)
17589 struct objfile
*objfile
;
17592 error (_("usage: save gdb-index DIRECTORY"));
17594 ALL_OBJFILES (objfile
)
17598 /* If the objfile does not correspond to an actual file, skip it. */
17599 if (stat (objfile
->name
, &st
) < 0)
17602 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17603 if (dwarf2_per_objfile
)
17605 volatile struct gdb_exception except
;
17607 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17609 write_psymtabs_to_index (objfile
, arg
);
17611 if (except
.reason
< 0)
17612 exception_fprintf (gdb_stderr
, except
,
17613 _("Error while writing index for `%s': "),
17621 int dwarf2_always_disassemble
;
17624 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17625 struct cmd_list_element
*c
, const char *value
)
17627 fprintf_filtered (file
,
17628 _("Whether to always disassemble "
17629 "DWARF expressions is %s.\n"),
17634 show_check_physname (struct ui_file
*file
, int from_tty
,
17635 struct cmd_list_element
*c
, const char *value
)
17637 fprintf_filtered (file
,
17638 _("Whether to check \"physname\" is %s.\n"),
17642 void _initialize_dwarf2_read (void);
17645 _initialize_dwarf2_read (void)
17647 struct cmd_list_element
*c
;
17649 dwarf2_objfile_data_key
17650 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17652 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17653 Set DWARF 2 specific variables.\n\
17654 Configure DWARF 2 variables such as the cache size"),
17655 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17656 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17658 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17659 Show DWARF 2 specific variables\n\
17660 Show DWARF 2 variables such as the cache size"),
17661 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17662 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17664 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17665 &dwarf2_max_cache_age
, _("\
17666 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17667 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17668 A higher limit means that cached compilation units will be stored\n\
17669 in memory longer, and more total memory will be used. Zero disables\n\
17670 caching, which can slow down startup."),
17672 show_dwarf2_max_cache_age
,
17673 &set_dwarf2_cmdlist
,
17674 &show_dwarf2_cmdlist
);
17676 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17677 &dwarf2_always_disassemble
, _("\
17678 Set whether `info address' always disassembles DWARF expressions."), _("\
17679 Show whether `info address' always disassembles DWARF expressions."), _("\
17680 When enabled, DWARF expressions are always printed in an assembly-like\n\
17681 syntax. When disabled, expressions will be printed in a more\n\
17682 conversational style, when possible."),
17684 show_dwarf2_always_disassemble
,
17685 &set_dwarf2_cmdlist
,
17686 &show_dwarf2_cmdlist
);
17688 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17689 Set debugging of the dwarf2 DIE reader."), _("\
17690 Show debugging of the dwarf2 DIE reader."), _("\
17691 When enabled (non-zero), DIEs are dumped after they are read in.\n\
17692 The value is the maximum depth to print."),
17695 &setdebuglist
, &showdebuglist
);
17697 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
17698 Set cross-checking of \"physname\" code against demangler."), _("\
17699 Show cross-checking of \"physname\" code against demangler."), _("\
17700 When enabled, GDB's internal \"physname\" code is checked against\n\
17702 NULL
, show_check_physname
,
17703 &setdebuglist
, &showdebuglist
);
17705 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
17707 Save a gdb-index file.\n\
17708 Usage: save gdb-index DIRECTORY"),
17710 set_cmd_completer (c
, filename_completer
);