1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb_string.h"
69 #include "gdb_assert.h"
70 #include <sys/types.h>
77 #define MAP_FAILED ((void *) -1)
81 typedef struct symbol
*symbolp
;
84 /* When non-zero, dump DIEs after they are read in. */
85 static int dwarf2_die_debug
= 0;
87 /* When non-zero, cross-check physname against demangler. */
88 static int check_physname
= 0;
90 /* When non-zero, do not reject deprecated .gdb_index sections. */
91 int use_deprecated_index_sections
= 0;
95 /* When set, the file that we're processing is known to have debugging
96 info for C++ namespaces. GCC 3.3.x did not produce this information,
97 but later versions do. */
99 static int processing_has_namespace_info
;
101 static const struct objfile_data
*dwarf2_objfile_data_key
;
103 struct dwarf2_section_info
108 /* Not NULL if the section was actually mmapped. */
110 /* Page aligned size of mmapped area. */
111 bfd_size_type map_len
;
112 /* True if we have tried to read this section. */
116 typedef struct dwarf2_section_info dwarf2_section_info_def
;
117 DEF_VEC_O (dwarf2_section_info_def
);
119 /* All offsets in the index are of this type. It must be
120 architecture-independent. */
121 typedef uint32_t offset_type
;
123 DEF_VEC_I (offset_type
);
125 /* A description of the mapped index. The file format is described in
126 a comment by the code that writes the index. */
129 /* Index data format version. */
132 /* The total length of the buffer. */
135 /* A pointer to the address table data. */
136 const gdb_byte
*address_table
;
138 /* Size of the address table data in bytes. */
139 offset_type address_table_size
;
141 /* The symbol table, implemented as a hash table. */
142 const offset_type
*symbol_table
;
144 /* Size in slots, each slot is 2 offset_types. */
145 offset_type symbol_table_slots
;
147 /* A pointer to the constant pool. */
148 const char *constant_pool
;
151 /* Collection of data recorded per objfile.
152 This hangs off of dwarf2_objfile_data_key. */
154 struct dwarf2_per_objfile
156 struct dwarf2_section_info info
;
157 struct dwarf2_section_info abbrev
;
158 struct dwarf2_section_info line
;
159 struct dwarf2_section_info loc
;
160 struct dwarf2_section_info macinfo
;
161 struct dwarf2_section_info macro
;
162 struct dwarf2_section_info str
;
163 struct dwarf2_section_info ranges
;
164 struct dwarf2_section_info addr
;
165 struct dwarf2_section_info frame
;
166 struct dwarf2_section_info eh_frame
;
167 struct dwarf2_section_info gdb_index
;
169 VEC (dwarf2_section_info_def
) *types
;
172 struct objfile
*objfile
;
174 /* Table of all the compilation units. This is used to locate
175 the target compilation unit of a particular reference. */
176 struct dwarf2_per_cu_data
**all_comp_units
;
178 /* The number of compilation units in ALL_COMP_UNITS. */
181 /* The number of .debug_types-related CUs. */
184 /* The .debug_types-related CUs (TUs). */
185 struct dwarf2_per_cu_data
**all_type_units
;
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data
*read_in_chain
;
191 /* A table mapping .debug_types signatures to its signatured_type entry.
192 This is NULL if the .debug_types section hasn't been read in yet. */
193 htab_t signatured_types
;
195 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
196 This is NULL if the table hasn't been allocated yet. */
199 /* A flag indicating wether this objfile has a section loaded at a
201 int has_section_at_zero
;
203 /* True if we are using the mapped index,
204 or we are faking it for OBJF_READNOW's sake. */
205 unsigned char using_index
;
207 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
208 struct mapped_index
*index_table
;
210 /* When using index_table, this keeps track of all quick_file_names entries.
211 TUs can share line table entries with CUs or other TUs, and there can be
212 a lot more TUs than unique line tables, so we maintain a separate table
213 of all line table entries to support the sharing. */
214 htab_t quick_file_names_table
;
216 /* Set during partial symbol reading, to prevent queueing of full
218 int reading_partial_symbols
;
220 /* Table mapping type DIEs to their struct type *.
221 This is NULL if not allocated yet.
222 The mapping is done via (CU/TU signature + DIE offset) -> type. */
223 htab_t die_type_hash
;
226 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
228 /* Default names of the debugging sections. */
230 /* Note that if the debugging section has been compressed, it might
231 have a name like .zdebug_info. */
233 static const struct dwarf2_debug_sections dwarf2_elf_names
=
235 { ".debug_info", ".zdebug_info" },
236 { ".debug_abbrev", ".zdebug_abbrev" },
237 { ".debug_line", ".zdebug_line" },
238 { ".debug_loc", ".zdebug_loc" },
239 { ".debug_macinfo", ".zdebug_macinfo" },
240 { ".debug_macro", ".zdebug_macro" },
241 { ".debug_str", ".zdebug_str" },
242 { ".debug_ranges", ".zdebug_ranges" },
243 { ".debug_types", ".zdebug_types" },
244 { ".debug_addr", ".zdebug_addr" },
245 { ".debug_frame", ".zdebug_frame" },
246 { ".eh_frame", NULL
},
247 { ".gdb_index", ".zgdb_index" },
251 /* List of DWO sections. */
253 static const struct dwo_section_names
255 struct dwarf2_section_names abbrev_dwo
;
256 struct dwarf2_section_names info_dwo
;
257 struct dwarf2_section_names line_dwo
;
258 struct dwarf2_section_names loc_dwo
;
259 struct dwarf2_section_names str_dwo
;
260 struct dwarf2_section_names str_offsets_dwo
;
261 struct dwarf2_section_names types_dwo
;
265 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
266 { ".debug_info.dwo", ".zdebug_info.dwo" },
267 { ".debug_line.dwo", ".zdebug_line.dwo" },
268 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
269 { ".debug_str.dwo", ".zdebug_str.dwo" },
270 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
271 { ".debug_types.dwo", ".zdebug_types.dwo" },
274 /* local data types */
276 /* We hold several abbreviation tables in memory at the same time. */
277 #ifndef ABBREV_HASH_SIZE
278 #define ABBREV_HASH_SIZE 121
281 /* The data in a compilation unit header, after target2host
282 translation, looks like this. */
283 struct comp_unit_head
287 unsigned char addr_size
;
288 unsigned char signed_addr_p
;
289 sect_offset abbrev_offset
;
291 /* Size of file offsets; either 4 or 8. */
292 unsigned int offset_size
;
294 /* Size of the length field; either 4 or 12. */
295 unsigned int initial_length_size
;
297 /* Offset to the first byte of this compilation unit header in the
298 .debug_info section, for resolving relative reference dies. */
301 /* Offset to first die in this cu from the start of the cu.
302 This will be the first byte following the compilation unit header. */
303 cu_offset first_die_offset
;
306 /* Type used for delaying computation of method physnames.
307 See comments for compute_delayed_physnames. */
308 struct delayed_method_info
310 /* The type to which the method is attached, i.e., its parent class. */
313 /* The index of the method in the type's function fieldlists. */
316 /* The index of the method in the fieldlist. */
319 /* The name of the DIE. */
322 /* The DIE associated with this method. */
323 struct die_info
*die
;
326 typedef struct delayed_method_info delayed_method_info
;
327 DEF_VEC_O (delayed_method_info
);
329 /* Internal state when decoding a particular compilation unit. */
332 /* The objfile containing this compilation unit. */
333 struct objfile
*objfile
;
335 /* The header of the compilation unit. */
336 struct comp_unit_head header
;
338 /* Base address of this compilation unit. */
339 CORE_ADDR base_address
;
341 /* Non-zero if base_address has been set. */
344 /* The language we are debugging. */
345 enum language language
;
346 const struct language_defn
*language_defn
;
348 const char *producer
;
350 /* The generic symbol table building routines have separate lists for
351 file scope symbols and all all other scopes (local scopes). So
352 we need to select the right one to pass to add_symbol_to_list().
353 We do it by keeping a pointer to the correct list in list_in_scope.
355 FIXME: The original dwarf code just treated the file scope as the
356 first local scope, and all other local scopes as nested local
357 scopes, and worked fine. Check to see if we really need to
358 distinguish these in buildsym.c. */
359 struct pending
**list_in_scope
;
361 /* DWARF abbreviation table associated with this compilation unit. */
362 struct abbrev_info
**dwarf2_abbrevs
;
364 /* Storage for the abbrev table. */
365 struct obstack abbrev_obstack
;
367 /* Hash table holding all the loaded partial DIEs
368 with partial_die->offset.SECT_OFF as hash. */
371 /* Storage for things with the same lifetime as this read-in compilation
372 unit, including partial DIEs. */
373 struct obstack comp_unit_obstack
;
375 /* When multiple dwarf2_cu structures are living in memory, this field
376 chains them all together, so that they can be released efficiently.
377 We will probably also want a generation counter so that most-recently-used
378 compilation units are cached... */
379 struct dwarf2_per_cu_data
*read_in_chain
;
381 /* Backchain to our per_cu entry if the tree has been built. */
382 struct dwarf2_per_cu_data
*per_cu
;
384 /* How many compilation units ago was this CU last referenced? */
387 /* A hash table of DIE cu_offset for following references with
388 die_info->offset.sect_off as hash. */
391 /* Full DIEs if read in. */
392 struct die_info
*dies
;
394 /* A set of pointers to dwarf2_per_cu_data objects for compilation
395 units referenced by this one. Only set during full symbol processing;
396 partial symbol tables do not have dependencies. */
399 /* Header data from the line table, during full symbol processing. */
400 struct line_header
*line_header
;
402 /* A list of methods which need to have physnames computed
403 after all type information has been read. */
404 VEC (delayed_method_info
) *method_list
;
406 /* To be copied to symtab->call_site_htab. */
407 htab_t call_site_htab
;
409 /* Non-NULL if this CU came from a DWO file. */
410 struct dwo_unit
*dwo_unit
;
412 /* The DW_AT_addr_base attribute if present, zero otherwise
413 (zero is a valid value though).
414 Note this value comes from the stub CU/TU's DIE. */
417 /* Mark used when releasing cached dies. */
418 unsigned int mark
: 1;
420 /* This CU references .debug_loc. See the symtab->locations_valid field.
421 This test is imperfect as there may exist optimized debug code not using
422 any location list and still facing inlining issues if handled as
423 unoptimized code. For a future better test see GCC PR other/32998. */
424 unsigned int has_loclist
: 1;
426 /* These cache the results of producer_is_gxx_lt_4_6.
427 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
428 information is cached because profiling CU expansion showed
429 excessive time spent in producer_is_gxx_lt_4_6. */
430 unsigned int checked_producer
: 1;
431 unsigned int producer_is_gxx_lt_4_6
: 1;
433 /* Non-zero if DW_AT_addr_base was found.
434 Used when processing DWO files. */
435 unsigned int have_addr_base
: 1;
438 /* Persistent data held for a compilation unit, even when not
439 processing it. We put a pointer to this structure in the
440 read_symtab_private field of the psymtab. */
442 struct dwarf2_per_cu_data
444 /* The start offset and length of this compilation unit. 2**29-1
445 bytes should suffice to store the length of any compilation unit
446 - if it doesn't, GDB will fall over anyway.
447 NOTE: Unlike comp_unit_head.length, this length includes
449 If the DIE refers to a DWO file, this is always of the original die,
452 unsigned int length
: 29;
454 /* Flag indicating this compilation unit will be read in before
455 any of the current compilation units are processed. */
456 unsigned int queued
: 1;
458 /* This flag will be set when reading partial DIEs if we need to load
459 absolutely all DIEs for this compilation unit, instead of just the ones
460 we think are interesting. It gets set if we look for a DIE in the
461 hash table and don't find it. */
462 unsigned int load_all_dies
: 1;
464 /* Non-zero if this CU is from .debug_types. */
465 unsigned int is_debug_types
: 1;
467 /* The section this CU/TU lives in.
468 If the DIE refers to a DWO file, this is always the original die,
470 struct dwarf2_section_info
*info_or_types_section
;
472 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
473 of the CU cache it gets reset to NULL again. */
474 struct dwarf2_cu
*cu
;
476 /* The corresponding objfile.
477 Normally we can get the objfile from dwarf2_per_objfile.
478 However we can enter this file with just a "per_cu" handle. */
479 struct objfile
*objfile
;
481 /* When using partial symbol tables, the 'psymtab' field is active.
482 Otherwise the 'quick' field is active. */
485 /* The partial symbol table associated with this compilation unit,
486 or NULL for partial units (which do not have an associated
488 struct partial_symtab
*psymtab
;
490 /* Data needed by the "quick" functions. */
491 struct dwarf2_per_cu_quick_data
*quick
;
495 /* Entry in the signatured_types hash table. */
497 struct signatured_type
499 /* The type's signature. */
502 /* Offset in the TU of the type's DIE, as read from the TU header.
503 If the definition lives in a DWO file, this value is unusable. */
504 cu_offset type_offset_in_tu
;
506 /* Offset in the section of the type's DIE.
507 If the definition lives in a DWO file, this is the offset in the
508 .debug_types.dwo section.
509 The value is zero until the actual value is known.
510 Zero is otherwise not a valid section offset. */
511 sect_offset type_offset_in_section
;
513 /* The CU(/TU) of this type. */
514 struct dwarf2_per_cu_data per_cu
;
517 /* These sections are what may appear in a "dwo" file. */
521 struct dwarf2_section_info abbrev
;
522 struct dwarf2_section_info info
;
523 struct dwarf2_section_info line
;
524 struct dwarf2_section_info loc
;
525 struct dwarf2_section_info str
;
526 struct dwarf2_section_info str_offsets
;
527 VEC (dwarf2_section_info_def
) *types
;
530 /* Common bits of DWO CUs/TUs. */
534 /* Backlink to the containing struct dwo_file. */
535 struct dwo_file
*dwo_file
;
537 /* The "id" that distinguishes this CU/TU.
538 .debug_info calls this "dwo_id", .debug_types calls this "signature".
539 Since signatures came first, we stick with it for consistency. */
542 /* The section this CU/TU lives in, in the DWO file. */
543 struct dwarf2_section_info
*info_or_types_section
;
545 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
549 /* For types, offset in the type's DIE of the type defined by this TU. */
550 cu_offset type_offset_in_tu
;
553 /* Data for one DWO file. */
557 /* The DW_AT_GNU_dwo_name attribute.
558 We don't manage space for this, it's an attribute. */
559 const char *dwo_name
;
561 /* The bfd, when the file is open. Otherwise this is NULL. */
564 /* Section info for this file. */
565 struct dwo_sections sections
;
567 /* Table of CUs in the file.
568 Each element is a struct dwo_unit. */
571 /* Table of TUs in the file.
572 Each element is a struct dwo_unit. */
576 /* Struct used to pass misc. parameters to read_die_and_children, et
577 al. which are used for both .debug_info and .debug_types dies.
578 All parameters here are unchanging for the life of the call. This
579 struct exists to abstract away the constant parameters of die reading. */
581 struct die_reader_specs
583 /* die_section->asection->owner. */
586 /* The CU of the DIE we are parsing. */
587 struct dwarf2_cu
*cu
;
589 /* Non-NULL if reading a DWO file. */
590 struct dwo_file
*dwo_file
;
592 /* The section the die comes from.
593 This is either .debug_info or .debug_types, or the .dwo variants. */
594 struct dwarf2_section_info
*die_section
;
596 /* die_section->buffer. */
600 /* Type of function passed to init_cu_and_read_dies, et.al. */
601 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
603 struct die_info
*comp_unit_die
,
607 /* The line number information for a compilation unit (found in the
608 .debug_line section) begins with a "statement program header",
609 which contains the following information. */
612 unsigned int total_length
;
613 unsigned short version
;
614 unsigned int header_length
;
615 unsigned char minimum_instruction_length
;
616 unsigned char maximum_ops_per_instruction
;
617 unsigned char default_is_stmt
;
619 unsigned char line_range
;
620 unsigned char opcode_base
;
622 /* standard_opcode_lengths[i] is the number of operands for the
623 standard opcode whose value is i. This means that
624 standard_opcode_lengths[0] is unused, and the last meaningful
625 element is standard_opcode_lengths[opcode_base - 1]. */
626 unsigned char *standard_opcode_lengths
;
628 /* The include_directories table. NOTE! These strings are not
629 allocated with xmalloc; instead, they are pointers into
630 debug_line_buffer. If you try to free them, `free' will get
632 unsigned int num_include_dirs
, include_dirs_size
;
635 /* The file_names table. NOTE! These strings are not allocated
636 with xmalloc; instead, they are pointers into debug_line_buffer.
637 Don't try to free them directly. */
638 unsigned int num_file_names
, file_names_size
;
642 unsigned int dir_index
;
643 unsigned int mod_time
;
645 int included_p
; /* Non-zero if referenced by the Line Number Program. */
646 struct symtab
*symtab
; /* The associated symbol table, if any. */
649 /* The start and end of the statement program following this
650 header. These point into dwarf2_per_objfile->line_buffer. */
651 gdb_byte
*statement_program_start
, *statement_program_end
;
654 /* When we construct a partial symbol table entry we only
655 need this much information. */
656 struct partial_die_info
658 /* Offset of this DIE. */
661 /* DWARF-2 tag for this DIE. */
662 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
664 /* Assorted flags describing the data found in this DIE. */
665 unsigned int has_children
: 1;
666 unsigned int is_external
: 1;
667 unsigned int is_declaration
: 1;
668 unsigned int has_type
: 1;
669 unsigned int has_specification
: 1;
670 unsigned int has_pc_info
: 1;
671 unsigned int may_be_inlined
: 1;
673 /* Flag set if the SCOPE field of this structure has been
675 unsigned int scope_set
: 1;
677 /* Flag set if the DIE has a byte_size attribute. */
678 unsigned int has_byte_size
: 1;
680 /* Flag set if any of the DIE's children are template arguments. */
681 unsigned int has_template_arguments
: 1;
683 /* Flag set if fixup_partial_die has been called on this die. */
684 unsigned int fixup_called
: 1;
686 /* The name of this DIE. Normally the value of DW_AT_name, but
687 sometimes a default name for unnamed DIEs. */
690 /* The linkage name, if present. */
691 const char *linkage_name
;
693 /* The scope to prepend to our children. This is generally
694 allocated on the comp_unit_obstack, so will disappear
695 when this compilation unit leaves the cache. */
698 /* The location description associated with this DIE, if any. */
699 struct dwarf_block
*locdesc
;
701 /* If HAS_PC_INFO, the PC range associated with this DIE. */
705 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
706 DW_AT_sibling, if any. */
707 /* NOTE: This member isn't strictly necessary, read_partial_die could
708 return DW_AT_sibling values to its caller load_partial_dies. */
711 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
712 DW_AT_specification (or DW_AT_abstract_origin or
714 sect_offset spec_offset
;
716 /* Pointers to this DIE's parent, first child, and next sibling,
718 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
721 /* This data structure holds the information of an abbrev. */
724 unsigned int number
; /* number identifying abbrev */
725 enum dwarf_tag tag
; /* dwarf tag */
726 unsigned short has_children
; /* boolean */
727 unsigned short num_attrs
; /* number of attributes */
728 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
729 struct abbrev_info
*next
; /* next in chain */
734 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
735 ENUM_BITFIELD(dwarf_form
) form
: 16;
738 /* Attributes have a name and a value. */
741 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
742 ENUM_BITFIELD(dwarf_form
) form
: 15;
744 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
745 field should be in u.str (existing only for DW_STRING) but it is kept
746 here for better struct attribute alignment. */
747 unsigned int string_is_canonical
: 1;
752 struct dwarf_block
*blk
;
756 struct signatured_type
*signatured_type
;
761 /* This data structure holds a complete die structure. */
764 /* DWARF-2 tag for this DIE. */
765 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
767 /* Number of attributes */
768 unsigned char num_attrs
;
770 /* True if we're presently building the full type name for the
771 type derived from this DIE. */
772 unsigned char building_fullname
: 1;
777 /* Offset in .debug_info or .debug_types section. */
780 /* The dies in a compilation unit form an n-ary tree. PARENT
781 points to this die's parent; CHILD points to the first child of
782 this node; and all the children of a given node are chained
783 together via their SIBLING fields. */
784 struct die_info
*child
; /* Its first child, if any. */
785 struct die_info
*sibling
; /* Its next sibling, if any. */
786 struct die_info
*parent
; /* Its parent, if any. */
788 /* An array of attributes, with NUM_ATTRS elements. There may be
789 zero, but it's not common and zero-sized arrays are not
790 sufficiently portable C. */
791 struct attribute attrs
[1];
794 /* Get at parts of an attribute structure. */
796 #define DW_STRING(attr) ((attr)->u.str)
797 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
798 #define DW_UNSND(attr) ((attr)->u.unsnd)
799 #define DW_BLOCK(attr) ((attr)->u.blk)
800 #define DW_SND(attr) ((attr)->u.snd)
801 #define DW_ADDR(attr) ((attr)->u.addr)
802 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
804 /* Blocks are a bunch of untyped bytes. */
809 /* Valid only if SIZE is not zero. */
813 #ifndef ATTR_ALLOC_CHUNK
814 #define ATTR_ALLOC_CHUNK 4
817 /* Allocate fields for structs, unions and enums in this size. */
818 #ifndef DW_FIELD_ALLOC_CHUNK
819 #define DW_FIELD_ALLOC_CHUNK 4
822 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
823 but this would require a corresponding change in unpack_field_as_long
825 static int bits_per_byte
= 8;
827 /* The routines that read and process dies for a C struct or C++ class
828 pass lists of data member fields and lists of member function fields
829 in an instance of a field_info structure, as defined below. */
832 /* List of data member and baseclasses fields. */
835 struct nextfield
*next
;
840 *fields
, *baseclasses
;
842 /* Number of fields (including baseclasses). */
845 /* Number of baseclasses. */
848 /* Set if the accesibility of one of the fields is not public. */
849 int non_public_fields
;
851 /* Member function fields array, entries are allocated in the order they
852 are encountered in the object file. */
855 struct nextfnfield
*next
;
856 struct fn_field fnfield
;
860 /* Member function fieldlist array, contains name of possibly overloaded
861 member function, number of overloaded member functions and a pointer
862 to the head of the member function field chain. */
867 struct nextfnfield
*head
;
871 /* Number of entries in the fnfieldlists array. */
874 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
875 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
876 struct typedef_field_list
878 struct typedef_field field
;
879 struct typedef_field_list
*next
;
882 unsigned typedef_field_list_count
;
885 /* One item on the queue of compilation units to read in full symbols
887 struct dwarf2_queue_item
889 struct dwarf2_per_cu_data
*per_cu
;
890 struct dwarf2_queue_item
*next
;
893 /* The current queue. */
894 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
896 /* Loaded secondary compilation units are kept in memory until they
897 have not been referenced for the processing of this many
898 compilation units. Set this to zero to disable caching. Cache
899 sizes of up to at least twenty will improve startup time for
900 typical inter-CU-reference binaries, at an obvious memory cost. */
901 static int dwarf2_max_cache_age
= 5;
903 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
904 struct cmd_list_element
*c
, const char *value
)
906 fprintf_filtered (file
, _("The upper bound on the age of cached "
907 "dwarf2 compilation units is %s.\n"),
912 /* Various complaints about symbol reading that don't abort the process. */
915 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
917 complaint (&symfile_complaints
,
918 _("statement list doesn't fit in .debug_line section"));
922 dwarf2_debug_line_missing_file_complaint (void)
924 complaint (&symfile_complaints
,
925 _(".debug_line section has line data without a file"));
929 dwarf2_debug_line_missing_end_sequence_complaint (void)
931 complaint (&symfile_complaints
,
932 _(".debug_line section has line "
933 "program sequence without an end"));
937 dwarf2_complex_location_expr_complaint (void)
939 complaint (&symfile_complaints
, _("location expression too complex"));
943 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
946 complaint (&symfile_complaints
,
947 _("const value length mismatch for '%s', got %d, expected %d"),
952 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
954 complaint (&symfile_complaints
,
955 _("macro info runs off end of `%s' section"),
956 section
->asection
->name
);
960 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
962 complaint (&symfile_complaints
,
963 _("macro debug info contains a "
964 "malformed macro definition:\n`%s'"),
969 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
971 complaint (&symfile_complaints
,
972 _("invalid attribute class or form for '%s' in '%s'"),
976 /* local function prototypes */
978 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
980 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
983 static void dwarf2_find_base_address (struct die_info
*die
,
984 struct dwarf2_cu
*cu
);
986 static void dwarf2_build_psymtabs_hard (struct objfile
*);
988 static void scan_partial_symbols (struct partial_die_info
*,
989 CORE_ADDR
*, CORE_ADDR
*,
990 int, struct dwarf2_cu
*);
992 static void add_partial_symbol (struct partial_die_info
*,
995 static void add_partial_namespace (struct partial_die_info
*pdi
,
996 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
997 int need_pc
, struct dwarf2_cu
*cu
);
999 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1000 CORE_ADDR
*highpc
, int need_pc
,
1001 struct dwarf2_cu
*cu
);
1003 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1004 struct dwarf2_cu
*cu
);
1006 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1007 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1008 int need_pc
, struct dwarf2_cu
*cu
);
1010 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1012 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1014 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1015 struct dwarf2_section_info
*);
1017 static void dwarf2_free_abbrev_table (void *);
1019 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1021 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1022 struct dwarf2_cu
*);
1024 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1025 struct dwarf2_cu
*);
1027 static struct partial_die_info
*load_partial_dies
1028 (const struct die_reader_specs
*, gdb_byte
*, int);
1030 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1031 struct partial_die_info
*,
1032 struct abbrev_info
*,
1036 static struct partial_die_info
*find_partial_die (sect_offset
,
1037 struct dwarf2_cu
*);
1039 static void fixup_partial_die (struct partial_die_info
*,
1040 struct dwarf2_cu
*);
1042 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1043 struct attribute
*, struct attr_abbrev
*,
1046 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1048 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1050 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1052 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1054 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1056 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1059 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1061 static LONGEST read_checked_initial_length_and_offset
1062 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1063 unsigned int *, unsigned int *);
1065 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1068 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1070 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1072 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1074 static char *read_indirect_string (bfd
*, gdb_byte
*,
1075 const struct comp_unit_head
*,
1078 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1080 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1082 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1085 static char *read_str_index (const struct die_reader_specs
*reader
,
1086 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1088 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1090 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1092 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1093 struct dwarf2_cu
*);
1095 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1100 struct dwarf2_cu
*cu
);
1102 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1104 static struct die_info
*die_specification (struct die_info
*die
,
1105 struct dwarf2_cu
**);
1107 static void free_line_header (struct line_header
*lh
);
1109 static void add_file_name (struct line_header
*, char *, unsigned int,
1110 unsigned int, unsigned int);
1112 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1113 struct dwarf2_cu
*cu
);
1115 static void dwarf_decode_lines (struct line_header
*, const char *,
1116 struct dwarf2_cu
*, struct partial_symtab
*,
1119 static void dwarf2_start_subfile (char *, const char *, const char *);
1121 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1122 struct dwarf2_cu
*);
1124 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1125 struct dwarf2_cu
*, struct symbol
*);
1127 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1128 struct dwarf2_cu
*);
1130 static void dwarf2_const_value_attr (struct attribute
*attr
,
1133 struct obstack
*obstack
,
1134 struct dwarf2_cu
*cu
, LONGEST
*value
,
1136 struct dwarf2_locexpr_baton
**baton
);
1138 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1140 static int need_gnat_info (struct dwarf2_cu
*);
1142 static struct type
*die_descriptive_type (struct die_info
*,
1143 struct dwarf2_cu
*);
1145 static void set_descriptive_type (struct type
*, struct die_info
*,
1146 struct dwarf2_cu
*);
1148 static struct type
*die_containing_type (struct die_info
*,
1149 struct dwarf2_cu
*);
1151 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1152 struct dwarf2_cu
*);
1154 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1156 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1158 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1160 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1161 const char *suffix
, int physname
,
1162 struct dwarf2_cu
*cu
);
1164 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1166 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1168 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1170 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1172 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1174 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1175 struct dwarf2_cu
*, struct partial_symtab
*);
1177 static int dwarf2_get_pc_bounds (struct die_info
*,
1178 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1179 struct partial_symtab
*);
1181 static void get_scope_pc_bounds (struct die_info
*,
1182 CORE_ADDR
*, CORE_ADDR
*,
1183 struct dwarf2_cu
*);
1185 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1186 CORE_ADDR
, struct dwarf2_cu
*);
1188 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1189 struct dwarf2_cu
*);
1191 static void dwarf2_attach_fields_to_type (struct field_info
*,
1192 struct type
*, struct dwarf2_cu
*);
1194 static void dwarf2_add_member_fn (struct field_info
*,
1195 struct die_info
*, struct type
*,
1196 struct dwarf2_cu
*);
1198 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1200 struct dwarf2_cu
*);
1202 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1204 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1206 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1208 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1210 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1212 static struct type
*read_module_type (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static const char *namespace_name (struct die_info
*die
,
1216 int *is_anonymous
, struct dwarf2_cu
*);
1218 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1220 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1222 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1223 struct dwarf2_cu
*);
1225 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1227 gdb_byte
**new_info_ptr
,
1228 struct die_info
*parent
);
1230 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1232 gdb_byte
**new_info_ptr
,
1233 struct die_info
*parent
);
1235 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1236 struct die_info
**, gdb_byte
*, int *, int);
1238 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1239 struct die_info
**, gdb_byte
*, int *);
1241 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1243 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1246 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1248 static const char *dwarf2_full_name (char *name
,
1249 struct die_info
*die
,
1250 struct dwarf2_cu
*cu
);
1252 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1253 struct dwarf2_cu
**);
1255 static char *dwarf_tag_name (unsigned int);
1257 static char *dwarf_attr_name (unsigned int);
1259 static char *dwarf_form_name (unsigned int);
1261 static char *dwarf_bool_name (unsigned int);
1263 static char *dwarf_type_encoding_name (unsigned int);
1266 static char *dwarf_cfi_name (unsigned int);
1269 static struct die_info
*sibling_die (struct die_info
*);
1271 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1273 static void dump_die_for_error (struct die_info
*);
1275 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1278 /*static*/ void dump_die (struct die_info
*, int max_level
);
1280 static void store_in_ref_table (struct die_info
*,
1281 struct dwarf2_cu
*);
1283 static int is_ref_attr (struct attribute
*);
1285 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1287 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1289 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1291 struct dwarf2_cu
**);
1293 static struct die_info
*follow_die_ref (struct die_info
*,
1295 struct dwarf2_cu
**);
1297 static struct die_info
*follow_die_sig (struct die_info
*,
1299 struct dwarf2_cu
**);
1301 static struct signatured_type
*lookup_signatured_type_at_offset
1302 (struct objfile
*objfile
,
1303 struct dwarf2_section_info
*section
, sect_offset offset
);
1305 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1307 static void read_signatured_type (struct signatured_type
*);
1309 /* memory allocation interface */
1311 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1313 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1315 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1317 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1318 char *, bfd
*, struct dwarf2_cu
*,
1319 struct dwarf2_section_info
*,
1322 static int attr_form_is_block (struct attribute
*);
1324 static int attr_form_is_section_offset (struct attribute
*);
1326 static int attr_form_is_constant (struct attribute
*);
1328 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1329 struct dwarf2_loclist_baton
*baton
,
1330 struct attribute
*attr
);
1332 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1334 struct dwarf2_cu
*cu
);
1336 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1338 struct abbrev_info
*abbrev
);
1340 static void free_stack_comp_unit (void *);
1342 static hashval_t
partial_die_hash (const void *item
);
1344 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1346 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1347 (sect_offset offset
, struct objfile
*objfile
);
1349 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1350 struct dwarf2_per_cu_data
*per_cu
);
1352 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1353 struct die_info
*comp_unit_die
);
1355 static void free_heap_comp_unit (void *);
1357 static void free_cached_comp_units (void *);
1359 static void age_cached_comp_units (void);
1361 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1363 static struct type
*set_die_type (struct die_info
*, struct type
*,
1364 struct dwarf2_cu
*);
1366 static void create_all_comp_units (struct objfile
*);
1368 static int create_all_type_units (struct objfile
*);
1370 static void load_full_comp_unit (struct dwarf2_per_cu_data
*);
1372 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1374 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1375 struct dwarf2_per_cu_data
*);
1377 static void dwarf2_mark (struct dwarf2_cu
*);
1379 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1381 static struct type
*get_die_type_at_offset (sect_offset
,
1382 struct dwarf2_per_cu_data
*per_cu
);
1384 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1386 static void dwarf2_release_queue (void *dummy
);
1388 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
);
1390 static void process_queue (void);
1392 static void find_file_and_directory (struct die_info
*die
,
1393 struct dwarf2_cu
*cu
,
1394 char **name
, char **comp_dir
);
1396 static char *file_full_name (int file
, struct line_header
*lh
,
1397 const char *comp_dir
);
1399 static gdb_byte
*read_and_check_comp_unit_head
1400 (struct comp_unit_head
*header
,
1401 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1402 int is_debug_types_section
);
1404 static void init_tu_and_read_dies
1405 (struct dwarf2_per_cu_data
*this_cu
, int keep
,
1406 die_reader_func_ftype
*die_reader_func
, void *data
);
1408 static void init_cutu_and_read_dies_simple
1409 (struct dwarf2_per_cu_data
*this_cu
,
1410 die_reader_func_ftype
*die_reader_func
, void *data
);
1412 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1414 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*);
1416 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1418 static struct dwo_unit
*lookup_dwo_comp_unit
1419 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1421 static struct dwo_unit
*lookup_dwo_type_unit
1422 (struct signatured_type
*, char *, const char *);
1424 static void free_dwo_file_cleanup (void *);
1426 static void munmap_section_buffer (struct dwarf2_section_info
*);
1430 /* Convert VALUE between big- and little-endian. */
1432 byte_swap (offset_type value
)
1436 result
= (value
& 0xff) << 24;
1437 result
|= (value
& 0xff00) << 8;
1438 result
|= (value
& 0xff0000) >> 8;
1439 result
|= (value
& 0xff000000) >> 24;
1443 #define MAYBE_SWAP(V) byte_swap (V)
1446 #define MAYBE_SWAP(V) (V)
1447 #endif /* WORDS_BIGENDIAN */
1449 /* The suffix for an index file. */
1450 #define INDEX_SUFFIX ".gdb-index"
1452 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1453 struct dwarf2_cu
*cu
);
1455 /* Try to locate the sections we need for DWARF 2 debugging
1456 information and return true if we have enough to do something.
1457 NAMES points to the dwarf2 section names, or is NULL if the standard
1458 ELF names are used. */
1461 dwarf2_has_info (struct objfile
*objfile
,
1462 const struct dwarf2_debug_sections
*names
)
1464 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1465 if (!dwarf2_per_objfile
)
1467 /* Initialize per-objfile state. */
1468 struct dwarf2_per_objfile
*data
1469 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1471 memset (data
, 0, sizeof (*data
));
1472 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1473 dwarf2_per_objfile
= data
;
1475 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1477 dwarf2_per_objfile
->objfile
= objfile
;
1479 return (dwarf2_per_objfile
->info
.asection
!= NULL
1480 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1483 /* When loading sections, we look either for uncompressed section or for
1484 compressed section names. */
1487 section_is_p (const char *section_name
,
1488 const struct dwarf2_section_names
*names
)
1490 if (names
->normal
!= NULL
1491 && strcmp (section_name
, names
->normal
) == 0)
1493 if (names
->compressed
!= NULL
1494 && strcmp (section_name
, names
->compressed
) == 0)
1499 /* This function is mapped across the sections and remembers the
1500 offset and size of each of the debugging sections we are interested
1504 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1506 const struct dwarf2_debug_sections
*names
;
1509 names
= &dwarf2_elf_names
;
1511 names
= (const struct dwarf2_debug_sections
*) vnames
;
1513 if (section_is_p (sectp
->name
, &names
->info
))
1515 dwarf2_per_objfile
->info
.asection
= sectp
;
1516 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1518 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1520 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1521 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1523 else if (section_is_p (sectp
->name
, &names
->line
))
1525 dwarf2_per_objfile
->line
.asection
= sectp
;
1526 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1528 else if (section_is_p (sectp
->name
, &names
->loc
))
1530 dwarf2_per_objfile
->loc
.asection
= sectp
;
1531 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1533 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1535 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1536 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1538 else if (section_is_p (sectp
->name
, &names
->macro
))
1540 dwarf2_per_objfile
->macro
.asection
= sectp
;
1541 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1543 else if (section_is_p (sectp
->name
, &names
->str
))
1545 dwarf2_per_objfile
->str
.asection
= sectp
;
1546 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1548 else if (section_is_p (sectp
->name
, &names
->addr
))
1550 dwarf2_per_objfile
->addr
.asection
= sectp
;
1551 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1553 else if (section_is_p (sectp
->name
, &names
->frame
))
1555 dwarf2_per_objfile
->frame
.asection
= sectp
;
1556 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1558 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1560 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1562 if (aflag
& SEC_HAS_CONTENTS
)
1564 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1565 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1568 else if (section_is_p (sectp
->name
, &names
->ranges
))
1570 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1571 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1573 else if (section_is_p (sectp
->name
, &names
->types
))
1575 struct dwarf2_section_info type_section
;
1577 memset (&type_section
, 0, sizeof (type_section
));
1578 type_section
.asection
= sectp
;
1579 type_section
.size
= bfd_get_section_size (sectp
);
1581 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1584 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1586 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1587 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1590 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1591 && bfd_section_vma (abfd
, sectp
) == 0)
1592 dwarf2_per_objfile
->has_section_at_zero
= 1;
1595 /* Decompress a section that was compressed using zlib. Store the
1596 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1599 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1600 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1602 bfd
*abfd
= sectp
->owner
;
1604 error (_("Support for zlib-compressed DWARF data (from '%s') "
1605 "is disabled in this copy of GDB"),
1606 bfd_get_filename (abfd
));
1608 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1609 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1610 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1611 bfd_size_type uncompressed_size
;
1612 gdb_byte
*uncompressed_buffer
;
1615 int header_size
= 12;
1617 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1618 || bfd_bread (compressed_buffer
,
1619 compressed_size
, abfd
) != compressed_size
)
1620 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1621 bfd_get_filename (abfd
));
1623 /* Read the zlib header. In this case, it should be "ZLIB" followed
1624 by the uncompressed section size, 8 bytes in big-endian order. */
1625 if (compressed_size
< header_size
1626 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1627 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1628 bfd_get_filename (abfd
));
1629 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1630 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1631 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1632 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1633 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1634 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1635 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1636 uncompressed_size
+= compressed_buffer
[11];
1638 /* It is possible the section consists of several compressed
1639 buffers concatenated together, so we uncompress in a loop. */
1643 strm
.avail_in
= compressed_size
- header_size
;
1644 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1645 strm
.avail_out
= uncompressed_size
;
1646 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1648 rc
= inflateInit (&strm
);
1649 while (strm
.avail_in
> 0)
1652 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1653 bfd_get_filename (abfd
), rc
);
1654 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1655 + (uncompressed_size
- strm
.avail_out
));
1656 rc
= inflate (&strm
, Z_FINISH
);
1657 if (rc
!= Z_STREAM_END
)
1658 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1659 bfd_get_filename (abfd
), rc
);
1660 rc
= inflateReset (&strm
);
1662 rc
= inflateEnd (&strm
);
1664 || strm
.avail_out
!= 0)
1665 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1666 bfd_get_filename (abfd
), rc
);
1668 do_cleanups (cleanup
);
1669 *outbuf
= uncompressed_buffer
;
1670 *outsize
= uncompressed_size
;
1674 /* A helper function that decides whether a section is empty. */
1677 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1679 return info
->asection
== NULL
|| info
->size
== 0;
1682 /* Read the contents of the section INFO.
1683 OBJFILE is the main object file, but not necessarily the file where
1684 the section comes from. E.g., for DWO files INFO->asection->owner
1685 is the bfd of the DWO file.
1686 If the section is compressed, uncompress it before returning. */
1689 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1691 asection
*sectp
= info
->asection
;
1693 gdb_byte
*buf
, *retbuf
;
1694 unsigned char header
[4];
1698 info
->buffer
= NULL
;
1699 info
->map_addr
= NULL
;
1702 if (dwarf2_section_empty_p (info
))
1705 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1706 abfd
= sectp
->owner
;
1708 /* Check if the file has a 4-byte header indicating compression. */
1709 if (info
->size
> sizeof (header
)
1710 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1711 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1713 /* Upon decompression, update the buffer and its size. */
1714 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1716 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1724 pagesize
= getpagesize ();
1726 /* Only try to mmap sections which are large enough: we don't want to
1727 waste space due to fragmentation. Also, only try mmap for sections
1728 without relocations. */
1730 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1732 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1733 MAP_PRIVATE
, sectp
->filepos
,
1734 &info
->map_addr
, &info
->map_len
);
1736 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1738 #if HAVE_POSIX_MADVISE
1739 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1746 /* If we get here, we are a normal, not-compressed section. */
1748 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1750 /* When debugging .o files, we may need to apply relocations; see
1751 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1752 We never compress sections in .o files, so we only need to
1753 try this when the section is not compressed. */
1754 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1757 info
->buffer
= retbuf
;
1761 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1762 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1763 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1764 bfd_get_filename (abfd
));
1767 /* A helper function that returns the size of a section in a safe way.
1768 If you are positive that the section has been read before using the
1769 size, then it is safe to refer to the dwarf2_section_info object's
1770 "size" field directly. In other cases, you must call this
1771 function, because for compressed sections the size field is not set
1772 correctly until the section has been read. */
1774 static bfd_size_type
1775 dwarf2_section_size (struct objfile
*objfile
,
1776 struct dwarf2_section_info
*info
)
1779 dwarf2_read_section (objfile
, info
);
1783 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1787 dwarf2_get_section_info (struct objfile
*objfile
,
1788 enum dwarf2_section_enum sect
,
1789 asection
**sectp
, gdb_byte
**bufp
,
1790 bfd_size_type
*sizep
)
1792 struct dwarf2_per_objfile
*data
1793 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1794 struct dwarf2_section_info
*info
;
1796 /* We may see an objfile without any DWARF, in which case we just
1807 case DWARF2_DEBUG_FRAME
:
1808 info
= &data
->frame
;
1810 case DWARF2_EH_FRAME
:
1811 info
= &data
->eh_frame
;
1814 gdb_assert_not_reached ("unexpected section");
1817 dwarf2_read_section (objfile
, info
);
1819 *sectp
= info
->asection
;
1820 *bufp
= info
->buffer
;
1821 *sizep
= info
->size
;
1825 /* DWARF quick_symbols_functions support. */
1827 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1828 unique line tables, so we maintain a separate table of all .debug_line
1829 derived entries to support the sharing.
1830 All the quick functions need is the list of file names. We discard the
1831 line_header when we're done and don't need to record it here. */
1832 struct quick_file_names
1834 /* The offset in .debug_line of the line table. We hash on this. */
1835 unsigned int offset
;
1837 /* The number of entries in file_names, real_names. */
1838 unsigned int num_file_names
;
1840 /* The file names from the line table, after being run through
1842 const char **file_names
;
1844 /* The file names from the line table after being run through
1845 gdb_realpath. These are computed lazily. */
1846 const char **real_names
;
1849 /* When using the index (and thus not using psymtabs), each CU has an
1850 object of this type. This is used to hold information needed by
1851 the various "quick" methods. */
1852 struct dwarf2_per_cu_quick_data
1854 /* The file table. This can be NULL if there was no file table
1855 or it's currently not read in.
1856 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1857 struct quick_file_names
*file_names
;
1859 /* The corresponding symbol table. This is NULL if symbols for this
1860 CU have not yet been read. */
1861 struct symtab
*symtab
;
1863 /* A temporary mark bit used when iterating over all CUs in
1864 expand_symtabs_matching. */
1865 unsigned int mark
: 1;
1867 /* True if we've tried to read the file table and found there isn't one.
1868 There will be no point in trying to read it again next time. */
1869 unsigned int no_file_data
: 1;
1872 /* Hash function for a quick_file_names. */
1875 hash_file_name_entry (const void *e
)
1877 const struct quick_file_names
*file_data
= e
;
1879 return file_data
->offset
;
1882 /* Equality function for a quick_file_names. */
1885 eq_file_name_entry (const void *a
, const void *b
)
1887 const struct quick_file_names
*ea
= a
;
1888 const struct quick_file_names
*eb
= b
;
1890 return ea
->offset
== eb
->offset
;
1893 /* Delete function for a quick_file_names. */
1896 delete_file_name_entry (void *e
)
1898 struct quick_file_names
*file_data
= e
;
1901 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1903 xfree ((void*) file_data
->file_names
[i
]);
1904 if (file_data
->real_names
)
1905 xfree ((void*) file_data
->real_names
[i
]);
1908 /* The space for the struct itself lives on objfile_obstack,
1909 so we don't free it here. */
1912 /* Create a quick_file_names hash table. */
1915 create_quick_file_names_table (unsigned int nr_initial_entries
)
1917 return htab_create_alloc (nr_initial_entries
,
1918 hash_file_name_entry
, eq_file_name_entry
,
1919 delete_file_name_entry
, xcalloc
, xfree
);
1922 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1923 have to be created afterwards. You should call age_cached_comp_units after
1924 processing PER_CU->CU. dw2_setup must have been already called. */
1927 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1929 if (per_cu
->is_debug_types
)
1930 load_full_type_unit (per_cu
);
1932 load_full_comp_unit (per_cu
);
1934 gdb_assert (per_cu
->cu
!= NULL
);
1936 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1939 /* Read in the symbols for PER_CU. */
1942 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1944 struct cleanup
*back_to
;
1946 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1948 queue_comp_unit (per_cu
);
1954 /* Age the cache, releasing compilation units that have not
1955 been used recently. */
1956 age_cached_comp_units ();
1958 do_cleanups (back_to
);
1961 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1962 the objfile from which this CU came. Returns the resulting symbol
1965 static struct symtab
*
1966 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1968 if (!per_cu
->v
.quick
->symtab
)
1970 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1971 increment_reading_symtab ();
1972 dw2_do_instantiate_symtab (per_cu
);
1973 do_cleanups (back_to
);
1975 return per_cu
->v
.quick
->symtab
;
1978 /* Return the CU given its index. */
1980 static struct dwarf2_per_cu_data
*
1981 dw2_get_cu (int index
)
1983 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1985 index
-= dwarf2_per_objfile
->n_comp_units
;
1986 return dwarf2_per_objfile
->all_type_units
[index
];
1988 return dwarf2_per_objfile
->all_comp_units
[index
];
1991 /* A helper function that knows how to read a 64-bit value in a way
1992 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1996 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1998 if (sizeof (ULONGEST
) < 8)
2002 /* Ignore the upper 4 bytes if they are all zero. */
2003 for (i
= 0; i
< 4; ++i
)
2004 if (bytes
[i
+ 4] != 0)
2007 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2010 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2014 /* Read the CU list from the mapped index, and use it to create all
2015 the CU objects for this objfile. Return 0 if something went wrong,
2016 1 if everything went ok. */
2019 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2020 offset_type cu_list_elements
)
2024 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2025 dwarf2_per_objfile
->all_comp_units
2026 = obstack_alloc (&objfile
->objfile_obstack
,
2027 dwarf2_per_objfile
->n_comp_units
2028 * sizeof (struct dwarf2_per_cu_data
*));
2030 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2032 struct dwarf2_per_cu_data
*the_cu
;
2033 ULONGEST offset
, length
;
2035 if (!extract_cu_value (cu_list
, &offset
)
2036 || !extract_cu_value (cu_list
+ 8, &length
))
2040 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2041 struct dwarf2_per_cu_data
);
2042 the_cu
->offset
.sect_off
= offset
;
2043 the_cu
->length
= length
;
2044 the_cu
->objfile
= objfile
;
2045 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2046 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2047 struct dwarf2_per_cu_quick_data
);
2048 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2054 /* Create the signatured type hash table from the index. */
2057 create_signatured_type_table_from_index (struct objfile
*objfile
,
2058 struct dwarf2_section_info
*section
,
2059 const gdb_byte
*bytes
,
2060 offset_type elements
)
2063 htab_t sig_types_hash
;
2065 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2066 dwarf2_per_objfile
->all_type_units
2067 = obstack_alloc (&objfile
->objfile_obstack
,
2068 dwarf2_per_objfile
->n_type_units
2069 * sizeof (struct dwarf2_per_cu_data
*));
2071 sig_types_hash
= allocate_signatured_type_table (objfile
);
2073 for (i
= 0; i
< elements
; i
+= 3)
2075 struct signatured_type
*sig_type
;
2076 ULONGEST offset
, type_offset_in_tu
, signature
;
2079 if (!extract_cu_value (bytes
, &offset
)
2080 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2082 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2085 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2086 struct signatured_type
);
2087 sig_type
->signature
= signature
;
2088 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2089 sig_type
->per_cu
.is_debug_types
= 1;
2090 sig_type
->per_cu
.info_or_types_section
= section
;
2091 sig_type
->per_cu
.offset
.sect_off
= offset
;
2092 sig_type
->per_cu
.objfile
= objfile
;
2093 sig_type
->per_cu
.v
.quick
2094 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2095 struct dwarf2_per_cu_quick_data
);
2097 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2100 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2103 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2108 /* Read the address map data from the mapped index, and use it to
2109 populate the objfile's psymtabs_addrmap. */
2112 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2114 const gdb_byte
*iter
, *end
;
2115 struct obstack temp_obstack
;
2116 struct addrmap
*mutable_map
;
2117 struct cleanup
*cleanup
;
2120 obstack_init (&temp_obstack
);
2121 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2122 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2124 iter
= index
->address_table
;
2125 end
= iter
+ index
->address_table_size
;
2127 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2131 ULONGEST hi
, lo
, cu_index
;
2132 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2134 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2136 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2139 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2140 dw2_get_cu (cu_index
));
2143 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2144 &objfile
->objfile_obstack
);
2145 do_cleanups (cleanup
);
2148 /* The hash function for strings in the mapped index. This is the same as
2149 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2150 implementation. This is necessary because the hash function is tied to the
2151 format of the mapped index file. The hash values do not have to match with
2154 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2157 mapped_index_string_hash (int index_version
, const void *p
)
2159 const unsigned char *str
= (const unsigned char *) p
;
2163 while ((c
= *str
++) != 0)
2165 if (index_version
>= 5)
2167 r
= r
* 67 + c
- 113;
2173 /* Find a slot in the mapped index INDEX for the object named NAME.
2174 If NAME is found, set *VEC_OUT to point to the CU vector in the
2175 constant pool and return 1. If NAME cannot be found, return 0. */
2178 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2179 offset_type
**vec_out
)
2181 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2183 offset_type slot
, step
;
2184 int (*cmp
) (const char *, const char *);
2186 if (current_language
->la_language
== language_cplus
2187 || current_language
->la_language
== language_java
2188 || current_language
->la_language
== language_fortran
)
2190 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2192 const char *paren
= strchr (name
, '(');
2198 dup
= xmalloc (paren
- name
+ 1);
2199 memcpy (dup
, name
, paren
- name
);
2200 dup
[paren
- name
] = 0;
2202 make_cleanup (xfree
, dup
);
2207 /* Index version 4 did not support case insensitive searches. But the
2208 indices for case insensitive languages are built in lowercase, therefore
2209 simulate our NAME being searched is also lowercased. */
2210 hash
= mapped_index_string_hash ((index
->version
== 4
2211 && case_sensitivity
== case_sensitive_off
2212 ? 5 : index
->version
),
2215 slot
= hash
& (index
->symbol_table_slots
- 1);
2216 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2217 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2221 /* Convert a slot number to an offset into the table. */
2222 offset_type i
= 2 * slot
;
2224 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2226 do_cleanups (back_to
);
2230 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2231 if (!cmp (name
, str
))
2233 *vec_out
= (offset_type
*) (index
->constant_pool
2234 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2235 do_cleanups (back_to
);
2239 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2243 /* Read the index file. If everything went ok, initialize the "quick"
2244 elements of all the CUs and return 1. Otherwise, return 0. */
2247 dwarf2_read_index (struct objfile
*objfile
)
2250 struct mapped_index
*map
;
2251 offset_type
*metadata
;
2252 const gdb_byte
*cu_list
;
2253 const gdb_byte
*types_list
= NULL
;
2254 offset_type version
, cu_list_elements
;
2255 offset_type types_list_elements
= 0;
2258 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2261 /* Older elfutils strip versions could keep the section in the main
2262 executable while splitting it for the separate debug info file. */
2263 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2264 & SEC_HAS_CONTENTS
) == 0)
2267 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2269 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2270 /* Version check. */
2271 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2272 /* Versions earlier than 3 emitted every copy of a psymbol. This
2273 causes the index to behave very poorly for certain requests. Version 3
2274 contained incomplete addrmap. So, it seems better to just ignore such
2278 static int warning_printed
= 0;
2279 if (!warning_printed
)
2281 warning (_("Skipping obsolete .gdb_index section in %s."),
2283 warning_printed
= 1;
2287 /* Index version 4 uses a different hash function than index version
2290 Versions earlier than 6 did not emit psymbols for inlined
2291 functions. Using these files will cause GDB not to be able to
2292 set breakpoints on inlined functions by name, so we ignore these
2293 indices unless the --use-deprecated-index-sections command line
2294 option was supplied. */
2295 if (version
< 6 && !use_deprecated_index_sections
)
2297 static int warning_printed
= 0;
2298 if (!warning_printed
)
2300 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2301 "--use-deprecated-index-sections to use them anyway"),
2303 warning_printed
= 1;
2307 /* Indexes with higher version than the one supported by GDB may be no
2308 longer backward compatible. */
2312 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2313 map
->version
= version
;
2314 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2316 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2319 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2320 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2324 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2325 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2326 - MAYBE_SWAP (metadata
[i
]))
2330 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2331 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2332 - MAYBE_SWAP (metadata
[i
]));
2335 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2336 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2337 - MAYBE_SWAP (metadata
[i
]))
2338 / (2 * sizeof (offset_type
)));
2341 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2343 /* Don't use the index if it's empty. */
2344 if (map
->symbol_table_slots
== 0)
2347 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2350 if (types_list_elements
)
2352 struct dwarf2_section_info
*section
;
2354 /* We can only handle a single .debug_types when we have an
2356 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2359 section
= VEC_index (dwarf2_section_info_def
,
2360 dwarf2_per_objfile
->types
, 0);
2362 if (!create_signatured_type_table_from_index (objfile
, section
,
2364 types_list_elements
))
2368 create_addrmap_from_index (objfile
, map
);
2370 dwarf2_per_objfile
->index_table
= map
;
2371 dwarf2_per_objfile
->using_index
= 1;
2372 dwarf2_per_objfile
->quick_file_names_table
=
2373 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2378 /* A helper for the "quick" functions which sets the global
2379 dwarf2_per_objfile according to OBJFILE. */
2382 dw2_setup (struct objfile
*objfile
)
2384 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2385 gdb_assert (dwarf2_per_objfile
);
2388 /* die_reader_func for dw2_get_file_names. */
2391 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2393 struct die_info
*comp_unit_die
,
2397 struct dwarf2_cu
*cu
= reader
->cu
;
2398 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2399 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2400 struct line_header
*lh
;
2401 struct attribute
*attr
;
2403 unsigned int bytes_read
;
2404 char *name
, *comp_dir
;
2406 struct quick_file_names
*qfn
;
2407 unsigned int line_offset
;
2413 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2416 struct quick_file_names find_entry
;
2418 line_offset
= DW_UNSND (attr
);
2420 /* We may have already read in this line header (TU line header sharing).
2421 If we have we're done. */
2422 find_entry
.offset
= line_offset
;
2423 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2424 &find_entry
, INSERT
);
2427 this_cu
->v
.quick
->file_names
= *slot
;
2431 lh
= dwarf_decode_line_header (line_offset
, cu
);
2435 this_cu
->v
.quick
->no_file_data
= 1;
2439 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2440 qfn
->offset
= line_offset
;
2441 gdb_assert (slot
!= NULL
);
2444 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2446 qfn
->num_file_names
= lh
->num_file_names
;
2447 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2448 lh
->num_file_names
* sizeof (char *));
2449 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2450 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2451 qfn
->real_names
= NULL
;
2453 free_line_header (lh
);
2455 this_cu
->v
.quick
->file_names
= qfn
;
2458 /* A helper for the "quick" functions which attempts to read the line
2459 table for THIS_CU. */
2461 static struct quick_file_names
*
2462 dw2_get_file_names (struct objfile
*objfile
,
2463 struct dwarf2_per_cu_data
*this_cu
)
2465 if (this_cu
->v
.quick
->file_names
!= NULL
)
2466 return this_cu
->v
.quick
->file_names
;
2467 /* If we know there is no line data, no point in looking again. */
2468 if (this_cu
->v
.quick
->no_file_data
)
2471 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2472 in the stub for CUs, there's is no need to lookup the DWO file.
2473 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2475 if (this_cu
->is_debug_types
)
2476 init_tu_and_read_dies (this_cu
, 0, dw2_get_file_names_reader
, NULL
);
2478 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2480 if (this_cu
->v
.quick
->no_file_data
)
2482 return this_cu
->v
.quick
->file_names
;
2485 /* A helper for the "quick" functions which computes and caches the
2486 real path for a given file name from the line table. */
2489 dw2_get_real_path (struct objfile
*objfile
,
2490 struct quick_file_names
*qfn
, int index
)
2492 if (qfn
->real_names
== NULL
)
2493 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2494 qfn
->num_file_names
, sizeof (char *));
2496 if (qfn
->real_names
[index
] == NULL
)
2497 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2499 return qfn
->real_names
[index
];
2502 static struct symtab
*
2503 dw2_find_last_source_symtab (struct objfile
*objfile
)
2507 dw2_setup (objfile
);
2508 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2509 return dw2_instantiate_symtab (dw2_get_cu (index
));
2512 /* Traversal function for dw2_forget_cached_source_info. */
2515 dw2_free_cached_file_names (void **slot
, void *info
)
2517 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2519 if (file_data
->real_names
)
2523 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2525 xfree ((void*) file_data
->real_names
[i
]);
2526 file_data
->real_names
[i
] = NULL
;
2534 dw2_forget_cached_source_info (struct objfile
*objfile
)
2536 dw2_setup (objfile
);
2538 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2539 dw2_free_cached_file_names
, NULL
);
2542 /* Helper function for dw2_map_symtabs_matching_filename that expands
2543 the symtabs and calls the iterator. */
2546 dw2_map_expand_apply (struct objfile
*objfile
,
2547 struct dwarf2_per_cu_data
*per_cu
,
2549 const char *full_path
, const char *real_path
,
2550 int (*callback
) (struct symtab
*, void *),
2553 struct symtab
*last_made
= objfile
->symtabs
;
2555 /* Don't visit already-expanded CUs. */
2556 if (per_cu
->v
.quick
->symtab
)
2559 /* This may expand more than one symtab, and we want to iterate over
2561 dw2_instantiate_symtab (per_cu
);
2563 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2564 objfile
->symtabs
, last_made
);
2567 /* Implementation of the map_symtabs_matching_filename method. */
2570 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2571 const char *full_path
, const char *real_path
,
2572 int (*callback
) (struct symtab
*, void *),
2576 const char *name_basename
= lbasename (name
);
2577 int name_len
= strlen (name
);
2578 int is_abs
= IS_ABSOLUTE_PATH (name
);
2580 dw2_setup (objfile
);
2582 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2583 + dwarf2_per_objfile
->n_type_units
); ++i
)
2586 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2587 struct quick_file_names
*file_data
;
2589 /* We only need to look at symtabs not already expanded. */
2590 if (per_cu
->v
.quick
->symtab
)
2593 file_data
= dw2_get_file_names (objfile
, per_cu
);
2594 if (file_data
== NULL
)
2597 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2599 const char *this_name
= file_data
->file_names
[j
];
2601 if (FILENAME_CMP (name
, this_name
) == 0
2602 || (!is_abs
&& compare_filenames_for_search (this_name
,
2605 if (dw2_map_expand_apply (objfile
, per_cu
,
2606 name
, full_path
, real_path
,
2611 /* Before we invoke realpath, which can get expensive when many
2612 files are involved, do a quick comparison of the basenames. */
2613 if (! basenames_may_differ
2614 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2617 if (full_path
!= NULL
)
2619 const char *this_real_name
= dw2_get_real_path (objfile
,
2622 if (this_real_name
!= NULL
2623 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2625 && compare_filenames_for_search (this_real_name
,
2628 if (dw2_map_expand_apply (objfile
, per_cu
,
2629 name
, full_path
, real_path
,
2635 if (real_path
!= NULL
)
2637 const char *this_real_name
= dw2_get_real_path (objfile
,
2640 if (this_real_name
!= NULL
2641 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2643 && compare_filenames_for_search (this_real_name
,
2646 if (dw2_map_expand_apply (objfile
, per_cu
,
2647 name
, full_path
, real_path
,
2658 static struct symtab
*
2659 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2660 const char *name
, domain_enum domain
)
2662 /* We do all the work in the pre_expand_symtabs_matching hook
2667 /* A helper function that expands all symtabs that hold an object
2671 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2673 dw2_setup (objfile
);
2675 /* index_table is NULL if OBJF_READNOW. */
2676 if (dwarf2_per_objfile
->index_table
)
2680 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2683 offset_type i
, len
= MAYBE_SWAP (*vec
);
2684 for (i
= 0; i
< len
; ++i
)
2686 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2687 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2689 dw2_instantiate_symtab (per_cu
);
2696 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2697 enum block_enum block_kind
, const char *name
,
2700 dw2_do_expand_symtabs_matching (objfile
, name
);
2704 dw2_print_stats (struct objfile
*objfile
)
2708 dw2_setup (objfile
);
2710 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2711 + dwarf2_per_objfile
->n_type_units
); ++i
)
2713 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2715 if (!per_cu
->v
.quick
->symtab
)
2718 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2722 dw2_dump (struct objfile
*objfile
)
2724 /* Nothing worth printing. */
2728 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2729 struct section_offsets
*delta
)
2731 /* There's nothing to relocate here. */
2735 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2736 const char *func_name
)
2738 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2742 dw2_expand_all_symtabs (struct objfile
*objfile
)
2746 dw2_setup (objfile
);
2748 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2749 + dwarf2_per_objfile
->n_type_units
); ++i
)
2751 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2753 dw2_instantiate_symtab (per_cu
);
2758 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2759 const char *filename
)
2763 dw2_setup (objfile
);
2765 /* We don't need to consider type units here.
2766 This is only called for examining code, e.g. expand_line_sal.
2767 There can be an order of magnitude (or more) more type units
2768 than comp units, and we avoid them if we can. */
2770 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2773 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2774 struct quick_file_names
*file_data
;
2776 /* We only need to look at symtabs not already expanded. */
2777 if (per_cu
->v
.quick
->symtab
)
2780 file_data
= dw2_get_file_names (objfile
, per_cu
);
2781 if (file_data
== NULL
)
2784 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2786 const char *this_name
= file_data
->file_names
[j
];
2787 if (FILENAME_CMP (this_name
, filename
) == 0)
2789 dw2_instantiate_symtab (per_cu
);
2797 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2799 struct dwarf2_per_cu_data
*per_cu
;
2801 struct quick_file_names
*file_data
;
2803 dw2_setup (objfile
);
2805 /* index_table is NULL if OBJF_READNOW. */
2806 if (!dwarf2_per_objfile
->index_table
)
2810 ALL_OBJFILE_SYMTABS (objfile
, s
)
2813 struct blockvector
*bv
= BLOCKVECTOR (s
);
2814 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2815 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2818 return sym
->symtab
->filename
;
2823 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2827 /* Note that this just looks at the very first one named NAME -- but
2828 actually we are looking for a function. find_main_filename
2829 should be rewritten so that it doesn't require a custom hook. It
2830 could just use the ordinary symbol tables. */
2831 /* vec[0] is the length, which must always be >0. */
2832 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2834 file_data
= dw2_get_file_names (objfile
, per_cu
);
2835 if (file_data
== NULL
)
2838 return file_data
->file_names
[file_data
->num_file_names
- 1];
2842 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2843 struct objfile
*objfile
, int global
,
2844 int (*callback
) (struct block
*,
2845 struct symbol
*, void *),
2846 void *data
, symbol_compare_ftype
*match
,
2847 symbol_compare_ftype
*ordered_compare
)
2849 /* Currently unimplemented; used for Ada. The function can be called if the
2850 current language is Ada for a non-Ada objfile using GNU index. As Ada
2851 does not look for non-Ada symbols this function should just return. */
2855 dw2_expand_symtabs_matching
2856 (struct objfile
*objfile
,
2857 int (*file_matcher
) (const char *, void *),
2858 int (*name_matcher
) (const char *, void *),
2859 enum search_domain kind
,
2864 struct mapped_index
*index
;
2866 dw2_setup (objfile
);
2868 /* index_table is NULL if OBJF_READNOW. */
2869 if (!dwarf2_per_objfile
->index_table
)
2871 index
= dwarf2_per_objfile
->index_table
;
2873 if (file_matcher
!= NULL
)
2875 struct cleanup
*cleanup
;
2876 htab_t visited_found
, visited_not_found
;
2878 visited_found
= htab_create_alloc (10,
2879 htab_hash_pointer
, htab_eq_pointer
,
2880 NULL
, xcalloc
, xfree
);
2881 cleanup
= make_cleanup_htab_delete (visited_found
);
2882 visited_not_found
= htab_create_alloc (10,
2883 htab_hash_pointer
, htab_eq_pointer
,
2884 NULL
, xcalloc
, xfree
);
2885 make_cleanup_htab_delete (visited_not_found
);
2887 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2888 + dwarf2_per_objfile
->n_type_units
); ++i
)
2891 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2892 struct quick_file_names
*file_data
;
2895 per_cu
->v
.quick
->mark
= 0;
2897 /* We only need to look at symtabs not already expanded. */
2898 if (per_cu
->v
.quick
->symtab
)
2901 file_data
= dw2_get_file_names (objfile
, per_cu
);
2902 if (file_data
== NULL
)
2905 if (htab_find (visited_not_found
, file_data
) != NULL
)
2907 else if (htab_find (visited_found
, file_data
) != NULL
)
2909 per_cu
->v
.quick
->mark
= 1;
2913 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2915 if (file_matcher (file_data
->file_names
[j
], data
))
2917 per_cu
->v
.quick
->mark
= 1;
2922 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2924 : visited_not_found
,
2929 do_cleanups (cleanup
);
2932 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2934 offset_type idx
= 2 * iter
;
2936 offset_type
*vec
, vec_len
, vec_idx
;
2938 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2941 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2943 if (! (*name_matcher
) (name
, data
))
2946 /* The name was matched, now expand corresponding CUs that were
2948 vec
= (offset_type
*) (index
->constant_pool
2949 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2950 vec_len
= MAYBE_SWAP (vec
[0]);
2951 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2953 struct dwarf2_per_cu_data
*per_cu
;
2955 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2956 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2957 dw2_instantiate_symtab (per_cu
);
2962 static struct symtab
*
2963 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2964 struct minimal_symbol
*msymbol
,
2966 struct obj_section
*section
,
2969 struct dwarf2_per_cu_data
*data
;
2971 dw2_setup (objfile
);
2973 if (!objfile
->psymtabs_addrmap
)
2976 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2980 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2981 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2982 paddress (get_objfile_arch (objfile
), pc
));
2984 return dw2_instantiate_symtab (data
);
2988 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2989 void *data
, int need_fullname
)
2992 struct cleanup
*cleanup
;
2993 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2994 NULL
, xcalloc
, xfree
);
2996 cleanup
= make_cleanup_htab_delete (visited
);
2997 dw2_setup (objfile
);
2999 /* We can ignore file names coming from already-expanded CUs. */
3000 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3001 + dwarf2_per_objfile
->n_type_units
); ++i
)
3003 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3005 if (per_cu
->v
.quick
->symtab
)
3007 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3010 *slot
= per_cu
->v
.quick
->file_names
;
3014 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3015 + dwarf2_per_objfile
->n_type_units
); ++i
)
3018 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3019 struct quick_file_names
*file_data
;
3022 /* We only need to look at symtabs not already expanded. */
3023 if (per_cu
->v
.quick
->symtab
)
3026 file_data
= dw2_get_file_names (objfile
, per_cu
);
3027 if (file_data
== NULL
)
3030 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3033 /* Already visited. */
3038 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3040 const char *this_real_name
;
3043 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3045 this_real_name
= NULL
;
3046 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3050 do_cleanups (cleanup
);
3054 dw2_has_symbols (struct objfile
*objfile
)
3059 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3062 dw2_find_last_source_symtab
,
3063 dw2_forget_cached_source_info
,
3064 dw2_map_symtabs_matching_filename
,
3066 dw2_pre_expand_symtabs_matching
,
3070 dw2_expand_symtabs_for_function
,
3071 dw2_expand_all_symtabs
,
3072 dw2_expand_symtabs_with_filename
,
3073 dw2_find_symbol_file
,
3074 dw2_map_matching_symbols
,
3075 dw2_expand_symtabs_matching
,
3076 dw2_find_pc_sect_symtab
,
3077 dw2_map_symbol_filenames
3080 /* Initialize for reading DWARF for this objfile. Return 0 if this
3081 file will use psymtabs, or 1 if using the GNU index. */
3084 dwarf2_initialize_objfile (struct objfile
*objfile
)
3086 /* If we're about to read full symbols, don't bother with the
3087 indices. In this case we also don't care if some other debug
3088 format is making psymtabs, because they are all about to be
3090 if ((objfile
->flags
& OBJF_READNOW
))
3094 dwarf2_per_objfile
->using_index
= 1;
3095 create_all_comp_units (objfile
);
3096 create_all_type_units (objfile
);
3097 dwarf2_per_objfile
->quick_file_names_table
=
3098 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3100 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3101 + dwarf2_per_objfile
->n_type_units
); ++i
)
3103 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3105 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3106 struct dwarf2_per_cu_quick_data
);
3109 /* Return 1 so that gdb sees the "quick" functions. However,
3110 these functions will be no-ops because we will have expanded
3115 if (dwarf2_read_index (objfile
))
3123 /* Build a partial symbol table. */
3126 dwarf2_build_psymtabs (struct objfile
*objfile
)
3128 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3130 init_psymbol_list (objfile
, 1024);
3133 dwarf2_build_psymtabs_hard (objfile
);
3136 /* Return TRUE if OFFSET is within CU_HEADER. */
3139 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3141 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3142 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3143 + cu_header
->initial_length_size
) };
3145 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3148 /* Read in the comp unit header information from the debug_info at info_ptr.
3149 NOTE: This leaves members offset, first_die_offset to be filled in
3153 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3154 gdb_byte
*info_ptr
, bfd
*abfd
)
3157 unsigned int bytes_read
;
3159 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3160 cu_header
->initial_length_size
= bytes_read
;
3161 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3162 info_ptr
+= bytes_read
;
3163 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3165 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3167 info_ptr
+= bytes_read
;
3168 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3170 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3171 if (signed_addr
< 0)
3172 internal_error (__FILE__
, __LINE__
,
3173 _("read_comp_unit_head: dwarf from non elf file"));
3174 cu_header
->signed_addr_p
= signed_addr
;
3179 /* Subroutine of read_and_check_comp_unit_head and
3180 read_and_check_type_unit_head to simplify them.
3181 Perform various error checking on the header. */
3184 error_check_comp_unit_head (struct comp_unit_head
*header
,
3185 struct dwarf2_section_info
*section
)
3187 bfd
*abfd
= section
->asection
->owner
;
3188 const char *filename
= bfd_get_filename (abfd
);
3190 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3191 error (_("Dwarf Error: wrong version in compilation unit header "
3192 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3195 if (header
->abbrev_offset
.sect_off
3196 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3197 &dwarf2_per_objfile
->abbrev
))
3198 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3199 "(offset 0x%lx + 6) [in module %s]"),
3200 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3203 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3204 avoid potential 32-bit overflow. */
3205 if (((unsigned long) header
->offset
.sect_off
3206 + header
->length
+ header
->initial_length_size
)
3208 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3209 "(offset 0x%lx + 0) [in module %s]"),
3210 (long) header
->length
, (long) header
->offset
.sect_off
,
3214 /* Read in a CU/TU header and perform some basic error checking.
3215 The contents of the header are stored in HEADER.
3216 The result is a pointer to the start of the first DIE. */
3219 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3220 struct dwarf2_section_info
*section
,
3222 int is_debug_types_section
)
3224 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3225 bfd
*abfd
= section
->asection
->owner
;
3227 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3229 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3231 /* If we're reading a type unit, skip over the signature and
3232 type_offset fields. */
3233 if (is_debug_types_section
)
3234 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3236 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3238 error_check_comp_unit_head (header
, section
);
3243 /* Read in the types comp unit header information from .debug_types entry at
3244 types_ptr. The result is a pointer to one past the end of the header. */
3247 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3248 struct dwarf2_section_info
*section
,
3250 ULONGEST
*signature
,
3251 cu_offset
*type_offset_in_tu
)
3253 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3254 bfd
*abfd
= section
->asection
->owner
;
3256 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3258 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3260 /* If we're reading a type unit, skip over the signature and
3261 type_offset fields. */
3262 if (signature
!= NULL
)
3263 *signature
= read_8_bytes (abfd
, info_ptr
);
3265 if (type_offset_in_tu
!= NULL
)
3266 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3267 header
->offset_size
);
3268 info_ptr
+= header
->offset_size
;
3270 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3272 error_check_comp_unit_head (header
, section
);
3277 /* Allocate a new partial symtab for file named NAME and mark this new
3278 partial symtab as being an include of PST. */
3281 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3282 struct objfile
*objfile
)
3284 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3286 subpst
->section_offsets
= pst
->section_offsets
;
3287 subpst
->textlow
= 0;
3288 subpst
->texthigh
= 0;
3290 subpst
->dependencies
= (struct partial_symtab
**)
3291 obstack_alloc (&objfile
->objfile_obstack
,
3292 sizeof (struct partial_symtab
*));
3293 subpst
->dependencies
[0] = pst
;
3294 subpst
->number_of_dependencies
= 1;
3296 subpst
->globals_offset
= 0;
3297 subpst
->n_global_syms
= 0;
3298 subpst
->statics_offset
= 0;
3299 subpst
->n_static_syms
= 0;
3300 subpst
->symtab
= NULL
;
3301 subpst
->read_symtab
= pst
->read_symtab
;
3304 /* No private part is necessary for include psymtabs. This property
3305 can be used to differentiate between such include psymtabs and
3306 the regular ones. */
3307 subpst
->read_symtab_private
= NULL
;
3310 /* Read the Line Number Program data and extract the list of files
3311 included by the source file represented by PST. Build an include
3312 partial symtab for each of these included files. */
3315 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3316 struct die_info
*die
,
3317 struct partial_symtab
*pst
)
3319 struct line_header
*lh
= NULL
;
3320 struct attribute
*attr
;
3322 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3324 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3326 return; /* No linetable, so no includes. */
3328 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3329 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3331 free_line_header (lh
);
3335 hash_signatured_type (const void *item
)
3337 const struct signatured_type
*sig_type
= item
;
3339 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3340 return sig_type
->signature
;
3344 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3346 const struct signatured_type
*lhs
= item_lhs
;
3347 const struct signatured_type
*rhs
= item_rhs
;
3349 return lhs
->signature
== rhs
->signature
;
3352 /* Allocate a hash table for signatured types. */
3355 allocate_signatured_type_table (struct objfile
*objfile
)
3357 return htab_create_alloc_ex (41,
3358 hash_signatured_type
,
3361 &objfile
->objfile_obstack
,
3362 hashtab_obstack_allocate
,
3363 dummy_obstack_deallocate
);
3366 /* A helper function to add a signatured type CU to a table. */
3369 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3371 struct signatured_type
*sigt
= *slot
;
3372 struct dwarf2_per_cu_data
***datap
= datum
;
3374 **datap
= &sigt
->per_cu
;
3380 /* Create the hash table of all entries in the .debug_types section.
3381 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3382 The result is a pointer to the hash table or NULL if there are
3386 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3387 VEC (dwarf2_section_info_def
) *types
)
3389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3390 htab_t types_htab
= NULL
;
3392 struct dwarf2_section_info
*section
;
3394 if (VEC_empty (dwarf2_section_info_def
, types
))
3398 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3402 gdb_byte
*info_ptr
, *end_ptr
;
3404 dwarf2_read_section (objfile
, section
);
3405 info_ptr
= section
->buffer
;
3407 if (info_ptr
== NULL
)
3410 /* We can't set abfd until now because the section may be empty or
3411 not present, in which case section->asection will be NULL. */
3412 abfd
= section
->asection
->owner
;
3414 if (types_htab
== NULL
)
3417 types_htab
= allocate_dwo_unit_table (objfile
);
3419 types_htab
= allocate_signatured_type_table (objfile
);
3422 if (dwarf2_die_debug
)
3423 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3424 bfd_get_filename (abfd
));
3426 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3427 because we don't need to read any dies: the signature is in the
3430 end_ptr
= info_ptr
+ section
->size
;
3431 while (info_ptr
< end_ptr
)
3434 cu_offset type_offset_in_tu
;
3436 struct signatured_type
*sig_type
;
3437 struct dwo_unit
*dwo_tu
;
3439 gdb_byte
*ptr
= info_ptr
;
3440 struct comp_unit_head header
;
3441 unsigned int length
;
3443 offset
.sect_off
= ptr
- section
->buffer
;
3445 /* We need to read the type's signature in order to build the hash
3446 table, but we don't need anything else just yet. */
3448 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3449 &signature
, &type_offset_in_tu
);
3451 length
= header
.initial_length_size
+ header
.length
;
3453 /* Skip dummy type units. */
3454 if (ptr
>= info_ptr
+ length
3455 || peek_abbrev_code (abfd
, ptr
) == 0)
3457 info_ptr
+= header
.initial_length_size
+ header
.length
;
3464 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3466 dwo_tu
->dwo_file
= dwo_file
;
3467 dwo_tu
->signature
= signature
;
3468 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3469 dwo_tu
->info_or_types_section
= section
;
3470 dwo_tu
->offset
= offset
;
3471 dwo_tu
->length
= length
;
3475 /* N.B.: type_offset is not usable if this type uses a DWO file.
3476 The real type_offset is in the DWO file. */
3478 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3479 struct signatured_type
);
3480 sig_type
->signature
= signature
;
3481 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3482 sig_type
->per_cu
.objfile
= objfile
;
3483 sig_type
->per_cu
.is_debug_types
= 1;
3484 sig_type
->per_cu
.info_or_types_section
= section
;
3485 sig_type
->per_cu
.offset
= offset
;
3486 sig_type
->per_cu
.length
= length
;
3489 slot
= htab_find_slot (types_htab
,
3490 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3492 gdb_assert (slot
!= NULL
);
3495 sect_offset dup_offset
;
3499 const struct dwo_unit
*dup_tu
= *slot
;
3501 dup_offset
= dup_tu
->offset
;
3505 const struct signatured_type
*dup_tu
= *slot
;
3507 dup_offset
= dup_tu
->per_cu
.offset
;
3510 complaint (&symfile_complaints
,
3511 _("debug type entry at offset 0x%x is duplicate to the "
3512 "entry at offset 0x%x, signature 0x%s"),
3513 offset
.sect_off
, dup_offset
.sect_off
,
3514 phex (signature
, sizeof (signature
)));
3516 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3518 if (dwarf2_die_debug
)
3519 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3521 phex (signature
, sizeof (signature
)));
3530 /* Create the hash table of all entries in the .debug_types section,
3531 and initialize all_type_units.
3532 The result is zero if there is an error (e.g. missing .debug_types section),
3533 otherwise non-zero. */
3536 create_all_type_units (struct objfile
*objfile
)
3539 struct dwarf2_per_cu_data
**iter
;
3541 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3542 if (types_htab
== NULL
)
3544 dwarf2_per_objfile
->signatured_types
= NULL
;
3548 dwarf2_per_objfile
->signatured_types
= types_htab
;
3550 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3551 dwarf2_per_objfile
->all_type_units
3552 = obstack_alloc (&objfile
->objfile_obstack
,
3553 dwarf2_per_objfile
->n_type_units
3554 * sizeof (struct dwarf2_per_cu_data
*));
3555 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3556 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3557 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3558 == dwarf2_per_objfile
->n_type_units
);
3563 /* Lookup a signature based type for DW_FORM_ref_sig8.
3564 Returns NULL if signature SIG is not present in the table. */
3566 static struct signatured_type
*
3567 lookup_signatured_type (ULONGEST sig
)
3569 struct signatured_type find_entry
, *entry
;
3571 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3573 complaint (&symfile_complaints
,
3574 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3578 find_entry
.signature
= sig
;
3579 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3583 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3586 init_cu_die_reader (struct die_reader_specs
*reader
,
3587 struct dwarf2_cu
*cu
,
3588 struct dwarf2_section_info
*section
,
3589 struct dwo_file
*dwo_file
)
3591 gdb_assert (section
->readin
);
3592 reader
->abfd
= section
->asection
->owner
;
3594 reader
->dwo_file
= dwo_file
;
3595 reader
->die_section
= section
;
3596 reader
->buffer
= section
->buffer
;
3599 /* Find the base address of the compilation unit for range lists and
3600 location lists. It will normally be specified by DW_AT_low_pc.
3601 In DWARF-3 draft 4, the base address could be overridden by
3602 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3603 compilation units with discontinuous ranges. */
3606 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3608 struct attribute
*attr
;
3611 cu
->base_address
= 0;
3613 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3616 cu
->base_address
= DW_ADDR (attr
);
3621 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3624 cu
->base_address
= DW_ADDR (attr
);
3630 /* Subroutine of init_{cu,tu}_and_read_dies.
3631 Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s).
3632 If the CU defers to a DWO file, read the DWO file as well.
3634 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3635 Otherwise, a new CU is allocated with xmalloc.
3637 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3638 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3640 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3641 linker) then DIE_READER_FUNC will not get called.
3643 FIXME: As an implementation detail between our callers and us,
3644 USE_EXISTING_CU and KEEP are OK. But bubbling them up into their callers
3645 isn't as clean as I'd like. Having more callers with good names
3646 may be the way to go. */
3649 init_and_read_dies_worker (struct dwarf2_per_cu_data
*this_cu
,
3650 int use_existing_cu
, int keep
,
3651 die_reader_func_ftype
*die_reader_func
,
3654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3655 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3656 bfd
*abfd
= section
->asection
->owner
;
3657 struct dwarf2_cu
*cu
;
3658 gdb_byte
*begin_info_ptr
, *info_ptr
;
3659 struct die_reader_specs reader
;
3660 struct die_info
*comp_unit_die
;
3662 struct attribute
*attr
;
3663 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3664 struct signatured_type
*sig_type
= NULL
;
3666 if (use_existing_cu
)
3668 if (this_cu
->is_debug_types
)
3669 gdb_assert (! use_existing_cu
);
3671 cleanups
= make_cleanup (null_cleanup
, NULL
);
3673 /* This is cheap if the section is already read in. */
3674 dwarf2_read_section (objfile
, section
);
3676 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3678 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3681 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3685 /* If !use_existing_cu, this_cu->cu must be NULL. */
3686 gdb_assert (this_cu
->cu
== NULL
);
3688 cu
= xmalloc (sizeof (*cu
));
3689 init_one_comp_unit (cu
, this_cu
);
3691 /* If an error occurs while loading, release our storage. */
3692 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3694 if (this_cu
->is_debug_types
)
3698 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3702 /* There's no way to get from PER_CU to its containing
3703 struct signatured_type.
3704 But we have the signature so we can use that. */
3705 sig_type
= lookup_signatured_type (signature
);
3706 /* We've already scanned all the signatured types,
3707 this must succeed. */
3708 gdb_assert (sig_type
!= NULL
);
3709 gdb_assert (&sig_type
->per_cu
== this_cu
);
3710 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3712 /* LENGTH has not been set yet for type units. */
3713 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3715 /* Establish the type offset that can be used to lookup the type. */
3716 sig_type
->type_offset_in_section
.sect_off
=
3717 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3721 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3722 section
, info_ptr
, 0);
3724 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3725 gdb_assert (this_cu
->length
3726 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3730 /* Skip dummy compilation units. */
3731 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3732 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3734 do_cleanups (cleanups
);
3738 /* Read the abbrevs for this compilation unit into a table. */
3739 if (cu
->dwarf2_abbrevs
== NULL
)
3741 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3742 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3745 /* Read the top level CU/TU die. */
3746 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3747 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3749 /* If we have a DWO stub, process it and then read in the DWO file.
3750 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3751 a DWO CU, that this test will fail. */
3752 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3755 char *dwo_name
= DW_STRING (attr
);
3756 const char *comp_dir
;
3757 struct dwo_unit
*dwo_unit
;
3758 ULONGEST signature
; /* Or dwo_id. */
3759 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3760 int i
,num_extra_attrs
;
3763 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3764 " has children (offset 0x%x) [in module %s]"),
3765 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3767 /* These attributes aren't processed until later:
3768 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3769 However, the attribute is found in the stub which we won't have later.
3770 In order to not impose this complication on the rest of the code,
3771 we read them here and copy them to the DWO CU/TU die. */
3772 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3774 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3776 if (! this_cu
->is_debug_types
)
3777 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3778 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3779 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3780 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3782 /* There should be a DW_AT_addr_base attribute here (if needed).
3783 We need the value before we can process DW_FORM_GNU_addr_index. */
3785 cu
->have_addr_base
= 0;
3786 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3789 cu
->addr_base
= DW_UNSND (attr
);
3790 cu
->have_addr_base
= 1;
3793 if (this_cu
->is_debug_types
)
3795 gdb_assert (sig_type
!= NULL
);
3796 signature
= sig_type
->signature
;
3800 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
3802 error (_("Dwarf Error: missing dwo_id [in module %s]"),
3804 signature
= DW_UNSND (attr
);
3807 /* We may need the comp_dir in order to find the DWO file. */
3809 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3811 comp_dir
= DW_STRING (attr
);
3813 if (this_cu
->is_debug_types
)
3814 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
3816 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
3819 if (dwo_unit
== NULL
)
3821 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
3822 " with ID %s [in module %s]"),
3823 this_cu
->offset
.sect_off
,
3824 phex (signature
, sizeof (signature
)),
3828 /* Set up for reading the DWO CU/TU. */
3829 cu
->dwo_unit
= dwo_unit
;
3830 section
= dwo_unit
->info_or_types_section
;
3831 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
3832 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
3834 if (this_cu
->is_debug_types
)
3838 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3841 gdb_assert (sig_type
->signature
== signature
);
3842 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3843 gdb_assert (dwo_unit
->length
3844 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3846 /* Establish the type offset that can be used to lookup the type.
3847 For DWO files, we don't know it until now. */
3848 sig_type
->type_offset_in_section
.sect_off
=
3849 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
3853 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3854 section
, info_ptr
, 0);
3855 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3856 gdb_assert (dwo_unit
->length
3857 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3860 /* Discard the original CU's abbrev table, and read the DWO's. */
3861 dwarf2_free_abbrev_table (cu
);
3862 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
3864 /* Read in the die, but leave space to copy over the attributes
3865 from the stub. This has the benefit of simplifying the rest of
3866 the code - all the real work is done here. */
3867 num_extra_attrs
= ((stmt_list
!= NULL
)
3870 + (ranges
!= NULL
));
3871 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
3872 &has_children
, num_extra_attrs
);
3874 /* Copy over the attributes from the stub to the DWO die. */
3875 i
= comp_unit_die
->num_attrs
;
3876 if (stmt_list
!= NULL
)
3877 comp_unit_die
->attrs
[i
++] = *stmt_list
;
3879 comp_unit_die
->attrs
[i
++] = *low_pc
;
3880 if (high_pc
!= NULL
)
3881 comp_unit_die
->attrs
[i
++] = *high_pc
;
3883 comp_unit_die
->attrs
[i
++] = *ranges
;
3884 comp_unit_die
->num_attrs
+= num_extra_attrs
;
3886 /* Skip dummy compilation units. */
3887 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
3888 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3890 do_cleanups (cleanups
);
3895 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3897 if (free_cu_cleanup
!= NULL
)
3901 /* We've successfully allocated this compilation unit. Let our
3902 caller clean it up when finished with it. */
3903 discard_cleanups (free_cu_cleanup
);
3905 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3906 So we have to manually free the abbrev table. */
3907 dwarf2_free_abbrev_table (cu
);
3909 /* Link this CU into read_in_chain. */
3910 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3911 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3914 do_cleanups (free_cu_cleanup
);
3917 do_cleanups (cleanups
);
3920 /* Main entry point for reading a CU.
3921 Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s).
3922 If the CU defers to a DWO file, read the DWO file as well.
3924 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3925 Otherwise, a new CU is allocated with xmalloc.
3927 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3928 read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */
3931 init_cu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3932 int use_existing_cu
, int keep
,
3933 die_reader_func_ftype
*die_reader_func
,
3936 init_and_read_dies_worker (this_cu
, use_existing_cu
, keep
,
3937 die_reader_func
, data
);
3940 /* Main entry point for reading a TU.
3941 Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s).
3942 If the TU defers to a DWO file, read the DWO file as well.
3944 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3945 read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */
3948 init_tu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3950 die_reader_func_ftype
*die_reader_func
,
3953 gdb_assert (this_cu
->is_debug_types
);
3954 init_and_read_dies_worker (this_cu
, 0, keep
, die_reader_func
, data
);
3957 /* Read CU/TU THIS_CU in section SECTION,
3958 but do not follow DW_AT_GNU_dwo_name if present.
3959 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
3960 have already done the lookup to find the DWO file).
3962 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3963 THIS_CU->is_debug_types, but nothing else.
3965 We fill in THIS_CU->length.
3967 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3968 linker) then DIE_READER_FUNC will not get called.
3970 THIS_CU->cu is always freed when done.
3971 This is done in order to not leave THIS_CU->cu in a state where we have
3972 to care whether it refers to the "main" CU or the DWO CU. */
3975 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3976 struct dwarf2_section_info
*abbrev_section
,
3977 struct dwo_file
*dwo_file
,
3978 die_reader_func_ftype
*die_reader_func
,
3981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3982 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3983 bfd
*abfd
= section
->asection
->owner
;
3984 struct dwarf2_cu cu
;
3985 gdb_byte
*begin_info_ptr
, *info_ptr
;
3986 struct die_reader_specs reader
;
3987 struct cleanup
*cleanups
;
3988 struct die_info
*comp_unit_die
;
3991 gdb_assert (this_cu
->cu
== NULL
);
3993 /* This is cheap if the section is already read in. */
3994 dwarf2_read_section (objfile
, section
);
3996 init_one_comp_unit (&cu
, this_cu
);
3998 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4000 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4001 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
4002 this_cu
->is_debug_types
);
4004 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4006 /* Skip dummy compilation units. */
4007 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4008 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4010 do_cleanups (cleanups
);
4014 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4015 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4017 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4018 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4020 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4022 do_cleanups (cleanups
);
4025 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4026 does not lookup the specified DWO file.
4027 This cannot be used to read DWO files.
4029 THIS_CU->cu is always freed when done.
4030 This is done in order to not leave THIS_CU->cu in a state where we have
4031 to care whether it refers to the "main" CU or the DWO CU.
4032 We can revisit this if the data shows there's a performance issue. */
4035 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4036 die_reader_func_ftype
*die_reader_func
,
4039 init_cutu_and_read_dies_no_follow (this_cu
,
4040 &dwarf2_per_objfile
->abbrev
,
4042 die_reader_func
, data
);
4045 /* die_reader_func for process_psymtab_comp_unit. */
4048 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4050 struct die_info
*comp_unit_die
,
4054 struct dwarf2_cu
*cu
= reader
->cu
;
4055 struct objfile
*objfile
= cu
->objfile
;
4056 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4057 bfd
*abfd
= objfile
->obfd
;
4058 struct attribute
*attr
;
4060 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4061 struct partial_symtab
*pst
;
4063 const char *filename
;
4065 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4068 prepare_one_comp_unit (cu
, comp_unit_die
);
4070 cu
->list_in_scope
= &file_symbols
;
4072 /* Allocate a new partial symbol table structure. */
4073 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4074 if (attr
== NULL
|| !DW_STRING (attr
))
4077 filename
= DW_STRING (attr
);
4078 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4080 /* TEXTLOW and TEXTHIGH are set below. */
4082 objfile
->global_psymbols
.next
,
4083 objfile
->static_psymbols
.next
);
4084 pst
->psymtabs_addrmap_supported
= 1;
4086 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4088 pst
->dirname
= DW_STRING (attr
);
4090 pst
->read_symtab_private
= per_cu
;
4092 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4094 /* Store the function that reads in the rest of the symbol table. */
4095 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4097 per_cu
->v
.psymtab
= pst
;
4099 dwarf2_find_base_address (comp_unit_die
, cu
);
4101 /* Possibly set the default values of LOWPC and HIGHPC from
4103 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4104 &best_highpc
, cu
, pst
);
4105 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4106 /* Store the contiguous range if it is not empty; it can be empty for
4107 CUs with no code. */
4108 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4109 best_lowpc
+ baseaddr
,
4110 best_highpc
+ baseaddr
- 1, pst
);
4112 /* Check if comp unit has_children.
4113 If so, read the rest of the partial symbols from this comp unit.
4114 If not, there's no more debug_info for this comp unit. */
4117 struct partial_die_info
*first_die
;
4118 CORE_ADDR lowpc
, highpc
;
4120 lowpc
= ((CORE_ADDR
) -1);
4121 highpc
= ((CORE_ADDR
) 0);
4123 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4125 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4128 /* If we didn't find a lowpc, set it to highpc to avoid
4129 complaints from `maint check'. */
4130 if (lowpc
== ((CORE_ADDR
) -1))
4133 /* If the compilation unit didn't have an explicit address range,
4134 then use the information extracted from its child dies. */
4138 best_highpc
= highpc
;
4141 pst
->textlow
= best_lowpc
+ baseaddr
;
4142 pst
->texthigh
= best_highpc
+ baseaddr
;
4144 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4145 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4146 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4147 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4148 sort_pst_symbols (pst
);
4150 if (per_cu
->is_debug_types
)
4152 /* It's not clear we want to do anything with stmt lists here.
4153 Waiting to see what gcc ultimately does. */
4157 /* Get the list of files included in the current compilation unit,
4158 and build a psymtab for each of them. */
4159 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4163 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4164 Process compilation unit THIS_CU for a psymtab. */
4167 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4169 /* If this compilation unit was already read in, free the
4170 cached copy in order to read it in again. This is
4171 necessary because we skipped some symbols when we first
4172 read in the compilation unit (see load_partial_dies).
4173 This problem could be avoided, but the benefit is unclear. */
4174 if (this_cu
->cu
!= NULL
)
4175 free_one_cached_comp_unit (this_cu
);
4177 gdb_assert (! this_cu
->is_debug_types
);
4178 init_cu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4181 /* Age out any secondary CUs. */
4182 age_cached_comp_units ();
4185 /* Traversal function for htab_traverse_noresize.
4186 Process one .debug_types comp-unit. */
4189 process_psymtab_type_unit (void **slot
, void *info
)
4191 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4192 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4194 gdb_assert (info
== NULL
);
4196 /* If this compilation unit was already read in, free the
4197 cached copy in order to read it in again. This is
4198 necessary because we skipped some symbols when we first
4199 read in the compilation unit (see load_partial_dies).
4200 This problem could be avoided, but the benefit is unclear. */
4201 if (per_cu
->cu
!= NULL
)
4202 free_one_cached_comp_unit (per_cu
);
4204 gdb_assert (per_cu
->is_debug_types
);
4205 init_tu_and_read_dies (per_cu
, 0, process_psymtab_comp_unit_reader
, NULL
);
4207 /* Age out any secondary CUs. */
4208 age_cached_comp_units ();
4213 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4214 Build partial symbol tables for the .debug_types comp-units. */
4217 build_type_psymtabs (struct objfile
*objfile
)
4219 if (! create_all_type_units (objfile
))
4222 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4223 process_psymtab_type_unit
, NULL
);
4226 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4229 psymtabs_addrmap_cleanup (void *o
)
4231 struct objfile
*objfile
= o
;
4233 objfile
->psymtabs_addrmap
= NULL
;
4236 /* Build the partial symbol table by doing a quick pass through the
4237 .debug_info and .debug_abbrev sections. */
4240 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4242 struct cleanup
*back_to
, *addrmap_cleanup
;
4243 struct obstack temp_obstack
;
4246 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4248 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4250 /* Any cached compilation units will be linked by the per-objfile
4251 read_in_chain. Make sure to free them when we're done. */
4252 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4254 build_type_psymtabs (objfile
);
4256 create_all_comp_units (objfile
);
4258 /* Create a temporary address map on a temporary obstack. We later
4259 copy this to the final obstack. */
4260 obstack_init (&temp_obstack
);
4261 make_cleanup_obstack_free (&temp_obstack
);
4262 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4263 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4265 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4267 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4269 process_psymtab_comp_unit (per_cu
);
4272 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4273 &objfile
->objfile_obstack
);
4274 discard_cleanups (addrmap_cleanup
);
4276 do_cleanups (back_to
);
4279 /* die_reader_func for load_partial_comp_unit. */
4282 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4284 struct die_info
*comp_unit_die
,
4288 struct dwarf2_cu
*cu
= reader
->cu
;
4290 prepare_one_comp_unit (cu
, comp_unit_die
);
4292 /* Check if comp unit has_children.
4293 If so, read the rest of the partial symbols from this comp unit.
4294 If not, there's no more debug_info for this comp unit. */
4296 load_partial_dies (reader
, info_ptr
, 0);
4299 /* Load the partial DIEs for a secondary CU into memory.
4300 This is also used when rereading a primary CU with load_all_dies. */
4303 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4305 if (this_cu
->is_debug_types
)
4306 init_tu_and_read_dies (this_cu
, 1, load_partial_comp_unit_reader
, NULL
);
4308 init_cu_and_read_dies (this_cu
, 0, 1, load_partial_comp_unit_reader
, NULL
);
4311 /* Create a list of all compilation units in OBJFILE.
4312 This is only done for -readnow and building partial symtabs. */
4315 create_all_comp_units (struct objfile
*objfile
)
4319 struct dwarf2_per_cu_data
**all_comp_units
;
4322 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4323 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4327 all_comp_units
= xmalloc (n_allocated
4328 * sizeof (struct dwarf2_per_cu_data
*));
4330 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4331 + dwarf2_per_objfile
->info
.size
)
4333 unsigned int length
, initial_length_size
;
4334 struct dwarf2_per_cu_data
*this_cu
;
4337 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4339 /* Read just enough information to find out where the next
4340 compilation unit is. */
4341 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4342 &initial_length_size
);
4344 /* Save the compilation unit for later lookup. */
4345 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4346 sizeof (struct dwarf2_per_cu_data
));
4347 memset (this_cu
, 0, sizeof (*this_cu
));
4348 this_cu
->offset
= offset
;
4349 this_cu
->length
= length
+ initial_length_size
;
4350 this_cu
->objfile
= objfile
;
4351 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4353 if (n_comp_units
== n_allocated
)
4356 all_comp_units
= xrealloc (all_comp_units
,
4358 * sizeof (struct dwarf2_per_cu_data
*));
4360 all_comp_units
[n_comp_units
++] = this_cu
;
4362 info_ptr
= info_ptr
+ this_cu
->length
;
4365 dwarf2_per_objfile
->all_comp_units
4366 = obstack_alloc (&objfile
->objfile_obstack
,
4367 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4368 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4369 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4370 xfree (all_comp_units
);
4371 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4374 /* Process all loaded DIEs for compilation unit CU, starting at
4375 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4376 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4377 DW_AT_ranges). If NEED_PC is set, then this function will set
4378 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4379 and record the covered ranges in the addrmap. */
4382 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4383 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4385 struct partial_die_info
*pdi
;
4387 /* Now, march along the PDI's, descending into ones which have
4388 interesting children but skipping the children of the other ones,
4389 until we reach the end of the compilation unit. */
4395 fixup_partial_die (pdi
, cu
);
4397 /* Anonymous namespaces or modules have no name but have interesting
4398 children, so we need to look at them. Ditto for anonymous
4401 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4402 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
4406 case DW_TAG_subprogram
:
4407 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4409 case DW_TAG_constant
:
4410 case DW_TAG_variable
:
4411 case DW_TAG_typedef
:
4412 case DW_TAG_union_type
:
4413 if (!pdi
->is_declaration
)
4415 add_partial_symbol (pdi
, cu
);
4418 case DW_TAG_class_type
:
4419 case DW_TAG_interface_type
:
4420 case DW_TAG_structure_type
:
4421 if (!pdi
->is_declaration
)
4423 add_partial_symbol (pdi
, cu
);
4426 case DW_TAG_enumeration_type
:
4427 if (!pdi
->is_declaration
)
4428 add_partial_enumeration (pdi
, cu
);
4430 case DW_TAG_base_type
:
4431 case DW_TAG_subrange_type
:
4432 /* File scope base type definitions are added to the partial
4434 add_partial_symbol (pdi
, cu
);
4436 case DW_TAG_namespace
:
4437 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4440 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4447 /* If the die has a sibling, skip to the sibling. */
4449 pdi
= pdi
->die_sibling
;
4453 /* Functions used to compute the fully scoped name of a partial DIE.
4455 Normally, this is simple. For C++, the parent DIE's fully scoped
4456 name is concatenated with "::" and the partial DIE's name. For
4457 Java, the same thing occurs except that "." is used instead of "::".
4458 Enumerators are an exception; they use the scope of their parent
4459 enumeration type, i.e. the name of the enumeration type is not
4460 prepended to the enumerator.
4462 There are two complexities. One is DW_AT_specification; in this
4463 case "parent" means the parent of the target of the specification,
4464 instead of the direct parent of the DIE. The other is compilers
4465 which do not emit DW_TAG_namespace; in this case we try to guess
4466 the fully qualified name of structure types from their members'
4467 linkage names. This must be done using the DIE's children rather
4468 than the children of any DW_AT_specification target. We only need
4469 to do this for structures at the top level, i.e. if the target of
4470 any DW_AT_specification (if any; otherwise the DIE itself) does not
4473 /* Compute the scope prefix associated with PDI's parent, in
4474 compilation unit CU. The result will be allocated on CU's
4475 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4476 field. NULL is returned if no prefix is necessary. */
4478 partial_die_parent_scope (struct partial_die_info
*pdi
,
4479 struct dwarf2_cu
*cu
)
4481 char *grandparent_scope
;
4482 struct partial_die_info
*parent
, *real_pdi
;
4484 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4485 then this means the parent of the specification DIE. */
4488 while (real_pdi
->has_specification
)
4489 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4491 parent
= real_pdi
->die_parent
;
4495 if (parent
->scope_set
)
4496 return parent
->scope
;
4498 fixup_partial_die (parent
, cu
);
4500 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4502 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4503 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4504 Work around this problem here. */
4505 if (cu
->language
== language_cplus
4506 && parent
->tag
== DW_TAG_namespace
4507 && strcmp (parent
->name
, "::") == 0
4508 && grandparent_scope
== NULL
)
4510 parent
->scope
= NULL
;
4511 parent
->scope_set
= 1;
4515 if (pdi
->tag
== DW_TAG_enumerator
)
4516 /* Enumerators should not get the name of the enumeration as a prefix. */
4517 parent
->scope
= grandparent_scope
;
4518 else if (parent
->tag
== DW_TAG_namespace
4519 || parent
->tag
== DW_TAG_module
4520 || parent
->tag
== DW_TAG_structure_type
4521 || parent
->tag
== DW_TAG_class_type
4522 || parent
->tag
== DW_TAG_interface_type
4523 || parent
->tag
== DW_TAG_union_type
4524 || parent
->tag
== DW_TAG_enumeration_type
)
4526 if (grandparent_scope
== NULL
)
4527 parent
->scope
= parent
->name
;
4529 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4531 parent
->name
, 0, cu
);
4535 /* FIXME drow/2004-04-01: What should we be doing with
4536 function-local names? For partial symbols, we should probably be
4538 complaint (&symfile_complaints
,
4539 _("unhandled containing DIE tag %d for DIE at %d"),
4540 parent
->tag
, pdi
->offset
.sect_off
);
4541 parent
->scope
= grandparent_scope
;
4544 parent
->scope_set
= 1;
4545 return parent
->scope
;
4548 /* Return the fully scoped name associated with PDI, from compilation unit
4549 CU. The result will be allocated with malloc. */
4552 partial_die_full_name (struct partial_die_info
*pdi
,
4553 struct dwarf2_cu
*cu
)
4557 /* If this is a template instantiation, we can not work out the
4558 template arguments from partial DIEs. So, unfortunately, we have
4559 to go through the full DIEs. At least any work we do building
4560 types here will be reused if full symbols are loaded later. */
4561 if (pdi
->has_template_arguments
)
4563 fixup_partial_die (pdi
, cu
);
4565 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4567 struct die_info
*die
;
4568 struct attribute attr
;
4569 struct dwarf2_cu
*ref_cu
= cu
;
4571 /* DW_FORM_ref_addr is using section offset. */
4573 attr
.form
= DW_FORM_ref_addr
;
4574 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4575 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4577 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4581 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4582 if (parent_scope
== NULL
)
4585 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4589 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4591 struct objfile
*objfile
= cu
->objfile
;
4593 char *actual_name
= NULL
;
4595 int built_actual_name
= 0;
4597 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4599 actual_name
= partial_die_full_name (pdi
, cu
);
4601 built_actual_name
= 1;
4603 if (actual_name
== NULL
)
4604 actual_name
= pdi
->name
;
4608 case DW_TAG_subprogram
:
4609 if (pdi
->is_external
|| cu
->language
== language_ada
)
4611 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4612 of the global scope. But in Ada, we want to be able to access
4613 nested procedures globally. So all Ada subprograms are stored
4614 in the global scope. */
4615 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4616 mst_text, objfile); */
4617 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4619 VAR_DOMAIN
, LOC_BLOCK
,
4620 &objfile
->global_psymbols
,
4621 0, pdi
->lowpc
+ baseaddr
,
4622 cu
->language
, objfile
);
4626 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4627 mst_file_text, objfile); */
4628 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4630 VAR_DOMAIN
, LOC_BLOCK
,
4631 &objfile
->static_psymbols
,
4632 0, pdi
->lowpc
+ baseaddr
,
4633 cu
->language
, objfile
);
4636 case DW_TAG_constant
:
4638 struct psymbol_allocation_list
*list
;
4640 if (pdi
->is_external
)
4641 list
= &objfile
->global_psymbols
;
4643 list
= &objfile
->static_psymbols
;
4644 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4645 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4646 list
, 0, 0, cu
->language
, objfile
);
4649 case DW_TAG_variable
:
4651 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4655 && !dwarf2_per_objfile
->has_section_at_zero
)
4657 /* A global or static variable may also have been stripped
4658 out by the linker if unused, in which case its address
4659 will be nullified; do not add such variables into partial
4660 symbol table then. */
4662 else if (pdi
->is_external
)
4665 Don't enter into the minimal symbol tables as there is
4666 a minimal symbol table entry from the ELF symbols already.
4667 Enter into partial symbol table if it has a location
4668 descriptor or a type.
4669 If the location descriptor is missing, new_symbol will create
4670 a LOC_UNRESOLVED symbol, the address of the variable will then
4671 be determined from the minimal symbol table whenever the variable
4673 The address for the partial symbol table entry is not
4674 used by GDB, but it comes in handy for debugging partial symbol
4677 if (pdi
->locdesc
|| pdi
->has_type
)
4678 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4680 VAR_DOMAIN
, LOC_STATIC
,
4681 &objfile
->global_psymbols
,
4683 cu
->language
, objfile
);
4687 /* Static Variable. Skip symbols without location descriptors. */
4688 if (pdi
->locdesc
== NULL
)
4690 if (built_actual_name
)
4691 xfree (actual_name
);
4694 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4695 mst_file_data, objfile); */
4696 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4698 VAR_DOMAIN
, LOC_STATIC
,
4699 &objfile
->static_psymbols
,
4701 cu
->language
, objfile
);
4704 case DW_TAG_typedef
:
4705 case DW_TAG_base_type
:
4706 case DW_TAG_subrange_type
:
4707 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4709 VAR_DOMAIN
, LOC_TYPEDEF
,
4710 &objfile
->static_psymbols
,
4711 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4713 case DW_TAG_namespace
:
4714 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4716 VAR_DOMAIN
, LOC_TYPEDEF
,
4717 &objfile
->global_psymbols
,
4718 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4720 case DW_TAG_class_type
:
4721 case DW_TAG_interface_type
:
4722 case DW_TAG_structure_type
:
4723 case DW_TAG_union_type
:
4724 case DW_TAG_enumeration_type
:
4725 /* Skip external references. The DWARF standard says in the section
4726 about "Structure, Union, and Class Type Entries": "An incomplete
4727 structure, union or class type is represented by a structure,
4728 union or class entry that does not have a byte size attribute
4729 and that has a DW_AT_declaration attribute." */
4730 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4732 if (built_actual_name
)
4733 xfree (actual_name
);
4737 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4738 static vs. global. */
4739 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4741 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4742 (cu
->language
== language_cplus
4743 || cu
->language
== language_java
)
4744 ? &objfile
->global_psymbols
4745 : &objfile
->static_psymbols
,
4746 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4749 case DW_TAG_enumerator
:
4750 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4752 VAR_DOMAIN
, LOC_CONST
,
4753 (cu
->language
== language_cplus
4754 || cu
->language
== language_java
)
4755 ? &objfile
->global_psymbols
4756 : &objfile
->static_psymbols
,
4757 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4763 if (built_actual_name
)
4764 xfree (actual_name
);
4767 /* Read a partial die corresponding to a namespace; also, add a symbol
4768 corresponding to that namespace to the symbol table. NAMESPACE is
4769 the name of the enclosing namespace. */
4772 add_partial_namespace (struct partial_die_info
*pdi
,
4773 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4774 int need_pc
, struct dwarf2_cu
*cu
)
4776 /* Add a symbol for the namespace. */
4778 add_partial_symbol (pdi
, cu
);
4780 /* Now scan partial symbols in that namespace. */
4782 if (pdi
->has_children
)
4783 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4786 /* Read a partial die corresponding to a Fortran module. */
4789 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4790 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4792 /* Now scan partial symbols in that module. */
4794 if (pdi
->has_children
)
4795 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4798 /* Read a partial die corresponding to a subprogram and create a partial
4799 symbol for that subprogram. When the CU language allows it, this
4800 routine also defines a partial symbol for each nested subprogram
4801 that this subprogram contains.
4803 DIE my also be a lexical block, in which case we simply search
4804 recursively for suprograms defined inside that lexical block.
4805 Again, this is only performed when the CU language allows this
4806 type of definitions. */
4809 add_partial_subprogram (struct partial_die_info
*pdi
,
4810 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4811 int need_pc
, struct dwarf2_cu
*cu
)
4813 if (pdi
->tag
== DW_TAG_subprogram
)
4815 if (pdi
->has_pc_info
)
4817 if (pdi
->lowpc
< *lowpc
)
4818 *lowpc
= pdi
->lowpc
;
4819 if (pdi
->highpc
> *highpc
)
4820 *highpc
= pdi
->highpc
;
4824 struct objfile
*objfile
= cu
->objfile
;
4826 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4827 SECT_OFF_TEXT (objfile
));
4828 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4829 pdi
->lowpc
+ baseaddr
,
4830 pdi
->highpc
- 1 + baseaddr
,
4831 cu
->per_cu
->v
.psymtab
);
4835 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4837 if (!pdi
->is_declaration
)
4838 /* Ignore subprogram DIEs that do not have a name, they are
4839 illegal. Do not emit a complaint at this point, we will
4840 do so when we convert this psymtab into a symtab. */
4842 add_partial_symbol (pdi
, cu
);
4846 if (! pdi
->has_children
)
4849 if (cu
->language
== language_ada
)
4851 pdi
= pdi
->die_child
;
4854 fixup_partial_die (pdi
, cu
);
4855 if (pdi
->tag
== DW_TAG_subprogram
4856 || pdi
->tag
== DW_TAG_lexical_block
)
4857 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4858 pdi
= pdi
->die_sibling
;
4863 /* Read a partial die corresponding to an enumeration type. */
4866 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4867 struct dwarf2_cu
*cu
)
4869 struct partial_die_info
*pdi
;
4871 if (enum_pdi
->name
!= NULL
)
4872 add_partial_symbol (enum_pdi
, cu
);
4874 pdi
= enum_pdi
->die_child
;
4877 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4878 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4880 add_partial_symbol (pdi
, cu
);
4881 pdi
= pdi
->die_sibling
;
4885 /* Return the initial uleb128 in the die at INFO_PTR. */
4888 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4890 unsigned int bytes_read
;
4892 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4895 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4896 Return the corresponding abbrev, or NULL if the number is zero (indicating
4897 an empty DIE). In either case *BYTES_READ will be set to the length of
4898 the initial number. */
4900 static struct abbrev_info
*
4901 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4902 struct dwarf2_cu
*cu
)
4904 bfd
*abfd
= cu
->objfile
->obfd
;
4905 unsigned int abbrev_number
;
4906 struct abbrev_info
*abbrev
;
4908 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4910 if (abbrev_number
== 0)
4913 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4916 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4917 abbrev_number
, bfd_get_filename (abfd
));
4923 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4924 Returns a pointer to the end of a series of DIEs, terminated by an empty
4925 DIE. Any children of the skipped DIEs will also be skipped. */
4928 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
4930 struct dwarf2_cu
*cu
= reader
->cu
;
4931 struct abbrev_info
*abbrev
;
4932 unsigned int bytes_read
;
4936 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4938 return info_ptr
+ bytes_read
;
4940 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
4944 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4945 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4946 abbrev corresponding to that skipped uleb128 should be passed in
4947 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4951 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
4952 struct abbrev_info
*abbrev
)
4954 unsigned int bytes_read
;
4955 struct attribute attr
;
4956 bfd
*abfd
= reader
->abfd
;
4957 struct dwarf2_cu
*cu
= reader
->cu
;
4958 gdb_byte
*buffer
= reader
->buffer
;
4959 unsigned int form
, i
;
4961 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4963 /* The only abbrev we care about is DW_AT_sibling. */
4964 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4966 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
4967 if (attr
.form
== DW_FORM_ref_addr
)
4968 complaint (&symfile_complaints
,
4969 _("ignoring absolute DW_AT_sibling"));
4971 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4974 /* If it isn't DW_AT_sibling, skip this attribute. */
4975 form
= abbrev
->attrs
[i
].form
;
4979 case DW_FORM_ref_addr
:
4980 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4981 and later it is offset sized. */
4982 if (cu
->header
.version
== 2)
4983 info_ptr
+= cu
->header
.addr_size
;
4985 info_ptr
+= cu
->header
.offset_size
;
4988 info_ptr
+= cu
->header
.addr_size
;
4995 case DW_FORM_flag_present
:
5007 case DW_FORM_ref_sig8
:
5010 case DW_FORM_string
:
5011 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5012 info_ptr
+= bytes_read
;
5014 case DW_FORM_sec_offset
:
5016 info_ptr
+= cu
->header
.offset_size
;
5018 case DW_FORM_exprloc
:
5020 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5021 info_ptr
+= bytes_read
;
5023 case DW_FORM_block1
:
5024 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5026 case DW_FORM_block2
:
5027 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5029 case DW_FORM_block4
:
5030 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5034 case DW_FORM_ref_udata
:
5035 case DW_FORM_GNU_addr_index
:
5036 case DW_FORM_GNU_str_index
:
5037 info_ptr
= skip_leb128 (abfd
, info_ptr
);
5039 case DW_FORM_indirect
:
5040 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5041 info_ptr
+= bytes_read
;
5042 /* We need to continue parsing from here, so just go back to
5044 goto skip_attribute
;
5047 error (_("Dwarf Error: Cannot handle %s "
5048 "in DWARF reader [in module %s]"),
5049 dwarf_form_name (form
),
5050 bfd_get_filename (abfd
));
5054 if (abbrev
->has_children
)
5055 return skip_children (reader
, info_ptr
);
5060 /* Locate ORIG_PDI's sibling.
5061 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5064 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5065 struct partial_die_info
*orig_pdi
,
5068 /* Do we know the sibling already? */
5070 if (orig_pdi
->sibling
)
5071 return orig_pdi
->sibling
;
5073 /* Are there any children to deal with? */
5075 if (!orig_pdi
->has_children
)
5078 /* Skip the children the long way. */
5080 return skip_children (reader
, info_ptr
);
5083 /* Expand this partial symbol table into a full symbol table. */
5086 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5092 warning (_("bug: psymtab for %s is already read in."),
5099 printf_filtered (_("Reading in symbols for %s..."),
5101 gdb_flush (gdb_stdout
);
5104 /* Restore our global data. */
5105 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5106 dwarf2_objfile_data_key
);
5108 /* If this psymtab is constructed from a debug-only objfile, the
5109 has_section_at_zero flag will not necessarily be correct. We
5110 can get the correct value for this flag by looking at the data
5111 associated with the (presumably stripped) associated objfile. */
5112 if (pst
->objfile
->separate_debug_objfile_backlink
)
5114 struct dwarf2_per_objfile
*dpo_backlink
5115 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5116 dwarf2_objfile_data_key
);
5118 dwarf2_per_objfile
->has_section_at_zero
5119 = dpo_backlink
->has_section_at_zero
;
5122 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5124 psymtab_to_symtab_1 (pst
);
5126 /* Finish up the debug error message. */
5128 printf_filtered (_("done.\n"));
5133 /* Reading in full CUs. */
5135 /* Add PER_CU to the queue. */
5138 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5140 struct dwarf2_queue_item
*item
;
5143 item
= xmalloc (sizeof (*item
));
5144 item
->per_cu
= per_cu
;
5147 if (dwarf2_queue
== NULL
)
5148 dwarf2_queue
= item
;
5150 dwarf2_queue_tail
->next
= item
;
5152 dwarf2_queue_tail
= item
;
5155 /* Process the queue. */
5158 process_queue (void)
5160 struct dwarf2_queue_item
*item
, *next_item
;
5162 /* The queue starts out with one item, but following a DIE reference
5163 may load a new CU, adding it to the end of the queue. */
5164 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5166 if (dwarf2_per_objfile
->using_index
5167 ? !item
->per_cu
->v
.quick
->symtab
5168 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5169 process_full_comp_unit (item
->per_cu
);
5171 item
->per_cu
->queued
= 0;
5172 next_item
= item
->next
;
5176 dwarf2_queue_tail
= NULL
;
5179 /* Free all allocated queue entries. This function only releases anything if
5180 an error was thrown; if the queue was processed then it would have been
5181 freed as we went along. */
5184 dwarf2_release_queue (void *dummy
)
5186 struct dwarf2_queue_item
*item
, *last
;
5188 item
= dwarf2_queue
;
5191 /* Anything still marked queued is likely to be in an
5192 inconsistent state, so discard it. */
5193 if (item
->per_cu
->queued
)
5195 if (item
->per_cu
->cu
!= NULL
)
5196 free_one_cached_comp_unit (item
->per_cu
);
5197 item
->per_cu
->queued
= 0;
5205 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5208 /* Read in full symbols for PST, and anything it depends on. */
5211 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5213 struct dwarf2_per_cu_data
*per_cu
;
5214 struct cleanup
*back_to
;
5217 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5218 if (!pst
->dependencies
[i
]->readin
)
5220 /* Inform about additional files that need to be read in. */
5223 /* FIXME: i18n: Need to make this a single string. */
5224 fputs_filtered (" ", gdb_stdout
);
5226 fputs_filtered ("and ", gdb_stdout
);
5228 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5229 wrap_here (""); /* Flush output. */
5230 gdb_flush (gdb_stdout
);
5232 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5235 per_cu
= pst
->read_symtab_private
;
5239 /* It's an include file, no symbols to read for it.
5240 Everything is in the parent symtab. */
5245 dw2_do_instantiate_symtab (per_cu
);
5248 /* Trivial hash function for die_info: the hash value of a DIE
5249 is its offset in .debug_info for this objfile. */
5252 die_hash (const void *item
)
5254 const struct die_info
*die
= item
;
5256 return die
->offset
.sect_off
;
5259 /* Trivial comparison function for die_info structures: two DIEs
5260 are equal if they have the same offset. */
5263 die_eq (const void *item_lhs
, const void *item_rhs
)
5265 const struct die_info
*die_lhs
= item_lhs
;
5266 const struct die_info
*die_rhs
= item_rhs
;
5268 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5271 /* die_reader_func for load_full_comp_unit.
5272 This is identical to read_signatured_type_reader,
5273 but is kept separate for now. */
5276 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5278 struct die_info
*comp_unit_die
,
5282 struct dwarf2_cu
*cu
= reader
->cu
;
5283 struct attribute
*attr
;
5285 gdb_assert (cu
->die_hash
== NULL
);
5287 htab_create_alloc_ex (cu
->header
.length
/ 12,
5291 &cu
->comp_unit_obstack
,
5292 hashtab_obstack_allocate
,
5293 dummy_obstack_deallocate
);
5296 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5297 &info_ptr
, comp_unit_die
);
5298 cu
->dies
= comp_unit_die
;
5299 /* comp_unit_die is not stored in die_hash, no need. */
5301 /* We try not to read any attributes in this function, because not
5302 all CUs needed for references have been loaded yet, and symbol
5303 table processing isn't initialized. But we have to set the CU language,
5304 or we won't be able to build types correctly.
5305 Similarly, if we do not read the producer, we can not apply
5306 producer-specific interpretation. */
5307 prepare_one_comp_unit (cu
, cu
->dies
);
5310 /* Load the DIEs associated with PER_CU into memory. */
5313 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5315 gdb_assert (! this_cu
->is_debug_types
);
5317 init_cu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
, NULL
);
5320 /* Add a DIE to the delayed physname list. */
5323 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5324 const char *name
, struct die_info
*die
,
5325 struct dwarf2_cu
*cu
)
5327 struct delayed_method_info mi
;
5329 mi
.fnfield_index
= fnfield_index
;
5333 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5336 /* A cleanup for freeing the delayed method list. */
5339 free_delayed_list (void *ptr
)
5341 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5342 if (cu
->method_list
!= NULL
)
5344 VEC_free (delayed_method_info
, cu
->method_list
);
5345 cu
->method_list
= NULL
;
5349 /* Compute the physnames of any methods on the CU's method list.
5351 The computation of method physnames is delayed in order to avoid the
5352 (bad) condition that one of the method's formal parameters is of an as yet
5356 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5359 struct delayed_method_info
*mi
;
5360 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5362 const char *physname
;
5363 struct fn_fieldlist
*fn_flp
5364 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5365 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5366 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5370 /* Go objects should be embedded in a DW_TAG_module DIE,
5371 and it's not clear if/how imported objects will appear.
5372 To keep Go support simple until that's worked out,
5373 go back through what we've read and create something usable.
5374 We could do this while processing each DIE, and feels kinda cleaner,
5375 but that way is more invasive.
5376 This is to, for example, allow the user to type "p var" or "b main"
5377 without having to specify the package name, and allow lookups
5378 of module.object to work in contexts that use the expression
5382 fixup_go_packaging (struct dwarf2_cu
*cu
)
5384 char *package_name
= NULL
;
5385 struct pending
*list
;
5388 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5390 for (i
= 0; i
< list
->nsyms
; ++i
)
5392 struct symbol
*sym
= list
->symbol
[i
];
5394 if (SYMBOL_LANGUAGE (sym
) == language_go
5395 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5397 char *this_package_name
= go_symbol_package_name (sym
);
5399 if (this_package_name
== NULL
)
5401 if (package_name
== NULL
)
5402 package_name
= this_package_name
;
5405 if (strcmp (package_name
, this_package_name
) != 0)
5406 complaint (&symfile_complaints
,
5407 _("Symtab %s has objects from two different Go packages: %s and %s"),
5408 (sym
->symtab
&& sym
->symtab
->filename
5409 ? sym
->symtab
->filename
5410 : cu
->objfile
->name
),
5411 this_package_name
, package_name
);
5412 xfree (this_package_name
);
5418 if (package_name
!= NULL
)
5420 struct objfile
*objfile
= cu
->objfile
;
5421 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5422 package_name
, objfile
);
5425 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5427 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5428 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5429 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5430 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5431 e.g., "main" finds the "main" module and not C's main(). */
5432 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5433 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5434 SYMBOL_TYPE (sym
) = type
;
5436 add_symbol_to_list (sym
, &global_symbols
);
5438 xfree (package_name
);
5442 /* Generate full symbol information for PER_CU, whose DIEs have
5443 already been loaded into memory. */
5446 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5448 struct dwarf2_cu
*cu
= per_cu
->cu
;
5449 struct objfile
*objfile
= per_cu
->objfile
;
5450 CORE_ADDR lowpc
, highpc
;
5451 struct symtab
*symtab
;
5452 struct cleanup
*back_to
, *delayed_list_cleanup
;
5455 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5458 back_to
= make_cleanup (really_free_pendings
, NULL
);
5459 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5461 cu
->list_in_scope
= &file_symbols
;
5463 /* Do line number decoding in read_file_scope () */
5464 process_die (cu
->dies
, cu
);
5466 /* For now fudge the Go package. */
5467 if (cu
->language
== language_go
)
5468 fixup_go_packaging (cu
);
5470 /* Now that we have processed all the DIEs in the CU, all the types
5471 should be complete, and it should now be safe to compute all of the
5473 compute_delayed_physnames (cu
);
5474 do_cleanups (delayed_list_cleanup
);
5476 /* Some compilers don't define a DW_AT_high_pc attribute for the
5477 compilation unit. If the DW_AT_high_pc is missing, synthesize
5478 it, by scanning the DIE's below the compilation unit. */
5479 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5481 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5485 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5487 /* Set symtab language to language from DW_AT_language. If the
5488 compilation is from a C file generated by language preprocessors, do
5489 not set the language if it was already deduced by start_subfile. */
5490 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5491 symtab
->language
= cu
->language
;
5493 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5494 produce DW_AT_location with location lists but it can be possibly
5495 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5496 there were bugs in prologue debug info, fixed later in GCC-4.5
5497 by "unwind info for epilogues" patch (which is not directly related).
5499 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5500 needed, it would be wrong due to missing DW_AT_producer there.
5502 Still one can confuse GDB by using non-standard GCC compilation
5503 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5505 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5506 symtab
->locations_valid
= 1;
5508 if (gcc_4_minor
>= 5)
5509 symtab
->epilogue_unwind_valid
= 1;
5511 symtab
->call_site_htab
= cu
->call_site_htab
;
5514 if (dwarf2_per_objfile
->using_index
)
5515 per_cu
->v
.quick
->symtab
= symtab
;
5518 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5519 pst
->symtab
= symtab
;
5523 do_cleanups (back_to
);
5526 /* Process a die and its children. */
5529 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5533 case DW_TAG_padding
:
5535 case DW_TAG_compile_unit
:
5536 read_file_scope (die
, cu
);
5538 case DW_TAG_type_unit
:
5539 read_type_unit_scope (die
, cu
);
5541 case DW_TAG_subprogram
:
5542 case DW_TAG_inlined_subroutine
:
5543 read_func_scope (die
, cu
);
5545 case DW_TAG_lexical_block
:
5546 case DW_TAG_try_block
:
5547 case DW_TAG_catch_block
:
5548 read_lexical_block_scope (die
, cu
);
5550 case DW_TAG_GNU_call_site
:
5551 read_call_site_scope (die
, cu
);
5553 case DW_TAG_class_type
:
5554 case DW_TAG_interface_type
:
5555 case DW_TAG_structure_type
:
5556 case DW_TAG_union_type
:
5557 process_structure_scope (die
, cu
);
5559 case DW_TAG_enumeration_type
:
5560 process_enumeration_scope (die
, cu
);
5563 /* These dies have a type, but processing them does not create
5564 a symbol or recurse to process the children. Therefore we can
5565 read them on-demand through read_type_die. */
5566 case DW_TAG_subroutine_type
:
5567 case DW_TAG_set_type
:
5568 case DW_TAG_array_type
:
5569 case DW_TAG_pointer_type
:
5570 case DW_TAG_ptr_to_member_type
:
5571 case DW_TAG_reference_type
:
5572 case DW_TAG_string_type
:
5575 case DW_TAG_base_type
:
5576 case DW_TAG_subrange_type
:
5577 case DW_TAG_typedef
:
5578 /* Add a typedef symbol for the type definition, if it has a
5580 new_symbol (die
, read_type_die (die
, cu
), cu
);
5582 case DW_TAG_common_block
:
5583 read_common_block (die
, cu
);
5585 case DW_TAG_common_inclusion
:
5587 case DW_TAG_namespace
:
5588 processing_has_namespace_info
= 1;
5589 read_namespace (die
, cu
);
5592 processing_has_namespace_info
= 1;
5593 read_module (die
, cu
);
5595 case DW_TAG_imported_declaration
:
5596 case DW_TAG_imported_module
:
5597 processing_has_namespace_info
= 1;
5598 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5599 || cu
->language
!= language_fortran
))
5600 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5601 dwarf_tag_name (die
->tag
));
5602 read_import_statement (die
, cu
);
5605 new_symbol (die
, NULL
, cu
);
5610 /* A helper function for dwarf2_compute_name which determines whether DIE
5611 needs to have the name of the scope prepended to the name listed in the
5615 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5617 struct attribute
*attr
;
5621 case DW_TAG_namespace
:
5622 case DW_TAG_typedef
:
5623 case DW_TAG_class_type
:
5624 case DW_TAG_interface_type
:
5625 case DW_TAG_structure_type
:
5626 case DW_TAG_union_type
:
5627 case DW_TAG_enumeration_type
:
5628 case DW_TAG_enumerator
:
5629 case DW_TAG_subprogram
:
5633 case DW_TAG_variable
:
5634 case DW_TAG_constant
:
5635 /* We only need to prefix "globally" visible variables. These include
5636 any variable marked with DW_AT_external or any variable that
5637 lives in a namespace. [Variables in anonymous namespaces
5638 require prefixing, but they are not DW_AT_external.] */
5640 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5642 struct dwarf2_cu
*spec_cu
= cu
;
5644 return die_needs_namespace (die_specification (die
, &spec_cu
),
5648 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5649 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5650 && die
->parent
->tag
!= DW_TAG_module
)
5652 /* A variable in a lexical block of some kind does not need a
5653 namespace, even though in C++ such variables may be external
5654 and have a mangled name. */
5655 if (die
->parent
->tag
== DW_TAG_lexical_block
5656 || die
->parent
->tag
== DW_TAG_try_block
5657 || die
->parent
->tag
== DW_TAG_catch_block
5658 || die
->parent
->tag
== DW_TAG_subprogram
)
5667 /* Retrieve the last character from a mem_file. */
5670 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5672 char *last_char_p
= (char *) object
;
5675 *last_char_p
= buffer
[length
- 1];
5678 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5679 compute the physname for the object, which include a method's:
5680 - formal parameters (C++/Java),
5681 - receiver type (Go),
5682 - return type (Java).
5684 The term "physname" is a bit confusing.
5685 For C++, for example, it is the demangled name.
5686 For Go, for example, it's the mangled name.
5688 For Ada, return the DIE's linkage name rather than the fully qualified
5689 name. PHYSNAME is ignored..
5691 The result is allocated on the objfile_obstack and canonicalized. */
5694 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5697 struct objfile
*objfile
= cu
->objfile
;
5700 name
= dwarf2_name (die
, cu
);
5702 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5703 compute it by typename_concat inside GDB. */
5704 if (cu
->language
== language_ada
5705 || (cu
->language
== language_fortran
&& physname
))
5707 /* For Ada unit, we prefer the linkage name over the name, as
5708 the former contains the exported name, which the user expects
5709 to be able to reference. Ideally, we want the user to be able
5710 to reference this entity using either natural or linkage name,
5711 but we haven't started looking at this enhancement yet. */
5712 struct attribute
*attr
;
5714 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5716 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5717 if (attr
&& DW_STRING (attr
))
5718 return DW_STRING (attr
);
5721 /* These are the only languages we know how to qualify names in. */
5723 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5724 || cu
->language
== language_fortran
))
5726 if (die_needs_namespace (die
, cu
))
5730 struct ui_file
*buf
;
5732 prefix
= determine_prefix (die
, cu
);
5733 buf
= mem_fileopen ();
5734 if (*prefix
!= '\0')
5736 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5739 fputs_unfiltered (prefixed_name
, buf
);
5740 xfree (prefixed_name
);
5743 fputs_unfiltered (name
, buf
);
5745 /* Template parameters may be specified in the DIE's DW_AT_name, or
5746 as children with DW_TAG_template_type_param or
5747 DW_TAG_value_type_param. If the latter, add them to the name
5748 here. If the name already has template parameters, then
5749 skip this step; some versions of GCC emit both, and
5750 it is more efficient to use the pre-computed name.
5752 Something to keep in mind about this process: it is very
5753 unlikely, or in some cases downright impossible, to produce
5754 something that will match the mangled name of a function.
5755 If the definition of the function has the same debug info,
5756 we should be able to match up with it anyway. But fallbacks
5757 using the minimal symbol, for instance to find a method
5758 implemented in a stripped copy of libstdc++, will not work.
5759 If we do not have debug info for the definition, we will have to
5760 match them up some other way.
5762 When we do name matching there is a related problem with function
5763 templates; two instantiated function templates are allowed to
5764 differ only by their return types, which we do not add here. */
5766 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5768 struct attribute
*attr
;
5769 struct die_info
*child
;
5772 die
->building_fullname
= 1;
5774 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5779 struct dwarf2_locexpr_baton
*baton
;
5782 if (child
->tag
!= DW_TAG_template_type_param
5783 && child
->tag
!= DW_TAG_template_value_param
)
5788 fputs_unfiltered ("<", buf
);
5792 fputs_unfiltered (", ", buf
);
5794 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5797 complaint (&symfile_complaints
,
5798 _("template parameter missing DW_AT_type"));
5799 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5802 type
= die_type (child
, cu
);
5804 if (child
->tag
== DW_TAG_template_type_param
)
5806 c_print_type (type
, "", buf
, -1, 0);
5810 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5813 complaint (&symfile_complaints
,
5814 _("template parameter missing "
5815 "DW_AT_const_value"));
5816 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5820 dwarf2_const_value_attr (attr
, type
, name
,
5821 &cu
->comp_unit_obstack
, cu
,
5822 &value
, &bytes
, &baton
);
5824 if (TYPE_NOSIGN (type
))
5825 /* GDB prints characters as NUMBER 'CHAR'. If that's
5826 changed, this can use value_print instead. */
5827 c_printchar (value
, type
, buf
);
5830 struct value_print_options opts
;
5833 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5837 else if (bytes
!= NULL
)
5839 v
= allocate_value (type
);
5840 memcpy (value_contents_writeable (v
), bytes
,
5841 TYPE_LENGTH (type
));
5844 v
= value_from_longest (type
, value
);
5846 /* Specify decimal so that we do not depend on
5848 get_formatted_print_options (&opts
, 'd');
5850 value_print (v
, buf
, &opts
);
5856 die
->building_fullname
= 0;
5860 /* Close the argument list, with a space if necessary
5861 (nested templates). */
5862 char last_char
= '\0';
5863 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5864 if (last_char
== '>')
5865 fputs_unfiltered (" >", buf
);
5867 fputs_unfiltered (">", buf
);
5871 /* For Java and C++ methods, append formal parameter type
5872 information, if PHYSNAME. */
5874 if (physname
&& die
->tag
== DW_TAG_subprogram
5875 && (cu
->language
== language_cplus
5876 || cu
->language
== language_java
))
5878 struct type
*type
= read_type_die (die
, cu
);
5880 c_type_print_args (type
, buf
, 1, cu
->language
);
5882 if (cu
->language
== language_java
)
5884 /* For java, we must append the return type to method
5886 if (die
->tag
== DW_TAG_subprogram
)
5887 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5890 else if (cu
->language
== language_cplus
)
5892 /* Assume that an artificial first parameter is
5893 "this", but do not crash if it is not. RealView
5894 marks unnamed (and thus unused) parameters as
5895 artificial; there is no way to differentiate
5897 if (TYPE_NFIELDS (type
) > 0
5898 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5899 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5900 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5902 fputs_unfiltered (" const", buf
);
5906 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5908 ui_file_delete (buf
);
5910 if (cu
->language
== language_cplus
)
5913 = dwarf2_canonicalize_name (name
, cu
,
5914 &objfile
->objfile_obstack
);
5925 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5926 If scope qualifiers are appropriate they will be added. The result
5927 will be allocated on the objfile_obstack, or NULL if the DIE does
5928 not have a name. NAME may either be from a previous call to
5929 dwarf2_name or NULL.
5931 The output string will be canonicalized (if C++/Java). */
5934 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5936 return dwarf2_compute_name (name
, die
, cu
, 0);
5939 /* Construct a physname for the given DIE in CU. NAME may either be
5940 from a previous call to dwarf2_name or NULL. The result will be
5941 allocated on the objfile_objstack or NULL if the DIE does not have a
5944 The output string will be canonicalized (if C++/Java). */
5947 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5949 struct objfile
*objfile
= cu
->objfile
;
5950 struct attribute
*attr
;
5951 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5952 struct cleanup
*back_to
;
5955 /* In this case dwarf2_compute_name is just a shortcut not building anything
5957 if (!die_needs_namespace (die
, cu
))
5958 return dwarf2_compute_name (name
, die
, cu
, 1);
5960 back_to
= make_cleanup (null_cleanup
, NULL
);
5962 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5964 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5966 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5968 if (attr
&& DW_STRING (attr
))
5972 mangled
= DW_STRING (attr
);
5974 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5975 type. It is easier for GDB users to search for such functions as
5976 `name(params)' than `long name(params)'. In such case the minimal
5977 symbol names do not match the full symbol names but for template
5978 functions there is never a need to look up their definition from their
5979 declaration so the only disadvantage remains the minimal symbol
5980 variant `long name(params)' does not have the proper inferior type.
5983 if (cu
->language
== language_go
)
5985 /* This is a lie, but we already lie to the caller new_symbol_full.
5986 new_symbol_full assumes we return the mangled name.
5987 This just undoes that lie until things are cleaned up. */
5992 demangled
= cplus_demangle (mangled
,
5993 (DMGL_PARAMS
| DMGL_ANSI
5994 | (cu
->language
== language_java
5995 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6000 make_cleanup (xfree
, demangled
);
6010 if (canon
== NULL
|| check_physname
)
6012 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6014 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6016 /* It may not mean a bug in GDB. The compiler could also
6017 compute DW_AT_linkage_name incorrectly. But in such case
6018 GDB would need to be bug-to-bug compatible. */
6020 complaint (&symfile_complaints
,
6021 _("Computed physname <%s> does not match demangled <%s> "
6022 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6023 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6025 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6026 is available here - over computed PHYSNAME. It is safer
6027 against both buggy GDB and buggy compilers. */
6041 retval
= obsavestring (retval
, strlen (retval
),
6042 &objfile
->objfile_obstack
);
6044 do_cleanups (back_to
);
6048 /* Read the import statement specified by the given die and record it. */
6051 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6053 struct objfile
*objfile
= cu
->objfile
;
6054 struct attribute
*import_attr
;
6055 struct die_info
*imported_die
, *child_die
;
6056 struct dwarf2_cu
*imported_cu
;
6057 const char *imported_name
;
6058 const char *imported_name_prefix
;
6059 const char *canonical_name
;
6060 const char *import_alias
;
6061 const char *imported_declaration
= NULL
;
6062 const char *import_prefix
;
6063 VEC (const_char_ptr
) *excludes
= NULL
;
6064 struct cleanup
*cleanups
;
6068 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6069 if (import_attr
== NULL
)
6071 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6072 dwarf_tag_name (die
->tag
));
6077 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6078 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6079 if (imported_name
== NULL
)
6081 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6083 The import in the following code:
6097 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6098 <52> DW_AT_decl_file : 1
6099 <53> DW_AT_decl_line : 6
6100 <54> DW_AT_import : <0x75>
6101 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6103 <5b> DW_AT_decl_file : 1
6104 <5c> DW_AT_decl_line : 2
6105 <5d> DW_AT_type : <0x6e>
6107 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6108 <76> DW_AT_byte_size : 4
6109 <77> DW_AT_encoding : 5 (signed)
6111 imports the wrong die ( 0x75 instead of 0x58 ).
6112 This case will be ignored until the gcc bug is fixed. */
6116 /* Figure out the local name after import. */
6117 import_alias
= dwarf2_name (die
, cu
);
6119 /* Figure out where the statement is being imported to. */
6120 import_prefix
= determine_prefix (die
, cu
);
6122 /* Figure out what the scope of the imported die is and prepend it
6123 to the name of the imported die. */
6124 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6126 if (imported_die
->tag
!= DW_TAG_namespace
6127 && imported_die
->tag
!= DW_TAG_module
)
6129 imported_declaration
= imported_name
;
6130 canonical_name
= imported_name_prefix
;
6132 else if (strlen (imported_name_prefix
) > 0)
6134 temp
= alloca (strlen (imported_name_prefix
)
6135 + 2 + strlen (imported_name
) + 1);
6136 strcpy (temp
, imported_name_prefix
);
6137 strcat (temp
, "::");
6138 strcat (temp
, imported_name
);
6139 canonical_name
= temp
;
6142 canonical_name
= imported_name
;
6144 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6146 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6147 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6148 child_die
= sibling_die (child_die
))
6150 /* DWARF-4: A Fortran use statement with a “rename list” may be
6151 represented by an imported module entry with an import attribute
6152 referring to the module and owned entries corresponding to those
6153 entities that are renamed as part of being imported. */
6155 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6157 complaint (&symfile_complaints
,
6158 _("child DW_TAG_imported_declaration expected "
6159 "- DIE at 0x%x [in module %s]"),
6160 child_die
->offset
.sect_off
, objfile
->name
);
6164 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6165 if (import_attr
== NULL
)
6167 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6168 dwarf_tag_name (child_die
->tag
));
6173 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6175 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6176 if (imported_name
== NULL
)
6178 complaint (&symfile_complaints
,
6179 _("child DW_TAG_imported_declaration has unknown "
6180 "imported name - DIE at 0x%x [in module %s]"),
6181 child_die
->offset
.sect_off
, objfile
->name
);
6185 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6187 process_die (child_die
, cu
);
6190 cp_add_using_directive (import_prefix
,
6193 imported_declaration
,
6195 &objfile
->objfile_obstack
);
6197 do_cleanups (cleanups
);
6200 /* Cleanup function for read_file_scope. */
6203 free_cu_line_header (void *arg
)
6205 struct dwarf2_cu
*cu
= arg
;
6207 free_line_header (cu
->line_header
);
6208 cu
->line_header
= NULL
;
6212 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6213 char **name
, char **comp_dir
)
6215 struct attribute
*attr
;
6220 /* Find the filename. Do not use dwarf2_name here, since the filename
6221 is not a source language identifier. */
6222 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6225 *name
= DW_STRING (attr
);
6228 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6230 *comp_dir
= DW_STRING (attr
);
6231 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6233 *comp_dir
= ldirname (*name
);
6234 if (*comp_dir
!= NULL
)
6235 make_cleanup (xfree
, *comp_dir
);
6237 if (*comp_dir
!= NULL
)
6239 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6240 directory, get rid of it. */
6241 char *cp
= strchr (*comp_dir
, ':');
6243 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6248 *name
= "<unknown>";
6251 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6252 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6253 COMP_DIR is the compilation directory.
6254 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6257 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6258 const char *comp_dir
, int want_line_info
)
6260 struct attribute
*attr
;
6262 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6265 unsigned int line_offset
= DW_UNSND (attr
);
6266 struct line_header
*line_header
6267 = dwarf_decode_line_header (line_offset
, cu
);
6271 cu
->line_header
= line_header
;
6272 make_cleanup (free_cu_line_header
, cu
);
6273 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6278 /* Process DW_TAG_compile_unit. */
6281 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6284 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6285 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6286 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6287 struct attribute
*attr
;
6289 char *comp_dir
= NULL
;
6290 struct die_info
*child_die
;
6291 bfd
*abfd
= objfile
->obfd
;
6294 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6296 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6298 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6299 from finish_block. */
6300 if (lowpc
== ((CORE_ADDR
) -1))
6305 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6307 prepare_one_comp_unit (cu
, die
);
6309 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6310 standardised yet. As a workaround for the language detection we fall
6311 back to the DW_AT_producer string. */
6312 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6313 cu
->language
= language_opencl
;
6315 /* Similar hack for Go. */
6316 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6317 set_cu_language (DW_LANG_Go
, cu
);
6319 /* We assume that we're processing GCC output. */
6320 processing_gcc_compilation
= 2;
6322 processing_has_namespace_info
= 0;
6324 start_symtab (name
, comp_dir
, lowpc
);
6325 record_debugformat ("DWARF 2");
6326 record_producer (cu
->producer
);
6328 /* Decode line number information if present. We do this before
6329 processing child DIEs, so that the line header table is available
6330 for DW_AT_decl_file. */
6331 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6333 /* Process all dies in compilation unit. */
6334 if (die
->child
!= NULL
)
6336 child_die
= die
->child
;
6337 while (child_die
&& child_die
->tag
)
6339 process_die (child_die
, cu
);
6340 child_die
= sibling_die (child_die
);
6344 /* Decode macro information, if present. Dwarf 2 macro information
6345 refers to information in the line number info statement program
6346 header, so we can only read it if we've read the header
6348 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6349 if (attr
&& cu
->line_header
)
6351 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6352 complaint (&symfile_complaints
,
6353 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6355 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6357 &dwarf2_per_objfile
->macro
, 1);
6361 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6362 if (attr
&& cu
->line_header
)
6364 unsigned int macro_offset
= DW_UNSND (attr
);
6366 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6368 &dwarf2_per_objfile
->macinfo
, 0);
6372 do_cleanups (back_to
);
6375 /* Process DW_TAG_type_unit.
6376 For TUs we want to skip the first top level sibling if it's not the
6377 actual type being defined by this TU. In this case the first top
6378 level sibling is there to provide context only. */
6381 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6383 struct objfile
*objfile
= cu
->objfile
;
6384 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6386 struct attribute
*attr
;
6388 char *comp_dir
= NULL
;
6389 struct die_info
*child_die
;
6390 bfd
*abfd
= objfile
->obfd
;
6392 /* start_symtab needs a low pc, but we don't really have one.
6393 Do what read_file_scope would do in the absence of such info. */
6394 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6396 /* Find the filename. Do not use dwarf2_name here, since the filename
6397 is not a source language identifier. */
6398 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6400 name
= DW_STRING (attr
);
6402 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6404 comp_dir
= DW_STRING (attr
);
6405 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6407 comp_dir
= ldirname (name
);
6408 if (comp_dir
!= NULL
)
6409 make_cleanup (xfree
, comp_dir
);
6415 prepare_one_comp_unit (cu
, die
);
6417 /* We assume that we're processing GCC output. */
6418 processing_gcc_compilation
= 2;
6420 processing_has_namespace_info
= 0;
6422 start_symtab (name
, comp_dir
, lowpc
);
6423 record_debugformat ("DWARF 2");
6424 record_producer (cu
->producer
);
6426 /* Decode line number information if present. We do this before
6427 processing child DIEs, so that the line header table is available
6428 for DW_AT_decl_file.
6429 We don't need the pc/line-number mapping for type units. */
6430 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6432 /* Process the dies in the type unit. */
6433 if (die
->child
== NULL
)
6435 dump_die_for_error (die
);
6436 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6437 bfd_get_filename (abfd
));
6440 child_die
= die
->child
;
6442 while (child_die
&& child_die
->tag
)
6444 process_die (child_die
, cu
);
6446 child_die
= sibling_die (child_die
);
6449 do_cleanups (back_to
);
6455 hash_dwo_file (const void *item
)
6457 const struct dwo_file
*dwo_file
= item
;
6459 return htab_hash_string (dwo_file
->dwo_name
);
6463 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6465 const struct dwo_file
*lhs
= item_lhs
;
6466 const struct dwo_file
*rhs
= item_rhs
;
6468 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6471 /* Allocate a hash table for DWO files. */
6474 allocate_dwo_file_hash_table (void)
6476 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6478 return htab_create_alloc_ex (41,
6482 &objfile
->objfile_obstack
,
6483 hashtab_obstack_allocate
,
6484 dummy_obstack_deallocate
);
6488 hash_dwo_unit (const void *item
)
6490 const struct dwo_unit
*dwo_unit
= item
;
6492 /* This drops the top 32 bits of the id, but is ok for a hash. */
6493 return dwo_unit
->signature
;
6497 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6499 const struct dwo_unit
*lhs
= item_lhs
;
6500 const struct dwo_unit
*rhs
= item_rhs
;
6502 /* The signature is assumed to be unique within the DWO file.
6503 So while object file CU dwo_id's always have the value zero,
6504 that's OK, assuming each object file DWO file has only one CU,
6505 and that's the rule for now. */
6506 return lhs
->signature
== rhs
->signature
;
6509 /* Allocate a hash table for DWO CUs,TUs.
6510 There is one of these tables for each of CUs,TUs for each DWO file. */
6513 allocate_dwo_unit_table (struct objfile
*objfile
)
6515 /* Start out with a pretty small number.
6516 Generally DWO files contain only one CU and maybe some TUs. */
6517 return htab_create_alloc_ex (3,
6521 &objfile
->objfile_obstack
,
6522 hashtab_obstack_allocate
,
6523 dummy_obstack_deallocate
);
6526 /* This function is mapped across the sections and remembers the offset and
6527 size of each of the DWO debugging sections we are interested in. */
6530 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6532 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6533 const struct dwo_section_names
*names
= &dwo_section_names
;
6535 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6537 dwo_file
->sections
.abbrev
.asection
= sectp
;
6538 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6540 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6542 dwo_file
->sections
.info
.asection
= sectp
;
6543 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6545 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6547 dwo_file
->sections
.line
.asection
= sectp
;
6548 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6550 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6552 dwo_file
->sections
.loc
.asection
= sectp
;
6553 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6555 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6557 dwo_file
->sections
.str
.asection
= sectp
;
6558 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6560 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6562 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6563 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6565 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6567 struct dwarf2_section_info type_section
;
6569 memset (&type_section
, 0, sizeof (type_section
));
6570 type_section
.asection
= sectp
;
6571 type_section
.size
= bfd_get_section_size (sectp
);
6572 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6577 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6579 struct create_dwo_info_table_data
6581 struct dwo_file
*dwo_file
;
6585 /* die_reader_func for create_debug_info_hash_table. */
6588 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6590 struct die_info
*comp_unit_die
,
6594 struct dwarf2_cu
*cu
= reader
->cu
;
6595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6596 sect_offset offset
= cu
->per_cu
->offset
;
6597 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6598 struct create_dwo_info_table_data
*data
= datap
;
6599 struct dwo_file
*dwo_file
= data
->dwo_file
;
6600 htab_t cu_htab
= data
->cu_htab
;
6602 struct attribute
*attr
;
6603 struct dwo_unit
*dwo_unit
;
6605 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6608 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6609 " its dwo_id [in module %s]"),
6610 offset
.sect_off
, dwo_file
->dwo_name
);
6614 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6615 dwo_unit
->dwo_file
= dwo_file
;
6616 dwo_unit
->signature
= DW_UNSND (attr
);
6617 dwo_unit
->info_or_types_section
= section
;
6618 dwo_unit
->offset
= offset
;
6619 dwo_unit
->length
= cu
->per_cu
->length
;
6621 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
6622 gdb_assert (slot
!= NULL
);
6625 const struct dwo_unit
*dup_dwo_unit
= *slot
;
6627 complaint (&symfile_complaints
,
6628 _("debug entry at offset 0x%x is duplicate to the entry at"
6629 " offset 0x%x, dwo_id 0x%s [in module %s]"),
6630 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
6631 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
6632 dwo_file
->dwo_name
);
6637 if (dwarf2_die_debug
)
6638 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
6640 phex (dwo_unit
->signature
,
6641 sizeof (dwo_unit
->signature
)));
6644 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
6647 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
6649 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6650 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
6653 gdb_byte
*info_ptr
, *end_ptr
;
6654 struct create_dwo_info_table_data create_dwo_info_table_data
;
6656 dwarf2_read_section (objfile
, section
);
6657 info_ptr
= section
->buffer
;
6659 if (info_ptr
== NULL
)
6662 /* We can't set abfd until now because the section may be empty or
6663 not present, in which case section->asection will be NULL. */
6664 abfd
= section
->asection
->owner
;
6666 if (dwarf2_die_debug
)
6667 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
6668 bfd_get_filename (abfd
));
6670 cu_htab
= allocate_dwo_unit_table (objfile
);
6672 create_dwo_info_table_data
.dwo_file
= dwo_file
;
6673 create_dwo_info_table_data
.cu_htab
= cu_htab
;
6675 end_ptr
= info_ptr
+ section
->size
;
6676 while (info_ptr
< end_ptr
)
6678 struct dwarf2_per_cu_data per_cu
;
6680 memset (&per_cu
, 0, sizeof (per_cu
));
6681 per_cu
.objfile
= objfile
;
6682 per_cu
.is_debug_types
= 0;
6683 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
6684 per_cu
.info_or_types_section
= section
;
6686 init_cutu_and_read_dies_no_follow (&per_cu
,
6687 &dwo_file
->sections
.abbrev
,
6689 create_debug_info_hash_table_reader
,
6690 &create_dwo_info_table_data
);
6692 info_ptr
+= per_cu
.length
;
6698 /* Subroutine of open_dwo_file to simplify it.
6699 Open the file specified by FILE_NAME and hand it off to BFD for
6700 preliminary analysis. Return a newly initialized bfd *, which
6701 includes a canonicalized copy of FILE_NAME.
6702 In case of trouble, return NULL.
6703 NOTE: This function is derived from symfile_bfd_open. */
6706 try_open_dwo_file (const char *file_name
)
6710 char *absolute_name
;
6713 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
6714 O_RDONLY
| O_BINARY
, &absolute_name
);
6718 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
6722 xfree (absolute_name
);
6725 bfd_set_cacheable (sym_bfd
, 1);
6727 if (!bfd_check_format (sym_bfd
, bfd_object
))
6729 bfd_close (sym_bfd
); /* This also closes desc. */
6730 xfree (absolute_name
);
6734 /* bfd_usrdata exists for applications and libbfd must not touch it. */
6735 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
6740 /* Try to open DWO file DWO_NAME.
6741 COMP_DIR is the DW_AT_comp_dir attribute.
6742 The result is the bfd handle of the file.
6743 If there is a problem finding or opening the file, return NULL.
6744 Upon success, the canonicalized path of the file is stored in the bfd,
6745 same as symfile_bfd_open. */
6748 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
6751 char *path_to_try
, *debug_dir
;
6753 if (IS_ABSOLUTE_PATH (dwo_name
))
6754 return try_open_dwo_file (dwo_name
);
6756 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
6758 if (comp_dir
!= NULL
)
6760 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
6762 /* NOTE: If comp_dir is a relative path, this will also try the
6763 search path, which seems useful. */
6764 abfd
= try_open_dwo_file (path_to_try
);
6765 xfree (path_to_try
);
6770 /* That didn't work, try debug-file-directory, which, despite its name,
6771 is a list of paths. */
6773 if (*debug_file_directory
== '\0')
6776 return try_open_dwo_file (dwo_name
);
6779 /* Initialize the use of the DWO file specified by DWO_NAME. */
6781 static struct dwo_file
*
6782 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
6784 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6785 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6788 struct cleanup
*cleanups
;
6790 if (dwarf2_die_debug
)
6791 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
6793 abfd
= open_dwo_file (dwo_name
, comp_dir
);
6796 dwo_file
->dwo_name
= dwo_name
;
6797 dwo_file
->dwo_bfd
= abfd
;
6799 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
6801 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
6803 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
6805 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
6806 dwo_file
->sections
.types
);
6808 discard_cleanups (cleanups
);
6813 /* Lookup DWO file DWO_NAME. */
6815 static struct dwo_file
*
6816 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
6818 struct dwo_file
*dwo_file
;
6819 struct dwo_file find_entry
;
6822 if (dwarf2_per_objfile
->dwo_files
== NULL
)
6823 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
6825 /* Have we already seen this DWO file? */
6826 find_entry
.dwo_name
= dwo_name
;
6827 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
6829 /* If not, read it in and build a table of the DWOs it contains. */
6831 *slot
= init_dwo_file (dwo_name
, comp_dir
);
6833 /* NOTE: This will be NULL if unable to open the file. */
6839 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
6840 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
6841 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
6842 nomenclature as TUs).
6843 The result is the DWO CU or NULL if we didn't find it
6844 (dwo_id mismatch or couldn't find the DWO file). */
6846 static struct dwo_unit
*
6847 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6848 char *dwo_name
, const char *comp_dir
,
6851 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6852 struct dwo_file
*dwo_file
;
6854 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
6855 if (dwo_file
== NULL
)
6858 /* Look up the DWO using its signature(dwo_id). */
6860 if (dwo_file
->cus
!= NULL
)
6862 struct dwo_unit find_dwo_cu
, *dwo_cu
;
6864 find_dwo_cu
.signature
= signature
;
6865 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
6871 /* We didn't find it. This must mean a dwo_id mismatch. */
6873 complaint (&symfile_complaints
,
6874 _("Could not find DWO CU referenced by CU at offset 0x%x"
6876 this_cu
->offset
.sect_off
, objfile
->name
);
6880 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
6881 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
6882 The result is the DWO CU or NULL if we didn't find it
6883 (dwo_id mismatch or couldn't find the DWO file). */
6885 static struct dwo_unit
*
6886 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
6887 char *dwo_name
, const char *comp_dir
)
6889 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6890 struct dwo_file
*dwo_file
;
6891 struct dwo_unit find_dwo_tu
, *dwo_tu
;
6893 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
6894 if (dwo_file
== NULL
)
6897 /* Look up the DWO using its signature(dwo_id). */
6899 if (dwo_file
->tus
!= NULL
)
6901 struct dwo_unit find_dwo_tu
, *dwo_tu
;
6903 find_dwo_tu
.signature
= this_tu
->signature
;
6904 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
6910 /* We didn't find it. This must mean a dwo_id mismatch. */
6912 complaint (&symfile_complaints
,
6913 _("Could not find DWO TU referenced by TU at offset 0x%x"
6915 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
6919 /* Free all resources associated with DWO_FILE.
6920 Close the DWO file and munmap the sections.
6921 All memory should be on the objfile obstack. */
6924 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
6927 struct dwarf2_section_info
*section
;
6929 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
6930 bfd_close (dwo_file
->dwo_bfd
);
6932 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
6933 munmap_section_buffer (&dwo_file
->sections
.info
);
6934 munmap_section_buffer (&dwo_file
->sections
.line
);
6935 munmap_section_buffer (&dwo_file
->sections
.loc
);
6936 munmap_section_buffer (&dwo_file
->sections
.str
);
6937 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
6940 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6943 munmap_section_buffer (section
);
6945 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
6948 /* Wrapper for free_dwo_file for use in cleanups. */
6951 free_dwo_file_cleanup (void *arg
)
6953 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
6954 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6956 free_dwo_file (dwo_file
, objfile
);
6959 /* Traversal function for free_dwo_files. */
6962 free_dwo_file_from_slot (void **slot
, void *info
)
6964 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6965 struct objfile
*objfile
= (struct objfile
*) info
;
6967 free_dwo_file (dwo_file
, objfile
);
6972 /* Free all resources associated with DWO_FILES. */
6975 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
6977 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
6980 /* Read in various DIEs. */
6982 /* qsort helper for inherit_abstract_dies. */
6985 unsigned_int_compar (const void *ap
, const void *bp
)
6987 unsigned int a
= *(unsigned int *) ap
;
6988 unsigned int b
= *(unsigned int *) bp
;
6990 return (a
> b
) - (b
> a
);
6993 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
6994 Inherit only the children of the DW_AT_abstract_origin DIE not being
6995 already referenced by DW_AT_abstract_origin from the children of the
6999 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7001 struct die_info
*child_die
;
7002 unsigned die_children_count
;
7003 /* CU offsets which were referenced by children of the current DIE. */
7004 sect_offset
*offsets
;
7005 sect_offset
*offsets_end
, *offsetp
;
7006 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7007 struct die_info
*origin_die
;
7008 /* Iterator of the ORIGIN_DIE children. */
7009 struct die_info
*origin_child_die
;
7010 struct cleanup
*cleanups
;
7011 struct attribute
*attr
;
7012 struct dwarf2_cu
*origin_cu
;
7013 struct pending
**origin_previous_list_in_scope
;
7015 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7019 /* Note that following die references may follow to a die in a
7023 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7025 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7027 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7028 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7030 if (die
->tag
!= origin_die
->tag
7031 && !(die
->tag
== DW_TAG_inlined_subroutine
7032 && origin_die
->tag
== DW_TAG_subprogram
))
7033 complaint (&symfile_complaints
,
7034 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7035 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7037 child_die
= die
->child
;
7038 die_children_count
= 0;
7039 while (child_die
&& child_die
->tag
)
7041 child_die
= sibling_die (child_die
);
7042 die_children_count
++;
7044 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7045 cleanups
= make_cleanup (xfree
, offsets
);
7047 offsets_end
= offsets
;
7048 child_die
= die
->child
;
7049 while (child_die
&& child_die
->tag
)
7051 /* For each CHILD_DIE, find the corresponding child of
7052 ORIGIN_DIE. If there is more than one layer of
7053 DW_AT_abstract_origin, follow them all; there shouldn't be,
7054 but GCC versions at least through 4.4 generate this (GCC PR
7056 struct die_info
*child_origin_die
= child_die
;
7057 struct dwarf2_cu
*child_origin_cu
= cu
;
7061 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7065 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7069 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7070 counterpart may exist. */
7071 if (child_origin_die
!= child_die
)
7073 if (child_die
->tag
!= child_origin_die
->tag
7074 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7075 && child_origin_die
->tag
== DW_TAG_subprogram
))
7076 complaint (&symfile_complaints
,
7077 _("Child DIE 0x%x and its abstract origin 0x%x have "
7078 "different tags"), child_die
->offset
.sect_off
,
7079 child_origin_die
->offset
.sect_off
);
7080 if (child_origin_die
->parent
!= origin_die
)
7081 complaint (&symfile_complaints
,
7082 _("Child DIE 0x%x and its abstract origin 0x%x have "
7083 "different parents"), child_die
->offset
.sect_off
,
7084 child_origin_die
->offset
.sect_off
);
7086 *offsets_end
++ = child_origin_die
->offset
;
7088 child_die
= sibling_die (child_die
);
7090 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7091 unsigned_int_compar
);
7092 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7093 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7094 complaint (&symfile_complaints
,
7095 _("Multiple children of DIE 0x%x refer "
7096 "to DIE 0x%x as their abstract origin"),
7097 die
->offset
.sect_off
, offsetp
->sect_off
);
7100 origin_child_die
= origin_die
->child
;
7101 while (origin_child_die
&& origin_child_die
->tag
)
7103 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7104 while (offsetp
< offsets_end
7105 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7107 if (offsetp
>= offsets_end
7108 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7110 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7111 process_die (origin_child_die
, origin_cu
);
7113 origin_child_die
= sibling_die (origin_child_die
);
7115 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7117 do_cleanups (cleanups
);
7121 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7123 struct objfile
*objfile
= cu
->objfile
;
7124 struct context_stack
*new;
7127 struct die_info
*child_die
;
7128 struct attribute
*attr
, *call_line
, *call_file
;
7131 struct block
*block
;
7132 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7133 VEC (symbolp
) *template_args
= NULL
;
7134 struct template_symbol
*templ_func
= NULL
;
7138 /* If we do not have call site information, we can't show the
7139 caller of this inlined function. That's too confusing, so
7140 only use the scope for local variables. */
7141 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7142 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7143 if (call_line
== NULL
|| call_file
== NULL
)
7145 read_lexical_block_scope (die
, cu
);
7150 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7152 name
= dwarf2_name (die
, cu
);
7154 /* Ignore functions with missing or empty names. These are actually
7155 illegal according to the DWARF standard. */
7158 complaint (&symfile_complaints
,
7159 _("missing name for subprogram DIE at %d"),
7160 die
->offset
.sect_off
);
7164 /* Ignore functions with missing or invalid low and high pc attributes. */
7165 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7167 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7168 if (!attr
|| !DW_UNSND (attr
))
7169 complaint (&symfile_complaints
,
7170 _("cannot get low and high bounds "
7171 "for subprogram DIE at %d"),
7172 die
->offset
.sect_off
);
7179 /* If we have any template arguments, then we must allocate a
7180 different sort of symbol. */
7181 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7183 if (child_die
->tag
== DW_TAG_template_type_param
7184 || child_die
->tag
== DW_TAG_template_value_param
)
7186 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7187 struct template_symbol
);
7188 templ_func
->base
.is_cplus_template_function
= 1;
7193 new = push_context (0, lowpc
);
7194 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7195 (struct symbol
*) templ_func
);
7197 /* If there is a location expression for DW_AT_frame_base, record
7199 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7201 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7202 expression is being recorded directly in the function's symbol
7203 and not in a separate frame-base object. I guess this hack is
7204 to avoid adding some sort of frame-base adjunct/annex to the
7205 function's symbol :-(. The problem with doing this is that it
7206 results in a function symbol with a location expression that
7207 has nothing to do with the location of the function, ouch! The
7208 relationship should be: a function's symbol has-a frame base; a
7209 frame-base has-a location expression. */
7210 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7212 cu
->list_in_scope
= &local_symbols
;
7214 if (die
->child
!= NULL
)
7216 child_die
= die
->child
;
7217 while (child_die
&& child_die
->tag
)
7219 if (child_die
->tag
== DW_TAG_template_type_param
7220 || child_die
->tag
== DW_TAG_template_value_param
)
7222 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7225 VEC_safe_push (symbolp
, template_args
, arg
);
7228 process_die (child_die
, cu
);
7229 child_die
= sibling_die (child_die
);
7233 inherit_abstract_dies (die
, cu
);
7235 /* If we have a DW_AT_specification, we might need to import using
7236 directives from the context of the specification DIE. See the
7237 comment in determine_prefix. */
7238 if (cu
->language
== language_cplus
7239 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7241 struct dwarf2_cu
*spec_cu
= cu
;
7242 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7246 child_die
= spec_die
->child
;
7247 while (child_die
&& child_die
->tag
)
7249 if (child_die
->tag
== DW_TAG_imported_module
)
7250 process_die (child_die
, spec_cu
);
7251 child_die
= sibling_die (child_die
);
7254 /* In some cases, GCC generates specification DIEs that
7255 themselves contain DW_AT_specification attributes. */
7256 spec_die
= die_specification (spec_die
, &spec_cu
);
7260 new = pop_context ();
7261 /* Make a block for the local symbols within. */
7262 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7263 lowpc
, highpc
, objfile
);
7265 /* For C++, set the block's scope. */
7266 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7267 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7268 determine_prefix (die
, cu
),
7269 processing_has_namespace_info
);
7271 /* If we have address ranges, record them. */
7272 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7274 /* Attach template arguments to function. */
7275 if (! VEC_empty (symbolp
, template_args
))
7277 gdb_assert (templ_func
!= NULL
);
7279 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7280 templ_func
->template_arguments
7281 = obstack_alloc (&objfile
->objfile_obstack
,
7282 (templ_func
->n_template_arguments
7283 * sizeof (struct symbol
*)));
7284 memcpy (templ_func
->template_arguments
,
7285 VEC_address (symbolp
, template_args
),
7286 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7287 VEC_free (symbolp
, template_args
);
7290 /* In C++, we can have functions nested inside functions (e.g., when
7291 a function declares a class that has methods). This means that
7292 when we finish processing a function scope, we may need to go
7293 back to building a containing block's symbol lists. */
7294 local_symbols
= new->locals
;
7295 param_symbols
= new->params
;
7296 using_directives
= new->using_directives
;
7298 /* If we've finished processing a top-level function, subsequent
7299 symbols go in the file symbol list. */
7300 if (outermost_context_p ())
7301 cu
->list_in_scope
= &file_symbols
;
7304 /* Process all the DIES contained within a lexical block scope. Start
7305 a new scope, process the dies, and then close the scope. */
7308 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7310 struct objfile
*objfile
= cu
->objfile
;
7311 struct context_stack
*new;
7312 CORE_ADDR lowpc
, highpc
;
7313 struct die_info
*child_die
;
7316 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7318 /* Ignore blocks with missing or invalid low and high pc attributes. */
7319 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7320 as multiple lexical blocks? Handling children in a sane way would
7321 be nasty. Might be easier to properly extend generic blocks to
7323 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7328 push_context (0, lowpc
);
7329 if (die
->child
!= NULL
)
7331 child_die
= die
->child
;
7332 while (child_die
&& child_die
->tag
)
7334 process_die (child_die
, cu
);
7335 child_die
= sibling_die (child_die
);
7338 new = pop_context ();
7340 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7343 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7346 /* Note that recording ranges after traversing children, as we
7347 do here, means that recording a parent's ranges entails
7348 walking across all its children's ranges as they appear in
7349 the address map, which is quadratic behavior.
7351 It would be nicer to record the parent's ranges before
7352 traversing its children, simply overriding whatever you find
7353 there. But since we don't even decide whether to create a
7354 block until after we've traversed its children, that's hard
7356 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7358 local_symbols
= new->locals
;
7359 using_directives
= new->using_directives
;
7362 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7365 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7367 struct objfile
*objfile
= cu
->objfile
;
7368 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7369 CORE_ADDR pc
, baseaddr
;
7370 struct attribute
*attr
;
7371 struct call_site
*call_site
, call_site_local
;
7374 struct die_info
*child_die
;
7376 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7378 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7381 complaint (&symfile_complaints
,
7382 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7383 "DIE 0x%x [in module %s]"),
7384 die
->offset
.sect_off
, objfile
->name
);
7387 pc
= DW_ADDR (attr
) + baseaddr
;
7389 if (cu
->call_site_htab
== NULL
)
7390 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7391 NULL
, &objfile
->objfile_obstack
,
7392 hashtab_obstack_allocate
, NULL
);
7393 call_site_local
.pc
= pc
;
7394 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7397 complaint (&symfile_complaints
,
7398 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7399 "DIE 0x%x [in module %s]"),
7400 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7404 /* Count parameters at the caller. */
7407 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7408 child_die
= sibling_die (child_die
))
7410 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7412 complaint (&symfile_complaints
,
7413 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7414 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7415 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7422 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7423 (sizeof (*call_site
)
7424 + (sizeof (*call_site
->parameter
)
7427 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7430 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7432 struct die_info
*func_die
;
7434 /* Skip also over DW_TAG_inlined_subroutine. */
7435 for (func_die
= die
->parent
;
7436 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7437 && func_die
->tag
!= DW_TAG_subroutine_type
;
7438 func_die
= func_die
->parent
);
7440 /* DW_AT_GNU_all_call_sites is a superset
7441 of DW_AT_GNU_all_tail_call_sites. */
7443 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7444 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7446 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7447 not complete. But keep CALL_SITE for look ups via call_site_htab,
7448 both the initial caller containing the real return address PC and
7449 the final callee containing the current PC of a chain of tail
7450 calls do not need to have the tail call list complete. But any
7451 function candidate for a virtual tail call frame searched via
7452 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7453 determined unambiguously. */
7457 struct type
*func_type
= NULL
;
7460 func_type
= get_die_type (func_die
, cu
);
7461 if (func_type
!= NULL
)
7463 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7465 /* Enlist this call site to the function. */
7466 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7467 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7470 complaint (&symfile_complaints
,
7471 _("Cannot find function owning DW_TAG_GNU_call_site "
7472 "DIE 0x%x [in module %s]"),
7473 die
->offset
.sect_off
, objfile
->name
);
7477 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7479 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7480 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7481 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7482 /* Keep NULL DWARF_BLOCK. */;
7483 else if (attr_form_is_block (attr
))
7485 struct dwarf2_locexpr_baton
*dlbaton
;
7487 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7488 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7489 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7490 dlbaton
->per_cu
= cu
->per_cu
;
7492 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7494 else if (is_ref_attr (attr
))
7496 struct dwarf2_cu
*target_cu
= cu
;
7497 struct die_info
*target_die
;
7499 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7500 gdb_assert (target_cu
->objfile
== objfile
);
7501 if (die_is_declaration (target_die
, target_cu
))
7503 const char *target_physname
;
7505 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7506 if (target_physname
== NULL
)
7507 complaint (&symfile_complaints
,
7508 _("DW_AT_GNU_call_site_target target DIE has invalid "
7509 "physname, for referencing DIE 0x%x [in module %s]"),
7510 die
->offset
.sect_off
, objfile
->name
);
7512 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7518 /* DW_AT_entry_pc should be preferred. */
7519 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7520 complaint (&symfile_complaints
,
7521 _("DW_AT_GNU_call_site_target target DIE has invalid "
7522 "low pc, for referencing DIE 0x%x [in module %s]"),
7523 die
->offset
.sect_off
, objfile
->name
);
7525 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7529 complaint (&symfile_complaints
,
7530 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7531 "block nor reference, for DIE 0x%x [in module %s]"),
7532 die
->offset
.sect_off
, objfile
->name
);
7534 call_site
->per_cu
= cu
->per_cu
;
7536 for (child_die
= die
->child
;
7537 child_die
&& child_die
->tag
;
7538 child_die
= sibling_die (child_die
))
7540 struct dwarf2_locexpr_baton
*dlbaton
;
7541 struct call_site_parameter
*parameter
;
7543 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7545 /* Already printed the complaint above. */
7549 gdb_assert (call_site
->parameter_count
< nparams
);
7550 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7552 /* DW_AT_location specifies the register number. Value of the data
7553 assumed for the register is contained in DW_AT_GNU_call_site_value. */
7555 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7556 if (!attr
|| !attr_form_is_block (attr
))
7558 complaint (&symfile_complaints
,
7559 _("No DW_FORM_block* DW_AT_location for "
7560 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7561 child_die
->offset
.sect_off
, objfile
->name
);
7564 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
7565 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
7566 if (parameter
->dwarf_reg
== -1
7567 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
7568 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
7569 ¶meter
->fb_offset
))
7571 complaint (&symfile_complaints
,
7572 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7573 "for DW_FORM_block* DW_AT_location for "
7574 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7575 child_die
->offset
.sect_off
, objfile
->name
);
7579 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7580 if (!attr_form_is_block (attr
))
7582 complaint (&symfile_complaints
,
7583 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7584 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7585 child_die
->offset
.sect_off
, objfile
->name
);
7588 parameter
->value
= DW_BLOCK (attr
)->data
;
7589 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7591 /* Parameters are not pre-cleared by memset above. */
7592 parameter
->data_value
= NULL
;
7593 parameter
->data_value_size
= 0;
7594 call_site
->parameter_count
++;
7596 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7599 if (!attr_form_is_block (attr
))
7600 complaint (&symfile_complaints
,
7601 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7602 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7603 child_die
->offset
.sect_off
, objfile
->name
);
7606 parameter
->data_value
= DW_BLOCK (attr
)->data
;
7607 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
7613 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
7614 Return 1 if the attributes are present and valid, otherwise, return 0.
7615 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
7618 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
7619 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
7620 struct partial_symtab
*ranges_pst
)
7622 struct objfile
*objfile
= cu
->objfile
;
7623 struct comp_unit_head
*cu_header
= &cu
->header
;
7624 bfd
*obfd
= objfile
->obfd
;
7625 unsigned int addr_size
= cu_header
->addr_size
;
7626 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7627 /* Base address selection entry. */
7638 found_base
= cu
->base_known
;
7639 base
= cu
->base_address
;
7641 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
7642 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7644 complaint (&symfile_complaints
,
7645 _("Offset %d out of bounds for DW_AT_ranges attribute"),
7649 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7651 /* Read in the largest possible address. */
7652 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
7653 if ((marker
& mask
) == mask
)
7655 /* If we found the largest possible address, then
7656 read the base address. */
7657 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7658 buffer
+= 2 * addr_size
;
7659 offset
+= 2 * addr_size
;
7665 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7669 CORE_ADDR range_beginning
, range_end
;
7671 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
7672 buffer
+= addr_size
;
7673 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
7674 buffer
+= addr_size
;
7675 offset
+= 2 * addr_size
;
7677 /* An end of list marker is a pair of zero addresses. */
7678 if (range_beginning
== 0 && range_end
== 0)
7679 /* Found the end of list entry. */
7682 /* Each base address selection entry is a pair of 2 values.
7683 The first is the largest possible address, the second is
7684 the base address. Check for a base address here. */
7685 if ((range_beginning
& mask
) == mask
)
7687 /* If we found the largest possible address, then
7688 read the base address. */
7689 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7696 /* We have no valid base address for the ranges
7698 complaint (&symfile_complaints
,
7699 _("Invalid .debug_ranges data (no base address)"));
7703 if (range_beginning
> range_end
)
7705 /* Inverted range entries are invalid. */
7706 complaint (&symfile_complaints
,
7707 _("Invalid .debug_ranges data (inverted range)"));
7711 /* Empty range entries have no effect. */
7712 if (range_beginning
== range_end
)
7715 range_beginning
+= base
;
7718 if (ranges_pst
!= NULL
)
7719 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7720 range_beginning
+ baseaddr
,
7721 range_end
- 1 + baseaddr
,
7724 /* FIXME: This is recording everything as a low-high
7725 segment of consecutive addresses. We should have a
7726 data structure for discontiguous block ranges
7730 low
= range_beginning
;
7736 if (range_beginning
< low
)
7737 low
= range_beginning
;
7738 if (range_end
> high
)
7744 /* If the first entry is an end-of-list marker, the range
7745 describes an empty scope, i.e. no instructions. */
7751 *high_return
= high
;
7755 /* Get low and high pc attributes from a die. Return 1 if the attributes
7756 are present and valid, otherwise, return 0. Return -1 if the range is
7757 discontinuous, i.e. derived from DW_AT_ranges information. */
7760 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
7761 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
7762 struct partial_symtab
*pst
)
7764 struct attribute
*attr
;
7765 struct attribute
*attr_high
;
7770 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7773 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7776 low
= DW_ADDR (attr
);
7777 if (attr_high
->form
== DW_FORM_addr
7778 || attr_high
->form
== DW_FORM_GNU_addr_index
)
7779 high
= DW_ADDR (attr_high
);
7781 high
= low
+ DW_UNSND (attr_high
);
7784 /* Found high w/o low attribute. */
7787 /* Found consecutive range of addresses. */
7792 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7795 /* Value of the DW_AT_ranges attribute is the offset in the
7796 .debug_ranges section. */
7797 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
7799 /* Found discontinuous range of addresses. */
7804 /* read_partial_die has also the strict LOW < HIGH requirement. */
7808 /* When using the GNU linker, .gnu.linkonce. sections are used to
7809 eliminate duplicate copies of functions and vtables and such.
7810 The linker will arbitrarily choose one and discard the others.
7811 The AT_*_pc values for such functions refer to local labels in
7812 these sections. If the section from that file was discarded, the
7813 labels are not in the output, so the relocs get a value of 0.
7814 If this is a discarded function, mark the pc bounds as invalid,
7815 so that GDB will ignore it. */
7816 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
7825 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
7826 its low and high PC addresses. Do nothing if these addresses could not
7827 be determined. Otherwise, set LOWPC to the low address if it is smaller,
7828 and HIGHPC to the high address if greater than HIGHPC. */
7831 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
7832 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7833 struct dwarf2_cu
*cu
)
7835 CORE_ADDR low
, high
;
7836 struct die_info
*child
= die
->child
;
7838 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
7840 *lowpc
= min (*lowpc
, low
);
7841 *highpc
= max (*highpc
, high
);
7844 /* If the language does not allow nested subprograms (either inside
7845 subprograms or lexical blocks), we're done. */
7846 if (cu
->language
!= language_ada
)
7849 /* Check all the children of the given DIE. If it contains nested
7850 subprograms, then check their pc bounds. Likewise, we need to
7851 check lexical blocks as well, as they may also contain subprogram
7853 while (child
&& child
->tag
)
7855 if (child
->tag
== DW_TAG_subprogram
7856 || child
->tag
== DW_TAG_lexical_block
)
7857 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
7858 child
= sibling_die (child
);
7862 /* Get the low and high pc's represented by the scope DIE, and store
7863 them in *LOWPC and *HIGHPC. If the correct values can't be
7864 determined, set *LOWPC to -1 and *HIGHPC to 0. */
7867 get_scope_pc_bounds (struct die_info
*die
,
7868 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7869 struct dwarf2_cu
*cu
)
7871 CORE_ADDR best_low
= (CORE_ADDR
) -1;
7872 CORE_ADDR best_high
= (CORE_ADDR
) 0;
7873 CORE_ADDR current_low
, current_high
;
7875 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
7877 best_low
= current_low
;
7878 best_high
= current_high
;
7882 struct die_info
*child
= die
->child
;
7884 while (child
&& child
->tag
)
7886 switch (child
->tag
) {
7887 case DW_TAG_subprogram
:
7888 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
7890 case DW_TAG_namespace
:
7892 /* FIXME: carlton/2004-01-16: Should we do this for
7893 DW_TAG_class_type/DW_TAG_structure_type, too? I think
7894 that current GCC's always emit the DIEs corresponding
7895 to definitions of methods of classes as children of a
7896 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
7897 the DIEs giving the declarations, which could be
7898 anywhere). But I don't see any reason why the
7899 standards says that they have to be there. */
7900 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
7902 if (current_low
!= ((CORE_ADDR
) -1))
7904 best_low
= min (best_low
, current_low
);
7905 best_high
= max (best_high
, current_high
);
7913 child
= sibling_die (child
);
7918 *highpc
= best_high
;
7921 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
7925 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
7926 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
7928 struct objfile
*objfile
= cu
->objfile
;
7929 struct attribute
*attr
;
7930 struct attribute
*attr_high
;
7932 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7935 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7938 CORE_ADDR low
= DW_ADDR (attr
);
7940 if (attr_high
->form
== DW_FORM_addr
7941 || attr_high
->form
== DW_FORM_GNU_addr_index
)
7942 high
= DW_ADDR (attr_high
);
7944 high
= low
+ DW_UNSND (attr_high
);
7946 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
7950 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7953 bfd
*obfd
= objfile
->obfd
;
7955 /* The value of the DW_AT_ranges attribute is the offset of the
7956 address range list in the .debug_ranges section. */
7957 unsigned long offset
= DW_UNSND (attr
);
7958 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7960 /* For some target architectures, but not others, the
7961 read_address function sign-extends the addresses it returns.
7962 To recognize base address selection entries, we need a
7964 unsigned int addr_size
= cu
->header
.addr_size
;
7965 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7967 /* The base address, to which the next pair is relative. Note
7968 that this 'base' is a DWARF concept: most entries in a range
7969 list are relative, to reduce the number of relocs against the
7970 debugging information. This is separate from this function's
7971 'baseaddr' argument, which GDB uses to relocate debugging
7972 information from a shared library based on the address at
7973 which the library was loaded. */
7974 CORE_ADDR base
= cu
->base_address
;
7975 int base_known
= cu
->base_known
;
7977 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
7978 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7980 complaint (&symfile_complaints
,
7981 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
7988 unsigned int bytes_read
;
7989 CORE_ADDR start
, end
;
7991 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7992 buffer
+= bytes_read
;
7993 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7994 buffer
+= bytes_read
;
7996 /* Did we find the end of the range list? */
7997 if (start
== 0 && end
== 0)
8000 /* Did we find a base address selection entry? */
8001 else if ((start
& base_select_mask
) == base_select_mask
)
8007 /* We found an ordinary address range. */
8012 complaint (&symfile_complaints
,
8013 _("Invalid .debug_ranges data "
8014 "(no base address)"));
8020 /* Inverted range entries are invalid. */
8021 complaint (&symfile_complaints
,
8022 _("Invalid .debug_ranges data "
8023 "(inverted range)"));
8027 /* Empty range entries have no effect. */
8031 record_block_range (block
,
8032 baseaddr
+ base
+ start
,
8033 baseaddr
+ base
+ end
- 1);
8039 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8040 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8041 during 4.6.0 experimental. */
8044 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8047 int major
, minor
, release
;
8050 if (cu
->producer
== NULL
)
8052 /* For unknown compilers expect their behavior is DWARF version
8055 GCC started to support .debug_types sections by -gdwarf-4 since
8056 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8057 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8058 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8059 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8064 if (cu
->checked_producer
)
8065 return cu
->producer_is_gxx_lt_4_6
;
8067 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8069 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
8071 /* For non-GCC compilers expect their behavior is DWARF version
8076 cs
= &cu
->producer
[strlen ("GNU ")];
8077 while (*cs
&& !isdigit (*cs
))
8079 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8081 /* Not recognized as GCC. */
8084 result
= major
< 4 || (major
== 4 && minor
< 6);
8087 cu
->checked_producer
= 1;
8088 cu
->producer_is_gxx_lt_4_6
= result
;
8093 /* Return the default accessibility type if it is not overriden by
8094 DW_AT_accessibility. */
8096 static enum dwarf_access_attribute
8097 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8099 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8101 /* The default DWARF 2 accessibility for members is public, the default
8102 accessibility for inheritance is private. */
8104 if (die
->tag
!= DW_TAG_inheritance
)
8105 return DW_ACCESS_public
;
8107 return DW_ACCESS_private
;
8111 /* DWARF 3+ defines the default accessibility a different way. The same
8112 rules apply now for DW_TAG_inheritance as for the members and it only
8113 depends on the container kind. */
8115 if (die
->parent
->tag
== DW_TAG_class_type
)
8116 return DW_ACCESS_private
;
8118 return DW_ACCESS_public
;
8122 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8123 offset. If the attribute was not found return 0, otherwise return
8124 1. If it was found but could not properly be handled, set *OFFSET
8128 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8131 struct attribute
*attr
;
8133 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8138 /* Note that we do not check for a section offset first here.
8139 This is because DW_AT_data_member_location is new in DWARF 4,
8140 so if we see it, we can assume that a constant form is really
8141 a constant and not a section offset. */
8142 if (attr_form_is_constant (attr
))
8143 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8144 else if (attr_form_is_section_offset (attr
))
8145 dwarf2_complex_location_expr_complaint ();
8146 else if (attr_form_is_block (attr
))
8147 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8149 dwarf2_complex_location_expr_complaint ();
8157 /* Add an aggregate field to the field list. */
8160 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8161 struct dwarf2_cu
*cu
)
8163 struct objfile
*objfile
= cu
->objfile
;
8164 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8165 struct nextfield
*new_field
;
8166 struct attribute
*attr
;
8168 char *fieldname
= "";
8170 /* Allocate a new field list entry and link it in. */
8171 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8172 make_cleanup (xfree
, new_field
);
8173 memset (new_field
, 0, sizeof (struct nextfield
));
8175 if (die
->tag
== DW_TAG_inheritance
)
8177 new_field
->next
= fip
->baseclasses
;
8178 fip
->baseclasses
= new_field
;
8182 new_field
->next
= fip
->fields
;
8183 fip
->fields
= new_field
;
8187 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8189 new_field
->accessibility
= DW_UNSND (attr
);
8191 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8192 if (new_field
->accessibility
!= DW_ACCESS_public
)
8193 fip
->non_public_fields
= 1;
8195 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8197 new_field
->virtuality
= DW_UNSND (attr
);
8199 new_field
->virtuality
= DW_VIRTUALITY_none
;
8201 fp
= &new_field
->field
;
8203 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8207 /* Data member other than a C++ static data member. */
8209 /* Get type of field. */
8210 fp
->type
= die_type (die
, cu
);
8212 SET_FIELD_BITPOS (*fp
, 0);
8214 /* Get bit size of field (zero if none). */
8215 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8218 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8222 FIELD_BITSIZE (*fp
) = 0;
8225 /* Get bit offset of field. */
8226 if (handle_data_member_location (die
, cu
, &offset
))
8227 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8228 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8231 if (gdbarch_bits_big_endian (gdbarch
))
8233 /* For big endian bits, the DW_AT_bit_offset gives the
8234 additional bit offset from the MSB of the containing
8235 anonymous object to the MSB of the field. We don't
8236 have to do anything special since we don't need to
8237 know the size of the anonymous object. */
8238 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8242 /* For little endian bits, compute the bit offset to the
8243 MSB of the anonymous object, subtract off the number of
8244 bits from the MSB of the field to the MSB of the
8245 object, and then subtract off the number of bits of
8246 the field itself. The result is the bit offset of
8247 the LSB of the field. */
8249 int bit_offset
= DW_UNSND (attr
);
8251 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8254 /* The size of the anonymous object containing
8255 the bit field is explicit, so use the
8256 indicated size (in bytes). */
8257 anonymous_size
= DW_UNSND (attr
);
8261 /* The size of the anonymous object containing
8262 the bit field must be inferred from the type
8263 attribute of the data member containing the
8265 anonymous_size
= TYPE_LENGTH (fp
->type
);
8267 SET_FIELD_BITPOS (*fp
,
8269 + anonymous_size
* bits_per_byte
8270 - bit_offset
- FIELD_BITSIZE (*fp
)));
8274 /* Get name of field. */
8275 fieldname
= dwarf2_name (die
, cu
);
8276 if (fieldname
== NULL
)
8279 /* The name is already allocated along with this objfile, so we don't
8280 need to duplicate it for the type. */
8281 fp
->name
= fieldname
;
8283 /* Change accessibility for artificial fields (e.g. virtual table
8284 pointer or virtual base class pointer) to private. */
8285 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8287 FIELD_ARTIFICIAL (*fp
) = 1;
8288 new_field
->accessibility
= DW_ACCESS_private
;
8289 fip
->non_public_fields
= 1;
8292 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8294 /* C++ static member. */
8296 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8297 is a declaration, but all versions of G++ as of this writing
8298 (so through at least 3.2.1) incorrectly generate
8299 DW_TAG_variable tags. */
8301 const char *physname
;
8303 /* Get name of field. */
8304 fieldname
= dwarf2_name (die
, cu
);
8305 if (fieldname
== NULL
)
8308 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8310 /* Only create a symbol if this is an external value.
8311 new_symbol checks this and puts the value in the global symbol
8312 table, which we want. If it is not external, new_symbol
8313 will try to put the value in cu->list_in_scope which is wrong. */
8314 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8316 /* A static const member, not much different than an enum as far as
8317 we're concerned, except that we can support more types. */
8318 new_symbol (die
, NULL
, cu
);
8321 /* Get physical name. */
8322 physname
= dwarf2_physname (fieldname
, die
, cu
);
8324 /* The name is already allocated along with this objfile, so we don't
8325 need to duplicate it for the type. */
8326 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8327 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8328 FIELD_NAME (*fp
) = fieldname
;
8330 else if (die
->tag
== DW_TAG_inheritance
)
8334 /* C++ base class field. */
8335 if (handle_data_member_location (die
, cu
, &offset
))
8336 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8337 FIELD_BITSIZE (*fp
) = 0;
8338 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8339 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8340 fip
->nbaseclasses
++;
8344 /* Add a typedef defined in the scope of the FIP's class. */
8347 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8348 struct dwarf2_cu
*cu
)
8350 struct objfile
*objfile
= cu
->objfile
;
8351 struct typedef_field_list
*new_field
;
8352 struct attribute
*attr
;
8353 struct typedef_field
*fp
;
8354 char *fieldname
= "";
8356 /* Allocate a new field list entry and link it in. */
8357 new_field
= xzalloc (sizeof (*new_field
));
8358 make_cleanup (xfree
, new_field
);
8360 gdb_assert (die
->tag
== DW_TAG_typedef
);
8362 fp
= &new_field
->field
;
8364 /* Get name of field. */
8365 fp
->name
= dwarf2_name (die
, cu
);
8366 if (fp
->name
== NULL
)
8369 fp
->type
= read_type_die (die
, cu
);
8371 new_field
->next
= fip
->typedef_field_list
;
8372 fip
->typedef_field_list
= new_field
;
8373 fip
->typedef_field_list_count
++;
8376 /* Create the vector of fields, and attach it to the type. */
8379 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8380 struct dwarf2_cu
*cu
)
8382 int nfields
= fip
->nfields
;
8384 /* Record the field count, allocate space for the array of fields,
8385 and create blank accessibility bitfields if necessary. */
8386 TYPE_NFIELDS (type
) = nfields
;
8387 TYPE_FIELDS (type
) = (struct field
*)
8388 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8389 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8391 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8393 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8395 TYPE_FIELD_PRIVATE_BITS (type
) =
8396 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8397 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8399 TYPE_FIELD_PROTECTED_BITS (type
) =
8400 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8401 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8403 TYPE_FIELD_IGNORE_BITS (type
) =
8404 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8405 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8408 /* If the type has baseclasses, allocate and clear a bit vector for
8409 TYPE_FIELD_VIRTUAL_BITS. */
8410 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8412 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8413 unsigned char *pointer
;
8415 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8416 pointer
= TYPE_ALLOC (type
, num_bytes
);
8417 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8418 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8419 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8422 /* Copy the saved-up fields into the field vector. Start from the head of
8423 the list, adding to the tail of the field array, so that they end up in
8424 the same order in the array in which they were added to the list. */
8425 while (nfields
-- > 0)
8427 struct nextfield
*fieldp
;
8431 fieldp
= fip
->fields
;
8432 fip
->fields
= fieldp
->next
;
8436 fieldp
= fip
->baseclasses
;
8437 fip
->baseclasses
= fieldp
->next
;
8440 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8441 switch (fieldp
->accessibility
)
8443 case DW_ACCESS_private
:
8444 if (cu
->language
!= language_ada
)
8445 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8448 case DW_ACCESS_protected
:
8449 if (cu
->language
!= language_ada
)
8450 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8453 case DW_ACCESS_public
:
8457 /* Unknown accessibility. Complain and treat it as public. */
8459 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8460 fieldp
->accessibility
);
8464 if (nfields
< fip
->nbaseclasses
)
8466 switch (fieldp
->virtuality
)
8468 case DW_VIRTUALITY_virtual
:
8469 case DW_VIRTUALITY_pure_virtual
:
8470 if (cu
->language
== language_ada
)
8471 error (_("unexpected virtuality in component of Ada type"));
8472 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8479 /* Add a member function to the proper fieldlist. */
8482 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8483 struct type
*type
, struct dwarf2_cu
*cu
)
8485 struct objfile
*objfile
= cu
->objfile
;
8486 struct attribute
*attr
;
8487 struct fnfieldlist
*flp
;
8489 struct fn_field
*fnp
;
8491 struct nextfnfield
*new_fnfield
;
8492 struct type
*this_type
;
8493 enum dwarf_access_attribute accessibility
;
8495 if (cu
->language
== language_ada
)
8496 error (_("unexpected member function in Ada type"));
8498 /* Get name of member function. */
8499 fieldname
= dwarf2_name (die
, cu
);
8500 if (fieldname
== NULL
)
8503 /* Look up member function name in fieldlist. */
8504 for (i
= 0; i
< fip
->nfnfields
; i
++)
8506 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8510 /* Create new list element if necessary. */
8511 if (i
< fip
->nfnfields
)
8512 flp
= &fip
->fnfieldlists
[i
];
8515 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8517 fip
->fnfieldlists
= (struct fnfieldlist
*)
8518 xrealloc (fip
->fnfieldlists
,
8519 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8520 * sizeof (struct fnfieldlist
));
8521 if (fip
->nfnfields
== 0)
8522 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8524 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8525 flp
->name
= fieldname
;
8528 i
= fip
->nfnfields
++;
8531 /* Create a new member function field and chain it to the field list
8533 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8534 make_cleanup (xfree
, new_fnfield
);
8535 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8536 new_fnfield
->next
= flp
->head
;
8537 flp
->head
= new_fnfield
;
8540 /* Fill in the member function field info. */
8541 fnp
= &new_fnfield
->fnfield
;
8543 /* Delay processing of the physname until later. */
8544 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8546 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8551 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8552 fnp
->physname
= physname
? physname
: "";
8555 fnp
->type
= alloc_type (objfile
);
8556 this_type
= read_type_die (die
, cu
);
8557 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8559 int nparams
= TYPE_NFIELDS (this_type
);
8561 /* TYPE is the domain of this method, and THIS_TYPE is the type
8562 of the method itself (TYPE_CODE_METHOD). */
8563 smash_to_method_type (fnp
->type
, type
,
8564 TYPE_TARGET_TYPE (this_type
),
8565 TYPE_FIELDS (this_type
),
8566 TYPE_NFIELDS (this_type
),
8567 TYPE_VARARGS (this_type
));
8569 /* Handle static member functions.
8570 Dwarf2 has no clean way to discern C++ static and non-static
8571 member functions. G++ helps GDB by marking the first
8572 parameter for non-static member functions (which is the this
8573 pointer) as artificial. We obtain this information from
8574 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8575 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8576 fnp
->voffset
= VOFFSET_STATIC
;
8579 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8580 dwarf2_full_name (fieldname
, die
, cu
));
8582 /* Get fcontext from DW_AT_containing_type if present. */
8583 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8584 fnp
->fcontext
= die_containing_type (die
, cu
);
8586 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8587 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8589 /* Get accessibility. */
8590 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8592 accessibility
= DW_UNSND (attr
);
8594 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8595 switch (accessibility
)
8597 case DW_ACCESS_private
:
8598 fnp
->is_private
= 1;
8600 case DW_ACCESS_protected
:
8601 fnp
->is_protected
= 1;
8605 /* Check for artificial methods. */
8606 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
8607 if (attr
&& DW_UNSND (attr
) != 0)
8608 fnp
->is_artificial
= 1;
8610 /* Get index in virtual function table if it is a virtual member
8611 function. For older versions of GCC, this is an offset in the
8612 appropriate virtual table, as specified by DW_AT_containing_type.
8613 For everyone else, it is an expression to be evaluated relative
8614 to the object address. */
8616 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
8619 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
8621 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
8623 /* Old-style GCC. */
8624 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
8626 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8627 || (DW_BLOCK (attr
)->size
> 1
8628 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
8629 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
8631 struct dwarf_block blk
;
8634 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8636 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
8637 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
8638 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8639 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
8640 dwarf2_complex_location_expr_complaint ();
8642 fnp
->voffset
/= cu
->header
.addr_size
;
8646 dwarf2_complex_location_expr_complaint ();
8649 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
8651 else if (attr_form_is_section_offset (attr
))
8653 dwarf2_complex_location_expr_complaint ();
8657 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
8663 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8664 if (attr
&& DW_UNSND (attr
))
8666 /* GCC does this, as of 2008-08-25; PR debug/37237. */
8667 complaint (&symfile_complaints
,
8668 _("Member function \"%s\" (offset %d) is virtual "
8669 "but the vtable offset is not specified"),
8670 fieldname
, die
->offset
.sect_off
);
8671 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8672 TYPE_CPLUS_DYNAMIC (type
) = 1;
8677 /* Create the vector of member function fields, and attach it to the type. */
8680 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
8681 struct dwarf2_cu
*cu
)
8683 struct fnfieldlist
*flp
;
8686 if (cu
->language
== language_ada
)
8687 error (_("unexpected member functions in Ada type"));
8689 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8690 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
8691 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
8693 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
8695 struct nextfnfield
*nfp
= flp
->head
;
8696 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
8699 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
8700 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
8701 fn_flp
->fn_fields
= (struct fn_field
*)
8702 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
8703 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
8704 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
8707 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
8710 /* Returns non-zero if NAME is the name of a vtable member in CU's
8711 language, zero otherwise. */
8713 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
8715 static const char vptr
[] = "_vptr";
8716 static const char vtable
[] = "vtable";
8718 /* Look for the C++ and Java forms of the vtable. */
8719 if ((cu
->language
== language_java
8720 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
8721 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
8722 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
8728 /* GCC outputs unnamed structures that are really pointers to member
8729 functions, with the ABI-specified layout. If TYPE describes
8730 such a structure, smash it into a member function type.
8732 GCC shouldn't do this; it should just output pointer to member DIEs.
8733 This is GCC PR debug/28767. */
8736 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
8738 struct type
*pfn_type
, *domain_type
, *new_type
;
8740 /* Check for a structure with no name and two children. */
8741 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
8744 /* Check for __pfn and __delta members. */
8745 if (TYPE_FIELD_NAME (type
, 0) == NULL
8746 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
8747 || TYPE_FIELD_NAME (type
, 1) == NULL
8748 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
8751 /* Find the type of the method. */
8752 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
8753 if (pfn_type
== NULL
8754 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
8755 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
8758 /* Look for the "this" argument. */
8759 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
8760 if (TYPE_NFIELDS (pfn_type
) == 0
8761 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
8762 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
8765 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
8766 new_type
= alloc_type (objfile
);
8767 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
8768 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
8769 TYPE_VARARGS (pfn_type
));
8770 smash_to_methodptr_type (type
, new_type
);
8773 /* Called when we find the DIE that starts a structure or union scope
8774 (definition) to create a type for the structure or union. Fill in
8775 the type's name and general properties; the members will not be
8776 processed until process_structure_type.
8778 NOTE: we need to call these functions regardless of whether or not the
8779 DIE has a DW_AT_name attribute, since it might be an anonymous
8780 structure or union. This gets the type entered into our set of
8783 However, if the structure is incomplete (an opaque struct/union)
8784 then suppress creating a symbol table entry for it since gdb only
8785 wants to find the one with the complete definition. Note that if
8786 it is complete, we just call new_symbol, which does it's own
8787 checking about whether the struct/union is anonymous or not (and
8788 suppresses creating a symbol table entry itself). */
8790 static struct type
*
8791 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8793 struct objfile
*objfile
= cu
->objfile
;
8795 struct attribute
*attr
;
8798 /* If the definition of this type lives in .debug_types, read that type.
8799 Don't follow DW_AT_specification though, that will take us back up
8800 the chain and we want to go down. */
8801 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8804 struct dwarf2_cu
*type_cu
= cu
;
8805 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8807 /* We could just recurse on read_structure_type, but we need to call
8808 get_die_type to ensure only one type for this DIE is created.
8809 This is important, for example, because for c++ classes we need
8810 TYPE_NAME set which is only done by new_symbol. Blech. */
8811 type
= read_type_die (type_die
, type_cu
);
8813 /* TYPE_CU may not be the same as CU.
8814 Ensure TYPE is recorded in CU's type_hash table. */
8815 return set_die_type (die
, type
, cu
);
8818 type
= alloc_type (objfile
);
8819 INIT_CPLUS_SPECIFIC (type
);
8821 name
= dwarf2_name (die
, cu
);
8824 if (cu
->language
== language_cplus
8825 || cu
->language
== language_java
)
8827 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
8829 /* dwarf2_full_name might have already finished building the DIE's
8830 type. If so, there is no need to continue. */
8831 if (get_die_type (die
, cu
) != NULL
)
8832 return get_die_type (die
, cu
);
8834 TYPE_TAG_NAME (type
) = full_name
;
8835 if (die
->tag
== DW_TAG_structure_type
8836 || die
->tag
== DW_TAG_class_type
)
8837 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
8841 /* The name is already allocated along with this objfile, so
8842 we don't need to duplicate it for the type. */
8843 TYPE_TAG_NAME (type
) = (char *) name
;
8844 if (die
->tag
== DW_TAG_class_type
)
8845 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
8849 if (die
->tag
== DW_TAG_structure_type
)
8851 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
8853 else if (die
->tag
== DW_TAG_union_type
)
8855 TYPE_CODE (type
) = TYPE_CODE_UNION
;
8859 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
8862 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
8863 TYPE_DECLARED_CLASS (type
) = 1;
8865 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8868 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8872 TYPE_LENGTH (type
) = 0;
8875 TYPE_STUB_SUPPORTED (type
) = 1;
8876 if (die_is_declaration (die
, cu
))
8877 TYPE_STUB (type
) = 1;
8878 else if (attr
== NULL
&& die
->child
== NULL
8879 && producer_is_realview (cu
->producer
))
8880 /* RealView does not output the required DW_AT_declaration
8881 on incomplete types. */
8882 TYPE_STUB (type
) = 1;
8884 /* We need to add the type field to the die immediately so we don't
8885 infinitely recurse when dealing with pointers to the structure
8886 type within the structure itself. */
8887 set_die_type (die
, type
, cu
);
8889 /* set_die_type should be already done. */
8890 set_descriptive_type (type
, die
, cu
);
8895 /* Finish creating a structure or union type, including filling in
8896 its members and creating a symbol for it. */
8899 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8901 struct objfile
*objfile
= cu
->objfile
;
8902 struct die_info
*child_die
= die
->child
;
8905 type
= get_die_type (die
, cu
);
8907 type
= read_structure_type (die
, cu
);
8909 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
8911 struct field_info fi
;
8912 struct die_info
*child_die
;
8913 VEC (symbolp
) *template_args
= NULL
;
8914 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8916 memset (&fi
, 0, sizeof (struct field_info
));
8918 child_die
= die
->child
;
8920 while (child_die
&& child_die
->tag
)
8922 if (child_die
->tag
== DW_TAG_member
8923 || child_die
->tag
== DW_TAG_variable
)
8925 /* NOTE: carlton/2002-11-05: A C++ static data member
8926 should be a DW_TAG_member that is a declaration, but
8927 all versions of G++ as of this writing (so through at
8928 least 3.2.1) incorrectly generate DW_TAG_variable
8929 tags for them instead. */
8930 dwarf2_add_field (&fi
, child_die
, cu
);
8932 else if (child_die
->tag
== DW_TAG_subprogram
)
8934 /* C++ member function. */
8935 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
8937 else if (child_die
->tag
== DW_TAG_inheritance
)
8939 /* C++ base class field. */
8940 dwarf2_add_field (&fi
, child_die
, cu
);
8942 else if (child_die
->tag
== DW_TAG_typedef
)
8943 dwarf2_add_typedef (&fi
, child_die
, cu
);
8944 else if (child_die
->tag
== DW_TAG_template_type_param
8945 || child_die
->tag
== DW_TAG_template_value_param
)
8947 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8950 VEC_safe_push (symbolp
, template_args
, arg
);
8953 child_die
= sibling_die (child_die
);
8956 /* Attach template arguments to type. */
8957 if (! VEC_empty (symbolp
, template_args
))
8959 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8960 TYPE_N_TEMPLATE_ARGUMENTS (type
)
8961 = VEC_length (symbolp
, template_args
);
8962 TYPE_TEMPLATE_ARGUMENTS (type
)
8963 = obstack_alloc (&objfile
->objfile_obstack
,
8964 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8965 * sizeof (struct symbol
*)));
8966 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
8967 VEC_address (symbolp
, template_args
),
8968 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8969 * sizeof (struct symbol
*)));
8970 VEC_free (symbolp
, template_args
);
8973 /* Attach fields and member functions to the type. */
8975 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
8978 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
8980 /* Get the type which refers to the base class (possibly this
8981 class itself) which contains the vtable pointer for the current
8982 class from the DW_AT_containing_type attribute. This use of
8983 DW_AT_containing_type is a GNU extension. */
8985 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8987 struct type
*t
= die_containing_type (die
, cu
);
8989 TYPE_VPTR_BASETYPE (type
) = t
;
8994 /* Our own class provides vtbl ptr. */
8995 for (i
= TYPE_NFIELDS (t
) - 1;
8996 i
>= TYPE_N_BASECLASSES (t
);
8999 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9001 if (is_vtable_name (fieldname
, cu
))
9003 TYPE_VPTR_FIELDNO (type
) = i
;
9008 /* Complain if virtual function table field not found. */
9009 if (i
< TYPE_N_BASECLASSES (t
))
9010 complaint (&symfile_complaints
,
9011 _("virtual function table pointer "
9012 "not found when defining class '%s'"),
9013 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9018 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9021 else if (cu
->producer
9022 && strncmp (cu
->producer
,
9023 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9025 /* The IBM XLC compiler does not provide direct indication
9026 of the containing type, but the vtable pointer is
9027 always named __vfp. */
9031 for (i
= TYPE_NFIELDS (type
) - 1;
9032 i
>= TYPE_N_BASECLASSES (type
);
9035 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9037 TYPE_VPTR_FIELDNO (type
) = i
;
9038 TYPE_VPTR_BASETYPE (type
) = type
;
9045 /* Copy fi.typedef_field_list linked list elements content into the
9046 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9047 if (fi
.typedef_field_list
)
9049 int i
= fi
.typedef_field_list_count
;
9051 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9052 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9053 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9054 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9056 /* Reverse the list order to keep the debug info elements order. */
9059 struct typedef_field
*dest
, *src
;
9061 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9062 src
= &fi
.typedef_field_list
->field
;
9063 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9068 do_cleanups (back_to
);
9070 if (HAVE_CPLUS_STRUCT (type
))
9071 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9074 quirk_gcc_member_function_pointer (type
, objfile
);
9076 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9077 snapshots) has been known to create a die giving a declaration
9078 for a class that has, as a child, a die giving a definition for a
9079 nested class. So we have to process our children even if the
9080 current die is a declaration. Normally, of course, a declaration
9081 won't have any children at all. */
9083 while (child_die
!= NULL
&& child_die
->tag
)
9085 if (child_die
->tag
== DW_TAG_member
9086 || child_die
->tag
== DW_TAG_variable
9087 || child_die
->tag
== DW_TAG_inheritance
9088 || child_die
->tag
== DW_TAG_template_value_param
9089 || child_die
->tag
== DW_TAG_template_type_param
)
9094 process_die (child_die
, cu
);
9096 child_die
= sibling_die (child_die
);
9099 /* Do not consider external references. According to the DWARF standard,
9100 these DIEs are identified by the fact that they have no byte_size
9101 attribute, and a declaration attribute. */
9102 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9103 || !die_is_declaration (die
, cu
))
9104 new_symbol (die
, type
, cu
);
9107 /* Given a DW_AT_enumeration_type die, set its type. We do not
9108 complete the type's fields yet, or create any symbols. */
9110 static struct type
*
9111 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9113 struct objfile
*objfile
= cu
->objfile
;
9115 struct attribute
*attr
;
9118 /* If the definition of this type lives in .debug_types, read that type.
9119 Don't follow DW_AT_specification though, that will take us back up
9120 the chain and we want to go down. */
9121 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9124 struct dwarf2_cu
*type_cu
= cu
;
9125 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9127 type
= read_type_die (type_die
, type_cu
);
9129 /* TYPE_CU may not be the same as CU.
9130 Ensure TYPE is recorded in CU's type_hash table. */
9131 return set_die_type (die
, type
, cu
);
9134 type
= alloc_type (objfile
);
9136 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9137 name
= dwarf2_full_name (NULL
, die
, cu
);
9139 TYPE_TAG_NAME (type
) = (char *) name
;
9141 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9144 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9148 TYPE_LENGTH (type
) = 0;
9151 /* The enumeration DIE can be incomplete. In Ada, any type can be
9152 declared as private in the package spec, and then defined only
9153 inside the package body. Such types are known as Taft Amendment
9154 Types. When another package uses such a type, an incomplete DIE
9155 may be generated by the compiler. */
9156 if (die_is_declaration (die
, cu
))
9157 TYPE_STUB (type
) = 1;
9159 return set_die_type (die
, type
, cu
);
9162 /* Given a pointer to a die which begins an enumeration, process all
9163 the dies that define the members of the enumeration, and create the
9164 symbol for the enumeration type.
9166 NOTE: We reverse the order of the element list. */
9169 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9171 struct type
*this_type
;
9173 this_type
= get_die_type (die
, cu
);
9174 if (this_type
== NULL
)
9175 this_type
= read_enumeration_type (die
, cu
);
9177 if (die
->child
!= NULL
)
9179 struct die_info
*child_die
;
9181 struct field
*fields
= NULL
;
9183 int unsigned_enum
= 1;
9188 child_die
= die
->child
;
9189 while (child_die
&& child_die
->tag
)
9191 if (child_die
->tag
!= DW_TAG_enumerator
)
9193 process_die (child_die
, cu
);
9197 name
= dwarf2_name (child_die
, cu
);
9200 sym
= new_symbol (child_die
, this_type
, cu
);
9201 if (SYMBOL_VALUE (sym
) < 0)
9206 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9209 mask
|= SYMBOL_VALUE (sym
);
9211 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9213 fields
= (struct field
*)
9215 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9216 * sizeof (struct field
));
9219 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9220 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9221 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9222 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9228 child_die
= sibling_die (child_die
);
9233 TYPE_NFIELDS (this_type
) = num_fields
;
9234 TYPE_FIELDS (this_type
) = (struct field
*)
9235 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9236 memcpy (TYPE_FIELDS (this_type
), fields
,
9237 sizeof (struct field
) * num_fields
);
9241 TYPE_UNSIGNED (this_type
) = 1;
9243 TYPE_FLAG_ENUM (this_type
) = 1;
9246 /* If we are reading an enum from a .debug_types unit, and the enum
9247 is a declaration, and the enum is not the signatured type in the
9248 unit, then we do not want to add a symbol for it. Adding a
9249 symbol would in some cases obscure the true definition of the
9250 enum, giving users an incomplete type when the definition is
9251 actually available. Note that we do not want to do this for all
9252 enums which are just declarations, because C++0x allows forward
9253 enum declarations. */
9254 if (cu
->per_cu
->is_debug_types
9255 && die_is_declaration (die
, cu
))
9257 struct signatured_type
*sig_type
;
9260 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9261 cu
->per_cu
->info_or_types_section
,
9262 cu
->per_cu
->offset
);
9263 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9264 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9268 new_symbol (die
, this_type
, cu
);
9271 /* Extract all information from a DW_TAG_array_type DIE and put it in
9272 the DIE's type field. For now, this only handles one dimensional
9275 static struct type
*
9276 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9278 struct objfile
*objfile
= cu
->objfile
;
9279 struct die_info
*child_die
;
9281 struct type
*element_type
, *range_type
, *index_type
;
9282 struct type
**range_types
= NULL
;
9283 struct attribute
*attr
;
9285 struct cleanup
*back_to
;
9288 element_type
= die_type (die
, cu
);
9290 /* The die_type call above may have already set the type for this DIE. */
9291 type
= get_die_type (die
, cu
);
9295 /* Irix 6.2 native cc creates array types without children for
9296 arrays with unspecified length. */
9297 if (die
->child
== NULL
)
9299 index_type
= objfile_type (objfile
)->builtin_int
;
9300 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9301 type
= create_array_type (NULL
, element_type
, range_type
);
9302 return set_die_type (die
, type
, cu
);
9305 back_to
= make_cleanup (null_cleanup
, NULL
);
9306 child_die
= die
->child
;
9307 while (child_die
&& child_die
->tag
)
9309 if (child_die
->tag
== DW_TAG_subrange_type
)
9311 struct type
*child_type
= read_type_die (child_die
, cu
);
9313 if (child_type
!= NULL
)
9315 /* The range type was succesfully read. Save it for the
9316 array type creation. */
9317 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9319 range_types
= (struct type
**)
9320 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9321 * sizeof (struct type
*));
9323 make_cleanup (free_current_contents
, &range_types
);
9325 range_types
[ndim
++] = child_type
;
9328 child_die
= sibling_die (child_die
);
9331 /* Dwarf2 dimensions are output from left to right, create the
9332 necessary array types in backwards order. */
9334 type
= element_type
;
9336 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9341 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9346 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9349 /* Understand Dwarf2 support for vector types (like they occur on
9350 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9351 array type. This is not part of the Dwarf2/3 standard yet, but a
9352 custom vendor extension. The main difference between a regular
9353 array and the vector variant is that vectors are passed by value
9355 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9357 make_vector_type (type
);
9359 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9360 implementation may choose to implement triple vectors using this
9362 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9365 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9366 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9368 complaint (&symfile_complaints
,
9369 _("DW_AT_byte_size for array type smaller "
9370 "than the total size of elements"));
9373 name
= dwarf2_name (die
, cu
);
9375 TYPE_NAME (type
) = name
;
9377 /* Install the type in the die. */
9378 set_die_type (die
, type
, cu
);
9380 /* set_die_type should be already done. */
9381 set_descriptive_type (type
, die
, cu
);
9383 do_cleanups (back_to
);
9388 static enum dwarf_array_dim_ordering
9389 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9391 struct attribute
*attr
;
9393 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9395 if (attr
) return DW_SND (attr
);
9397 /* GNU F77 is a special case, as at 08/2004 array type info is the
9398 opposite order to the dwarf2 specification, but data is still
9399 laid out as per normal fortran.
9401 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9402 version checking. */
9404 if (cu
->language
== language_fortran
9405 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9407 return DW_ORD_row_major
;
9410 switch (cu
->language_defn
->la_array_ordering
)
9412 case array_column_major
:
9413 return DW_ORD_col_major
;
9414 case array_row_major
:
9416 return DW_ORD_row_major
;
9420 /* Extract all information from a DW_TAG_set_type DIE and put it in
9421 the DIE's type field. */
9423 static struct type
*
9424 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9426 struct type
*domain_type
, *set_type
;
9427 struct attribute
*attr
;
9429 domain_type
= die_type (die
, cu
);
9431 /* The die_type call above may have already set the type for this DIE. */
9432 set_type
= get_die_type (die
, cu
);
9436 set_type
= create_set_type (NULL
, domain_type
);
9438 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9440 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9442 return set_die_type (die
, set_type
, cu
);
9445 /* First cut: install each common block member as a global variable. */
9448 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9450 struct die_info
*child_die
;
9451 struct attribute
*attr
;
9453 CORE_ADDR base
= (CORE_ADDR
) 0;
9455 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9458 /* Support the .debug_loc offsets. */
9459 if (attr_form_is_block (attr
))
9461 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9463 else if (attr_form_is_section_offset (attr
))
9465 dwarf2_complex_location_expr_complaint ();
9469 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9470 "common block member");
9473 if (die
->child
!= NULL
)
9475 child_die
= die
->child
;
9476 while (child_die
&& child_die
->tag
)
9480 sym
= new_symbol (child_die
, NULL
, cu
);
9482 && handle_data_member_location (child_die
, cu
, &offset
))
9484 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9485 add_symbol_to_list (sym
, &global_symbols
);
9487 child_die
= sibling_die (child_die
);
9492 /* Create a type for a C++ namespace. */
9494 static struct type
*
9495 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9497 struct objfile
*objfile
= cu
->objfile
;
9498 const char *previous_prefix
, *name
;
9502 /* For extensions, reuse the type of the original namespace. */
9503 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9505 struct die_info
*ext_die
;
9506 struct dwarf2_cu
*ext_cu
= cu
;
9508 ext_die
= dwarf2_extension (die
, &ext_cu
);
9509 type
= read_type_die (ext_die
, ext_cu
);
9511 /* EXT_CU may not be the same as CU.
9512 Ensure TYPE is recorded in CU's type_hash table. */
9513 return set_die_type (die
, type
, cu
);
9516 name
= namespace_name (die
, &is_anonymous
, cu
);
9518 /* Now build the name of the current namespace. */
9520 previous_prefix
= determine_prefix (die
, cu
);
9521 if (previous_prefix
[0] != '\0')
9522 name
= typename_concat (&objfile
->objfile_obstack
,
9523 previous_prefix
, name
, 0, cu
);
9525 /* Create the type. */
9526 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9528 TYPE_NAME (type
) = (char *) name
;
9529 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9531 return set_die_type (die
, type
, cu
);
9534 /* Read a C++ namespace. */
9537 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9539 struct objfile
*objfile
= cu
->objfile
;
9542 /* Add a symbol associated to this if we haven't seen the namespace
9543 before. Also, add a using directive if it's an anonymous
9546 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9550 type
= read_type_die (die
, cu
);
9551 new_symbol (die
, type
, cu
);
9553 namespace_name (die
, &is_anonymous
, cu
);
9556 const char *previous_prefix
= determine_prefix (die
, cu
);
9558 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9559 NULL
, NULL
, &objfile
->objfile_obstack
);
9563 if (die
->child
!= NULL
)
9565 struct die_info
*child_die
= die
->child
;
9567 while (child_die
&& child_die
->tag
)
9569 process_die (child_die
, cu
);
9570 child_die
= sibling_die (child_die
);
9575 /* Read a Fortran module as type. This DIE can be only a declaration used for
9576 imported module. Still we need that type as local Fortran "use ... only"
9577 declaration imports depend on the created type in determine_prefix. */
9579 static struct type
*
9580 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9582 struct objfile
*objfile
= cu
->objfile
;
9586 module_name
= dwarf2_name (die
, cu
);
9588 complaint (&symfile_complaints
,
9589 _("DW_TAG_module has no name, offset 0x%x"),
9590 die
->offset
.sect_off
);
9591 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
9593 /* determine_prefix uses TYPE_TAG_NAME. */
9594 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9596 return set_die_type (die
, type
, cu
);
9599 /* Read a Fortran module. */
9602 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
9604 struct die_info
*child_die
= die
->child
;
9606 while (child_die
&& child_die
->tag
)
9608 process_die (child_die
, cu
);
9609 child_die
= sibling_die (child_die
);
9613 /* Return the name of the namespace represented by DIE. Set
9614 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
9618 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
9620 struct die_info
*current_die
;
9621 const char *name
= NULL
;
9623 /* Loop through the extensions until we find a name. */
9625 for (current_die
= die
;
9626 current_die
!= NULL
;
9627 current_die
= dwarf2_extension (die
, &cu
))
9629 name
= dwarf2_name (current_die
, cu
);
9634 /* Is it an anonymous namespace? */
9636 *is_anonymous
= (name
== NULL
);
9638 name
= CP_ANONYMOUS_NAMESPACE_STR
;
9643 /* Extract all information from a DW_TAG_pointer_type DIE and add to
9644 the user defined type vector. */
9646 static struct type
*
9647 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9649 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9650 struct comp_unit_head
*cu_header
= &cu
->header
;
9652 struct attribute
*attr_byte_size
;
9653 struct attribute
*attr_address_class
;
9654 int byte_size
, addr_class
;
9655 struct type
*target_type
;
9657 target_type
= die_type (die
, cu
);
9659 /* The die_type call above may have already set the type for this DIE. */
9660 type
= get_die_type (die
, cu
);
9664 type
= lookup_pointer_type (target_type
);
9666 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9668 byte_size
= DW_UNSND (attr_byte_size
);
9670 byte_size
= cu_header
->addr_size
;
9672 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
9673 if (attr_address_class
)
9674 addr_class
= DW_UNSND (attr_address_class
);
9676 addr_class
= DW_ADDR_none
;
9678 /* If the pointer size or address class is different than the
9679 default, create a type variant marked as such and set the
9680 length accordingly. */
9681 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
9683 if (gdbarch_address_class_type_flags_p (gdbarch
))
9687 type_flags
= gdbarch_address_class_type_flags
9688 (gdbarch
, byte_size
, addr_class
);
9689 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
9691 type
= make_type_with_address_space (type
, type_flags
);
9693 else if (TYPE_LENGTH (type
) != byte_size
)
9695 complaint (&symfile_complaints
,
9696 _("invalid pointer size %d"), byte_size
);
9700 /* Should we also complain about unhandled address classes? */
9704 TYPE_LENGTH (type
) = byte_size
;
9705 return set_die_type (die
, type
, cu
);
9708 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
9709 the user defined type vector. */
9711 static struct type
*
9712 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9715 struct type
*to_type
;
9716 struct type
*domain
;
9718 to_type
= die_type (die
, cu
);
9719 domain
= die_containing_type (die
, cu
);
9721 /* The calls above may have already set the type for this DIE. */
9722 type
= get_die_type (die
, cu
);
9726 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
9727 type
= lookup_methodptr_type (to_type
);
9729 type
= lookup_memberptr_type (to_type
, domain
);
9731 return set_die_type (die
, type
, cu
);
9734 /* Extract all information from a DW_TAG_reference_type DIE and add to
9735 the user defined type vector. */
9737 static struct type
*
9738 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9740 struct comp_unit_head
*cu_header
= &cu
->header
;
9741 struct type
*type
, *target_type
;
9742 struct attribute
*attr
;
9744 target_type
= die_type (die
, cu
);
9746 /* The die_type call above may have already set the type for this DIE. */
9747 type
= get_die_type (die
, cu
);
9751 type
= lookup_reference_type (target_type
);
9752 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9755 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9759 TYPE_LENGTH (type
) = cu_header
->addr_size
;
9761 return set_die_type (die
, type
, cu
);
9764 static struct type
*
9765 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9767 struct type
*base_type
, *cv_type
;
9769 base_type
= die_type (die
, cu
);
9771 /* The die_type call above may have already set the type for this DIE. */
9772 cv_type
= get_die_type (die
, cu
);
9776 /* In case the const qualifier is applied to an array type, the element type
9777 is so qualified, not the array type (section 6.7.3 of C99). */
9778 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
9780 struct type
*el_type
, *inner_array
;
9782 base_type
= copy_type (base_type
);
9783 inner_array
= base_type
;
9785 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
9787 TYPE_TARGET_TYPE (inner_array
) =
9788 copy_type (TYPE_TARGET_TYPE (inner_array
));
9789 inner_array
= TYPE_TARGET_TYPE (inner_array
);
9792 el_type
= TYPE_TARGET_TYPE (inner_array
);
9793 TYPE_TARGET_TYPE (inner_array
) =
9794 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
9796 return set_die_type (die
, base_type
, cu
);
9799 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
9800 return set_die_type (die
, cv_type
, cu
);
9803 static struct type
*
9804 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9806 struct type
*base_type
, *cv_type
;
9808 base_type
= die_type (die
, cu
);
9810 /* The die_type call above may have already set the type for this DIE. */
9811 cv_type
= get_die_type (die
, cu
);
9815 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
9816 return set_die_type (die
, cv_type
, cu
);
9819 /* Extract all information from a DW_TAG_string_type DIE and add to
9820 the user defined type vector. It isn't really a user defined type,
9821 but it behaves like one, with other DIE's using an AT_user_def_type
9822 attribute to reference it. */
9824 static struct type
*
9825 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9827 struct objfile
*objfile
= cu
->objfile
;
9828 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9829 struct type
*type
, *range_type
, *index_type
, *char_type
;
9830 struct attribute
*attr
;
9831 unsigned int length
;
9833 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
9836 length
= DW_UNSND (attr
);
9840 /* Check for the DW_AT_byte_size attribute. */
9841 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9844 length
= DW_UNSND (attr
);
9852 index_type
= objfile_type (objfile
)->builtin_int
;
9853 range_type
= create_range_type (NULL
, index_type
, 1, length
);
9854 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
9855 type
= create_string_type (NULL
, char_type
, range_type
);
9857 return set_die_type (die
, type
, cu
);
9860 /* Handle DIES due to C code like:
9864 int (*funcp)(int a, long l);
9868 ('funcp' generates a DW_TAG_subroutine_type DIE). */
9870 static struct type
*
9871 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9873 struct objfile
*objfile
= cu
->objfile
;
9874 struct type
*type
; /* Type that this function returns. */
9875 struct type
*ftype
; /* Function that returns above type. */
9876 struct attribute
*attr
;
9878 type
= die_type (die
, cu
);
9880 /* The die_type call above may have already set the type for this DIE. */
9881 ftype
= get_die_type (die
, cu
);
9885 ftype
= lookup_function_type (type
);
9887 /* All functions in C++, Pascal and Java have prototypes. */
9888 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
9889 if ((attr
&& (DW_UNSND (attr
) != 0))
9890 || cu
->language
== language_cplus
9891 || cu
->language
== language_java
9892 || cu
->language
== language_pascal
)
9893 TYPE_PROTOTYPED (ftype
) = 1;
9894 else if (producer_is_realview (cu
->producer
))
9895 /* RealView does not emit DW_AT_prototyped. We can not
9896 distinguish prototyped and unprototyped functions; default to
9897 prototyped, since that is more common in modern code (and
9898 RealView warns about unprototyped functions). */
9899 TYPE_PROTOTYPED (ftype
) = 1;
9901 /* Store the calling convention in the type if it's available in
9902 the subroutine die. Otherwise set the calling convention to
9903 the default value DW_CC_normal. */
9904 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
9906 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
9907 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
9908 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
9910 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
9912 /* We need to add the subroutine type to the die immediately so
9913 we don't infinitely recurse when dealing with parameters
9914 declared as the same subroutine type. */
9915 set_die_type (die
, ftype
, cu
);
9917 if (die
->child
!= NULL
)
9919 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
9920 struct die_info
*child_die
;
9921 int nparams
, iparams
;
9923 /* Count the number of parameters.
9924 FIXME: GDB currently ignores vararg functions, but knows about
9925 vararg member functions. */
9927 child_die
= die
->child
;
9928 while (child_die
&& child_die
->tag
)
9930 if (child_die
->tag
== DW_TAG_formal_parameter
)
9932 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
9933 TYPE_VARARGS (ftype
) = 1;
9934 child_die
= sibling_die (child_die
);
9937 /* Allocate storage for parameters and fill them in. */
9938 TYPE_NFIELDS (ftype
) = nparams
;
9939 TYPE_FIELDS (ftype
) = (struct field
*)
9940 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
9942 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
9943 even if we error out during the parameters reading below. */
9944 for (iparams
= 0; iparams
< nparams
; iparams
++)
9945 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
9948 child_die
= die
->child
;
9949 while (child_die
&& child_die
->tag
)
9951 if (child_die
->tag
== DW_TAG_formal_parameter
)
9953 struct type
*arg_type
;
9955 /* DWARF version 2 has no clean way to discern C++
9956 static and non-static member functions. G++ helps
9957 GDB by marking the first parameter for non-static
9958 member functions (which is the this pointer) as
9959 artificial. We pass this information to
9960 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
9962 DWARF version 3 added DW_AT_object_pointer, which GCC
9963 4.5 does not yet generate. */
9964 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
9966 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
9969 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
9971 /* GCC/43521: In java, the formal parameter
9972 "this" is sometimes not marked with DW_AT_artificial. */
9973 if (cu
->language
== language_java
)
9975 const char *name
= dwarf2_name (child_die
, cu
);
9977 if (name
&& !strcmp (name
, "this"))
9978 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
9981 arg_type
= die_type (child_die
, cu
);
9983 /* RealView does not mark THIS as const, which the testsuite
9984 expects. GCC marks THIS as const in method definitions,
9985 but not in the class specifications (GCC PR 43053). */
9986 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
9987 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
9990 struct dwarf2_cu
*arg_cu
= cu
;
9991 const char *name
= dwarf2_name (child_die
, cu
);
9993 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
9996 /* If the compiler emits this, use it. */
9997 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10000 else if (name
&& strcmp (name
, "this") == 0)
10001 /* Function definitions will have the argument names. */
10003 else if (name
== NULL
&& iparams
== 0)
10004 /* Declarations may not have the names, so like
10005 elsewhere in GDB, assume an artificial first
10006 argument is "this". */
10010 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10014 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10017 child_die
= sibling_die (child_die
);
10024 static struct type
*
10025 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10027 struct objfile
*objfile
= cu
->objfile
;
10028 const char *name
= NULL
;
10029 struct type
*this_type
, *target_type
;
10031 name
= dwarf2_full_name (NULL
, die
, cu
);
10032 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10033 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10034 TYPE_NAME (this_type
) = (char *) name
;
10035 set_die_type (die
, this_type
, cu
);
10036 target_type
= die_type (die
, cu
);
10037 if (target_type
!= this_type
)
10038 TYPE_TARGET_TYPE (this_type
) = target_type
;
10041 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10042 spec and cause infinite loops in GDB. */
10043 complaint (&symfile_complaints
,
10044 _("Self-referential DW_TAG_typedef "
10045 "- DIE at 0x%x [in module %s]"),
10046 die
->offset
.sect_off
, objfile
->name
);
10047 TYPE_TARGET_TYPE (this_type
) = NULL
;
10052 /* Find a representation of a given base type and install
10053 it in the TYPE field of the die. */
10055 static struct type
*
10056 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10058 struct objfile
*objfile
= cu
->objfile
;
10060 struct attribute
*attr
;
10061 int encoding
= 0, size
= 0;
10063 enum type_code code
= TYPE_CODE_INT
;
10064 int type_flags
= 0;
10065 struct type
*target_type
= NULL
;
10067 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10070 encoding
= DW_UNSND (attr
);
10072 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10075 size
= DW_UNSND (attr
);
10077 name
= dwarf2_name (die
, cu
);
10080 complaint (&symfile_complaints
,
10081 _("DW_AT_name missing from DW_TAG_base_type"));
10086 case DW_ATE_address
:
10087 /* Turn DW_ATE_address into a void * pointer. */
10088 code
= TYPE_CODE_PTR
;
10089 type_flags
|= TYPE_FLAG_UNSIGNED
;
10090 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10092 case DW_ATE_boolean
:
10093 code
= TYPE_CODE_BOOL
;
10094 type_flags
|= TYPE_FLAG_UNSIGNED
;
10096 case DW_ATE_complex_float
:
10097 code
= TYPE_CODE_COMPLEX
;
10098 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10100 case DW_ATE_decimal_float
:
10101 code
= TYPE_CODE_DECFLOAT
;
10104 code
= TYPE_CODE_FLT
;
10106 case DW_ATE_signed
:
10108 case DW_ATE_unsigned
:
10109 type_flags
|= TYPE_FLAG_UNSIGNED
;
10110 if (cu
->language
== language_fortran
10112 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10113 code
= TYPE_CODE_CHAR
;
10115 case DW_ATE_signed_char
:
10116 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10117 || cu
->language
== language_pascal
10118 || cu
->language
== language_fortran
)
10119 code
= TYPE_CODE_CHAR
;
10121 case DW_ATE_unsigned_char
:
10122 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10123 || cu
->language
== language_pascal
10124 || cu
->language
== language_fortran
)
10125 code
= TYPE_CODE_CHAR
;
10126 type_flags
|= TYPE_FLAG_UNSIGNED
;
10129 /* We just treat this as an integer and then recognize the
10130 type by name elsewhere. */
10134 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10135 dwarf_type_encoding_name (encoding
));
10139 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10140 TYPE_NAME (type
) = name
;
10141 TYPE_TARGET_TYPE (type
) = target_type
;
10143 if (name
&& strcmp (name
, "char") == 0)
10144 TYPE_NOSIGN (type
) = 1;
10146 return set_die_type (die
, type
, cu
);
10149 /* Read the given DW_AT_subrange DIE. */
10151 static struct type
*
10152 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10154 struct type
*base_type
;
10155 struct type
*range_type
;
10156 struct attribute
*attr
;
10158 int low_default_is_valid
;
10160 LONGEST negative_mask
;
10162 base_type
= die_type (die
, cu
);
10163 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10164 check_typedef (base_type
);
10166 /* The die_type call above may have already set the type for this DIE. */
10167 range_type
= get_die_type (die
, cu
);
10171 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10172 omitting DW_AT_lower_bound. */
10173 switch (cu
->language
)
10176 case language_cplus
:
10178 low_default_is_valid
= 1;
10180 case language_fortran
:
10182 low_default_is_valid
= 1;
10185 case language_java
:
10186 case language_objc
:
10188 low_default_is_valid
= (cu
->header
.version
>= 4);
10192 case language_pascal
:
10194 low_default_is_valid
= (cu
->header
.version
>= 4);
10198 low_default_is_valid
= 0;
10202 /* FIXME: For variable sized arrays either of these could be
10203 a variable rather than a constant value. We'll allow it,
10204 but we don't know how to handle it. */
10205 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10207 low
= dwarf2_get_attr_constant_value (attr
, low
);
10208 else if (!low_default_is_valid
)
10209 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10210 "- DIE at 0x%x [in module %s]"),
10211 die
->offset
.sect_off
, cu
->objfile
->name
);
10213 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10216 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10218 /* GCC encodes arrays with unspecified or dynamic length
10219 with a DW_FORM_block1 attribute or a reference attribute.
10220 FIXME: GDB does not yet know how to handle dynamic
10221 arrays properly, treat them as arrays with unspecified
10224 FIXME: jimb/2003-09-22: GDB does not really know
10225 how to handle arrays of unspecified length
10226 either; we just represent them as zero-length
10227 arrays. Choose an appropriate upper bound given
10228 the lower bound we've computed above. */
10232 high
= dwarf2_get_attr_constant_value (attr
, 1);
10236 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10239 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10240 high
= low
+ count
- 1;
10244 /* Unspecified array length. */
10249 /* Dwarf-2 specifications explicitly allows to create subrange types
10250 without specifying a base type.
10251 In that case, the base type must be set to the type of
10252 the lower bound, upper bound or count, in that order, if any of these
10253 three attributes references an object that has a type.
10254 If no base type is found, the Dwarf-2 specifications say that
10255 a signed integer type of size equal to the size of an address should
10257 For the following C code: `extern char gdb_int [];'
10258 GCC produces an empty range DIE.
10259 FIXME: muller/2010-05-28: Possible references to object for low bound,
10260 high bound or count are not yet handled by this code. */
10261 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10263 struct objfile
*objfile
= cu
->objfile
;
10264 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10265 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10266 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10268 /* Test "int", "long int", and "long long int" objfile types,
10269 and select the first one having a size above or equal to the
10270 architecture address size. */
10271 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10272 base_type
= int_type
;
10275 int_type
= objfile_type (objfile
)->builtin_long
;
10276 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10277 base_type
= int_type
;
10280 int_type
= objfile_type (objfile
)->builtin_long_long
;
10281 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10282 base_type
= int_type
;
10288 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10289 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10290 low
|= negative_mask
;
10291 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10292 high
|= negative_mask
;
10294 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10296 /* Mark arrays with dynamic length at least as an array of unspecified
10297 length. GDB could check the boundary but before it gets implemented at
10298 least allow accessing the array elements. */
10299 if (attr
&& attr_form_is_block (attr
))
10300 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10302 /* Ada expects an empty array on no boundary attributes. */
10303 if (attr
== NULL
&& cu
->language
!= language_ada
)
10304 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10306 name
= dwarf2_name (die
, cu
);
10308 TYPE_NAME (range_type
) = name
;
10310 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10312 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10314 set_die_type (die
, range_type
, cu
);
10316 /* set_die_type should be already done. */
10317 set_descriptive_type (range_type
, die
, cu
);
10322 static struct type
*
10323 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10327 /* For now, we only support the C meaning of an unspecified type: void. */
10329 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10330 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10332 return set_die_type (die
, type
, cu
);
10335 /* Read a single die and all its descendents. Set the die's sibling
10336 field to NULL; set other fields in the die correctly, and set all
10337 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10338 location of the info_ptr after reading all of those dies. PARENT
10339 is the parent of the die in question. */
10341 static struct die_info
*
10342 read_die_and_children (const struct die_reader_specs
*reader
,
10343 gdb_byte
*info_ptr
,
10344 gdb_byte
**new_info_ptr
,
10345 struct die_info
*parent
)
10347 struct die_info
*die
;
10351 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10354 *new_info_ptr
= cur_ptr
;
10357 store_in_ref_table (die
, reader
->cu
);
10360 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10364 *new_info_ptr
= cur_ptr
;
10367 die
->sibling
= NULL
;
10368 die
->parent
= parent
;
10372 /* Read a die, all of its descendents, and all of its siblings; set
10373 all of the fields of all of the dies correctly. Arguments are as
10374 in read_die_and_children. */
10376 static struct die_info
*
10377 read_die_and_siblings (const struct die_reader_specs
*reader
,
10378 gdb_byte
*info_ptr
,
10379 gdb_byte
**new_info_ptr
,
10380 struct die_info
*parent
)
10382 struct die_info
*first_die
, *last_sibling
;
10385 cur_ptr
= info_ptr
;
10386 first_die
= last_sibling
= NULL
;
10390 struct die_info
*die
10391 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10395 *new_info_ptr
= cur_ptr
;
10402 last_sibling
->sibling
= die
;
10404 last_sibling
= die
;
10408 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10410 The caller is responsible for filling in the extra attributes
10411 and updating (*DIEP)->num_attrs.
10412 Set DIEP to point to a newly allocated die with its information,
10413 except for its child, sibling, and parent fields.
10414 Set HAS_CHILDREN to tell whether the die has children or not. */
10417 read_full_die_1 (const struct die_reader_specs
*reader
,
10418 struct die_info
**diep
, gdb_byte
*info_ptr
,
10419 int *has_children
, int num_extra_attrs
)
10421 unsigned int abbrev_number
, bytes_read
, i
;
10422 sect_offset offset
;
10423 struct abbrev_info
*abbrev
;
10424 struct die_info
*die
;
10425 struct dwarf2_cu
*cu
= reader
->cu
;
10426 bfd
*abfd
= reader
->abfd
;
10428 offset
.sect_off
= info_ptr
- reader
->buffer
;
10429 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10430 info_ptr
+= bytes_read
;
10431 if (!abbrev_number
)
10438 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10440 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10442 bfd_get_filename (abfd
));
10444 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10445 die
->offset
= offset
;
10446 die
->tag
= abbrev
->tag
;
10447 die
->abbrev
= abbrev_number
;
10449 /* Make the result usable.
10450 The caller needs to update num_attrs after adding the extra
10452 die
->num_attrs
= abbrev
->num_attrs
;
10454 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10455 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10459 *has_children
= abbrev
->has_children
;
10463 /* Read a die and all its attributes.
10464 Set DIEP to point to a newly allocated die with its information,
10465 except for its child, sibling, and parent fields.
10466 Set HAS_CHILDREN to tell whether the die has children or not. */
10469 read_full_die (const struct die_reader_specs
*reader
,
10470 struct die_info
**diep
, gdb_byte
*info_ptr
,
10473 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10476 /* In DWARF version 2, the description of the debugging information is
10477 stored in a separate .debug_abbrev section. Before we read any
10478 dies from a section we read in all abbreviations and install them
10479 in a hash table. This function also sets flags in CU describing
10480 the data found in the abbrev table. */
10483 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10484 struct dwarf2_section_info
*abbrev_section
)
10487 bfd
*abfd
= abbrev_section
->asection
->owner
;
10488 struct comp_unit_head
*cu_header
= &cu
->header
;
10489 gdb_byte
*abbrev_ptr
;
10490 struct abbrev_info
*cur_abbrev
;
10491 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10492 unsigned int abbrev_form
, hash_number
;
10493 struct attr_abbrev
*cur_attrs
;
10494 unsigned int allocated_attrs
;
10496 /* Initialize dwarf2 abbrevs. */
10497 obstack_init (&cu
->abbrev_obstack
);
10498 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10500 * sizeof (struct abbrev_info
*)));
10501 memset (cu
->dwarf2_abbrevs
, 0,
10502 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10504 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10505 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10506 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10507 abbrev_ptr
+= bytes_read
;
10509 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10510 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10512 /* Loop until we reach an abbrev number of 0. */
10513 while (abbrev_number
)
10515 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10517 /* read in abbrev header */
10518 cur_abbrev
->number
= abbrev_number
;
10519 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10520 abbrev_ptr
+= bytes_read
;
10521 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10524 /* now read in declarations */
10525 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10526 abbrev_ptr
+= bytes_read
;
10527 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10528 abbrev_ptr
+= bytes_read
;
10529 while (abbrev_name
)
10531 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10533 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10535 = xrealloc (cur_attrs
, (allocated_attrs
10536 * sizeof (struct attr_abbrev
)));
10539 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10540 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10541 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10542 abbrev_ptr
+= bytes_read
;
10543 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10544 abbrev_ptr
+= bytes_read
;
10547 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10548 (cur_abbrev
->num_attrs
10549 * sizeof (struct attr_abbrev
)));
10550 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10551 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10553 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10554 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10555 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10557 /* Get next abbreviation.
10558 Under Irix6 the abbreviations for a compilation unit are not
10559 always properly terminated with an abbrev number of 0.
10560 Exit loop if we encounter an abbreviation which we have
10561 already read (which means we are about to read the abbreviations
10562 for the next compile unit) or if the end of the abbreviation
10563 table is reached. */
10564 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10565 >= abbrev_section
->size
)
10567 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10568 abbrev_ptr
+= bytes_read
;
10569 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10576 /* Release the memory used by the abbrev table for a compilation unit. */
10579 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10581 struct dwarf2_cu
*cu
= ptr_to_cu
;
10583 obstack_free (&cu
->abbrev_obstack
, NULL
);
10584 cu
->dwarf2_abbrevs
= NULL
;
10587 /* Lookup an abbrev_info structure in the abbrev hash table. */
10589 static struct abbrev_info
*
10590 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
10592 unsigned int hash_number
;
10593 struct abbrev_info
*abbrev
;
10595 hash_number
= number
% ABBREV_HASH_SIZE
;
10596 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
10600 if (abbrev
->number
== number
)
10603 abbrev
= abbrev
->next
;
10608 /* Returns nonzero if TAG represents a type that we might generate a partial
10612 is_type_tag_for_partial (int tag
)
10617 /* Some types that would be reasonable to generate partial symbols for,
10618 that we don't at present. */
10619 case DW_TAG_array_type
:
10620 case DW_TAG_file_type
:
10621 case DW_TAG_ptr_to_member_type
:
10622 case DW_TAG_set_type
:
10623 case DW_TAG_string_type
:
10624 case DW_TAG_subroutine_type
:
10626 case DW_TAG_base_type
:
10627 case DW_TAG_class_type
:
10628 case DW_TAG_interface_type
:
10629 case DW_TAG_enumeration_type
:
10630 case DW_TAG_structure_type
:
10631 case DW_TAG_subrange_type
:
10632 case DW_TAG_typedef
:
10633 case DW_TAG_union_type
:
10640 /* Load all DIEs that are interesting for partial symbols into memory. */
10642 static struct partial_die_info
*
10643 load_partial_dies (const struct die_reader_specs
*reader
,
10644 gdb_byte
*info_ptr
, int building_psymtab
)
10646 struct dwarf2_cu
*cu
= reader
->cu
;
10647 struct objfile
*objfile
= cu
->objfile
;
10648 struct partial_die_info
*part_die
;
10649 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
10650 struct abbrev_info
*abbrev
;
10651 unsigned int bytes_read
;
10652 unsigned int load_all
= 0;
10653 int nesting_level
= 1;
10658 gdb_assert (cu
->per_cu
!= NULL
);
10659 if (cu
->per_cu
->load_all_dies
)
10663 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10667 &cu
->comp_unit_obstack
,
10668 hashtab_obstack_allocate
,
10669 dummy_obstack_deallocate
);
10671 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10672 sizeof (struct partial_die_info
));
10676 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
10678 /* A NULL abbrev means the end of a series of children. */
10679 if (abbrev
== NULL
)
10681 if (--nesting_level
== 0)
10683 /* PART_DIE was probably the last thing allocated on the
10684 comp_unit_obstack, so we could call obstack_free
10685 here. We don't do that because the waste is small,
10686 and will be cleaned up when we're done with this
10687 compilation unit. This way, we're also more robust
10688 against other users of the comp_unit_obstack. */
10691 info_ptr
+= bytes_read
;
10692 last_die
= parent_die
;
10693 parent_die
= parent_die
->die_parent
;
10697 /* Check for template arguments. We never save these; if
10698 they're seen, we just mark the parent, and go on our way. */
10699 if (parent_die
!= NULL
10700 && cu
->language
== language_cplus
10701 && (abbrev
->tag
== DW_TAG_template_type_param
10702 || abbrev
->tag
== DW_TAG_template_value_param
))
10704 parent_die
->has_template_arguments
= 1;
10708 /* We don't need a partial DIE for the template argument. */
10709 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10714 /* We only recurse into c++ subprograms looking for template arguments.
10715 Skip their other children. */
10717 && cu
->language
== language_cplus
10718 && parent_die
!= NULL
10719 && parent_die
->tag
== DW_TAG_subprogram
)
10721 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10725 /* Check whether this DIE is interesting enough to save. Normally
10726 we would not be interested in members here, but there may be
10727 later variables referencing them via DW_AT_specification (for
10728 static members). */
10730 && !is_type_tag_for_partial (abbrev
->tag
)
10731 && abbrev
->tag
!= DW_TAG_constant
10732 && abbrev
->tag
!= DW_TAG_enumerator
10733 && abbrev
->tag
!= DW_TAG_subprogram
10734 && abbrev
->tag
!= DW_TAG_lexical_block
10735 && abbrev
->tag
!= DW_TAG_variable
10736 && abbrev
->tag
!= DW_TAG_namespace
10737 && abbrev
->tag
!= DW_TAG_module
10738 && abbrev
->tag
!= DW_TAG_member
)
10740 /* Otherwise we skip to the next sibling, if any. */
10741 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10745 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
10748 /* This two-pass algorithm for processing partial symbols has a
10749 high cost in cache pressure. Thus, handle some simple cases
10750 here which cover the majority of C partial symbols. DIEs
10751 which neither have specification tags in them, nor could have
10752 specification tags elsewhere pointing at them, can simply be
10753 processed and discarded.
10755 This segment is also optional; scan_partial_symbols and
10756 add_partial_symbol will handle these DIEs if we chain
10757 them in normally. When compilers which do not emit large
10758 quantities of duplicate debug information are more common,
10759 this code can probably be removed. */
10761 /* Any complete simple types at the top level (pretty much all
10762 of them, for a language without namespaces), can be processed
10764 if (parent_die
== NULL
10765 && part_die
->has_specification
== 0
10766 && part_die
->is_declaration
== 0
10767 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
10768 || part_die
->tag
== DW_TAG_base_type
10769 || part_die
->tag
== DW_TAG_subrange_type
))
10771 if (building_psymtab
&& part_die
->name
!= NULL
)
10772 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
10773 VAR_DOMAIN
, LOC_TYPEDEF
,
10774 &objfile
->static_psymbols
,
10775 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
10776 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
10780 /* The exception for DW_TAG_typedef with has_children above is
10781 a workaround of GCC PR debug/47510. In the case of this complaint
10782 type_name_no_tag_or_error will error on such types later.
10784 GDB skipped children of DW_TAG_typedef by the shortcut above and then
10785 it could not find the child DIEs referenced later, this is checked
10786 above. In correct DWARF DW_TAG_typedef should have no children. */
10788 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
10789 complaint (&symfile_complaints
,
10790 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
10791 "- DIE at 0x%x [in module %s]"),
10792 part_die
->offset
.sect_off
, objfile
->name
);
10794 /* If we're at the second level, and we're an enumerator, and
10795 our parent has no specification (meaning possibly lives in a
10796 namespace elsewhere), then we can add the partial symbol now
10797 instead of queueing it. */
10798 if (part_die
->tag
== DW_TAG_enumerator
10799 && parent_die
!= NULL
10800 && parent_die
->die_parent
== NULL
10801 && parent_die
->tag
== DW_TAG_enumeration_type
10802 && parent_die
->has_specification
== 0)
10804 if (part_die
->name
== NULL
)
10805 complaint (&symfile_complaints
,
10806 _("malformed enumerator DIE ignored"));
10807 else if (building_psymtab
)
10808 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
10809 VAR_DOMAIN
, LOC_CONST
,
10810 (cu
->language
== language_cplus
10811 || cu
->language
== language_java
)
10812 ? &objfile
->global_psymbols
10813 : &objfile
->static_psymbols
,
10814 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
10816 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
10820 /* We'll save this DIE so link it in. */
10821 part_die
->die_parent
= parent_die
;
10822 part_die
->die_sibling
= NULL
;
10823 part_die
->die_child
= NULL
;
10825 if (last_die
&& last_die
== parent_die
)
10826 last_die
->die_child
= part_die
;
10828 last_die
->die_sibling
= part_die
;
10830 last_die
= part_die
;
10832 if (first_die
== NULL
)
10833 first_die
= part_die
;
10835 /* Maybe add the DIE to the hash table. Not all DIEs that we
10836 find interesting need to be in the hash table, because we
10837 also have the parent/sibling/child chains; only those that we
10838 might refer to by offset later during partial symbol reading.
10840 For now this means things that might have be the target of a
10841 DW_AT_specification, DW_AT_abstract_origin, or
10842 DW_AT_extension. DW_AT_extension will refer only to
10843 namespaces; DW_AT_abstract_origin refers to functions (and
10844 many things under the function DIE, but we do not recurse
10845 into function DIEs during partial symbol reading) and
10846 possibly variables as well; DW_AT_specification refers to
10847 declarations. Declarations ought to have the DW_AT_declaration
10848 flag. It happens that GCC forgets to put it in sometimes, but
10849 only for functions, not for types.
10851 Adding more things than necessary to the hash table is harmless
10852 except for the performance cost. Adding too few will result in
10853 wasted time in find_partial_die, when we reread the compilation
10854 unit with load_all_dies set. */
10857 || abbrev
->tag
== DW_TAG_constant
10858 || abbrev
->tag
== DW_TAG_subprogram
10859 || abbrev
->tag
== DW_TAG_variable
10860 || abbrev
->tag
== DW_TAG_namespace
10861 || part_die
->is_declaration
)
10865 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
10866 part_die
->offset
.sect_off
, INSERT
);
10870 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10871 sizeof (struct partial_die_info
));
10873 /* For some DIEs we want to follow their children (if any). For C
10874 we have no reason to follow the children of structures; for other
10875 languages we have to, so that we can get at method physnames
10876 to infer fully qualified class names, for DW_AT_specification,
10877 and for C++ template arguments. For C++, we also look one level
10878 inside functions to find template arguments (if the name of the
10879 function does not already contain the template arguments).
10881 For Ada, we need to scan the children of subprograms and lexical
10882 blocks as well because Ada allows the definition of nested
10883 entities that could be interesting for the debugger, such as
10884 nested subprograms for instance. */
10885 if (last_die
->has_children
10887 || last_die
->tag
== DW_TAG_namespace
10888 || last_die
->tag
== DW_TAG_module
10889 || last_die
->tag
== DW_TAG_enumeration_type
10890 || (cu
->language
== language_cplus
10891 && last_die
->tag
== DW_TAG_subprogram
10892 && (last_die
->name
== NULL
10893 || strchr (last_die
->name
, '<') == NULL
))
10894 || (cu
->language
!= language_c
10895 && (last_die
->tag
== DW_TAG_class_type
10896 || last_die
->tag
== DW_TAG_interface_type
10897 || last_die
->tag
== DW_TAG_structure_type
10898 || last_die
->tag
== DW_TAG_union_type
))
10899 || (cu
->language
== language_ada
10900 && (last_die
->tag
== DW_TAG_subprogram
10901 || last_die
->tag
== DW_TAG_lexical_block
))))
10904 parent_die
= last_die
;
10908 /* Otherwise we skip to the next sibling, if any. */
10909 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
10911 /* Back to the top, do it again. */
10915 /* Read a minimal amount of information into the minimal die structure. */
10918 read_partial_die (const struct die_reader_specs
*reader
,
10919 struct partial_die_info
*part_die
,
10920 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
10921 gdb_byte
*info_ptr
)
10923 struct dwarf2_cu
*cu
= reader
->cu
;
10924 struct objfile
*objfile
= cu
->objfile
;
10925 gdb_byte
*buffer
= reader
->buffer
;
10927 struct attribute attr
;
10928 int has_low_pc_attr
= 0;
10929 int has_high_pc_attr
= 0;
10930 int high_pc_relative
= 0;
10932 memset (part_die
, 0, sizeof (struct partial_die_info
));
10934 part_die
->offset
.sect_off
= info_ptr
- buffer
;
10936 info_ptr
+= abbrev_len
;
10938 if (abbrev
== NULL
)
10941 part_die
->tag
= abbrev
->tag
;
10942 part_die
->has_children
= abbrev
->has_children
;
10944 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10946 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
10948 /* Store the data if it is of an attribute we want to keep in a
10949 partial symbol table. */
10953 switch (part_die
->tag
)
10955 case DW_TAG_compile_unit
:
10956 case DW_TAG_type_unit
:
10957 /* Compilation units have a DW_AT_name that is a filename, not
10958 a source language identifier. */
10959 case DW_TAG_enumeration_type
:
10960 case DW_TAG_enumerator
:
10961 /* These tags always have simple identifiers already; no need
10962 to canonicalize them. */
10963 part_die
->name
= DW_STRING (&attr
);
10967 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
10968 &objfile
->objfile_obstack
);
10972 case DW_AT_linkage_name
:
10973 case DW_AT_MIPS_linkage_name
:
10974 /* Note that both forms of linkage name might appear. We
10975 assume they will be the same, and we only store the last
10977 if (cu
->language
== language_ada
)
10978 part_die
->name
= DW_STRING (&attr
);
10979 part_die
->linkage_name
= DW_STRING (&attr
);
10982 has_low_pc_attr
= 1;
10983 part_die
->lowpc
= DW_ADDR (&attr
);
10985 case DW_AT_high_pc
:
10986 has_high_pc_attr
= 1;
10987 if (attr
.form
== DW_FORM_addr
10988 || attr
.form
== DW_FORM_GNU_addr_index
)
10989 part_die
->highpc
= DW_ADDR (&attr
);
10992 high_pc_relative
= 1;
10993 part_die
->highpc
= DW_UNSND (&attr
);
10996 case DW_AT_location
:
10997 /* Support the .debug_loc offsets. */
10998 if (attr_form_is_block (&attr
))
11000 part_die
->locdesc
= DW_BLOCK (&attr
);
11002 else if (attr_form_is_section_offset (&attr
))
11004 dwarf2_complex_location_expr_complaint ();
11008 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11009 "partial symbol information");
11012 case DW_AT_external
:
11013 part_die
->is_external
= DW_UNSND (&attr
);
11015 case DW_AT_declaration
:
11016 part_die
->is_declaration
= DW_UNSND (&attr
);
11019 part_die
->has_type
= 1;
11021 case DW_AT_abstract_origin
:
11022 case DW_AT_specification
:
11023 case DW_AT_extension
:
11024 part_die
->has_specification
= 1;
11025 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11027 case DW_AT_sibling
:
11028 /* Ignore absolute siblings, they might point outside of
11029 the current compile unit. */
11030 if (attr
.form
== DW_FORM_ref_addr
)
11031 complaint (&symfile_complaints
,
11032 _("ignoring absolute DW_AT_sibling"));
11034 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11036 case DW_AT_byte_size
:
11037 part_die
->has_byte_size
= 1;
11039 case DW_AT_calling_convention
:
11040 /* DWARF doesn't provide a way to identify a program's source-level
11041 entry point. DW_AT_calling_convention attributes are only meant
11042 to describe functions' calling conventions.
11044 However, because it's a necessary piece of information in
11045 Fortran, and because DW_CC_program is the only piece of debugging
11046 information whose definition refers to a 'main program' at all,
11047 several compilers have begun marking Fortran main programs with
11048 DW_CC_program --- even when those functions use the standard
11049 calling conventions.
11051 So until DWARF specifies a way to provide this information and
11052 compilers pick up the new representation, we'll support this
11054 if (DW_UNSND (&attr
) == DW_CC_program
11055 && cu
->language
== language_fortran
)
11057 set_main_name (part_die
->name
);
11059 /* As this DIE has a static linkage the name would be difficult
11060 to look up later. */
11061 language_of_main
= language_fortran
;
11065 if (DW_UNSND (&attr
) == DW_INL_inlined
11066 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11067 part_die
->may_be_inlined
= 1;
11074 if (high_pc_relative
)
11075 part_die
->highpc
+= part_die
->lowpc
;
11077 if (has_low_pc_attr
&& has_high_pc_attr
)
11079 /* When using the GNU linker, .gnu.linkonce. sections are used to
11080 eliminate duplicate copies of functions and vtables and such.
11081 The linker will arbitrarily choose one and discard the others.
11082 The AT_*_pc values for such functions refer to local labels in
11083 these sections. If the section from that file was discarded, the
11084 labels are not in the output, so the relocs get a value of 0.
11085 If this is a discarded function, mark the pc bounds as invalid,
11086 so that GDB will ignore it. */
11087 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11089 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11091 complaint (&symfile_complaints
,
11092 _("DW_AT_low_pc %s is zero "
11093 "for DIE at 0x%x [in module %s]"),
11094 paddress (gdbarch
, part_die
->lowpc
),
11095 part_die
->offset
.sect_off
, objfile
->name
);
11097 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11098 else if (part_die
->lowpc
>= part_die
->highpc
)
11100 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11102 complaint (&symfile_complaints
,
11103 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11104 "for DIE at 0x%x [in module %s]"),
11105 paddress (gdbarch
, part_die
->lowpc
),
11106 paddress (gdbarch
, part_die
->highpc
),
11107 part_die
->offset
.sect_off
, objfile
->name
);
11110 part_die
->has_pc_info
= 1;
11116 /* Find a cached partial DIE at OFFSET in CU. */
11118 static struct partial_die_info
*
11119 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11121 struct partial_die_info
*lookup_die
= NULL
;
11122 struct partial_die_info part_die
;
11124 part_die
.offset
= offset
;
11125 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11131 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11132 except in the case of .debug_types DIEs which do not reference
11133 outside their CU (they do however referencing other types via
11134 DW_FORM_ref_sig8). */
11136 static struct partial_die_info
*
11137 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11139 struct objfile
*objfile
= cu
->objfile
;
11140 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11141 struct partial_die_info
*pd
= NULL
;
11143 if (offset_in_cu_p (&cu
->header
, offset
))
11145 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11148 /* We missed recording what we needed.
11149 Load all dies and try again. */
11150 per_cu
= cu
->per_cu
;
11154 /* TUs don't reference other CUs/TUs (except via type signatures). */
11155 if (cu
->per_cu
->is_debug_types
)
11157 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11158 " external reference to offset 0x%lx [in module %s].\n"),
11159 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11160 bfd_get_filename (objfile
->obfd
));
11162 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11164 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11165 load_partial_comp_unit (per_cu
);
11167 per_cu
->cu
->last_used
= 0;
11168 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11171 /* If we didn't find it, and not all dies have been loaded,
11172 load them all and try again. */
11174 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11176 /* FIXME: The testsuite doesn't trigger this code path.
11177 http://sourceware.org/bugzilla/show_bug.cgi?id=13961 */
11179 free_one_cached_comp_unit (per_cu
);
11180 per_cu
->load_all_dies
= 1;
11181 load_partial_comp_unit (per_cu
);
11183 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11187 internal_error (__FILE__
, __LINE__
,
11188 _("could not find partial DIE 0x%x "
11189 "in cache [from module %s]\n"),
11190 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11194 /* See if we can figure out if the class lives in a namespace. We do
11195 this by looking for a member function; its demangled name will
11196 contain namespace info, if there is any. */
11199 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11200 struct dwarf2_cu
*cu
)
11202 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11203 what template types look like, because the demangler
11204 frequently doesn't give the same name as the debug info. We
11205 could fix this by only using the demangled name to get the
11206 prefix (but see comment in read_structure_type). */
11208 struct partial_die_info
*real_pdi
;
11209 struct partial_die_info
*child_pdi
;
11211 /* If this DIE (this DIE's specification, if any) has a parent, then
11212 we should not do this. We'll prepend the parent's fully qualified
11213 name when we create the partial symbol. */
11215 real_pdi
= struct_pdi
;
11216 while (real_pdi
->has_specification
)
11217 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11219 if (real_pdi
->die_parent
!= NULL
)
11222 for (child_pdi
= struct_pdi
->die_child
;
11224 child_pdi
= child_pdi
->die_sibling
)
11226 if (child_pdi
->tag
== DW_TAG_subprogram
11227 && child_pdi
->linkage_name
!= NULL
)
11229 char *actual_class_name
11230 = language_class_name_from_physname (cu
->language_defn
,
11231 child_pdi
->linkage_name
);
11232 if (actual_class_name
!= NULL
)
11235 = obsavestring (actual_class_name
,
11236 strlen (actual_class_name
),
11237 &cu
->objfile
->objfile_obstack
);
11238 xfree (actual_class_name
);
11245 /* Adjust PART_DIE before generating a symbol for it. This function
11246 may set the is_external flag or change the DIE's name. */
11249 fixup_partial_die (struct partial_die_info
*part_die
,
11250 struct dwarf2_cu
*cu
)
11252 /* Once we've fixed up a die, there's no point in doing so again.
11253 This also avoids a memory leak if we were to call
11254 guess_partial_die_structure_name multiple times. */
11255 if (part_die
->fixup_called
)
11258 /* If we found a reference attribute and the DIE has no name, try
11259 to find a name in the referred to DIE. */
11261 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11263 struct partial_die_info
*spec_die
;
11265 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11267 fixup_partial_die (spec_die
, cu
);
11269 if (spec_die
->name
)
11271 part_die
->name
= spec_die
->name
;
11273 /* Copy DW_AT_external attribute if it is set. */
11274 if (spec_die
->is_external
)
11275 part_die
->is_external
= spec_die
->is_external
;
11279 /* Set default names for some unnamed DIEs. */
11281 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11282 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11284 /* If there is no parent die to provide a namespace, and there are
11285 children, see if we can determine the namespace from their linkage
11287 if (cu
->language
== language_cplus
11288 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11289 && part_die
->die_parent
== NULL
11290 && part_die
->has_children
11291 && (part_die
->tag
== DW_TAG_class_type
11292 || part_die
->tag
== DW_TAG_structure_type
11293 || part_die
->tag
== DW_TAG_union_type
))
11294 guess_partial_die_structure_name (part_die
, cu
);
11296 /* GCC might emit a nameless struct or union that has a linkage
11297 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11298 if (part_die
->name
== NULL
11299 && (part_die
->tag
== DW_TAG_class_type
11300 || part_die
->tag
== DW_TAG_interface_type
11301 || part_die
->tag
== DW_TAG_structure_type
11302 || part_die
->tag
== DW_TAG_union_type
)
11303 && part_die
->linkage_name
!= NULL
)
11307 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11312 /* Strip any leading namespaces/classes, keep only the base name.
11313 DW_AT_name for named DIEs does not contain the prefixes. */
11314 base
= strrchr (demangled
, ':');
11315 if (base
&& base
> demangled
&& base
[-1] == ':')
11320 part_die
->name
= obsavestring (base
, strlen (base
),
11321 &cu
->objfile
->objfile_obstack
);
11326 part_die
->fixup_called
= 1;
11329 /* Read an attribute value described by an attribute form. */
11332 read_attribute_value (const struct die_reader_specs
*reader
,
11333 struct attribute
*attr
, unsigned form
,
11334 gdb_byte
*info_ptr
)
11336 struct dwarf2_cu
*cu
= reader
->cu
;
11337 bfd
*abfd
= reader
->abfd
;
11338 struct comp_unit_head
*cu_header
= &cu
->header
;
11339 unsigned int bytes_read
;
11340 struct dwarf_block
*blk
;
11345 case DW_FORM_ref_addr
:
11346 if (cu
->header
.version
== 2)
11347 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11349 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11350 &cu
->header
, &bytes_read
);
11351 info_ptr
+= bytes_read
;
11354 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11355 info_ptr
+= bytes_read
;
11357 case DW_FORM_block2
:
11358 blk
= dwarf_alloc_block (cu
);
11359 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11361 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11362 info_ptr
+= blk
->size
;
11363 DW_BLOCK (attr
) = blk
;
11365 case DW_FORM_block4
:
11366 blk
= dwarf_alloc_block (cu
);
11367 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11369 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11370 info_ptr
+= blk
->size
;
11371 DW_BLOCK (attr
) = blk
;
11373 case DW_FORM_data2
:
11374 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11377 case DW_FORM_data4
:
11378 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11381 case DW_FORM_data8
:
11382 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11385 case DW_FORM_sec_offset
:
11386 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11387 info_ptr
+= bytes_read
;
11389 case DW_FORM_string
:
11390 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11391 DW_STRING_IS_CANONICAL (attr
) = 0;
11392 info_ptr
+= bytes_read
;
11395 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11397 DW_STRING_IS_CANONICAL (attr
) = 0;
11398 info_ptr
+= bytes_read
;
11400 case DW_FORM_exprloc
:
11401 case DW_FORM_block
:
11402 blk
= dwarf_alloc_block (cu
);
11403 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11404 info_ptr
+= bytes_read
;
11405 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11406 info_ptr
+= blk
->size
;
11407 DW_BLOCK (attr
) = blk
;
11409 case DW_FORM_block1
:
11410 blk
= dwarf_alloc_block (cu
);
11411 blk
->size
= read_1_byte (abfd
, info_ptr
);
11413 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11414 info_ptr
+= blk
->size
;
11415 DW_BLOCK (attr
) = blk
;
11417 case DW_FORM_data1
:
11418 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11422 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11425 case DW_FORM_flag_present
:
11426 DW_UNSND (attr
) = 1;
11428 case DW_FORM_sdata
:
11429 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11430 info_ptr
+= bytes_read
;
11432 case DW_FORM_udata
:
11433 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11434 info_ptr
+= bytes_read
;
11437 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11438 + read_1_byte (abfd
, info_ptr
));
11442 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11443 + read_2_bytes (abfd
, info_ptr
));
11447 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11448 + read_4_bytes (abfd
, info_ptr
));
11452 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11453 + read_8_bytes (abfd
, info_ptr
));
11456 case DW_FORM_ref_sig8
:
11457 /* Convert the signature to something we can record in DW_UNSND
11459 NOTE: This is NULL if the type wasn't found. */
11460 DW_SIGNATURED_TYPE (attr
) =
11461 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11464 case DW_FORM_ref_udata
:
11465 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11466 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11467 info_ptr
+= bytes_read
;
11469 case DW_FORM_indirect
:
11470 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11471 info_ptr
+= bytes_read
;
11472 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11474 case DW_FORM_GNU_addr_index
:
11475 if (reader
->dwo_file
== NULL
)
11477 /* For now flag a hard error.
11478 Later we can turn this into a complaint. */
11479 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11480 dwarf_form_name (form
),
11481 bfd_get_filename (abfd
));
11483 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11484 info_ptr
+= bytes_read
;
11486 case DW_FORM_GNU_str_index
:
11487 if (reader
->dwo_file
== NULL
)
11489 /* For now flag a hard error.
11490 Later we can turn this into a complaint if warranted. */
11491 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11492 dwarf_form_name (form
),
11493 bfd_get_filename (abfd
));
11496 ULONGEST str_index
=
11497 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11499 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11500 DW_STRING_IS_CANONICAL (attr
) = 0;
11501 info_ptr
+= bytes_read
;
11505 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11506 dwarf_form_name (form
),
11507 bfd_get_filename (abfd
));
11510 /* We have seen instances where the compiler tried to emit a byte
11511 size attribute of -1 which ended up being encoded as an unsigned
11512 0xffffffff. Although 0xffffffff is technically a valid size value,
11513 an object of this size seems pretty unlikely so we can relatively
11514 safely treat these cases as if the size attribute was invalid and
11515 treat them as zero by default. */
11516 if (attr
->name
== DW_AT_byte_size
11517 && form
== DW_FORM_data4
11518 && DW_UNSND (attr
) >= 0xffffffff)
11521 (&symfile_complaints
,
11522 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11523 hex_string (DW_UNSND (attr
)));
11524 DW_UNSND (attr
) = 0;
11530 /* Read an attribute described by an abbreviated attribute. */
11533 read_attribute (const struct die_reader_specs
*reader
,
11534 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11535 gdb_byte
*info_ptr
)
11537 attr
->name
= abbrev
->name
;
11538 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11541 /* Read dwarf information from a buffer. */
11543 static unsigned int
11544 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11546 return bfd_get_8 (abfd
, buf
);
11550 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11552 return bfd_get_signed_8 (abfd
, buf
);
11555 static unsigned int
11556 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11558 return bfd_get_16 (abfd
, buf
);
11562 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11564 return bfd_get_signed_16 (abfd
, buf
);
11567 static unsigned int
11568 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11570 return bfd_get_32 (abfd
, buf
);
11574 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11576 return bfd_get_signed_32 (abfd
, buf
);
11580 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
11582 return bfd_get_64 (abfd
, buf
);
11586 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
11587 unsigned int *bytes_read
)
11589 struct comp_unit_head
*cu_header
= &cu
->header
;
11590 CORE_ADDR retval
= 0;
11592 if (cu_header
->signed_addr_p
)
11594 switch (cu_header
->addr_size
)
11597 retval
= bfd_get_signed_16 (abfd
, buf
);
11600 retval
= bfd_get_signed_32 (abfd
, buf
);
11603 retval
= bfd_get_signed_64 (abfd
, buf
);
11606 internal_error (__FILE__
, __LINE__
,
11607 _("read_address: bad switch, signed [in module %s]"),
11608 bfd_get_filename (abfd
));
11613 switch (cu_header
->addr_size
)
11616 retval
= bfd_get_16 (abfd
, buf
);
11619 retval
= bfd_get_32 (abfd
, buf
);
11622 retval
= bfd_get_64 (abfd
, buf
);
11625 internal_error (__FILE__
, __LINE__
,
11626 _("read_address: bad switch, "
11627 "unsigned [in module %s]"),
11628 bfd_get_filename (abfd
));
11632 *bytes_read
= cu_header
->addr_size
;
11636 /* Read the initial length from a section. The (draft) DWARF 3
11637 specification allows the initial length to take up either 4 bytes
11638 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
11639 bytes describe the length and all offsets will be 8 bytes in length
11642 An older, non-standard 64-bit format is also handled by this
11643 function. The older format in question stores the initial length
11644 as an 8-byte quantity without an escape value. Lengths greater
11645 than 2^32 aren't very common which means that the initial 4 bytes
11646 is almost always zero. Since a length value of zero doesn't make
11647 sense for the 32-bit format, this initial zero can be considered to
11648 be an escape value which indicates the presence of the older 64-bit
11649 format. As written, the code can't detect (old format) lengths
11650 greater than 4GB. If it becomes necessary to handle lengths
11651 somewhat larger than 4GB, we could allow other small values (such
11652 as the non-sensical values of 1, 2, and 3) to also be used as
11653 escape values indicating the presence of the old format.
11655 The value returned via bytes_read should be used to increment the
11656 relevant pointer after calling read_initial_length().
11658 [ Note: read_initial_length() and read_offset() are based on the
11659 document entitled "DWARF Debugging Information Format", revision
11660 3, draft 8, dated November 19, 2001. This document was obtained
11663 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
11665 This document is only a draft and is subject to change. (So beware.)
11667 Details regarding the older, non-standard 64-bit format were
11668 determined empirically by examining 64-bit ELF files produced by
11669 the SGI toolchain on an IRIX 6.5 machine.
11671 - Kevin, July 16, 2002
11675 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
11677 LONGEST length
= bfd_get_32 (abfd
, buf
);
11679 if (length
== 0xffffffff)
11681 length
= bfd_get_64 (abfd
, buf
+ 4);
11684 else if (length
== 0)
11686 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
11687 length
= bfd_get_64 (abfd
, buf
);
11698 /* Cover function for read_initial_length.
11699 Returns the length of the object at BUF, and stores the size of the
11700 initial length in *BYTES_READ and stores the size that offsets will be in
11702 If the initial length size is not equivalent to that specified in
11703 CU_HEADER then issue a complaint.
11704 This is useful when reading non-comp-unit headers. */
11707 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
11708 const struct comp_unit_head
*cu_header
,
11709 unsigned int *bytes_read
,
11710 unsigned int *offset_size
)
11712 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
11714 gdb_assert (cu_header
->initial_length_size
== 4
11715 || cu_header
->initial_length_size
== 8
11716 || cu_header
->initial_length_size
== 12);
11718 if (cu_header
->initial_length_size
!= *bytes_read
)
11719 complaint (&symfile_complaints
,
11720 _("intermixed 32-bit and 64-bit DWARF sections"));
11722 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
11726 /* Read an offset from the data stream. The size of the offset is
11727 given by cu_header->offset_size. */
11730 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
11731 unsigned int *bytes_read
)
11733 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
11735 *bytes_read
= cu_header
->offset_size
;
11739 /* Read an offset from the data stream. */
11742 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
11744 LONGEST retval
= 0;
11746 switch (offset_size
)
11749 retval
= bfd_get_32 (abfd
, buf
);
11752 retval
= bfd_get_64 (abfd
, buf
);
11755 internal_error (__FILE__
, __LINE__
,
11756 _("read_offset_1: bad switch [in module %s]"),
11757 bfd_get_filename (abfd
));
11764 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
11766 /* If the size of a host char is 8 bits, we can return a pointer
11767 to the buffer, otherwise we have to copy the data to a buffer
11768 allocated on the temporary obstack. */
11769 gdb_assert (HOST_CHAR_BIT
== 8);
11774 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11776 /* If the size of a host char is 8 bits, we can return a pointer
11777 to the string, otherwise we have to copy the string to a buffer
11778 allocated on the temporary obstack. */
11779 gdb_assert (HOST_CHAR_BIT
== 8);
11782 *bytes_read_ptr
= 1;
11785 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
11786 return (char *) buf
;
11790 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
11792 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
11793 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
11794 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
11795 bfd_get_filename (abfd
));
11796 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
11797 error (_("DW_FORM_strp pointing outside of "
11798 ".debug_str section [in module %s]"),
11799 bfd_get_filename (abfd
));
11800 gdb_assert (HOST_CHAR_BIT
== 8);
11801 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
11803 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
11807 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
11808 const struct comp_unit_head
*cu_header
,
11809 unsigned int *bytes_read_ptr
)
11811 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
11813 return read_indirect_string_at_offset (abfd
, str_offset
);
11817 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11820 unsigned int num_read
;
11822 unsigned char byte
;
11830 byte
= bfd_get_8 (abfd
, buf
);
11833 result
|= ((ULONGEST
) (byte
& 127) << shift
);
11834 if ((byte
& 128) == 0)
11840 *bytes_read_ptr
= num_read
;
11845 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11848 int i
, shift
, num_read
;
11849 unsigned char byte
;
11857 byte
= bfd_get_8 (abfd
, buf
);
11860 result
|= ((LONGEST
) (byte
& 127) << shift
);
11862 if ((byte
& 128) == 0)
11867 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
11868 result
|= -(((LONGEST
) 1) << shift
);
11869 *bytes_read_ptr
= num_read
;
11873 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
11874 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
11875 ADDR_SIZE is the size of addresses from the CU header. */
11878 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
11880 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11881 bfd
*abfd
= objfile
->obfd
;
11882 const gdb_byte
*info_ptr
;
11884 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
11885 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
11886 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
11888 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
11889 error (_("DW_FORM_addr_index pointing outside of "
11890 ".debug_addr section [in module %s]"),
11892 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
11893 + addr_base
+ addr_index
* addr_size
);
11894 if (addr_size
== 4)
11895 return bfd_get_32 (abfd
, info_ptr
);
11897 return bfd_get_64 (abfd
, info_ptr
);
11900 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
11903 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
11905 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
11908 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
11911 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
11912 unsigned int *bytes_read
)
11914 bfd
*abfd
= cu
->objfile
->obfd
;
11915 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
11917 return read_addr_index (cu
, addr_index
);
11920 /* Data structure to pass results from dwarf2_read_addr_index_reader
11921 back to dwarf2_read_addr_index. */
11923 struct dwarf2_read_addr_index_data
11925 ULONGEST addr_base
;
11929 /* die_reader_func for dwarf2_read_addr_index. */
11932 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
11933 gdb_byte
*info_ptr
,
11934 struct die_info
*comp_unit_die
,
11938 struct dwarf2_cu
*cu
= reader
->cu
;
11939 struct dwarf2_read_addr_index_data
*aidata
=
11940 (struct dwarf2_read_addr_index_data
*) data
;
11942 aidata
->addr_base
= cu
->addr_base
;
11943 aidata
->addr_size
= cu
->header
.addr_size
;
11946 /* Given an index in .debug_addr, fetch the value.
11947 NOTE: This can be called during dwarf expression evaluation,
11948 long after the debug information has been read, and thus per_cu->cu
11949 may no longer exist. */
11952 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
11953 unsigned int addr_index
)
11955 struct objfile
*objfile
= per_cu
->objfile
;
11956 struct dwarf2_cu
*cu
= per_cu
->cu
;
11957 ULONGEST addr_base
;
11960 /* This is intended to be called from outside this file. */
11961 dw2_setup (objfile
);
11963 /* We need addr_base and addr_size.
11964 If we don't have PER_CU->cu, we have to get it.
11965 Nasty, but the alternative is storing the needed info in PER_CU,
11966 which at this point doesn't seem justified: it's not clear how frequently
11967 it would get used and it would increase the size of every PER_CU.
11968 Entry points like dwarf2_per_cu_addr_size do a similar thing
11969 so we're not in uncharted territory here.
11970 Alas we need to be a bit more complicated as addr_base is contained
11973 We don't need to read the entire CU(/TU).
11974 We just need the header and top level die.
11975 IWBN to use the aging mechanism to let us lazily later discard the CU.
11976 See however init_cutu_and_read_dies_simple. */
11980 addr_base
= cu
->addr_base
;
11981 addr_size
= cu
->header
.addr_size
;
11985 struct dwarf2_read_addr_index_data aidata
;
11987 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
11989 addr_base
= aidata
.addr_base
;
11990 addr_size
= aidata
.addr_size
;
11993 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
11996 /* Given a DW_AT_str_index, fetch the string. */
11999 read_str_index (const struct die_reader_specs
*reader
,
12000 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12002 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12003 const char *dwo_name
= objfile
->name
;
12004 bfd
*abfd
= objfile
->obfd
;
12005 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12006 gdb_byte
*info_ptr
;
12007 ULONGEST str_offset
;
12009 dwarf2_read_section (objfile
, §ions
->str
);
12010 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12011 if (sections
->str
.buffer
== NULL
)
12012 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12013 " in CU at offset 0x%lx [in module %s]"),
12014 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12015 if (sections
->str_offsets
.buffer
== NULL
)
12016 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12017 " in CU at offset 0x%lx [in module %s]"),
12018 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12019 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12020 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12021 " section in CU at offset 0x%lx [in module %s]"),
12022 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12023 info_ptr
= (sections
->str_offsets
.buffer
12024 + str_index
* cu
->header
.offset_size
);
12025 if (cu
->header
.offset_size
== 4)
12026 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12028 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12029 if (str_offset
>= sections
->str
.size
)
12030 error (_("Offset from DW_FORM_str_index pointing outside of"
12031 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12032 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12033 return (char *) (sections
->str
.buffer
+ str_offset
);
12036 /* Return a pointer to just past the end of an LEB128 number in BUF. */
12039 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
12045 byte
= bfd_get_8 (abfd
, buf
);
12047 if ((byte
& 128) == 0)
12052 /* Return the length of an LEB128 number in BUF. */
12055 leb128_size (const gdb_byte
*buf
)
12057 const gdb_byte
*begin
= buf
;
12063 if ((byte
& 128) == 0)
12064 return buf
- begin
;
12069 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12076 cu
->language
= language_c
;
12078 case DW_LANG_C_plus_plus
:
12079 cu
->language
= language_cplus
;
12082 cu
->language
= language_d
;
12084 case DW_LANG_Fortran77
:
12085 case DW_LANG_Fortran90
:
12086 case DW_LANG_Fortran95
:
12087 cu
->language
= language_fortran
;
12090 cu
->language
= language_go
;
12092 case DW_LANG_Mips_Assembler
:
12093 cu
->language
= language_asm
;
12096 cu
->language
= language_java
;
12098 case DW_LANG_Ada83
:
12099 case DW_LANG_Ada95
:
12100 cu
->language
= language_ada
;
12102 case DW_LANG_Modula2
:
12103 cu
->language
= language_m2
;
12105 case DW_LANG_Pascal83
:
12106 cu
->language
= language_pascal
;
12109 cu
->language
= language_objc
;
12111 case DW_LANG_Cobol74
:
12112 case DW_LANG_Cobol85
:
12114 cu
->language
= language_minimal
;
12117 cu
->language_defn
= language_def (cu
->language
);
12120 /* Return the named attribute or NULL if not there. */
12122 static struct attribute
*
12123 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12128 struct attribute
*spec
= NULL
;
12130 for (i
= 0; i
< die
->num_attrs
; ++i
)
12132 if (die
->attrs
[i
].name
== name
)
12133 return &die
->attrs
[i
];
12134 if (die
->attrs
[i
].name
== DW_AT_specification
12135 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12136 spec
= &die
->attrs
[i
];
12142 die
= follow_die_ref (die
, spec
, &cu
);
12148 /* Return the named attribute or NULL if not there,
12149 but do not follow DW_AT_specification, etc.
12150 This is for use in contexts where we're reading .debug_types dies.
12151 Following DW_AT_specification, DW_AT_abstract_origin will take us
12152 back up the chain, and we want to go down. */
12154 static struct attribute
*
12155 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12156 struct dwarf2_cu
*cu
)
12160 for (i
= 0; i
< die
->num_attrs
; ++i
)
12161 if (die
->attrs
[i
].name
== name
)
12162 return &die
->attrs
[i
];
12167 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12168 and holds a non-zero value. This function should only be used for
12169 DW_FORM_flag or DW_FORM_flag_present attributes. */
12172 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12174 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12176 return (attr
&& DW_UNSND (attr
));
12180 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12182 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12183 which value is non-zero. However, we have to be careful with
12184 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12185 (via dwarf2_flag_true_p) follows this attribute. So we may
12186 end up accidently finding a declaration attribute that belongs
12187 to a different DIE referenced by the specification attribute,
12188 even though the given DIE does not have a declaration attribute. */
12189 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12190 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12193 /* Return the die giving the specification for DIE, if there is
12194 one. *SPEC_CU is the CU containing DIE on input, and the CU
12195 containing the return value on output. If there is no
12196 specification, but there is an abstract origin, that is
12199 static struct die_info
*
12200 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12202 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12205 if (spec_attr
== NULL
)
12206 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12208 if (spec_attr
== NULL
)
12211 return follow_die_ref (die
, spec_attr
, spec_cu
);
12214 /* Free the line_header structure *LH, and any arrays and strings it
12216 NOTE: This is also used as a "cleanup" function. */
12219 free_line_header (struct line_header
*lh
)
12221 if (lh
->standard_opcode_lengths
)
12222 xfree (lh
->standard_opcode_lengths
);
12224 /* Remember that all the lh->file_names[i].name pointers are
12225 pointers into debug_line_buffer, and don't need to be freed. */
12226 if (lh
->file_names
)
12227 xfree (lh
->file_names
);
12229 /* Similarly for the include directory names. */
12230 if (lh
->include_dirs
)
12231 xfree (lh
->include_dirs
);
12236 /* Add an entry to LH's include directory table. */
12239 add_include_dir (struct line_header
*lh
, char *include_dir
)
12241 /* Grow the array if necessary. */
12242 if (lh
->include_dirs_size
== 0)
12244 lh
->include_dirs_size
= 1; /* for testing */
12245 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12246 * sizeof (*lh
->include_dirs
));
12248 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12250 lh
->include_dirs_size
*= 2;
12251 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12252 (lh
->include_dirs_size
12253 * sizeof (*lh
->include_dirs
)));
12256 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12259 /* Add an entry to LH's file name table. */
12262 add_file_name (struct line_header
*lh
,
12264 unsigned int dir_index
,
12265 unsigned int mod_time
,
12266 unsigned int length
)
12268 struct file_entry
*fe
;
12270 /* Grow the array if necessary. */
12271 if (lh
->file_names_size
== 0)
12273 lh
->file_names_size
= 1; /* for testing */
12274 lh
->file_names
= xmalloc (lh
->file_names_size
12275 * sizeof (*lh
->file_names
));
12277 else if (lh
->num_file_names
>= lh
->file_names_size
)
12279 lh
->file_names_size
*= 2;
12280 lh
->file_names
= xrealloc (lh
->file_names
,
12281 (lh
->file_names_size
12282 * sizeof (*lh
->file_names
)));
12285 fe
= &lh
->file_names
[lh
->num_file_names
++];
12287 fe
->dir_index
= dir_index
;
12288 fe
->mod_time
= mod_time
;
12289 fe
->length
= length
;
12290 fe
->included_p
= 0;
12294 /* Read the statement program header starting at OFFSET in
12295 .debug_line, or .debug_line.dwo. Return a pointer
12296 to a struct line_header, allocated using xmalloc.
12298 NOTE: the strings in the include directory and file name tables of
12299 the returned object point into the dwarf line section buffer,
12300 and must not be freed. */
12302 static struct line_header
*
12303 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12305 struct cleanup
*back_to
;
12306 struct line_header
*lh
;
12307 gdb_byte
*line_ptr
;
12308 unsigned int bytes_read
, offset_size
;
12310 char *cur_dir
, *cur_file
;
12311 struct dwarf2_section_info
*section
;
12314 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12316 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12317 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12319 section
= &dwarf2_per_objfile
->line
;
12320 abfd
= section
->asection
->owner
;
12322 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12323 if (section
->buffer
== NULL
)
12325 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12326 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12328 complaint (&symfile_complaints
, _("missing .debug_line section"));
12332 /* Make sure that at least there's room for the total_length field.
12333 That could be 12 bytes long, but we're just going to fudge that. */
12334 if (offset
+ 4 >= section
->size
)
12336 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12340 lh
= xmalloc (sizeof (*lh
));
12341 memset (lh
, 0, sizeof (*lh
));
12342 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12345 line_ptr
= section
->buffer
+ offset
;
12347 /* Read in the header. */
12349 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12350 &bytes_read
, &offset_size
);
12351 line_ptr
+= bytes_read
;
12352 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12354 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12357 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12358 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12360 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12361 line_ptr
+= offset_size
;
12362 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12364 if (lh
->version
>= 4)
12366 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12370 lh
->maximum_ops_per_instruction
= 1;
12372 if (lh
->maximum_ops_per_instruction
== 0)
12374 lh
->maximum_ops_per_instruction
= 1;
12375 complaint (&symfile_complaints
,
12376 _("invalid maximum_ops_per_instruction "
12377 "in `.debug_line' section"));
12380 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12382 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12384 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12386 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12388 lh
->standard_opcode_lengths
12389 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12391 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12392 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12394 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12398 /* Read directory table. */
12399 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12401 line_ptr
+= bytes_read
;
12402 add_include_dir (lh
, cur_dir
);
12404 line_ptr
+= bytes_read
;
12406 /* Read file name table. */
12407 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12409 unsigned int dir_index
, mod_time
, length
;
12411 line_ptr
+= bytes_read
;
12412 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12413 line_ptr
+= bytes_read
;
12414 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12415 line_ptr
+= bytes_read
;
12416 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12417 line_ptr
+= bytes_read
;
12419 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12421 line_ptr
+= bytes_read
;
12422 lh
->statement_program_start
= line_ptr
;
12424 if (line_ptr
> (section
->buffer
+ section
->size
))
12425 complaint (&symfile_complaints
,
12426 _("line number info header doesn't "
12427 "fit in `.debug_line' section"));
12429 discard_cleanups (back_to
);
12433 /* Subroutine of dwarf_decode_lines to simplify it.
12434 Return the file name of the psymtab for included file FILE_INDEX
12435 in line header LH of PST.
12436 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12437 If space for the result is malloc'd, it will be freed by a cleanup.
12438 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12441 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12442 const struct partial_symtab
*pst
,
12443 const char *comp_dir
)
12445 const struct file_entry fe
= lh
->file_names
[file_index
];
12446 char *include_name
= fe
.name
;
12447 char *include_name_to_compare
= include_name
;
12448 char *dir_name
= NULL
;
12449 const char *pst_filename
;
12450 char *copied_name
= NULL
;
12454 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12456 if (!IS_ABSOLUTE_PATH (include_name
)
12457 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12459 /* Avoid creating a duplicate psymtab for PST.
12460 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12461 Before we do the comparison, however, we need to account
12462 for DIR_NAME and COMP_DIR.
12463 First prepend dir_name (if non-NULL). If we still don't
12464 have an absolute path prepend comp_dir (if non-NULL).
12465 However, the directory we record in the include-file's
12466 psymtab does not contain COMP_DIR (to match the
12467 corresponding symtab(s)).
12472 bash$ gcc -g ./hello.c
12473 include_name = "hello.c"
12475 DW_AT_comp_dir = comp_dir = "/tmp"
12476 DW_AT_name = "./hello.c" */
12478 if (dir_name
!= NULL
)
12480 include_name
= concat (dir_name
, SLASH_STRING
,
12481 include_name
, (char *)NULL
);
12482 include_name_to_compare
= include_name
;
12483 make_cleanup (xfree
, include_name
);
12485 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12487 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12488 include_name
, (char *)NULL
);
12492 pst_filename
= pst
->filename
;
12493 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12495 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12496 pst_filename
, (char *)NULL
);
12497 pst_filename
= copied_name
;
12500 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12502 if (include_name_to_compare
!= include_name
)
12503 xfree (include_name_to_compare
);
12504 if (copied_name
!= NULL
)
12505 xfree (copied_name
);
12509 return include_name
;
12512 /* Ignore this record_line request. */
12515 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12520 /* Subroutine of dwarf_decode_lines to simplify it.
12521 Process the line number information in LH. */
12524 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12525 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12527 gdb_byte
*line_ptr
, *extended_end
;
12528 gdb_byte
*line_end
;
12529 unsigned int bytes_read
, extended_len
;
12530 unsigned char op_code
, extended_op
, adj_opcode
;
12531 CORE_ADDR baseaddr
;
12532 struct objfile
*objfile
= cu
->objfile
;
12533 bfd
*abfd
= objfile
->obfd
;
12534 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12535 const int decode_for_pst_p
= (pst
!= NULL
);
12536 struct subfile
*last_subfile
= NULL
;
12537 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12540 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12542 line_ptr
= lh
->statement_program_start
;
12543 line_end
= lh
->statement_program_end
;
12545 /* Read the statement sequences until there's nothing left. */
12546 while (line_ptr
< line_end
)
12548 /* state machine registers */
12549 CORE_ADDR address
= 0;
12550 unsigned int file
= 1;
12551 unsigned int line
= 1;
12552 unsigned int column
= 0;
12553 int is_stmt
= lh
->default_is_stmt
;
12554 int basic_block
= 0;
12555 int end_sequence
= 0;
12557 unsigned char op_index
= 0;
12559 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12561 /* Start a subfile for the current file of the state machine. */
12562 /* lh->include_dirs and lh->file_names are 0-based, but the
12563 directory and file name numbers in the statement program
12565 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12569 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12571 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12574 /* Decode the table. */
12575 while (!end_sequence
)
12577 op_code
= read_1_byte (abfd
, line_ptr
);
12579 if (line_ptr
> line_end
)
12581 dwarf2_debug_line_missing_end_sequence_complaint ();
12585 if (op_code
>= lh
->opcode_base
)
12587 /* Special operand. */
12588 adj_opcode
= op_code
- lh
->opcode_base
;
12589 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
12590 / lh
->maximum_ops_per_instruction
)
12591 * lh
->minimum_instruction_length
);
12592 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
12593 % lh
->maximum_ops_per_instruction
);
12594 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
12595 if (lh
->num_file_names
< file
|| file
== 0)
12596 dwarf2_debug_line_missing_file_complaint ();
12597 /* For now we ignore lines not starting on an
12598 instruction boundary. */
12599 else if (op_index
== 0)
12601 lh
->file_names
[file
- 1].included_p
= 1;
12602 if (!decode_for_pst_p
&& is_stmt
)
12604 if (last_subfile
!= current_subfile
)
12606 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12608 (*p_record_line
) (last_subfile
, 0, addr
);
12609 last_subfile
= current_subfile
;
12611 /* Append row to matrix using current values. */
12612 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12613 (*p_record_line
) (current_subfile
, line
, addr
);
12618 else switch (op_code
)
12620 case DW_LNS_extended_op
:
12621 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
12623 line_ptr
+= bytes_read
;
12624 extended_end
= line_ptr
+ extended_len
;
12625 extended_op
= read_1_byte (abfd
, line_ptr
);
12627 switch (extended_op
)
12629 case DW_LNE_end_sequence
:
12630 p_record_line
= record_line
;
12633 case DW_LNE_set_address
:
12634 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
12636 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12638 /* This line table is for a function which has been
12639 GCd by the linker. Ignore it. PR gdb/12528 */
12642 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
12644 complaint (&symfile_complaints
,
12645 _(".debug_line address at offset 0x%lx is 0 "
12647 line_offset
, objfile
->name
);
12648 p_record_line
= noop_record_line
;
12652 line_ptr
+= bytes_read
;
12653 address
+= baseaddr
;
12655 case DW_LNE_define_file
:
12658 unsigned int dir_index
, mod_time
, length
;
12660 cur_file
= read_direct_string (abfd
, line_ptr
,
12662 line_ptr
+= bytes_read
;
12664 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12665 line_ptr
+= bytes_read
;
12667 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12668 line_ptr
+= bytes_read
;
12670 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12671 line_ptr
+= bytes_read
;
12672 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12675 case DW_LNE_set_discriminator
:
12676 /* The discriminator is not interesting to the debugger;
12678 line_ptr
= extended_end
;
12681 complaint (&symfile_complaints
,
12682 _("mangled .debug_line section"));
12685 /* Make sure that we parsed the extended op correctly. If e.g.
12686 we expected a different address size than the producer used,
12687 we may have read the wrong number of bytes. */
12688 if (line_ptr
!= extended_end
)
12690 complaint (&symfile_complaints
,
12691 _("mangled .debug_line section"));
12696 if (lh
->num_file_names
< file
|| file
== 0)
12697 dwarf2_debug_line_missing_file_complaint ();
12700 lh
->file_names
[file
- 1].included_p
= 1;
12701 if (!decode_for_pst_p
&& is_stmt
)
12703 if (last_subfile
!= current_subfile
)
12705 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12707 (*p_record_line
) (last_subfile
, 0, addr
);
12708 last_subfile
= current_subfile
;
12710 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12711 (*p_record_line
) (current_subfile
, line
, addr
);
12716 case DW_LNS_advance_pc
:
12719 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12721 address
+= (((op_index
+ adjust
)
12722 / lh
->maximum_ops_per_instruction
)
12723 * lh
->minimum_instruction_length
);
12724 op_index
= ((op_index
+ adjust
)
12725 % lh
->maximum_ops_per_instruction
);
12726 line_ptr
+= bytes_read
;
12729 case DW_LNS_advance_line
:
12730 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
12731 line_ptr
+= bytes_read
;
12733 case DW_LNS_set_file
:
12735 /* The arrays lh->include_dirs and lh->file_names are
12736 0-based, but the directory and file name numbers in
12737 the statement program are 1-based. */
12738 struct file_entry
*fe
;
12741 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12742 line_ptr
+= bytes_read
;
12743 if (lh
->num_file_names
< file
|| file
== 0)
12744 dwarf2_debug_line_missing_file_complaint ();
12747 fe
= &lh
->file_names
[file
- 1];
12749 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12750 if (!decode_for_pst_p
)
12752 last_subfile
= current_subfile
;
12753 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12758 case DW_LNS_set_column
:
12759 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12760 line_ptr
+= bytes_read
;
12762 case DW_LNS_negate_stmt
:
12763 is_stmt
= (!is_stmt
);
12765 case DW_LNS_set_basic_block
:
12768 /* Add to the address register of the state machine the
12769 address increment value corresponding to special opcode
12770 255. I.e., this value is scaled by the minimum
12771 instruction length since special opcode 255 would have
12772 scaled the increment. */
12773 case DW_LNS_const_add_pc
:
12775 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
12777 address
+= (((op_index
+ adjust
)
12778 / lh
->maximum_ops_per_instruction
)
12779 * lh
->minimum_instruction_length
);
12780 op_index
= ((op_index
+ adjust
)
12781 % lh
->maximum_ops_per_instruction
);
12784 case DW_LNS_fixed_advance_pc
:
12785 address
+= read_2_bytes (abfd
, line_ptr
);
12791 /* Unknown standard opcode, ignore it. */
12794 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
12796 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12797 line_ptr
+= bytes_read
;
12802 if (lh
->num_file_names
< file
|| file
== 0)
12803 dwarf2_debug_line_missing_file_complaint ();
12806 lh
->file_names
[file
- 1].included_p
= 1;
12807 if (!decode_for_pst_p
)
12809 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12810 (*p_record_line
) (current_subfile
, 0, addr
);
12816 /* Decode the Line Number Program (LNP) for the given line_header
12817 structure and CU. The actual information extracted and the type
12818 of structures created from the LNP depends on the value of PST.
12820 1. If PST is NULL, then this procedure uses the data from the program
12821 to create all necessary symbol tables, and their linetables.
12823 2. If PST is not NULL, this procedure reads the program to determine
12824 the list of files included by the unit represented by PST, and
12825 builds all the associated partial symbol tables.
12827 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12828 It is used for relative paths in the line table.
12829 NOTE: When processing partial symtabs (pst != NULL),
12830 comp_dir == pst->dirname.
12832 NOTE: It is important that psymtabs have the same file name (via strcmp)
12833 as the corresponding symtab. Since COMP_DIR is not used in the name of the
12834 symtab we don't use it in the name of the psymtabs we create.
12835 E.g. expand_line_sal requires this when finding psymtabs to expand.
12836 A good testcase for this is mb-inline.exp. */
12839 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
12840 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
12841 int want_line_info
)
12843 struct objfile
*objfile
= cu
->objfile
;
12844 const int decode_for_pst_p
= (pst
!= NULL
);
12845 struct subfile
*first_subfile
= current_subfile
;
12847 if (want_line_info
)
12848 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
12850 if (decode_for_pst_p
)
12854 /* Now that we're done scanning the Line Header Program, we can
12855 create the psymtab of each included file. */
12856 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
12857 if (lh
->file_names
[file_index
].included_p
== 1)
12859 char *include_name
=
12860 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
12861 if (include_name
!= NULL
)
12862 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
12867 /* Make sure a symtab is created for every file, even files
12868 which contain only variables (i.e. no code with associated
12872 for (i
= 0; i
< lh
->num_file_names
; i
++)
12875 struct file_entry
*fe
;
12877 fe
= &lh
->file_names
[i
];
12879 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12880 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12882 /* Skip the main file; we don't need it, and it must be
12883 allocated last, so that it will show up before the
12884 non-primary symtabs in the objfile's symtab list. */
12885 if (current_subfile
== first_subfile
)
12888 if (current_subfile
->symtab
== NULL
)
12889 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
12891 fe
->symtab
= current_subfile
->symtab
;
12896 /* Start a subfile for DWARF. FILENAME is the name of the file and
12897 DIRNAME the name of the source directory which contains FILENAME
12898 or NULL if not known. COMP_DIR is the compilation directory for the
12899 linetable's compilation unit or NULL if not known.
12900 This routine tries to keep line numbers from identical absolute and
12901 relative file names in a common subfile.
12903 Using the `list' example from the GDB testsuite, which resides in
12904 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
12905 of /srcdir/list0.c yields the following debugging information for list0.c:
12907 DW_AT_name: /srcdir/list0.c
12908 DW_AT_comp_dir: /compdir
12909 files.files[0].name: list0.h
12910 files.files[0].dir: /srcdir
12911 files.files[1].name: list0.c
12912 files.files[1].dir: /srcdir
12914 The line number information for list0.c has to end up in a single
12915 subfile, so that `break /srcdir/list0.c:1' works as expected.
12916 start_subfile will ensure that this happens provided that we pass the
12917 concatenation of files.files[1].dir and files.files[1].name as the
12921 dwarf2_start_subfile (char *filename
, const char *dirname
,
12922 const char *comp_dir
)
12926 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
12927 `start_symtab' will always pass the contents of DW_AT_comp_dir as
12928 second argument to start_subfile. To be consistent, we do the
12929 same here. In order not to lose the line information directory,
12930 we concatenate it to the filename when it makes sense.
12931 Note that the Dwarf3 standard says (speaking of filenames in line
12932 information): ``The directory index is ignored for file names
12933 that represent full path names''. Thus ignoring dirname in the
12934 `else' branch below isn't an issue. */
12936 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
12937 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
12939 fullname
= filename
;
12941 start_subfile (fullname
, comp_dir
);
12943 if (fullname
!= filename
)
12948 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
12949 struct dwarf2_cu
*cu
)
12951 struct objfile
*objfile
= cu
->objfile
;
12952 struct comp_unit_head
*cu_header
= &cu
->header
;
12954 /* NOTE drow/2003-01-30: There used to be a comment and some special
12955 code here to turn a symbol with DW_AT_external and a
12956 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
12957 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
12958 with some versions of binutils) where shared libraries could have
12959 relocations against symbols in their debug information - the
12960 minimal symbol would have the right address, but the debug info
12961 would not. It's no longer necessary, because we will explicitly
12962 apply relocations when we read in the debug information now. */
12964 /* A DW_AT_location attribute with no contents indicates that a
12965 variable has been optimized away. */
12966 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
12968 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
12972 /* Handle one degenerate form of location expression specially, to
12973 preserve GDB's previous behavior when section offsets are
12974 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
12975 then mark this symbol as LOC_STATIC. */
12977 if (attr_form_is_block (attr
)
12978 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
12979 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
12980 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
12981 && (DW_BLOCK (attr
)->size
12982 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
12984 unsigned int dummy
;
12986 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
12987 SYMBOL_VALUE_ADDRESS (sym
) =
12988 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
12990 SYMBOL_VALUE_ADDRESS (sym
) =
12991 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
12992 SYMBOL_CLASS (sym
) = LOC_STATIC
;
12993 fixup_symbol_section (sym
, objfile
);
12994 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
12995 SYMBOL_SECTION (sym
));
12999 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13000 expression evaluator, and use LOC_COMPUTED only when necessary
13001 (i.e. when the value of a register or memory location is
13002 referenced, or a thread-local block, etc.). Then again, it might
13003 not be worthwhile. I'm assuming that it isn't unless performance
13004 or memory numbers show me otherwise. */
13006 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13007 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13009 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13010 cu
->has_loclist
= 1;
13013 /* Given a pointer to a DWARF information entry, figure out if we need
13014 to make a symbol table entry for it, and if so, create a new entry
13015 and return a pointer to it.
13016 If TYPE is NULL, determine symbol type from the die, otherwise
13017 used the passed type.
13018 If SPACE is not NULL, use it to hold the new symbol. If it is
13019 NULL, allocate a new symbol on the objfile's obstack. */
13021 static struct symbol
*
13022 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13023 struct symbol
*space
)
13025 struct objfile
*objfile
= cu
->objfile
;
13026 struct symbol
*sym
= NULL
;
13028 struct attribute
*attr
= NULL
;
13029 struct attribute
*attr2
= NULL
;
13030 CORE_ADDR baseaddr
;
13031 struct pending
**list_to_add
= NULL
;
13033 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13035 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13037 name
= dwarf2_name (die
, cu
);
13040 const char *linkagename
;
13041 int suppress_add
= 0;
13046 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13047 OBJSTAT (objfile
, n_syms
++);
13049 /* Cache this symbol's name and the name's demangled form (if any). */
13050 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13051 linkagename
= dwarf2_physname (name
, die
, cu
);
13052 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13054 /* Fortran does not have mangling standard and the mangling does differ
13055 between gfortran, iFort etc. */
13056 if (cu
->language
== language_fortran
13057 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13058 symbol_set_demangled_name (&(sym
->ginfo
),
13059 (char *) dwarf2_full_name (name
, die
, cu
),
13062 /* Default assumptions.
13063 Use the passed type or decode it from the die. */
13064 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13065 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13067 SYMBOL_TYPE (sym
) = type
;
13069 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13070 attr
= dwarf2_attr (die
,
13071 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13075 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13078 attr
= dwarf2_attr (die
,
13079 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13083 int file_index
= DW_UNSND (attr
);
13085 if (cu
->line_header
== NULL
13086 || file_index
> cu
->line_header
->num_file_names
)
13087 complaint (&symfile_complaints
,
13088 _("file index out of range"));
13089 else if (file_index
> 0)
13091 struct file_entry
*fe
;
13093 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13094 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13101 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13104 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13106 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13107 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13108 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13109 add_symbol_to_list (sym
, cu
->list_in_scope
);
13111 case DW_TAG_subprogram
:
13112 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13114 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13115 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13116 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13117 || cu
->language
== language_ada
)
13119 /* Subprograms marked external are stored as a global symbol.
13120 Ada subprograms, whether marked external or not, are always
13121 stored as a global symbol, because we want to be able to
13122 access them globally. For instance, we want to be able
13123 to break on a nested subprogram without having to
13124 specify the context. */
13125 list_to_add
= &global_symbols
;
13129 list_to_add
= cu
->list_in_scope
;
13132 case DW_TAG_inlined_subroutine
:
13133 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13135 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13136 SYMBOL_INLINED (sym
) = 1;
13137 list_to_add
= cu
->list_in_scope
;
13139 case DW_TAG_template_value_param
:
13141 /* Fall through. */
13142 case DW_TAG_constant
:
13143 case DW_TAG_variable
:
13144 case DW_TAG_member
:
13145 /* Compilation with minimal debug info may result in
13146 variables with missing type entries. Change the
13147 misleading `void' type to something sensible. */
13148 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13150 = objfile_type (objfile
)->nodebug_data_symbol
;
13152 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13153 /* In the case of DW_TAG_member, we should only be called for
13154 static const members. */
13155 if (die
->tag
== DW_TAG_member
)
13157 /* dwarf2_add_field uses die_is_declaration,
13158 so we do the same. */
13159 gdb_assert (die_is_declaration (die
, cu
));
13164 dwarf2_const_value (attr
, sym
, cu
);
13165 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13168 if (attr2
&& (DW_UNSND (attr2
) != 0))
13169 list_to_add
= &global_symbols
;
13171 list_to_add
= cu
->list_in_scope
;
13175 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13178 var_decode_location (attr
, sym
, cu
);
13179 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13180 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13181 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13182 && !dwarf2_per_objfile
->has_section_at_zero
)
13184 /* When a static variable is eliminated by the linker,
13185 the corresponding debug information is not stripped
13186 out, but the variable address is set to null;
13187 do not add such variables into symbol table. */
13189 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13191 /* Workaround gfortran PR debug/40040 - it uses
13192 DW_AT_location for variables in -fPIC libraries which may
13193 get overriden by other libraries/executable and get
13194 a different address. Resolve it by the minimal symbol
13195 which may come from inferior's executable using copy
13196 relocation. Make this workaround only for gfortran as for
13197 other compilers GDB cannot guess the minimal symbol
13198 Fortran mangling kind. */
13199 if (cu
->language
== language_fortran
&& die
->parent
13200 && die
->parent
->tag
== DW_TAG_module
13202 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13203 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13205 /* A variable with DW_AT_external is never static,
13206 but it may be block-scoped. */
13207 list_to_add
= (cu
->list_in_scope
== &file_symbols
13208 ? &global_symbols
: cu
->list_in_scope
);
13211 list_to_add
= cu
->list_in_scope
;
13215 /* We do not know the address of this symbol.
13216 If it is an external symbol and we have type information
13217 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13218 The address of the variable will then be determined from
13219 the minimal symbol table whenever the variable is
13221 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13222 if (attr2
&& (DW_UNSND (attr2
) != 0)
13223 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13225 /* A variable with DW_AT_external is never static, but it
13226 may be block-scoped. */
13227 list_to_add
= (cu
->list_in_scope
== &file_symbols
13228 ? &global_symbols
: cu
->list_in_scope
);
13230 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13232 else if (!die_is_declaration (die
, cu
))
13234 /* Use the default LOC_OPTIMIZED_OUT class. */
13235 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13237 list_to_add
= cu
->list_in_scope
;
13241 case DW_TAG_formal_parameter
:
13242 /* If we are inside a function, mark this as an argument. If
13243 not, we might be looking at an argument to an inlined function
13244 when we do not have enough information to show inlined frames;
13245 pretend it's a local variable in that case so that the user can
13247 if (context_stack_depth
> 0
13248 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13249 SYMBOL_IS_ARGUMENT (sym
) = 1;
13250 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13253 var_decode_location (attr
, sym
, cu
);
13255 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13258 dwarf2_const_value (attr
, sym
, cu
);
13261 list_to_add
= cu
->list_in_scope
;
13263 case DW_TAG_unspecified_parameters
:
13264 /* From varargs functions; gdb doesn't seem to have any
13265 interest in this information, so just ignore it for now.
13268 case DW_TAG_template_type_param
:
13270 /* Fall through. */
13271 case DW_TAG_class_type
:
13272 case DW_TAG_interface_type
:
13273 case DW_TAG_structure_type
:
13274 case DW_TAG_union_type
:
13275 case DW_TAG_set_type
:
13276 case DW_TAG_enumeration_type
:
13277 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13278 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13281 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13282 really ever be static objects: otherwise, if you try
13283 to, say, break of a class's method and you're in a file
13284 which doesn't mention that class, it won't work unless
13285 the check for all static symbols in lookup_symbol_aux
13286 saves you. See the OtherFileClass tests in
13287 gdb.c++/namespace.exp. */
13291 list_to_add
= (cu
->list_in_scope
== &file_symbols
13292 && (cu
->language
== language_cplus
13293 || cu
->language
== language_java
)
13294 ? &global_symbols
: cu
->list_in_scope
);
13296 /* The semantics of C++ state that "struct foo {
13297 ... }" also defines a typedef for "foo". A Java
13298 class declaration also defines a typedef for the
13300 if (cu
->language
== language_cplus
13301 || cu
->language
== language_java
13302 || cu
->language
== language_ada
)
13304 /* The symbol's name is already allocated along
13305 with this objfile, so we don't need to
13306 duplicate it for the type. */
13307 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13308 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13313 case DW_TAG_typedef
:
13314 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13315 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13316 list_to_add
= cu
->list_in_scope
;
13318 case DW_TAG_base_type
:
13319 case DW_TAG_subrange_type
:
13320 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13321 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13322 list_to_add
= cu
->list_in_scope
;
13324 case DW_TAG_enumerator
:
13325 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13328 dwarf2_const_value (attr
, sym
, cu
);
13331 /* NOTE: carlton/2003-11-10: See comment above in the
13332 DW_TAG_class_type, etc. block. */
13334 list_to_add
= (cu
->list_in_scope
== &file_symbols
13335 && (cu
->language
== language_cplus
13336 || cu
->language
== language_java
)
13337 ? &global_symbols
: cu
->list_in_scope
);
13340 case DW_TAG_namespace
:
13341 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13342 list_to_add
= &global_symbols
;
13345 /* Not a tag we recognize. Hopefully we aren't processing
13346 trash data, but since we must specifically ignore things
13347 we don't recognize, there is nothing else we should do at
13349 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13350 dwarf_tag_name (die
->tag
));
13356 sym
->hash_next
= objfile
->template_symbols
;
13357 objfile
->template_symbols
= sym
;
13358 list_to_add
= NULL
;
13361 if (list_to_add
!= NULL
)
13362 add_symbol_to_list (sym
, list_to_add
);
13364 /* For the benefit of old versions of GCC, check for anonymous
13365 namespaces based on the demangled name. */
13366 if (!processing_has_namespace_info
13367 && cu
->language
== language_cplus
)
13368 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13373 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13375 static struct symbol
*
13376 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13378 return new_symbol_full (die
, type
, cu
, NULL
);
13381 /* Given an attr with a DW_FORM_dataN value in host byte order,
13382 zero-extend it as appropriate for the symbol's type. The DWARF
13383 standard (v4) is not entirely clear about the meaning of using
13384 DW_FORM_dataN for a constant with a signed type, where the type is
13385 wider than the data. The conclusion of a discussion on the DWARF
13386 list was that this is unspecified. We choose to always zero-extend
13387 because that is the interpretation long in use by GCC. */
13390 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13391 const char *name
, struct obstack
*obstack
,
13392 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13394 struct objfile
*objfile
= cu
->objfile
;
13395 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13396 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13397 LONGEST l
= DW_UNSND (attr
);
13399 if (bits
< sizeof (*value
) * 8)
13401 l
&= ((LONGEST
) 1 << bits
) - 1;
13404 else if (bits
== sizeof (*value
) * 8)
13408 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13409 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13416 /* Read a constant value from an attribute. Either set *VALUE, or if
13417 the value does not fit in *VALUE, set *BYTES - either already
13418 allocated on the objfile obstack, or newly allocated on OBSTACK,
13419 or, set *BATON, if we translated the constant to a location
13423 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13424 const char *name
, struct obstack
*obstack
,
13425 struct dwarf2_cu
*cu
,
13426 LONGEST
*value
, gdb_byte
**bytes
,
13427 struct dwarf2_locexpr_baton
**baton
)
13429 struct objfile
*objfile
= cu
->objfile
;
13430 struct comp_unit_head
*cu_header
= &cu
->header
;
13431 struct dwarf_block
*blk
;
13432 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13433 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13439 switch (attr
->form
)
13442 case DW_FORM_GNU_addr_index
:
13446 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13447 dwarf2_const_value_length_mismatch_complaint (name
,
13448 cu_header
->addr_size
,
13449 TYPE_LENGTH (type
));
13450 /* Symbols of this form are reasonably rare, so we just
13451 piggyback on the existing location code rather than writing
13452 a new implementation of symbol_computed_ops. */
13453 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13454 sizeof (struct dwarf2_locexpr_baton
));
13455 (*baton
)->per_cu
= cu
->per_cu
;
13456 gdb_assert ((*baton
)->per_cu
);
13458 (*baton
)->size
= 2 + cu_header
->addr_size
;
13459 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13460 (*baton
)->data
= data
;
13462 data
[0] = DW_OP_addr
;
13463 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13464 byte_order
, DW_ADDR (attr
));
13465 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13468 case DW_FORM_string
:
13470 case DW_FORM_GNU_str_index
:
13471 /* DW_STRING is already allocated on the objfile obstack, point
13473 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13475 case DW_FORM_block1
:
13476 case DW_FORM_block2
:
13477 case DW_FORM_block4
:
13478 case DW_FORM_block
:
13479 case DW_FORM_exprloc
:
13480 blk
= DW_BLOCK (attr
);
13481 if (TYPE_LENGTH (type
) != blk
->size
)
13482 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13483 TYPE_LENGTH (type
));
13484 *bytes
= blk
->data
;
13487 /* The DW_AT_const_value attributes are supposed to carry the
13488 symbol's value "represented as it would be on the target
13489 architecture." By the time we get here, it's already been
13490 converted to host endianness, so we just need to sign- or
13491 zero-extend it as appropriate. */
13492 case DW_FORM_data1
:
13493 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13494 obstack
, cu
, value
, 8);
13496 case DW_FORM_data2
:
13497 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13498 obstack
, cu
, value
, 16);
13500 case DW_FORM_data4
:
13501 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13502 obstack
, cu
, value
, 32);
13504 case DW_FORM_data8
:
13505 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13506 obstack
, cu
, value
, 64);
13509 case DW_FORM_sdata
:
13510 *value
= DW_SND (attr
);
13513 case DW_FORM_udata
:
13514 *value
= DW_UNSND (attr
);
13518 complaint (&symfile_complaints
,
13519 _("unsupported const value attribute form: '%s'"),
13520 dwarf_form_name (attr
->form
));
13527 /* Copy constant value from an attribute to a symbol. */
13530 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13531 struct dwarf2_cu
*cu
)
13533 struct objfile
*objfile
= cu
->objfile
;
13534 struct comp_unit_head
*cu_header
= &cu
->header
;
13537 struct dwarf2_locexpr_baton
*baton
;
13539 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13540 SYMBOL_PRINT_NAME (sym
),
13541 &objfile
->objfile_obstack
, cu
,
13542 &value
, &bytes
, &baton
);
13546 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13547 SYMBOL_LOCATION_BATON (sym
) = baton
;
13548 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13550 else if (bytes
!= NULL
)
13552 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13553 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13557 SYMBOL_VALUE (sym
) = value
;
13558 SYMBOL_CLASS (sym
) = LOC_CONST
;
13562 /* Return the type of the die in question using its DW_AT_type attribute. */
13564 static struct type
*
13565 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13567 struct attribute
*type_attr
;
13569 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13572 /* A missing DW_AT_type represents a void type. */
13573 return objfile_type (cu
->objfile
)->builtin_void
;
13576 return lookup_die_type (die
, type_attr
, cu
);
13579 /* True iff CU's producer generates GNAT Ada auxiliary information
13580 that allows to find parallel types through that information instead
13581 of having to do expensive parallel lookups by type name. */
13584 need_gnat_info (struct dwarf2_cu
*cu
)
13586 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
13587 of GNAT produces this auxiliary information, without any indication
13588 that it is produced. Part of enhancing the FSF version of GNAT
13589 to produce that information will be to put in place an indicator
13590 that we can use in order to determine whether the descriptive type
13591 info is available or not. One suggestion that has been made is
13592 to use a new attribute, attached to the CU die. For now, assume
13593 that the descriptive type info is not available. */
13597 /* Return the auxiliary type of the die in question using its
13598 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
13599 attribute is not present. */
13601 static struct type
*
13602 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13604 struct attribute
*type_attr
;
13606 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
13610 return lookup_die_type (die
, type_attr
, cu
);
13613 /* If DIE has a descriptive_type attribute, then set the TYPE's
13614 descriptive type accordingly. */
13617 set_descriptive_type (struct type
*type
, struct die_info
*die
,
13618 struct dwarf2_cu
*cu
)
13620 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
13622 if (descriptive_type
)
13624 ALLOCATE_GNAT_AUX_TYPE (type
);
13625 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
13629 /* Return the containing type of the die in question using its
13630 DW_AT_containing_type attribute. */
13632 static struct type
*
13633 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13635 struct attribute
*type_attr
;
13637 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
13639 error (_("Dwarf Error: Problem turning containing type into gdb type "
13640 "[in module %s]"), cu
->objfile
->name
);
13642 return lookup_die_type (die
, type_attr
, cu
);
13645 /* Look up the type of DIE in CU using its type attribute ATTR.
13646 If there is no type substitute an error marker. */
13648 static struct type
*
13649 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
13650 struct dwarf2_cu
*cu
)
13652 struct objfile
*objfile
= cu
->objfile
;
13653 struct type
*this_type
;
13655 /* First see if we have it cached. */
13657 if (is_ref_attr (attr
))
13659 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
13661 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
13663 else if (attr
->form
== DW_FORM_ref_sig8
)
13665 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13667 /* sig_type will be NULL if the signatured type is missing from
13669 if (sig_type
== NULL
)
13670 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13671 "at 0x%x [in module %s]"),
13672 die
->offset
.sect_off
, objfile
->name
);
13674 gdb_assert (sig_type
->per_cu
.is_debug_types
);
13675 /* If we haven't filled in type_offset_in_section yet, then we
13676 haven't read the type in yet. */
13678 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
13681 get_die_type_at_offset (sig_type
->type_offset_in_section
,
13682 &sig_type
->per_cu
);
13687 dump_die_for_error (die
);
13688 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
13689 dwarf_attr_name (attr
->name
), objfile
->name
);
13692 /* If not cached we need to read it in. */
13694 if (this_type
== NULL
)
13696 struct die_info
*type_die
;
13697 struct dwarf2_cu
*type_cu
= cu
;
13699 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
13700 /* If we found the type now, it's probably because the type came
13701 from an inter-CU reference and the type's CU got expanded before
13703 this_type
= get_die_type (type_die
, type_cu
);
13704 if (this_type
== NULL
)
13705 this_type
= read_type_die_1 (type_die
, type_cu
);
13708 /* If we still don't have a type use an error marker. */
13710 if (this_type
== NULL
)
13712 char *message
, *saved
;
13714 /* read_type_die already issued a complaint. */
13715 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
13717 cu
->header
.offset
.sect_off
,
13718 die
->offset
.sect_off
);
13719 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
13720 message
, strlen (message
));
13723 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
13729 /* Return the type in DIE, CU.
13730 Returns NULL for invalid types.
13732 This first does a lookup in the appropriate type_hash table,
13733 and only reads the die in if necessary.
13735 NOTE: This can be called when reading in partial or full symbols. */
13737 static struct type
*
13738 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
13740 struct type
*this_type
;
13742 this_type
= get_die_type (die
, cu
);
13746 return read_type_die_1 (die
, cu
);
13749 /* Read the type in DIE, CU.
13750 Returns NULL for invalid types. */
13752 static struct type
*
13753 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
13755 struct type
*this_type
= NULL
;
13759 case DW_TAG_class_type
:
13760 case DW_TAG_interface_type
:
13761 case DW_TAG_structure_type
:
13762 case DW_TAG_union_type
:
13763 this_type
= read_structure_type (die
, cu
);
13765 case DW_TAG_enumeration_type
:
13766 this_type
= read_enumeration_type (die
, cu
);
13768 case DW_TAG_subprogram
:
13769 case DW_TAG_subroutine_type
:
13770 case DW_TAG_inlined_subroutine
:
13771 this_type
= read_subroutine_type (die
, cu
);
13773 case DW_TAG_array_type
:
13774 this_type
= read_array_type (die
, cu
);
13776 case DW_TAG_set_type
:
13777 this_type
= read_set_type (die
, cu
);
13779 case DW_TAG_pointer_type
:
13780 this_type
= read_tag_pointer_type (die
, cu
);
13782 case DW_TAG_ptr_to_member_type
:
13783 this_type
= read_tag_ptr_to_member_type (die
, cu
);
13785 case DW_TAG_reference_type
:
13786 this_type
= read_tag_reference_type (die
, cu
);
13788 case DW_TAG_const_type
:
13789 this_type
= read_tag_const_type (die
, cu
);
13791 case DW_TAG_volatile_type
:
13792 this_type
= read_tag_volatile_type (die
, cu
);
13794 case DW_TAG_string_type
:
13795 this_type
= read_tag_string_type (die
, cu
);
13797 case DW_TAG_typedef
:
13798 this_type
= read_typedef (die
, cu
);
13800 case DW_TAG_subrange_type
:
13801 this_type
= read_subrange_type (die
, cu
);
13803 case DW_TAG_base_type
:
13804 this_type
= read_base_type (die
, cu
);
13806 case DW_TAG_unspecified_type
:
13807 this_type
= read_unspecified_type (die
, cu
);
13809 case DW_TAG_namespace
:
13810 this_type
= read_namespace_type (die
, cu
);
13812 case DW_TAG_module
:
13813 this_type
= read_module_type (die
, cu
);
13816 complaint (&symfile_complaints
,
13817 _("unexpected tag in read_type_die: '%s'"),
13818 dwarf_tag_name (die
->tag
));
13825 /* See if we can figure out if the class lives in a namespace. We do
13826 this by looking for a member function; its demangled name will
13827 contain namespace info, if there is any.
13828 Return the computed name or NULL.
13829 Space for the result is allocated on the objfile's obstack.
13830 This is the full-die version of guess_partial_die_structure_name.
13831 In this case we know DIE has no useful parent. */
13834 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
13836 struct die_info
*spec_die
;
13837 struct dwarf2_cu
*spec_cu
;
13838 struct die_info
*child
;
13841 spec_die
= die_specification (die
, &spec_cu
);
13842 if (spec_die
!= NULL
)
13848 for (child
= die
->child
;
13850 child
= child
->sibling
)
13852 if (child
->tag
== DW_TAG_subprogram
)
13854 struct attribute
*attr
;
13856 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
13858 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
13862 = language_class_name_from_physname (cu
->language_defn
,
13866 if (actual_name
!= NULL
)
13868 char *die_name
= dwarf2_name (die
, cu
);
13870 if (die_name
!= NULL
13871 && strcmp (die_name
, actual_name
) != 0)
13873 /* Strip off the class name from the full name.
13874 We want the prefix. */
13875 int die_name_len
= strlen (die_name
);
13876 int actual_name_len
= strlen (actual_name
);
13878 /* Test for '::' as a sanity check. */
13879 if (actual_name_len
> die_name_len
+ 2
13880 && actual_name
[actual_name_len
13881 - die_name_len
- 1] == ':')
13883 obsavestring (actual_name
,
13884 actual_name_len
- die_name_len
- 2,
13885 &cu
->objfile
->objfile_obstack
);
13888 xfree (actual_name
);
13897 /* GCC might emit a nameless typedef that has a linkage name. Determine the
13898 prefix part in such case. See
13899 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13902 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
13904 struct attribute
*attr
;
13907 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
13908 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
13911 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
13912 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
13915 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
13917 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
13918 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
13921 /* dwarf2_name had to be already called. */
13922 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
13924 /* Strip the base name, keep any leading namespaces/classes. */
13925 base
= strrchr (DW_STRING (attr
), ':');
13926 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
13929 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
13930 &cu
->objfile
->objfile_obstack
);
13933 /* Return the name of the namespace/class that DIE is defined within,
13934 or "" if we can't tell. The caller should not xfree the result.
13936 For example, if we're within the method foo() in the following
13946 then determine_prefix on foo's die will return "N::C". */
13948 static const char *
13949 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
13951 struct die_info
*parent
, *spec_die
;
13952 struct dwarf2_cu
*spec_cu
;
13953 struct type
*parent_type
;
13956 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
13957 && cu
->language
!= language_fortran
)
13960 retval
= anonymous_struct_prefix (die
, cu
);
13964 /* We have to be careful in the presence of DW_AT_specification.
13965 For example, with GCC 3.4, given the code
13969 // Definition of N::foo.
13973 then we'll have a tree of DIEs like this:
13975 1: DW_TAG_compile_unit
13976 2: DW_TAG_namespace // N
13977 3: DW_TAG_subprogram // declaration of N::foo
13978 4: DW_TAG_subprogram // definition of N::foo
13979 DW_AT_specification // refers to die #3
13981 Thus, when processing die #4, we have to pretend that we're in
13982 the context of its DW_AT_specification, namely the contex of die
13985 spec_die
= die_specification (die
, &spec_cu
);
13986 if (spec_die
== NULL
)
13987 parent
= die
->parent
;
13990 parent
= spec_die
->parent
;
13994 if (parent
== NULL
)
13996 else if (parent
->building_fullname
)
13999 const char *parent_name
;
14001 /* It has been seen on RealView 2.2 built binaries,
14002 DW_TAG_template_type_param types actually _defined_ as
14003 children of the parent class:
14006 template class <class Enum> Class{};
14007 Class<enum E> class_e;
14009 1: DW_TAG_class_type (Class)
14010 2: DW_TAG_enumeration_type (E)
14011 3: DW_TAG_enumerator (enum1:0)
14012 3: DW_TAG_enumerator (enum2:1)
14014 2: DW_TAG_template_type_param
14015 DW_AT_type DW_FORM_ref_udata (E)
14017 Besides being broken debug info, it can put GDB into an
14018 infinite loop. Consider:
14020 When we're building the full name for Class<E>, we'll start
14021 at Class, and go look over its template type parameters,
14022 finding E. We'll then try to build the full name of E, and
14023 reach here. We're now trying to build the full name of E,
14024 and look over the parent DIE for containing scope. In the
14025 broken case, if we followed the parent DIE of E, we'd again
14026 find Class, and once again go look at its template type
14027 arguments, etc., etc. Simply don't consider such parent die
14028 as source-level parent of this die (it can't be, the language
14029 doesn't allow it), and break the loop here. */
14030 name
= dwarf2_name (die
, cu
);
14031 parent_name
= dwarf2_name (parent
, cu
);
14032 complaint (&symfile_complaints
,
14033 _("template param type '%s' defined within parent '%s'"),
14034 name
? name
: "<unknown>",
14035 parent_name
? parent_name
: "<unknown>");
14039 switch (parent
->tag
)
14041 case DW_TAG_namespace
:
14042 parent_type
= read_type_die (parent
, cu
);
14043 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14044 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14045 Work around this problem here. */
14046 if (cu
->language
== language_cplus
14047 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14049 /* We give a name to even anonymous namespaces. */
14050 return TYPE_TAG_NAME (parent_type
);
14051 case DW_TAG_class_type
:
14052 case DW_TAG_interface_type
:
14053 case DW_TAG_structure_type
:
14054 case DW_TAG_union_type
:
14055 case DW_TAG_module
:
14056 parent_type
= read_type_die (parent
, cu
);
14057 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14058 return TYPE_TAG_NAME (parent_type
);
14060 /* An anonymous structure is only allowed non-static data
14061 members; no typedefs, no member functions, et cetera.
14062 So it does not need a prefix. */
14064 case DW_TAG_compile_unit
:
14065 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14066 if (cu
->language
== language_cplus
14067 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14068 && die
->child
!= NULL
14069 && (die
->tag
== DW_TAG_class_type
14070 || die
->tag
== DW_TAG_structure_type
14071 || die
->tag
== DW_TAG_union_type
))
14073 char *name
= guess_full_die_structure_name (die
, cu
);
14079 return determine_prefix (parent
, cu
);
14083 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14084 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14085 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14086 an obconcat, otherwise allocate storage for the result. The CU argument is
14087 used to determine the language and hence, the appropriate separator. */
14089 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14092 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14093 int physname
, struct dwarf2_cu
*cu
)
14095 const char *lead
= "";
14098 if (suffix
== NULL
|| suffix
[0] == '\0'
14099 || prefix
== NULL
|| prefix
[0] == '\0')
14101 else if (cu
->language
== language_java
)
14103 else if (cu
->language
== language_fortran
&& physname
)
14105 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14106 DW_AT_MIPS_linkage_name is preferred and used instead. */
14114 if (prefix
== NULL
)
14116 if (suffix
== NULL
)
14122 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14124 strcpy (retval
, lead
);
14125 strcat (retval
, prefix
);
14126 strcat (retval
, sep
);
14127 strcat (retval
, suffix
);
14132 /* We have an obstack. */
14133 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14137 /* Return sibling of die, NULL if no sibling. */
14139 static struct die_info
*
14140 sibling_die (struct die_info
*die
)
14142 return die
->sibling
;
14145 /* Get name of a die, return NULL if not found. */
14148 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14149 struct obstack
*obstack
)
14151 if (name
&& cu
->language
== language_cplus
)
14153 char *canon_name
= cp_canonicalize_string (name
);
14155 if (canon_name
!= NULL
)
14157 if (strcmp (canon_name
, name
) != 0)
14158 name
= obsavestring (canon_name
, strlen (canon_name
),
14160 xfree (canon_name
);
14167 /* Get name of a die, return NULL if not found. */
14170 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14172 struct attribute
*attr
;
14174 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14175 if ((!attr
|| !DW_STRING (attr
))
14176 && die
->tag
!= DW_TAG_class_type
14177 && die
->tag
!= DW_TAG_interface_type
14178 && die
->tag
!= DW_TAG_structure_type
14179 && die
->tag
!= DW_TAG_union_type
)
14184 case DW_TAG_compile_unit
:
14185 /* Compilation units have a DW_AT_name that is a filename, not
14186 a source language identifier. */
14187 case DW_TAG_enumeration_type
:
14188 case DW_TAG_enumerator
:
14189 /* These tags always have simple identifiers already; no need
14190 to canonicalize them. */
14191 return DW_STRING (attr
);
14193 case DW_TAG_subprogram
:
14194 /* Java constructors will all be named "<init>", so return
14195 the class name when we see this special case. */
14196 if (cu
->language
== language_java
14197 && DW_STRING (attr
) != NULL
14198 && strcmp (DW_STRING (attr
), "<init>") == 0)
14200 struct dwarf2_cu
*spec_cu
= cu
;
14201 struct die_info
*spec_die
;
14203 /* GCJ will output '<init>' for Java constructor names.
14204 For this special case, return the name of the parent class. */
14206 /* GCJ may output suprogram DIEs with AT_specification set.
14207 If so, use the name of the specified DIE. */
14208 spec_die
= die_specification (die
, &spec_cu
);
14209 if (spec_die
!= NULL
)
14210 return dwarf2_name (spec_die
, spec_cu
);
14215 if (die
->tag
== DW_TAG_class_type
)
14216 return dwarf2_name (die
, cu
);
14218 while (die
->tag
!= DW_TAG_compile_unit
);
14222 case DW_TAG_class_type
:
14223 case DW_TAG_interface_type
:
14224 case DW_TAG_structure_type
:
14225 case DW_TAG_union_type
:
14226 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14227 structures or unions. These were of the form "._%d" in GCC 4.1,
14228 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14229 and GCC 4.4. We work around this problem by ignoring these. */
14230 if (attr
&& DW_STRING (attr
)
14231 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14232 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14235 /* GCC might emit a nameless typedef that has a linkage name. See
14236 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14237 if (!attr
|| DW_STRING (attr
) == NULL
)
14239 char *demangled
= NULL
;
14241 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14243 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14245 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14248 /* Avoid demangling DW_STRING (attr) the second time on a second
14249 call for the same DIE. */
14250 if (!DW_STRING_IS_CANONICAL (attr
))
14251 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14257 /* FIXME: we already did this for the partial symbol... */
14258 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14259 &cu
->objfile
->objfile_obstack
);
14260 DW_STRING_IS_CANONICAL (attr
) = 1;
14263 /* Strip any leading namespaces/classes, keep only the base name.
14264 DW_AT_name for named DIEs does not contain the prefixes. */
14265 base
= strrchr (DW_STRING (attr
), ':');
14266 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14269 return DW_STRING (attr
);
14278 if (!DW_STRING_IS_CANONICAL (attr
))
14281 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14282 &cu
->objfile
->objfile_obstack
);
14283 DW_STRING_IS_CANONICAL (attr
) = 1;
14285 return DW_STRING (attr
);
14288 /* Return the die that this die in an extension of, or NULL if there
14289 is none. *EXT_CU is the CU containing DIE on input, and the CU
14290 containing the return value on output. */
14292 static struct die_info
*
14293 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14295 struct attribute
*attr
;
14297 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14301 return follow_die_ref (die
, attr
, ext_cu
);
14304 /* Convert a DIE tag into its string name. */
14307 dwarf_tag_name (unsigned tag
)
14311 case DW_TAG_padding
:
14312 return "DW_TAG_padding";
14313 case DW_TAG_array_type
:
14314 return "DW_TAG_array_type";
14315 case DW_TAG_class_type
:
14316 return "DW_TAG_class_type";
14317 case DW_TAG_entry_point
:
14318 return "DW_TAG_entry_point";
14319 case DW_TAG_enumeration_type
:
14320 return "DW_TAG_enumeration_type";
14321 case DW_TAG_formal_parameter
:
14322 return "DW_TAG_formal_parameter";
14323 case DW_TAG_imported_declaration
:
14324 return "DW_TAG_imported_declaration";
14326 return "DW_TAG_label";
14327 case DW_TAG_lexical_block
:
14328 return "DW_TAG_lexical_block";
14329 case DW_TAG_member
:
14330 return "DW_TAG_member";
14331 case DW_TAG_pointer_type
:
14332 return "DW_TAG_pointer_type";
14333 case DW_TAG_reference_type
:
14334 return "DW_TAG_reference_type";
14335 case DW_TAG_compile_unit
:
14336 return "DW_TAG_compile_unit";
14337 case DW_TAG_string_type
:
14338 return "DW_TAG_string_type";
14339 case DW_TAG_structure_type
:
14340 return "DW_TAG_structure_type";
14341 case DW_TAG_subroutine_type
:
14342 return "DW_TAG_subroutine_type";
14343 case DW_TAG_typedef
:
14344 return "DW_TAG_typedef";
14345 case DW_TAG_union_type
:
14346 return "DW_TAG_union_type";
14347 case DW_TAG_unspecified_parameters
:
14348 return "DW_TAG_unspecified_parameters";
14349 case DW_TAG_variant
:
14350 return "DW_TAG_variant";
14351 case DW_TAG_common_block
:
14352 return "DW_TAG_common_block";
14353 case DW_TAG_common_inclusion
:
14354 return "DW_TAG_common_inclusion";
14355 case DW_TAG_inheritance
:
14356 return "DW_TAG_inheritance";
14357 case DW_TAG_inlined_subroutine
:
14358 return "DW_TAG_inlined_subroutine";
14359 case DW_TAG_module
:
14360 return "DW_TAG_module";
14361 case DW_TAG_ptr_to_member_type
:
14362 return "DW_TAG_ptr_to_member_type";
14363 case DW_TAG_set_type
:
14364 return "DW_TAG_set_type";
14365 case DW_TAG_subrange_type
:
14366 return "DW_TAG_subrange_type";
14367 case DW_TAG_with_stmt
:
14368 return "DW_TAG_with_stmt";
14369 case DW_TAG_access_declaration
:
14370 return "DW_TAG_access_declaration";
14371 case DW_TAG_base_type
:
14372 return "DW_TAG_base_type";
14373 case DW_TAG_catch_block
:
14374 return "DW_TAG_catch_block";
14375 case DW_TAG_const_type
:
14376 return "DW_TAG_const_type";
14377 case DW_TAG_constant
:
14378 return "DW_TAG_constant";
14379 case DW_TAG_enumerator
:
14380 return "DW_TAG_enumerator";
14381 case DW_TAG_file_type
:
14382 return "DW_TAG_file_type";
14383 case DW_TAG_friend
:
14384 return "DW_TAG_friend";
14385 case DW_TAG_namelist
:
14386 return "DW_TAG_namelist";
14387 case DW_TAG_namelist_item
:
14388 return "DW_TAG_namelist_item";
14389 case DW_TAG_packed_type
:
14390 return "DW_TAG_packed_type";
14391 case DW_TAG_subprogram
:
14392 return "DW_TAG_subprogram";
14393 case DW_TAG_template_type_param
:
14394 return "DW_TAG_template_type_param";
14395 case DW_TAG_template_value_param
:
14396 return "DW_TAG_template_value_param";
14397 case DW_TAG_thrown_type
:
14398 return "DW_TAG_thrown_type";
14399 case DW_TAG_try_block
:
14400 return "DW_TAG_try_block";
14401 case DW_TAG_variant_part
:
14402 return "DW_TAG_variant_part";
14403 case DW_TAG_variable
:
14404 return "DW_TAG_variable";
14405 case DW_TAG_volatile_type
:
14406 return "DW_TAG_volatile_type";
14407 case DW_TAG_dwarf_procedure
:
14408 return "DW_TAG_dwarf_procedure";
14409 case DW_TAG_restrict_type
:
14410 return "DW_TAG_restrict_type";
14411 case DW_TAG_interface_type
:
14412 return "DW_TAG_interface_type";
14413 case DW_TAG_namespace
:
14414 return "DW_TAG_namespace";
14415 case DW_TAG_imported_module
:
14416 return "DW_TAG_imported_module";
14417 case DW_TAG_unspecified_type
:
14418 return "DW_TAG_unspecified_type";
14419 case DW_TAG_partial_unit
:
14420 return "DW_TAG_partial_unit";
14421 case DW_TAG_imported_unit
:
14422 return "DW_TAG_imported_unit";
14423 case DW_TAG_condition
:
14424 return "DW_TAG_condition";
14425 case DW_TAG_shared_type
:
14426 return "DW_TAG_shared_type";
14427 case DW_TAG_type_unit
:
14428 return "DW_TAG_type_unit";
14429 case DW_TAG_MIPS_loop
:
14430 return "DW_TAG_MIPS_loop";
14431 case DW_TAG_HP_array_descriptor
:
14432 return "DW_TAG_HP_array_descriptor";
14433 case DW_TAG_format_label
:
14434 return "DW_TAG_format_label";
14435 case DW_TAG_function_template
:
14436 return "DW_TAG_function_template";
14437 case DW_TAG_class_template
:
14438 return "DW_TAG_class_template";
14439 case DW_TAG_GNU_BINCL
:
14440 return "DW_TAG_GNU_BINCL";
14441 case DW_TAG_GNU_EINCL
:
14442 return "DW_TAG_GNU_EINCL";
14443 case DW_TAG_upc_shared_type
:
14444 return "DW_TAG_upc_shared_type";
14445 case DW_TAG_upc_strict_type
:
14446 return "DW_TAG_upc_strict_type";
14447 case DW_TAG_upc_relaxed_type
:
14448 return "DW_TAG_upc_relaxed_type";
14449 case DW_TAG_PGI_kanji_type
:
14450 return "DW_TAG_PGI_kanji_type";
14451 case DW_TAG_PGI_interface_block
:
14452 return "DW_TAG_PGI_interface_block";
14453 case DW_TAG_GNU_call_site
:
14454 return "DW_TAG_GNU_call_site";
14456 return "DW_TAG_<unknown>";
14460 /* Convert a DWARF attribute code into its string name. */
14463 dwarf_attr_name (unsigned attr
)
14467 case DW_AT_sibling
:
14468 return "DW_AT_sibling";
14469 case DW_AT_location
:
14470 return "DW_AT_location";
14472 return "DW_AT_name";
14473 case DW_AT_ordering
:
14474 return "DW_AT_ordering";
14475 case DW_AT_subscr_data
:
14476 return "DW_AT_subscr_data";
14477 case DW_AT_byte_size
:
14478 return "DW_AT_byte_size";
14479 case DW_AT_bit_offset
:
14480 return "DW_AT_bit_offset";
14481 case DW_AT_bit_size
:
14482 return "DW_AT_bit_size";
14483 case DW_AT_element_list
:
14484 return "DW_AT_element_list";
14485 case DW_AT_stmt_list
:
14486 return "DW_AT_stmt_list";
14488 return "DW_AT_low_pc";
14489 case DW_AT_high_pc
:
14490 return "DW_AT_high_pc";
14491 case DW_AT_language
:
14492 return "DW_AT_language";
14494 return "DW_AT_member";
14496 return "DW_AT_discr";
14497 case DW_AT_discr_value
:
14498 return "DW_AT_discr_value";
14499 case DW_AT_visibility
:
14500 return "DW_AT_visibility";
14502 return "DW_AT_import";
14503 case DW_AT_string_length
:
14504 return "DW_AT_string_length";
14505 case DW_AT_common_reference
:
14506 return "DW_AT_common_reference";
14507 case DW_AT_comp_dir
:
14508 return "DW_AT_comp_dir";
14509 case DW_AT_const_value
:
14510 return "DW_AT_const_value";
14511 case DW_AT_containing_type
:
14512 return "DW_AT_containing_type";
14513 case DW_AT_default_value
:
14514 return "DW_AT_default_value";
14516 return "DW_AT_inline";
14517 case DW_AT_is_optional
:
14518 return "DW_AT_is_optional";
14519 case DW_AT_lower_bound
:
14520 return "DW_AT_lower_bound";
14521 case DW_AT_producer
:
14522 return "DW_AT_producer";
14523 case DW_AT_prototyped
:
14524 return "DW_AT_prototyped";
14525 case DW_AT_return_addr
:
14526 return "DW_AT_return_addr";
14527 case DW_AT_start_scope
:
14528 return "DW_AT_start_scope";
14529 case DW_AT_bit_stride
:
14530 return "DW_AT_bit_stride";
14531 case DW_AT_upper_bound
:
14532 return "DW_AT_upper_bound";
14533 case DW_AT_abstract_origin
:
14534 return "DW_AT_abstract_origin";
14535 case DW_AT_accessibility
:
14536 return "DW_AT_accessibility";
14537 case DW_AT_address_class
:
14538 return "DW_AT_address_class";
14539 case DW_AT_artificial
:
14540 return "DW_AT_artificial";
14541 case DW_AT_base_types
:
14542 return "DW_AT_base_types";
14543 case DW_AT_calling_convention
:
14544 return "DW_AT_calling_convention";
14546 return "DW_AT_count";
14547 case DW_AT_data_member_location
:
14548 return "DW_AT_data_member_location";
14549 case DW_AT_decl_column
:
14550 return "DW_AT_decl_column";
14551 case DW_AT_decl_file
:
14552 return "DW_AT_decl_file";
14553 case DW_AT_decl_line
:
14554 return "DW_AT_decl_line";
14555 case DW_AT_declaration
:
14556 return "DW_AT_declaration";
14557 case DW_AT_discr_list
:
14558 return "DW_AT_discr_list";
14559 case DW_AT_encoding
:
14560 return "DW_AT_encoding";
14561 case DW_AT_external
:
14562 return "DW_AT_external";
14563 case DW_AT_frame_base
:
14564 return "DW_AT_frame_base";
14566 return "DW_AT_friend";
14567 case DW_AT_identifier_case
:
14568 return "DW_AT_identifier_case";
14569 case DW_AT_macro_info
:
14570 return "DW_AT_macro_info";
14571 case DW_AT_namelist_items
:
14572 return "DW_AT_namelist_items";
14573 case DW_AT_priority
:
14574 return "DW_AT_priority";
14575 case DW_AT_segment
:
14576 return "DW_AT_segment";
14577 case DW_AT_specification
:
14578 return "DW_AT_specification";
14579 case DW_AT_static_link
:
14580 return "DW_AT_static_link";
14582 return "DW_AT_type";
14583 case DW_AT_use_location
:
14584 return "DW_AT_use_location";
14585 case DW_AT_variable_parameter
:
14586 return "DW_AT_variable_parameter";
14587 case DW_AT_virtuality
:
14588 return "DW_AT_virtuality";
14589 case DW_AT_vtable_elem_location
:
14590 return "DW_AT_vtable_elem_location";
14591 /* DWARF 3 values. */
14592 case DW_AT_allocated
:
14593 return "DW_AT_allocated";
14594 case DW_AT_associated
:
14595 return "DW_AT_associated";
14596 case DW_AT_data_location
:
14597 return "DW_AT_data_location";
14598 case DW_AT_byte_stride
:
14599 return "DW_AT_byte_stride";
14600 case DW_AT_entry_pc
:
14601 return "DW_AT_entry_pc";
14602 case DW_AT_use_UTF8
:
14603 return "DW_AT_use_UTF8";
14604 case DW_AT_extension
:
14605 return "DW_AT_extension";
14607 return "DW_AT_ranges";
14608 case DW_AT_trampoline
:
14609 return "DW_AT_trampoline";
14610 case DW_AT_call_column
:
14611 return "DW_AT_call_column";
14612 case DW_AT_call_file
:
14613 return "DW_AT_call_file";
14614 case DW_AT_call_line
:
14615 return "DW_AT_call_line";
14616 case DW_AT_description
:
14617 return "DW_AT_description";
14618 case DW_AT_binary_scale
:
14619 return "DW_AT_binary_scale";
14620 case DW_AT_decimal_scale
:
14621 return "DW_AT_decimal_scale";
14623 return "DW_AT_small";
14624 case DW_AT_decimal_sign
:
14625 return "DW_AT_decimal_sign";
14626 case DW_AT_digit_count
:
14627 return "DW_AT_digit_count";
14628 case DW_AT_picture_string
:
14629 return "DW_AT_picture_string";
14630 case DW_AT_mutable
:
14631 return "DW_AT_mutable";
14632 case DW_AT_threads_scaled
:
14633 return "DW_AT_threads_scaled";
14634 case DW_AT_explicit
:
14635 return "DW_AT_explicit";
14636 case DW_AT_object_pointer
:
14637 return "DW_AT_object_pointer";
14638 case DW_AT_endianity
:
14639 return "DW_AT_endianity";
14640 case DW_AT_elemental
:
14641 return "DW_AT_elemental";
14643 return "DW_AT_pure";
14644 case DW_AT_recursive
:
14645 return "DW_AT_recursive";
14646 /* DWARF 4 values. */
14647 case DW_AT_signature
:
14648 return "DW_AT_signature";
14649 case DW_AT_linkage_name
:
14650 return "DW_AT_linkage_name";
14651 /* Tentative Fission values. */
14652 case DW_AT_GNU_dwo_name
:
14653 return "DW_AT_GNU_dwo_name";
14654 case DW_AT_GNU_dwo_id
:
14655 return "DW_AT_GNU_dwo_id";
14656 case DW_AT_GNU_addr_base
:
14657 return "DW_AT_GNU_addr_base";
14658 case DW_AT_GNU_pubnames
:
14659 return "DW_AT_GNU_pubnames";
14660 case DW_AT_GNU_pubtypes
:
14661 return "DW_AT_GNU_pubtypes";
14662 /* SGI/MIPS extensions. */
14663 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14664 case DW_AT_MIPS_fde
:
14665 return "DW_AT_MIPS_fde";
14667 case DW_AT_MIPS_loop_begin
:
14668 return "DW_AT_MIPS_loop_begin";
14669 case DW_AT_MIPS_tail_loop_begin
:
14670 return "DW_AT_MIPS_tail_loop_begin";
14671 case DW_AT_MIPS_epilog_begin
:
14672 return "DW_AT_MIPS_epilog_begin";
14673 case DW_AT_MIPS_loop_unroll_factor
:
14674 return "DW_AT_MIPS_loop_unroll_factor";
14675 case DW_AT_MIPS_software_pipeline_depth
:
14676 return "DW_AT_MIPS_software_pipeline_depth";
14677 case DW_AT_MIPS_linkage_name
:
14678 return "DW_AT_MIPS_linkage_name";
14679 case DW_AT_MIPS_stride
:
14680 return "DW_AT_MIPS_stride";
14681 case DW_AT_MIPS_abstract_name
:
14682 return "DW_AT_MIPS_abstract_name";
14683 case DW_AT_MIPS_clone_origin
:
14684 return "DW_AT_MIPS_clone_origin";
14685 case DW_AT_MIPS_has_inlines
:
14686 return "DW_AT_MIPS_has_inlines";
14687 /* HP extensions. */
14688 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
14689 case DW_AT_HP_block_index
:
14690 return "DW_AT_HP_block_index";
14692 case DW_AT_HP_unmodifiable
:
14693 return "DW_AT_HP_unmodifiable";
14694 case DW_AT_HP_actuals_stmt_list
:
14695 return "DW_AT_HP_actuals_stmt_list";
14696 case DW_AT_HP_proc_per_section
:
14697 return "DW_AT_HP_proc_per_section";
14698 case DW_AT_HP_raw_data_ptr
:
14699 return "DW_AT_HP_raw_data_ptr";
14700 case DW_AT_HP_pass_by_reference
:
14701 return "DW_AT_HP_pass_by_reference";
14702 case DW_AT_HP_opt_level
:
14703 return "DW_AT_HP_opt_level";
14704 case DW_AT_HP_prof_version_id
:
14705 return "DW_AT_HP_prof_version_id";
14706 case DW_AT_HP_opt_flags
:
14707 return "DW_AT_HP_opt_flags";
14708 case DW_AT_HP_cold_region_low_pc
:
14709 return "DW_AT_HP_cold_region_low_pc";
14710 case DW_AT_HP_cold_region_high_pc
:
14711 return "DW_AT_HP_cold_region_high_pc";
14712 case DW_AT_HP_all_variables_modifiable
:
14713 return "DW_AT_HP_all_variables_modifiable";
14714 case DW_AT_HP_linkage_name
:
14715 return "DW_AT_HP_linkage_name";
14716 case DW_AT_HP_prof_flags
:
14717 return "DW_AT_HP_prof_flags";
14718 /* GNU extensions. */
14719 case DW_AT_sf_names
:
14720 return "DW_AT_sf_names";
14721 case DW_AT_src_info
:
14722 return "DW_AT_src_info";
14723 case DW_AT_mac_info
:
14724 return "DW_AT_mac_info";
14725 case DW_AT_src_coords
:
14726 return "DW_AT_src_coords";
14727 case DW_AT_body_begin
:
14728 return "DW_AT_body_begin";
14729 case DW_AT_body_end
:
14730 return "DW_AT_body_end";
14731 case DW_AT_GNU_vector
:
14732 return "DW_AT_GNU_vector";
14733 case DW_AT_GNU_odr_signature
:
14734 return "DW_AT_GNU_odr_signature";
14735 /* VMS extensions. */
14736 case DW_AT_VMS_rtnbeg_pd_address
:
14737 return "DW_AT_VMS_rtnbeg_pd_address";
14738 /* UPC extension. */
14739 case DW_AT_upc_threads_scaled
:
14740 return "DW_AT_upc_threads_scaled";
14741 /* PGI (STMicroelectronics) extensions. */
14742 case DW_AT_PGI_lbase
:
14743 return "DW_AT_PGI_lbase";
14744 case DW_AT_PGI_soffset
:
14745 return "DW_AT_PGI_soffset";
14746 case DW_AT_PGI_lstride
:
14747 return "DW_AT_PGI_lstride";
14749 return "DW_AT_<unknown>";
14753 /* Convert a DWARF value form code into its string name. */
14756 dwarf_form_name (unsigned form
)
14761 return "DW_FORM_addr";
14762 case DW_FORM_block2
:
14763 return "DW_FORM_block2";
14764 case DW_FORM_block4
:
14765 return "DW_FORM_block4";
14766 case DW_FORM_data2
:
14767 return "DW_FORM_data2";
14768 case DW_FORM_data4
:
14769 return "DW_FORM_data4";
14770 case DW_FORM_data8
:
14771 return "DW_FORM_data8";
14772 case DW_FORM_string
:
14773 return "DW_FORM_string";
14774 case DW_FORM_block
:
14775 return "DW_FORM_block";
14776 case DW_FORM_block1
:
14777 return "DW_FORM_block1";
14778 case DW_FORM_data1
:
14779 return "DW_FORM_data1";
14781 return "DW_FORM_flag";
14782 case DW_FORM_sdata
:
14783 return "DW_FORM_sdata";
14785 return "DW_FORM_strp";
14786 case DW_FORM_udata
:
14787 return "DW_FORM_udata";
14788 case DW_FORM_ref_addr
:
14789 return "DW_FORM_ref_addr";
14791 return "DW_FORM_ref1";
14793 return "DW_FORM_ref2";
14795 return "DW_FORM_ref4";
14797 return "DW_FORM_ref8";
14798 case DW_FORM_ref_udata
:
14799 return "DW_FORM_ref_udata";
14800 case DW_FORM_indirect
:
14801 return "DW_FORM_indirect";
14802 case DW_FORM_sec_offset
:
14803 return "DW_FORM_sec_offset";
14804 case DW_FORM_exprloc
:
14805 return "DW_FORM_exprloc";
14806 case DW_FORM_flag_present
:
14807 return "DW_FORM_flag_present";
14808 case DW_FORM_ref_sig8
:
14809 return "DW_FORM_ref_sig8";
14810 case DW_FORM_GNU_addr_index
:
14811 return "DW_FORM_GNU_addr_index";
14812 case DW_FORM_GNU_str_index
:
14813 return "DW_FORM_GNU_str_index";
14815 return "DW_FORM_<unknown>";
14819 /* Convert a DWARF stack opcode into its string name. */
14822 dwarf_stack_op_name (unsigned op
)
14827 return "DW_OP_addr";
14829 return "DW_OP_deref";
14830 case DW_OP_const1u
:
14831 return "DW_OP_const1u";
14832 case DW_OP_const1s
:
14833 return "DW_OP_const1s";
14834 case DW_OP_const2u
:
14835 return "DW_OP_const2u";
14836 case DW_OP_const2s
:
14837 return "DW_OP_const2s";
14838 case DW_OP_const4u
:
14839 return "DW_OP_const4u";
14840 case DW_OP_const4s
:
14841 return "DW_OP_const4s";
14842 case DW_OP_const8u
:
14843 return "DW_OP_const8u";
14844 case DW_OP_const8s
:
14845 return "DW_OP_const8s";
14847 return "DW_OP_constu";
14849 return "DW_OP_consts";
14851 return "DW_OP_dup";
14853 return "DW_OP_drop";
14855 return "DW_OP_over";
14857 return "DW_OP_pick";
14859 return "DW_OP_swap";
14861 return "DW_OP_rot";
14863 return "DW_OP_xderef";
14865 return "DW_OP_abs";
14867 return "DW_OP_and";
14869 return "DW_OP_div";
14871 return "DW_OP_minus";
14873 return "DW_OP_mod";
14875 return "DW_OP_mul";
14877 return "DW_OP_neg";
14879 return "DW_OP_not";
14883 return "DW_OP_plus";
14884 case DW_OP_plus_uconst
:
14885 return "DW_OP_plus_uconst";
14887 return "DW_OP_shl";
14889 return "DW_OP_shr";
14891 return "DW_OP_shra";
14893 return "DW_OP_xor";
14895 return "DW_OP_bra";
14909 return "DW_OP_skip";
14911 return "DW_OP_lit0";
14913 return "DW_OP_lit1";
14915 return "DW_OP_lit2";
14917 return "DW_OP_lit3";
14919 return "DW_OP_lit4";
14921 return "DW_OP_lit5";
14923 return "DW_OP_lit6";
14925 return "DW_OP_lit7";
14927 return "DW_OP_lit8";
14929 return "DW_OP_lit9";
14931 return "DW_OP_lit10";
14933 return "DW_OP_lit11";
14935 return "DW_OP_lit12";
14937 return "DW_OP_lit13";
14939 return "DW_OP_lit14";
14941 return "DW_OP_lit15";
14943 return "DW_OP_lit16";
14945 return "DW_OP_lit17";
14947 return "DW_OP_lit18";
14949 return "DW_OP_lit19";
14951 return "DW_OP_lit20";
14953 return "DW_OP_lit21";
14955 return "DW_OP_lit22";
14957 return "DW_OP_lit23";
14959 return "DW_OP_lit24";
14961 return "DW_OP_lit25";
14963 return "DW_OP_lit26";
14965 return "DW_OP_lit27";
14967 return "DW_OP_lit28";
14969 return "DW_OP_lit29";
14971 return "DW_OP_lit30";
14973 return "DW_OP_lit31";
14975 return "DW_OP_reg0";
14977 return "DW_OP_reg1";
14979 return "DW_OP_reg2";
14981 return "DW_OP_reg3";
14983 return "DW_OP_reg4";
14985 return "DW_OP_reg5";
14987 return "DW_OP_reg6";
14989 return "DW_OP_reg7";
14991 return "DW_OP_reg8";
14993 return "DW_OP_reg9";
14995 return "DW_OP_reg10";
14997 return "DW_OP_reg11";
14999 return "DW_OP_reg12";
15001 return "DW_OP_reg13";
15003 return "DW_OP_reg14";
15005 return "DW_OP_reg15";
15007 return "DW_OP_reg16";
15009 return "DW_OP_reg17";
15011 return "DW_OP_reg18";
15013 return "DW_OP_reg19";
15015 return "DW_OP_reg20";
15017 return "DW_OP_reg21";
15019 return "DW_OP_reg22";
15021 return "DW_OP_reg23";
15023 return "DW_OP_reg24";
15025 return "DW_OP_reg25";
15027 return "DW_OP_reg26";
15029 return "DW_OP_reg27";
15031 return "DW_OP_reg28";
15033 return "DW_OP_reg29";
15035 return "DW_OP_reg30";
15037 return "DW_OP_reg31";
15039 return "DW_OP_breg0";
15041 return "DW_OP_breg1";
15043 return "DW_OP_breg2";
15045 return "DW_OP_breg3";
15047 return "DW_OP_breg4";
15049 return "DW_OP_breg5";
15051 return "DW_OP_breg6";
15053 return "DW_OP_breg7";
15055 return "DW_OP_breg8";
15057 return "DW_OP_breg9";
15059 return "DW_OP_breg10";
15061 return "DW_OP_breg11";
15063 return "DW_OP_breg12";
15065 return "DW_OP_breg13";
15067 return "DW_OP_breg14";
15069 return "DW_OP_breg15";
15071 return "DW_OP_breg16";
15073 return "DW_OP_breg17";
15075 return "DW_OP_breg18";
15077 return "DW_OP_breg19";
15079 return "DW_OP_breg20";
15081 return "DW_OP_breg21";
15083 return "DW_OP_breg22";
15085 return "DW_OP_breg23";
15087 return "DW_OP_breg24";
15089 return "DW_OP_breg25";
15091 return "DW_OP_breg26";
15093 return "DW_OP_breg27";
15095 return "DW_OP_breg28";
15097 return "DW_OP_breg29";
15099 return "DW_OP_breg30";
15101 return "DW_OP_breg31";
15103 return "DW_OP_regx";
15105 return "DW_OP_fbreg";
15107 return "DW_OP_bregx";
15109 return "DW_OP_piece";
15110 case DW_OP_deref_size
:
15111 return "DW_OP_deref_size";
15112 case DW_OP_xderef_size
:
15113 return "DW_OP_xderef_size";
15115 return "DW_OP_nop";
15116 /* DWARF 3 extensions. */
15117 case DW_OP_push_object_address
:
15118 return "DW_OP_push_object_address";
15120 return "DW_OP_call2";
15122 return "DW_OP_call4";
15123 case DW_OP_call_ref
:
15124 return "DW_OP_call_ref";
15125 case DW_OP_form_tls_address
:
15126 return "DW_OP_form_tls_address";
15127 case DW_OP_call_frame_cfa
:
15128 return "DW_OP_call_frame_cfa";
15129 case DW_OP_bit_piece
:
15130 return "DW_OP_bit_piece";
15131 /* DWARF 4 extensions. */
15132 case DW_OP_implicit_value
:
15133 return "DW_OP_implicit_value";
15134 case DW_OP_stack_value
:
15135 return "DW_OP_stack_value";
15136 /* GNU extensions. */
15137 case DW_OP_GNU_push_tls_address
:
15138 return "DW_OP_GNU_push_tls_address";
15139 case DW_OP_GNU_uninit
:
15140 return "DW_OP_GNU_uninit";
15141 case DW_OP_GNU_encoded_addr
:
15142 return "DW_OP_GNU_encoded_addr";
15143 case DW_OP_GNU_implicit_pointer
:
15144 return "DW_OP_GNU_implicit_pointer";
15145 case DW_OP_GNU_entry_value
:
15146 return "DW_OP_GNU_entry_value";
15147 case DW_OP_GNU_const_type
:
15148 return "DW_OP_GNU_const_type";
15149 case DW_OP_GNU_regval_type
:
15150 return "DW_OP_GNU_regval_type";
15151 case DW_OP_GNU_deref_type
:
15152 return "DW_OP_GNU_deref_type";
15153 case DW_OP_GNU_convert
:
15154 return "DW_OP_GNU_convert";
15155 case DW_OP_GNU_reinterpret
:
15156 return "DW_OP_GNU_reinterpret";
15157 case DW_OP_GNU_parameter_ref
:
15158 return "DW_OP_GNU_parameter_ref";
15165 dwarf_bool_name (unsigned mybool
)
15173 /* Convert a DWARF type code into its string name. */
15176 dwarf_type_encoding_name (unsigned enc
)
15181 return "DW_ATE_void";
15182 case DW_ATE_address
:
15183 return "DW_ATE_address";
15184 case DW_ATE_boolean
:
15185 return "DW_ATE_boolean";
15186 case DW_ATE_complex_float
:
15187 return "DW_ATE_complex_float";
15189 return "DW_ATE_float";
15190 case DW_ATE_signed
:
15191 return "DW_ATE_signed";
15192 case DW_ATE_signed_char
:
15193 return "DW_ATE_signed_char";
15194 case DW_ATE_unsigned
:
15195 return "DW_ATE_unsigned";
15196 case DW_ATE_unsigned_char
:
15197 return "DW_ATE_unsigned_char";
15199 case DW_ATE_imaginary_float
:
15200 return "DW_ATE_imaginary_float";
15201 case DW_ATE_packed_decimal
:
15202 return "DW_ATE_packed_decimal";
15203 case DW_ATE_numeric_string
:
15204 return "DW_ATE_numeric_string";
15205 case DW_ATE_edited
:
15206 return "DW_ATE_edited";
15207 case DW_ATE_signed_fixed
:
15208 return "DW_ATE_signed_fixed";
15209 case DW_ATE_unsigned_fixed
:
15210 return "DW_ATE_unsigned_fixed";
15211 case DW_ATE_decimal_float
:
15212 return "DW_ATE_decimal_float";
15215 return "DW_ATE_UTF";
15216 /* HP extensions. */
15217 case DW_ATE_HP_float80
:
15218 return "DW_ATE_HP_float80";
15219 case DW_ATE_HP_complex_float80
:
15220 return "DW_ATE_HP_complex_float80";
15221 case DW_ATE_HP_float128
:
15222 return "DW_ATE_HP_float128";
15223 case DW_ATE_HP_complex_float128
:
15224 return "DW_ATE_HP_complex_float128";
15225 case DW_ATE_HP_floathpintel
:
15226 return "DW_ATE_HP_floathpintel";
15227 case DW_ATE_HP_imaginary_float80
:
15228 return "DW_ATE_HP_imaginary_float80";
15229 case DW_ATE_HP_imaginary_float128
:
15230 return "DW_ATE_HP_imaginary_float128";
15232 return "DW_ATE_<unknown>";
15236 /* Convert a DWARF call frame info operation to its string name. */
15240 dwarf_cfi_name (unsigned cfi_opc
)
15244 case DW_CFA_advance_loc
:
15245 return "DW_CFA_advance_loc";
15246 case DW_CFA_offset
:
15247 return "DW_CFA_offset";
15248 case DW_CFA_restore
:
15249 return "DW_CFA_restore";
15251 return "DW_CFA_nop";
15252 case DW_CFA_set_loc
:
15253 return "DW_CFA_set_loc";
15254 case DW_CFA_advance_loc1
:
15255 return "DW_CFA_advance_loc1";
15256 case DW_CFA_advance_loc2
:
15257 return "DW_CFA_advance_loc2";
15258 case DW_CFA_advance_loc4
:
15259 return "DW_CFA_advance_loc4";
15260 case DW_CFA_offset_extended
:
15261 return "DW_CFA_offset_extended";
15262 case DW_CFA_restore_extended
:
15263 return "DW_CFA_restore_extended";
15264 case DW_CFA_undefined
:
15265 return "DW_CFA_undefined";
15266 case DW_CFA_same_value
:
15267 return "DW_CFA_same_value";
15268 case DW_CFA_register
:
15269 return "DW_CFA_register";
15270 case DW_CFA_remember_state
:
15271 return "DW_CFA_remember_state";
15272 case DW_CFA_restore_state
:
15273 return "DW_CFA_restore_state";
15274 case DW_CFA_def_cfa
:
15275 return "DW_CFA_def_cfa";
15276 case DW_CFA_def_cfa_register
:
15277 return "DW_CFA_def_cfa_register";
15278 case DW_CFA_def_cfa_offset
:
15279 return "DW_CFA_def_cfa_offset";
15281 case DW_CFA_def_cfa_expression
:
15282 return "DW_CFA_def_cfa_expression";
15283 case DW_CFA_expression
:
15284 return "DW_CFA_expression";
15285 case DW_CFA_offset_extended_sf
:
15286 return "DW_CFA_offset_extended_sf";
15287 case DW_CFA_def_cfa_sf
:
15288 return "DW_CFA_def_cfa_sf";
15289 case DW_CFA_def_cfa_offset_sf
:
15290 return "DW_CFA_def_cfa_offset_sf";
15291 case DW_CFA_val_offset
:
15292 return "DW_CFA_val_offset";
15293 case DW_CFA_val_offset_sf
:
15294 return "DW_CFA_val_offset_sf";
15295 case DW_CFA_val_expression
:
15296 return "DW_CFA_val_expression";
15297 /* SGI/MIPS specific. */
15298 case DW_CFA_MIPS_advance_loc8
:
15299 return "DW_CFA_MIPS_advance_loc8";
15300 /* GNU extensions. */
15301 case DW_CFA_GNU_window_save
:
15302 return "DW_CFA_GNU_window_save";
15303 case DW_CFA_GNU_args_size
:
15304 return "DW_CFA_GNU_args_size";
15305 case DW_CFA_GNU_negative_offset_extended
:
15306 return "DW_CFA_GNU_negative_offset_extended";
15308 return "DW_CFA_<unknown>";
15314 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15318 print_spaces (indent
, f
);
15319 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15320 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15322 if (die
->parent
!= NULL
)
15324 print_spaces (indent
, f
);
15325 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15326 die
->parent
->offset
.sect_off
);
15329 print_spaces (indent
, f
);
15330 fprintf_unfiltered (f
, " has children: %s\n",
15331 dwarf_bool_name (die
->child
!= NULL
));
15333 print_spaces (indent
, f
);
15334 fprintf_unfiltered (f
, " attributes:\n");
15336 for (i
= 0; i
< die
->num_attrs
; ++i
)
15338 print_spaces (indent
, f
);
15339 fprintf_unfiltered (f
, " %s (%s) ",
15340 dwarf_attr_name (die
->attrs
[i
].name
),
15341 dwarf_form_name (die
->attrs
[i
].form
));
15343 switch (die
->attrs
[i
].form
)
15346 case DW_FORM_GNU_addr_index
:
15347 fprintf_unfiltered (f
, "address: ");
15348 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15350 case DW_FORM_block2
:
15351 case DW_FORM_block4
:
15352 case DW_FORM_block
:
15353 case DW_FORM_block1
:
15354 fprintf_unfiltered (f
, "block: size %d",
15355 DW_BLOCK (&die
->attrs
[i
])->size
);
15357 case DW_FORM_exprloc
:
15358 fprintf_unfiltered (f
, "expression: size %u",
15359 DW_BLOCK (&die
->attrs
[i
])->size
);
15361 case DW_FORM_ref_addr
:
15362 fprintf_unfiltered (f
, "ref address: ");
15363 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15369 case DW_FORM_ref_udata
:
15370 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15371 (long) (DW_UNSND (&die
->attrs
[i
])));
15373 case DW_FORM_data1
:
15374 case DW_FORM_data2
:
15375 case DW_FORM_data4
:
15376 case DW_FORM_data8
:
15377 case DW_FORM_udata
:
15378 case DW_FORM_sdata
:
15379 fprintf_unfiltered (f
, "constant: %s",
15380 pulongest (DW_UNSND (&die
->attrs
[i
])));
15382 case DW_FORM_sec_offset
:
15383 fprintf_unfiltered (f
, "section offset: %s",
15384 pulongest (DW_UNSND (&die
->attrs
[i
])));
15386 case DW_FORM_ref_sig8
:
15387 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15388 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15389 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15391 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15393 case DW_FORM_string
:
15395 case DW_FORM_GNU_str_index
:
15396 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15397 DW_STRING (&die
->attrs
[i
])
15398 ? DW_STRING (&die
->attrs
[i
]) : "",
15399 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15402 if (DW_UNSND (&die
->attrs
[i
]))
15403 fprintf_unfiltered (f
, "flag: TRUE");
15405 fprintf_unfiltered (f
, "flag: FALSE");
15407 case DW_FORM_flag_present
:
15408 fprintf_unfiltered (f
, "flag: TRUE");
15410 case DW_FORM_indirect
:
15411 /* The reader will have reduced the indirect form to
15412 the "base form" so this form should not occur. */
15413 fprintf_unfiltered (f
,
15414 "unexpected attribute form: DW_FORM_indirect");
15417 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15418 die
->attrs
[i
].form
);
15421 fprintf_unfiltered (f
, "\n");
15426 dump_die_for_error (struct die_info
*die
)
15428 dump_die_shallow (gdb_stderr
, 0, die
);
15432 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15434 int indent
= level
* 4;
15436 gdb_assert (die
!= NULL
);
15438 if (level
>= max_level
)
15441 dump_die_shallow (f
, indent
, die
);
15443 if (die
->child
!= NULL
)
15445 print_spaces (indent
, f
);
15446 fprintf_unfiltered (f
, " Children:");
15447 if (level
+ 1 < max_level
)
15449 fprintf_unfiltered (f
, "\n");
15450 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15454 fprintf_unfiltered (f
,
15455 " [not printed, max nesting level reached]\n");
15459 if (die
->sibling
!= NULL
&& level
> 0)
15461 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15465 /* This is called from the pdie macro in gdbinit.in.
15466 It's not static so gcc will keep a copy callable from gdb. */
15469 dump_die (struct die_info
*die
, int max_level
)
15471 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15475 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15479 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15485 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15486 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15489 is_ref_attr (struct attribute
*attr
)
15491 switch (attr
->form
)
15493 case DW_FORM_ref_addr
:
15498 case DW_FORM_ref_udata
:
15505 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15509 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15511 sect_offset retval
= { DW_UNSND (attr
) };
15513 if (is_ref_attr (attr
))
15516 retval
.sect_off
= 0;
15517 complaint (&symfile_complaints
,
15518 _("unsupported die ref attribute form: '%s'"),
15519 dwarf_form_name (attr
->form
));
15523 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15524 * the value held by the attribute is not constant. */
15527 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15529 if (attr
->form
== DW_FORM_sdata
)
15530 return DW_SND (attr
);
15531 else if (attr
->form
== DW_FORM_udata
15532 || attr
->form
== DW_FORM_data1
15533 || attr
->form
== DW_FORM_data2
15534 || attr
->form
== DW_FORM_data4
15535 || attr
->form
== DW_FORM_data8
)
15536 return DW_UNSND (attr
);
15539 complaint (&symfile_complaints
,
15540 _("Attribute value is not a constant (%s)"),
15541 dwarf_form_name (attr
->form
));
15542 return default_value
;
15546 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15547 unit and add it to our queue.
15548 The result is non-zero if PER_CU was queued, otherwise the result is zero
15549 meaning either PER_CU is already queued or it is already loaded. */
15552 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15553 struct dwarf2_per_cu_data
*per_cu
)
15555 /* We may arrive here during partial symbol reading, if we need full
15556 DIEs to process an unusual case (e.g. template arguments). Do
15557 not queue PER_CU, just tell our caller to load its DIEs. */
15558 if (dwarf2_per_objfile
->reading_partial_symbols
)
15560 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15565 /* Mark the dependence relation so that we don't flush PER_CU
15567 dwarf2_add_dependence (this_cu
, per_cu
);
15569 /* If it's already on the queue, we have nothing to do. */
15570 if (per_cu
->queued
)
15573 /* If the compilation unit is already loaded, just mark it as
15575 if (per_cu
->cu
!= NULL
)
15577 per_cu
->cu
->last_used
= 0;
15581 /* Add it to the queue. */
15582 queue_comp_unit (per_cu
);
15587 /* Follow reference or signature attribute ATTR of SRC_DIE.
15588 On entry *REF_CU is the CU of SRC_DIE.
15589 On exit *REF_CU is the CU of the result. */
15591 static struct die_info
*
15592 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15593 struct dwarf2_cu
**ref_cu
)
15595 struct die_info
*die
;
15597 if (is_ref_attr (attr
))
15598 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15599 else if (attr
->form
== DW_FORM_ref_sig8
)
15600 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15603 dump_die_for_error (src_die
);
15604 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15605 (*ref_cu
)->objfile
->name
);
15611 /* Follow reference OFFSET.
15612 On entry *REF_CU is the CU of the source die referencing OFFSET.
15613 On exit *REF_CU is the CU of the result.
15614 Returns NULL if OFFSET is invalid. */
15616 static struct die_info
*
15617 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15619 struct die_info temp_die
;
15620 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15622 gdb_assert (cu
->per_cu
!= NULL
);
15626 if (cu
->per_cu
->is_debug_types
)
15628 /* .debug_types CUs cannot reference anything outside their CU.
15629 If they need to, they have to reference a signatured type via
15630 DW_FORM_ref_sig8. */
15631 if (! offset_in_cu_p (&cu
->header
, offset
))
15634 else if (! offset_in_cu_p (&cu
->header
, offset
))
15636 struct dwarf2_per_cu_data
*per_cu
;
15638 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15640 /* If necessary, add it to the queue and load its DIEs. */
15641 if (maybe_queue_comp_unit (cu
, per_cu
))
15642 load_full_comp_unit (per_cu
);
15644 target_cu
= per_cu
->cu
;
15646 else if (cu
->dies
== NULL
)
15648 /* We're loading full DIEs during partial symbol reading. */
15649 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15650 load_full_comp_unit (cu
->per_cu
);
15653 *ref_cu
= target_cu
;
15654 temp_die
.offset
= offset
;
15655 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15658 /* Follow reference attribute ATTR of SRC_DIE.
15659 On entry *REF_CU is the CU of SRC_DIE.
15660 On exit *REF_CU is the CU of the result. */
15662 static struct die_info
*
15663 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15664 struct dwarf2_cu
**ref_cu
)
15666 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15667 struct dwarf2_cu
*cu
= *ref_cu
;
15668 struct die_info
*die
;
15670 die
= follow_die_offset (offset
, ref_cu
);
15672 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15673 "at 0x%x [in module %s]"),
15674 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15679 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15680 Returned value is intended for DW_OP_call*. Returned
15681 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15683 struct dwarf2_locexpr_baton
15684 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15685 struct dwarf2_per_cu_data
*per_cu
,
15686 CORE_ADDR (*get_frame_pc
) (void *baton
),
15689 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15690 struct dwarf2_cu
*cu
;
15691 struct die_info
*die
;
15692 struct attribute
*attr
;
15693 struct dwarf2_locexpr_baton retval
;
15695 dw2_setup (per_cu
->objfile
);
15697 if (per_cu
->cu
== NULL
)
15701 die
= follow_die_offset (offset
, &cu
);
15703 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15704 offset
.sect_off
, per_cu
->objfile
->name
);
15706 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15709 /* DWARF: "If there is no such attribute, then there is no effect.".
15710 DATA is ignored if SIZE is 0. */
15712 retval
.data
= NULL
;
15715 else if (attr_form_is_section_offset (attr
))
15717 struct dwarf2_loclist_baton loclist_baton
;
15718 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15721 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15723 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15725 retval
.size
= size
;
15729 if (!attr_form_is_block (attr
))
15730 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15731 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15732 offset
.sect_off
, per_cu
->objfile
->name
);
15734 retval
.data
= DW_BLOCK (attr
)->data
;
15735 retval
.size
= DW_BLOCK (attr
)->size
;
15737 retval
.per_cu
= cu
->per_cu
;
15739 age_cached_comp_units ();
15744 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15748 dwarf2_get_die_type (cu_offset die_offset
,
15749 struct dwarf2_per_cu_data
*per_cu
)
15751 sect_offset die_offset_sect
;
15753 dw2_setup (per_cu
->objfile
);
15755 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15756 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15759 /* Follow the signature attribute ATTR in SRC_DIE.
15760 On entry *REF_CU is the CU of SRC_DIE.
15761 On exit *REF_CU is the CU of the result. */
15763 static struct die_info
*
15764 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15765 struct dwarf2_cu
**ref_cu
)
15767 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15768 struct die_info temp_die
;
15769 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15770 struct dwarf2_cu
*sig_cu
;
15771 struct die_info
*die
;
15773 /* sig_type will be NULL if the signatured type is missing from
15775 if (sig_type
== NULL
)
15776 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15777 "at 0x%x [in module %s]"),
15778 src_die
->offset
.sect_off
, objfile
->name
);
15780 /* If necessary, add it to the queue and load its DIEs. */
15782 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
15783 read_signatured_type (sig_type
);
15785 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15787 sig_cu
= sig_type
->per_cu
.cu
;
15788 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15789 temp_die
.offset
= sig_type
->type_offset_in_section
;
15790 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15791 temp_die
.offset
.sect_off
);
15798 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15799 "from DIE at 0x%x [in module %s]"),
15800 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15803 /* Given an offset of a signatured type, return its signatured_type. */
15805 static struct signatured_type
*
15806 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15807 struct dwarf2_section_info
*section
,
15808 sect_offset offset
)
15810 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15811 unsigned int length
, initial_length_size
;
15812 unsigned int sig_offset
;
15813 struct signatured_type find_entry
, *sig_type
;
15815 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15816 sig_offset
= (initial_length_size
15818 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15819 + 1 /*address_size*/);
15820 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15821 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15823 /* This is only used to lookup previously recorded types.
15824 If we didn't find it, it's our bug. */
15825 gdb_assert (sig_type
!= NULL
);
15826 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15831 /* Load the DIEs associated with type unit PER_CU into memory. */
15834 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15836 struct objfile
*objfile
= per_cu
->objfile
;
15837 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15838 sect_offset offset
= per_cu
->offset
;
15839 struct signatured_type
*sig_type
;
15841 dwarf2_read_section (objfile
, sect
);
15843 /* We have the section offset, but we need the signature to do the
15844 hash table lookup. */
15845 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15846 the signature to assert we found the right one.
15847 Ok, but it's a lot of work. We should simplify things so any needed
15848 assert doesn't require all this clumsiness. */
15849 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15851 gdb_assert (&sig_type
->per_cu
== per_cu
);
15852 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15854 read_signatured_type (sig_type
);
15856 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15859 /* die_reader_func for read_signatured_type.
15860 This is identical to load_full_comp_unit_reader,
15861 but is kept separate for now. */
15864 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15865 gdb_byte
*info_ptr
,
15866 struct die_info
*comp_unit_die
,
15870 struct dwarf2_cu
*cu
= reader
->cu
;
15871 struct attribute
*attr
;
15873 gdb_assert (cu
->die_hash
== NULL
);
15875 htab_create_alloc_ex (cu
->header
.length
/ 12,
15879 &cu
->comp_unit_obstack
,
15880 hashtab_obstack_allocate
,
15881 dummy_obstack_deallocate
);
15884 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15885 &info_ptr
, comp_unit_die
);
15886 cu
->dies
= comp_unit_die
;
15887 /* comp_unit_die is not stored in die_hash, no need. */
15889 /* We try not to read any attributes in this function, because not
15890 all CUs needed for references have been loaded yet, and symbol
15891 table processing isn't initialized. But we have to set the CU language,
15892 or we won't be able to build types correctly.
15893 Similarly, if we do not read the producer, we can not apply
15894 producer-specific interpretation. */
15895 prepare_one_comp_unit (cu
, cu
->dies
);
15898 /* Read in a signatured type and build its CU and DIEs.
15899 If the type is a stub for the real type in a DWO file,
15900 read in the real type from the DWO file as well. */
15903 read_signatured_type (struct signatured_type
*sig_type
)
15905 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15907 gdb_assert (per_cu
->is_debug_types
);
15908 gdb_assert (per_cu
->cu
== NULL
);
15910 init_tu_and_read_dies (per_cu
, 1, read_signatured_type_reader
, NULL
);
15913 /* Decode simple location descriptions.
15914 Given a pointer to a dwarf block that defines a location, compute
15915 the location and return the value.
15917 NOTE drow/2003-11-18: This function is called in two situations
15918 now: for the address of static or global variables (partial symbols
15919 only) and for offsets into structures which are expected to be
15920 (more or less) constant. The partial symbol case should go away,
15921 and only the constant case should remain. That will let this
15922 function complain more accurately. A few special modes are allowed
15923 without complaint for global variables (for instance, global
15924 register values and thread-local values).
15926 A location description containing no operations indicates that the
15927 object is optimized out. The return value is 0 for that case.
15928 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15929 callers will only want a very basic result and this can become a
15932 Note that stack[0] is unused except as a default error return. */
15935 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15937 struct objfile
*objfile
= cu
->objfile
;
15939 int size
= blk
->size
;
15940 gdb_byte
*data
= blk
->data
;
15941 CORE_ADDR stack
[64];
15943 unsigned int bytes_read
, unsnd
;
15949 stack
[++stacki
] = 0;
15988 stack
[++stacki
] = op
- DW_OP_lit0
;
16023 stack
[++stacki
] = op
- DW_OP_reg0
;
16025 dwarf2_complex_location_expr_complaint ();
16029 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16031 stack
[++stacki
] = unsnd
;
16033 dwarf2_complex_location_expr_complaint ();
16037 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16042 case DW_OP_const1u
:
16043 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16047 case DW_OP_const1s
:
16048 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16052 case DW_OP_const2u
:
16053 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16057 case DW_OP_const2s
:
16058 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16062 case DW_OP_const4u
:
16063 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16067 case DW_OP_const4s
:
16068 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16072 case DW_OP_const8u
:
16073 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16078 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16084 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16089 stack
[stacki
+ 1] = stack
[stacki
];
16094 stack
[stacki
- 1] += stack
[stacki
];
16098 case DW_OP_plus_uconst
:
16099 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16105 stack
[stacki
- 1] -= stack
[stacki
];
16110 /* If we're not the last op, then we definitely can't encode
16111 this using GDB's address_class enum. This is valid for partial
16112 global symbols, although the variable's address will be bogus
16115 dwarf2_complex_location_expr_complaint ();
16118 case DW_OP_GNU_push_tls_address
:
16119 /* The top of the stack has the offset from the beginning
16120 of the thread control block at which the variable is located. */
16121 /* Nothing should follow this operator, so the top of stack would
16123 /* This is valid for partial global symbols, but the variable's
16124 address will be bogus in the psymtab. Make it always at least
16125 non-zero to not look as a variable garbage collected by linker
16126 which have DW_OP_addr 0. */
16128 dwarf2_complex_location_expr_complaint ();
16132 case DW_OP_GNU_uninit
:
16135 case DW_OP_GNU_addr_index
:
16136 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16143 const char *name
= dwarf_stack_op_name (op
);
16146 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16149 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16153 return (stack
[stacki
]);
16156 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16157 outside of the allocated space. Also enforce minimum>0. */
16158 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16160 complaint (&symfile_complaints
,
16161 _("location description stack overflow"));
16167 complaint (&symfile_complaints
,
16168 _("location description stack underflow"));
16172 return (stack
[stacki
]);
16175 /* memory allocation interface */
16177 static struct dwarf_block
*
16178 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16180 struct dwarf_block
*blk
;
16182 blk
= (struct dwarf_block
*)
16183 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16187 static struct abbrev_info
*
16188 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
16190 struct abbrev_info
*abbrev
;
16192 abbrev
= (struct abbrev_info
*)
16193 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
16194 memset (abbrev
, 0, sizeof (struct abbrev_info
));
16198 static struct die_info
*
16199 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16201 struct die_info
*die
;
16202 size_t size
= sizeof (struct die_info
);
16205 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16207 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16208 memset (die
, 0, sizeof (struct die_info
));
16213 /* Macro support. */
16215 /* Return the full name of file number I in *LH's file name table.
16216 Use COMP_DIR as the name of the current directory of the
16217 compilation. The result is allocated using xmalloc; the caller is
16218 responsible for freeing it. */
16220 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16222 /* Is the file number a valid index into the line header's file name
16223 table? Remember that file numbers start with one, not zero. */
16224 if (1 <= file
&& file
<= lh
->num_file_names
)
16226 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16228 if (IS_ABSOLUTE_PATH (fe
->name
))
16229 return xstrdup (fe
->name
);
16237 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16243 dir_len
= strlen (dir
);
16244 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16245 strcpy (full_name
, dir
);
16246 full_name
[dir_len
] = '/';
16247 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16251 return xstrdup (fe
->name
);
16256 /* The compiler produced a bogus file number. We can at least
16257 record the macro definitions made in the file, even if we
16258 won't be able to find the file by name. */
16259 char fake_name
[80];
16261 sprintf (fake_name
, "<bad macro file number %d>", file
);
16263 complaint (&symfile_complaints
,
16264 _("bad file number in macro information (%d)"),
16267 return xstrdup (fake_name
);
16272 static struct macro_source_file
*
16273 macro_start_file (int file
, int line
,
16274 struct macro_source_file
*current_file
,
16275 const char *comp_dir
,
16276 struct line_header
*lh
, struct objfile
*objfile
)
16278 /* The full name of this source file. */
16279 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16281 /* We don't create a macro table for this compilation unit
16282 at all until we actually get a filename. */
16283 if (! pending_macros
)
16284 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16285 objfile
->macro_cache
);
16287 if (! current_file
)
16288 /* If we have no current file, then this must be the start_file
16289 directive for the compilation unit's main source file. */
16290 current_file
= macro_set_main (pending_macros
, full_name
);
16292 current_file
= macro_include (current_file
, line
, full_name
);
16296 return current_file
;
16300 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16301 followed by a null byte. */
16303 copy_string (const char *buf
, int len
)
16305 char *s
= xmalloc (len
+ 1);
16307 memcpy (s
, buf
, len
);
16313 static const char *
16314 consume_improper_spaces (const char *p
, const char *body
)
16318 complaint (&symfile_complaints
,
16319 _("macro definition contains spaces "
16320 "in formal argument list:\n`%s'"),
16332 parse_macro_definition (struct macro_source_file
*file
, int line
,
16337 /* The body string takes one of two forms. For object-like macro
16338 definitions, it should be:
16340 <macro name> " " <definition>
16342 For function-like macro definitions, it should be:
16344 <macro name> "() " <definition>
16346 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16348 Spaces may appear only where explicitly indicated, and in the
16351 The Dwarf 2 spec says that an object-like macro's name is always
16352 followed by a space, but versions of GCC around March 2002 omit
16353 the space when the macro's definition is the empty string.
16355 The Dwarf 2 spec says that there should be no spaces between the
16356 formal arguments in a function-like macro's formal argument list,
16357 but versions of GCC around March 2002 include spaces after the
16361 /* Find the extent of the macro name. The macro name is terminated
16362 by either a space or null character (for an object-like macro) or
16363 an opening paren (for a function-like macro). */
16364 for (p
= body
; *p
; p
++)
16365 if (*p
== ' ' || *p
== '(')
16368 if (*p
== ' ' || *p
== '\0')
16370 /* It's an object-like macro. */
16371 int name_len
= p
- body
;
16372 char *name
= copy_string (body
, name_len
);
16373 const char *replacement
;
16376 replacement
= body
+ name_len
+ 1;
16379 dwarf2_macro_malformed_definition_complaint (body
);
16380 replacement
= body
+ name_len
;
16383 macro_define_object (file
, line
, name
, replacement
);
16387 else if (*p
== '(')
16389 /* It's a function-like macro. */
16390 char *name
= copy_string (body
, p
- body
);
16393 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16397 p
= consume_improper_spaces (p
, body
);
16399 /* Parse the formal argument list. */
16400 while (*p
&& *p
!= ')')
16402 /* Find the extent of the current argument name. */
16403 const char *arg_start
= p
;
16405 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16408 if (! *p
|| p
== arg_start
)
16409 dwarf2_macro_malformed_definition_complaint (body
);
16412 /* Make sure argv has room for the new argument. */
16413 if (argc
>= argv_size
)
16416 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16419 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16422 p
= consume_improper_spaces (p
, body
);
16424 /* Consume the comma, if present. */
16429 p
= consume_improper_spaces (p
, body
);
16438 /* Perfectly formed definition, no complaints. */
16439 macro_define_function (file
, line
, name
,
16440 argc
, (const char **) argv
,
16442 else if (*p
== '\0')
16444 /* Complain, but do define it. */
16445 dwarf2_macro_malformed_definition_complaint (body
);
16446 macro_define_function (file
, line
, name
,
16447 argc
, (const char **) argv
,
16451 /* Just complain. */
16452 dwarf2_macro_malformed_definition_complaint (body
);
16455 /* Just complain. */
16456 dwarf2_macro_malformed_definition_complaint (body
);
16462 for (i
= 0; i
< argc
; i
++)
16468 dwarf2_macro_malformed_definition_complaint (body
);
16471 /* Skip some bytes from BYTES according to the form given in FORM.
16472 Returns the new pointer. */
16475 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
16476 enum dwarf_form form
,
16477 unsigned int offset_size
,
16478 struct dwarf2_section_info
*section
)
16480 unsigned int bytes_read
;
16484 case DW_FORM_data1
:
16489 case DW_FORM_data2
:
16493 case DW_FORM_data4
:
16497 case DW_FORM_data8
:
16501 case DW_FORM_string
:
16502 read_direct_string (abfd
, bytes
, &bytes_read
);
16503 bytes
+= bytes_read
;
16506 case DW_FORM_sec_offset
:
16508 bytes
+= offset_size
;
16511 case DW_FORM_block
:
16512 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16513 bytes
+= bytes_read
;
16516 case DW_FORM_block1
:
16517 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16519 case DW_FORM_block2
:
16520 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16522 case DW_FORM_block4
:
16523 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16526 case DW_FORM_sdata
:
16527 case DW_FORM_udata
:
16528 case DW_FORM_GNU_addr_index
:
16529 case DW_FORM_GNU_str_index
:
16530 bytes
= skip_leb128 (abfd
, bytes
);
16536 complaint (&symfile_complaints
,
16537 _("invalid form 0x%x in `%s'"),
16539 section
->asection
->name
);
16547 /* A helper for dwarf_decode_macros that handles skipping an unknown
16548 opcode. Returns an updated pointer to the macro data buffer; or,
16549 on error, issues a complaint and returns NULL. */
16552 skip_unknown_opcode (unsigned int opcode
,
16553 gdb_byte
**opcode_definitions
,
16556 unsigned int offset_size
,
16557 struct dwarf2_section_info
*section
)
16559 unsigned int bytes_read
, i
;
16563 if (opcode_definitions
[opcode
] == NULL
)
16565 complaint (&symfile_complaints
,
16566 _("unrecognized DW_MACFINO opcode 0x%x"),
16571 defn
= opcode_definitions
[opcode
];
16572 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16573 defn
+= bytes_read
;
16575 for (i
= 0; i
< arg
; ++i
)
16577 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
16578 if (mac_ptr
== NULL
)
16580 /* skip_form_bytes already issued the complaint. */
16588 /* A helper function which parses the header of a macro section.
16589 If the macro section is the extended (for now called "GNU") type,
16590 then this updates *OFFSET_SIZE. Returns a pointer to just after
16591 the header, or issues a complaint and returns NULL on error. */
16594 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16597 unsigned int *offset_size
,
16598 int section_is_gnu
)
16600 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16602 if (section_is_gnu
)
16604 unsigned int version
, flags
;
16606 version
= read_2_bytes (abfd
, mac_ptr
);
16609 complaint (&symfile_complaints
,
16610 _("unrecognized version `%d' in .debug_macro section"),
16616 flags
= read_1_byte (abfd
, mac_ptr
);
16618 *offset_size
= (flags
& 1) ? 8 : 4;
16620 if ((flags
& 2) != 0)
16621 /* We don't need the line table offset. */
16622 mac_ptr
+= *offset_size
;
16624 /* Vendor opcode descriptions. */
16625 if ((flags
& 4) != 0)
16627 unsigned int i
, count
;
16629 count
= read_1_byte (abfd
, mac_ptr
);
16631 for (i
= 0; i
< count
; ++i
)
16633 unsigned int opcode
, bytes_read
;
16636 opcode
= read_1_byte (abfd
, mac_ptr
);
16638 opcode_definitions
[opcode
] = mac_ptr
;
16639 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16640 mac_ptr
+= bytes_read
;
16649 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16650 including DW_MACRO_GNU_transparent_include. */
16653 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16654 struct macro_source_file
*current_file
,
16655 struct line_header
*lh
, char *comp_dir
,
16656 struct dwarf2_section_info
*section
,
16657 int section_is_gnu
,
16658 unsigned int offset_size
,
16659 struct objfile
*objfile
,
16660 htab_t include_hash
)
16662 enum dwarf_macro_record_type macinfo_type
;
16663 int at_commandline
;
16664 gdb_byte
*opcode_definitions
[256];
16666 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16667 &offset_size
, section_is_gnu
);
16668 if (mac_ptr
== NULL
)
16670 /* We already issued a complaint. */
16674 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16675 GDB is still reading the definitions from command line. First
16676 DW_MACINFO_start_file will need to be ignored as it was already executed
16677 to create CURRENT_FILE for the main source holding also the command line
16678 definitions. On first met DW_MACINFO_start_file this flag is reset to
16679 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16681 at_commandline
= 1;
16685 /* Do we at least have room for a macinfo type byte? */
16686 if (mac_ptr
>= mac_end
)
16688 dwarf2_macros_too_long_complaint (section
);
16692 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16695 /* Note that we rely on the fact that the corresponding GNU and
16696 DWARF constants are the same. */
16697 switch (macinfo_type
)
16699 /* A zero macinfo type indicates the end of the macro
16704 case DW_MACRO_GNU_define
:
16705 case DW_MACRO_GNU_undef
:
16706 case DW_MACRO_GNU_define_indirect
:
16707 case DW_MACRO_GNU_undef_indirect
:
16709 unsigned int bytes_read
;
16714 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16715 mac_ptr
+= bytes_read
;
16717 if (macinfo_type
== DW_MACRO_GNU_define
16718 || macinfo_type
== DW_MACRO_GNU_undef
)
16720 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16721 mac_ptr
+= bytes_read
;
16725 LONGEST str_offset
;
16727 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16728 mac_ptr
+= offset_size
;
16730 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16733 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16734 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16735 if (! current_file
)
16737 /* DWARF violation as no main source is present. */
16738 complaint (&symfile_complaints
,
16739 _("debug info with no main source gives macro %s "
16741 is_define
? _("definition") : _("undefinition"),
16745 if ((line
== 0 && !at_commandline
)
16746 || (line
!= 0 && at_commandline
))
16747 complaint (&symfile_complaints
,
16748 _("debug info gives %s macro %s with %s line %d: %s"),
16749 at_commandline
? _("command-line") : _("in-file"),
16750 is_define
? _("definition") : _("undefinition"),
16751 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16754 parse_macro_definition (current_file
, line
, body
);
16757 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16758 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16759 macro_undef (current_file
, line
, body
);
16764 case DW_MACRO_GNU_start_file
:
16766 unsigned int bytes_read
;
16769 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16770 mac_ptr
+= bytes_read
;
16771 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16772 mac_ptr
+= bytes_read
;
16774 if ((line
== 0 && !at_commandline
)
16775 || (line
!= 0 && at_commandline
))
16776 complaint (&symfile_complaints
,
16777 _("debug info gives source %d included "
16778 "from %s at %s line %d"),
16779 file
, at_commandline
? _("command-line") : _("file"),
16780 line
== 0 ? _("zero") : _("non-zero"), line
);
16782 if (at_commandline
)
16784 /* This DW_MACRO_GNU_start_file was executed in the
16786 at_commandline
= 0;
16789 current_file
= macro_start_file (file
, line
,
16790 current_file
, comp_dir
,
16795 case DW_MACRO_GNU_end_file
:
16796 if (! current_file
)
16797 complaint (&symfile_complaints
,
16798 _("macro debug info has an unmatched "
16799 "`close_file' directive"));
16802 current_file
= current_file
->included_by
;
16803 if (! current_file
)
16805 enum dwarf_macro_record_type next_type
;
16807 /* GCC circa March 2002 doesn't produce the zero
16808 type byte marking the end of the compilation
16809 unit. Complain if it's not there, but exit no
16812 /* Do we at least have room for a macinfo type byte? */
16813 if (mac_ptr
>= mac_end
)
16815 dwarf2_macros_too_long_complaint (section
);
16819 /* We don't increment mac_ptr here, so this is just
16821 next_type
= read_1_byte (abfd
, mac_ptr
);
16822 if (next_type
!= 0)
16823 complaint (&symfile_complaints
,
16824 _("no terminating 0-type entry for "
16825 "macros in `.debug_macinfo' section"));
16832 case DW_MACRO_GNU_transparent_include
:
16837 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16838 mac_ptr
+= offset_size
;
16840 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16843 /* This has actually happened; see
16844 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16845 complaint (&symfile_complaints
,
16846 _("recursive DW_MACRO_GNU_transparent_include in "
16847 ".debug_macro section"));
16853 dwarf_decode_macro_bytes (abfd
,
16854 section
->buffer
+ offset
,
16855 mac_end
, current_file
,
16857 section
, section_is_gnu
,
16858 offset_size
, objfile
, include_hash
);
16860 htab_remove_elt (include_hash
, mac_ptr
);
16865 case DW_MACINFO_vendor_ext
:
16866 if (!section_is_gnu
)
16868 unsigned int bytes_read
;
16871 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16872 mac_ptr
+= bytes_read
;
16873 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16874 mac_ptr
+= bytes_read
;
16876 /* We don't recognize any vendor extensions. */
16882 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16883 mac_ptr
, abfd
, offset_size
,
16885 if (mac_ptr
== NULL
)
16889 } while (macinfo_type
!= 0);
16893 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
16894 char *comp_dir
, bfd
*abfd
,
16895 struct dwarf2_cu
*cu
,
16896 struct dwarf2_section_info
*section
,
16897 int section_is_gnu
)
16899 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16900 gdb_byte
*mac_ptr
, *mac_end
;
16901 struct macro_source_file
*current_file
= 0;
16902 enum dwarf_macro_record_type macinfo_type
;
16903 unsigned int offset_size
= cu
->header
.offset_size
;
16904 gdb_byte
*opcode_definitions
[256];
16905 struct cleanup
*cleanup
;
16906 htab_t include_hash
;
16909 dwarf2_read_section (objfile
, section
);
16910 if (section
->buffer
== NULL
)
16912 complaint (&symfile_complaints
, _("missing %s section"),
16913 section
->asection
->name
);
16917 /* First pass: Find the name of the base filename.
16918 This filename is needed in order to process all macros whose definition
16919 (or undefinition) comes from the command line. These macros are defined
16920 before the first DW_MACINFO_start_file entry, and yet still need to be
16921 associated to the base file.
16923 To determine the base file name, we scan the macro definitions until we
16924 reach the first DW_MACINFO_start_file entry. We then initialize
16925 CURRENT_FILE accordingly so that any macro definition found before the
16926 first DW_MACINFO_start_file can still be associated to the base file. */
16928 mac_ptr
= section
->buffer
+ offset
;
16929 mac_end
= section
->buffer
+ section
->size
;
16931 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16932 &offset_size
, section_is_gnu
);
16933 if (mac_ptr
== NULL
)
16935 /* We already issued a complaint. */
16941 /* Do we at least have room for a macinfo type byte? */
16942 if (mac_ptr
>= mac_end
)
16944 /* Complaint is printed during the second pass as GDB will probably
16945 stop the first pass earlier upon finding
16946 DW_MACINFO_start_file. */
16950 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16953 /* Note that we rely on the fact that the corresponding GNU and
16954 DWARF constants are the same. */
16955 switch (macinfo_type
)
16957 /* A zero macinfo type indicates the end of the macro
16962 case DW_MACRO_GNU_define
:
16963 case DW_MACRO_GNU_undef
:
16964 /* Only skip the data by MAC_PTR. */
16966 unsigned int bytes_read
;
16968 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16969 mac_ptr
+= bytes_read
;
16970 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16971 mac_ptr
+= bytes_read
;
16975 case DW_MACRO_GNU_start_file
:
16977 unsigned int bytes_read
;
16980 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16981 mac_ptr
+= bytes_read
;
16982 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16983 mac_ptr
+= bytes_read
;
16985 current_file
= macro_start_file (file
, line
, current_file
,
16986 comp_dir
, lh
, objfile
);
16990 case DW_MACRO_GNU_end_file
:
16991 /* No data to skip by MAC_PTR. */
16994 case DW_MACRO_GNU_define_indirect
:
16995 case DW_MACRO_GNU_undef_indirect
:
16997 unsigned int bytes_read
;
16999 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17000 mac_ptr
+= bytes_read
;
17001 mac_ptr
+= offset_size
;
17005 case DW_MACRO_GNU_transparent_include
:
17006 /* Note that, according to the spec, a transparent include
17007 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17008 skip this opcode. */
17009 mac_ptr
+= offset_size
;
17012 case DW_MACINFO_vendor_ext
:
17013 /* Only skip the data by MAC_PTR. */
17014 if (!section_is_gnu
)
17016 unsigned int bytes_read
;
17018 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17019 mac_ptr
+= bytes_read
;
17020 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17021 mac_ptr
+= bytes_read
;
17026 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17027 mac_ptr
, abfd
, offset_size
,
17029 if (mac_ptr
== NULL
)
17033 } while (macinfo_type
!= 0 && current_file
== NULL
);
17035 /* Second pass: Process all entries.
17037 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17038 command-line macro definitions/undefinitions. This flag is unset when we
17039 reach the first DW_MACINFO_start_file entry. */
17041 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17042 NULL
, xcalloc
, xfree
);
17043 cleanup
= make_cleanup_htab_delete (include_hash
);
17044 mac_ptr
= section
->buffer
+ offset
;
17045 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17047 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17048 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17049 offset_size
, objfile
, include_hash
);
17050 do_cleanups (cleanup
);
17053 /* Check if the attribute's form is a DW_FORM_block*
17054 if so return true else false. */
17057 attr_form_is_block (struct attribute
*attr
)
17059 return (attr
== NULL
? 0 :
17060 attr
->form
== DW_FORM_block1
17061 || attr
->form
== DW_FORM_block2
17062 || attr
->form
== DW_FORM_block4
17063 || attr
->form
== DW_FORM_block
17064 || attr
->form
== DW_FORM_exprloc
);
17067 /* Return non-zero if ATTR's value is a section offset --- classes
17068 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17069 You may use DW_UNSND (attr) to retrieve such offsets.
17071 Section 7.5.4, "Attribute Encodings", explains that no attribute
17072 may have a value that belongs to more than one of these classes; it
17073 would be ambiguous if we did, because we use the same forms for all
17077 attr_form_is_section_offset (struct attribute
*attr
)
17079 return (attr
->form
== DW_FORM_data4
17080 || attr
->form
== DW_FORM_data8
17081 || attr
->form
== DW_FORM_sec_offset
);
17084 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17085 zero otherwise. When this function returns true, you can apply
17086 dwarf2_get_attr_constant_value to it.
17088 However, note that for some attributes you must check
17089 attr_form_is_section_offset before using this test. DW_FORM_data4
17090 and DW_FORM_data8 are members of both the constant class, and of
17091 the classes that contain offsets into other debug sections
17092 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17093 that, if an attribute's can be either a constant or one of the
17094 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17095 taken as section offsets, not constants. */
17098 attr_form_is_constant (struct attribute
*attr
)
17100 switch (attr
->form
)
17102 case DW_FORM_sdata
:
17103 case DW_FORM_udata
:
17104 case DW_FORM_data1
:
17105 case DW_FORM_data2
:
17106 case DW_FORM_data4
:
17107 case DW_FORM_data8
:
17114 /* Return the .debug_loc section to use for CU.
17115 For DWO files use .debug_loc.dwo. */
17117 static struct dwarf2_section_info
*
17118 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17121 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17122 return &dwarf2_per_objfile
->loc
;
17125 /* A helper function that fills in a dwarf2_loclist_baton. */
17128 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17129 struct dwarf2_loclist_baton
*baton
,
17130 struct attribute
*attr
)
17132 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17134 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17136 baton
->per_cu
= cu
->per_cu
;
17137 gdb_assert (baton
->per_cu
);
17138 /* We don't know how long the location list is, but make sure we
17139 don't run off the edge of the section. */
17140 baton
->size
= section
->size
- DW_UNSND (attr
);
17141 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17142 baton
->base_address
= cu
->base_address
;
17146 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17147 struct dwarf2_cu
*cu
)
17149 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17150 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17152 if (attr_form_is_section_offset (attr
)
17153 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17154 the section. If so, fall through to the complaint in the
17156 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17158 struct dwarf2_loclist_baton
*baton
;
17160 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17161 sizeof (struct dwarf2_loclist_baton
));
17163 fill_in_loclist_baton (cu
, baton
, attr
);
17165 if (cu
->base_known
== 0)
17166 complaint (&symfile_complaints
,
17167 _("Location list used without "
17168 "specifying the CU base address."));
17170 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17171 SYMBOL_LOCATION_BATON (sym
) = baton
;
17175 struct dwarf2_locexpr_baton
*baton
;
17177 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17178 sizeof (struct dwarf2_locexpr_baton
));
17179 baton
->per_cu
= cu
->per_cu
;
17180 gdb_assert (baton
->per_cu
);
17182 if (attr_form_is_block (attr
))
17184 /* Note that we're just copying the block's data pointer
17185 here, not the actual data. We're still pointing into the
17186 info_buffer for SYM's objfile; right now we never release
17187 that buffer, but when we do clean up properly this may
17189 baton
->size
= DW_BLOCK (attr
)->size
;
17190 baton
->data
= DW_BLOCK (attr
)->data
;
17194 dwarf2_invalid_attrib_class_complaint ("location description",
17195 SYMBOL_NATURAL_NAME (sym
));
17199 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17200 SYMBOL_LOCATION_BATON (sym
) = baton
;
17204 /* Return the OBJFILE associated with the compilation unit CU. If CU
17205 came from a separate debuginfo file, then the master objfile is
17209 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17211 struct objfile
*objfile
= per_cu
->objfile
;
17213 /* Return the master objfile, so that we can report and look up the
17214 correct file containing this variable. */
17215 if (objfile
->separate_debug_objfile_backlink
)
17216 objfile
= objfile
->separate_debug_objfile_backlink
;
17221 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17222 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17223 CU_HEADERP first. */
17225 static const struct comp_unit_head
*
17226 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17227 struct dwarf2_per_cu_data
*per_cu
)
17229 struct objfile
*objfile
;
17230 struct dwarf2_per_objfile
*per_objfile
;
17231 gdb_byte
*info_ptr
;
17234 return &per_cu
->cu
->header
;
17236 objfile
= per_cu
->objfile
;
17237 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17238 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
17240 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17241 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
17246 /* Return the address size given in the compilation unit header for CU. */
17249 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17251 struct comp_unit_head cu_header_local
;
17252 const struct comp_unit_head
*cu_headerp
;
17254 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17256 return cu_headerp
->addr_size
;
17259 /* Return the offset size given in the compilation unit header for CU. */
17262 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17264 struct comp_unit_head cu_header_local
;
17265 const struct comp_unit_head
*cu_headerp
;
17267 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17269 return cu_headerp
->offset_size
;
17272 /* See its dwarf2loc.h declaration. */
17275 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17277 struct comp_unit_head cu_header_local
;
17278 const struct comp_unit_head
*cu_headerp
;
17280 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17282 if (cu_headerp
->version
== 2)
17283 return cu_headerp
->addr_size
;
17285 return cu_headerp
->offset_size
;
17288 /* Return the text offset of the CU. The returned offset comes from
17289 this CU's objfile. If this objfile came from a separate debuginfo
17290 file, then the offset may be different from the corresponding
17291 offset in the parent objfile. */
17294 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17296 struct objfile
*objfile
= per_cu
->objfile
;
17298 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17301 /* Locate the .debug_info compilation unit from CU's objfile which contains
17302 the DIE at OFFSET. Raises an error on failure. */
17304 static struct dwarf2_per_cu_data
*
17305 dwarf2_find_containing_comp_unit (sect_offset offset
,
17306 struct objfile
*objfile
)
17308 struct dwarf2_per_cu_data
*this_cu
;
17312 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17315 int mid
= low
+ (high
- low
) / 2;
17317 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17318 >= offset
.sect_off
)
17323 gdb_assert (low
== high
);
17324 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17328 error (_("Dwarf Error: could not find partial DIE containing "
17329 "offset 0x%lx [in module %s]"),
17330 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17332 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17333 <= offset
.sect_off
);
17334 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17338 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17339 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17340 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17341 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17342 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17347 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17350 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17352 memset (cu
, 0, sizeof (*cu
));
17354 cu
->per_cu
= per_cu
;
17355 cu
->objfile
= per_cu
->objfile
;
17356 obstack_init (&cu
->comp_unit_obstack
);
17359 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17362 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
17364 struct attribute
*attr
;
17366 /* Set the language we're debugging. */
17367 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17369 set_cu_language (DW_UNSND (attr
), cu
);
17372 cu
->language
= language_minimal
;
17373 cu
->language_defn
= language_def (cu
->language
);
17376 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17378 cu
->producer
= DW_STRING (attr
);
17381 /* Release one cached compilation unit, CU. We unlink it from the tree
17382 of compilation units, but we don't remove it from the read_in_chain;
17383 the caller is responsible for that.
17384 NOTE: DATA is a void * because this function is also used as a
17385 cleanup routine. */
17388 free_heap_comp_unit (void *data
)
17390 struct dwarf2_cu
*cu
= data
;
17392 gdb_assert (cu
->per_cu
!= NULL
);
17393 cu
->per_cu
->cu
= NULL
;
17396 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17401 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17402 when we're finished with it. We can't free the pointer itself, but be
17403 sure to unlink it from the cache. Also release any associated storage. */
17406 free_stack_comp_unit (void *data
)
17408 struct dwarf2_cu
*cu
= data
;
17410 gdb_assert (cu
->per_cu
!= NULL
);
17411 cu
->per_cu
->cu
= NULL
;
17414 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17415 cu
->partial_dies
= NULL
;
17418 /* Free all cached compilation units. */
17421 free_cached_comp_units (void *data
)
17423 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17425 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17426 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17427 while (per_cu
!= NULL
)
17429 struct dwarf2_per_cu_data
*next_cu
;
17431 next_cu
= per_cu
->cu
->read_in_chain
;
17433 free_heap_comp_unit (per_cu
->cu
);
17434 *last_chain
= next_cu
;
17440 /* Increase the age counter on each cached compilation unit, and free
17441 any that are too old. */
17444 age_cached_comp_units (void)
17446 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17448 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17449 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17450 while (per_cu
!= NULL
)
17452 per_cu
->cu
->last_used
++;
17453 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17454 dwarf2_mark (per_cu
->cu
);
17455 per_cu
= per_cu
->cu
->read_in_chain
;
17458 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17459 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17460 while (per_cu
!= NULL
)
17462 struct dwarf2_per_cu_data
*next_cu
;
17464 next_cu
= per_cu
->cu
->read_in_chain
;
17466 if (!per_cu
->cu
->mark
)
17468 free_heap_comp_unit (per_cu
->cu
);
17469 *last_chain
= next_cu
;
17472 last_chain
= &per_cu
->cu
->read_in_chain
;
17478 /* Remove a single compilation unit from the cache. */
17481 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17483 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17485 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17486 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17487 while (per_cu
!= NULL
)
17489 struct dwarf2_per_cu_data
*next_cu
;
17491 next_cu
= per_cu
->cu
->read_in_chain
;
17493 if (per_cu
== target_per_cu
)
17495 free_heap_comp_unit (per_cu
->cu
);
17497 *last_chain
= next_cu
;
17501 last_chain
= &per_cu
->cu
->read_in_chain
;
17507 /* Release all extra memory associated with OBJFILE. */
17510 dwarf2_free_objfile (struct objfile
*objfile
)
17512 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17514 if (dwarf2_per_objfile
== NULL
)
17517 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17518 free_cached_comp_units (NULL
);
17520 if (dwarf2_per_objfile
->quick_file_names_table
)
17521 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17523 /* Everything else should be on the objfile obstack. */
17526 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17527 We store these in a hash table separate from the DIEs, and preserve them
17528 when the DIEs are flushed out of cache.
17530 The CU "per_cu" pointer is needed because offset alone is not enough to
17531 uniquely identify the type. A file may have multiple .debug_types sections,
17532 or the type may come from a DWO file. We have to use something in
17533 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17534 routine, get_die_type_at_offset, from outside this file, and thus won't
17535 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17538 struct dwarf2_per_cu_offset_and_type
17540 const struct dwarf2_per_cu_data
*per_cu
;
17541 sect_offset offset
;
17545 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17548 per_cu_offset_and_type_hash (const void *item
)
17550 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17552 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17555 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17558 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17560 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17561 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17563 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17564 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17567 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17568 table if necessary. For convenience, return TYPE.
17570 The DIEs reading must have careful ordering to:
17571 * Not cause infite loops trying to read in DIEs as a prerequisite for
17572 reading current DIE.
17573 * Not trying to dereference contents of still incompletely read in types
17574 while reading in other DIEs.
17575 * Enable referencing still incompletely read in types just by a pointer to
17576 the type without accessing its fields.
17578 Therefore caller should follow these rules:
17579 * Try to fetch any prerequisite types we may need to build this DIE type
17580 before building the type and calling set_die_type.
17581 * After building type call set_die_type for current DIE as soon as
17582 possible before fetching more types to complete the current type.
17583 * Make the type as complete as possible before fetching more types. */
17585 static struct type
*
17586 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17588 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17589 struct objfile
*objfile
= cu
->objfile
;
17591 /* For Ada types, make sure that the gnat-specific data is always
17592 initialized (if not already set). There are a few types where
17593 we should not be doing so, because the type-specific area is
17594 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17595 where the type-specific area is used to store the floatformat).
17596 But this is not a problem, because the gnat-specific information
17597 is actually not needed for these types. */
17598 if (need_gnat_info (cu
)
17599 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17600 && TYPE_CODE (type
) != TYPE_CODE_FLT
17601 && !HAVE_GNAT_AUX_INFO (type
))
17602 INIT_GNAT_SPECIFIC (type
);
17604 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17606 dwarf2_per_objfile
->die_type_hash
=
17607 htab_create_alloc_ex (127,
17608 per_cu_offset_and_type_hash
,
17609 per_cu_offset_and_type_eq
,
17611 &objfile
->objfile_obstack
,
17612 hashtab_obstack_allocate
,
17613 dummy_obstack_deallocate
);
17616 ofs
.per_cu
= cu
->per_cu
;
17617 ofs
.offset
= die
->offset
;
17619 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17620 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17622 complaint (&symfile_complaints
,
17623 _("A problem internal to GDB: DIE 0x%x has type already set"),
17624 die
->offset
.sect_off
);
17625 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17630 /* Look up the type for the die at OFFSET in the appropriate type_hash
17631 table, or return NULL if the die does not have a saved type. */
17633 static struct type
*
17634 get_die_type_at_offset (sect_offset offset
,
17635 struct dwarf2_per_cu_data
*per_cu
)
17637 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17639 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17642 ofs
.per_cu
= per_cu
;
17643 ofs
.offset
= offset
;
17644 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17651 /* Look up the type for DIE in the appropriate type_hash table,
17652 or return NULL if DIE does not have a saved type. */
17654 static struct type
*
17655 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17657 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17660 /* Add a dependence relationship from CU to REF_PER_CU. */
17663 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17664 struct dwarf2_per_cu_data
*ref_per_cu
)
17668 if (cu
->dependencies
== NULL
)
17670 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17671 NULL
, &cu
->comp_unit_obstack
,
17672 hashtab_obstack_allocate
,
17673 dummy_obstack_deallocate
);
17675 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17677 *slot
= ref_per_cu
;
17680 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17681 Set the mark field in every compilation unit in the
17682 cache that we must keep because we are keeping CU. */
17685 dwarf2_mark_helper (void **slot
, void *data
)
17687 struct dwarf2_per_cu_data
*per_cu
;
17689 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17691 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17692 reading of the chain. As such dependencies remain valid it is not much
17693 useful to track and undo them during QUIT cleanups. */
17694 if (per_cu
->cu
== NULL
)
17697 if (per_cu
->cu
->mark
)
17699 per_cu
->cu
->mark
= 1;
17701 if (per_cu
->cu
->dependencies
!= NULL
)
17702 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17707 /* Set the mark field in CU and in every other compilation unit in the
17708 cache that we must keep because we are keeping CU. */
17711 dwarf2_mark (struct dwarf2_cu
*cu
)
17716 if (cu
->dependencies
!= NULL
)
17717 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17721 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17725 per_cu
->cu
->mark
= 0;
17726 per_cu
= per_cu
->cu
->read_in_chain
;
17730 /* Trivial hash function for partial_die_info: the hash value of a DIE
17731 is its offset in .debug_info for this objfile. */
17734 partial_die_hash (const void *item
)
17736 const struct partial_die_info
*part_die
= item
;
17738 return part_die
->offset
.sect_off
;
17741 /* Trivial comparison function for partial_die_info structures: two DIEs
17742 are equal if they have the same offset. */
17745 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17747 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17748 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17750 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17753 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17754 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17757 set_dwarf2_cmd (char *args
, int from_tty
)
17759 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17763 show_dwarf2_cmd (char *args
, int from_tty
)
17765 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17768 /* If section described by INFO was mmapped, munmap it now. */
17771 munmap_section_buffer (struct dwarf2_section_info
*info
)
17773 if (info
->map_addr
!= NULL
)
17778 res
= munmap (info
->map_addr
, info
->map_len
);
17779 gdb_assert (res
== 0);
17781 /* Without HAVE_MMAP, we should never be here to begin with. */
17782 gdb_assert_not_reached ("no mmap support");
17787 /* munmap debug sections for OBJFILE, if necessary. */
17790 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17792 struct dwarf2_per_objfile
*data
= d
;
17794 struct dwarf2_section_info
*section
;
17796 /* This is sorted according to the order they're defined in to make it easier
17797 to keep in sync. */
17798 munmap_section_buffer (&data
->info
);
17799 munmap_section_buffer (&data
->abbrev
);
17800 munmap_section_buffer (&data
->line
);
17801 munmap_section_buffer (&data
->loc
);
17802 munmap_section_buffer (&data
->macinfo
);
17803 munmap_section_buffer (&data
->macro
);
17804 munmap_section_buffer (&data
->str
);
17805 munmap_section_buffer (&data
->ranges
);
17806 munmap_section_buffer (&data
->addr
);
17807 munmap_section_buffer (&data
->frame
);
17808 munmap_section_buffer (&data
->eh_frame
);
17809 munmap_section_buffer (&data
->gdb_index
);
17812 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17814 munmap_section_buffer (section
);
17816 VEC_free (dwarf2_section_info_def
, data
->types
);
17818 if (data
->dwo_files
)
17819 free_dwo_files (data
->dwo_files
, objfile
);
17823 /* The "save gdb-index" command. */
17825 /* The contents of the hash table we create when building the string
17827 struct strtab_entry
17829 offset_type offset
;
17833 /* Hash function for a strtab_entry.
17835 Function is used only during write_hash_table so no index format backward
17836 compatibility is needed. */
17839 hash_strtab_entry (const void *e
)
17841 const struct strtab_entry
*entry
= e
;
17842 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17845 /* Equality function for a strtab_entry. */
17848 eq_strtab_entry (const void *a
, const void *b
)
17850 const struct strtab_entry
*ea
= a
;
17851 const struct strtab_entry
*eb
= b
;
17852 return !strcmp (ea
->str
, eb
->str
);
17855 /* Create a strtab_entry hash table. */
17858 create_strtab (void)
17860 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17861 xfree
, xcalloc
, xfree
);
17864 /* Add a string to the constant pool. Return the string's offset in
17868 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17871 struct strtab_entry entry
;
17872 struct strtab_entry
*result
;
17875 slot
= htab_find_slot (table
, &entry
, INSERT
);
17880 result
= XNEW (struct strtab_entry
);
17881 result
->offset
= obstack_object_size (cpool
);
17883 obstack_grow_str0 (cpool
, str
);
17886 return result
->offset
;
17889 /* An entry in the symbol table. */
17890 struct symtab_index_entry
17892 /* The name of the symbol. */
17894 /* The offset of the name in the constant pool. */
17895 offset_type index_offset
;
17896 /* A sorted vector of the indices of all the CUs that hold an object
17898 VEC (offset_type
) *cu_indices
;
17901 /* The symbol table. This is a power-of-2-sized hash table. */
17902 struct mapped_symtab
17904 offset_type n_elements
;
17906 struct symtab_index_entry
**data
;
17909 /* Hash function for a symtab_index_entry. */
17912 hash_symtab_entry (const void *e
)
17914 const struct symtab_index_entry
*entry
= e
;
17915 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17916 sizeof (offset_type
) * VEC_length (offset_type
,
17917 entry
->cu_indices
),
17921 /* Equality function for a symtab_index_entry. */
17924 eq_symtab_entry (const void *a
, const void *b
)
17926 const struct symtab_index_entry
*ea
= a
;
17927 const struct symtab_index_entry
*eb
= b
;
17928 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17929 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17931 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17932 VEC_address (offset_type
, eb
->cu_indices
),
17933 sizeof (offset_type
) * len
);
17936 /* Destroy a symtab_index_entry. */
17939 delete_symtab_entry (void *p
)
17941 struct symtab_index_entry
*entry
= p
;
17942 VEC_free (offset_type
, entry
->cu_indices
);
17946 /* Create a hash table holding symtab_index_entry objects. */
17949 create_symbol_hash_table (void)
17951 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17952 delete_symtab_entry
, xcalloc
, xfree
);
17955 /* Create a new mapped symtab object. */
17957 static struct mapped_symtab
*
17958 create_mapped_symtab (void)
17960 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17961 symtab
->n_elements
= 0;
17962 symtab
->size
= 1024;
17963 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17967 /* Destroy a mapped_symtab. */
17970 cleanup_mapped_symtab (void *p
)
17972 struct mapped_symtab
*symtab
= p
;
17973 /* The contents of the array are freed when the other hash table is
17975 xfree (symtab
->data
);
17979 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17982 Function is used only during write_hash_table so no index format backward
17983 compatibility is needed. */
17985 static struct symtab_index_entry
**
17986 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17988 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17990 index
= hash
& (symtab
->size
- 1);
17991 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17995 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17996 return &symtab
->data
[index
];
17997 index
= (index
+ step
) & (symtab
->size
- 1);
18001 /* Expand SYMTAB's hash table. */
18004 hash_expand (struct mapped_symtab
*symtab
)
18006 offset_type old_size
= symtab
->size
;
18008 struct symtab_index_entry
**old_entries
= symtab
->data
;
18011 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18013 for (i
= 0; i
< old_size
; ++i
)
18015 if (old_entries
[i
])
18017 struct symtab_index_entry
**slot
= find_slot (symtab
,
18018 old_entries
[i
]->name
);
18019 *slot
= old_entries
[i
];
18023 xfree (old_entries
);
18026 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
18027 is the index of the CU in which the symbol appears. */
18030 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18031 offset_type cu_index
)
18033 struct symtab_index_entry
**slot
;
18035 ++symtab
->n_elements
;
18036 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18037 hash_expand (symtab
);
18039 slot
= find_slot (symtab
, name
);
18042 *slot
= XNEW (struct symtab_index_entry
);
18043 (*slot
)->name
= name
;
18044 (*slot
)->cu_indices
= NULL
;
18046 /* Don't push an index twice. Due to how we add entries we only
18047 have to check the last one. */
18048 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
18049 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
18050 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
18053 /* Add a vector of indices to the constant pool. */
18056 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18057 struct symtab_index_entry
*entry
)
18061 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18064 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18065 offset_type val
= MAYBE_SWAP (len
);
18070 entry
->index_offset
= obstack_object_size (cpool
);
18072 obstack_grow (cpool
, &val
, sizeof (val
));
18074 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18077 val
= MAYBE_SWAP (iter
);
18078 obstack_grow (cpool
, &val
, sizeof (val
));
18083 struct symtab_index_entry
*old_entry
= *slot
;
18084 entry
->index_offset
= old_entry
->index_offset
;
18087 return entry
->index_offset
;
18090 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18091 constant pool entries going into the obstack CPOOL. */
18094 write_hash_table (struct mapped_symtab
*symtab
,
18095 struct obstack
*output
, struct obstack
*cpool
)
18098 htab_t symbol_hash_table
;
18101 symbol_hash_table
= create_symbol_hash_table ();
18102 str_table
= create_strtab ();
18104 /* We add all the index vectors to the constant pool first, to
18105 ensure alignment is ok. */
18106 for (i
= 0; i
< symtab
->size
; ++i
)
18108 if (symtab
->data
[i
])
18109 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18112 /* Now write out the hash table. */
18113 for (i
= 0; i
< symtab
->size
; ++i
)
18115 offset_type str_off
, vec_off
;
18117 if (symtab
->data
[i
])
18119 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18120 vec_off
= symtab
->data
[i
]->index_offset
;
18124 /* While 0 is a valid constant pool index, it is not valid
18125 to have 0 for both offsets. */
18130 str_off
= MAYBE_SWAP (str_off
);
18131 vec_off
= MAYBE_SWAP (vec_off
);
18133 obstack_grow (output
, &str_off
, sizeof (str_off
));
18134 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18137 htab_delete (str_table
);
18138 htab_delete (symbol_hash_table
);
18141 /* Struct to map psymtab to CU index in the index file. */
18142 struct psymtab_cu_index_map
18144 struct partial_symtab
*psymtab
;
18145 unsigned int cu_index
;
18149 hash_psymtab_cu_index (const void *item
)
18151 const struct psymtab_cu_index_map
*map
= item
;
18153 return htab_hash_pointer (map
->psymtab
);
18157 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18159 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18160 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18162 return lhs
->psymtab
== rhs
->psymtab
;
18165 /* Helper struct for building the address table. */
18166 struct addrmap_index_data
18168 struct objfile
*objfile
;
18169 struct obstack
*addr_obstack
;
18170 htab_t cu_index_htab
;
18172 /* Non-zero if the previous_* fields are valid.
18173 We can't write an entry until we see the next entry (since it is only then
18174 that we know the end of the entry). */
18175 int previous_valid
;
18176 /* Index of the CU in the table of all CUs in the index file. */
18177 unsigned int previous_cu_index
;
18178 /* Start address of the CU. */
18179 CORE_ADDR previous_cu_start
;
18182 /* Write an address entry to OBSTACK. */
18185 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18186 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18188 offset_type cu_index_to_write
;
18190 CORE_ADDR baseaddr
;
18192 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18194 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18195 obstack_grow (obstack
, addr
, 8);
18196 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18197 obstack_grow (obstack
, addr
, 8);
18198 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18199 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18202 /* Worker function for traversing an addrmap to build the address table. */
18205 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18207 struct addrmap_index_data
*data
= datap
;
18208 struct partial_symtab
*pst
= obj
;
18209 offset_type cu_index
;
18212 if (data
->previous_valid
)
18213 add_address_entry (data
->objfile
, data
->addr_obstack
,
18214 data
->previous_cu_start
, start_addr
,
18215 data
->previous_cu_index
);
18217 data
->previous_cu_start
= start_addr
;
18220 struct psymtab_cu_index_map find_map
, *map
;
18221 find_map
.psymtab
= pst
;
18222 map
= htab_find (data
->cu_index_htab
, &find_map
);
18223 gdb_assert (map
!= NULL
);
18224 data
->previous_cu_index
= map
->cu_index
;
18225 data
->previous_valid
= 1;
18228 data
->previous_valid
= 0;
18233 /* Write OBJFILE's address map to OBSTACK.
18234 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18235 in the index file. */
18238 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18239 htab_t cu_index_htab
)
18241 struct addrmap_index_data addrmap_index_data
;
18243 /* When writing the address table, we have to cope with the fact that
18244 the addrmap iterator only provides the start of a region; we have to
18245 wait until the next invocation to get the start of the next region. */
18247 addrmap_index_data
.objfile
= objfile
;
18248 addrmap_index_data
.addr_obstack
= obstack
;
18249 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18250 addrmap_index_data
.previous_valid
= 0;
18252 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18253 &addrmap_index_data
);
18255 /* It's highly unlikely the last entry (end address = 0xff...ff)
18256 is valid, but we should still handle it.
18257 The end address is recorded as the start of the next region, but that
18258 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18260 if (addrmap_index_data
.previous_valid
)
18261 add_address_entry (objfile
, obstack
,
18262 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18263 addrmap_index_data
.previous_cu_index
);
18266 /* Add a list of partial symbols to SYMTAB. */
18269 write_psymbols (struct mapped_symtab
*symtab
,
18271 struct partial_symbol
**psymp
,
18273 offset_type cu_index
,
18276 for (; count
-- > 0; ++psymp
)
18278 void **slot
, *lookup
;
18280 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
18281 error (_("Ada is not currently supported by the index"));
18283 /* We only want to add a given psymbol once. However, we also
18284 want to account for whether it is global or static. So, we
18285 may add it twice, using slightly different values. */
18288 uintptr_t val
= 1 | (uintptr_t) *psymp
;
18290 lookup
= (void *) val
;
18295 /* Only add a given psymbol once. */
18296 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
18300 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
18305 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18306 exception if there is an error. */
18309 write_obstack (FILE *file
, struct obstack
*obstack
)
18311 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18313 != obstack_object_size (obstack
))
18314 error (_("couldn't data write to file"));
18317 /* Unlink a file if the argument is not NULL. */
18320 unlink_if_set (void *p
)
18322 char **filename
= p
;
18324 unlink (*filename
);
18327 /* A helper struct used when iterating over debug_types. */
18328 struct signatured_type_index_data
18330 struct objfile
*objfile
;
18331 struct mapped_symtab
*symtab
;
18332 struct obstack
*types_list
;
18337 /* A helper function that writes a single signatured_type to an
18341 write_one_signatured_type (void **slot
, void *d
)
18343 struct signatured_type_index_data
*info
= d
;
18344 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18345 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18346 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18349 write_psymbols (info
->symtab
,
18351 info
->objfile
->global_psymbols
.list
18352 + psymtab
->globals_offset
,
18353 psymtab
->n_global_syms
, info
->cu_index
,
18355 write_psymbols (info
->symtab
,
18357 info
->objfile
->static_psymbols
.list
18358 + psymtab
->statics_offset
,
18359 psymtab
->n_static_syms
, info
->cu_index
,
18362 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18363 entry
->per_cu
.offset
.sect_off
);
18364 obstack_grow (info
->types_list
, val
, 8);
18365 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18366 entry
->type_offset_in_tu
.cu_off
);
18367 obstack_grow (info
->types_list
, val
, 8);
18368 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18369 obstack_grow (info
->types_list
, val
, 8);
18376 /* Create an index file for OBJFILE in the directory DIR. */
18379 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18381 struct cleanup
*cleanup
;
18382 char *filename
, *cleanup_filename
;
18383 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18384 struct obstack cu_list
, types_cu_list
;
18387 struct mapped_symtab
*symtab
;
18388 offset_type val
, size_of_contents
, total_len
;
18392 htab_t cu_index_htab
;
18393 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18395 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18398 if (dwarf2_per_objfile
->using_index
)
18399 error (_("Cannot use an index to create the index"));
18401 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18402 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18404 if (stat (objfile
->name
, &st
) < 0)
18405 perror_with_name (objfile
->name
);
18407 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18408 INDEX_SUFFIX
, (char *) NULL
);
18409 cleanup
= make_cleanup (xfree
, filename
);
18411 out_file
= fopen (filename
, "wb");
18413 error (_("Can't open `%s' for writing"), filename
);
18415 cleanup_filename
= filename
;
18416 make_cleanup (unlink_if_set
, &cleanup_filename
);
18418 symtab
= create_mapped_symtab ();
18419 make_cleanup (cleanup_mapped_symtab
, symtab
);
18421 obstack_init (&addr_obstack
);
18422 make_cleanup_obstack_free (&addr_obstack
);
18424 obstack_init (&cu_list
);
18425 make_cleanup_obstack_free (&cu_list
);
18427 obstack_init (&types_cu_list
);
18428 make_cleanup_obstack_free (&types_cu_list
);
18430 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18431 NULL
, xcalloc
, xfree
);
18432 make_cleanup_htab_delete (psyms_seen
);
18434 /* While we're scanning CU's create a table that maps a psymtab pointer
18435 (which is what addrmap records) to its index (which is what is recorded
18436 in the index file). This will later be needed to write the address
18438 cu_index_htab
= htab_create_alloc (100,
18439 hash_psymtab_cu_index
,
18440 eq_psymtab_cu_index
,
18441 NULL
, xcalloc
, xfree
);
18442 make_cleanup_htab_delete (cu_index_htab
);
18443 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18444 xmalloc (sizeof (struct psymtab_cu_index_map
)
18445 * dwarf2_per_objfile
->n_comp_units
);
18446 make_cleanup (xfree
, psymtab_cu_index_map
);
18448 /* The CU list is already sorted, so we don't need to do additional
18449 work here. Also, the debug_types entries do not appear in
18450 all_comp_units, but only in their own hash table. */
18451 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18453 struct dwarf2_per_cu_data
*per_cu
18454 = dwarf2_per_objfile
->all_comp_units
[i
];
18455 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18457 struct psymtab_cu_index_map
*map
;
18460 write_psymbols (symtab
,
18462 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18463 psymtab
->n_global_syms
, i
,
18465 write_psymbols (symtab
,
18467 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18468 psymtab
->n_static_syms
, i
,
18471 map
= &psymtab_cu_index_map
[i
];
18472 map
->psymtab
= psymtab
;
18474 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18475 gdb_assert (slot
!= NULL
);
18476 gdb_assert (*slot
== NULL
);
18479 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18480 per_cu
->offset
.sect_off
);
18481 obstack_grow (&cu_list
, val
, 8);
18482 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18483 obstack_grow (&cu_list
, val
, 8);
18486 /* Dump the address map. */
18487 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18489 /* Write out the .debug_type entries, if any. */
18490 if (dwarf2_per_objfile
->signatured_types
)
18492 struct signatured_type_index_data sig_data
;
18494 sig_data
.objfile
= objfile
;
18495 sig_data
.symtab
= symtab
;
18496 sig_data
.types_list
= &types_cu_list
;
18497 sig_data
.psyms_seen
= psyms_seen
;
18498 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18499 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18500 write_one_signatured_type
, &sig_data
);
18503 obstack_init (&constant_pool
);
18504 make_cleanup_obstack_free (&constant_pool
);
18505 obstack_init (&symtab_obstack
);
18506 make_cleanup_obstack_free (&symtab_obstack
);
18507 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18509 obstack_init (&contents
);
18510 make_cleanup_obstack_free (&contents
);
18511 size_of_contents
= 6 * sizeof (offset_type
);
18512 total_len
= size_of_contents
;
18514 /* The version number. */
18515 val
= MAYBE_SWAP (6);
18516 obstack_grow (&contents
, &val
, sizeof (val
));
18518 /* The offset of the CU list from the start of the file. */
18519 val
= MAYBE_SWAP (total_len
);
18520 obstack_grow (&contents
, &val
, sizeof (val
));
18521 total_len
+= obstack_object_size (&cu_list
);
18523 /* The offset of the types CU list from the start of the file. */
18524 val
= MAYBE_SWAP (total_len
);
18525 obstack_grow (&contents
, &val
, sizeof (val
));
18526 total_len
+= obstack_object_size (&types_cu_list
);
18528 /* The offset of the address table from the start of the file. */
18529 val
= MAYBE_SWAP (total_len
);
18530 obstack_grow (&contents
, &val
, sizeof (val
));
18531 total_len
+= obstack_object_size (&addr_obstack
);
18533 /* The offset of the symbol table from the start of the file. */
18534 val
= MAYBE_SWAP (total_len
);
18535 obstack_grow (&contents
, &val
, sizeof (val
));
18536 total_len
+= obstack_object_size (&symtab_obstack
);
18538 /* The offset of the constant pool from the start of the file. */
18539 val
= MAYBE_SWAP (total_len
);
18540 obstack_grow (&contents
, &val
, sizeof (val
));
18541 total_len
+= obstack_object_size (&constant_pool
);
18543 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18545 write_obstack (out_file
, &contents
);
18546 write_obstack (out_file
, &cu_list
);
18547 write_obstack (out_file
, &types_cu_list
);
18548 write_obstack (out_file
, &addr_obstack
);
18549 write_obstack (out_file
, &symtab_obstack
);
18550 write_obstack (out_file
, &constant_pool
);
18554 /* We want to keep the file, so we set cleanup_filename to NULL
18555 here. See unlink_if_set. */
18556 cleanup_filename
= NULL
;
18558 do_cleanups (cleanup
);
18561 /* Implementation of the `save gdb-index' command.
18563 Note that the file format used by this command is documented in the
18564 GDB manual. Any changes here must be documented there. */
18567 save_gdb_index_command (char *arg
, int from_tty
)
18569 struct objfile
*objfile
;
18572 error (_("usage: save gdb-index DIRECTORY"));
18574 ALL_OBJFILES (objfile
)
18578 /* If the objfile does not correspond to an actual file, skip it. */
18579 if (stat (objfile
->name
, &st
) < 0)
18582 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18583 if (dwarf2_per_objfile
)
18585 volatile struct gdb_exception except
;
18587 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18589 write_psymtabs_to_index (objfile
, arg
);
18591 if (except
.reason
< 0)
18592 exception_fprintf (gdb_stderr
, except
,
18593 _("Error while writing index for `%s': "),
18601 int dwarf2_always_disassemble
;
18604 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18605 struct cmd_list_element
*c
, const char *value
)
18607 fprintf_filtered (file
,
18608 _("Whether to always disassemble "
18609 "DWARF expressions is %s.\n"),
18614 show_check_physname (struct ui_file
*file
, int from_tty
,
18615 struct cmd_list_element
*c
, const char *value
)
18617 fprintf_filtered (file
,
18618 _("Whether to check \"physname\" is %s.\n"),
18622 void _initialize_dwarf2_read (void);
18625 _initialize_dwarf2_read (void)
18627 struct cmd_list_element
*c
;
18629 dwarf2_objfile_data_key
18630 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18632 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18633 Set DWARF 2 specific variables.\n\
18634 Configure DWARF 2 variables such as the cache size"),
18635 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18636 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18638 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18639 Show DWARF 2 specific variables\n\
18640 Show DWARF 2 variables such as the cache size"),
18641 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18642 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18644 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18645 &dwarf2_max_cache_age
, _("\
18646 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18647 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18648 A higher limit means that cached compilation units will be stored\n\
18649 in memory longer, and more total memory will be used. Zero disables\n\
18650 caching, which can slow down startup."),
18652 show_dwarf2_max_cache_age
,
18653 &set_dwarf2_cmdlist
,
18654 &show_dwarf2_cmdlist
);
18656 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18657 &dwarf2_always_disassemble
, _("\
18658 Set whether `info address' always disassembles DWARF expressions."), _("\
18659 Show whether `info address' always disassembles DWARF expressions."), _("\
18660 When enabled, DWARF expressions are always printed in an assembly-like\n\
18661 syntax. When disabled, expressions will be printed in a more\n\
18662 conversational style, when possible."),
18664 show_dwarf2_always_disassemble
,
18665 &set_dwarf2_cmdlist
,
18666 &show_dwarf2_cmdlist
);
18668 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18669 Set debugging of the dwarf2 DIE reader."), _("\
18670 Show debugging of the dwarf2 DIE reader."), _("\
18671 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18672 The value is the maximum depth to print."),
18675 &setdebuglist
, &showdebuglist
);
18677 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18678 Set cross-checking of \"physname\" code against demangler."), _("\
18679 Show cross-checking of \"physname\" code against demangler."), _("\
18680 When enabled, GDB's internal \"physname\" code is checked against\n\
18682 NULL
, show_check_physname
,
18683 &setdebuglist
, &showdebuglist
);
18685 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18687 Save a gdb-index file.\n\
18688 Usage: save gdb-index DIRECTORY"),
18690 set_cmd_completer (c
, filename_completer
);