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 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
152 DEF_VEC_P (dwarf2_per_cu_ptr
);
154 /* Collection of data recorded per objfile.
155 This hangs off of dwarf2_objfile_data_key. */
157 struct dwarf2_per_objfile
159 struct dwarf2_section_info info
;
160 struct dwarf2_section_info abbrev
;
161 struct dwarf2_section_info line
;
162 struct dwarf2_section_info loc
;
163 struct dwarf2_section_info macinfo
;
164 struct dwarf2_section_info macro
;
165 struct dwarf2_section_info str
;
166 struct dwarf2_section_info ranges
;
167 struct dwarf2_section_info addr
;
168 struct dwarf2_section_info frame
;
169 struct dwarf2_section_info eh_frame
;
170 struct dwarf2_section_info gdb_index
;
172 VEC (dwarf2_section_info_def
) *types
;
175 struct objfile
*objfile
;
177 /* Table of all the compilation units. This is used to locate
178 the target compilation unit of a particular reference. */
179 struct dwarf2_per_cu_data
**all_comp_units
;
181 /* The number of compilation units in ALL_COMP_UNITS. */
184 /* The number of .debug_types-related CUs. */
187 /* The .debug_types-related CUs (TUs). */
188 struct dwarf2_per_cu_data
**all_type_units
;
190 /* A chain of compilation units that are currently read in, so that
191 they can be freed later. */
192 struct dwarf2_per_cu_data
*read_in_chain
;
194 /* A table mapping .debug_types signatures to its signatured_type entry.
195 This is NULL if the .debug_types section hasn't been read in yet. */
196 htab_t signatured_types
;
198 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
199 This is NULL if the table hasn't been allocated yet. */
202 /* A flag indicating wether this objfile has a section loaded at a
204 int has_section_at_zero
;
206 /* True if we are using the mapped index,
207 or we are faking it for OBJF_READNOW's sake. */
208 unsigned char using_index
;
210 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
211 struct mapped_index
*index_table
;
213 /* When using index_table, this keeps track of all quick_file_names entries.
214 TUs can share line table entries with CUs or other TUs, and there can be
215 a lot more TUs than unique line tables, so we maintain a separate table
216 of all line table entries to support the sharing. */
217 htab_t quick_file_names_table
;
219 /* Set during partial symbol reading, to prevent queueing of full
221 int reading_partial_symbols
;
223 /* Table mapping type DIEs to their struct type *.
224 This is NULL if not allocated yet.
225 The mapping is done via (CU/TU signature + DIE offset) -> type. */
226 htab_t die_type_hash
;
228 /* The CUs we recently read. */
229 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
232 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
234 /* Default names of the debugging sections. */
236 /* Note that if the debugging section has been compressed, it might
237 have a name like .zdebug_info. */
239 static const struct dwarf2_debug_sections dwarf2_elf_names
=
241 { ".debug_info", ".zdebug_info" },
242 { ".debug_abbrev", ".zdebug_abbrev" },
243 { ".debug_line", ".zdebug_line" },
244 { ".debug_loc", ".zdebug_loc" },
245 { ".debug_macinfo", ".zdebug_macinfo" },
246 { ".debug_macro", ".zdebug_macro" },
247 { ".debug_str", ".zdebug_str" },
248 { ".debug_ranges", ".zdebug_ranges" },
249 { ".debug_types", ".zdebug_types" },
250 { ".debug_addr", ".zdebug_addr" },
251 { ".debug_frame", ".zdebug_frame" },
252 { ".eh_frame", NULL
},
253 { ".gdb_index", ".zgdb_index" },
257 /* List of DWO sections. */
259 static const struct dwo_section_names
261 struct dwarf2_section_names abbrev_dwo
;
262 struct dwarf2_section_names info_dwo
;
263 struct dwarf2_section_names line_dwo
;
264 struct dwarf2_section_names loc_dwo
;
265 struct dwarf2_section_names str_dwo
;
266 struct dwarf2_section_names str_offsets_dwo
;
267 struct dwarf2_section_names types_dwo
;
271 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
272 { ".debug_info.dwo", ".zdebug_info.dwo" },
273 { ".debug_line.dwo", ".zdebug_line.dwo" },
274 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
275 { ".debug_str.dwo", ".zdebug_str.dwo" },
276 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
277 { ".debug_types.dwo", ".zdebug_types.dwo" },
280 /* local data types */
282 /* We hold several abbreviation tables in memory at the same time. */
283 #ifndef ABBREV_HASH_SIZE
284 #define ABBREV_HASH_SIZE 121
287 /* The data in a compilation unit header, after target2host
288 translation, looks like this. */
289 struct comp_unit_head
293 unsigned char addr_size
;
294 unsigned char signed_addr_p
;
295 sect_offset abbrev_offset
;
297 /* Size of file offsets; either 4 or 8. */
298 unsigned int offset_size
;
300 /* Size of the length field; either 4 or 12. */
301 unsigned int initial_length_size
;
303 /* Offset to the first byte of this compilation unit header in the
304 .debug_info section, for resolving relative reference dies. */
307 /* Offset to first die in this cu from the start of the cu.
308 This will be the first byte following the compilation unit header. */
309 cu_offset first_die_offset
;
312 /* Type used for delaying computation of method physnames.
313 See comments for compute_delayed_physnames. */
314 struct delayed_method_info
316 /* The type to which the method is attached, i.e., its parent class. */
319 /* The index of the method in the type's function fieldlists. */
322 /* The index of the method in the fieldlist. */
325 /* The name of the DIE. */
328 /* The DIE associated with this method. */
329 struct die_info
*die
;
332 typedef struct delayed_method_info delayed_method_info
;
333 DEF_VEC_O (delayed_method_info
);
335 /* Internal state when decoding a particular compilation unit. */
338 /* The objfile containing this compilation unit. */
339 struct objfile
*objfile
;
341 /* The header of the compilation unit. */
342 struct comp_unit_head header
;
344 /* Base address of this compilation unit. */
345 CORE_ADDR base_address
;
347 /* Non-zero if base_address has been set. */
350 /* The language we are debugging. */
351 enum language language
;
352 const struct language_defn
*language_defn
;
354 const char *producer
;
356 /* The generic symbol table building routines have separate lists for
357 file scope symbols and all all other scopes (local scopes). So
358 we need to select the right one to pass to add_symbol_to_list().
359 We do it by keeping a pointer to the correct list in list_in_scope.
361 FIXME: The original dwarf code just treated the file scope as the
362 first local scope, and all other local scopes as nested local
363 scopes, and worked fine. Check to see if we really need to
364 distinguish these in buildsym.c. */
365 struct pending
**list_in_scope
;
367 /* DWARF abbreviation table associated with this compilation unit. */
368 struct abbrev_info
**dwarf2_abbrevs
;
370 /* Storage for the abbrev table. */
371 struct obstack abbrev_obstack
;
373 /* Hash table holding all the loaded partial DIEs
374 with partial_die->offset.SECT_OFF as hash. */
377 /* Storage for things with the same lifetime as this read-in compilation
378 unit, including partial DIEs. */
379 struct obstack comp_unit_obstack
;
381 /* When multiple dwarf2_cu structures are living in memory, this field
382 chains them all together, so that they can be released efficiently.
383 We will probably also want a generation counter so that most-recently-used
384 compilation units are cached... */
385 struct dwarf2_per_cu_data
*read_in_chain
;
387 /* Backchain to our per_cu entry if the tree has been built. */
388 struct dwarf2_per_cu_data
*per_cu
;
390 /* How many compilation units ago was this CU last referenced? */
393 /* A hash table of DIE cu_offset for following references with
394 die_info->offset.sect_off as hash. */
397 /* Full DIEs if read in. */
398 struct die_info
*dies
;
400 /* A set of pointers to dwarf2_per_cu_data objects for compilation
401 units referenced by this one. Only set during full symbol processing;
402 partial symbol tables do not have dependencies. */
405 /* Header data from the line table, during full symbol processing. */
406 struct line_header
*line_header
;
408 /* A list of methods which need to have physnames computed
409 after all type information has been read. */
410 VEC (delayed_method_info
) *method_list
;
412 /* To be copied to symtab->call_site_htab. */
413 htab_t call_site_htab
;
415 /* Non-NULL if this CU came from a DWO file. */
416 struct dwo_unit
*dwo_unit
;
418 /* The DW_AT_addr_base attribute if present, zero otherwise
419 (zero is a valid value though).
420 Note this value comes from the stub CU/TU's DIE. */
423 /* Mark used when releasing cached dies. */
424 unsigned int mark
: 1;
426 /* This CU references .debug_loc. See the symtab->locations_valid field.
427 This test is imperfect as there may exist optimized debug code not using
428 any location list and still facing inlining issues if handled as
429 unoptimized code. For a future better test see GCC PR other/32998. */
430 unsigned int has_loclist
: 1;
432 /* These cache the results of producer_is_gxx_lt_4_6.
433 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
434 information is cached because profiling CU expansion showed
435 excessive time spent in producer_is_gxx_lt_4_6. */
436 unsigned int checked_producer
: 1;
437 unsigned int producer_is_gxx_lt_4_6
: 1;
439 /* Non-zero if DW_AT_addr_base was found.
440 Used when processing DWO files. */
441 unsigned int have_addr_base
: 1;
444 /* Persistent data held for a compilation unit, even when not
445 processing it. We put a pointer to this structure in the
446 read_symtab_private field of the psymtab. */
448 struct dwarf2_per_cu_data
450 /* The start offset and length of this compilation unit. 2**29-1
451 bytes should suffice to store the length of any compilation unit
452 - if it doesn't, GDB will fall over anyway.
453 NOTE: Unlike comp_unit_head.length, this length includes
455 If the DIE refers to a DWO file, this is always of the original die,
458 unsigned int length
: 29;
460 /* Flag indicating this compilation unit will be read in before
461 any of the current compilation units are processed. */
462 unsigned int queued
: 1;
464 /* This flag will be set when reading partial DIEs if we need to load
465 absolutely all DIEs for this compilation unit, instead of just the ones
466 we think are interesting. It gets set if we look for a DIE in the
467 hash table and don't find it. */
468 unsigned int load_all_dies
: 1;
470 /* Non-zero if this CU is from .debug_types. */
471 unsigned int is_debug_types
: 1;
473 /* The section this CU/TU lives in.
474 If the DIE refers to a DWO file, this is always the original die,
476 struct dwarf2_section_info
*info_or_types_section
;
478 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
479 of the CU cache it gets reset to NULL again. */
480 struct dwarf2_cu
*cu
;
482 /* The corresponding objfile.
483 Normally we can get the objfile from dwarf2_per_objfile.
484 However we can enter this file with just a "per_cu" handle. */
485 struct objfile
*objfile
;
487 /* When using partial symbol tables, the 'psymtab' field is active.
488 Otherwise the 'quick' field is active. */
491 /* The partial symbol table associated with this compilation unit,
492 or NULL for unread partial units. */
493 struct partial_symtab
*psymtab
;
495 /* Data needed by the "quick" functions. */
496 struct dwarf2_per_cu_quick_data
*quick
;
499 /* The CUs we import using DW_TAG_imported_unit. This is filled in
500 while reading psymtabs, used to compute the psymtab dependencies,
501 and then cleared. Then it is filled in again while reading full
502 symbols, and only deleted when the objfile is destroyed. */
503 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
506 /* Entry in the signatured_types hash table. */
508 struct signatured_type
510 /* The type's signature. */
513 /* Offset in the TU of the type's DIE, as read from the TU header.
514 If the definition lives in a DWO file, this value is unusable. */
515 cu_offset type_offset_in_tu
;
517 /* Offset in the section of the type's DIE.
518 If the definition lives in a DWO file, this is the offset in the
519 .debug_types.dwo section.
520 The value is zero until the actual value is known.
521 Zero is otherwise not a valid section offset. */
522 sect_offset type_offset_in_section
;
524 /* The CU(/TU) of this type. */
525 struct dwarf2_per_cu_data per_cu
;
528 /* These sections are what may appear in a "dwo" file. */
532 struct dwarf2_section_info abbrev
;
533 struct dwarf2_section_info info
;
534 struct dwarf2_section_info line
;
535 struct dwarf2_section_info loc
;
536 struct dwarf2_section_info str
;
537 struct dwarf2_section_info str_offsets
;
538 VEC (dwarf2_section_info_def
) *types
;
541 /* Common bits of DWO CUs/TUs. */
545 /* Backlink to the containing struct dwo_file. */
546 struct dwo_file
*dwo_file
;
548 /* The "id" that distinguishes this CU/TU.
549 .debug_info calls this "dwo_id", .debug_types calls this "signature".
550 Since signatures came first, we stick with it for consistency. */
553 /* The section this CU/TU lives in, in the DWO file. */
554 struct dwarf2_section_info
*info_or_types_section
;
556 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
560 /* For types, offset in the type's DIE of the type defined by this TU. */
561 cu_offset type_offset_in_tu
;
564 /* Data for one DWO file. */
568 /* The DW_AT_GNU_dwo_name attribute.
569 We don't manage space for this, it's an attribute. */
570 const char *dwo_name
;
572 /* The bfd, when the file is open. Otherwise this is NULL. */
575 /* Section info for this file. */
576 struct dwo_sections sections
;
578 /* Table of CUs in the file.
579 Each element is a struct dwo_unit. */
582 /* Table of TUs in the file.
583 Each element is a struct dwo_unit. */
587 /* Struct used to pass misc. parameters to read_die_and_children, et
588 al. which are used for both .debug_info and .debug_types dies.
589 All parameters here are unchanging for the life of the call. This
590 struct exists to abstract away the constant parameters of die reading. */
592 struct die_reader_specs
594 /* die_section->asection->owner. */
597 /* The CU of the DIE we are parsing. */
598 struct dwarf2_cu
*cu
;
600 /* Non-NULL if reading a DWO file. */
601 struct dwo_file
*dwo_file
;
603 /* The section the die comes from.
604 This is either .debug_info or .debug_types, or the .dwo variants. */
605 struct dwarf2_section_info
*die_section
;
607 /* die_section->buffer. */
610 /* The end of the buffer. */
611 const gdb_byte
*buffer_end
;
614 /* Type of function passed to init_cutu_and_read_dies, et.al. */
615 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
617 struct die_info
*comp_unit_die
,
621 /* The line number information for a compilation unit (found in the
622 .debug_line section) begins with a "statement program header",
623 which contains the following information. */
626 unsigned int total_length
;
627 unsigned short version
;
628 unsigned int header_length
;
629 unsigned char minimum_instruction_length
;
630 unsigned char maximum_ops_per_instruction
;
631 unsigned char default_is_stmt
;
633 unsigned char line_range
;
634 unsigned char opcode_base
;
636 /* standard_opcode_lengths[i] is the number of operands for the
637 standard opcode whose value is i. This means that
638 standard_opcode_lengths[0] is unused, and the last meaningful
639 element is standard_opcode_lengths[opcode_base - 1]. */
640 unsigned char *standard_opcode_lengths
;
642 /* The include_directories table. NOTE! These strings are not
643 allocated with xmalloc; instead, they are pointers into
644 debug_line_buffer. If you try to free them, `free' will get
646 unsigned int num_include_dirs
, include_dirs_size
;
649 /* The file_names table. NOTE! These strings are not allocated
650 with xmalloc; instead, they are pointers into debug_line_buffer.
651 Don't try to free them directly. */
652 unsigned int num_file_names
, file_names_size
;
656 unsigned int dir_index
;
657 unsigned int mod_time
;
659 int included_p
; /* Non-zero if referenced by the Line Number Program. */
660 struct symtab
*symtab
; /* The associated symbol table, if any. */
663 /* The start and end of the statement program following this
664 header. These point into dwarf2_per_objfile->line_buffer. */
665 gdb_byte
*statement_program_start
, *statement_program_end
;
668 /* When we construct a partial symbol table entry we only
669 need this much information. */
670 struct partial_die_info
672 /* Offset of this DIE. */
675 /* DWARF-2 tag for this DIE. */
676 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
678 /* Assorted flags describing the data found in this DIE. */
679 unsigned int has_children
: 1;
680 unsigned int is_external
: 1;
681 unsigned int is_declaration
: 1;
682 unsigned int has_type
: 1;
683 unsigned int has_specification
: 1;
684 unsigned int has_pc_info
: 1;
685 unsigned int may_be_inlined
: 1;
687 /* Flag set if the SCOPE field of this structure has been
689 unsigned int scope_set
: 1;
691 /* Flag set if the DIE has a byte_size attribute. */
692 unsigned int has_byte_size
: 1;
694 /* Flag set if any of the DIE's children are template arguments. */
695 unsigned int has_template_arguments
: 1;
697 /* Flag set if fixup_partial_die has been called on this die. */
698 unsigned int fixup_called
: 1;
700 /* The name of this DIE. Normally the value of DW_AT_name, but
701 sometimes a default name for unnamed DIEs. */
704 /* The linkage name, if present. */
705 const char *linkage_name
;
707 /* The scope to prepend to our children. This is generally
708 allocated on the comp_unit_obstack, so will disappear
709 when this compilation unit leaves the cache. */
712 /* Some data associated with the partial DIE. The tag determines
713 which field is live. */
716 /* The location description associated with this DIE, if any. */
717 struct dwarf_block
*locdesc
;
718 /* The offset of an import, for DW_TAG_imported_unit. */
722 /* If HAS_PC_INFO, the PC range associated with this DIE. */
726 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
727 DW_AT_sibling, if any. */
728 /* NOTE: This member isn't strictly necessary, read_partial_die could
729 return DW_AT_sibling values to its caller load_partial_dies. */
732 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
733 DW_AT_specification (or DW_AT_abstract_origin or
735 sect_offset spec_offset
;
737 /* Pointers to this DIE's parent, first child, and next sibling,
739 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
742 /* This data structure holds the information of an abbrev. */
745 unsigned int number
; /* number identifying abbrev */
746 enum dwarf_tag tag
; /* dwarf tag */
747 unsigned short has_children
; /* boolean */
748 unsigned short num_attrs
; /* number of attributes */
749 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
750 struct abbrev_info
*next
; /* next in chain */
755 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
756 ENUM_BITFIELD(dwarf_form
) form
: 16;
759 /* Attributes have a name and a value. */
762 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
763 ENUM_BITFIELD(dwarf_form
) form
: 15;
765 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
766 field should be in u.str (existing only for DW_STRING) but it is kept
767 here for better struct attribute alignment. */
768 unsigned int string_is_canonical
: 1;
773 struct dwarf_block
*blk
;
777 struct signatured_type
*signatured_type
;
782 /* This data structure holds a complete die structure. */
785 /* DWARF-2 tag for this DIE. */
786 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
788 /* Number of attributes */
789 unsigned char num_attrs
;
791 /* True if we're presently building the full type name for the
792 type derived from this DIE. */
793 unsigned char building_fullname
: 1;
798 /* Offset in .debug_info or .debug_types section. */
801 /* The dies in a compilation unit form an n-ary tree. PARENT
802 points to this die's parent; CHILD points to the first child of
803 this node; and all the children of a given node are chained
804 together via their SIBLING fields. */
805 struct die_info
*child
; /* Its first child, if any. */
806 struct die_info
*sibling
; /* Its next sibling, if any. */
807 struct die_info
*parent
; /* Its parent, if any. */
809 /* An array of attributes, with NUM_ATTRS elements. There may be
810 zero, but it's not common and zero-sized arrays are not
811 sufficiently portable C. */
812 struct attribute attrs
[1];
815 /* Get at parts of an attribute structure. */
817 #define DW_STRING(attr) ((attr)->u.str)
818 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
819 #define DW_UNSND(attr) ((attr)->u.unsnd)
820 #define DW_BLOCK(attr) ((attr)->u.blk)
821 #define DW_SND(attr) ((attr)->u.snd)
822 #define DW_ADDR(attr) ((attr)->u.addr)
823 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
825 /* Blocks are a bunch of untyped bytes. */
830 /* Valid only if SIZE is not zero. */
834 #ifndef ATTR_ALLOC_CHUNK
835 #define ATTR_ALLOC_CHUNK 4
838 /* Allocate fields for structs, unions and enums in this size. */
839 #ifndef DW_FIELD_ALLOC_CHUNK
840 #define DW_FIELD_ALLOC_CHUNK 4
843 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
844 but this would require a corresponding change in unpack_field_as_long
846 static int bits_per_byte
= 8;
848 /* The routines that read and process dies for a C struct or C++ class
849 pass lists of data member fields and lists of member function fields
850 in an instance of a field_info structure, as defined below. */
853 /* List of data member and baseclasses fields. */
856 struct nextfield
*next
;
861 *fields
, *baseclasses
;
863 /* Number of fields (including baseclasses). */
866 /* Number of baseclasses. */
869 /* Set if the accesibility of one of the fields is not public. */
870 int non_public_fields
;
872 /* Member function fields array, entries are allocated in the order they
873 are encountered in the object file. */
876 struct nextfnfield
*next
;
877 struct fn_field fnfield
;
881 /* Member function fieldlist array, contains name of possibly overloaded
882 member function, number of overloaded member functions and a pointer
883 to the head of the member function field chain. */
888 struct nextfnfield
*head
;
892 /* Number of entries in the fnfieldlists array. */
895 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
896 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
897 struct typedef_field_list
899 struct typedef_field field
;
900 struct typedef_field_list
*next
;
903 unsigned typedef_field_list_count
;
906 /* One item on the queue of compilation units to read in full symbols
908 struct dwarf2_queue_item
910 struct dwarf2_per_cu_data
*per_cu
;
911 enum language pretend_language
;
912 struct dwarf2_queue_item
*next
;
915 /* The current queue. */
916 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
918 /* Loaded secondary compilation units are kept in memory until they
919 have not been referenced for the processing of this many
920 compilation units. Set this to zero to disable caching. Cache
921 sizes of up to at least twenty will improve startup time for
922 typical inter-CU-reference binaries, at an obvious memory cost. */
923 static int dwarf2_max_cache_age
= 5;
925 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
926 struct cmd_list_element
*c
, const char *value
)
928 fprintf_filtered (file
, _("The upper bound on the age of cached "
929 "dwarf2 compilation units is %s.\n"),
934 /* Various complaints about symbol reading that don't abort the process. */
937 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
939 complaint (&symfile_complaints
,
940 _("statement list doesn't fit in .debug_line section"));
944 dwarf2_debug_line_missing_file_complaint (void)
946 complaint (&symfile_complaints
,
947 _(".debug_line section has line data without a file"));
951 dwarf2_debug_line_missing_end_sequence_complaint (void)
953 complaint (&symfile_complaints
,
954 _(".debug_line section has line "
955 "program sequence without an end"));
959 dwarf2_complex_location_expr_complaint (void)
961 complaint (&symfile_complaints
, _("location expression too complex"));
965 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
968 complaint (&symfile_complaints
,
969 _("const value length mismatch for '%s', got %d, expected %d"),
974 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
976 complaint (&symfile_complaints
,
977 _("debug info runs off end of %s section"
979 section
->asection
->name
,
980 bfd_get_filename (section
->asection
->owner
));
984 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
986 complaint (&symfile_complaints
,
987 _("macro debug info contains a "
988 "malformed macro definition:\n`%s'"),
993 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
995 complaint (&symfile_complaints
,
996 _("invalid attribute class or form for '%s' in '%s'"),
1000 /* local function prototypes */
1002 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1004 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1007 static void dwarf2_find_base_address (struct die_info
*die
,
1008 struct dwarf2_cu
*cu
);
1010 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1012 static void scan_partial_symbols (struct partial_die_info
*,
1013 CORE_ADDR
*, CORE_ADDR
*,
1014 int, struct dwarf2_cu
*);
1016 static void add_partial_symbol (struct partial_die_info
*,
1017 struct dwarf2_cu
*);
1019 static void add_partial_namespace (struct partial_die_info
*pdi
,
1020 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1021 int need_pc
, struct dwarf2_cu
*cu
);
1023 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1024 CORE_ADDR
*highpc
, int need_pc
,
1025 struct dwarf2_cu
*cu
);
1027 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1028 struct dwarf2_cu
*cu
);
1030 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1031 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1032 int need_pc
, struct dwarf2_cu
*cu
);
1034 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1036 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1038 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1039 struct dwarf2_section_info
*);
1041 static void dwarf2_free_abbrev_table (void *);
1043 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1045 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1046 struct dwarf2_cu
*);
1048 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1049 struct dwarf2_cu
*);
1051 static struct partial_die_info
*load_partial_dies
1052 (const struct die_reader_specs
*, gdb_byte
*, int);
1054 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1055 struct partial_die_info
*,
1056 struct abbrev_info
*,
1060 static struct partial_die_info
*find_partial_die (sect_offset
,
1061 struct dwarf2_cu
*);
1063 static void fixup_partial_die (struct partial_die_info
*,
1064 struct dwarf2_cu
*);
1066 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1067 struct attribute
*, struct attr_abbrev
*,
1070 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1072 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1074 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1076 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1078 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1080 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1083 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1085 static LONGEST read_checked_initial_length_and_offset
1086 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1087 unsigned int *, unsigned int *);
1089 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1092 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1094 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1096 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1098 static char *read_indirect_string (bfd
*, gdb_byte
*,
1099 const struct comp_unit_head
*,
1102 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1104 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1106 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1109 static char *read_str_index (const struct die_reader_specs
*reader
,
1110 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1112 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1114 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1115 struct dwarf2_cu
*);
1117 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1119 struct dwarf2_cu
*);
1121 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1122 struct dwarf2_cu
*cu
);
1124 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1126 static struct die_info
*die_specification (struct die_info
*die
,
1127 struct dwarf2_cu
**);
1129 static void free_line_header (struct line_header
*lh
);
1131 static void add_file_name (struct line_header
*, char *, unsigned int,
1132 unsigned int, unsigned int);
1134 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1135 struct dwarf2_cu
*cu
);
1137 static void dwarf_decode_lines (struct line_header
*, const char *,
1138 struct dwarf2_cu
*, struct partial_symtab
*,
1141 static void dwarf2_start_subfile (char *, const char *, const char *);
1143 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1144 struct dwarf2_cu
*);
1146 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1147 struct dwarf2_cu
*, struct symbol
*);
1149 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1150 struct dwarf2_cu
*);
1152 static void dwarf2_const_value_attr (struct attribute
*attr
,
1155 struct obstack
*obstack
,
1156 struct dwarf2_cu
*cu
, LONGEST
*value
,
1158 struct dwarf2_locexpr_baton
**baton
);
1160 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1162 static int need_gnat_info (struct dwarf2_cu
*);
1164 static struct type
*die_descriptive_type (struct die_info
*,
1165 struct dwarf2_cu
*);
1167 static void set_descriptive_type (struct type
*, struct die_info
*,
1168 struct dwarf2_cu
*);
1170 static struct type
*die_containing_type (struct die_info
*,
1171 struct dwarf2_cu
*);
1173 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1174 struct dwarf2_cu
*);
1176 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1178 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1180 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1182 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1183 const char *suffix
, int physname
,
1184 struct dwarf2_cu
*cu
);
1186 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1188 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1190 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1192 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1194 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1196 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1197 struct dwarf2_cu
*, struct partial_symtab
*);
1199 static int dwarf2_get_pc_bounds (struct die_info
*,
1200 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1201 struct partial_symtab
*);
1203 static void get_scope_pc_bounds (struct die_info
*,
1204 CORE_ADDR
*, CORE_ADDR
*,
1205 struct dwarf2_cu
*);
1207 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1208 CORE_ADDR
, struct dwarf2_cu
*);
1210 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1211 struct dwarf2_cu
*);
1213 static void dwarf2_attach_fields_to_type (struct field_info
*,
1214 struct type
*, struct dwarf2_cu
*);
1216 static void dwarf2_add_member_fn (struct field_info
*,
1217 struct die_info
*, struct type
*,
1218 struct dwarf2_cu
*);
1220 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1222 struct dwarf2_cu
*);
1224 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1226 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1228 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1230 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1232 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1234 static struct type
*read_module_type (struct die_info
*die
,
1235 struct dwarf2_cu
*cu
);
1237 static const char *namespace_name (struct die_info
*die
,
1238 int *is_anonymous
, struct dwarf2_cu
*);
1240 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1242 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1244 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1245 struct dwarf2_cu
*);
1247 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1249 gdb_byte
**new_info_ptr
,
1250 struct die_info
*parent
);
1252 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1254 gdb_byte
**new_info_ptr
,
1255 struct die_info
*parent
);
1257 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1258 struct die_info
**, gdb_byte
*, int *, int);
1260 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1261 struct die_info
**, gdb_byte
*, int *);
1263 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1265 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1268 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1270 static const char *dwarf2_full_name (char *name
,
1271 struct die_info
*die
,
1272 struct dwarf2_cu
*cu
);
1274 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1275 struct dwarf2_cu
**);
1277 static const char *dwarf_tag_name (unsigned int);
1279 static const char *dwarf_attr_name (unsigned int);
1281 static const char *dwarf_form_name (unsigned int);
1283 static char *dwarf_bool_name (unsigned int);
1285 static const char *dwarf_type_encoding_name (unsigned int);
1287 static struct die_info
*sibling_die (struct die_info
*);
1289 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1291 static void dump_die_for_error (struct die_info
*);
1293 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1296 /*static*/ void dump_die (struct die_info
*, int max_level
);
1298 static void store_in_ref_table (struct die_info
*,
1299 struct dwarf2_cu
*);
1301 static int is_ref_attr (struct attribute
*);
1303 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1305 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1307 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1309 struct dwarf2_cu
**);
1311 static struct die_info
*follow_die_ref (struct die_info
*,
1313 struct dwarf2_cu
**);
1315 static struct die_info
*follow_die_sig (struct die_info
*,
1317 struct dwarf2_cu
**);
1319 static struct signatured_type
*lookup_signatured_type_at_offset
1320 (struct objfile
*objfile
,
1321 struct dwarf2_section_info
*section
, sect_offset offset
);
1323 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1325 static void read_signatured_type (struct signatured_type
*);
1327 /* memory allocation interface */
1329 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1331 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1333 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1335 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1336 char *, bfd
*, struct dwarf2_cu
*,
1337 struct dwarf2_section_info
*,
1340 static int attr_form_is_block (struct attribute
*);
1342 static int attr_form_is_section_offset (struct attribute
*);
1344 static int attr_form_is_constant (struct attribute
*);
1346 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1347 struct dwarf2_loclist_baton
*baton
,
1348 struct attribute
*attr
);
1350 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1352 struct dwarf2_cu
*cu
);
1354 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1356 struct abbrev_info
*abbrev
);
1358 static void free_stack_comp_unit (void *);
1360 static hashval_t
partial_die_hash (const void *item
);
1362 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1364 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1365 (sect_offset offset
, struct objfile
*objfile
);
1367 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1368 struct dwarf2_per_cu_data
*per_cu
);
1370 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1371 struct die_info
*comp_unit_die
,
1372 enum language pretend_language
);
1374 static void free_heap_comp_unit (void *);
1376 static void free_cached_comp_units (void *);
1378 static void age_cached_comp_units (void);
1380 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1382 static struct type
*set_die_type (struct die_info
*, struct type
*,
1383 struct dwarf2_cu
*);
1385 static void create_all_comp_units (struct objfile
*);
1387 static int create_all_type_units (struct objfile
*);
1389 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1392 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1395 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1396 struct dwarf2_per_cu_data
*);
1398 static void dwarf2_mark (struct dwarf2_cu
*);
1400 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1402 static struct type
*get_die_type_at_offset (sect_offset
,
1403 struct dwarf2_per_cu_data
*per_cu
);
1405 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1407 static void dwarf2_release_queue (void *dummy
);
1409 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1410 enum language pretend_language
);
1412 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1413 struct dwarf2_per_cu_data
*per_cu
,
1414 enum language pretend_language
);
1416 static void process_queue (void);
1418 static void find_file_and_directory (struct die_info
*die
,
1419 struct dwarf2_cu
*cu
,
1420 char **name
, char **comp_dir
);
1422 static char *file_full_name (int file
, struct line_header
*lh
,
1423 const char *comp_dir
);
1425 static gdb_byte
*read_and_check_comp_unit_head
1426 (struct comp_unit_head
*header
,
1427 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1428 int is_debug_types_section
);
1430 static void init_cutu_and_read_dies
1431 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1432 die_reader_func_ftype
*die_reader_func
, void *data
);
1434 static void init_cutu_and_read_dies_simple
1435 (struct dwarf2_per_cu_data
*this_cu
,
1436 die_reader_func_ftype
*die_reader_func
, void *data
);
1438 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1440 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1442 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1444 static struct dwo_unit
*lookup_dwo_comp_unit
1445 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1447 static struct dwo_unit
*lookup_dwo_type_unit
1448 (struct signatured_type
*, char *, const char *);
1450 static void free_dwo_file_cleanup (void *);
1452 static void munmap_section_buffer (struct dwarf2_section_info
*);
1454 static void process_cu_includes (void);
1458 /* Convert VALUE between big- and little-endian. */
1460 byte_swap (offset_type value
)
1464 result
= (value
& 0xff) << 24;
1465 result
|= (value
& 0xff00) << 8;
1466 result
|= (value
& 0xff0000) >> 8;
1467 result
|= (value
& 0xff000000) >> 24;
1471 #define MAYBE_SWAP(V) byte_swap (V)
1474 #define MAYBE_SWAP(V) (V)
1475 #endif /* WORDS_BIGENDIAN */
1477 /* The suffix for an index file. */
1478 #define INDEX_SUFFIX ".gdb-index"
1480 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1481 struct dwarf2_cu
*cu
);
1483 /* Try to locate the sections we need for DWARF 2 debugging
1484 information and return true if we have enough to do something.
1485 NAMES points to the dwarf2 section names, or is NULL if the standard
1486 ELF names are used. */
1489 dwarf2_has_info (struct objfile
*objfile
,
1490 const struct dwarf2_debug_sections
*names
)
1492 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1493 if (!dwarf2_per_objfile
)
1495 /* Initialize per-objfile state. */
1496 struct dwarf2_per_objfile
*data
1497 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1499 memset (data
, 0, sizeof (*data
));
1500 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1501 dwarf2_per_objfile
= data
;
1503 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1505 dwarf2_per_objfile
->objfile
= objfile
;
1507 return (dwarf2_per_objfile
->info
.asection
!= NULL
1508 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1511 /* When loading sections, we look either for uncompressed section or for
1512 compressed section names. */
1515 section_is_p (const char *section_name
,
1516 const struct dwarf2_section_names
*names
)
1518 if (names
->normal
!= NULL
1519 && strcmp (section_name
, names
->normal
) == 0)
1521 if (names
->compressed
!= NULL
1522 && strcmp (section_name
, names
->compressed
) == 0)
1527 /* This function is mapped across the sections and remembers the
1528 offset and size of each of the debugging sections we are interested
1532 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1534 const struct dwarf2_debug_sections
*names
;
1537 names
= &dwarf2_elf_names
;
1539 names
= (const struct dwarf2_debug_sections
*) vnames
;
1541 if (section_is_p (sectp
->name
, &names
->info
))
1543 dwarf2_per_objfile
->info
.asection
= sectp
;
1544 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1546 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1548 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1549 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1551 else if (section_is_p (sectp
->name
, &names
->line
))
1553 dwarf2_per_objfile
->line
.asection
= sectp
;
1554 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1556 else if (section_is_p (sectp
->name
, &names
->loc
))
1558 dwarf2_per_objfile
->loc
.asection
= sectp
;
1559 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1561 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1563 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1564 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1566 else if (section_is_p (sectp
->name
, &names
->macro
))
1568 dwarf2_per_objfile
->macro
.asection
= sectp
;
1569 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1571 else if (section_is_p (sectp
->name
, &names
->str
))
1573 dwarf2_per_objfile
->str
.asection
= sectp
;
1574 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1576 else if (section_is_p (sectp
->name
, &names
->addr
))
1578 dwarf2_per_objfile
->addr
.asection
= sectp
;
1579 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1581 else if (section_is_p (sectp
->name
, &names
->frame
))
1583 dwarf2_per_objfile
->frame
.asection
= sectp
;
1584 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1586 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1588 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1590 if (aflag
& SEC_HAS_CONTENTS
)
1592 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1593 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1596 else if (section_is_p (sectp
->name
, &names
->ranges
))
1598 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1599 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1601 else if (section_is_p (sectp
->name
, &names
->types
))
1603 struct dwarf2_section_info type_section
;
1605 memset (&type_section
, 0, sizeof (type_section
));
1606 type_section
.asection
= sectp
;
1607 type_section
.size
= bfd_get_section_size (sectp
);
1609 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1612 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1614 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1615 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1618 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1619 && bfd_section_vma (abfd
, sectp
) == 0)
1620 dwarf2_per_objfile
->has_section_at_zero
= 1;
1623 /* Decompress a section that was compressed using zlib. Store the
1624 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1627 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1628 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1630 bfd
*abfd
= sectp
->owner
;
1632 error (_("Support for zlib-compressed DWARF data (from '%s') "
1633 "is disabled in this copy of GDB"),
1634 bfd_get_filename (abfd
));
1636 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1637 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1638 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1639 bfd_size_type uncompressed_size
;
1640 gdb_byte
*uncompressed_buffer
;
1643 int header_size
= 12;
1645 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1646 || bfd_bread (compressed_buffer
,
1647 compressed_size
, abfd
) != compressed_size
)
1648 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1649 bfd_get_filename (abfd
));
1651 /* Read the zlib header. In this case, it should be "ZLIB" followed
1652 by the uncompressed section size, 8 bytes in big-endian order. */
1653 if (compressed_size
< header_size
1654 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1655 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1656 bfd_get_filename (abfd
));
1657 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1658 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1659 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1660 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1661 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1662 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1663 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1664 uncompressed_size
+= compressed_buffer
[11];
1666 /* It is possible the section consists of several compressed
1667 buffers concatenated together, so we uncompress in a loop. */
1671 strm
.avail_in
= compressed_size
- header_size
;
1672 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1673 strm
.avail_out
= uncompressed_size
;
1674 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1676 rc
= inflateInit (&strm
);
1677 while (strm
.avail_in
> 0)
1680 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1681 bfd_get_filename (abfd
), rc
);
1682 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1683 + (uncompressed_size
- strm
.avail_out
));
1684 rc
= inflate (&strm
, Z_FINISH
);
1685 if (rc
!= Z_STREAM_END
)
1686 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1687 bfd_get_filename (abfd
), rc
);
1688 rc
= inflateReset (&strm
);
1690 rc
= inflateEnd (&strm
);
1692 || strm
.avail_out
!= 0)
1693 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1694 bfd_get_filename (abfd
), rc
);
1696 do_cleanups (cleanup
);
1697 *outbuf
= uncompressed_buffer
;
1698 *outsize
= uncompressed_size
;
1702 /* A helper function that decides whether a section is empty,
1706 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1708 return info
->asection
== NULL
|| info
->size
== 0;
1711 /* Read the contents of the section INFO.
1712 OBJFILE is the main object file, but not necessarily the file where
1713 the section comes from. E.g., for DWO files INFO->asection->owner
1714 is the bfd of the DWO file.
1715 If the section is compressed, uncompress it before returning. */
1718 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1720 asection
*sectp
= info
->asection
;
1722 gdb_byte
*buf
, *retbuf
;
1723 unsigned char header
[4];
1727 info
->buffer
= NULL
;
1728 info
->map_addr
= NULL
;
1731 if (dwarf2_section_empty_p (info
))
1734 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1735 abfd
= sectp
->owner
;
1737 /* Check if the file has a 4-byte header indicating compression. */
1738 if (info
->size
> sizeof (header
)
1739 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1740 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1742 /* Upon decompression, update the buffer and its size. */
1743 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1745 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1753 pagesize
= getpagesize ();
1755 /* Only try to mmap sections which are large enough: we don't want to
1756 waste space due to fragmentation. Also, only try mmap for sections
1757 without relocations. */
1759 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1761 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1762 MAP_PRIVATE
, sectp
->filepos
,
1763 &info
->map_addr
, &info
->map_len
);
1765 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1767 #if HAVE_POSIX_MADVISE
1768 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1775 /* If we get here, we are a normal, not-compressed section. */
1777 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1779 /* When debugging .o files, we may need to apply relocations; see
1780 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1781 We never compress sections in .o files, so we only need to
1782 try this when the section is not compressed. */
1783 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1786 info
->buffer
= retbuf
;
1790 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1791 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1792 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1793 bfd_get_filename (abfd
));
1796 /* A helper function that returns the size of a section in a safe way.
1797 If you are positive that the section has been read before using the
1798 size, then it is safe to refer to the dwarf2_section_info object's
1799 "size" field directly. In other cases, you must call this
1800 function, because for compressed sections the size field is not set
1801 correctly until the section has been read. */
1803 static bfd_size_type
1804 dwarf2_section_size (struct objfile
*objfile
,
1805 struct dwarf2_section_info
*info
)
1808 dwarf2_read_section (objfile
, info
);
1812 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1816 dwarf2_get_section_info (struct objfile
*objfile
,
1817 enum dwarf2_section_enum sect
,
1818 asection
**sectp
, gdb_byte
**bufp
,
1819 bfd_size_type
*sizep
)
1821 struct dwarf2_per_objfile
*data
1822 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1823 struct dwarf2_section_info
*info
;
1825 /* We may see an objfile without any DWARF, in which case we just
1836 case DWARF2_DEBUG_FRAME
:
1837 info
= &data
->frame
;
1839 case DWARF2_EH_FRAME
:
1840 info
= &data
->eh_frame
;
1843 gdb_assert_not_reached ("unexpected section");
1846 dwarf2_read_section (objfile
, info
);
1848 *sectp
= info
->asection
;
1849 *bufp
= info
->buffer
;
1850 *sizep
= info
->size
;
1854 /* DWARF quick_symbols_functions support. */
1856 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1857 unique line tables, so we maintain a separate table of all .debug_line
1858 derived entries to support the sharing.
1859 All the quick functions need is the list of file names. We discard the
1860 line_header when we're done and don't need to record it here. */
1861 struct quick_file_names
1863 /* The offset in .debug_line of the line table. We hash on this. */
1864 unsigned int offset
;
1866 /* The number of entries in file_names, real_names. */
1867 unsigned int num_file_names
;
1869 /* The file names from the line table, after being run through
1871 const char **file_names
;
1873 /* The file names from the line table after being run through
1874 gdb_realpath. These are computed lazily. */
1875 const char **real_names
;
1878 /* When using the index (and thus not using psymtabs), each CU has an
1879 object of this type. This is used to hold information needed by
1880 the various "quick" methods. */
1881 struct dwarf2_per_cu_quick_data
1883 /* The file table. This can be NULL if there was no file table
1884 or it's currently not read in.
1885 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1886 struct quick_file_names
*file_names
;
1888 /* The corresponding symbol table. This is NULL if symbols for this
1889 CU have not yet been read. */
1890 struct symtab
*symtab
;
1892 /* A temporary mark bit used when iterating over all CUs in
1893 expand_symtabs_matching. */
1894 unsigned int mark
: 1;
1896 /* True if we've tried to read the file table and found there isn't one.
1897 There will be no point in trying to read it again next time. */
1898 unsigned int no_file_data
: 1;
1901 /* Hash function for a quick_file_names. */
1904 hash_file_name_entry (const void *e
)
1906 const struct quick_file_names
*file_data
= e
;
1908 return file_data
->offset
;
1911 /* Equality function for a quick_file_names. */
1914 eq_file_name_entry (const void *a
, const void *b
)
1916 const struct quick_file_names
*ea
= a
;
1917 const struct quick_file_names
*eb
= b
;
1919 return ea
->offset
== eb
->offset
;
1922 /* Delete function for a quick_file_names. */
1925 delete_file_name_entry (void *e
)
1927 struct quick_file_names
*file_data
= e
;
1930 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1932 xfree ((void*) file_data
->file_names
[i
]);
1933 if (file_data
->real_names
)
1934 xfree ((void*) file_data
->real_names
[i
]);
1937 /* The space for the struct itself lives on objfile_obstack,
1938 so we don't free it here. */
1941 /* Create a quick_file_names hash table. */
1944 create_quick_file_names_table (unsigned int nr_initial_entries
)
1946 return htab_create_alloc (nr_initial_entries
,
1947 hash_file_name_entry
, eq_file_name_entry
,
1948 delete_file_name_entry
, xcalloc
, xfree
);
1951 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1952 have to be created afterwards. You should call age_cached_comp_units after
1953 processing PER_CU->CU. dw2_setup must have been already called. */
1956 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1958 if (per_cu
->is_debug_types
)
1959 load_full_type_unit (per_cu
);
1961 load_full_comp_unit (per_cu
, language_minimal
);
1963 gdb_assert (per_cu
->cu
!= NULL
);
1965 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1968 /* Read in the symbols for PER_CU. */
1971 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1973 struct cleanup
*back_to
;
1975 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1977 if (dwarf2_per_objfile
->using_index
1978 ? per_cu
->v
.quick
->symtab
== NULL
1979 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
1981 queue_comp_unit (per_cu
, language_minimal
);
1987 /* Age the cache, releasing compilation units that have not
1988 been used recently. */
1989 age_cached_comp_units ();
1991 do_cleanups (back_to
);
1994 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1995 the objfile from which this CU came. Returns the resulting symbol
1998 static struct symtab
*
1999 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2001 gdb_assert (dwarf2_per_objfile
->using_index
);
2002 if (!per_cu
->v
.quick
->symtab
)
2004 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2005 increment_reading_symtab ();
2006 dw2_do_instantiate_symtab (per_cu
);
2007 process_cu_includes ();
2008 do_cleanups (back_to
);
2010 return per_cu
->v
.quick
->symtab
;
2013 /* Return the CU given its index. */
2015 static struct dwarf2_per_cu_data
*
2016 dw2_get_cu (int index
)
2018 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2020 index
-= dwarf2_per_objfile
->n_comp_units
;
2021 return dwarf2_per_objfile
->all_type_units
[index
];
2023 return dwarf2_per_objfile
->all_comp_units
[index
];
2026 /* A helper function that knows how to read a 64-bit value in a way
2027 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2031 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2033 if (sizeof (ULONGEST
) < 8)
2037 /* Ignore the upper 4 bytes if they are all zero. */
2038 for (i
= 0; i
< 4; ++i
)
2039 if (bytes
[i
+ 4] != 0)
2042 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2045 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2049 /* Read the CU list from the mapped index, and use it to create all
2050 the CU objects for this objfile. Return 0 if something went wrong,
2051 1 if everything went ok. */
2054 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2055 offset_type cu_list_elements
)
2059 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2060 dwarf2_per_objfile
->all_comp_units
2061 = obstack_alloc (&objfile
->objfile_obstack
,
2062 dwarf2_per_objfile
->n_comp_units
2063 * sizeof (struct dwarf2_per_cu_data
*));
2065 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2067 struct dwarf2_per_cu_data
*the_cu
;
2068 ULONGEST offset
, length
;
2070 if (!extract_cu_value (cu_list
, &offset
)
2071 || !extract_cu_value (cu_list
+ 8, &length
))
2075 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2076 struct dwarf2_per_cu_data
);
2077 the_cu
->offset
.sect_off
= offset
;
2078 the_cu
->length
= length
;
2079 the_cu
->objfile
= objfile
;
2080 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2081 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2082 struct dwarf2_per_cu_quick_data
);
2083 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2089 /* Create the signatured type hash table from the index. */
2092 create_signatured_type_table_from_index (struct objfile
*objfile
,
2093 struct dwarf2_section_info
*section
,
2094 const gdb_byte
*bytes
,
2095 offset_type elements
)
2098 htab_t sig_types_hash
;
2100 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2101 dwarf2_per_objfile
->all_type_units
2102 = obstack_alloc (&objfile
->objfile_obstack
,
2103 dwarf2_per_objfile
->n_type_units
2104 * sizeof (struct dwarf2_per_cu_data
*));
2106 sig_types_hash
= allocate_signatured_type_table (objfile
);
2108 for (i
= 0; i
< elements
; i
+= 3)
2110 struct signatured_type
*sig_type
;
2111 ULONGEST offset
, type_offset_in_tu
, signature
;
2114 if (!extract_cu_value (bytes
, &offset
)
2115 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2117 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2120 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2121 struct signatured_type
);
2122 sig_type
->signature
= signature
;
2123 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2124 sig_type
->per_cu
.is_debug_types
= 1;
2125 sig_type
->per_cu
.info_or_types_section
= section
;
2126 sig_type
->per_cu
.offset
.sect_off
= offset
;
2127 sig_type
->per_cu
.objfile
= objfile
;
2128 sig_type
->per_cu
.v
.quick
2129 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2130 struct dwarf2_per_cu_quick_data
);
2132 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2135 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2138 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2143 /* Read the address map data from the mapped index, and use it to
2144 populate the objfile's psymtabs_addrmap. */
2147 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2149 const gdb_byte
*iter
, *end
;
2150 struct obstack temp_obstack
;
2151 struct addrmap
*mutable_map
;
2152 struct cleanup
*cleanup
;
2155 obstack_init (&temp_obstack
);
2156 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2157 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2159 iter
= index
->address_table
;
2160 end
= iter
+ index
->address_table_size
;
2162 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2166 ULONGEST hi
, lo
, cu_index
;
2167 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2169 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2171 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2174 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2175 dw2_get_cu (cu_index
));
2178 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2179 &objfile
->objfile_obstack
);
2180 do_cleanups (cleanup
);
2183 /* The hash function for strings in the mapped index. This is the same as
2184 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2185 implementation. This is necessary because the hash function is tied to the
2186 format of the mapped index file. The hash values do not have to match with
2189 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2192 mapped_index_string_hash (int index_version
, const void *p
)
2194 const unsigned char *str
= (const unsigned char *) p
;
2198 while ((c
= *str
++) != 0)
2200 if (index_version
>= 5)
2202 r
= r
* 67 + c
- 113;
2208 /* Find a slot in the mapped index INDEX for the object named NAME.
2209 If NAME is found, set *VEC_OUT to point to the CU vector in the
2210 constant pool and return 1. If NAME cannot be found, return 0. */
2213 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2214 offset_type
**vec_out
)
2216 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2218 offset_type slot
, step
;
2219 int (*cmp
) (const char *, const char *);
2221 if (current_language
->la_language
== language_cplus
2222 || current_language
->la_language
== language_java
2223 || current_language
->la_language
== language_fortran
)
2225 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2227 const char *paren
= strchr (name
, '(');
2233 dup
= xmalloc (paren
- name
+ 1);
2234 memcpy (dup
, name
, paren
- name
);
2235 dup
[paren
- name
] = 0;
2237 make_cleanup (xfree
, dup
);
2242 /* Index version 4 did not support case insensitive searches. But the
2243 indices for case insensitive languages are built in lowercase, therefore
2244 simulate our NAME being searched is also lowercased. */
2245 hash
= mapped_index_string_hash ((index
->version
== 4
2246 && case_sensitivity
== case_sensitive_off
2247 ? 5 : index
->version
),
2250 slot
= hash
& (index
->symbol_table_slots
- 1);
2251 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2252 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2256 /* Convert a slot number to an offset into the table. */
2257 offset_type i
= 2 * slot
;
2259 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2261 do_cleanups (back_to
);
2265 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2266 if (!cmp (name
, str
))
2268 *vec_out
= (offset_type
*) (index
->constant_pool
2269 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2270 do_cleanups (back_to
);
2274 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2278 /* Read the index file. If everything went ok, initialize the "quick"
2279 elements of all the CUs and return 1. Otherwise, return 0. */
2282 dwarf2_read_index (struct objfile
*objfile
)
2285 struct mapped_index
*map
;
2286 offset_type
*metadata
;
2287 const gdb_byte
*cu_list
;
2288 const gdb_byte
*types_list
= NULL
;
2289 offset_type version
, cu_list_elements
;
2290 offset_type types_list_elements
= 0;
2293 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2296 /* Older elfutils strip versions could keep the section in the main
2297 executable while splitting it for the separate debug info file. */
2298 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2299 & SEC_HAS_CONTENTS
) == 0)
2302 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2304 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2305 /* Version check. */
2306 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2307 /* Versions earlier than 3 emitted every copy of a psymbol. This
2308 causes the index to behave very poorly for certain requests. Version 3
2309 contained incomplete addrmap. So, it seems better to just ignore such
2313 static int warning_printed
= 0;
2314 if (!warning_printed
)
2316 warning (_("Skipping obsolete .gdb_index section in %s."),
2318 warning_printed
= 1;
2322 /* Index version 4 uses a different hash function than index version
2325 Versions earlier than 6 did not emit psymbols for inlined
2326 functions. Using these files will cause GDB not to be able to
2327 set breakpoints on inlined functions by name, so we ignore these
2328 indices unless the --use-deprecated-index-sections command line
2329 option was supplied. */
2330 if (version
< 6 && !use_deprecated_index_sections
)
2332 static int warning_printed
= 0;
2333 if (!warning_printed
)
2335 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2336 "--use-deprecated-index-sections to use them anyway"),
2338 warning_printed
= 1;
2342 /* Indexes with higher version than the one supported by GDB may be no
2343 longer backward compatible. */
2347 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2348 map
->version
= version
;
2349 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2351 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2354 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2355 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2359 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2360 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2361 - MAYBE_SWAP (metadata
[i
]))
2365 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2366 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2367 - MAYBE_SWAP (metadata
[i
]));
2370 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2371 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2372 - MAYBE_SWAP (metadata
[i
]))
2373 / (2 * sizeof (offset_type
)));
2376 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2378 /* Don't use the index if it's empty. */
2379 if (map
->symbol_table_slots
== 0)
2382 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2385 if (types_list_elements
)
2387 struct dwarf2_section_info
*section
;
2389 /* We can only handle a single .debug_types when we have an
2391 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2394 section
= VEC_index (dwarf2_section_info_def
,
2395 dwarf2_per_objfile
->types
, 0);
2397 if (!create_signatured_type_table_from_index (objfile
, section
,
2399 types_list_elements
))
2403 create_addrmap_from_index (objfile
, map
);
2405 dwarf2_per_objfile
->index_table
= map
;
2406 dwarf2_per_objfile
->using_index
= 1;
2407 dwarf2_per_objfile
->quick_file_names_table
=
2408 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2413 /* A helper for the "quick" functions which sets the global
2414 dwarf2_per_objfile according to OBJFILE. */
2417 dw2_setup (struct objfile
*objfile
)
2419 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2420 gdb_assert (dwarf2_per_objfile
);
2423 /* die_reader_func for dw2_get_file_names. */
2426 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2428 struct die_info
*comp_unit_die
,
2432 struct dwarf2_cu
*cu
= reader
->cu
;
2433 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2434 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2435 struct line_header
*lh
;
2436 struct attribute
*attr
;
2438 char *name
, *comp_dir
;
2440 struct quick_file_names
*qfn
;
2441 unsigned int line_offset
;
2447 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2450 struct quick_file_names find_entry
;
2452 line_offset
= DW_UNSND (attr
);
2454 /* We may have already read in this line header (TU line header sharing).
2455 If we have we're done. */
2456 find_entry
.offset
= line_offset
;
2457 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2458 &find_entry
, INSERT
);
2461 this_cu
->v
.quick
->file_names
= *slot
;
2465 lh
= dwarf_decode_line_header (line_offset
, cu
);
2469 this_cu
->v
.quick
->no_file_data
= 1;
2473 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2474 qfn
->offset
= line_offset
;
2475 gdb_assert (slot
!= NULL
);
2478 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2480 qfn
->num_file_names
= lh
->num_file_names
;
2481 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2482 lh
->num_file_names
* sizeof (char *));
2483 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2484 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2485 qfn
->real_names
= NULL
;
2487 free_line_header (lh
);
2489 this_cu
->v
.quick
->file_names
= qfn
;
2492 /* A helper for the "quick" functions which attempts to read the line
2493 table for THIS_CU. */
2495 static struct quick_file_names
*
2496 dw2_get_file_names (struct objfile
*objfile
,
2497 struct dwarf2_per_cu_data
*this_cu
)
2499 if (this_cu
->v
.quick
->file_names
!= NULL
)
2500 return this_cu
->v
.quick
->file_names
;
2501 /* If we know there is no line data, no point in looking again. */
2502 if (this_cu
->v
.quick
->no_file_data
)
2505 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2506 in the stub for CUs, there's is no need to lookup the DWO file.
2507 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2509 if (this_cu
->is_debug_types
)
2510 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2512 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2514 if (this_cu
->v
.quick
->no_file_data
)
2516 return this_cu
->v
.quick
->file_names
;
2519 /* A helper for the "quick" functions which computes and caches the
2520 real path for a given file name from the line table. */
2523 dw2_get_real_path (struct objfile
*objfile
,
2524 struct quick_file_names
*qfn
, int index
)
2526 if (qfn
->real_names
== NULL
)
2527 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2528 qfn
->num_file_names
, sizeof (char *));
2530 if (qfn
->real_names
[index
] == NULL
)
2531 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2533 return qfn
->real_names
[index
];
2536 static struct symtab
*
2537 dw2_find_last_source_symtab (struct objfile
*objfile
)
2541 dw2_setup (objfile
);
2542 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2543 return dw2_instantiate_symtab (dw2_get_cu (index
));
2546 /* Traversal function for dw2_forget_cached_source_info. */
2549 dw2_free_cached_file_names (void **slot
, void *info
)
2551 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2553 if (file_data
->real_names
)
2557 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2559 xfree ((void*) file_data
->real_names
[i
]);
2560 file_data
->real_names
[i
] = NULL
;
2568 dw2_forget_cached_source_info (struct objfile
*objfile
)
2570 dw2_setup (objfile
);
2572 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2573 dw2_free_cached_file_names
, NULL
);
2576 /* Helper function for dw2_map_symtabs_matching_filename that expands
2577 the symtabs and calls the iterator. */
2580 dw2_map_expand_apply (struct objfile
*objfile
,
2581 struct dwarf2_per_cu_data
*per_cu
,
2583 const char *full_path
, const char *real_path
,
2584 int (*callback
) (struct symtab
*, void *),
2587 struct symtab
*last_made
= objfile
->symtabs
;
2589 /* Don't visit already-expanded CUs. */
2590 if (per_cu
->v
.quick
->symtab
)
2593 /* This may expand more than one symtab, and we want to iterate over
2595 dw2_instantiate_symtab (per_cu
);
2597 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2598 objfile
->symtabs
, last_made
);
2601 /* Implementation of the map_symtabs_matching_filename method. */
2604 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2605 const char *full_path
, const char *real_path
,
2606 int (*callback
) (struct symtab
*, void *),
2610 const char *name_basename
= lbasename (name
);
2611 int name_len
= strlen (name
);
2612 int is_abs
= IS_ABSOLUTE_PATH (name
);
2614 dw2_setup (objfile
);
2616 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2617 + dwarf2_per_objfile
->n_type_units
); ++i
)
2620 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2621 struct quick_file_names
*file_data
;
2623 /* We only need to look at symtabs not already expanded. */
2624 if (per_cu
->v
.quick
->symtab
)
2627 file_data
= dw2_get_file_names (objfile
, per_cu
);
2628 if (file_data
== NULL
)
2631 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2633 const char *this_name
= file_data
->file_names
[j
];
2635 if (FILENAME_CMP (name
, this_name
) == 0
2636 || (!is_abs
&& compare_filenames_for_search (this_name
,
2639 if (dw2_map_expand_apply (objfile
, per_cu
,
2640 name
, full_path
, real_path
,
2645 /* Before we invoke realpath, which can get expensive when many
2646 files are involved, do a quick comparison of the basenames. */
2647 if (! basenames_may_differ
2648 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2651 if (full_path
!= NULL
)
2653 const char *this_real_name
= dw2_get_real_path (objfile
,
2656 if (this_real_name
!= NULL
2657 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2659 && compare_filenames_for_search (this_real_name
,
2662 if (dw2_map_expand_apply (objfile
, per_cu
,
2663 name
, full_path
, real_path
,
2669 if (real_path
!= NULL
)
2671 const char *this_real_name
= dw2_get_real_path (objfile
,
2674 if (this_real_name
!= NULL
2675 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2677 && compare_filenames_for_search (this_real_name
,
2680 if (dw2_map_expand_apply (objfile
, per_cu
,
2681 name
, full_path
, real_path
,
2692 static struct symtab
*
2693 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2694 const char *name
, domain_enum domain
)
2696 /* We do all the work in the pre_expand_symtabs_matching hook
2701 /* A helper function that expands all symtabs that hold an object
2705 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2707 dw2_setup (objfile
);
2709 /* index_table is NULL if OBJF_READNOW. */
2710 if (dwarf2_per_objfile
->index_table
)
2714 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2717 offset_type i
, len
= MAYBE_SWAP (*vec
);
2718 for (i
= 0; i
< len
; ++i
)
2720 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2721 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2723 dw2_instantiate_symtab (per_cu
);
2730 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2731 enum block_enum block_kind
, const char *name
,
2734 dw2_do_expand_symtabs_matching (objfile
, name
);
2738 dw2_print_stats (struct objfile
*objfile
)
2742 dw2_setup (objfile
);
2744 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2745 + dwarf2_per_objfile
->n_type_units
); ++i
)
2747 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2749 if (!per_cu
->v
.quick
->symtab
)
2752 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2756 dw2_dump (struct objfile
*objfile
)
2758 /* Nothing worth printing. */
2762 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2763 struct section_offsets
*delta
)
2765 /* There's nothing to relocate here. */
2769 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2770 const char *func_name
)
2772 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2776 dw2_expand_all_symtabs (struct objfile
*objfile
)
2780 dw2_setup (objfile
);
2782 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2783 + dwarf2_per_objfile
->n_type_units
); ++i
)
2785 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2787 dw2_instantiate_symtab (per_cu
);
2792 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2793 const char *filename
)
2797 dw2_setup (objfile
);
2799 /* We don't need to consider type units here.
2800 This is only called for examining code, e.g. expand_line_sal.
2801 There can be an order of magnitude (or more) more type units
2802 than comp units, and we avoid them if we can. */
2804 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2807 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2808 struct quick_file_names
*file_data
;
2810 /* We only need to look at symtabs not already expanded. */
2811 if (per_cu
->v
.quick
->symtab
)
2814 file_data
= dw2_get_file_names (objfile
, per_cu
);
2815 if (file_data
== NULL
)
2818 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2820 const char *this_name
= file_data
->file_names
[j
];
2821 if (FILENAME_CMP (this_name
, filename
) == 0)
2823 dw2_instantiate_symtab (per_cu
);
2831 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2833 struct dwarf2_per_cu_data
*per_cu
;
2835 struct quick_file_names
*file_data
;
2837 dw2_setup (objfile
);
2839 /* index_table is NULL if OBJF_READNOW. */
2840 if (!dwarf2_per_objfile
->index_table
)
2844 ALL_OBJFILE_SYMTABS (objfile
, s
)
2847 struct blockvector
*bv
= BLOCKVECTOR (s
);
2848 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2849 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2852 return sym
->symtab
->filename
;
2857 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2861 /* Note that this just looks at the very first one named NAME -- but
2862 actually we are looking for a function. find_main_filename
2863 should be rewritten so that it doesn't require a custom hook. It
2864 could just use the ordinary symbol tables. */
2865 /* vec[0] is the length, which must always be >0. */
2866 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2868 file_data
= dw2_get_file_names (objfile
, per_cu
);
2869 if (file_data
== NULL
2870 || file_data
->num_file_names
== 0)
2873 return file_data
->file_names
[file_data
->num_file_names
- 1];
2877 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2878 struct objfile
*objfile
, int global
,
2879 int (*callback
) (struct block
*,
2880 struct symbol
*, void *),
2881 void *data
, symbol_compare_ftype
*match
,
2882 symbol_compare_ftype
*ordered_compare
)
2884 /* Currently unimplemented; used for Ada. The function can be called if the
2885 current language is Ada for a non-Ada objfile using GNU index. As Ada
2886 does not look for non-Ada symbols this function should just return. */
2890 dw2_expand_symtabs_matching
2891 (struct objfile
*objfile
,
2892 int (*file_matcher
) (const char *, void *),
2893 int (*name_matcher
) (const char *, void *),
2894 enum search_domain kind
,
2899 struct mapped_index
*index
;
2901 dw2_setup (objfile
);
2903 /* index_table is NULL if OBJF_READNOW. */
2904 if (!dwarf2_per_objfile
->index_table
)
2906 index
= dwarf2_per_objfile
->index_table
;
2908 if (file_matcher
!= NULL
)
2910 struct cleanup
*cleanup
;
2911 htab_t visited_found
, visited_not_found
;
2913 visited_found
= htab_create_alloc (10,
2914 htab_hash_pointer
, htab_eq_pointer
,
2915 NULL
, xcalloc
, xfree
);
2916 cleanup
= make_cleanup_htab_delete (visited_found
);
2917 visited_not_found
= htab_create_alloc (10,
2918 htab_hash_pointer
, htab_eq_pointer
,
2919 NULL
, xcalloc
, xfree
);
2920 make_cleanup_htab_delete (visited_not_found
);
2922 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2923 + dwarf2_per_objfile
->n_type_units
); ++i
)
2926 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2927 struct quick_file_names
*file_data
;
2930 per_cu
->v
.quick
->mark
= 0;
2932 /* We only need to look at symtabs not already expanded. */
2933 if (per_cu
->v
.quick
->symtab
)
2936 file_data
= dw2_get_file_names (objfile
, per_cu
);
2937 if (file_data
== NULL
)
2940 if (htab_find (visited_not_found
, file_data
) != NULL
)
2942 else if (htab_find (visited_found
, file_data
) != NULL
)
2944 per_cu
->v
.quick
->mark
= 1;
2948 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2950 if (file_matcher (file_data
->file_names
[j
], data
))
2952 per_cu
->v
.quick
->mark
= 1;
2957 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2959 : visited_not_found
,
2964 do_cleanups (cleanup
);
2967 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2969 offset_type idx
= 2 * iter
;
2971 offset_type
*vec
, vec_len
, vec_idx
;
2973 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2976 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2978 if (! (*name_matcher
) (name
, data
))
2981 /* The name was matched, now expand corresponding CUs that were
2983 vec
= (offset_type
*) (index
->constant_pool
2984 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2985 vec_len
= MAYBE_SWAP (vec
[0]);
2986 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2988 struct dwarf2_per_cu_data
*per_cu
;
2990 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2991 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2992 dw2_instantiate_symtab (per_cu
);
2997 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3000 static struct symtab
*
3001 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3005 if (BLOCKVECTOR (symtab
) != NULL
3006 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3009 if (symtab
->includes
== NULL
)
3012 for (i
= 0; symtab
->includes
[i
]; ++i
)
3014 struct symtab
*s
= symtab
->includes
[i
];
3016 s
= recursively_find_pc_sect_symtab (s
, pc
);
3024 static struct symtab
*
3025 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3026 struct minimal_symbol
*msymbol
,
3028 struct obj_section
*section
,
3031 struct dwarf2_per_cu_data
*data
;
3032 struct symtab
*result
;
3034 dw2_setup (objfile
);
3036 if (!objfile
->psymtabs_addrmap
)
3039 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3043 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3044 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3045 paddress (get_objfile_arch (objfile
), pc
));
3047 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3048 gdb_assert (result
!= NULL
);
3053 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3054 void *data
, int need_fullname
)
3057 struct cleanup
*cleanup
;
3058 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3059 NULL
, xcalloc
, xfree
);
3061 cleanup
= make_cleanup_htab_delete (visited
);
3062 dw2_setup (objfile
);
3064 /* We can ignore file names coming from already-expanded CUs. */
3065 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3066 + dwarf2_per_objfile
->n_type_units
); ++i
)
3068 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3070 if (per_cu
->v
.quick
->symtab
)
3072 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3075 *slot
= per_cu
->v
.quick
->file_names
;
3079 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3080 + dwarf2_per_objfile
->n_type_units
); ++i
)
3083 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3084 struct quick_file_names
*file_data
;
3087 /* We only need to look at symtabs not already expanded. */
3088 if (per_cu
->v
.quick
->symtab
)
3091 file_data
= dw2_get_file_names (objfile
, per_cu
);
3092 if (file_data
== NULL
)
3095 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3098 /* Already visited. */
3103 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3105 const char *this_real_name
;
3108 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3110 this_real_name
= NULL
;
3111 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3115 do_cleanups (cleanup
);
3119 dw2_has_symbols (struct objfile
*objfile
)
3124 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3127 dw2_find_last_source_symtab
,
3128 dw2_forget_cached_source_info
,
3129 dw2_map_symtabs_matching_filename
,
3131 dw2_pre_expand_symtabs_matching
,
3135 dw2_expand_symtabs_for_function
,
3136 dw2_expand_all_symtabs
,
3137 dw2_expand_symtabs_with_filename
,
3138 dw2_find_symbol_file
,
3139 dw2_map_matching_symbols
,
3140 dw2_expand_symtabs_matching
,
3141 dw2_find_pc_sect_symtab
,
3142 dw2_map_symbol_filenames
3145 /* Initialize for reading DWARF for this objfile. Return 0 if this
3146 file will use psymtabs, or 1 if using the GNU index. */
3149 dwarf2_initialize_objfile (struct objfile
*objfile
)
3151 /* If we're about to read full symbols, don't bother with the
3152 indices. In this case we also don't care if some other debug
3153 format is making psymtabs, because they are all about to be
3155 if ((objfile
->flags
& OBJF_READNOW
))
3159 dwarf2_per_objfile
->using_index
= 1;
3160 create_all_comp_units (objfile
);
3161 create_all_type_units (objfile
);
3162 dwarf2_per_objfile
->quick_file_names_table
=
3163 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3165 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3166 + dwarf2_per_objfile
->n_type_units
); ++i
)
3168 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3170 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3171 struct dwarf2_per_cu_quick_data
);
3174 /* Return 1 so that gdb sees the "quick" functions. However,
3175 these functions will be no-ops because we will have expanded
3180 if (dwarf2_read_index (objfile
))
3188 /* Build a partial symbol table. */
3191 dwarf2_build_psymtabs (struct objfile
*objfile
)
3193 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3195 init_psymbol_list (objfile
, 1024);
3198 dwarf2_build_psymtabs_hard (objfile
);
3201 /* Return TRUE if OFFSET is within CU_HEADER. */
3204 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3206 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3207 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3208 + cu_header
->initial_length_size
) };
3210 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3213 /* Read in the comp unit header information from the debug_info at info_ptr.
3214 NOTE: This leaves members offset, first_die_offset to be filled in
3218 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3219 gdb_byte
*info_ptr
, bfd
*abfd
)
3222 unsigned int bytes_read
;
3224 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3225 cu_header
->initial_length_size
= bytes_read
;
3226 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3227 info_ptr
+= bytes_read
;
3228 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3230 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3232 info_ptr
+= bytes_read
;
3233 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3235 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3236 if (signed_addr
< 0)
3237 internal_error (__FILE__
, __LINE__
,
3238 _("read_comp_unit_head: dwarf from non elf file"));
3239 cu_header
->signed_addr_p
= signed_addr
;
3244 /* Subroutine of read_and_check_comp_unit_head and
3245 read_and_check_type_unit_head to simplify them.
3246 Perform various error checking on the header. */
3249 error_check_comp_unit_head (struct comp_unit_head
*header
,
3250 struct dwarf2_section_info
*section
)
3252 bfd
*abfd
= section
->asection
->owner
;
3253 const char *filename
= bfd_get_filename (abfd
);
3255 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3256 error (_("Dwarf Error: wrong version in compilation unit header "
3257 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3260 if (header
->abbrev_offset
.sect_off
3261 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3262 &dwarf2_per_objfile
->abbrev
))
3263 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3264 "(offset 0x%lx + 6) [in module %s]"),
3265 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3268 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3269 avoid potential 32-bit overflow. */
3270 if (((unsigned long) header
->offset
.sect_off
3271 + header
->length
+ header
->initial_length_size
)
3273 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3274 "(offset 0x%lx + 0) [in module %s]"),
3275 (long) header
->length
, (long) header
->offset
.sect_off
,
3279 /* Read in a CU/TU header and perform some basic error checking.
3280 The contents of the header are stored in HEADER.
3281 The result is a pointer to the start of the first DIE. */
3284 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3285 struct dwarf2_section_info
*section
,
3287 int is_debug_types_section
)
3289 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3290 bfd
*abfd
= section
->asection
->owner
;
3292 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3294 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3296 /* If we're reading a type unit, skip over the signature and
3297 type_offset fields. */
3298 if (is_debug_types_section
)
3299 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3301 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3303 error_check_comp_unit_head (header
, section
);
3308 /* Read in the types comp unit header information from .debug_types entry at
3309 types_ptr. The result is a pointer to one past the end of the header. */
3312 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3313 struct dwarf2_section_info
*section
,
3315 ULONGEST
*signature
,
3316 cu_offset
*type_offset_in_tu
)
3318 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3319 bfd
*abfd
= section
->asection
->owner
;
3321 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3323 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3325 /* If we're reading a type unit, skip over the signature and
3326 type_offset fields. */
3327 if (signature
!= NULL
)
3328 *signature
= read_8_bytes (abfd
, info_ptr
);
3330 if (type_offset_in_tu
!= NULL
)
3331 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3332 header
->offset_size
);
3333 info_ptr
+= header
->offset_size
;
3335 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3337 error_check_comp_unit_head (header
, section
);
3342 /* Allocate a new partial symtab for file named NAME and mark this new
3343 partial symtab as being an include of PST. */
3346 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3347 struct objfile
*objfile
)
3349 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3351 subpst
->section_offsets
= pst
->section_offsets
;
3352 subpst
->textlow
= 0;
3353 subpst
->texthigh
= 0;
3355 subpst
->dependencies
= (struct partial_symtab
**)
3356 obstack_alloc (&objfile
->objfile_obstack
,
3357 sizeof (struct partial_symtab
*));
3358 subpst
->dependencies
[0] = pst
;
3359 subpst
->number_of_dependencies
= 1;
3361 subpst
->globals_offset
= 0;
3362 subpst
->n_global_syms
= 0;
3363 subpst
->statics_offset
= 0;
3364 subpst
->n_static_syms
= 0;
3365 subpst
->symtab
= NULL
;
3366 subpst
->read_symtab
= pst
->read_symtab
;
3369 /* No private part is necessary for include psymtabs. This property
3370 can be used to differentiate between such include psymtabs and
3371 the regular ones. */
3372 subpst
->read_symtab_private
= NULL
;
3375 /* Read the Line Number Program data and extract the list of files
3376 included by the source file represented by PST. Build an include
3377 partial symtab for each of these included files. */
3380 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3381 struct die_info
*die
,
3382 struct partial_symtab
*pst
)
3384 struct line_header
*lh
= NULL
;
3385 struct attribute
*attr
;
3387 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3389 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3391 return; /* No linetable, so no includes. */
3393 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3394 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3396 free_line_header (lh
);
3400 hash_signatured_type (const void *item
)
3402 const struct signatured_type
*sig_type
= item
;
3404 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3405 return sig_type
->signature
;
3409 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3411 const struct signatured_type
*lhs
= item_lhs
;
3412 const struct signatured_type
*rhs
= item_rhs
;
3414 return lhs
->signature
== rhs
->signature
;
3417 /* Allocate a hash table for signatured types. */
3420 allocate_signatured_type_table (struct objfile
*objfile
)
3422 return htab_create_alloc_ex (41,
3423 hash_signatured_type
,
3426 &objfile
->objfile_obstack
,
3427 hashtab_obstack_allocate
,
3428 dummy_obstack_deallocate
);
3431 /* A helper function to add a signatured type CU to a table. */
3434 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3436 struct signatured_type
*sigt
= *slot
;
3437 struct dwarf2_per_cu_data
***datap
= datum
;
3439 **datap
= &sigt
->per_cu
;
3445 /* Create the hash table of all entries in the .debug_types section.
3446 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3447 The result is a pointer to the hash table or NULL if there are
3451 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3452 VEC (dwarf2_section_info_def
) *types
)
3454 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3455 htab_t types_htab
= NULL
;
3457 struct dwarf2_section_info
*section
;
3459 if (VEC_empty (dwarf2_section_info_def
, types
))
3463 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3467 gdb_byte
*info_ptr
, *end_ptr
;
3469 dwarf2_read_section (objfile
, section
);
3470 info_ptr
= section
->buffer
;
3472 if (info_ptr
== NULL
)
3475 /* We can't set abfd until now because the section may be empty or
3476 not present, in which case section->asection will be NULL. */
3477 abfd
= section
->asection
->owner
;
3479 if (types_htab
== NULL
)
3482 types_htab
= allocate_dwo_unit_table (objfile
);
3484 types_htab
= allocate_signatured_type_table (objfile
);
3487 if (dwarf2_die_debug
)
3488 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3489 bfd_get_filename (abfd
));
3491 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3492 because we don't need to read any dies: the signature is in the
3495 end_ptr
= info_ptr
+ section
->size
;
3496 while (info_ptr
< end_ptr
)
3499 cu_offset type_offset_in_tu
;
3501 struct signatured_type
*sig_type
;
3502 struct dwo_unit
*dwo_tu
;
3504 gdb_byte
*ptr
= info_ptr
;
3505 struct comp_unit_head header
;
3506 unsigned int length
;
3508 offset
.sect_off
= ptr
- section
->buffer
;
3510 /* We need to read the type's signature in order to build the hash
3511 table, but we don't need anything else just yet. */
3513 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3514 &signature
, &type_offset_in_tu
);
3516 length
= header
.initial_length_size
+ header
.length
;
3518 /* Skip dummy type units. */
3519 if (ptr
>= info_ptr
+ length
3520 || peek_abbrev_code (abfd
, ptr
) == 0)
3522 info_ptr
+= header
.initial_length_size
+ header
.length
;
3529 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3531 dwo_tu
->dwo_file
= dwo_file
;
3532 dwo_tu
->signature
= signature
;
3533 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3534 dwo_tu
->info_or_types_section
= section
;
3535 dwo_tu
->offset
= offset
;
3536 dwo_tu
->length
= length
;
3540 /* N.B.: type_offset is not usable if this type uses a DWO file.
3541 The real type_offset is in the DWO file. */
3543 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3544 struct signatured_type
);
3545 sig_type
->signature
= signature
;
3546 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3547 sig_type
->per_cu
.objfile
= objfile
;
3548 sig_type
->per_cu
.is_debug_types
= 1;
3549 sig_type
->per_cu
.info_or_types_section
= section
;
3550 sig_type
->per_cu
.offset
= offset
;
3551 sig_type
->per_cu
.length
= length
;
3554 slot
= htab_find_slot (types_htab
,
3555 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3557 gdb_assert (slot
!= NULL
);
3560 sect_offset dup_offset
;
3564 const struct dwo_unit
*dup_tu
= *slot
;
3566 dup_offset
= dup_tu
->offset
;
3570 const struct signatured_type
*dup_tu
= *slot
;
3572 dup_offset
= dup_tu
->per_cu
.offset
;
3575 complaint (&symfile_complaints
,
3576 _("debug type entry at offset 0x%x is duplicate to the "
3577 "entry at offset 0x%x, signature 0x%s"),
3578 offset
.sect_off
, dup_offset
.sect_off
,
3579 phex (signature
, sizeof (signature
)));
3581 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3583 if (dwarf2_die_debug
)
3584 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3586 phex (signature
, sizeof (signature
)));
3595 /* Create the hash table of all entries in the .debug_types section,
3596 and initialize all_type_units.
3597 The result is zero if there is an error (e.g. missing .debug_types section),
3598 otherwise non-zero. */
3601 create_all_type_units (struct objfile
*objfile
)
3604 struct dwarf2_per_cu_data
**iter
;
3606 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3607 if (types_htab
== NULL
)
3609 dwarf2_per_objfile
->signatured_types
= NULL
;
3613 dwarf2_per_objfile
->signatured_types
= types_htab
;
3615 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3616 dwarf2_per_objfile
->all_type_units
3617 = obstack_alloc (&objfile
->objfile_obstack
,
3618 dwarf2_per_objfile
->n_type_units
3619 * sizeof (struct dwarf2_per_cu_data
*));
3620 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3621 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3622 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3623 == dwarf2_per_objfile
->n_type_units
);
3628 /* Lookup a signature based type for DW_FORM_ref_sig8.
3629 Returns NULL if signature SIG is not present in the table. */
3631 static struct signatured_type
*
3632 lookup_signatured_type (ULONGEST sig
)
3634 struct signatured_type find_entry
, *entry
;
3636 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3638 complaint (&symfile_complaints
,
3639 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3643 find_entry
.signature
= sig
;
3644 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3648 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3651 init_cu_die_reader (struct die_reader_specs
*reader
,
3652 struct dwarf2_cu
*cu
,
3653 struct dwarf2_section_info
*section
,
3654 struct dwo_file
*dwo_file
)
3656 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3657 reader
->abfd
= section
->asection
->owner
;
3659 reader
->dwo_file
= dwo_file
;
3660 reader
->die_section
= section
;
3661 reader
->buffer
= section
->buffer
;
3662 reader
->buffer_end
= section
->buffer
+ section
->size
;
3665 /* Find the base address of the compilation unit for range lists and
3666 location lists. It will normally be specified by DW_AT_low_pc.
3667 In DWARF-3 draft 4, the base address could be overridden by
3668 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3669 compilation units with discontinuous ranges. */
3672 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3674 struct attribute
*attr
;
3677 cu
->base_address
= 0;
3679 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3682 cu
->base_address
= DW_ADDR (attr
);
3687 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3690 cu
->base_address
= DW_ADDR (attr
);
3696 /* Initialize a CU (or TU) and read its DIEs.
3697 If the CU defers to a DWO file, read the DWO file as well.
3699 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3700 Otherwise, a new CU is allocated with xmalloc.
3702 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3703 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3705 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3706 linker) then DIE_READER_FUNC will not get called. */
3709 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3710 int use_existing_cu
, int keep
,
3711 die_reader_func_ftype
*die_reader_func
,
3714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3715 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3716 bfd
*abfd
= section
->asection
->owner
;
3717 struct dwarf2_cu
*cu
;
3718 gdb_byte
*begin_info_ptr
, *info_ptr
;
3719 struct die_reader_specs reader
;
3720 struct die_info
*comp_unit_die
;
3722 struct attribute
*attr
;
3723 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3724 struct signatured_type
*sig_type
= NULL
;
3726 if (use_existing_cu
)
3729 cleanups
= make_cleanup (null_cleanup
, NULL
);
3731 /* This is cheap if the section is already read in. */
3732 dwarf2_read_section (objfile
, section
);
3734 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3736 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3739 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3743 /* If !use_existing_cu, this_cu->cu must be NULL. */
3744 gdb_assert (this_cu
->cu
== NULL
);
3746 cu
= xmalloc (sizeof (*cu
));
3747 init_one_comp_unit (cu
, this_cu
);
3749 /* If an error occurs while loading, release our storage. */
3750 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3752 if (this_cu
->is_debug_types
)
3756 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3760 /* There's no way to get from PER_CU to its containing
3761 struct signatured_type.
3762 But we have the signature so we can use that. */
3763 sig_type
= lookup_signatured_type (signature
);
3764 /* We've already scanned all the signatured types,
3765 this must succeed. */
3766 gdb_assert (sig_type
!= NULL
);
3767 gdb_assert (&sig_type
->per_cu
== this_cu
);
3768 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3770 /* LENGTH has not been set yet for type units. */
3771 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3773 /* Establish the type offset that can be used to lookup the type. */
3774 sig_type
->type_offset_in_section
.sect_off
=
3775 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3779 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3780 section
, info_ptr
, 0);
3782 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3783 gdb_assert (this_cu
->length
3784 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3788 /* Skip dummy compilation units. */
3789 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3790 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3792 do_cleanups (cleanups
);
3796 /* Read the abbrevs for this compilation unit into a table. */
3797 if (cu
->dwarf2_abbrevs
== NULL
)
3799 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3800 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3803 /* Read the top level CU/TU die. */
3804 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3805 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3807 /* If we have a DWO stub, process it and then read in the DWO file.
3808 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3809 a DWO CU, that this test will fail. */
3810 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3813 char *dwo_name
= DW_STRING (attr
);
3814 const char *comp_dir
;
3815 struct dwo_unit
*dwo_unit
;
3816 ULONGEST signature
; /* Or dwo_id. */
3817 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3818 int i
,num_extra_attrs
;
3821 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3822 " has children (offset 0x%x) [in module %s]"),
3823 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3825 /* These attributes aren't processed until later:
3826 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3827 However, the attribute is found in the stub which we won't have later.
3828 In order to not impose this complication on the rest of the code,
3829 we read them here and copy them to the DWO CU/TU die. */
3830 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3832 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3834 if (! this_cu
->is_debug_types
)
3835 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3836 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3837 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3838 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3840 /* There should be a DW_AT_addr_base attribute here (if needed).
3841 We need the value before we can process DW_FORM_GNU_addr_index. */
3843 cu
->have_addr_base
= 0;
3844 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3847 cu
->addr_base
= DW_UNSND (attr
);
3848 cu
->have_addr_base
= 1;
3851 if (this_cu
->is_debug_types
)
3853 gdb_assert (sig_type
!= NULL
);
3854 signature
= sig_type
->signature
;
3858 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
3860 error (_("Dwarf Error: missing dwo_id [in module %s]"),
3862 signature
= DW_UNSND (attr
);
3865 /* We may need the comp_dir in order to find the DWO file. */
3867 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3869 comp_dir
= DW_STRING (attr
);
3871 if (this_cu
->is_debug_types
)
3872 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
3874 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
3877 if (dwo_unit
== NULL
)
3879 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
3880 " with ID %s [in module %s]"),
3881 this_cu
->offset
.sect_off
,
3882 phex (signature
, sizeof (signature
)),
3886 /* Set up for reading the DWO CU/TU. */
3887 cu
->dwo_unit
= dwo_unit
;
3888 section
= dwo_unit
->info_or_types_section
;
3889 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
3890 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
3892 if (this_cu
->is_debug_types
)
3896 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3899 gdb_assert (sig_type
->signature
== signature
);
3900 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3901 gdb_assert (dwo_unit
->length
3902 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3904 /* Establish the type offset that can be used to lookup the type.
3905 For DWO files, we don't know it until now. */
3906 sig_type
->type_offset_in_section
.sect_off
=
3907 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
3911 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3912 section
, info_ptr
, 0);
3913 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3914 gdb_assert (dwo_unit
->length
3915 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3918 /* Discard the original CU's abbrev table, and read the DWO's. */
3919 dwarf2_free_abbrev_table (cu
);
3920 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
3922 /* Read in the die, but leave space to copy over the attributes
3923 from the stub. This has the benefit of simplifying the rest of
3924 the code - all the real work is done here. */
3925 num_extra_attrs
= ((stmt_list
!= NULL
)
3928 + (ranges
!= NULL
));
3929 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
3930 &has_children
, num_extra_attrs
);
3932 /* Copy over the attributes from the stub to the DWO die. */
3933 i
= comp_unit_die
->num_attrs
;
3934 if (stmt_list
!= NULL
)
3935 comp_unit_die
->attrs
[i
++] = *stmt_list
;
3937 comp_unit_die
->attrs
[i
++] = *low_pc
;
3938 if (high_pc
!= NULL
)
3939 comp_unit_die
->attrs
[i
++] = *high_pc
;
3941 comp_unit_die
->attrs
[i
++] = *ranges
;
3942 comp_unit_die
->num_attrs
+= num_extra_attrs
;
3944 /* Skip dummy compilation units. */
3945 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
3946 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3948 do_cleanups (cleanups
);
3953 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3955 if (free_cu_cleanup
!= NULL
)
3959 /* We've successfully allocated this compilation unit. Let our
3960 caller clean it up when finished with it. */
3961 discard_cleanups (free_cu_cleanup
);
3963 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3964 So we have to manually free the abbrev table. */
3965 dwarf2_free_abbrev_table (cu
);
3967 /* Link this CU into read_in_chain. */
3968 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3969 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3972 do_cleanups (free_cu_cleanup
);
3975 do_cleanups (cleanups
);
3978 /* Read CU/TU THIS_CU in section SECTION,
3979 but do not follow DW_AT_GNU_dwo_name if present.
3980 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
3981 have already done the lookup to find the DWO file).
3983 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3984 THIS_CU->is_debug_types, but nothing else.
3986 We fill in THIS_CU->length.
3988 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3989 linker) then DIE_READER_FUNC will not get called.
3991 THIS_CU->cu is always freed when done.
3992 This is done in order to not leave THIS_CU->cu in a state where we have
3993 to care whether it refers to the "main" CU or the DWO CU. */
3996 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3997 struct dwarf2_section_info
*abbrev_section
,
3998 struct dwo_file
*dwo_file
,
3999 die_reader_func_ftype
*die_reader_func
,
4002 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4003 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4004 bfd
*abfd
= section
->asection
->owner
;
4005 struct dwarf2_cu cu
;
4006 gdb_byte
*begin_info_ptr
, *info_ptr
;
4007 struct die_reader_specs reader
;
4008 struct cleanup
*cleanups
;
4009 struct die_info
*comp_unit_die
;
4012 gdb_assert (this_cu
->cu
== NULL
);
4014 /* This is cheap if the section is already read in. */
4015 dwarf2_read_section (objfile
, section
);
4017 init_one_comp_unit (&cu
, this_cu
);
4019 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4021 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4022 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
4023 this_cu
->is_debug_types
);
4025 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4027 /* Skip dummy compilation units. */
4028 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4029 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4031 do_cleanups (cleanups
);
4035 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4036 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4038 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4039 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4041 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4043 do_cleanups (cleanups
);
4046 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4047 does not lookup the specified DWO file.
4048 This cannot be used to read DWO files.
4050 THIS_CU->cu is always freed when done.
4051 This is done in order to not leave THIS_CU->cu in a state where we have
4052 to care whether it refers to the "main" CU or the DWO CU.
4053 We can revisit this if the data shows there's a performance issue. */
4056 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4057 die_reader_func_ftype
*die_reader_func
,
4060 init_cutu_and_read_dies_no_follow (this_cu
,
4061 &dwarf2_per_objfile
->abbrev
,
4063 die_reader_func
, data
);
4066 /* die_reader_func for process_psymtab_comp_unit. */
4069 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4071 struct die_info
*comp_unit_die
,
4075 struct dwarf2_cu
*cu
= reader
->cu
;
4076 struct objfile
*objfile
= cu
->objfile
;
4077 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4078 struct attribute
*attr
;
4080 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4081 struct partial_symtab
*pst
;
4083 const char *filename
;
4084 int *want_partial_unit_ptr
= data
;
4086 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4087 && (want_partial_unit_ptr
== NULL
4088 || !*want_partial_unit_ptr
))
4091 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4093 cu
->list_in_scope
= &file_symbols
;
4095 /* Allocate a new partial symbol table structure. */
4096 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4097 if (attr
== NULL
|| !DW_STRING (attr
))
4100 filename
= DW_STRING (attr
);
4101 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4103 /* TEXTLOW and TEXTHIGH are set below. */
4105 objfile
->global_psymbols
.next
,
4106 objfile
->static_psymbols
.next
);
4107 pst
->psymtabs_addrmap_supported
= 1;
4109 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4111 pst
->dirname
= DW_STRING (attr
);
4113 pst
->read_symtab_private
= per_cu
;
4115 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4117 /* Store the function that reads in the rest of the symbol table. */
4118 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4120 per_cu
->v
.psymtab
= pst
;
4122 dwarf2_find_base_address (comp_unit_die
, cu
);
4124 /* Possibly set the default values of LOWPC and HIGHPC from
4126 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4127 &best_highpc
, cu
, pst
);
4128 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4129 /* Store the contiguous range if it is not empty; it can be empty for
4130 CUs with no code. */
4131 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4132 best_lowpc
+ baseaddr
,
4133 best_highpc
+ baseaddr
- 1, pst
);
4135 /* Check if comp unit has_children.
4136 If so, read the rest of the partial symbols from this comp unit.
4137 If not, there's no more debug_info for this comp unit. */
4140 struct partial_die_info
*first_die
;
4141 CORE_ADDR lowpc
, highpc
;
4143 lowpc
= ((CORE_ADDR
) -1);
4144 highpc
= ((CORE_ADDR
) 0);
4146 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4148 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4151 /* If we didn't find a lowpc, set it to highpc to avoid
4152 complaints from `maint check'. */
4153 if (lowpc
== ((CORE_ADDR
) -1))
4156 /* If the compilation unit didn't have an explicit address range,
4157 then use the information extracted from its child dies. */
4161 best_highpc
= highpc
;
4164 pst
->textlow
= best_lowpc
+ baseaddr
;
4165 pst
->texthigh
= best_highpc
+ baseaddr
;
4167 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4168 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4169 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4170 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4171 sort_pst_symbols (pst
);
4173 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4176 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4177 struct dwarf2_per_cu_data
*iter
;
4179 /* Fill in 'dependencies' here; we fill in 'users' in a
4181 pst
->number_of_dependencies
= len
;
4182 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4183 len
* sizeof (struct symtab
*));
4185 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4188 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4190 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4193 if (per_cu
->is_debug_types
)
4195 /* It's not clear we want to do anything with stmt lists here.
4196 Waiting to see what gcc ultimately does. */
4200 /* Get the list of files included in the current compilation unit,
4201 and build a psymtab for each of them. */
4202 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4206 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4207 Process compilation unit THIS_CU for a psymtab. */
4210 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4211 int want_partial_unit
)
4213 /* If this compilation unit was already read in, free the
4214 cached copy in order to read it in again. This is
4215 necessary because we skipped some symbols when we first
4216 read in the compilation unit (see load_partial_dies).
4217 This problem could be avoided, but the benefit is unclear. */
4218 if (this_cu
->cu
!= NULL
)
4219 free_one_cached_comp_unit (this_cu
);
4221 gdb_assert (! this_cu
->is_debug_types
);
4222 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4223 &want_partial_unit
);
4225 /* Age out any secondary CUs. */
4226 age_cached_comp_units ();
4229 /* Traversal function for htab_traverse_noresize.
4230 Process one .debug_types comp-unit. */
4233 process_psymtab_type_unit (void **slot
, void *info
)
4235 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4236 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4238 gdb_assert (per_cu
->is_debug_types
);
4239 gdb_assert (info
== NULL
);
4241 /* If this compilation unit was already read in, free the
4242 cached copy in order to read it in again. This is
4243 necessary because we skipped some symbols when we first
4244 read in the compilation unit (see load_partial_dies).
4245 This problem could be avoided, but the benefit is unclear. */
4246 if (per_cu
->cu
!= NULL
)
4247 free_one_cached_comp_unit (per_cu
);
4249 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4252 /* Age out any secondary CUs. */
4253 age_cached_comp_units ();
4258 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4259 Build partial symbol tables for the .debug_types comp-units. */
4262 build_type_psymtabs (struct objfile
*objfile
)
4264 if (! create_all_type_units (objfile
))
4267 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4268 process_psymtab_type_unit
, NULL
);
4271 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4274 psymtabs_addrmap_cleanup (void *o
)
4276 struct objfile
*objfile
= o
;
4278 objfile
->psymtabs_addrmap
= NULL
;
4281 /* Compute the 'user' field for each psymtab in OBJFILE. */
4284 set_partial_user (struct objfile
*objfile
)
4288 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4290 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4291 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4294 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4296 /* Set the 'user' field only if it is not already set. */
4297 if (pst
->dependencies
[j
]->user
== NULL
)
4298 pst
->dependencies
[j
]->user
= pst
;
4303 /* Build the partial symbol table by doing a quick pass through the
4304 .debug_info and .debug_abbrev sections. */
4307 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4309 struct cleanup
*back_to
, *addrmap_cleanup
;
4310 struct obstack temp_obstack
;
4313 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4315 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4317 /* Any cached compilation units will be linked by the per-objfile
4318 read_in_chain. Make sure to free them when we're done. */
4319 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4321 build_type_psymtabs (objfile
);
4323 create_all_comp_units (objfile
);
4325 /* Create a temporary address map on a temporary obstack. We later
4326 copy this to the final obstack. */
4327 obstack_init (&temp_obstack
);
4328 make_cleanup_obstack_free (&temp_obstack
);
4329 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4330 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4332 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4334 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4336 process_psymtab_comp_unit (per_cu
, 0);
4339 set_partial_user (objfile
);
4341 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4342 &objfile
->objfile_obstack
);
4343 discard_cleanups (addrmap_cleanup
);
4345 do_cleanups (back_to
);
4348 /* die_reader_func for load_partial_comp_unit. */
4351 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4353 struct die_info
*comp_unit_die
,
4357 struct dwarf2_cu
*cu
= reader
->cu
;
4359 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4361 /* Check if comp unit has_children.
4362 If so, read the rest of the partial symbols from this comp unit.
4363 If not, there's no more debug_info for this comp unit. */
4365 load_partial_dies (reader
, info_ptr
, 0);
4368 /* Load the partial DIEs for a secondary CU into memory.
4369 This is also used when rereading a primary CU with load_all_dies. */
4372 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4374 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4377 /* Create a list of all compilation units in OBJFILE.
4378 This is only done for -readnow and building partial symtabs. */
4381 create_all_comp_units (struct objfile
*objfile
)
4385 struct dwarf2_per_cu_data
**all_comp_units
;
4388 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4389 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4393 all_comp_units
= xmalloc (n_allocated
4394 * sizeof (struct dwarf2_per_cu_data
*));
4396 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4397 + dwarf2_per_objfile
->info
.size
)
4399 unsigned int length
, initial_length_size
;
4400 struct dwarf2_per_cu_data
*this_cu
;
4403 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4405 /* Read just enough information to find out where the next
4406 compilation unit is. */
4407 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4408 &initial_length_size
);
4410 /* Save the compilation unit for later lookup. */
4411 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4412 sizeof (struct dwarf2_per_cu_data
));
4413 memset (this_cu
, 0, sizeof (*this_cu
));
4414 this_cu
->offset
= offset
;
4415 this_cu
->length
= length
+ initial_length_size
;
4416 this_cu
->objfile
= objfile
;
4417 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4419 if (n_comp_units
== n_allocated
)
4422 all_comp_units
= xrealloc (all_comp_units
,
4424 * sizeof (struct dwarf2_per_cu_data
*));
4426 all_comp_units
[n_comp_units
++] = this_cu
;
4428 info_ptr
= info_ptr
+ this_cu
->length
;
4431 dwarf2_per_objfile
->all_comp_units
4432 = obstack_alloc (&objfile
->objfile_obstack
,
4433 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4434 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4435 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4436 xfree (all_comp_units
);
4437 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4440 /* Process all loaded DIEs for compilation unit CU, starting at
4441 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4442 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4443 DW_AT_ranges). If NEED_PC is set, then this function will set
4444 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4445 and record the covered ranges in the addrmap. */
4448 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4449 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4451 struct partial_die_info
*pdi
;
4453 /* Now, march along the PDI's, descending into ones which have
4454 interesting children but skipping the children of the other ones,
4455 until we reach the end of the compilation unit. */
4461 fixup_partial_die (pdi
, cu
);
4463 /* Anonymous namespaces or modules have no name but have interesting
4464 children, so we need to look at them. Ditto for anonymous
4467 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4468 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4469 || pdi
->tag
== DW_TAG_imported_unit
)
4473 case DW_TAG_subprogram
:
4474 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4476 case DW_TAG_constant
:
4477 case DW_TAG_variable
:
4478 case DW_TAG_typedef
:
4479 case DW_TAG_union_type
:
4480 if (!pdi
->is_declaration
)
4482 add_partial_symbol (pdi
, cu
);
4485 case DW_TAG_class_type
:
4486 case DW_TAG_interface_type
:
4487 case DW_TAG_structure_type
:
4488 if (!pdi
->is_declaration
)
4490 add_partial_symbol (pdi
, cu
);
4493 case DW_TAG_enumeration_type
:
4494 if (!pdi
->is_declaration
)
4495 add_partial_enumeration (pdi
, cu
);
4497 case DW_TAG_base_type
:
4498 case DW_TAG_subrange_type
:
4499 /* File scope base type definitions are added to the partial
4501 add_partial_symbol (pdi
, cu
);
4503 case DW_TAG_namespace
:
4504 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4507 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4509 case DW_TAG_imported_unit
:
4511 struct dwarf2_per_cu_data
*per_cu
;
4513 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4516 /* Go read the partial unit, if needed. */
4517 if (per_cu
->v
.psymtab
== NULL
)
4518 process_psymtab_comp_unit (per_cu
, 1);
4520 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4529 /* If the die has a sibling, skip to the sibling. */
4531 pdi
= pdi
->die_sibling
;
4535 /* Functions used to compute the fully scoped name of a partial DIE.
4537 Normally, this is simple. For C++, the parent DIE's fully scoped
4538 name is concatenated with "::" and the partial DIE's name. For
4539 Java, the same thing occurs except that "." is used instead of "::".
4540 Enumerators are an exception; they use the scope of their parent
4541 enumeration type, i.e. the name of the enumeration type is not
4542 prepended to the enumerator.
4544 There are two complexities. One is DW_AT_specification; in this
4545 case "parent" means the parent of the target of the specification,
4546 instead of the direct parent of the DIE. The other is compilers
4547 which do not emit DW_TAG_namespace; in this case we try to guess
4548 the fully qualified name of structure types from their members'
4549 linkage names. This must be done using the DIE's children rather
4550 than the children of any DW_AT_specification target. We only need
4551 to do this for structures at the top level, i.e. if the target of
4552 any DW_AT_specification (if any; otherwise the DIE itself) does not
4555 /* Compute the scope prefix associated with PDI's parent, in
4556 compilation unit CU. The result will be allocated on CU's
4557 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4558 field. NULL is returned if no prefix is necessary. */
4560 partial_die_parent_scope (struct partial_die_info
*pdi
,
4561 struct dwarf2_cu
*cu
)
4563 char *grandparent_scope
;
4564 struct partial_die_info
*parent
, *real_pdi
;
4566 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4567 then this means the parent of the specification DIE. */
4570 while (real_pdi
->has_specification
)
4571 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4573 parent
= real_pdi
->die_parent
;
4577 if (parent
->scope_set
)
4578 return parent
->scope
;
4580 fixup_partial_die (parent
, cu
);
4582 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4584 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4585 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4586 Work around this problem here. */
4587 if (cu
->language
== language_cplus
4588 && parent
->tag
== DW_TAG_namespace
4589 && strcmp (parent
->name
, "::") == 0
4590 && grandparent_scope
== NULL
)
4592 parent
->scope
= NULL
;
4593 parent
->scope_set
= 1;
4597 if (pdi
->tag
== DW_TAG_enumerator
)
4598 /* Enumerators should not get the name of the enumeration as a prefix. */
4599 parent
->scope
= grandparent_scope
;
4600 else if (parent
->tag
== DW_TAG_namespace
4601 || parent
->tag
== DW_TAG_module
4602 || parent
->tag
== DW_TAG_structure_type
4603 || parent
->tag
== DW_TAG_class_type
4604 || parent
->tag
== DW_TAG_interface_type
4605 || parent
->tag
== DW_TAG_union_type
4606 || parent
->tag
== DW_TAG_enumeration_type
)
4608 if (grandparent_scope
== NULL
)
4609 parent
->scope
= parent
->name
;
4611 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4613 parent
->name
, 0, cu
);
4617 /* FIXME drow/2004-04-01: What should we be doing with
4618 function-local names? For partial symbols, we should probably be
4620 complaint (&symfile_complaints
,
4621 _("unhandled containing DIE tag %d for DIE at %d"),
4622 parent
->tag
, pdi
->offset
.sect_off
);
4623 parent
->scope
= grandparent_scope
;
4626 parent
->scope_set
= 1;
4627 return parent
->scope
;
4630 /* Return the fully scoped name associated with PDI, from compilation unit
4631 CU. The result will be allocated with malloc. */
4634 partial_die_full_name (struct partial_die_info
*pdi
,
4635 struct dwarf2_cu
*cu
)
4639 /* If this is a template instantiation, we can not work out the
4640 template arguments from partial DIEs. So, unfortunately, we have
4641 to go through the full DIEs. At least any work we do building
4642 types here will be reused if full symbols are loaded later. */
4643 if (pdi
->has_template_arguments
)
4645 fixup_partial_die (pdi
, cu
);
4647 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4649 struct die_info
*die
;
4650 struct attribute attr
;
4651 struct dwarf2_cu
*ref_cu
= cu
;
4653 /* DW_FORM_ref_addr is using section offset. */
4655 attr
.form
= DW_FORM_ref_addr
;
4656 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4657 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4659 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4663 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4664 if (parent_scope
== NULL
)
4667 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4671 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4673 struct objfile
*objfile
= cu
->objfile
;
4675 char *actual_name
= NULL
;
4677 int built_actual_name
= 0;
4679 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4681 actual_name
= partial_die_full_name (pdi
, cu
);
4683 built_actual_name
= 1;
4685 if (actual_name
== NULL
)
4686 actual_name
= pdi
->name
;
4690 case DW_TAG_subprogram
:
4691 if (pdi
->is_external
|| cu
->language
== language_ada
)
4693 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4694 of the global scope. But in Ada, we want to be able to access
4695 nested procedures globally. So all Ada subprograms are stored
4696 in the global scope. */
4697 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4698 mst_text, objfile); */
4699 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4701 VAR_DOMAIN
, LOC_BLOCK
,
4702 &objfile
->global_psymbols
,
4703 0, pdi
->lowpc
+ baseaddr
,
4704 cu
->language
, objfile
);
4708 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4709 mst_file_text, objfile); */
4710 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4712 VAR_DOMAIN
, LOC_BLOCK
,
4713 &objfile
->static_psymbols
,
4714 0, pdi
->lowpc
+ baseaddr
,
4715 cu
->language
, objfile
);
4718 case DW_TAG_constant
:
4720 struct psymbol_allocation_list
*list
;
4722 if (pdi
->is_external
)
4723 list
= &objfile
->global_psymbols
;
4725 list
= &objfile
->static_psymbols
;
4726 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4727 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4728 list
, 0, 0, cu
->language
, objfile
);
4731 case DW_TAG_variable
:
4733 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4737 && !dwarf2_per_objfile
->has_section_at_zero
)
4739 /* A global or static variable may also have been stripped
4740 out by the linker if unused, in which case its address
4741 will be nullified; do not add such variables into partial
4742 symbol table then. */
4744 else if (pdi
->is_external
)
4747 Don't enter into the minimal symbol tables as there is
4748 a minimal symbol table entry from the ELF symbols already.
4749 Enter into partial symbol table if it has a location
4750 descriptor or a type.
4751 If the location descriptor is missing, new_symbol will create
4752 a LOC_UNRESOLVED symbol, the address of the variable will then
4753 be determined from the minimal symbol table whenever the variable
4755 The address for the partial symbol table entry is not
4756 used by GDB, but it comes in handy for debugging partial symbol
4759 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4760 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4762 VAR_DOMAIN
, LOC_STATIC
,
4763 &objfile
->global_psymbols
,
4765 cu
->language
, objfile
);
4769 /* Static Variable. Skip symbols without location descriptors. */
4770 if (pdi
->d
.locdesc
== NULL
)
4772 if (built_actual_name
)
4773 xfree (actual_name
);
4776 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4777 mst_file_data, objfile); */
4778 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4780 VAR_DOMAIN
, LOC_STATIC
,
4781 &objfile
->static_psymbols
,
4783 cu
->language
, objfile
);
4786 case DW_TAG_typedef
:
4787 case DW_TAG_base_type
:
4788 case DW_TAG_subrange_type
:
4789 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4791 VAR_DOMAIN
, LOC_TYPEDEF
,
4792 &objfile
->static_psymbols
,
4793 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4795 case DW_TAG_namespace
:
4796 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4798 VAR_DOMAIN
, LOC_TYPEDEF
,
4799 &objfile
->global_psymbols
,
4800 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4802 case DW_TAG_class_type
:
4803 case DW_TAG_interface_type
:
4804 case DW_TAG_structure_type
:
4805 case DW_TAG_union_type
:
4806 case DW_TAG_enumeration_type
:
4807 /* Skip external references. The DWARF standard says in the section
4808 about "Structure, Union, and Class Type Entries": "An incomplete
4809 structure, union or class type is represented by a structure,
4810 union or class entry that does not have a byte size attribute
4811 and that has a DW_AT_declaration attribute." */
4812 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4814 if (built_actual_name
)
4815 xfree (actual_name
);
4819 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4820 static vs. global. */
4821 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4823 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4824 (cu
->language
== language_cplus
4825 || cu
->language
== language_java
)
4826 ? &objfile
->global_psymbols
4827 : &objfile
->static_psymbols
,
4828 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4831 case DW_TAG_enumerator
:
4832 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4834 VAR_DOMAIN
, LOC_CONST
,
4835 (cu
->language
== language_cplus
4836 || cu
->language
== language_java
)
4837 ? &objfile
->global_psymbols
4838 : &objfile
->static_psymbols
,
4839 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4845 if (built_actual_name
)
4846 xfree (actual_name
);
4849 /* Read a partial die corresponding to a namespace; also, add a symbol
4850 corresponding to that namespace to the symbol table. NAMESPACE is
4851 the name of the enclosing namespace. */
4854 add_partial_namespace (struct partial_die_info
*pdi
,
4855 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4856 int need_pc
, struct dwarf2_cu
*cu
)
4858 /* Add a symbol for the namespace. */
4860 add_partial_symbol (pdi
, cu
);
4862 /* Now scan partial symbols in that namespace. */
4864 if (pdi
->has_children
)
4865 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4868 /* Read a partial die corresponding to a Fortran module. */
4871 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4872 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4874 /* Now scan partial symbols in that module. */
4876 if (pdi
->has_children
)
4877 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4880 /* Read a partial die corresponding to a subprogram and create a partial
4881 symbol for that subprogram. When the CU language allows it, this
4882 routine also defines a partial symbol for each nested subprogram
4883 that this subprogram contains.
4885 DIE my also be a lexical block, in which case we simply search
4886 recursively for suprograms defined inside that lexical block.
4887 Again, this is only performed when the CU language allows this
4888 type of definitions. */
4891 add_partial_subprogram (struct partial_die_info
*pdi
,
4892 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4893 int need_pc
, struct dwarf2_cu
*cu
)
4895 if (pdi
->tag
== DW_TAG_subprogram
)
4897 if (pdi
->has_pc_info
)
4899 if (pdi
->lowpc
< *lowpc
)
4900 *lowpc
= pdi
->lowpc
;
4901 if (pdi
->highpc
> *highpc
)
4902 *highpc
= pdi
->highpc
;
4906 struct objfile
*objfile
= cu
->objfile
;
4908 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4909 SECT_OFF_TEXT (objfile
));
4910 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4911 pdi
->lowpc
+ baseaddr
,
4912 pdi
->highpc
- 1 + baseaddr
,
4913 cu
->per_cu
->v
.psymtab
);
4917 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4919 if (!pdi
->is_declaration
)
4920 /* Ignore subprogram DIEs that do not have a name, they are
4921 illegal. Do not emit a complaint at this point, we will
4922 do so when we convert this psymtab into a symtab. */
4924 add_partial_symbol (pdi
, cu
);
4928 if (! pdi
->has_children
)
4931 if (cu
->language
== language_ada
)
4933 pdi
= pdi
->die_child
;
4936 fixup_partial_die (pdi
, cu
);
4937 if (pdi
->tag
== DW_TAG_subprogram
4938 || pdi
->tag
== DW_TAG_lexical_block
)
4939 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4940 pdi
= pdi
->die_sibling
;
4945 /* Read a partial die corresponding to an enumeration type. */
4948 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4949 struct dwarf2_cu
*cu
)
4951 struct partial_die_info
*pdi
;
4953 if (enum_pdi
->name
!= NULL
)
4954 add_partial_symbol (enum_pdi
, cu
);
4956 pdi
= enum_pdi
->die_child
;
4959 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4960 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4962 add_partial_symbol (pdi
, cu
);
4963 pdi
= pdi
->die_sibling
;
4967 /* Return the initial uleb128 in the die at INFO_PTR. */
4970 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4972 unsigned int bytes_read
;
4974 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4977 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4978 Return the corresponding abbrev, or NULL if the number is zero (indicating
4979 an empty DIE). In either case *BYTES_READ will be set to the length of
4980 the initial number. */
4982 static struct abbrev_info
*
4983 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4984 struct dwarf2_cu
*cu
)
4986 bfd
*abfd
= cu
->objfile
->obfd
;
4987 unsigned int abbrev_number
;
4988 struct abbrev_info
*abbrev
;
4990 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4992 if (abbrev_number
== 0)
4995 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4998 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4999 abbrev_number
, bfd_get_filename (abfd
));
5005 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5006 Returns a pointer to the end of a series of DIEs, terminated by an empty
5007 DIE. Any children of the skipped DIEs will also be skipped. */
5010 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5012 struct dwarf2_cu
*cu
= reader
->cu
;
5013 struct abbrev_info
*abbrev
;
5014 unsigned int bytes_read
;
5018 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5020 return info_ptr
+ bytes_read
;
5022 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5026 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5027 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5028 abbrev corresponding to that skipped uleb128 should be passed in
5029 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5033 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5034 struct abbrev_info
*abbrev
)
5036 unsigned int bytes_read
;
5037 struct attribute attr
;
5038 bfd
*abfd
= reader
->abfd
;
5039 struct dwarf2_cu
*cu
= reader
->cu
;
5040 gdb_byte
*buffer
= reader
->buffer
;
5041 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5042 gdb_byte
*start_info_ptr
= info_ptr
;
5043 unsigned int form
, i
;
5045 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5047 /* The only abbrev we care about is DW_AT_sibling. */
5048 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5050 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5051 if (attr
.form
== DW_FORM_ref_addr
)
5052 complaint (&symfile_complaints
,
5053 _("ignoring absolute DW_AT_sibling"));
5055 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5058 /* If it isn't DW_AT_sibling, skip this attribute. */
5059 form
= abbrev
->attrs
[i
].form
;
5063 case DW_FORM_ref_addr
:
5064 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5065 and later it is offset sized. */
5066 if (cu
->header
.version
== 2)
5067 info_ptr
+= cu
->header
.addr_size
;
5069 info_ptr
+= cu
->header
.offset_size
;
5072 info_ptr
+= cu
->header
.addr_size
;
5079 case DW_FORM_flag_present
:
5091 case DW_FORM_ref_sig8
:
5094 case DW_FORM_string
:
5095 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5096 info_ptr
+= bytes_read
;
5098 case DW_FORM_sec_offset
:
5100 info_ptr
+= cu
->header
.offset_size
;
5102 case DW_FORM_exprloc
:
5104 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5105 info_ptr
+= bytes_read
;
5107 case DW_FORM_block1
:
5108 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5110 case DW_FORM_block2
:
5111 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5113 case DW_FORM_block4
:
5114 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5118 case DW_FORM_ref_udata
:
5119 case DW_FORM_GNU_addr_index
:
5120 case DW_FORM_GNU_str_index
:
5121 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5123 case DW_FORM_indirect
:
5124 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5125 info_ptr
+= bytes_read
;
5126 /* We need to continue parsing from here, so just go back to
5128 goto skip_attribute
;
5131 error (_("Dwarf Error: Cannot handle %s "
5132 "in DWARF reader [in module %s]"),
5133 dwarf_form_name (form
),
5134 bfd_get_filename (abfd
));
5138 if (abbrev
->has_children
)
5139 return skip_children (reader
, info_ptr
);
5144 /* Locate ORIG_PDI's sibling.
5145 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5148 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5149 struct partial_die_info
*orig_pdi
,
5152 /* Do we know the sibling already? */
5154 if (orig_pdi
->sibling
)
5155 return orig_pdi
->sibling
;
5157 /* Are there any children to deal with? */
5159 if (!orig_pdi
->has_children
)
5162 /* Skip the children the long way. */
5164 return skip_children (reader
, info_ptr
);
5167 /* Expand this partial symbol table into a full symbol table. */
5170 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5176 warning (_("bug: psymtab for %s is already read in."),
5183 printf_filtered (_("Reading in symbols for %s..."),
5185 gdb_flush (gdb_stdout
);
5188 /* Restore our global data. */
5189 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5190 dwarf2_objfile_data_key
);
5192 /* If this psymtab is constructed from a debug-only objfile, the
5193 has_section_at_zero flag will not necessarily be correct. We
5194 can get the correct value for this flag by looking at the data
5195 associated with the (presumably stripped) associated objfile. */
5196 if (pst
->objfile
->separate_debug_objfile_backlink
)
5198 struct dwarf2_per_objfile
*dpo_backlink
5199 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5200 dwarf2_objfile_data_key
);
5202 dwarf2_per_objfile
->has_section_at_zero
5203 = dpo_backlink
->has_section_at_zero
;
5206 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5208 psymtab_to_symtab_1 (pst
);
5210 /* Finish up the debug error message. */
5212 printf_filtered (_("done.\n"));
5216 process_cu_includes ();
5219 /* Reading in full CUs. */
5221 /* Add PER_CU to the queue. */
5224 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5225 enum language pretend_language
)
5227 struct dwarf2_queue_item
*item
;
5230 item
= xmalloc (sizeof (*item
));
5231 item
->per_cu
= per_cu
;
5232 item
->pretend_language
= pretend_language
;
5235 if (dwarf2_queue
== NULL
)
5236 dwarf2_queue
= item
;
5238 dwarf2_queue_tail
->next
= item
;
5240 dwarf2_queue_tail
= item
;
5243 /* Process the queue. */
5246 process_queue (void)
5248 struct dwarf2_queue_item
*item
, *next_item
;
5250 /* The queue starts out with one item, but following a DIE reference
5251 may load a new CU, adding it to the end of the queue. */
5252 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5254 if (dwarf2_per_objfile
->using_index
5255 ? !item
->per_cu
->v
.quick
->symtab
5256 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5257 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5259 item
->per_cu
->queued
= 0;
5260 next_item
= item
->next
;
5264 dwarf2_queue_tail
= NULL
;
5267 /* Free all allocated queue entries. This function only releases anything if
5268 an error was thrown; if the queue was processed then it would have been
5269 freed as we went along. */
5272 dwarf2_release_queue (void *dummy
)
5274 struct dwarf2_queue_item
*item
, *last
;
5276 item
= dwarf2_queue
;
5279 /* Anything still marked queued is likely to be in an
5280 inconsistent state, so discard it. */
5281 if (item
->per_cu
->queued
)
5283 if (item
->per_cu
->cu
!= NULL
)
5284 free_one_cached_comp_unit (item
->per_cu
);
5285 item
->per_cu
->queued
= 0;
5293 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5296 /* Read in full symbols for PST, and anything it depends on. */
5299 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5301 struct dwarf2_per_cu_data
*per_cu
;
5307 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5308 if (!pst
->dependencies
[i
]->readin
5309 && pst
->dependencies
[i
]->user
== NULL
)
5311 /* Inform about additional files that need to be read in. */
5314 /* FIXME: i18n: Need to make this a single string. */
5315 fputs_filtered (" ", gdb_stdout
);
5317 fputs_filtered ("and ", gdb_stdout
);
5319 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5320 wrap_here (""); /* Flush output. */
5321 gdb_flush (gdb_stdout
);
5323 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5326 per_cu
= pst
->read_symtab_private
;
5330 /* It's an include file, no symbols to read for it.
5331 Everything is in the parent symtab. */
5336 dw2_do_instantiate_symtab (per_cu
);
5339 /* Trivial hash function for die_info: the hash value of a DIE
5340 is its offset in .debug_info for this objfile. */
5343 die_hash (const void *item
)
5345 const struct die_info
*die
= item
;
5347 return die
->offset
.sect_off
;
5350 /* Trivial comparison function for die_info structures: two DIEs
5351 are equal if they have the same offset. */
5354 die_eq (const void *item_lhs
, const void *item_rhs
)
5356 const struct die_info
*die_lhs
= item_lhs
;
5357 const struct die_info
*die_rhs
= item_rhs
;
5359 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5362 /* die_reader_func for load_full_comp_unit.
5363 This is identical to read_signatured_type_reader,
5364 but is kept separate for now. */
5367 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5369 struct die_info
*comp_unit_die
,
5373 struct dwarf2_cu
*cu
= reader
->cu
;
5374 enum language
*language_ptr
= data
;
5376 gdb_assert (cu
->die_hash
== NULL
);
5378 htab_create_alloc_ex (cu
->header
.length
/ 12,
5382 &cu
->comp_unit_obstack
,
5383 hashtab_obstack_allocate
,
5384 dummy_obstack_deallocate
);
5387 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5388 &info_ptr
, comp_unit_die
);
5389 cu
->dies
= comp_unit_die
;
5390 /* comp_unit_die is not stored in die_hash, no need. */
5392 /* We try not to read any attributes in this function, because not
5393 all CUs needed for references have been loaded yet, and symbol
5394 table processing isn't initialized. But we have to set the CU language,
5395 or we won't be able to build types correctly.
5396 Similarly, if we do not read the producer, we can not apply
5397 producer-specific interpretation. */
5398 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5401 /* Load the DIEs associated with PER_CU into memory. */
5404 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5405 enum language pretend_language
)
5407 gdb_assert (! this_cu
->is_debug_types
);
5409 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5413 /* Add a DIE to the delayed physname list. */
5416 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5417 const char *name
, struct die_info
*die
,
5418 struct dwarf2_cu
*cu
)
5420 struct delayed_method_info mi
;
5422 mi
.fnfield_index
= fnfield_index
;
5426 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5429 /* A cleanup for freeing the delayed method list. */
5432 free_delayed_list (void *ptr
)
5434 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5435 if (cu
->method_list
!= NULL
)
5437 VEC_free (delayed_method_info
, cu
->method_list
);
5438 cu
->method_list
= NULL
;
5442 /* Compute the physnames of any methods on the CU's method list.
5444 The computation of method physnames is delayed in order to avoid the
5445 (bad) condition that one of the method's formal parameters is of an as yet
5449 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5452 struct delayed_method_info
*mi
;
5453 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5455 const char *physname
;
5456 struct fn_fieldlist
*fn_flp
5457 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5458 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5459 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5463 /* Go objects should be embedded in a DW_TAG_module DIE,
5464 and it's not clear if/how imported objects will appear.
5465 To keep Go support simple until that's worked out,
5466 go back through what we've read and create something usable.
5467 We could do this while processing each DIE, and feels kinda cleaner,
5468 but that way is more invasive.
5469 This is to, for example, allow the user to type "p var" or "b main"
5470 without having to specify the package name, and allow lookups
5471 of module.object to work in contexts that use the expression
5475 fixup_go_packaging (struct dwarf2_cu
*cu
)
5477 char *package_name
= NULL
;
5478 struct pending
*list
;
5481 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5483 for (i
= 0; i
< list
->nsyms
; ++i
)
5485 struct symbol
*sym
= list
->symbol
[i
];
5487 if (SYMBOL_LANGUAGE (sym
) == language_go
5488 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5490 char *this_package_name
= go_symbol_package_name (sym
);
5492 if (this_package_name
== NULL
)
5494 if (package_name
== NULL
)
5495 package_name
= this_package_name
;
5498 if (strcmp (package_name
, this_package_name
) != 0)
5499 complaint (&symfile_complaints
,
5500 _("Symtab %s has objects from two different Go packages: %s and %s"),
5501 (sym
->symtab
&& sym
->symtab
->filename
5502 ? sym
->symtab
->filename
5503 : cu
->objfile
->name
),
5504 this_package_name
, package_name
);
5505 xfree (this_package_name
);
5511 if (package_name
!= NULL
)
5513 struct objfile
*objfile
= cu
->objfile
;
5514 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5515 package_name
, objfile
);
5518 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5520 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5521 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5522 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5523 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5524 e.g., "main" finds the "main" module and not C's main(). */
5525 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5526 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5527 SYMBOL_TYPE (sym
) = type
;
5529 add_symbol_to_list (sym
, &global_symbols
);
5531 xfree (package_name
);
5535 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5537 /* Return the symtab for PER_CU. This works properly regardless of
5538 whether we're using the index or psymtabs. */
5540 static struct symtab
*
5541 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5543 return (dwarf2_per_objfile
->using_index
5544 ? per_cu
->v
.quick
->symtab
5545 : per_cu
->v
.psymtab
->symtab
);
5548 /* A helper function for computing the list of all symbol tables
5549 included by PER_CU. */
5552 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5553 htab_t all_children
,
5554 struct dwarf2_per_cu_data
*per_cu
)
5558 struct dwarf2_per_cu_data
*iter
;
5560 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5563 /* This inclusion and its children have been processed. */
5568 /* Only add a CU if it has a symbol table. */
5569 if (get_symtab (per_cu
) != NULL
)
5570 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5573 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5575 recursively_compute_inclusions (result
, all_children
, iter
);
5578 /* Compute the symtab 'includes' fields for the symtab related to
5582 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5584 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5587 struct dwarf2_per_cu_data
*iter
;
5588 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5589 htab_t all_children
;
5590 struct symtab
*symtab
= get_symtab (per_cu
);
5592 /* If we don't have a symtab, we can just skip this case. */
5596 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5597 NULL
, xcalloc
, xfree
);
5600 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5603 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5605 /* Now we have a transitive closure of all the included CUs, so
5606 we can convert it to a list of symtabs. */
5607 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5609 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5610 (len
+ 1) * sizeof (struct symtab
*));
5612 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5614 symtab
->includes
[ix
] = get_symtab (iter
);
5615 symtab
->includes
[len
] = NULL
;
5617 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5618 htab_delete (all_children
);
5622 /* Compute the 'includes' field for the symtabs of all the CUs we just
5626 process_cu_includes (void)
5629 struct dwarf2_per_cu_data
*iter
;
5632 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5635 compute_symtab_includes (iter
);
5637 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5640 /* Generate full symbol information for PER_CU, whose DIEs have
5641 already been loaded into memory. */
5644 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5645 enum language pretend_language
)
5647 struct dwarf2_cu
*cu
= per_cu
->cu
;
5648 struct objfile
*objfile
= per_cu
->objfile
;
5649 CORE_ADDR lowpc
, highpc
;
5650 struct symtab
*symtab
;
5651 struct cleanup
*back_to
, *delayed_list_cleanup
;
5654 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5657 back_to
= make_cleanup (really_free_pendings
, NULL
);
5658 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5660 cu
->list_in_scope
= &file_symbols
;
5662 cu
->language
= pretend_language
;
5663 cu
->language_defn
= language_def (cu
->language
);
5665 /* Do line number decoding in read_file_scope () */
5666 process_die (cu
->dies
, cu
);
5668 /* For now fudge the Go package. */
5669 if (cu
->language
== language_go
)
5670 fixup_go_packaging (cu
);
5672 /* Now that we have processed all the DIEs in the CU, all the types
5673 should be complete, and it should now be safe to compute all of the
5675 compute_delayed_physnames (cu
);
5676 do_cleanups (delayed_list_cleanup
);
5678 /* Some compilers don't define a DW_AT_high_pc attribute for the
5679 compilation unit. If the DW_AT_high_pc is missing, synthesize
5680 it, by scanning the DIE's below the compilation unit. */
5681 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5683 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5687 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5689 /* Set symtab language to language from DW_AT_language. If the
5690 compilation is from a C file generated by language preprocessors, do
5691 not set the language if it was already deduced by start_subfile. */
5692 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5693 symtab
->language
= cu
->language
;
5695 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5696 produce DW_AT_location with location lists but it can be possibly
5697 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5698 there were bugs in prologue debug info, fixed later in GCC-4.5
5699 by "unwind info for epilogues" patch (which is not directly related).
5701 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5702 needed, it would be wrong due to missing DW_AT_producer there.
5704 Still one can confuse GDB by using non-standard GCC compilation
5705 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5707 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5708 symtab
->locations_valid
= 1;
5710 if (gcc_4_minor
>= 5)
5711 symtab
->epilogue_unwind_valid
= 1;
5713 symtab
->call_site_htab
= cu
->call_site_htab
;
5716 if (dwarf2_per_objfile
->using_index
)
5717 per_cu
->v
.quick
->symtab
= symtab
;
5720 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5721 pst
->symtab
= symtab
;
5725 /* Push it for inclusion processing later. */
5726 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5728 do_cleanups (back_to
);
5731 /* Process an imported unit DIE. */
5734 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5736 struct attribute
*attr
;
5738 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5741 struct dwarf2_per_cu_data
*per_cu
;
5742 struct symtab
*imported_symtab
;
5745 offset
= dwarf2_get_ref_die_offset (attr
);
5746 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5748 /* Queue the unit, if needed. */
5749 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5750 load_full_comp_unit (per_cu
, cu
->language
);
5752 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5757 /* Process a die and its children. */
5760 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5764 case DW_TAG_padding
:
5766 case DW_TAG_compile_unit
:
5767 case DW_TAG_partial_unit
:
5768 read_file_scope (die
, cu
);
5770 case DW_TAG_type_unit
:
5771 read_type_unit_scope (die
, cu
);
5773 case DW_TAG_subprogram
:
5774 case DW_TAG_inlined_subroutine
:
5775 read_func_scope (die
, cu
);
5777 case DW_TAG_lexical_block
:
5778 case DW_TAG_try_block
:
5779 case DW_TAG_catch_block
:
5780 read_lexical_block_scope (die
, cu
);
5782 case DW_TAG_GNU_call_site
:
5783 read_call_site_scope (die
, cu
);
5785 case DW_TAG_class_type
:
5786 case DW_TAG_interface_type
:
5787 case DW_TAG_structure_type
:
5788 case DW_TAG_union_type
:
5789 process_structure_scope (die
, cu
);
5791 case DW_TAG_enumeration_type
:
5792 process_enumeration_scope (die
, cu
);
5795 /* These dies have a type, but processing them does not create
5796 a symbol or recurse to process the children. Therefore we can
5797 read them on-demand through read_type_die. */
5798 case DW_TAG_subroutine_type
:
5799 case DW_TAG_set_type
:
5800 case DW_TAG_array_type
:
5801 case DW_TAG_pointer_type
:
5802 case DW_TAG_ptr_to_member_type
:
5803 case DW_TAG_reference_type
:
5804 case DW_TAG_string_type
:
5807 case DW_TAG_base_type
:
5808 case DW_TAG_subrange_type
:
5809 case DW_TAG_typedef
:
5810 /* Add a typedef symbol for the type definition, if it has a
5812 new_symbol (die
, read_type_die (die
, cu
), cu
);
5814 case DW_TAG_common_block
:
5815 read_common_block (die
, cu
);
5817 case DW_TAG_common_inclusion
:
5819 case DW_TAG_namespace
:
5820 processing_has_namespace_info
= 1;
5821 read_namespace (die
, cu
);
5824 processing_has_namespace_info
= 1;
5825 read_module (die
, cu
);
5827 case DW_TAG_imported_declaration
:
5828 case DW_TAG_imported_module
:
5829 processing_has_namespace_info
= 1;
5830 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5831 || cu
->language
!= language_fortran
))
5832 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5833 dwarf_tag_name (die
->tag
));
5834 read_import_statement (die
, cu
);
5837 case DW_TAG_imported_unit
:
5838 process_imported_unit_die (die
, cu
);
5842 new_symbol (die
, NULL
, cu
);
5847 /* A helper function for dwarf2_compute_name which determines whether DIE
5848 needs to have the name of the scope prepended to the name listed in the
5852 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5854 struct attribute
*attr
;
5858 case DW_TAG_namespace
:
5859 case DW_TAG_typedef
:
5860 case DW_TAG_class_type
:
5861 case DW_TAG_interface_type
:
5862 case DW_TAG_structure_type
:
5863 case DW_TAG_union_type
:
5864 case DW_TAG_enumeration_type
:
5865 case DW_TAG_enumerator
:
5866 case DW_TAG_subprogram
:
5870 case DW_TAG_variable
:
5871 case DW_TAG_constant
:
5872 /* We only need to prefix "globally" visible variables. These include
5873 any variable marked with DW_AT_external or any variable that
5874 lives in a namespace. [Variables in anonymous namespaces
5875 require prefixing, but they are not DW_AT_external.] */
5877 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5879 struct dwarf2_cu
*spec_cu
= cu
;
5881 return die_needs_namespace (die_specification (die
, &spec_cu
),
5885 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5886 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5887 && die
->parent
->tag
!= DW_TAG_module
)
5889 /* A variable in a lexical block of some kind does not need a
5890 namespace, even though in C++ such variables may be external
5891 and have a mangled name. */
5892 if (die
->parent
->tag
== DW_TAG_lexical_block
5893 || die
->parent
->tag
== DW_TAG_try_block
5894 || die
->parent
->tag
== DW_TAG_catch_block
5895 || die
->parent
->tag
== DW_TAG_subprogram
)
5904 /* Retrieve the last character from a mem_file. */
5907 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5909 char *last_char_p
= (char *) object
;
5912 *last_char_p
= buffer
[length
- 1];
5915 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5916 compute the physname for the object, which include a method's:
5917 - formal parameters (C++/Java),
5918 - receiver type (Go),
5919 - return type (Java).
5921 The term "physname" is a bit confusing.
5922 For C++, for example, it is the demangled name.
5923 For Go, for example, it's the mangled name.
5925 For Ada, return the DIE's linkage name rather than the fully qualified
5926 name. PHYSNAME is ignored..
5928 The result is allocated on the objfile_obstack and canonicalized. */
5931 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5934 struct objfile
*objfile
= cu
->objfile
;
5937 name
= dwarf2_name (die
, cu
);
5939 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5940 compute it by typename_concat inside GDB. */
5941 if (cu
->language
== language_ada
5942 || (cu
->language
== language_fortran
&& physname
))
5944 /* For Ada unit, we prefer the linkage name over the name, as
5945 the former contains the exported name, which the user expects
5946 to be able to reference. Ideally, we want the user to be able
5947 to reference this entity using either natural or linkage name,
5948 but we haven't started looking at this enhancement yet. */
5949 struct attribute
*attr
;
5951 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5953 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5954 if (attr
&& DW_STRING (attr
))
5955 return DW_STRING (attr
);
5958 /* These are the only languages we know how to qualify names in. */
5960 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5961 || cu
->language
== language_fortran
))
5963 if (die_needs_namespace (die
, cu
))
5967 struct ui_file
*buf
;
5969 prefix
= determine_prefix (die
, cu
);
5970 buf
= mem_fileopen ();
5971 if (*prefix
!= '\0')
5973 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5976 fputs_unfiltered (prefixed_name
, buf
);
5977 xfree (prefixed_name
);
5980 fputs_unfiltered (name
, buf
);
5982 /* Template parameters may be specified in the DIE's DW_AT_name, or
5983 as children with DW_TAG_template_type_param or
5984 DW_TAG_value_type_param. If the latter, add them to the name
5985 here. If the name already has template parameters, then
5986 skip this step; some versions of GCC emit both, and
5987 it is more efficient to use the pre-computed name.
5989 Something to keep in mind about this process: it is very
5990 unlikely, or in some cases downright impossible, to produce
5991 something that will match the mangled name of a function.
5992 If the definition of the function has the same debug info,
5993 we should be able to match up with it anyway. But fallbacks
5994 using the minimal symbol, for instance to find a method
5995 implemented in a stripped copy of libstdc++, will not work.
5996 If we do not have debug info for the definition, we will have to
5997 match them up some other way.
5999 When we do name matching there is a related problem with function
6000 templates; two instantiated function templates are allowed to
6001 differ only by their return types, which we do not add here. */
6003 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6005 struct attribute
*attr
;
6006 struct die_info
*child
;
6009 die
->building_fullname
= 1;
6011 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6016 struct dwarf2_locexpr_baton
*baton
;
6019 if (child
->tag
!= DW_TAG_template_type_param
6020 && child
->tag
!= DW_TAG_template_value_param
)
6025 fputs_unfiltered ("<", buf
);
6029 fputs_unfiltered (", ", buf
);
6031 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6034 complaint (&symfile_complaints
,
6035 _("template parameter missing DW_AT_type"));
6036 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6039 type
= die_type (child
, cu
);
6041 if (child
->tag
== DW_TAG_template_type_param
)
6043 c_print_type (type
, "", buf
, -1, 0);
6047 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6050 complaint (&symfile_complaints
,
6051 _("template parameter missing "
6052 "DW_AT_const_value"));
6053 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6057 dwarf2_const_value_attr (attr
, type
, name
,
6058 &cu
->comp_unit_obstack
, cu
,
6059 &value
, &bytes
, &baton
);
6061 if (TYPE_NOSIGN (type
))
6062 /* GDB prints characters as NUMBER 'CHAR'. If that's
6063 changed, this can use value_print instead. */
6064 c_printchar (value
, type
, buf
);
6067 struct value_print_options opts
;
6070 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6074 else if (bytes
!= NULL
)
6076 v
= allocate_value (type
);
6077 memcpy (value_contents_writeable (v
), bytes
,
6078 TYPE_LENGTH (type
));
6081 v
= value_from_longest (type
, value
);
6083 /* Specify decimal so that we do not depend on
6085 get_formatted_print_options (&opts
, 'd');
6087 value_print (v
, buf
, &opts
);
6093 die
->building_fullname
= 0;
6097 /* Close the argument list, with a space if necessary
6098 (nested templates). */
6099 char last_char
= '\0';
6100 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6101 if (last_char
== '>')
6102 fputs_unfiltered (" >", buf
);
6104 fputs_unfiltered (">", buf
);
6108 /* For Java and C++ methods, append formal parameter type
6109 information, if PHYSNAME. */
6111 if (physname
&& die
->tag
== DW_TAG_subprogram
6112 && (cu
->language
== language_cplus
6113 || cu
->language
== language_java
))
6115 struct type
*type
= read_type_die (die
, cu
);
6117 c_type_print_args (type
, buf
, 1, cu
->language
);
6119 if (cu
->language
== language_java
)
6121 /* For java, we must append the return type to method
6123 if (die
->tag
== DW_TAG_subprogram
)
6124 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6127 else if (cu
->language
== language_cplus
)
6129 /* Assume that an artificial first parameter is
6130 "this", but do not crash if it is not. RealView
6131 marks unnamed (and thus unused) parameters as
6132 artificial; there is no way to differentiate
6134 if (TYPE_NFIELDS (type
) > 0
6135 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6136 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6137 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6139 fputs_unfiltered (" const", buf
);
6143 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6145 ui_file_delete (buf
);
6147 if (cu
->language
== language_cplus
)
6150 = dwarf2_canonicalize_name (name
, cu
,
6151 &objfile
->objfile_obstack
);
6162 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6163 If scope qualifiers are appropriate they will be added. The result
6164 will be allocated on the objfile_obstack, or NULL if the DIE does
6165 not have a name. NAME may either be from a previous call to
6166 dwarf2_name or NULL.
6168 The output string will be canonicalized (if C++/Java). */
6171 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6173 return dwarf2_compute_name (name
, die
, cu
, 0);
6176 /* Construct a physname for the given DIE in CU. NAME may either be
6177 from a previous call to dwarf2_name or NULL. The result will be
6178 allocated on the objfile_objstack or NULL if the DIE does not have a
6181 The output string will be canonicalized (if C++/Java). */
6184 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6186 struct objfile
*objfile
= cu
->objfile
;
6187 struct attribute
*attr
;
6188 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6189 struct cleanup
*back_to
;
6192 /* In this case dwarf2_compute_name is just a shortcut not building anything
6194 if (!die_needs_namespace (die
, cu
))
6195 return dwarf2_compute_name (name
, die
, cu
, 1);
6197 back_to
= make_cleanup (null_cleanup
, NULL
);
6199 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6201 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6203 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6205 if (attr
&& DW_STRING (attr
))
6209 mangled
= DW_STRING (attr
);
6211 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6212 type. It is easier for GDB users to search for such functions as
6213 `name(params)' than `long name(params)'. In such case the minimal
6214 symbol names do not match the full symbol names but for template
6215 functions there is never a need to look up their definition from their
6216 declaration so the only disadvantage remains the minimal symbol
6217 variant `long name(params)' does not have the proper inferior type.
6220 if (cu
->language
== language_go
)
6222 /* This is a lie, but we already lie to the caller new_symbol_full.
6223 new_symbol_full assumes we return the mangled name.
6224 This just undoes that lie until things are cleaned up. */
6229 demangled
= cplus_demangle (mangled
,
6230 (DMGL_PARAMS
| DMGL_ANSI
6231 | (cu
->language
== language_java
6232 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6237 make_cleanup (xfree
, demangled
);
6247 if (canon
== NULL
|| check_physname
)
6249 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6251 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6253 /* It may not mean a bug in GDB. The compiler could also
6254 compute DW_AT_linkage_name incorrectly. But in such case
6255 GDB would need to be bug-to-bug compatible. */
6257 complaint (&symfile_complaints
,
6258 _("Computed physname <%s> does not match demangled <%s> "
6259 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6260 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6262 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6263 is available here - over computed PHYSNAME. It is safer
6264 against both buggy GDB and buggy compilers. */
6278 retval
= obsavestring (retval
, strlen (retval
),
6279 &objfile
->objfile_obstack
);
6281 do_cleanups (back_to
);
6285 /* Read the import statement specified by the given die and record it. */
6288 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6290 struct objfile
*objfile
= cu
->objfile
;
6291 struct attribute
*import_attr
;
6292 struct die_info
*imported_die
, *child_die
;
6293 struct dwarf2_cu
*imported_cu
;
6294 const char *imported_name
;
6295 const char *imported_name_prefix
;
6296 const char *canonical_name
;
6297 const char *import_alias
;
6298 const char *imported_declaration
= NULL
;
6299 const char *import_prefix
;
6300 VEC (const_char_ptr
) *excludes
= NULL
;
6301 struct cleanup
*cleanups
;
6305 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6306 if (import_attr
== NULL
)
6308 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6309 dwarf_tag_name (die
->tag
));
6314 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6315 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6316 if (imported_name
== NULL
)
6318 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6320 The import in the following code:
6334 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6335 <52> DW_AT_decl_file : 1
6336 <53> DW_AT_decl_line : 6
6337 <54> DW_AT_import : <0x75>
6338 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6340 <5b> DW_AT_decl_file : 1
6341 <5c> DW_AT_decl_line : 2
6342 <5d> DW_AT_type : <0x6e>
6344 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6345 <76> DW_AT_byte_size : 4
6346 <77> DW_AT_encoding : 5 (signed)
6348 imports the wrong die ( 0x75 instead of 0x58 ).
6349 This case will be ignored until the gcc bug is fixed. */
6353 /* Figure out the local name after import. */
6354 import_alias
= dwarf2_name (die
, cu
);
6356 /* Figure out where the statement is being imported to. */
6357 import_prefix
= determine_prefix (die
, cu
);
6359 /* Figure out what the scope of the imported die is and prepend it
6360 to the name of the imported die. */
6361 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6363 if (imported_die
->tag
!= DW_TAG_namespace
6364 && imported_die
->tag
!= DW_TAG_module
)
6366 imported_declaration
= imported_name
;
6367 canonical_name
= imported_name_prefix
;
6369 else if (strlen (imported_name_prefix
) > 0)
6371 temp
= alloca (strlen (imported_name_prefix
)
6372 + 2 + strlen (imported_name
) + 1);
6373 strcpy (temp
, imported_name_prefix
);
6374 strcat (temp
, "::");
6375 strcat (temp
, imported_name
);
6376 canonical_name
= temp
;
6379 canonical_name
= imported_name
;
6381 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6383 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6384 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6385 child_die
= sibling_die (child_die
))
6387 /* DWARF-4: A Fortran use statement with a “rename list” may be
6388 represented by an imported module entry with an import attribute
6389 referring to the module and owned entries corresponding to those
6390 entities that are renamed as part of being imported. */
6392 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6394 complaint (&symfile_complaints
,
6395 _("child DW_TAG_imported_declaration expected "
6396 "- DIE at 0x%x [in module %s]"),
6397 child_die
->offset
.sect_off
, objfile
->name
);
6401 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6402 if (import_attr
== NULL
)
6404 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6405 dwarf_tag_name (child_die
->tag
));
6410 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6412 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6413 if (imported_name
== NULL
)
6415 complaint (&symfile_complaints
,
6416 _("child DW_TAG_imported_declaration has unknown "
6417 "imported name - DIE at 0x%x [in module %s]"),
6418 child_die
->offset
.sect_off
, objfile
->name
);
6422 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6424 process_die (child_die
, cu
);
6427 cp_add_using_directive (import_prefix
,
6430 imported_declaration
,
6432 &objfile
->objfile_obstack
);
6434 do_cleanups (cleanups
);
6437 /* Cleanup function for read_file_scope. */
6440 free_cu_line_header (void *arg
)
6442 struct dwarf2_cu
*cu
= arg
;
6444 free_line_header (cu
->line_header
);
6445 cu
->line_header
= NULL
;
6449 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6450 char **name
, char **comp_dir
)
6452 struct attribute
*attr
;
6457 /* Find the filename. Do not use dwarf2_name here, since the filename
6458 is not a source language identifier. */
6459 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6462 *name
= DW_STRING (attr
);
6465 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6467 *comp_dir
= DW_STRING (attr
);
6468 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6470 *comp_dir
= ldirname (*name
);
6471 if (*comp_dir
!= NULL
)
6472 make_cleanup (xfree
, *comp_dir
);
6474 if (*comp_dir
!= NULL
)
6476 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6477 directory, get rid of it. */
6478 char *cp
= strchr (*comp_dir
, ':');
6480 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6485 *name
= "<unknown>";
6488 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6489 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6490 COMP_DIR is the compilation directory.
6491 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6494 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6495 const char *comp_dir
, int want_line_info
)
6497 struct attribute
*attr
;
6499 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6502 unsigned int line_offset
= DW_UNSND (attr
);
6503 struct line_header
*line_header
6504 = dwarf_decode_line_header (line_offset
, cu
);
6508 cu
->line_header
= line_header
;
6509 make_cleanup (free_cu_line_header
, cu
);
6510 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6515 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6518 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6520 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6521 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6522 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6523 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6524 struct attribute
*attr
;
6526 char *comp_dir
= NULL
;
6527 struct die_info
*child_die
;
6528 bfd
*abfd
= objfile
->obfd
;
6531 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6533 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6535 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6536 from finish_block. */
6537 if (lowpc
== ((CORE_ADDR
) -1))
6542 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6544 prepare_one_comp_unit (cu
, die
, cu
->language
);
6546 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6547 standardised yet. As a workaround for the language detection we fall
6548 back to the DW_AT_producer string. */
6549 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6550 cu
->language
= language_opencl
;
6552 /* Similar hack for Go. */
6553 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6554 set_cu_language (DW_LANG_Go
, cu
);
6556 /* We assume that we're processing GCC output. */
6557 processing_gcc_compilation
= 2;
6559 processing_has_namespace_info
= 0;
6561 start_symtab (name
, comp_dir
, lowpc
);
6562 record_debugformat ("DWARF 2");
6563 record_producer (cu
->producer
);
6565 /* Decode line number information if present. We do this before
6566 processing child DIEs, so that the line header table is available
6567 for DW_AT_decl_file. */
6568 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6570 /* Process all dies in compilation unit. */
6571 if (die
->child
!= NULL
)
6573 child_die
= die
->child
;
6574 while (child_die
&& child_die
->tag
)
6576 process_die (child_die
, cu
);
6577 child_die
= sibling_die (child_die
);
6581 /* Decode macro information, if present. Dwarf 2 macro information
6582 refers to information in the line number info statement program
6583 header, so we can only read it if we've read the header
6585 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6586 if (attr
&& cu
->line_header
)
6588 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6589 complaint (&symfile_complaints
,
6590 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6592 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6594 &dwarf2_per_objfile
->macro
, 1,
6599 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6600 if (attr
&& cu
->line_header
)
6602 unsigned int macro_offset
= DW_UNSND (attr
);
6604 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6606 &dwarf2_per_objfile
->macinfo
, 0,
6611 do_cleanups (back_to
);
6614 /* Process DW_TAG_type_unit.
6615 For TUs we want to skip the first top level sibling if it's not the
6616 actual type being defined by this TU. In this case the first top
6617 level sibling is there to provide context only. */
6620 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6622 struct objfile
*objfile
= cu
->objfile
;
6623 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6625 struct attribute
*attr
;
6627 char *comp_dir
= NULL
;
6628 struct die_info
*child_die
;
6629 bfd
*abfd
= objfile
->obfd
;
6631 /* start_symtab needs a low pc, but we don't really have one.
6632 Do what read_file_scope would do in the absence of such info. */
6633 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6635 /* Find the filename. Do not use dwarf2_name here, since the filename
6636 is not a source language identifier. */
6637 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6639 name
= DW_STRING (attr
);
6641 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6643 comp_dir
= DW_STRING (attr
);
6644 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6646 comp_dir
= ldirname (name
);
6647 if (comp_dir
!= NULL
)
6648 make_cleanup (xfree
, comp_dir
);
6654 prepare_one_comp_unit (cu
, die
, language_minimal
);
6656 /* We assume that we're processing GCC output. */
6657 processing_gcc_compilation
= 2;
6659 processing_has_namespace_info
= 0;
6661 start_symtab (name
, comp_dir
, lowpc
);
6662 record_debugformat ("DWARF 2");
6663 record_producer (cu
->producer
);
6665 /* Decode line number information if present. We do this before
6666 processing child DIEs, so that the line header table is available
6667 for DW_AT_decl_file.
6668 We don't need the pc/line-number mapping for type units. */
6669 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6671 /* Process the dies in the type unit. */
6672 if (die
->child
== NULL
)
6674 dump_die_for_error (die
);
6675 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6676 bfd_get_filename (abfd
));
6679 child_die
= die
->child
;
6681 while (child_die
&& child_die
->tag
)
6683 process_die (child_die
, cu
);
6685 child_die
= sibling_die (child_die
);
6688 do_cleanups (back_to
);
6694 hash_dwo_file (const void *item
)
6696 const struct dwo_file
*dwo_file
= item
;
6698 return htab_hash_string (dwo_file
->dwo_name
);
6702 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6704 const struct dwo_file
*lhs
= item_lhs
;
6705 const struct dwo_file
*rhs
= item_rhs
;
6707 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6710 /* Allocate a hash table for DWO files. */
6713 allocate_dwo_file_hash_table (void)
6715 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6717 return htab_create_alloc_ex (41,
6721 &objfile
->objfile_obstack
,
6722 hashtab_obstack_allocate
,
6723 dummy_obstack_deallocate
);
6727 hash_dwo_unit (const void *item
)
6729 const struct dwo_unit
*dwo_unit
= item
;
6731 /* This drops the top 32 bits of the id, but is ok for a hash. */
6732 return dwo_unit
->signature
;
6736 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6738 const struct dwo_unit
*lhs
= item_lhs
;
6739 const struct dwo_unit
*rhs
= item_rhs
;
6741 /* The signature is assumed to be unique within the DWO file.
6742 So while object file CU dwo_id's always have the value zero,
6743 that's OK, assuming each object file DWO file has only one CU,
6744 and that's the rule for now. */
6745 return lhs
->signature
== rhs
->signature
;
6748 /* Allocate a hash table for DWO CUs,TUs.
6749 There is one of these tables for each of CUs,TUs for each DWO file. */
6752 allocate_dwo_unit_table (struct objfile
*objfile
)
6754 /* Start out with a pretty small number.
6755 Generally DWO files contain only one CU and maybe some TUs. */
6756 return htab_create_alloc_ex (3,
6760 &objfile
->objfile_obstack
,
6761 hashtab_obstack_allocate
,
6762 dummy_obstack_deallocate
);
6765 /* This function is mapped across the sections and remembers the offset and
6766 size of each of the DWO debugging sections we are interested in. */
6769 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6771 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6772 const struct dwo_section_names
*names
= &dwo_section_names
;
6774 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6776 dwo_file
->sections
.abbrev
.asection
= sectp
;
6777 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6779 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6781 dwo_file
->sections
.info
.asection
= sectp
;
6782 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6784 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6786 dwo_file
->sections
.line
.asection
= sectp
;
6787 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6789 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6791 dwo_file
->sections
.loc
.asection
= sectp
;
6792 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6794 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6796 dwo_file
->sections
.str
.asection
= sectp
;
6797 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6799 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6801 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6802 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6804 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6806 struct dwarf2_section_info type_section
;
6808 memset (&type_section
, 0, sizeof (type_section
));
6809 type_section
.asection
= sectp
;
6810 type_section
.size
= bfd_get_section_size (sectp
);
6811 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6816 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6818 struct create_dwo_info_table_data
6820 struct dwo_file
*dwo_file
;
6824 /* die_reader_func for create_debug_info_hash_table. */
6827 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6829 struct die_info
*comp_unit_die
,
6833 struct dwarf2_cu
*cu
= reader
->cu
;
6834 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6835 sect_offset offset
= cu
->per_cu
->offset
;
6836 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6837 struct create_dwo_info_table_data
*data
= datap
;
6838 struct dwo_file
*dwo_file
= data
->dwo_file
;
6839 htab_t cu_htab
= data
->cu_htab
;
6841 struct attribute
*attr
;
6842 struct dwo_unit
*dwo_unit
;
6844 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6847 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6848 " its dwo_id [in module %s]"),
6849 offset
.sect_off
, dwo_file
->dwo_name
);
6853 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6854 dwo_unit
->dwo_file
= dwo_file
;
6855 dwo_unit
->signature
= DW_UNSND (attr
);
6856 dwo_unit
->info_or_types_section
= section
;
6857 dwo_unit
->offset
= offset
;
6858 dwo_unit
->length
= cu
->per_cu
->length
;
6860 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
6861 gdb_assert (slot
!= NULL
);
6864 const struct dwo_unit
*dup_dwo_unit
= *slot
;
6866 complaint (&symfile_complaints
,
6867 _("debug entry at offset 0x%x is duplicate to the entry at"
6868 " offset 0x%x, dwo_id 0x%s [in module %s]"),
6869 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
6870 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
6871 dwo_file
->dwo_name
);
6876 if (dwarf2_die_debug
)
6877 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
6879 phex (dwo_unit
->signature
,
6880 sizeof (dwo_unit
->signature
)));
6883 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
6886 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
6888 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6889 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
6892 gdb_byte
*info_ptr
, *end_ptr
;
6893 struct create_dwo_info_table_data create_dwo_info_table_data
;
6895 dwarf2_read_section (objfile
, section
);
6896 info_ptr
= section
->buffer
;
6898 if (info_ptr
== NULL
)
6901 /* We can't set abfd until now because the section may be empty or
6902 not present, in which case section->asection will be NULL. */
6903 abfd
= section
->asection
->owner
;
6905 if (dwarf2_die_debug
)
6906 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
6907 bfd_get_filename (abfd
));
6909 cu_htab
= allocate_dwo_unit_table (objfile
);
6911 create_dwo_info_table_data
.dwo_file
= dwo_file
;
6912 create_dwo_info_table_data
.cu_htab
= cu_htab
;
6914 end_ptr
= info_ptr
+ section
->size
;
6915 while (info_ptr
< end_ptr
)
6917 struct dwarf2_per_cu_data per_cu
;
6919 memset (&per_cu
, 0, sizeof (per_cu
));
6920 per_cu
.objfile
= objfile
;
6921 per_cu
.is_debug_types
= 0;
6922 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
6923 per_cu
.info_or_types_section
= section
;
6925 init_cutu_and_read_dies_no_follow (&per_cu
,
6926 &dwo_file
->sections
.abbrev
,
6928 create_debug_info_hash_table_reader
,
6929 &create_dwo_info_table_data
);
6931 info_ptr
+= per_cu
.length
;
6937 /* Subroutine of open_dwo_file to simplify it.
6938 Open the file specified by FILE_NAME and hand it off to BFD for
6939 preliminary analysis. Return a newly initialized bfd *, which
6940 includes a canonicalized copy of FILE_NAME.
6941 In case of trouble, return NULL.
6942 NOTE: This function is derived from symfile_bfd_open. */
6945 try_open_dwo_file (const char *file_name
)
6949 char *absolute_name
;
6951 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
6952 O_RDONLY
| O_BINARY
, &absolute_name
);
6956 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
6960 xfree (absolute_name
);
6963 bfd_set_cacheable (sym_bfd
, 1);
6965 if (!bfd_check_format (sym_bfd
, bfd_object
))
6967 bfd_close (sym_bfd
); /* This also closes desc. */
6968 xfree (absolute_name
);
6972 /* bfd_usrdata exists for applications and libbfd must not touch it. */
6973 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
6978 /* Try to open DWO file DWO_NAME.
6979 COMP_DIR is the DW_AT_comp_dir attribute.
6980 The result is the bfd handle of the file.
6981 If there is a problem finding or opening the file, return NULL.
6982 Upon success, the canonicalized path of the file is stored in the bfd,
6983 same as symfile_bfd_open. */
6986 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
6990 if (IS_ABSOLUTE_PATH (dwo_name
))
6991 return try_open_dwo_file (dwo_name
);
6993 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
6995 if (comp_dir
!= NULL
)
6997 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
6999 /* NOTE: If comp_dir is a relative path, this will also try the
7000 search path, which seems useful. */
7001 abfd
= try_open_dwo_file (path_to_try
);
7002 xfree (path_to_try
);
7007 /* That didn't work, try debug-file-directory, which, despite its name,
7008 is a list of paths. */
7010 if (*debug_file_directory
== '\0')
7013 return try_open_dwo_file (dwo_name
);
7016 /* Initialize the use of the DWO file specified by DWO_NAME. */
7018 static struct dwo_file
*
7019 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7021 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7022 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7025 struct cleanup
*cleanups
;
7027 if (dwarf2_die_debug
)
7028 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7030 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7033 dwo_file
->dwo_name
= dwo_name
;
7034 dwo_file
->dwo_bfd
= abfd
;
7036 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7038 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7040 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7042 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7043 dwo_file
->sections
.types
);
7045 discard_cleanups (cleanups
);
7050 /* Lookup DWO file DWO_NAME. */
7052 static struct dwo_file
*
7053 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7055 struct dwo_file
*dwo_file
;
7056 struct dwo_file find_entry
;
7059 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7060 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7062 /* Have we already seen this DWO file? */
7063 find_entry
.dwo_name
= dwo_name
;
7064 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7066 /* If not, read it in and build a table of the DWOs it contains. */
7068 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7070 /* NOTE: This will be NULL if unable to open the file. */
7076 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7077 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7078 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7079 nomenclature as TUs).
7080 The result is the DWO CU or NULL if we didn't find it
7081 (dwo_id mismatch or couldn't find the DWO file). */
7083 static struct dwo_unit
*
7084 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7085 char *dwo_name
, const char *comp_dir
,
7088 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7089 struct dwo_file
*dwo_file
;
7091 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7092 if (dwo_file
== NULL
)
7095 /* Look up the DWO using its signature(dwo_id). */
7097 if (dwo_file
->cus
!= NULL
)
7099 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7101 find_dwo_cu
.signature
= signature
;
7102 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7108 /* We didn't find it. This must mean a dwo_id mismatch. */
7110 complaint (&symfile_complaints
,
7111 _("Could not find DWO CU referenced by CU at offset 0x%x"
7113 this_cu
->offset
.sect_off
, objfile
->name
);
7117 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7118 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7119 The result is the DWO CU or NULL if we didn't find it
7120 (dwo_id mismatch or couldn't find the DWO file). */
7122 static struct dwo_unit
*
7123 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7124 char *dwo_name
, const char *comp_dir
)
7126 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7127 struct dwo_file
*dwo_file
;
7129 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7130 if (dwo_file
== NULL
)
7133 /* Look up the DWO using its signature(dwo_id). */
7135 if (dwo_file
->tus
!= NULL
)
7137 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7139 find_dwo_tu
.signature
= this_tu
->signature
;
7140 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7146 /* We didn't find it. This must mean a dwo_id mismatch. */
7148 complaint (&symfile_complaints
,
7149 _("Could not find DWO TU referenced by TU at offset 0x%x"
7151 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7155 /* Free all resources associated with DWO_FILE.
7156 Close the DWO file and munmap the sections.
7157 All memory should be on the objfile obstack. */
7160 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7163 struct dwarf2_section_info
*section
;
7165 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7166 bfd_close (dwo_file
->dwo_bfd
);
7168 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7169 munmap_section_buffer (&dwo_file
->sections
.info
);
7170 munmap_section_buffer (&dwo_file
->sections
.line
);
7171 munmap_section_buffer (&dwo_file
->sections
.loc
);
7172 munmap_section_buffer (&dwo_file
->sections
.str
);
7173 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7176 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7179 munmap_section_buffer (section
);
7181 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7184 /* Wrapper for free_dwo_file for use in cleanups. */
7187 free_dwo_file_cleanup (void *arg
)
7189 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7190 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7192 free_dwo_file (dwo_file
, objfile
);
7195 /* Traversal function for free_dwo_files. */
7198 free_dwo_file_from_slot (void **slot
, void *info
)
7200 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7201 struct objfile
*objfile
= (struct objfile
*) info
;
7203 free_dwo_file (dwo_file
, objfile
);
7208 /* Free all resources associated with DWO_FILES. */
7211 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7213 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7216 /* Read in various DIEs. */
7218 /* qsort helper for inherit_abstract_dies. */
7221 unsigned_int_compar (const void *ap
, const void *bp
)
7223 unsigned int a
= *(unsigned int *) ap
;
7224 unsigned int b
= *(unsigned int *) bp
;
7226 return (a
> b
) - (b
> a
);
7229 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7230 Inherit only the children of the DW_AT_abstract_origin DIE not being
7231 already referenced by DW_AT_abstract_origin from the children of the
7235 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7237 struct die_info
*child_die
;
7238 unsigned die_children_count
;
7239 /* CU offsets which were referenced by children of the current DIE. */
7240 sect_offset
*offsets
;
7241 sect_offset
*offsets_end
, *offsetp
;
7242 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7243 struct die_info
*origin_die
;
7244 /* Iterator of the ORIGIN_DIE children. */
7245 struct die_info
*origin_child_die
;
7246 struct cleanup
*cleanups
;
7247 struct attribute
*attr
;
7248 struct dwarf2_cu
*origin_cu
;
7249 struct pending
**origin_previous_list_in_scope
;
7251 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7255 /* Note that following die references may follow to a die in a
7259 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7261 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7263 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7264 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7266 if (die
->tag
!= origin_die
->tag
7267 && !(die
->tag
== DW_TAG_inlined_subroutine
7268 && origin_die
->tag
== DW_TAG_subprogram
))
7269 complaint (&symfile_complaints
,
7270 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7271 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7273 child_die
= die
->child
;
7274 die_children_count
= 0;
7275 while (child_die
&& child_die
->tag
)
7277 child_die
= sibling_die (child_die
);
7278 die_children_count
++;
7280 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7281 cleanups
= make_cleanup (xfree
, offsets
);
7283 offsets_end
= offsets
;
7284 child_die
= die
->child
;
7285 while (child_die
&& child_die
->tag
)
7287 /* For each CHILD_DIE, find the corresponding child of
7288 ORIGIN_DIE. If there is more than one layer of
7289 DW_AT_abstract_origin, follow them all; there shouldn't be,
7290 but GCC versions at least through 4.4 generate this (GCC PR
7292 struct die_info
*child_origin_die
= child_die
;
7293 struct dwarf2_cu
*child_origin_cu
= cu
;
7297 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7301 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7305 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7306 counterpart may exist. */
7307 if (child_origin_die
!= child_die
)
7309 if (child_die
->tag
!= child_origin_die
->tag
7310 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7311 && child_origin_die
->tag
== DW_TAG_subprogram
))
7312 complaint (&symfile_complaints
,
7313 _("Child DIE 0x%x and its abstract origin 0x%x have "
7314 "different tags"), child_die
->offset
.sect_off
,
7315 child_origin_die
->offset
.sect_off
);
7316 if (child_origin_die
->parent
!= origin_die
)
7317 complaint (&symfile_complaints
,
7318 _("Child DIE 0x%x and its abstract origin 0x%x have "
7319 "different parents"), child_die
->offset
.sect_off
,
7320 child_origin_die
->offset
.sect_off
);
7322 *offsets_end
++ = child_origin_die
->offset
;
7324 child_die
= sibling_die (child_die
);
7326 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7327 unsigned_int_compar
);
7328 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7329 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7330 complaint (&symfile_complaints
,
7331 _("Multiple children of DIE 0x%x refer "
7332 "to DIE 0x%x as their abstract origin"),
7333 die
->offset
.sect_off
, offsetp
->sect_off
);
7336 origin_child_die
= origin_die
->child
;
7337 while (origin_child_die
&& origin_child_die
->tag
)
7339 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7340 while (offsetp
< offsets_end
7341 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7343 if (offsetp
>= offsets_end
7344 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7346 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7347 process_die (origin_child_die
, origin_cu
);
7349 origin_child_die
= sibling_die (origin_child_die
);
7351 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7353 do_cleanups (cleanups
);
7357 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7359 struct objfile
*objfile
= cu
->objfile
;
7360 struct context_stack
*new;
7363 struct die_info
*child_die
;
7364 struct attribute
*attr
, *call_line
, *call_file
;
7367 struct block
*block
;
7368 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7369 VEC (symbolp
) *template_args
= NULL
;
7370 struct template_symbol
*templ_func
= NULL
;
7374 /* If we do not have call site information, we can't show the
7375 caller of this inlined function. That's too confusing, so
7376 only use the scope for local variables. */
7377 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7378 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7379 if (call_line
== NULL
|| call_file
== NULL
)
7381 read_lexical_block_scope (die
, cu
);
7386 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7388 name
= dwarf2_name (die
, cu
);
7390 /* Ignore functions with missing or empty names. These are actually
7391 illegal according to the DWARF standard. */
7394 complaint (&symfile_complaints
,
7395 _("missing name for subprogram DIE at %d"),
7396 die
->offset
.sect_off
);
7400 /* Ignore functions with missing or invalid low and high pc attributes. */
7401 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7403 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7404 if (!attr
|| !DW_UNSND (attr
))
7405 complaint (&symfile_complaints
,
7406 _("cannot get low and high bounds "
7407 "for subprogram DIE at %d"),
7408 die
->offset
.sect_off
);
7415 /* If we have any template arguments, then we must allocate a
7416 different sort of symbol. */
7417 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7419 if (child_die
->tag
== DW_TAG_template_type_param
7420 || child_die
->tag
== DW_TAG_template_value_param
)
7422 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7423 struct template_symbol
);
7424 templ_func
->base
.is_cplus_template_function
= 1;
7429 new = push_context (0, lowpc
);
7430 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7431 (struct symbol
*) templ_func
);
7433 /* If there is a location expression for DW_AT_frame_base, record
7435 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7437 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7438 expression is being recorded directly in the function's symbol
7439 and not in a separate frame-base object. I guess this hack is
7440 to avoid adding some sort of frame-base adjunct/annex to the
7441 function's symbol :-(. The problem with doing this is that it
7442 results in a function symbol with a location expression that
7443 has nothing to do with the location of the function, ouch! The
7444 relationship should be: a function's symbol has-a frame base; a
7445 frame-base has-a location expression. */
7446 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7448 cu
->list_in_scope
= &local_symbols
;
7450 if (die
->child
!= NULL
)
7452 child_die
= die
->child
;
7453 while (child_die
&& child_die
->tag
)
7455 if (child_die
->tag
== DW_TAG_template_type_param
7456 || child_die
->tag
== DW_TAG_template_value_param
)
7458 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7461 VEC_safe_push (symbolp
, template_args
, arg
);
7464 process_die (child_die
, cu
);
7465 child_die
= sibling_die (child_die
);
7469 inherit_abstract_dies (die
, cu
);
7471 /* If we have a DW_AT_specification, we might need to import using
7472 directives from the context of the specification DIE. See the
7473 comment in determine_prefix. */
7474 if (cu
->language
== language_cplus
7475 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7477 struct dwarf2_cu
*spec_cu
= cu
;
7478 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7482 child_die
= spec_die
->child
;
7483 while (child_die
&& child_die
->tag
)
7485 if (child_die
->tag
== DW_TAG_imported_module
)
7486 process_die (child_die
, spec_cu
);
7487 child_die
= sibling_die (child_die
);
7490 /* In some cases, GCC generates specification DIEs that
7491 themselves contain DW_AT_specification attributes. */
7492 spec_die
= die_specification (spec_die
, &spec_cu
);
7496 new = pop_context ();
7497 /* Make a block for the local symbols within. */
7498 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7499 lowpc
, highpc
, objfile
);
7501 /* For C++, set the block's scope. */
7502 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7503 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7504 determine_prefix (die
, cu
),
7505 processing_has_namespace_info
);
7507 /* If we have address ranges, record them. */
7508 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7510 /* Attach template arguments to function. */
7511 if (! VEC_empty (symbolp
, template_args
))
7513 gdb_assert (templ_func
!= NULL
);
7515 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7516 templ_func
->template_arguments
7517 = obstack_alloc (&objfile
->objfile_obstack
,
7518 (templ_func
->n_template_arguments
7519 * sizeof (struct symbol
*)));
7520 memcpy (templ_func
->template_arguments
,
7521 VEC_address (symbolp
, template_args
),
7522 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7523 VEC_free (symbolp
, template_args
);
7526 /* In C++, we can have functions nested inside functions (e.g., when
7527 a function declares a class that has methods). This means that
7528 when we finish processing a function scope, we may need to go
7529 back to building a containing block's symbol lists. */
7530 local_symbols
= new->locals
;
7531 param_symbols
= new->params
;
7532 using_directives
= new->using_directives
;
7534 /* If we've finished processing a top-level function, subsequent
7535 symbols go in the file symbol list. */
7536 if (outermost_context_p ())
7537 cu
->list_in_scope
= &file_symbols
;
7540 /* Process all the DIES contained within a lexical block scope. Start
7541 a new scope, process the dies, and then close the scope. */
7544 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7546 struct objfile
*objfile
= cu
->objfile
;
7547 struct context_stack
*new;
7548 CORE_ADDR lowpc
, highpc
;
7549 struct die_info
*child_die
;
7552 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7554 /* Ignore blocks with missing or invalid low and high pc attributes. */
7555 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7556 as multiple lexical blocks? Handling children in a sane way would
7557 be nasty. Might be easier to properly extend generic blocks to
7559 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7564 push_context (0, lowpc
);
7565 if (die
->child
!= NULL
)
7567 child_die
= die
->child
;
7568 while (child_die
&& child_die
->tag
)
7570 process_die (child_die
, cu
);
7571 child_die
= sibling_die (child_die
);
7574 new = pop_context ();
7576 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7579 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7582 /* Note that recording ranges after traversing children, as we
7583 do here, means that recording a parent's ranges entails
7584 walking across all its children's ranges as they appear in
7585 the address map, which is quadratic behavior.
7587 It would be nicer to record the parent's ranges before
7588 traversing its children, simply overriding whatever you find
7589 there. But since we don't even decide whether to create a
7590 block until after we've traversed its children, that's hard
7592 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7594 local_symbols
= new->locals
;
7595 using_directives
= new->using_directives
;
7598 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7601 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7603 struct objfile
*objfile
= cu
->objfile
;
7604 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7605 CORE_ADDR pc
, baseaddr
;
7606 struct attribute
*attr
;
7607 struct call_site
*call_site
, call_site_local
;
7610 struct die_info
*child_die
;
7612 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7614 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7617 complaint (&symfile_complaints
,
7618 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7619 "DIE 0x%x [in module %s]"),
7620 die
->offset
.sect_off
, objfile
->name
);
7623 pc
= DW_ADDR (attr
) + baseaddr
;
7625 if (cu
->call_site_htab
== NULL
)
7626 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7627 NULL
, &objfile
->objfile_obstack
,
7628 hashtab_obstack_allocate
, NULL
);
7629 call_site_local
.pc
= pc
;
7630 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7633 complaint (&symfile_complaints
,
7634 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7635 "DIE 0x%x [in module %s]"),
7636 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7640 /* Count parameters at the caller. */
7643 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7644 child_die
= sibling_die (child_die
))
7646 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7648 complaint (&symfile_complaints
,
7649 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7650 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7651 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7658 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7659 (sizeof (*call_site
)
7660 + (sizeof (*call_site
->parameter
)
7663 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7666 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7668 struct die_info
*func_die
;
7670 /* Skip also over DW_TAG_inlined_subroutine. */
7671 for (func_die
= die
->parent
;
7672 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7673 && func_die
->tag
!= DW_TAG_subroutine_type
;
7674 func_die
= func_die
->parent
);
7676 /* DW_AT_GNU_all_call_sites is a superset
7677 of DW_AT_GNU_all_tail_call_sites. */
7679 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7680 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7682 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7683 not complete. But keep CALL_SITE for look ups via call_site_htab,
7684 both the initial caller containing the real return address PC and
7685 the final callee containing the current PC of a chain of tail
7686 calls do not need to have the tail call list complete. But any
7687 function candidate for a virtual tail call frame searched via
7688 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7689 determined unambiguously. */
7693 struct type
*func_type
= NULL
;
7696 func_type
= get_die_type (func_die
, cu
);
7697 if (func_type
!= NULL
)
7699 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7701 /* Enlist this call site to the function. */
7702 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7703 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7706 complaint (&symfile_complaints
,
7707 _("Cannot find function owning DW_TAG_GNU_call_site "
7708 "DIE 0x%x [in module %s]"),
7709 die
->offset
.sect_off
, objfile
->name
);
7713 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7715 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7716 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7717 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7718 /* Keep NULL DWARF_BLOCK. */;
7719 else if (attr_form_is_block (attr
))
7721 struct dwarf2_locexpr_baton
*dlbaton
;
7723 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7724 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7725 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7726 dlbaton
->per_cu
= cu
->per_cu
;
7728 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7730 else if (is_ref_attr (attr
))
7732 struct dwarf2_cu
*target_cu
= cu
;
7733 struct die_info
*target_die
;
7735 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7736 gdb_assert (target_cu
->objfile
== objfile
);
7737 if (die_is_declaration (target_die
, target_cu
))
7739 const char *target_physname
;
7741 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7742 if (target_physname
== NULL
)
7743 complaint (&symfile_complaints
,
7744 _("DW_AT_GNU_call_site_target target DIE has invalid "
7745 "physname, for referencing DIE 0x%x [in module %s]"),
7746 die
->offset
.sect_off
, objfile
->name
);
7748 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7754 /* DW_AT_entry_pc should be preferred. */
7755 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7756 complaint (&symfile_complaints
,
7757 _("DW_AT_GNU_call_site_target target DIE has invalid "
7758 "low pc, for referencing DIE 0x%x [in module %s]"),
7759 die
->offset
.sect_off
, objfile
->name
);
7761 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7765 complaint (&symfile_complaints
,
7766 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7767 "block nor reference, for DIE 0x%x [in module %s]"),
7768 die
->offset
.sect_off
, objfile
->name
);
7770 call_site
->per_cu
= cu
->per_cu
;
7772 for (child_die
= die
->child
;
7773 child_die
&& child_die
->tag
;
7774 child_die
= sibling_die (child_die
))
7776 struct call_site_parameter
*parameter
;
7778 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7780 /* Already printed the complaint above. */
7784 gdb_assert (call_site
->parameter_count
< nparams
);
7785 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7787 /* DW_AT_location specifies the register number. Value of the data
7788 assumed for the register is contained in DW_AT_GNU_call_site_value. */
7790 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7791 if (!attr
|| !attr_form_is_block (attr
))
7793 complaint (&symfile_complaints
,
7794 _("No DW_FORM_block* DW_AT_location for "
7795 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7796 child_die
->offset
.sect_off
, objfile
->name
);
7799 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
7800 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
7801 if (parameter
->dwarf_reg
== -1
7802 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
7803 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
7804 ¶meter
->fb_offset
))
7806 complaint (&symfile_complaints
,
7807 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7808 "for DW_FORM_block* DW_AT_location for "
7809 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7810 child_die
->offset
.sect_off
, objfile
->name
);
7814 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7815 if (!attr_form_is_block (attr
))
7817 complaint (&symfile_complaints
,
7818 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7819 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7820 child_die
->offset
.sect_off
, objfile
->name
);
7823 parameter
->value
= DW_BLOCK (attr
)->data
;
7824 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7826 /* Parameters are not pre-cleared by memset above. */
7827 parameter
->data_value
= NULL
;
7828 parameter
->data_value_size
= 0;
7829 call_site
->parameter_count
++;
7831 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7834 if (!attr_form_is_block (attr
))
7835 complaint (&symfile_complaints
,
7836 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7837 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7838 child_die
->offset
.sect_off
, objfile
->name
);
7841 parameter
->data_value
= DW_BLOCK (attr
)->data
;
7842 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
7848 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
7849 Return 1 if the attributes are present and valid, otherwise, return 0.
7850 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
7853 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
7854 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
7855 struct partial_symtab
*ranges_pst
)
7857 struct objfile
*objfile
= cu
->objfile
;
7858 struct comp_unit_head
*cu_header
= &cu
->header
;
7859 bfd
*obfd
= objfile
->obfd
;
7860 unsigned int addr_size
= cu_header
->addr_size
;
7861 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7862 /* Base address selection entry. */
7873 found_base
= cu
->base_known
;
7874 base
= cu
->base_address
;
7876 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
7877 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7879 complaint (&symfile_complaints
,
7880 _("Offset %d out of bounds for DW_AT_ranges attribute"),
7884 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7886 /* Read in the largest possible address. */
7887 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
7888 if ((marker
& mask
) == mask
)
7890 /* If we found the largest possible address, then
7891 read the base address. */
7892 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7893 buffer
+= 2 * addr_size
;
7894 offset
+= 2 * addr_size
;
7900 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7904 CORE_ADDR range_beginning
, range_end
;
7906 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
7907 buffer
+= addr_size
;
7908 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
7909 buffer
+= addr_size
;
7910 offset
+= 2 * addr_size
;
7912 /* An end of list marker is a pair of zero addresses. */
7913 if (range_beginning
== 0 && range_end
== 0)
7914 /* Found the end of list entry. */
7917 /* Each base address selection entry is a pair of 2 values.
7918 The first is the largest possible address, the second is
7919 the base address. Check for a base address here. */
7920 if ((range_beginning
& mask
) == mask
)
7922 /* If we found the largest possible address, then
7923 read the base address. */
7924 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7931 /* We have no valid base address for the ranges
7933 complaint (&symfile_complaints
,
7934 _("Invalid .debug_ranges data (no base address)"));
7938 if (range_beginning
> range_end
)
7940 /* Inverted range entries are invalid. */
7941 complaint (&symfile_complaints
,
7942 _("Invalid .debug_ranges data (inverted range)"));
7946 /* Empty range entries have no effect. */
7947 if (range_beginning
== range_end
)
7950 range_beginning
+= base
;
7953 if (ranges_pst
!= NULL
)
7954 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7955 range_beginning
+ baseaddr
,
7956 range_end
- 1 + baseaddr
,
7959 /* FIXME: This is recording everything as a low-high
7960 segment of consecutive addresses. We should have a
7961 data structure for discontiguous block ranges
7965 low
= range_beginning
;
7971 if (range_beginning
< low
)
7972 low
= range_beginning
;
7973 if (range_end
> high
)
7979 /* If the first entry is an end-of-list marker, the range
7980 describes an empty scope, i.e. no instructions. */
7986 *high_return
= high
;
7990 /* Get low and high pc attributes from a die. Return 1 if the attributes
7991 are present and valid, otherwise, return 0. Return -1 if the range is
7992 discontinuous, i.e. derived from DW_AT_ranges information. */
7995 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
7996 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
7997 struct partial_symtab
*pst
)
7999 struct attribute
*attr
;
8000 struct attribute
*attr_high
;
8005 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8008 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8011 low
= DW_ADDR (attr
);
8012 if (attr_high
->form
== DW_FORM_addr
8013 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8014 high
= DW_ADDR (attr_high
);
8016 high
= low
+ DW_UNSND (attr_high
);
8019 /* Found high w/o low attribute. */
8022 /* Found consecutive range of addresses. */
8027 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8030 /* Value of the DW_AT_ranges attribute is the offset in the
8031 .debug_ranges section. */
8032 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
8034 /* Found discontinuous range of addresses. */
8039 /* read_partial_die has also the strict LOW < HIGH requirement. */
8043 /* When using the GNU linker, .gnu.linkonce. sections are used to
8044 eliminate duplicate copies of functions and vtables and such.
8045 The linker will arbitrarily choose one and discard the others.
8046 The AT_*_pc values for such functions refer to local labels in
8047 these sections. If the section from that file was discarded, the
8048 labels are not in the output, so the relocs get a value of 0.
8049 If this is a discarded function, mark the pc bounds as invalid,
8050 so that GDB will ignore it. */
8051 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8060 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8061 its low and high PC addresses. Do nothing if these addresses could not
8062 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8063 and HIGHPC to the high address if greater than HIGHPC. */
8066 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8067 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8068 struct dwarf2_cu
*cu
)
8070 CORE_ADDR low
, high
;
8071 struct die_info
*child
= die
->child
;
8073 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8075 *lowpc
= min (*lowpc
, low
);
8076 *highpc
= max (*highpc
, high
);
8079 /* If the language does not allow nested subprograms (either inside
8080 subprograms or lexical blocks), we're done. */
8081 if (cu
->language
!= language_ada
)
8084 /* Check all the children of the given DIE. If it contains nested
8085 subprograms, then check their pc bounds. Likewise, we need to
8086 check lexical blocks as well, as they may also contain subprogram
8088 while (child
&& child
->tag
)
8090 if (child
->tag
== DW_TAG_subprogram
8091 || child
->tag
== DW_TAG_lexical_block
)
8092 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8093 child
= sibling_die (child
);
8097 /* Get the low and high pc's represented by the scope DIE, and store
8098 them in *LOWPC and *HIGHPC. If the correct values can't be
8099 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8102 get_scope_pc_bounds (struct die_info
*die
,
8103 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8104 struct dwarf2_cu
*cu
)
8106 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8107 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8108 CORE_ADDR current_low
, current_high
;
8110 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8112 best_low
= current_low
;
8113 best_high
= current_high
;
8117 struct die_info
*child
= die
->child
;
8119 while (child
&& child
->tag
)
8121 switch (child
->tag
) {
8122 case DW_TAG_subprogram
:
8123 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8125 case DW_TAG_namespace
:
8127 /* FIXME: carlton/2004-01-16: Should we do this for
8128 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8129 that current GCC's always emit the DIEs corresponding
8130 to definitions of methods of classes as children of a
8131 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8132 the DIEs giving the declarations, which could be
8133 anywhere). But I don't see any reason why the
8134 standards says that they have to be there. */
8135 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8137 if (current_low
!= ((CORE_ADDR
) -1))
8139 best_low
= min (best_low
, current_low
);
8140 best_high
= max (best_high
, current_high
);
8148 child
= sibling_die (child
);
8153 *highpc
= best_high
;
8156 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8160 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8161 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8163 struct objfile
*objfile
= cu
->objfile
;
8164 struct attribute
*attr
;
8165 struct attribute
*attr_high
;
8167 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8170 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8173 CORE_ADDR low
= DW_ADDR (attr
);
8175 if (attr_high
->form
== DW_FORM_addr
8176 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8177 high
= DW_ADDR (attr_high
);
8179 high
= low
+ DW_UNSND (attr_high
);
8181 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8185 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8188 bfd
*obfd
= objfile
->obfd
;
8190 /* The value of the DW_AT_ranges attribute is the offset of the
8191 address range list in the .debug_ranges section. */
8192 unsigned long offset
= DW_UNSND (attr
);
8193 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8195 /* For some target architectures, but not others, the
8196 read_address function sign-extends the addresses it returns.
8197 To recognize base address selection entries, we need a
8199 unsigned int addr_size
= cu
->header
.addr_size
;
8200 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8202 /* The base address, to which the next pair is relative. Note
8203 that this 'base' is a DWARF concept: most entries in a range
8204 list are relative, to reduce the number of relocs against the
8205 debugging information. This is separate from this function's
8206 'baseaddr' argument, which GDB uses to relocate debugging
8207 information from a shared library based on the address at
8208 which the library was loaded. */
8209 CORE_ADDR base
= cu
->base_address
;
8210 int base_known
= cu
->base_known
;
8212 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8213 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8215 complaint (&symfile_complaints
,
8216 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8223 unsigned int bytes_read
;
8224 CORE_ADDR start
, end
;
8226 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8227 buffer
+= bytes_read
;
8228 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8229 buffer
+= bytes_read
;
8231 /* Did we find the end of the range list? */
8232 if (start
== 0 && end
== 0)
8235 /* Did we find a base address selection entry? */
8236 else if ((start
& base_select_mask
) == base_select_mask
)
8242 /* We found an ordinary address range. */
8247 complaint (&symfile_complaints
,
8248 _("Invalid .debug_ranges data "
8249 "(no base address)"));
8255 /* Inverted range entries are invalid. */
8256 complaint (&symfile_complaints
,
8257 _("Invalid .debug_ranges data "
8258 "(inverted range)"));
8262 /* Empty range entries have no effect. */
8266 record_block_range (block
,
8267 baseaddr
+ base
+ start
,
8268 baseaddr
+ base
+ end
- 1);
8274 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8275 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8276 during 4.6.0 experimental. */
8279 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8282 int major
, minor
, release
;
8285 if (cu
->producer
== NULL
)
8287 /* For unknown compilers expect their behavior is DWARF version
8290 GCC started to support .debug_types sections by -gdwarf-4 since
8291 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8292 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8293 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8294 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8299 if (cu
->checked_producer
)
8300 return cu
->producer_is_gxx_lt_4_6
;
8302 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8304 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
8306 /* For non-GCC compilers expect their behavior is DWARF version
8311 cs
= &cu
->producer
[strlen ("GNU ")];
8312 while (*cs
&& !isdigit (*cs
))
8314 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8316 /* Not recognized as GCC. */
8319 result
= major
< 4 || (major
== 4 && minor
< 6);
8322 cu
->checked_producer
= 1;
8323 cu
->producer_is_gxx_lt_4_6
= result
;
8328 /* Return the default accessibility type if it is not overriden by
8329 DW_AT_accessibility. */
8331 static enum dwarf_access_attribute
8332 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8334 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8336 /* The default DWARF 2 accessibility for members is public, the default
8337 accessibility for inheritance is private. */
8339 if (die
->tag
!= DW_TAG_inheritance
)
8340 return DW_ACCESS_public
;
8342 return DW_ACCESS_private
;
8346 /* DWARF 3+ defines the default accessibility a different way. The same
8347 rules apply now for DW_TAG_inheritance as for the members and it only
8348 depends on the container kind. */
8350 if (die
->parent
->tag
== DW_TAG_class_type
)
8351 return DW_ACCESS_private
;
8353 return DW_ACCESS_public
;
8357 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8358 offset. If the attribute was not found return 0, otherwise return
8359 1. If it was found but could not properly be handled, set *OFFSET
8363 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8366 struct attribute
*attr
;
8368 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8373 /* Note that we do not check for a section offset first here.
8374 This is because DW_AT_data_member_location is new in DWARF 4,
8375 so if we see it, we can assume that a constant form is really
8376 a constant and not a section offset. */
8377 if (attr_form_is_constant (attr
))
8378 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8379 else if (attr_form_is_section_offset (attr
))
8380 dwarf2_complex_location_expr_complaint ();
8381 else if (attr_form_is_block (attr
))
8382 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8384 dwarf2_complex_location_expr_complaint ();
8392 /* Add an aggregate field to the field list. */
8395 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8396 struct dwarf2_cu
*cu
)
8398 struct objfile
*objfile
= cu
->objfile
;
8399 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8400 struct nextfield
*new_field
;
8401 struct attribute
*attr
;
8403 char *fieldname
= "";
8405 /* Allocate a new field list entry and link it in. */
8406 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8407 make_cleanup (xfree
, new_field
);
8408 memset (new_field
, 0, sizeof (struct nextfield
));
8410 if (die
->tag
== DW_TAG_inheritance
)
8412 new_field
->next
= fip
->baseclasses
;
8413 fip
->baseclasses
= new_field
;
8417 new_field
->next
= fip
->fields
;
8418 fip
->fields
= new_field
;
8422 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8424 new_field
->accessibility
= DW_UNSND (attr
);
8426 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8427 if (new_field
->accessibility
!= DW_ACCESS_public
)
8428 fip
->non_public_fields
= 1;
8430 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8432 new_field
->virtuality
= DW_UNSND (attr
);
8434 new_field
->virtuality
= DW_VIRTUALITY_none
;
8436 fp
= &new_field
->field
;
8438 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8442 /* Data member other than a C++ static data member. */
8444 /* Get type of field. */
8445 fp
->type
= die_type (die
, cu
);
8447 SET_FIELD_BITPOS (*fp
, 0);
8449 /* Get bit size of field (zero if none). */
8450 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8453 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8457 FIELD_BITSIZE (*fp
) = 0;
8460 /* Get bit offset of field. */
8461 if (handle_data_member_location (die
, cu
, &offset
))
8462 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8463 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8466 if (gdbarch_bits_big_endian (gdbarch
))
8468 /* For big endian bits, the DW_AT_bit_offset gives the
8469 additional bit offset from the MSB of the containing
8470 anonymous object to the MSB of the field. We don't
8471 have to do anything special since we don't need to
8472 know the size of the anonymous object. */
8473 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8477 /* For little endian bits, compute the bit offset to the
8478 MSB of the anonymous object, subtract off the number of
8479 bits from the MSB of the field to the MSB of the
8480 object, and then subtract off the number of bits of
8481 the field itself. The result is the bit offset of
8482 the LSB of the field. */
8484 int bit_offset
= DW_UNSND (attr
);
8486 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8489 /* The size of the anonymous object containing
8490 the bit field is explicit, so use the
8491 indicated size (in bytes). */
8492 anonymous_size
= DW_UNSND (attr
);
8496 /* The size of the anonymous object containing
8497 the bit field must be inferred from the type
8498 attribute of the data member containing the
8500 anonymous_size
= TYPE_LENGTH (fp
->type
);
8502 SET_FIELD_BITPOS (*fp
,
8504 + anonymous_size
* bits_per_byte
8505 - bit_offset
- FIELD_BITSIZE (*fp
)));
8509 /* Get name of field. */
8510 fieldname
= dwarf2_name (die
, cu
);
8511 if (fieldname
== NULL
)
8514 /* The name is already allocated along with this objfile, so we don't
8515 need to duplicate it for the type. */
8516 fp
->name
= fieldname
;
8518 /* Change accessibility for artificial fields (e.g. virtual table
8519 pointer or virtual base class pointer) to private. */
8520 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8522 FIELD_ARTIFICIAL (*fp
) = 1;
8523 new_field
->accessibility
= DW_ACCESS_private
;
8524 fip
->non_public_fields
= 1;
8527 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8529 /* C++ static member. */
8531 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8532 is a declaration, but all versions of G++ as of this writing
8533 (so through at least 3.2.1) incorrectly generate
8534 DW_TAG_variable tags. */
8536 const char *physname
;
8538 /* Get name of field. */
8539 fieldname
= dwarf2_name (die
, cu
);
8540 if (fieldname
== NULL
)
8543 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8545 /* Only create a symbol if this is an external value.
8546 new_symbol checks this and puts the value in the global symbol
8547 table, which we want. If it is not external, new_symbol
8548 will try to put the value in cu->list_in_scope which is wrong. */
8549 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8551 /* A static const member, not much different than an enum as far as
8552 we're concerned, except that we can support more types. */
8553 new_symbol (die
, NULL
, cu
);
8556 /* Get physical name. */
8557 physname
= dwarf2_physname (fieldname
, die
, cu
);
8559 /* The name is already allocated along with this objfile, so we don't
8560 need to duplicate it for the type. */
8561 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8562 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8563 FIELD_NAME (*fp
) = fieldname
;
8565 else if (die
->tag
== DW_TAG_inheritance
)
8569 /* C++ base class field. */
8570 if (handle_data_member_location (die
, cu
, &offset
))
8571 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8572 FIELD_BITSIZE (*fp
) = 0;
8573 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8574 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8575 fip
->nbaseclasses
++;
8579 /* Add a typedef defined in the scope of the FIP's class. */
8582 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8583 struct dwarf2_cu
*cu
)
8585 struct objfile
*objfile
= cu
->objfile
;
8586 struct typedef_field_list
*new_field
;
8587 struct attribute
*attr
;
8588 struct typedef_field
*fp
;
8589 char *fieldname
= "";
8591 /* Allocate a new field list entry and link it in. */
8592 new_field
= xzalloc (sizeof (*new_field
));
8593 make_cleanup (xfree
, new_field
);
8595 gdb_assert (die
->tag
== DW_TAG_typedef
);
8597 fp
= &new_field
->field
;
8599 /* Get name of field. */
8600 fp
->name
= dwarf2_name (die
, cu
);
8601 if (fp
->name
== NULL
)
8604 fp
->type
= read_type_die (die
, cu
);
8606 new_field
->next
= fip
->typedef_field_list
;
8607 fip
->typedef_field_list
= new_field
;
8608 fip
->typedef_field_list_count
++;
8611 /* Create the vector of fields, and attach it to the type. */
8614 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8615 struct dwarf2_cu
*cu
)
8617 int nfields
= fip
->nfields
;
8619 /* Record the field count, allocate space for the array of fields,
8620 and create blank accessibility bitfields if necessary. */
8621 TYPE_NFIELDS (type
) = nfields
;
8622 TYPE_FIELDS (type
) = (struct field
*)
8623 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8624 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8626 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8628 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8630 TYPE_FIELD_PRIVATE_BITS (type
) =
8631 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8632 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8634 TYPE_FIELD_PROTECTED_BITS (type
) =
8635 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8636 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8638 TYPE_FIELD_IGNORE_BITS (type
) =
8639 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8640 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8643 /* If the type has baseclasses, allocate and clear a bit vector for
8644 TYPE_FIELD_VIRTUAL_BITS. */
8645 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8647 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8648 unsigned char *pointer
;
8650 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8651 pointer
= TYPE_ALLOC (type
, num_bytes
);
8652 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8653 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8654 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8657 /* Copy the saved-up fields into the field vector. Start from the head of
8658 the list, adding to the tail of the field array, so that they end up in
8659 the same order in the array in which they were added to the list. */
8660 while (nfields
-- > 0)
8662 struct nextfield
*fieldp
;
8666 fieldp
= fip
->fields
;
8667 fip
->fields
= fieldp
->next
;
8671 fieldp
= fip
->baseclasses
;
8672 fip
->baseclasses
= fieldp
->next
;
8675 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8676 switch (fieldp
->accessibility
)
8678 case DW_ACCESS_private
:
8679 if (cu
->language
!= language_ada
)
8680 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8683 case DW_ACCESS_protected
:
8684 if (cu
->language
!= language_ada
)
8685 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8688 case DW_ACCESS_public
:
8692 /* Unknown accessibility. Complain and treat it as public. */
8694 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8695 fieldp
->accessibility
);
8699 if (nfields
< fip
->nbaseclasses
)
8701 switch (fieldp
->virtuality
)
8703 case DW_VIRTUALITY_virtual
:
8704 case DW_VIRTUALITY_pure_virtual
:
8705 if (cu
->language
== language_ada
)
8706 error (_("unexpected virtuality in component of Ada type"));
8707 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8714 /* Add a member function to the proper fieldlist. */
8717 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8718 struct type
*type
, struct dwarf2_cu
*cu
)
8720 struct objfile
*objfile
= cu
->objfile
;
8721 struct attribute
*attr
;
8722 struct fnfieldlist
*flp
;
8724 struct fn_field
*fnp
;
8726 struct nextfnfield
*new_fnfield
;
8727 struct type
*this_type
;
8728 enum dwarf_access_attribute accessibility
;
8730 if (cu
->language
== language_ada
)
8731 error (_("unexpected member function in Ada type"));
8733 /* Get name of member function. */
8734 fieldname
= dwarf2_name (die
, cu
);
8735 if (fieldname
== NULL
)
8738 /* Look up member function name in fieldlist. */
8739 for (i
= 0; i
< fip
->nfnfields
; i
++)
8741 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8745 /* Create new list element if necessary. */
8746 if (i
< fip
->nfnfields
)
8747 flp
= &fip
->fnfieldlists
[i
];
8750 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8752 fip
->fnfieldlists
= (struct fnfieldlist
*)
8753 xrealloc (fip
->fnfieldlists
,
8754 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8755 * sizeof (struct fnfieldlist
));
8756 if (fip
->nfnfields
== 0)
8757 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8759 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8760 flp
->name
= fieldname
;
8763 i
= fip
->nfnfields
++;
8766 /* Create a new member function field and chain it to the field list
8768 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8769 make_cleanup (xfree
, new_fnfield
);
8770 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8771 new_fnfield
->next
= flp
->head
;
8772 flp
->head
= new_fnfield
;
8775 /* Fill in the member function field info. */
8776 fnp
= &new_fnfield
->fnfield
;
8778 /* Delay processing of the physname until later. */
8779 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8781 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8786 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8787 fnp
->physname
= physname
? physname
: "";
8790 fnp
->type
= alloc_type (objfile
);
8791 this_type
= read_type_die (die
, cu
);
8792 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8794 int nparams
= TYPE_NFIELDS (this_type
);
8796 /* TYPE is the domain of this method, and THIS_TYPE is the type
8797 of the method itself (TYPE_CODE_METHOD). */
8798 smash_to_method_type (fnp
->type
, type
,
8799 TYPE_TARGET_TYPE (this_type
),
8800 TYPE_FIELDS (this_type
),
8801 TYPE_NFIELDS (this_type
),
8802 TYPE_VARARGS (this_type
));
8804 /* Handle static member functions.
8805 Dwarf2 has no clean way to discern C++ static and non-static
8806 member functions. G++ helps GDB by marking the first
8807 parameter for non-static member functions (which is the this
8808 pointer) as artificial. We obtain this information from
8809 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8810 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8811 fnp
->voffset
= VOFFSET_STATIC
;
8814 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8815 dwarf2_full_name (fieldname
, die
, cu
));
8817 /* Get fcontext from DW_AT_containing_type if present. */
8818 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8819 fnp
->fcontext
= die_containing_type (die
, cu
);
8821 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8822 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8824 /* Get accessibility. */
8825 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8827 accessibility
= DW_UNSND (attr
);
8829 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8830 switch (accessibility
)
8832 case DW_ACCESS_private
:
8833 fnp
->is_private
= 1;
8835 case DW_ACCESS_protected
:
8836 fnp
->is_protected
= 1;
8840 /* Check for artificial methods. */
8841 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
8842 if (attr
&& DW_UNSND (attr
) != 0)
8843 fnp
->is_artificial
= 1;
8845 /* Get index in virtual function table if it is a virtual member
8846 function. For older versions of GCC, this is an offset in the
8847 appropriate virtual table, as specified by DW_AT_containing_type.
8848 For everyone else, it is an expression to be evaluated relative
8849 to the object address. */
8851 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
8854 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
8856 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
8858 /* Old-style GCC. */
8859 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
8861 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8862 || (DW_BLOCK (attr
)->size
> 1
8863 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
8864 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
8866 struct dwarf_block blk
;
8869 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8871 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
8872 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
8873 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8874 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
8875 dwarf2_complex_location_expr_complaint ();
8877 fnp
->voffset
/= cu
->header
.addr_size
;
8881 dwarf2_complex_location_expr_complaint ();
8884 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
8886 else if (attr_form_is_section_offset (attr
))
8888 dwarf2_complex_location_expr_complaint ();
8892 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
8898 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8899 if (attr
&& DW_UNSND (attr
))
8901 /* GCC does this, as of 2008-08-25; PR debug/37237. */
8902 complaint (&symfile_complaints
,
8903 _("Member function \"%s\" (offset %d) is virtual "
8904 "but the vtable offset is not specified"),
8905 fieldname
, die
->offset
.sect_off
);
8906 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8907 TYPE_CPLUS_DYNAMIC (type
) = 1;
8912 /* Create the vector of member function fields, and attach it to the type. */
8915 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
8916 struct dwarf2_cu
*cu
)
8918 struct fnfieldlist
*flp
;
8921 if (cu
->language
== language_ada
)
8922 error (_("unexpected member functions in Ada type"));
8924 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8925 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
8926 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
8928 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
8930 struct nextfnfield
*nfp
= flp
->head
;
8931 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
8934 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
8935 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
8936 fn_flp
->fn_fields
= (struct fn_field
*)
8937 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
8938 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
8939 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
8942 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
8945 /* Returns non-zero if NAME is the name of a vtable member in CU's
8946 language, zero otherwise. */
8948 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
8950 static const char vptr
[] = "_vptr";
8951 static const char vtable
[] = "vtable";
8953 /* Look for the C++ and Java forms of the vtable. */
8954 if ((cu
->language
== language_java
8955 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
8956 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
8957 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
8963 /* GCC outputs unnamed structures that are really pointers to member
8964 functions, with the ABI-specified layout. If TYPE describes
8965 such a structure, smash it into a member function type.
8967 GCC shouldn't do this; it should just output pointer to member DIEs.
8968 This is GCC PR debug/28767. */
8971 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
8973 struct type
*pfn_type
, *domain_type
, *new_type
;
8975 /* Check for a structure with no name and two children. */
8976 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
8979 /* Check for __pfn and __delta members. */
8980 if (TYPE_FIELD_NAME (type
, 0) == NULL
8981 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
8982 || TYPE_FIELD_NAME (type
, 1) == NULL
8983 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
8986 /* Find the type of the method. */
8987 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
8988 if (pfn_type
== NULL
8989 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
8990 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
8993 /* Look for the "this" argument. */
8994 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
8995 if (TYPE_NFIELDS (pfn_type
) == 0
8996 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
8997 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
9000 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9001 new_type
= alloc_type (objfile
);
9002 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9003 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9004 TYPE_VARARGS (pfn_type
));
9005 smash_to_methodptr_type (type
, new_type
);
9008 /* Called when we find the DIE that starts a structure or union scope
9009 (definition) to create a type for the structure or union. Fill in
9010 the type's name and general properties; the members will not be
9011 processed until process_structure_type.
9013 NOTE: we need to call these functions regardless of whether or not the
9014 DIE has a DW_AT_name attribute, since it might be an anonymous
9015 structure or union. This gets the type entered into our set of
9018 However, if the structure is incomplete (an opaque struct/union)
9019 then suppress creating a symbol table entry for it since gdb only
9020 wants to find the one with the complete definition. Note that if
9021 it is complete, we just call new_symbol, which does it's own
9022 checking about whether the struct/union is anonymous or not (and
9023 suppresses creating a symbol table entry itself). */
9025 static struct type
*
9026 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9028 struct objfile
*objfile
= cu
->objfile
;
9030 struct attribute
*attr
;
9033 /* If the definition of this type lives in .debug_types, read that type.
9034 Don't follow DW_AT_specification though, that will take us back up
9035 the chain and we want to go down. */
9036 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9039 struct dwarf2_cu
*type_cu
= cu
;
9040 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9042 /* We could just recurse on read_structure_type, but we need to call
9043 get_die_type to ensure only one type for this DIE is created.
9044 This is important, for example, because for c++ classes we need
9045 TYPE_NAME set which is only done by new_symbol. Blech. */
9046 type
= read_type_die (type_die
, type_cu
);
9048 /* TYPE_CU may not be the same as CU.
9049 Ensure TYPE is recorded in CU's type_hash table. */
9050 return set_die_type (die
, type
, cu
);
9053 type
= alloc_type (objfile
);
9054 INIT_CPLUS_SPECIFIC (type
);
9056 name
= dwarf2_name (die
, cu
);
9059 if (cu
->language
== language_cplus
9060 || cu
->language
== language_java
)
9062 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9064 /* dwarf2_full_name might have already finished building the DIE's
9065 type. If so, there is no need to continue. */
9066 if (get_die_type (die
, cu
) != NULL
)
9067 return get_die_type (die
, cu
);
9069 TYPE_TAG_NAME (type
) = full_name
;
9070 if (die
->tag
== DW_TAG_structure_type
9071 || die
->tag
== DW_TAG_class_type
)
9072 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9076 /* The name is already allocated along with this objfile, so
9077 we don't need to duplicate it for the type. */
9078 TYPE_TAG_NAME (type
) = (char *) name
;
9079 if (die
->tag
== DW_TAG_class_type
)
9080 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9084 if (die
->tag
== DW_TAG_structure_type
)
9086 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9088 else if (die
->tag
== DW_TAG_union_type
)
9090 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9094 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9097 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9098 TYPE_DECLARED_CLASS (type
) = 1;
9100 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9103 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9107 TYPE_LENGTH (type
) = 0;
9110 TYPE_STUB_SUPPORTED (type
) = 1;
9111 if (die_is_declaration (die
, cu
))
9112 TYPE_STUB (type
) = 1;
9113 else if (attr
== NULL
&& die
->child
== NULL
9114 && producer_is_realview (cu
->producer
))
9115 /* RealView does not output the required DW_AT_declaration
9116 on incomplete types. */
9117 TYPE_STUB (type
) = 1;
9119 /* We need to add the type field to the die immediately so we don't
9120 infinitely recurse when dealing with pointers to the structure
9121 type within the structure itself. */
9122 set_die_type (die
, type
, cu
);
9124 /* set_die_type should be already done. */
9125 set_descriptive_type (type
, die
, cu
);
9130 /* Finish creating a structure or union type, including filling in
9131 its members and creating a symbol for it. */
9134 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9136 struct objfile
*objfile
= cu
->objfile
;
9137 struct die_info
*child_die
= die
->child
;
9140 type
= get_die_type (die
, cu
);
9142 type
= read_structure_type (die
, cu
);
9144 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9146 struct field_info fi
;
9147 struct die_info
*child_die
;
9148 VEC (symbolp
) *template_args
= NULL
;
9149 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9151 memset (&fi
, 0, sizeof (struct field_info
));
9153 child_die
= die
->child
;
9155 while (child_die
&& child_die
->tag
)
9157 if (child_die
->tag
== DW_TAG_member
9158 || child_die
->tag
== DW_TAG_variable
)
9160 /* NOTE: carlton/2002-11-05: A C++ static data member
9161 should be a DW_TAG_member that is a declaration, but
9162 all versions of G++ as of this writing (so through at
9163 least 3.2.1) incorrectly generate DW_TAG_variable
9164 tags for them instead. */
9165 dwarf2_add_field (&fi
, child_die
, cu
);
9167 else if (child_die
->tag
== DW_TAG_subprogram
)
9169 /* C++ member function. */
9170 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9172 else if (child_die
->tag
== DW_TAG_inheritance
)
9174 /* C++ base class field. */
9175 dwarf2_add_field (&fi
, child_die
, cu
);
9177 else if (child_die
->tag
== DW_TAG_typedef
)
9178 dwarf2_add_typedef (&fi
, child_die
, cu
);
9179 else if (child_die
->tag
== DW_TAG_template_type_param
9180 || child_die
->tag
== DW_TAG_template_value_param
)
9182 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9185 VEC_safe_push (symbolp
, template_args
, arg
);
9188 child_die
= sibling_die (child_die
);
9191 /* Attach template arguments to type. */
9192 if (! VEC_empty (symbolp
, template_args
))
9194 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9195 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9196 = VEC_length (symbolp
, template_args
);
9197 TYPE_TEMPLATE_ARGUMENTS (type
)
9198 = obstack_alloc (&objfile
->objfile_obstack
,
9199 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9200 * sizeof (struct symbol
*)));
9201 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9202 VEC_address (symbolp
, template_args
),
9203 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9204 * sizeof (struct symbol
*)));
9205 VEC_free (symbolp
, template_args
);
9208 /* Attach fields and member functions to the type. */
9210 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9213 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9215 /* Get the type which refers to the base class (possibly this
9216 class itself) which contains the vtable pointer for the current
9217 class from the DW_AT_containing_type attribute. This use of
9218 DW_AT_containing_type is a GNU extension. */
9220 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9222 struct type
*t
= die_containing_type (die
, cu
);
9224 TYPE_VPTR_BASETYPE (type
) = t
;
9229 /* Our own class provides vtbl ptr. */
9230 for (i
= TYPE_NFIELDS (t
) - 1;
9231 i
>= TYPE_N_BASECLASSES (t
);
9234 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9236 if (is_vtable_name (fieldname
, cu
))
9238 TYPE_VPTR_FIELDNO (type
) = i
;
9243 /* Complain if virtual function table field not found. */
9244 if (i
< TYPE_N_BASECLASSES (t
))
9245 complaint (&symfile_complaints
,
9246 _("virtual function table pointer "
9247 "not found when defining class '%s'"),
9248 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9253 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9256 else if (cu
->producer
9257 && strncmp (cu
->producer
,
9258 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9260 /* The IBM XLC compiler does not provide direct indication
9261 of the containing type, but the vtable pointer is
9262 always named __vfp. */
9266 for (i
= TYPE_NFIELDS (type
) - 1;
9267 i
>= TYPE_N_BASECLASSES (type
);
9270 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9272 TYPE_VPTR_FIELDNO (type
) = i
;
9273 TYPE_VPTR_BASETYPE (type
) = type
;
9280 /* Copy fi.typedef_field_list linked list elements content into the
9281 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9282 if (fi
.typedef_field_list
)
9284 int i
= fi
.typedef_field_list_count
;
9286 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9287 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9288 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9289 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9291 /* Reverse the list order to keep the debug info elements order. */
9294 struct typedef_field
*dest
, *src
;
9296 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9297 src
= &fi
.typedef_field_list
->field
;
9298 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9303 do_cleanups (back_to
);
9305 if (HAVE_CPLUS_STRUCT (type
))
9306 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9309 quirk_gcc_member_function_pointer (type
, objfile
);
9311 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9312 snapshots) has been known to create a die giving a declaration
9313 for a class that has, as a child, a die giving a definition for a
9314 nested class. So we have to process our children even if the
9315 current die is a declaration. Normally, of course, a declaration
9316 won't have any children at all. */
9318 while (child_die
!= NULL
&& child_die
->tag
)
9320 if (child_die
->tag
== DW_TAG_member
9321 || child_die
->tag
== DW_TAG_variable
9322 || child_die
->tag
== DW_TAG_inheritance
9323 || child_die
->tag
== DW_TAG_template_value_param
9324 || child_die
->tag
== DW_TAG_template_type_param
)
9329 process_die (child_die
, cu
);
9331 child_die
= sibling_die (child_die
);
9334 /* Do not consider external references. According to the DWARF standard,
9335 these DIEs are identified by the fact that they have no byte_size
9336 attribute, and a declaration attribute. */
9337 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9338 || !die_is_declaration (die
, cu
))
9339 new_symbol (die
, type
, cu
);
9342 /* Given a DW_AT_enumeration_type die, set its type. We do not
9343 complete the type's fields yet, or create any symbols. */
9345 static struct type
*
9346 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9348 struct objfile
*objfile
= cu
->objfile
;
9350 struct attribute
*attr
;
9353 /* If the definition of this type lives in .debug_types, read that type.
9354 Don't follow DW_AT_specification though, that will take us back up
9355 the chain and we want to go down. */
9356 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9359 struct dwarf2_cu
*type_cu
= cu
;
9360 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9362 type
= read_type_die (type_die
, type_cu
);
9364 /* TYPE_CU may not be the same as CU.
9365 Ensure TYPE is recorded in CU's type_hash table. */
9366 return set_die_type (die
, type
, cu
);
9369 type
= alloc_type (objfile
);
9371 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9372 name
= dwarf2_full_name (NULL
, die
, cu
);
9374 TYPE_TAG_NAME (type
) = (char *) name
;
9376 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9379 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9383 TYPE_LENGTH (type
) = 0;
9386 /* The enumeration DIE can be incomplete. In Ada, any type can be
9387 declared as private in the package spec, and then defined only
9388 inside the package body. Such types are known as Taft Amendment
9389 Types. When another package uses such a type, an incomplete DIE
9390 may be generated by the compiler. */
9391 if (die_is_declaration (die
, cu
))
9392 TYPE_STUB (type
) = 1;
9394 return set_die_type (die
, type
, cu
);
9397 /* Given a pointer to a die which begins an enumeration, process all
9398 the dies that define the members of the enumeration, and create the
9399 symbol for the enumeration type.
9401 NOTE: We reverse the order of the element list. */
9404 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9406 struct type
*this_type
;
9408 this_type
= get_die_type (die
, cu
);
9409 if (this_type
== NULL
)
9410 this_type
= read_enumeration_type (die
, cu
);
9412 if (die
->child
!= NULL
)
9414 struct die_info
*child_die
;
9416 struct field
*fields
= NULL
;
9418 int unsigned_enum
= 1;
9423 child_die
= die
->child
;
9424 while (child_die
&& child_die
->tag
)
9426 if (child_die
->tag
!= DW_TAG_enumerator
)
9428 process_die (child_die
, cu
);
9432 name
= dwarf2_name (child_die
, cu
);
9435 sym
= new_symbol (child_die
, this_type
, cu
);
9436 if (SYMBOL_VALUE (sym
) < 0)
9441 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9444 mask
|= SYMBOL_VALUE (sym
);
9446 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9448 fields
= (struct field
*)
9450 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9451 * sizeof (struct field
));
9454 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9455 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9456 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9457 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9463 child_die
= sibling_die (child_die
);
9468 TYPE_NFIELDS (this_type
) = num_fields
;
9469 TYPE_FIELDS (this_type
) = (struct field
*)
9470 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9471 memcpy (TYPE_FIELDS (this_type
), fields
,
9472 sizeof (struct field
) * num_fields
);
9476 TYPE_UNSIGNED (this_type
) = 1;
9478 TYPE_FLAG_ENUM (this_type
) = 1;
9481 /* If we are reading an enum from a .debug_types unit, and the enum
9482 is a declaration, and the enum is not the signatured type in the
9483 unit, then we do not want to add a symbol for it. Adding a
9484 symbol would in some cases obscure the true definition of the
9485 enum, giving users an incomplete type when the definition is
9486 actually available. Note that we do not want to do this for all
9487 enums which are just declarations, because C++0x allows forward
9488 enum declarations. */
9489 if (cu
->per_cu
->is_debug_types
9490 && die_is_declaration (die
, cu
))
9492 struct signatured_type
*sig_type
;
9495 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9496 cu
->per_cu
->info_or_types_section
,
9497 cu
->per_cu
->offset
);
9498 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9499 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9503 new_symbol (die
, this_type
, cu
);
9506 /* Extract all information from a DW_TAG_array_type DIE and put it in
9507 the DIE's type field. For now, this only handles one dimensional
9510 static struct type
*
9511 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9513 struct objfile
*objfile
= cu
->objfile
;
9514 struct die_info
*child_die
;
9516 struct type
*element_type
, *range_type
, *index_type
;
9517 struct type
**range_types
= NULL
;
9518 struct attribute
*attr
;
9520 struct cleanup
*back_to
;
9523 element_type
= die_type (die
, cu
);
9525 /* The die_type call above may have already set the type for this DIE. */
9526 type
= get_die_type (die
, cu
);
9530 /* Irix 6.2 native cc creates array types without children for
9531 arrays with unspecified length. */
9532 if (die
->child
== NULL
)
9534 index_type
= objfile_type (objfile
)->builtin_int
;
9535 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9536 type
= create_array_type (NULL
, element_type
, range_type
);
9537 return set_die_type (die
, type
, cu
);
9540 back_to
= make_cleanup (null_cleanup
, NULL
);
9541 child_die
= die
->child
;
9542 while (child_die
&& child_die
->tag
)
9544 if (child_die
->tag
== DW_TAG_subrange_type
)
9546 struct type
*child_type
= read_type_die (child_die
, cu
);
9548 if (child_type
!= NULL
)
9550 /* The range type was succesfully read. Save it for the
9551 array type creation. */
9552 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9554 range_types
= (struct type
**)
9555 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9556 * sizeof (struct type
*));
9558 make_cleanup (free_current_contents
, &range_types
);
9560 range_types
[ndim
++] = child_type
;
9563 child_die
= sibling_die (child_die
);
9566 /* Dwarf2 dimensions are output from left to right, create the
9567 necessary array types in backwards order. */
9569 type
= element_type
;
9571 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9576 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9581 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9584 /* Understand Dwarf2 support for vector types (like they occur on
9585 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9586 array type. This is not part of the Dwarf2/3 standard yet, but a
9587 custom vendor extension. The main difference between a regular
9588 array and the vector variant is that vectors are passed by value
9590 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9592 make_vector_type (type
);
9594 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9595 implementation may choose to implement triple vectors using this
9597 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9600 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9601 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9603 complaint (&symfile_complaints
,
9604 _("DW_AT_byte_size for array type smaller "
9605 "than the total size of elements"));
9608 name
= dwarf2_name (die
, cu
);
9610 TYPE_NAME (type
) = name
;
9612 /* Install the type in the die. */
9613 set_die_type (die
, type
, cu
);
9615 /* set_die_type should be already done. */
9616 set_descriptive_type (type
, die
, cu
);
9618 do_cleanups (back_to
);
9623 static enum dwarf_array_dim_ordering
9624 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9626 struct attribute
*attr
;
9628 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9630 if (attr
) return DW_SND (attr
);
9632 /* GNU F77 is a special case, as at 08/2004 array type info is the
9633 opposite order to the dwarf2 specification, but data is still
9634 laid out as per normal fortran.
9636 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9637 version checking. */
9639 if (cu
->language
== language_fortran
9640 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9642 return DW_ORD_row_major
;
9645 switch (cu
->language_defn
->la_array_ordering
)
9647 case array_column_major
:
9648 return DW_ORD_col_major
;
9649 case array_row_major
:
9651 return DW_ORD_row_major
;
9655 /* Extract all information from a DW_TAG_set_type DIE and put it in
9656 the DIE's type field. */
9658 static struct type
*
9659 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9661 struct type
*domain_type
, *set_type
;
9662 struct attribute
*attr
;
9664 domain_type
= die_type (die
, cu
);
9666 /* The die_type call above may have already set the type for this DIE. */
9667 set_type
= get_die_type (die
, cu
);
9671 set_type
= create_set_type (NULL
, domain_type
);
9673 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9675 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9677 return set_die_type (die
, set_type
, cu
);
9680 /* First cut: install each common block member as a global variable. */
9683 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9685 struct die_info
*child_die
;
9686 struct attribute
*attr
;
9688 CORE_ADDR base
= (CORE_ADDR
) 0;
9690 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9693 /* Support the .debug_loc offsets. */
9694 if (attr_form_is_block (attr
))
9696 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9698 else if (attr_form_is_section_offset (attr
))
9700 dwarf2_complex_location_expr_complaint ();
9704 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9705 "common block member");
9708 if (die
->child
!= NULL
)
9710 child_die
= die
->child
;
9711 while (child_die
&& child_die
->tag
)
9715 sym
= new_symbol (child_die
, NULL
, cu
);
9717 && handle_data_member_location (child_die
, cu
, &offset
))
9719 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9720 add_symbol_to_list (sym
, &global_symbols
);
9722 child_die
= sibling_die (child_die
);
9727 /* Create a type for a C++ namespace. */
9729 static struct type
*
9730 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9732 struct objfile
*objfile
= cu
->objfile
;
9733 const char *previous_prefix
, *name
;
9737 /* For extensions, reuse the type of the original namespace. */
9738 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9740 struct die_info
*ext_die
;
9741 struct dwarf2_cu
*ext_cu
= cu
;
9743 ext_die
= dwarf2_extension (die
, &ext_cu
);
9744 type
= read_type_die (ext_die
, ext_cu
);
9746 /* EXT_CU may not be the same as CU.
9747 Ensure TYPE is recorded in CU's type_hash table. */
9748 return set_die_type (die
, type
, cu
);
9751 name
= namespace_name (die
, &is_anonymous
, cu
);
9753 /* Now build the name of the current namespace. */
9755 previous_prefix
= determine_prefix (die
, cu
);
9756 if (previous_prefix
[0] != '\0')
9757 name
= typename_concat (&objfile
->objfile_obstack
,
9758 previous_prefix
, name
, 0, cu
);
9760 /* Create the type. */
9761 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9763 TYPE_NAME (type
) = (char *) name
;
9764 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9766 return set_die_type (die
, type
, cu
);
9769 /* Read a C++ namespace. */
9772 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9774 struct objfile
*objfile
= cu
->objfile
;
9777 /* Add a symbol associated to this if we haven't seen the namespace
9778 before. Also, add a using directive if it's an anonymous
9781 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9785 type
= read_type_die (die
, cu
);
9786 new_symbol (die
, type
, cu
);
9788 namespace_name (die
, &is_anonymous
, cu
);
9791 const char *previous_prefix
= determine_prefix (die
, cu
);
9793 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9794 NULL
, NULL
, &objfile
->objfile_obstack
);
9798 if (die
->child
!= NULL
)
9800 struct die_info
*child_die
= die
->child
;
9802 while (child_die
&& child_die
->tag
)
9804 process_die (child_die
, cu
);
9805 child_die
= sibling_die (child_die
);
9810 /* Read a Fortran module as type. This DIE can be only a declaration used for
9811 imported module. Still we need that type as local Fortran "use ... only"
9812 declaration imports depend on the created type in determine_prefix. */
9814 static struct type
*
9815 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9817 struct objfile
*objfile
= cu
->objfile
;
9821 module_name
= dwarf2_name (die
, cu
);
9823 complaint (&symfile_complaints
,
9824 _("DW_TAG_module has no name, offset 0x%x"),
9825 die
->offset
.sect_off
);
9826 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
9828 /* determine_prefix uses TYPE_TAG_NAME. */
9829 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9831 return set_die_type (die
, type
, cu
);
9834 /* Read a Fortran module. */
9837 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
9839 struct die_info
*child_die
= die
->child
;
9841 while (child_die
&& child_die
->tag
)
9843 process_die (child_die
, cu
);
9844 child_die
= sibling_die (child_die
);
9848 /* Return the name of the namespace represented by DIE. Set
9849 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
9853 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
9855 struct die_info
*current_die
;
9856 const char *name
= NULL
;
9858 /* Loop through the extensions until we find a name. */
9860 for (current_die
= die
;
9861 current_die
!= NULL
;
9862 current_die
= dwarf2_extension (die
, &cu
))
9864 name
= dwarf2_name (current_die
, cu
);
9869 /* Is it an anonymous namespace? */
9871 *is_anonymous
= (name
== NULL
);
9873 name
= CP_ANONYMOUS_NAMESPACE_STR
;
9878 /* Extract all information from a DW_TAG_pointer_type DIE and add to
9879 the user defined type vector. */
9881 static struct type
*
9882 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9884 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9885 struct comp_unit_head
*cu_header
= &cu
->header
;
9887 struct attribute
*attr_byte_size
;
9888 struct attribute
*attr_address_class
;
9889 int byte_size
, addr_class
;
9890 struct type
*target_type
;
9892 target_type
= die_type (die
, cu
);
9894 /* The die_type call above may have already set the type for this DIE. */
9895 type
= get_die_type (die
, cu
);
9899 type
= lookup_pointer_type (target_type
);
9901 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9903 byte_size
= DW_UNSND (attr_byte_size
);
9905 byte_size
= cu_header
->addr_size
;
9907 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
9908 if (attr_address_class
)
9909 addr_class
= DW_UNSND (attr_address_class
);
9911 addr_class
= DW_ADDR_none
;
9913 /* If the pointer size or address class is different than the
9914 default, create a type variant marked as such and set the
9915 length accordingly. */
9916 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
9918 if (gdbarch_address_class_type_flags_p (gdbarch
))
9922 type_flags
= gdbarch_address_class_type_flags
9923 (gdbarch
, byte_size
, addr_class
);
9924 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
9926 type
= make_type_with_address_space (type
, type_flags
);
9928 else if (TYPE_LENGTH (type
) != byte_size
)
9930 complaint (&symfile_complaints
,
9931 _("invalid pointer size %d"), byte_size
);
9935 /* Should we also complain about unhandled address classes? */
9939 TYPE_LENGTH (type
) = byte_size
;
9940 return set_die_type (die
, type
, cu
);
9943 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
9944 the user defined type vector. */
9946 static struct type
*
9947 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9950 struct type
*to_type
;
9951 struct type
*domain
;
9953 to_type
= die_type (die
, cu
);
9954 domain
= die_containing_type (die
, cu
);
9956 /* The calls above may have already set the type for this DIE. */
9957 type
= get_die_type (die
, cu
);
9961 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
9962 type
= lookup_methodptr_type (to_type
);
9964 type
= lookup_memberptr_type (to_type
, domain
);
9966 return set_die_type (die
, type
, cu
);
9969 /* Extract all information from a DW_TAG_reference_type DIE and add to
9970 the user defined type vector. */
9972 static struct type
*
9973 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9975 struct comp_unit_head
*cu_header
= &cu
->header
;
9976 struct type
*type
, *target_type
;
9977 struct attribute
*attr
;
9979 target_type
= die_type (die
, cu
);
9981 /* The die_type call above may have already set the type for this DIE. */
9982 type
= get_die_type (die
, cu
);
9986 type
= lookup_reference_type (target_type
);
9987 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9990 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9994 TYPE_LENGTH (type
) = cu_header
->addr_size
;
9996 return set_die_type (die
, type
, cu
);
9999 static struct type
*
10000 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10002 struct type
*base_type
, *cv_type
;
10004 base_type
= die_type (die
, cu
);
10006 /* The die_type call above may have already set the type for this DIE. */
10007 cv_type
= get_die_type (die
, cu
);
10011 /* In case the const qualifier is applied to an array type, the element type
10012 is so qualified, not the array type (section 6.7.3 of C99). */
10013 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10015 struct type
*el_type
, *inner_array
;
10017 base_type
= copy_type (base_type
);
10018 inner_array
= base_type
;
10020 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10022 TYPE_TARGET_TYPE (inner_array
) =
10023 copy_type (TYPE_TARGET_TYPE (inner_array
));
10024 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10027 el_type
= TYPE_TARGET_TYPE (inner_array
);
10028 TYPE_TARGET_TYPE (inner_array
) =
10029 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10031 return set_die_type (die
, base_type
, cu
);
10034 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10035 return set_die_type (die
, cv_type
, cu
);
10038 static struct type
*
10039 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10041 struct type
*base_type
, *cv_type
;
10043 base_type
= die_type (die
, cu
);
10045 /* The die_type call above may have already set the type for this DIE. */
10046 cv_type
= get_die_type (die
, cu
);
10050 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10051 return set_die_type (die
, cv_type
, cu
);
10054 /* Extract all information from a DW_TAG_string_type DIE and add to
10055 the user defined type vector. It isn't really a user defined type,
10056 but it behaves like one, with other DIE's using an AT_user_def_type
10057 attribute to reference it. */
10059 static struct type
*
10060 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10062 struct objfile
*objfile
= cu
->objfile
;
10063 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10064 struct type
*type
, *range_type
, *index_type
, *char_type
;
10065 struct attribute
*attr
;
10066 unsigned int length
;
10068 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10071 length
= DW_UNSND (attr
);
10075 /* Check for the DW_AT_byte_size attribute. */
10076 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10079 length
= DW_UNSND (attr
);
10087 index_type
= objfile_type (objfile
)->builtin_int
;
10088 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10089 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10090 type
= create_string_type (NULL
, char_type
, range_type
);
10092 return set_die_type (die
, type
, cu
);
10095 /* Handle DIES due to C code like:
10099 int (*funcp)(int a, long l);
10103 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10105 static struct type
*
10106 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10108 struct objfile
*objfile
= cu
->objfile
;
10109 struct type
*type
; /* Type that this function returns. */
10110 struct type
*ftype
; /* Function that returns above type. */
10111 struct attribute
*attr
;
10113 type
= die_type (die
, cu
);
10115 /* The die_type call above may have already set the type for this DIE. */
10116 ftype
= get_die_type (die
, cu
);
10120 ftype
= lookup_function_type (type
);
10122 /* All functions in C++, Pascal and Java have prototypes. */
10123 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10124 if ((attr
&& (DW_UNSND (attr
) != 0))
10125 || cu
->language
== language_cplus
10126 || cu
->language
== language_java
10127 || cu
->language
== language_pascal
)
10128 TYPE_PROTOTYPED (ftype
) = 1;
10129 else if (producer_is_realview (cu
->producer
))
10130 /* RealView does not emit DW_AT_prototyped. We can not
10131 distinguish prototyped and unprototyped functions; default to
10132 prototyped, since that is more common in modern code (and
10133 RealView warns about unprototyped functions). */
10134 TYPE_PROTOTYPED (ftype
) = 1;
10136 /* Store the calling convention in the type if it's available in
10137 the subroutine die. Otherwise set the calling convention to
10138 the default value DW_CC_normal. */
10139 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10141 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10142 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10143 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10145 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10147 /* We need to add the subroutine type to the die immediately so
10148 we don't infinitely recurse when dealing with parameters
10149 declared as the same subroutine type. */
10150 set_die_type (die
, ftype
, cu
);
10152 if (die
->child
!= NULL
)
10154 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10155 struct die_info
*child_die
;
10156 int nparams
, iparams
;
10158 /* Count the number of parameters.
10159 FIXME: GDB currently ignores vararg functions, but knows about
10160 vararg member functions. */
10162 child_die
= die
->child
;
10163 while (child_die
&& child_die
->tag
)
10165 if (child_die
->tag
== DW_TAG_formal_parameter
)
10167 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10168 TYPE_VARARGS (ftype
) = 1;
10169 child_die
= sibling_die (child_die
);
10172 /* Allocate storage for parameters and fill them in. */
10173 TYPE_NFIELDS (ftype
) = nparams
;
10174 TYPE_FIELDS (ftype
) = (struct field
*)
10175 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10177 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10178 even if we error out during the parameters reading below. */
10179 for (iparams
= 0; iparams
< nparams
; iparams
++)
10180 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10183 child_die
= die
->child
;
10184 while (child_die
&& child_die
->tag
)
10186 if (child_die
->tag
== DW_TAG_formal_parameter
)
10188 struct type
*arg_type
;
10190 /* DWARF version 2 has no clean way to discern C++
10191 static and non-static member functions. G++ helps
10192 GDB by marking the first parameter for non-static
10193 member functions (which is the this pointer) as
10194 artificial. We pass this information to
10195 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10197 DWARF version 3 added DW_AT_object_pointer, which GCC
10198 4.5 does not yet generate. */
10199 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10201 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10204 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10206 /* GCC/43521: In java, the formal parameter
10207 "this" is sometimes not marked with DW_AT_artificial. */
10208 if (cu
->language
== language_java
)
10210 const char *name
= dwarf2_name (child_die
, cu
);
10212 if (name
&& !strcmp (name
, "this"))
10213 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10216 arg_type
= die_type (child_die
, cu
);
10218 /* RealView does not mark THIS as const, which the testsuite
10219 expects. GCC marks THIS as const in method definitions,
10220 but not in the class specifications (GCC PR 43053). */
10221 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10222 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10225 struct dwarf2_cu
*arg_cu
= cu
;
10226 const char *name
= dwarf2_name (child_die
, cu
);
10228 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10231 /* If the compiler emits this, use it. */
10232 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10235 else if (name
&& strcmp (name
, "this") == 0)
10236 /* Function definitions will have the argument names. */
10238 else if (name
== NULL
&& iparams
== 0)
10239 /* Declarations may not have the names, so like
10240 elsewhere in GDB, assume an artificial first
10241 argument is "this". */
10245 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10249 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10252 child_die
= sibling_die (child_die
);
10259 static struct type
*
10260 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10262 struct objfile
*objfile
= cu
->objfile
;
10263 const char *name
= NULL
;
10264 struct type
*this_type
, *target_type
;
10266 name
= dwarf2_full_name (NULL
, die
, cu
);
10267 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10268 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10269 TYPE_NAME (this_type
) = (char *) name
;
10270 set_die_type (die
, this_type
, cu
);
10271 target_type
= die_type (die
, cu
);
10272 if (target_type
!= this_type
)
10273 TYPE_TARGET_TYPE (this_type
) = target_type
;
10276 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10277 spec and cause infinite loops in GDB. */
10278 complaint (&symfile_complaints
,
10279 _("Self-referential DW_TAG_typedef "
10280 "- DIE at 0x%x [in module %s]"),
10281 die
->offset
.sect_off
, objfile
->name
);
10282 TYPE_TARGET_TYPE (this_type
) = NULL
;
10287 /* Find a representation of a given base type and install
10288 it in the TYPE field of the die. */
10290 static struct type
*
10291 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10293 struct objfile
*objfile
= cu
->objfile
;
10295 struct attribute
*attr
;
10296 int encoding
= 0, size
= 0;
10298 enum type_code code
= TYPE_CODE_INT
;
10299 int type_flags
= 0;
10300 struct type
*target_type
= NULL
;
10302 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10305 encoding
= DW_UNSND (attr
);
10307 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10310 size
= DW_UNSND (attr
);
10312 name
= dwarf2_name (die
, cu
);
10315 complaint (&symfile_complaints
,
10316 _("DW_AT_name missing from DW_TAG_base_type"));
10321 case DW_ATE_address
:
10322 /* Turn DW_ATE_address into a void * pointer. */
10323 code
= TYPE_CODE_PTR
;
10324 type_flags
|= TYPE_FLAG_UNSIGNED
;
10325 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10327 case DW_ATE_boolean
:
10328 code
= TYPE_CODE_BOOL
;
10329 type_flags
|= TYPE_FLAG_UNSIGNED
;
10331 case DW_ATE_complex_float
:
10332 code
= TYPE_CODE_COMPLEX
;
10333 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10335 case DW_ATE_decimal_float
:
10336 code
= TYPE_CODE_DECFLOAT
;
10339 code
= TYPE_CODE_FLT
;
10341 case DW_ATE_signed
:
10343 case DW_ATE_unsigned
:
10344 type_flags
|= TYPE_FLAG_UNSIGNED
;
10345 if (cu
->language
== language_fortran
10347 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10348 code
= TYPE_CODE_CHAR
;
10350 case DW_ATE_signed_char
:
10351 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10352 || cu
->language
== language_pascal
10353 || cu
->language
== language_fortran
)
10354 code
= TYPE_CODE_CHAR
;
10356 case DW_ATE_unsigned_char
:
10357 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10358 || cu
->language
== language_pascal
10359 || cu
->language
== language_fortran
)
10360 code
= TYPE_CODE_CHAR
;
10361 type_flags
|= TYPE_FLAG_UNSIGNED
;
10364 /* We just treat this as an integer and then recognize the
10365 type by name elsewhere. */
10369 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10370 dwarf_type_encoding_name (encoding
));
10374 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10375 TYPE_NAME (type
) = name
;
10376 TYPE_TARGET_TYPE (type
) = target_type
;
10378 if (name
&& strcmp (name
, "char") == 0)
10379 TYPE_NOSIGN (type
) = 1;
10381 return set_die_type (die
, type
, cu
);
10384 /* Read the given DW_AT_subrange DIE. */
10386 static struct type
*
10387 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10389 struct type
*base_type
;
10390 struct type
*range_type
;
10391 struct attribute
*attr
;
10393 int low_default_is_valid
;
10395 LONGEST negative_mask
;
10397 base_type
= die_type (die
, cu
);
10398 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10399 check_typedef (base_type
);
10401 /* The die_type call above may have already set the type for this DIE. */
10402 range_type
= get_die_type (die
, cu
);
10406 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10407 omitting DW_AT_lower_bound. */
10408 switch (cu
->language
)
10411 case language_cplus
:
10413 low_default_is_valid
= 1;
10415 case language_fortran
:
10417 low_default_is_valid
= 1;
10420 case language_java
:
10421 case language_objc
:
10423 low_default_is_valid
= (cu
->header
.version
>= 4);
10427 case language_pascal
:
10429 low_default_is_valid
= (cu
->header
.version
>= 4);
10433 low_default_is_valid
= 0;
10437 /* FIXME: For variable sized arrays either of these could be
10438 a variable rather than a constant value. We'll allow it,
10439 but we don't know how to handle it. */
10440 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10442 low
= dwarf2_get_attr_constant_value (attr
, low
);
10443 else if (!low_default_is_valid
)
10444 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10445 "- DIE at 0x%x [in module %s]"),
10446 die
->offset
.sect_off
, cu
->objfile
->name
);
10448 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10451 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10453 /* GCC encodes arrays with unspecified or dynamic length
10454 with a DW_FORM_block1 attribute or a reference attribute.
10455 FIXME: GDB does not yet know how to handle dynamic
10456 arrays properly, treat them as arrays with unspecified
10459 FIXME: jimb/2003-09-22: GDB does not really know
10460 how to handle arrays of unspecified length
10461 either; we just represent them as zero-length
10462 arrays. Choose an appropriate upper bound given
10463 the lower bound we've computed above. */
10467 high
= dwarf2_get_attr_constant_value (attr
, 1);
10471 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10474 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10475 high
= low
+ count
- 1;
10479 /* Unspecified array length. */
10484 /* Dwarf-2 specifications explicitly allows to create subrange types
10485 without specifying a base type.
10486 In that case, the base type must be set to the type of
10487 the lower bound, upper bound or count, in that order, if any of these
10488 three attributes references an object that has a type.
10489 If no base type is found, the Dwarf-2 specifications say that
10490 a signed integer type of size equal to the size of an address should
10492 For the following C code: `extern char gdb_int [];'
10493 GCC produces an empty range DIE.
10494 FIXME: muller/2010-05-28: Possible references to object for low bound,
10495 high bound or count are not yet handled by this code. */
10496 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10498 struct objfile
*objfile
= cu
->objfile
;
10499 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10500 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10501 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10503 /* Test "int", "long int", and "long long int" objfile types,
10504 and select the first one having a size above or equal to the
10505 architecture address size. */
10506 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10507 base_type
= int_type
;
10510 int_type
= objfile_type (objfile
)->builtin_long
;
10511 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10512 base_type
= int_type
;
10515 int_type
= objfile_type (objfile
)->builtin_long_long
;
10516 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10517 base_type
= int_type
;
10523 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10524 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10525 low
|= negative_mask
;
10526 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10527 high
|= negative_mask
;
10529 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10531 /* Mark arrays with dynamic length at least as an array of unspecified
10532 length. GDB could check the boundary but before it gets implemented at
10533 least allow accessing the array elements. */
10534 if (attr
&& attr_form_is_block (attr
))
10535 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10537 /* Ada expects an empty array on no boundary attributes. */
10538 if (attr
== NULL
&& cu
->language
!= language_ada
)
10539 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10541 name
= dwarf2_name (die
, cu
);
10543 TYPE_NAME (range_type
) = name
;
10545 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10547 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10549 set_die_type (die
, range_type
, cu
);
10551 /* set_die_type should be already done. */
10552 set_descriptive_type (range_type
, die
, cu
);
10557 static struct type
*
10558 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10562 /* For now, we only support the C meaning of an unspecified type: void. */
10564 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10565 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10567 return set_die_type (die
, type
, cu
);
10570 /* Read a single die and all its descendents. Set the die's sibling
10571 field to NULL; set other fields in the die correctly, and set all
10572 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10573 location of the info_ptr after reading all of those dies. PARENT
10574 is the parent of the die in question. */
10576 static struct die_info
*
10577 read_die_and_children (const struct die_reader_specs
*reader
,
10578 gdb_byte
*info_ptr
,
10579 gdb_byte
**new_info_ptr
,
10580 struct die_info
*parent
)
10582 struct die_info
*die
;
10586 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10589 *new_info_ptr
= cur_ptr
;
10592 store_in_ref_table (die
, reader
->cu
);
10595 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10599 *new_info_ptr
= cur_ptr
;
10602 die
->sibling
= NULL
;
10603 die
->parent
= parent
;
10607 /* Read a die, all of its descendents, and all of its siblings; set
10608 all of the fields of all of the dies correctly. Arguments are as
10609 in read_die_and_children. */
10611 static struct die_info
*
10612 read_die_and_siblings (const struct die_reader_specs
*reader
,
10613 gdb_byte
*info_ptr
,
10614 gdb_byte
**new_info_ptr
,
10615 struct die_info
*parent
)
10617 struct die_info
*first_die
, *last_sibling
;
10620 cur_ptr
= info_ptr
;
10621 first_die
= last_sibling
= NULL
;
10625 struct die_info
*die
10626 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10630 *new_info_ptr
= cur_ptr
;
10637 last_sibling
->sibling
= die
;
10639 last_sibling
= die
;
10643 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10645 The caller is responsible for filling in the extra attributes
10646 and updating (*DIEP)->num_attrs.
10647 Set DIEP to point to a newly allocated die with its information,
10648 except for its child, sibling, and parent fields.
10649 Set HAS_CHILDREN to tell whether the die has children or not. */
10652 read_full_die_1 (const struct die_reader_specs
*reader
,
10653 struct die_info
**diep
, gdb_byte
*info_ptr
,
10654 int *has_children
, int num_extra_attrs
)
10656 unsigned int abbrev_number
, bytes_read
, i
;
10657 sect_offset offset
;
10658 struct abbrev_info
*abbrev
;
10659 struct die_info
*die
;
10660 struct dwarf2_cu
*cu
= reader
->cu
;
10661 bfd
*abfd
= reader
->abfd
;
10663 offset
.sect_off
= info_ptr
- reader
->buffer
;
10664 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10665 info_ptr
+= bytes_read
;
10666 if (!abbrev_number
)
10673 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10675 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10677 bfd_get_filename (abfd
));
10679 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10680 die
->offset
= offset
;
10681 die
->tag
= abbrev
->tag
;
10682 die
->abbrev
= abbrev_number
;
10684 /* Make the result usable.
10685 The caller needs to update num_attrs after adding the extra
10687 die
->num_attrs
= abbrev
->num_attrs
;
10689 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10690 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10694 *has_children
= abbrev
->has_children
;
10698 /* Read a die and all its attributes.
10699 Set DIEP to point to a newly allocated die with its information,
10700 except for its child, sibling, and parent fields.
10701 Set HAS_CHILDREN to tell whether the die has children or not. */
10704 read_full_die (const struct die_reader_specs
*reader
,
10705 struct die_info
**diep
, gdb_byte
*info_ptr
,
10708 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10711 /* In DWARF version 2, the description of the debugging information is
10712 stored in a separate .debug_abbrev section. Before we read any
10713 dies from a section we read in all abbreviations and install them
10714 in a hash table. This function also sets flags in CU describing
10715 the data found in the abbrev table. */
10718 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10719 struct dwarf2_section_info
*abbrev_section
)
10722 bfd
*abfd
= abbrev_section
->asection
->owner
;
10723 struct comp_unit_head
*cu_header
= &cu
->header
;
10724 gdb_byte
*abbrev_ptr
;
10725 struct abbrev_info
*cur_abbrev
;
10726 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10727 unsigned int abbrev_form
, hash_number
;
10728 struct attr_abbrev
*cur_attrs
;
10729 unsigned int allocated_attrs
;
10731 /* Initialize dwarf2 abbrevs. */
10732 obstack_init (&cu
->abbrev_obstack
);
10733 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10735 * sizeof (struct abbrev_info
*)));
10736 memset (cu
->dwarf2_abbrevs
, 0,
10737 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10739 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10740 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10741 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10742 abbrev_ptr
+= bytes_read
;
10744 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10745 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10747 /* Loop until we reach an abbrev number of 0. */
10748 while (abbrev_number
)
10750 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10752 /* read in abbrev header */
10753 cur_abbrev
->number
= abbrev_number
;
10754 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10755 abbrev_ptr
+= bytes_read
;
10756 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10759 /* now read in declarations */
10760 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10761 abbrev_ptr
+= bytes_read
;
10762 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10763 abbrev_ptr
+= bytes_read
;
10764 while (abbrev_name
)
10766 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10768 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10770 = xrealloc (cur_attrs
, (allocated_attrs
10771 * sizeof (struct attr_abbrev
)));
10774 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10775 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10776 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10777 abbrev_ptr
+= bytes_read
;
10778 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10779 abbrev_ptr
+= bytes_read
;
10782 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10783 (cur_abbrev
->num_attrs
10784 * sizeof (struct attr_abbrev
)));
10785 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10786 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10788 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10789 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10790 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10792 /* Get next abbreviation.
10793 Under Irix6 the abbreviations for a compilation unit are not
10794 always properly terminated with an abbrev number of 0.
10795 Exit loop if we encounter an abbreviation which we have
10796 already read (which means we are about to read the abbreviations
10797 for the next compile unit) or if the end of the abbreviation
10798 table is reached. */
10799 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10800 >= abbrev_section
->size
)
10802 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10803 abbrev_ptr
+= bytes_read
;
10804 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10811 /* Release the memory used by the abbrev table for a compilation unit. */
10814 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10816 struct dwarf2_cu
*cu
= ptr_to_cu
;
10818 obstack_free (&cu
->abbrev_obstack
, NULL
);
10819 cu
->dwarf2_abbrevs
= NULL
;
10822 /* Lookup an abbrev_info structure in the abbrev hash table. */
10824 static struct abbrev_info
*
10825 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
10827 unsigned int hash_number
;
10828 struct abbrev_info
*abbrev
;
10830 hash_number
= number
% ABBREV_HASH_SIZE
;
10831 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
10835 if (abbrev
->number
== number
)
10838 abbrev
= abbrev
->next
;
10843 /* Returns nonzero if TAG represents a type that we might generate a partial
10847 is_type_tag_for_partial (int tag
)
10852 /* Some types that would be reasonable to generate partial symbols for,
10853 that we don't at present. */
10854 case DW_TAG_array_type
:
10855 case DW_TAG_file_type
:
10856 case DW_TAG_ptr_to_member_type
:
10857 case DW_TAG_set_type
:
10858 case DW_TAG_string_type
:
10859 case DW_TAG_subroutine_type
:
10861 case DW_TAG_base_type
:
10862 case DW_TAG_class_type
:
10863 case DW_TAG_interface_type
:
10864 case DW_TAG_enumeration_type
:
10865 case DW_TAG_structure_type
:
10866 case DW_TAG_subrange_type
:
10867 case DW_TAG_typedef
:
10868 case DW_TAG_union_type
:
10875 /* Load all DIEs that are interesting for partial symbols into memory. */
10877 static struct partial_die_info
*
10878 load_partial_dies (const struct die_reader_specs
*reader
,
10879 gdb_byte
*info_ptr
, int building_psymtab
)
10881 struct dwarf2_cu
*cu
= reader
->cu
;
10882 struct objfile
*objfile
= cu
->objfile
;
10883 struct partial_die_info
*part_die
;
10884 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
10885 struct abbrev_info
*abbrev
;
10886 unsigned int bytes_read
;
10887 unsigned int load_all
= 0;
10888 int nesting_level
= 1;
10893 gdb_assert (cu
->per_cu
!= NULL
);
10894 if (cu
->per_cu
->load_all_dies
)
10898 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10902 &cu
->comp_unit_obstack
,
10903 hashtab_obstack_allocate
,
10904 dummy_obstack_deallocate
);
10906 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10907 sizeof (struct partial_die_info
));
10911 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
10913 /* A NULL abbrev means the end of a series of children. */
10914 if (abbrev
== NULL
)
10916 if (--nesting_level
== 0)
10918 /* PART_DIE was probably the last thing allocated on the
10919 comp_unit_obstack, so we could call obstack_free
10920 here. We don't do that because the waste is small,
10921 and will be cleaned up when we're done with this
10922 compilation unit. This way, we're also more robust
10923 against other users of the comp_unit_obstack. */
10926 info_ptr
+= bytes_read
;
10927 last_die
= parent_die
;
10928 parent_die
= parent_die
->die_parent
;
10932 /* Check for template arguments. We never save these; if
10933 they're seen, we just mark the parent, and go on our way. */
10934 if (parent_die
!= NULL
10935 && cu
->language
== language_cplus
10936 && (abbrev
->tag
== DW_TAG_template_type_param
10937 || abbrev
->tag
== DW_TAG_template_value_param
))
10939 parent_die
->has_template_arguments
= 1;
10943 /* We don't need a partial DIE for the template argument. */
10944 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10949 /* We only recurse into c++ subprograms looking for template arguments.
10950 Skip their other children. */
10952 && cu
->language
== language_cplus
10953 && parent_die
!= NULL
10954 && parent_die
->tag
== DW_TAG_subprogram
)
10956 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10960 /* Check whether this DIE is interesting enough to save. Normally
10961 we would not be interested in members here, but there may be
10962 later variables referencing them via DW_AT_specification (for
10963 static members). */
10965 && !is_type_tag_for_partial (abbrev
->tag
)
10966 && abbrev
->tag
!= DW_TAG_constant
10967 && abbrev
->tag
!= DW_TAG_enumerator
10968 && abbrev
->tag
!= DW_TAG_subprogram
10969 && abbrev
->tag
!= DW_TAG_lexical_block
10970 && abbrev
->tag
!= DW_TAG_variable
10971 && abbrev
->tag
!= DW_TAG_namespace
10972 && abbrev
->tag
!= DW_TAG_module
10973 && abbrev
->tag
!= DW_TAG_member
10974 && abbrev
->tag
!= DW_TAG_imported_unit
)
10976 /* Otherwise we skip to the next sibling, if any. */
10977 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10981 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
10984 /* This two-pass algorithm for processing partial symbols has a
10985 high cost in cache pressure. Thus, handle some simple cases
10986 here which cover the majority of C partial symbols. DIEs
10987 which neither have specification tags in them, nor could have
10988 specification tags elsewhere pointing at them, can simply be
10989 processed and discarded.
10991 This segment is also optional; scan_partial_symbols and
10992 add_partial_symbol will handle these DIEs if we chain
10993 them in normally. When compilers which do not emit large
10994 quantities of duplicate debug information are more common,
10995 this code can probably be removed. */
10997 /* Any complete simple types at the top level (pretty much all
10998 of them, for a language without namespaces), can be processed
11000 if (parent_die
== NULL
11001 && part_die
->has_specification
== 0
11002 && part_die
->is_declaration
== 0
11003 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11004 || part_die
->tag
== DW_TAG_base_type
11005 || part_die
->tag
== DW_TAG_subrange_type
))
11007 if (building_psymtab
&& part_die
->name
!= NULL
)
11008 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11009 VAR_DOMAIN
, LOC_TYPEDEF
,
11010 &objfile
->static_psymbols
,
11011 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11012 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11016 /* The exception for DW_TAG_typedef with has_children above is
11017 a workaround of GCC PR debug/47510. In the case of this complaint
11018 type_name_no_tag_or_error will error on such types later.
11020 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11021 it could not find the child DIEs referenced later, this is checked
11022 above. In correct DWARF DW_TAG_typedef should have no children. */
11024 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11025 complaint (&symfile_complaints
,
11026 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11027 "- DIE at 0x%x [in module %s]"),
11028 part_die
->offset
.sect_off
, objfile
->name
);
11030 /* If we're at the second level, and we're an enumerator, and
11031 our parent has no specification (meaning possibly lives in a
11032 namespace elsewhere), then we can add the partial symbol now
11033 instead of queueing it. */
11034 if (part_die
->tag
== DW_TAG_enumerator
11035 && parent_die
!= NULL
11036 && parent_die
->die_parent
== NULL
11037 && parent_die
->tag
== DW_TAG_enumeration_type
11038 && parent_die
->has_specification
== 0)
11040 if (part_die
->name
== NULL
)
11041 complaint (&symfile_complaints
,
11042 _("malformed enumerator DIE ignored"));
11043 else if (building_psymtab
)
11044 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11045 VAR_DOMAIN
, LOC_CONST
,
11046 (cu
->language
== language_cplus
11047 || cu
->language
== language_java
)
11048 ? &objfile
->global_psymbols
11049 : &objfile
->static_psymbols
,
11050 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11052 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11056 /* We'll save this DIE so link it in. */
11057 part_die
->die_parent
= parent_die
;
11058 part_die
->die_sibling
= NULL
;
11059 part_die
->die_child
= NULL
;
11061 if (last_die
&& last_die
== parent_die
)
11062 last_die
->die_child
= part_die
;
11064 last_die
->die_sibling
= part_die
;
11066 last_die
= part_die
;
11068 if (first_die
== NULL
)
11069 first_die
= part_die
;
11071 /* Maybe add the DIE to the hash table. Not all DIEs that we
11072 find interesting need to be in the hash table, because we
11073 also have the parent/sibling/child chains; only those that we
11074 might refer to by offset later during partial symbol reading.
11076 For now this means things that might have be the target of a
11077 DW_AT_specification, DW_AT_abstract_origin, or
11078 DW_AT_extension. DW_AT_extension will refer only to
11079 namespaces; DW_AT_abstract_origin refers to functions (and
11080 many things under the function DIE, but we do not recurse
11081 into function DIEs during partial symbol reading) and
11082 possibly variables as well; DW_AT_specification refers to
11083 declarations. Declarations ought to have the DW_AT_declaration
11084 flag. It happens that GCC forgets to put it in sometimes, but
11085 only for functions, not for types.
11087 Adding more things than necessary to the hash table is harmless
11088 except for the performance cost. Adding too few will result in
11089 wasted time in find_partial_die, when we reread the compilation
11090 unit with load_all_dies set. */
11093 || abbrev
->tag
== DW_TAG_constant
11094 || abbrev
->tag
== DW_TAG_subprogram
11095 || abbrev
->tag
== DW_TAG_variable
11096 || abbrev
->tag
== DW_TAG_namespace
11097 || part_die
->is_declaration
)
11101 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11102 part_die
->offset
.sect_off
, INSERT
);
11106 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11107 sizeof (struct partial_die_info
));
11109 /* For some DIEs we want to follow their children (if any). For C
11110 we have no reason to follow the children of structures; for other
11111 languages we have to, so that we can get at method physnames
11112 to infer fully qualified class names, for DW_AT_specification,
11113 and for C++ template arguments. For C++, we also look one level
11114 inside functions to find template arguments (if the name of the
11115 function does not already contain the template arguments).
11117 For Ada, we need to scan the children of subprograms and lexical
11118 blocks as well because Ada allows the definition of nested
11119 entities that could be interesting for the debugger, such as
11120 nested subprograms for instance. */
11121 if (last_die
->has_children
11123 || last_die
->tag
== DW_TAG_namespace
11124 || last_die
->tag
== DW_TAG_module
11125 || last_die
->tag
== DW_TAG_enumeration_type
11126 || (cu
->language
== language_cplus
11127 && last_die
->tag
== DW_TAG_subprogram
11128 && (last_die
->name
== NULL
11129 || strchr (last_die
->name
, '<') == NULL
))
11130 || (cu
->language
!= language_c
11131 && (last_die
->tag
== DW_TAG_class_type
11132 || last_die
->tag
== DW_TAG_interface_type
11133 || last_die
->tag
== DW_TAG_structure_type
11134 || last_die
->tag
== DW_TAG_union_type
))
11135 || (cu
->language
== language_ada
11136 && (last_die
->tag
== DW_TAG_subprogram
11137 || last_die
->tag
== DW_TAG_lexical_block
))))
11140 parent_die
= last_die
;
11144 /* Otherwise we skip to the next sibling, if any. */
11145 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11147 /* Back to the top, do it again. */
11151 /* Read a minimal amount of information into the minimal die structure. */
11154 read_partial_die (const struct die_reader_specs
*reader
,
11155 struct partial_die_info
*part_die
,
11156 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11157 gdb_byte
*info_ptr
)
11159 struct dwarf2_cu
*cu
= reader
->cu
;
11160 struct objfile
*objfile
= cu
->objfile
;
11161 gdb_byte
*buffer
= reader
->buffer
;
11163 struct attribute attr
;
11164 int has_low_pc_attr
= 0;
11165 int has_high_pc_attr
= 0;
11166 int high_pc_relative
= 0;
11168 memset (part_die
, 0, sizeof (struct partial_die_info
));
11170 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11172 info_ptr
+= abbrev_len
;
11174 if (abbrev
== NULL
)
11177 part_die
->tag
= abbrev
->tag
;
11178 part_die
->has_children
= abbrev
->has_children
;
11180 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11182 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11184 /* Store the data if it is of an attribute we want to keep in a
11185 partial symbol table. */
11189 switch (part_die
->tag
)
11191 case DW_TAG_compile_unit
:
11192 case DW_TAG_partial_unit
:
11193 case DW_TAG_type_unit
:
11194 /* Compilation units have a DW_AT_name that is a filename, not
11195 a source language identifier. */
11196 case DW_TAG_enumeration_type
:
11197 case DW_TAG_enumerator
:
11198 /* These tags always have simple identifiers already; no need
11199 to canonicalize them. */
11200 part_die
->name
= DW_STRING (&attr
);
11204 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11205 &objfile
->objfile_obstack
);
11209 case DW_AT_linkage_name
:
11210 case DW_AT_MIPS_linkage_name
:
11211 /* Note that both forms of linkage name might appear. We
11212 assume they will be the same, and we only store the last
11214 if (cu
->language
== language_ada
)
11215 part_die
->name
= DW_STRING (&attr
);
11216 part_die
->linkage_name
= DW_STRING (&attr
);
11219 has_low_pc_attr
= 1;
11220 part_die
->lowpc
= DW_ADDR (&attr
);
11222 case DW_AT_high_pc
:
11223 has_high_pc_attr
= 1;
11224 if (attr
.form
== DW_FORM_addr
11225 || attr
.form
== DW_FORM_GNU_addr_index
)
11226 part_die
->highpc
= DW_ADDR (&attr
);
11229 high_pc_relative
= 1;
11230 part_die
->highpc
= DW_UNSND (&attr
);
11233 case DW_AT_location
:
11234 /* Support the .debug_loc offsets. */
11235 if (attr_form_is_block (&attr
))
11237 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11239 else if (attr_form_is_section_offset (&attr
))
11241 dwarf2_complex_location_expr_complaint ();
11245 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11246 "partial symbol information");
11249 case DW_AT_external
:
11250 part_die
->is_external
= DW_UNSND (&attr
);
11252 case DW_AT_declaration
:
11253 part_die
->is_declaration
= DW_UNSND (&attr
);
11256 part_die
->has_type
= 1;
11258 case DW_AT_abstract_origin
:
11259 case DW_AT_specification
:
11260 case DW_AT_extension
:
11261 part_die
->has_specification
= 1;
11262 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11264 case DW_AT_sibling
:
11265 /* Ignore absolute siblings, they might point outside of
11266 the current compile unit. */
11267 if (attr
.form
== DW_FORM_ref_addr
)
11268 complaint (&symfile_complaints
,
11269 _("ignoring absolute DW_AT_sibling"));
11271 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11273 case DW_AT_byte_size
:
11274 part_die
->has_byte_size
= 1;
11276 case DW_AT_calling_convention
:
11277 /* DWARF doesn't provide a way to identify a program's source-level
11278 entry point. DW_AT_calling_convention attributes are only meant
11279 to describe functions' calling conventions.
11281 However, because it's a necessary piece of information in
11282 Fortran, and because DW_CC_program is the only piece of debugging
11283 information whose definition refers to a 'main program' at all,
11284 several compilers have begun marking Fortran main programs with
11285 DW_CC_program --- even when those functions use the standard
11286 calling conventions.
11288 So until DWARF specifies a way to provide this information and
11289 compilers pick up the new representation, we'll support this
11291 if (DW_UNSND (&attr
) == DW_CC_program
11292 && cu
->language
== language_fortran
)
11294 set_main_name (part_die
->name
);
11296 /* As this DIE has a static linkage the name would be difficult
11297 to look up later. */
11298 language_of_main
= language_fortran
;
11302 if (DW_UNSND (&attr
) == DW_INL_inlined
11303 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11304 part_die
->may_be_inlined
= 1;
11308 if (part_die
->tag
== DW_TAG_imported_unit
)
11309 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11317 if (high_pc_relative
)
11318 part_die
->highpc
+= part_die
->lowpc
;
11320 if (has_low_pc_attr
&& has_high_pc_attr
)
11322 /* When using the GNU linker, .gnu.linkonce. sections are used to
11323 eliminate duplicate copies of functions and vtables and such.
11324 The linker will arbitrarily choose one and discard the others.
11325 The AT_*_pc values for such functions refer to local labels in
11326 these sections. If the section from that file was discarded, the
11327 labels are not in the output, so the relocs get a value of 0.
11328 If this is a discarded function, mark the pc bounds as invalid,
11329 so that GDB will ignore it. */
11330 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11332 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11334 complaint (&symfile_complaints
,
11335 _("DW_AT_low_pc %s is zero "
11336 "for DIE at 0x%x [in module %s]"),
11337 paddress (gdbarch
, part_die
->lowpc
),
11338 part_die
->offset
.sect_off
, objfile
->name
);
11340 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11341 else if (part_die
->lowpc
>= part_die
->highpc
)
11343 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11345 complaint (&symfile_complaints
,
11346 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11347 "for DIE at 0x%x [in module %s]"),
11348 paddress (gdbarch
, part_die
->lowpc
),
11349 paddress (gdbarch
, part_die
->highpc
),
11350 part_die
->offset
.sect_off
, objfile
->name
);
11353 part_die
->has_pc_info
= 1;
11359 /* Find a cached partial DIE at OFFSET in CU. */
11361 static struct partial_die_info
*
11362 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11364 struct partial_die_info
*lookup_die
= NULL
;
11365 struct partial_die_info part_die
;
11367 part_die
.offset
= offset
;
11368 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11374 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11375 except in the case of .debug_types DIEs which do not reference
11376 outside their CU (they do however referencing other types via
11377 DW_FORM_ref_sig8). */
11379 static struct partial_die_info
*
11380 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11382 struct objfile
*objfile
= cu
->objfile
;
11383 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11384 struct partial_die_info
*pd
= NULL
;
11386 if (offset_in_cu_p (&cu
->header
, offset
))
11388 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11391 /* We missed recording what we needed.
11392 Load all dies and try again. */
11393 per_cu
= cu
->per_cu
;
11397 /* TUs don't reference other CUs/TUs (except via type signatures). */
11398 if (cu
->per_cu
->is_debug_types
)
11400 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11401 " external reference to offset 0x%lx [in module %s].\n"),
11402 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11403 bfd_get_filename (objfile
->obfd
));
11405 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11407 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11408 load_partial_comp_unit (per_cu
);
11410 per_cu
->cu
->last_used
= 0;
11411 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11414 /* If we didn't find it, and not all dies have been loaded,
11415 load them all and try again. */
11417 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11419 per_cu
->load_all_dies
= 1;
11421 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11422 THIS_CU->cu may already be in use. So we can't just free it and
11423 replace its DIEs with the ones we read in. Instead, we leave those
11424 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11425 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11427 load_partial_comp_unit (per_cu
);
11429 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11433 internal_error (__FILE__
, __LINE__
,
11434 _("could not find partial DIE 0x%x "
11435 "in cache [from module %s]\n"),
11436 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11440 /* See if we can figure out if the class lives in a namespace. We do
11441 this by looking for a member function; its demangled name will
11442 contain namespace info, if there is any. */
11445 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11446 struct dwarf2_cu
*cu
)
11448 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11449 what template types look like, because the demangler
11450 frequently doesn't give the same name as the debug info. We
11451 could fix this by only using the demangled name to get the
11452 prefix (but see comment in read_structure_type). */
11454 struct partial_die_info
*real_pdi
;
11455 struct partial_die_info
*child_pdi
;
11457 /* If this DIE (this DIE's specification, if any) has a parent, then
11458 we should not do this. We'll prepend the parent's fully qualified
11459 name when we create the partial symbol. */
11461 real_pdi
= struct_pdi
;
11462 while (real_pdi
->has_specification
)
11463 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11465 if (real_pdi
->die_parent
!= NULL
)
11468 for (child_pdi
= struct_pdi
->die_child
;
11470 child_pdi
= child_pdi
->die_sibling
)
11472 if (child_pdi
->tag
== DW_TAG_subprogram
11473 && child_pdi
->linkage_name
!= NULL
)
11475 char *actual_class_name
11476 = language_class_name_from_physname (cu
->language_defn
,
11477 child_pdi
->linkage_name
);
11478 if (actual_class_name
!= NULL
)
11481 = obsavestring (actual_class_name
,
11482 strlen (actual_class_name
),
11483 &cu
->objfile
->objfile_obstack
);
11484 xfree (actual_class_name
);
11491 /* Adjust PART_DIE before generating a symbol for it. This function
11492 may set the is_external flag or change the DIE's name. */
11495 fixup_partial_die (struct partial_die_info
*part_die
,
11496 struct dwarf2_cu
*cu
)
11498 /* Once we've fixed up a die, there's no point in doing so again.
11499 This also avoids a memory leak if we were to call
11500 guess_partial_die_structure_name multiple times. */
11501 if (part_die
->fixup_called
)
11504 /* If we found a reference attribute and the DIE has no name, try
11505 to find a name in the referred to DIE. */
11507 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11509 struct partial_die_info
*spec_die
;
11511 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11513 fixup_partial_die (spec_die
, cu
);
11515 if (spec_die
->name
)
11517 part_die
->name
= spec_die
->name
;
11519 /* Copy DW_AT_external attribute if it is set. */
11520 if (spec_die
->is_external
)
11521 part_die
->is_external
= spec_die
->is_external
;
11525 /* Set default names for some unnamed DIEs. */
11527 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11528 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11530 /* If there is no parent die to provide a namespace, and there are
11531 children, see if we can determine the namespace from their linkage
11533 if (cu
->language
== language_cplus
11534 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11535 && part_die
->die_parent
== NULL
11536 && part_die
->has_children
11537 && (part_die
->tag
== DW_TAG_class_type
11538 || part_die
->tag
== DW_TAG_structure_type
11539 || part_die
->tag
== DW_TAG_union_type
))
11540 guess_partial_die_structure_name (part_die
, cu
);
11542 /* GCC might emit a nameless struct or union that has a linkage
11543 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11544 if (part_die
->name
== NULL
11545 && (part_die
->tag
== DW_TAG_class_type
11546 || part_die
->tag
== DW_TAG_interface_type
11547 || part_die
->tag
== DW_TAG_structure_type
11548 || part_die
->tag
== DW_TAG_union_type
)
11549 && part_die
->linkage_name
!= NULL
)
11553 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11558 /* Strip any leading namespaces/classes, keep only the base name.
11559 DW_AT_name for named DIEs does not contain the prefixes. */
11560 base
= strrchr (demangled
, ':');
11561 if (base
&& base
> demangled
&& base
[-1] == ':')
11566 part_die
->name
= obsavestring (base
, strlen (base
),
11567 &cu
->objfile
->objfile_obstack
);
11572 part_die
->fixup_called
= 1;
11575 /* Read an attribute value described by an attribute form. */
11578 read_attribute_value (const struct die_reader_specs
*reader
,
11579 struct attribute
*attr
, unsigned form
,
11580 gdb_byte
*info_ptr
)
11582 struct dwarf2_cu
*cu
= reader
->cu
;
11583 bfd
*abfd
= reader
->abfd
;
11584 struct comp_unit_head
*cu_header
= &cu
->header
;
11585 unsigned int bytes_read
;
11586 struct dwarf_block
*blk
;
11591 case DW_FORM_ref_addr
:
11592 if (cu
->header
.version
== 2)
11593 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11595 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11596 &cu
->header
, &bytes_read
);
11597 info_ptr
+= bytes_read
;
11600 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11601 info_ptr
+= bytes_read
;
11603 case DW_FORM_block2
:
11604 blk
= dwarf_alloc_block (cu
);
11605 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11607 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11608 info_ptr
+= blk
->size
;
11609 DW_BLOCK (attr
) = blk
;
11611 case DW_FORM_block4
:
11612 blk
= dwarf_alloc_block (cu
);
11613 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11615 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11616 info_ptr
+= blk
->size
;
11617 DW_BLOCK (attr
) = blk
;
11619 case DW_FORM_data2
:
11620 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11623 case DW_FORM_data4
:
11624 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11627 case DW_FORM_data8
:
11628 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11631 case DW_FORM_sec_offset
:
11632 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11633 info_ptr
+= bytes_read
;
11635 case DW_FORM_string
:
11636 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11637 DW_STRING_IS_CANONICAL (attr
) = 0;
11638 info_ptr
+= bytes_read
;
11641 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11643 DW_STRING_IS_CANONICAL (attr
) = 0;
11644 info_ptr
+= bytes_read
;
11646 case DW_FORM_exprloc
:
11647 case DW_FORM_block
:
11648 blk
= dwarf_alloc_block (cu
);
11649 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11650 info_ptr
+= bytes_read
;
11651 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11652 info_ptr
+= blk
->size
;
11653 DW_BLOCK (attr
) = blk
;
11655 case DW_FORM_block1
:
11656 blk
= dwarf_alloc_block (cu
);
11657 blk
->size
= read_1_byte (abfd
, info_ptr
);
11659 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11660 info_ptr
+= blk
->size
;
11661 DW_BLOCK (attr
) = blk
;
11663 case DW_FORM_data1
:
11664 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11668 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11671 case DW_FORM_flag_present
:
11672 DW_UNSND (attr
) = 1;
11674 case DW_FORM_sdata
:
11675 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11676 info_ptr
+= bytes_read
;
11678 case DW_FORM_udata
:
11679 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11680 info_ptr
+= bytes_read
;
11683 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11684 + read_1_byte (abfd
, info_ptr
));
11688 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11689 + read_2_bytes (abfd
, info_ptr
));
11693 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11694 + read_4_bytes (abfd
, info_ptr
));
11698 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11699 + read_8_bytes (abfd
, info_ptr
));
11702 case DW_FORM_ref_sig8
:
11703 /* Convert the signature to something we can record in DW_UNSND
11705 NOTE: This is NULL if the type wasn't found. */
11706 DW_SIGNATURED_TYPE (attr
) =
11707 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11710 case DW_FORM_ref_udata
:
11711 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11712 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11713 info_ptr
+= bytes_read
;
11715 case DW_FORM_indirect
:
11716 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11717 info_ptr
+= bytes_read
;
11718 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11720 case DW_FORM_GNU_addr_index
:
11721 if (reader
->dwo_file
== NULL
)
11723 /* For now flag a hard error.
11724 Later we can turn this into a complaint. */
11725 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11726 dwarf_form_name (form
),
11727 bfd_get_filename (abfd
));
11729 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11730 info_ptr
+= bytes_read
;
11732 case DW_FORM_GNU_str_index
:
11733 if (reader
->dwo_file
== NULL
)
11735 /* For now flag a hard error.
11736 Later we can turn this into a complaint if warranted. */
11737 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11738 dwarf_form_name (form
),
11739 bfd_get_filename (abfd
));
11742 ULONGEST str_index
=
11743 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11745 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11746 DW_STRING_IS_CANONICAL (attr
) = 0;
11747 info_ptr
+= bytes_read
;
11751 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11752 dwarf_form_name (form
),
11753 bfd_get_filename (abfd
));
11756 /* We have seen instances where the compiler tried to emit a byte
11757 size attribute of -1 which ended up being encoded as an unsigned
11758 0xffffffff. Although 0xffffffff is technically a valid size value,
11759 an object of this size seems pretty unlikely so we can relatively
11760 safely treat these cases as if the size attribute was invalid and
11761 treat them as zero by default. */
11762 if (attr
->name
== DW_AT_byte_size
11763 && form
== DW_FORM_data4
11764 && DW_UNSND (attr
) >= 0xffffffff)
11767 (&symfile_complaints
,
11768 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11769 hex_string (DW_UNSND (attr
)));
11770 DW_UNSND (attr
) = 0;
11776 /* Read an attribute described by an abbreviated attribute. */
11779 read_attribute (const struct die_reader_specs
*reader
,
11780 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11781 gdb_byte
*info_ptr
)
11783 attr
->name
= abbrev
->name
;
11784 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11787 /* Read dwarf information from a buffer. */
11789 static unsigned int
11790 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11792 return bfd_get_8 (abfd
, buf
);
11796 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11798 return bfd_get_signed_8 (abfd
, buf
);
11801 static unsigned int
11802 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11804 return bfd_get_16 (abfd
, buf
);
11808 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11810 return bfd_get_signed_16 (abfd
, buf
);
11813 static unsigned int
11814 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11816 return bfd_get_32 (abfd
, buf
);
11820 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11822 return bfd_get_signed_32 (abfd
, buf
);
11826 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
11828 return bfd_get_64 (abfd
, buf
);
11832 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
11833 unsigned int *bytes_read
)
11835 struct comp_unit_head
*cu_header
= &cu
->header
;
11836 CORE_ADDR retval
= 0;
11838 if (cu_header
->signed_addr_p
)
11840 switch (cu_header
->addr_size
)
11843 retval
= bfd_get_signed_16 (abfd
, buf
);
11846 retval
= bfd_get_signed_32 (abfd
, buf
);
11849 retval
= bfd_get_signed_64 (abfd
, buf
);
11852 internal_error (__FILE__
, __LINE__
,
11853 _("read_address: bad switch, signed [in module %s]"),
11854 bfd_get_filename (abfd
));
11859 switch (cu_header
->addr_size
)
11862 retval
= bfd_get_16 (abfd
, buf
);
11865 retval
= bfd_get_32 (abfd
, buf
);
11868 retval
= bfd_get_64 (abfd
, buf
);
11871 internal_error (__FILE__
, __LINE__
,
11872 _("read_address: bad switch, "
11873 "unsigned [in module %s]"),
11874 bfd_get_filename (abfd
));
11878 *bytes_read
= cu_header
->addr_size
;
11882 /* Read the initial length from a section. The (draft) DWARF 3
11883 specification allows the initial length to take up either 4 bytes
11884 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
11885 bytes describe the length and all offsets will be 8 bytes in length
11888 An older, non-standard 64-bit format is also handled by this
11889 function. The older format in question stores the initial length
11890 as an 8-byte quantity without an escape value. Lengths greater
11891 than 2^32 aren't very common which means that the initial 4 bytes
11892 is almost always zero. Since a length value of zero doesn't make
11893 sense for the 32-bit format, this initial zero can be considered to
11894 be an escape value which indicates the presence of the older 64-bit
11895 format. As written, the code can't detect (old format) lengths
11896 greater than 4GB. If it becomes necessary to handle lengths
11897 somewhat larger than 4GB, we could allow other small values (such
11898 as the non-sensical values of 1, 2, and 3) to also be used as
11899 escape values indicating the presence of the old format.
11901 The value returned via bytes_read should be used to increment the
11902 relevant pointer after calling read_initial_length().
11904 [ Note: read_initial_length() and read_offset() are based on the
11905 document entitled "DWARF Debugging Information Format", revision
11906 3, draft 8, dated November 19, 2001. This document was obtained
11909 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
11911 This document is only a draft and is subject to change. (So beware.)
11913 Details regarding the older, non-standard 64-bit format were
11914 determined empirically by examining 64-bit ELF files produced by
11915 the SGI toolchain on an IRIX 6.5 machine.
11917 - Kevin, July 16, 2002
11921 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
11923 LONGEST length
= bfd_get_32 (abfd
, buf
);
11925 if (length
== 0xffffffff)
11927 length
= bfd_get_64 (abfd
, buf
+ 4);
11930 else if (length
== 0)
11932 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
11933 length
= bfd_get_64 (abfd
, buf
);
11944 /* Cover function for read_initial_length.
11945 Returns the length of the object at BUF, and stores the size of the
11946 initial length in *BYTES_READ and stores the size that offsets will be in
11948 If the initial length size is not equivalent to that specified in
11949 CU_HEADER then issue a complaint.
11950 This is useful when reading non-comp-unit headers. */
11953 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
11954 const struct comp_unit_head
*cu_header
,
11955 unsigned int *bytes_read
,
11956 unsigned int *offset_size
)
11958 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
11960 gdb_assert (cu_header
->initial_length_size
== 4
11961 || cu_header
->initial_length_size
== 8
11962 || cu_header
->initial_length_size
== 12);
11964 if (cu_header
->initial_length_size
!= *bytes_read
)
11965 complaint (&symfile_complaints
,
11966 _("intermixed 32-bit and 64-bit DWARF sections"));
11968 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
11972 /* Read an offset from the data stream. The size of the offset is
11973 given by cu_header->offset_size. */
11976 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
11977 unsigned int *bytes_read
)
11979 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
11981 *bytes_read
= cu_header
->offset_size
;
11985 /* Read an offset from the data stream. */
11988 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
11990 LONGEST retval
= 0;
11992 switch (offset_size
)
11995 retval
= bfd_get_32 (abfd
, buf
);
11998 retval
= bfd_get_64 (abfd
, buf
);
12001 internal_error (__FILE__
, __LINE__
,
12002 _("read_offset_1: bad switch [in module %s]"),
12003 bfd_get_filename (abfd
));
12010 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12012 /* If the size of a host char is 8 bits, we can return a pointer
12013 to the buffer, otherwise we have to copy the data to a buffer
12014 allocated on the temporary obstack. */
12015 gdb_assert (HOST_CHAR_BIT
== 8);
12020 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12022 /* If the size of a host char is 8 bits, we can return a pointer
12023 to the string, otherwise we have to copy the string to a buffer
12024 allocated on the temporary obstack. */
12025 gdb_assert (HOST_CHAR_BIT
== 8);
12028 *bytes_read_ptr
= 1;
12031 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12032 return (char *) buf
;
12036 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12038 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12039 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12040 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12041 bfd_get_filename (abfd
));
12042 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12043 error (_("DW_FORM_strp pointing outside of "
12044 ".debug_str section [in module %s]"),
12045 bfd_get_filename (abfd
));
12046 gdb_assert (HOST_CHAR_BIT
== 8);
12047 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12049 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12053 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12054 const struct comp_unit_head
*cu_header
,
12055 unsigned int *bytes_read_ptr
)
12057 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12059 return read_indirect_string_at_offset (abfd
, str_offset
);
12063 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12066 unsigned int num_read
;
12068 unsigned char byte
;
12076 byte
= bfd_get_8 (abfd
, buf
);
12079 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12080 if ((byte
& 128) == 0)
12086 *bytes_read_ptr
= num_read
;
12091 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12094 int i
, shift
, num_read
;
12095 unsigned char byte
;
12103 byte
= bfd_get_8 (abfd
, buf
);
12106 result
|= ((LONGEST
) (byte
& 127) << shift
);
12108 if ((byte
& 128) == 0)
12113 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12114 result
|= -(((LONGEST
) 1) << shift
);
12115 *bytes_read_ptr
= num_read
;
12119 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12120 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12121 ADDR_SIZE is the size of addresses from the CU header. */
12124 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12126 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12127 bfd
*abfd
= objfile
->obfd
;
12128 const gdb_byte
*info_ptr
;
12130 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12131 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12132 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12134 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12135 error (_("DW_FORM_addr_index pointing outside of "
12136 ".debug_addr section [in module %s]"),
12138 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12139 + addr_base
+ addr_index
* addr_size
);
12140 if (addr_size
== 4)
12141 return bfd_get_32 (abfd
, info_ptr
);
12143 return bfd_get_64 (abfd
, info_ptr
);
12146 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12149 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12151 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12154 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12157 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12158 unsigned int *bytes_read
)
12160 bfd
*abfd
= cu
->objfile
->obfd
;
12161 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12163 return read_addr_index (cu
, addr_index
);
12166 /* Data structure to pass results from dwarf2_read_addr_index_reader
12167 back to dwarf2_read_addr_index. */
12169 struct dwarf2_read_addr_index_data
12171 ULONGEST addr_base
;
12175 /* die_reader_func for dwarf2_read_addr_index. */
12178 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12179 gdb_byte
*info_ptr
,
12180 struct die_info
*comp_unit_die
,
12184 struct dwarf2_cu
*cu
= reader
->cu
;
12185 struct dwarf2_read_addr_index_data
*aidata
=
12186 (struct dwarf2_read_addr_index_data
*) data
;
12188 aidata
->addr_base
= cu
->addr_base
;
12189 aidata
->addr_size
= cu
->header
.addr_size
;
12192 /* Given an index in .debug_addr, fetch the value.
12193 NOTE: This can be called during dwarf expression evaluation,
12194 long after the debug information has been read, and thus per_cu->cu
12195 may no longer exist. */
12198 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12199 unsigned int addr_index
)
12201 struct objfile
*objfile
= per_cu
->objfile
;
12202 struct dwarf2_cu
*cu
= per_cu
->cu
;
12203 ULONGEST addr_base
;
12206 /* This is intended to be called from outside this file. */
12207 dw2_setup (objfile
);
12209 /* We need addr_base and addr_size.
12210 If we don't have PER_CU->cu, we have to get it.
12211 Nasty, but the alternative is storing the needed info in PER_CU,
12212 which at this point doesn't seem justified: it's not clear how frequently
12213 it would get used and it would increase the size of every PER_CU.
12214 Entry points like dwarf2_per_cu_addr_size do a similar thing
12215 so we're not in uncharted territory here.
12216 Alas we need to be a bit more complicated as addr_base is contained
12219 We don't need to read the entire CU(/TU).
12220 We just need the header and top level die.
12221 IWBN to use the aging mechanism to let us lazily later discard the CU.
12222 See however init_cutu_and_read_dies_simple. */
12226 addr_base
= cu
->addr_base
;
12227 addr_size
= cu
->header
.addr_size
;
12231 struct dwarf2_read_addr_index_data aidata
;
12233 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12235 addr_base
= aidata
.addr_base
;
12236 addr_size
= aidata
.addr_size
;
12239 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12242 /* Given a DW_AT_str_index, fetch the string. */
12245 read_str_index (const struct die_reader_specs
*reader
,
12246 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12248 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12249 const char *dwo_name
= objfile
->name
;
12250 bfd
*abfd
= objfile
->obfd
;
12251 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12252 gdb_byte
*info_ptr
;
12253 ULONGEST str_offset
;
12255 dwarf2_read_section (objfile
, §ions
->str
);
12256 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12257 if (sections
->str
.buffer
== NULL
)
12258 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12259 " in CU at offset 0x%lx [in module %s]"),
12260 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12261 if (sections
->str_offsets
.buffer
== NULL
)
12262 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12263 " in CU at offset 0x%lx [in module %s]"),
12264 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12265 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12266 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12267 " section in CU at offset 0x%lx [in module %s]"),
12268 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12269 info_ptr
= (sections
->str_offsets
.buffer
12270 + str_index
* cu
->header
.offset_size
);
12271 if (cu
->header
.offset_size
== 4)
12272 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12274 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12275 if (str_offset
>= sections
->str
.size
)
12276 error (_("Offset from DW_FORM_str_index pointing outside of"
12277 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12278 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12279 return (char *) (sections
->str
.buffer
+ str_offset
);
12282 /* Return the length of an LEB128 number in BUF. */
12285 leb128_size (const gdb_byte
*buf
)
12287 const gdb_byte
*begin
= buf
;
12293 if ((byte
& 128) == 0)
12294 return buf
- begin
;
12299 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12306 cu
->language
= language_c
;
12308 case DW_LANG_C_plus_plus
:
12309 cu
->language
= language_cplus
;
12312 cu
->language
= language_d
;
12314 case DW_LANG_Fortran77
:
12315 case DW_LANG_Fortran90
:
12316 case DW_LANG_Fortran95
:
12317 cu
->language
= language_fortran
;
12320 cu
->language
= language_go
;
12322 case DW_LANG_Mips_Assembler
:
12323 cu
->language
= language_asm
;
12326 cu
->language
= language_java
;
12328 case DW_LANG_Ada83
:
12329 case DW_LANG_Ada95
:
12330 cu
->language
= language_ada
;
12332 case DW_LANG_Modula2
:
12333 cu
->language
= language_m2
;
12335 case DW_LANG_Pascal83
:
12336 cu
->language
= language_pascal
;
12339 cu
->language
= language_objc
;
12341 case DW_LANG_Cobol74
:
12342 case DW_LANG_Cobol85
:
12344 cu
->language
= language_minimal
;
12347 cu
->language_defn
= language_def (cu
->language
);
12350 /* Return the named attribute or NULL if not there. */
12352 static struct attribute
*
12353 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12358 struct attribute
*spec
= NULL
;
12360 for (i
= 0; i
< die
->num_attrs
; ++i
)
12362 if (die
->attrs
[i
].name
== name
)
12363 return &die
->attrs
[i
];
12364 if (die
->attrs
[i
].name
== DW_AT_specification
12365 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12366 spec
= &die
->attrs
[i
];
12372 die
= follow_die_ref (die
, spec
, &cu
);
12378 /* Return the named attribute or NULL if not there,
12379 but do not follow DW_AT_specification, etc.
12380 This is for use in contexts where we're reading .debug_types dies.
12381 Following DW_AT_specification, DW_AT_abstract_origin will take us
12382 back up the chain, and we want to go down. */
12384 static struct attribute
*
12385 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12386 struct dwarf2_cu
*cu
)
12390 for (i
= 0; i
< die
->num_attrs
; ++i
)
12391 if (die
->attrs
[i
].name
== name
)
12392 return &die
->attrs
[i
];
12397 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12398 and holds a non-zero value. This function should only be used for
12399 DW_FORM_flag or DW_FORM_flag_present attributes. */
12402 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12404 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12406 return (attr
&& DW_UNSND (attr
));
12410 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12412 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12413 which value is non-zero. However, we have to be careful with
12414 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12415 (via dwarf2_flag_true_p) follows this attribute. So we may
12416 end up accidently finding a declaration attribute that belongs
12417 to a different DIE referenced by the specification attribute,
12418 even though the given DIE does not have a declaration attribute. */
12419 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12420 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12423 /* Return the die giving the specification for DIE, if there is
12424 one. *SPEC_CU is the CU containing DIE on input, and the CU
12425 containing the return value on output. If there is no
12426 specification, but there is an abstract origin, that is
12429 static struct die_info
*
12430 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12432 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12435 if (spec_attr
== NULL
)
12436 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12438 if (spec_attr
== NULL
)
12441 return follow_die_ref (die
, spec_attr
, spec_cu
);
12444 /* Free the line_header structure *LH, and any arrays and strings it
12446 NOTE: This is also used as a "cleanup" function. */
12449 free_line_header (struct line_header
*lh
)
12451 if (lh
->standard_opcode_lengths
)
12452 xfree (lh
->standard_opcode_lengths
);
12454 /* Remember that all the lh->file_names[i].name pointers are
12455 pointers into debug_line_buffer, and don't need to be freed. */
12456 if (lh
->file_names
)
12457 xfree (lh
->file_names
);
12459 /* Similarly for the include directory names. */
12460 if (lh
->include_dirs
)
12461 xfree (lh
->include_dirs
);
12466 /* Add an entry to LH's include directory table. */
12469 add_include_dir (struct line_header
*lh
, char *include_dir
)
12471 /* Grow the array if necessary. */
12472 if (lh
->include_dirs_size
== 0)
12474 lh
->include_dirs_size
= 1; /* for testing */
12475 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12476 * sizeof (*lh
->include_dirs
));
12478 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12480 lh
->include_dirs_size
*= 2;
12481 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12482 (lh
->include_dirs_size
12483 * sizeof (*lh
->include_dirs
)));
12486 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12489 /* Add an entry to LH's file name table. */
12492 add_file_name (struct line_header
*lh
,
12494 unsigned int dir_index
,
12495 unsigned int mod_time
,
12496 unsigned int length
)
12498 struct file_entry
*fe
;
12500 /* Grow the array if necessary. */
12501 if (lh
->file_names_size
== 0)
12503 lh
->file_names_size
= 1; /* for testing */
12504 lh
->file_names
= xmalloc (lh
->file_names_size
12505 * sizeof (*lh
->file_names
));
12507 else if (lh
->num_file_names
>= lh
->file_names_size
)
12509 lh
->file_names_size
*= 2;
12510 lh
->file_names
= xrealloc (lh
->file_names
,
12511 (lh
->file_names_size
12512 * sizeof (*lh
->file_names
)));
12515 fe
= &lh
->file_names
[lh
->num_file_names
++];
12517 fe
->dir_index
= dir_index
;
12518 fe
->mod_time
= mod_time
;
12519 fe
->length
= length
;
12520 fe
->included_p
= 0;
12524 /* Read the statement program header starting at OFFSET in
12525 .debug_line, or .debug_line.dwo. Return a pointer
12526 to a struct line_header, allocated using xmalloc.
12528 NOTE: the strings in the include directory and file name tables of
12529 the returned object point into the dwarf line section buffer,
12530 and must not be freed. */
12532 static struct line_header
*
12533 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12535 struct cleanup
*back_to
;
12536 struct line_header
*lh
;
12537 gdb_byte
*line_ptr
;
12538 unsigned int bytes_read
, offset_size
;
12540 char *cur_dir
, *cur_file
;
12541 struct dwarf2_section_info
*section
;
12544 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12546 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12547 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12549 section
= &dwarf2_per_objfile
->line
;
12551 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12552 if (section
->buffer
== NULL
)
12554 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12555 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12557 complaint (&symfile_complaints
, _("missing .debug_line section"));
12561 /* We can't do this until we know the section is non-empty.
12562 Only then do we know we have such a section. */
12563 abfd
= section
->asection
->owner
;
12565 /* Make sure that at least there's room for the total_length field.
12566 That could be 12 bytes long, but we're just going to fudge that. */
12567 if (offset
+ 4 >= section
->size
)
12569 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12573 lh
= xmalloc (sizeof (*lh
));
12574 memset (lh
, 0, sizeof (*lh
));
12575 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12578 line_ptr
= section
->buffer
+ offset
;
12580 /* Read in the header. */
12582 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12583 &bytes_read
, &offset_size
);
12584 line_ptr
+= bytes_read
;
12585 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12587 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12590 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12591 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12593 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12594 line_ptr
+= offset_size
;
12595 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12597 if (lh
->version
>= 4)
12599 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12603 lh
->maximum_ops_per_instruction
= 1;
12605 if (lh
->maximum_ops_per_instruction
== 0)
12607 lh
->maximum_ops_per_instruction
= 1;
12608 complaint (&symfile_complaints
,
12609 _("invalid maximum_ops_per_instruction "
12610 "in `.debug_line' section"));
12613 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12615 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12617 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12619 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12621 lh
->standard_opcode_lengths
12622 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12624 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12625 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12627 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12631 /* Read directory table. */
12632 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12634 line_ptr
+= bytes_read
;
12635 add_include_dir (lh
, cur_dir
);
12637 line_ptr
+= bytes_read
;
12639 /* Read file name table. */
12640 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12642 unsigned int dir_index
, mod_time
, length
;
12644 line_ptr
+= bytes_read
;
12645 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12646 line_ptr
+= bytes_read
;
12647 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12648 line_ptr
+= bytes_read
;
12649 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12650 line_ptr
+= bytes_read
;
12652 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12654 line_ptr
+= bytes_read
;
12655 lh
->statement_program_start
= line_ptr
;
12657 if (line_ptr
> (section
->buffer
+ section
->size
))
12658 complaint (&symfile_complaints
,
12659 _("line number info header doesn't "
12660 "fit in `.debug_line' section"));
12662 discard_cleanups (back_to
);
12666 /* Subroutine of dwarf_decode_lines to simplify it.
12667 Return the file name of the psymtab for included file FILE_INDEX
12668 in line header LH of PST.
12669 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12670 If space for the result is malloc'd, it will be freed by a cleanup.
12671 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12674 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12675 const struct partial_symtab
*pst
,
12676 const char *comp_dir
)
12678 const struct file_entry fe
= lh
->file_names
[file_index
];
12679 char *include_name
= fe
.name
;
12680 char *include_name_to_compare
= include_name
;
12681 char *dir_name
= NULL
;
12682 const char *pst_filename
;
12683 char *copied_name
= NULL
;
12687 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12689 if (!IS_ABSOLUTE_PATH (include_name
)
12690 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12692 /* Avoid creating a duplicate psymtab for PST.
12693 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12694 Before we do the comparison, however, we need to account
12695 for DIR_NAME and COMP_DIR.
12696 First prepend dir_name (if non-NULL). If we still don't
12697 have an absolute path prepend comp_dir (if non-NULL).
12698 However, the directory we record in the include-file's
12699 psymtab does not contain COMP_DIR (to match the
12700 corresponding symtab(s)).
12705 bash$ gcc -g ./hello.c
12706 include_name = "hello.c"
12708 DW_AT_comp_dir = comp_dir = "/tmp"
12709 DW_AT_name = "./hello.c" */
12711 if (dir_name
!= NULL
)
12713 include_name
= concat (dir_name
, SLASH_STRING
,
12714 include_name
, (char *)NULL
);
12715 include_name_to_compare
= include_name
;
12716 make_cleanup (xfree
, include_name
);
12718 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12720 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12721 include_name
, (char *)NULL
);
12725 pst_filename
= pst
->filename
;
12726 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12728 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12729 pst_filename
, (char *)NULL
);
12730 pst_filename
= copied_name
;
12733 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12735 if (include_name_to_compare
!= include_name
)
12736 xfree (include_name_to_compare
);
12737 if (copied_name
!= NULL
)
12738 xfree (copied_name
);
12742 return include_name
;
12745 /* Ignore this record_line request. */
12748 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12753 /* Subroutine of dwarf_decode_lines to simplify it.
12754 Process the line number information in LH. */
12757 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12758 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12760 gdb_byte
*line_ptr
, *extended_end
;
12761 gdb_byte
*line_end
;
12762 unsigned int bytes_read
, extended_len
;
12763 unsigned char op_code
, extended_op
, adj_opcode
;
12764 CORE_ADDR baseaddr
;
12765 struct objfile
*objfile
= cu
->objfile
;
12766 bfd
*abfd
= objfile
->obfd
;
12767 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12768 const int decode_for_pst_p
= (pst
!= NULL
);
12769 struct subfile
*last_subfile
= NULL
;
12770 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12773 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12775 line_ptr
= lh
->statement_program_start
;
12776 line_end
= lh
->statement_program_end
;
12778 /* Read the statement sequences until there's nothing left. */
12779 while (line_ptr
< line_end
)
12781 /* state machine registers */
12782 CORE_ADDR address
= 0;
12783 unsigned int file
= 1;
12784 unsigned int line
= 1;
12785 unsigned int column
= 0;
12786 int is_stmt
= lh
->default_is_stmt
;
12787 int basic_block
= 0;
12788 int end_sequence
= 0;
12790 unsigned char op_index
= 0;
12792 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12794 /* Start a subfile for the current file of the state machine. */
12795 /* lh->include_dirs and lh->file_names are 0-based, but the
12796 directory and file name numbers in the statement program
12798 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12802 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12804 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12807 /* Decode the table. */
12808 while (!end_sequence
)
12810 op_code
= read_1_byte (abfd
, line_ptr
);
12812 if (line_ptr
> line_end
)
12814 dwarf2_debug_line_missing_end_sequence_complaint ();
12818 if (op_code
>= lh
->opcode_base
)
12820 /* Special operand. */
12821 adj_opcode
= op_code
- lh
->opcode_base
;
12822 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
12823 / lh
->maximum_ops_per_instruction
)
12824 * lh
->minimum_instruction_length
);
12825 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
12826 % lh
->maximum_ops_per_instruction
);
12827 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
12828 if (lh
->num_file_names
< file
|| file
== 0)
12829 dwarf2_debug_line_missing_file_complaint ();
12830 /* For now we ignore lines not starting on an
12831 instruction boundary. */
12832 else if (op_index
== 0)
12834 lh
->file_names
[file
- 1].included_p
= 1;
12835 if (!decode_for_pst_p
&& is_stmt
)
12837 if (last_subfile
!= current_subfile
)
12839 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12841 (*p_record_line
) (last_subfile
, 0, addr
);
12842 last_subfile
= current_subfile
;
12844 /* Append row to matrix using current values. */
12845 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12846 (*p_record_line
) (current_subfile
, line
, addr
);
12851 else switch (op_code
)
12853 case DW_LNS_extended_op
:
12854 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
12856 line_ptr
+= bytes_read
;
12857 extended_end
= line_ptr
+ extended_len
;
12858 extended_op
= read_1_byte (abfd
, line_ptr
);
12860 switch (extended_op
)
12862 case DW_LNE_end_sequence
:
12863 p_record_line
= record_line
;
12866 case DW_LNE_set_address
:
12867 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
12869 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12871 /* This line table is for a function which has been
12872 GCd by the linker. Ignore it. PR gdb/12528 */
12875 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
12877 complaint (&symfile_complaints
,
12878 _(".debug_line address at offset 0x%lx is 0 "
12880 line_offset
, objfile
->name
);
12881 p_record_line
= noop_record_line
;
12885 line_ptr
+= bytes_read
;
12886 address
+= baseaddr
;
12888 case DW_LNE_define_file
:
12891 unsigned int dir_index
, mod_time
, length
;
12893 cur_file
= read_direct_string (abfd
, line_ptr
,
12895 line_ptr
+= bytes_read
;
12897 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12898 line_ptr
+= bytes_read
;
12900 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12901 line_ptr
+= bytes_read
;
12903 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12904 line_ptr
+= bytes_read
;
12905 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12908 case DW_LNE_set_discriminator
:
12909 /* The discriminator is not interesting to the debugger;
12911 line_ptr
= extended_end
;
12914 complaint (&symfile_complaints
,
12915 _("mangled .debug_line section"));
12918 /* Make sure that we parsed the extended op correctly. If e.g.
12919 we expected a different address size than the producer used,
12920 we may have read the wrong number of bytes. */
12921 if (line_ptr
!= extended_end
)
12923 complaint (&symfile_complaints
,
12924 _("mangled .debug_line section"));
12929 if (lh
->num_file_names
< file
|| file
== 0)
12930 dwarf2_debug_line_missing_file_complaint ();
12933 lh
->file_names
[file
- 1].included_p
= 1;
12934 if (!decode_for_pst_p
&& is_stmt
)
12936 if (last_subfile
!= current_subfile
)
12938 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12940 (*p_record_line
) (last_subfile
, 0, addr
);
12941 last_subfile
= current_subfile
;
12943 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12944 (*p_record_line
) (current_subfile
, line
, addr
);
12949 case DW_LNS_advance_pc
:
12952 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12954 address
+= (((op_index
+ adjust
)
12955 / lh
->maximum_ops_per_instruction
)
12956 * lh
->minimum_instruction_length
);
12957 op_index
= ((op_index
+ adjust
)
12958 % lh
->maximum_ops_per_instruction
);
12959 line_ptr
+= bytes_read
;
12962 case DW_LNS_advance_line
:
12963 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
12964 line_ptr
+= bytes_read
;
12966 case DW_LNS_set_file
:
12968 /* The arrays lh->include_dirs and lh->file_names are
12969 0-based, but the directory and file name numbers in
12970 the statement program are 1-based. */
12971 struct file_entry
*fe
;
12974 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12975 line_ptr
+= bytes_read
;
12976 if (lh
->num_file_names
< file
|| file
== 0)
12977 dwarf2_debug_line_missing_file_complaint ();
12980 fe
= &lh
->file_names
[file
- 1];
12982 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12983 if (!decode_for_pst_p
)
12985 last_subfile
= current_subfile
;
12986 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12991 case DW_LNS_set_column
:
12992 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12993 line_ptr
+= bytes_read
;
12995 case DW_LNS_negate_stmt
:
12996 is_stmt
= (!is_stmt
);
12998 case DW_LNS_set_basic_block
:
13001 /* Add to the address register of the state machine the
13002 address increment value corresponding to special opcode
13003 255. I.e., this value is scaled by the minimum
13004 instruction length since special opcode 255 would have
13005 scaled the increment. */
13006 case DW_LNS_const_add_pc
:
13008 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13010 address
+= (((op_index
+ adjust
)
13011 / lh
->maximum_ops_per_instruction
)
13012 * lh
->minimum_instruction_length
);
13013 op_index
= ((op_index
+ adjust
)
13014 % lh
->maximum_ops_per_instruction
);
13017 case DW_LNS_fixed_advance_pc
:
13018 address
+= read_2_bytes (abfd
, line_ptr
);
13024 /* Unknown standard opcode, ignore it. */
13027 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13029 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13030 line_ptr
+= bytes_read
;
13035 if (lh
->num_file_names
< file
|| file
== 0)
13036 dwarf2_debug_line_missing_file_complaint ();
13039 lh
->file_names
[file
- 1].included_p
= 1;
13040 if (!decode_for_pst_p
)
13042 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13043 (*p_record_line
) (current_subfile
, 0, addr
);
13049 /* Decode the Line Number Program (LNP) for the given line_header
13050 structure and CU. The actual information extracted and the type
13051 of structures created from the LNP depends on the value of PST.
13053 1. If PST is NULL, then this procedure uses the data from the program
13054 to create all necessary symbol tables, and their linetables.
13056 2. If PST is not NULL, this procedure reads the program to determine
13057 the list of files included by the unit represented by PST, and
13058 builds all the associated partial symbol tables.
13060 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13061 It is used for relative paths in the line table.
13062 NOTE: When processing partial symtabs (pst != NULL),
13063 comp_dir == pst->dirname.
13065 NOTE: It is important that psymtabs have the same file name (via strcmp)
13066 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13067 symtab we don't use it in the name of the psymtabs we create.
13068 E.g. expand_line_sal requires this when finding psymtabs to expand.
13069 A good testcase for this is mb-inline.exp. */
13072 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13073 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13074 int want_line_info
)
13076 struct objfile
*objfile
= cu
->objfile
;
13077 const int decode_for_pst_p
= (pst
!= NULL
);
13078 struct subfile
*first_subfile
= current_subfile
;
13080 if (want_line_info
)
13081 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13083 if (decode_for_pst_p
)
13087 /* Now that we're done scanning the Line Header Program, we can
13088 create the psymtab of each included file. */
13089 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13090 if (lh
->file_names
[file_index
].included_p
== 1)
13092 char *include_name
=
13093 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13094 if (include_name
!= NULL
)
13095 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13100 /* Make sure a symtab is created for every file, even files
13101 which contain only variables (i.e. no code with associated
13105 for (i
= 0; i
< lh
->num_file_names
; i
++)
13108 struct file_entry
*fe
;
13110 fe
= &lh
->file_names
[i
];
13112 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13113 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13115 /* Skip the main file; we don't need it, and it must be
13116 allocated last, so that it will show up before the
13117 non-primary symtabs in the objfile's symtab list. */
13118 if (current_subfile
== first_subfile
)
13121 if (current_subfile
->symtab
== NULL
)
13122 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13124 fe
->symtab
= current_subfile
->symtab
;
13129 /* Start a subfile for DWARF. FILENAME is the name of the file and
13130 DIRNAME the name of the source directory which contains FILENAME
13131 or NULL if not known. COMP_DIR is the compilation directory for the
13132 linetable's compilation unit or NULL if not known.
13133 This routine tries to keep line numbers from identical absolute and
13134 relative file names in a common subfile.
13136 Using the `list' example from the GDB testsuite, which resides in
13137 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13138 of /srcdir/list0.c yields the following debugging information for list0.c:
13140 DW_AT_name: /srcdir/list0.c
13141 DW_AT_comp_dir: /compdir
13142 files.files[0].name: list0.h
13143 files.files[0].dir: /srcdir
13144 files.files[1].name: list0.c
13145 files.files[1].dir: /srcdir
13147 The line number information for list0.c has to end up in a single
13148 subfile, so that `break /srcdir/list0.c:1' works as expected.
13149 start_subfile will ensure that this happens provided that we pass the
13150 concatenation of files.files[1].dir and files.files[1].name as the
13154 dwarf2_start_subfile (char *filename
, const char *dirname
,
13155 const char *comp_dir
)
13159 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13160 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13161 second argument to start_subfile. To be consistent, we do the
13162 same here. In order not to lose the line information directory,
13163 we concatenate it to the filename when it makes sense.
13164 Note that the Dwarf3 standard says (speaking of filenames in line
13165 information): ``The directory index is ignored for file names
13166 that represent full path names''. Thus ignoring dirname in the
13167 `else' branch below isn't an issue. */
13169 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13170 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13172 fullname
= filename
;
13174 start_subfile (fullname
, comp_dir
);
13176 if (fullname
!= filename
)
13181 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13182 struct dwarf2_cu
*cu
)
13184 struct objfile
*objfile
= cu
->objfile
;
13185 struct comp_unit_head
*cu_header
= &cu
->header
;
13187 /* NOTE drow/2003-01-30: There used to be a comment and some special
13188 code here to turn a symbol with DW_AT_external and a
13189 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13190 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13191 with some versions of binutils) where shared libraries could have
13192 relocations against symbols in their debug information - the
13193 minimal symbol would have the right address, but the debug info
13194 would not. It's no longer necessary, because we will explicitly
13195 apply relocations when we read in the debug information now. */
13197 /* A DW_AT_location attribute with no contents indicates that a
13198 variable has been optimized away. */
13199 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13201 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13205 /* Handle one degenerate form of location expression specially, to
13206 preserve GDB's previous behavior when section offsets are
13207 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13208 then mark this symbol as LOC_STATIC. */
13210 if (attr_form_is_block (attr
)
13211 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13212 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13213 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13214 && (DW_BLOCK (attr
)->size
13215 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13217 unsigned int dummy
;
13219 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13220 SYMBOL_VALUE_ADDRESS (sym
) =
13221 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13223 SYMBOL_VALUE_ADDRESS (sym
) =
13224 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13225 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13226 fixup_symbol_section (sym
, objfile
);
13227 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13228 SYMBOL_SECTION (sym
));
13232 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13233 expression evaluator, and use LOC_COMPUTED only when necessary
13234 (i.e. when the value of a register or memory location is
13235 referenced, or a thread-local block, etc.). Then again, it might
13236 not be worthwhile. I'm assuming that it isn't unless performance
13237 or memory numbers show me otherwise. */
13239 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13240 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13242 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13243 cu
->has_loclist
= 1;
13246 /* Given a pointer to a DWARF information entry, figure out if we need
13247 to make a symbol table entry for it, and if so, create a new entry
13248 and return a pointer to it.
13249 If TYPE is NULL, determine symbol type from the die, otherwise
13250 used the passed type.
13251 If SPACE is not NULL, use it to hold the new symbol. If it is
13252 NULL, allocate a new symbol on the objfile's obstack. */
13254 static struct symbol
*
13255 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13256 struct symbol
*space
)
13258 struct objfile
*objfile
= cu
->objfile
;
13259 struct symbol
*sym
= NULL
;
13261 struct attribute
*attr
= NULL
;
13262 struct attribute
*attr2
= NULL
;
13263 CORE_ADDR baseaddr
;
13264 struct pending
**list_to_add
= NULL
;
13266 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13268 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13270 name
= dwarf2_name (die
, cu
);
13273 const char *linkagename
;
13274 int suppress_add
= 0;
13279 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13280 OBJSTAT (objfile
, n_syms
++);
13282 /* Cache this symbol's name and the name's demangled form (if any). */
13283 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13284 linkagename
= dwarf2_physname (name
, die
, cu
);
13285 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13287 /* Fortran does not have mangling standard and the mangling does differ
13288 between gfortran, iFort etc. */
13289 if (cu
->language
== language_fortran
13290 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13291 symbol_set_demangled_name (&(sym
->ginfo
),
13292 (char *) dwarf2_full_name (name
, die
, cu
),
13295 /* Default assumptions.
13296 Use the passed type or decode it from the die. */
13297 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13298 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13300 SYMBOL_TYPE (sym
) = type
;
13302 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13303 attr
= dwarf2_attr (die
,
13304 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13308 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13311 attr
= dwarf2_attr (die
,
13312 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13316 int file_index
= DW_UNSND (attr
);
13318 if (cu
->line_header
== NULL
13319 || file_index
> cu
->line_header
->num_file_names
)
13320 complaint (&symfile_complaints
,
13321 _("file index out of range"));
13322 else if (file_index
> 0)
13324 struct file_entry
*fe
;
13326 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13327 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13334 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13337 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13339 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13340 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13341 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13342 add_symbol_to_list (sym
, cu
->list_in_scope
);
13344 case DW_TAG_subprogram
:
13345 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13347 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13348 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13349 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13350 || cu
->language
== language_ada
)
13352 /* Subprograms marked external are stored as a global symbol.
13353 Ada subprograms, whether marked external or not, are always
13354 stored as a global symbol, because we want to be able to
13355 access them globally. For instance, we want to be able
13356 to break on a nested subprogram without having to
13357 specify the context. */
13358 list_to_add
= &global_symbols
;
13362 list_to_add
= cu
->list_in_scope
;
13365 case DW_TAG_inlined_subroutine
:
13366 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13368 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13369 SYMBOL_INLINED (sym
) = 1;
13370 list_to_add
= cu
->list_in_scope
;
13372 case DW_TAG_template_value_param
:
13374 /* Fall through. */
13375 case DW_TAG_constant
:
13376 case DW_TAG_variable
:
13377 case DW_TAG_member
:
13378 /* Compilation with minimal debug info may result in
13379 variables with missing type entries. Change the
13380 misleading `void' type to something sensible. */
13381 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13383 = objfile_type (objfile
)->nodebug_data_symbol
;
13385 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13386 /* In the case of DW_TAG_member, we should only be called for
13387 static const members. */
13388 if (die
->tag
== DW_TAG_member
)
13390 /* dwarf2_add_field uses die_is_declaration,
13391 so we do the same. */
13392 gdb_assert (die_is_declaration (die
, cu
));
13397 dwarf2_const_value (attr
, sym
, cu
);
13398 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13401 if (attr2
&& (DW_UNSND (attr2
) != 0))
13402 list_to_add
= &global_symbols
;
13404 list_to_add
= cu
->list_in_scope
;
13408 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13411 var_decode_location (attr
, sym
, cu
);
13412 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13413 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13414 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13415 && !dwarf2_per_objfile
->has_section_at_zero
)
13417 /* When a static variable is eliminated by the linker,
13418 the corresponding debug information is not stripped
13419 out, but the variable address is set to null;
13420 do not add such variables into symbol table. */
13422 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13424 /* Workaround gfortran PR debug/40040 - it uses
13425 DW_AT_location for variables in -fPIC libraries which may
13426 get overriden by other libraries/executable and get
13427 a different address. Resolve it by the minimal symbol
13428 which may come from inferior's executable using copy
13429 relocation. Make this workaround only for gfortran as for
13430 other compilers GDB cannot guess the minimal symbol
13431 Fortran mangling kind. */
13432 if (cu
->language
== language_fortran
&& die
->parent
13433 && die
->parent
->tag
== DW_TAG_module
13435 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13436 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13438 /* A variable with DW_AT_external is never static,
13439 but it may be block-scoped. */
13440 list_to_add
= (cu
->list_in_scope
== &file_symbols
13441 ? &global_symbols
: cu
->list_in_scope
);
13444 list_to_add
= cu
->list_in_scope
;
13448 /* We do not know the address of this symbol.
13449 If it is an external symbol and we have type information
13450 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13451 The address of the variable will then be determined from
13452 the minimal symbol table whenever the variable is
13454 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13455 if (attr2
&& (DW_UNSND (attr2
) != 0)
13456 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13458 /* A variable with DW_AT_external is never static, but it
13459 may be block-scoped. */
13460 list_to_add
= (cu
->list_in_scope
== &file_symbols
13461 ? &global_symbols
: cu
->list_in_scope
);
13463 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13465 else if (!die_is_declaration (die
, cu
))
13467 /* Use the default LOC_OPTIMIZED_OUT class. */
13468 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13470 list_to_add
= cu
->list_in_scope
;
13474 case DW_TAG_formal_parameter
:
13475 /* If we are inside a function, mark this as an argument. If
13476 not, we might be looking at an argument to an inlined function
13477 when we do not have enough information to show inlined frames;
13478 pretend it's a local variable in that case so that the user can
13480 if (context_stack_depth
> 0
13481 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13482 SYMBOL_IS_ARGUMENT (sym
) = 1;
13483 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13486 var_decode_location (attr
, sym
, cu
);
13488 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13491 dwarf2_const_value (attr
, sym
, cu
);
13494 list_to_add
= cu
->list_in_scope
;
13496 case DW_TAG_unspecified_parameters
:
13497 /* From varargs functions; gdb doesn't seem to have any
13498 interest in this information, so just ignore it for now.
13501 case DW_TAG_template_type_param
:
13503 /* Fall through. */
13504 case DW_TAG_class_type
:
13505 case DW_TAG_interface_type
:
13506 case DW_TAG_structure_type
:
13507 case DW_TAG_union_type
:
13508 case DW_TAG_set_type
:
13509 case DW_TAG_enumeration_type
:
13510 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13511 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13514 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13515 really ever be static objects: otherwise, if you try
13516 to, say, break of a class's method and you're in a file
13517 which doesn't mention that class, it won't work unless
13518 the check for all static symbols in lookup_symbol_aux
13519 saves you. See the OtherFileClass tests in
13520 gdb.c++/namespace.exp. */
13524 list_to_add
= (cu
->list_in_scope
== &file_symbols
13525 && (cu
->language
== language_cplus
13526 || cu
->language
== language_java
)
13527 ? &global_symbols
: cu
->list_in_scope
);
13529 /* The semantics of C++ state that "struct foo {
13530 ... }" also defines a typedef for "foo". A Java
13531 class declaration also defines a typedef for the
13533 if (cu
->language
== language_cplus
13534 || cu
->language
== language_java
13535 || cu
->language
== language_ada
)
13537 /* The symbol's name is already allocated along
13538 with this objfile, so we don't need to
13539 duplicate it for the type. */
13540 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13541 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13546 case DW_TAG_typedef
:
13547 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13548 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13549 list_to_add
= cu
->list_in_scope
;
13551 case DW_TAG_base_type
:
13552 case DW_TAG_subrange_type
:
13553 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13554 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13555 list_to_add
= cu
->list_in_scope
;
13557 case DW_TAG_enumerator
:
13558 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13561 dwarf2_const_value (attr
, sym
, cu
);
13564 /* NOTE: carlton/2003-11-10: See comment above in the
13565 DW_TAG_class_type, etc. block. */
13567 list_to_add
= (cu
->list_in_scope
== &file_symbols
13568 && (cu
->language
== language_cplus
13569 || cu
->language
== language_java
)
13570 ? &global_symbols
: cu
->list_in_scope
);
13573 case DW_TAG_namespace
:
13574 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13575 list_to_add
= &global_symbols
;
13578 /* Not a tag we recognize. Hopefully we aren't processing
13579 trash data, but since we must specifically ignore things
13580 we don't recognize, there is nothing else we should do at
13582 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13583 dwarf_tag_name (die
->tag
));
13589 sym
->hash_next
= objfile
->template_symbols
;
13590 objfile
->template_symbols
= sym
;
13591 list_to_add
= NULL
;
13594 if (list_to_add
!= NULL
)
13595 add_symbol_to_list (sym
, list_to_add
);
13597 /* For the benefit of old versions of GCC, check for anonymous
13598 namespaces based on the demangled name. */
13599 if (!processing_has_namespace_info
13600 && cu
->language
== language_cplus
)
13601 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13606 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13608 static struct symbol
*
13609 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13611 return new_symbol_full (die
, type
, cu
, NULL
);
13614 /* Given an attr with a DW_FORM_dataN value in host byte order,
13615 zero-extend it as appropriate for the symbol's type. The DWARF
13616 standard (v4) is not entirely clear about the meaning of using
13617 DW_FORM_dataN for a constant with a signed type, where the type is
13618 wider than the data. The conclusion of a discussion on the DWARF
13619 list was that this is unspecified. We choose to always zero-extend
13620 because that is the interpretation long in use by GCC. */
13623 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13624 const char *name
, struct obstack
*obstack
,
13625 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13627 struct objfile
*objfile
= cu
->objfile
;
13628 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13629 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13630 LONGEST l
= DW_UNSND (attr
);
13632 if (bits
< sizeof (*value
) * 8)
13634 l
&= ((LONGEST
) 1 << bits
) - 1;
13637 else if (bits
== sizeof (*value
) * 8)
13641 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13642 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13649 /* Read a constant value from an attribute. Either set *VALUE, or if
13650 the value does not fit in *VALUE, set *BYTES - either already
13651 allocated on the objfile obstack, or newly allocated on OBSTACK,
13652 or, set *BATON, if we translated the constant to a location
13656 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13657 const char *name
, struct obstack
*obstack
,
13658 struct dwarf2_cu
*cu
,
13659 LONGEST
*value
, gdb_byte
**bytes
,
13660 struct dwarf2_locexpr_baton
**baton
)
13662 struct objfile
*objfile
= cu
->objfile
;
13663 struct comp_unit_head
*cu_header
= &cu
->header
;
13664 struct dwarf_block
*blk
;
13665 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13666 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13672 switch (attr
->form
)
13675 case DW_FORM_GNU_addr_index
:
13679 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13680 dwarf2_const_value_length_mismatch_complaint (name
,
13681 cu_header
->addr_size
,
13682 TYPE_LENGTH (type
));
13683 /* Symbols of this form are reasonably rare, so we just
13684 piggyback on the existing location code rather than writing
13685 a new implementation of symbol_computed_ops. */
13686 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13687 sizeof (struct dwarf2_locexpr_baton
));
13688 (*baton
)->per_cu
= cu
->per_cu
;
13689 gdb_assert ((*baton
)->per_cu
);
13691 (*baton
)->size
= 2 + cu_header
->addr_size
;
13692 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13693 (*baton
)->data
= data
;
13695 data
[0] = DW_OP_addr
;
13696 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13697 byte_order
, DW_ADDR (attr
));
13698 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13701 case DW_FORM_string
:
13703 case DW_FORM_GNU_str_index
:
13704 /* DW_STRING is already allocated on the objfile obstack, point
13706 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13708 case DW_FORM_block1
:
13709 case DW_FORM_block2
:
13710 case DW_FORM_block4
:
13711 case DW_FORM_block
:
13712 case DW_FORM_exprloc
:
13713 blk
= DW_BLOCK (attr
);
13714 if (TYPE_LENGTH (type
) != blk
->size
)
13715 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13716 TYPE_LENGTH (type
));
13717 *bytes
= blk
->data
;
13720 /* The DW_AT_const_value attributes are supposed to carry the
13721 symbol's value "represented as it would be on the target
13722 architecture." By the time we get here, it's already been
13723 converted to host endianness, so we just need to sign- or
13724 zero-extend it as appropriate. */
13725 case DW_FORM_data1
:
13726 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13727 obstack
, cu
, value
, 8);
13729 case DW_FORM_data2
:
13730 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13731 obstack
, cu
, value
, 16);
13733 case DW_FORM_data4
:
13734 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13735 obstack
, cu
, value
, 32);
13737 case DW_FORM_data8
:
13738 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13739 obstack
, cu
, value
, 64);
13742 case DW_FORM_sdata
:
13743 *value
= DW_SND (attr
);
13746 case DW_FORM_udata
:
13747 *value
= DW_UNSND (attr
);
13751 complaint (&symfile_complaints
,
13752 _("unsupported const value attribute form: '%s'"),
13753 dwarf_form_name (attr
->form
));
13760 /* Copy constant value from an attribute to a symbol. */
13763 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13764 struct dwarf2_cu
*cu
)
13766 struct objfile
*objfile
= cu
->objfile
;
13767 struct comp_unit_head
*cu_header
= &cu
->header
;
13770 struct dwarf2_locexpr_baton
*baton
;
13772 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13773 SYMBOL_PRINT_NAME (sym
),
13774 &objfile
->objfile_obstack
, cu
,
13775 &value
, &bytes
, &baton
);
13779 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13780 SYMBOL_LOCATION_BATON (sym
) = baton
;
13781 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13783 else if (bytes
!= NULL
)
13785 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13786 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13790 SYMBOL_VALUE (sym
) = value
;
13791 SYMBOL_CLASS (sym
) = LOC_CONST
;
13795 /* Return the type of the die in question using its DW_AT_type attribute. */
13797 static struct type
*
13798 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13800 struct attribute
*type_attr
;
13802 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13805 /* A missing DW_AT_type represents a void type. */
13806 return objfile_type (cu
->objfile
)->builtin_void
;
13809 return lookup_die_type (die
, type_attr
, cu
);
13812 /* True iff CU's producer generates GNAT Ada auxiliary information
13813 that allows to find parallel types through that information instead
13814 of having to do expensive parallel lookups by type name. */
13817 need_gnat_info (struct dwarf2_cu
*cu
)
13819 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
13820 of GNAT produces this auxiliary information, without any indication
13821 that it is produced. Part of enhancing the FSF version of GNAT
13822 to produce that information will be to put in place an indicator
13823 that we can use in order to determine whether the descriptive type
13824 info is available or not. One suggestion that has been made is
13825 to use a new attribute, attached to the CU die. For now, assume
13826 that the descriptive type info is not available. */
13830 /* Return the auxiliary type of the die in question using its
13831 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
13832 attribute is not present. */
13834 static struct type
*
13835 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13837 struct attribute
*type_attr
;
13839 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
13843 return lookup_die_type (die
, type_attr
, cu
);
13846 /* If DIE has a descriptive_type attribute, then set the TYPE's
13847 descriptive type accordingly. */
13850 set_descriptive_type (struct type
*type
, struct die_info
*die
,
13851 struct dwarf2_cu
*cu
)
13853 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
13855 if (descriptive_type
)
13857 ALLOCATE_GNAT_AUX_TYPE (type
);
13858 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
13862 /* Return the containing type of the die in question using its
13863 DW_AT_containing_type attribute. */
13865 static struct type
*
13866 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13868 struct attribute
*type_attr
;
13870 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
13872 error (_("Dwarf Error: Problem turning containing type into gdb type "
13873 "[in module %s]"), cu
->objfile
->name
);
13875 return lookup_die_type (die
, type_attr
, cu
);
13878 /* Look up the type of DIE in CU using its type attribute ATTR.
13879 If there is no type substitute an error marker. */
13881 static struct type
*
13882 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
13883 struct dwarf2_cu
*cu
)
13885 struct objfile
*objfile
= cu
->objfile
;
13886 struct type
*this_type
;
13888 /* First see if we have it cached. */
13890 if (is_ref_attr (attr
))
13892 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
13894 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
13896 else if (attr
->form
== DW_FORM_ref_sig8
)
13898 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13900 /* sig_type will be NULL if the signatured type is missing from
13902 if (sig_type
== NULL
)
13903 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13904 "at 0x%x [in module %s]"),
13905 die
->offset
.sect_off
, objfile
->name
);
13907 gdb_assert (sig_type
->per_cu
.is_debug_types
);
13908 /* If we haven't filled in type_offset_in_section yet, then we
13909 haven't read the type in yet. */
13911 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
13914 get_die_type_at_offset (sig_type
->type_offset_in_section
,
13915 &sig_type
->per_cu
);
13920 dump_die_for_error (die
);
13921 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
13922 dwarf_attr_name (attr
->name
), objfile
->name
);
13925 /* If not cached we need to read it in. */
13927 if (this_type
== NULL
)
13929 struct die_info
*type_die
;
13930 struct dwarf2_cu
*type_cu
= cu
;
13932 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
13933 /* If we found the type now, it's probably because the type came
13934 from an inter-CU reference and the type's CU got expanded before
13936 this_type
= get_die_type (type_die
, type_cu
);
13937 if (this_type
== NULL
)
13938 this_type
= read_type_die_1 (type_die
, type_cu
);
13941 /* If we still don't have a type use an error marker. */
13943 if (this_type
== NULL
)
13945 char *message
, *saved
;
13947 /* read_type_die already issued a complaint. */
13948 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
13950 cu
->header
.offset
.sect_off
,
13951 die
->offset
.sect_off
);
13952 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
13953 message
, strlen (message
));
13956 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
13962 /* Return the type in DIE, CU.
13963 Returns NULL for invalid types.
13965 This first does a lookup in the appropriate type_hash table,
13966 and only reads the die in if necessary.
13968 NOTE: This can be called when reading in partial or full symbols. */
13970 static struct type
*
13971 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
13973 struct type
*this_type
;
13975 this_type
= get_die_type (die
, cu
);
13979 return read_type_die_1 (die
, cu
);
13982 /* Read the type in DIE, CU.
13983 Returns NULL for invalid types. */
13985 static struct type
*
13986 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
13988 struct type
*this_type
= NULL
;
13992 case DW_TAG_class_type
:
13993 case DW_TAG_interface_type
:
13994 case DW_TAG_structure_type
:
13995 case DW_TAG_union_type
:
13996 this_type
= read_structure_type (die
, cu
);
13998 case DW_TAG_enumeration_type
:
13999 this_type
= read_enumeration_type (die
, cu
);
14001 case DW_TAG_subprogram
:
14002 case DW_TAG_subroutine_type
:
14003 case DW_TAG_inlined_subroutine
:
14004 this_type
= read_subroutine_type (die
, cu
);
14006 case DW_TAG_array_type
:
14007 this_type
= read_array_type (die
, cu
);
14009 case DW_TAG_set_type
:
14010 this_type
= read_set_type (die
, cu
);
14012 case DW_TAG_pointer_type
:
14013 this_type
= read_tag_pointer_type (die
, cu
);
14015 case DW_TAG_ptr_to_member_type
:
14016 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14018 case DW_TAG_reference_type
:
14019 this_type
= read_tag_reference_type (die
, cu
);
14021 case DW_TAG_const_type
:
14022 this_type
= read_tag_const_type (die
, cu
);
14024 case DW_TAG_volatile_type
:
14025 this_type
= read_tag_volatile_type (die
, cu
);
14027 case DW_TAG_string_type
:
14028 this_type
= read_tag_string_type (die
, cu
);
14030 case DW_TAG_typedef
:
14031 this_type
= read_typedef (die
, cu
);
14033 case DW_TAG_subrange_type
:
14034 this_type
= read_subrange_type (die
, cu
);
14036 case DW_TAG_base_type
:
14037 this_type
= read_base_type (die
, cu
);
14039 case DW_TAG_unspecified_type
:
14040 this_type
= read_unspecified_type (die
, cu
);
14042 case DW_TAG_namespace
:
14043 this_type
= read_namespace_type (die
, cu
);
14045 case DW_TAG_module
:
14046 this_type
= read_module_type (die
, cu
);
14049 complaint (&symfile_complaints
,
14050 _("unexpected tag in read_type_die: '%s'"),
14051 dwarf_tag_name (die
->tag
));
14058 /* See if we can figure out if the class lives in a namespace. We do
14059 this by looking for a member function; its demangled name will
14060 contain namespace info, if there is any.
14061 Return the computed name or NULL.
14062 Space for the result is allocated on the objfile's obstack.
14063 This is the full-die version of guess_partial_die_structure_name.
14064 In this case we know DIE has no useful parent. */
14067 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14069 struct die_info
*spec_die
;
14070 struct dwarf2_cu
*spec_cu
;
14071 struct die_info
*child
;
14074 spec_die
= die_specification (die
, &spec_cu
);
14075 if (spec_die
!= NULL
)
14081 for (child
= die
->child
;
14083 child
= child
->sibling
)
14085 if (child
->tag
== DW_TAG_subprogram
)
14087 struct attribute
*attr
;
14089 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14091 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14095 = language_class_name_from_physname (cu
->language_defn
,
14099 if (actual_name
!= NULL
)
14101 char *die_name
= dwarf2_name (die
, cu
);
14103 if (die_name
!= NULL
14104 && strcmp (die_name
, actual_name
) != 0)
14106 /* Strip off the class name from the full name.
14107 We want the prefix. */
14108 int die_name_len
= strlen (die_name
);
14109 int actual_name_len
= strlen (actual_name
);
14111 /* Test for '::' as a sanity check. */
14112 if (actual_name_len
> die_name_len
+ 2
14113 && actual_name
[actual_name_len
14114 - die_name_len
- 1] == ':')
14116 obsavestring (actual_name
,
14117 actual_name_len
- die_name_len
- 2,
14118 &cu
->objfile
->objfile_obstack
);
14121 xfree (actual_name
);
14130 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14131 prefix part in such case. See
14132 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14135 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14137 struct attribute
*attr
;
14140 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14141 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14144 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14145 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14148 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14150 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14151 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14154 /* dwarf2_name had to be already called. */
14155 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14157 /* Strip the base name, keep any leading namespaces/classes. */
14158 base
= strrchr (DW_STRING (attr
), ':');
14159 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14162 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14163 &cu
->objfile
->objfile_obstack
);
14166 /* Return the name of the namespace/class that DIE is defined within,
14167 or "" if we can't tell. The caller should not xfree the result.
14169 For example, if we're within the method foo() in the following
14179 then determine_prefix on foo's die will return "N::C". */
14181 static const char *
14182 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14184 struct die_info
*parent
, *spec_die
;
14185 struct dwarf2_cu
*spec_cu
;
14186 struct type
*parent_type
;
14189 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14190 && cu
->language
!= language_fortran
)
14193 retval
= anonymous_struct_prefix (die
, cu
);
14197 /* We have to be careful in the presence of DW_AT_specification.
14198 For example, with GCC 3.4, given the code
14202 // Definition of N::foo.
14206 then we'll have a tree of DIEs like this:
14208 1: DW_TAG_compile_unit
14209 2: DW_TAG_namespace // N
14210 3: DW_TAG_subprogram // declaration of N::foo
14211 4: DW_TAG_subprogram // definition of N::foo
14212 DW_AT_specification // refers to die #3
14214 Thus, when processing die #4, we have to pretend that we're in
14215 the context of its DW_AT_specification, namely the contex of die
14218 spec_die
= die_specification (die
, &spec_cu
);
14219 if (spec_die
== NULL
)
14220 parent
= die
->parent
;
14223 parent
= spec_die
->parent
;
14227 if (parent
== NULL
)
14229 else if (parent
->building_fullname
)
14232 const char *parent_name
;
14234 /* It has been seen on RealView 2.2 built binaries,
14235 DW_TAG_template_type_param types actually _defined_ as
14236 children of the parent class:
14239 template class <class Enum> Class{};
14240 Class<enum E> class_e;
14242 1: DW_TAG_class_type (Class)
14243 2: DW_TAG_enumeration_type (E)
14244 3: DW_TAG_enumerator (enum1:0)
14245 3: DW_TAG_enumerator (enum2:1)
14247 2: DW_TAG_template_type_param
14248 DW_AT_type DW_FORM_ref_udata (E)
14250 Besides being broken debug info, it can put GDB into an
14251 infinite loop. Consider:
14253 When we're building the full name for Class<E>, we'll start
14254 at Class, and go look over its template type parameters,
14255 finding E. We'll then try to build the full name of E, and
14256 reach here. We're now trying to build the full name of E,
14257 and look over the parent DIE for containing scope. In the
14258 broken case, if we followed the parent DIE of E, we'd again
14259 find Class, and once again go look at its template type
14260 arguments, etc., etc. Simply don't consider such parent die
14261 as source-level parent of this die (it can't be, the language
14262 doesn't allow it), and break the loop here. */
14263 name
= dwarf2_name (die
, cu
);
14264 parent_name
= dwarf2_name (parent
, cu
);
14265 complaint (&symfile_complaints
,
14266 _("template param type '%s' defined within parent '%s'"),
14267 name
? name
: "<unknown>",
14268 parent_name
? parent_name
: "<unknown>");
14272 switch (parent
->tag
)
14274 case DW_TAG_namespace
:
14275 parent_type
= read_type_die (parent
, cu
);
14276 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14277 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14278 Work around this problem here. */
14279 if (cu
->language
== language_cplus
14280 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14282 /* We give a name to even anonymous namespaces. */
14283 return TYPE_TAG_NAME (parent_type
);
14284 case DW_TAG_class_type
:
14285 case DW_TAG_interface_type
:
14286 case DW_TAG_structure_type
:
14287 case DW_TAG_union_type
:
14288 case DW_TAG_module
:
14289 parent_type
= read_type_die (parent
, cu
);
14290 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14291 return TYPE_TAG_NAME (parent_type
);
14293 /* An anonymous structure is only allowed non-static data
14294 members; no typedefs, no member functions, et cetera.
14295 So it does not need a prefix. */
14297 case DW_TAG_compile_unit
:
14298 case DW_TAG_partial_unit
:
14299 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14300 if (cu
->language
== language_cplus
14301 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14302 && die
->child
!= NULL
14303 && (die
->tag
== DW_TAG_class_type
14304 || die
->tag
== DW_TAG_structure_type
14305 || die
->tag
== DW_TAG_union_type
))
14307 char *name
= guess_full_die_structure_name (die
, cu
);
14313 return determine_prefix (parent
, cu
);
14317 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14318 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14319 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14320 an obconcat, otherwise allocate storage for the result. The CU argument is
14321 used to determine the language and hence, the appropriate separator. */
14323 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14326 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14327 int physname
, struct dwarf2_cu
*cu
)
14329 const char *lead
= "";
14332 if (suffix
== NULL
|| suffix
[0] == '\0'
14333 || prefix
== NULL
|| prefix
[0] == '\0')
14335 else if (cu
->language
== language_java
)
14337 else if (cu
->language
== language_fortran
&& physname
)
14339 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14340 DW_AT_MIPS_linkage_name is preferred and used instead. */
14348 if (prefix
== NULL
)
14350 if (suffix
== NULL
)
14356 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14358 strcpy (retval
, lead
);
14359 strcat (retval
, prefix
);
14360 strcat (retval
, sep
);
14361 strcat (retval
, suffix
);
14366 /* We have an obstack. */
14367 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14371 /* Return sibling of die, NULL if no sibling. */
14373 static struct die_info
*
14374 sibling_die (struct die_info
*die
)
14376 return die
->sibling
;
14379 /* Get name of a die, return NULL if not found. */
14382 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14383 struct obstack
*obstack
)
14385 if (name
&& cu
->language
== language_cplus
)
14387 char *canon_name
= cp_canonicalize_string (name
);
14389 if (canon_name
!= NULL
)
14391 if (strcmp (canon_name
, name
) != 0)
14392 name
= obsavestring (canon_name
, strlen (canon_name
),
14394 xfree (canon_name
);
14401 /* Get name of a die, return NULL if not found. */
14404 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14406 struct attribute
*attr
;
14408 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14409 if ((!attr
|| !DW_STRING (attr
))
14410 && die
->tag
!= DW_TAG_class_type
14411 && die
->tag
!= DW_TAG_interface_type
14412 && die
->tag
!= DW_TAG_structure_type
14413 && die
->tag
!= DW_TAG_union_type
)
14418 case DW_TAG_compile_unit
:
14419 case DW_TAG_partial_unit
:
14420 /* Compilation units have a DW_AT_name that is a filename, not
14421 a source language identifier. */
14422 case DW_TAG_enumeration_type
:
14423 case DW_TAG_enumerator
:
14424 /* These tags always have simple identifiers already; no need
14425 to canonicalize them. */
14426 return DW_STRING (attr
);
14428 case DW_TAG_subprogram
:
14429 /* Java constructors will all be named "<init>", so return
14430 the class name when we see this special case. */
14431 if (cu
->language
== language_java
14432 && DW_STRING (attr
) != NULL
14433 && strcmp (DW_STRING (attr
), "<init>") == 0)
14435 struct dwarf2_cu
*spec_cu
= cu
;
14436 struct die_info
*spec_die
;
14438 /* GCJ will output '<init>' for Java constructor names.
14439 For this special case, return the name of the parent class. */
14441 /* GCJ may output suprogram DIEs with AT_specification set.
14442 If so, use the name of the specified DIE. */
14443 spec_die
= die_specification (die
, &spec_cu
);
14444 if (spec_die
!= NULL
)
14445 return dwarf2_name (spec_die
, spec_cu
);
14450 if (die
->tag
== DW_TAG_class_type
)
14451 return dwarf2_name (die
, cu
);
14453 while (die
->tag
!= DW_TAG_compile_unit
14454 && die
->tag
!= DW_TAG_partial_unit
);
14458 case DW_TAG_class_type
:
14459 case DW_TAG_interface_type
:
14460 case DW_TAG_structure_type
:
14461 case DW_TAG_union_type
:
14462 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14463 structures or unions. These were of the form "._%d" in GCC 4.1,
14464 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14465 and GCC 4.4. We work around this problem by ignoring these. */
14466 if (attr
&& DW_STRING (attr
)
14467 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14468 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14471 /* GCC might emit a nameless typedef that has a linkage name. See
14472 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14473 if (!attr
|| DW_STRING (attr
) == NULL
)
14475 char *demangled
= NULL
;
14477 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14479 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14481 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14484 /* Avoid demangling DW_STRING (attr) the second time on a second
14485 call for the same DIE. */
14486 if (!DW_STRING_IS_CANONICAL (attr
))
14487 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14493 /* FIXME: we already did this for the partial symbol... */
14494 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14495 &cu
->objfile
->objfile_obstack
);
14496 DW_STRING_IS_CANONICAL (attr
) = 1;
14499 /* Strip any leading namespaces/classes, keep only the base name.
14500 DW_AT_name for named DIEs does not contain the prefixes. */
14501 base
= strrchr (DW_STRING (attr
), ':');
14502 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14505 return DW_STRING (attr
);
14514 if (!DW_STRING_IS_CANONICAL (attr
))
14517 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14518 &cu
->objfile
->objfile_obstack
);
14519 DW_STRING_IS_CANONICAL (attr
) = 1;
14521 return DW_STRING (attr
);
14524 /* Return the die that this die in an extension of, or NULL if there
14525 is none. *EXT_CU is the CU containing DIE on input, and the CU
14526 containing the return value on output. */
14528 static struct die_info
*
14529 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14531 struct attribute
*attr
;
14533 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14537 return follow_die_ref (die
, attr
, ext_cu
);
14540 /* Convert a DIE tag into its string name. */
14542 static const char *
14543 dwarf_tag_name (unsigned tag
)
14545 const char *name
= get_DW_TAG_name (tag
);
14548 return "DW_TAG_<unknown>";
14553 /* Convert a DWARF attribute code into its string name. */
14555 static const char *
14556 dwarf_attr_name (unsigned attr
)
14560 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14561 if (attr
== DW_AT_MIPS_fde
)
14562 return "DW_AT_MIPS_fde";
14564 if (attr
== DW_AT_HP_block_index
)
14565 return "DW_AT_HP_block_index";
14568 name
= get_DW_AT_name (attr
);
14571 return "DW_AT_<unknown>";
14576 /* Convert a DWARF value form code into its string name. */
14578 static const char *
14579 dwarf_form_name (unsigned form
)
14581 const char *name
= get_DW_FORM_name (form
);
14584 return "DW_FORM_<unknown>";
14590 dwarf_bool_name (unsigned mybool
)
14598 /* Convert a DWARF type code into its string name. */
14600 static const char *
14601 dwarf_type_encoding_name (unsigned enc
)
14603 const char *name
= get_DW_ATE_name (enc
);
14606 return "DW_ATE_<unknown>";
14612 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14616 print_spaces (indent
, f
);
14617 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14618 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14620 if (die
->parent
!= NULL
)
14622 print_spaces (indent
, f
);
14623 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14624 die
->parent
->offset
.sect_off
);
14627 print_spaces (indent
, f
);
14628 fprintf_unfiltered (f
, " has children: %s\n",
14629 dwarf_bool_name (die
->child
!= NULL
));
14631 print_spaces (indent
, f
);
14632 fprintf_unfiltered (f
, " attributes:\n");
14634 for (i
= 0; i
< die
->num_attrs
; ++i
)
14636 print_spaces (indent
, f
);
14637 fprintf_unfiltered (f
, " %s (%s) ",
14638 dwarf_attr_name (die
->attrs
[i
].name
),
14639 dwarf_form_name (die
->attrs
[i
].form
));
14641 switch (die
->attrs
[i
].form
)
14644 case DW_FORM_GNU_addr_index
:
14645 fprintf_unfiltered (f
, "address: ");
14646 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14648 case DW_FORM_block2
:
14649 case DW_FORM_block4
:
14650 case DW_FORM_block
:
14651 case DW_FORM_block1
:
14652 fprintf_unfiltered (f
, "block: size %d",
14653 DW_BLOCK (&die
->attrs
[i
])->size
);
14655 case DW_FORM_exprloc
:
14656 fprintf_unfiltered (f
, "expression: size %u",
14657 DW_BLOCK (&die
->attrs
[i
])->size
);
14659 case DW_FORM_ref_addr
:
14660 fprintf_unfiltered (f
, "ref address: ");
14661 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14667 case DW_FORM_ref_udata
:
14668 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14669 (long) (DW_UNSND (&die
->attrs
[i
])));
14671 case DW_FORM_data1
:
14672 case DW_FORM_data2
:
14673 case DW_FORM_data4
:
14674 case DW_FORM_data8
:
14675 case DW_FORM_udata
:
14676 case DW_FORM_sdata
:
14677 fprintf_unfiltered (f
, "constant: %s",
14678 pulongest (DW_UNSND (&die
->attrs
[i
])));
14680 case DW_FORM_sec_offset
:
14681 fprintf_unfiltered (f
, "section offset: %s",
14682 pulongest (DW_UNSND (&die
->attrs
[i
])));
14684 case DW_FORM_ref_sig8
:
14685 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14686 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14687 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14689 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14691 case DW_FORM_string
:
14693 case DW_FORM_GNU_str_index
:
14694 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14695 DW_STRING (&die
->attrs
[i
])
14696 ? DW_STRING (&die
->attrs
[i
]) : "",
14697 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14700 if (DW_UNSND (&die
->attrs
[i
]))
14701 fprintf_unfiltered (f
, "flag: TRUE");
14703 fprintf_unfiltered (f
, "flag: FALSE");
14705 case DW_FORM_flag_present
:
14706 fprintf_unfiltered (f
, "flag: TRUE");
14708 case DW_FORM_indirect
:
14709 /* The reader will have reduced the indirect form to
14710 the "base form" so this form should not occur. */
14711 fprintf_unfiltered (f
,
14712 "unexpected attribute form: DW_FORM_indirect");
14715 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14716 die
->attrs
[i
].form
);
14719 fprintf_unfiltered (f
, "\n");
14724 dump_die_for_error (struct die_info
*die
)
14726 dump_die_shallow (gdb_stderr
, 0, die
);
14730 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14732 int indent
= level
* 4;
14734 gdb_assert (die
!= NULL
);
14736 if (level
>= max_level
)
14739 dump_die_shallow (f
, indent
, die
);
14741 if (die
->child
!= NULL
)
14743 print_spaces (indent
, f
);
14744 fprintf_unfiltered (f
, " Children:");
14745 if (level
+ 1 < max_level
)
14747 fprintf_unfiltered (f
, "\n");
14748 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14752 fprintf_unfiltered (f
,
14753 " [not printed, max nesting level reached]\n");
14757 if (die
->sibling
!= NULL
&& level
> 0)
14759 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14763 /* This is called from the pdie macro in gdbinit.in.
14764 It's not static so gcc will keep a copy callable from gdb. */
14767 dump_die (struct die_info
*die
, int max_level
)
14769 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14773 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14777 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14783 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14784 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14787 is_ref_attr (struct attribute
*attr
)
14789 switch (attr
->form
)
14791 case DW_FORM_ref_addr
:
14796 case DW_FORM_ref_udata
:
14803 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14807 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14809 sect_offset retval
= { DW_UNSND (attr
) };
14811 if (is_ref_attr (attr
))
14814 retval
.sect_off
= 0;
14815 complaint (&symfile_complaints
,
14816 _("unsupported die ref attribute form: '%s'"),
14817 dwarf_form_name (attr
->form
));
14821 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
14822 * the value held by the attribute is not constant. */
14825 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
14827 if (attr
->form
== DW_FORM_sdata
)
14828 return DW_SND (attr
);
14829 else if (attr
->form
== DW_FORM_udata
14830 || attr
->form
== DW_FORM_data1
14831 || attr
->form
== DW_FORM_data2
14832 || attr
->form
== DW_FORM_data4
14833 || attr
->form
== DW_FORM_data8
)
14834 return DW_UNSND (attr
);
14837 complaint (&symfile_complaints
,
14838 _("Attribute value is not a constant (%s)"),
14839 dwarf_form_name (attr
->form
));
14840 return default_value
;
14844 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
14845 unit and add it to our queue.
14846 The result is non-zero if PER_CU was queued, otherwise the result is zero
14847 meaning either PER_CU is already queued or it is already loaded. */
14850 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
14851 struct dwarf2_per_cu_data
*per_cu
,
14852 enum language pretend_language
)
14854 /* We may arrive here during partial symbol reading, if we need full
14855 DIEs to process an unusual case (e.g. template arguments). Do
14856 not queue PER_CU, just tell our caller to load its DIEs. */
14857 if (dwarf2_per_objfile
->reading_partial_symbols
)
14859 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
14864 /* Mark the dependence relation so that we don't flush PER_CU
14866 dwarf2_add_dependence (this_cu
, per_cu
);
14868 /* If it's already on the queue, we have nothing to do. */
14869 if (per_cu
->queued
)
14872 /* If the compilation unit is already loaded, just mark it as
14874 if (per_cu
->cu
!= NULL
)
14876 per_cu
->cu
->last_used
= 0;
14880 /* Add it to the queue. */
14881 queue_comp_unit (per_cu
, pretend_language
);
14886 /* Follow reference or signature attribute ATTR of SRC_DIE.
14887 On entry *REF_CU is the CU of SRC_DIE.
14888 On exit *REF_CU is the CU of the result. */
14890 static struct die_info
*
14891 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
14892 struct dwarf2_cu
**ref_cu
)
14894 struct die_info
*die
;
14896 if (is_ref_attr (attr
))
14897 die
= follow_die_ref (src_die
, attr
, ref_cu
);
14898 else if (attr
->form
== DW_FORM_ref_sig8
)
14899 die
= follow_die_sig (src_die
, attr
, ref_cu
);
14902 dump_die_for_error (src_die
);
14903 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
14904 (*ref_cu
)->objfile
->name
);
14910 /* Follow reference OFFSET.
14911 On entry *REF_CU is the CU of the source die referencing OFFSET.
14912 On exit *REF_CU is the CU of the result.
14913 Returns NULL if OFFSET is invalid. */
14915 static struct die_info
*
14916 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
14918 struct die_info temp_die
;
14919 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
14921 gdb_assert (cu
->per_cu
!= NULL
);
14925 if (cu
->per_cu
->is_debug_types
)
14927 /* .debug_types CUs cannot reference anything outside their CU.
14928 If they need to, they have to reference a signatured type via
14929 DW_FORM_ref_sig8. */
14930 if (! offset_in_cu_p (&cu
->header
, offset
))
14933 else if (! offset_in_cu_p (&cu
->header
, offset
))
14935 struct dwarf2_per_cu_data
*per_cu
;
14937 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
14939 /* If necessary, add it to the queue and load its DIEs. */
14940 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
14941 load_full_comp_unit (per_cu
, cu
->language
);
14943 target_cu
= per_cu
->cu
;
14945 else if (cu
->dies
== NULL
)
14947 /* We're loading full DIEs during partial symbol reading. */
14948 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
14949 load_full_comp_unit (cu
->per_cu
, language_minimal
);
14952 *ref_cu
= target_cu
;
14953 temp_die
.offset
= offset
;
14954 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
14957 /* Follow reference attribute ATTR of SRC_DIE.
14958 On entry *REF_CU is the CU of SRC_DIE.
14959 On exit *REF_CU is the CU of the result. */
14961 static struct die_info
*
14962 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
14963 struct dwarf2_cu
**ref_cu
)
14965 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14966 struct dwarf2_cu
*cu
= *ref_cu
;
14967 struct die_info
*die
;
14969 die
= follow_die_offset (offset
, ref_cu
);
14971 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
14972 "at 0x%x [in module %s]"),
14973 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
14978 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
14979 Returned value is intended for DW_OP_call*. Returned
14980 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
14982 struct dwarf2_locexpr_baton
14983 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
14984 struct dwarf2_per_cu_data
*per_cu
,
14985 CORE_ADDR (*get_frame_pc
) (void *baton
),
14988 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
14989 struct dwarf2_cu
*cu
;
14990 struct die_info
*die
;
14991 struct attribute
*attr
;
14992 struct dwarf2_locexpr_baton retval
;
14994 dw2_setup (per_cu
->objfile
);
14996 if (per_cu
->cu
== NULL
)
15000 die
= follow_die_offset (offset
, &cu
);
15002 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15003 offset
.sect_off
, per_cu
->objfile
->name
);
15005 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15008 /* DWARF: "If there is no such attribute, then there is no effect.".
15009 DATA is ignored if SIZE is 0. */
15011 retval
.data
= NULL
;
15014 else if (attr_form_is_section_offset (attr
))
15016 struct dwarf2_loclist_baton loclist_baton
;
15017 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15020 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15022 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15024 retval
.size
= size
;
15028 if (!attr_form_is_block (attr
))
15029 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15030 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15031 offset
.sect_off
, per_cu
->objfile
->name
);
15033 retval
.data
= DW_BLOCK (attr
)->data
;
15034 retval
.size
= DW_BLOCK (attr
)->size
;
15036 retval
.per_cu
= cu
->per_cu
;
15038 age_cached_comp_units ();
15043 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15047 dwarf2_get_die_type (cu_offset die_offset
,
15048 struct dwarf2_per_cu_data
*per_cu
)
15050 sect_offset die_offset_sect
;
15052 dw2_setup (per_cu
->objfile
);
15054 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15055 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15058 /* Follow the signature attribute ATTR in SRC_DIE.
15059 On entry *REF_CU is the CU of SRC_DIE.
15060 On exit *REF_CU is the CU of the result. */
15062 static struct die_info
*
15063 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15064 struct dwarf2_cu
**ref_cu
)
15066 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15067 struct die_info temp_die
;
15068 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15069 struct dwarf2_cu
*sig_cu
;
15070 struct die_info
*die
;
15072 /* sig_type will be NULL if the signatured type is missing from
15074 if (sig_type
== NULL
)
15075 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15076 "at 0x%x [in module %s]"),
15077 src_die
->offset
.sect_off
, objfile
->name
);
15079 /* If necessary, add it to the queue and load its DIEs. */
15081 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15082 read_signatured_type (sig_type
);
15084 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15086 sig_cu
= sig_type
->per_cu
.cu
;
15087 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15088 temp_die
.offset
= sig_type
->type_offset_in_section
;
15089 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15090 temp_die
.offset
.sect_off
);
15097 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15098 "from DIE at 0x%x [in module %s]"),
15099 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15102 /* Given an offset of a signatured type, return its signatured_type. */
15104 static struct signatured_type
*
15105 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15106 struct dwarf2_section_info
*section
,
15107 sect_offset offset
)
15109 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15110 unsigned int length
, initial_length_size
;
15111 unsigned int sig_offset
;
15112 struct signatured_type find_entry
, *sig_type
;
15114 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15115 sig_offset
= (initial_length_size
15117 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15118 + 1 /*address_size*/);
15119 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15120 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15122 /* This is only used to lookup previously recorded types.
15123 If we didn't find it, it's our bug. */
15124 gdb_assert (sig_type
!= NULL
);
15125 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15130 /* Load the DIEs associated with type unit PER_CU into memory. */
15133 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15135 struct objfile
*objfile
= per_cu
->objfile
;
15136 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15137 sect_offset offset
= per_cu
->offset
;
15138 struct signatured_type
*sig_type
;
15140 dwarf2_read_section (objfile
, sect
);
15142 /* We have the section offset, but we need the signature to do the
15143 hash table lookup. */
15144 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15145 the signature to assert we found the right one.
15146 Ok, but it's a lot of work. We should simplify things so any needed
15147 assert doesn't require all this clumsiness. */
15148 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15150 gdb_assert (&sig_type
->per_cu
== per_cu
);
15151 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15153 read_signatured_type (sig_type
);
15155 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15158 /* die_reader_func for read_signatured_type.
15159 This is identical to load_full_comp_unit_reader,
15160 but is kept separate for now. */
15163 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15164 gdb_byte
*info_ptr
,
15165 struct die_info
*comp_unit_die
,
15169 struct dwarf2_cu
*cu
= reader
->cu
;
15171 gdb_assert (cu
->die_hash
== NULL
);
15173 htab_create_alloc_ex (cu
->header
.length
/ 12,
15177 &cu
->comp_unit_obstack
,
15178 hashtab_obstack_allocate
,
15179 dummy_obstack_deallocate
);
15182 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15183 &info_ptr
, comp_unit_die
);
15184 cu
->dies
= comp_unit_die
;
15185 /* comp_unit_die is not stored in die_hash, no need. */
15187 /* We try not to read any attributes in this function, because not
15188 all CUs needed for references have been loaded yet, and symbol
15189 table processing isn't initialized. But we have to set the CU language,
15190 or we won't be able to build types correctly.
15191 Similarly, if we do not read the producer, we can not apply
15192 producer-specific interpretation. */
15193 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15196 /* Read in a signatured type and build its CU and DIEs.
15197 If the type is a stub for the real type in a DWO file,
15198 read in the real type from the DWO file as well. */
15201 read_signatured_type (struct signatured_type
*sig_type
)
15203 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15205 gdb_assert (per_cu
->is_debug_types
);
15206 gdb_assert (per_cu
->cu
== NULL
);
15208 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15211 /* Decode simple location descriptions.
15212 Given a pointer to a dwarf block that defines a location, compute
15213 the location and return the value.
15215 NOTE drow/2003-11-18: This function is called in two situations
15216 now: for the address of static or global variables (partial symbols
15217 only) and for offsets into structures which are expected to be
15218 (more or less) constant. The partial symbol case should go away,
15219 and only the constant case should remain. That will let this
15220 function complain more accurately. A few special modes are allowed
15221 without complaint for global variables (for instance, global
15222 register values and thread-local values).
15224 A location description containing no operations indicates that the
15225 object is optimized out. The return value is 0 for that case.
15226 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15227 callers will only want a very basic result and this can become a
15230 Note that stack[0] is unused except as a default error return. */
15233 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15235 struct objfile
*objfile
= cu
->objfile
;
15237 int size
= blk
->size
;
15238 gdb_byte
*data
= blk
->data
;
15239 CORE_ADDR stack
[64];
15241 unsigned int bytes_read
, unsnd
;
15247 stack
[++stacki
] = 0;
15286 stack
[++stacki
] = op
- DW_OP_lit0
;
15321 stack
[++stacki
] = op
- DW_OP_reg0
;
15323 dwarf2_complex_location_expr_complaint ();
15327 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15329 stack
[++stacki
] = unsnd
;
15331 dwarf2_complex_location_expr_complaint ();
15335 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15340 case DW_OP_const1u
:
15341 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15345 case DW_OP_const1s
:
15346 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15350 case DW_OP_const2u
:
15351 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15355 case DW_OP_const2s
:
15356 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15360 case DW_OP_const4u
:
15361 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15365 case DW_OP_const4s
:
15366 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15370 case DW_OP_const8u
:
15371 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15376 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15382 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15387 stack
[stacki
+ 1] = stack
[stacki
];
15392 stack
[stacki
- 1] += stack
[stacki
];
15396 case DW_OP_plus_uconst
:
15397 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15403 stack
[stacki
- 1] -= stack
[stacki
];
15408 /* If we're not the last op, then we definitely can't encode
15409 this using GDB's address_class enum. This is valid for partial
15410 global symbols, although the variable's address will be bogus
15413 dwarf2_complex_location_expr_complaint ();
15416 case DW_OP_GNU_push_tls_address
:
15417 /* The top of the stack has the offset from the beginning
15418 of the thread control block at which the variable is located. */
15419 /* Nothing should follow this operator, so the top of stack would
15421 /* This is valid for partial global symbols, but the variable's
15422 address will be bogus in the psymtab. Make it always at least
15423 non-zero to not look as a variable garbage collected by linker
15424 which have DW_OP_addr 0. */
15426 dwarf2_complex_location_expr_complaint ();
15430 case DW_OP_GNU_uninit
:
15433 case DW_OP_GNU_addr_index
:
15434 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15441 const char *name
= get_DW_OP_name (op
);
15444 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15447 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15451 return (stack
[stacki
]);
15454 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15455 outside of the allocated space. Also enforce minimum>0. */
15456 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15458 complaint (&symfile_complaints
,
15459 _("location description stack overflow"));
15465 complaint (&symfile_complaints
,
15466 _("location description stack underflow"));
15470 return (stack
[stacki
]);
15473 /* memory allocation interface */
15475 static struct dwarf_block
*
15476 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15478 struct dwarf_block
*blk
;
15480 blk
= (struct dwarf_block
*)
15481 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15485 static struct abbrev_info
*
15486 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15488 struct abbrev_info
*abbrev
;
15490 abbrev
= (struct abbrev_info
*)
15491 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15492 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15496 static struct die_info
*
15497 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15499 struct die_info
*die
;
15500 size_t size
= sizeof (struct die_info
);
15503 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15505 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15506 memset (die
, 0, sizeof (struct die_info
));
15511 /* Macro support. */
15513 /* Return the full name of file number I in *LH's file name table.
15514 Use COMP_DIR as the name of the current directory of the
15515 compilation. The result is allocated using xmalloc; the caller is
15516 responsible for freeing it. */
15518 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15520 /* Is the file number a valid index into the line header's file name
15521 table? Remember that file numbers start with one, not zero. */
15522 if (1 <= file
&& file
<= lh
->num_file_names
)
15524 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15526 if (IS_ABSOLUTE_PATH (fe
->name
))
15527 return xstrdup (fe
->name
);
15535 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15541 dir_len
= strlen (dir
);
15542 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15543 strcpy (full_name
, dir
);
15544 full_name
[dir_len
] = '/';
15545 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15549 return xstrdup (fe
->name
);
15554 /* The compiler produced a bogus file number. We can at least
15555 record the macro definitions made in the file, even if we
15556 won't be able to find the file by name. */
15557 char fake_name
[80];
15559 sprintf (fake_name
, "<bad macro file number %d>", file
);
15561 complaint (&symfile_complaints
,
15562 _("bad file number in macro information (%d)"),
15565 return xstrdup (fake_name
);
15570 static struct macro_source_file
*
15571 macro_start_file (int file
, int line
,
15572 struct macro_source_file
*current_file
,
15573 const char *comp_dir
,
15574 struct line_header
*lh
, struct objfile
*objfile
)
15576 /* The full name of this source file. */
15577 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15579 /* We don't create a macro table for this compilation unit
15580 at all until we actually get a filename. */
15581 if (! pending_macros
)
15582 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15583 objfile
->macro_cache
);
15585 if (! current_file
)
15587 /* If we have no current file, then this must be the start_file
15588 directive for the compilation unit's main source file. */
15589 current_file
= macro_set_main (pending_macros
, full_name
);
15590 macro_define_special (pending_macros
);
15593 current_file
= macro_include (current_file
, line
, full_name
);
15597 return current_file
;
15601 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15602 followed by a null byte. */
15604 copy_string (const char *buf
, int len
)
15606 char *s
= xmalloc (len
+ 1);
15608 memcpy (s
, buf
, len
);
15614 static const char *
15615 consume_improper_spaces (const char *p
, const char *body
)
15619 complaint (&symfile_complaints
,
15620 _("macro definition contains spaces "
15621 "in formal argument list:\n`%s'"),
15633 parse_macro_definition (struct macro_source_file
*file
, int line
,
15638 /* The body string takes one of two forms. For object-like macro
15639 definitions, it should be:
15641 <macro name> " " <definition>
15643 For function-like macro definitions, it should be:
15645 <macro name> "() " <definition>
15647 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15649 Spaces may appear only where explicitly indicated, and in the
15652 The Dwarf 2 spec says that an object-like macro's name is always
15653 followed by a space, but versions of GCC around March 2002 omit
15654 the space when the macro's definition is the empty string.
15656 The Dwarf 2 spec says that there should be no spaces between the
15657 formal arguments in a function-like macro's formal argument list,
15658 but versions of GCC around March 2002 include spaces after the
15662 /* Find the extent of the macro name. The macro name is terminated
15663 by either a space or null character (for an object-like macro) or
15664 an opening paren (for a function-like macro). */
15665 for (p
= body
; *p
; p
++)
15666 if (*p
== ' ' || *p
== '(')
15669 if (*p
== ' ' || *p
== '\0')
15671 /* It's an object-like macro. */
15672 int name_len
= p
- body
;
15673 char *name
= copy_string (body
, name_len
);
15674 const char *replacement
;
15677 replacement
= body
+ name_len
+ 1;
15680 dwarf2_macro_malformed_definition_complaint (body
);
15681 replacement
= body
+ name_len
;
15684 macro_define_object (file
, line
, name
, replacement
);
15688 else if (*p
== '(')
15690 /* It's a function-like macro. */
15691 char *name
= copy_string (body
, p
- body
);
15694 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15698 p
= consume_improper_spaces (p
, body
);
15700 /* Parse the formal argument list. */
15701 while (*p
&& *p
!= ')')
15703 /* Find the extent of the current argument name. */
15704 const char *arg_start
= p
;
15706 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15709 if (! *p
|| p
== arg_start
)
15710 dwarf2_macro_malformed_definition_complaint (body
);
15713 /* Make sure argv has room for the new argument. */
15714 if (argc
>= argv_size
)
15717 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15720 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15723 p
= consume_improper_spaces (p
, body
);
15725 /* Consume the comma, if present. */
15730 p
= consume_improper_spaces (p
, body
);
15739 /* Perfectly formed definition, no complaints. */
15740 macro_define_function (file
, line
, name
,
15741 argc
, (const char **) argv
,
15743 else if (*p
== '\0')
15745 /* Complain, but do define it. */
15746 dwarf2_macro_malformed_definition_complaint (body
);
15747 macro_define_function (file
, line
, name
,
15748 argc
, (const char **) argv
,
15752 /* Just complain. */
15753 dwarf2_macro_malformed_definition_complaint (body
);
15756 /* Just complain. */
15757 dwarf2_macro_malformed_definition_complaint (body
);
15763 for (i
= 0; i
< argc
; i
++)
15769 dwarf2_macro_malformed_definition_complaint (body
);
15772 /* Skip some bytes from BYTES according to the form given in FORM.
15773 Returns the new pointer. */
15776 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
15777 enum dwarf_form form
,
15778 unsigned int offset_size
,
15779 struct dwarf2_section_info
*section
)
15781 unsigned int bytes_read
;
15785 case DW_FORM_data1
:
15790 case DW_FORM_data2
:
15794 case DW_FORM_data4
:
15798 case DW_FORM_data8
:
15802 case DW_FORM_string
:
15803 read_direct_string (abfd
, bytes
, &bytes_read
);
15804 bytes
+= bytes_read
;
15807 case DW_FORM_sec_offset
:
15809 bytes
+= offset_size
;
15812 case DW_FORM_block
:
15813 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15814 bytes
+= bytes_read
;
15817 case DW_FORM_block1
:
15818 bytes
+= 1 + read_1_byte (abfd
, bytes
);
15820 case DW_FORM_block2
:
15821 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
15823 case DW_FORM_block4
:
15824 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
15827 case DW_FORM_sdata
:
15828 case DW_FORM_udata
:
15829 case DW_FORM_GNU_addr_index
:
15830 case DW_FORM_GNU_str_index
:
15831 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
15834 dwarf2_section_buffer_overflow_complaint (section
);
15842 complaint (&symfile_complaints
,
15843 _("invalid form 0x%x in `%s'"),
15845 section
->asection
->name
);
15853 /* A helper for dwarf_decode_macros that handles skipping an unknown
15854 opcode. Returns an updated pointer to the macro data buffer; or,
15855 on error, issues a complaint and returns NULL. */
15858 skip_unknown_opcode (unsigned int opcode
,
15859 gdb_byte
**opcode_definitions
,
15860 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15862 unsigned int offset_size
,
15863 struct dwarf2_section_info
*section
)
15865 unsigned int bytes_read
, i
;
15869 if (opcode_definitions
[opcode
] == NULL
)
15871 complaint (&symfile_complaints
,
15872 _("unrecognized DW_MACFINO opcode 0x%x"),
15877 defn
= opcode_definitions
[opcode
];
15878 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
15879 defn
+= bytes_read
;
15881 for (i
= 0; i
< arg
; ++i
)
15883 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
15885 if (mac_ptr
== NULL
)
15887 /* skip_form_bytes already issued the complaint. */
15895 /* A helper function which parses the header of a macro section.
15896 If the macro section is the extended (for now called "GNU") type,
15897 then this updates *OFFSET_SIZE. Returns a pointer to just after
15898 the header, or issues a complaint and returns NULL on error. */
15901 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
15904 unsigned int *offset_size
,
15905 int section_is_gnu
)
15907 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
15909 if (section_is_gnu
)
15911 unsigned int version
, flags
;
15913 version
= read_2_bytes (abfd
, mac_ptr
);
15916 complaint (&symfile_complaints
,
15917 _("unrecognized version `%d' in .debug_macro section"),
15923 flags
= read_1_byte (abfd
, mac_ptr
);
15925 *offset_size
= (flags
& 1) ? 8 : 4;
15927 if ((flags
& 2) != 0)
15928 /* We don't need the line table offset. */
15929 mac_ptr
+= *offset_size
;
15931 /* Vendor opcode descriptions. */
15932 if ((flags
& 4) != 0)
15934 unsigned int i
, count
;
15936 count
= read_1_byte (abfd
, mac_ptr
);
15938 for (i
= 0; i
< count
; ++i
)
15940 unsigned int opcode
, bytes_read
;
15943 opcode
= read_1_byte (abfd
, mac_ptr
);
15945 opcode_definitions
[opcode
] = mac_ptr
;
15946 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
15947 mac_ptr
+= bytes_read
;
15956 /* A helper for dwarf_decode_macros that handles the GNU extensions,
15957 including DW_MACRO_GNU_transparent_include. */
15960 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
15961 struct macro_source_file
*current_file
,
15962 struct line_header
*lh
, char *comp_dir
,
15963 struct dwarf2_section_info
*section
,
15964 int section_is_gnu
,
15965 unsigned int offset_size
,
15966 struct objfile
*objfile
,
15967 htab_t include_hash
)
15969 enum dwarf_macro_record_type macinfo_type
;
15970 int at_commandline
;
15971 gdb_byte
*opcode_definitions
[256];
15973 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
15974 &offset_size
, section_is_gnu
);
15975 if (mac_ptr
== NULL
)
15977 /* We already issued a complaint. */
15981 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
15982 GDB is still reading the definitions from command line. First
15983 DW_MACINFO_start_file will need to be ignored as it was already executed
15984 to create CURRENT_FILE for the main source holding also the command line
15985 definitions. On first met DW_MACINFO_start_file this flag is reset to
15986 normally execute all the remaining DW_MACINFO_start_file macinfos. */
15988 at_commandline
= 1;
15992 /* Do we at least have room for a macinfo type byte? */
15993 if (mac_ptr
>= mac_end
)
15995 dwarf2_section_buffer_overflow_complaint (section
);
15999 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16002 /* Note that we rely on the fact that the corresponding GNU and
16003 DWARF constants are the same. */
16004 switch (macinfo_type
)
16006 /* A zero macinfo type indicates the end of the macro
16011 case DW_MACRO_GNU_define
:
16012 case DW_MACRO_GNU_undef
:
16013 case DW_MACRO_GNU_define_indirect
:
16014 case DW_MACRO_GNU_undef_indirect
:
16016 unsigned int bytes_read
;
16021 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16022 mac_ptr
+= bytes_read
;
16024 if (macinfo_type
== DW_MACRO_GNU_define
16025 || macinfo_type
== DW_MACRO_GNU_undef
)
16027 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16028 mac_ptr
+= bytes_read
;
16032 LONGEST str_offset
;
16034 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16035 mac_ptr
+= offset_size
;
16037 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16040 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16041 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16042 if (! current_file
)
16044 /* DWARF violation as no main source is present. */
16045 complaint (&symfile_complaints
,
16046 _("debug info with no main source gives macro %s "
16048 is_define
? _("definition") : _("undefinition"),
16052 if ((line
== 0 && !at_commandline
)
16053 || (line
!= 0 && at_commandline
))
16054 complaint (&symfile_complaints
,
16055 _("debug info gives %s macro %s with %s line %d: %s"),
16056 at_commandline
? _("command-line") : _("in-file"),
16057 is_define
? _("definition") : _("undefinition"),
16058 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16061 parse_macro_definition (current_file
, line
, body
);
16064 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16065 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16066 macro_undef (current_file
, line
, body
);
16071 case DW_MACRO_GNU_start_file
:
16073 unsigned int bytes_read
;
16076 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16077 mac_ptr
+= bytes_read
;
16078 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16079 mac_ptr
+= bytes_read
;
16081 if ((line
== 0 && !at_commandline
)
16082 || (line
!= 0 && at_commandline
))
16083 complaint (&symfile_complaints
,
16084 _("debug info gives source %d included "
16085 "from %s at %s line %d"),
16086 file
, at_commandline
? _("command-line") : _("file"),
16087 line
== 0 ? _("zero") : _("non-zero"), line
);
16089 if (at_commandline
)
16091 /* This DW_MACRO_GNU_start_file was executed in the
16093 at_commandline
= 0;
16096 current_file
= macro_start_file (file
, line
,
16097 current_file
, comp_dir
,
16102 case DW_MACRO_GNU_end_file
:
16103 if (! current_file
)
16104 complaint (&symfile_complaints
,
16105 _("macro debug info has an unmatched "
16106 "`close_file' directive"));
16109 current_file
= current_file
->included_by
;
16110 if (! current_file
)
16112 enum dwarf_macro_record_type next_type
;
16114 /* GCC circa March 2002 doesn't produce the zero
16115 type byte marking the end of the compilation
16116 unit. Complain if it's not there, but exit no
16119 /* Do we at least have room for a macinfo type byte? */
16120 if (mac_ptr
>= mac_end
)
16122 dwarf2_section_buffer_overflow_complaint (section
);
16126 /* We don't increment mac_ptr here, so this is just
16128 next_type
= read_1_byte (abfd
, mac_ptr
);
16129 if (next_type
!= 0)
16130 complaint (&symfile_complaints
,
16131 _("no terminating 0-type entry for "
16132 "macros in `.debug_macinfo' section"));
16139 case DW_MACRO_GNU_transparent_include
:
16144 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16145 mac_ptr
+= offset_size
;
16147 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16150 /* This has actually happened; see
16151 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16152 complaint (&symfile_complaints
,
16153 _("recursive DW_MACRO_GNU_transparent_include in "
16154 ".debug_macro section"));
16160 dwarf_decode_macro_bytes (abfd
,
16161 section
->buffer
+ offset
,
16162 mac_end
, current_file
,
16164 section
, section_is_gnu
,
16165 offset_size
, objfile
, include_hash
);
16167 htab_remove_elt (include_hash
, mac_ptr
);
16172 case DW_MACINFO_vendor_ext
:
16173 if (!section_is_gnu
)
16175 unsigned int bytes_read
;
16178 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16179 mac_ptr
+= bytes_read
;
16180 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16181 mac_ptr
+= bytes_read
;
16183 /* We don't recognize any vendor extensions. */
16189 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16190 mac_ptr
, mac_end
, abfd
, offset_size
,
16192 if (mac_ptr
== NULL
)
16196 } while (macinfo_type
!= 0);
16200 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
16201 char *comp_dir
, bfd
*abfd
,
16202 struct dwarf2_cu
*cu
,
16203 struct dwarf2_section_info
*section
,
16204 int section_is_gnu
, const char *section_name
)
16206 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16207 gdb_byte
*mac_ptr
, *mac_end
;
16208 struct macro_source_file
*current_file
= 0;
16209 enum dwarf_macro_record_type macinfo_type
;
16210 unsigned int offset_size
= cu
->header
.offset_size
;
16211 gdb_byte
*opcode_definitions
[256];
16212 struct cleanup
*cleanup
;
16213 htab_t include_hash
;
16216 dwarf2_read_section (objfile
, section
);
16217 if (section
->buffer
== NULL
)
16219 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16223 /* First pass: Find the name of the base filename.
16224 This filename is needed in order to process all macros whose definition
16225 (or undefinition) comes from the command line. These macros are defined
16226 before the first DW_MACINFO_start_file entry, and yet still need to be
16227 associated to the base file.
16229 To determine the base file name, we scan the macro definitions until we
16230 reach the first DW_MACINFO_start_file entry. We then initialize
16231 CURRENT_FILE accordingly so that any macro definition found before the
16232 first DW_MACINFO_start_file can still be associated to the base file. */
16234 mac_ptr
= section
->buffer
+ offset
;
16235 mac_end
= section
->buffer
+ section
->size
;
16237 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16238 &offset_size
, section_is_gnu
);
16239 if (mac_ptr
== NULL
)
16241 /* We already issued a complaint. */
16247 /* Do we at least have room for a macinfo type byte? */
16248 if (mac_ptr
>= mac_end
)
16250 /* Complaint is printed during the second pass as GDB will probably
16251 stop the first pass earlier upon finding
16252 DW_MACINFO_start_file. */
16256 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16259 /* Note that we rely on the fact that the corresponding GNU and
16260 DWARF constants are the same. */
16261 switch (macinfo_type
)
16263 /* A zero macinfo type indicates the end of the macro
16268 case DW_MACRO_GNU_define
:
16269 case DW_MACRO_GNU_undef
:
16270 /* Only skip the data by MAC_PTR. */
16272 unsigned int bytes_read
;
16274 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16275 mac_ptr
+= bytes_read
;
16276 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16277 mac_ptr
+= bytes_read
;
16281 case DW_MACRO_GNU_start_file
:
16283 unsigned int bytes_read
;
16286 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16287 mac_ptr
+= bytes_read
;
16288 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16289 mac_ptr
+= bytes_read
;
16291 current_file
= macro_start_file (file
, line
, current_file
,
16292 comp_dir
, lh
, objfile
);
16296 case DW_MACRO_GNU_end_file
:
16297 /* No data to skip by MAC_PTR. */
16300 case DW_MACRO_GNU_define_indirect
:
16301 case DW_MACRO_GNU_undef_indirect
:
16303 unsigned int bytes_read
;
16305 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16306 mac_ptr
+= bytes_read
;
16307 mac_ptr
+= offset_size
;
16311 case DW_MACRO_GNU_transparent_include
:
16312 /* Note that, according to the spec, a transparent include
16313 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16314 skip this opcode. */
16315 mac_ptr
+= offset_size
;
16318 case DW_MACINFO_vendor_ext
:
16319 /* Only skip the data by MAC_PTR. */
16320 if (!section_is_gnu
)
16322 unsigned int bytes_read
;
16324 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16325 mac_ptr
+= bytes_read
;
16326 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16327 mac_ptr
+= bytes_read
;
16332 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16333 mac_ptr
, mac_end
, abfd
, offset_size
,
16335 if (mac_ptr
== NULL
)
16339 } while (macinfo_type
!= 0 && current_file
== NULL
);
16341 /* Second pass: Process all entries.
16343 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16344 command-line macro definitions/undefinitions. This flag is unset when we
16345 reach the first DW_MACINFO_start_file entry. */
16347 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16348 NULL
, xcalloc
, xfree
);
16349 cleanup
= make_cleanup_htab_delete (include_hash
);
16350 mac_ptr
= section
->buffer
+ offset
;
16351 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16353 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16354 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16355 offset_size
, objfile
, include_hash
);
16356 do_cleanups (cleanup
);
16359 /* Check if the attribute's form is a DW_FORM_block*
16360 if so return true else false. */
16363 attr_form_is_block (struct attribute
*attr
)
16365 return (attr
== NULL
? 0 :
16366 attr
->form
== DW_FORM_block1
16367 || attr
->form
== DW_FORM_block2
16368 || attr
->form
== DW_FORM_block4
16369 || attr
->form
== DW_FORM_block
16370 || attr
->form
== DW_FORM_exprloc
);
16373 /* Return non-zero if ATTR's value is a section offset --- classes
16374 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16375 You may use DW_UNSND (attr) to retrieve such offsets.
16377 Section 7.5.4, "Attribute Encodings", explains that no attribute
16378 may have a value that belongs to more than one of these classes; it
16379 would be ambiguous if we did, because we use the same forms for all
16383 attr_form_is_section_offset (struct attribute
*attr
)
16385 return (attr
->form
== DW_FORM_data4
16386 || attr
->form
== DW_FORM_data8
16387 || attr
->form
== DW_FORM_sec_offset
);
16390 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16391 zero otherwise. When this function returns true, you can apply
16392 dwarf2_get_attr_constant_value to it.
16394 However, note that for some attributes you must check
16395 attr_form_is_section_offset before using this test. DW_FORM_data4
16396 and DW_FORM_data8 are members of both the constant class, and of
16397 the classes that contain offsets into other debug sections
16398 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16399 that, if an attribute's can be either a constant or one of the
16400 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16401 taken as section offsets, not constants. */
16404 attr_form_is_constant (struct attribute
*attr
)
16406 switch (attr
->form
)
16408 case DW_FORM_sdata
:
16409 case DW_FORM_udata
:
16410 case DW_FORM_data1
:
16411 case DW_FORM_data2
:
16412 case DW_FORM_data4
:
16413 case DW_FORM_data8
:
16420 /* Return the .debug_loc section to use for CU.
16421 For DWO files use .debug_loc.dwo. */
16423 static struct dwarf2_section_info
*
16424 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16427 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16428 return &dwarf2_per_objfile
->loc
;
16431 /* A helper function that fills in a dwarf2_loclist_baton. */
16434 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16435 struct dwarf2_loclist_baton
*baton
,
16436 struct attribute
*attr
)
16438 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16440 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16442 baton
->per_cu
= cu
->per_cu
;
16443 gdb_assert (baton
->per_cu
);
16444 /* We don't know how long the location list is, but make sure we
16445 don't run off the edge of the section. */
16446 baton
->size
= section
->size
- DW_UNSND (attr
);
16447 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16448 baton
->base_address
= cu
->base_address
;
16449 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16453 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16454 struct dwarf2_cu
*cu
)
16456 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16457 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16459 if (attr_form_is_section_offset (attr
)
16460 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16461 the section. If so, fall through to the complaint in the
16463 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16465 struct dwarf2_loclist_baton
*baton
;
16467 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16468 sizeof (struct dwarf2_loclist_baton
));
16470 fill_in_loclist_baton (cu
, baton
, attr
);
16472 if (cu
->base_known
== 0)
16473 complaint (&symfile_complaints
,
16474 _("Location list used without "
16475 "specifying the CU base address."));
16477 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16478 SYMBOL_LOCATION_BATON (sym
) = baton
;
16482 struct dwarf2_locexpr_baton
*baton
;
16484 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16485 sizeof (struct dwarf2_locexpr_baton
));
16486 baton
->per_cu
= cu
->per_cu
;
16487 gdb_assert (baton
->per_cu
);
16489 if (attr_form_is_block (attr
))
16491 /* Note that we're just copying the block's data pointer
16492 here, not the actual data. We're still pointing into the
16493 info_buffer for SYM's objfile; right now we never release
16494 that buffer, but when we do clean up properly this may
16496 baton
->size
= DW_BLOCK (attr
)->size
;
16497 baton
->data
= DW_BLOCK (attr
)->data
;
16501 dwarf2_invalid_attrib_class_complaint ("location description",
16502 SYMBOL_NATURAL_NAME (sym
));
16506 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16507 SYMBOL_LOCATION_BATON (sym
) = baton
;
16511 /* Return the OBJFILE associated with the compilation unit CU. If CU
16512 came from a separate debuginfo file, then the master objfile is
16516 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16518 struct objfile
*objfile
= per_cu
->objfile
;
16520 /* Return the master objfile, so that we can report and look up the
16521 correct file containing this variable. */
16522 if (objfile
->separate_debug_objfile_backlink
)
16523 objfile
= objfile
->separate_debug_objfile_backlink
;
16528 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16529 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16530 CU_HEADERP first. */
16532 static const struct comp_unit_head
*
16533 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16534 struct dwarf2_per_cu_data
*per_cu
)
16536 struct objfile
*objfile
;
16537 struct dwarf2_per_objfile
*per_objfile
;
16538 gdb_byte
*info_ptr
;
16541 return &per_cu
->cu
->header
;
16543 objfile
= per_cu
->objfile
;
16544 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16545 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16547 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16548 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16553 /* Return the address size given in the compilation unit header for CU. */
16556 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16558 struct comp_unit_head cu_header_local
;
16559 const struct comp_unit_head
*cu_headerp
;
16561 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16563 return cu_headerp
->addr_size
;
16566 /* Return the offset size given in the compilation unit header for CU. */
16569 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16571 struct comp_unit_head cu_header_local
;
16572 const struct comp_unit_head
*cu_headerp
;
16574 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16576 return cu_headerp
->offset_size
;
16579 /* See its dwarf2loc.h declaration. */
16582 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16584 struct comp_unit_head cu_header_local
;
16585 const struct comp_unit_head
*cu_headerp
;
16587 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16589 if (cu_headerp
->version
== 2)
16590 return cu_headerp
->addr_size
;
16592 return cu_headerp
->offset_size
;
16595 /* Return the text offset of the CU. The returned offset comes from
16596 this CU's objfile. If this objfile came from a separate debuginfo
16597 file, then the offset may be different from the corresponding
16598 offset in the parent objfile. */
16601 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16603 struct objfile
*objfile
= per_cu
->objfile
;
16605 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16608 /* Locate the .debug_info compilation unit from CU's objfile which contains
16609 the DIE at OFFSET. Raises an error on failure. */
16611 static struct dwarf2_per_cu_data
*
16612 dwarf2_find_containing_comp_unit (sect_offset offset
,
16613 struct objfile
*objfile
)
16615 struct dwarf2_per_cu_data
*this_cu
;
16619 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16622 int mid
= low
+ (high
- low
) / 2;
16624 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16625 >= offset
.sect_off
)
16630 gdb_assert (low
== high
);
16631 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16635 error (_("Dwarf Error: could not find partial DIE containing "
16636 "offset 0x%lx [in module %s]"),
16637 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16639 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16640 <= offset
.sect_off
);
16641 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16645 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16646 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16647 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16648 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16649 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16654 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16657 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16659 memset (cu
, 0, sizeof (*cu
));
16661 cu
->per_cu
= per_cu
;
16662 cu
->objfile
= per_cu
->objfile
;
16663 obstack_init (&cu
->comp_unit_obstack
);
16666 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16669 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
16670 enum language pretend_language
)
16672 struct attribute
*attr
;
16674 /* Set the language we're debugging. */
16675 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16677 set_cu_language (DW_UNSND (attr
), cu
);
16680 cu
->language
= pretend_language
;
16681 cu
->language_defn
= language_def (cu
->language
);
16684 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16686 cu
->producer
= DW_STRING (attr
);
16689 /* Release one cached compilation unit, CU. We unlink it from the tree
16690 of compilation units, but we don't remove it from the read_in_chain;
16691 the caller is responsible for that.
16692 NOTE: DATA is a void * because this function is also used as a
16693 cleanup routine. */
16696 free_heap_comp_unit (void *data
)
16698 struct dwarf2_cu
*cu
= data
;
16700 gdb_assert (cu
->per_cu
!= NULL
);
16701 cu
->per_cu
->cu
= NULL
;
16704 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16709 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16710 when we're finished with it. We can't free the pointer itself, but be
16711 sure to unlink it from the cache. Also release any associated storage. */
16714 free_stack_comp_unit (void *data
)
16716 struct dwarf2_cu
*cu
= data
;
16718 gdb_assert (cu
->per_cu
!= NULL
);
16719 cu
->per_cu
->cu
= NULL
;
16722 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16723 cu
->partial_dies
= NULL
;
16726 /* Free all cached compilation units. */
16729 free_cached_comp_units (void *data
)
16731 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16733 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16734 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16735 while (per_cu
!= NULL
)
16737 struct dwarf2_per_cu_data
*next_cu
;
16739 next_cu
= per_cu
->cu
->read_in_chain
;
16741 free_heap_comp_unit (per_cu
->cu
);
16742 *last_chain
= next_cu
;
16748 /* Increase the age counter on each cached compilation unit, and free
16749 any that are too old. */
16752 age_cached_comp_units (void)
16754 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16756 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16757 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16758 while (per_cu
!= NULL
)
16760 per_cu
->cu
->last_used
++;
16761 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16762 dwarf2_mark (per_cu
->cu
);
16763 per_cu
= per_cu
->cu
->read_in_chain
;
16766 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16767 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16768 while (per_cu
!= NULL
)
16770 struct dwarf2_per_cu_data
*next_cu
;
16772 next_cu
= per_cu
->cu
->read_in_chain
;
16774 if (!per_cu
->cu
->mark
)
16776 free_heap_comp_unit (per_cu
->cu
);
16777 *last_chain
= next_cu
;
16780 last_chain
= &per_cu
->cu
->read_in_chain
;
16786 /* Remove a single compilation unit from the cache. */
16789 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
16791 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16793 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16794 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16795 while (per_cu
!= NULL
)
16797 struct dwarf2_per_cu_data
*next_cu
;
16799 next_cu
= per_cu
->cu
->read_in_chain
;
16801 if (per_cu
== target_per_cu
)
16803 free_heap_comp_unit (per_cu
->cu
);
16805 *last_chain
= next_cu
;
16809 last_chain
= &per_cu
->cu
->read_in_chain
;
16815 /* Release all extra memory associated with OBJFILE. */
16818 dwarf2_free_objfile (struct objfile
*objfile
)
16820 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16822 if (dwarf2_per_objfile
== NULL
)
16825 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
16826 free_cached_comp_units (NULL
);
16828 if (dwarf2_per_objfile
->quick_file_names_table
)
16829 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
16831 /* Everything else should be on the objfile obstack. */
16834 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
16835 We store these in a hash table separate from the DIEs, and preserve them
16836 when the DIEs are flushed out of cache.
16838 The CU "per_cu" pointer is needed because offset alone is not enough to
16839 uniquely identify the type. A file may have multiple .debug_types sections,
16840 or the type may come from a DWO file. We have to use something in
16841 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
16842 routine, get_die_type_at_offset, from outside this file, and thus won't
16843 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
16846 struct dwarf2_per_cu_offset_and_type
16848 const struct dwarf2_per_cu_data
*per_cu
;
16849 sect_offset offset
;
16853 /* Hash function for a dwarf2_per_cu_offset_and_type. */
16856 per_cu_offset_and_type_hash (const void *item
)
16858 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
16860 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
16863 /* Equality function for a dwarf2_per_cu_offset_and_type. */
16866 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
16868 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
16869 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
16871 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
16872 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
16875 /* Set the type associated with DIE to TYPE. Save it in CU's hash
16876 table if necessary. For convenience, return TYPE.
16878 The DIEs reading must have careful ordering to:
16879 * Not cause infite loops trying to read in DIEs as a prerequisite for
16880 reading current DIE.
16881 * Not trying to dereference contents of still incompletely read in types
16882 while reading in other DIEs.
16883 * Enable referencing still incompletely read in types just by a pointer to
16884 the type without accessing its fields.
16886 Therefore caller should follow these rules:
16887 * Try to fetch any prerequisite types we may need to build this DIE type
16888 before building the type and calling set_die_type.
16889 * After building type call set_die_type for current DIE as soon as
16890 possible before fetching more types to complete the current type.
16891 * Make the type as complete as possible before fetching more types. */
16893 static struct type
*
16894 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16896 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
16897 struct objfile
*objfile
= cu
->objfile
;
16899 /* For Ada types, make sure that the gnat-specific data is always
16900 initialized (if not already set). There are a few types where
16901 we should not be doing so, because the type-specific area is
16902 already used to hold some other piece of info (eg: TYPE_CODE_FLT
16903 where the type-specific area is used to store the floatformat).
16904 But this is not a problem, because the gnat-specific information
16905 is actually not needed for these types. */
16906 if (need_gnat_info (cu
)
16907 && TYPE_CODE (type
) != TYPE_CODE_FUNC
16908 && TYPE_CODE (type
) != TYPE_CODE_FLT
16909 && !HAVE_GNAT_AUX_INFO (type
))
16910 INIT_GNAT_SPECIFIC (type
);
16912 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16914 dwarf2_per_objfile
->die_type_hash
=
16915 htab_create_alloc_ex (127,
16916 per_cu_offset_and_type_hash
,
16917 per_cu_offset_and_type_eq
,
16919 &objfile
->objfile_obstack
,
16920 hashtab_obstack_allocate
,
16921 dummy_obstack_deallocate
);
16924 ofs
.per_cu
= cu
->per_cu
;
16925 ofs
.offset
= die
->offset
;
16927 slot
= (struct dwarf2_per_cu_offset_and_type
**)
16928 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
16930 complaint (&symfile_complaints
,
16931 _("A problem internal to GDB: DIE 0x%x has type already set"),
16932 die
->offset
.sect_off
);
16933 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
16938 /* Look up the type for the die at OFFSET in the appropriate type_hash
16939 table, or return NULL if the die does not have a saved type. */
16941 static struct type
*
16942 get_die_type_at_offset (sect_offset offset
,
16943 struct dwarf2_per_cu_data
*per_cu
)
16945 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
16947 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
16950 ofs
.per_cu
= per_cu
;
16951 ofs
.offset
= offset
;
16952 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
16959 /* Look up the type for DIE in the appropriate type_hash table,
16960 or return NULL if DIE does not have a saved type. */
16962 static struct type
*
16963 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16965 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
16968 /* Add a dependence relationship from CU to REF_PER_CU. */
16971 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
16972 struct dwarf2_per_cu_data
*ref_per_cu
)
16976 if (cu
->dependencies
== NULL
)
16978 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
16979 NULL
, &cu
->comp_unit_obstack
,
16980 hashtab_obstack_allocate
,
16981 dummy_obstack_deallocate
);
16983 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
16985 *slot
= ref_per_cu
;
16988 /* Subroutine of dwarf2_mark to pass to htab_traverse.
16989 Set the mark field in every compilation unit in the
16990 cache that we must keep because we are keeping CU. */
16993 dwarf2_mark_helper (void **slot
, void *data
)
16995 struct dwarf2_per_cu_data
*per_cu
;
16997 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
16999 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17000 reading of the chain. As such dependencies remain valid it is not much
17001 useful to track and undo them during QUIT cleanups. */
17002 if (per_cu
->cu
== NULL
)
17005 if (per_cu
->cu
->mark
)
17007 per_cu
->cu
->mark
= 1;
17009 if (per_cu
->cu
->dependencies
!= NULL
)
17010 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17015 /* Set the mark field in CU and in every other compilation unit in the
17016 cache that we must keep because we are keeping CU. */
17019 dwarf2_mark (struct dwarf2_cu
*cu
)
17024 if (cu
->dependencies
!= NULL
)
17025 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17029 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17033 per_cu
->cu
->mark
= 0;
17034 per_cu
= per_cu
->cu
->read_in_chain
;
17038 /* Trivial hash function for partial_die_info: the hash value of a DIE
17039 is its offset in .debug_info for this objfile. */
17042 partial_die_hash (const void *item
)
17044 const struct partial_die_info
*part_die
= item
;
17046 return part_die
->offset
.sect_off
;
17049 /* Trivial comparison function for partial_die_info structures: two DIEs
17050 are equal if they have the same offset. */
17053 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17055 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17056 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17058 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17061 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17062 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17065 set_dwarf2_cmd (char *args
, int from_tty
)
17067 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17071 show_dwarf2_cmd (char *args
, int from_tty
)
17073 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17076 /* If section described by INFO was mmapped, munmap it now. */
17079 munmap_section_buffer (struct dwarf2_section_info
*info
)
17081 if (info
->map_addr
!= NULL
)
17086 res
= munmap (info
->map_addr
, info
->map_len
);
17087 gdb_assert (res
== 0);
17089 /* Without HAVE_MMAP, we should never be here to begin with. */
17090 gdb_assert_not_reached ("no mmap support");
17095 /* munmap debug sections for OBJFILE, if necessary. */
17098 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17100 struct dwarf2_per_objfile
*data
= d
;
17102 struct dwarf2_section_info
*section
;
17104 /* This is sorted according to the order they're defined in to make it easier
17105 to keep in sync. */
17106 munmap_section_buffer (&data
->info
);
17107 munmap_section_buffer (&data
->abbrev
);
17108 munmap_section_buffer (&data
->line
);
17109 munmap_section_buffer (&data
->loc
);
17110 munmap_section_buffer (&data
->macinfo
);
17111 munmap_section_buffer (&data
->macro
);
17112 munmap_section_buffer (&data
->str
);
17113 munmap_section_buffer (&data
->ranges
);
17114 munmap_section_buffer (&data
->addr
);
17115 munmap_section_buffer (&data
->frame
);
17116 munmap_section_buffer (&data
->eh_frame
);
17117 munmap_section_buffer (&data
->gdb_index
);
17120 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17122 munmap_section_buffer (section
);
17124 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17125 VEC_free (dwarf2_per_cu_ptr
,
17126 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17128 VEC_free (dwarf2_section_info_def
, data
->types
);
17130 if (data
->dwo_files
)
17131 free_dwo_files (data
->dwo_files
, objfile
);
17135 /* The "save gdb-index" command. */
17137 /* The contents of the hash table we create when building the string
17139 struct strtab_entry
17141 offset_type offset
;
17145 /* Hash function for a strtab_entry.
17147 Function is used only during write_hash_table so no index format backward
17148 compatibility is needed. */
17151 hash_strtab_entry (const void *e
)
17153 const struct strtab_entry
*entry
= e
;
17154 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17157 /* Equality function for a strtab_entry. */
17160 eq_strtab_entry (const void *a
, const void *b
)
17162 const struct strtab_entry
*ea
= a
;
17163 const struct strtab_entry
*eb
= b
;
17164 return !strcmp (ea
->str
, eb
->str
);
17167 /* Create a strtab_entry hash table. */
17170 create_strtab (void)
17172 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17173 xfree
, xcalloc
, xfree
);
17176 /* Add a string to the constant pool. Return the string's offset in
17180 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17183 struct strtab_entry entry
;
17184 struct strtab_entry
*result
;
17187 slot
= htab_find_slot (table
, &entry
, INSERT
);
17192 result
= XNEW (struct strtab_entry
);
17193 result
->offset
= obstack_object_size (cpool
);
17195 obstack_grow_str0 (cpool
, str
);
17198 return result
->offset
;
17201 /* An entry in the symbol table. */
17202 struct symtab_index_entry
17204 /* The name of the symbol. */
17206 /* The offset of the name in the constant pool. */
17207 offset_type index_offset
;
17208 /* A sorted vector of the indices of all the CUs that hold an object
17210 VEC (offset_type
) *cu_indices
;
17213 /* The symbol table. This is a power-of-2-sized hash table. */
17214 struct mapped_symtab
17216 offset_type n_elements
;
17218 struct symtab_index_entry
**data
;
17221 /* Hash function for a symtab_index_entry. */
17224 hash_symtab_entry (const void *e
)
17226 const struct symtab_index_entry
*entry
= e
;
17227 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17228 sizeof (offset_type
) * VEC_length (offset_type
,
17229 entry
->cu_indices
),
17233 /* Equality function for a symtab_index_entry. */
17236 eq_symtab_entry (const void *a
, const void *b
)
17238 const struct symtab_index_entry
*ea
= a
;
17239 const struct symtab_index_entry
*eb
= b
;
17240 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17241 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17243 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17244 VEC_address (offset_type
, eb
->cu_indices
),
17245 sizeof (offset_type
) * len
);
17248 /* Destroy a symtab_index_entry. */
17251 delete_symtab_entry (void *p
)
17253 struct symtab_index_entry
*entry
= p
;
17254 VEC_free (offset_type
, entry
->cu_indices
);
17258 /* Create a hash table holding symtab_index_entry objects. */
17261 create_symbol_hash_table (void)
17263 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17264 delete_symtab_entry
, xcalloc
, xfree
);
17267 /* Create a new mapped symtab object. */
17269 static struct mapped_symtab
*
17270 create_mapped_symtab (void)
17272 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17273 symtab
->n_elements
= 0;
17274 symtab
->size
= 1024;
17275 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17279 /* Destroy a mapped_symtab. */
17282 cleanup_mapped_symtab (void *p
)
17284 struct mapped_symtab
*symtab
= p
;
17285 /* The contents of the array are freed when the other hash table is
17287 xfree (symtab
->data
);
17291 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17294 Function is used only during write_hash_table so no index format backward
17295 compatibility is needed. */
17297 static struct symtab_index_entry
**
17298 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17300 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17302 index
= hash
& (symtab
->size
- 1);
17303 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17307 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17308 return &symtab
->data
[index
];
17309 index
= (index
+ step
) & (symtab
->size
- 1);
17313 /* Expand SYMTAB's hash table. */
17316 hash_expand (struct mapped_symtab
*symtab
)
17318 offset_type old_size
= symtab
->size
;
17320 struct symtab_index_entry
**old_entries
= symtab
->data
;
17323 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17325 for (i
= 0; i
< old_size
; ++i
)
17327 if (old_entries
[i
])
17329 struct symtab_index_entry
**slot
= find_slot (symtab
,
17330 old_entries
[i
]->name
);
17331 *slot
= old_entries
[i
];
17335 xfree (old_entries
);
17338 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
17339 is the index of the CU in which the symbol appears. */
17342 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17343 offset_type cu_index
)
17345 struct symtab_index_entry
**slot
;
17347 ++symtab
->n_elements
;
17348 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17349 hash_expand (symtab
);
17351 slot
= find_slot (symtab
, name
);
17354 *slot
= XNEW (struct symtab_index_entry
);
17355 (*slot
)->name
= name
;
17356 (*slot
)->cu_indices
= NULL
;
17358 /* Don't push an index twice. Due to how we add entries we only
17359 have to check the last one. */
17360 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
17361 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
17362 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
17365 /* Add a vector of indices to the constant pool. */
17368 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17369 struct symtab_index_entry
*entry
)
17373 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17376 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17377 offset_type val
= MAYBE_SWAP (len
);
17382 entry
->index_offset
= obstack_object_size (cpool
);
17384 obstack_grow (cpool
, &val
, sizeof (val
));
17386 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17389 val
= MAYBE_SWAP (iter
);
17390 obstack_grow (cpool
, &val
, sizeof (val
));
17395 struct symtab_index_entry
*old_entry
= *slot
;
17396 entry
->index_offset
= old_entry
->index_offset
;
17399 return entry
->index_offset
;
17402 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17403 constant pool entries going into the obstack CPOOL. */
17406 write_hash_table (struct mapped_symtab
*symtab
,
17407 struct obstack
*output
, struct obstack
*cpool
)
17410 htab_t symbol_hash_table
;
17413 symbol_hash_table
= create_symbol_hash_table ();
17414 str_table
= create_strtab ();
17416 /* We add all the index vectors to the constant pool first, to
17417 ensure alignment is ok. */
17418 for (i
= 0; i
< symtab
->size
; ++i
)
17420 if (symtab
->data
[i
])
17421 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17424 /* Now write out the hash table. */
17425 for (i
= 0; i
< symtab
->size
; ++i
)
17427 offset_type str_off
, vec_off
;
17429 if (symtab
->data
[i
])
17431 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17432 vec_off
= symtab
->data
[i
]->index_offset
;
17436 /* While 0 is a valid constant pool index, it is not valid
17437 to have 0 for both offsets. */
17442 str_off
= MAYBE_SWAP (str_off
);
17443 vec_off
= MAYBE_SWAP (vec_off
);
17445 obstack_grow (output
, &str_off
, sizeof (str_off
));
17446 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17449 htab_delete (str_table
);
17450 htab_delete (symbol_hash_table
);
17453 /* Struct to map psymtab to CU index in the index file. */
17454 struct psymtab_cu_index_map
17456 struct partial_symtab
*psymtab
;
17457 unsigned int cu_index
;
17461 hash_psymtab_cu_index (const void *item
)
17463 const struct psymtab_cu_index_map
*map
= item
;
17465 return htab_hash_pointer (map
->psymtab
);
17469 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17471 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17472 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17474 return lhs
->psymtab
== rhs
->psymtab
;
17477 /* Helper struct for building the address table. */
17478 struct addrmap_index_data
17480 struct objfile
*objfile
;
17481 struct obstack
*addr_obstack
;
17482 htab_t cu_index_htab
;
17484 /* Non-zero if the previous_* fields are valid.
17485 We can't write an entry until we see the next entry (since it is only then
17486 that we know the end of the entry). */
17487 int previous_valid
;
17488 /* Index of the CU in the table of all CUs in the index file. */
17489 unsigned int previous_cu_index
;
17490 /* Start address of the CU. */
17491 CORE_ADDR previous_cu_start
;
17494 /* Write an address entry to OBSTACK. */
17497 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17498 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17500 offset_type cu_index_to_write
;
17502 CORE_ADDR baseaddr
;
17504 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17506 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17507 obstack_grow (obstack
, addr
, 8);
17508 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17509 obstack_grow (obstack
, addr
, 8);
17510 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17511 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17514 /* Worker function for traversing an addrmap to build the address table. */
17517 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17519 struct addrmap_index_data
*data
= datap
;
17520 struct partial_symtab
*pst
= obj
;
17522 if (data
->previous_valid
)
17523 add_address_entry (data
->objfile
, data
->addr_obstack
,
17524 data
->previous_cu_start
, start_addr
,
17525 data
->previous_cu_index
);
17527 data
->previous_cu_start
= start_addr
;
17530 struct psymtab_cu_index_map find_map
, *map
;
17531 find_map
.psymtab
= pst
;
17532 map
= htab_find (data
->cu_index_htab
, &find_map
);
17533 gdb_assert (map
!= NULL
);
17534 data
->previous_cu_index
= map
->cu_index
;
17535 data
->previous_valid
= 1;
17538 data
->previous_valid
= 0;
17543 /* Write OBJFILE's address map to OBSTACK.
17544 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17545 in the index file. */
17548 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17549 htab_t cu_index_htab
)
17551 struct addrmap_index_data addrmap_index_data
;
17553 /* When writing the address table, we have to cope with the fact that
17554 the addrmap iterator only provides the start of a region; we have to
17555 wait until the next invocation to get the start of the next region. */
17557 addrmap_index_data
.objfile
= objfile
;
17558 addrmap_index_data
.addr_obstack
= obstack
;
17559 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17560 addrmap_index_data
.previous_valid
= 0;
17562 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17563 &addrmap_index_data
);
17565 /* It's highly unlikely the last entry (end address = 0xff...ff)
17566 is valid, but we should still handle it.
17567 The end address is recorded as the start of the next region, but that
17568 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17570 if (addrmap_index_data
.previous_valid
)
17571 add_address_entry (objfile
, obstack
,
17572 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17573 addrmap_index_data
.previous_cu_index
);
17576 /* Add a list of partial symbols to SYMTAB. */
17579 write_psymbols (struct mapped_symtab
*symtab
,
17581 struct partial_symbol
**psymp
,
17583 offset_type cu_index
,
17586 for (; count
-- > 0; ++psymp
)
17588 void **slot
, *lookup
;
17590 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
17591 error (_("Ada is not currently supported by the index"));
17593 /* We only want to add a given psymbol once. However, we also
17594 want to account for whether it is global or static. So, we
17595 may add it twice, using slightly different values. */
17598 uintptr_t val
= 1 | (uintptr_t) *psymp
;
17600 lookup
= (void *) val
;
17605 /* Only add a given psymbol once. */
17606 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
17610 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
17615 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17616 exception if there is an error. */
17619 write_obstack (FILE *file
, struct obstack
*obstack
)
17621 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17623 != obstack_object_size (obstack
))
17624 error (_("couldn't data write to file"));
17627 /* Unlink a file if the argument is not NULL. */
17630 unlink_if_set (void *p
)
17632 char **filename
= p
;
17634 unlink (*filename
);
17637 /* A helper struct used when iterating over debug_types. */
17638 struct signatured_type_index_data
17640 struct objfile
*objfile
;
17641 struct mapped_symtab
*symtab
;
17642 struct obstack
*types_list
;
17647 /* A helper function that writes a single signatured_type to an
17651 write_one_signatured_type (void **slot
, void *d
)
17653 struct signatured_type_index_data
*info
= d
;
17654 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17655 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17656 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17659 write_psymbols (info
->symtab
,
17661 info
->objfile
->global_psymbols
.list
17662 + psymtab
->globals_offset
,
17663 psymtab
->n_global_syms
, info
->cu_index
,
17665 write_psymbols (info
->symtab
,
17667 info
->objfile
->static_psymbols
.list
17668 + psymtab
->statics_offset
,
17669 psymtab
->n_static_syms
, info
->cu_index
,
17672 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17673 entry
->per_cu
.offset
.sect_off
);
17674 obstack_grow (info
->types_list
, val
, 8);
17675 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17676 entry
->type_offset_in_tu
.cu_off
);
17677 obstack_grow (info
->types_list
, val
, 8);
17678 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17679 obstack_grow (info
->types_list
, val
, 8);
17686 /* Recurse into all "included" dependencies and write their symbols as
17687 if they appeared in this psymtab. */
17690 recursively_write_psymbols (struct objfile
*objfile
,
17691 struct partial_symtab
*psymtab
,
17692 struct mapped_symtab
*symtab
,
17694 offset_type cu_index
)
17698 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
17699 if (psymtab
->dependencies
[i
]->user
!= NULL
)
17700 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
17701 symtab
, psyms_seen
, cu_index
);
17703 write_psymbols (symtab
,
17705 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17706 psymtab
->n_global_syms
, cu_index
,
17708 write_psymbols (symtab
,
17710 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17711 psymtab
->n_static_syms
, cu_index
,
17715 /* Create an index file for OBJFILE in the directory DIR. */
17718 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17720 struct cleanup
*cleanup
;
17721 char *filename
, *cleanup_filename
;
17722 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
17723 struct obstack cu_list
, types_cu_list
;
17726 struct mapped_symtab
*symtab
;
17727 offset_type val
, size_of_contents
, total_len
;
17730 htab_t cu_index_htab
;
17731 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
17733 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
17736 if (dwarf2_per_objfile
->using_index
)
17737 error (_("Cannot use an index to create the index"));
17739 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
17740 error (_("Cannot make an index when the file has multiple .debug_types sections"));
17742 if (stat (objfile
->name
, &st
) < 0)
17743 perror_with_name (objfile
->name
);
17745 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
17746 INDEX_SUFFIX
, (char *) NULL
);
17747 cleanup
= make_cleanup (xfree
, filename
);
17749 out_file
= fopen (filename
, "wb");
17751 error (_("Can't open `%s' for writing"), filename
);
17753 cleanup_filename
= filename
;
17754 make_cleanup (unlink_if_set
, &cleanup_filename
);
17756 symtab
= create_mapped_symtab ();
17757 make_cleanup (cleanup_mapped_symtab
, symtab
);
17759 obstack_init (&addr_obstack
);
17760 make_cleanup_obstack_free (&addr_obstack
);
17762 obstack_init (&cu_list
);
17763 make_cleanup_obstack_free (&cu_list
);
17765 obstack_init (&types_cu_list
);
17766 make_cleanup_obstack_free (&types_cu_list
);
17768 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
17769 NULL
, xcalloc
, xfree
);
17770 make_cleanup_htab_delete (psyms_seen
);
17772 /* While we're scanning CU's create a table that maps a psymtab pointer
17773 (which is what addrmap records) to its index (which is what is recorded
17774 in the index file). This will later be needed to write the address
17776 cu_index_htab
= htab_create_alloc (100,
17777 hash_psymtab_cu_index
,
17778 eq_psymtab_cu_index
,
17779 NULL
, xcalloc
, xfree
);
17780 make_cleanup_htab_delete (cu_index_htab
);
17781 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
17782 xmalloc (sizeof (struct psymtab_cu_index_map
)
17783 * dwarf2_per_objfile
->n_comp_units
);
17784 make_cleanup (xfree
, psymtab_cu_index_map
);
17786 /* The CU list is already sorted, so we don't need to do additional
17787 work here. Also, the debug_types entries do not appear in
17788 all_comp_units, but only in their own hash table. */
17789 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
17791 struct dwarf2_per_cu_data
*per_cu
17792 = dwarf2_per_objfile
->all_comp_units
[i
];
17793 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17795 struct psymtab_cu_index_map
*map
;
17798 if (psymtab
->user
== NULL
)
17799 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
17801 map
= &psymtab_cu_index_map
[i
];
17802 map
->psymtab
= psymtab
;
17804 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
17805 gdb_assert (slot
!= NULL
);
17806 gdb_assert (*slot
== NULL
);
17809 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17810 per_cu
->offset
.sect_off
);
17811 obstack_grow (&cu_list
, val
, 8);
17812 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
17813 obstack_grow (&cu_list
, val
, 8);
17816 /* Dump the address map. */
17817 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
17819 /* Write out the .debug_type entries, if any. */
17820 if (dwarf2_per_objfile
->signatured_types
)
17822 struct signatured_type_index_data sig_data
;
17824 sig_data
.objfile
= objfile
;
17825 sig_data
.symtab
= symtab
;
17826 sig_data
.types_list
= &types_cu_list
;
17827 sig_data
.psyms_seen
= psyms_seen
;
17828 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
17829 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
17830 write_one_signatured_type
, &sig_data
);
17833 obstack_init (&constant_pool
);
17834 make_cleanup_obstack_free (&constant_pool
);
17835 obstack_init (&symtab_obstack
);
17836 make_cleanup_obstack_free (&symtab_obstack
);
17837 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
17839 obstack_init (&contents
);
17840 make_cleanup_obstack_free (&contents
);
17841 size_of_contents
= 6 * sizeof (offset_type
);
17842 total_len
= size_of_contents
;
17844 /* The version number. */
17845 val
= MAYBE_SWAP (6);
17846 obstack_grow (&contents
, &val
, sizeof (val
));
17848 /* The offset of the CU list from the start of the file. */
17849 val
= MAYBE_SWAP (total_len
);
17850 obstack_grow (&contents
, &val
, sizeof (val
));
17851 total_len
+= obstack_object_size (&cu_list
);
17853 /* The offset of the types CU list from the start of the file. */
17854 val
= MAYBE_SWAP (total_len
);
17855 obstack_grow (&contents
, &val
, sizeof (val
));
17856 total_len
+= obstack_object_size (&types_cu_list
);
17858 /* The offset of the address table from the start of the file. */
17859 val
= MAYBE_SWAP (total_len
);
17860 obstack_grow (&contents
, &val
, sizeof (val
));
17861 total_len
+= obstack_object_size (&addr_obstack
);
17863 /* The offset of the symbol table from the start of the file. */
17864 val
= MAYBE_SWAP (total_len
);
17865 obstack_grow (&contents
, &val
, sizeof (val
));
17866 total_len
+= obstack_object_size (&symtab_obstack
);
17868 /* The offset of the constant pool from the start of the file. */
17869 val
= MAYBE_SWAP (total_len
);
17870 obstack_grow (&contents
, &val
, sizeof (val
));
17871 total_len
+= obstack_object_size (&constant_pool
);
17873 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
17875 write_obstack (out_file
, &contents
);
17876 write_obstack (out_file
, &cu_list
);
17877 write_obstack (out_file
, &types_cu_list
);
17878 write_obstack (out_file
, &addr_obstack
);
17879 write_obstack (out_file
, &symtab_obstack
);
17880 write_obstack (out_file
, &constant_pool
);
17884 /* We want to keep the file, so we set cleanup_filename to NULL
17885 here. See unlink_if_set. */
17886 cleanup_filename
= NULL
;
17888 do_cleanups (cleanup
);
17891 /* Implementation of the `save gdb-index' command.
17893 Note that the file format used by this command is documented in the
17894 GDB manual. Any changes here must be documented there. */
17897 save_gdb_index_command (char *arg
, int from_tty
)
17899 struct objfile
*objfile
;
17902 error (_("usage: save gdb-index DIRECTORY"));
17904 ALL_OBJFILES (objfile
)
17908 /* If the objfile does not correspond to an actual file, skip it. */
17909 if (stat (objfile
->name
, &st
) < 0)
17912 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17913 if (dwarf2_per_objfile
)
17915 volatile struct gdb_exception except
;
17917 TRY_CATCH (except
, RETURN_MASK_ERROR
)
17919 write_psymtabs_to_index (objfile
, arg
);
17921 if (except
.reason
< 0)
17922 exception_fprintf (gdb_stderr
, except
,
17923 _("Error while writing index for `%s': "),
17931 int dwarf2_always_disassemble
;
17934 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
17935 struct cmd_list_element
*c
, const char *value
)
17937 fprintf_filtered (file
,
17938 _("Whether to always disassemble "
17939 "DWARF expressions is %s.\n"),
17944 show_check_physname (struct ui_file
*file
, int from_tty
,
17945 struct cmd_list_element
*c
, const char *value
)
17947 fprintf_filtered (file
,
17948 _("Whether to check \"physname\" is %s.\n"),
17952 void _initialize_dwarf2_read (void);
17955 _initialize_dwarf2_read (void)
17957 struct cmd_list_element
*c
;
17959 dwarf2_objfile_data_key
17960 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
17962 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
17963 Set DWARF 2 specific variables.\n\
17964 Configure DWARF 2 variables such as the cache size"),
17965 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
17966 0/*allow-unknown*/, &maintenance_set_cmdlist
);
17968 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
17969 Show DWARF 2 specific variables\n\
17970 Show DWARF 2 variables such as the cache size"),
17971 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
17972 0/*allow-unknown*/, &maintenance_show_cmdlist
);
17974 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
17975 &dwarf2_max_cache_age
, _("\
17976 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
17977 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
17978 A higher limit means that cached compilation units will be stored\n\
17979 in memory longer, and more total memory will be used. Zero disables\n\
17980 caching, which can slow down startup."),
17982 show_dwarf2_max_cache_age
,
17983 &set_dwarf2_cmdlist
,
17984 &show_dwarf2_cmdlist
);
17986 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
17987 &dwarf2_always_disassemble
, _("\
17988 Set whether `info address' always disassembles DWARF expressions."), _("\
17989 Show whether `info address' always disassembles DWARF expressions."), _("\
17990 When enabled, DWARF expressions are always printed in an assembly-like\n\
17991 syntax. When disabled, expressions will be printed in a more\n\
17992 conversational style, when possible."),
17994 show_dwarf2_always_disassemble
,
17995 &set_dwarf2_cmdlist
,
17996 &show_dwarf2_cmdlist
);
17998 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
17999 Set debugging of the dwarf2 DIE reader."), _("\
18000 Show debugging of the dwarf2 DIE reader."), _("\
18001 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18002 The value is the maximum depth to print."),
18005 &setdebuglist
, &showdebuglist
);
18007 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18008 Set cross-checking of \"physname\" code against demangler."), _("\
18009 Show cross-checking of \"physname\" code against demangler."), _("\
18010 When enabled, GDB's internal \"physname\" code is checked against\n\
18012 NULL
, show_check_physname
,
18013 &setdebuglist
, &showdebuglist
);
18015 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18017 Save a gdb-index file.\n\
18018 Usage: save gdb-index DIRECTORY"),
18020 set_cmd_completer (c
, filename_completer
);