1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
68 #include "gdb_string.h"
69 #include "gdb_assert.h"
70 #include <sys/types.h>
77 #define MAP_FAILED ((void *) -1)
81 typedef struct symbol
*symbolp
;
84 /* When non-zero, dump DIEs after they are read in. */
85 static int dwarf2_die_debug
= 0;
87 /* When non-zero, cross-check physname against demangler. */
88 static int check_physname
= 0;
90 /* When non-zero, do not reject deprecated .gdb_index sections. */
91 int use_deprecated_index_sections
= 0;
95 /* When set, the file that we're processing is known to have debugging
96 info for C++ namespaces. GCC 3.3.x did not produce this information,
97 but later versions do. */
99 static int processing_has_namespace_info
;
101 static const struct objfile_data
*dwarf2_objfile_data_key
;
103 struct dwarf2_section_info
108 /* Not NULL if the section was actually mmapped. */
110 /* Page aligned size of mmapped area. */
111 bfd_size_type map_len
;
112 /* True if we have tried to read this section. */
116 typedef struct dwarf2_section_info dwarf2_section_info_def
;
117 DEF_VEC_O (dwarf2_section_info_def
);
119 /* All offsets in the index are of this type. It must be
120 architecture-independent. */
121 typedef uint32_t offset_type
;
123 DEF_VEC_I (offset_type
);
125 /* A description of the mapped index. The file format is described in
126 a comment by the code that writes the index. */
129 /* Index data format version. */
132 /* The total length of the buffer. */
135 /* A pointer to the address table data. */
136 const gdb_byte
*address_table
;
138 /* Size of the address table data in bytes. */
139 offset_type address_table_size
;
141 /* The symbol table, implemented as a hash table. */
142 const offset_type
*symbol_table
;
144 /* Size in slots, each slot is 2 offset_types. */
145 offset_type symbol_table_slots
;
147 /* A pointer to the constant pool. */
148 const char *constant_pool
;
151 /* Collection of data recorded per objfile.
152 This hangs off of dwarf2_objfile_data_key. */
154 struct dwarf2_per_objfile
156 struct dwarf2_section_info info
;
157 struct dwarf2_section_info abbrev
;
158 struct dwarf2_section_info line
;
159 struct dwarf2_section_info loc
;
160 struct dwarf2_section_info macinfo
;
161 struct dwarf2_section_info macro
;
162 struct dwarf2_section_info str
;
163 struct dwarf2_section_info ranges
;
164 struct dwarf2_section_info addr
;
165 struct dwarf2_section_info frame
;
166 struct dwarf2_section_info eh_frame
;
167 struct dwarf2_section_info gdb_index
;
169 VEC (dwarf2_section_info_def
) *types
;
172 struct objfile
*objfile
;
174 /* Table of all the compilation units. This is used to locate
175 the target compilation unit of a particular reference. */
176 struct dwarf2_per_cu_data
**all_comp_units
;
178 /* The number of compilation units in ALL_COMP_UNITS. */
181 /* The number of .debug_types-related CUs. */
184 /* The .debug_types-related CUs (TUs). */
185 struct dwarf2_per_cu_data
**all_type_units
;
187 /* A chain of compilation units that are currently read in, so that
188 they can be freed later. */
189 struct dwarf2_per_cu_data
*read_in_chain
;
191 /* A table mapping .debug_types signatures to its signatured_type entry.
192 This is NULL if the .debug_types section hasn't been read in yet. */
193 htab_t signatured_types
;
195 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
196 This is NULL if the table hasn't been allocated yet. */
199 /* A flag indicating wether this objfile has a section loaded at a
201 int has_section_at_zero
;
203 /* True if we are using the mapped index,
204 or we are faking it for OBJF_READNOW's sake. */
205 unsigned char using_index
;
207 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
208 struct mapped_index
*index_table
;
210 /* When using index_table, this keeps track of all quick_file_names entries.
211 TUs can share line table entries with CUs or other TUs, and there can be
212 a lot more TUs than unique line tables, so we maintain a separate table
213 of all line table entries to support the sharing. */
214 htab_t quick_file_names_table
;
216 /* Set during partial symbol reading, to prevent queueing of full
218 int reading_partial_symbols
;
220 /* Table mapping type DIEs to their struct type *.
221 This is NULL if not allocated yet.
222 The mapping is done via (CU/TU signature + DIE offset) -> type. */
223 htab_t die_type_hash
;
226 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
228 /* Default names of the debugging sections. */
230 /* Note that if the debugging section has been compressed, it might
231 have a name like .zdebug_info. */
233 static const struct dwarf2_debug_sections dwarf2_elf_names
=
235 { ".debug_info", ".zdebug_info" },
236 { ".debug_abbrev", ".zdebug_abbrev" },
237 { ".debug_line", ".zdebug_line" },
238 { ".debug_loc", ".zdebug_loc" },
239 { ".debug_macinfo", ".zdebug_macinfo" },
240 { ".debug_macro", ".zdebug_macro" },
241 { ".debug_str", ".zdebug_str" },
242 { ".debug_ranges", ".zdebug_ranges" },
243 { ".debug_types", ".zdebug_types" },
244 { ".debug_addr", ".zdebug_addr" },
245 { ".debug_frame", ".zdebug_frame" },
246 { ".eh_frame", NULL
},
247 { ".gdb_index", ".zgdb_index" },
251 /* List of DWO sections. */
253 static const struct dwo_section_names
255 struct dwarf2_section_names abbrev_dwo
;
256 struct dwarf2_section_names info_dwo
;
257 struct dwarf2_section_names line_dwo
;
258 struct dwarf2_section_names loc_dwo
;
259 struct dwarf2_section_names str_dwo
;
260 struct dwarf2_section_names str_offsets_dwo
;
261 struct dwarf2_section_names types_dwo
;
265 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
266 { ".debug_info.dwo", ".zdebug_info.dwo" },
267 { ".debug_line.dwo", ".zdebug_line.dwo" },
268 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
269 { ".debug_str.dwo", ".zdebug_str.dwo" },
270 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
271 { ".debug_types.dwo", ".zdebug_types.dwo" },
274 /* local data types */
276 /* We hold several abbreviation tables in memory at the same time. */
277 #ifndef ABBREV_HASH_SIZE
278 #define ABBREV_HASH_SIZE 121
281 /* The data in a compilation unit header, after target2host
282 translation, looks like this. */
283 struct comp_unit_head
287 unsigned char addr_size
;
288 unsigned char signed_addr_p
;
289 sect_offset abbrev_offset
;
291 /* Size of file offsets; either 4 or 8. */
292 unsigned int offset_size
;
294 /* Size of the length field; either 4 or 12. */
295 unsigned int initial_length_size
;
297 /* Offset to the first byte of this compilation unit header in the
298 .debug_info section, for resolving relative reference dies. */
301 /* Offset to first die in this cu from the start of the cu.
302 This will be the first byte following the compilation unit header. */
303 cu_offset first_die_offset
;
306 /* Type used for delaying computation of method physnames.
307 See comments for compute_delayed_physnames. */
308 struct delayed_method_info
310 /* The type to which the method is attached, i.e., its parent class. */
313 /* The index of the method in the type's function fieldlists. */
316 /* The index of the method in the fieldlist. */
319 /* The name of the DIE. */
322 /* The DIE associated with this method. */
323 struct die_info
*die
;
326 typedef struct delayed_method_info delayed_method_info
;
327 DEF_VEC_O (delayed_method_info
);
329 /* Internal state when decoding a particular compilation unit. */
332 /* The objfile containing this compilation unit. */
333 struct objfile
*objfile
;
335 /* The header of the compilation unit. */
336 struct comp_unit_head header
;
338 /* Base address of this compilation unit. */
339 CORE_ADDR base_address
;
341 /* Non-zero if base_address has been set. */
344 /* The language we are debugging. */
345 enum language language
;
346 const struct language_defn
*language_defn
;
348 const char *producer
;
350 /* The generic symbol table building routines have separate lists for
351 file scope symbols and all all other scopes (local scopes). So
352 we need to select the right one to pass to add_symbol_to_list().
353 We do it by keeping a pointer to the correct list in list_in_scope.
355 FIXME: The original dwarf code just treated the file scope as the
356 first local scope, and all other local scopes as nested local
357 scopes, and worked fine. Check to see if we really need to
358 distinguish these in buildsym.c. */
359 struct pending
**list_in_scope
;
361 /* DWARF abbreviation table associated with this compilation unit. */
362 struct abbrev_info
**dwarf2_abbrevs
;
364 /* Storage for the abbrev table. */
365 struct obstack abbrev_obstack
;
367 /* Hash table holding all the loaded partial DIEs
368 with partial_die->offset.SECT_OFF as hash. */
371 /* Storage for things with the same lifetime as this read-in compilation
372 unit, including partial DIEs. */
373 struct obstack comp_unit_obstack
;
375 /* When multiple dwarf2_cu structures are living in memory, this field
376 chains them all together, so that they can be released efficiently.
377 We will probably also want a generation counter so that most-recently-used
378 compilation units are cached... */
379 struct dwarf2_per_cu_data
*read_in_chain
;
381 /* Backchain to our per_cu entry if the tree has been built. */
382 struct dwarf2_per_cu_data
*per_cu
;
384 /* How many compilation units ago was this CU last referenced? */
387 /* A hash table of DIE cu_offset for following references with
388 die_info->offset.sect_off as hash. */
391 /* Full DIEs if read in. */
392 struct die_info
*dies
;
394 /* A set of pointers to dwarf2_per_cu_data objects for compilation
395 units referenced by this one. Only set during full symbol processing;
396 partial symbol tables do not have dependencies. */
399 /* Header data from the line table, during full symbol processing. */
400 struct line_header
*line_header
;
402 /* A list of methods which need to have physnames computed
403 after all type information has been read. */
404 VEC (delayed_method_info
) *method_list
;
406 /* To be copied to symtab->call_site_htab. */
407 htab_t call_site_htab
;
409 /* Non-NULL if this CU came from a DWO file. */
410 struct dwo_unit
*dwo_unit
;
412 /* The DW_AT_addr_base attribute if present, zero otherwise
413 (zero is a valid value though).
414 Note this value comes from the stub CU/TU's DIE. */
417 /* Mark used when releasing cached dies. */
418 unsigned int mark
: 1;
420 /* This CU references .debug_loc. See the symtab->locations_valid field.
421 This test is imperfect as there may exist optimized debug code not using
422 any location list and still facing inlining issues if handled as
423 unoptimized code. For a future better test see GCC PR other/32998. */
424 unsigned int has_loclist
: 1;
426 /* These cache the results of producer_is_gxx_lt_4_6.
427 CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This
428 information is cached because profiling CU expansion showed
429 excessive time spent in producer_is_gxx_lt_4_6. */
430 unsigned int checked_producer
: 1;
431 unsigned int producer_is_gxx_lt_4_6
: 1;
433 /* Non-zero if DW_AT_addr_base was found.
434 Used when processing DWO files. */
435 unsigned int have_addr_base
: 1;
438 /* Persistent data held for a compilation unit, even when not
439 processing it. We put a pointer to this structure in the
440 read_symtab_private field of the psymtab. */
442 struct dwarf2_per_cu_data
444 /* The start offset and length of this compilation unit. 2**29-1
445 bytes should suffice to store the length of any compilation unit
446 - if it doesn't, GDB will fall over anyway.
447 NOTE: Unlike comp_unit_head.length, this length includes
449 If the DIE refers to a DWO file, this is always of the original die,
452 unsigned int length
: 29;
454 /* Flag indicating this compilation unit will be read in before
455 any of the current compilation units are processed. */
456 unsigned int queued
: 1;
458 /* This flag will be set when reading partial DIEs if we need to load
459 absolutely all DIEs for this compilation unit, instead of just the ones
460 we think are interesting. It gets set if we look for a DIE in the
461 hash table and don't find it. */
462 unsigned int load_all_dies
: 1;
464 /* Non-zero if this CU is from .debug_types. */
465 unsigned int is_debug_types
: 1;
467 /* The section this CU/TU lives in.
468 If the DIE refers to a DWO file, this is always the original die,
470 struct dwarf2_section_info
*info_or_types_section
;
472 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
473 of the CU cache it gets reset to NULL again. */
474 struct dwarf2_cu
*cu
;
476 /* The corresponding objfile.
477 Normally we can get the objfile from dwarf2_per_objfile.
478 However we can enter this file with just a "per_cu" handle. */
479 struct objfile
*objfile
;
481 /* When using partial symbol tables, the 'psymtab' field is active.
482 Otherwise the 'quick' field is active. */
485 /* The partial symbol table associated with this compilation unit,
486 or NULL for partial units (which do not have an associated
488 struct partial_symtab
*psymtab
;
490 /* Data needed by the "quick" functions. */
491 struct dwarf2_per_cu_quick_data
*quick
;
495 /* Entry in the signatured_types hash table. */
497 struct signatured_type
499 /* The type's signature. */
502 /* Offset in the TU of the type's DIE, as read from the TU header.
503 If the definition lives in a DWO file, this value is unusable. */
504 cu_offset type_offset_in_tu
;
506 /* Offset in the section of the type's DIE.
507 If the definition lives in a DWO file, this is the offset in the
508 .debug_types.dwo section.
509 The value is zero until the actual value is known.
510 Zero is otherwise not a valid section offset. */
511 sect_offset type_offset_in_section
;
513 /* The CU(/TU) of this type. */
514 struct dwarf2_per_cu_data per_cu
;
517 /* These sections are what may appear in a "dwo" file. */
521 struct dwarf2_section_info abbrev
;
522 struct dwarf2_section_info info
;
523 struct dwarf2_section_info line
;
524 struct dwarf2_section_info loc
;
525 struct dwarf2_section_info str
;
526 struct dwarf2_section_info str_offsets
;
527 VEC (dwarf2_section_info_def
) *types
;
530 /* Common bits of DWO CUs/TUs. */
534 /* Backlink to the containing struct dwo_file. */
535 struct dwo_file
*dwo_file
;
537 /* The "id" that distinguishes this CU/TU.
538 .debug_info calls this "dwo_id", .debug_types calls this "signature".
539 Since signatures came first, we stick with it for consistency. */
542 /* The section this CU/TU lives in, in the DWO file. */
543 struct dwarf2_section_info
*info_or_types_section
;
545 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
549 /* For types, offset in the type's DIE of the type defined by this TU. */
550 cu_offset type_offset_in_tu
;
553 /* Data for one DWO file. */
557 /* The DW_AT_GNU_dwo_name attribute.
558 We don't manage space for this, it's an attribute. */
559 const char *dwo_name
;
561 /* The bfd, when the file is open. Otherwise this is NULL. */
564 /* Section info for this file. */
565 struct dwo_sections sections
;
567 /* Table of CUs in the file.
568 Each element is a struct dwo_unit. */
571 /* Table of TUs in the file.
572 Each element is a struct dwo_unit. */
576 /* Struct used to pass misc. parameters to read_die_and_children, et
577 al. which are used for both .debug_info and .debug_types dies.
578 All parameters here are unchanging for the life of the call. This
579 struct exists to abstract away the constant parameters of die reading. */
581 struct die_reader_specs
583 /* die_section->asection->owner. */
586 /* The CU of the DIE we are parsing. */
587 struct dwarf2_cu
*cu
;
589 /* Non-NULL if reading a DWO file. */
590 struct dwo_file
*dwo_file
;
592 /* The section the die comes from.
593 This is either .debug_info or .debug_types, or the .dwo variants. */
594 struct dwarf2_section_info
*die_section
;
596 /* die_section->buffer. */
600 /* Type of function passed to init_cutu_and_read_dies, et.al. */
601 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
603 struct die_info
*comp_unit_die
,
607 /* The line number information for a compilation unit (found in the
608 .debug_line section) begins with a "statement program header",
609 which contains the following information. */
612 unsigned int total_length
;
613 unsigned short version
;
614 unsigned int header_length
;
615 unsigned char minimum_instruction_length
;
616 unsigned char maximum_ops_per_instruction
;
617 unsigned char default_is_stmt
;
619 unsigned char line_range
;
620 unsigned char opcode_base
;
622 /* standard_opcode_lengths[i] is the number of operands for the
623 standard opcode whose value is i. This means that
624 standard_opcode_lengths[0] is unused, and the last meaningful
625 element is standard_opcode_lengths[opcode_base - 1]. */
626 unsigned char *standard_opcode_lengths
;
628 /* The include_directories table. NOTE! These strings are not
629 allocated with xmalloc; instead, they are pointers into
630 debug_line_buffer. If you try to free them, `free' will get
632 unsigned int num_include_dirs
, include_dirs_size
;
635 /* The file_names table. NOTE! These strings are not allocated
636 with xmalloc; instead, they are pointers into debug_line_buffer.
637 Don't try to free them directly. */
638 unsigned int num_file_names
, file_names_size
;
642 unsigned int dir_index
;
643 unsigned int mod_time
;
645 int included_p
; /* Non-zero if referenced by the Line Number Program. */
646 struct symtab
*symtab
; /* The associated symbol table, if any. */
649 /* The start and end of the statement program following this
650 header. These point into dwarf2_per_objfile->line_buffer. */
651 gdb_byte
*statement_program_start
, *statement_program_end
;
654 /* When we construct a partial symbol table entry we only
655 need this much information. */
656 struct partial_die_info
658 /* Offset of this DIE. */
661 /* DWARF-2 tag for this DIE. */
662 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
664 /* Assorted flags describing the data found in this DIE. */
665 unsigned int has_children
: 1;
666 unsigned int is_external
: 1;
667 unsigned int is_declaration
: 1;
668 unsigned int has_type
: 1;
669 unsigned int has_specification
: 1;
670 unsigned int has_pc_info
: 1;
671 unsigned int may_be_inlined
: 1;
673 /* Flag set if the SCOPE field of this structure has been
675 unsigned int scope_set
: 1;
677 /* Flag set if the DIE has a byte_size attribute. */
678 unsigned int has_byte_size
: 1;
680 /* Flag set if any of the DIE's children are template arguments. */
681 unsigned int has_template_arguments
: 1;
683 /* Flag set if fixup_partial_die has been called on this die. */
684 unsigned int fixup_called
: 1;
686 /* The name of this DIE. Normally the value of DW_AT_name, but
687 sometimes a default name for unnamed DIEs. */
690 /* The linkage name, if present. */
691 const char *linkage_name
;
693 /* The scope to prepend to our children. This is generally
694 allocated on the comp_unit_obstack, so will disappear
695 when this compilation unit leaves the cache. */
698 /* The location description associated with this DIE, if any. */
699 struct dwarf_block
*locdesc
;
701 /* If HAS_PC_INFO, the PC range associated with this DIE. */
705 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
706 DW_AT_sibling, if any. */
707 /* NOTE: This member isn't strictly necessary, read_partial_die could
708 return DW_AT_sibling values to its caller load_partial_dies. */
711 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
712 DW_AT_specification (or DW_AT_abstract_origin or
714 sect_offset spec_offset
;
716 /* Pointers to this DIE's parent, first child, and next sibling,
718 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
721 /* This data structure holds the information of an abbrev. */
724 unsigned int number
; /* number identifying abbrev */
725 enum dwarf_tag tag
; /* dwarf tag */
726 unsigned short has_children
; /* boolean */
727 unsigned short num_attrs
; /* number of attributes */
728 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
729 struct abbrev_info
*next
; /* next in chain */
734 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
735 ENUM_BITFIELD(dwarf_form
) form
: 16;
738 /* Attributes have a name and a value. */
741 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
742 ENUM_BITFIELD(dwarf_form
) form
: 15;
744 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
745 field should be in u.str (existing only for DW_STRING) but it is kept
746 here for better struct attribute alignment. */
747 unsigned int string_is_canonical
: 1;
752 struct dwarf_block
*blk
;
756 struct signatured_type
*signatured_type
;
761 /* This data structure holds a complete die structure. */
764 /* DWARF-2 tag for this DIE. */
765 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
767 /* Number of attributes */
768 unsigned char num_attrs
;
770 /* True if we're presently building the full type name for the
771 type derived from this DIE. */
772 unsigned char building_fullname
: 1;
777 /* Offset in .debug_info or .debug_types section. */
780 /* The dies in a compilation unit form an n-ary tree. PARENT
781 points to this die's parent; CHILD points to the first child of
782 this node; and all the children of a given node are chained
783 together via their SIBLING fields. */
784 struct die_info
*child
; /* Its first child, if any. */
785 struct die_info
*sibling
; /* Its next sibling, if any. */
786 struct die_info
*parent
; /* Its parent, if any. */
788 /* An array of attributes, with NUM_ATTRS elements. There may be
789 zero, but it's not common and zero-sized arrays are not
790 sufficiently portable C. */
791 struct attribute attrs
[1];
794 /* Get at parts of an attribute structure. */
796 #define DW_STRING(attr) ((attr)->u.str)
797 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
798 #define DW_UNSND(attr) ((attr)->u.unsnd)
799 #define DW_BLOCK(attr) ((attr)->u.blk)
800 #define DW_SND(attr) ((attr)->u.snd)
801 #define DW_ADDR(attr) ((attr)->u.addr)
802 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
804 /* Blocks are a bunch of untyped bytes. */
809 /* Valid only if SIZE is not zero. */
813 #ifndef ATTR_ALLOC_CHUNK
814 #define ATTR_ALLOC_CHUNK 4
817 /* Allocate fields for structs, unions and enums in this size. */
818 #ifndef DW_FIELD_ALLOC_CHUNK
819 #define DW_FIELD_ALLOC_CHUNK 4
822 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
823 but this would require a corresponding change in unpack_field_as_long
825 static int bits_per_byte
= 8;
827 /* The routines that read and process dies for a C struct or C++ class
828 pass lists of data member fields and lists of member function fields
829 in an instance of a field_info structure, as defined below. */
832 /* List of data member and baseclasses fields. */
835 struct nextfield
*next
;
840 *fields
, *baseclasses
;
842 /* Number of fields (including baseclasses). */
845 /* Number of baseclasses. */
848 /* Set if the accesibility of one of the fields is not public. */
849 int non_public_fields
;
851 /* Member function fields array, entries are allocated in the order they
852 are encountered in the object file. */
855 struct nextfnfield
*next
;
856 struct fn_field fnfield
;
860 /* Member function fieldlist array, contains name of possibly overloaded
861 member function, number of overloaded member functions and a pointer
862 to the head of the member function field chain. */
867 struct nextfnfield
*head
;
871 /* Number of entries in the fnfieldlists array. */
874 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
875 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
876 struct typedef_field_list
878 struct typedef_field field
;
879 struct typedef_field_list
*next
;
882 unsigned typedef_field_list_count
;
885 /* One item on the queue of compilation units to read in full symbols
887 struct dwarf2_queue_item
889 struct dwarf2_per_cu_data
*per_cu
;
890 struct dwarf2_queue_item
*next
;
893 /* The current queue. */
894 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
896 /* Loaded secondary compilation units are kept in memory until they
897 have not been referenced for the processing of this many
898 compilation units. Set this to zero to disable caching. Cache
899 sizes of up to at least twenty will improve startup time for
900 typical inter-CU-reference binaries, at an obvious memory cost. */
901 static int dwarf2_max_cache_age
= 5;
903 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
904 struct cmd_list_element
*c
, const char *value
)
906 fprintf_filtered (file
, _("The upper bound on the age of cached "
907 "dwarf2 compilation units is %s.\n"),
912 /* Various complaints about symbol reading that don't abort the process. */
915 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
917 complaint (&symfile_complaints
,
918 _("statement list doesn't fit in .debug_line section"));
922 dwarf2_debug_line_missing_file_complaint (void)
924 complaint (&symfile_complaints
,
925 _(".debug_line section has line data without a file"));
929 dwarf2_debug_line_missing_end_sequence_complaint (void)
931 complaint (&symfile_complaints
,
932 _(".debug_line section has line "
933 "program sequence without an end"));
937 dwarf2_complex_location_expr_complaint (void)
939 complaint (&symfile_complaints
, _("location expression too complex"));
943 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
946 complaint (&symfile_complaints
,
947 _("const value length mismatch for '%s', got %d, expected %d"),
952 dwarf2_macros_too_long_complaint (struct dwarf2_section_info
*section
)
954 complaint (&symfile_complaints
,
955 _("macro info runs off end of `%s' section"),
956 section
->asection
->name
);
960 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
962 complaint (&symfile_complaints
,
963 _("macro debug info contains a "
964 "malformed macro definition:\n`%s'"),
969 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
971 complaint (&symfile_complaints
,
972 _("invalid attribute class or form for '%s' in '%s'"),
976 /* local function prototypes */
978 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
980 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
983 static void dwarf2_find_base_address (struct die_info
*die
,
984 struct dwarf2_cu
*cu
);
986 static void dwarf2_build_psymtabs_hard (struct objfile
*);
988 static void scan_partial_symbols (struct partial_die_info
*,
989 CORE_ADDR
*, CORE_ADDR
*,
990 int, struct dwarf2_cu
*);
992 static void add_partial_symbol (struct partial_die_info
*,
995 static void add_partial_namespace (struct partial_die_info
*pdi
,
996 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
997 int need_pc
, struct dwarf2_cu
*cu
);
999 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1000 CORE_ADDR
*highpc
, int need_pc
,
1001 struct dwarf2_cu
*cu
);
1003 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1004 struct dwarf2_cu
*cu
);
1006 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1007 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1008 int need_pc
, struct dwarf2_cu
*cu
);
1010 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1012 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1014 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1015 struct dwarf2_section_info
*);
1017 static void dwarf2_free_abbrev_table (void *);
1019 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1021 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1022 struct dwarf2_cu
*);
1024 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1025 struct dwarf2_cu
*);
1027 static struct partial_die_info
*load_partial_dies
1028 (const struct die_reader_specs
*, gdb_byte
*, int);
1030 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1031 struct partial_die_info
*,
1032 struct abbrev_info
*,
1036 static struct partial_die_info
*find_partial_die (sect_offset
,
1037 struct dwarf2_cu
*);
1039 static void fixup_partial_die (struct partial_die_info
*,
1040 struct dwarf2_cu
*);
1042 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1043 struct attribute
*, struct attr_abbrev
*,
1046 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1048 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1050 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1052 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1054 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1056 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1059 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1061 static LONGEST read_checked_initial_length_and_offset
1062 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1063 unsigned int *, unsigned int *);
1065 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1068 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1070 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1072 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1074 static char *read_indirect_string (bfd
*, gdb_byte
*,
1075 const struct comp_unit_head
*,
1078 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1080 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1082 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1085 static char *read_str_index (const struct die_reader_specs
*reader
,
1086 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1088 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
1090 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1092 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1093 struct dwarf2_cu
*);
1095 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1097 struct dwarf2_cu
*);
1099 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1100 struct dwarf2_cu
*cu
);
1102 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1104 static struct die_info
*die_specification (struct die_info
*die
,
1105 struct dwarf2_cu
**);
1107 static void free_line_header (struct line_header
*lh
);
1109 static void add_file_name (struct line_header
*, char *, unsigned int,
1110 unsigned int, unsigned int);
1112 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1113 struct dwarf2_cu
*cu
);
1115 static void dwarf_decode_lines (struct line_header
*, const char *,
1116 struct dwarf2_cu
*, struct partial_symtab
*,
1119 static void dwarf2_start_subfile (char *, const char *, const char *);
1121 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1122 struct dwarf2_cu
*);
1124 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1125 struct dwarf2_cu
*, struct symbol
*);
1127 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1128 struct dwarf2_cu
*);
1130 static void dwarf2_const_value_attr (struct attribute
*attr
,
1133 struct obstack
*obstack
,
1134 struct dwarf2_cu
*cu
, LONGEST
*value
,
1136 struct dwarf2_locexpr_baton
**baton
);
1138 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1140 static int need_gnat_info (struct dwarf2_cu
*);
1142 static struct type
*die_descriptive_type (struct die_info
*,
1143 struct dwarf2_cu
*);
1145 static void set_descriptive_type (struct type
*, struct die_info
*,
1146 struct dwarf2_cu
*);
1148 static struct type
*die_containing_type (struct die_info
*,
1149 struct dwarf2_cu
*);
1151 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1152 struct dwarf2_cu
*);
1154 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1156 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1158 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1160 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1161 const char *suffix
, int physname
,
1162 struct dwarf2_cu
*cu
);
1164 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1166 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1168 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1170 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1172 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1174 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1175 struct dwarf2_cu
*, struct partial_symtab
*);
1177 static int dwarf2_get_pc_bounds (struct die_info
*,
1178 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1179 struct partial_symtab
*);
1181 static void get_scope_pc_bounds (struct die_info
*,
1182 CORE_ADDR
*, CORE_ADDR
*,
1183 struct dwarf2_cu
*);
1185 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1186 CORE_ADDR
, struct dwarf2_cu
*);
1188 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1189 struct dwarf2_cu
*);
1191 static void dwarf2_attach_fields_to_type (struct field_info
*,
1192 struct type
*, struct dwarf2_cu
*);
1194 static void dwarf2_add_member_fn (struct field_info
*,
1195 struct die_info
*, struct type
*,
1196 struct dwarf2_cu
*);
1198 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1200 struct dwarf2_cu
*);
1202 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1204 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1206 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1208 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1210 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1212 static struct type
*read_module_type (struct die_info
*die
,
1213 struct dwarf2_cu
*cu
);
1215 static const char *namespace_name (struct die_info
*die
,
1216 int *is_anonymous
, struct dwarf2_cu
*);
1218 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1220 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1222 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1223 struct dwarf2_cu
*);
1225 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1227 gdb_byte
**new_info_ptr
,
1228 struct die_info
*parent
);
1230 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1232 gdb_byte
**new_info_ptr
,
1233 struct die_info
*parent
);
1235 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1236 struct die_info
**, gdb_byte
*, int *, int);
1238 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1239 struct die_info
**, gdb_byte
*, int *);
1241 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1243 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1246 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1248 static const char *dwarf2_full_name (char *name
,
1249 struct die_info
*die
,
1250 struct dwarf2_cu
*cu
);
1252 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1253 struct dwarf2_cu
**);
1255 static 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_cutu_and_read_dies
1405 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_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,
1678 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1680 return info
->asection
== NULL
|| info
->size
== 0;
1683 /* Read the contents of the section INFO.
1684 OBJFILE is the main object file, but not necessarily the file where
1685 the section comes from. E.g., for DWO files INFO->asection->owner
1686 is the bfd of the DWO file.
1687 If the section is compressed, uncompress it before returning. */
1690 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1692 asection
*sectp
= info
->asection
;
1694 gdb_byte
*buf
, *retbuf
;
1695 unsigned char header
[4];
1699 info
->buffer
= NULL
;
1700 info
->map_addr
= NULL
;
1703 if (dwarf2_section_empty_p (info
))
1706 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1707 abfd
= sectp
->owner
;
1709 /* Check if the file has a 4-byte header indicating compression. */
1710 if (info
->size
> sizeof (header
)
1711 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1712 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1714 /* Upon decompression, update the buffer and its size. */
1715 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1717 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1725 pagesize
= getpagesize ();
1727 /* Only try to mmap sections which are large enough: we don't want to
1728 waste space due to fragmentation. Also, only try mmap for sections
1729 without relocations. */
1731 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1733 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1734 MAP_PRIVATE
, sectp
->filepos
,
1735 &info
->map_addr
, &info
->map_len
);
1737 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1739 #if HAVE_POSIX_MADVISE
1740 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1747 /* If we get here, we are a normal, not-compressed section. */
1749 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1751 /* When debugging .o files, we may need to apply relocations; see
1752 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1753 We never compress sections in .o files, so we only need to
1754 try this when the section is not compressed. */
1755 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1758 info
->buffer
= retbuf
;
1762 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1763 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1764 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1765 bfd_get_filename (abfd
));
1768 /* A helper function that returns the size of a section in a safe way.
1769 If you are positive that the section has been read before using the
1770 size, then it is safe to refer to the dwarf2_section_info object's
1771 "size" field directly. In other cases, you must call this
1772 function, because for compressed sections the size field is not set
1773 correctly until the section has been read. */
1775 static bfd_size_type
1776 dwarf2_section_size (struct objfile
*objfile
,
1777 struct dwarf2_section_info
*info
)
1780 dwarf2_read_section (objfile
, info
);
1784 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1788 dwarf2_get_section_info (struct objfile
*objfile
,
1789 enum dwarf2_section_enum sect
,
1790 asection
**sectp
, gdb_byte
**bufp
,
1791 bfd_size_type
*sizep
)
1793 struct dwarf2_per_objfile
*data
1794 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1795 struct dwarf2_section_info
*info
;
1797 /* We may see an objfile without any DWARF, in which case we just
1808 case DWARF2_DEBUG_FRAME
:
1809 info
= &data
->frame
;
1811 case DWARF2_EH_FRAME
:
1812 info
= &data
->eh_frame
;
1815 gdb_assert_not_reached ("unexpected section");
1818 dwarf2_read_section (objfile
, info
);
1820 *sectp
= info
->asection
;
1821 *bufp
= info
->buffer
;
1822 *sizep
= info
->size
;
1826 /* DWARF quick_symbols_functions support. */
1828 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1829 unique line tables, so we maintain a separate table of all .debug_line
1830 derived entries to support the sharing.
1831 All the quick functions need is the list of file names. We discard the
1832 line_header when we're done and don't need to record it here. */
1833 struct quick_file_names
1835 /* The offset in .debug_line of the line table. We hash on this. */
1836 unsigned int offset
;
1838 /* The number of entries in file_names, real_names. */
1839 unsigned int num_file_names
;
1841 /* The file names from the line table, after being run through
1843 const char **file_names
;
1845 /* The file names from the line table after being run through
1846 gdb_realpath. These are computed lazily. */
1847 const char **real_names
;
1850 /* When using the index (and thus not using psymtabs), each CU has an
1851 object of this type. This is used to hold information needed by
1852 the various "quick" methods. */
1853 struct dwarf2_per_cu_quick_data
1855 /* The file table. This can be NULL if there was no file table
1856 or it's currently not read in.
1857 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1858 struct quick_file_names
*file_names
;
1860 /* The corresponding symbol table. This is NULL if symbols for this
1861 CU have not yet been read. */
1862 struct symtab
*symtab
;
1864 /* A temporary mark bit used when iterating over all CUs in
1865 expand_symtabs_matching. */
1866 unsigned int mark
: 1;
1868 /* True if we've tried to read the file table and found there isn't one.
1869 There will be no point in trying to read it again next time. */
1870 unsigned int no_file_data
: 1;
1873 /* Hash function for a quick_file_names. */
1876 hash_file_name_entry (const void *e
)
1878 const struct quick_file_names
*file_data
= e
;
1880 return file_data
->offset
;
1883 /* Equality function for a quick_file_names. */
1886 eq_file_name_entry (const void *a
, const void *b
)
1888 const struct quick_file_names
*ea
= a
;
1889 const struct quick_file_names
*eb
= b
;
1891 return ea
->offset
== eb
->offset
;
1894 /* Delete function for a quick_file_names. */
1897 delete_file_name_entry (void *e
)
1899 struct quick_file_names
*file_data
= e
;
1902 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1904 xfree ((void*) file_data
->file_names
[i
]);
1905 if (file_data
->real_names
)
1906 xfree ((void*) file_data
->real_names
[i
]);
1909 /* The space for the struct itself lives on objfile_obstack,
1910 so we don't free it here. */
1913 /* Create a quick_file_names hash table. */
1916 create_quick_file_names_table (unsigned int nr_initial_entries
)
1918 return htab_create_alloc (nr_initial_entries
,
1919 hash_file_name_entry
, eq_file_name_entry
,
1920 delete_file_name_entry
, xcalloc
, xfree
);
1923 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1924 have to be created afterwards. You should call age_cached_comp_units after
1925 processing PER_CU->CU. dw2_setup must have been already called. */
1928 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1930 if (per_cu
->is_debug_types
)
1931 load_full_type_unit (per_cu
);
1933 load_full_comp_unit (per_cu
);
1935 gdb_assert (per_cu
->cu
!= NULL
);
1937 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
1940 /* Read in the symbols for PER_CU. */
1943 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1945 struct cleanup
*back_to
;
1947 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1949 queue_comp_unit (per_cu
);
1955 /* Age the cache, releasing compilation units that have not
1956 been used recently. */
1957 age_cached_comp_units ();
1959 do_cleanups (back_to
);
1962 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1963 the objfile from which this CU came. Returns the resulting symbol
1966 static struct symtab
*
1967 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
1969 if (!per_cu
->v
.quick
->symtab
)
1971 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1972 increment_reading_symtab ();
1973 dw2_do_instantiate_symtab (per_cu
);
1974 do_cleanups (back_to
);
1976 return per_cu
->v
.quick
->symtab
;
1979 /* Return the CU given its index. */
1981 static struct dwarf2_per_cu_data
*
1982 dw2_get_cu (int index
)
1984 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1986 index
-= dwarf2_per_objfile
->n_comp_units
;
1987 return dwarf2_per_objfile
->all_type_units
[index
];
1989 return dwarf2_per_objfile
->all_comp_units
[index
];
1992 /* A helper function that knows how to read a 64-bit value in a way
1993 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1997 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1999 if (sizeof (ULONGEST
) < 8)
2003 /* Ignore the upper 4 bytes if they are all zero. */
2004 for (i
= 0; i
< 4; ++i
)
2005 if (bytes
[i
+ 4] != 0)
2008 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2011 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2015 /* Read the CU list from the mapped index, and use it to create all
2016 the CU objects for this objfile. Return 0 if something went wrong,
2017 1 if everything went ok. */
2020 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2021 offset_type cu_list_elements
)
2025 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2026 dwarf2_per_objfile
->all_comp_units
2027 = obstack_alloc (&objfile
->objfile_obstack
,
2028 dwarf2_per_objfile
->n_comp_units
2029 * sizeof (struct dwarf2_per_cu_data
*));
2031 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2033 struct dwarf2_per_cu_data
*the_cu
;
2034 ULONGEST offset
, length
;
2036 if (!extract_cu_value (cu_list
, &offset
)
2037 || !extract_cu_value (cu_list
+ 8, &length
))
2041 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2042 struct dwarf2_per_cu_data
);
2043 the_cu
->offset
.sect_off
= offset
;
2044 the_cu
->length
= length
;
2045 the_cu
->objfile
= objfile
;
2046 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2047 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2048 struct dwarf2_per_cu_quick_data
);
2049 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2055 /* Create the signatured type hash table from the index. */
2058 create_signatured_type_table_from_index (struct objfile
*objfile
,
2059 struct dwarf2_section_info
*section
,
2060 const gdb_byte
*bytes
,
2061 offset_type elements
)
2064 htab_t sig_types_hash
;
2066 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2067 dwarf2_per_objfile
->all_type_units
2068 = obstack_alloc (&objfile
->objfile_obstack
,
2069 dwarf2_per_objfile
->n_type_units
2070 * sizeof (struct dwarf2_per_cu_data
*));
2072 sig_types_hash
= allocate_signatured_type_table (objfile
);
2074 for (i
= 0; i
< elements
; i
+= 3)
2076 struct signatured_type
*sig_type
;
2077 ULONGEST offset
, type_offset_in_tu
, signature
;
2080 if (!extract_cu_value (bytes
, &offset
)
2081 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2083 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2086 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2087 struct signatured_type
);
2088 sig_type
->signature
= signature
;
2089 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2090 sig_type
->per_cu
.is_debug_types
= 1;
2091 sig_type
->per_cu
.info_or_types_section
= section
;
2092 sig_type
->per_cu
.offset
.sect_off
= offset
;
2093 sig_type
->per_cu
.objfile
= objfile
;
2094 sig_type
->per_cu
.v
.quick
2095 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2096 struct dwarf2_per_cu_quick_data
);
2098 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2101 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2104 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2109 /* Read the address map data from the mapped index, and use it to
2110 populate the objfile's psymtabs_addrmap. */
2113 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2115 const gdb_byte
*iter
, *end
;
2116 struct obstack temp_obstack
;
2117 struct addrmap
*mutable_map
;
2118 struct cleanup
*cleanup
;
2121 obstack_init (&temp_obstack
);
2122 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2123 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2125 iter
= index
->address_table
;
2126 end
= iter
+ index
->address_table_size
;
2128 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2132 ULONGEST hi
, lo
, cu_index
;
2133 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2135 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2137 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2140 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2141 dw2_get_cu (cu_index
));
2144 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2145 &objfile
->objfile_obstack
);
2146 do_cleanups (cleanup
);
2149 /* The hash function for strings in the mapped index. This is the same as
2150 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2151 implementation. This is necessary because the hash function is tied to the
2152 format of the mapped index file. The hash values do not have to match with
2155 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2158 mapped_index_string_hash (int index_version
, const void *p
)
2160 const unsigned char *str
= (const unsigned char *) p
;
2164 while ((c
= *str
++) != 0)
2166 if (index_version
>= 5)
2168 r
= r
* 67 + c
- 113;
2174 /* Find a slot in the mapped index INDEX for the object named NAME.
2175 If NAME is found, set *VEC_OUT to point to the CU vector in the
2176 constant pool and return 1. If NAME cannot be found, return 0. */
2179 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2180 offset_type
**vec_out
)
2182 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2184 offset_type slot
, step
;
2185 int (*cmp
) (const char *, const char *);
2187 if (current_language
->la_language
== language_cplus
2188 || current_language
->la_language
== language_java
2189 || current_language
->la_language
== language_fortran
)
2191 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2193 const char *paren
= strchr (name
, '(');
2199 dup
= xmalloc (paren
- name
+ 1);
2200 memcpy (dup
, name
, paren
- name
);
2201 dup
[paren
- name
] = 0;
2203 make_cleanup (xfree
, dup
);
2208 /* Index version 4 did not support case insensitive searches. But the
2209 indices for case insensitive languages are built in lowercase, therefore
2210 simulate our NAME being searched is also lowercased. */
2211 hash
= mapped_index_string_hash ((index
->version
== 4
2212 && case_sensitivity
== case_sensitive_off
2213 ? 5 : index
->version
),
2216 slot
= hash
& (index
->symbol_table_slots
- 1);
2217 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2218 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2222 /* Convert a slot number to an offset into the table. */
2223 offset_type i
= 2 * slot
;
2225 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2227 do_cleanups (back_to
);
2231 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2232 if (!cmp (name
, str
))
2234 *vec_out
= (offset_type
*) (index
->constant_pool
2235 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2236 do_cleanups (back_to
);
2240 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2244 /* Read the index file. If everything went ok, initialize the "quick"
2245 elements of all the CUs and return 1. Otherwise, return 0. */
2248 dwarf2_read_index (struct objfile
*objfile
)
2251 struct mapped_index
*map
;
2252 offset_type
*metadata
;
2253 const gdb_byte
*cu_list
;
2254 const gdb_byte
*types_list
= NULL
;
2255 offset_type version
, cu_list_elements
;
2256 offset_type types_list_elements
= 0;
2259 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2262 /* Older elfutils strip versions could keep the section in the main
2263 executable while splitting it for the separate debug info file. */
2264 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2265 & SEC_HAS_CONTENTS
) == 0)
2268 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2270 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2271 /* Version check. */
2272 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2273 /* Versions earlier than 3 emitted every copy of a psymbol. This
2274 causes the index to behave very poorly for certain requests. Version 3
2275 contained incomplete addrmap. So, it seems better to just ignore such
2279 static int warning_printed
= 0;
2280 if (!warning_printed
)
2282 warning (_("Skipping obsolete .gdb_index section in %s."),
2284 warning_printed
= 1;
2288 /* Index version 4 uses a different hash function than index version
2291 Versions earlier than 6 did not emit psymbols for inlined
2292 functions. Using these files will cause GDB not to be able to
2293 set breakpoints on inlined functions by name, so we ignore these
2294 indices unless the --use-deprecated-index-sections command line
2295 option was supplied. */
2296 if (version
< 6 && !use_deprecated_index_sections
)
2298 static int warning_printed
= 0;
2299 if (!warning_printed
)
2301 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2302 "--use-deprecated-index-sections to use them anyway"),
2304 warning_printed
= 1;
2308 /* Indexes with higher version than the one supported by GDB may be no
2309 longer backward compatible. */
2313 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2314 map
->version
= version
;
2315 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2317 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2320 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2321 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2325 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2326 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2327 - MAYBE_SWAP (metadata
[i
]))
2331 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2332 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2333 - MAYBE_SWAP (metadata
[i
]));
2336 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2337 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2338 - MAYBE_SWAP (metadata
[i
]))
2339 / (2 * sizeof (offset_type
)));
2342 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2344 /* Don't use the index if it's empty. */
2345 if (map
->symbol_table_slots
== 0)
2348 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2351 if (types_list_elements
)
2353 struct dwarf2_section_info
*section
;
2355 /* We can only handle a single .debug_types when we have an
2357 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2360 section
= VEC_index (dwarf2_section_info_def
,
2361 dwarf2_per_objfile
->types
, 0);
2363 if (!create_signatured_type_table_from_index (objfile
, section
,
2365 types_list_elements
))
2369 create_addrmap_from_index (objfile
, map
);
2371 dwarf2_per_objfile
->index_table
= map
;
2372 dwarf2_per_objfile
->using_index
= 1;
2373 dwarf2_per_objfile
->quick_file_names_table
=
2374 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2379 /* A helper for the "quick" functions which sets the global
2380 dwarf2_per_objfile according to OBJFILE. */
2383 dw2_setup (struct objfile
*objfile
)
2385 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2386 gdb_assert (dwarf2_per_objfile
);
2389 /* die_reader_func for dw2_get_file_names. */
2392 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2394 struct die_info
*comp_unit_die
,
2398 struct dwarf2_cu
*cu
= reader
->cu
;
2399 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2400 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2401 struct line_header
*lh
;
2402 struct attribute
*attr
;
2404 unsigned int bytes_read
;
2405 char *name
, *comp_dir
;
2407 struct quick_file_names
*qfn
;
2408 unsigned int line_offset
;
2414 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2417 struct quick_file_names find_entry
;
2419 line_offset
= DW_UNSND (attr
);
2421 /* We may have already read in this line header (TU line header sharing).
2422 If we have we're done. */
2423 find_entry
.offset
= line_offset
;
2424 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2425 &find_entry
, INSERT
);
2428 this_cu
->v
.quick
->file_names
= *slot
;
2432 lh
= dwarf_decode_line_header (line_offset
, cu
);
2436 this_cu
->v
.quick
->no_file_data
= 1;
2440 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2441 qfn
->offset
= line_offset
;
2442 gdb_assert (slot
!= NULL
);
2445 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2447 qfn
->num_file_names
= lh
->num_file_names
;
2448 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2449 lh
->num_file_names
* sizeof (char *));
2450 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2451 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2452 qfn
->real_names
= NULL
;
2454 free_line_header (lh
);
2456 this_cu
->v
.quick
->file_names
= qfn
;
2459 /* A helper for the "quick" functions which attempts to read the line
2460 table for THIS_CU. */
2462 static struct quick_file_names
*
2463 dw2_get_file_names (struct objfile
*objfile
,
2464 struct dwarf2_per_cu_data
*this_cu
)
2466 if (this_cu
->v
.quick
->file_names
!= NULL
)
2467 return this_cu
->v
.quick
->file_names
;
2468 /* If we know there is no line data, no point in looking again. */
2469 if (this_cu
->v
.quick
->no_file_data
)
2472 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2473 in the stub for CUs, there's is no need to lookup the DWO file.
2474 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2476 if (this_cu
->is_debug_types
)
2477 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2479 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2481 if (this_cu
->v
.quick
->no_file_data
)
2483 return this_cu
->v
.quick
->file_names
;
2486 /* A helper for the "quick" functions which computes and caches the
2487 real path for a given file name from the line table. */
2490 dw2_get_real_path (struct objfile
*objfile
,
2491 struct quick_file_names
*qfn
, int index
)
2493 if (qfn
->real_names
== NULL
)
2494 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2495 qfn
->num_file_names
, sizeof (char *));
2497 if (qfn
->real_names
[index
] == NULL
)
2498 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2500 return qfn
->real_names
[index
];
2503 static struct symtab
*
2504 dw2_find_last_source_symtab (struct objfile
*objfile
)
2508 dw2_setup (objfile
);
2509 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2510 return dw2_instantiate_symtab (dw2_get_cu (index
));
2513 /* Traversal function for dw2_forget_cached_source_info. */
2516 dw2_free_cached_file_names (void **slot
, void *info
)
2518 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2520 if (file_data
->real_names
)
2524 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2526 xfree ((void*) file_data
->real_names
[i
]);
2527 file_data
->real_names
[i
] = NULL
;
2535 dw2_forget_cached_source_info (struct objfile
*objfile
)
2537 dw2_setup (objfile
);
2539 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2540 dw2_free_cached_file_names
, NULL
);
2543 /* Helper function for dw2_map_symtabs_matching_filename that expands
2544 the symtabs and calls the iterator. */
2547 dw2_map_expand_apply (struct objfile
*objfile
,
2548 struct dwarf2_per_cu_data
*per_cu
,
2550 const char *full_path
, const char *real_path
,
2551 int (*callback
) (struct symtab
*, void *),
2554 struct symtab
*last_made
= objfile
->symtabs
;
2556 /* Don't visit already-expanded CUs. */
2557 if (per_cu
->v
.quick
->symtab
)
2560 /* This may expand more than one symtab, and we want to iterate over
2562 dw2_instantiate_symtab (per_cu
);
2564 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2565 objfile
->symtabs
, last_made
);
2568 /* Implementation of the map_symtabs_matching_filename method. */
2571 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2572 const char *full_path
, const char *real_path
,
2573 int (*callback
) (struct symtab
*, void *),
2577 const char *name_basename
= lbasename (name
);
2578 int name_len
= strlen (name
);
2579 int is_abs
= IS_ABSOLUTE_PATH (name
);
2581 dw2_setup (objfile
);
2583 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2584 + dwarf2_per_objfile
->n_type_units
); ++i
)
2587 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2588 struct quick_file_names
*file_data
;
2590 /* We only need to look at symtabs not already expanded. */
2591 if (per_cu
->v
.quick
->symtab
)
2594 file_data
= dw2_get_file_names (objfile
, per_cu
);
2595 if (file_data
== NULL
)
2598 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2600 const char *this_name
= file_data
->file_names
[j
];
2602 if (FILENAME_CMP (name
, this_name
) == 0
2603 || (!is_abs
&& compare_filenames_for_search (this_name
,
2606 if (dw2_map_expand_apply (objfile
, per_cu
,
2607 name
, full_path
, real_path
,
2612 /* Before we invoke realpath, which can get expensive when many
2613 files are involved, do a quick comparison of the basenames. */
2614 if (! basenames_may_differ
2615 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2618 if (full_path
!= NULL
)
2620 const char *this_real_name
= dw2_get_real_path (objfile
,
2623 if (this_real_name
!= NULL
2624 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2626 && compare_filenames_for_search (this_real_name
,
2629 if (dw2_map_expand_apply (objfile
, per_cu
,
2630 name
, full_path
, real_path
,
2636 if (real_path
!= NULL
)
2638 const char *this_real_name
= dw2_get_real_path (objfile
,
2641 if (this_real_name
!= NULL
2642 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2644 && compare_filenames_for_search (this_real_name
,
2647 if (dw2_map_expand_apply (objfile
, per_cu
,
2648 name
, full_path
, real_path
,
2659 static struct symtab
*
2660 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2661 const char *name
, domain_enum domain
)
2663 /* We do all the work in the pre_expand_symtabs_matching hook
2668 /* A helper function that expands all symtabs that hold an object
2672 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2674 dw2_setup (objfile
);
2676 /* index_table is NULL if OBJF_READNOW. */
2677 if (dwarf2_per_objfile
->index_table
)
2681 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2684 offset_type i
, len
= MAYBE_SWAP (*vec
);
2685 for (i
= 0; i
< len
; ++i
)
2687 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2688 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2690 dw2_instantiate_symtab (per_cu
);
2697 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2698 enum block_enum block_kind
, const char *name
,
2701 dw2_do_expand_symtabs_matching (objfile
, name
);
2705 dw2_print_stats (struct objfile
*objfile
)
2709 dw2_setup (objfile
);
2711 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2712 + dwarf2_per_objfile
->n_type_units
); ++i
)
2714 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2716 if (!per_cu
->v
.quick
->symtab
)
2719 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2723 dw2_dump (struct objfile
*objfile
)
2725 /* Nothing worth printing. */
2729 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2730 struct section_offsets
*delta
)
2732 /* There's nothing to relocate here. */
2736 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2737 const char *func_name
)
2739 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2743 dw2_expand_all_symtabs (struct objfile
*objfile
)
2747 dw2_setup (objfile
);
2749 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2750 + dwarf2_per_objfile
->n_type_units
); ++i
)
2752 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2754 dw2_instantiate_symtab (per_cu
);
2759 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2760 const char *filename
)
2764 dw2_setup (objfile
);
2766 /* We don't need to consider type units here.
2767 This is only called for examining code, e.g. expand_line_sal.
2768 There can be an order of magnitude (or more) more type units
2769 than comp units, and we avoid them if we can. */
2771 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2774 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2775 struct quick_file_names
*file_data
;
2777 /* We only need to look at symtabs not already expanded. */
2778 if (per_cu
->v
.quick
->symtab
)
2781 file_data
= dw2_get_file_names (objfile
, per_cu
);
2782 if (file_data
== NULL
)
2785 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2787 const char *this_name
= file_data
->file_names
[j
];
2788 if (FILENAME_CMP (this_name
, filename
) == 0)
2790 dw2_instantiate_symtab (per_cu
);
2798 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2800 struct dwarf2_per_cu_data
*per_cu
;
2802 struct quick_file_names
*file_data
;
2804 dw2_setup (objfile
);
2806 /* index_table is NULL if OBJF_READNOW. */
2807 if (!dwarf2_per_objfile
->index_table
)
2811 ALL_OBJFILE_SYMTABS (objfile
, s
)
2814 struct blockvector
*bv
= BLOCKVECTOR (s
);
2815 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2816 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2819 return sym
->symtab
->filename
;
2824 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2828 /* Note that this just looks at the very first one named NAME -- but
2829 actually we are looking for a function. find_main_filename
2830 should be rewritten so that it doesn't require a custom hook. It
2831 could just use the ordinary symbol tables. */
2832 /* vec[0] is the length, which must always be >0. */
2833 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2835 file_data
= dw2_get_file_names (objfile
, per_cu
);
2836 if (file_data
== NULL
2837 || file_data
->num_file_names
== 0)
2840 return file_data
->file_names
[file_data
->num_file_names
- 1];
2844 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2845 struct objfile
*objfile
, int global
,
2846 int (*callback
) (struct block
*,
2847 struct symbol
*, void *),
2848 void *data
, symbol_compare_ftype
*match
,
2849 symbol_compare_ftype
*ordered_compare
)
2851 /* Currently unimplemented; used for Ada. The function can be called if the
2852 current language is Ada for a non-Ada objfile using GNU index. As Ada
2853 does not look for non-Ada symbols this function should just return. */
2857 dw2_expand_symtabs_matching
2858 (struct objfile
*objfile
,
2859 int (*file_matcher
) (const char *, void *),
2860 int (*name_matcher
) (const char *, void *),
2861 enum search_domain kind
,
2866 struct mapped_index
*index
;
2868 dw2_setup (objfile
);
2870 /* index_table is NULL if OBJF_READNOW. */
2871 if (!dwarf2_per_objfile
->index_table
)
2873 index
= dwarf2_per_objfile
->index_table
;
2875 if (file_matcher
!= NULL
)
2877 struct cleanup
*cleanup
;
2878 htab_t visited_found
, visited_not_found
;
2880 visited_found
= htab_create_alloc (10,
2881 htab_hash_pointer
, htab_eq_pointer
,
2882 NULL
, xcalloc
, xfree
);
2883 cleanup
= make_cleanup_htab_delete (visited_found
);
2884 visited_not_found
= htab_create_alloc (10,
2885 htab_hash_pointer
, htab_eq_pointer
,
2886 NULL
, xcalloc
, xfree
);
2887 make_cleanup_htab_delete (visited_not_found
);
2889 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2890 + dwarf2_per_objfile
->n_type_units
); ++i
)
2893 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2894 struct quick_file_names
*file_data
;
2897 per_cu
->v
.quick
->mark
= 0;
2899 /* We only need to look at symtabs not already expanded. */
2900 if (per_cu
->v
.quick
->symtab
)
2903 file_data
= dw2_get_file_names (objfile
, per_cu
);
2904 if (file_data
== NULL
)
2907 if (htab_find (visited_not_found
, file_data
) != NULL
)
2909 else if (htab_find (visited_found
, file_data
) != NULL
)
2911 per_cu
->v
.quick
->mark
= 1;
2915 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2917 if (file_matcher (file_data
->file_names
[j
], data
))
2919 per_cu
->v
.quick
->mark
= 1;
2924 slot
= htab_find_slot (per_cu
->v
.quick
->mark
2926 : visited_not_found
,
2931 do_cleanups (cleanup
);
2934 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2936 offset_type idx
= 2 * iter
;
2938 offset_type
*vec
, vec_len
, vec_idx
;
2940 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2943 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2945 if (! (*name_matcher
) (name
, data
))
2948 /* The name was matched, now expand corresponding CUs that were
2950 vec
= (offset_type
*) (index
->constant_pool
2951 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2952 vec_len
= MAYBE_SWAP (vec
[0]);
2953 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2955 struct dwarf2_per_cu_data
*per_cu
;
2957 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2958 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2959 dw2_instantiate_symtab (per_cu
);
2964 static struct symtab
*
2965 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2966 struct minimal_symbol
*msymbol
,
2968 struct obj_section
*section
,
2971 struct dwarf2_per_cu_data
*data
;
2973 dw2_setup (objfile
);
2975 if (!objfile
->psymtabs_addrmap
)
2978 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2982 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2983 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2984 paddress (get_objfile_arch (objfile
), pc
));
2986 return dw2_instantiate_symtab (data
);
2990 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
2991 void *data
, int need_fullname
)
2994 struct cleanup
*cleanup
;
2995 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
2996 NULL
, xcalloc
, xfree
);
2998 cleanup
= make_cleanup_htab_delete (visited
);
2999 dw2_setup (objfile
);
3001 /* We can ignore file names coming from already-expanded CUs. */
3002 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3003 + dwarf2_per_objfile
->n_type_units
); ++i
)
3005 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3007 if (per_cu
->v
.quick
->symtab
)
3009 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3012 *slot
= per_cu
->v
.quick
->file_names
;
3016 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3017 + dwarf2_per_objfile
->n_type_units
); ++i
)
3020 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3021 struct quick_file_names
*file_data
;
3024 /* We only need to look at symtabs not already expanded. */
3025 if (per_cu
->v
.quick
->symtab
)
3028 file_data
= dw2_get_file_names (objfile
, per_cu
);
3029 if (file_data
== NULL
)
3032 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3035 /* Already visited. */
3040 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3042 const char *this_real_name
;
3045 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3047 this_real_name
= NULL
;
3048 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3052 do_cleanups (cleanup
);
3056 dw2_has_symbols (struct objfile
*objfile
)
3061 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3064 dw2_find_last_source_symtab
,
3065 dw2_forget_cached_source_info
,
3066 dw2_map_symtabs_matching_filename
,
3068 dw2_pre_expand_symtabs_matching
,
3072 dw2_expand_symtabs_for_function
,
3073 dw2_expand_all_symtabs
,
3074 dw2_expand_symtabs_with_filename
,
3075 dw2_find_symbol_file
,
3076 dw2_map_matching_symbols
,
3077 dw2_expand_symtabs_matching
,
3078 dw2_find_pc_sect_symtab
,
3079 dw2_map_symbol_filenames
3082 /* Initialize for reading DWARF for this objfile. Return 0 if this
3083 file will use psymtabs, or 1 if using the GNU index. */
3086 dwarf2_initialize_objfile (struct objfile
*objfile
)
3088 /* If we're about to read full symbols, don't bother with the
3089 indices. In this case we also don't care if some other debug
3090 format is making psymtabs, because they are all about to be
3092 if ((objfile
->flags
& OBJF_READNOW
))
3096 dwarf2_per_objfile
->using_index
= 1;
3097 create_all_comp_units (objfile
);
3098 create_all_type_units (objfile
);
3099 dwarf2_per_objfile
->quick_file_names_table
=
3100 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3102 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3103 + dwarf2_per_objfile
->n_type_units
); ++i
)
3105 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3107 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3108 struct dwarf2_per_cu_quick_data
);
3111 /* Return 1 so that gdb sees the "quick" functions. However,
3112 these functions will be no-ops because we will have expanded
3117 if (dwarf2_read_index (objfile
))
3125 /* Build a partial symbol table. */
3128 dwarf2_build_psymtabs (struct objfile
*objfile
)
3130 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3132 init_psymbol_list (objfile
, 1024);
3135 dwarf2_build_psymtabs_hard (objfile
);
3138 /* Return TRUE if OFFSET is within CU_HEADER. */
3141 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3143 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3144 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3145 + cu_header
->initial_length_size
) };
3147 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3150 /* Read in the comp unit header information from the debug_info at info_ptr.
3151 NOTE: This leaves members offset, first_die_offset to be filled in
3155 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3156 gdb_byte
*info_ptr
, bfd
*abfd
)
3159 unsigned int bytes_read
;
3161 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3162 cu_header
->initial_length_size
= bytes_read
;
3163 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3164 info_ptr
+= bytes_read
;
3165 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3167 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3169 info_ptr
+= bytes_read
;
3170 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3172 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3173 if (signed_addr
< 0)
3174 internal_error (__FILE__
, __LINE__
,
3175 _("read_comp_unit_head: dwarf from non elf file"));
3176 cu_header
->signed_addr_p
= signed_addr
;
3181 /* Subroutine of read_and_check_comp_unit_head and
3182 read_and_check_type_unit_head to simplify them.
3183 Perform various error checking on the header. */
3186 error_check_comp_unit_head (struct comp_unit_head
*header
,
3187 struct dwarf2_section_info
*section
)
3189 bfd
*abfd
= section
->asection
->owner
;
3190 const char *filename
= bfd_get_filename (abfd
);
3192 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3193 error (_("Dwarf Error: wrong version in compilation unit header "
3194 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3197 if (header
->abbrev_offset
.sect_off
3198 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3199 &dwarf2_per_objfile
->abbrev
))
3200 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3201 "(offset 0x%lx + 6) [in module %s]"),
3202 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3205 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3206 avoid potential 32-bit overflow. */
3207 if (((unsigned long) header
->offset
.sect_off
3208 + header
->length
+ header
->initial_length_size
)
3210 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3211 "(offset 0x%lx + 0) [in module %s]"),
3212 (long) header
->length
, (long) header
->offset
.sect_off
,
3216 /* Read in a CU/TU header and perform some basic error checking.
3217 The contents of the header are stored in HEADER.
3218 The result is a pointer to the start of the first DIE. */
3221 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3222 struct dwarf2_section_info
*section
,
3224 int is_debug_types_section
)
3226 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3227 bfd
*abfd
= section
->asection
->owner
;
3229 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3231 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3233 /* If we're reading a type unit, skip over the signature and
3234 type_offset fields. */
3235 if (is_debug_types_section
)
3236 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3238 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3240 error_check_comp_unit_head (header
, section
);
3245 /* Read in the types comp unit header information from .debug_types entry at
3246 types_ptr. The result is a pointer to one past the end of the header. */
3249 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3250 struct dwarf2_section_info
*section
,
3252 ULONGEST
*signature
,
3253 cu_offset
*type_offset_in_tu
)
3255 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3256 bfd
*abfd
= section
->asection
->owner
;
3258 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3260 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3262 /* If we're reading a type unit, skip over the signature and
3263 type_offset fields. */
3264 if (signature
!= NULL
)
3265 *signature
= read_8_bytes (abfd
, info_ptr
);
3267 if (type_offset_in_tu
!= NULL
)
3268 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3269 header
->offset_size
);
3270 info_ptr
+= header
->offset_size
;
3272 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3274 error_check_comp_unit_head (header
, section
);
3279 /* Allocate a new partial symtab for file named NAME and mark this new
3280 partial symtab as being an include of PST. */
3283 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3284 struct objfile
*objfile
)
3286 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3288 subpst
->section_offsets
= pst
->section_offsets
;
3289 subpst
->textlow
= 0;
3290 subpst
->texthigh
= 0;
3292 subpst
->dependencies
= (struct partial_symtab
**)
3293 obstack_alloc (&objfile
->objfile_obstack
,
3294 sizeof (struct partial_symtab
*));
3295 subpst
->dependencies
[0] = pst
;
3296 subpst
->number_of_dependencies
= 1;
3298 subpst
->globals_offset
= 0;
3299 subpst
->n_global_syms
= 0;
3300 subpst
->statics_offset
= 0;
3301 subpst
->n_static_syms
= 0;
3302 subpst
->symtab
= NULL
;
3303 subpst
->read_symtab
= pst
->read_symtab
;
3306 /* No private part is necessary for include psymtabs. This property
3307 can be used to differentiate between such include psymtabs and
3308 the regular ones. */
3309 subpst
->read_symtab_private
= NULL
;
3312 /* Read the Line Number Program data and extract the list of files
3313 included by the source file represented by PST. Build an include
3314 partial symtab for each of these included files. */
3317 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3318 struct die_info
*die
,
3319 struct partial_symtab
*pst
)
3321 struct line_header
*lh
= NULL
;
3322 struct attribute
*attr
;
3324 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3326 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3328 return; /* No linetable, so no includes. */
3330 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3331 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3333 free_line_header (lh
);
3337 hash_signatured_type (const void *item
)
3339 const struct signatured_type
*sig_type
= item
;
3341 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3342 return sig_type
->signature
;
3346 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3348 const struct signatured_type
*lhs
= item_lhs
;
3349 const struct signatured_type
*rhs
= item_rhs
;
3351 return lhs
->signature
== rhs
->signature
;
3354 /* Allocate a hash table for signatured types. */
3357 allocate_signatured_type_table (struct objfile
*objfile
)
3359 return htab_create_alloc_ex (41,
3360 hash_signatured_type
,
3363 &objfile
->objfile_obstack
,
3364 hashtab_obstack_allocate
,
3365 dummy_obstack_deallocate
);
3368 /* A helper function to add a signatured type CU to a table. */
3371 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3373 struct signatured_type
*sigt
= *slot
;
3374 struct dwarf2_per_cu_data
***datap
= datum
;
3376 **datap
= &sigt
->per_cu
;
3382 /* Create the hash table of all entries in the .debug_types section.
3383 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3384 The result is a pointer to the hash table or NULL if there are
3388 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3389 VEC (dwarf2_section_info_def
) *types
)
3391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3392 htab_t types_htab
= NULL
;
3394 struct dwarf2_section_info
*section
;
3396 if (VEC_empty (dwarf2_section_info_def
, types
))
3400 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3404 gdb_byte
*info_ptr
, *end_ptr
;
3406 dwarf2_read_section (objfile
, section
);
3407 info_ptr
= section
->buffer
;
3409 if (info_ptr
== NULL
)
3412 /* We can't set abfd until now because the section may be empty or
3413 not present, in which case section->asection will be NULL. */
3414 abfd
= section
->asection
->owner
;
3416 if (types_htab
== NULL
)
3419 types_htab
= allocate_dwo_unit_table (objfile
);
3421 types_htab
= allocate_signatured_type_table (objfile
);
3424 if (dwarf2_die_debug
)
3425 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3426 bfd_get_filename (abfd
));
3428 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3429 because we don't need to read any dies: the signature is in the
3432 end_ptr
= info_ptr
+ section
->size
;
3433 while (info_ptr
< end_ptr
)
3436 cu_offset type_offset_in_tu
;
3438 struct signatured_type
*sig_type
;
3439 struct dwo_unit
*dwo_tu
;
3441 gdb_byte
*ptr
= info_ptr
;
3442 struct comp_unit_head header
;
3443 unsigned int length
;
3445 offset
.sect_off
= ptr
- section
->buffer
;
3447 /* We need to read the type's signature in order to build the hash
3448 table, but we don't need anything else just yet. */
3450 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3451 &signature
, &type_offset_in_tu
);
3453 length
= header
.initial_length_size
+ header
.length
;
3455 /* Skip dummy type units. */
3456 if (ptr
>= info_ptr
+ length
3457 || peek_abbrev_code (abfd
, ptr
) == 0)
3459 info_ptr
+= header
.initial_length_size
+ header
.length
;
3466 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3468 dwo_tu
->dwo_file
= dwo_file
;
3469 dwo_tu
->signature
= signature
;
3470 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3471 dwo_tu
->info_or_types_section
= section
;
3472 dwo_tu
->offset
= offset
;
3473 dwo_tu
->length
= length
;
3477 /* N.B.: type_offset is not usable if this type uses a DWO file.
3478 The real type_offset is in the DWO file. */
3480 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3481 struct signatured_type
);
3482 sig_type
->signature
= signature
;
3483 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3484 sig_type
->per_cu
.objfile
= objfile
;
3485 sig_type
->per_cu
.is_debug_types
= 1;
3486 sig_type
->per_cu
.info_or_types_section
= section
;
3487 sig_type
->per_cu
.offset
= offset
;
3488 sig_type
->per_cu
.length
= length
;
3491 slot
= htab_find_slot (types_htab
,
3492 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3494 gdb_assert (slot
!= NULL
);
3497 sect_offset dup_offset
;
3501 const struct dwo_unit
*dup_tu
= *slot
;
3503 dup_offset
= dup_tu
->offset
;
3507 const struct signatured_type
*dup_tu
= *slot
;
3509 dup_offset
= dup_tu
->per_cu
.offset
;
3512 complaint (&symfile_complaints
,
3513 _("debug type entry at offset 0x%x is duplicate to the "
3514 "entry at offset 0x%x, signature 0x%s"),
3515 offset
.sect_off
, dup_offset
.sect_off
,
3516 phex (signature
, sizeof (signature
)));
3518 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3520 if (dwarf2_die_debug
)
3521 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3523 phex (signature
, sizeof (signature
)));
3532 /* Create the hash table of all entries in the .debug_types section,
3533 and initialize all_type_units.
3534 The result is zero if there is an error (e.g. missing .debug_types section),
3535 otherwise non-zero. */
3538 create_all_type_units (struct objfile
*objfile
)
3541 struct dwarf2_per_cu_data
**iter
;
3543 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3544 if (types_htab
== NULL
)
3546 dwarf2_per_objfile
->signatured_types
= NULL
;
3550 dwarf2_per_objfile
->signatured_types
= types_htab
;
3552 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3553 dwarf2_per_objfile
->all_type_units
3554 = obstack_alloc (&objfile
->objfile_obstack
,
3555 dwarf2_per_objfile
->n_type_units
3556 * sizeof (struct dwarf2_per_cu_data
*));
3557 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3558 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3559 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3560 == dwarf2_per_objfile
->n_type_units
);
3565 /* Lookup a signature based type for DW_FORM_ref_sig8.
3566 Returns NULL if signature SIG is not present in the table. */
3568 static struct signatured_type
*
3569 lookup_signatured_type (ULONGEST sig
)
3571 struct signatured_type find_entry
, *entry
;
3573 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3575 complaint (&symfile_complaints
,
3576 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3580 find_entry
.signature
= sig
;
3581 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3585 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3588 init_cu_die_reader (struct die_reader_specs
*reader
,
3589 struct dwarf2_cu
*cu
,
3590 struct dwarf2_section_info
*section
,
3591 struct dwo_file
*dwo_file
)
3593 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3594 reader
->abfd
= section
->asection
->owner
;
3596 reader
->dwo_file
= dwo_file
;
3597 reader
->die_section
= section
;
3598 reader
->buffer
= section
->buffer
;
3601 /* Find the base address of the compilation unit for range lists and
3602 location lists. It will normally be specified by DW_AT_low_pc.
3603 In DWARF-3 draft 4, the base address could be overridden by
3604 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3605 compilation units with discontinuous ranges. */
3608 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3610 struct attribute
*attr
;
3613 cu
->base_address
= 0;
3615 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3618 cu
->base_address
= DW_ADDR (attr
);
3623 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3626 cu
->base_address
= DW_ADDR (attr
);
3632 /* Initialize a CU (or TU) and read its DIEs.
3633 If the CU defers to a DWO file, read the DWO file as well.
3635 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3636 Otherwise, a new CU is allocated with xmalloc.
3638 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3639 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3641 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3642 linker) then DIE_READER_FUNC will not get called. */
3645 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3646 int use_existing_cu
, int keep
,
3647 die_reader_func_ftype
*die_reader_func
,
3650 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3651 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3652 bfd
*abfd
= section
->asection
->owner
;
3653 struct dwarf2_cu
*cu
;
3654 gdb_byte
*begin_info_ptr
, *info_ptr
;
3655 struct die_reader_specs reader
;
3656 struct die_info
*comp_unit_die
;
3658 struct attribute
*attr
;
3659 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3660 struct signatured_type
*sig_type
= NULL
;
3662 if (use_existing_cu
)
3665 cleanups
= make_cleanup (null_cleanup
, NULL
);
3667 /* This is cheap if the section is already read in. */
3668 dwarf2_read_section (objfile
, section
);
3670 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3672 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3675 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3679 /* If !use_existing_cu, this_cu->cu must be NULL. */
3680 gdb_assert (this_cu
->cu
== NULL
);
3682 cu
= xmalloc (sizeof (*cu
));
3683 init_one_comp_unit (cu
, this_cu
);
3685 /* If an error occurs while loading, release our storage. */
3686 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3688 if (this_cu
->is_debug_types
)
3692 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3696 /* There's no way to get from PER_CU to its containing
3697 struct signatured_type.
3698 But we have the signature so we can use that. */
3699 sig_type
= lookup_signatured_type (signature
);
3700 /* We've already scanned all the signatured types,
3701 this must succeed. */
3702 gdb_assert (sig_type
!= NULL
);
3703 gdb_assert (&sig_type
->per_cu
== this_cu
);
3704 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3706 /* LENGTH has not been set yet for type units. */
3707 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3709 /* Establish the type offset that can be used to lookup the type. */
3710 sig_type
->type_offset_in_section
.sect_off
=
3711 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3715 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3716 section
, info_ptr
, 0);
3718 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3719 gdb_assert (this_cu
->length
3720 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3724 /* Skip dummy compilation units. */
3725 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3726 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3728 do_cleanups (cleanups
);
3732 /* Read the abbrevs for this compilation unit into a table. */
3733 if (cu
->dwarf2_abbrevs
== NULL
)
3735 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3736 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3739 /* Read the top level CU/TU die. */
3740 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3741 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3743 /* If we have a DWO stub, process it and then read in the DWO file.
3744 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3745 a DWO CU, that this test will fail. */
3746 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3749 char *dwo_name
= DW_STRING (attr
);
3750 const char *comp_dir
;
3751 struct dwo_unit
*dwo_unit
;
3752 ULONGEST signature
; /* Or dwo_id. */
3753 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3754 int i
,num_extra_attrs
;
3757 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3758 " has children (offset 0x%x) [in module %s]"),
3759 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3761 /* These attributes aren't processed until later:
3762 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3763 However, the attribute is found in the stub which we won't have later.
3764 In order to not impose this complication on the rest of the code,
3765 we read them here and copy them to the DWO CU/TU die. */
3766 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3768 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3770 if (! this_cu
->is_debug_types
)
3771 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3772 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3773 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3774 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3776 /* There should be a DW_AT_addr_base attribute here (if needed).
3777 We need the value before we can process DW_FORM_GNU_addr_index. */
3779 cu
->have_addr_base
= 0;
3780 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3783 cu
->addr_base
= DW_UNSND (attr
);
3784 cu
->have_addr_base
= 1;
3787 if (this_cu
->is_debug_types
)
3789 gdb_assert (sig_type
!= NULL
);
3790 signature
= sig_type
->signature
;
3794 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
3796 error (_("Dwarf Error: missing dwo_id [in module %s]"),
3798 signature
= DW_UNSND (attr
);
3801 /* We may need the comp_dir in order to find the DWO file. */
3803 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
3805 comp_dir
= DW_STRING (attr
);
3807 if (this_cu
->is_debug_types
)
3808 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
3810 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
3813 if (dwo_unit
== NULL
)
3815 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
3816 " with ID %s [in module %s]"),
3817 this_cu
->offset
.sect_off
,
3818 phex (signature
, sizeof (signature
)),
3822 /* Set up for reading the DWO CU/TU. */
3823 cu
->dwo_unit
= dwo_unit
;
3824 section
= dwo_unit
->info_or_types_section
;
3825 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
3826 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
3828 if (this_cu
->is_debug_types
)
3832 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3835 gdb_assert (sig_type
->signature
== signature
);
3836 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3837 gdb_assert (dwo_unit
->length
3838 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3840 /* Establish the type offset that can be used to lookup the type.
3841 For DWO files, we don't know it until now. */
3842 sig_type
->type_offset_in_section
.sect_off
=
3843 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
3847 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3848 section
, info_ptr
, 0);
3849 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3850 gdb_assert (dwo_unit
->length
3851 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3854 /* Discard the original CU's abbrev table, and read the DWO's. */
3855 dwarf2_free_abbrev_table (cu
);
3856 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
3858 /* Read in the die, but leave space to copy over the attributes
3859 from the stub. This has the benefit of simplifying the rest of
3860 the code - all the real work is done here. */
3861 num_extra_attrs
= ((stmt_list
!= NULL
)
3864 + (ranges
!= NULL
));
3865 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
3866 &has_children
, num_extra_attrs
);
3868 /* Copy over the attributes from the stub to the DWO die. */
3869 i
= comp_unit_die
->num_attrs
;
3870 if (stmt_list
!= NULL
)
3871 comp_unit_die
->attrs
[i
++] = *stmt_list
;
3873 comp_unit_die
->attrs
[i
++] = *low_pc
;
3874 if (high_pc
!= NULL
)
3875 comp_unit_die
->attrs
[i
++] = *high_pc
;
3877 comp_unit_die
->attrs
[i
++] = *ranges
;
3878 comp_unit_die
->num_attrs
+= num_extra_attrs
;
3880 /* Skip dummy compilation units. */
3881 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
3882 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3884 do_cleanups (cleanups
);
3889 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3891 if (free_cu_cleanup
!= NULL
)
3895 /* We've successfully allocated this compilation unit. Let our
3896 caller clean it up when finished with it. */
3897 discard_cleanups (free_cu_cleanup
);
3899 /* We can only discard free_cu_cleanup and all subsequent cleanups.
3900 So we have to manually free the abbrev table. */
3901 dwarf2_free_abbrev_table (cu
);
3903 /* Link this CU into read_in_chain. */
3904 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3905 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3908 do_cleanups (free_cu_cleanup
);
3911 do_cleanups (cleanups
);
3914 /* Read CU/TU THIS_CU in section SECTION,
3915 but do not follow DW_AT_GNU_dwo_name if present.
3916 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
3917 have already done the lookup to find the DWO file).
3919 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
3920 THIS_CU->is_debug_types, but nothing else.
3922 We fill in THIS_CU->length.
3924 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3925 linker) then DIE_READER_FUNC will not get called.
3927 THIS_CU->cu is always freed when done.
3928 This is done in order to not leave THIS_CU->cu in a state where we have
3929 to care whether it refers to the "main" CU or the DWO CU. */
3932 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
3933 struct dwarf2_section_info
*abbrev_section
,
3934 struct dwo_file
*dwo_file
,
3935 die_reader_func_ftype
*die_reader_func
,
3938 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3939 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3940 bfd
*abfd
= section
->asection
->owner
;
3941 struct dwarf2_cu cu
;
3942 gdb_byte
*begin_info_ptr
, *info_ptr
;
3943 struct die_reader_specs reader
;
3944 struct cleanup
*cleanups
;
3945 struct die_info
*comp_unit_die
;
3948 gdb_assert (this_cu
->cu
== NULL
);
3950 /* This is cheap if the section is already read in. */
3951 dwarf2_read_section (objfile
, section
);
3953 init_one_comp_unit (&cu
, this_cu
);
3955 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
3957 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3958 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
3959 this_cu
->is_debug_types
);
3961 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3963 /* Skip dummy compilation units. */
3964 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3965 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3967 do_cleanups (cleanups
);
3971 dwarf2_read_abbrevs (&cu
, abbrev_section
);
3972 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3974 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
3975 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3977 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
3979 do_cleanups (cleanups
);
3982 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
3983 does not lookup the specified DWO file.
3984 This cannot be used to read DWO files.
3986 THIS_CU->cu is always freed when done.
3987 This is done in order to not leave THIS_CU->cu in a state where we have
3988 to care whether it refers to the "main" CU or the DWO CU.
3989 We can revisit this if the data shows there's a performance issue. */
3992 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
3993 die_reader_func_ftype
*die_reader_func
,
3996 init_cutu_and_read_dies_no_follow (this_cu
,
3997 &dwarf2_per_objfile
->abbrev
,
3999 die_reader_func
, data
);
4002 /* die_reader_func for process_psymtab_comp_unit. */
4005 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4007 struct die_info
*comp_unit_die
,
4011 struct dwarf2_cu
*cu
= reader
->cu
;
4012 struct objfile
*objfile
= cu
->objfile
;
4013 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4014 bfd
*abfd
= objfile
->obfd
;
4015 struct attribute
*attr
;
4017 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4018 struct partial_symtab
*pst
;
4020 const char *filename
;
4022 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4025 prepare_one_comp_unit (cu
, comp_unit_die
);
4027 cu
->list_in_scope
= &file_symbols
;
4029 /* Allocate a new partial symbol table structure. */
4030 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4031 if (attr
== NULL
|| !DW_STRING (attr
))
4034 filename
= DW_STRING (attr
);
4035 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4037 /* TEXTLOW and TEXTHIGH are set below. */
4039 objfile
->global_psymbols
.next
,
4040 objfile
->static_psymbols
.next
);
4041 pst
->psymtabs_addrmap_supported
= 1;
4043 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4045 pst
->dirname
= DW_STRING (attr
);
4047 pst
->read_symtab_private
= per_cu
;
4049 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4051 /* Store the function that reads in the rest of the symbol table. */
4052 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4054 per_cu
->v
.psymtab
= pst
;
4056 dwarf2_find_base_address (comp_unit_die
, cu
);
4058 /* Possibly set the default values of LOWPC and HIGHPC from
4060 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4061 &best_highpc
, cu
, pst
);
4062 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4063 /* Store the contiguous range if it is not empty; it can be empty for
4064 CUs with no code. */
4065 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4066 best_lowpc
+ baseaddr
,
4067 best_highpc
+ baseaddr
- 1, pst
);
4069 /* Check if comp unit has_children.
4070 If so, read the rest of the partial symbols from this comp unit.
4071 If not, there's no more debug_info for this comp unit. */
4074 struct partial_die_info
*first_die
;
4075 CORE_ADDR lowpc
, highpc
;
4077 lowpc
= ((CORE_ADDR
) -1);
4078 highpc
= ((CORE_ADDR
) 0);
4080 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4082 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4085 /* If we didn't find a lowpc, set it to highpc to avoid
4086 complaints from `maint check'. */
4087 if (lowpc
== ((CORE_ADDR
) -1))
4090 /* If the compilation unit didn't have an explicit address range,
4091 then use the information extracted from its child dies. */
4095 best_highpc
= highpc
;
4098 pst
->textlow
= best_lowpc
+ baseaddr
;
4099 pst
->texthigh
= best_highpc
+ baseaddr
;
4101 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4102 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4103 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4104 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4105 sort_pst_symbols (pst
);
4107 if (per_cu
->is_debug_types
)
4109 /* It's not clear we want to do anything with stmt lists here.
4110 Waiting to see what gcc ultimately does. */
4114 /* Get the list of files included in the current compilation unit,
4115 and build a psymtab for each of them. */
4116 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4120 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4121 Process compilation unit THIS_CU for a psymtab. */
4124 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4126 /* If this compilation unit was already read in, free the
4127 cached copy in order to read it in again. This is
4128 necessary because we skipped some symbols when we first
4129 read in the compilation unit (see load_partial_dies).
4130 This problem could be avoided, but the benefit is unclear. */
4131 if (this_cu
->cu
!= NULL
)
4132 free_one_cached_comp_unit (this_cu
);
4134 gdb_assert (! this_cu
->is_debug_types
);
4135 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4138 /* Age out any secondary CUs. */
4139 age_cached_comp_units ();
4142 /* Traversal function for htab_traverse_noresize.
4143 Process one .debug_types comp-unit. */
4146 process_psymtab_type_unit (void **slot
, void *info
)
4148 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4149 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4151 gdb_assert (per_cu
->is_debug_types
);
4152 gdb_assert (info
== NULL
);
4154 /* If this compilation unit was already read in, free the
4155 cached copy in order to read it in again. This is
4156 necessary because we skipped some symbols when we first
4157 read in the compilation unit (see load_partial_dies).
4158 This problem could be avoided, but the benefit is unclear. */
4159 if (per_cu
->cu
!= NULL
)
4160 free_one_cached_comp_unit (per_cu
);
4162 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4165 /* Age out any secondary CUs. */
4166 age_cached_comp_units ();
4171 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4172 Build partial symbol tables for the .debug_types comp-units. */
4175 build_type_psymtabs (struct objfile
*objfile
)
4177 if (! create_all_type_units (objfile
))
4180 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4181 process_psymtab_type_unit
, NULL
);
4184 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4187 psymtabs_addrmap_cleanup (void *o
)
4189 struct objfile
*objfile
= o
;
4191 objfile
->psymtabs_addrmap
= NULL
;
4194 /* Build the partial symbol table by doing a quick pass through the
4195 .debug_info and .debug_abbrev sections. */
4198 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4200 struct cleanup
*back_to
, *addrmap_cleanup
;
4201 struct obstack temp_obstack
;
4204 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4206 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4208 /* Any cached compilation units will be linked by the per-objfile
4209 read_in_chain. Make sure to free them when we're done. */
4210 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4212 build_type_psymtabs (objfile
);
4214 create_all_comp_units (objfile
);
4216 /* Create a temporary address map on a temporary obstack. We later
4217 copy this to the final obstack. */
4218 obstack_init (&temp_obstack
);
4219 make_cleanup_obstack_free (&temp_obstack
);
4220 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4221 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4223 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4225 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4227 process_psymtab_comp_unit (per_cu
);
4230 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4231 &objfile
->objfile_obstack
);
4232 discard_cleanups (addrmap_cleanup
);
4234 do_cleanups (back_to
);
4237 /* die_reader_func for load_partial_comp_unit. */
4240 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4242 struct die_info
*comp_unit_die
,
4246 struct dwarf2_cu
*cu
= reader
->cu
;
4248 prepare_one_comp_unit (cu
, comp_unit_die
);
4250 /* Check if comp unit has_children.
4251 If so, read the rest of the partial symbols from this comp unit.
4252 If not, there's no more debug_info for this comp unit. */
4254 load_partial_dies (reader
, info_ptr
, 0);
4257 /* Load the partial DIEs for a secondary CU into memory.
4258 This is also used when rereading a primary CU with load_all_dies. */
4261 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4263 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4266 /* Create a list of all compilation units in OBJFILE.
4267 This is only done for -readnow and building partial symtabs. */
4270 create_all_comp_units (struct objfile
*objfile
)
4274 struct dwarf2_per_cu_data
**all_comp_units
;
4277 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4278 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4282 all_comp_units
= xmalloc (n_allocated
4283 * sizeof (struct dwarf2_per_cu_data
*));
4285 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4286 + dwarf2_per_objfile
->info
.size
)
4288 unsigned int length
, initial_length_size
;
4289 struct dwarf2_per_cu_data
*this_cu
;
4292 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4294 /* Read just enough information to find out where the next
4295 compilation unit is. */
4296 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4297 &initial_length_size
);
4299 /* Save the compilation unit for later lookup. */
4300 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4301 sizeof (struct dwarf2_per_cu_data
));
4302 memset (this_cu
, 0, sizeof (*this_cu
));
4303 this_cu
->offset
= offset
;
4304 this_cu
->length
= length
+ initial_length_size
;
4305 this_cu
->objfile
= objfile
;
4306 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4308 if (n_comp_units
== n_allocated
)
4311 all_comp_units
= xrealloc (all_comp_units
,
4313 * sizeof (struct dwarf2_per_cu_data
*));
4315 all_comp_units
[n_comp_units
++] = this_cu
;
4317 info_ptr
= info_ptr
+ this_cu
->length
;
4320 dwarf2_per_objfile
->all_comp_units
4321 = obstack_alloc (&objfile
->objfile_obstack
,
4322 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4323 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4324 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4325 xfree (all_comp_units
);
4326 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4329 /* Process all loaded DIEs for compilation unit CU, starting at
4330 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4331 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4332 DW_AT_ranges). If NEED_PC is set, then this function will set
4333 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4334 and record the covered ranges in the addrmap. */
4337 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4338 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4340 struct partial_die_info
*pdi
;
4342 /* Now, march along the PDI's, descending into ones which have
4343 interesting children but skipping the children of the other ones,
4344 until we reach the end of the compilation unit. */
4350 fixup_partial_die (pdi
, cu
);
4352 /* Anonymous namespaces or modules have no name but have interesting
4353 children, so we need to look at them. Ditto for anonymous
4356 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4357 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
4361 case DW_TAG_subprogram
:
4362 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4364 case DW_TAG_constant
:
4365 case DW_TAG_variable
:
4366 case DW_TAG_typedef
:
4367 case DW_TAG_union_type
:
4368 if (!pdi
->is_declaration
)
4370 add_partial_symbol (pdi
, cu
);
4373 case DW_TAG_class_type
:
4374 case DW_TAG_interface_type
:
4375 case DW_TAG_structure_type
:
4376 if (!pdi
->is_declaration
)
4378 add_partial_symbol (pdi
, cu
);
4381 case DW_TAG_enumeration_type
:
4382 if (!pdi
->is_declaration
)
4383 add_partial_enumeration (pdi
, cu
);
4385 case DW_TAG_base_type
:
4386 case DW_TAG_subrange_type
:
4387 /* File scope base type definitions are added to the partial
4389 add_partial_symbol (pdi
, cu
);
4391 case DW_TAG_namespace
:
4392 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4395 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4402 /* If the die has a sibling, skip to the sibling. */
4404 pdi
= pdi
->die_sibling
;
4408 /* Functions used to compute the fully scoped name of a partial DIE.
4410 Normally, this is simple. For C++, the parent DIE's fully scoped
4411 name is concatenated with "::" and the partial DIE's name. For
4412 Java, the same thing occurs except that "." is used instead of "::".
4413 Enumerators are an exception; they use the scope of their parent
4414 enumeration type, i.e. the name of the enumeration type is not
4415 prepended to the enumerator.
4417 There are two complexities. One is DW_AT_specification; in this
4418 case "parent" means the parent of the target of the specification,
4419 instead of the direct parent of the DIE. The other is compilers
4420 which do not emit DW_TAG_namespace; in this case we try to guess
4421 the fully qualified name of structure types from their members'
4422 linkage names. This must be done using the DIE's children rather
4423 than the children of any DW_AT_specification target. We only need
4424 to do this for structures at the top level, i.e. if the target of
4425 any DW_AT_specification (if any; otherwise the DIE itself) does not
4428 /* Compute the scope prefix associated with PDI's parent, in
4429 compilation unit CU. The result will be allocated on CU's
4430 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4431 field. NULL is returned if no prefix is necessary. */
4433 partial_die_parent_scope (struct partial_die_info
*pdi
,
4434 struct dwarf2_cu
*cu
)
4436 char *grandparent_scope
;
4437 struct partial_die_info
*parent
, *real_pdi
;
4439 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4440 then this means the parent of the specification DIE. */
4443 while (real_pdi
->has_specification
)
4444 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4446 parent
= real_pdi
->die_parent
;
4450 if (parent
->scope_set
)
4451 return parent
->scope
;
4453 fixup_partial_die (parent
, cu
);
4455 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4457 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4458 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4459 Work around this problem here. */
4460 if (cu
->language
== language_cplus
4461 && parent
->tag
== DW_TAG_namespace
4462 && strcmp (parent
->name
, "::") == 0
4463 && grandparent_scope
== NULL
)
4465 parent
->scope
= NULL
;
4466 parent
->scope_set
= 1;
4470 if (pdi
->tag
== DW_TAG_enumerator
)
4471 /* Enumerators should not get the name of the enumeration as a prefix. */
4472 parent
->scope
= grandparent_scope
;
4473 else if (parent
->tag
== DW_TAG_namespace
4474 || parent
->tag
== DW_TAG_module
4475 || parent
->tag
== DW_TAG_structure_type
4476 || parent
->tag
== DW_TAG_class_type
4477 || parent
->tag
== DW_TAG_interface_type
4478 || parent
->tag
== DW_TAG_union_type
4479 || parent
->tag
== DW_TAG_enumeration_type
)
4481 if (grandparent_scope
== NULL
)
4482 parent
->scope
= parent
->name
;
4484 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4486 parent
->name
, 0, cu
);
4490 /* FIXME drow/2004-04-01: What should we be doing with
4491 function-local names? For partial symbols, we should probably be
4493 complaint (&symfile_complaints
,
4494 _("unhandled containing DIE tag %d for DIE at %d"),
4495 parent
->tag
, pdi
->offset
.sect_off
);
4496 parent
->scope
= grandparent_scope
;
4499 parent
->scope_set
= 1;
4500 return parent
->scope
;
4503 /* Return the fully scoped name associated with PDI, from compilation unit
4504 CU. The result will be allocated with malloc. */
4507 partial_die_full_name (struct partial_die_info
*pdi
,
4508 struct dwarf2_cu
*cu
)
4512 /* If this is a template instantiation, we can not work out the
4513 template arguments from partial DIEs. So, unfortunately, we have
4514 to go through the full DIEs. At least any work we do building
4515 types here will be reused if full symbols are loaded later. */
4516 if (pdi
->has_template_arguments
)
4518 fixup_partial_die (pdi
, cu
);
4520 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4522 struct die_info
*die
;
4523 struct attribute attr
;
4524 struct dwarf2_cu
*ref_cu
= cu
;
4526 /* DW_FORM_ref_addr is using section offset. */
4528 attr
.form
= DW_FORM_ref_addr
;
4529 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4530 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4532 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4536 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4537 if (parent_scope
== NULL
)
4540 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4544 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4546 struct objfile
*objfile
= cu
->objfile
;
4548 char *actual_name
= NULL
;
4550 int built_actual_name
= 0;
4552 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4554 actual_name
= partial_die_full_name (pdi
, cu
);
4556 built_actual_name
= 1;
4558 if (actual_name
== NULL
)
4559 actual_name
= pdi
->name
;
4563 case DW_TAG_subprogram
:
4564 if (pdi
->is_external
|| cu
->language
== language_ada
)
4566 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4567 of the global scope. But in Ada, we want to be able to access
4568 nested procedures globally. So all Ada subprograms are stored
4569 in the global scope. */
4570 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4571 mst_text, objfile); */
4572 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4574 VAR_DOMAIN
, LOC_BLOCK
,
4575 &objfile
->global_psymbols
,
4576 0, pdi
->lowpc
+ baseaddr
,
4577 cu
->language
, objfile
);
4581 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4582 mst_file_text, objfile); */
4583 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4585 VAR_DOMAIN
, LOC_BLOCK
,
4586 &objfile
->static_psymbols
,
4587 0, pdi
->lowpc
+ baseaddr
,
4588 cu
->language
, objfile
);
4591 case DW_TAG_constant
:
4593 struct psymbol_allocation_list
*list
;
4595 if (pdi
->is_external
)
4596 list
= &objfile
->global_psymbols
;
4598 list
= &objfile
->static_psymbols
;
4599 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4600 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4601 list
, 0, 0, cu
->language
, objfile
);
4604 case DW_TAG_variable
:
4606 addr
= decode_locdesc (pdi
->locdesc
, cu
);
4610 && !dwarf2_per_objfile
->has_section_at_zero
)
4612 /* A global or static variable may also have been stripped
4613 out by the linker if unused, in which case its address
4614 will be nullified; do not add such variables into partial
4615 symbol table then. */
4617 else if (pdi
->is_external
)
4620 Don't enter into the minimal symbol tables as there is
4621 a minimal symbol table entry from the ELF symbols already.
4622 Enter into partial symbol table if it has a location
4623 descriptor or a type.
4624 If the location descriptor is missing, new_symbol will create
4625 a LOC_UNRESOLVED symbol, the address of the variable will then
4626 be determined from the minimal symbol table whenever the variable
4628 The address for the partial symbol table entry is not
4629 used by GDB, but it comes in handy for debugging partial symbol
4632 if (pdi
->locdesc
|| pdi
->has_type
)
4633 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4635 VAR_DOMAIN
, LOC_STATIC
,
4636 &objfile
->global_psymbols
,
4638 cu
->language
, objfile
);
4642 /* Static Variable. Skip symbols without location descriptors. */
4643 if (pdi
->locdesc
== NULL
)
4645 if (built_actual_name
)
4646 xfree (actual_name
);
4649 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4650 mst_file_data, objfile); */
4651 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4653 VAR_DOMAIN
, LOC_STATIC
,
4654 &objfile
->static_psymbols
,
4656 cu
->language
, objfile
);
4659 case DW_TAG_typedef
:
4660 case DW_TAG_base_type
:
4661 case DW_TAG_subrange_type
:
4662 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4664 VAR_DOMAIN
, LOC_TYPEDEF
,
4665 &objfile
->static_psymbols
,
4666 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4668 case DW_TAG_namespace
:
4669 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4671 VAR_DOMAIN
, LOC_TYPEDEF
,
4672 &objfile
->global_psymbols
,
4673 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4675 case DW_TAG_class_type
:
4676 case DW_TAG_interface_type
:
4677 case DW_TAG_structure_type
:
4678 case DW_TAG_union_type
:
4679 case DW_TAG_enumeration_type
:
4680 /* Skip external references. The DWARF standard says in the section
4681 about "Structure, Union, and Class Type Entries": "An incomplete
4682 structure, union or class type is represented by a structure,
4683 union or class entry that does not have a byte size attribute
4684 and that has a DW_AT_declaration attribute." */
4685 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4687 if (built_actual_name
)
4688 xfree (actual_name
);
4692 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4693 static vs. global. */
4694 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4696 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4697 (cu
->language
== language_cplus
4698 || cu
->language
== language_java
)
4699 ? &objfile
->global_psymbols
4700 : &objfile
->static_psymbols
,
4701 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4704 case DW_TAG_enumerator
:
4705 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4707 VAR_DOMAIN
, LOC_CONST
,
4708 (cu
->language
== language_cplus
4709 || cu
->language
== language_java
)
4710 ? &objfile
->global_psymbols
4711 : &objfile
->static_psymbols
,
4712 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4718 if (built_actual_name
)
4719 xfree (actual_name
);
4722 /* Read a partial die corresponding to a namespace; also, add a symbol
4723 corresponding to that namespace to the symbol table. NAMESPACE is
4724 the name of the enclosing namespace. */
4727 add_partial_namespace (struct partial_die_info
*pdi
,
4728 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4729 int need_pc
, struct dwarf2_cu
*cu
)
4731 /* Add a symbol for the namespace. */
4733 add_partial_symbol (pdi
, cu
);
4735 /* Now scan partial symbols in that namespace. */
4737 if (pdi
->has_children
)
4738 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4741 /* Read a partial die corresponding to a Fortran module. */
4744 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4745 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4747 /* Now scan partial symbols in that module. */
4749 if (pdi
->has_children
)
4750 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4753 /* Read a partial die corresponding to a subprogram and create a partial
4754 symbol for that subprogram. When the CU language allows it, this
4755 routine also defines a partial symbol for each nested subprogram
4756 that this subprogram contains.
4758 DIE my also be a lexical block, in which case we simply search
4759 recursively for suprograms defined inside that lexical block.
4760 Again, this is only performed when the CU language allows this
4761 type of definitions. */
4764 add_partial_subprogram (struct partial_die_info
*pdi
,
4765 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4766 int need_pc
, struct dwarf2_cu
*cu
)
4768 if (pdi
->tag
== DW_TAG_subprogram
)
4770 if (pdi
->has_pc_info
)
4772 if (pdi
->lowpc
< *lowpc
)
4773 *lowpc
= pdi
->lowpc
;
4774 if (pdi
->highpc
> *highpc
)
4775 *highpc
= pdi
->highpc
;
4779 struct objfile
*objfile
= cu
->objfile
;
4781 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4782 SECT_OFF_TEXT (objfile
));
4783 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4784 pdi
->lowpc
+ baseaddr
,
4785 pdi
->highpc
- 1 + baseaddr
,
4786 cu
->per_cu
->v
.psymtab
);
4790 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
4792 if (!pdi
->is_declaration
)
4793 /* Ignore subprogram DIEs that do not have a name, they are
4794 illegal. Do not emit a complaint at this point, we will
4795 do so when we convert this psymtab into a symtab. */
4797 add_partial_symbol (pdi
, cu
);
4801 if (! pdi
->has_children
)
4804 if (cu
->language
== language_ada
)
4806 pdi
= pdi
->die_child
;
4809 fixup_partial_die (pdi
, cu
);
4810 if (pdi
->tag
== DW_TAG_subprogram
4811 || pdi
->tag
== DW_TAG_lexical_block
)
4812 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4813 pdi
= pdi
->die_sibling
;
4818 /* Read a partial die corresponding to an enumeration type. */
4821 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4822 struct dwarf2_cu
*cu
)
4824 struct partial_die_info
*pdi
;
4826 if (enum_pdi
->name
!= NULL
)
4827 add_partial_symbol (enum_pdi
, cu
);
4829 pdi
= enum_pdi
->die_child
;
4832 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4833 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4835 add_partial_symbol (pdi
, cu
);
4836 pdi
= pdi
->die_sibling
;
4840 /* Return the initial uleb128 in the die at INFO_PTR. */
4843 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
4845 unsigned int bytes_read
;
4847 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4850 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4851 Return the corresponding abbrev, or NULL if the number is zero (indicating
4852 an empty DIE). In either case *BYTES_READ will be set to the length of
4853 the initial number. */
4855 static struct abbrev_info
*
4856 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4857 struct dwarf2_cu
*cu
)
4859 bfd
*abfd
= cu
->objfile
->obfd
;
4860 unsigned int abbrev_number
;
4861 struct abbrev_info
*abbrev
;
4863 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4865 if (abbrev_number
== 0)
4868 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4871 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4872 abbrev_number
, bfd_get_filename (abfd
));
4878 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4879 Returns a pointer to the end of a series of DIEs, terminated by an empty
4880 DIE. Any children of the skipped DIEs will also be skipped. */
4883 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
4885 struct dwarf2_cu
*cu
= reader
->cu
;
4886 struct abbrev_info
*abbrev
;
4887 unsigned int bytes_read
;
4891 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4893 return info_ptr
+ bytes_read
;
4895 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
4899 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4900 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4901 abbrev corresponding to that skipped uleb128 should be passed in
4902 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4906 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
4907 struct abbrev_info
*abbrev
)
4909 unsigned int bytes_read
;
4910 struct attribute attr
;
4911 bfd
*abfd
= reader
->abfd
;
4912 struct dwarf2_cu
*cu
= reader
->cu
;
4913 gdb_byte
*buffer
= reader
->buffer
;
4914 unsigned int form
, i
;
4916 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4918 /* The only abbrev we care about is DW_AT_sibling. */
4919 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4921 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
4922 if (attr
.form
== DW_FORM_ref_addr
)
4923 complaint (&symfile_complaints
,
4924 _("ignoring absolute DW_AT_sibling"));
4926 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
4929 /* If it isn't DW_AT_sibling, skip this attribute. */
4930 form
= abbrev
->attrs
[i
].form
;
4934 case DW_FORM_ref_addr
:
4935 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4936 and later it is offset sized. */
4937 if (cu
->header
.version
== 2)
4938 info_ptr
+= cu
->header
.addr_size
;
4940 info_ptr
+= cu
->header
.offset_size
;
4943 info_ptr
+= cu
->header
.addr_size
;
4950 case DW_FORM_flag_present
:
4962 case DW_FORM_ref_sig8
:
4965 case DW_FORM_string
:
4966 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4967 info_ptr
+= bytes_read
;
4969 case DW_FORM_sec_offset
:
4971 info_ptr
+= cu
->header
.offset_size
;
4973 case DW_FORM_exprloc
:
4975 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4976 info_ptr
+= bytes_read
;
4978 case DW_FORM_block1
:
4979 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4981 case DW_FORM_block2
:
4982 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4984 case DW_FORM_block4
:
4985 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4989 case DW_FORM_ref_udata
:
4990 case DW_FORM_GNU_addr_index
:
4991 case DW_FORM_GNU_str_index
:
4992 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4994 case DW_FORM_indirect
:
4995 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4996 info_ptr
+= bytes_read
;
4997 /* We need to continue parsing from here, so just go back to
4999 goto skip_attribute
;
5002 error (_("Dwarf Error: Cannot handle %s "
5003 "in DWARF reader [in module %s]"),
5004 dwarf_form_name (form
),
5005 bfd_get_filename (abfd
));
5009 if (abbrev
->has_children
)
5010 return skip_children (reader
, info_ptr
);
5015 /* Locate ORIG_PDI's sibling.
5016 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5019 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5020 struct partial_die_info
*orig_pdi
,
5023 /* Do we know the sibling already? */
5025 if (orig_pdi
->sibling
)
5026 return orig_pdi
->sibling
;
5028 /* Are there any children to deal with? */
5030 if (!orig_pdi
->has_children
)
5033 /* Skip the children the long way. */
5035 return skip_children (reader
, info_ptr
);
5038 /* Expand this partial symbol table into a full symbol table. */
5041 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5047 warning (_("bug: psymtab for %s is already read in."),
5054 printf_filtered (_("Reading in symbols for %s..."),
5056 gdb_flush (gdb_stdout
);
5059 /* Restore our global data. */
5060 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5061 dwarf2_objfile_data_key
);
5063 /* If this psymtab is constructed from a debug-only objfile, the
5064 has_section_at_zero flag will not necessarily be correct. We
5065 can get the correct value for this flag by looking at the data
5066 associated with the (presumably stripped) associated objfile. */
5067 if (pst
->objfile
->separate_debug_objfile_backlink
)
5069 struct dwarf2_per_objfile
*dpo_backlink
5070 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5071 dwarf2_objfile_data_key
);
5073 dwarf2_per_objfile
->has_section_at_zero
5074 = dpo_backlink
->has_section_at_zero
;
5077 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5079 psymtab_to_symtab_1 (pst
);
5081 /* Finish up the debug error message. */
5083 printf_filtered (_("done.\n"));
5088 /* Reading in full CUs. */
5090 /* Add PER_CU to the queue. */
5093 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5095 struct dwarf2_queue_item
*item
;
5098 item
= xmalloc (sizeof (*item
));
5099 item
->per_cu
= per_cu
;
5102 if (dwarf2_queue
== NULL
)
5103 dwarf2_queue
= item
;
5105 dwarf2_queue_tail
->next
= item
;
5107 dwarf2_queue_tail
= item
;
5110 /* Process the queue. */
5113 process_queue (void)
5115 struct dwarf2_queue_item
*item
, *next_item
;
5117 /* The queue starts out with one item, but following a DIE reference
5118 may load a new CU, adding it to the end of the queue. */
5119 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5121 if (dwarf2_per_objfile
->using_index
5122 ? !item
->per_cu
->v
.quick
->symtab
5123 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5124 process_full_comp_unit (item
->per_cu
);
5126 item
->per_cu
->queued
= 0;
5127 next_item
= item
->next
;
5131 dwarf2_queue_tail
= NULL
;
5134 /* Free all allocated queue entries. This function only releases anything if
5135 an error was thrown; if the queue was processed then it would have been
5136 freed as we went along. */
5139 dwarf2_release_queue (void *dummy
)
5141 struct dwarf2_queue_item
*item
, *last
;
5143 item
= dwarf2_queue
;
5146 /* Anything still marked queued is likely to be in an
5147 inconsistent state, so discard it. */
5148 if (item
->per_cu
->queued
)
5150 if (item
->per_cu
->cu
!= NULL
)
5151 free_one_cached_comp_unit (item
->per_cu
);
5152 item
->per_cu
->queued
= 0;
5160 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5163 /* Read in full symbols for PST, and anything it depends on. */
5166 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5168 struct dwarf2_per_cu_data
*per_cu
;
5169 struct cleanup
*back_to
;
5172 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5173 if (!pst
->dependencies
[i
]->readin
)
5175 /* Inform about additional files that need to be read in. */
5178 /* FIXME: i18n: Need to make this a single string. */
5179 fputs_filtered (" ", gdb_stdout
);
5181 fputs_filtered ("and ", gdb_stdout
);
5183 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5184 wrap_here (""); /* Flush output. */
5185 gdb_flush (gdb_stdout
);
5187 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5190 per_cu
= pst
->read_symtab_private
;
5194 /* It's an include file, no symbols to read for it.
5195 Everything is in the parent symtab. */
5200 dw2_do_instantiate_symtab (per_cu
);
5203 /* Trivial hash function for die_info: the hash value of a DIE
5204 is its offset in .debug_info for this objfile. */
5207 die_hash (const void *item
)
5209 const struct die_info
*die
= item
;
5211 return die
->offset
.sect_off
;
5214 /* Trivial comparison function for die_info structures: two DIEs
5215 are equal if they have the same offset. */
5218 die_eq (const void *item_lhs
, const void *item_rhs
)
5220 const struct die_info
*die_lhs
= item_lhs
;
5221 const struct die_info
*die_rhs
= item_rhs
;
5223 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5226 /* die_reader_func for load_full_comp_unit.
5227 This is identical to read_signatured_type_reader,
5228 but is kept separate for now. */
5231 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5233 struct die_info
*comp_unit_die
,
5237 struct dwarf2_cu
*cu
= reader
->cu
;
5238 struct attribute
*attr
;
5240 gdb_assert (cu
->die_hash
== NULL
);
5242 htab_create_alloc_ex (cu
->header
.length
/ 12,
5246 &cu
->comp_unit_obstack
,
5247 hashtab_obstack_allocate
,
5248 dummy_obstack_deallocate
);
5251 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5252 &info_ptr
, comp_unit_die
);
5253 cu
->dies
= comp_unit_die
;
5254 /* comp_unit_die is not stored in die_hash, no need. */
5256 /* We try not to read any attributes in this function, because not
5257 all CUs needed for references have been loaded yet, and symbol
5258 table processing isn't initialized. But we have to set the CU language,
5259 or we won't be able to build types correctly.
5260 Similarly, if we do not read the producer, we can not apply
5261 producer-specific interpretation. */
5262 prepare_one_comp_unit (cu
, cu
->dies
);
5265 /* Load the DIEs associated with PER_CU into memory. */
5268 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5270 gdb_assert (! this_cu
->is_debug_types
);
5272 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
, NULL
);
5275 /* Add a DIE to the delayed physname list. */
5278 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5279 const char *name
, struct die_info
*die
,
5280 struct dwarf2_cu
*cu
)
5282 struct delayed_method_info mi
;
5284 mi
.fnfield_index
= fnfield_index
;
5288 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5291 /* A cleanup for freeing the delayed method list. */
5294 free_delayed_list (void *ptr
)
5296 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5297 if (cu
->method_list
!= NULL
)
5299 VEC_free (delayed_method_info
, cu
->method_list
);
5300 cu
->method_list
= NULL
;
5304 /* Compute the physnames of any methods on the CU's method list.
5306 The computation of method physnames is delayed in order to avoid the
5307 (bad) condition that one of the method's formal parameters is of an as yet
5311 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5314 struct delayed_method_info
*mi
;
5315 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5317 const char *physname
;
5318 struct fn_fieldlist
*fn_flp
5319 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5320 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5321 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5325 /* Go objects should be embedded in a DW_TAG_module DIE,
5326 and it's not clear if/how imported objects will appear.
5327 To keep Go support simple until that's worked out,
5328 go back through what we've read and create something usable.
5329 We could do this while processing each DIE, and feels kinda cleaner,
5330 but that way is more invasive.
5331 This is to, for example, allow the user to type "p var" or "b main"
5332 without having to specify the package name, and allow lookups
5333 of module.object to work in contexts that use the expression
5337 fixup_go_packaging (struct dwarf2_cu
*cu
)
5339 char *package_name
= NULL
;
5340 struct pending
*list
;
5343 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5345 for (i
= 0; i
< list
->nsyms
; ++i
)
5347 struct symbol
*sym
= list
->symbol
[i
];
5349 if (SYMBOL_LANGUAGE (sym
) == language_go
5350 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5352 char *this_package_name
= go_symbol_package_name (sym
);
5354 if (this_package_name
== NULL
)
5356 if (package_name
== NULL
)
5357 package_name
= this_package_name
;
5360 if (strcmp (package_name
, this_package_name
) != 0)
5361 complaint (&symfile_complaints
,
5362 _("Symtab %s has objects from two different Go packages: %s and %s"),
5363 (sym
->symtab
&& sym
->symtab
->filename
5364 ? sym
->symtab
->filename
5365 : cu
->objfile
->name
),
5366 this_package_name
, package_name
);
5367 xfree (this_package_name
);
5373 if (package_name
!= NULL
)
5375 struct objfile
*objfile
= cu
->objfile
;
5376 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5377 package_name
, objfile
);
5380 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5382 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5383 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5384 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5385 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5386 e.g., "main" finds the "main" module and not C's main(). */
5387 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5388 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5389 SYMBOL_TYPE (sym
) = type
;
5391 add_symbol_to_list (sym
, &global_symbols
);
5393 xfree (package_name
);
5397 /* Generate full symbol information for PER_CU, whose DIEs have
5398 already been loaded into memory. */
5401 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
5403 struct dwarf2_cu
*cu
= per_cu
->cu
;
5404 struct objfile
*objfile
= per_cu
->objfile
;
5405 CORE_ADDR lowpc
, highpc
;
5406 struct symtab
*symtab
;
5407 struct cleanup
*back_to
, *delayed_list_cleanup
;
5410 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5413 back_to
= make_cleanup (really_free_pendings
, NULL
);
5414 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5416 cu
->list_in_scope
= &file_symbols
;
5418 /* Do line number decoding in read_file_scope () */
5419 process_die (cu
->dies
, cu
);
5421 /* For now fudge the Go package. */
5422 if (cu
->language
== language_go
)
5423 fixup_go_packaging (cu
);
5425 /* Now that we have processed all the DIEs in the CU, all the types
5426 should be complete, and it should now be safe to compute all of the
5428 compute_delayed_physnames (cu
);
5429 do_cleanups (delayed_list_cleanup
);
5431 /* Some compilers don't define a DW_AT_high_pc attribute for the
5432 compilation unit. If the DW_AT_high_pc is missing, synthesize
5433 it, by scanning the DIE's below the compilation unit. */
5434 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5436 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5440 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5442 /* Set symtab language to language from DW_AT_language. If the
5443 compilation is from a C file generated by language preprocessors, do
5444 not set the language if it was already deduced by start_subfile. */
5445 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5446 symtab
->language
= cu
->language
;
5448 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5449 produce DW_AT_location with location lists but it can be possibly
5450 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5451 there were bugs in prologue debug info, fixed later in GCC-4.5
5452 by "unwind info for epilogues" patch (which is not directly related).
5454 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5455 needed, it would be wrong due to missing DW_AT_producer there.
5457 Still one can confuse GDB by using non-standard GCC compilation
5458 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5460 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5461 symtab
->locations_valid
= 1;
5463 if (gcc_4_minor
>= 5)
5464 symtab
->epilogue_unwind_valid
= 1;
5466 symtab
->call_site_htab
= cu
->call_site_htab
;
5469 if (dwarf2_per_objfile
->using_index
)
5470 per_cu
->v
.quick
->symtab
= symtab
;
5473 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5474 pst
->symtab
= symtab
;
5478 do_cleanups (back_to
);
5481 /* Process a die and its children. */
5484 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5488 case DW_TAG_padding
:
5490 case DW_TAG_compile_unit
:
5491 read_file_scope (die
, cu
);
5493 case DW_TAG_type_unit
:
5494 read_type_unit_scope (die
, cu
);
5496 case DW_TAG_subprogram
:
5497 case DW_TAG_inlined_subroutine
:
5498 read_func_scope (die
, cu
);
5500 case DW_TAG_lexical_block
:
5501 case DW_TAG_try_block
:
5502 case DW_TAG_catch_block
:
5503 read_lexical_block_scope (die
, cu
);
5505 case DW_TAG_GNU_call_site
:
5506 read_call_site_scope (die
, cu
);
5508 case DW_TAG_class_type
:
5509 case DW_TAG_interface_type
:
5510 case DW_TAG_structure_type
:
5511 case DW_TAG_union_type
:
5512 process_structure_scope (die
, cu
);
5514 case DW_TAG_enumeration_type
:
5515 process_enumeration_scope (die
, cu
);
5518 /* These dies have a type, but processing them does not create
5519 a symbol or recurse to process the children. Therefore we can
5520 read them on-demand through read_type_die. */
5521 case DW_TAG_subroutine_type
:
5522 case DW_TAG_set_type
:
5523 case DW_TAG_array_type
:
5524 case DW_TAG_pointer_type
:
5525 case DW_TAG_ptr_to_member_type
:
5526 case DW_TAG_reference_type
:
5527 case DW_TAG_string_type
:
5530 case DW_TAG_base_type
:
5531 case DW_TAG_subrange_type
:
5532 case DW_TAG_typedef
:
5533 /* Add a typedef symbol for the type definition, if it has a
5535 new_symbol (die
, read_type_die (die
, cu
), cu
);
5537 case DW_TAG_common_block
:
5538 read_common_block (die
, cu
);
5540 case DW_TAG_common_inclusion
:
5542 case DW_TAG_namespace
:
5543 processing_has_namespace_info
= 1;
5544 read_namespace (die
, cu
);
5547 processing_has_namespace_info
= 1;
5548 read_module (die
, cu
);
5550 case DW_TAG_imported_declaration
:
5551 case DW_TAG_imported_module
:
5552 processing_has_namespace_info
= 1;
5553 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5554 || cu
->language
!= language_fortran
))
5555 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5556 dwarf_tag_name (die
->tag
));
5557 read_import_statement (die
, cu
);
5560 new_symbol (die
, NULL
, cu
);
5565 /* A helper function for dwarf2_compute_name which determines whether DIE
5566 needs to have the name of the scope prepended to the name listed in the
5570 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5572 struct attribute
*attr
;
5576 case DW_TAG_namespace
:
5577 case DW_TAG_typedef
:
5578 case DW_TAG_class_type
:
5579 case DW_TAG_interface_type
:
5580 case DW_TAG_structure_type
:
5581 case DW_TAG_union_type
:
5582 case DW_TAG_enumeration_type
:
5583 case DW_TAG_enumerator
:
5584 case DW_TAG_subprogram
:
5588 case DW_TAG_variable
:
5589 case DW_TAG_constant
:
5590 /* We only need to prefix "globally" visible variables. These include
5591 any variable marked with DW_AT_external or any variable that
5592 lives in a namespace. [Variables in anonymous namespaces
5593 require prefixing, but they are not DW_AT_external.] */
5595 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
5597 struct dwarf2_cu
*spec_cu
= cu
;
5599 return die_needs_namespace (die_specification (die
, &spec_cu
),
5603 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5604 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
5605 && die
->parent
->tag
!= DW_TAG_module
)
5607 /* A variable in a lexical block of some kind does not need a
5608 namespace, even though in C++ such variables may be external
5609 and have a mangled name. */
5610 if (die
->parent
->tag
== DW_TAG_lexical_block
5611 || die
->parent
->tag
== DW_TAG_try_block
5612 || die
->parent
->tag
== DW_TAG_catch_block
5613 || die
->parent
->tag
== DW_TAG_subprogram
)
5622 /* Retrieve the last character from a mem_file. */
5625 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
5627 char *last_char_p
= (char *) object
;
5630 *last_char_p
= buffer
[length
- 1];
5633 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
5634 compute the physname for the object, which include a method's:
5635 - formal parameters (C++/Java),
5636 - receiver type (Go),
5637 - return type (Java).
5639 The term "physname" is a bit confusing.
5640 For C++, for example, it is the demangled name.
5641 For Go, for example, it's the mangled name.
5643 For Ada, return the DIE's linkage name rather than the fully qualified
5644 name. PHYSNAME is ignored..
5646 The result is allocated on the objfile_obstack and canonicalized. */
5649 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
5652 struct objfile
*objfile
= cu
->objfile
;
5655 name
= dwarf2_name (die
, cu
);
5657 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
5658 compute it by typename_concat inside GDB. */
5659 if (cu
->language
== language_ada
5660 || (cu
->language
== language_fortran
&& physname
))
5662 /* For Ada unit, we prefer the linkage name over the name, as
5663 the former contains the exported name, which the user expects
5664 to be able to reference. Ideally, we want the user to be able
5665 to reference this entity using either natural or linkage name,
5666 but we haven't started looking at this enhancement yet. */
5667 struct attribute
*attr
;
5669 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5671 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5672 if (attr
&& DW_STRING (attr
))
5673 return DW_STRING (attr
);
5676 /* These are the only languages we know how to qualify names in. */
5678 && (cu
->language
== language_cplus
|| cu
->language
== language_java
5679 || cu
->language
== language_fortran
))
5681 if (die_needs_namespace (die
, cu
))
5685 struct ui_file
*buf
;
5687 prefix
= determine_prefix (die
, cu
);
5688 buf
= mem_fileopen ();
5689 if (*prefix
!= '\0')
5691 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
5694 fputs_unfiltered (prefixed_name
, buf
);
5695 xfree (prefixed_name
);
5698 fputs_unfiltered (name
, buf
);
5700 /* Template parameters may be specified in the DIE's DW_AT_name, or
5701 as children with DW_TAG_template_type_param or
5702 DW_TAG_value_type_param. If the latter, add them to the name
5703 here. If the name already has template parameters, then
5704 skip this step; some versions of GCC emit both, and
5705 it is more efficient to use the pre-computed name.
5707 Something to keep in mind about this process: it is very
5708 unlikely, or in some cases downright impossible, to produce
5709 something that will match the mangled name of a function.
5710 If the definition of the function has the same debug info,
5711 we should be able to match up with it anyway. But fallbacks
5712 using the minimal symbol, for instance to find a method
5713 implemented in a stripped copy of libstdc++, will not work.
5714 If we do not have debug info for the definition, we will have to
5715 match them up some other way.
5717 When we do name matching there is a related problem with function
5718 templates; two instantiated function templates are allowed to
5719 differ only by their return types, which we do not add here. */
5721 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
5723 struct attribute
*attr
;
5724 struct die_info
*child
;
5727 die
->building_fullname
= 1;
5729 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
5734 struct dwarf2_locexpr_baton
*baton
;
5737 if (child
->tag
!= DW_TAG_template_type_param
5738 && child
->tag
!= DW_TAG_template_value_param
)
5743 fputs_unfiltered ("<", buf
);
5747 fputs_unfiltered (", ", buf
);
5749 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
5752 complaint (&symfile_complaints
,
5753 _("template parameter missing DW_AT_type"));
5754 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
5757 type
= die_type (child
, cu
);
5759 if (child
->tag
== DW_TAG_template_type_param
)
5761 c_print_type (type
, "", buf
, -1, 0);
5765 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
5768 complaint (&symfile_complaints
,
5769 _("template parameter missing "
5770 "DW_AT_const_value"));
5771 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
5775 dwarf2_const_value_attr (attr
, type
, name
,
5776 &cu
->comp_unit_obstack
, cu
,
5777 &value
, &bytes
, &baton
);
5779 if (TYPE_NOSIGN (type
))
5780 /* GDB prints characters as NUMBER 'CHAR'. If that's
5781 changed, this can use value_print instead. */
5782 c_printchar (value
, type
, buf
);
5785 struct value_print_options opts
;
5788 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
5792 else if (bytes
!= NULL
)
5794 v
= allocate_value (type
);
5795 memcpy (value_contents_writeable (v
), bytes
,
5796 TYPE_LENGTH (type
));
5799 v
= value_from_longest (type
, value
);
5801 /* Specify decimal so that we do not depend on
5803 get_formatted_print_options (&opts
, 'd');
5805 value_print (v
, buf
, &opts
);
5811 die
->building_fullname
= 0;
5815 /* Close the argument list, with a space if necessary
5816 (nested templates). */
5817 char last_char
= '\0';
5818 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5819 if (last_char
== '>')
5820 fputs_unfiltered (" >", buf
);
5822 fputs_unfiltered (">", buf
);
5826 /* For Java and C++ methods, append formal parameter type
5827 information, if PHYSNAME. */
5829 if (physname
&& die
->tag
== DW_TAG_subprogram
5830 && (cu
->language
== language_cplus
5831 || cu
->language
== language_java
))
5833 struct type
*type
= read_type_die (die
, cu
);
5835 c_type_print_args (type
, buf
, 1, cu
->language
);
5837 if (cu
->language
== language_java
)
5839 /* For java, we must append the return type to method
5841 if (die
->tag
== DW_TAG_subprogram
)
5842 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5845 else if (cu
->language
== language_cplus
)
5847 /* Assume that an artificial first parameter is
5848 "this", but do not crash if it is not. RealView
5849 marks unnamed (and thus unused) parameters as
5850 artificial; there is no way to differentiate
5852 if (TYPE_NFIELDS (type
) > 0
5853 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5854 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5855 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5857 fputs_unfiltered (" const", buf
);
5861 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
5863 ui_file_delete (buf
);
5865 if (cu
->language
== language_cplus
)
5868 = dwarf2_canonicalize_name (name
, cu
,
5869 &objfile
->objfile_obstack
);
5880 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5881 If scope qualifiers are appropriate they will be added. The result
5882 will be allocated on the objfile_obstack, or NULL if the DIE does
5883 not have a name. NAME may either be from a previous call to
5884 dwarf2_name or NULL.
5886 The output string will be canonicalized (if C++/Java). */
5889 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5891 return dwarf2_compute_name (name
, die
, cu
, 0);
5894 /* Construct a physname for the given DIE in CU. NAME may either be
5895 from a previous call to dwarf2_name or NULL. The result will be
5896 allocated on the objfile_objstack or NULL if the DIE does not have a
5899 The output string will be canonicalized (if C++/Java). */
5902 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5904 struct objfile
*objfile
= cu
->objfile
;
5905 struct attribute
*attr
;
5906 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
5907 struct cleanup
*back_to
;
5910 /* In this case dwarf2_compute_name is just a shortcut not building anything
5912 if (!die_needs_namespace (die
, cu
))
5913 return dwarf2_compute_name (name
, die
, cu
, 1);
5915 back_to
= make_cleanup (null_cleanup
, NULL
);
5917 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
5919 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
5921 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
5923 if (attr
&& DW_STRING (attr
))
5927 mangled
= DW_STRING (attr
);
5929 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
5930 type. It is easier for GDB users to search for such functions as
5931 `name(params)' than `long name(params)'. In such case the minimal
5932 symbol names do not match the full symbol names but for template
5933 functions there is never a need to look up their definition from their
5934 declaration so the only disadvantage remains the minimal symbol
5935 variant `long name(params)' does not have the proper inferior type.
5938 if (cu
->language
== language_go
)
5940 /* This is a lie, but we already lie to the caller new_symbol_full.
5941 new_symbol_full assumes we return the mangled name.
5942 This just undoes that lie until things are cleaned up. */
5947 demangled
= cplus_demangle (mangled
,
5948 (DMGL_PARAMS
| DMGL_ANSI
5949 | (cu
->language
== language_java
5950 ? DMGL_JAVA
| DMGL_RET_POSTFIX
5955 make_cleanup (xfree
, demangled
);
5965 if (canon
== NULL
|| check_physname
)
5967 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
5969 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
5971 /* It may not mean a bug in GDB. The compiler could also
5972 compute DW_AT_linkage_name incorrectly. But in such case
5973 GDB would need to be bug-to-bug compatible. */
5975 complaint (&symfile_complaints
,
5976 _("Computed physname <%s> does not match demangled <%s> "
5977 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
5978 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
5980 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
5981 is available here - over computed PHYSNAME. It is safer
5982 against both buggy GDB and buggy compilers. */
5996 retval
= obsavestring (retval
, strlen (retval
),
5997 &objfile
->objfile_obstack
);
5999 do_cleanups (back_to
);
6003 /* Read the import statement specified by the given die and record it. */
6006 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6008 struct objfile
*objfile
= cu
->objfile
;
6009 struct attribute
*import_attr
;
6010 struct die_info
*imported_die
, *child_die
;
6011 struct dwarf2_cu
*imported_cu
;
6012 const char *imported_name
;
6013 const char *imported_name_prefix
;
6014 const char *canonical_name
;
6015 const char *import_alias
;
6016 const char *imported_declaration
= NULL
;
6017 const char *import_prefix
;
6018 VEC (const_char_ptr
) *excludes
= NULL
;
6019 struct cleanup
*cleanups
;
6023 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6024 if (import_attr
== NULL
)
6026 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6027 dwarf_tag_name (die
->tag
));
6032 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6033 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6034 if (imported_name
== NULL
)
6036 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6038 The import in the following code:
6052 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6053 <52> DW_AT_decl_file : 1
6054 <53> DW_AT_decl_line : 6
6055 <54> DW_AT_import : <0x75>
6056 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6058 <5b> DW_AT_decl_file : 1
6059 <5c> DW_AT_decl_line : 2
6060 <5d> DW_AT_type : <0x6e>
6062 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6063 <76> DW_AT_byte_size : 4
6064 <77> DW_AT_encoding : 5 (signed)
6066 imports the wrong die ( 0x75 instead of 0x58 ).
6067 This case will be ignored until the gcc bug is fixed. */
6071 /* Figure out the local name after import. */
6072 import_alias
= dwarf2_name (die
, cu
);
6074 /* Figure out where the statement is being imported to. */
6075 import_prefix
= determine_prefix (die
, cu
);
6077 /* Figure out what the scope of the imported die is and prepend it
6078 to the name of the imported die. */
6079 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6081 if (imported_die
->tag
!= DW_TAG_namespace
6082 && imported_die
->tag
!= DW_TAG_module
)
6084 imported_declaration
= imported_name
;
6085 canonical_name
= imported_name_prefix
;
6087 else if (strlen (imported_name_prefix
) > 0)
6089 temp
= alloca (strlen (imported_name_prefix
)
6090 + 2 + strlen (imported_name
) + 1);
6091 strcpy (temp
, imported_name_prefix
);
6092 strcat (temp
, "::");
6093 strcat (temp
, imported_name
);
6094 canonical_name
= temp
;
6097 canonical_name
= imported_name
;
6099 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6101 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6102 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6103 child_die
= sibling_die (child_die
))
6105 /* DWARF-4: A Fortran use statement with a “rename list” may be
6106 represented by an imported module entry with an import attribute
6107 referring to the module and owned entries corresponding to those
6108 entities that are renamed as part of being imported. */
6110 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6112 complaint (&symfile_complaints
,
6113 _("child DW_TAG_imported_declaration expected "
6114 "- DIE at 0x%x [in module %s]"),
6115 child_die
->offset
.sect_off
, objfile
->name
);
6119 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6120 if (import_attr
== NULL
)
6122 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6123 dwarf_tag_name (child_die
->tag
));
6128 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6130 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6131 if (imported_name
== NULL
)
6133 complaint (&symfile_complaints
,
6134 _("child DW_TAG_imported_declaration has unknown "
6135 "imported name - DIE at 0x%x [in module %s]"),
6136 child_die
->offset
.sect_off
, objfile
->name
);
6140 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6142 process_die (child_die
, cu
);
6145 cp_add_using_directive (import_prefix
,
6148 imported_declaration
,
6150 &objfile
->objfile_obstack
);
6152 do_cleanups (cleanups
);
6155 /* Cleanup function for read_file_scope. */
6158 free_cu_line_header (void *arg
)
6160 struct dwarf2_cu
*cu
= arg
;
6162 free_line_header (cu
->line_header
);
6163 cu
->line_header
= NULL
;
6167 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6168 char **name
, char **comp_dir
)
6170 struct attribute
*attr
;
6175 /* Find the filename. Do not use dwarf2_name here, since the filename
6176 is not a source language identifier. */
6177 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6180 *name
= DW_STRING (attr
);
6183 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6185 *comp_dir
= DW_STRING (attr
);
6186 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6188 *comp_dir
= ldirname (*name
);
6189 if (*comp_dir
!= NULL
)
6190 make_cleanup (xfree
, *comp_dir
);
6192 if (*comp_dir
!= NULL
)
6194 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6195 directory, get rid of it. */
6196 char *cp
= strchr (*comp_dir
, ':');
6198 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6203 *name
= "<unknown>";
6206 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6207 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6208 COMP_DIR is the compilation directory.
6209 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6212 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6213 const char *comp_dir
, int want_line_info
)
6215 struct attribute
*attr
;
6217 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6220 unsigned int line_offset
= DW_UNSND (attr
);
6221 struct line_header
*line_header
6222 = dwarf_decode_line_header (line_offset
, cu
);
6226 cu
->line_header
= line_header
;
6227 make_cleanup (free_cu_line_header
, cu
);
6228 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6233 /* Process DW_TAG_compile_unit. */
6236 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6238 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6239 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6240 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6241 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6242 struct attribute
*attr
;
6244 char *comp_dir
= NULL
;
6245 struct die_info
*child_die
;
6246 bfd
*abfd
= objfile
->obfd
;
6249 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6251 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6253 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6254 from finish_block. */
6255 if (lowpc
== ((CORE_ADDR
) -1))
6260 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6262 prepare_one_comp_unit (cu
, die
);
6264 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6265 standardised yet. As a workaround for the language detection we fall
6266 back to the DW_AT_producer string. */
6267 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6268 cu
->language
= language_opencl
;
6270 /* Similar hack for Go. */
6271 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6272 set_cu_language (DW_LANG_Go
, cu
);
6274 /* We assume that we're processing GCC output. */
6275 processing_gcc_compilation
= 2;
6277 processing_has_namespace_info
= 0;
6279 start_symtab (name
, comp_dir
, lowpc
);
6280 record_debugformat ("DWARF 2");
6281 record_producer (cu
->producer
);
6283 /* Decode line number information if present. We do this before
6284 processing child DIEs, so that the line header table is available
6285 for DW_AT_decl_file. */
6286 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6288 /* Process all dies in compilation unit. */
6289 if (die
->child
!= NULL
)
6291 child_die
= die
->child
;
6292 while (child_die
&& child_die
->tag
)
6294 process_die (child_die
, cu
);
6295 child_die
= sibling_die (child_die
);
6299 /* Decode macro information, if present. Dwarf 2 macro information
6300 refers to information in the line number info statement program
6301 header, so we can only read it if we've read the header
6303 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6304 if (attr
&& cu
->line_header
)
6306 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6307 complaint (&symfile_complaints
,
6308 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6310 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6312 &dwarf2_per_objfile
->macro
, 1,
6317 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6318 if (attr
&& cu
->line_header
)
6320 unsigned int macro_offset
= DW_UNSND (attr
);
6322 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6324 &dwarf2_per_objfile
->macinfo
, 0,
6329 do_cleanups (back_to
);
6332 /* Process DW_TAG_type_unit.
6333 For TUs we want to skip the first top level sibling if it's not the
6334 actual type being defined by this TU. In this case the first top
6335 level sibling is there to provide context only. */
6338 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6340 struct objfile
*objfile
= cu
->objfile
;
6341 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6343 struct attribute
*attr
;
6345 char *comp_dir
= NULL
;
6346 struct die_info
*child_die
;
6347 bfd
*abfd
= objfile
->obfd
;
6349 /* start_symtab needs a low pc, but we don't really have one.
6350 Do what read_file_scope would do in the absence of such info. */
6351 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6353 /* Find the filename. Do not use dwarf2_name here, since the filename
6354 is not a source language identifier. */
6355 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6357 name
= DW_STRING (attr
);
6359 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6361 comp_dir
= DW_STRING (attr
);
6362 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6364 comp_dir
= ldirname (name
);
6365 if (comp_dir
!= NULL
)
6366 make_cleanup (xfree
, comp_dir
);
6372 prepare_one_comp_unit (cu
, die
);
6374 /* We assume that we're processing GCC output. */
6375 processing_gcc_compilation
= 2;
6377 processing_has_namespace_info
= 0;
6379 start_symtab (name
, comp_dir
, lowpc
);
6380 record_debugformat ("DWARF 2");
6381 record_producer (cu
->producer
);
6383 /* Decode line number information if present. We do this before
6384 processing child DIEs, so that the line header table is available
6385 for DW_AT_decl_file.
6386 We don't need the pc/line-number mapping for type units. */
6387 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6389 /* Process the dies in the type unit. */
6390 if (die
->child
== NULL
)
6392 dump_die_for_error (die
);
6393 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6394 bfd_get_filename (abfd
));
6397 child_die
= die
->child
;
6399 while (child_die
&& child_die
->tag
)
6401 process_die (child_die
, cu
);
6403 child_die
= sibling_die (child_die
);
6406 do_cleanups (back_to
);
6412 hash_dwo_file (const void *item
)
6414 const struct dwo_file
*dwo_file
= item
;
6416 return htab_hash_string (dwo_file
->dwo_name
);
6420 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6422 const struct dwo_file
*lhs
= item_lhs
;
6423 const struct dwo_file
*rhs
= item_rhs
;
6425 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6428 /* Allocate a hash table for DWO files. */
6431 allocate_dwo_file_hash_table (void)
6433 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6435 return htab_create_alloc_ex (41,
6439 &objfile
->objfile_obstack
,
6440 hashtab_obstack_allocate
,
6441 dummy_obstack_deallocate
);
6445 hash_dwo_unit (const void *item
)
6447 const struct dwo_unit
*dwo_unit
= item
;
6449 /* This drops the top 32 bits of the id, but is ok for a hash. */
6450 return dwo_unit
->signature
;
6454 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6456 const struct dwo_unit
*lhs
= item_lhs
;
6457 const struct dwo_unit
*rhs
= item_rhs
;
6459 /* The signature is assumed to be unique within the DWO file.
6460 So while object file CU dwo_id's always have the value zero,
6461 that's OK, assuming each object file DWO file has only one CU,
6462 and that's the rule for now. */
6463 return lhs
->signature
== rhs
->signature
;
6466 /* Allocate a hash table for DWO CUs,TUs.
6467 There is one of these tables for each of CUs,TUs for each DWO file. */
6470 allocate_dwo_unit_table (struct objfile
*objfile
)
6472 /* Start out with a pretty small number.
6473 Generally DWO files contain only one CU and maybe some TUs. */
6474 return htab_create_alloc_ex (3,
6478 &objfile
->objfile_obstack
,
6479 hashtab_obstack_allocate
,
6480 dummy_obstack_deallocate
);
6483 /* This function is mapped across the sections and remembers the offset and
6484 size of each of the DWO debugging sections we are interested in. */
6487 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6489 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6490 const struct dwo_section_names
*names
= &dwo_section_names
;
6492 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6494 dwo_file
->sections
.abbrev
.asection
= sectp
;
6495 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6497 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6499 dwo_file
->sections
.info
.asection
= sectp
;
6500 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6502 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6504 dwo_file
->sections
.line
.asection
= sectp
;
6505 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6507 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6509 dwo_file
->sections
.loc
.asection
= sectp
;
6510 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6512 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6514 dwo_file
->sections
.str
.asection
= sectp
;
6515 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6517 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6519 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6520 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6522 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6524 struct dwarf2_section_info type_section
;
6526 memset (&type_section
, 0, sizeof (type_section
));
6527 type_section
.asection
= sectp
;
6528 type_section
.size
= bfd_get_section_size (sectp
);
6529 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6534 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6536 struct create_dwo_info_table_data
6538 struct dwo_file
*dwo_file
;
6542 /* die_reader_func for create_debug_info_hash_table. */
6545 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6547 struct die_info
*comp_unit_die
,
6551 struct dwarf2_cu
*cu
= reader
->cu
;
6552 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6553 sect_offset offset
= cu
->per_cu
->offset
;
6554 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6555 struct create_dwo_info_table_data
*data
= datap
;
6556 struct dwo_file
*dwo_file
= data
->dwo_file
;
6557 htab_t cu_htab
= data
->cu_htab
;
6559 struct attribute
*attr
;
6560 struct dwo_unit
*dwo_unit
;
6562 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6565 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6566 " its dwo_id [in module %s]"),
6567 offset
.sect_off
, dwo_file
->dwo_name
);
6571 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6572 dwo_unit
->dwo_file
= dwo_file
;
6573 dwo_unit
->signature
= DW_UNSND (attr
);
6574 dwo_unit
->info_or_types_section
= section
;
6575 dwo_unit
->offset
= offset
;
6576 dwo_unit
->length
= cu
->per_cu
->length
;
6578 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
6579 gdb_assert (slot
!= NULL
);
6582 const struct dwo_unit
*dup_dwo_unit
= *slot
;
6584 complaint (&symfile_complaints
,
6585 _("debug entry at offset 0x%x is duplicate to the entry at"
6586 " offset 0x%x, dwo_id 0x%s [in module %s]"),
6587 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
6588 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
6589 dwo_file
->dwo_name
);
6594 if (dwarf2_die_debug
)
6595 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
6597 phex (dwo_unit
->signature
,
6598 sizeof (dwo_unit
->signature
)));
6601 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
6604 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
6606 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6607 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
6610 gdb_byte
*info_ptr
, *end_ptr
;
6611 struct create_dwo_info_table_data create_dwo_info_table_data
;
6613 dwarf2_read_section (objfile
, section
);
6614 info_ptr
= section
->buffer
;
6616 if (info_ptr
== NULL
)
6619 /* We can't set abfd until now because the section may be empty or
6620 not present, in which case section->asection will be NULL. */
6621 abfd
= section
->asection
->owner
;
6623 if (dwarf2_die_debug
)
6624 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
6625 bfd_get_filename (abfd
));
6627 cu_htab
= allocate_dwo_unit_table (objfile
);
6629 create_dwo_info_table_data
.dwo_file
= dwo_file
;
6630 create_dwo_info_table_data
.cu_htab
= cu_htab
;
6632 end_ptr
= info_ptr
+ section
->size
;
6633 while (info_ptr
< end_ptr
)
6635 struct dwarf2_per_cu_data per_cu
;
6637 memset (&per_cu
, 0, sizeof (per_cu
));
6638 per_cu
.objfile
= objfile
;
6639 per_cu
.is_debug_types
= 0;
6640 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
6641 per_cu
.info_or_types_section
= section
;
6643 init_cutu_and_read_dies_no_follow (&per_cu
,
6644 &dwo_file
->sections
.abbrev
,
6646 create_debug_info_hash_table_reader
,
6647 &create_dwo_info_table_data
);
6649 info_ptr
+= per_cu
.length
;
6655 /* Subroutine of open_dwo_file to simplify it.
6656 Open the file specified by FILE_NAME and hand it off to BFD for
6657 preliminary analysis. Return a newly initialized bfd *, which
6658 includes a canonicalized copy of FILE_NAME.
6659 In case of trouble, return NULL.
6660 NOTE: This function is derived from symfile_bfd_open. */
6663 try_open_dwo_file (const char *file_name
)
6667 char *absolute_name
;
6670 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
6671 O_RDONLY
| O_BINARY
, &absolute_name
);
6675 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
6679 xfree (absolute_name
);
6682 bfd_set_cacheable (sym_bfd
, 1);
6684 if (!bfd_check_format (sym_bfd
, bfd_object
))
6686 bfd_close (sym_bfd
); /* This also closes desc. */
6687 xfree (absolute_name
);
6691 /* bfd_usrdata exists for applications and libbfd must not touch it. */
6692 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
6697 /* Try to open DWO file DWO_NAME.
6698 COMP_DIR is the DW_AT_comp_dir attribute.
6699 The result is the bfd handle of the file.
6700 If there is a problem finding or opening the file, return NULL.
6701 Upon success, the canonicalized path of the file is stored in the bfd,
6702 same as symfile_bfd_open. */
6705 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
6708 char *path_to_try
, *debug_dir
;
6710 if (IS_ABSOLUTE_PATH (dwo_name
))
6711 return try_open_dwo_file (dwo_name
);
6713 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
6715 if (comp_dir
!= NULL
)
6717 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
6719 /* NOTE: If comp_dir is a relative path, this will also try the
6720 search path, which seems useful. */
6721 abfd
= try_open_dwo_file (path_to_try
);
6722 xfree (path_to_try
);
6727 /* That didn't work, try debug-file-directory, which, despite its name,
6728 is a list of paths. */
6730 if (*debug_file_directory
== '\0')
6733 return try_open_dwo_file (dwo_name
);
6736 /* Initialize the use of the DWO file specified by DWO_NAME. */
6738 static struct dwo_file
*
6739 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
6741 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6742 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6745 struct cleanup
*cleanups
;
6747 if (dwarf2_die_debug
)
6748 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
6750 abfd
= open_dwo_file (dwo_name
, comp_dir
);
6753 dwo_file
->dwo_name
= dwo_name
;
6754 dwo_file
->dwo_bfd
= abfd
;
6756 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
6758 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
6760 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
6762 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
6763 dwo_file
->sections
.types
);
6765 discard_cleanups (cleanups
);
6770 /* Lookup DWO file DWO_NAME. */
6772 static struct dwo_file
*
6773 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
6775 struct dwo_file
*dwo_file
;
6776 struct dwo_file find_entry
;
6779 if (dwarf2_per_objfile
->dwo_files
== NULL
)
6780 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
6782 /* Have we already seen this DWO file? */
6783 find_entry
.dwo_name
= dwo_name
;
6784 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
6786 /* If not, read it in and build a table of the DWOs it contains. */
6788 *slot
= init_dwo_file (dwo_name
, comp_dir
);
6790 /* NOTE: This will be NULL if unable to open the file. */
6796 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
6797 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
6798 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
6799 nomenclature as TUs).
6800 The result is the DWO CU or NULL if we didn't find it
6801 (dwo_id mismatch or couldn't find the DWO file). */
6803 static struct dwo_unit
*
6804 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6805 char *dwo_name
, const char *comp_dir
,
6808 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6809 struct dwo_file
*dwo_file
;
6811 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
6812 if (dwo_file
== NULL
)
6815 /* Look up the DWO using its signature(dwo_id). */
6817 if (dwo_file
->cus
!= NULL
)
6819 struct dwo_unit find_dwo_cu
, *dwo_cu
;
6821 find_dwo_cu
.signature
= signature
;
6822 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
6828 /* We didn't find it. This must mean a dwo_id mismatch. */
6830 complaint (&symfile_complaints
,
6831 _("Could not find DWO CU referenced by CU at offset 0x%x"
6833 this_cu
->offset
.sect_off
, objfile
->name
);
6837 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
6838 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
6839 The result is the DWO CU or NULL if we didn't find it
6840 (dwo_id mismatch or couldn't find the DWO file). */
6842 static struct dwo_unit
*
6843 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
6844 char *dwo_name
, const char *comp_dir
)
6846 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6847 struct dwo_file
*dwo_file
;
6848 struct dwo_unit find_dwo_tu
, *dwo_tu
;
6850 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
6851 if (dwo_file
== NULL
)
6854 /* Look up the DWO using its signature(dwo_id). */
6856 if (dwo_file
->tus
!= NULL
)
6858 struct dwo_unit find_dwo_tu
, *dwo_tu
;
6860 find_dwo_tu
.signature
= this_tu
->signature
;
6861 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
6867 /* We didn't find it. This must mean a dwo_id mismatch. */
6869 complaint (&symfile_complaints
,
6870 _("Could not find DWO TU referenced by TU at offset 0x%x"
6872 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
6876 /* Free all resources associated with DWO_FILE.
6877 Close the DWO file and munmap the sections.
6878 All memory should be on the objfile obstack. */
6881 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
6884 struct dwarf2_section_info
*section
;
6886 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
6887 bfd_close (dwo_file
->dwo_bfd
);
6889 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
6890 munmap_section_buffer (&dwo_file
->sections
.info
);
6891 munmap_section_buffer (&dwo_file
->sections
.line
);
6892 munmap_section_buffer (&dwo_file
->sections
.loc
);
6893 munmap_section_buffer (&dwo_file
->sections
.str
);
6894 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
6897 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6900 munmap_section_buffer (section
);
6902 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
6905 /* Wrapper for free_dwo_file for use in cleanups. */
6908 free_dwo_file_cleanup (void *arg
)
6910 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
6911 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6913 free_dwo_file (dwo_file
, objfile
);
6916 /* Traversal function for free_dwo_files. */
6919 free_dwo_file_from_slot (void **slot
, void *info
)
6921 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
6922 struct objfile
*objfile
= (struct objfile
*) info
;
6924 free_dwo_file (dwo_file
, objfile
);
6929 /* Free all resources associated with DWO_FILES. */
6932 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
6934 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
6937 /* Read in various DIEs. */
6939 /* qsort helper for inherit_abstract_dies. */
6942 unsigned_int_compar (const void *ap
, const void *bp
)
6944 unsigned int a
= *(unsigned int *) ap
;
6945 unsigned int b
= *(unsigned int *) bp
;
6947 return (a
> b
) - (b
> a
);
6950 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
6951 Inherit only the children of the DW_AT_abstract_origin DIE not being
6952 already referenced by DW_AT_abstract_origin from the children of the
6956 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
6958 struct die_info
*child_die
;
6959 unsigned die_children_count
;
6960 /* CU offsets which were referenced by children of the current DIE. */
6961 sect_offset
*offsets
;
6962 sect_offset
*offsets_end
, *offsetp
;
6963 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
6964 struct die_info
*origin_die
;
6965 /* Iterator of the ORIGIN_DIE children. */
6966 struct die_info
*origin_child_die
;
6967 struct cleanup
*cleanups
;
6968 struct attribute
*attr
;
6969 struct dwarf2_cu
*origin_cu
;
6970 struct pending
**origin_previous_list_in_scope
;
6972 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
6976 /* Note that following die references may follow to a die in a
6980 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
6982 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
6984 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
6985 origin_cu
->list_in_scope
= cu
->list_in_scope
;
6987 if (die
->tag
!= origin_die
->tag
6988 && !(die
->tag
== DW_TAG_inlined_subroutine
6989 && origin_die
->tag
== DW_TAG_subprogram
))
6990 complaint (&symfile_complaints
,
6991 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
6992 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
6994 child_die
= die
->child
;
6995 die_children_count
= 0;
6996 while (child_die
&& child_die
->tag
)
6998 child_die
= sibling_die (child_die
);
6999 die_children_count
++;
7001 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7002 cleanups
= make_cleanup (xfree
, offsets
);
7004 offsets_end
= offsets
;
7005 child_die
= die
->child
;
7006 while (child_die
&& child_die
->tag
)
7008 /* For each CHILD_DIE, find the corresponding child of
7009 ORIGIN_DIE. If there is more than one layer of
7010 DW_AT_abstract_origin, follow them all; there shouldn't be,
7011 but GCC versions at least through 4.4 generate this (GCC PR
7013 struct die_info
*child_origin_die
= child_die
;
7014 struct dwarf2_cu
*child_origin_cu
= cu
;
7018 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7022 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7026 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7027 counterpart may exist. */
7028 if (child_origin_die
!= child_die
)
7030 if (child_die
->tag
!= child_origin_die
->tag
7031 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7032 && child_origin_die
->tag
== DW_TAG_subprogram
))
7033 complaint (&symfile_complaints
,
7034 _("Child DIE 0x%x and its abstract origin 0x%x have "
7035 "different tags"), child_die
->offset
.sect_off
,
7036 child_origin_die
->offset
.sect_off
);
7037 if (child_origin_die
->parent
!= origin_die
)
7038 complaint (&symfile_complaints
,
7039 _("Child DIE 0x%x and its abstract origin 0x%x have "
7040 "different parents"), child_die
->offset
.sect_off
,
7041 child_origin_die
->offset
.sect_off
);
7043 *offsets_end
++ = child_origin_die
->offset
;
7045 child_die
= sibling_die (child_die
);
7047 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7048 unsigned_int_compar
);
7049 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7050 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7051 complaint (&symfile_complaints
,
7052 _("Multiple children of DIE 0x%x refer "
7053 "to DIE 0x%x as their abstract origin"),
7054 die
->offset
.sect_off
, offsetp
->sect_off
);
7057 origin_child_die
= origin_die
->child
;
7058 while (origin_child_die
&& origin_child_die
->tag
)
7060 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7061 while (offsetp
< offsets_end
7062 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7064 if (offsetp
>= offsets_end
7065 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7067 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7068 process_die (origin_child_die
, origin_cu
);
7070 origin_child_die
= sibling_die (origin_child_die
);
7072 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7074 do_cleanups (cleanups
);
7078 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7080 struct objfile
*objfile
= cu
->objfile
;
7081 struct context_stack
*new;
7084 struct die_info
*child_die
;
7085 struct attribute
*attr
, *call_line
, *call_file
;
7088 struct block
*block
;
7089 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7090 VEC (symbolp
) *template_args
= NULL
;
7091 struct template_symbol
*templ_func
= NULL
;
7095 /* If we do not have call site information, we can't show the
7096 caller of this inlined function. That's too confusing, so
7097 only use the scope for local variables. */
7098 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7099 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7100 if (call_line
== NULL
|| call_file
== NULL
)
7102 read_lexical_block_scope (die
, cu
);
7107 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7109 name
= dwarf2_name (die
, cu
);
7111 /* Ignore functions with missing or empty names. These are actually
7112 illegal according to the DWARF standard. */
7115 complaint (&symfile_complaints
,
7116 _("missing name for subprogram DIE at %d"),
7117 die
->offset
.sect_off
);
7121 /* Ignore functions with missing or invalid low and high pc attributes. */
7122 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7124 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7125 if (!attr
|| !DW_UNSND (attr
))
7126 complaint (&symfile_complaints
,
7127 _("cannot get low and high bounds "
7128 "for subprogram DIE at %d"),
7129 die
->offset
.sect_off
);
7136 /* If we have any template arguments, then we must allocate a
7137 different sort of symbol. */
7138 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7140 if (child_die
->tag
== DW_TAG_template_type_param
7141 || child_die
->tag
== DW_TAG_template_value_param
)
7143 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7144 struct template_symbol
);
7145 templ_func
->base
.is_cplus_template_function
= 1;
7150 new = push_context (0, lowpc
);
7151 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7152 (struct symbol
*) templ_func
);
7154 /* If there is a location expression for DW_AT_frame_base, record
7156 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7158 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7159 expression is being recorded directly in the function's symbol
7160 and not in a separate frame-base object. I guess this hack is
7161 to avoid adding some sort of frame-base adjunct/annex to the
7162 function's symbol :-(. The problem with doing this is that it
7163 results in a function symbol with a location expression that
7164 has nothing to do with the location of the function, ouch! The
7165 relationship should be: a function's symbol has-a frame base; a
7166 frame-base has-a location expression. */
7167 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7169 cu
->list_in_scope
= &local_symbols
;
7171 if (die
->child
!= NULL
)
7173 child_die
= die
->child
;
7174 while (child_die
&& child_die
->tag
)
7176 if (child_die
->tag
== DW_TAG_template_type_param
7177 || child_die
->tag
== DW_TAG_template_value_param
)
7179 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7182 VEC_safe_push (symbolp
, template_args
, arg
);
7185 process_die (child_die
, cu
);
7186 child_die
= sibling_die (child_die
);
7190 inherit_abstract_dies (die
, cu
);
7192 /* If we have a DW_AT_specification, we might need to import using
7193 directives from the context of the specification DIE. See the
7194 comment in determine_prefix. */
7195 if (cu
->language
== language_cplus
7196 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7198 struct dwarf2_cu
*spec_cu
= cu
;
7199 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7203 child_die
= spec_die
->child
;
7204 while (child_die
&& child_die
->tag
)
7206 if (child_die
->tag
== DW_TAG_imported_module
)
7207 process_die (child_die
, spec_cu
);
7208 child_die
= sibling_die (child_die
);
7211 /* In some cases, GCC generates specification DIEs that
7212 themselves contain DW_AT_specification attributes. */
7213 spec_die
= die_specification (spec_die
, &spec_cu
);
7217 new = pop_context ();
7218 /* Make a block for the local symbols within. */
7219 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7220 lowpc
, highpc
, objfile
);
7222 /* For C++, set the block's scope. */
7223 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7224 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7225 determine_prefix (die
, cu
),
7226 processing_has_namespace_info
);
7228 /* If we have address ranges, record them. */
7229 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7231 /* Attach template arguments to function. */
7232 if (! VEC_empty (symbolp
, template_args
))
7234 gdb_assert (templ_func
!= NULL
);
7236 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7237 templ_func
->template_arguments
7238 = obstack_alloc (&objfile
->objfile_obstack
,
7239 (templ_func
->n_template_arguments
7240 * sizeof (struct symbol
*)));
7241 memcpy (templ_func
->template_arguments
,
7242 VEC_address (symbolp
, template_args
),
7243 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7244 VEC_free (symbolp
, template_args
);
7247 /* In C++, we can have functions nested inside functions (e.g., when
7248 a function declares a class that has methods). This means that
7249 when we finish processing a function scope, we may need to go
7250 back to building a containing block's symbol lists. */
7251 local_symbols
= new->locals
;
7252 param_symbols
= new->params
;
7253 using_directives
= new->using_directives
;
7255 /* If we've finished processing a top-level function, subsequent
7256 symbols go in the file symbol list. */
7257 if (outermost_context_p ())
7258 cu
->list_in_scope
= &file_symbols
;
7261 /* Process all the DIES contained within a lexical block scope. Start
7262 a new scope, process the dies, and then close the scope. */
7265 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7267 struct objfile
*objfile
= cu
->objfile
;
7268 struct context_stack
*new;
7269 CORE_ADDR lowpc
, highpc
;
7270 struct die_info
*child_die
;
7273 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7275 /* Ignore blocks with missing or invalid low and high pc attributes. */
7276 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7277 as multiple lexical blocks? Handling children in a sane way would
7278 be nasty. Might be easier to properly extend generic blocks to
7280 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7285 push_context (0, lowpc
);
7286 if (die
->child
!= NULL
)
7288 child_die
= die
->child
;
7289 while (child_die
&& child_die
->tag
)
7291 process_die (child_die
, cu
);
7292 child_die
= sibling_die (child_die
);
7295 new = pop_context ();
7297 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7300 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7303 /* Note that recording ranges after traversing children, as we
7304 do here, means that recording a parent's ranges entails
7305 walking across all its children's ranges as they appear in
7306 the address map, which is quadratic behavior.
7308 It would be nicer to record the parent's ranges before
7309 traversing its children, simply overriding whatever you find
7310 there. But since we don't even decide whether to create a
7311 block until after we've traversed its children, that's hard
7313 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7315 local_symbols
= new->locals
;
7316 using_directives
= new->using_directives
;
7319 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7322 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7324 struct objfile
*objfile
= cu
->objfile
;
7325 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7326 CORE_ADDR pc
, baseaddr
;
7327 struct attribute
*attr
;
7328 struct call_site
*call_site
, call_site_local
;
7331 struct die_info
*child_die
;
7333 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7335 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7338 complaint (&symfile_complaints
,
7339 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7340 "DIE 0x%x [in module %s]"),
7341 die
->offset
.sect_off
, objfile
->name
);
7344 pc
= DW_ADDR (attr
) + baseaddr
;
7346 if (cu
->call_site_htab
== NULL
)
7347 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7348 NULL
, &objfile
->objfile_obstack
,
7349 hashtab_obstack_allocate
, NULL
);
7350 call_site_local
.pc
= pc
;
7351 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7354 complaint (&symfile_complaints
,
7355 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7356 "DIE 0x%x [in module %s]"),
7357 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7361 /* Count parameters at the caller. */
7364 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7365 child_die
= sibling_die (child_die
))
7367 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7369 complaint (&symfile_complaints
,
7370 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7371 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7372 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7379 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7380 (sizeof (*call_site
)
7381 + (sizeof (*call_site
->parameter
)
7384 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7387 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7389 struct die_info
*func_die
;
7391 /* Skip also over DW_TAG_inlined_subroutine. */
7392 for (func_die
= die
->parent
;
7393 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7394 && func_die
->tag
!= DW_TAG_subroutine_type
;
7395 func_die
= func_die
->parent
);
7397 /* DW_AT_GNU_all_call_sites is a superset
7398 of DW_AT_GNU_all_tail_call_sites. */
7400 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7401 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7403 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7404 not complete. But keep CALL_SITE for look ups via call_site_htab,
7405 both the initial caller containing the real return address PC and
7406 the final callee containing the current PC of a chain of tail
7407 calls do not need to have the tail call list complete. But any
7408 function candidate for a virtual tail call frame searched via
7409 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7410 determined unambiguously. */
7414 struct type
*func_type
= NULL
;
7417 func_type
= get_die_type (func_die
, cu
);
7418 if (func_type
!= NULL
)
7420 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7422 /* Enlist this call site to the function. */
7423 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7424 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7427 complaint (&symfile_complaints
,
7428 _("Cannot find function owning DW_TAG_GNU_call_site "
7429 "DIE 0x%x [in module %s]"),
7430 die
->offset
.sect_off
, objfile
->name
);
7434 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7436 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7437 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7438 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7439 /* Keep NULL DWARF_BLOCK. */;
7440 else if (attr_form_is_block (attr
))
7442 struct dwarf2_locexpr_baton
*dlbaton
;
7444 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7445 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7446 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7447 dlbaton
->per_cu
= cu
->per_cu
;
7449 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7451 else if (is_ref_attr (attr
))
7453 struct dwarf2_cu
*target_cu
= cu
;
7454 struct die_info
*target_die
;
7456 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7457 gdb_assert (target_cu
->objfile
== objfile
);
7458 if (die_is_declaration (target_die
, target_cu
))
7460 const char *target_physname
;
7462 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7463 if (target_physname
== NULL
)
7464 complaint (&symfile_complaints
,
7465 _("DW_AT_GNU_call_site_target target DIE has invalid "
7466 "physname, for referencing DIE 0x%x [in module %s]"),
7467 die
->offset
.sect_off
, objfile
->name
);
7469 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7475 /* DW_AT_entry_pc should be preferred. */
7476 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7477 complaint (&symfile_complaints
,
7478 _("DW_AT_GNU_call_site_target target DIE has invalid "
7479 "low pc, for referencing DIE 0x%x [in module %s]"),
7480 die
->offset
.sect_off
, objfile
->name
);
7482 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7486 complaint (&symfile_complaints
,
7487 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7488 "block nor reference, for DIE 0x%x [in module %s]"),
7489 die
->offset
.sect_off
, objfile
->name
);
7491 call_site
->per_cu
= cu
->per_cu
;
7493 for (child_die
= die
->child
;
7494 child_die
&& child_die
->tag
;
7495 child_die
= sibling_die (child_die
))
7497 struct dwarf2_locexpr_baton
*dlbaton
;
7498 struct call_site_parameter
*parameter
;
7500 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7502 /* Already printed the complaint above. */
7506 gdb_assert (call_site
->parameter_count
< nparams
);
7507 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7509 /* DW_AT_location specifies the register number. Value of the data
7510 assumed for the register is contained in DW_AT_GNU_call_site_value. */
7512 attr
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7513 if (!attr
|| !attr_form_is_block (attr
))
7515 complaint (&symfile_complaints
,
7516 _("No DW_FORM_block* DW_AT_location for "
7517 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7518 child_die
->offset
.sect_off
, objfile
->name
);
7521 parameter
->dwarf_reg
= dwarf_block_to_dwarf_reg (DW_BLOCK (attr
)->data
,
7522 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
]);
7523 if (parameter
->dwarf_reg
== -1
7524 && !dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (attr
)->data
,
7525 &DW_BLOCK (attr
)->data
[DW_BLOCK (attr
)->size
],
7526 ¶meter
->fb_offset
))
7528 complaint (&symfile_complaints
,
7529 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7530 "for DW_FORM_block* DW_AT_location for "
7531 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7532 child_die
->offset
.sect_off
, objfile
->name
);
7536 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7537 if (!attr_form_is_block (attr
))
7539 complaint (&symfile_complaints
,
7540 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7541 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7542 child_die
->offset
.sect_off
, objfile
->name
);
7545 parameter
->value
= DW_BLOCK (attr
)->data
;
7546 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7548 /* Parameters are not pre-cleared by memset above. */
7549 parameter
->data_value
= NULL
;
7550 parameter
->data_value_size
= 0;
7551 call_site
->parameter_count
++;
7553 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7556 if (!attr_form_is_block (attr
))
7557 complaint (&symfile_complaints
,
7558 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7559 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7560 child_die
->offset
.sect_off
, objfile
->name
);
7563 parameter
->data_value
= DW_BLOCK (attr
)->data
;
7564 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
7570 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
7571 Return 1 if the attributes are present and valid, otherwise, return 0.
7572 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
7575 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
7576 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
7577 struct partial_symtab
*ranges_pst
)
7579 struct objfile
*objfile
= cu
->objfile
;
7580 struct comp_unit_head
*cu_header
= &cu
->header
;
7581 bfd
*obfd
= objfile
->obfd
;
7582 unsigned int addr_size
= cu_header
->addr_size
;
7583 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7584 /* Base address selection entry. */
7595 found_base
= cu
->base_known
;
7596 base
= cu
->base_address
;
7598 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
7599 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7601 complaint (&symfile_complaints
,
7602 _("Offset %d out of bounds for DW_AT_ranges attribute"),
7606 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7608 /* Read in the largest possible address. */
7609 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
7610 if ((marker
& mask
) == mask
)
7612 /* If we found the largest possible address, then
7613 read the base address. */
7614 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7615 buffer
+= 2 * addr_size
;
7616 offset
+= 2 * addr_size
;
7622 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7626 CORE_ADDR range_beginning
, range_end
;
7628 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
7629 buffer
+= addr_size
;
7630 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
7631 buffer
+= addr_size
;
7632 offset
+= 2 * addr_size
;
7634 /* An end of list marker is a pair of zero addresses. */
7635 if (range_beginning
== 0 && range_end
== 0)
7636 /* Found the end of list entry. */
7639 /* Each base address selection entry is a pair of 2 values.
7640 The first is the largest possible address, the second is
7641 the base address. Check for a base address here. */
7642 if ((range_beginning
& mask
) == mask
)
7644 /* If we found the largest possible address, then
7645 read the base address. */
7646 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
7653 /* We have no valid base address for the ranges
7655 complaint (&symfile_complaints
,
7656 _("Invalid .debug_ranges data (no base address)"));
7660 if (range_beginning
> range_end
)
7662 /* Inverted range entries are invalid. */
7663 complaint (&symfile_complaints
,
7664 _("Invalid .debug_ranges data (inverted range)"));
7668 /* Empty range entries have no effect. */
7669 if (range_beginning
== range_end
)
7672 range_beginning
+= base
;
7675 if (ranges_pst
!= NULL
)
7676 addrmap_set_empty (objfile
->psymtabs_addrmap
,
7677 range_beginning
+ baseaddr
,
7678 range_end
- 1 + baseaddr
,
7681 /* FIXME: This is recording everything as a low-high
7682 segment of consecutive addresses. We should have a
7683 data structure for discontiguous block ranges
7687 low
= range_beginning
;
7693 if (range_beginning
< low
)
7694 low
= range_beginning
;
7695 if (range_end
> high
)
7701 /* If the first entry is an end-of-list marker, the range
7702 describes an empty scope, i.e. no instructions. */
7708 *high_return
= high
;
7712 /* Get low and high pc attributes from a die. Return 1 if the attributes
7713 are present and valid, otherwise, return 0. Return -1 if the range is
7714 discontinuous, i.e. derived from DW_AT_ranges information. */
7717 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
7718 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
7719 struct partial_symtab
*pst
)
7721 struct attribute
*attr
;
7722 struct attribute
*attr_high
;
7727 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7730 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7733 low
= DW_ADDR (attr
);
7734 if (attr_high
->form
== DW_FORM_addr
7735 || attr_high
->form
== DW_FORM_GNU_addr_index
)
7736 high
= DW_ADDR (attr_high
);
7738 high
= low
+ DW_UNSND (attr_high
);
7741 /* Found high w/o low attribute. */
7744 /* Found consecutive range of addresses. */
7749 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7752 /* Value of the DW_AT_ranges attribute is the offset in the
7753 .debug_ranges section. */
7754 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
7756 /* Found discontinuous range of addresses. */
7761 /* read_partial_die has also the strict LOW < HIGH requirement. */
7765 /* When using the GNU linker, .gnu.linkonce. sections are used to
7766 eliminate duplicate copies of functions and vtables and such.
7767 The linker will arbitrarily choose one and discard the others.
7768 The AT_*_pc values for such functions refer to local labels in
7769 these sections. If the section from that file was discarded, the
7770 labels are not in the output, so the relocs get a value of 0.
7771 If this is a discarded function, mark the pc bounds as invalid,
7772 so that GDB will ignore it. */
7773 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
7782 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
7783 its low and high PC addresses. Do nothing if these addresses could not
7784 be determined. Otherwise, set LOWPC to the low address if it is smaller,
7785 and HIGHPC to the high address if greater than HIGHPC. */
7788 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
7789 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7790 struct dwarf2_cu
*cu
)
7792 CORE_ADDR low
, high
;
7793 struct die_info
*child
= die
->child
;
7795 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
7797 *lowpc
= min (*lowpc
, low
);
7798 *highpc
= max (*highpc
, high
);
7801 /* If the language does not allow nested subprograms (either inside
7802 subprograms or lexical blocks), we're done. */
7803 if (cu
->language
!= language_ada
)
7806 /* Check all the children of the given DIE. If it contains nested
7807 subprograms, then check their pc bounds. Likewise, we need to
7808 check lexical blocks as well, as they may also contain subprogram
7810 while (child
&& child
->tag
)
7812 if (child
->tag
== DW_TAG_subprogram
7813 || child
->tag
== DW_TAG_lexical_block
)
7814 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
7815 child
= sibling_die (child
);
7819 /* Get the low and high pc's represented by the scope DIE, and store
7820 them in *LOWPC and *HIGHPC. If the correct values can't be
7821 determined, set *LOWPC to -1 and *HIGHPC to 0. */
7824 get_scope_pc_bounds (struct die_info
*die
,
7825 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
7826 struct dwarf2_cu
*cu
)
7828 CORE_ADDR best_low
= (CORE_ADDR
) -1;
7829 CORE_ADDR best_high
= (CORE_ADDR
) 0;
7830 CORE_ADDR current_low
, current_high
;
7832 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
7834 best_low
= current_low
;
7835 best_high
= current_high
;
7839 struct die_info
*child
= die
->child
;
7841 while (child
&& child
->tag
)
7843 switch (child
->tag
) {
7844 case DW_TAG_subprogram
:
7845 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
7847 case DW_TAG_namespace
:
7849 /* FIXME: carlton/2004-01-16: Should we do this for
7850 DW_TAG_class_type/DW_TAG_structure_type, too? I think
7851 that current GCC's always emit the DIEs corresponding
7852 to definitions of methods of classes as children of a
7853 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
7854 the DIEs giving the declarations, which could be
7855 anywhere). But I don't see any reason why the
7856 standards says that they have to be there. */
7857 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
7859 if (current_low
!= ((CORE_ADDR
) -1))
7861 best_low
= min (best_low
, current_low
);
7862 best_high
= max (best_high
, current_high
);
7870 child
= sibling_die (child
);
7875 *highpc
= best_high
;
7878 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
7882 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
7883 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
7885 struct objfile
*objfile
= cu
->objfile
;
7886 struct attribute
*attr
;
7887 struct attribute
*attr_high
;
7889 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
7892 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7895 CORE_ADDR low
= DW_ADDR (attr
);
7897 if (attr_high
->form
== DW_FORM_addr
7898 || attr_high
->form
== DW_FORM_GNU_addr_index
)
7899 high
= DW_ADDR (attr_high
);
7901 high
= low
+ DW_UNSND (attr_high
);
7903 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
7907 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
7910 bfd
*obfd
= objfile
->obfd
;
7912 /* The value of the DW_AT_ranges attribute is the offset of the
7913 address range list in the .debug_ranges section. */
7914 unsigned long offset
= DW_UNSND (attr
);
7915 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
7917 /* For some target architectures, but not others, the
7918 read_address function sign-extends the addresses it returns.
7919 To recognize base address selection entries, we need a
7921 unsigned int addr_size
= cu
->header
.addr_size
;
7922 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
7924 /* The base address, to which the next pair is relative. Note
7925 that this 'base' is a DWARF concept: most entries in a range
7926 list are relative, to reduce the number of relocs against the
7927 debugging information. This is separate from this function's
7928 'baseaddr' argument, which GDB uses to relocate debugging
7929 information from a shared library based on the address at
7930 which the library was loaded. */
7931 CORE_ADDR base
= cu
->base_address
;
7932 int base_known
= cu
->base_known
;
7934 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
7935 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
7937 complaint (&symfile_complaints
,
7938 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
7945 unsigned int bytes_read
;
7946 CORE_ADDR start
, end
;
7948 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7949 buffer
+= bytes_read
;
7950 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
7951 buffer
+= bytes_read
;
7953 /* Did we find the end of the range list? */
7954 if (start
== 0 && end
== 0)
7957 /* Did we find a base address selection entry? */
7958 else if ((start
& base_select_mask
) == base_select_mask
)
7964 /* We found an ordinary address range. */
7969 complaint (&symfile_complaints
,
7970 _("Invalid .debug_ranges data "
7971 "(no base address)"));
7977 /* Inverted range entries are invalid. */
7978 complaint (&symfile_complaints
,
7979 _("Invalid .debug_ranges data "
7980 "(inverted range)"));
7984 /* Empty range entries have no effect. */
7988 record_block_range (block
,
7989 baseaddr
+ base
+ start
,
7990 baseaddr
+ base
+ end
- 1);
7996 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
7997 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
7998 during 4.6.0 experimental. */
8001 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8004 int major
, minor
, release
;
8007 if (cu
->producer
== NULL
)
8009 /* For unknown compilers expect their behavior is DWARF version
8012 GCC started to support .debug_types sections by -gdwarf-4 since
8013 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8014 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8015 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8016 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8021 if (cu
->checked_producer
)
8022 return cu
->producer_is_gxx_lt_4_6
;
8024 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8026 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
8028 /* For non-GCC compilers expect their behavior is DWARF version
8033 cs
= &cu
->producer
[strlen ("GNU ")];
8034 while (*cs
&& !isdigit (*cs
))
8036 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8038 /* Not recognized as GCC. */
8041 result
= major
< 4 || (major
== 4 && minor
< 6);
8044 cu
->checked_producer
= 1;
8045 cu
->producer_is_gxx_lt_4_6
= result
;
8050 /* Return the default accessibility type if it is not overriden by
8051 DW_AT_accessibility. */
8053 static enum dwarf_access_attribute
8054 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8056 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8058 /* The default DWARF 2 accessibility for members is public, the default
8059 accessibility for inheritance is private. */
8061 if (die
->tag
!= DW_TAG_inheritance
)
8062 return DW_ACCESS_public
;
8064 return DW_ACCESS_private
;
8068 /* DWARF 3+ defines the default accessibility a different way. The same
8069 rules apply now for DW_TAG_inheritance as for the members and it only
8070 depends on the container kind. */
8072 if (die
->parent
->tag
== DW_TAG_class_type
)
8073 return DW_ACCESS_private
;
8075 return DW_ACCESS_public
;
8079 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8080 offset. If the attribute was not found return 0, otherwise return
8081 1. If it was found but could not properly be handled, set *OFFSET
8085 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8088 struct attribute
*attr
;
8090 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8095 /* Note that we do not check for a section offset first here.
8096 This is because DW_AT_data_member_location is new in DWARF 4,
8097 so if we see it, we can assume that a constant form is really
8098 a constant and not a section offset. */
8099 if (attr_form_is_constant (attr
))
8100 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8101 else if (attr_form_is_section_offset (attr
))
8102 dwarf2_complex_location_expr_complaint ();
8103 else if (attr_form_is_block (attr
))
8104 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8106 dwarf2_complex_location_expr_complaint ();
8114 /* Add an aggregate field to the field list. */
8117 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8118 struct dwarf2_cu
*cu
)
8120 struct objfile
*objfile
= cu
->objfile
;
8121 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8122 struct nextfield
*new_field
;
8123 struct attribute
*attr
;
8125 char *fieldname
= "";
8127 /* Allocate a new field list entry and link it in. */
8128 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8129 make_cleanup (xfree
, new_field
);
8130 memset (new_field
, 0, sizeof (struct nextfield
));
8132 if (die
->tag
== DW_TAG_inheritance
)
8134 new_field
->next
= fip
->baseclasses
;
8135 fip
->baseclasses
= new_field
;
8139 new_field
->next
= fip
->fields
;
8140 fip
->fields
= new_field
;
8144 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8146 new_field
->accessibility
= DW_UNSND (attr
);
8148 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8149 if (new_field
->accessibility
!= DW_ACCESS_public
)
8150 fip
->non_public_fields
= 1;
8152 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8154 new_field
->virtuality
= DW_UNSND (attr
);
8156 new_field
->virtuality
= DW_VIRTUALITY_none
;
8158 fp
= &new_field
->field
;
8160 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8164 /* Data member other than a C++ static data member. */
8166 /* Get type of field. */
8167 fp
->type
= die_type (die
, cu
);
8169 SET_FIELD_BITPOS (*fp
, 0);
8171 /* Get bit size of field (zero if none). */
8172 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8175 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8179 FIELD_BITSIZE (*fp
) = 0;
8182 /* Get bit offset of field. */
8183 if (handle_data_member_location (die
, cu
, &offset
))
8184 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8185 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8188 if (gdbarch_bits_big_endian (gdbarch
))
8190 /* For big endian bits, the DW_AT_bit_offset gives the
8191 additional bit offset from the MSB of the containing
8192 anonymous object to the MSB of the field. We don't
8193 have to do anything special since we don't need to
8194 know the size of the anonymous object. */
8195 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8199 /* For little endian bits, compute the bit offset to the
8200 MSB of the anonymous object, subtract off the number of
8201 bits from the MSB of the field to the MSB of the
8202 object, and then subtract off the number of bits of
8203 the field itself. The result is the bit offset of
8204 the LSB of the field. */
8206 int bit_offset
= DW_UNSND (attr
);
8208 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8211 /* The size of the anonymous object containing
8212 the bit field is explicit, so use the
8213 indicated size (in bytes). */
8214 anonymous_size
= DW_UNSND (attr
);
8218 /* The size of the anonymous object containing
8219 the bit field must be inferred from the type
8220 attribute of the data member containing the
8222 anonymous_size
= TYPE_LENGTH (fp
->type
);
8224 SET_FIELD_BITPOS (*fp
,
8226 + anonymous_size
* bits_per_byte
8227 - bit_offset
- FIELD_BITSIZE (*fp
)));
8231 /* Get name of field. */
8232 fieldname
= dwarf2_name (die
, cu
);
8233 if (fieldname
== NULL
)
8236 /* The name is already allocated along with this objfile, so we don't
8237 need to duplicate it for the type. */
8238 fp
->name
= fieldname
;
8240 /* Change accessibility for artificial fields (e.g. virtual table
8241 pointer or virtual base class pointer) to private. */
8242 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8244 FIELD_ARTIFICIAL (*fp
) = 1;
8245 new_field
->accessibility
= DW_ACCESS_private
;
8246 fip
->non_public_fields
= 1;
8249 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8251 /* C++ static member. */
8253 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8254 is a declaration, but all versions of G++ as of this writing
8255 (so through at least 3.2.1) incorrectly generate
8256 DW_TAG_variable tags. */
8258 const char *physname
;
8260 /* Get name of field. */
8261 fieldname
= dwarf2_name (die
, cu
);
8262 if (fieldname
== NULL
)
8265 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8267 /* Only create a symbol if this is an external value.
8268 new_symbol checks this and puts the value in the global symbol
8269 table, which we want. If it is not external, new_symbol
8270 will try to put the value in cu->list_in_scope which is wrong. */
8271 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8273 /* A static const member, not much different than an enum as far as
8274 we're concerned, except that we can support more types. */
8275 new_symbol (die
, NULL
, cu
);
8278 /* Get physical name. */
8279 physname
= dwarf2_physname (fieldname
, die
, cu
);
8281 /* The name is already allocated along with this objfile, so we don't
8282 need to duplicate it for the type. */
8283 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8284 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8285 FIELD_NAME (*fp
) = fieldname
;
8287 else if (die
->tag
== DW_TAG_inheritance
)
8291 /* C++ base class field. */
8292 if (handle_data_member_location (die
, cu
, &offset
))
8293 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8294 FIELD_BITSIZE (*fp
) = 0;
8295 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8296 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8297 fip
->nbaseclasses
++;
8301 /* Add a typedef defined in the scope of the FIP's class. */
8304 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8305 struct dwarf2_cu
*cu
)
8307 struct objfile
*objfile
= cu
->objfile
;
8308 struct typedef_field_list
*new_field
;
8309 struct attribute
*attr
;
8310 struct typedef_field
*fp
;
8311 char *fieldname
= "";
8313 /* Allocate a new field list entry and link it in. */
8314 new_field
= xzalloc (sizeof (*new_field
));
8315 make_cleanup (xfree
, new_field
);
8317 gdb_assert (die
->tag
== DW_TAG_typedef
);
8319 fp
= &new_field
->field
;
8321 /* Get name of field. */
8322 fp
->name
= dwarf2_name (die
, cu
);
8323 if (fp
->name
== NULL
)
8326 fp
->type
= read_type_die (die
, cu
);
8328 new_field
->next
= fip
->typedef_field_list
;
8329 fip
->typedef_field_list
= new_field
;
8330 fip
->typedef_field_list_count
++;
8333 /* Create the vector of fields, and attach it to the type. */
8336 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8337 struct dwarf2_cu
*cu
)
8339 int nfields
= fip
->nfields
;
8341 /* Record the field count, allocate space for the array of fields,
8342 and create blank accessibility bitfields if necessary. */
8343 TYPE_NFIELDS (type
) = nfields
;
8344 TYPE_FIELDS (type
) = (struct field
*)
8345 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8346 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8348 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8350 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8352 TYPE_FIELD_PRIVATE_BITS (type
) =
8353 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8354 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8356 TYPE_FIELD_PROTECTED_BITS (type
) =
8357 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8358 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8360 TYPE_FIELD_IGNORE_BITS (type
) =
8361 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8362 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8365 /* If the type has baseclasses, allocate and clear a bit vector for
8366 TYPE_FIELD_VIRTUAL_BITS. */
8367 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8369 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8370 unsigned char *pointer
;
8372 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8373 pointer
= TYPE_ALLOC (type
, num_bytes
);
8374 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8375 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8376 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8379 /* Copy the saved-up fields into the field vector. Start from the head of
8380 the list, adding to the tail of the field array, so that they end up in
8381 the same order in the array in which they were added to the list. */
8382 while (nfields
-- > 0)
8384 struct nextfield
*fieldp
;
8388 fieldp
= fip
->fields
;
8389 fip
->fields
= fieldp
->next
;
8393 fieldp
= fip
->baseclasses
;
8394 fip
->baseclasses
= fieldp
->next
;
8397 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8398 switch (fieldp
->accessibility
)
8400 case DW_ACCESS_private
:
8401 if (cu
->language
!= language_ada
)
8402 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8405 case DW_ACCESS_protected
:
8406 if (cu
->language
!= language_ada
)
8407 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8410 case DW_ACCESS_public
:
8414 /* Unknown accessibility. Complain and treat it as public. */
8416 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8417 fieldp
->accessibility
);
8421 if (nfields
< fip
->nbaseclasses
)
8423 switch (fieldp
->virtuality
)
8425 case DW_VIRTUALITY_virtual
:
8426 case DW_VIRTUALITY_pure_virtual
:
8427 if (cu
->language
== language_ada
)
8428 error (_("unexpected virtuality in component of Ada type"));
8429 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8436 /* Add a member function to the proper fieldlist. */
8439 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8440 struct type
*type
, struct dwarf2_cu
*cu
)
8442 struct objfile
*objfile
= cu
->objfile
;
8443 struct attribute
*attr
;
8444 struct fnfieldlist
*flp
;
8446 struct fn_field
*fnp
;
8448 struct nextfnfield
*new_fnfield
;
8449 struct type
*this_type
;
8450 enum dwarf_access_attribute accessibility
;
8452 if (cu
->language
== language_ada
)
8453 error (_("unexpected member function in Ada type"));
8455 /* Get name of member function. */
8456 fieldname
= dwarf2_name (die
, cu
);
8457 if (fieldname
== NULL
)
8460 /* Look up member function name in fieldlist. */
8461 for (i
= 0; i
< fip
->nfnfields
; i
++)
8463 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8467 /* Create new list element if necessary. */
8468 if (i
< fip
->nfnfields
)
8469 flp
= &fip
->fnfieldlists
[i
];
8472 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8474 fip
->fnfieldlists
= (struct fnfieldlist
*)
8475 xrealloc (fip
->fnfieldlists
,
8476 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8477 * sizeof (struct fnfieldlist
));
8478 if (fip
->nfnfields
== 0)
8479 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8481 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8482 flp
->name
= fieldname
;
8485 i
= fip
->nfnfields
++;
8488 /* Create a new member function field and chain it to the field list
8490 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8491 make_cleanup (xfree
, new_fnfield
);
8492 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8493 new_fnfield
->next
= flp
->head
;
8494 flp
->head
= new_fnfield
;
8497 /* Fill in the member function field info. */
8498 fnp
= &new_fnfield
->fnfield
;
8500 /* Delay processing of the physname until later. */
8501 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8503 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8508 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8509 fnp
->physname
= physname
? physname
: "";
8512 fnp
->type
= alloc_type (objfile
);
8513 this_type
= read_type_die (die
, cu
);
8514 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8516 int nparams
= TYPE_NFIELDS (this_type
);
8518 /* TYPE is the domain of this method, and THIS_TYPE is the type
8519 of the method itself (TYPE_CODE_METHOD). */
8520 smash_to_method_type (fnp
->type
, type
,
8521 TYPE_TARGET_TYPE (this_type
),
8522 TYPE_FIELDS (this_type
),
8523 TYPE_NFIELDS (this_type
),
8524 TYPE_VARARGS (this_type
));
8526 /* Handle static member functions.
8527 Dwarf2 has no clean way to discern C++ static and non-static
8528 member functions. G++ helps GDB by marking the first
8529 parameter for non-static member functions (which is the this
8530 pointer) as artificial. We obtain this information from
8531 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8532 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8533 fnp
->voffset
= VOFFSET_STATIC
;
8536 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8537 dwarf2_full_name (fieldname
, die
, cu
));
8539 /* Get fcontext from DW_AT_containing_type if present. */
8540 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8541 fnp
->fcontext
= die_containing_type (die
, cu
);
8543 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8544 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8546 /* Get accessibility. */
8547 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8549 accessibility
= DW_UNSND (attr
);
8551 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8552 switch (accessibility
)
8554 case DW_ACCESS_private
:
8555 fnp
->is_private
= 1;
8557 case DW_ACCESS_protected
:
8558 fnp
->is_protected
= 1;
8562 /* Check for artificial methods. */
8563 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
8564 if (attr
&& DW_UNSND (attr
) != 0)
8565 fnp
->is_artificial
= 1;
8567 /* Get index in virtual function table if it is a virtual member
8568 function. For older versions of GCC, this is an offset in the
8569 appropriate virtual table, as specified by DW_AT_containing_type.
8570 For everyone else, it is an expression to be evaluated relative
8571 to the object address. */
8573 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
8576 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
8578 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
8580 /* Old-style GCC. */
8581 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
8583 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8584 || (DW_BLOCK (attr
)->size
> 1
8585 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
8586 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
8588 struct dwarf_block blk
;
8591 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
8593 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
8594 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
8595 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8596 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
8597 dwarf2_complex_location_expr_complaint ();
8599 fnp
->voffset
/= cu
->header
.addr_size
;
8603 dwarf2_complex_location_expr_complaint ();
8606 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
8608 else if (attr_form_is_section_offset (attr
))
8610 dwarf2_complex_location_expr_complaint ();
8614 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
8620 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8621 if (attr
&& DW_UNSND (attr
))
8623 /* GCC does this, as of 2008-08-25; PR debug/37237. */
8624 complaint (&symfile_complaints
,
8625 _("Member function \"%s\" (offset %d) is virtual "
8626 "but the vtable offset is not specified"),
8627 fieldname
, die
->offset
.sect_off
);
8628 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8629 TYPE_CPLUS_DYNAMIC (type
) = 1;
8634 /* Create the vector of member function fields, and attach it to the type. */
8637 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
8638 struct dwarf2_cu
*cu
)
8640 struct fnfieldlist
*flp
;
8643 if (cu
->language
== language_ada
)
8644 error (_("unexpected member functions in Ada type"));
8646 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8647 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
8648 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
8650 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
8652 struct nextfnfield
*nfp
= flp
->head
;
8653 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
8656 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
8657 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
8658 fn_flp
->fn_fields
= (struct fn_field
*)
8659 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
8660 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
8661 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
8664 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
8667 /* Returns non-zero if NAME is the name of a vtable member in CU's
8668 language, zero otherwise. */
8670 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
8672 static const char vptr
[] = "_vptr";
8673 static const char vtable
[] = "vtable";
8675 /* Look for the C++ and Java forms of the vtable. */
8676 if ((cu
->language
== language_java
8677 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
8678 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
8679 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
8685 /* GCC outputs unnamed structures that are really pointers to member
8686 functions, with the ABI-specified layout. If TYPE describes
8687 such a structure, smash it into a member function type.
8689 GCC shouldn't do this; it should just output pointer to member DIEs.
8690 This is GCC PR debug/28767. */
8693 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
8695 struct type
*pfn_type
, *domain_type
, *new_type
;
8697 /* Check for a structure with no name and two children. */
8698 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
8701 /* Check for __pfn and __delta members. */
8702 if (TYPE_FIELD_NAME (type
, 0) == NULL
8703 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
8704 || TYPE_FIELD_NAME (type
, 1) == NULL
8705 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
8708 /* Find the type of the method. */
8709 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
8710 if (pfn_type
== NULL
8711 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
8712 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
8715 /* Look for the "this" argument. */
8716 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
8717 if (TYPE_NFIELDS (pfn_type
) == 0
8718 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
8719 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
8722 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
8723 new_type
= alloc_type (objfile
);
8724 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
8725 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
8726 TYPE_VARARGS (pfn_type
));
8727 smash_to_methodptr_type (type
, new_type
);
8730 /* Called when we find the DIE that starts a structure or union scope
8731 (definition) to create a type for the structure or union. Fill in
8732 the type's name and general properties; the members will not be
8733 processed until process_structure_type.
8735 NOTE: we need to call these functions regardless of whether or not the
8736 DIE has a DW_AT_name attribute, since it might be an anonymous
8737 structure or union. This gets the type entered into our set of
8740 However, if the structure is incomplete (an opaque struct/union)
8741 then suppress creating a symbol table entry for it since gdb only
8742 wants to find the one with the complete definition. Note that if
8743 it is complete, we just call new_symbol, which does it's own
8744 checking about whether the struct/union is anonymous or not (and
8745 suppresses creating a symbol table entry itself). */
8747 static struct type
*
8748 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8750 struct objfile
*objfile
= cu
->objfile
;
8752 struct attribute
*attr
;
8755 /* If the definition of this type lives in .debug_types, read that type.
8756 Don't follow DW_AT_specification though, that will take us back up
8757 the chain and we want to go down. */
8758 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
8761 struct dwarf2_cu
*type_cu
= cu
;
8762 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
8764 /* We could just recurse on read_structure_type, but we need to call
8765 get_die_type to ensure only one type for this DIE is created.
8766 This is important, for example, because for c++ classes we need
8767 TYPE_NAME set which is only done by new_symbol. Blech. */
8768 type
= read_type_die (type_die
, type_cu
);
8770 /* TYPE_CU may not be the same as CU.
8771 Ensure TYPE is recorded in CU's type_hash table. */
8772 return set_die_type (die
, type
, cu
);
8775 type
= alloc_type (objfile
);
8776 INIT_CPLUS_SPECIFIC (type
);
8778 name
= dwarf2_name (die
, cu
);
8781 if (cu
->language
== language_cplus
8782 || cu
->language
== language_java
)
8784 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
8786 /* dwarf2_full_name might have already finished building the DIE's
8787 type. If so, there is no need to continue. */
8788 if (get_die_type (die
, cu
) != NULL
)
8789 return get_die_type (die
, cu
);
8791 TYPE_TAG_NAME (type
) = full_name
;
8792 if (die
->tag
== DW_TAG_structure_type
8793 || die
->tag
== DW_TAG_class_type
)
8794 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
8798 /* The name is already allocated along with this objfile, so
8799 we don't need to duplicate it for the type. */
8800 TYPE_TAG_NAME (type
) = (char *) name
;
8801 if (die
->tag
== DW_TAG_class_type
)
8802 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
8806 if (die
->tag
== DW_TAG_structure_type
)
8808 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
8810 else if (die
->tag
== DW_TAG_union_type
)
8812 TYPE_CODE (type
) = TYPE_CODE_UNION
;
8816 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
8819 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
8820 TYPE_DECLARED_CLASS (type
) = 1;
8822 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8825 TYPE_LENGTH (type
) = DW_UNSND (attr
);
8829 TYPE_LENGTH (type
) = 0;
8832 TYPE_STUB_SUPPORTED (type
) = 1;
8833 if (die_is_declaration (die
, cu
))
8834 TYPE_STUB (type
) = 1;
8835 else if (attr
== NULL
&& die
->child
== NULL
8836 && producer_is_realview (cu
->producer
))
8837 /* RealView does not output the required DW_AT_declaration
8838 on incomplete types. */
8839 TYPE_STUB (type
) = 1;
8841 /* We need to add the type field to the die immediately so we don't
8842 infinitely recurse when dealing with pointers to the structure
8843 type within the structure itself. */
8844 set_die_type (die
, type
, cu
);
8846 /* set_die_type should be already done. */
8847 set_descriptive_type (type
, die
, cu
);
8852 /* Finish creating a structure or union type, including filling in
8853 its members and creating a symbol for it. */
8856 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8858 struct objfile
*objfile
= cu
->objfile
;
8859 struct die_info
*child_die
= die
->child
;
8862 type
= get_die_type (die
, cu
);
8864 type
= read_structure_type (die
, cu
);
8866 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
8868 struct field_info fi
;
8869 struct die_info
*child_die
;
8870 VEC (symbolp
) *template_args
= NULL
;
8871 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
8873 memset (&fi
, 0, sizeof (struct field_info
));
8875 child_die
= die
->child
;
8877 while (child_die
&& child_die
->tag
)
8879 if (child_die
->tag
== DW_TAG_member
8880 || child_die
->tag
== DW_TAG_variable
)
8882 /* NOTE: carlton/2002-11-05: A C++ static data member
8883 should be a DW_TAG_member that is a declaration, but
8884 all versions of G++ as of this writing (so through at
8885 least 3.2.1) incorrectly generate DW_TAG_variable
8886 tags for them instead. */
8887 dwarf2_add_field (&fi
, child_die
, cu
);
8889 else if (child_die
->tag
== DW_TAG_subprogram
)
8891 /* C++ member function. */
8892 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
8894 else if (child_die
->tag
== DW_TAG_inheritance
)
8896 /* C++ base class field. */
8897 dwarf2_add_field (&fi
, child_die
, cu
);
8899 else if (child_die
->tag
== DW_TAG_typedef
)
8900 dwarf2_add_typedef (&fi
, child_die
, cu
);
8901 else if (child_die
->tag
== DW_TAG_template_type_param
8902 || child_die
->tag
== DW_TAG_template_value_param
)
8904 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8907 VEC_safe_push (symbolp
, template_args
, arg
);
8910 child_die
= sibling_die (child_die
);
8913 /* Attach template arguments to type. */
8914 if (! VEC_empty (symbolp
, template_args
))
8916 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8917 TYPE_N_TEMPLATE_ARGUMENTS (type
)
8918 = VEC_length (symbolp
, template_args
);
8919 TYPE_TEMPLATE_ARGUMENTS (type
)
8920 = obstack_alloc (&objfile
->objfile_obstack
,
8921 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8922 * sizeof (struct symbol
*)));
8923 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
8924 VEC_address (symbolp
, template_args
),
8925 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
8926 * sizeof (struct symbol
*)));
8927 VEC_free (symbolp
, template_args
);
8930 /* Attach fields and member functions to the type. */
8932 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
8935 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
8937 /* Get the type which refers to the base class (possibly this
8938 class itself) which contains the vtable pointer for the current
8939 class from the DW_AT_containing_type attribute. This use of
8940 DW_AT_containing_type is a GNU extension. */
8942 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8944 struct type
*t
= die_containing_type (die
, cu
);
8946 TYPE_VPTR_BASETYPE (type
) = t
;
8951 /* Our own class provides vtbl ptr. */
8952 for (i
= TYPE_NFIELDS (t
) - 1;
8953 i
>= TYPE_N_BASECLASSES (t
);
8956 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
8958 if (is_vtable_name (fieldname
, cu
))
8960 TYPE_VPTR_FIELDNO (type
) = i
;
8965 /* Complain if virtual function table field not found. */
8966 if (i
< TYPE_N_BASECLASSES (t
))
8967 complaint (&symfile_complaints
,
8968 _("virtual function table pointer "
8969 "not found when defining class '%s'"),
8970 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
8975 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
8978 else if (cu
->producer
8979 && strncmp (cu
->producer
,
8980 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
8982 /* The IBM XLC compiler does not provide direct indication
8983 of the containing type, but the vtable pointer is
8984 always named __vfp. */
8988 for (i
= TYPE_NFIELDS (type
) - 1;
8989 i
>= TYPE_N_BASECLASSES (type
);
8992 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
8994 TYPE_VPTR_FIELDNO (type
) = i
;
8995 TYPE_VPTR_BASETYPE (type
) = type
;
9002 /* Copy fi.typedef_field_list linked list elements content into the
9003 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9004 if (fi
.typedef_field_list
)
9006 int i
= fi
.typedef_field_list_count
;
9008 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9009 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9010 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9011 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9013 /* Reverse the list order to keep the debug info elements order. */
9016 struct typedef_field
*dest
, *src
;
9018 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9019 src
= &fi
.typedef_field_list
->field
;
9020 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9025 do_cleanups (back_to
);
9027 if (HAVE_CPLUS_STRUCT (type
))
9028 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9031 quirk_gcc_member_function_pointer (type
, objfile
);
9033 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9034 snapshots) has been known to create a die giving a declaration
9035 for a class that has, as a child, a die giving a definition for a
9036 nested class. So we have to process our children even if the
9037 current die is a declaration. Normally, of course, a declaration
9038 won't have any children at all. */
9040 while (child_die
!= NULL
&& child_die
->tag
)
9042 if (child_die
->tag
== DW_TAG_member
9043 || child_die
->tag
== DW_TAG_variable
9044 || child_die
->tag
== DW_TAG_inheritance
9045 || child_die
->tag
== DW_TAG_template_value_param
9046 || child_die
->tag
== DW_TAG_template_type_param
)
9051 process_die (child_die
, cu
);
9053 child_die
= sibling_die (child_die
);
9056 /* Do not consider external references. According to the DWARF standard,
9057 these DIEs are identified by the fact that they have no byte_size
9058 attribute, and a declaration attribute. */
9059 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9060 || !die_is_declaration (die
, cu
))
9061 new_symbol (die
, type
, cu
);
9064 /* Given a DW_AT_enumeration_type die, set its type. We do not
9065 complete the type's fields yet, or create any symbols. */
9067 static struct type
*
9068 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9070 struct objfile
*objfile
= cu
->objfile
;
9072 struct attribute
*attr
;
9075 /* If the definition of this type lives in .debug_types, read that type.
9076 Don't follow DW_AT_specification though, that will take us back up
9077 the chain and we want to go down. */
9078 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9081 struct dwarf2_cu
*type_cu
= cu
;
9082 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9084 type
= read_type_die (type_die
, type_cu
);
9086 /* TYPE_CU may not be the same as CU.
9087 Ensure TYPE is recorded in CU's type_hash table. */
9088 return set_die_type (die
, type
, cu
);
9091 type
= alloc_type (objfile
);
9093 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9094 name
= dwarf2_full_name (NULL
, die
, cu
);
9096 TYPE_TAG_NAME (type
) = (char *) name
;
9098 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9101 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9105 TYPE_LENGTH (type
) = 0;
9108 /* The enumeration DIE can be incomplete. In Ada, any type can be
9109 declared as private in the package spec, and then defined only
9110 inside the package body. Such types are known as Taft Amendment
9111 Types. When another package uses such a type, an incomplete DIE
9112 may be generated by the compiler. */
9113 if (die_is_declaration (die
, cu
))
9114 TYPE_STUB (type
) = 1;
9116 return set_die_type (die
, type
, cu
);
9119 /* Given a pointer to a die which begins an enumeration, process all
9120 the dies that define the members of the enumeration, and create the
9121 symbol for the enumeration type.
9123 NOTE: We reverse the order of the element list. */
9126 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9128 struct type
*this_type
;
9130 this_type
= get_die_type (die
, cu
);
9131 if (this_type
== NULL
)
9132 this_type
= read_enumeration_type (die
, cu
);
9134 if (die
->child
!= NULL
)
9136 struct die_info
*child_die
;
9138 struct field
*fields
= NULL
;
9140 int unsigned_enum
= 1;
9145 child_die
= die
->child
;
9146 while (child_die
&& child_die
->tag
)
9148 if (child_die
->tag
!= DW_TAG_enumerator
)
9150 process_die (child_die
, cu
);
9154 name
= dwarf2_name (child_die
, cu
);
9157 sym
= new_symbol (child_die
, this_type
, cu
);
9158 if (SYMBOL_VALUE (sym
) < 0)
9163 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9166 mask
|= SYMBOL_VALUE (sym
);
9168 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9170 fields
= (struct field
*)
9172 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9173 * sizeof (struct field
));
9176 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9177 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9178 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9179 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9185 child_die
= sibling_die (child_die
);
9190 TYPE_NFIELDS (this_type
) = num_fields
;
9191 TYPE_FIELDS (this_type
) = (struct field
*)
9192 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9193 memcpy (TYPE_FIELDS (this_type
), fields
,
9194 sizeof (struct field
) * num_fields
);
9198 TYPE_UNSIGNED (this_type
) = 1;
9200 TYPE_FLAG_ENUM (this_type
) = 1;
9203 /* If we are reading an enum from a .debug_types unit, and the enum
9204 is a declaration, and the enum is not the signatured type in the
9205 unit, then we do not want to add a symbol for it. Adding a
9206 symbol would in some cases obscure the true definition of the
9207 enum, giving users an incomplete type when the definition is
9208 actually available. Note that we do not want to do this for all
9209 enums which are just declarations, because C++0x allows forward
9210 enum declarations. */
9211 if (cu
->per_cu
->is_debug_types
9212 && die_is_declaration (die
, cu
))
9214 struct signatured_type
*sig_type
;
9217 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9218 cu
->per_cu
->info_or_types_section
,
9219 cu
->per_cu
->offset
);
9220 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9221 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9225 new_symbol (die
, this_type
, cu
);
9228 /* Extract all information from a DW_TAG_array_type DIE and put it in
9229 the DIE's type field. For now, this only handles one dimensional
9232 static struct type
*
9233 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9235 struct objfile
*objfile
= cu
->objfile
;
9236 struct die_info
*child_die
;
9238 struct type
*element_type
, *range_type
, *index_type
;
9239 struct type
**range_types
= NULL
;
9240 struct attribute
*attr
;
9242 struct cleanup
*back_to
;
9245 element_type
= die_type (die
, cu
);
9247 /* The die_type call above may have already set the type for this DIE. */
9248 type
= get_die_type (die
, cu
);
9252 /* Irix 6.2 native cc creates array types without children for
9253 arrays with unspecified length. */
9254 if (die
->child
== NULL
)
9256 index_type
= objfile_type (objfile
)->builtin_int
;
9257 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9258 type
= create_array_type (NULL
, element_type
, range_type
);
9259 return set_die_type (die
, type
, cu
);
9262 back_to
= make_cleanup (null_cleanup
, NULL
);
9263 child_die
= die
->child
;
9264 while (child_die
&& child_die
->tag
)
9266 if (child_die
->tag
== DW_TAG_subrange_type
)
9268 struct type
*child_type
= read_type_die (child_die
, cu
);
9270 if (child_type
!= NULL
)
9272 /* The range type was succesfully read. Save it for the
9273 array type creation. */
9274 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9276 range_types
= (struct type
**)
9277 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9278 * sizeof (struct type
*));
9280 make_cleanup (free_current_contents
, &range_types
);
9282 range_types
[ndim
++] = child_type
;
9285 child_die
= sibling_die (child_die
);
9288 /* Dwarf2 dimensions are output from left to right, create the
9289 necessary array types in backwards order. */
9291 type
= element_type
;
9293 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9298 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9303 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9306 /* Understand Dwarf2 support for vector types (like they occur on
9307 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9308 array type. This is not part of the Dwarf2/3 standard yet, but a
9309 custom vendor extension. The main difference between a regular
9310 array and the vector variant is that vectors are passed by value
9312 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9314 make_vector_type (type
);
9316 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9317 implementation may choose to implement triple vectors using this
9319 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9322 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9323 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9325 complaint (&symfile_complaints
,
9326 _("DW_AT_byte_size for array type smaller "
9327 "than the total size of elements"));
9330 name
= dwarf2_name (die
, cu
);
9332 TYPE_NAME (type
) = name
;
9334 /* Install the type in the die. */
9335 set_die_type (die
, type
, cu
);
9337 /* set_die_type should be already done. */
9338 set_descriptive_type (type
, die
, cu
);
9340 do_cleanups (back_to
);
9345 static enum dwarf_array_dim_ordering
9346 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9348 struct attribute
*attr
;
9350 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9352 if (attr
) return DW_SND (attr
);
9354 /* GNU F77 is a special case, as at 08/2004 array type info is the
9355 opposite order to the dwarf2 specification, but data is still
9356 laid out as per normal fortran.
9358 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9359 version checking. */
9361 if (cu
->language
== language_fortran
9362 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9364 return DW_ORD_row_major
;
9367 switch (cu
->language_defn
->la_array_ordering
)
9369 case array_column_major
:
9370 return DW_ORD_col_major
;
9371 case array_row_major
:
9373 return DW_ORD_row_major
;
9377 /* Extract all information from a DW_TAG_set_type DIE and put it in
9378 the DIE's type field. */
9380 static struct type
*
9381 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9383 struct type
*domain_type
, *set_type
;
9384 struct attribute
*attr
;
9386 domain_type
= die_type (die
, cu
);
9388 /* The die_type call above may have already set the type for this DIE. */
9389 set_type
= get_die_type (die
, cu
);
9393 set_type
= create_set_type (NULL
, domain_type
);
9395 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9397 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9399 return set_die_type (die
, set_type
, cu
);
9402 /* First cut: install each common block member as a global variable. */
9405 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9407 struct die_info
*child_die
;
9408 struct attribute
*attr
;
9410 CORE_ADDR base
= (CORE_ADDR
) 0;
9412 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9415 /* Support the .debug_loc offsets. */
9416 if (attr_form_is_block (attr
))
9418 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9420 else if (attr_form_is_section_offset (attr
))
9422 dwarf2_complex_location_expr_complaint ();
9426 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9427 "common block member");
9430 if (die
->child
!= NULL
)
9432 child_die
= die
->child
;
9433 while (child_die
&& child_die
->tag
)
9437 sym
= new_symbol (child_die
, NULL
, cu
);
9439 && handle_data_member_location (child_die
, cu
, &offset
))
9441 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9442 add_symbol_to_list (sym
, &global_symbols
);
9444 child_die
= sibling_die (child_die
);
9449 /* Create a type for a C++ namespace. */
9451 static struct type
*
9452 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9454 struct objfile
*objfile
= cu
->objfile
;
9455 const char *previous_prefix
, *name
;
9459 /* For extensions, reuse the type of the original namespace. */
9460 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9462 struct die_info
*ext_die
;
9463 struct dwarf2_cu
*ext_cu
= cu
;
9465 ext_die
= dwarf2_extension (die
, &ext_cu
);
9466 type
= read_type_die (ext_die
, ext_cu
);
9468 /* EXT_CU may not be the same as CU.
9469 Ensure TYPE is recorded in CU's type_hash table. */
9470 return set_die_type (die
, type
, cu
);
9473 name
= namespace_name (die
, &is_anonymous
, cu
);
9475 /* Now build the name of the current namespace. */
9477 previous_prefix
= determine_prefix (die
, cu
);
9478 if (previous_prefix
[0] != '\0')
9479 name
= typename_concat (&objfile
->objfile_obstack
,
9480 previous_prefix
, name
, 0, cu
);
9482 /* Create the type. */
9483 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9485 TYPE_NAME (type
) = (char *) name
;
9486 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9488 return set_die_type (die
, type
, cu
);
9491 /* Read a C++ namespace. */
9494 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9496 struct objfile
*objfile
= cu
->objfile
;
9499 /* Add a symbol associated to this if we haven't seen the namespace
9500 before. Also, add a using directive if it's an anonymous
9503 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9507 type
= read_type_die (die
, cu
);
9508 new_symbol (die
, type
, cu
);
9510 namespace_name (die
, &is_anonymous
, cu
);
9513 const char *previous_prefix
= determine_prefix (die
, cu
);
9515 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9516 NULL
, NULL
, &objfile
->objfile_obstack
);
9520 if (die
->child
!= NULL
)
9522 struct die_info
*child_die
= die
->child
;
9524 while (child_die
&& child_die
->tag
)
9526 process_die (child_die
, cu
);
9527 child_die
= sibling_die (child_die
);
9532 /* Read a Fortran module as type. This DIE can be only a declaration used for
9533 imported module. Still we need that type as local Fortran "use ... only"
9534 declaration imports depend on the created type in determine_prefix. */
9536 static struct type
*
9537 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9539 struct objfile
*objfile
= cu
->objfile
;
9543 module_name
= dwarf2_name (die
, cu
);
9545 complaint (&symfile_complaints
,
9546 _("DW_TAG_module has no name, offset 0x%x"),
9547 die
->offset
.sect_off
);
9548 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
9550 /* determine_prefix uses TYPE_TAG_NAME. */
9551 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9553 return set_die_type (die
, type
, cu
);
9556 /* Read a Fortran module. */
9559 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
9561 struct die_info
*child_die
= die
->child
;
9563 while (child_die
&& child_die
->tag
)
9565 process_die (child_die
, cu
);
9566 child_die
= sibling_die (child_die
);
9570 /* Return the name of the namespace represented by DIE. Set
9571 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
9575 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
9577 struct die_info
*current_die
;
9578 const char *name
= NULL
;
9580 /* Loop through the extensions until we find a name. */
9582 for (current_die
= die
;
9583 current_die
!= NULL
;
9584 current_die
= dwarf2_extension (die
, &cu
))
9586 name
= dwarf2_name (current_die
, cu
);
9591 /* Is it an anonymous namespace? */
9593 *is_anonymous
= (name
== NULL
);
9595 name
= CP_ANONYMOUS_NAMESPACE_STR
;
9600 /* Extract all information from a DW_TAG_pointer_type DIE and add to
9601 the user defined type vector. */
9603 static struct type
*
9604 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9606 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9607 struct comp_unit_head
*cu_header
= &cu
->header
;
9609 struct attribute
*attr_byte_size
;
9610 struct attribute
*attr_address_class
;
9611 int byte_size
, addr_class
;
9612 struct type
*target_type
;
9614 target_type
= die_type (die
, cu
);
9616 /* The die_type call above may have already set the type for this DIE. */
9617 type
= get_die_type (die
, cu
);
9621 type
= lookup_pointer_type (target_type
);
9623 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9625 byte_size
= DW_UNSND (attr_byte_size
);
9627 byte_size
= cu_header
->addr_size
;
9629 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
9630 if (attr_address_class
)
9631 addr_class
= DW_UNSND (attr_address_class
);
9633 addr_class
= DW_ADDR_none
;
9635 /* If the pointer size or address class is different than the
9636 default, create a type variant marked as such and set the
9637 length accordingly. */
9638 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
9640 if (gdbarch_address_class_type_flags_p (gdbarch
))
9644 type_flags
= gdbarch_address_class_type_flags
9645 (gdbarch
, byte_size
, addr_class
);
9646 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
9648 type
= make_type_with_address_space (type
, type_flags
);
9650 else if (TYPE_LENGTH (type
) != byte_size
)
9652 complaint (&symfile_complaints
,
9653 _("invalid pointer size %d"), byte_size
);
9657 /* Should we also complain about unhandled address classes? */
9661 TYPE_LENGTH (type
) = byte_size
;
9662 return set_die_type (die
, type
, cu
);
9665 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
9666 the user defined type vector. */
9668 static struct type
*
9669 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9672 struct type
*to_type
;
9673 struct type
*domain
;
9675 to_type
= die_type (die
, cu
);
9676 domain
= die_containing_type (die
, cu
);
9678 /* The calls above may have already set the type for this DIE. */
9679 type
= get_die_type (die
, cu
);
9683 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
9684 type
= lookup_methodptr_type (to_type
);
9686 type
= lookup_memberptr_type (to_type
, domain
);
9688 return set_die_type (die
, type
, cu
);
9691 /* Extract all information from a DW_TAG_reference_type DIE and add to
9692 the user defined type vector. */
9694 static struct type
*
9695 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9697 struct comp_unit_head
*cu_header
= &cu
->header
;
9698 struct type
*type
, *target_type
;
9699 struct attribute
*attr
;
9701 target_type
= die_type (die
, cu
);
9703 /* The die_type call above may have already set the type for this DIE. */
9704 type
= get_die_type (die
, cu
);
9708 type
= lookup_reference_type (target_type
);
9709 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9712 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9716 TYPE_LENGTH (type
) = cu_header
->addr_size
;
9718 return set_die_type (die
, type
, cu
);
9721 static struct type
*
9722 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9724 struct type
*base_type
, *cv_type
;
9726 base_type
= die_type (die
, cu
);
9728 /* The die_type call above may have already set the type for this DIE. */
9729 cv_type
= get_die_type (die
, cu
);
9733 /* In case the const qualifier is applied to an array type, the element type
9734 is so qualified, not the array type (section 6.7.3 of C99). */
9735 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
9737 struct type
*el_type
, *inner_array
;
9739 base_type
= copy_type (base_type
);
9740 inner_array
= base_type
;
9742 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
9744 TYPE_TARGET_TYPE (inner_array
) =
9745 copy_type (TYPE_TARGET_TYPE (inner_array
));
9746 inner_array
= TYPE_TARGET_TYPE (inner_array
);
9749 el_type
= TYPE_TARGET_TYPE (inner_array
);
9750 TYPE_TARGET_TYPE (inner_array
) =
9751 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
9753 return set_die_type (die
, base_type
, cu
);
9756 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
9757 return set_die_type (die
, cv_type
, cu
);
9760 static struct type
*
9761 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9763 struct type
*base_type
, *cv_type
;
9765 base_type
= die_type (die
, cu
);
9767 /* The die_type call above may have already set the type for this DIE. */
9768 cv_type
= get_die_type (die
, cu
);
9772 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
9773 return set_die_type (die
, cv_type
, cu
);
9776 /* Extract all information from a DW_TAG_string_type DIE and add to
9777 the user defined type vector. It isn't really a user defined type,
9778 but it behaves like one, with other DIE's using an AT_user_def_type
9779 attribute to reference it. */
9781 static struct type
*
9782 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9784 struct objfile
*objfile
= cu
->objfile
;
9785 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9786 struct type
*type
, *range_type
, *index_type
, *char_type
;
9787 struct attribute
*attr
;
9788 unsigned int length
;
9790 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
9793 length
= DW_UNSND (attr
);
9797 /* Check for the DW_AT_byte_size attribute. */
9798 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9801 length
= DW_UNSND (attr
);
9809 index_type
= objfile_type (objfile
)->builtin_int
;
9810 range_type
= create_range_type (NULL
, index_type
, 1, length
);
9811 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
9812 type
= create_string_type (NULL
, char_type
, range_type
);
9814 return set_die_type (die
, type
, cu
);
9817 /* Handle DIES due to C code like:
9821 int (*funcp)(int a, long l);
9825 ('funcp' generates a DW_TAG_subroutine_type DIE). */
9827 static struct type
*
9828 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9830 struct objfile
*objfile
= cu
->objfile
;
9831 struct type
*type
; /* Type that this function returns. */
9832 struct type
*ftype
; /* Function that returns above type. */
9833 struct attribute
*attr
;
9835 type
= die_type (die
, cu
);
9837 /* The die_type call above may have already set the type for this DIE. */
9838 ftype
= get_die_type (die
, cu
);
9842 ftype
= lookup_function_type (type
);
9844 /* All functions in C++, Pascal and Java have prototypes. */
9845 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
9846 if ((attr
&& (DW_UNSND (attr
) != 0))
9847 || cu
->language
== language_cplus
9848 || cu
->language
== language_java
9849 || cu
->language
== language_pascal
)
9850 TYPE_PROTOTYPED (ftype
) = 1;
9851 else if (producer_is_realview (cu
->producer
))
9852 /* RealView does not emit DW_AT_prototyped. We can not
9853 distinguish prototyped and unprototyped functions; default to
9854 prototyped, since that is more common in modern code (and
9855 RealView warns about unprototyped functions). */
9856 TYPE_PROTOTYPED (ftype
) = 1;
9858 /* Store the calling convention in the type if it's available in
9859 the subroutine die. Otherwise set the calling convention to
9860 the default value DW_CC_normal. */
9861 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
9863 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
9864 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
9865 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
9867 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
9869 /* We need to add the subroutine type to the die immediately so
9870 we don't infinitely recurse when dealing with parameters
9871 declared as the same subroutine type. */
9872 set_die_type (die
, ftype
, cu
);
9874 if (die
->child
!= NULL
)
9876 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
9877 struct die_info
*child_die
;
9878 int nparams
, iparams
;
9880 /* Count the number of parameters.
9881 FIXME: GDB currently ignores vararg functions, but knows about
9882 vararg member functions. */
9884 child_die
= die
->child
;
9885 while (child_die
&& child_die
->tag
)
9887 if (child_die
->tag
== DW_TAG_formal_parameter
)
9889 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
9890 TYPE_VARARGS (ftype
) = 1;
9891 child_die
= sibling_die (child_die
);
9894 /* Allocate storage for parameters and fill them in. */
9895 TYPE_NFIELDS (ftype
) = nparams
;
9896 TYPE_FIELDS (ftype
) = (struct field
*)
9897 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
9899 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
9900 even if we error out during the parameters reading below. */
9901 for (iparams
= 0; iparams
< nparams
; iparams
++)
9902 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
9905 child_die
= die
->child
;
9906 while (child_die
&& child_die
->tag
)
9908 if (child_die
->tag
== DW_TAG_formal_parameter
)
9910 struct type
*arg_type
;
9912 /* DWARF version 2 has no clean way to discern C++
9913 static and non-static member functions. G++ helps
9914 GDB by marking the first parameter for non-static
9915 member functions (which is the this pointer) as
9916 artificial. We pass this information to
9917 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
9919 DWARF version 3 added DW_AT_object_pointer, which GCC
9920 4.5 does not yet generate. */
9921 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
9923 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
9926 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
9928 /* GCC/43521: In java, the formal parameter
9929 "this" is sometimes not marked with DW_AT_artificial. */
9930 if (cu
->language
== language_java
)
9932 const char *name
= dwarf2_name (child_die
, cu
);
9934 if (name
&& !strcmp (name
, "this"))
9935 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
9938 arg_type
= die_type (child_die
, cu
);
9940 /* RealView does not mark THIS as const, which the testsuite
9941 expects. GCC marks THIS as const in method definitions,
9942 but not in the class specifications (GCC PR 43053). */
9943 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
9944 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
9947 struct dwarf2_cu
*arg_cu
= cu
;
9948 const char *name
= dwarf2_name (child_die
, cu
);
9950 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
9953 /* If the compiler emits this, use it. */
9954 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
9957 else if (name
&& strcmp (name
, "this") == 0)
9958 /* Function definitions will have the argument names. */
9960 else if (name
== NULL
&& iparams
== 0)
9961 /* Declarations may not have the names, so like
9962 elsewhere in GDB, assume an artificial first
9963 argument is "this". */
9967 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
9971 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
9974 child_die
= sibling_die (child_die
);
9981 static struct type
*
9982 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
9984 struct objfile
*objfile
= cu
->objfile
;
9985 const char *name
= NULL
;
9986 struct type
*this_type
, *target_type
;
9988 name
= dwarf2_full_name (NULL
, die
, cu
);
9989 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
9990 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
9991 TYPE_NAME (this_type
) = (char *) name
;
9992 set_die_type (die
, this_type
, cu
);
9993 target_type
= die_type (die
, cu
);
9994 if (target_type
!= this_type
)
9995 TYPE_TARGET_TYPE (this_type
) = target_type
;
9998 /* Self-referential typedefs are, it seems, not allowed by the DWARF
9999 spec and cause infinite loops in GDB. */
10000 complaint (&symfile_complaints
,
10001 _("Self-referential DW_TAG_typedef "
10002 "- DIE at 0x%x [in module %s]"),
10003 die
->offset
.sect_off
, objfile
->name
);
10004 TYPE_TARGET_TYPE (this_type
) = NULL
;
10009 /* Find a representation of a given base type and install
10010 it in the TYPE field of the die. */
10012 static struct type
*
10013 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10015 struct objfile
*objfile
= cu
->objfile
;
10017 struct attribute
*attr
;
10018 int encoding
= 0, size
= 0;
10020 enum type_code code
= TYPE_CODE_INT
;
10021 int type_flags
= 0;
10022 struct type
*target_type
= NULL
;
10024 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10027 encoding
= DW_UNSND (attr
);
10029 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10032 size
= DW_UNSND (attr
);
10034 name
= dwarf2_name (die
, cu
);
10037 complaint (&symfile_complaints
,
10038 _("DW_AT_name missing from DW_TAG_base_type"));
10043 case DW_ATE_address
:
10044 /* Turn DW_ATE_address into a void * pointer. */
10045 code
= TYPE_CODE_PTR
;
10046 type_flags
|= TYPE_FLAG_UNSIGNED
;
10047 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10049 case DW_ATE_boolean
:
10050 code
= TYPE_CODE_BOOL
;
10051 type_flags
|= TYPE_FLAG_UNSIGNED
;
10053 case DW_ATE_complex_float
:
10054 code
= TYPE_CODE_COMPLEX
;
10055 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10057 case DW_ATE_decimal_float
:
10058 code
= TYPE_CODE_DECFLOAT
;
10061 code
= TYPE_CODE_FLT
;
10063 case DW_ATE_signed
:
10065 case DW_ATE_unsigned
:
10066 type_flags
|= TYPE_FLAG_UNSIGNED
;
10067 if (cu
->language
== language_fortran
10069 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10070 code
= TYPE_CODE_CHAR
;
10072 case DW_ATE_signed_char
:
10073 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10074 || cu
->language
== language_pascal
10075 || cu
->language
== language_fortran
)
10076 code
= TYPE_CODE_CHAR
;
10078 case DW_ATE_unsigned_char
:
10079 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10080 || cu
->language
== language_pascal
10081 || cu
->language
== language_fortran
)
10082 code
= TYPE_CODE_CHAR
;
10083 type_flags
|= TYPE_FLAG_UNSIGNED
;
10086 /* We just treat this as an integer and then recognize the
10087 type by name elsewhere. */
10091 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10092 dwarf_type_encoding_name (encoding
));
10096 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10097 TYPE_NAME (type
) = name
;
10098 TYPE_TARGET_TYPE (type
) = target_type
;
10100 if (name
&& strcmp (name
, "char") == 0)
10101 TYPE_NOSIGN (type
) = 1;
10103 return set_die_type (die
, type
, cu
);
10106 /* Read the given DW_AT_subrange DIE. */
10108 static struct type
*
10109 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10111 struct type
*base_type
;
10112 struct type
*range_type
;
10113 struct attribute
*attr
;
10115 int low_default_is_valid
;
10117 LONGEST negative_mask
;
10119 base_type
= die_type (die
, cu
);
10120 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10121 check_typedef (base_type
);
10123 /* The die_type call above may have already set the type for this DIE. */
10124 range_type
= get_die_type (die
, cu
);
10128 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10129 omitting DW_AT_lower_bound. */
10130 switch (cu
->language
)
10133 case language_cplus
:
10135 low_default_is_valid
= 1;
10137 case language_fortran
:
10139 low_default_is_valid
= 1;
10142 case language_java
:
10143 case language_objc
:
10145 low_default_is_valid
= (cu
->header
.version
>= 4);
10149 case language_pascal
:
10151 low_default_is_valid
= (cu
->header
.version
>= 4);
10155 low_default_is_valid
= 0;
10159 /* FIXME: For variable sized arrays either of these could be
10160 a variable rather than a constant value. We'll allow it,
10161 but we don't know how to handle it. */
10162 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10164 low
= dwarf2_get_attr_constant_value (attr
, low
);
10165 else if (!low_default_is_valid
)
10166 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10167 "- DIE at 0x%x [in module %s]"),
10168 die
->offset
.sect_off
, cu
->objfile
->name
);
10170 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10173 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10175 /* GCC encodes arrays with unspecified or dynamic length
10176 with a DW_FORM_block1 attribute or a reference attribute.
10177 FIXME: GDB does not yet know how to handle dynamic
10178 arrays properly, treat them as arrays with unspecified
10181 FIXME: jimb/2003-09-22: GDB does not really know
10182 how to handle arrays of unspecified length
10183 either; we just represent them as zero-length
10184 arrays. Choose an appropriate upper bound given
10185 the lower bound we've computed above. */
10189 high
= dwarf2_get_attr_constant_value (attr
, 1);
10193 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10196 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10197 high
= low
+ count
- 1;
10201 /* Unspecified array length. */
10206 /* Dwarf-2 specifications explicitly allows to create subrange types
10207 without specifying a base type.
10208 In that case, the base type must be set to the type of
10209 the lower bound, upper bound or count, in that order, if any of these
10210 three attributes references an object that has a type.
10211 If no base type is found, the Dwarf-2 specifications say that
10212 a signed integer type of size equal to the size of an address should
10214 For the following C code: `extern char gdb_int [];'
10215 GCC produces an empty range DIE.
10216 FIXME: muller/2010-05-28: Possible references to object for low bound,
10217 high bound or count are not yet handled by this code. */
10218 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10220 struct objfile
*objfile
= cu
->objfile
;
10221 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10222 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10223 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10225 /* Test "int", "long int", and "long long int" objfile types,
10226 and select the first one having a size above or equal to the
10227 architecture address size. */
10228 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10229 base_type
= int_type
;
10232 int_type
= objfile_type (objfile
)->builtin_long
;
10233 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10234 base_type
= int_type
;
10237 int_type
= objfile_type (objfile
)->builtin_long_long
;
10238 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10239 base_type
= int_type
;
10245 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10246 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10247 low
|= negative_mask
;
10248 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10249 high
|= negative_mask
;
10251 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10253 /* Mark arrays with dynamic length at least as an array of unspecified
10254 length. GDB could check the boundary but before it gets implemented at
10255 least allow accessing the array elements. */
10256 if (attr
&& attr_form_is_block (attr
))
10257 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10259 /* Ada expects an empty array on no boundary attributes. */
10260 if (attr
== NULL
&& cu
->language
!= language_ada
)
10261 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10263 name
= dwarf2_name (die
, cu
);
10265 TYPE_NAME (range_type
) = name
;
10267 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10269 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10271 set_die_type (die
, range_type
, cu
);
10273 /* set_die_type should be already done. */
10274 set_descriptive_type (range_type
, die
, cu
);
10279 static struct type
*
10280 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10284 /* For now, we only support the C meaning of an unspecified type: void. */
10286 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10287 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10289 return set_die_type (die
, type
, cu
);
10292 /* Read a single die and all its descendents. Set the die's sibling
10293 field to NULL; set other fields in the die correctly, and set all
10294 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10295 location of the info_ptr after reading all of those dies. PARENT
10296 is the parent of the die in question. */
10298 static struct die_info
*
10299 read_die_and_children (const struct die_reader_specs
*reader
,
10300 gdb_byte
*info_ptr
,
10301 gdb_byte
**new_info_ptr
,
10302 struct die_info
*parent
)
10304 struct die_info
*die
;
10308 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10311 *new_info_ptr
= cur_ptr
;
10314 store_in_ref_table (die
, reader
->cu
);
10317 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10321 *new_info_ptr
= cur_ptr
;
10324 die
->sibling
= NULL
;
10325 die
->parent
= parent
;
10329 /* Read a die, all of its descendents, and all of its siblings; set
10330 all of the fields of all of the dies correctly. Arguments are as
10331 in read_die_and_children. */
10333 static struct die_info
*
10334 read_die_and_siblings (const struct die_reader_specs
*reader
,
10335 gdb_byte
*info_ptr
,
10336 gdb_byte
**new_info_ptr
,
10337 struct die_info
*parent
)
10339 struct die_info
*first_die
, *last_sibling
;
10342 cur_ptr
= info_ptr
;
10343 first_die
= last_sibling
= NULL
;
10347 struct die_info
*die
10348 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10352 *new_info_ptr
= cur_ptr
;
10359 last_sibling
->sibling
= die
;
10361 last_sibling
= die
;
10365 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10367 The caller is responsible for filling in the extra attributes
10368 and updating (*DIEP)->num_attrs.
10369 Set DIEP to point to a newly allocated die with its information,
10370 except for its child, sibling, and parent fields.
10371 Set HAS_CHILDREN to tell whether the die has children or not. */
10374 read_full_die_1 (const struct die_reader_specs
*reader
,
10375 struct die_info
**diep
, gdb_byte
*info_ptr
,
10376 int *has_children
, int num_extra_attrs
)
10378 unsigned int abbrev_number
, bytes_read
, i
;
10379 sect_offset offset
;
10380 struct abbrev_info
*abbrev
;
10381 struct die_info
*die
;
10382 struct dwarf2_cu
*cu
= reader
->cu
;
10383 bfd
*abfd
= reader
->abfd
;
10385 offset
.sect_off
= info_ptr
- reader
->buffer
;
10386 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10387 info_ptr
+= bytes_read
;
10388 if (!abbrev_number
)
10395 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10397 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10399 bfd_get_filename (abfd
));
10401 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10402 die
->offset
= offset
;
10403 die
->tag
= abbrev
->tag
;
10404 die
->abbrev
= abbrev_number
;
10406 /* Make the result usable.
10407 The caller needs to update num_attrs after adding the extra
10409 die
->num_attrs
= abbrev
->num_attrs
;
10411 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10412 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10416 *has_children
= abbrev
->has_children
;
10420 /* Read a die and all its attributes.
10421 Set DIEP to point to a newly allocated die with its information,
10422 except for its child, sibling, and parent fields.
10423 Set HAS_CHILDREN to tell whether the die has children or not. */
10426 read_full_die (const struct die_reader_specs
*reader
,
10427 struct die_info
**diep
, gdb_byte
*info_ptr
,
10430 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10433 /* In DWARF version 2, the description of the debugging information is
10434 stored in a separate .debug_abbrev section. Before we read any
10435 dies from a section we read in all abbreviations and install them
10436 in a hash table. This function also sets flags in CU describing
10437 the data found in the abbrev table. */
10440 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10441 struct dwarf2_section_info
*abbrev_section
)
10444 bfd
*abfd
= abbrev_section
->asection
->owner
;
10445 struct comp_unit_head
*cu_header
= &cu
->header
;
10446 gdb_byte
*abbrev_ptr
;
10447 struct abbrev_info
*cur_abbrev
;
10448 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10449 unsigned int abbrev_form
, hash_number
;
10450 struct attr_abbrev
*cur_attrs
;
10451 unsigned int allocated_attrs
;
10453 /* Initialize dwarf2 abbrevs. */
10454 obstack_init (&cu
->abbrev_obstack
);
10455 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10457 * sizeof (struct abbrev_info
*)));
10458 memset (cu
->dwarf2_abbrevs
, 0,
10459 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10461 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10462 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10463 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10464 abbrev_ptr
+= bytes_read
;
10466 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10467 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10469 /* Loop until we reach an abbrev number of 0. */
10470 while (abbrev_number
)
10472 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10474 /* read in abbrev header */
10475 cur_abbrev
->number
= abbrev_number
;
10476 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10477 abbrev_ptr
+= bytes_read
;
10478 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10481 /* now read in declarations */
10482 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10483 abbrev_ptr
+= bytes_read
;
10484 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10485 abbrev_ptr
+= bytes_read
;
10486 while (abbrev_name
)
10488 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10490 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10492 = xrealloc (cur_attrs
, (allocated_attrs
10493 * sizeof (struct attr_abbrev
)));
10496 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10497 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10498 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10499 abbrev_ptr
+= bytes_read
;
10500 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10501 abbrev_ptr
+= bytes_read
;
10504 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10505 (cur_abbrev
->num_attrs
10506 * sizeof (struct attr_abbrev
)));
10507 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10508 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10510 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10511 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10512 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10514 /* Get next abbreviation.
10515 Under Irix6 the abbreviations for a compilation unit are not
10516 always properly terminated with an abbrev number of 0.
10517 Exit loop if we encounter an abbreviation which we have
10518 already read (which means we are about to read the abbreviations
10519 for the next compile unit) or if the end of the abbreviation
10520 table is reached. */
10521 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10522 >= abbrev_section
->size
)
10524 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10525 abbrev_ptr
+= bytes_read
;
10526 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10533 /* Release the memory used by the abbrev table for a compilation unit. */
10536 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10538 struct dwarf2_cu
*cu
= ptr_to_cu
;
10540 obstack_free (&cu
->abbrev_obstack
, NULL
);
10541 cu
->dwarf2_abbrevs
= NULL
;
10544 /* Lookup an abbrev_info structure in the abbrev hash table. */
10546 static struct abbrev_info
*
10547 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
10549 unsigned int hash_number
;
10550 struct abbrev_info
*abbrev
;
10552 hash_number
= number
% ABBREV_HASH_SIZE
;
10553 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
10557 if (abbrev
->number
== number
)
10560 abbrev
= abbrev
->next
;
10565 /* Returns nonzero if TAG represents a type that we might generate a partial
10569 is_type_tag_for_partial (int tag
)
10574 /* Some types that would be reasonable to generate partial symbols for,
10575 that we don't at present. */
10576 case DW_TAG_array_type
:
10577 case DW_TAG_file_type
:
10578 case DW_TAG_ptr_to_member_type
:
10579 case DW_TAG_set_type
:
10580 case DW_TAG_string_type
:
10581 case DW_TAG_subroutine_type
:
10583 case DW_TAG_base_type
:
10584 case DW_TAG_class_type
:
10585 case DW_TAG_interface_type
:
10586 case DW_TAG_enumeration_type
:
10587 case DW_TAG_structure_type
:
10588 case DW_TAG_subrange_type
:
10589 case DW_TAG_typedef
:
10590 case DW_TAG_union_type
:
10597 /* Load all DIEs that are interesting for partial symbols into memory. */
10599 static struct partial_die_info
*
10600 load_partial_dies (const struct die_reader_specs
*reader
,
10601 gdb_byte
*info_ptr
, int building_psymtab
)
10603 struct dwarf2_cu
*cu
= reader
->cu
;
10604 struct objfile
*objfile
= cu
->objfile
;
10605 struct partial_die_info
*part_die
;
10606 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
10607 struct abbrev_info
*abbrev
;
10608 unsigned int bytes_read
;
10609 unsigned int load_all
= 0;
10610 int nesting_level
= 1;
10615 gdb_assert (cu
->per_cu
!= NULL
);
10616 if (cu
->per_cu
->load_all_dies
)
10620 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10624 &cu
->comp_unit_obstack
,
10625 hashtab_obstack_allocate
,
10626 dummy_obstack_deallocate
);
10628 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10629 sizeof (struct partial_die_info
));
10633 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
10635 /* A NULL abbrev means the end of a series of children. */
10636 if (abbrev
== NULL
)
10638 if (--nesting_level
== 0)
10640 /* PART_DIE was probably the last thing allocated on the
10641 comp_unit_obstack, so we could call obstack_free
10642 here. We don't do that because the waste is small,
10643 and will be cleaned up when we're done with this
10644 compilation unit. This way, we're also more robust
10645 against other users of the comp_unit_obstack. */
10648 info_ptr
+= bytes_read
;
10649 last_die
= parent_die
;
10650 parent_die
= parent_die
->die_parent
;
10654 /* Check for template arguments. We never save these; if
10655 they're seen, we just mark the parent, and go on our way. */
10656 if (parent_die
!= NULL
10657 && cu
->language
== language_cplus
10658 && (abbrev
->tag
== DW_TAG_template_type_param
10659 || abbrev
->tag
== DW_TAG_template_value_param
))
10661 parent_die
->has_template_arguments
= 1;
10665 /* We don't need a partial DIE for the template argument. */
10666 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10671 /* We only recurse into c++ subprograms looking for template arguments.
10672 Skip their other children. */
10674 && cu
->language
== language_cplus
10675 && parent_die
!= NULL
10676 && parent_die
->tag
== DW_TAG_subprogram
)
10678 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10682 /* Check whether this DIE is interesting enough to save. Normally
10683 we would not be interested in members here, but there may be
10684 later variables referencing them via DW_AT_specification (for
10685 static members). */
10687 && !is_type_tag_for_partial (abbrev
->tag
)
10688 && abbrev
->tag
!= DW_TAG_constant
10689 && abbrev
->tag
!= DW_TAG_enumerator
10690 && abbrev
->tag
!= DW_TAG_subprogram
10691 && abbrev
->tag
!= DW_TAG_lexical_block
10692 && abbrev
->tag
!= DW_TAG_variable
10693 && abbrev
->tag
!= DW_TAG_namespace
10694 && abbrev
->tag
!= DW_TAG_module
10695 && abbrev
->tag
!= DW_TAG_member
)
10697 /* Otherwise we skip to the next sibling, if any. */
10698 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
10702 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
10705 /* This two-pass algorithm for processing partial symbols has a
10706 high cost in cache pressure. Thus, handle some simple cases
10707 here which cover the majority of C partial symbols. DIEs
10708 which neither have specification tags in them, nor could have
10709 specification tags elsewhere pointing at them, can simply be
10710 processed and discarded.
10712 This segment is also optional; scan_partial_symbols and
10713 add_partial_symbol will handle these DIEs if we chain
10714 them in normally. When compilers which do not emit large
10715 quantities of duplicate debug information are more common,
10716 this code can probably be removed. */
10718 /* Any complete simple types at the top level (pretty much all
10719 of them, for a language without namespaces), can be processed
10721 if (parent_die
== NULL
10722 && part_die
->has_specification
== 0
10723 && part_die
->is_declaration
== 0
10724 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
10725 || part_die
->tag
== DW_TAG_base_type
10726 || part_die
->tag
== DW_TAG_subrange_type
))
10728 if (building_psymtab
&& part_die
->name
!= NULL
)
10729 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
10730 VAR_DOMAIN
, LOC_TYPEDEF
,
10731 &objfile
->static_psymbols
,
10732 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
10733 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
10737 /* The exception for DW_TAG_typedef with has_children above is
10738 a workaround of GCC PR debug/47510. In the case of this complaint
10739 type_name_no_tag_or_error will error on such types later.
10741 GDB skipped children of DW_TAG_typedef by the shortcut above and then
10742 it could not find the child DIEs referenced later, this is checked
10743 above. In correct DWARF DW_TAG_typedef should have no children. */
10745 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
10746 complaint (&symfile_complaints
,
10747 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
10748 "- DIE at 0x%x [in module %s]"),
10749 part_die
->offset
.sect_off
, objfile
->name
);
10751 /* If we're at the second level, and we're an enumerator, and
10752 our parent has no specification (meaning possibly lives in a
10753 namespace elsewhere), then we can add the partial symbol now
10754 instead of queueing it. */
10755 if (part_die
->tag
== DW_TAG_enumerator
10756 && parent_die
!= NULL
10757 && parent_die
->die_parent
== NULL
10758 && parent_die
->tag
== DW_TAG_enumeration_type
10759 && parent_die
->has_specification
== 0)
10761 if (part_die
->name
== NULL
)
10762 complaint (&symfile_complaints
,
10763 _("malformed enumerator DIE ignored"));
10764 else if (building_psymtab
)
10765 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
10766 VAR_DOMAIN
, LOC_CONST
,
10767 (cu
->language
== language_cplus
10768 || cu
->language
== language_java
)
10769 ? &objfile
->global_psymbols
10770 : &objfile
->static_psymbols
,
10771 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
10773 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
10777 /* We'll save this DIE so link it in. */
10778 part_die
->die_parent
= parent_die
;
10779 part_die
->die_sibling
= NULL
;
10780 part_die
->die_child
= NULL
;
10782 if (last_die
&& last_die
== parent_die
)
10783 last_die
->die_child
= part_die
;
10785 last_die
->die_sibling
= part_die
;
10787 last_die
= part_die
;
10789 if (first_die
== NULL
)
10790 first_die
= part_die
;
10792 /* Maybe add the DIE to the hash table. Not all DIEs that we
10793 find interesting need to be in the hash table, because we
10794 also have the parent/sibling/child chains; only those that we
10795 might refer to by offset later during partial symbol reading.
10797 For now this means things that might have be the target of a
10798 DW_AT_specification, DW_AT_abstract_origin, or
10799 DW_AT_extension. DW_AT_extension will refer only to
10800 namespaces; DW_AT_abstract_origin refers to functions (and
10801 many things under the function DIE, but we do not recurse
10802 into function DIEs during partial symbol reading) and
10803 possibly variables as well; DW_AT_specification refers to
10804 declarations. Declarations ought to have the DW_AT_declaration
10805 flag. It happens that GCC forgets to put it in sometimes, but
10806 only for functions, not for types.
10808 Adding more things than necessary to the hash table is harmless
10809 except for the performance cost. Adding too few will result in
10810 wasted time in find_partial_die, when we reread the compilation
10811 unit with load_all_dies set. */
10814 || abbrev
->tag
== DW_TAG_constant
10815 || abbrev
->tag
== DW_TAG_subprogram
10816 || abbrev
->tag
== DW_TAG_variable
10817 || abbrev
->tag
== DW_TAG_namespace
10818 || part_die
->is_declaration
)
10822 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
10823 part_die
->offset
.sect_off
, INSERT
);
10827 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
10828 sizeof (struct partial_die_info
));
10830 /* For some DIEs we want to follow their children (if any). For C
10831 we have no reason to follow the children of structures; for other
10832 languages we have to, so that we can get at method physnames
10833 to infer fully qualified class names, for DW_AT_specification,
10834 and for C++ template arguments. For C++, we also look one level
10835 inside functions to find template arguments (if the name of the
10836 function does not already contain the template arguments).
10838 For Ada, we need to scan the children of subprograms and lexical
10839 blocks as well because Ada allows the definition of nested
10840 entities that could be interesting for the debugger, such as
10841 nested subprograms for instance. */
10842 if (last_die
->has_children
10844 || last_die
->tag
== DW_TAG_namespace
10845 || last_die
->tag
== DW_TAG_module
10846 || last_die
->tag
== DW_TAG_enumeration_type
10847 || (cu
->language
== language_cplus
10848 && last_die
->tag
== DW_TAG_subprogram
10849 && (last_die
->name
== NULL
10850 || strchr (last_die
->name
, '<') == NULL
))
10851 || (cu
->language
!= language_c
10852 && (last_die
->tag
== DW_TAG_class_type
10853 || last_die
->tag
== DW_TAG_interface_type
10854 || last_die
->tag
== DW_TAG_structure_type
10855 || last_die
->tag
== DW_TAG_union_type
))
10856 || (cu
->language
== language_ada
10857 && (last_die
->tag
== DW_TAG_subprogram
10858 || last_die
->tag
== DW_TAG_lexical_block
))))
10861 parent_die
= last_die
;
10865 /* Otherwise we skip to the next sibling, if any. */
10866 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
10868 /* Back to the top, do it again. */
10872 /* Read a minimal amount of information into the minimal die structure. */
10875 read_partial_die (const struct die_reader_specs
*reader
,
10876 struct partial_die_info
*part_die
,
10877 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
10878 gdb_byte
*info_ptr
)
10880 struct dwarf2_cu
*cu
= reader
->cu
;
10881 struct objfile
*objfile
= cu
->objfile
;
10882 gdb_byte
*buffer
= reader
->buffer
;
10884 struct attribute attr
;
10885 int has_low_pc_attr
= 0;
10886 int has_high_pc_attr
= 0;
10887 int high_pc_relative
= 0;
10889 memset (part_die
, 0, sizeof (struct partial_die_info
));
10891 part_die
->offset
.sect_off
= info_ptr
- buffer
;
10893 info_ptr
+= abbrev_len
;
10895 if (abbrev
== NULL
)
10898 part_die
->tag
= abbrev
->tag
;
10899 part_die
->has_children
= abbrev
->has_children
;
10901 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10903 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
10905 /* Store the data if it is of an attribute we want to keep in a
10906 partial symbol table. */
10910 switch (part_die
->tag
)
10912 case DW_TAG_compile_unit
:
10913 case DW_TAG_type_unit
:
10914 /* Compilation units have a DW_AT_name that is a filename, not
10915 a source language identifier. */
10916 case DW_TAG_enumeration_type
:
10917 case DW_TAG_enumerator
:
10918 /* These tags always have simple identifiers already; no need
10919 to canonicalize them. */
10920 part_die
->name
= DW_STRING (&attr
);
10924 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
10925 &objfile
->objfile_obstack
);
10929 case DW_AT_linkage_name
:
10930 case DW_AT_MIPS_linkage_name
:
10931 /* Note that both forms of linkage name might appear. We
10932 assume they will be the same, and we only store the last
10934 if (cu
->language
== language_ada
)
10935 part_die
->name
= DW_STRING (&attr
);
10936 part_die
->linkage_name
= DW_STRING (&attr
);
10939 has_low_pc_attr
= 1;
10940 part_die
->lowpc
= DW_ADDR (&attr
);
10942 case DW_AT_high_pc
:
10943 has_high_pc_attr
= 1;
10944 if (attr
.form
== DW_FORM_addr
10945 || attr
.form
== DW_FORM_GNU_addr_index
)
10946 part_die
->highpc
= DW_ADDR (&attr
);
10949 high_pc_relative
= 1;
10950 part_die
->highpc
= DW_UNSND (&attr
);
10953 case DW_AT_location
:
10954 /* Support the .debug_loc offsets. */
10955 if (attr_form_is_block (&attr
))
10957 part_die
->locdesc
= DW_BLOCK (&attr
);
10959 else if (attr_form_is_section_offset (&attr
))
10961 dwarf2_complex_location_expr_complaint ();
10965 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10966 "partial symbol information");
10969 case DW_AT_external
:
10970 part_die
->is_external
= DW_UNSND (&attr
);
10972 case DW_AT_declaration
:
10973 part_die
->is_declaration
= DW_UNSND (&attr
);
10976 part_die
->has_type
= 1;
10978 case DW_AT_abstract_origin
:
10979 case DW_AT_specification
:
10980 case DW_AT_extension
:
10981 part_die
->has_specification
= 1;
10982 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
10984 case DW_AT_sibling
:
10985 /* Ignore absolute siblings, they might point outside of
10986 the current compile unit. */
10987 if (attr
.form
== DW_FORM_ref_addr
)
10988 complaint (&symfile_complaints
,
10989 _("ignoring absolute DW_AT_sibling"));
10991 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
10993 case DW_AT_byte_size
:
10994 part_die
->has_byte_size
= 1;
10996 case DW_AT_calling_convention
:
10997 /* DWARF doesn't provide a way to identify a program's source-level
10998 entry point. DW_AT_calling_convention attributes are only meant
10999 to describe functions' calling conventions.
11001 However, because it's a necessary piece of information in
11002 Fortran, and because DW_CC_program is the only piece of debugging
11003 information whose definition refers to a 'main program' at all,
11004 several compilers have begun marking Fortran main programs with
11005 DW_CC_program --- even when those functions use the standard
11006 calling conventions.
11008 So until DWARF specifies a way to provide this information and
11009 compilers pick up the new representation, we'll support this
11011 if (DW_UNSND (&attr
) == DW_CC_program
11012 && cu
->language
== language_fortran
)
11014 set_main_name (part_die
->name
);
11016 /* As this DIE has a static linkage the name would be difficult
11017 to look up later. */
11018 language_of_main
= language_fortran
;
11022 if (DW_UNSND (&attr
) == DW_INL_inlined
11023 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11024 part_die
->may_be_inlined
= 1;
11031 if (high_pc_relative
)
11032 part_die
->highpc
+= part_die
->lowpc
;
11034 if (has_low_pc_attr
&& has_high_pc_attr
)
11036 /* When using the GNU linker, .gnu.linkonce. sections are used to
11037 eliminate duplicate copies of functions and vtables and such.
11038 The linker will arbitrarily choose one and discard the others.
11039 The AT_*_pc values for such functions refer to local labels in
11040 these sections. If the section from that file was discarded, the
11041 labels are not in the output, so the relocs get a value of 0.
11042 If this is a discarded function, mark the pc bounds as invalid,
11043 so that GDB will ignore it. */
11044 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11046 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11048 complaint (&symfile_complaints
,
11049 _("DW_AT_low_pc %s is zero "
11050 "for DIE at 0x%x [in module %s]"),
11051 paddress (gdbarch
, part_die
->lowpc
),
11052 part_die
->offset
.sect_off
, objfile
->name
);
11054 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11055 else if (part_die
->lowpc
>= part_die
->highpc
)
11057 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11059 complaint (&symfile_complaints
,
11060 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11061 "for DIE at 0x%x [in module %s]"),
11062 paddress (gdbarch
, part_die
->lowpc
),
11063 paddress (gdbarch
, part_die
->highpc
),
11064 part_die
->offset
.sect_off
, objfile
->name
);
11067 part_die
->has_pc_info
= 1;
11073 /* Find a cached partial DIE at OFFSET in CU. */
11075 static struct partial_die_info
*
11076 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11078 struct partial_die_info
*lookup_die
= NULL
;
11079 struct partial_die_info part_die
;
11081 part_die
.offset
= offset
;
11082 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11088 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11089 except in the case of .debug_types DIEs which do not reference
11090 outside their CU (they do however referencing other types via
11091 DW_FORM_ref_sig8). */
11093 static struct partial_die_info
*
11094 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11096 struct objfile
*objfile
= cu
->objfile
;
11097 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11098 struct partial_die_info
*pd
= NULL
;
11100 if (offset_in_cu_p (&cu
->header
, offset
))
11102 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11105 /* We missed recording what we needed.
11106 Load all dies and try again. */
11107 per_cu
= cu
->per_cu
;
11111 /* TUs don't reference other CUs/TUs (except via type signatures). */
11112 if (cu
->per_cu
->is_debug_types
)
11114 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11115 " external reference to offset 0x%lx [in module %s].\n"),
11116 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11117 bfd_get_filename (objfile
->obfd
));
11119 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11121 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11122 load_partial_comp_unit (per_cu
);
11124 per_cu
->cu
->last_used
= 0;
11125 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11128 /* If we didn't find it, and not all dies have been loaded,
11129 load them all and try again. */
11131 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11133 per_cu
->load_all_dies
= 1;
11135 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11136 THIS_CU->cu may already be in use. So we can't just free it and
11137 replace its DIEs with the ones we read in. Instead, we leave those
11138 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11139 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11141 load_partial_comp_unit (per_cu
);
11143 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11147 internal_error (__FILE__
, __LINE__
,
11148 _("could not find partial DIE 0x%x "
11149 "in cache [from module %s]\n"),
11150 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11154 /* See if we can figure out if the class lives in a namespace. We do
11155 this by looking for a member function; its demangled name will
11156 contain namespace info, if there is any. */
11159 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11160 struct dwarf2_cu
*cu
)
11162 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11163 what template types look like, because the demangler
11164 frequently doesn't give the same name as the debug info. We
11165 could fix this by only using the demangled name to get the
11166 prefix (but see comment in read_structure_type). */
11168 struct partial_die_info
*real_pdi
;
11169 struct partial_die_info
*child_pdi
;
11171 /* If this DIE (this DIE's specification, if any) has a parent, then
11172 we should not do this. We'll prepend the parent's fully qualified
11173 name when we create the partial symbol. */
11175 real_pdi
= struct_pdi
;
11176 while (real_pdi
->has_specification
)
11177 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11179 if (real_pdi
->die_parent
!= NULL
)
11182 for (child_pdi
= struct_pdi
->die_child
;
11184 child_pdi
= child_pdi
->die_sibling
)
11186 if (child_pdi
->tag
== DW_TAG_subprogram
11187 && child_pdi
->linkage_name
!= NULL
)
11189 char *actual_class_name
11190 = language_class_name_from_physname (cu
->language_defn
,
11191 child_pdi
->linkage_name
);
11192 if (actual_class_name
!= NULL
)
11195 = obsavestring (actual_class_name
,
11196 strlen (actual_class_name
),
11197 &cu
->objfile
->objfile_obstack
);
11198 xfree (actual_class_name
);
11205 /* Adjust PART_DIE before generating a symbol for it. This function
11206 may set the is_external flag or change the DIE's name. */
11209 fixup_partial_die (struct partial_die_info
*part_die
,
11210 struct dwarf2_cu
*cu
)
11212 /* Once we've fixed up a die, there's no point in doing so again.
11213 This also avoids a memory leak if we were to call
11214 guess_partial_die_structure_name multiple times. */
11215 if (part_die
->fixup_called
)
11218 /* If we found a reference attribute and the DIE has no name, try
11219 to find a name in the referred to DIE. */
11221 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11223 struct partial_die_info
*spec_die
;
11225 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11227 fixup_partial_die (spec_die
, cu
);
11229 if (spec_die
->name
)
11231 part_die
->name
= spec_die
->name
;
11233 /* Copy DW_AT_external attribute if it is set. */
11234 if (spec_die
->is_external
)
11235 part_die
->is_external
= spec_die
->is_external
;
11239 /* Set default names for some unnamed DIEs. */
11241 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11242 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11244 /* If there is no parent die to provide a namespace, and there are
11245 children, see if we can determine the namespace from their linkage
11247 if (cu
->language
== language_cplus
11248 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11249 && part_die
->die_parent
== NULL
11250 && part_die
->has_children
11251 && (part_die
->tag
== DW_TAG_class_type
11252 || part_die
->tag
== DW_TAG_structure_type
11253 || part_die
->tag
== DW_TAG_union_type
))
11254 guess_partial_die_structure_name (part_die
, cu
);
11256 /* GCC might emit a nameless struct or union that has a linkage
11257 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11258 if (part_die
->name
== NULL
11259 && (part_die
->tag
== DW_TAG_class_type
11260 || part_die
->tag
== DW_TAG_interface_type
11261 || part_die
->tag
== DW_TAG_structure_type
11262 || part_die
->tag
== DW_TAG_union_type
)
11263 && part_die
->linkage_name
!= NULL
)
11267 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11272 /* Strip any leading namespaces/classes, keep only the base name.
11273 DW_AT_name for named DIEs does not contain the prefixes. */
11274 base
= strrchr (demangled
, ':');
11275 if (base
&& base
> demangled
&& base
[-1] == ':')
11280 part_die
->name
= obsavestring (base
, strlen (base
),
11281 &cu
->objfile
->objfile_obstack
);
11286 part_die
->fixup_called
= 1;
11289 /* Read an attribute value described by an attribute form. */
11292 read_attribute_value (const struct die_reader_specs
*reader
,
11293 struct attribute
*attr
, unsigned form
,
11294 gdb_byte
*info_ptr
)
11296 struct dwarf2_cu
*cu
= reader
->cu
;
11297 bfd
*abfd
= reader
->abfd
;
11298 struct comp_unit_head
*cu_header
= &cu
->header
;
11299 unsigned int bytes_read
;
11300 struct dwarf_block
*blk
;
11305 case DW_FORM_ref_addr
:
11306 if (cu
->header
.version
== 2)
11307 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11309 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11310 &cu
->header
, &bytes_read
);
11311 info_ptr
+= bytes_read
;
11314 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11315 info_ptr
+= bytes_read
;
11317 case DW_FORM_block2
:
11318 blk
= dwarf_alloc_block (cu
);
11319 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11321 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11322 info_ptr
+= blk
->size
;
11323 DW_BLOCK (attr
) = blk
;
11325 case DW_FORM_block4
:
11326 blk
= dwarf_alloc_block (cu
);
11327 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11329 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11330 info_ptr
+= blk
->size
;
11331 DW_BLOCK (attr
) = blk
;
11333 case DW_FORM_data2
:
11334 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11337 case DW_FORM_data4
:
11338 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11341 case DW_FORM_data8
:
11342 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11345 case DW_FORM_sec_offset
:
11346 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11347 info_ptr
+= bytes_read
;
11349 case DW_FORM_string
:
11350 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11351 DW_STRING_IS_CANONICAL (attr
) = 0;
11352 info_ptr
+= bytes_read
;
11355 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11357 DW_STRING_IS_CANONICAL (attr
) = 0;
11358 info_ptr
+= bytes_read
;
11360 case DW_FORM_exprloc
:
11361 case DW_FORM_block
:
11362 blk
= dwarf_alloc_block (cu
);
11363 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11364 info_ptr
+= bytes_read
;
11365 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11366 info_ptr
+= blk
->size
;
11367 DW_BLOCK (attr
) = blk
;
11369 case DW_FORM_block1
:
11370 blk
= dwarf_alloc_block (cu
);
11371 blk
->size
= read_1_byte (abfd
, info_ptr
);
11373 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11374 info_ptr
+= blk
->size
;
11375 DW_BLOCK (attr
) = blk
;
11377 case DW_FORM_data1
:
11378 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11382 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11385 case DW_FORM_flag_present
:
11386 DW_UNSND (attr
) = 1;
11388 case DW_FORM_sdata
:
11389 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11390 info_ptr
+= bytes_read
;
11392 case DW_FORM_udata
:
11393 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11394 info_ptr
+= bytes_read
;
11397 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11398 + read_1_byte (abfd
, info_ptr
));
11402 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11403 + read_2_bytes (abfd
, info_ptr
));
11407 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11408 + read_4_bytes (abfd
, info_ptr
));
11412 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11413 + read_8_bytes (abfd
, info_ptr
));
11416 case DW_FORM_ref_sig8
:
11417 /* Convert the signature to something we can record in DW_UNSND
11419 NOTE: This is NULL if the type wasn't found. */
11420 DW_SIGNATURED_TYPE (attr
) =
11421 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11424 case DW_FORM_ref_udata
:
11425 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11426 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11427 info_ptr
+= bytes_read
;
11429 case DW_FORM_indirect
:
11430 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11431 info_ptr
+= bytes_read
;
11432 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11434 case DW_FORM_GNU_addr_index
:
11435 if (reader
->dwo_file
== NULL
)
11437 /* For now flag a hard error.
11438 Later we can turn this into a complaint. */
11439 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11440 dwarf_form_name (form
),
11441 bfd_get_filename (abfd
));
11443 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11444 info_ptr
+= bytes_read
;
11446 case DW_FORM_GNU_str_index
:
11447 if (reader
->dwo_file
== NULL
)
11449 /* For now flag a hard error.
11450 Later we can turn this into a complaint if warranted. */
11451 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11452 dwarf_form_name (form
),
11453 bfd_get_filename (abfd
));
11456 ULONGEST str_index
=
11457 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11459 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11460 DW_STRING_IS_CANONICAL (attr
) = 0;
11461 info_ptr
+= bytes_read
;
11465 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11466 dwarf_form_name (form
),
11467 bfd_get_filename (abfd
));
11470 /* We have seen instances where the compiler tried to emit a byte
11471 size attribute of -1 which ended up being encoded as an unsigned
11472 0xffffffff. Although 0xffffffff is technically a valid size value,
11473 an object of this size seems pretty unlikely so we can relatively
11474 safely treat these cases as if the size attribute was invalid and
11475 treat them as zero by default. */
11476 if (attr
->name
== DW_AT_byte_size
11477 && form
== DW_FORM_data4
11478 && DW_UNSND (attr
) >= 0xffffffff)
11481 (&symfile_complaints
,
11482 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11483 hex_string (DW_UNSND (attr
)));
11484 DW_UNSND (attr
) = 0;
11490 /* Read an attribute described by an abbreviated attribute. */
11493 read_attribute (const struct die_reader_specs
*reader
,
11494 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11495 gdb_byte
*info_ptr
)
11497 attr
->name
= abbrev
->name
;
11498 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11501 /* Read dwarf information from a buffer. */
11503 static unsigned int
11504 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11506 return bfd_get_8 (abfd
, buf
);
11510 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11512 return bfd_get_signed_8 (abfd
, buf
);
11515 static unsigned int
11516 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11518 return bfd_get_16 (abfd
, buf
);
11522 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11524 return bfd_get_signed_16 (abfd
, buf
);
11527 static unsigned int
11528 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11530 return bfd_get_32 (abfd
, buf
);
11534 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11536 return bfd_get_signed_32 (abfd
, buf
);
11540 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
11542 return bfd_get_64 (abfd
, buf
);
11546 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
11547 unsigned int *bytes_read
)
11549 struct comp_unit_head
*cu_header
= &cu
->header
;
11550 CORE_ADDR retval
= 0;
11552 if (cu_header
->signed_addr_p
)
11554 switch (cu_header
->addr_size
)
11557 retval
= bfd_get_signed_16 (abfd
, buf
);
11560 retval
= bfd_get_signed_32 (abfd
, buf
);
11563 retval
= bfd_get_signed_64 (abfd
, buf
);
11566 internal_error (__FILE__
, __LINE__
,
11567 _("read_address: bad switch, signed [in module %s]"),
11568 bfd_get_filename (abfd
));
11573 switch (cu_header
->addr_size
)
11576 retval
= bfd_get_16 (abfd
, buf
);
11579 retval
= bfd_get_32 (abfd
, buf
);
11582 retval
= bfd_get_64 (abfd
, buf
);
11585 internal_error (__FILE__
, __LINE__
,
11586 _("read_address: bad switch, "
11587 "unsigned [in module %s]"),
11588 bfd_get_filename (abfd
));
11592 *bytes_read
= cu_header
->addr_size
;
11596 /* Read the initial length from a section. The (draft) DWARF 3
11597 specification allows the initial length to take up either 4 bytes
11598 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
11599 bytes describe the length and all offsets will be 8 bytes in length
11602 An older, non-standard 64-bit format is also handled by this
11603 function. The older format in question stores the initial length
11604 as an 8-byte quantity without an escape value. Lengths greater
11605 than 2^32 aren't very common which means that the initial 4 bytes
11606 is almost always zero. Since a length value of zero doesn't make
11607 sense for the 32-bit format, this initial zero can be considered to
11608 be an escape value which indicates the presence of the older 64-bit
11609 format. As written, the code can't detect (old format) lengths
11610 greater than 4GB. If it becomes necessary to handle lengths
11611 somewhat larger than 4GB, we could allow other small values (such
11612 as the non-sensical values of 1, 2, and 3) to also be used as
11613 escape values indicating the presence of the old format.
11615 The value returned via bytes_read should be used to increment the
11616 relevant pointer after calling read_initial_length().
11618 [ Note: read_initial_length() and read_offset() are based on the
11619 document entitled "DWARF Debugging Information Format", revision
11620 3, draft 8, dated November 19, 2001. This document was obtained
11623 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
11625 This document is only a draft and is subject to change. (So beware.)
11627 Details regarding the older, non-standard 64-bit format were
11628 determined empirically by examining 64-bit ELF files produced by
11629 the SGI toolchain on an IRIX 6.5 machine.
11631 - Kevin, July 16, 2002
11635 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
11637 LONGEST length
= bfd_get_32 (abfd
, buf
);
11639 if (length
== 0xffffffff)
11641 length
= bfd_get_64 (abfd
, buf
+ 4);
11644 else if (length
== 0)
11646 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
11647 length
= bfd_get_64 (abfd
, buf
);
11658 /* Cover function for read_initial_length.
11659 Returns the length of the object at BUF, and stores the size of the
11660 initial length in *BYTES_READ and stores the size that offsets will be in
11662 If the initial length size is not equivalent to that specified in
11663 CU_HEADER then issue a complaint.
11664 This is useful when reading non-comp-unit headers. */
11667 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
11668 const struct comp_unit_head
*cu_header
,
11669 unsigned int *bytes_read
,
11670 unsigned int *offset_size
)
11672 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
11674 gdb_assert (cu_header
->initial_length_size
== 4
11675 || cu_header
->initial_length_size
== 8
11676 || cu_header
->initial_length_size
== 12);
11678 if (cu_header
->initial_length_size
!= *bytes_read
)
11679 complaint (&symfile_complaints
,
11680 _("intermixed 32-bit and 64-bit DWARF sections"));
11682 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
11686 /* Read an offset from the data stream. The size of the offset is
11687 given by cu_header->offset_size. */
11690 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
11691 unsigned int *bytes_read
)
11693 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
11695 *bytes_read
= cu_header
->offset_size
;
11699 /* Read an offset from the data stream. */
11702 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
11704 LONGEST retval
= 0;
11706 switch (offset_size
)
11709 retval
= bfd_get_32 (abfd
, buf
);
11712 retval
= bfd_get_64 (abfd
, buf
);
11715 internal_error (__FILE__
, __LINE__
,
11716 _("read_offset_1: bad switch [in module %s]"),
11717 bfd_get_filename (abfd
));
11724 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
11726 /* If the size of a host char is 8 bits, we can return a pointer
11727 to the buffer, otherwise we have to copy the data to a buffer
11728 allocated on the temporary obstack. */
11729 gdb_assert (HOST_CHAR_BIT
== 8);
11734 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11736 /* If the size of a host char is 8 bits, we can return a pointer
11737 to the string, otherwise we have to copy the string to a buffer
11738 allocated on the temporary obstack. */
11739 gdb_assert (HOST_CHAR_BIT
== 8);
11742 *bytes_read_ptr
= 1;
11745 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
11746 return (char *) buf
;
11750 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
11752 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
11753 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
11754 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
11755 bfd_get_filename (abfd
));
11756 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
11757 error (_("DW_FORM_strp pointing outside of "
11758 ".debug_str section [in module %s]"),
11759 bfd_get_filename (abfd
));
11760 gdb_assert (HOST_CHAR_BIT
== 8);
11761 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
11763 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
11767 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
11768 const struct comp_unit_head
*cu_header
,
11769 unsigned int *bytes_read_ptr
)
11771 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
11773 return read_indirect_string_at_offset (abfd
, str_offset
);
11777 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11780 unsigned int num_read
;
11782 unsigned char byte
;
11790 byte
= bfd_get_8 (abfd
, buf
);
11793 result
|= ((ULONGEST
) (byte
& 127) << shift
);
11794 if ((byte
& 128) == 0)
11800 *bytes_read_ptr
= num_read
;
11805 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
11808 int i
, shift
, num_read
;
11809 unsigned char byte
;
11817 byte
= bfd_get_8 (abfd
, buf
);
11820 result
|= ((LONGEST
) (byte
& 127) << shift
);
11822 if ((byte
& 128) == 0)
11827 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
11828 result
|= -(((LONGEST
) 1) << shift
);
11829 *bytes_read_ptr
= num_read
;
11833 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
11834 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
11835 ADDR_SIZE is the size of addresses from the CU header. */
11838 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
11840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11841 bfd
*abfd
= objfile
->obfd
;
11842 const gdb_byte
*info_ptr
;
11844 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
11845 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
11846 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
11848 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
11849 error (_("DW_FORM_addr_index pointing outside of "
11850 ".debug_addr section [in module %s]"),
11852 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
11853 + addr_base
+ addr_index
* addr_size
);
11854 if (addr_size
== 4)
11855 return bfd_get_32 (abfd
, info_ptr
);
11857 return bfd_get_64 (abfd
, info_ptr
);
11860 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
11863 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
11865 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
11868 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
11871 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
11872 unsigned int *bytes_read
)
11874 bfd
*abfd
= cu
->objfile
->obfd
;
11875 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
11877 return read_addr_index (cu
, addr_index
);
11880 /* Data structure to pass results from dwarf2_read_addr_index_reader
11881 back to dwarf2_read_addr_index. */
11883 struct dwarf2_read_addr_index_data
11885 ULONGEST addr_base
;
11889 /* die_reader_func for dwarf2_read_addr_index. */
11892 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
11893 gdb_byte
*info_ptr
,
11894 struct die_info
*comp_unit_die
,
11898 struct dwarf2_cu
*cu
= reader
->cu
;
11899 struct dwarf2_read_addr_index_data
*aidata
=
11900 (struct dwarf2_read_addr_index_data
*) data
;
11902 aidata
->addr_base
= cu
->addr_base
;
11903 aidata
->addr_size
= cu
->header
.addr_size
;
11906 /* Given an index in .debug_addr, fetch the value.
11907 NOTE: This can be called during dwarf expression evaluation,
11908 long after the debug information has been read, and thus per_cu->cu
11909 may no longer exist. */
11912 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
11913 unsigned int addr_index
)
11915 struct objfile
*objfile
= per_cu
->objfile
;
11916 struct dwarf2_cu
*cu
= per_cu
->cu
;
11917 ULONGEST addr_base
;
11920 /* This is intended to be called from outside this file. */
11921 dw2_setup (objfile
);
11923 /* We need addr_base and addr_size.
11924 If we don't have PER_CU->cu, we have to get it.
11925 Nasty, but the alternative is storing the needed info in PER_CU,
11926 which at this point doesn't seem justified: it's not clear how frequently
11927 it would get used and it would increase the size of every PER_CU.
11928 Entry points like dwarf2_per_cu_addr_size do a similar thing
11929 so we're not in uncharted territory here.
11930 Alas we need to be a bit more complicated as addr_base is contained
11933 We don't need to read the entire CU(/TU).
11934 We just need the header and top level die.
11935 IWBN to use the aging mechanism to let us lazily later discard the CU.
11936 See however init_cutu_and_read_dies_simple. */
11940 addr_base
= cu
->addr_base
;
11941 addr_size
= cu
->header
.addr_size
;
11945 struct dwarf2_read_addr_index_data aidata
;
11947 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
11949 addr_base
= aidata
.addr_base
;
11950 addr_size
= aidata
.addr_size
;
11953 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
11956 /* Given a DW_AT_str_index, fetch the string. */
11959 read_str_index (const struct die_reader_specs
*reader
,
11960 struct dwarf2_cu
*cu
, ULONGEST str_index
)
11962 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11963 const char *dwo_name
= objfile
->name
;
11964 bfd
*abfd
= objfile
->obfd
;
11965 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
11966 gdb_byte
*info_ptr
;
11967 ULONGEST str_offset
;
11969 dwarf2_read_section (objfile
, §ions
->str
);
11970 dwarf2_read_section (objfile
, §ions
->str_offsets
);
11971 if (sections
->str
.buffer
== NULL
)
11972 error (_("DW_FORM_str_index used without .debug_str.dwo section"
11973 " in CU at offset 0x%lx [in module %s]"),
11974 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11975 if (sections
->str_offsets
.buffer
== NULL
)
11976 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
11977 " in CU at offset 0x%lx [in module %s]"),
11978 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11979 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
11980 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
11981 " section in CU at offset 0x%lx [in module %s]"),
11982 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11983 info_ptr
= (sections
->str_offsets
.buffer
11984 + str_index
* cu
->header
.offset_size
);
11985 if (cu
->header
.offset_size
== 4)
11986 str_offset
= bfd_get_32 (abfd
, info_ptr
);
11988 str_offset
= bfd_get_64 (abfd
, info_ptr
);
11989 if (str_offset
>= sections
->str
.size
)
11990 error (_("Offset from DW_FORM_str_index pointing outside of"
11991 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
11992 (long) cu
->header
.offset
.sect_off
, dwo_name
);
11993 return (char *) (sections
->str
.buffer
+ str_offset
);
11996 /* Return a pointer to just past the end of an LEB128 number in BUF. */
11999 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
12005 byte
= bfd_get_8 (abfd
, buf
);
12007 if ((byte
& 128) == 0)
12012 /* Return the length of an LEB128 number in BUF. */
12015 leb128_size (const gdb_byte
*buf
)
12017 const gdb_byte
*begin
= buf
;
12023 if ((byte
& 128) == 0)
12024 return buf
- begin
;
12029 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12036 cu
->language
= language_c
;
12038 case DW_LANG_C_plus_plus
:
12039 cu
->language
= language_cplus
;
12042 cu
->language
= language_d
;
12044 case DW_LANG_Fortran77
:
12045 case DW_LANG_Fortran90
:
12046 case DW_LANG_Fortran95
:
12047 cu
->language
= language_fortran
;
12050 cu
->language
= language_go
;
12052 case DW_LANG_Mips_Assembler
:
12053 cu
->language
= language_asm
;
12056 cu
->language
= language_java
;
12058 case DW_LANG_Ada83
:
12059 case DW_LANG_Ada95
:
12060 cu
->language
= language_ada
;
12062 case DW_LANG_Modula2
:
12063 cu
->language
= language_m2
;
12065 case DW_LANG_Pascal83
:
12066 cu
->language
= language_pascal
;
12069 cu
->language
= language_objc
;
12071 case DW_LANG_Cobol74
:
12072 case DW_LANG_Cobol85
:
12074 cu
->language
= language_minimal
;
12077 cu
->language_defn
= language_def (cu
->language
);
12080 /* Return the named attribute or NULL if not there. */
12082 static struct attribute
*
12083 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12088 struct attribute
*spec
= NULL
;
12090 for (i
= 0; i
< die
->num_attrs
; ++i
)
12092 if (die
->attrs
[i
].name
== name
)
12093 return &die
->attrs
[i
];
12094 if (die
->attrs
[i
].name
== DW_AT_specification
12095 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12096 spec
= &die
->attrs
[i
];
12102 die
= follow_die_ref (die
, spec
, &cu
);
12108 /* Return the named attribute or NULL if not there,
12109 but do not follow DW_AT_specification, etc.
12110 This is for use in contexts where we're reading .debug_types dies.
12111 Following DW_AT_specification, DW_AT_abstract_origin will take us
12112 back up the chain, and we want to go down. */
12114 static struct attribute
*
12115 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12116 struct dwarf2_cu
*cu
)
12120 for (i
= 0; i
< die
->num_attrs
; ++i
)
12121 if (die
->attrs
[i
].name
== name
)
12122 return &die
->attrs
[i
];
12127 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12128 and holds a non-zero value. This function should only be used for
12129 DW_FORM_flag or DW_FORM_flag_present attributes. */
12132 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12134 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12136 return (attr
&& DW_UNSND (attr
));
12140 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12142 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12143 which value is non-zero. However, we have to be careful with
12144 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12145 (via dwarf2_flag_true_p) follows this attribute. So we may
12146 end up accidently finding a declaration attribute that belongs
12147 to a different DIE referenced by the specification attribute,
12148 even though the given DIE does not have a declaration attribute. */
12149 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12150 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12153 /* Return the die giving the specification for DIE, if there is
12154 one. *SPEC_CU is the CU containing DIE on input, and the CU
12155 containing the return value on output. If there is no
12156 specification, but there is an abstract origin, that is
12159 static struct die_info
*
12160 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12162 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12165 if (spec_attr
== NULL
)
12166 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12168 if (spec_attr
== NULL
)
12171 return follow_die_ref (die
, spec_attr
, spec_cu
);
12174 /* Free the line_header structure *LH, and any arrays and strings it
12176 NOTE: This is also used as a "cleanup" function. */
12179 free_line_header (struct line_header
*lh
)
12181 if (lh
->standard_opcode_lengths
)
12182 xfree (lh
->standard_opcode_lengths
);
12184 /* Remember that all the lh->file_names[i].name pointers are
12185 pointers into debug_line_buffer, and don't need to be freed. */
12186 if (lh
->file_names
)
12187 xfree (lh
->file_names
);
12189 /* Similarly for the include directory names. */
12190 if (lh
->include_dirs
)
12191 xfree (lh
->include_dirs
);
12196 /* Add an entry to LH's include directory table. */
12199 add_include_dir (struct line_header
*lh
, char *include_dir
)
12201 /* Grow the array if necessary. */
12202 if (lh
->include_dirs_size
== 0)
12204 lh
->include_dirs_size
= 1; /* for testing */
12205 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12206 * sizeof (*lh
->include_dirs
));
12208 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12210 lh
->include_dirs_size
*= 2;
12211 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12212 (lh
->include_dirs_size
12213 * sizeof (*lh
->include_dirs
)));
12216 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12219 /* Add an entry to LH's file name table. */
12222 add_file_name (struct line_header
*lh
,
12224 unsigned int dir_index
,
12225 unsigned int mod_time
,
12226 unsigned int length
)
12228 struct file_entry
*fe
;
12230 /* Grow the array if necessary. */
12231 if (lh
->file_names_size
== 0)
12233 lh
->file_names_size
= 1; /* for testing */
12234 lh
->file_names
= xmalloc (lh
->file_names_size
12235 * sizeof (*lh
->file_names
));
12237 else if (lh
->num_file_names
>= lh
->file_names_size
)
12239 lh
->file_names_size
*= 2;
12240 lh
->file_names
= xrealloc (lh
->file_names
,
12241 (lh
->file_names_size
12242 * sizeof (*lh
->file_names
)));
12245 fe
= &lh
->file_names
[lh
->num_file_names
++];
12247 fe
->dir_index
= dir_index
;
12248 fe
->mod_time
= mod_time
;
12249 fe
->length
= length
;
12250 fe
->included_p
= 0;
12254 /* Read the statement program header starting at OFFSET in
12255 .debug_line, or .debug_line.dwo. Return a pointer
12256 to a struct line_header, allocated using xmalloc.
12258 NOTE: the strings in the include directory and file name tables of
12259 the returned object point into the dwarf line section buffer,
12260 and must not be freed. */
12262 static struct line_header
*
12263 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12265 struct cleanup
*back_to
;
12266 struct line_header
*lh
;
12267 gdb_byte
*line_ptr
;
12268 unsigned int bytes_read
, offset_size
;
12270 char *cur_dir
, *cur_file
;
12271 struct dwarf2_section_info
*section
;
12274 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12276 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12277 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12279 section
= &dwarf2_per_objfile
->line
;
12281 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12282 if (section
->buffer
== NULL
)
12284 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12285 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12287 complaint (&symfile_complaints
, _("missing .debug_line section"));
12291 /* We can't do this until we know the section is non-empty.
12292 Only then do we know we have such a section. */
12293 abfd
= section
->asection
->owner
;
12295 /* Make sure that at least there's room for the total_length field.
12296 That could be 12 bytes long, but we're just going to fudge that. */
12297 if (offset
+ 4 >= section
->size
)
12299 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12303 lh
= xmalloc (sizeof (*lh
));
12304 memset (lh
, 0, sizeof (*lh
));
12305 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12308 line_ptr
= section
->buffer
+ offset
;
12310 /* Read in the header. */
12312 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12313 &bytes_read
, &offset_size
);
12314 line_ptr
+= bytes_read
;
12315 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12317 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12320 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12321 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12323 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12324 line_ptr
+= offset_size
;
12325 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12327 if (lh
->version
>= 4)
12329 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12333 lh
->maximum_ops_per_instruction
= 1;
12335 if (lh
->maximum_ops_per_instruction
== 0)
12337 lh
->maximum_ops_per_instruction
= 1;
12338 complaint (&symfile_complaints
,
12339 _("invalid maximum_ops_per_instruction "
12340 "in `.debug_line' section"));
12343 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12345 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12347 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12349 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12351 lh
->standard_opcode_lengths
12352 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12354 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12355 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12357 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12361 /* Read directory table. */
12362 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12364 line_ptr
+= bytes_read
;
12365 add_include_dir (lh
, cur_dir
);
12367 line_ptr
+= bytes_read
;
12369 /* Read file name table. */
12370 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12372 unsigned int dir_index
, mod_time
, length
;
12374 line_ptr
+= bytes_read
;
12375 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12376 line_ptr
+= bytes_read
;
12377 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12378 line_ptr
+= bytes_read
;
12379 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12380 line_ptr
+= bytes_read
;
12382 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12384 line_ptr
+= bytes_read
;
12385 lh
->statement_program_start
= line_ptr
;
12387 if (line_ptr
> (section
->buffer
+ section
->size
))
12388 complaint (&symfile_complaints
,
12389 _("line number info header doesn't "
12390 "fit in `.debug_line' section"));
12392 discard_cleanups (back_to
);
12396 /* Subroutine of dwarf_decode_lines to simplify it.
12397 Return the file name of the psymtab for included file FILE_INDEX
12398 in line header LH of PST.
12399 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12400 If space for the result is malloc'd, it will be freed by a cleanup.
12401 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12404 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12405 const struct partial_symtab
*pst
,
12406 const char *comp_dir
)
12408 const struct file_entry fe
= lh
->file_names
[file_index
];
12409 char *include_name
= fe
.name
;
12410 char *include_name_to_compare
= include_name
;
12411 char *dir_name
= NULL
;
12412 const char *pst_filename
;
12413 char *copied_name
= NULL
;
12417 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12419 if (!IS_ABSOLUTE_PATH (include_name
)
12420 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12422 /* Avoid creating a duplicate psymtab for PST.
12423 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12424 Before we do the comparison, however, we need to account
12425 for DIR_NAME and COMP_DIR.
12426 First prepend dir_name (if non-NULL). If we still don't
12427 have an absolute path prepend comp_dir (if non-NULL).
12428 However, the directory we record in the include-file's
12429 psymtab does not contain COMP_DIR (to match the
12430 corresponding symtab(s)).
12435 bash$ gcc -g ./hello.c
12436 include_name = "hello.c"
12438 DW_AT_comp_dir = comp_dir = "/tmp"
12439 DW_AT_name = "./hello.c" */
12441 if (dir_name
!= NULL
)
12443 include_name
= concat (dir_name
, SLASH_STRING
,
12444 include_name
, (char *)NULL
);
12445 include_name_to_compare
= include_name
;
12446 make_cleanup (xfree
, include_name
);
12448 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12450 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12451 include_name
, (char *)NULL
);
12455 pst_filename
= pst
->filename
;
12456 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12458 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12459 pst_filename
, (char *)NULL
);
12460 pst_filename
= copied_name
;
12463 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12465 if (include_name_to_compare
!= include_name
)
12466 xfree (include_name_to_compare
);
12467 if (copied_name
!= NULL
)
12468 xfree (copied_name
);
12472 return include_name
;
12475 /* Ignore this record_line request. */
12478 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12483 /* Subroutine of dwarf_decode_lines to simplify it.
12484 Process the line number information in LH. */
12487 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12488 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12490 gdb_byte
*line_ptr
, *extended_end
;
12491 gdb_byte
*line_end
;
12492 unsigned int bytes_read
, extended_len
;
12493 unsigned char op_code
, extended_op
, adj_opcode
;
12494 CORE_ADDR baseaddr
;
12495 struct objfile
*objfile
= cu
->objfile
;
12496 bfd
*abfd
= objfile
->obfd
;
12497 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12498 const int decode_for_pst_p
= (pst
!= NULL
);
12499 struct subfile
*last_subfile
= NULL
;
12500 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12503 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12505 line_ptr
= lh
->statement_program_start
;
12506 line_end
= lh
->statement_program_end
;
12508 /* Read the statement sequences until there's nothing left. */
12509 while (line_ptr
< line_end
)
12511 /* state machine registers */
12512 CORE_ADDR address
= 0;
12513 unsigned int file
= 1;
12514 unsigned int line
= 1;
12515 unsigned int column
= 0;
12516 int is_stmt
= lh
->default_is_stmt
;
12517 int basic_block
= 0;
12518 int end_sequence
= 0;
12520 unsigned char op_index
= 0;
12522 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12524 /* Start a subfile for the current file of the state machine. */
12525 /* lh->include_dirs and lh->file_names are 0-based, but the
12526 directory and file name numbers in the statement program
12528 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12532 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12534 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12537 /* Decode the table. */
12538 while (!end_sequence
)
12540 op_code
= read_1_byte (abfd
, line_ptr
);
12542 if (line_ptr
> line_end
)
12544 dwarf2_debug_line_missing_end_sequence_complaint ();
12548 if (op_code
>= lh
->opcode_base
)
12550 /* Special operand. */
12551 adj_opcode
= op_code
- lh
->opcode_base
;
12552 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
12553 / lh
->maximum_ops_per_instruction
)
12554 * lh
->minimum_instruction_length
);
12555 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
12556 % lh
->maximum_ops_per_instruction
);
12557 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
12558 if (lh
->num_file_names
< file
|| file
== 0)
12559 dwarf2_debug_line_missing_file_complaint ();
12560 /* For now we ignore lines not starting on an
12561 instruction boundary. */
12562 else if (op_index
== 0)
12564 lh
->file_names
[file
- 1].included_p
= 1;
12565 if (!decode_for_pst_p
&& is_stmt
)
12567 if (last_subfile
!= current_subfile
)
12569 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12571 (*p_record_line
) (last_subfile
, 0, addr
);
12572 last_subfile
= current_subfile
;
12574 /* Append row to matrix using current values. */
12575 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12576 (*p_record_line
) (current_subfile
, line
, addr
);
12581 else switch (op_code
)
12583 case DW_LNS_extended_op
:
12584 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
12586 line_ptr
+= bytes_read
;
12587 extended_end
= line_ptr
+ extended_len
;
12588 extended_op
= read_1_byte (abfd
, line_ptr
);
12590 switch (extended_op
)
12592 case DW_LNE_end_sequence
:
12593 p_record_line
= record_line
;
12596 case DW_LNE_set_address
:
12597 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
12599 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12601 /* This line table is for a function which has been
12602 GCd by the linker. Ignore it. PR gdb/12528 */
12605 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
12607 complaint (&symfile_complaints
,
12608 _(".debug_line address at offset 0x%lx is 0 "
12610 line_offset
, objfile
->name
);
12611 p_record_line
= noop_record_line
;
12615 line_ptr
+= bytes_read
;
12616 address
+= baseaddr
;
12618 case DW_LNE_define_file
:
12621 unsigned int dir_index
, mod_time
, length
;
12623 cur_file
= read_direct_string (abfd
, line_ptr
,
12625 line_ptr
+= bytes_read
;
12627 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12628 line_ptr
+= bytes_read
;
12630 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12631 line_ptr
+= bytes_read
;
12633 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12634 line_ptr
+= bytes_read
;
12635 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12638 case DW_LNE_set_discriminator
:
12639 /* The discriminator is not interesting to the debugger;
12641 line_ptr
= extended_end
;
12644 complaint (&symfile_complaints
,
12645 _("mangled .debug_line section"));
12648 /* Make sure that we parsed the extended op correctly. If e.g.
12649 we expected a different address size than the producer used,
12650 we may have read the wrong number of bytes. */
12651 if (line_ptr
!= extended_end
)
12653 complaint (&symfile_complaints
,
12654 _("mangled .debug_line section"));
12659 if (lh
->num_file_names
< file
|| file
== 0)
12660 dwarf2_debug_line_missing_file_complaint ();
12663 lh
->file_names
[file
- 1].included_p
= 1;
12664 if (!decode_for_pst_p
&& is_stmt
)
12666 if (last_subfile
!= current_subfile
)
12668 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12670 (*p_record_line
) (last_subfile
, 0, addr
);
12671 last_subfile
= current_subfile
;
12673 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12674 (*p_record_line
) (current_subfile
, line
, addr
);
12679 case DW_LNS_advance_pc
:
12682 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12684 address
+= (((op_index
+ adjust
)
12685 / lh
->maximum_ops_per_instruction
)
12686 * lh
->minimum_instruction_length
);
12687 op_index
= ((op_index
+ adjust
)
12688 % lh
->maximum_ops_per_instruction
);
12689 line_ptr
+= bytes_read
;
12692 case DW_LNS_advance_line
:
12693 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
12694 line_ptr
+= bytes_read
;
12696 case DW_LNS_set_file
:
12698 /* The arrays lh->include_dirs and lh->file_names are
12699 0-based, but the directory and file name numbers in
12700 the statement program are 1-based. */
12701 struct file_entry
*fe
;
12704 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12705 line_ptr
+= bytes_read
;
12706 if (lh
->num_file_names
< file
|| file
== 0)
12707 dwarf2_debug_line_missing_file_complaint ();
12710 fe
= &lh
->file_names
[file
- 1];
12712 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12713 if (!decode_for_pst_p
)
12715 last_subfile
= current_subfile
;
12716 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12721 case DW_LNS_set_column
:
12722 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12723 line_ptr
+= bytes_read
;
12725 case DW_LNS_negate_stmt
:
12726 is_stmt
= (!is_stmt
);
12728 case DW_LNS_set_basic_block
:
12731 /* Add to the address register of the state machine the
12732 address increment value corresponding to special opcode
12733 255. I.e., this value is scaled by the minimum
12734 instruction length since special opcode 255 would have
12735 scaled the increment. */
12736 case DW_LNS_const_add_pc
:
12738 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
12740 address
+= (((op_index
+ adjust
)
12741 / lh
->maximum_ops_per_instruction
)
12742 * lh
->minimum_instruction_length
);
12743 op_index
= ((op_index
+ adjust
)
12744 % lh
->maximum_ops_per_instruction
);
12747 case DW_LNS_fixed_advance_pc
:
12748 address
+= read_2_bytes (abfd
, line_ptr
);
12754 /* Unknown standard opcode, ignore it. */
12757 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
12759 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12760 line_ptr
+= bytes_read
;
12765 if (lh
->num_file_names
< file
|| file
== 0)
12766 dwarf2_debug_line_missing_file_complaint ();
12769 lh
->file_names
[file
- 1].included_p
= 1;
12770 if (!decode_for_pst_p
)
12772 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
12773 (*p_record_line
) (current_subfile
, 0, addr
);
12779 /* Decode the Line Number Program (LNP) for the given line_header
12780 structure and CU. The actual information extracted and the type
12781 of structures created from the LNP depends on the value of PST.
12783 1. If PST is NULL, then this procedure uses the data from the program
12784 to create all necessary symbol tables, and their linetables.
12786 2. If PST is not NULL, this procedure reads the program to determine
12787 the list of files included by the unit represented by PST, and
12788 builds all the associated partial symbol tables.
12790 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12791 It is used for relative paths in the line table.
12792 NOTE: When processing partial symtabs (pst != NULL),
12793 comp_dir == pst->dirname.
12795 NOTE: It is important that psymtabs have the same file name (via strcmp)
12796 as the corresponding symtab. Since COMP_DIR is not used in the name of the
12797 symtab we don't use it in the name of the psymtabs we create.
12798 E.g. expand_line_sal requires this when finding psymtabs to expand.
12799 A good testcase for this is mb-inline.exp. */
12802 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
12803 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
12804 int want_line_info
)
12806 struct objfile
*objfile
= cu
->objfile
;
12807 const int decode_for_pst_p
= (pst
!= NULL
);
12808 struct subfile
*first_subfile
= current_subfile
;
12810 if (want_line_info
)
12811 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
12813 if (decode_for_pst_p
)
12817 /* Now that we're done scanning the Line Header Program, we can
12818 create the psymtab of each included file. */
12819 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
12820 if (lh
->file_names
[file_index
].included_p
== 1)
12822 char *include_name
=
12823 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
12824 if (include_name
!= NULL
)
12825 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
12830 /* Make sure a symtab is created for every file, even files
12831 which contain only variables (i.e. no code with associated
12835 for (i
= 0; i
< lh
->num_file_names
; i
++)
12838 struct file_entry
*fe
;
12840 fe
= &lh
->file_names
[i
];
12842 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12843 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12845 /* Skip the main file; we don't need it, and it must be
12846 allocated last, so that it will show up before the
12847 non-primary symtabs in the objfile's symtab list. */
12848 if (current_subfile
== first_subfile
)
12851 if (current_subfile
->symtab
== NULL
)
12852 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
12854 fe
->symtab
= current_subfile
->symtab
;
12859 /* Start a subfile for DWARF. FILENAME is the name of the file and
12860 DIRNAME the name of the source directory which contains FILENAME
12861 or NULL if not known. COMP_DIR is the compilation directory for the
12862 linetable's compilation unit or NULL if not known.
12863 This routine tries to keep line numbers from identical absolute and
12864 relative file names in a common subfile.
12866 Using the `list' example from the GDB testsuite, which resides in
12867 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
12868 of /srcdir/list0.c yields the following debugging information for list0.c:
12870 DW_AT_name: /srcdir/list0.c
12871 DW_AT_comp_dir: /compdir
12872 files.files[0].name: list0.h
12873 files.files[0].dir: /srcdir
12874 files.files[1].name: list0.c
12875 files.files[1].dir: /srcdir
12877 The line number information for list0.c has to end up in a single
12878 subfile, so that `break /srcdir/list0.c:1' works as expected.
12879 start_subfile will ensure that this happens provided that we pass the
12880 concatenation of files.files[1].dir and files.files[1].name as the
12884 dwarf2_start_subfile (char *filename
, const char *dirname
,
12885 const char *comp_dir
)
12889 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
12890 `start_symtab' will always pass the contents of DW_AT_comp_dir as
12891 second argument to start_subfile. To be consistent, we do the
12892 same here. In order not to lose the line information directory,
12893 we concatenate it to the filename when it makes sense.
12894 Note that the Dwarf3 standard says (speaking of filenames in line
12895 information): ``The directory index is ignored for file names
12896 that represent full path names''. Thus ignoring dirname in the
12897 `else' branch below isn't an issue. */
12899 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
12900 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
12902 fullname
= filename
;
12904 start_subfile (fullname
, comp_dir
);
12906 if (fullname
!= filename
)
12911 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
12912 struct dwarf2_cu
*cu
)
12914 struct objfile
*objfile
= cu
->objfile
;
12915 struct comp_unit_head
*cu_header
= &cu
->header
;
12917 /* NOTE drow/2003-01-30: There used to be a comment and some special
12918 code here to turn a symbol with DW_AT_external and a
12919 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
12920 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
12921 with some versions of binutils) where shared libraries could have
12922 relocations against symbols in their debug information - the
12923 minimal symbol would have the right address, but the debug info
12924 would not. It's no longer necessary, because we will explicitly
12925 apply relocations when we read in the debug information now. */
12927 /* A DW_AT_location attribute with no contents indicates that a
12928 variable has been optimized away. */
12929 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
12931 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
12935 /* Handle one degenerate form of location expression specially, to
12936 preserve GDB's previous behavior when section offsets are
12937 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
12938 then mark this symbol as LOC_STATIC. */
12940 if (attr_form_is_block (attr
)
12941 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
12942 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
12943 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
12944 && (DW_BLOCK (attr
)->size
12945 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
12947 unsigned int dummy
;
12949 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
12950 SYMBOL_VALUE_ADDRESS (sym
) =
12951 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
12953 SYMBOL_VALUE_ADDRESS (sym
) =
12954 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
12955 SYMBOL_CLASS (sym
) = LOC_STATIC
;
12956 fixup_symbol_section (sym
, objfile
);
12957 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
12958 SYMBOL_SECTION (sym
));
12962 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
12963 expression evaluator, and use LOC_COMPUTED only when necessary
12964 (i.e. when the value of a register or memory location is
12965 referenced, or a thread-local block, etc.). Then again, it might
12966 not be worthwhile. I'm assuming that it isn't unless performance
12967 or memory numbers show me otherwise. */
12969 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
12970 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
12972 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
12973 cu
->has_loclist
= 1;
12976 /* Given a pointer to a DWARF information entry, figure out if we need
12977 to make a symbol table entry for it, and if so, create a new entry
12978 and return a pointer to it.
12979 If TYPE is NULL, determine symbol type from the die, otherwise
12980 used the passed type.
12981 If SPACE is not NULL, use it to hold the new symbol. If it is
12982 NULL, allocate a new symbol on the objfile's obstack. */
12984 static struct symbol
*
12985 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
12986 struct symbol
*space
)
12988 struct objfile
*objfile
= cu
->objfile
;
12989 struct symbol
*sym
= NULL
;
12991 struct attribute
*attr
= NULL
;
12992 struct attribute
*attr2
= NULL
;
12993 CORE_ADDR baseaddr
;
12994 struct pending
**list_to_add
= NULL
;
12996 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12998 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13000 name
= dwarf2_name (die
, cu
);
13003 const char *linkagename
;
13004 int suppress_add
= 0;
13009 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13010 OBJSTAT (objfile
, n_syms
++);
13012 /* Cache this symbol's name and the name's demangled form (if any). */
13013 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13014 linkagename
= dwarf2_physname (name
, die
, cu
);
13015 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13017 /* Fortran does not have mangling standard and the mangling does differ
13018 between gfortran, iFort etc. */
13019 if (cu
->language
== language_fortran
13020 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13021 symbol_set_demangled_name (&(sym
->ginfo
),
13022 (char *) dwarf2_full_name (name
, die
, cu
),
13025 /* Default assumptions.
13026 Use the passed type or decode it from the die. */
13027 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13028 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13030 SYMBOL_TYPE (sym
) = type
;
13032 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13033 attr
= dwarf2_attr (die
,
13034 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13038 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13041 attr
= dwarf2_attr (die
,
13042 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13046 int file_index
= DW_UNSND (attr
);
13048 if (cu
->line_header
== NULL
13049 || file_index
> cu
->line_header
->num_file_names
)
13050 complaint (&symfile_complaints
,
13051 _("file index out of range"));
13052 else if (file_index
> 0)
13054 struct file_entry
*fe
;
13056 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13057 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13064 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13067 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13069 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13070 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13071 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13072 add_symbol_to_list (sym
, cu
->list_in_scope
);
13074 case DW_TAG_subprogram
:
13075 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13077 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13078 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13079 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13080 || cu
->language
== language_ada
)
13082 /* Subprograms marked external are stored as a global symbol.
13083 Ada subprograms, whether marked external or not, are always
13084 stored as a global symbol, because we want to be able to
13085 access them globally. For instance, we want to be able
13086 to break on a nested subprogram without having to
13087 specify the context. */
13088 list_to_add
= &global_symbols
;
13092 list_to_add
= cu
->list_in_scope
;
13095 case DW_TAG_inlined_subroutine
:
13096 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13098 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13099 SYMBOL_INLINED (sym
) = 1;
13100 list_to_add
= cu
->list_in_scope
;
13102 case DW_TAG_template_value_param
:
13104 /* Fall through. */
13105 case DW_TAG_constant
:
13106 case DW_TAG_variable
:
13107 case DW_TAG_member
:
13108 /* Compilation with minimal debug info may result in
13109 variables with missing type entries. Change the
13110 misleading `void' type to something sensible. */
13111 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13113 = objfile_type (objfile
)->nodebug_data_symbol
;
13115 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13116 /* In the case of DW_TAG_member, we should only be called for
13117 static const members. */
13118 if (die
->tag
== DW_TAG_member
)
13120 /* dwarf2_add_field uses die_is_declaration,
13121 so we do the same. */
13122 gdb_assert (die_is_declaration (die
, cu
));
13127 dwarf2_const_value (attr
, sym
, cu
);
13128 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13131 if (attr2
&& (DW_UNSND (attr2
) != 0))
13132 list_to_add
= &global_symbols
;
13134 list_to_add
= cu
->list_in_scope
;
13138 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13141 var_decode_location (attr
, sym
, cu
);
13142 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13143 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13144 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13145 && !dwarf2_per_objfile
->has_section_at_zero
)
13147 /* When a static variable is eliminated by the linker,
13148 the corresponding debug information is not stripped
13149 out, but the variable address is set to null;
13150 do not add such variables into symbol table. */
13152 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13154 /* Workaround gfortran PR debug/40040 - it uses
13155 DW_AT_location for variables in -fPIC libraries which may
13156 get overriden by other libraries/executable and get
13157 a different address. Resolve it by the minimal symbol
13158 which may come from inferior's executable using copy
13159 relocation. Make this workaround only for gfortran as for
13160 other compilers GDB cannot guess the minimal symbol
13161 Fortran mangling kind. */
13162 if (cu
->language
== language_fortran
&& die
->parent
13163 && die
->parent
->tag
== DW_TAG_module
13165 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13166 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13168 /* A variable with DW_AT_external is never static,
13169 but it may be block-scoped. */
13170 list_to_add
= (cu
->list_in_scope
== &file_symbols
13171 ? &global_symbols
: cu
->list_in_scope
);
13174 list_to_add
= cu
->list_in_scope
;
13178 /* We do not know the address of this symbol.
13179 If it is an external symbol and we have type information
13180 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13181 The address of the variable will then be determined from
13182 the minimal symbol table whenever the variable is
13184 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13185 if (attr2
&& (DW_UNSND (attr2
) != 0)
13186 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13188 /* A variable with DW_AT_external is never static, but it
13189 may be block-scoped. */
13190 list_to_add
= (cu
->list_in_scope
== &file_symbols
13191 ? &global_symbols
: cu
->list_in_scope
);
13193 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13195 else if (!die_is_declaration (die
, cu
))
13197 /* Use the default LOC_OPTIMIZED_OUT class. */
13198 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13200 list_to_add
= cu
->list_in_scope
;
13204 case DW_TAG_formal_parameter
:
13205 /* If we are inside a function, mark this as an argument. If
13206 not, we might be looking at an argument to an inlined function
13207 when we do not have enough information to show inlined frames;
13208 pretend it's a local variable in that case so that the user can
13210 if (context_stack_depth
> 0
13211 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13212 SYMBOL_IS_ARGUMENT (sym
) = 1;
13213 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13216 var_decode_location (attr
, sym
, cu
);
13218 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13221 dwarf2_const_value (attr
, sym
, cu
);
13224 list_to_add
= cu
->list_in_scope
;
13226 case DW_TAG_unspecified_parameters
:
13227 /* From varargs functions; gdb doesn't seem to have any
13228 interest in this information, so just ignore it for now.
13231 case DW_TAG_template_type_param
:
13233 /* Fall through. */
13234 case DW_TAG_class_type
:
13235 case DW_TAG_interface_type
:
13236 case DW_TAG_structure_type
:
13237 case DW_TAG_union_type
:
13238 case DW_TAG_set_type
:
13239 case DW_TAG_enumeration_type
:
13240 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13241 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13244 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13245 really ever be static objects: otherwise, if you try
13246 to, say, break of a class's method and you're in a file
13247 which doesn't mention that class, it won't work unless
13248 the check for all static symbols in lookup_symbol_aux
13249 saves you. See the OtherFileClass tests in
13250 gdb.c++/namespace.exp. */
13254 list_to_add
= (cu
->list_in_scope
== &file_symbols
13255 && (cu
->language
== language_cplus
13256 || cu
->language
== language_java
)
13257 ? &global_symbols
: cu
->list_in_scope
);
13259 /* The semantics of C++ state that "struct foo {
13260 ... }" also defines a typedef for "foo". A Java
13261 class declaration also defines a typedef for the
13263 if (cu
->language
== language_cplus
13264 || cu
->language
== language_java
13265 || cu
->language
== language_ada
)
13267 /* The symbol's name is already allocated along
13268 with this objfile, so we don't need to
13269 duplicate it for the type. */
13270 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13271 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13276 case DW_TAG_typedef
:
13277 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13278 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13279 list_to_add
= cu
->list_in_scope
;
13281 case DW_TAG_base_type
:
13282 case DW_TAG_subrange_type
:
13283 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13284 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13285 list_to_add
= cu
->list_in_scope
;
13287 case DW_TAG_enumerator
:
13288 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13291 dwarf2_const_value (attr
, sym
, cu
);
13294 /* NOTE: carlton/2003-11-10: See comment above in the
13295 DW_TAG_class_type, etc. block. */
13297 list_to_add
= (cu
->list_in_scope
== &file_symbols
13298 && (cu
->language
== language_cplus
13299 || cu
->language
== language_java
)
13300 ? &global_symbols
: cu
->list_in_scope
);
13303 case DW_TAG_namespace
:
13304 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13305 list_to_add
= &global_symbols
;
13308 /* Not a tag we recognize. Hopefully we aren't processing
13309 trash data, but since we must specifically ignore things
13310 we don't recognize, there is nothing else we should do at
13312 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13313 dwarf_tag_name (die
->tag
));
13319 sym
->hash_next
= objfile
->template_symbols
;
13320 objfile
->template_symbols
= sym
;
13321 list_to_add
= NULL
;
13324 if (list_to_add
!= NULL
)
13325 add_symbol_to_list (sym
, list_to_add
);
13327 /* For the benefit of old versions of GCC, check for anonymous
13328 namespaces based on the demangled name. */
13329 if (!processing_has_namespace_info
13330 && cu
->language
== language_cplus
)
13331 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13336 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13338 static struct symbol
*
13339 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13341 return new_symbol_full (die
, type
, cu
, NULL
);
13344 /* Given an attr with a DW_FORM_dataN value in host byte order,
13345 zero-extend it as appropriate for the symbol's type. The DWARF
13346 standard (v4) is not entirely clear about the meaning of using
13347 DW_FORM_dataN for a constant with a signed type, where the type is
13348 wider than the data. The conclusion of a discussion on the DWARF
13349 list was that this is unspecified. We choose to always zero-extend
13350 because that is the interpretation long in use by GCC. */
13353 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13354 const char *name
, struct obstack
*obstack
,
13355 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13357 struct objfile
*objfile
= cu
->objfile
;
13358 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13359 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13360 LONGEST l
= DW_UNSND (attr
);
13362 if (bits
< sizeof (*value
) * 8)
13364 l
&= ((LONGEST
) 1 << bits
) - 1;
13367 else if (bits
== sizeof (*value
) * 8)
13371 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13372 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13379 /* Read a constant value from an attribute. Either set *VALUE, or if
13380 the value does not fit in *VALUE, set *BYTES - either already
13381 allocated on the objfile obstack, or newly allocated on OBSTACK,
13382 or, set *BATON, if we translated the constant to a location
13386 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13387 const char *name
, struct obstack
*obstack
,
13388 struct dwarf2_cu
*cu
,
13389 LONGEST
*value
, gdb_byte
**bytes
,
13390 struct dwarf2_locexpr_baton
**baton
)
13392 struct objfile
*objfile
= cu
->objfile
;
13393 struct comp_unit_head
*cu_header
= &cu
->header
;
13394 struct dwarf_block
*blk
;
13395 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13396 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13402 switch (attr
->form
)
13405 case DW_FORM_GNU_addr_index
:
13409 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13410 dwarf2_const_value_length_mismatch_complaint (name
,
13411 cu_header
->addr_size
,
13412 TYPE_LENGTH (type
));
13413 /* Symbols of this form are reasonably rare, so we just
13414 piggyback on the existing location code rather than writing
13415 a new implementation of symbol_computed_ops. */
13416 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13417 sizeof (struct dwarf2_locexpr_baton
));
13418 (*baton
)->per_cu
= cu
->per_cu
;
13419 gdb_assert ((*baton
)->per_cu
);
13421 (*baton
)->size
= 2 + cu_header
->addr_size
;
13422 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13423 (*baton
)->data
= data
;
13425 data
[0] = DW_OP_addr
;
13426 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13427 byte_order
, DW_ADDR (attr
));
13428 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13431 case DW_FORM_string
:
13433 case DW_FORM_GNU_str_index
:
13434 /* DW_STRING is already allocated on the objfile obstack, point
13436 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13438 case DW_FORM_block1
:
13439 case DW_FORM_block2
:
13440 case DW_FORM_block4
:
13441 case DW_FORM_block
:
13442 case DW_FORM_exprloc
:
13443 blk
= DW_BLOCK (attr
);
13444 if (TYPE_LENGTH (type
) != blk
->size
)
13445 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13446 TYPE_LENGTH (type
));
13447 *bytes
= blk
->data
;
13450 /* The DW_AT_const_value attributes are supposed to carry the
13451 symbol's value "represented as it would be on the target
13452 architecture." By the time we get here, it's already been
13453 converted to host endianness, so we just need to sign- or
13454 zero-extend it as appropriate. */
13455 case DW_FORM_data1
:
13456 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13457 obstack
, cu
, value
, 8);
13459 case DW_FORM_data2
:
13460 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13461 obstack
, cu
, value
, 16);
13463 case DW_FORM_data4
:
13464 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13465 obstack
, cu
, value
, 32);
13467 case DW_FORM_data8
:
13468 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13469 obstack
, cu
, value
, 64);
13472 case DW_FORM_sdata
:
13473 *value
= DW_SND (attr
);
13476 case DW_FORM_udata
:
13477 *value
= DW_UNSND (attr
);
13481 complaint (&symfile_complaints
,
13482 _("unsupported const value attribute form: '%s'"),
13483 dwarf_form_name (attr
->form
));
13490 /* Copy constant value from an attribute to a symbol. */
13493 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13494 struct dwarf2_cu
*cu
)
13496 struct objfile
*objfile
= cu
->objfile
;
13497 struct comp_unit_head
*cu_header
= &cu
->header
;
13500 struct dwarf2_locexpr_baton
*baton
;
13502 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13503 SYMBOL_PRINT_NAME (sym
),
13504 &objfile
->objfile_obstack
, cu
,
13505 &value
, &bytes
, &baton
);
13509 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13510 SYMBOL_LOCATION_BATON (sym
) = baton
;
13511 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13513 else if (bytes
!= NULL
)
13515 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13516 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13520 SYMBOL_VALUE (sym
) = value
;
13521 SYMBOL_CLASS (sym
) = LOC_CONST
;
13525 /* Return the type of the die in question using its DW_AT_type attribute. */
13527 static struct type
*
13528 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13530 struct attribute
*type_attr
;
13532 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13535 /* A missing DW_AT_type represents a void type. */
13536 return objfile_type (cu
->objfile
)->builtin_void
;
13539 return lookup_die_type (die
, type_attr
, cu
);
13542 /* True iff CU's producer generates GNAT Ada auxiliary information
13543 that allows to find parallel types through that information instead
13544 of having to do expensive parallel lookups by type name. */
13547 need_gnat_info (struct dwarf2_cu
*cu
)
13549 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
13550 of GNAT produces this auxiliary information, without any indication
13551 that it is produced. Part of enhancing the FSF version of GNAT
13552 to produce that information will be to put in place an indicator
13553 that we can use in order to determine whether the descriptive type
13554 info is available or not. One suggestion that has been made is
13555 to use a new attribute, attached to the CU die. For now, assume
13556 that the descriptive type info is not available. */
13560 /* Return the auxiliary type of the die in question using its
13561 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
13562 attribute is not present. */
13564 static struct type
*
13565 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13567 struct attribute
*type_attr
;
13569 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
13573 return lookup_die_type (die
, type_attr
, cu
);
13576 /* If DIE has a descriptive_type attribute, then set the TYPE's
13577 descriptive type accordingly. */
13580 set_descriptive_type (struct type
*type
, struct die_info
*die
,
13581 struct dwarf2_cu
*cu
)
13583 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
13585 if (descriptive_type
)
13587 ALLOCATE_GNAT_AUX_TYPE (type
);
13588 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
13592 /* Return the containing type of the die in question using its
13593 DW_AT_containing_type attribute. */
13595 static struct type
*
13596 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13598 struct attribute
*type_attr
;
13600 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
13602 error (_("Dwarf Error: Problem turning containing type into gdb type "
13603 "[in module %s]"), cu
->objfile
->name
);
13605 return lookup_die_type (die
, type_attr
, cu
);
13608 /* Look up the type of DIE in CU using its type attribute ATTR.
13609 If there is no type substitute an error marker. */
13611 static struct type
*
13612 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
13613 struct dwarf2_cu
*cu
)
13615 struct objfile
*objfile
= cu
->objfile
;
13616 struct type
*this_type
;
13618 /* First see if we have it cached. */
13620 if (is_ref_attr (attr
))
13622 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
13624 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
13626 else if (attr
->form
== DW_FORM_ref_sig8
)
13628 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13630 /* sig_type will be NULL if the signatured type is missing from
13632 if (sig_type
== NULL
)
13633 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13634 "at 0x%x [in module %s]"),
13635 die
->offset
.sect_off
, objfile
->name
);
13637 gdb_assert (sig_type
->per_cu
.is_debug_types
);
13638 /* If we haven't filled in type_offset_in_section yet, then we
13639 haven't read the type in yet. */
13641 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
13644 get_die_type_at_offset (sig_type
->type_offset_in_section
,
13645 &sig_type
->per_cu
);
13650 dump_die_for_error (die
);
13651 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
13652 dwarf_attr_name (attr
->name
), objfile
->name
);
13655 /* If not cached we need to read it in. */
13657 if (this_type
== NULL
)
13659 struct die_info
*type_die
;
13660 struct dwarf2_cu
*type_cu
= cu
;
13662 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
13663 /* If we found the type now, it's probably because the type came
13664 from an inter-CU reference and the type's CU got expanded before
13666 this_type
= get_die_type (type_die
, type_cu
);
13667 if (this_type
== NULL
)
13668 this_type
= read_type_die_1 (type_die
, type_cu
);
13671 /* If we still don't have a type use an error marker. */
13673 if (this_type
== NULL
)
13675 char *message
, *saved
;
13677 /* read_type_die already issued a complaint. */
13678 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
13680 cu
->header
.offset
.sect_off
,
13681 die
->offset
.sect_off
);
13682 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
13683 message
, strlen (message
));
13686 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
13692 /* Return the type in DIE, CU.
13693 Returns NULL for invalid types.
13695 This first does a lookup in the appropriate type_hash table,
13696 and only reads the die in if necessary.
13698 NOTE: This can be called when reading in partial or full symbols. */
13700 static struct type
*
13701 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
13703 struct type
*this_type
;
13705 this_type
= get_die_type (die
, cu
);
13709 return read_type_die_1 (die
, cu
);
13712 /* Read the type in DIE, CU.
13713 Returns NULL for invalid types. */
13715 static struct type
*
13716 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
13718 struct type
*this_type
= NULL
;
13722 case DW_TAG_class_type
:
13723 case DW_TAG_interface_type
:
13724 case DW_TAG_structure_type
:
13725 case DW_TAG_union_type
:
13726 this_type
= read_structure_type (die
, cu
);
13728 case DW_TAG_enumeration_type
:
13729 this_type
= read_enumeration_type (die
, cu
);
13731 case DW_TAG_subprogram
:
13732 case DW_TAG_subroutine_type
:
13733 case DW_TAG_inlined_subroutine
:
13734 this_type
= read_subroutine_type (die
, cu
);
13736 case DW_TAG_array_type
:
13737 this_type
= read_array_type (die
, cu
);
13739 case DW_TAG_set_type
:
13740 this_type
= read_set_type (die
, cu
);
13742 case DW_TAG_pointer_type
:
13743 this_type
= read_tag_pointer_type (die
, cu
);
13745 case DW_TAG_ptr_to_member_type
:
13746 this_type
= read_tag_ptr_to_member_type (die
, cu
);
13748 case DW_TAG_reference_type
:
13749 this_type
= read_tag_reference_type (die
, cu
);
13751 case DW_TAG_const_type
:
13752 this_type
= read_tag_const_type (die
, cu
);
13754 case DW_TAG_volatile_type
:
13755 this_type
= read_tag_volatile_type (die
, cu
);
13757 case DW_TAG_string_type
:
13758 this_type
= read_tag_string_type (die
, cu
);
13760 case DW_TAG_typedef
:
13761 this_type
= read_typedef (die
, cu
);
13763 case DW_TAG_subrange_type
:
13764 this_type
= read_subrange_type (die
, cu
);
13766 case DW_TAG_base_type
:
13767 this_type
= read_base_type (die
, cu
);
13769 case DW_TAG_unspecified_type
:
13770 this_type
= read_unspecified_type (die
, cu
);
13772 case DW_TAG_namespace
:
13773 this_type
= read_namespace_type (die
, cu
);
13775 case DW_TAG_module
:
13776 this_type
= read_module_type (die
, cu
);
13779 complaint (&symfile_complaints
,
13780 _("unexpected tag in read_type_die: '%s'"),
13781 dwarf_tag_name (die
->tag
));
13788 /* See if we can figure out if the class lives in a namespace. We do
13789 this by looking for a member function; its demangled name will
13790 contain namespace info, if there is any.
13791 Return the computed name or NULL.
13792 Space for the result is allocated on the objfile's obstack.
13793 This is the full-die version of guess_partial_die_structure_name.
13794 In this case we know DIE has no useful parent. */
13797 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
13799 struct die_info
*spec_die
;
13800 struct dwarf2_cu
*spec_cu
;
13801 struct die_info
*child
;
13804 spec_die
= die_specification (die
, &spec_cu
);
13805 if (spec_die
!= NULL
)
13811 for (child
= die
->child
;
13813 child
= child
->sibling
)
13815 if (child
->tag
== DW_TAG_subprogram
)
13817 struct attribute
*attr
;
13819 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
13821 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
13825 = language_class_name_from_physname (cu
->language_defn
,
13829 if (actual_name
!= NULL
)
13831 char *die_name
= dwarf2_name (die
, cu
);
13833 if (die_name
!= NULL
13834 && strcmp (die_name
, actual_name
) != 0)
13836 /* Strip off the class name from the full name.
13837 We want the prefix. */
13838 int die_name_len
= strlen (die_name
);
13839 int actual_name_len
= strlen (actual_name
);
13841 /* Test for '::' as a sanity check. */
13842 if (actual_name_len
> die_name_len
+ 2
13843 && actual_name
[actual_name_len
13844 - die_name_len
- 1] == ':')
13846 obsavestring (actual_name
,
13847 actual_name_len
- die_name_len
- 2,
13848 &cu
->objfile
->objfile_obstack
);
13851 xfree (actual_name
);
13860 /* GCC might emit a nameless typedef that has a linkage name. Determine the
13861 prefix part in such case. See
13862 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13865 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
13867 struct attribute
*attr
;
13870 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
13871 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
13874 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
13875 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
13878 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
13880 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
13881 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
13884 /* dwarf2_name had to be already called. */
13885 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
13887 /* Strip the base name, keep any leading namespaces/classes. */
13888 base
= strrchr (DW_STRING (attr
), ':');
13889 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
13892 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
13893 &cu
->objfile
->objfile_obstack
);
13896 /* Return the name of the namespace/class that DIE is defined within,
13897 or "" if we can't tell. The caller should not xfree the result.
13899 For example, if we're within the method foo() in the following
13909 then determine_prefix on foo's die will return "N::C". */
13911 static const char *
13912 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
13914 struct die_info
*parent
, *spec_die
;
13915 struct dwarf2_cu
*spec_cu
;
13916 struct type
*parent_type
;
13919 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
13920 && cu
->language
!= language_fortran
)
13923 retval
= anonymous_struct_prefix (die
, cu
);
13927 /* We have to be careful in the presence of DW_AT_specification.
13928 For example, with GCC 3.4, given the code
13932 // Definition of N::foo.
13936 then we'll have a tree of DIEs like this:
13938 1: DW_TAG_compile_unit
13939 2: DW_TAG_namespace // N
13940 3: DW_TAG_subprogram // declaration of N::foo
13941 4: DW_TAG_subprogram // definition of N::foo
13942 DW_AT_specification // refers to die #3
13944 Thus, when processing die #4, we have to pretend that we're in
13945 the context of its DW_AT_specification, namely the contex of die
13948 spec_die
= die_specification (die
, &spec_cu
);
13949 if (spec_die
== NULL
)
13950 parent
= die
->parent
;
13953 parent
= spec_die
->parent
;
13957 if (parent
== NULL
)
13959 else if (parent
->building_fullname
)
13962 const char *parent_name
;
13964 /* It has been seen on RealView 2.2 built binaries,
13965 DW_TAG_template_type_param types actually _defined_ as
13966 children of the parent class:
13969 template class <class Enum> Class{};
13970 Class<enum E> class_e;
13972 1: DW_TAG_class_type (Class)
13973 2: DW_TAG_enumeration_type (E)
13974 3: DW_TAG_enumerator (enum1:0)
13975 3: DW_TAG_enumerator (enum2:1)
13977 2: DW_TAG_template_type_param
13978 DW_AT_type DW_FORM_ref_udata (E)
13980 Besides being broken debug info, it can put GDB into an
13981 infinite loop. Consider:
13983 When we're building the full name for Class<E>, we'll start
13984 at Class, and go look over its template type parameters,
13985 finding E. We'll then try to build the full name of E, and
13986 reach here. We're now trying to build the full name of E,
13987 and look over the parent DIE for containing scope. In the
13988 broken case, if we followed the parent DIE of E, we'd again
13989 find Class, and once again go look at its template type
13990 arguments, etc., etc. Simply don't consider such parent die
13991 as source-level parent of this die (it can't be, the language
13992 doesn't allow it), and break the loop here. */
13993 name
= dwarf2_name (die
, cu
);
13994 parent_name
= dwarf2_name (parent
, cu
);
13995 complaint (&symfile_complaints
,
13996 _("template param type '%s' defined within parent '%s'"),
13997 name
? name
: "<unknown>",
13998 parent_name
? parent_name
: "<unknown>");
14002 switch (parent
->tag
)
14004 case DW_TAG_namespace
:
14005 parent_type
= read_type_die (parent
, cu
);
14006 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14007 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14008 Work around this problem here. */
14009 if (cu
->language
== language_cplus
14010 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14012 /* We give a name to even anonymous namespaces. */
14013 return TYPE_TAG_NAME (parent_type
);
14014 case DW_TAG_class_type
:
14015 case DW_TAG_interface_type
:
14016 case DW_TAG_structure_type
:
14017 case DW_TAG_union_type
:
14018 case DW_TAG_module
:
14019 parent_type
= read_type_die (parent
, cu
);
14020 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14021 return TYPE_TAG_NAME (parent_type
);
14023 /* An anonymous structure is only allowed non-static data
14024 members; no typedefs, no member functions, et cetera.
14025 So it does not need a prefix. */
14027 case DW_TAG_compile_unit
:
14028 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14029 if (cu
->language
== language_cplus
14030 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14031 && die
->child
!= NULL
14032 && (die
->tag
== DW_TAG_class_type
14033 || die
->tag
== DW_TAG_structure_type
14034 || die
->tag
== DW_TAG_union_type
))
14036 char *name
= guess_full_die_structure_name (die
, cu
);
14042 return determine_prefix (parent
, cu
);
14046 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14047 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14048 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14049 an obconcat, otherwise allocate storage for the result. The CU argument is
14050 used to determine the language and hence, the appropriate separator. */
14052 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14055 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14056 int physname
, struct dwarf2_cu
*cu
)
14058 const char *lead
= "";
14061 if (suffix
== NULL
|| suffix
[0] == '\0'
14062 || prefix
== NULL
|| prefix
[0] == '\0')
14064 else if (cu
->language
== language_java
)
14066 else if (cu
->language
== language_fortran
&& physname
)
14068 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14069 DW_AT_MIPS_linkage_name is preferred and used instead. */
14077 if (prefix
== NULL
)
14079 if (suffix
== NULL
)
14085 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14087 strcpy (retval
, lead
);
14088 strcat (retval
, prefix
);
14089 strcat (retval
, sep
);
14090 strcat (retval
, suffix
);
14095 /* We have an obstack. */
14096 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14100 /* Return sibling of die, NULL if no sibling. */
14102 static struct die_info
*
14103 sibling_die (struct die_info
*die
)
14105 return die
->sibling
;
14108 /* Get name of a die, return NULL if not found. */
14111 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14112 struct obstack
*obstack
)
14114 if (name
&& cu
->language
== language_cplus
)
14116 char *canon_name
= cp_canonicalize_string (name
);
14118 if (canon_name
!= NULL
)
14120 if (strcmp (canon_name
, name
) != 0)
14121 name
= obsavestring (canon_name
, strlen (canon_name
),
14123 xfree (canon_name
);
14130 /* Get name of a die, return NULL if not found. */
14133 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14135 struct attribute
*attr
;
14137 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14138 if ((!attr
|| !DW_STRING (attr
))
14139 && die
->tag
!= DW_TAG_class_type
14140 && die
->tag
!= DW_TAG_interface_type
14141 && die
->tag
!= DW_TAG_structure_type
14142 && die
->tag
!= DW_TAG_union_type
)
14147 case DW_TAG_compile_unit
:
14148 /* Compilation units have a DW_AT_name that is a filename, not
14149 a source language identifier. */
14150 case DW_TAG_enumeration_type
:
14151 case DW_TAG_enumerator
:
14152 /* These tags always have simple identifiers already; no need
14153 to canonicalize them. */
14154 return DW_STRING (attr
);
14156 case DW_TAG_subprogram
:
14157 /* Java constructors will all be named "<init>", so return
14158 the class name when we see this special case. */
14159 if (cu
->language
== language_java
14160 && DW_STRING (attr
) != NULL
14161 && strcmp (DW_STRING (attr
), "<init>") == 0)
14163 struct dwarf2_cu
*spec_cu
= cu
;
14164 struct die_info
*spec_die
;
14166 /* GCJ will output '<init>' for Java constructor names.
14167 For this special case, return the name of the parent class. */
14169 /* GCJ may output suprogram DIEs with AT_specification set.
14170 If so, use the name of the specified DIE. */
14171 spec_die
= die_specification (die
, &spec_cu
);
14172 if (spec_die
!= NULL
)
14173 return dwarf2_name (spec_die
, spec_cu
);
14178 if (die
->tag
== DW_TAG_class_type
)
14179 return dwarf2_name (die
, cu
);
14181 while (die
->tag
!= DW_TAG_compile_unit
);
14185 case DW_TAG_class_type
:
14186 case DW_TAG_interface_type
:
14187 case DW_TAG_structure_type
:
14188 case DW_TAG_union_type
:
14189 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14190 structures or unions. These were of the form "._%d" in GCC 4.1,
14191 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14192 and GCC 4.4. We work around this problem by ignoring these. */
14193 if (attr
&& DW_STRING (attr
)
14194 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14195 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14198 /* GCC might emit a nameless typedef that has a linkage name. See
14199 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14200 if (!attr
|| DW_STRING (attr
) == NULL
)
14202 char *demangled
= NULL
;
14204 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14206 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14208 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14211 /* Avoid demangling DW_STRING (attr) the second time on a second
14212 call for the same DIE. */
14213 if (!DW_STRING_IS_CANONICAL (attr
))
14214 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14220 /* FIXME: we already did this for the partial symbol... */
14221 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14222 &cu
->objfile
->objfile_obstack
);
14223 DW_STRING_IS_CANONICAL (attr
) = 1;
14226 /* Strip any leading namespaces/classes, keep only the base name.
14227 DW_AT_name for named DIEs does not contain the prefixes. */
14228 base
= strrchr (DW_STRING (attr
), ':');
14229 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14232 return DW_STRING (attr
);
14241 if (!DW_STRING_IS_CANONICAL (attr
))
14244 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14245 &cu
->objfile
->objfile_obstack
);
14246 DW_STRING_IS_CANONICAL (attr
) = 1;
14248 return DW_STRING (attr
);
14251 /* Return the die that this die in an extension of, or NULL if there
14252 is none. *EXT_CU is the CU containing DIE on input, and the CU
14253 containing the return value on output. */
14255 static struct die_info
*
14256 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14258 struct attribute
*attr
;
14260 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14264 return follow_die_ref (die
, attr
, ext_cu
);
14267 /* Convert a DIE tag into its string name. */
14270 dwarf_tag_name (unsigned tag
)
14274 case DW_TAG_padding
:
14275 return "DW_TAG_padding";
14276 case DW_TAG_array_type
:
14277 return "DW_TAG_array_type";
14278 case DW_TAG_class_type
:
14279 return "DW_TAG_class_type";
14280 case DW_TAG_entry_point
:
14281 return "DW_TAG_entry_point";
14282 case DW_TAG_enumeration_type
:
14283 return "DW_TAG_enumeration_type";
14284 case DW_TAG_formal_parameter
:
14285 return "DW_TAG_formal_parameter";
14286 case DW_TAG_imported_declaration
:
14287 return "DW_TAG_imported_declaration";
14289 return "DW_TAG_label";
14290 case DW_TAG_lexical_block
:
14291 return "DW_TAG_lexical_block";
14292 case DW_TAG_member
:
14293 return "DW_TAG_member";
14294 case DW_TAG_pointer_type
:
14295 return "DW_TAG_pointer_type";
14296 case DW_TAG_reference_type
:
14297 return "DW_TAG_reference_type";
14298 case DW_TAG_compile_unit
:
14299 return "DW_TAG_compile_unit";
14300 case DW_TAG_string_type
:
14301 return "DW_TAG_string_type";
14302 case DW_TAG_structure_type
:
14303 return "DW_TAG_structure_type";
14304 case DW_TAG_subroutine_type
:
14305 return "DW_TAG_subroutine_type";
14306 case DW_TAG_typedef
:
14307 return "DW_TAG_typedef";
14308 case DW_TAG_union_type
:
14309 return "DW_TAG_union_type";
14310 case DW_TAG_unspecified_parameters
:
14311 return "DW_TAG_unspecified_parameters";
14312 case DW_TAG_variant
:
14313 return "DW_TAG_variant";
14314 case DW_TAG_common_block
:
14315 return "DW_TAG_common_block";
14316 case DW_TAG_common_inclusion
:
14317 return "DW_TAG_common_inclusion";
14318 case DW_TAG_inheritance
:
14319 return "DW_TAG_inheritance";
14320 case DW_TAG_inlined_subroutine
:
14321 return "DW_TAG_inlined_subroutine";
14322 case DW_TAG_module
:
14323 return "DW_TAG_module";
14324 case DW_TAG_ptr_to_member_type
:
14325 return "DW_TAG_ptr_to_member_type";
14326 case DW_TAG_set_type
:
14327 return "DW_TAG_set_type";
14328 case DW_TAG_subrange_type
:
14329 return "DW_TAG_subrange_type";
14330 case DW_TAG_with_stmt
:
14331 return "DW_TAG_with_stmt";
14332 case DW_TAG_access_declaration
:
14333 return "DW_TAG_access_declaration";
14334 case DW_TAG_base_type
:
14335 return "DW_TAG_base_type";
14336 case DW_TAG_catch_block
:
14337 return "DW_TAG_catch_block";
14338 case DW_TAG_const_type
:
14339 return "DW_TAG_const_type";
14340 case DW_TAG_constant
:
14341 return "DW_TAG_constant";
14342 case DW_TAG_enumerator
:
14343 return "DW_TAG_enumerator";
14344 case DW_TAG_file_type
:
14345 return "DW_TAG_file_type";
14346 case DW_TAG_friend
:
14347 return "DW_TAG_friend";
14348 case DW_TAG_namelist
:
14349 return "DW_TAG_namelist";
14350 case DW_TAG_namelist_item
:
14351 return "DW_TAG_namelist_item";
14352 case DW_TAG_packed_type
:
14353 return "DW_TAG_packed_type";
14354 case DW_TAG_subprogram
:
14355 return "DW_TAG_subprogram";
14356 case DW_TAG_template_type_param
:
14357 return "DW_TAG_template_type_param";
14358 case DW_TAG_template_value_param
:
14359 return "DW_TAG_template_value_param";
14360 case DW_TAG_thrown_type
:
14361 return "DW_TAG_thrown_type";
14362 case DW_TAG_try_block
:
14363 return "DW_TAG_try_block";
14364 case DW_TAG_variant_part
:
14365 return "DW_TAG_variant_part";
14366 case DW_TAG_variable
:
14367 return "DW_TAG_variable";
14368 case DW_TAG_volatile_type
:
14369 return "DW_TAG_volatile_type";
14370 case DW_TAG_dwarf_procedure
:
14371 return "DW_TAG_dwarf_procedure";
14372 case DW_TAG_restrict_type
:
14373 return "DW_TAG_restrict_type";
14374 case DW_TAG_interface_type
:
14375 return "DW_TAG_interface_type";
14376 case DW_TAG_namespace
:
14377 return "DW_TAG_namespace";
14378 case DW_TAG_imported_module
:
14379 return "DW_TAG_imported_module";
14380 case DW_TAG_unspecified_type
:
14381 return "DW_TAG_unspecified_type";
14382 case DW_TAG_partial_unit
:
14383 return "DW_TAG_partial_unit";
14384 case DW_TAG_imported_unit
:
14385 return "DW_TAG_imported_unit";
14386 case DW_TAG_condition
:
14387 return "DW_TAG_condition";
14388 case DW_TAG_shared_type
:
14389 return "DW_TAG_shared_type";
14390 case DW_TAG_type_unit
:
14391 return "DW_TAG_type_unit";
14392 case DW_TAG_MIPS_loop
:
14393 return "DW_TAG_MIPS_loop";
14394 case DW_TAG_HP_array_descriptor
:
14395 return "DW_TAG_HP_array_descriptor";
14396 case DW_TAG_format_label
:
14397 return "DW_TAG_format_label";
14398 case DW_TAG_function_template
:
14399 return "DW_TAG_function_template";
14400 case DW_TAG_class_template
:
14401 return "DW_TAG_class_template";
14402 case DW_TAG_GNU_BINCL
:
14403 return "DW_TAG_GNU_BINCL";
14404 case DW_TAG_GNU_EINCL
:
14405 return "DW_TAG_GNU_EINCL";
14406 case DW_TAG_upc_shared_type
:
14407 return "DW_TAG_upc_shared_type";
14408 case DW_TAG_upc_strict_type
:
14409 return "DW_TAG_upc_strict_type";
14410 case DW_TAG_upc_relaxed_type
:
14411 return "DW_TAG_upc_relaxed_type";
14412 case DW_TAG_PGI_kanji_type
:
14413 return "DW_TAG_PGI_kanji_type";
14414 case DW_TAG_PGI_interface_block
:
14415 return "DW_TAG_PGI_interface_block";
14416 case DW_TAG_GNU_call_site
:
14417 return "DW_TAG_GNU_call_site";
14419 return "DW_TAG_<unknown>";
14423 /* Convert a DWARF attribute code into its string name. */
14426 dwarf_attr_name (unsigned attr
)
14430 case DW_AT_sibling
:
14431 return "DW_AT_sibling";
14432 case DW_AT_location
:
14433 return "DW_AT_location";
14435 return "DW_AT_name";
14436 case DW_AT_ordering
:
14437 return "DW_AT_ordering";
14438 case DW_AT_subscr_data
:
14439 return "DW_AT_subscr_data";
14440 case DW_AT_byte_size
:
14441 return "DW_AT_byte_size";
14442 case DW_AT_bit_offset
:
14443 return "DW_AT_bit_offset";
14444 case DW_AT_bit_size
:
14445 return "DW_AT_bit_size";
14446 case DW_AT_element_list
:
14447 return "DW_AT_element_list";
14448 case DW_AT_stmt_list
:
14449 return "DW_AT_stmt_list";
14451 return "DW_AT_low_pc";
14452 case DW_AT_high_pc
:
14453 return "DW_AT_high_pc";
14454 case DW_AT_language
:
14455 return "DW_AT_language";
14457 return "DW_AT_member";
14459 return "DW_AT_discr";
14460 case DW_AT_discr_value
:
14461 return "DW_AT_discr_value";
14462 case DW_AT_visibility
:
14463 return "DW_AT_visibility";
14465 return "DW_AT_import";
14466 case DW_AT_string_length
:
14467 return "DW_AT_string_length";
14468 case DW_AT_common_reference
:
14469 return "DW_AT_common_reference";
14470 case DW_AT_comp_dir
:
14471 return "DW_AT_comp_dir";
14472 case DW_AT_const_value
:
14473 return "DW_AT_const_value";
14474 case DW_AT_containing_type
:
14475 return "DW_AT_containing_type";
14476 case DW_AT_default_value
:
14477 return "DW_AT_default_value";
14479 return "DW_AT_inline";
14480 case DW_AT_is_optional
:
14481 return "DW_AT_is_optional";
14482 case DW_AT_lower_bound
:
14483 return "DW_AT_lower_bound";
14484 case DW_AT_producer
:
14485 return "DW_AT_producer";
14486 case DW_AT_prototyped
:
14487 return "DW_AT_prototyped";
14488 case DW_AT_return_addr
:
14489 return "DW_AT_return_addr";
14490 case DW_AT_start_scope
:
14491 return "DW_AT_start_scope";
14492 case DW_AT_bit_stride
:
14493 return "DW_AT_bit_stride";
14494 case DW_AT_upper_bound
:
14495 return "DW_AT_upper_bound";
14496 case DW_AT_abstract_origin
:
14497 return "DW_AT_abstract_origin";
14498 case DW_AT_accessibility
:
14499 return "DW_AT_accessibility";
14500 case DW_AT_address_class
:
14501 return "DW_AT_address_class";
14502 case DW_AT_artificial
:
14503 return "DW_AT_artificial";
14504 case DW_AT_base_types
:
14505 return "DW_AT_base_types";
14506 case DW_AT_calling_convention
:
14507 return "DW_AT_calling_convention";
14509 return "DW_AT_count";
14510 case DW_AT_data_member_location
:
14511 return "DW_AT_data_member_location";
14512 case DW_AT_decl_column
:
14513 return "DW_AT_decl_column";
14514 case DW_AT_decl_file
:
14515 return "DW_AT_decl_file";
14516 case DW_AT_decl_line
:
14517 return "DW_AT_decl_line";
14518 case DW_AT_declaration
:
14519 return "DW_AT_declaration";
14520 case DW_AT_discr_list
:
14521 return "DW_AT_discr_list";
14522 case DW_AT_encoding
:
14523 return "DW_AT_encoding";
14524 case DW_AT_external
:
14525 return "DW_AT_external";
14526 case DW_AT_frame_base
:
14527 return "DW_AT_frame_base";
14529 return "DW_AT_friend";
14530 case DW_AT_identifier_case
:
14531 return "DW_AT_identifier_case";
14532 case DW_AT_macro_info
:
14533 return "DW_AT_macro_info";
14534 case DW_AT_namelist_items
:
14535 return "DW_AT_namelist_items";
14536 case DW_AT_priority
:
14537 return "DW_AT_priority";
14538 case DW_AT_segment
:
14539 return "DW_AT_segment";
14540 case DW_AT_specification
:
14541 return "DW_AT_specification";
14542 case DW_AT_static_link
:
14543 return "DW_AT_static_link";
14545 return "DW_AT_type";
14546 case DW_AT_use_location
:
14547 return "DW_AT_use_location";
14548 case DW_AT_variable_parameter
:
14549 return "DW_AT_variable_parameter";
14550 case DW_AT_virtuality
:
14551 return "DW_AT_virtuality";
14552 case DW_AT_vtable_elem_location
:
14553 return "DW_AT_vtable_elem_location";
14554 /* DWARF 3 values. */
14555 case DW_AT_allocated
:
14556 return "DW_AT_allocated";
14557 case DW_AT_associated
:
14558 return "DW_AT_associated";
14559 case DW_AT_data_location
:
14560 return "DW_AT_data_location";
14561 case DW_AT_byte_stride
:
14562 return "DW_AT_byte_stride";
14563 case DW_AT_entry_pc
:
14564 return "DW_AT_entry_pc";
14565 case DW_AT_use_UTF8
:
14566 return "DW_AT_use_UTF8";
14567 case DW_AT_extension
:
14568 return "DW_AT_extension";
14570 return "DW_AT_ranges";
14571 case DW_AT_trampoline
:
14572 return "DW_AT_trampoline";
14573 case DW_AT_call_column
:
14574 return "DW_AT_call_column";
14575 case DW_AT_call_file
:
14576 return "DW_AT_call_file";
14577 case DW_AT_call_line
:
14578 return "DW_AT_call_line";
14579 case DW_AT_description
:
14580 return "DW_AT_description";
14581 case DW_AT_binary_scale
:
14582 return "DW_AT_binary_scale";
14583 case DW_AT_decimal_scale
:
14584 return "DW_AT_decimal_scale";
14586 return "DW_AT_small";
14587 case DW_AT_decimal_sign
:
14588 return "DW_AT_decimal_sign";
14589 case DW_AT_digit_count
:
14590 return "DW_AT_digit_count";
14591 case DW_AT_picture_string
:
14592 return "DW_AT_picture_string";
14593 case DW_AT_mutable
:
14594 return "DW_AT_mutable";
14595 case DW_AT_threads_scaled
:
14596 return "DW_AT_threads_scaled";
14597 case DW_AT_explicit
:
14598 return "DW_AT_explicit";
14599 case DW_AT_object_pointer
:
14600 return "DW_AT_object_pointer";
14601 case DW_AT_endianity
:
14602 return "DW_AT_endianity";
14603 case DW_AT_elemental
:
14604 return "DW_AT_elemental";
14606 return "DW_AT_pure";
14607 case DW_AT_recursive
:
14608 return "DW_AT_recursive";
14609 /* DWARF 4 values. */
14610 case DW_AT_signature
:
14611 return "DW_AT_signature";
14612 case DW_AT_linkage_name
:
14613 return "DW_AT_linkage_name";
14614 /* Tentative Fission values. */
14615 case DW_AT_GNU_dwo_name
:
14616 return "DW_AT_GNU_dwo_name";
14617 case DW_AT_GNU_dwo_id
:
14618 return "DW_AT_GNU_dwo_id";
14619 case DW_AT_GNU_addr_base
:
14620 return "DW_AT_GNU_addr_base";
14621 case DW_AT_GNU_pubnames
:
14622 return "DW_AT_GNU_pubnames";
14623 case DW_AT_GNU_pubtypes
:
14624 return "DW_AT_GNU_pubtypes";
14625 /* SGI/MIPS extensions. */
14626 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14627 case DW_AT_MIPS_fde
:
14628 return "DW_AT_MIPS_fde";
14630 case DW_AT_MIPS_loop_begin
:
14631 return "DW_AT_MIPS_loop_begin";
14632 case DW_AT_MIPS_tail_loop_begin
:
14633 return "DW_AT_MIPS_tail_loop_begin";
14634 case DW_AT_MIPS_epilog_begin
:
14635 return "DW_AT_MIPS_epilog_begin";
14636 case DW_AT_MIPS_loop_unroll_factor
:
14637 return "DW_AT_MIPS_loop_unroll_factor";
14638 case DW_AT_MIPS_software_pipeline_depth
:
14639 return "DW_AT_MIPS_software_pipeline_depth";
14640 case DW_AT_MIPS_linkage_name
:
14641 return "DW_AT_MIPS_linkage_name";
14642 case DW_AT_MIPS_stride
:
14643 return "DW_AT_MIPS_stride";
14644 case DW_AT_MIPS_abstract_name
:
14645 return "DW_AT_MIPS_abstract_name";
14646 case DW_AT_MIPS_clone_origin
:
14647 return "DW_AT_MIPS_clone_origin";
14648 case DW_AT_MIPS_has_inlines
:
14649 return "DW_AT_MIPS_has_inlines";
14650 /* HP extensions. */
14651 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
14652 case DW_AT_HP_block_index
:
14653 return "DW_AT_HP_block_index";
14655 case DW_AT_HP_unmodifiable
:
14656 return "DW_AT_HP_unmodifiable";
14657 case DW_AT_HP_actuals_stmt_list
:
14658 return "DW_AT_HP_actuals_stmt_list";
14659 case DW_AT_HP_proc_per_section
:
14660 return "DW_AT_HP_proc_per_section";
14661 case DW_AT_HP_raw_data_ptr
:
14662 return "DW_AT_HP_raw_data_ptr";
14663 case DW_AT_HP_pass_by_reference
:
14664 return "DW_AT_HP_pass_by_reference";
14665 case DW_AT_HP_opt_level
:
14666 return "DW_AT_HP_opt_level";
14667 case DW_AT_HP_prof_version_id
:
14668 return "DW_AT_HP_prof_version_id";
14669 case DW_AT_HP_opt_flags
:
14670 return "DW_AT_HP_opt_flags";
14671 case DW_AT_HP_cold_region_low_pc
:
14672 return "DW_AT_HP_cold_region_low_pc";
14673 case DW_AT_HP_cold_region_high_pc
:
14674 return "DW_AT_HP_cold_region_high_pc";
14675 case DW_AT_HP_all_variables_modifiable
:
14676 return "DW_AT_HP_all_variables_modifiable";
14677 case DW_AT_HP_linkage_name
:
14678 return "DW_AT_HP_linkage_name";
14679 case DW_AT_HP_prof_flags
:
14680 return "DW_AT_HP_prof_flags";
14681 /* GNU extensions. */
14682 case DW_AT_sf_names
:
14683 return "DW_AT_sf_names";
14684 case DW_AT_src_info
:
14685 return "DW_AT_src_info";
14686 case DW_AT_mac_info
:
14687 return "DW_AT_mac_info";
14688 case DW_AT_src_coords
:
14689 return "DW_AT_src_coords";
14690 case DW_AT_body_begin
:
14691 return "DW_AT_body_begin";
14692 case DW_AT_body_end
:
14693 return "DW_AT_body_end";
14694 case DW_AT_GNU_vector
:
14695 return "DW_AT_GNU_vector";
14696 case DW_AT_GNU_odr_signature
:
14697 return "DW_AT_GNU_odr_signature";
14698 /* VMS extensions. */
14699 case DW_AT_VMS_rtnbeg_pd_address
:
14700 return "DW_AT_VMS_rtnbeg_pd_address";
14701 /* UPC extension. */
14702 case DW_AT_upc_threads_scaled
:
14703 return "DW_AT_upc_threads_scaled";
14704 /* PGI (STMicroelectronics) extensions. */
14705 case DW_AT_PGI_lbase
:
14706 return "DW_AT_PGI_lbase";
14707 case DW_AT_PGI_soffset
:
14708 return "DW_AT_PGI_soffset";
14709 case DW_AT_PGI_lstride
:
14710 return "DW_AT_PGI_lstride";
14712 return "DW_AT_<unknown>";
14716 /* Convert a DWARF value form code into its string name. */
14719 dwarf_form_name (unsigned form
)
14724 return "DW_FORM_addr";
14725 case DW_FORM_block2
:
14726 return "DW_FORM_block2";
14727 case DW_FORM_block4
:
14728 return "DW_FORM_block4";
14729 case DW_FORM_data2
:
14730 return "DW_FORM_data2";
14731 case DW_FORM_data4
:
14732 return "DW_FORM_data4";
14733 case DW_FORM_data8
:
14734 return "DW_FORM_data8";
14735 case DW_FORM_string
:
14736 return "DW_FORM_string";
14737 case DW_FORM_block
:
14738 return "DW_FORM_block";
14739 case DW_FORM_block1
:
14740 return "DW_FORM_block1";
14741 case DW_FORM_data1
:
14742 return "DW_FORM_data1";
14744 return "DW_FORM_flag";
14745 case DW_FORM_sdata
:
14746 return "DW_FORM_sdata";
14748 return "DW_FORM_strp";
14749 case DW_FORM_udata
:
14750 return "DW_FORM_udata";
14751 case DW_FORM_ref_addr
:
14752 return "DW_FORM_ref_addr";
14754 return "DW_FORM_ref1";
14756 return "DW_FORM_ref2";
14758 return "DW_FORM_ref4";
14760 return "DW_FORM_ref8";
14761 case DW_FORM_ref_udata
:
14762 return "DW_FORM_ref_udata";
14763 case DW_FORM_indirect
:
14764 return "DW_FORM_indirect";
14765 case DW_FORM_sec_offset
:
14766 return "DW_FORM_sec_offset";
14767 case DW_FORM_exprloc
:
14768 return "DW_FORM_exprloc";
14769 case DW_FORM_flag_present
:
14770 return "DW_FORM_flag_present";
14771 case DW_FORM_ref_sig8
:
14772 return "DW_FORM_ref_sig8";
14773 case DW_FORM_GNU_addr_index
:
14774 return "DW_FORM_GNU_addr_index";
14775 case DW_FORM_GNU_str_index
:
14776 return "DW_FORM_GNU_str_index";
14778 return "DW_FORM_<unknown>";
14782 /* Convert a DWARF stack opcode into its string name. */
14785 dwarf_stack_op_name (unsigned op
)
14790 return "DW_OP_addr";
14792 return "DW_OP_deref";
14793 case DW_OP_const1u
:
14794 return "DW_OP_const1u";
14795 case DW_OP_const1s
:
14796 return "DW_OP_const1s";
14797 case DW_OP_const2u
:
14798 return "DW_OP_const2u";
14799 case DW_OP_const2s
:
14800 return "DW_OP_const2s";
14801 case DW_OP_const4u
:
14802 return "DW_OP_const4u";
14803 case DW_OP_const4s
:
14804 return "DW_OP_const4s";
14805 case DW_OP_const8u
:
14806 return "DW_OP_const8u";
14807 case DW_OP_const8s
:
14808 return "DW_OP_const8s";
14810 return "DW_OP_constu";
14812 return "DW_OP_consts";
14814 return "DW_OP_dup";
14816 return "DW_OP_drop";
14818 return "DW_OP_over";
14820 return "DW_OP_pick";
14822 return "DW_OP_swap";
14824 return "DW_OP_rot";
14826 return "DW_OP_xderef";
14828 return "DW_OP_abs";
14830 return "DW_OP_and";
14832 return "DW_OP_div";
14834 return "DW_OP_minus";
14836 return "DW_OP_mod";
14838 return "DW_OP_mul";
14840 return "DW_OP_neg";
14842 return "DW_OP_not";
14846 return "DW_OP_plus";
14847 case DW_OP_plus_uconst
:
14848 return "DW_OP_plus_uconst";
14850 return "DW_OP_shl";
14852 return "DW_OP_shr";
14854 return "DW_OP_shra";
14856 return "DW_OP_xor";
14858 return "DW_OP_bra";
14872 return "DW_OP_skip";
14874 return "DW_OP_lit0";
14876 return "DW_OP_lit1";
14878 return "DW_OP_lit2";
14880 return "DW_OP_lit3";
14882 return "DW_OP_lit4";
14884 return "DW_OP_lit5";
14886 return "DW_OP_lit6";
14888 return "DW_OP_lit7";
14890 return "DW_OP_lit8";
14892 return "DW_OP_lit9";
14894 return "DW_OP_lit10";
14896 return "DW_OP_lit11";
14898 return "DW_OP_lit12";
14900 return "DW_OP_lit13";
14902 return "DW_OP_lit14";
14904 return "DW_OP_lit15";
14906 return "DW_OP_lit16";
14908 return "DW_OP_lit17";
14910 return "DW_OP_lit18";
14912 return "DW_OP_lit19";
14914 return "DW_OP_lit20";
14916 return "DW_OP_lit21";
14918 return "DW_OP_lit22";
14920 return "DW_OP_lit23";
14922 return "DW_OP_lit24";
14924 return "DW_OP_lit25";
14926 return "DW_OP_lit26";
14928 return "DW_OP_lit27";
14930 return "DW_OP_lit28";
14932 return "DW_OP_lit29";
14934 return "DW_OP_lit30";
14936 return "DW_OP_lit31";
14938 return "DW_OP_reg0";
14940 return "DW_OP_reg1";
14942 return "DW_OP_reg2";
14944 return "DW_OP_reg3";
14946 return "DW_OP_reg4";
14948 return "DW_OP_reg5";
14950 return "DW_OP_reg6";
14952 return "DW_OP_reg7";
14954 return "DW_OP_reg8";
14956 return "DW_OP_reg9";
14958 return "DW_OP_reg10";
14960 return "DW_OP_reg11";
14962 return "DW_OP_reg12";
14964 return "DW_OP_reg13";
14966 return "DW_OP_reg14";
14968 return "DW_OP_reg15";
14970 return "DW_OP_reg16";
14972 return "DW_OP_reg17";
14974 return "DW_OP_reg18";
14976 return "DW_OP_reg19";
14978 return "DW_OP_reg20";
14980 return "DW_OP_reg21";
14982 return "DW_OP_reg22";
14984 return "DW_OP_reg23";
14986 return "DW_OP_reg24";
14988 return "DW_OP_reg25";
14990 return "DW_OP_reg26";
14992 return "DW_OP_reg27";
14994 return "DW_OP_reg28";
14996 return "DW_OP_reg29";
14998 return "DW_OP_reg30";
15000 return "DW_OP_reg31";
15002 return "DW_OP_breg0";
15004 return "DW_OP_breg1";
15006 return "DW_OP_breg2";
15008 return "DW_OP_breg3";
15010 return "DW_OP_breg4";
15012 return "DW_OP_breg5";
15014 return "DW_OP_breg6";
15016 return "DW_OP_breg7";
15018 return "DW_OP_breg8";
15020 return "DW_OP_breg9";
15022 return "DW_OP_breg10";
15024 return "DW_OP_breg11";
15026 return "DW_OP_breg12";
15028 return "DW_OP_breg13";
15030 return "DW_OP_breg14";
15032 return "DW_OP_breg15";
15034 return "DW_OP_breg16";
15036 return "DW_OP_breg17";
15038 return "DW_OP_breg18";
15040 return "DW_OP_breg19";
15042 return "DW_OP_breg20";
15044 return "DW_OP_breg21";
15046 return "DW_OP_breg22";
15048 return "DW_OP_breg23";
15050 return "DW_OP_breg24";
15052 return "DW_OP_breg25";
15054 return "DW_OP_breg26";
15056 return "DW_OP_breg27";
15058 return "DW_OP_breg28";
15060 return "DW_OP_breg29";
15062 return "DW_OP_breg30";
15064 return "DW_OP_breg31";
15066 return "DW_OP_regx";
15068 return "DW_OP_fbreg";
15070 return "DW_OP_bregx";
15072 return "DW_OP_piece";
15073 case DW_OP_deref_size
:
15074 return "DW_OP_deref_size";
15075 case DW_OP_xderef_size
:
15076 return "DW_OP_xderef_size";
15078 return "DW_OP_nop";
15079 /* DWARF 3 extensions. */
15080 case DW_OP_push_object_address
:
15081 return "DW_OP_push_object_address";
15083 return "DW_OP_call2";
15085 return "DW_OP_call4";
15086 case DW_OP_call_ref
:
15087 return "DW_OP_call_ref";
15088 case DW_OP_form_tls_address
:
15089 return "DW_OP_form_tls_address";
15090 case DW_OP_call_frame_cfa
:
15091 return "DW_OP_call_frame_cfa";
15092 case DW_OP_bit_piece
:
15093 return "DW_OP_bit_piece";
15094 /* DWARF 4 extensions. */
15095 case DW_OP_implicit_value
:
15096 return "DW_OP_implicit_value";
15097 case DW_OP_stack_value
:
15098 return "DW_OP_stack_value";
15099 /* GNU extensions. */
15100 case DW_OP_GNU_push_tls_address
:
15101 return "DW_OP_GNU_push_tls_address";
15102 case DW_OP_GNU_uninit
:
15103 return "DW_OP_GNU_uninit";
15104 case DW_OP_GNU_encoded_addr
:
15105 return "DW_OP_GNU_encoded_addr";
15106 case DW_OP_GNU_implicit_pointer
:
15107 return "DW_OP_GNU_implicit_pointer";
15108 case DW_OP_GNU_entry_value
:
15109 return "DW_OP_GNU_entry_value";
15110 case DW_OP_GNU_const_type
:
15111 return "DW_OP_GNU_const_type";
15112 case DW_OP_GNU_regval_type
:
15113 return "DW_OP_GNU_regval_type";
15114 case DW_OP_GNU_deref_type
:
15115 return "DW_OP_GNU_deref_type";
15116 case DW_OP_GNU_convert
:
15117 return "DW_OP_GNU_convert";
15118 case DW_OP_GNU_reinterpret
:
15119 return "DW_OP_GNU_reinterpret";
15120 case DW_OP_GNU_parameter_ref
:
15121 return "DW_OP_GNU_parameter_ref";
15128 dwarf_bool_name (unsigned mybool
)
15136 /* Convert a DWARF type code into its string name. */
15139 dwarf_type_encoding_name (unsigned enc
)
15144 return "DW_ATE_void";
15145 case DW_ATE_address
:
15146 return "DW_ATE_address";
15147 case DW_ATE_boolean
:
15148 return "DW_ATE_boolean";
15149 case DW_ATE_complex_float
:
15150 return "DW_ATE_complex_float";
15152 return "DW_ATE_float";
15153 case DW_ATE_signed
:
15154 return "DW_ATE_signed";
15155 case DW_ATE_signed_char
:
15156 return "DW_ATE_signed_char";
15157 case DW_ATE_unsigned
:
15158 return "DW_ATE_unsigned";
15159 case DW_ATE_unsigned_char
:
15160 return "DW_ATE_unsigned_char";
15162 case DW_ATE_imaginary_float
:
15163 return "DW_ATE_imaginary_float";
15164 case DW_ATE_packed_decimal
:
15165 return "DW_ATE_packed_decimal";
15166 case DW_ATE_numeric_string
:
15167 return "DW_ATE_numeric_string";
15168 case DW_ATE_edited
:
15169 return "DW_ATE_edited";
15170 case DW_ATE_signed_fixed
:
15171 return "DW_ATE_signed_fixed";
15172 case DW_ATE_unsigned_fixed
:
15173 return "DW_ATE_unsigned_fixed";
15174 case DW_ATE_decimal_float
:
15175 return "DW_ATE_decimal_float";
15178 return "DW_ATE_UTF";
15179 /* HP extensions. */
15180 case DW_ATE_HP_float80
:
15181 return "DW_ATE_HP_float80";
15182 case DW_ATE_HP_complex_float80
:
15183 return "DW_ATE_HP_complex_float80";
15184 case DW_ATE_HP_float128
:
15185 return "DW_ATE_HP_float128";
15186 case DW_ATE_HP_complex_float128
:
15187 return "DW_ATE_HP_complex_float128";
15188 case DW_ATE_HP_floathpintel
:
15189 return "DW_ATE_HP_floathpintel";
15190 case DW_ATE_HP_imaginary_float80
:
15191 return "DW_ATE_HP_imaginary_float80";
15192 case DW_ATE_HP_imaginary_float128
:
15193 return "DW_ATE_HP_imaginary_float128";
15195 return "DW_ATE_<unknown>";
15199 /* Convert a DWARF call frame info operation to its string name. */
15203 dwarf_cfi_name (unsigned cfi_opc
)
15207 case DW_CFA_advance_loc
:
15208 return "DW_CFA_advance_loc";
15209 case DW_CFA_offset
:
15210 return "DW_CFA_offset";
15211 case DW_CFA_restore
:
15212 return "DW_CFA_restore";
15214 return "DW_CFA_nop";
15215 case DW_CFA_set_loc
:
15216 return "DW_CFA_set_loc";
15217 case DW_CFA_advance_loc1
:
15218 return "DW_CFA_advance_loc1";
15219 case DW_CFA_advance_loc2
:
15220 return "DW_CFA_advance_loc2";
15221 case DW_CFA_advance_loc4
:
15222 return "DW_CFA_advance_loc4";
15223 case DW_CFA_offset_extended
:
15224 return "DW_CFA_offset_extended";
15225 case DW_CFA_restore_extended
:
15226 return "DW_CFA_restore_extended";
15227 case DW_CFA_undefined
:
15228 return "DW_CFA_undefined";
15229 case DW_CFA_same_value
:
15230 return "DW_CFA_same_value";
15231 case DW_CFA_register
:
15232 return "DW_CFA_register";
15233 case DW_CFA_remember_state
:
15234 return "DW_CFA_remember_state";
15235 case DW_CFA_restore_state
:
15236 return "DW_CFA_restore_state";
15237 case DW_CFA_def_cfa
:
15238 return "DW_CFA_def_cfa";
15239 case DW_CFA_def_cfa_register
:
15240 return "DW_CFA_def_cfa_register";
15241 case DW_CFA_def_cfa_offset
:
15242 return "DW_CFA_def_cfa_offset";
15244 case DW_CFA_def_cfa_expression
:
15245 return "DW_CFA_def_cfa_expression";
15246 case DW_CFA_expression
:
15247 return "DW_CFA_expression";
15248 case DW_CFA_offset_extended_sf
:
15249 return "DW_CFA_offset_extended_sf";
15250 case DW_CFA_def_cfa_sf
:
15251 return "DW_CFA_def_cfa_sf";
15252 case DW_CFA_def_cfa_offset_sf
:
15253 return "DW_CFA_def_cfa_offset_sf";
15254 case DW_CFA_val_offset
:
15255 return "DW_CFA_val_offset";
15256 case DW_CFA_val_offset_sf
:
15257 return "DW_CFA_val_offset_sf";
15258 case DW_CFA_val_expression
:
15259 return "DW_CFA_val_expression";
15260 /* SGI/MIPS specific. */
15261 case DW_CFA_MIPS_advance_loc8
:
15262 return "DW_CFA_MIPS_advance_loc8";
15263 /* GNU extensions. */
15264 case DW_CFA_GNU_window_save
:
15265 return "DW_CFA_GNU_window_save";
15266 case DW_CFA_GNU_args_size
:
15267 return "DW_CFA_GNU_args_size";
15268 case DW_CFA_GNU_negative_offset_extended
:
15269 return "DW_CFA_GNU_negative_offset_extended";
15271 return "DW_CFA_<unknown>";
15277 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15281 print_spaces (indent
, f
);
15282 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15283 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15285 if (die
->parent
!= NULL
)
15287 print_spaces (indent
, f
);
15288 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15289 die
->parent
->offset
.sect_off
);
15292 print_spaces (indent
, f
);
15293 fprintf_unfiltered (f
, " has children: %s\n",
15294 dwarf_bool_name (die
->child
!= NULL
));
15296 print_spaces (indent
, f
);
15297 fprintf_unfiltered (f
, " attributes:\n");
15299 for (i
= 0; i
< die
->num_attrs
; ++i
)
15301 print_spaces (indent
, f
);
15302 fprintf_unfiltered (f
, " %s (%s) ",
15303 dwarf_attr_name (die
->attrs
[i
].name
),
15304 dwarf_form_name (die
->attrs
[i
].form
));
15306 switch (die
->attrs
[i
].form
)
15309 case DW_FORM_GNU_addr_index
:
15310 fprintf_unfiltered (f
, "address: ");
15311 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15313 case DW_FORM_block2
:
15314 case DW_FORM_block4
:
15315 case DW_FORM_block
:
15316 case DW_FORM_block1
:
15317 fprintf_unfiltered (f
, "block: size %d",
15318 DW_BLOCK (&die
->attrs
[i
])->size
);
15320 case DW_FORM_exprloc
:
15321 fprintf_unfiltered (f
, "expression: size %u",
15322 DW_BLOCK (&die
->attrs
[i
])->size
);
15324 case DW_FORM_ref_addr
:
15325 fprintf_unfiltered (f
, "ref address: ");
15326 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15332 case DW_FORM_ref_udata
:
15333 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15334 (long) (DW_UNSND (&die
->attrs
[i
])));
15336 case DW_FORM_data1
:
15337 case DW_FORM_data2
:
15338 case DW_FORM_data4
:
15339 case DW_FORM_data8
:
15340 case DW_FORM_udata
:
15341 case DW_FORM_sdata
:
15342 fprintf_unfiltered (f
, "constant: %s",
15343 pulongest (DW_UNSND (&die
->attrs
[i
])));
15345 case DW_FORM_sec_offset
:
15346 fprintf_unfiltered (f
, "section offset: %s",
15347 pulongest (DW_UNSND (&die
->attrs
[i
])));
15349 case DW_FORM_ref_sig8
:
15350 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15351 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15352 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15354 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15356 case DW_FORM_string
:
15358 case DW_FORM_GNU_str_index
:
15359 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15360 DW_STRING (&die
->attrs
[i
])
15361 ? DW_STRING (&die
->attrs
[i
]) : "",
15362 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15365 if (DW_UNSND (&die
->attrs
[i
]))
15366 fprintf_unfiltered (f
, "flag: TRUE");
15368 fprintf_unfiltered (f
, "flag: FALSE");
15370 case DW_FORM_flag_present
:
15371 fprintf_unfiltered (f
, "flag: TRUE");
15373 case DW_FORM_indirect
:
15374 /* The reader will have reduced the indirect form to
15375 the "base form" so this form should not occur. */
15376 fprintf_unfiltered (f
,
15377 "unexpected attribute form: DW_FORM_indirect");
15380 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15381 die
->attrs
[i
].form
);
15384 fprintf_unfiltered (f
, "\n");
15389 dump_die_for_error (struct die_info
*die
)
15391 dump_die_shallow (gdb_stderr
, 0, die
);
15395 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15397 int indent
= level
* 4;
15399 gdb_assert (die
!= NULL
);
15401 if (level
>= max_level
)
15404 dump_die_shallow (f
, indent
, die
);
15406 if (die
->child
!= NULL
)
15408 print_spaces (indent
, f
);
15409 fprintf_unfiltered (f
, " Children:");
15410 if (level
+ 1 < max_level
)
15412 fprintf_unfiltered (f
, "\n");
15413 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15417 fprintf_unfiltered (f
,
15418 " [not printed, max nesting level reached]\n");
15422 if (die
->sibling
!= NULL
&& level
> 0)
15424 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15428 /* This is called from the pdie macro in gdbinit.in.
15429 It's not static so gcc will keep a copy callable from gdb. */
15432 dump_die (struct die_info
*die
, int max_level
)
15434 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15438 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15442 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15448 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15449 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15452 is_ref_attr (struct attribute
*attr
)
15454 switch (attr
->form
)
15456 case DW_FORM_ref_addr
:
15461 case DW_FORM_ref_udata
:
15468 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15472 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15474 sect_offset retval
= { DW_UNSND (attr
) };
15476 if (is_ref_attr (attr
))
15479 retval
.sect_off
= 0;
15480 complaint (&symfile_complaints
,
15481 _("unsupported die ref attribute form: '%s'"),
15482 dwarf_form_name (attr
->form
));
15486 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15487 * the value held by the attribute is not constant. */
15490 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15492 if (attr
->form
== DW_FORM_sdata
)
15493 return DW_SND (attr
);
15494 else if (attr
->form
== DW_FORM_udata
15495 || attr
->form
== DW_FORM_data1
15496 || attr
->form
== DW_FORM_data2
15497 || attr
->form
== DW_FORM_data4
15498 || attr
->form
== DW_FORM_data8
)
15499 return DW_UNSND (attr
);
15502 complaint (&symfile_complaints
,
15503 _("Attribute value is not a constant (%s)"),
15504 dwarf_form_name (attr
->form
));
15505 return default_value
;
15509 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15510 unit and add it to our queue.
15511 The result is non-zero if PER_CU was queued, otherwise the result is zero
15512 meaning either PER_CU is already queued or it is already loaded. */
15515 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15516 struct dwarf2_per_cu_data
*per_cu
)
15518 /* We may arrive here during partial symbol reading, if we need full
15519 DIEs to process an unusual case (e.g. template arguments). Do
15520 not queue PER_CU, just tell our caller to load its DIEs. */
15521 if (dwarf2_per_objfile
->reading_partial_symbols
)
15523 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15528 /* Mark the dependence relation so that we don't flush PER_CU
15530 dwarf2_add_dependence (this_cu
, per_cu
);
15532 /* If it's already on the queue, we have nothing to do. */
15533 if (per_cu
->queued
)
15536 /* If the compilation unit is already loaded, just mark it as
15538 if (per_cu
->cu
!= NULL
)
15540 per_cu
->cu
->last_used
= 0;
15544 /* Add it to the queue. */
15545 queue_comp_unit (per_cu
);
15550 /* Follow reference or signature attribute ATTR of SRC_DIE.
15551 On entry *REF_CU is the CU of SRC_DIE.
15552 On exit *REF_CU is the CU of the result. */
15554 static struct die_info
*
15555 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15556 struct dwarf2_cu
**ref_cu
)
15558 struct die_info
*die
;
15560 if (is_ref_attr (attr
))
15561 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15562 else if (attr
->form
== DW_FORM_ref_sig8
)
15563 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15566 dump_die_for_error (src_die
);
15567 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15568 (*ref_cu
)->objfile
->name
);
15574 /* Follow reference OFFSET.
15575 On entry *REF_CU is the CU of the source die referencing OFFSET.
15576 On exit *REF_CU is the CU of the result.
15577 Returns NULL if OFFSET is invalid. */
15579 static struct die_info
*
15580 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15582 struct die_info temp_die
;
15583 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15585 gdb_assert (cu
->per_cu
!= NULL
);
15589 if (cu
->per_cu
->is_debug_types
)
15591 /* .debug_types CUs cannot reference anything outside their CU.
15592 If they need to, they have to reference a signatured type via
15593 DW_FORM_ref_sig8. */
15594 if (! offset_in_cu_p (&cu
->header
, offset
))
15597 else if (! offset_in_cu_p (&cu
->header
, offset
))
15599 struct dwarf2_per_cu_data
*per_cu
;
15601 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15603 /* If necessary, add it to the queue and load its DIEs. */
15604 if (maybe_queue_comp_unit (cu
, per_cu
))
15605 load_full_comp_unit (per_cu
);
15607 target_cu
= per_cu
->cu
;
15609 else if (cu
->dies
== NULL
)
15611 /* We're loading full DIEs during partial symbol reading. */
15612 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15613 load_full_comp_unit (cu
->per_cu
);
15616 *ref_cu
= target_cu
;
15617 temp_die
.offset
= offset
;
15618 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15621 /* Follow reference attribute ATTR of SRC_DIE.
15622 On entry *REF_CU is the CU of SRC_DIE.
15623 On exit *REF_CU is the CU of the result. */
15625 static struct die_info
*
15626 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15627 struct dwarf2_cu
**ref_cu
)
15629 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15630 struct dwarf2_cu
*cu
= *ref_cu
;
15631 struct die_info
*die
;
15633 die
= follow_die_offset (offset
, ref_cu
);
15635 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15636 "at 0x%x [in module %s]"),
15637 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15642 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15643 Returned value is intended for DW_OP_call*. Returned
15644 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15646 struct dwarf2_locexpr_baton
15647 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15648 struct dwarf2_per_cu_data
*per_cu
,
15649 CORE_ADDR (*get_frame_pc
) (void *baton
),
15652 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15653 struct dwarf2_cu
*cu
;
15654 struct die_info
*die
;
15655 struct attribute
*attr
;
15656 struct dwarf2_locexpr_baton retval
;
15658 dw2_setup (per_cu
->objfile
);
15660 if (per_cu
->cu
== NULL
)
15664 die
= follow_die_offset (offset
, &cu
);
15666 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15667 offset
.sect_off
, per_cu
->objfile
->name
);
15669 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15672 /* DWARF: "If there is no such attribute, then there is no effect.".
15673 DATA is ignored if SIZE is 0. */
15675 retval
.data
= NULL
;
15678 else if (attr_form_is_section_offset (attr
))
15680 struct dwarf2_loclist_baton loclist_baton
;
15681 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15684 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15686 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15688 retval
.size
= size
;
15692 if (!attr_form_is_block (attr
))
15693 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15694 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15695 offset
.sect_off
, per_cu
->objfile
->name
);
15697 retval
.data
= DW_BLOCK (attr
)->data
;
15698 retval
.size
= DW_BLOCK (attr
)->size
;
15700 retval
.per_cu
= cu
->per_cu
;
15702 age_cached_comp_units ();
15707 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15711 dwarf2_get_die_type (cu_offset die_offset
,
15712 struct dwarf2_per_cu_data
*per_cu
)
15714 sect_offset die_offset_sect
;
15716 dw2_setup (per_cu
->objfile
);
15718 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15719 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15722 /* Follow the signature attribute ATTR in SRC_DIE.
15723 On entry *REF_CU is the CU of SRC_DIE.
15724 On exit *REF_CU is the CU of the result. */
15726 static struct die_info
*
15727 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15728 struct dwarf2_cu
**ref_cu
)
15730 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15731 struct die_info temp_die
;
15732 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15733 struct dwarf2_cu
*sig_cu
;
15734 struct die_info
*die
;
15736 /* sig_type will be NULL if the signatured type is missing from
15738 if (sig_type
== NULL
)
15739 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15740 "at 0x%x [in module %s]"),
15741 src_die
->offset
.sect_off
, objfile
->name
);
15743 /* If necessary, add it to the queue and load its DIEs. */
15745 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
15746 read_signatured_type (sig_type
);
15748 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15750 sig_cu
= sig_type
->per_cu
.cu
;
15751 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15752 temp_die
.offset
= sig_type
->type_offset_in_section
;
15753 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15754 temp_die
.offset
.sect_off
);
15761 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15762 "from DIE at 0x%x [in module %s]"),
15763 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15766 /* Given an offset of a signatured type, return its signatured_type. */
15768 static struct signatured_type
*
15769 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15770 struct dwarf2_section_info
*section
,
15771 sect_offset offset
)
15773 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15774 unsigned int length
, initial_length_size
;
15775 unsigned int sig_offset
;
15776 struct signatured_type find_entry
, *sig_type
;
15778 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15779 sig_offset
= (initial_length_size
15781 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15782 + 1 /*address_size*/);
15783 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15784 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15786 /* This is only used to lookup previously recorded types.
15787 If we didn't find it, it's our bug. */
15788 gdb_assert (sig_type
!= NULL
);
15789 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15794 /* Load the DIEs associated with type unit PER_CU into memory. */
15797 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15799 struct objfile
*objfile
= per_cu
->objfile
;
15800 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15801 sect_offset offset
= per_cu
->offset
;
15802 struct signatured_type
*sig_type
;
15804 dwarf2_read_section (objfile
, sect
);
15806 /* We have the section offset, but we need the signature to do the
15807 hash table lookup. */
15808 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15809 the signature to assert we found the right one.
15810 Ok, but it's a lot of work. We should simplify things so any needed
15811 assert doesn't require all this clumsiness. */
15812 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15814 gdb_assert (&sig_type
->per_cu
== per_cu
);
15815 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15817 read_signatured_type (sig_type
);
15819 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15822 /* die_reader_func for read_signatured_type.
15823 This is identical to load_full_comp_unit_reader,
15824 but is kept separate for now. */
15827 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15828 gdb_byte
*info_ptr
,
15829 struct die_info
*comp_unit_die
,
15833 struct dwarf2_cu
*cu
= reader
->cu
;
15834 struct attribute
*attr
;
15836 gdb_assert (cu
->die_hash
== NULL
);
15838 htab_create_alloc_ex (cu
->header
.length
/ 12,
15842 &cu
->comp_unit_obstack
,
15843 hashtab_obstack_allocate
,
15844 dummy_obstack_deallocate
);
15847 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15848 &info_ptr
, comp_unit_die
);
15849 cu
->dies
= comp_unit_die
;
15850 /* comp_unit_die is not stored in die_hash, no need. */
15852 /* We try not to read any attributes in this function, because not
15853 all CUs needed for references have been loaded yet, and symbol
15854 table processing isn't initialized. But we have to set the CU language,
15855 or we won't be able to build types correctly.
15856 Similarly, if we do not read the producer, we can not apply
15857 producer-specific interpretation. */
15858 prepare_one_comp_unit (cu
, cu
->dies
);
15861 /* Read in a signatured type and build its CU and DIEs.
15862 If the type is a stub for the real type in a DWO file,
15863 read in the real type from the DWO file as well. */
15866 read_signatured_type (struct signatured_type
*sig_type
)
15868 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15870 gdb_assert (per_cu
->is_debug_types
);
15871 gdb_assert (per_cu
->cu
== NULL
);
15873 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15876 /* Decode simple location descriptions.
15877 Given a pointer to a dwarf block that defines a location, compute
15878 the location and return the value.
15880 NOTE drow/2003-11-18: This function is called in two situations
15881 now: for the address of static or global variables (partial symbols
15882 only) and for offsets into structures which are expected to be
15883 (more or less) constant. The partial symbol case should go away,
15884 and only the constant case should remain. That will let this
15885 function complain more accurately. A few special modes are allowed
15886 without complaint for global variables (for instance, global
15887 register values and thread-local values).
15889 A location description containing no operations indicates that the
15890 object is optimized out. The return value is 0 for that case.
15891 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15892 callers will only want a very basic result and this can become a
15895 Note that stack[0] is unused except as a default error return. */
15898 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15900 struct objfile
*objfile
= cu
->objfile
;
15902 int size
= blk
->size
;
15903 gdb_byte
*data
= blk
->data
;
15904 CORE_ADDR stack
[64];
15906 unsigned int bytes_read
, unsnd
;
15912 stack
[++stacki
] = 0;
15951 stack
[++stacki
] = op
- DW_OP_lit0
;
15986 stack
[++stacki
] = op
- DW_OP_reg0
;
15988 dwarf2_complex_location_expr_complaint ();
15992 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15994 stack
[++stacki
] = unsnd
;
15996 dwarf2_complex_location_expr_complaint ();
16000 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16005 case DW_OP_const1u
:
16006 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16010 case DW_OP_const1s
:
16011 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16015 case DW_OP_const2u
:
16016 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16020 case DW_OP_const2s
:
16021 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16025 case DW_OP_const4u
:
16026 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16030 case DW_OP_const4s
:
16031 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16035 case DW_OP_const8u
:
16036 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16041 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16047 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16052 stack
[stacki
+ 1] = stack
[stacki
];
16057 stack
[stacki
- 1] += stack
[stacki
];
16061 case DW_OP_plus_uconst
:
16062 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16068 stack
[stacki
- 1] -= stack
[stacki
];
16073 /* If we're not the last op, then we definitely can't encode
16074 this using GDB's address_class enum. This is valid for partial
16075 global symbols, although the variable's address will be bogus
16078 dwarf2_complex_location_expr_complaint ();
16081 case DW_OP_GNU_push_tls_address
:
16082 /* The top of the stack has the offset from the beginning
16083 of the thread control block at which the variable is located. */
16084 /* Nothing should follow this operator, so the top of stack would
16086 /* This is valid for partial global symbols, but the variable's
16087 address will be bogus in the psymtab. Make it always at least
16088 non-zero to not look as a variable garbage collected by linker
16089 which have DW_OP_addr 0. */
16091 dwarf2_complex_location_expr_complaint ();
16095 case DW_OP_GNU_uninit
:
16098 case DW_OP_GNU_addr_index
:
16099 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16106 const char *name
= dwarf_stack_op_name (op
);
16109 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16112 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16116 return (stack
[stacki
]);
16119 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16120 outside of the allocated space. Also enforce minimum>0. */
16121 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16123 complaint (&symfile_complaints
,
16124 _("location description stack overflow"));
16130 complaint (&symfile_complaints
,
16131 _("location description stack underflow"));
16135 return (stack
[stacki
]);
16138 /* memory allocation interface */
16140 static struct dwarf_block
*
16141 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16143 struct dwarf_block
*blk
;
16145 blk
= (struct dwarf_block
*)
16146 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16150 static struct abbrev_info
*
16151 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
16153 struct abbrev_info
*abbrev
;
16155 abbrev
= (struct abbrev_info
*)
16156 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
16157 memset (abbrev
, 0, sizeof (struct abbrev_info
));
16161 static struct die_info
*
16162 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16164 struct die_info
*die
;
16165 size_t size
= sizeof (struct die_info
);
16168 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16170 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16171 memset (die
, 0, sizeof (struct die_info
));
16176 /* Macro support. */
16178 /* Return the full name of file number I in *LH's file name table.
16179 Use COMP_DIR as the name of the current directory of the
16180 compilation. The result is allocated using xmalloc; the caller is
16181 responsible for freeing it. */
16183 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16185 /* Is the file number a valid index into the line header's file name
16186 table? Remember that file numbers start with one, not zero. */
16187 if (1 <= file
&& file
<= lh
->num_file_names
)
16189 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16191 if (IS_ABSOLUTE_PATH (fe
->name
))
16192 return xstrdup (fe
->name
);
16200 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16206 dir_len
= strlen (dir
);
16207 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16208 strcpy (full_name
, dir
);
16209 full_name
[dir_len
] = '/';
16210 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16214 return xstrdup (fe
->name
);
16219 /* The compiler produced a bogus file number. We can at least
16220 record the macro definitions made in the file, even if we
16221 won't be able to find the file by name. */
16222 char fake_name
[80];
16224 sprintf (fake_name
, "<bad macro file number %d>", file
);
16226 complaint (&symfile_complaints
,
16227 _("bad file number in macro information (%d)"),
16230 return xstrdup (fake_name
);
16235 static struct macro_source_file
*
16236 macro_start_file (int file
, int line
,
16237 struct macro_source_file
*current_file
,
16238 const char *comp_dir
,
16239 struct line_header
*lh
, struct objfile
*objfile
)
16241 /* The full name of this source file. */
16242 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16244 /* We don't create a macro table for this compilation unit
16245 at all until we actually get a filename. */
16246 if (! pending_macros
)
16247 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16248 objfile
->macro_cache
);
16250 if (! current_file
)
16251 /* If we have no current file, then this must be the start_file
16252 directive for the compilation unit's main source file. */
16253 current_file
= macro_set_main (pending_macros
, full_name
);
16255 current_file
= macro_include (current_file
, line
, full_name
);
16259 return current_file
;
16263 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16264 followed by a null byte. */
16266 copy_string (const char *buf
, int len
)
16268 char *s
= xmalloc (len
+ 1);
16270 memcpy (s
, buf
, len
);
16276 static const char *
16277 consume_improper_spaces (const char *p
, const char *body
)
16281 complaint (&symfile_complaints
,
16282 _("macro definition contains spaces "
16283 "in formal argument list:\n`%s'"),
16295 parse_macro_definition (struct macro_source_file
*file
, int line
,
16300 /* The body string takes one of two forms. For object-like macro
16301 definitions, it should be:
16303 <macro name> " " <definition>
16305 For function-like macro definitions, it should be:
16307 <macro name> "() " <definition>
16309 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16311 Spaces may appear only where explicitly indicated, and in the
16314 The Dwarf 2 spec says that an object-like macro's name is always
16315 followed by a space, but versions of GCC around March 2002 omit
16316 the space when the macro's definition is the empty string.
16318 The Dwarf 2 spec says that there should be no spaces between the
16319 formal arguments in a function-like macro's formal argument list,
16320 but versions of GCC around March 2002 include spaces after the
16324 /* Find the extent of the macro name. The macro name is terminated
16325 by either a space or null character (for an object-like macro) or
16326 an opening paren (for a function-like macro). */
16327 for (p
= body
; *p
; p
++)
16328 if (*p
== ' ' || *p
== '(')
16331 if (*p
== ' ' || *p
== '\0')
16333 /* It's an object-like macro. */
16334 int name_len
= p
- body
;
16335 char *name
= copy_string (body
, name_len
);
16336 const char *replacement
;
16339 replacement
= body
+ name_len
+ 1;
16342 dwarf2_macro_malformed_definition_complaint (body
);
16343 replacement
= body
+ name_len
;
16346 macro_define_object (file
, line
, name
, replacement
);
16350 else if (*p
== '(')
16352 /* It's a function-like macro. */
16353 char *name
= copy_string (body
, p
- body
);
16356 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16360 p
= consume_improper_spaces (p
, body
);
16362 /* Parse the formal argument list. */
16363 while (*p
&& *p
!= ')')
16365 /* Find the extent of the current argument name. */
16366 const char *arg_start
= p
;
16368 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16371 if (! *p
|| p
== arg_start
)
16372 dwarf2_macro_malformed_definition_complaint (body
);
16375 /* Make sure argv has room for the new argument. */
16376 if (argc
>= argv_size
)
16379 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16382 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16385 p
= consume_improper_spaces (p
, body
);
16387 /* Consume the comma, if present. */
16392 p
= consume_improper_spaces (p
, body
);
16401 /* Perfectly formed definition, no complaints. */
16402 macro_define_function (file
, line
, name
,
16403 argc
, (const char **) argv
,
16405 else if (*p
== '\0')
16407 /* Complain, but do define it. */
16408 dwarf2_macro_malformed_definition_complaint (body
);
16409 macro_define_function (file
, line
, name
,
16410 argc
, (const char **) argv
,
16414 /* Just complain. */
16415 dwarf2_macro_malformed_definition_complaint (body
);
16418 /* Just complain. */
16419 dwarf2_macro_malformed_definition_complaint (body
);
16425 for (i
= 0; i
< argc
; i
++)
16431 dwarf2_macro_malformed_definition_complaint (body
);
16434 /* Skip some bytes from BYTES according to the form given in FORM.
16435 Returns the new pointer. */
16438 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
,
16439 enum dwarf_form form
,
16440 unsigned int offset_size
,
16441 struct dwarf2_section_info
*section
)
16443 unsigned int bytes_read
;
16447 case DW_FORM_data1
:
16452 case DW_FORM_data2
:
16456 case DW_FORM_data4
:
16460 case DW_FORM_data8
:
16464 case DW_FORM_string
:
16465 read_direct_string (abfd
, bytes
, &bytes_read
);
16466 bytes
+= bytes_read
;
16469 case DW_FORM_sec_offset
:
16471 bytes
+= offset_size
;
16474 case DW_FORM_block
:
16475 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16476 bytes
+= bytes_read
;
16479 case DW_FORM_block1
:
16480 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16482 case DW_FORM_block2
:
16483 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16485 case DW_FORM_block4
:
16486 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16489 case DW_FORM_sdata
:
16490 case DW_FORM_udata
:
16491 case DW_FORM_GNU_addr_index
:
16492 case DW_FORM_GNU_str_index
:
16493 bytes
= skip_leb128 (abfd
, bytes
);
16499 complaint (&symfile_complaints
,
16500 _("invalid form 0x%x in `%s'"),
16502 section
->asection
->name
);
16510 /* A helper for dwarf_decode_macros that handles skipping an unknown
16511 opcode. Returns an updated pointer to the macro data buffer; or,
16512 on error, issues a complaint and returns NULL. */
16515 skip_unknown_opcode (unsigned int opcode
,
16516 gdb_byte
**opcode_definitions
,
16519 unsigned int offset_size
,
16520 struct dwarf2_section_info
*section
)
16522 unsigned int bytes_read
, i
;
16526 if (opcode_definitions
[opcode
] == NULL
)
16528 complaint (&symfile_complaints
,
16529 _("unrecognized DW_MACFINO opcode 0x%x"),
16534 defn
= opcode_definitions
[opcode
];
16535 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16536 defn
+= bytes_read
;
16538 for (i
= 0; i
< arg
; ++i
)
16540 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, defn
[i
], offset_size
, section
);
16541 if (mac_ptr
== NULL
)
16543 /* skip_form_bytes already issued the complaint. */
16551 /* A helper function which parses the header of a macro section.
16552 If the macro section is the extended (for now called "GNU") type,
16553 then this updates *OFFSET_SIZE. Returns a pointer to just after
16554 the header, or issues a complaint and returns NULL on error. */
16557 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16560 unsigned int *offset_size
,
16561 int section_is_gnu
)
16563 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16565 if (section_is_gnu
)
16567 unsigned int version
, flags
;
16569 version
= read_2_bytes (abfd
, mac_ptr
);
16572 complaint (&symfile_complaints
,
16573 _("unrecognized version `%d' in .debug_macro section"),
16579 flags
= read_1_byte (abfd
, mac_ptr
);
16581 *offset_size
= (flags
& 1) ? 8 : 4;
16583 if ((flags
& 2) != 0)
16584 /* We don't need the line table offset. */
16585 mac_ptr
+= *offset_size
;
16587 /* Vendor opcode descriptions. */
16588 if ((flags
& 4) != 0)
16590 unsigned int i
, count
;
16592 count
= read_1_byte (abfd
, mac_ptr
);
16594 for (i
= 0; i
< count
; ++i
)
16596 unsigned int opcode
, bytes_read
;
16599 opcode
= read_1_byte (abfd
, mac_ptr
);
16601 opcode_definitions
[opcode
] = mac_ptr
;
16602 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16603 mac_ptr
+= bytes_read
;
16612 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16613 including DW_MACRO_GNU_transparent_include. */
16616 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16617 struct macro_source_file
*current_file
,
16618 struct line_header
*lh
, char *comp_dir
,
16619 struct dwarf2_section_info
*section
,
16620 int section_is_gnu
,
16621 unsigned int offset_size
,
16622 struct objfile
*objfile
,
16623 htab_t include_hash
)
16625 enum dwarf_macro_record_type macinfo_type
;
16626 int at_commandline
;
16627 gdb_byte
*opcode_definitions
[256];
16629 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16630 &offset_size
, section_is_gnu
);
16631 if (mac_ptr
== NULL
)
16633 /* We already issued a complaint. */
16637 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16638 GDB is still reading the definitions from command line. First
16639 DW_MACINFO_start_file will need to be ignored as it was already executed
16640 to create CURRENT_FILE for the main source holding also the command line
16641 definitions. On first met DW_MACINFO_start_file this flag is reset to
16642 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16644 at_commandline
= 1;
16648 /* Do we at least have room for a macinfo type byte? */
16649 if (mac_ptr
>= mac_end
)
16651 dwarf2_macros_too_long_complaint (section
);
16655 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16658 /* Note that we rely on the fact that the corresponding GNU and
16659 DWARF constants are the same. */
16660 switch (macinfo_type
)
16662 /* A zero macinfo type indicates the end of the macro
16667 case DW_MACRO_GNU_define
:
16668 case DW_MACRO_GNU_undef
:
16669 case DW_MACRO_GNU_define_indirect
:
16670 case DW_MACRO_GNU_undef_indirect
:
16672 unsigned int bytes_read
;
16677 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16678 mac_ptr
+= bytes_read
;
16680 if (macinfo_type
== DW_MACRO_GNU_define
16681 || macinfo_type
== DW_MACRO_GNU_undef
)
16683 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16684 mac_ptr
+= bytes_read
;
16688 LONGEST str_offset
;
16690 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16691 mac_ptr
+= offset_size
;
16693 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16696 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16697 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16698 if (! current_file
)
16700 /* DWARF violation as no main source is present. */
16701 complaint (&symfile_complaints
,
16702 _("debug info with no main source gives macro %s "
16704 is_define
? _("definition") : _("undefinition"),
16708 if ((line
== 0 && !at_commandline
)
16709 || (line
!= 0 && at_commandline
))
16710 complaint (&symfile_complaints
,
16711 _("debug info gives %s macro %s with %s line %d: %s"),
16712 at_commandline
? _("command-line") : _("in-file"),
16713 is_define
? _("definition") : _("undefinition"),
16714 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16717 parse_macro_definition (current_file
, line
, body
);
16720 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16721 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16722 macro_undef (current_file
, line
, body
);
16727 case DW_MACRO_GNU_start_file
:
16729 unsigned int bytes_read
;
16732 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16733 mac_ptr
+= bytes_read
;
16734 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16735 mac_ptr
+= bytes_read
;
16737 if ((line
== 0 && !at_commandline
)
16738 || (line
!= 0 && at_commandline
))
16739 complaint (&symfile_complaints
,
16740 _("debug info gives source %d included "
16741 "from %s at %s line %d"),
16742 file
, at_commandline
? _("command-line") : _("file"),
16743 line
== 0 ? _("zero") : _("non-zero"), line
);
16745 if (at_commandline
)
16747 /* This DW_MACRO_GNU_start_file was executed in the
16749 at_commandline
= 0;
16752 current_file
= macro_start_file (file
, line
,
16753 current_file
, comp_dir
,
16758 case DW_MACRO_GNU_end_file
:
16759 if (! current_file
)
16760 complaint (&symfile_complaints
,
16761 _("macro debug info has an unmatched "
16762 "`close_file' directive"));
16765 current_file
= current_file
->included_by
;
16766 if (! current_file
)
16768 enum dwarf_macro_record_type next_type
;
16770 /* GCC circa March 2002 doesn't produce the zero
16771 type byte marking the end of the compilation
16772 unit. Complain if it's not there, but exit no
16775 /* Do we at least have room for a macinfo type byte? */
16776 if (mac_ptr
>= mac_end
)
16778 dwarf2_macros_too_long_complaint (section
);
16782 /* We don't increment mac_ptr here, so this is just
16784 next_type
= read_1_byte (abfd
, mac_ptr
);
16785 if (next_type
!= 0)
16786 complaint (&symfile_complaints
,
16787 _("no terminating 0-type entry for "
16788 "macros in `.debug_macinfo' section"));
16795 case DW_MACRO_GNU_transparent_include
:
16800 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16801 mac_ptr
+= offset_size
;
16803 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16806 /* This has actually happened; see
16807 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16808 complaint (&symfile_complaints
,
16809 _("recursive DW_MACRO_GNU_transparent_include in "
16810 ".debug_macro section"));
16816 dwarf_decode_macro_bytes (abfd
,
16817 section
->buffer
+ offset
,
16818 mac_end
, current_file
,
16820 section
, section_is_gnu
,
16821 offset_size
, objfile
, include_hash
);
16823 htab_remove_elt (include_hash
, mac_ptr
);
16828 case DW_MACINFO_vendor_ext
:
16829 if (!section_is_gnu
)
16831 unsigned int bytes_read
;
16834 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16835 mac_ptr
+= bytes_read
;
16836 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16837 mac_ptr
+= bytes_read
;
16839 /* We don't recognize any vendor extensions. */
16845 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16846 mac_ptr
, abfd
, offset_size
,
16848 if (mac_ptr
== NULL
)
16852 } while (macinfo_type
!= 0);
16856 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
16857 char *comp_dir
, bfd
*abfd
,
16858 struct dwarf2_cu
*cu
,
16859 struct dwarf2_section_info
*section
,
16860 int section_is_gnu
, const char *section_name
)
16862 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16863 gdb_byte
*mac_ptr
, *mac_end
;
16864 struct macro_source_file
*current_file
= 0;
16865 enum dwarf_macro_record_type macinfo_type
;
16866 unsigned int offset_size
= cu
->header
.offset_size
;
16867 gdb_byte
*opcode_definitions
[256];
16868 struct cleanup
*cleanup
;
16869 htab_t include_hash
;
16872 dwarf2_read_section (objfile
, section
);
16873 if (section
->buffer
== NULL
)
16875 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16879 /* First pass: Find the name of the base filename.
16880 This filename is needed in order to process all macros whose definition
16881 (or undefinition) comes from the command line. These macros are defined
16882 before the first DW_MACINFO_start_file entry, and yet still need to be
16883 associated to the base file.
16885 To determine the base file name, we scan the macro definitions until we
16886 reach the first DW_MACINFO_start_file entry. We then initialize
16887 CURRENT_FILE accordingly so that any macro definition found before the
16888 first DW_MACINFO_start_file can still be associated to the base file. */
16890 mac_ptr
= section
->buffer
+ offset
;
16891 mac_end
= section
->buffer
+ section
->size
;
16893 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16894 &offset_size
, section_is_gnu
);
16895 if (mac_ptr
== NULL
)
16897 /* We already issued a complaint. */
16903 /* Do we at least have room for a macinfo type byte? */
16904 if (mac_ptr
>= mac_end
)
16906 /* Complaint is printed during the second pass as GDB will probably
16907 stop the first pass earlier upon finding
16908 DW_MACINFO_start_file. */
16912 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16915 /* Note that we rely on the fact that the corresponding GNU and
16916 DWARF constants are the same. */
16917 switch (macinfo_type
)
16919 /* A zero macinfo type indicates the end of the macro
16924 case DW_MACRO_GNU_define
:
16925 case DW_MACRO_GNU_undef
:
16926 /* Only skip the data by MAC_PTR. */
16928 unsigned int bytes_read
;
16930 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16931 mac_ptr
+= bytes_read
;
16932 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16933 mac_ptr
+= bytes_read
;
16937 case DW_MACRO_GNU_start_file
:
16939 unsigned int bytes_read
;
16942 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16943 mac_ptr
+= bytes_read
;
16944 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16945 mac_ptr
+= bytes_read
;
16947 current_file
= macro_start_file (file
, line
, current_file
,
16948 comp_dir
, lh
, objfile
);
16952 case DW_MACRO_GNU_end_file
:
16953 /* No data to skip by MAC_PTR. */
16956 case DW_MACRO_GNU_define_indirect
:
16957 case DW_MACRO_GNU_undef_indirect
:
16959 unsigned int bytes_read
;
16961 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16962 mac_ptr
+= bytes_read
;
16963 mac_ptr
+= offset_size
;
16967 case DW_MACRO_GNU_transparent_include
:
16968 /* Note that, according to the spec, a transparent include
16969 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16970 skip this opcode. */
16971 mac_ptr
+= offset_size
;
16974 case DW_MACINFO_vendor_ext
:
16975 /* Only skip the data by MAC_PTR. */
16976 if (!section_is_gnu
)
16978 unsigned int bytes_read
;
16980 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16981 mac_ptr
+= bytes_read
;
16982 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16983 mac_ptr
+= bytes_read
;
16988 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16989 mac_ptr
, abfd
, offset_size
,
16991 if (mac_ptr
== NULL
)
16995 } while (macinfo_type
!= 0 && current_file
== NULL
);
16997 /* Second pass: Process all entries.
16999 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17000 command-line macro definitions/undefinitions. This flag is unset when we
17001 reach the first DW_MACINFO_start_file entry. */
17003 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17004 NULL
, xcalloc
, xfree
);
17005 cleanup
= make_cleanup_htab_delete (include_hash
);
17006 mac_ptr
= section
->buffer
+ offset
;
17007 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17009 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17010 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17011 offset_size
, objfile
, include_hash
);
17012 do_cleanups (cleanup
);
17015 /* Check if the attribute's form is a DW_FORM_block*
17016 if so return true else false. */
17019 attr_form_is_block (struct attribute
*attr
)
17021 return (attr
== NULL
? 0 :
17022 attr
->form
== DW_FORM_block1
17023 || attr
->form
== DW_FORM_block2
17024 || attr
->form
== DW_FORM_block4
17025 || attr
->form
== DW_FORM_block
17026 || attr
->form
== DW_FORM_exprloc
);
17029 /* Return non-zero if ATTR's value is a section offset --- classes
17030 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17031 You may use DW_UNSND (attr) to retrieve such offsets.
17033 Section 7.5.4, "Attribute Encodings", explains that no attribute
17034 may have a value that belongs to more than one of these classes; it
17035 would be ambiguous if we did, because we use the same forms for all
17039 attr_form_is_section_offset (struct attribute
*attr
)
17041 return (attr
->form
== DW_FORM_data4
17042 || attr
->form
== DW_FORM_data8
17043 || attr
->form
== DW_FORM_sec_offset
);
17046 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17047 zero otherwise. When this function returns true, you can apply
17048 dwarf2_get_attr_constant_value to it.
17050 However, note that for some attributes you must check
17051 attr_form_is_section_offset before using this test. DW_FORM_data4
17052 and DW_FORM_data8 are members of both the constant class, and of
17053 the classes that contain offsets into other debug sections
17054 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17055 that, if an attribute's can be either a constant or one of the
17056 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17057 taken as section offsets, not constants. */
17060 attr_form_is_constant (struct attribute
*attr
)
17062 switch (attr
->form
)
17064 case DW_FORM_sdata
:
17065 case DW_FORM_udata
:
17066 case DW_FORM_data1
:
17067 case DW_FORM_data2
:
17068 case DW_FORM_data4
:
17069 case DW_FORM_data8
:
17076 /* Return the .debug_loc section to use for CU.
17077 For DWO files use .debug_loc.dwo. */
17079 static struct dwarf2_section_info
*
17080 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17083 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17084 return &dwarf2_per_objfile
->loc
;
17087 /* A helper function that fills in a dwarf2_loclist_baton. */
17090 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17091 struct dwarf2_loclist_baton
*baton
,
17092 struct attribute
*attr
)
17094 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17096 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17098 baton
->per_cu
= cu
->per_cu
;
17099 gdb_assert (baton
->per_cu
);
17100 /* We don't know how long the location list is, but make sure we
17101 don't run off the edge of the section. */
17102 baton
->size
= section
->size
- DW_UNSND (attr
);
17103 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17104 baton
->base_address
= cu
->base_address
;
17108 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17109 struct dwarf2_cu
*cu
)
17111 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17112 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17114 if (attr_form_is_section_offset (attr
)
17115 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17116 the section. If so, fall through to the complaint in the
17118 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17120 struct dwarf2_loclist_baton
*baton
;
17122 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17123 sizeof (struct dwarf2_loclist_baton
));
17125 fill_in_loclist_baton (cu
, baton
, attr
);
17127 if (cu
->base_known
== 0)
17128 complaint (&symfile_complaints
,
17129 _("Location list used without "
17130 "specifying the CU base address."));
17132 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17133 SYMBOL_LOCATION_BATON (sym
) = baton
;
17137 struct dwarf2_locexpr_baton
*baton
;
17139 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17140 sizeof (struct dwarf2_locexpr_baton
));
17141 baton
->per_cu
= cu
->per_cu
;
17142 gdb_assert (baton
->per_cu
);
17144 if (attr_form_is_block (attr
))
17146 /* Note that we're just copying the block's data pointer
17147 here, not the actual data. We're still pointing into the
17148 info_buffer for SYM's objfile; right now we never release
17149 that buffer, but when we do clean up properly this may
17151 baton
->size
= DW_BLOCK (attr
)->size
;
17152 baton
->data
= DW_BLOCK (attr
)->data
;
17156 dwarf2_invalid_attrib_class_complaint ("location description",
17157 SYMBOL_NATURAL_NAME (sym
));
17161 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17162 SYMBOL_LOCATION_BATON (sym
) = baton
;
17166 /* Return the OBJFILE associated with the compilation unit CU. If CU
17167 came from a separate debuginfo file, then the master objfile is
17171 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17173 struct objfile
*objfile
= per_cu
->objfile
;
17175 /* Return the master objfile, so that we can report and look up the
17176 correct file containing this variable. */
17177 if (objfile
->separate_debug_objfile_backlink
)
17178 objfile
= objfile
->separate_debug_objfile_backlink
;
17183 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17184 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17185 CU_HEADERP first. */
17187 static const struct comp_unit_head
*
17188 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17189 struct dwarf2_per_cu_data
*per_cu
)
17191 struct objfile
*objfile
;
17192 struct dwarf2_per_objfile
*per_objfile
;
17193 gdb_byte
*info_ptr
;
17196 return &per_cu
->cu
->header
;
17198 objfile
= per_cu
->objfile
;
17199 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17200 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
17202 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17203 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
17208 /* Return the address size given in the compilation unit header for CU. */
17211 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17213 struct comp_unit_head cu_header_local
;
17214 const struct comp_unit_head
*cu_headerp
;
17216 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17218 return cu_headerp
->addr_size
;
17221 /* Return the offset size given in the compilation unit header for CU. */
17224 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17226 struct comp_unit_head cu_header_local
;
17227 const struct comp_unit_head
*cu_headerp
;
17229 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17231 return cu_headerp
->offset_size
;
17234 /* See its dwarf2loc.h declaration. */
17237 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17239 struct comp_unit_head cu_header_local
;
17240 const struct comp_unit_head
*cu_headerp
;
17242 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17244 if (cu_headerp
->version
== 2)
17245 return cu_headerp
->addr_size
;
17247 return cu_headerp
->offset_size
;
17250 /* Return the text offset of the CU. The returned offset comes from
17251 this CU's objfile. If this objfile came from a separate debuginfo
17252 file, then the offset may be different from the corresponding
17253 offset in the parent objfile. */
17256 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17258 struct objfile
*objfile
= per_cu
->objfile
;
17260 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17263 /* Locate the .debug_info compilation unit from CU's objfile which contains
17264 the DIE at OFFSET. Raises an error on failure. */
17266 static struct dwarf2_per_cu_data
*
17267 dwarf2_find_containing_comp_unit (sect_offset offset
,
17268 struct objfile
*objfile
)
17270 struct dwarf2_per_cu_data
*this_cu
;
17274 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17277 int mid
= low
+ (high
- low
) / 2;
17279 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17280 >= offset
.sect_off
)
17285 gdb_assert (low
== high
);
17286 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17290 error (_("Dwarf Error: could not find partial DIE containing "
17291 "offset 0x%lx [in module %s]"),
17292 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17294 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17295 <= offset
.sect_off
);
17296 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17300 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17301 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17302 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17303 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17304 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17309 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17312 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17314 memset (cu
, 0, sizeof (*cu
));
17316 cu
->per_cu
= per_cu
;
17317 cu
->objfile
= per_cu
->objfile
;
17318 obstack_init (&cu
->comp_unit_obstack
);
17321 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17324 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
17326 struct attribute
*attr
;
17328 /* Set the language we're debugging. */
17329 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17331 set_cu_language (DW_UNSND (attr
), cu
);
17334 cu
->language
= language_minimal
;
17335 cu
->language_defn
= language_def (cu
->language
);
17338 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17340 cu
->producer
= DW_STRING (attr
);
17343 /* Release one cached compilation unit, CU. We unlink it from the tree
17344 of compilation units, but we don't remove it from the read_in_chain;
17345 the caller is responsible for that.
17346 NOTE: DATA is a void * because this function is also used as a
17347 cleanup routine. */
17350 free_heap_comp_unit (void *data
)
17352 struct dwarf2_cu
*cu
= data
;
17354 gdb_assert (cu
->per_cu
!= NULL
);
17355 cu
->per_cu
->cu
= NULL
;
17358 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17363 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17364 when we're finished with it. We can't free the pointer itself, but be
17365 sure to unlink it from the cache. Also release any associated storage. */
17368 free_stack_comp_unit (void *data
)
17370 struct dwarf2_cu
*cu
= data
;
17372 gdb_assert (cu
->per_cu
!= NULL
);
17373 cu
->per_cu
->cu
= NULL
;
17376 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17377 cu
->partial_dies
= NULL
;
17380 /* Free all cached compilation units. */
17383 free_cached_comp_units (void *data
)
17385 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17387 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17388 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17389 while (per_cu
!= NULL
)
17391 struct dwarf2_per_cu_data
*next_cu
;
17393 next_cu
= per_cu
->cu
->read_in_chain
;
17395 free_heap_comp_unit (per_cu
->cu
);
17396 *last_chain
= next_cu
;
17402 /* Increase the age counter on each cached compilation unit, and free
17403 any that are too old. */
17406 age_cached_comp_units (void)
17408 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17410 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17411 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17412 while (per_cu
!= NULL
)
17414 per_cu
->cu
->last_used
++;
17415 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17416 dwarf2_mark (per_cu
->cu
);
17417 per_cu
= per_cu
->cu
->read_in_chain
;
17420 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17421 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17422 while (per_cu
!= NULL
)
17424 struct dwarf2_per_cu_data
*next_cu
;
17426 next_cu
= per_cu
->cu
->read_in_chain
;
17428 if (!per_cu
->cu
->mark
)
17430 free_heap_comp_unit (per_cu
->cu
);
17431 *last_chain
= next_cu
;
17434 last_chain
= &per_cu
->cu
->read_in_chain
;
17440 /* Remove a single compilation unit from the cache. */
17443 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17445 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17447 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17448 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17449 while (per_cu
!= NULL
)
17451 struct dwarf2_per_cu_data
*next_cu
;
17453 next_cu
= per_cu
->cu
->read_in_chain
;
17455 if (per_cu
== target_per_cu
)
17457 free_heap_comp_unit (per_cu
->cu
);
17459 *last_chain
= next_cu
;
17463 last_chain
= &per_cu
->cu
->read_in_chain
;
17469 /* Release all extra memory associated with OBJFILE. */
17472 dwarf2_free_objfile (struct objfile
*objfile
)
17474 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17476 if (dwarf2_per_objfile
== NULL
)
17479 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17480 free_cached_comp_units (NULL
);
17482 if (dwarf2_per_objfile
->quick_file_names_table
)
17483 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17485 /* Everything else should be on the objfile obstack. */
17488 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17489 We store these in a hash table separate from the DIEs, and preserve them
17490 when the DIEs are flushed out of cache.
17492 The CU "per_cu" pointer is needed because offset alone is not enough to
17493 uniquely identify the type. A file may have multiple .debug_types sections,
17494 or the type may come from a DWO file. We have to use something in
17495 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17496 routine, get_die_type_at_offset, from outside this file, and thus won't
17497 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17500 struct dwarf2_per_cu_offset_and_type
17502 const struct dwarf2_per_cu_data
*per_cu
;
17503 sect_offset offset
;
17507 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17510 per_cu_offset_and_type_hash (const void *item
)
17512 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17514 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17517 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17520 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17522 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17523 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17525 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17526 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17529 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17530 table if necessary. For convenience, return TYPE.
17532 The DIEs reading must have careful ordering to:
17533 * Not cause infite loops trying to read in DIEs as a prerequisite for
17534 reading current DIE.
17535 * Not trying to dereference contents of still incompletely read in types
17536 while reading in other DIEs.
17537 * Enable referencing still incompletely read in types just by a pointer to
17538 the type without accessing its fields.
17540 Therefore caller should follow these rules:
17541 * Try to fetch any prerequisite types we may need to build this DIE type
17542 before building the type and calling set_die_type.
17543 * After building type call set_die_type for current DIE as soon as
17544 possible before fetching more types to complete the current type.
17545 * Make the type as complete as possible before fetching more types. */
17547 static struct type
*
17548 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17550 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17551 struct objfile
*objfile
= cu
->objfile
;
17553 /* For Ada types, make sure that the gnat-specific data is always
17554 initialized (if not already set). There are a few types where
17555 we should not be doing so, because the type-specific area is
17556 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17557 where the type-specific area is used to store the floatformat).
17558 But this is not a problem, because the gnat-specific information
17559 is actually not needed for these types. */
17560 if (need_gnat_info (cu
)
17561 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17562 && TYPE_CODE (type
) != TYPE_CODE_FLT
17563 && !HAVE_GNAT_AUX_INFO (type
))
17564 INIT_GNAT_SPECIFIC (type
);
17566 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17568 dwarf2_per_objfile
->die_type_hash
=
17569 htab_create_alloc_ex (127,
17570 per_cu_offset_and_type_hash
,
17571 per_cu_offset_and_type_eq
,
17573 &objfile
->objfile_obstack
,
17574 hashtab_obstack_allocate
,
17575 dummy_obstack_deallocate
);
17578 ofs
.per_cu
= cu
->per_cu
;
17579 ofs
.offset
= die
->offset
;
17581 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17582 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17584 complaint (&symfile_complaints
,
17585 _("A problem internal to GDB: DIE 0x%x has type already set"),
17586 die
->offset
.sect_off
);
17587 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17592 /* Look up the type for the die at OFFSET in the appropriate type_hash
17593 table, or return NULL if the die does not have a saved type. */
17595 static struct type
*
17596 get_die_type_at_offset (sect_offset offset
,
17597 struct dwarf2_per_cu_data
*per_cu
)
17599 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17601 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17604 ofs
.per_cu
= per_cu
;
17605 ofs
.offset
= offset
;
17606 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17613 /* Look up the type for DIE in the appropriate type_hash table,
17614 or return NULL if DIE does not have a saved type. */
17616 static struct type
*
17617 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17619 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17622 /* Add a dependence relationship from CU to REF_PER_CU. */
17625 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17626 struct dwarf2_per_cu_data
*ref_per_cu
)
17630 if (cu
->dependencies
== NULL
)
17632 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17633 NULL
, &cu
->comp_unit_obstack
,
17634 hashtab_obstack_allocate
,
17635 dummy_obstack_deallocate
);
17637 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17639 *slot
= ref_per_cu
;
17642 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17643 Set the mark field in every compilation unit in the
17644 cache that we must keep because we are keeping CU. */
17647 dwarf2_mark_helper (void **slot
, void *data
)
17649 struct dwarf2_per_cu_data
*per_cu
;
17651 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17653 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17654 reading of the chain. As such dependencies remain valid it is not much
17655 useful to track and undo them during QUIT cleanups. */
17656 if (per_cu
->cu
== NULL
)
17659 if (per_cu
->cu
->mark
)
17661 per_cu
->cu
->mark
= 1;
17663 if (per_cu
->cu
->dependencies
!= NULL
)
17664 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17669 /* Set the mark field in CU and in every other compilation unit in the
17670 cache that we must keep because we are keeping CU. */
17673 dwarf2_mark (struct dwarf2_cu
*cu
)
17678 if (cu
->dependencies
!= NULL
)
17679 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17683 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17687 per_cu
->cu
->mark
= 0;
17688 per_cu
= per_cu
->cu
->read_in_chain
;
17692 /* Trivial hash function for partial_die_info: the hash value of a DIE
17693 is its offset in .debug_info for this objfile. */
17696 partial_die_hash (const void *item
)
17698 const struct partial_die_info
*part_die
= item
;
17700 return part_die
->offset
.sect_off
;
17703 /* Trivial comparison function for partial_die_info structures: two DIEs
17704 are equal if they have the same offset. */
17707 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17709 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17710 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17712 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17715 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17716 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17719 set_dwarf2_cmd (char *args
, int from_tty
)
17721 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17725 show_dwarf2_cmd (char *args
, int from_tty
)
17727 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17730 /* If section described by INFO was mmapped, munmap it now. */
17733 munmap_section_buffer (struct dwarf2_section_info
*info
)
17735 if (info
->map_addr
!= NULL
)
17740 res
= munmap (info
->map_addr
, info
->map_len
);
17741 gdb_assert (res
== 0);
17743 /* Without HAVE_MMAP, we should never be here to begin with. */
17744 gdb_assert_not_reached ("no mmap support");
17749 /* munmap debug sections for OBJFILE, if necessary. */
17752 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17754 struct dwarf2_per_objfile
*data
= d
;
17756 struct dwarf2_section_info
*section
;
17758 /* This is sorted according to the order they're defined in to make it easier
17759 to keep in sync. */
17760 munmap_section_buffer (&data
->info
);
17761 munmap_section_buffer (&data
->abbrev
);
17762 munmap_section_buffer (&data
->line
);
17763 munmap_section_buffer (&data
->loc
);
17764 munmap_section_buffer (&data
->macinfo
);
17765 munmap_section_buffer (&data
->macro
);
17766 munmap_section_buffer (&data
->str
);
17767 munmap_section_buffer (&data
->ranges
);
17768 munmap_section_buffer (&data
->addr
);
17769 munmap_section_buffer (&data
->frame
);
17770 munmap_section_buffer (&data
->eh_frame
);
17771 munmap_section_buffer (&data
->gdb_index
);
17774 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17776 munmap_section_buffer (section
);
17778 VEC_free (dwarf2_section_info_def
, data
->types
);
17780 if (data
->dwo_files
)
17781 free_dwo_files (data
->dwo_files
, objfile
);
17785 /* The "save gdb-index" command. */
17787 /* The contents of the hash table we create when building the string
17789 struct strtab_entry
17791 offset_type offset
;
17795 /* Hash function for a strtab_entry.
17797 Function is used only during write_hash_table so no index format backward
17798 compatibility is needed. */
17801 hash_strtab_entry (const void *e
)
17803 const struct strtab_entry
*entry
= e
;
17804 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17807 /* Equality function for a strtab_entry. */
17810 eq_strtab_entry (const void *a
, const void *b
)
17812 const struct strtab_entry
*ea
= a
;
17813 const struct strtab_entry
*eb
= b
;
17814 return !strcmp (ea
->str
, eb
->str
);
17817 /* Create a strtab_entry hash table. */
17820 create_strtab (void)
17822 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17823 xfree
, xcalloc
, xfree
);
17826 /* Add a string to the constant pool. Return the string's offset in
17830 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17833 struct strtab_entry entry
;
17834 struct strtab_entry
*result
;
17837 slot
= htab_find_slot (table
, &entry
, INSERT
);
17842 result
= XNEW (struct strtab_entry
);
17843 result
->offset
= obstack_object_size (cpool
);
17845 obstack_grow_str0 (cpool
, str
);
17848 return result
->offset
;
17851 /* An entry in the symbol table. */
17852 struct symtab_index_entry
17854 /* The name of the symbol. */
17856 /* The offset of the name in the constant pool. */
17857 offset_type index_offset
;
17858 /* A sorted vector of the indices of all the CUs that hold an object
17860 VEC (offset_type
) *cu_indices
;
17863 /* The symbol table. This is a power-of-2-sized hash table. */
17864 struct mapped_symtab
17866 offset_type n_elements
;
17868 struct symtab_index_entry
**data
;
17871 /* Hash function for a symtab_index_entry. */
17874 hash_symtab_entry (const void *e
)
17876 const struct symtab_index_entry
*entry
= e
;
17877 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17878 sizeof (offset_type
) * VEC_length (offset_type
,
17879 entry
->cu_indices
),
17883 /* Equality function for a symtab_index_entry. */
17886 eq_symtab_entry (const void *a
, const void *b
)
17888 const struct symtab_index_entry
*ea
= a
;
17889 const struct symtab_index_entry
*eb
= b
;
17890 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17891 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17893 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17894 VEC_address (offset_type
, eb
->cu_indices
),
17895 sizeof (offset_type
) * len
);
17898 /* Destroy a symtab_index_entry. */
17901 delete_symtab_entry (void *p
)
17903 struct symtab_index_entry
*entry
= p
;
17904 VEC_free (offset_type
, entry
->cu_indices
);
17908 /* Create a hash table holding symtab_index_entry objects. */
17911 create_symbol_hash_table (void)
17913 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17914 delete_symtab_entry
, xcalloc
, xfree
);
17917 /* Create a new mapped symtab object. */
17919 static struct mapped_symtab
*
17920 create_mapped_symtab (void)
17922 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17923 symtab
->n_elements
= 0;
17924 symtab
->size
= 1024;
17925 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17929 /* Destroy a mapped_symtab. */
17932 cleanup_mapped_symtab (void *p
)
17934 struct mapped_symtab
*symtab
= p
;
17935 /* The contents of the array are freed when the other hash table is
17937 xfree (symtab
->data
);
17941 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17944 Function is used only during write_hash_table so no index format backward
17945 compatibility is needed. */
17947 static struct symtab_index_entry
**
17948 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17950 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17952 index
= hash
& (symtab
->size
- 1);
17953 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17957 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17958 return &symtab
->data
[index
];
17959 index
= (index
+ step
) & (symtab
->size
- 1);
17963 /* Expand SYMTAB's hash table. */
17966 hash_expand (struct mapped_symtab
*symtab
)
17968 offset_type old_size
= symtab
->size
;
17970 struct symtab_index_entry
**old_entries
= symtab
->data
;
17973 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17975 for (i
= 0; i
< old_size
; ++i
)
17977 if (old_entries
[i
])
17979 struct symtab_index_entry
**slot
= find_slot (symtab
,
17980 old_entries
[i
]->name
);
17981 *slot
= old_entries
[i
];
17985 xfree (old_entries
);
17988 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
17989 is the index of the CU in which the symbol appears. */
17992 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17993 offset_type cu_index
)
17995 struct symtab_index_entry
**slot
;
17997 ++symtab
->n_elements
;
17998 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17999 hash_expand (symtab
);
18001 slot
= find_slot (symtab
, name
);
18004 *slot
= XNEW (struct symtab_index_entry
);
18005 (*slot
)->name
= name
;
18006 (*slot
)->cu_indices
= NULL
;
18008 /* Don't push an index twice. Due to how we add entries we only
18009 have to check the last one. */
18010 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
18011 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
18012 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
18015 /* Add a vector of indices to the constant pool. */
18018 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18019 struct symtab_index_entry
*entry
)
18023 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18026 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18027 offset_type val
= MAYBE_SWAP (len
);
18032 entry
->index_offset
= obstack_object_size (cpool
);
18034 obstack_grow (cpool
, &val
, sizeof (val
));
18036 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18039 val
= MAYBE_SWAP (iter
);
18040 obstack_grow (cpool
, &val
, sizeof (val
));
18045 struct symtab_index_entry
*old_entry
= *slot
;
18046 entry
->index_offset
= old_entry
->index_offset
;
18049 return entry
->index_offset
;
18052 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18053 constant pool entries going into the obstack CPOOL. */
18056 write_hash_table (struct mapped_symtab
*symtab
,
18057 struct obstack
*output
, struct obstack
*cpool
)
18060 htab_t symbol_hash_table
;
18063 symbol_hash_table
= create_symbol_hash_table ();
18064 str_table
= create_strtab ();
18066 /* We add all the index vectors to the constant pool first, to
18067 ensure alignment is ok. */
18068 for (i
= 0; i
< symtab
->size
; ++i
)
18070 if (symtab
->data
[i
])
18071 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18074 /* Now write out the hash table. */
18075 for (i
= 0; i
< symtab
->size
; ++i
)
18077 offset_type str_off
, vec_off
;
18079 if (symtab
->data
[i
])
18081 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18082 vec_off
= symtab
->data
[i
]->index_offset
;
18086 /* While 0 is a valid constant pool index, it is not valid
18087 to have 0 for both offsets. */
18092 str_off
= MAYBE_SWAP (str_off
);
18093 vec_off
= MAYBE_SWAP (vec_off
);
18095 obstack_grow (output
, &str_off
, sizeof (str_off
));
18096 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18099 htab_delete (str_table
);
18100 htab_delete (symbol_hash_table
);
18103 /* Struct to map psymtab to CU index in the index file. */
18104 struct psymtab_cu_index_map
18106 struct partial_symtab
*psymtab
;
18107 unsigned int cu_index
;
18111 hash_psymtab_cu_index (const void *item
)
18113 const struct psymtab_cu_index_map
*map
= item
;
18115 return htab_hash_pointer (map
->psymtab
);
18119 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18121 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18122 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18124 return lhs
->psymtab
== rhs
->psymtab
;
18127 /* Helper struct for building the address table. */
18128 struct addrmap_index_data
18130 struct objfile
*objfile
;
18131 struct obstack
*addr_obstack
;
18132 htab_t cu_index_htab
;
18134 /* Non-zero if the previous_* fields are valid.
18135 We can't write an entry until we see the next entry (since it is only then
18136 that we know the end of the entry). */
18137 int previous_valid
;
18138 /* Index of the CU in the table of all CUs in the index file. */
18139 unsigned int previous_cu_index
;
18140 /* Start address of the CU. */
18141 CORE_ADDR previous_cu_start
;
18144 /* Write an address entry to OBSTACK. */
18147 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18148 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18150 offset_type cu_index_to_write
;
18152 CORE_ADDR baseaddr
;
18154 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18156 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18157 obstack_grow (obstack
, addr
, 8);
18158 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18159 obstack_grow (obstack
, addr
, 8);
18160 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18161 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18164 /* Worker function for traversing an addrmap to build the address table. */
18167 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18169 struct addrmap_index_data
*data
= datap
;
18170 struct partial_symtab
*pst
= obj
;
18171 offset_type cu_index
;
18174 if (data
->previous_valid
)
18175 add_address_entry (data
->objfile
, data
->addr_obstack
,
18176 data
->previous_cu_start
, start_addr
,
18177 data
->previous_cu_index
);
18179 data
->previous_cu_start
= start_addr
;
18182 struct psymtab_cu_index_map find_map
, *map
;
18183 find_map
.psymtab
= pst
;
18184 map
= htab_find (data
->cu_index_htab
, &find_map
);
18185 gdb_assert (map
!= NULL
);
18186 data
->previous_cu_index
= map
->cu_index
;
18187 data
->previous_valid
= 1;
18190 data
->previous_valid
= 0;
18195 /* Write OBJFILE's address map to OBSTACK.
18196 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18197 in the index file. */
18200 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18201 htab_t cu_index_htab
)
18203 struct addrmap_index_data addrmap_index_data
;
18205 /* When writing the address table, we have to cope with the fact that
18206 the addrmap iterator only provides the start of a region; we have to
18207 wait until the next invocation to get the start of the next region. */
18209 addrmap_index_data
.objfile
= objfile
;
18210 addrmap_index_data
.addr_obstack
= obstack
;
18211 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18212 addrmap_index_data
.previous_valid
= 0;
18214 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18215 &addrmap_index_data
);
18217 /* It's highly unlikely the last entry (end address = 0xff...ff)
18218 is valid, but we should still handle it.
18219 The end address is recorded as the start of the next region, but that
18220 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18222 if (addrmap_index_data
.previous_valid
)
18223 add_address_entry (objfile
, obstack
,
18224 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18225 addrmap_index_data
.previous_cu_index
);
18228 /* Add a list of partial symbols to SYMTAB. */
18231 write_psymbols (struct mapped_symtab
*symtab
,
18233 struct partial_symbol
**psymp
,
18235 offset_type cu_index
,
18238 for (; count
-- > 0; ++psymp
)
18240 void **slot
, *lookup
;
18242 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
18243 error (_("Ada is not currently supported by the index"));
18245 /* We only want to add a given psymbol once. However, we also
18246 want to account for whether it is global or static. So, we
18247 may add it twice, using slightly different values. */
18250 uintptr_t val
= 1 | (uintptr_t) *psymp
;
18252 lookup
= (void *) val
;
18257 /* Only add a given psymbol once. */
18258 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
18262 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (*psymp
), cu_index
);
18267 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18268 exception if there is an error. */
18271 write_obstack (FILE *file
, struct obstack
*obstack
)
18273 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18275 != obstack_object_size (obstack
))
18276 error (_("couldn't data write to file"));
18279 /* Unlink a file if the argument is not NULL. */
18282 unlink_if_set (void *p
)
18284 char **filename
= p
;
18286 unlink (*filename
);
18289 /* A helper struct used when iterating over debug_types. */
18290 struct signatured_type_index_data
18292 struct objfile
*objfile
;
18293 struct mapped_symtab
*symtab
;
18294 struct obstack
*types_list
;
18299 /* A helper function that writes a single signatured_type to an
18303 write_one_signatured_type (void **slot
, void *d
)
18305 struct signatured_type_index_data
*info
= d
;
18306 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18307 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18308 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18311 write_psymbols (info
->symtab
,
18313 info
->objfile
->global_psymbols
.list
18314 + psymtab
->globals_offset
,
18315 psymtab
->n_global_syms
, info
->cu_index
,
18317 write_psymbols (info
->symtab
,
18319 info
->objfile
->static_psymbols
.list
18320 + psymtab
->statics_offset
,
18321 psymtab
->n_static_syms
, info
->cu_index
,
18324 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18325 entry
->per_cu
.offset
.sect_off
);
18326 obstack_grow (info
->types_list
, val
, 8);
18327 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18328 entry
->type_offset_in_tu
.cu_off
);
18329 obstack_grow (info
->types_list
, val
, 8);
18330 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18331 obstack_grow (info
->types_list
, val
, 8);
18338 /* Create an index file for OBJFILE in the directory DIR. */
18341 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18343 struct cleanup
*cleanup
;
18344 char *filename
, *cleanup_filename
;
18345 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18346 struct obstack cu_list
, types_cu_list
;
18349 struct mapped_symtab
*symtab
;
18350 offset_type val
, size_of_contents
, total_len
;
18354 htab_t cu_index_htab
;
18355 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18357 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18360 if (dwarf2_per_objfile
->using_index
)
18361 error (_("Cannot use an index to create the index"));
18363 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18364 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18366 if (stat (objfile
->name
, &st
) < 0)
18367 perror_with_name (objfile
->name
);
18369 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18370 INDEX_SUFFIX
, (char *) NULL
);
18371 cleanup
= make_cleanup (xfree
, filename
);
18373 out_file
= fopen (filename
, "wb");
18375 error (_("Can't open `%s' for writing"), filename
);
18377 cleanup_filename
= filename
;
18378 make_cleanup (unlink_if_set
, &cleanup_filename
);
18380 symtab
= create_mapped_symtab ();
18381 make_cleanup (cleanup_mapped_symtab
, symtab
);
18383 obstack_init (&addr_obstack
);
18384 make_cleanup_obstack_free (&addr_obstack
);
18386 obstack_init (&cu_list
);
18387 make_cleanup_obstack_free (&cu_list
);
18389 obstack_init (&types_cu_list
);
18390 make_cleanup_obstack_free (&types_cu_list
);
18392 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18393 NULL
, xcalloc
, xfree
);
18394 make_cleanup_htab_delete (psyms_seen
);
18396 /* While we're scanning CU's create a table that maps a psymtab pointer
18397 (which is what addrmap records) to its index (which is what is recorded
18398 in the index file). This will later be needed to write the address
18400 cu_index_htab
= htab_create_alloc (100,
18401 hash_psymtab_cu_index
,
18402 eq_psymtab_cu_index
,
18403 NULL
, xcalloc
, xfree
);
18404 make_cleanup_htab_delete (cu_index_htab
);
18405 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18406 xmalloc (sizeof (struct psymtab_cu_index_map
)
18407 * dwarf2_per_objfile
->n_comp_units
);
18408 make_cleanup (xfree
, psymtab_cu_index_map
);
18410 /* The CU list is already sorted, so we don't need to do additional
18411 work here. Also, the debug_types entries do not appear in
18412 all_comp_units, but only in their own hash table. */
18413 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18415 struct dwarf2_per_cu_data
*per_cu
18416 = dwarf2_per_objfile
->all_comp_units
[i
];
18417 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18419 struct psymtab_cu_index_map
*map
;
18422 write_psymbols (symtab
,
18424 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18425 psymtab
->n_global_syms
, i
,
18427 write_psymbols (symtab
,
18429 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18430 psymtab
->n_static_syms
, i
,
18433 map
= &psymtab_cu_index_map
[i
];
18434 map
->psymtab
= psymtab
;
18436 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18437 gdb_assert (slot
!= NULL
);
18438 gdb_assert (*slot
== NULL
);
18441 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18442 per_cu
->offset
.sect_off
);
18443 obstack_grow (&cu_list
, val
, 8);
18444 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18445 obstack_grow (&cu_list
, val
, 8);
18448 /* Dump the address map. */
18449 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18451 /* Write out the .debug_type entries, if any. */
18452 if (dwarf2_per_objfile
->signatured_types
)
18454 struct signatured_type_index_data sig_data
;
18456 sig_data
.objfile
= objfile
;
18457 sig_data
.symtab
= symtab
;
18458 sig_data
.types_list
= &types_cu_list
;
18459 sig_data
.psyms_seen
= psyms_seen
;
18460 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18461 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18462 write_one_signatured_type
, &sig_data
);
18465 obstack_init (&constant_pool
);
18466 make_cleanup_obstack_free (&constant_pool
);
18467 obstack_init (&symtab_obstack
);
18468 make_cleanup_obstack_free (&symtab_obstack
);
18469 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18471 obstack_init (&contents
);
18472 make_cleanup_obstack_free (&contents
);
18473 size_of_contents
= 6 * sizeof (offset_type
);
18474 total_len
= size_of_contents
;
18476 /* The version number. */
18477 val
= MAYBE_SWAP (6);
18478 obstack_grow (&contents
, &val
, sizeof (val
));
18480 /* The offset of the CU list from the start of the file. */
18481 val
= MAYBE_SWAP (total_len
);
18482 obstack_grow (&contents
, &val
, sizeof (val
));
18483 total_len
+= obstack_object_size (&cu_list
);
18485 /* The offset of the types CU list from the start of the file. */
18486 val
= MAYBE_SWAP (total_len
);
18487 obstack_grow (&contents
, &val
, sizeof (val
));
18488 total_len
+= obstack_object_size (&types_cu_list
);
18490 /* The offset of the address table from the start of the file. */
18491 val
= MAYBE_SWAP (total_len
);
18492 obstack_grow (&contents
, &val
, sizeof (val
));
18493 total_len
+= obstack_object_size (&addr_obstack
);
18495 /* The offset of the symbol table from the start of the file. */
18496 val
= MAYBE_SWAP (total_len
);
18497 obstack_grow (&contents
, &val
, sizeof (val
));
18498 total_len
+= obstack_object_size (&symtab_obstack
);
18500 /* The offset of the constant pool from the start of the file. */
18501 val
= MAYBE_SWAP (total_len
);
18502 obstack_grow (&contents
, &val
, sizeof (val
));
18503 total_len
+= obstack_object_size (&constant_pool
);
18505 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18507 write_obstack (out_file
, &contents
);
18508 write_obstack (out_file
, &cu_list
);
18509 write_obstack (out_file
, &types_cu_list
);
18510 write_obstack (out_file
, &addr_obstack
);
18511 write_obstack (out_file
, &symtab_obstack
);
18512 write_obstack (out_file
, &constant_pool
);
18516 /* We want to keep the file, so we set cleanup_filename to NULL
18517 here. See unlink_if_set. */
18518 cleanup_filename
= NULL
;
18520 do_cleanups (cleanup
);
18523 /* Implementation of the `save gdb-index' command.
18525 Note that the file format used by this command is documented in the
18526 GDB manual. Any changes here must be documented there. */
18529 save_gdb_index_command (char *arg
, int from_tty
)
18531 struct objfile
*objfile
;
18534 error (_("usage: save gdb-index DIRECTORY"));
18536 ALL_OBJFILES (objfile
)
18540 /* If the objfile does not correspond to an actual file, skip it. */
18541 if (stat (objfile
->name
, &st
) < 0)
18544 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18545 if (dwarf2_per_objfile
)
18547 volatile struct gdb_exception except
;
18549 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18551 write_psymtabs_to_index (objfile
, arg
);
18553 if (except
.reason
< 0)
18554 exception_fprintf (gdb_stderr
, except
,
18555 _("Error while writing index for `%s': "),
18563 int dwarf2_always_disassemble
;
18566 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18567 struct cmd_list_element
*c
, const char *value
)
18569 fprintf_filtered (file
,
18570 _("Whether to always disassemble "
18571 "DWARF expressions is %s.\n"),
18576 show_check_physname (struct ui_file
*file
, int from_tty
,
18577 struct cmd_list_element
*c
, const char *value
)
18579 fprintf_filtered (file
,
18580 _("Whether to check \"physname\" is %s.\n"),
18584 void _initialize_dwarf2_read (void);
18587 _initialize_dwarf2_read (void)
18589 struct cmd_list_element
*c
;
18591 dwarf2_objfile_data_key
18592 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18594 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18595 Set DWARF 2 specific variables.\n\
18596 Configure DWARF 2 variables such as the cache size"),
18597 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18598 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18600 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18601 Show DWARF 2 specific variables\n\
18602 Show DWARF 2 variables such as the cache size"),
18603 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18604 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18606 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18607 &dwarf2_max_cache_age
, _("\
18608 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18609 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18610 A higher limit means that cached compilation units will be stored\n\
18611 in memory longer, and more total memory will be used. Zero disables\n\
18612 caching, which can slow down startup."),
18614 show_dwarf2_max_cache_age
,
18615 &set_dwarf2_cmdlist
,
18616 &show_dwarf2_cmdlist
);
18618 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18619 &dwarf2_always_disassemble
, _("\
18620 Set whether `info address' always disassembles DWARF expressions."), _("\
18621 Show whether `info address' always disassembles DWARF expressions."), _("\
18622 When enabled, DWARF expressions are always printed in an assembly-like\n\
18623 syntax. When disabled, expressions will be printed in a more\n\
18624 conversational style, when possible."),
18626 show_dwarf2_always_disassemble
,
18627 &set_dwarf2_cmdlist
,
18628 &show_dwarf2_cmdlist
);
18630 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18631 Set debugging of the dwarf2 DIE reader."), _("\
18632 Show debugging of the dwarf2 DIE reader."), _("\
18633 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18634 The value is the maximum depth to print."),
18637 &setdebuglist
, &showdebuglist
);
18639 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18640 Set cross-checking of \"physname\" code against demangler."), _("\
18641 Show cross-checking of \"physname\" code against demangler."), _("\
18642 When enabled, GDB's internal \"physname\" code is checked against\n\
18644 NULL
, show_check_physname
,
18645 &setdebuglist
, &showdebuglist
);
18647 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18649 Save a gdb-index file.\n\
18650 Usage: save gdb-index DIRECTORY"),
18652 set_cmd_completer (c
, filename_completer
);