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 */
65 #include "gdb/gdb-index.h"
69 #include "gdb_string.h"
70 #include "gdb_assert.h"
71 #include <sys/types.h>
78 #define MAP_FAILED ((void *) -1)
82 typedef struct symbol
*symbolp
;
85 /* When non-zero, print basic high level tracing messages.
86 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
87 static int dwarf2_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static int dwarf2_die_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 int use_deprecated_index_sections
= 0;
100 /* When set, the file that we're processing is known to have debugging
101 info for C++ namespaces. GCC 3.3.x did not produce this information,
102 but later versions do. */
104 static int processing_has_namespace_info
;
106 static const struct objfile_data
*dwarf2_objfile_data_key
;
108 struct dwarf2_section_info
113 /* Not NULL if the section was actually mmapped. */
115 /* Page aligned size of mmapped area. */
116 bfd_size_type map_len
;
117 /* True if we have tried to read this section. */
121 typedef struct dwarf2_section_info dwarf2_section_info_def
;
122 DEF_VEC_O (dwarf2_section_info_def
);
124 /* All offsets in the index are of this type. It must be
125 architecture-independent. */
126 typedef uint32_t offset_type
;
128 DEF_VEC_I (offset_type
);
130 /* Ensure only legit values are used. */
131 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
133 gdb_assert ((unsigned int) (value) <= 1); \
134 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
137 /* Ensure only legit values are used. */
138 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
140 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
141 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
142 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
145 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
146 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
148 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
149 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
152 /* A description of the mapped index. The file format is described in
153 a comment by the code that writes the index. */
156 /* Index data format version. */
159 /* The total length of the buffer. */
162 /* A pointer to the address table data. */
163 const gdb_byte
*address_table
;
165 /* Size of the address table data in bytes. */
166 offset_type address_table_size
;
168 /* The symbol table, implemented as a hash table. */
169 const offset_type
*symbol_table
;
171 /* Size in slots, each slot is 2 offset_types. */
172 offset_type symbol_table_slots
;
174 /* A pointer to the constant pool. */
175 const char *constant_pool
;
178 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
179 DEF_VEC_P (dwarf2_per_cu_ptr
);
181 /* Collection of data recorded per objfile.
182 This hangs off of dwarf2_objfile_data_key. */
184 struct dwarf2_per_objfile
186 struct dwarf2_section_info info
;
187 struct dwarf2_section_info abbrev
;
188 struct dwarf2_section_info line
;
189 struct dwarf2_section_info loc
;
190 struct dwarf2_section_info macinfo
;
191 struct dwarf2_section_info macro
;
192 struct dwarf2_section_info str
;
193 struct dwarf2_section_info ranges
;
194 struct dwarf2_section_info addr
;
195 struct dwarf2_section_info frame
;
196 struct dwarf2_section_info eh_frame
;
197 struct dwarf2_section_info gdb_index
;
199 VEC (dwarf2_section_info_def
) *types
;
202 struct objfile
*objfile
;
204 /* Table of all the compilation units. This is used to locate
205 the target compilation unit of a particular reference. */
206 struct dwarf2_per_cu_data
**all_comp_units
;
208 /* The number of compilation units in ALL_COMP_UNITS. */
211 /* The number of .debug_types-related CUs. */
214 /* The .debug_types-related CUs (TUs). */
215 struct dwarf2_per_cu_data
**all_type_units
;
217 /* A chain of compilation units that are currently read in, so that
218 they can be freed later. */
219 struct dwarf2_per_cu_data
*read_in_chain
;
221 /* A table mapping .debug_types signatures to its signatured_type entry.
222 This is NULL if the .debug_types section hasn't been read in yet. */
223 htab_t signatured_types
;
225 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
226 This is NULL if the table hasn't been allocated yet. */
229 /* A flag indicating wether this objfile has a section loaded at a
231 int has_section_at_zero
;
233 /* True if we are using the mapped index,
234 or we are faking it for OBJF_READNOW's sake. */
235 unsigned char using_index
;
237 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
238 struct mapped_index
*index_table
;
240 /* When using index_table, this keeps track of all quick_file_names entries.
241 TUs can share line table entries with CUs or other TUs, and there can be
242 a lot more TUs than unique line tables, so we maintain a separate table
243 of all line table entries to support the sharing. */
244 htab_t quick_file_names_table
;
246 /* Set during partial symbol reading, to prevent queueing of full
248 int reading_partial_symbols
;
250 /* Table mapping type DIEs to their struct type *.
251 This is NULL if not allocated yet.
252 The mapping is done via (CU/TU signature + DIE offset) -> type. */
253 htab_t die_type_hash
;
255 /* The CUs we recently read. */
256 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
259 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
261 /* Default names of the debugging sections. */
263 /* Note that if the debugging section has been compressed, it might
264 have a name like .zdebug_info. */
266 static const struct dwarf2_debug_sections dwarf2_elf_names
=
268 { ".debug_info", ".zdebug_info" },
269 { ".debug_abbrev", ".zdebug_abbrev" },
270 { ".debug_line", ".zdebug_line" },
271 { ".debug_loc", ".zdebug_loc" },
272 { ".debug_macinfo", ".zdebug_macinfo" },
273 { ".debug_macro", ".zdebug_macro" },
274 { ".debug_str", ".zdebug_str" },
275 { ".debug_ranges", ".zdebug_ranges" },
276 { ".debug_types", ".zdebug_types" },
277 { ".debug_addr", ".zdebug_addr" },
278 { ".debug_frame", ".zdebug_frame" },
279 { ".eh_frame", NULL
},
280 { ".gdb_index", ".zgdb_index" },
284 /* List of DWO sections. */
286 static const struct dwo_section_names
288 struct dwarf2_section_names abbrev_dwo
;
289 struct dwarf2_section_names info_dwo
;
290 struct dwarf2_section_names line_dwo
;
291 struct dwarf2_section_names loc_dwo
;
292 struct dwarf2_section_names macinfo_dwo
;
293 struct dwarf2_section_names macro_dwo
;
294 struct dwarf2_section_names str_dwo
;
295 struct dwarf2_section_names str_offsets_dwo
;
296 struct dwarf2_section_names types_dwo
;
300 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
301 { ".debug_info.dwo", ".zdebug_info.dwo" },
302 { ".debug_line.dwo", ".zdebug_line.dwo" },
303 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
304 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
305 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
306 { ".debug_str.dwo", ".zdebug_str.dwo" },
307 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
308 { ".debug_types.dwo", ".zdebug_types.dwo" },
311 /* local data types */
313 /* We hold several abbreviation tables in memory at the same time. */
314 #ifndef ABBREV_HASH_SIZE
315 #define ABBREV_HASH_SIZE 121
318 /* The data in a compilation unit header, after target2host
319 translation, looks like this. */
320 struct comp_unit_head
324 unsigned char addr_size
;
325 unsigned char signed_addr_p
;
326 sect_offset abbrev_offset
;
328 /* Size of file offsets; either 4 or 8. */
329 unsigned int offset_size
;
331 /* Size of the length field; either 4 or 12. */
332 unsigned int initial_length_size
;
334 /* Offset to the first byte of this compilation unit header in the
335 .debug_info section, for resolving relative reference dies. */
338 /* Offset to first die in this cu from the start of the cu.
339 This will be the first byte following the compilation unit header. */
340 cu_offset first_die_offset
;
343 /* Type used for delaying computation of method physnames.
344 See comments for compute_delayed_physnames. */
345 struct delayed_method_info
347 /* The type to which the method is attached, i.e., its parent class. */
350 /* The index of the method in the type's function fieldlists. */
353 /* The index of the method in the fieldlist. */
356 /* The name of the DIE. */
359 /* The DIE associated with this method. */
360 struct die_info
*die
;
363 typedef struct delayed_method_info delayed_method_info
;
364 DEF_VEC_O (delayed_method_info
);
366 /* Internal state when decoding a particular compilation unit. */
369 /* The objfile containing this compilation unit. */
370 struct objfile
*objfile
;
372 /* The header of the compilation unit. */
373 struct comp_unit_head header
;
375 /* Base address of this compilation unit. */
376 CORE_ADDR base_address
;
378 /* Non-zero if base_address has been set. */
381 /* The language we are debugging. */
382 enum language language
;
383 const struct language_defn
*language_defn
;
385 const char *producer
;
387 /* The generic symbol table building routines have separate lists for
388 file scope symbols and all all other scopes (local scopes). So
389 we need to select the right one to pass to add_symbol_to_list().
390 We do it by keeping a pointer to the correct list in list_in_scope.
392 FIXME: The original dwarf code just treated the file scope as the
393 first local scope, and all other local scopes as nested local
394 scopes, and worked fine. Check to see if we really need to
395 distinguish these in buildsym.c. */
396 struct pending
**list_in_scope
;
398 /* DWARF abbreviation table associated with this compilation unit. */
399 struct abbrev_info
**dwarf2_abbrevs
;
401 /* Storage for the abbrev table. */
402 struct obstack abbrev_obstack
;
404 /* Hash table holding all the loaded partial DIEs
405 with partial_die->offset.SECT_OFF as hash. */
408 /* Storage for things with the same lifetime as this read-in compilation
409 unit, including partial DIEs. */
410 struct obstack comp_unit_obstack
;
412 /* When multiple dwarf2_cu structures are living in memory, this field
413 chains them all together, so that they can be released efficiently.
414 We will probably also want a generation counter so that most-recently-used
415 compilation units are cached... */
416 struct dwarf2_per_cu_data
*read_in_chain
;
418 /* Backchain to our per_cu entry if the tree has been built. */
419 struct dwarf2_per_cu_data
*per_cu
;
421 /* How many compilation units ago was this CU last referenced? */
424 /* A hash table of DIE cu_offset for following references with
425 die_info->offset.sect_off as hash. */
428 /* Full DIEs if read in. */
429 struct die_info
*dies
;
431 /* A set of pointers to dwarf2_per_cu_data objects for compilation
432 units referenced by this one. Only set during full symbol processing;
433 partial symbol tables do not have dependencies. */
436 /* Header data from the line table, during full symbol processing. */
437 struct line_header
*line_header
;
439 /* A list of methods which need to have physnames computed
440 after all type information has been read. */
441 VEC (delayed_method_info
) *method_list
;
443 /* To be copied to symtab->call_site_htab. */
444 htab_t call_site_htab
;
446 /* Non-NULL if this CU came from a DWO file.
447 There is an invariant here that is important to remember:
448 Except for attributes copied from the top level DIE in the "main"
449 (or "stub") file in preparation for reading the DWO file
450 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
451 Either there isn't a DWO file (in which case this is NULL and the point
452 is moot), or there is and either we're not going to read it (in which
453 case this is NULL) or there is and we are reading it (in which case this
455 struct dwo_unit
*dwo_unit
;
457 /* The DW_AT_addr_base attribute if present, zero otherwise
458 (zero is a valid value though).
459 Note this value comes from the stub CU/TU's DIE. */
462 /* Mark used when releasing cached dies. */
463 unsigned int mark
: 1;
465 /* This CU references .debug_loc. See the symtab->locations_valid field.
466 This test is imperfect as there may exist optimized debug code not using
467 any location list and still facing inlining issues if handled as
468 unoptimized code. For a future better test see GCC PR other/32998. */
469 unsigned int has_loclist
: 1;
471 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
472 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
473 are valid. This information is cached because profiling CU expansion
474 showed excessive time spent in producer_is_gxx_lt_4_6. */
475 unsigned int checked_producer
: 1;
476 unsigned int producer_is_gxx_lt_4_6
: 1;
477 unsigned int producer_is_icc
: 1;
479 /* Non-zero if DW_AT_addr_base was found.
480 Used when processing DWO files. */
481 unsigned int have_addr_base
: 1;
484 /* Persistent data held for a compilation unit, even when not
485 processing it. We put a pointer to this structure in the
486 read_symtab_private field of the psymtab. */
488 struct dwarf2_per_cu_data
490 /* The start offset and length of this compilation unit. 2**29-1
491 bytes should suffice to store the length of any compilation unit
492 - if it doesn't, GDB will fall over anyway.
493 NOTE: Unlike comp_unit_head.length, this length includes
495 If the DIE refers to a DWO file, this is always of the original die,
498 unsigned int length
: 29;
500 /* Flag indicating this compilation unit will be read in before
501 any of the current compilation units are processed. */
502 unsigned int queued
: 1;
504 /* This flag will be set when reading partial DIEs if we need to load
505 absolutely all DIEs for this compilation unit, instead of just the ones
506 we think are interesting. It gets set if we look for a DIE in the
507 hash table and don't find it. */
508 unsigned int load_all_dies
: 1;
510 /* Non-zero if this CU is from .debug_types. */
511 unsigned int is_debug_types
: 1;
513 /* The section this CU/TU lives in.
514 If the DIE refers to a DWO file, this is always the original die,
516 struct dwarf2_section_info
*info_or_types_section
;
518 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
519 of the CU cache it gets reset to NULL again. */
520 struct dwarf2_cu
*cu
;
522 /* The corresponding objfile.
523 Normally we can get the objfile from dwarf2_per_objfile.
524 However we can enter this file with just a "per_cu" handle. */
525 struct objfile
*objfile
;
527 /* When using partial symbol tables, the 'psymtab' field is active.
528 Otherwise the 'quick' field is active. */
531 /* The partial symbol table associated with this compilation unit,
532 or NULL for unread partial units. */
533 struct partial_symtab
*psymtab
;
535 /* Data needed by the "quick" functions. */
536 struct dwarf2_per_cu_quick_data
*quick
;
539 /* The CUs we import using DW_TAG_imported_unit. This is filled in
540 while reading psymtabs, used to compute the psymtab dependencies,
541 and then cleared. Then it is filled in again while reading full
542 symbols, and only deleted when the objfile is destroyed. */
543 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
546 /* Entry in the signatured_types hash table. */
548 struct signatured_type
550 /* The type's signature. */
553 /* Offset in the TU of the type's DIE, as read from the TU header.
554 If the definition lives in a DWO file, this value is unusable. */
555 cu_offset type_offset_in_tu
;
557 /* Offset in the section of the type's DIE.
558 If the definition lives in a DWO file, this is the offset in the
559 .debug_types.dwo section.
560 The value is zero until the actual value is known.
561 Zero is otherwise not a valid section offset. */
562 sect_offset type_offset_in_section
;
564 /* The CU(/TU) of this type. */
565 struct dwarf2_per_cu_data per_cu
;
568 /* These sections are what may appear in a "dwo" file. */
572 struct dwarf2_section_info abbrev
;
573 struct dwarf2_section_info info
;
574 struct dwarf2_section_info line
;
575 struct dwarf2_section_info loc
;
576 struct dwarf2_section_info macinfo
;
577 struct dwarf2_section_info macro
;
578 struct dwarf2_section_info str
;
579 struct dwarf2_section_info str_offsets
;
580 VEC (dwarf2_section_info_def
) *types
;
583 /* Common bits of DWO CUs/TUs. */
587 /* Backlink to the containing struct dwo_file. */
588 struct dwo_file
*dwo_file
;
590 /* The "id" that distinguishes this CU/TU.
591 .debug_info calls this "dwo_id", .debug_types calls this "signature".
592 Since signatures came first, we stick with it for consistency. */
595 /* The section this CU/TU lives in, in the DWO file. */
596 struct dwarf2_section_info
*info_or_types_section
;
598 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
602 /* For types, offset in the type's DIE of the type defined by this TU. */
603 cu_offset type_offset_in_tu
;
606 /* Data for one DWO file. */
610 /* The DW_AT_GNU_dwo_name attribute.
611 We don't manage space for this, it's an attribute. */
612 const char *dwo_name
;
614 /* The bfd, when the file is open. Otherwise this is NULL. */
617 /* Section info for this file. */
618 struct dwo_sections sections
;
620 /* Table of CUs in the file.
621 Each element is a struct dwo_unit. */
624 /* Table of TUs in the file.
625 Each element is a struct dwo_unit. */
629 /* Struct used to pass misc. parameters to read_die_and_children, et
630 al. which are used for both .debug_info and .debug_types dies.
631 All parameters here are unchanging for the life of the call. This
632 struct exists to abstract away the constant parameters of die reading. */
634 struct die_reader_specs
636 /* die_section->asection->owner. */
639 /* The CU of the DIE we are parsing. */
640 struct dwarf2_cu
*cu
;
642 /* Non-NULL if reading a DWO file. */
643 struct dwo_file
*dwo_file
;
645 /* The section the die comes from.
646 This is either .debug_info or .debug_types, or the .dwo variants. */
647 struct dwarf2_section_info
*die_section
;
649 /* die_section->buffer. */
652 /* The end of the buffer. */
653 const gdb_byte
*buffer_end
;
656 /* Type of function passed to init_cutu_and_read_dies, et.al. */
657 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
659 struct die_info
*comp_unit_die
,
663 /* The line number information for a compilation unit (found in the
664 .debug_line section) begins with a "statement program header",
665 which contains the following information. */
668 unsigned int total_length
;
669 unsigned short version
;
670 unsigned int header_length
;
671 unsigned char minimum_instruction_length
;
672 unsigned char maximum_ops_per_instruction
;
673 unsigned char default_is_stmt
;
675 unsigned char line_range
;
676 unsigned char opcode_base
;
678 /* standard_opcode_lengths[i] is the number of operands for the
679 standard opcode whose value is i. This means that
680 standard_opcode_lengths[0] is unused, and the last meaningful
681 element is standard_opcode_lengths[opcode_base - 1]. */
682 unsigned char *standard_opcode_lengths
;
684 /* The include_directories table. NOTE! These strings are not
685 allocated with xmalloc; instead, they are pointers into
686 debug_line_buffer. If you try to free them, `free' will get
688 unsigned int num_include_dirs
, include_dirs_size
;
691 /* The file_names table. NOTE! These strings are not allocated
692 with xmalloc; instead, they are pointers into debug_line_buffer.
693 Don't try to free them directly. */
694 unsigned int num_file_names
, file_names_size
;
698 unsigned int dir_index
;
699 unsigned int mod_time
;
701 int included_p
; /* Non-zero if referenced by the Line Number Program. */
702 struct symtab
*symtab
; /* The associated symbol table, if any. */
705 /* The start and end of the statement program following this
706 header. These point into dwarf2_per_objfile->line_buffer. */
707 gdb_byte
*statement_program_start
, *statement_program_end
;
710 /* When we construct a partial symbol table entry we only
711 need this much information. */
712 struct partial_die_info
714 /* Offset of this DIE. */
717 /* DWARF-2 tag for this DIE. */
718 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
720 /* Assorted flags describing the data found in this DIE. */
721 unsigned int has_children
: 1;
722 unsigned int is_external
: 1;
723 unsigned int is_declaration
: 1;
724 unsigned int has_type
: 1;
725 unsigned int has_specification
: 1;
726 unsigned int has_pc_info
: 1;
727 unsigned int may_be_inlined
: 1;
729 /* Flag set if the SCOPE field of this structure has been
731 unsigned int scope_set
: 1;
733 /* Flag set if the DIE has a byte_size attribute. */
734 unsigned int has_byte_size
: 1;
736 /* Flag set if any of the DIE's children are template arguments. */
737 unsigned int has_template_arguments
: 1;
739 /* Flag set if fixup_partial_die has been called on this die. */
740 unsigned int fixup_called
: 1;
742 /* The name of this DIE. Normally the value of DW_AT_name, but
743 sometimes a default name for unnamed DIEs. */
746 /* The linkage name, if present. */
747 const char *linkage_name
;
749 /* The scope to prepend to our children. This is generally
750 allocated on the comp_unit_obstack, so will disappear
751 when this compilation unit leaves the cache. */
754 /* Some data associated with the partial DIE. The tag determines
755 which field is live. */
758 /* The location description associated with this DIE, if any. */
759 struct dwarf_block
*locdesc
;
760 /* The offset of an import, for DW_TAG_imported_unit. */
764 /* If HAS_PC_INFO, the PC range associated with this DIE. */
768 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
769 DW_AT_sibling, if any. */
770 /* NOTE: This member isn't strictly necessary, read_partial_die could
771 return DW_AT_sibling values to its caller load_partial_dies. */
774 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
775 DW_AT_specification (or DW_AT_abstract_origin or
777 sect_offset spec_offset
;
779 /* Pointers to this DIE's parent, first child, and next sibling,
781 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
784 /* This data structure holds the information of an abbrev. */
787 unsigned int number
; /* number identifying abbrev */
788 enum dwarf_tag tag
; /* dwarf tag */
789 unsigned short has_children
; /* boolean */
790 unsigned short num_attrs
; /* number of attributes */
791 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
792 struct abbrev_info
*next
; /* next in chain */
797 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
798 ENUM_BITFIELD(dwarf_form
) form
: 16;
801 /* Attributes have a name and a value. */
804 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
805 ENUM_BITFIELD(dwarf_form
) form
: 15;
807 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
808 field should be in u.str (existing only for DW_STRING) but it is kept
809 here for better struct attribute alignment. */
810 unsigned int string_is_canonical
: 1;
815 struct dwarf_block
*blk
;
819 struct signatured_type
*signatured_type
;
824 /* This data structure holds a complete die structure. */
827 /* DWARF-2 tag for this DIE. */
828 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
830 /* Number of attributes */
831 unsigned char num_attrs
;
833 /* True if we're presently building the full type name for the
834 type derived from this DIE. */
835 unsigned char building_fullname
: 1;
840 /* Offset in .debug_info or .debug_types section. */
843 /* The dies in a compilation unit form an n-ary tree. PARENT
844 points to this die's parent; CHILD points to the first child of
845 this node; and all the children of a given node are chained
846 together via their SIBLING fields. */
847 struct die_info
*child
; /* Its first child, if any. */
848 struct die_info
*sibling
; /* Its next sibling, if any. */
849 struct die_info
*parent
; /* Its parent, if any. */
851 /* An array of attributes, with NUM_ATTRS elements. There may be
852 zero, but it's not common and zero-sized arrays are not
853 sufficiently portable C. */
854 struct attribute attrs
[1];
857 /* Get at parts of an attribute structure. */
859 #define DW_STRING(attr) ((attr)->u.str)
860 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
861 #define DW_UNSND(attr) ((attr)->u.unsnd)
862 #define DW_BLOCK(attr) ((attr)->u.blk)
863 #define DW_SND(attr) ((attr)->u.snd)
864 #define DW_ADDR(attr) ((attr)->u.addr)
865 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
867 /* Blocks are a bunch of untyped bytes. */
872 /* Valid only if SIZE is not zero. */
876 #ifndef ATTR_ALLOC_CHUNK
877 #define ATTR_ALLOC_CHUNK 4
880 /* Allocate fields for structs, unions and enums in this size. */
881 #ifndef DW_FIELD_ALLOC_CHUNK
882 #define DW_FIELD_ALLOC_CHUNK 4
885 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
886 but this would require a corresponding change in unpack_field_as_long
888 static int bits_per_byte
= 8;
890 /* The routines that read and process dies for a C struct or C++ class
891 pass lists of data member fields and lists of member function fields
892 in an instance of a field_info structure, as defined below. */
895 /* List of data member and baseclasses fields. */
898 struct nextfield
*next
;
903 *fields
, *baseclasses
;
905 /* Number of fields (including baseclasses). */
908 /* Number of baseclasses. */
911 /* Set if the accesibility of one of the fields is not public. */
912 int non_public_fields
;
914 /* Member function fields array, entries are allocated in the order they
915 are encountered in the object file. */
918 struct nextfnfield
*next
;
919 struct fn_field fnfield
;
923 /* Member function fieldlist array, contains name of possibly overloaded
924 member function, number of overloaded member functions and a pointer
925 to the head of the member function field chain. */
930 struct nextfnfield
*head
;
934 /* Number of entries in the fnfieldlists array. */
937 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
938 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
939 struct typedef_field_list
941 struct typedef_field field
;
942 struct typedef_field_list
*next
;
945 unsigned typedef_field_list_count
;
948 /* One item on the queue of compilation units to read in full symbols
950 struct dwarf2_queue_item
952 struct dwarf2_per_cu_data
*per_cu
;
953 enum language pretend_language
;
954 struct dwarf2_queue_item
*next
;
957 /* The current queue. */
958 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
960 /* Loaded secondary compilation units are kept in memory until they
961 have not been referenced for the processing of this many
962 compilation units. Set this to zero to disable caching. Cache
963 sizes of up to at least twenty will improve startup time for
964 typical inter-CU-reference binaries, at an obvious memory cost. */
965 static int dwarf2_max_cache_age
= 5;
967 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
968 struct cmd_list_element
*c
, const char *value
)
970 fprintf_filtered (file
, _("The upper bound on the age of cached "
971 "dwarf2 compilation units is %s.\n"),
976 /* Various complaints about symbol reading that don't abort the process. */
979 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
981 complaint (&symfile_complaints
,
982 _("statement list doesn't fit in .debug_line section"));
986 dwarf2_debug_line_missing_file_complaint (void)
988 complaint (&symfile_complaints
,
989 _(".debug_line section has line data without a file"));
993 dwarf2_debug_line_missing_end_sequence_complaint (void)
995 complaint (&symfile_complaints
,
996 _(".debug_line section has line "
997 "program sequence without an end"));
1001 dwarf2_complex_location_expr_complaint (void)
1003 complaint (&symfile_complaints
, _("location expression too complex"));
1007 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1010 complaint (&symfile_complaints
,
1011 _("const value length mismatch for '%s', got %d, expected %d"),
1016 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1018 complaint (&symfile_complaints
,
1019 _("debug info runs off end of %s section"
1021 section
->asection
->name
,
1022 bfd_get_filename (section
->asection
->owner
));
1026 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1028 complaint (&symfile_complaints
,
1029 _("macro debug info contains a "
1030 "malformed macro definition:\n`%s'"),
1035 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1037 complaint (&symfile_complaints
,
1038 _("invalid attribute class or form for '%s' in '%s'"),
1042 /* local function prototypes */
1044 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1046 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1049 static void dwarf2_find_base_address (struct die_info
*die
,
1050 struct dwarf2_cu
*cu
);
1052 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1054 static void scan_partial_symbols (struct partial_die_info
*,
1055 CORE_ADDR
*, CORE_ADDR
*,
1056 int, struct dwarf2_cu
*);
1058 static void add_partial_symbol (struct partial_die_info
*,
1059 struct dwarf2_cu
*);
1061 static void add_partial_namespace (struct partial_die_info
*pdi
,
1062 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1063 int need_pc
, struct dwarf2_cu
*cu
);
1065 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1066 CORE_ADDR
*highpc
, int need_pc
,
1067 struct dwarf2_cu
*cu
);
1069 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1070 struct dwarf2_cu
*cu
);
1072 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1073 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1074 int need_pc
, struct dwarf2_cu
*cu
);
1076 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1078 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1080 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1081 struct dwarf2_section_info
*);
1083 static void dwarf2_free_abbrev_table (void *);
1085 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1087 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1088 struct dwarf2_cu
*);
1090 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1091 struct dwarf2_cu
*);
1093 static struct partial_die_info
*load_partial_dies
1094 (const struct die_reader_specs
*, gdb_byte
*, int);
1096 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1097 struct partial_die_info
*,
1098 struct abbrev_info
*,
1102 static struct partial_die_info
*find_partial_die (sect_offset
,
1103 struct dwarf2_cu
*);
1105 static void fixup_partial_die (struct partial_die_info
*,
1106 struct dwarf2_cu
*);
1108 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1109 struct attribute
*, struct attr_abbrev
*,
1112 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1114 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1116 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1118 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1120 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1122 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1125 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1127 static LONGEST read_checked_initial_length_and_offset
1128 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1129 unsigned int *, unsigned int *);
1131 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1134 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1136 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1138 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1140 static char *read_indirect_string (bfd
*, gdb_byte
*,
1141 const struct comp_unit_head
*,
1144 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1146 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1148 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1151 static char *read_str_index (const struct die_reader_specs
*reader
,
1152 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1154 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1156 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1157 struct dwarf2_cu
*);
1159 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1161 struct dwarf2_cu
*);
1163 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1164 struct dwarf2_cu
*cu
);
1166 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1168 static struct die_info
*die_specification (struct die_info
*die
,
1169 struct dwarf2_cu
**);
1171 static void free_line_header (struct line_header
*lh
);
1173 static void add_file_name (struct line_header
*, char *, unsigned int,
1174 unsigned int, unsigned int);
1176 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1177 struct dwarf2_cu
*cu
);
1179 static void dwarf_decode_lines (struct line_header
*, const char *,
1180 struct dwarf2_cu
*, struct partial_symtab
*,
1183 static void dwarf2_start_subfile (char *, const char *, const char *);
1185 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1186 struct dwarf2_cu
*);
1188 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1189 struct dwarf2_cu
*, struct symbol
*);
1191 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1192 struct dwarf2_cu
*);
1194 static void dwarf2_const_value_attr (struct attribute
*attr
,
1197 struct obstack
*obstack
,
1198 struct dwarf2_cu
*cu
, LONGEST
*value
,
1200 struct dwarf2_locexpr_baton
**baton
);
1202 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1204 static int need_gnat_info (struct dwarf2_cu
*);
1206 static struct type
*die_descriptive_type (struct die_info
*,
1207 struct dwarf2_cu
*);
1209 static void set_descriptive_type (struct type
*, struct die_info
*,
1210 struct dwarf2_cu
*);
1212 static struct type
*die_containing_type (struct die_info
*,
1213 struct dwarf2_cu
*);
1215 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1216 struct dwarf2_cu
*);
1218 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1220 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1222 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1224 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1225 const char *suffix
, int physname
,
1226 struct dwarf2_cu
*cu
);
1228 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1230 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1232 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1234 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1236 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1238 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1239 struct dwarf2_cu
*, struct partial_symtab
*);
1241 static int dwarf2_get_pc_bounds (struct die_info
*,
1242 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1243 struct partial_symtab
*);
1245 static void get_scope_pc_bounds (struct die_info
*,
1246 CORE_ADDR
*, CORE_ADDR
*,
1247 struct dwarf2_cu
*);
1249 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1250 CORE_ADDR
, struct dwarf2_cu
*);
1252 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1253 struct dwarf2_cu
*);
1255 static void dwarf2_attach_fields_to_type (struct field_info
*,
1256 struct type
*, struct dwarf2_cu
*);
1258 static void dwarf2_add_member_fn (struct field_info
*,
1259 struct die_info
*, struct type
*,
1260 struct dwarf2_cu
*);
1262 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1264 struct dwarf2_cu
*);
1266 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1268 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1270 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1272 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1274 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1276 static struct type
*read_module_type (struct die_info
*die
,
1277 struct dwarf2_cu
*cu
);
1279 static const char *namespace_name (struct die_info
*die
,
1280 int *is_anonymous
, struct dwarf2_cu
*);
1282 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1284 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1286 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1287 struct dwarf2_cu
*);
1289 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1291 gdb_byte
**new_info_ptr
,
1292 struct die_info
*parent
);
1294 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1296 gdb_byte
**new_info_ptr
,
1297 struct die_info
*parent
);
1299 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1300 struct die_info
**, gdb_byte
*, int *, int);
1302 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1303 struct die_info
**, gdb_byte
*, int *);
1305 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1307 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1310 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1312 static const char *dwarf2_full_name (char *name
,
1313 struct die_info
*die
,
1314 struct dwarf2_cu
*cu
);
1316 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1317 struct dwarf2_cu
**);
1319 static const char *dwarf_tag_name (unsigned int);
1321 static const char *dwarf_attr_name (unsigned int);
1323 static const char *dwarf_form_name (unsigned int);
1325 static char *dwarf_bool_name (unsigned int);
1327 static const char *dwarf_type_encoding_name (unsigned int);
1329 static struct die_info
*sibling_die (struct die_info
*);
1331 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1333 static void dump_die_for_error (struct die_info
*);
1335 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1338 /*static*/ void dump_die (struct die_info
*, int max_level
);
1340 static void store_in_ref_table (struct die_info
*,
1341 struct dwarf2_cu
*);
1343 static int is_ref_attr (struct attribute
*);
1345 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1347 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1349 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1351 struct dwarf2_cu
**);
1353 static struct die_info
*follow_die_ref (struct die_info
*,
1355 struct dwarf2_cu
**);
1357 static struct die_info
*follow_die_sig (struct die_info
*,
1359 struct dwarf2_cu
**);
1361 static struct signatured_type
*lookup_signatured_type_at_offset
1362 (struct objfile
*objfile
,
1363 struct dwarf2_section_info
*section
, sect_offset offset
);
1365 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1367 static void read_signatured_type (struct signatured_type
*);
1369 /* memory allocation interface */
1371 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1373 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1375 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1377 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1380 static int attr_form_is_block (struct attribute
*);
1382 static int attr_form_is_section_offset (struct attribute
*);
1384 static int attr_form_is_constant (struct attribute
*);
1386 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1387 struct dwarf2_loclist_baton
*baton
,
1388 struct attribute
*attr
);
1390 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1392 struct dwarf2_cu
*cu
);
1394 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1396 struct abbrev_info
*abbrev
);
1398 static void free_stack_comp_unit (void *);
1400 static hashval_t
partial_die_hash (const void *item
);
1402 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1404 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1405 (sect_offset offset
, struct objfile
*objfile
);
1407 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1408 struct dwarf2_per_cu_data
*per_cu
);
1410 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1411 struct die_info
*comp_unit_die
,
1412 enum language pretend_language
);
1414 static void free_heap_comp_unit (void *);
1416 static void free_cached_comp_units (void *);
1418 static void age_cached_comp_units (void);
1420 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1422 static struct type
*set_die_type (struct die_info
*, struct type
*,
1423 struct dwarf2_cu
*);
1425 static void create_all_comp_units (struct objfile
*);
1427 static int create_all_type_units (struct objfile
*);
1429 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1432 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1435 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1436 struct dwarf2_per_cu_data
*);
1438 static void dwarf2_mark (struct dwarf2_cu
*);
1440 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1442 static struct type
*get_die_type_at_offset (sect_offset
,
1443 struct dwarf2_per_cu_data
*per_cu
);
1445 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1447 static void dwarf2_release_queue (void *dummy
);
1449 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1450 enum language pretend_language
);
1452 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1453 struct dwarf2_per_cu_data
*per_cu
,
1454 enum language pretend_language
);
1456 static void process_queue (void);
1458 static void find_file_and_directory (struct die_info
*die
,
1459 struct dwarf2_cu
*cu
,
1460 char **name
, char **comp_dir
);
1462 static char *file_full_name (int file
, struct line_header
*lh
,
1463 const char *comp_dir
);
1465 static void init_cutu_and_read_dies
1466 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1467 die_reader_func_ftype
*die_reader_func
, void *data
);
1469 static void init_cutu_and_read_dies_simple
1470 (struct dwarf2_per_cu_data
*this_cu
,
1471 die_reader_func_ftype
*die_reader_func
, void *data
);
1473 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1475 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1477 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1479 static struct dwo_unit
*lookup_dwo_comp_unit
1480 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1482 static struct dwo_unit
*lookup_dwo_type_unit
1483 (struct signatured_type
*, char *, const char *);
1485 static void free_dwo_file_cleanup (void *);
1487 static void munmap_section_buffer (struct dwarf2_section_info
*);
1489 static void process_cu_includes (void);
1493 /* Convert VALUE between big- and little-endian. */
1495 byte_swap (offset_type value
)
1499 result
= (value
& 0xff) << 24;
1500 result
|= (value
& 0xff00) << 8;
1501 result
|= (value
& 0xff0000) >> 8;
1502 result
|= (value
& 0xff000000) >> 24;
1506 #define MAYBE_SWAP(V) byte_swap (V)
1509 #define MAYBE_SWAP(V) (V)
1510 #endif /* WORDS_BIGENDIAN */
1512 /* The suffix for an index file. */
1513 #define INDEX_SUFFIX ".gdb-index"
1515 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1516 struct dwarf2_cu
*cu
);
1518 /* Try to locate the sections we need for DWARF 2 debugging
1519 information and return true if we have enough to do something.
1520 NAMES points to the dwarf2 section names, or is NULL if the standard
1521 ELF names are used. */
1524 dwarf2_has_info (struct objfile
*objfile
,
1525 const struct dwarf2_debug_sections
*names
)
1527 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1528 if (!dwarf2_per_objfile
)
1530 /* Initialize per-objfile state. */
1531 struct dwarf2_per_objfile
*data
1532 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1534 memset (data
, 0, sizeof (*data
));
1535 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1536 dwarf2_per_objfile
= data
;
1538 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1540 dwarf2_per_objfile
->objfile
= objfile
;
1542 return (dwarf2_per_objfile
->info
.asection
!= NULL
1543 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1546 /* When loading sections, we look either for uncompressed section or for
1547 compressed section names. */
1550 section_is_p (const char *section_name
,
1551 const struct dwarf2_section_names
*names
)
1553 if (names
->normal
!= NULL
1554 && strcmp (section_name
, names
->normal
) == 0)
1556 if (names
->compressed
!= NULL
1557 && strcmp (section_name
, names
->compressed
) == 0)
1562 /* This function is mapped across the sections and remembers the
1563 offset and size of each of the debugging sections we are interested
1567 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1569 const struct dwarf2_debug_sections
*names
;
1572 names
= &dwarf2_elf_names
;
1574 names
= (const struct dwarf2_debug_sections
*) vnames
;
1576 if (section_is_p (sectp
->name
, &names
->info
))
1578 dwarf2_per_objfile
->info
.asection
= sectp
;
1579 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1581 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1583 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1584 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1586 else if (section_is_p (sectp
->name
, &names
->line
))
1588 dwarf2_per_objfile
->line
.asection
= sectp
;
1589 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1591 else if (section_is_p (sectp
->name
, &names
->loc
))
1593 dwarf2_per_objfile
->loc
.asection
= sectp
;
1594 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1596 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1598 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1599 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1601 else if (section_is_p (sectp
->name
, &names
->macro
))
1603 dwarf2_per_objfile
->macro
.asection
= sectp
;
1604 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1606 else if (section_is_p (sectp
->name
, &names
->str
))
1608 dwarf2_per_objfile
->str
.asection
= sectp
;
1609 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1611 else if (section_is_p (sectp
->name
, &names
->addr
))
1613 dwarf2_per_objfile
->addr
.asection
= sectp
;
1614 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1616 else if (section_is_p (sectp
->name
, &names
->frame
))
1618 dwarf2_per_objfile
->frame
.asection
= sectp
;
1619 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1621 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1623 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1625 if (aflag
& SEC_HAS_CONTENTS
)
1627 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1628 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1631 else if (section_is_p (sectp
->name
, &names
->ranges
))
1633 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1634 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1636 else if (section_is_p (sectp
->name
, &names
->types
))
1638 struct dwarf2_section_info type_section
;
1640 memset (&type_section
, 0, sizeof (type_section
));
1641 type_section
.asection
= sectp
;
1642 type_section
.size
= bfd_get_section_size (sectp
);
1644 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1647 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1649 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1650 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1653 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1654 && bfd_section_vma (abfd
, sectp
) == 0)
1655 dwarf2_per_objfile
->has_section_at_zero
= 1;
1658 /* Decompress a section that was compressed using zlib. Store the
1659 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1662 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1663 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1665 bfd
*abfd
= sectp
->owner
;
1667 error (_("Support for zlib-compressed DWARF data (from '%s') "
1668 "is disabled in this copy of GDB"),
1669 bfd_get_filename (abfd
));
1671 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1672 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1673 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1674 bfd_size_type uncompressed_size
;
1675 gdb_byte
*uncompressed_buffer
;
1678 int header_size
= 12;
1680 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1681 || bfd_bread (compressed_buffer
,
1682 compressed_size
, abfd
) != compressed_size
)
1683 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1684 bfd_get_filename (abfd
));
1686 /* Read the zlib header. In this case, it should be "ZLIB" followed
1687 by the uncompressed section size, 8 bytes in big-endian order. */
1688 if (compressed_size
< header_size
1689 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1690 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1691 bfd_get_filename (abfd
));
1692 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1693 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1694 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1695 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1696 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1697 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1698 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1699 uncompressed_size
+= compressed_buffer
[11];
1701 /* It is possible the section consists of several compressed
1702 buffers concatenated together, so we uncompress in a loop. */
1706 strm
.avail_in
= compressed_size
- header_size
;
1707 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1708 strm
.avail_out
= uncompressed_size
;
1709 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1711 rc
= inflateInit (&strm
);
1712 while (strm
.avail_in
> 0)
1715 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1716 bfd_get_filename (abfd
), rc
);
1717 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1718 + (uncompressed_size
- strm
.avail_out
));
1719 rc
= inflate (&strm
, Z_FINISH
);
1720 if (rc
!= Z_STREAM_END
)
1721 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1722 bfd_get_filename (abfd
), rc
);
1723 rc
= inflateReset (&strm
);
1725 rc
= inflateEnd (&strm
);
1727 || strm
.avail_out
!= 0)
1728 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1729 bfd_get_filename (abfd
), rc
);
1731 do_cleanups (cleanup
);
1732 *outbuf
= uncompressed_buffer
;
1733 *outsize
= uncompressed_size
;
1737 /* A helper function that decides whether a section is empty,
1741 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1743 return info
->asection
== NULL
|| info
->size
== 0;
1746 /* Read the contents of the section INFO.
1747 OBJFILE is the main object file, but not necessarily the file where
1748 the section comes from. E.g., for DWO files INFO->asection->owner
1749 is the bfd of the DWO file.
1750 If the section is compressed, uncompress it before returning. */
1753 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1755 asection
*sectp
= info
->asection
;
1757 gdb_byte
*buf
, *retbuf
;
1758 unsigned char header
[4];
1762 info
->buffer
= NULL
;
1763 info
->map_addr
= NULL
;
1766 if (dwarf2_section_empty_p (info
))
1769 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1770 abfd
= sectp
->owner
;
1772 /* Check if the file has a 4-byte header indicating compression. */
1773 if (info
->size
> sizeof (header
)
1774 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1775 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1777 /* Upon decompression, update the buffer and its size. */
1778 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1780 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1788 pagesize
= getpagesize ();
1790 /* Only try to mmap sections which are large enough: we don't want to
1791 waste space due to fragmentation. Also, only try mmap for sections
1792 without relocations. */
1794 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1796 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1797 MAP_PRIVATE
, sectp
->filepos
,
1798 &info
->map_addr
, &info
->map_len
);
1800 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1802 #if HAVE_POSIX_MADVISE
1803 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1810 /* If we get here, we are a normal, not-compressed section. */
1812 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1814 /* When debugging .o files, we may need to apply relocations; see
1815 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1816 We never compress sections in .o files, so we only need to
1817 try this when the section is not compressed. */
1818 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1821 info
->buffer
= retbuf
;
1825 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1826 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1827 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1828 bfd_get_filename (abfd
));
1831 /* A helper function that returns the size of a section in a safe way.
1832 If you are positive that the section has been read before using the
1833 size, then it is safe to refer to the dwarf2_section_info object's
1834 "size" field directly. In other cases, you must call this
1835 function, because for compressed sections the size field is not set
1836 correctly until the section has been read. */
1838 static bfd_size_type
1839 dwarf2_section_size (struct objfile
*objfile
,
1840 struct dwarf2_section_info
*info
)
1843 dwarf2_read_section (objfile
, info
);
1847 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1851 dwarf2_get_section_info (struct objfile
*objfile
,
1852 enum dwarf2_section_enum sect
,
1853 asection
**sectp
, gdb_byte
**bufp
,
1854 bfd_size_type
*sizep
)
1856 struct dwarf2_per_objfile
*data
1857 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1858 struct dwarf2_section_info
*info
;
1860 /* We may see an objfile without any DWARF, in which case we just
1871 case DWARF2_DEBUG_FRAME
:
1872 info
= &data
->frame
;
1874 case DWARF2_EH_FRAME
:
1875 info
= &data
->eh_frame
;
1878 gdb_assert_not_reached ("unexpected section");
1881 dwarf2_read_section (objfile
, info
);
1883 *sectp
= info
->asection
;
1884 *bufp
= info
->buffer
;
1885 *sizep
= info
->size
;
1889 /* DWARF quick_symbols_functions support. */
1891 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1892 unique line tables, so we maintain a separate table of all .debug_line
1893 derived entries to support the sharing.
1894 All the quick functions need is the list of file names. We discard the
1895 line_header when we're done and don't need to record it here. */
1896 struct quick_file_names
1898 /* The offset in .debug_line of the line table. We hash on this. */
1899 unsigned int offset
;
1901 /* The number of entries in file_names, real_names. */
1902 unsigned int num_file_names
;
1904 /* The file names from the line table, after being run through
1906 const char **file_names
;
1908 /* The file names from the line table after being run through
1909 gdb_realpath. These are computed lazily. */
1910 const char **real_names
;
1913 /* When using the index (and thus not using psymtabs), each CU has an
1914 object of this type. This is used to hold information needed by
1915 the various "quick" methods. */
1916 struct dwarf2_per_cu_quick_data
1918 /* The file table. This can be NULL if there was no file table
1919 or it's currently not read in.
1920 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1921 struct quick_file_names
*file_names
;
1923 /* The corresponding symbol table. This is NULL if symbols for this
1924 CU have not yet been read. */
1925 struct symtab
*symtab
;
1927 /* A temporary mark bit used when iterating over all CUs in
1928 expand_symtabs_matching. */
1929 unsigned int mark
: 1;
1931 /* True if we've tried to read the file table and found there isn't one.
1932 There will be no point in trying to read it again next time. */
1933 unsigned int no_file_data
: 1;
1936 /* Hash function for a quick_file_names. */
1939 hash_file_name_entry (const void *e
)
1941 const struct quick_file_names
*file_data
= e
;
1943 return file_data
->offset
;
1946 /* Equality function for a quick_file_names. */
1949 eq_file_name_entry (const void *a
, const void *b
)
1951 const struct quick_file_names
*ea
= a
;
1952 const struct quick_file_names
*eb
= b
;
1954 return ea
->offset
== eb
->offset
;
1957 /* Delete function for a quick_file_names. */
1960 delete_file_name_entry (void *e
)
1962 struct quick_file_names
*file_data
= e
;
1965 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1967 xfree ((void*) file_data
->file_names
[i
]);
1968 if (file_data
->real_names
)
1969 xfree ((void*) file_data
->real_names
[i
]);
1972 /* The space for the struct itself lives on objfile_obstack,
1973 so we don't free it here. */
1976 /* Create a quick_file_names hash table. */
1979 create_quick_file_names_table (unsigned int nr_initial_entries
)
1981 return htab_create_alloc (nr_initial_entries
,
1982 hash_file_name_entry
, eq_file_name_entry
,
1983 delete_file_name_entry
, xcalloc
, xfree
);
1986 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1987 have to be created afterwards. You should call age_cached_comp_units after
1988 processing PER_CU->CU. dw2_setup must have been already called. */
1991 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1993 if (per_cu
->is_debug_types
)
1994 load_full_type_unit (per_cu
);
1996 load_full_comp_unit (per_cu
, language_minimal
);
1998 gdb_assert (per_cu
->cu
!= NULL
);
2000 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2003 /* Read in the symbols for PER_CU. */
2006 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2008 struct cleanup
*back_to
;
2010 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2012 if (dwarf2_per_objfile
->using_index
2013 ? per_cu
->v
.quick
->symtab
== NULL
2014 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2016 queue_comp_unit (per_cu
, language_minimal
);
2022 /* Age the cache, releasing compilation units that have not
2023 been used recently. */
2024 age_cached_comp_units ();
2026 do_cleanups (back_to
);
2029 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2030 the objfile from which this CU came. Returns the resulting symbol
2033 static struct symtab
*
2034 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2036 gdb_assert (dwarf2_per_objfile
->using_index
);
2037 if (!per_cu
->v
.quick
->symtab
)
2039 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2040 increment_reading_symtab ();
2041 dw2_do_instantiate_symtab (per_cu
);
2042 process_cu_includes ();
2043 do_cleanups (back_to
);
2045 return per_cu
->v
.quick
->symtab
;
2048 /* Return the CU given its index. */
2050 static struct dwarf2_per_cu_data
*
2051 dw2_get_cu (int index
)
2053 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2055 index
-= dwarf2_per_objfile
->n_comp_units
;
2056 return dwarf2_per_objfile
->all_type_units
[index
];
2058 return dwarf2_per_objfile
->all_comp_units
[index
];
2061 /* A helper function that knows how to read a 64-bit value in a way
2062 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2066 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2068 if (sizeof (ULONGEST
) < 8)
2072 /* Ignore the upper 4 bytes if they are all zero. */
2073 for (i
= 0; i
< 4; ++i
)
2074 if (bytes
[i
+ 4] != 0)
2077 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2080 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2084 /* Read the CU list from the mapped index, and use it to create all
2085 the CU objects for this objfile. Return 0 if something went wrong,
2086 1 if everything went ok. */
2089 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2090 offset_type cu_list_elements
)
2094 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2095 dwarf2_per_objfile
->all_comp_units
2096 = obstack_alloc (&objfile
->objfile_obstack
,
2097 dwarf2_per_objfile
->n_comp_units
2098 * sizeof (struct dwarf2_per_cu_data
*));
2100 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2102 struct dwarf2_per_cu_data
*the_cu
;
2103 ULONGEST offset
, length
;
2105 if (!extract_cu_value (cu_list
, &offset
)
2106 || !extract_cu_value (cu_list
+ 8, &length
))
2110 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2111 struct dwarf2_per_cu_data
);
2112 the_cu
->offset
.sect_off
= offset
;
2113 the_cu
->length
= length
;
2114 the_cu
->objfile
= objfile
;
2115 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2116 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2117 struct dwarf2_per_cu_quick_data
);
2118 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2124 /* Create the signatured type hash table from the index. */
2127 create_signatured_type_table_from_index (struct objfile
*objfile
,
2128 struct dwarf2_section_info
*section
,
2129 const gdb_byte
*bytes
,
2130 offset_type elements
)
2133 htab_t sig_types_hash
;
2135 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2136 dwarf2_per_objfile
->all_type_units
2137 = obstack_alloc (&objfile
->objfile_obstack
,
2138 dwarf2_per_objfile
->n_type_units
2139 * sizeof (struct dwarf2_per_cu_data
*));
2141 sig_types_hash
= allocate_signatured_type_table (objfile
);
2143 for (i
= 0; i
< elements
; i
+= 3)
2145 struct signatured_type
*sig_type
;
2146 ULONGEST offset
, type_offset_in_tu
, signature
;
2149 if (!extract_cu_value (bytes
, &offset
)
2150 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2152 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2155 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2156 struct signatured_type
);
2157 sig_type
->signature
= signature
;
2158 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2159 sig_type
->per_cu
.is_debug_types
= 1;
2160 sig_type
->per_cu
.info_or_types_section
= section
;
2161 sig_type
->per_cu
.offset
.sect_off
= offset
;
2162 sig_type
->per_cu
.objfile
= objfile
;
2163 sig_type
->per_cu
.v
.quick
2164 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2165 struct dwarf2_per_cu_quick_data
);
2167 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2170 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2173 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2178 /* Read the address map data from the mapped index, and use it to
2179 populate the objfile's psymtabs_addrmap. */
2182 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2184 const gdb_byte
*iter
, *end
;
2185 struct obstack temp_obstack
;
2186 struct addrmap
*mutable_map
;
2187 struct cleanup
*cleanup
;
2190 obstack_init (&temp_obstack
);
2191 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2192 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2194 iter
= index
->address_table
;
2195 end
= iter
+ index
->address_table_size
;
2197 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2201 ULONGEST hi
, lo
, cu_index
;
2202 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2204 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2206 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2209 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2210 dw2_get_cu (cu_index
));
2213 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2214 &objfile
->objfile_obstack
);
2215 do_cleanups (cleanup
);
2218 /* The hash function for strings in the mapped index. This is the same as
2219 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2220 implementation. This is necessary because the hash function is tied to the
2221 format of the mapped index file. The hash values do not have to match with
2224 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2227 mapped_index_string_hash (int index_version
, const void *p
)
2229 const unsigned char *str
= (const unsigned char *) p
;
2233 while ((c
= *str
++) != 0)
2235 if (index_version
>= 5)
2237 r
= r
* 67 + c
- 113;
2243 /* Find a slot in the mapped index INDEX for the object named NAME.
2244 If NAME is found, set *VEC_OUT to point to the CU vector in the
2245 constant pool and return 1. If NAME cannot be found, return 0. */
2248 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2249 offset_type
**vec_out
)
2251 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2253 offset_type slot
, step
;
2254 int (*cmp
) (const char *, const char *);
2256 if (current_language
->la_language
== language_cplus
2257 || current_language
->la_language
== language_java
2258 || current_language
->la_language
== language_fortran
)
2260 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2262 const char *paren
= strchr (name
, '(');
2268 dup
= xmalloc (paren
- name
+ 1);
2269 memcpy (dup
, name
, paren
- name
);
2270 dup
[paren
- name
] = 0;
2272 make_cleanup (xfree
, dup
);
2277 /* Index version 4 did not support case insensitive searches. But the
2278 indices for case insensitive languages are built in lowercase, therefore
2279 simulate our NAME being searched is also lowercased. */
2280 hash
= mapped_index_string_hash ((index
->version
== 4
2281 && case_sensitivity
== case_sensitive_off
2282 ? 5 : index
->version
),
2285 slot
= hash
& (index
->symbol_table_slots
- 1);
2286 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2287 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2291 /* Convert a slot number to an offset into the table. */
2292 offset_type i
= 2 * slot
;
2294 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2296 do_cleanups (back_to
);
2300 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2301 if (!cmp (name
, str
))
2303 *vec_out
= (offset_type
*) (index
->constant_pool
2304 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2305 do_cleanups (back_to
);
2309 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2313 /* Read the index file. If everything went ok, initialize the "quick"
2314 elements of all the CUs and return 1. Otherwise, return 0. */
2317 dwarf2_read_index (struct objfile
*objfile
)
2320 struct mapped_index
*map
;
2321 offset_type
*metadata
;
2322 const gdb_byte
*cu_list
;
2323 const gdb_byte
*types_list
= NULL
;
2324 offset_type version
, cu_list_elements
;
2325 offset_type types_list_elements
= 0;
2328 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2331 /* Older elfutils strip versions could keep the section in the main
2332 executable while splitting it for the separate debug info file. */
2333 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2334 & SEC_HAS_CONTENTS
) == 0)
2337 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2339 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2340 /* Version check. */
2341 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2342 /* Versions earlier than 3 emitted every copy of a psymbol. This
2343 causes the index to behave very poorly for certain requests. Version 3
2344 contained incomplete addrmap. So, it seems better to just ignore such
2348 static int warning_printed
= 0;
2349 if (!warning_printed
)
2351 warning (_("Skipping obsolete .gdb_index section in %s."),
2353 warning_printed
= 1;
2357 /* Index version 4 uses a different hash function than index version
2360 Versions earlier than 6 did not emit psymbols for inlined
2361 functions. Using these files will cause GDB not to be able to
2362 set breakpoints on inlined functions by name, so we ignore these
2363 indices unless the --use-deprecated-index-sections command line
2364 option was supplied. */
2365 if (version
< 6 && !use_deprecated_index_sections
)
2367 static int warning_printed
= 0;
2368 if (!warning_printed
)
2370 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2371 "--use-deprecated-index-sections to use them anyway"),
2373 warning_printed
= 1;
2377 /* Indexes with higher version than the one supported by GDB may be no
2378 longer backward compatible. */
2382 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2383 map
->version
= version
;
2384 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2386 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2389 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2390 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2394 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2395 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2396 - MAYBE_SWAP (metadata
[i
]))
2400 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2401 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2402 - MAYBE_SWAP (metadata
[i
]));
2405 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2406 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2407 - MAYBE_SWAP (metadata
[i
]))
2408 / (2 * sizeof (offset_type
)));
2411 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2413 /* Don't use the index if it's empty. */
2414 if (map
->symbol_table_slots
== 0)
2417 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2420 if (types_list_elements
)
2422 struct dwarf2_section_info
*section
;
2424 /* We can only handle a single .debug_types when we have an
2426 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2429 section
= VEC_index (dwarf2_section_info_def
,
2430 dwarf2_per_objfile
->types
, 0);
2432 if (!create_signatured_type_table_from_index (objfile
, section
,
2434 types_list_elements
))
2438 create_addrmap_from_index (objfile
, map
);
2440 dwarf2_per_objfile
->index_table
= map
;
2441 dwarf2_per_objfile
->using_index
= 1;
2442 dwarf2_per_objfile
->quick_file_names_table
=
2443 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2448 /* A helper for the "quick" functions which sets the global
2449 dwarf2_per_objfile according to OBJFILE. */
2452 dw2_setup (struct objfile
*objfile
)
2454 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2455 gdb_assert (dwarf2_per_objfile
);
2458 /* die_reader_func for dw2_get_file_names. */
2461 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2463 struct die_info
*comp_unit_die
,
2467 struct dwarf2_cu
*cu
= reader
->cu
;
2468 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2469 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2470 struct line_header
*lh
;
2471 struct attribute
*attr
;
2473 char *name
, *comp_dir
;
2475 struct quick_file_names
*qfn
;
2476 unsigned int line_offset
;
2478 /* Our callers never want to match partial units -- instead they
2479 will match the enclosing full CU. */
2480 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2482 this_cu
->v
.quick
->no_file_data
= 1;
2490 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2493 struct quick_file_names find_entry
;
2495 line_offset
= DW_UNSND (attr
);
2497 /* We may have already read in this line header (TU line header sharing).
2498 If we have we're done. */
2499 find_entry
.offset
= line_offset
;
2500 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2501 &find_entry
, INSERT
);
2504 this_cu
->v
.quick
->file_names
= *slot
;
2508 lh
= dwarf_decode_line_header (line_offset
, cu
);
2512 this_cu
->v
.quick
->no_file_data
= 1;
2516 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2517 qfn
->offset
= line_offset
;
2518 gdb_assert (slot
!= NULL
);
2521 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2523 qfn
->num_file_names
= lh
->num_file_names
;
2524 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2525 lh
->num_file_names
* sizeof (char *));
2526 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2527 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2528 qfn
->real_names
= NULL
;
2530 free_line_header (lh
);
2532 this_cu
->v
.quick
->file_names
= qfn
;
2535 /* A helper for the "quick" functions which attempts to read the line
2536 table for THIS_CU. */
2538 static struct quick_file_names
*
2539 dw2_get_file_names (struct objfile
*objfile
,
2540 struct dwarf2_per_cu_data
*this_cu
)
2542 if (this_cu
->v
.quick
->file_names
!= NULL
)
2543 return this_cu
->v
.quick
->file_names
;
2544 /* If we know there is no line data, no point in looking again. */
2545 if (this_cu
->v
.quick
->no_file_data
)
2548 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2549 in the stub for CUs, there's is no need to lookup the DWO file.
2550 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2552 if (this_cu
->is_debug_types
)
2553 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2555 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2557 if (this_cu
->v
.quick
->no_file_data
)
2559 return this_cu
->v
.quick
->file_names
;
2562 /* A helper for the "quick" functions which computes and caches the
2563 real path for a given file name from the line table. */
2566 dw2_get_real_path (struct objfile
*objfile
,
2567 struct quick_file_names
*qfn
, int index
)
2569 if (qfn
->real_names
== NULL
)
2570 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2571 qfn
->num_file_names
, sizeof (char *));
2573 if (qfn
->real_names
[index
] == NULL
)
2574 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2576 return qfn
->real_names
[index
];
2579 static struct symtab
*
2580 dw2_find_last_source_symtab (struct objfile
*objfile
)
2584 dw2_setup (objfile
);
2585 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2586 return dw2_instantiate_symtab (dw2_get_cu (index
));
2589 /* Traversal function for dw2_forget_cached_source_info. */
2592 dw2_free_cached_file_names (void **slot
, void *info
)
2594 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2596 if (file_data
->real_names
)
2600 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2602 xfree ((void*) file_data
->real_names
[i
]);
2603 file_data
->real_names
[i
] = NULL
;
2611 dw2_forget_cached_source_info (struct objfile
*objfile
)
2613 dw2_setup (objfile
);
2615 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2616 dw2_free_cached_file_names
, NULL
);
2619 /* Helper function for dw2_map_symtabs_matching_filename that expands
2620 the symtabs and calls the iterator. */
2623 dw2_map_expand_apply (struct objfile
*objfile
,
2624 struct dwarf2_per_cu_data
*per_cu
,
2626 const char *full_path
, const char *real_path
,
2627 int (*callback
) (struct symtab
*, void *),
2630 struct symtab
*last_made
= objfile
->symtabs
;
2632 /* Don't visit already-expanded CUs. */
2633 if (per_cu
->v
.quick
->symtab
)
2636 /* This may expand more than one symtab, and we want to iterate over
2638 dw2_instantiate_symtab (per_cu
);
2640 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2641 objfile
->symtabs
, last_made
);
2644 /* Implementation of the map_symtabs_matching_filename method. */
2647 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2648 const char *full_path
, const char *real_path
,
2649 int (*callback
) (struct symtab
*, void *),
2653 const char *name_basename
= lbasename (name
);
2654 int name_len
= strlen (name
);
2655 int is_abs
= IS_ABSOLUTE_PATH (name
);
2657 dw2_setup (objfile
);
2659 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2660 + dwarf2_per_objfile
->n_type_units
); ++i
)
2663 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2664 struct quick_file_names
*file_data
;
2666 /* We only need to look at symtabs not already expanded. */
2667 if (per_cu
->v
.quick
->symtab
)
2670 file_data
= dw2_get_file_names (objfile
, per_cu
);
2671 if (file_data
== NULL
)
2674 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2676 const char *this_name
= file_data
->file_names
[j
];
2678 if (FILENAME_CMP (name
, this_name
) == 0
2679 || (!is_abs
&& compare_filenames_for_search (this_name
,
2682 if (dw2_map_expand_apply (objfile
, per_cu
,
2683 name
, full_path
, real_path
,
2688 /* Before we invoke realpath, which can get expensive when many
2689 files are involved, do a quick comparison of the basenames. */
2690 if (! basenames_may_differ
2691 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2694 if (full_path
!= NULL
)
2696 const char *this_real_name
= dw2_get_real_path (objfile
,
2699 if (this_real_name
!= NULL
2700 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2702 && compare_filenames_for_search (this_real_name
,
2705 if (dw2_map_expand_apply (objfile
, per_cu
,
2706 name
, full_path
, real_path
,
2712 if (real_path
!= NULL
)
2714 const char *this_real_name
= dw2_get_real_path (objfile
,
2717 if (this_real_name
!= NULL
2718 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2720 && compare_filenames_for_search (this_real_name
,
2723 if (dw2_map_expand_apply (objfile
, per_cu
,
2724 name
, full_path
, real_path
,
2735 static struct symtab
*
2736 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2737 const char *name
, domain_enum domain
)
2739 /* We do all the work in the pre_expand_symtabs_matching hook
2744 /* A helper function that expands all symtabs that hold an object
2745 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2746 symbols in block BLOCK_KIND. */
2749 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2750 int want_specific_block
,
2751 enum block_enum block_kind
,
2752 const char *name
, domain_enum domain
)
2754 struct mapped_index
*index
;
2756 dw2_setup (objfile
);
2758 index
= dwarf2_per_objfile
->index_table
;
2760 /* index_table is NULL if OBJF_READNOW. */
2765 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2767 offset_type i
, len
= MAYBE_SWAP (*vec
);
2768 for (i
= 0; i
< len
; ++i
)
2770 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2771 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2772 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2773 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2774 /* This value is only valid for index versions >= 7. */
2775 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2776 gdb_index_symbol_kind symbol_kind
=
2777 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2779 if (want_specific_block
2780 && index
->version
>= 7
2781 && want_static
!= is_static
)
2784 /* Only check the symbol's kind if it has one.
2785 Indices prior to version 7 don't record it. */
2786 if (index
->version
>= 7)
2791 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2792 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2793 /* Some types are also in VAR_DOMAIN. */
2794 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2798 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2802 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
2810 dw2_instantiate_symtab (per_cu
);
2817 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2818 enum block_enum block_kind
, const char *name
,
2821 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
2825 dw2_print_stats (struct objfile
*objfile
)
2829 dw2_setup (objfile
);
2831 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2832 + dwarf2_per_objfile
->n_type_units
); ++i
)
2834 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2836 if (!per_cu
->v
.quick
->symtab
)
2839 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2843 dw2_dump (struct objfile
*objfile
)
2845 /* Nothing worth printing. */
2849 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2850 struct section_offsets
*delta
)
2852 /* There's nothing to relocate here. */
2856 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2857 const char *func_name
)
2859 /* Note: It doesn't matter what we pass for block_kind here. */
2860 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
2865 dw2_expand_all_symtabs (struct objfile
*objfile
)
2869 dw2_setup (objfile
);
2871 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2872 + dwarf2_per_objfile
->n_type_units
); ++i
)
2874 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2876 dw2_instantiate_symtab (per_cu
);
2881 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2882 const char *filename
)
2886 dw2_setup (objfile
);
2888 /* We don't need to consider type units here.
2889 This is only called for examining code, e.g. expand_line_sal.
2890 There can be an order of magnitude (or more) more type units
2891 than comp units, and we avoid them if we can. */
2893 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2896 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2897 struct quick_file_names
*file_data
;
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 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2909 const char *this_name
= file_data
->file_names
[j
];
2910 if (FILENAME_CMP (this_name
, filename
) == 0)
2912 dw2_instantiate_symtab (per_cu
);
2919 /* A helper function for dw2_find_symbol_file that finds the primary
2920 file name for a given CU. This is a die_reader_func. */
2923 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
2925 struct die_info
*comp_unit_die
,
2929 const char **result_ptr
= data
;
2930 struct dwarf2_cu
*cu
= reader
->cu
;
2931 struct attribute
*attr
;
2933 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
2937 *result_ptr
= DW_STRING (attr
);
2941 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2943 struct dwarf2_per_cu_data
*per_cu
;
2945 struct quick_file_names
*file_data
;
2946 const char *filename
;
2948 dw2_setup (objfile
);
2950 /* index_table is NULL if OBJF_READNOW. */
2951 if (!dwarf2_per_objfile
->index_table
)
2955 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
2957 struct blockvector
*bv
= BLOCKVECTOR (s
);
2958 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2959 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2962 return sym
->symtab
->filename
;
2967 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2971 /* Note that this just looks at the very first one named NAME -- but
2972 actually we are looking for a function. find_main_filename
2973 should be rewritten so that it doesn't require a custom hook. It
2974 could just use the ordinary symbol tables. */
2975 /* vec[0] is the length, which must always be >0. */
2976 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
2978 if (per_cu
->v
.quick
->symtab
!= NULL
)
2979 return per_cu
->v
.quick
->symtab
->filename
;
2981 init_cutu_and_read_dies (per_cu
, 0, 0, dw2_get_primary_filename_reader
,
2988 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2989 struct objfile
*objfile
, int global
,
2990 int (*callback
) (struct block
*,
2991 struct symbol
*, void *),
2992 void *data
, symbol_compare_ftype
*match
,
2993 symbol_compare_ftype
*ordered_compare
)
2995 /* Currently unimplemented; used for Ada. The function can be called if the
2996 current language is Ada for a non-Ada objfile using GNU index. As Ada
2997 does not look for non-Ada symbols this function should just return. */
3001 dw2_expand_symtabs_matching
3002 (struct objfile
*objfile
,
3003 int (*file_matcher
) (const char *, void *),
3004 int (*name_matcher
) (const char *, void *),
3005 enum search_domain kind
,
3010 struct mapped_index
*index
;
3012 dw2_setup (objfile
);
3014 /* index_table is NULL if OBJF_READNOW. */
3015 if (!dwarf2_per_objfile
->index_table
)
3017 index
= dwarf2_per_objfile
->index_table
;
3019 if (file_matcher
!= NULL
)
3021 struct cleanup
*cleanup
;
3022 htab_t visited_found
, visited_not_found
;
3024 visited_found
= htab_create_alloc (10,
3025 htab_hash_pointer
, htab_eq_pointer
,
3026 NULL
, xcalloc
, xfree
);
3027 cleanup
= make_cleanup_htab_delete (visited_found
);
3028 visited_not_found
= htab_create_alloc (10,
3029 htab_hash_pointer
, htab_eq_pointer
,
3030 NULL
, xcalloc
, xfree
);
3031 make_cleanup_htab_delete (visited_not_found
);
3033 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3034 + dwarf2_per_objfile
->n_type_units
); ++i
)
3037 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3038 struct quick_file_names
*file_data
;
3041 per_cu
->v
.quick
->mark
= 0;
3043 /* We only need to look at symtabs not already expanded. */
3044 if (per_cu
->v
.quick
->symtab
)
3047 file_data
= dw2_get_file_names (objfile
, per_cu
);
3048 if (file_data
== NULL
)
3051 if (htab_find (visited_not_found
, file_data
) != NULL
)
3053 else if (htab_find (visited_found
, file_data
) != NULL
)
3055 per_cu
->v
.quick
->mark
= 1;
3059 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3061 if (file_matcher (file_data
->file_names
[j
], data
))
3063 per_cu
->v
.quick
->mark
= 1;
3068 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3070 : visited_not_found
,
3075 do_cleanups (cleanup
);
3078 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3080 offset_type idx
= 2 * iter
;
3082 offset_type
*vec
, vec_len
, vec_idx
;
3084 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3087 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3089 if (! (*name_matcher
) (name
, data
))
3092 /* The name was matched, now expand corresponding CUs that were
3094 vec
= (offset_type
*) (index
->constant_pool
3095 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3096 vec_len
= MAYBE_SWAP (vec
[0]);
3097 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3099 struct dwarf2_per_cu_data
*per_cu
;
3100 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3101 gdb_index_symbol_kind symbol_kind
=
3102 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3103 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3105 /* Don't crash on bad data. */
3106 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3107 + dwarf2_per_objfile
->n_comp_units
))
3110 /* Only check the symbol's kind if it has one.
3111 Indices prior to version 7 don't record it. */
3112 if (index
->version
>= 7)
3116 case VARIABLES_DOMAIN
:
3117 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3120 case FUNCTIONS_DOMAIN
:
3121 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3125 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3133 per_cu
= dw2_get_cu (cu_index
);
3134 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3135 dw2_instantiate_symtab (per_cu
);
3140 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3143 static struct symtab
*
3144 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3148 if (BLOCKVECTOR (symtab
) != NULL
3149 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3152 if (symtab
->includes
== NULL
)
3155 for (i
= 0; symtab
->includes
[i
]; ++i
)
3157 struct symtab
*s
= symtab
->includes
[i
];
3159 s
= recursively_find_pc_sect_symtab (s
, pc
);
3167 static struct symtab
*
3168 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3169 struct minimal_symbol
*msymbol
,
3171 struct obj_section
*section
,
3174 struct dwarf2_per_cu_data
*data
;
3175 struct symtab
*result
;
3177 dw2_setup (objfile
);
3179 if (!objfile
->psymtabs_addrmap
)
3182 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3186 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3187 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3188 paddress (get_objfile_arch (objfile
), pc
));
3190 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3191 gdb_assert (result
!= NULL
);
3196 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3197 void *data
, int need_fullname
)
3200 struct cleanup
*cleanup
;
3201 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3202 NULL
, xcalloc
, xfree
);
3204 cleanup
= make_cleanup_htab_delete (visited
);
3205 dw2_setup (objfile
);
3207 /* We can ignore file names coming from already-expanded CUs. */
3208 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3209 + dwarf2_per_objfile
->n_type_units
); ++i
)
3211 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3213 if (per_cu
->v
.quick
->symtab
)
3215 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3218 *slot
= per_cu
->v
.quick
->file_names
;
3222 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3223 + dwarf2_per_objfile
->n_type_units
); ++i
)
3226 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3227 struct quick_file_names
*file_data
;
3230 /* We only need to look at symtabs not already expanded. */
3231 if (per_cu
->v
.quick
->symtab
)
3234 file_data
= dw2_get_file_names (objfile
, per_cu
);
3235 if (file_data
== NULL
)
3238 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3241 /* Already visited. */
3246 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3248 const char *this_real_name
;
3251 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3253 this_real_name
= NULL
;
3254 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3258 do_cleanups (cleanup
);
3262 dw2_has_symbols (struct objfile
*objfile
)
3267 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3270 dw2_find_last_source_symtab
,
3271 dw2_forget_cached_source_info
,
3272 dw2_map_symtabs_matching_filename
,
3274 dw2_pre_expand_symtabs_matching
,
3278 dw2_expand_symtabs_for_function
,
3279 dw2_expand_all_symtabs
,
3280 dw2_expand_symtabs_with_filename
,
3281 dw2_find_symbol_file
,
3282 dw2_map_matching_symbols
,
3283 dw2_expand_symtabs_matching
,
3284 dw2_find_pc_sect_symtab
,
3285 dw2_map_symbol_filenames
3288 /* Initialize for reading DWARF for this objfile. Return 0 if this
3289 file will use psymtabs, or 1 if using the GNU index. */
3292 dwarf2_initialize_objfile (struct objfile
*objfile
)
3294 /* If we're about to read full symbols, don't bother with the
3295 indices. In this case we also don't care if some other debug
3296 format is making psymtabs, because they are all about to be
3298 if ((objfile
->flags
& OBJF_READNOW
))
3302 dwarf2_per_objfile
->using_index
= 1;
3303 create_all_comp_units (objfile
);
3304 create_all_type_units (objfile
);
3305 dwarf2_per_objfile
->quick_file_names_table
=
3306 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3308 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3309 + dwarf2_per_objfile
->n_type_units
); ++i
)
3311 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3313 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3314 struct dwarf2_per_cu_quick_data
);
3317 /* Return 1 so that gdb sees the "quick" functions. However,
3318 these functions will be no-ops because we will have expanded
3323 if (dwarf2_read_index (objfile
))
3331 /* Build a partial symbol table. */
3334 dwarf2_build_psymtabs (struct objfile
*objfile
)
3336 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3338 init_psymbol_list (objfile
, 1024);
3341 dwarf2_build_psymtabs_hard (objfile
);
3344 /* Return TRUE if OFFSET is within CU_HEADER. */
3347 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3349 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3350 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3351 + cu_header
->initial_length_size
) };
3353 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3356 /* Read in the comp unit header information from the debug_info at info_ptr.
3357 NOTE: This leaves members offset, first_die_offset to be filled in
3361 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3362 gdb_byte
*info_ptr
, bfd
*abfd
)
3365 unsigned int bytes_read
;
3367 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3368 cu_header
->initial_length_size
= bytes_read
;
3369 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3370 info_ptr
+= bytes_read
;
3371 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3373 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3375 info_ptr
+= bytes_read
;
3376 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3378 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3379 if (signed_addr
< 0)
3380 internal_error (__FILE__
, __LINE__
,
3381 _("read_comp_unit_head: dwarf from non elf file"));
3382 cu_header
->signed_addr_p
= signed_addr
;
3387 /* Subroutine of read_and_check_comp_unit_head and
3388 read_and_check_type_unit_head to simplify them.
3389 Perform various error checking on the header. */
3392 error_check_comp_unit_head (struct comp_unit_head
*header
,
3393 struct dwarf2_section_info
*section
,
3394 struct dwarf2_section_info
*abbrev_section
)
3396 bfd
*abfd
= section
->asection
->owner
;
3397 const char *filename
= bfd_get_filename (abfd
);
3399 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3400 error (_("Dwarf Error: wrong version in compilation unit header "
3401 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3404 if (header
->abbrev_offset
.sect_off
3405 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3406 &dwarf2_per_objfile
->abbrev
))
3407 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3408 "(offset 0x%lx + 6) [in module %s]"),
3409 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3412 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3413 avoid potential 32-bit overflow. */
3414 if (((unsigned long) header
->offset
.sect_off
3415 + header
->length
+ header
->initial_length_size
)
3417 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3418 "(offset 0x%lx + 0) [in module %s]"),
3419 (long) header
->length
, (long) header
->offset
.sect_off
,
3423 /* Read in a CU/TU header and perform some basic error checking.
3424 The contents of the header are stored in HEADER.
3425 The result is a pointer to the start of the first DIE. */
3428 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3429 struct dwarf2_section_info
*section
,
3430 struct dwarf2_section_info
*abbrev_section
,
3432 int is_debug_types_section
)
3434 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3435 bfd
*abfd
= section
->asection
->owner
;
3437 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3439 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3441 /* If we're reading a type unit, skip over the signature and
3442 type_offset fields. */
3443 if (is_debug_types_section
)
3444 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3446 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3448 error_check_comp_unit_head (header
, section
, abbrev_section
);
3453 /* Read in the types comp unit header information from .debug_types entry at
3454 types_ptr. The result is a pointer to one past the end of the header. */
3457 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3458 struct dwarf2_section_info
*section
,
3459 struct dwarf2_section_info
*abbrev_section
,
3461 ULONGEST
*signature
,
3462 cu_offset
*type_offset_in_tu
)
3464 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3465 bfd
*abfd
= section
->asection
->owner
;
3467 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3469 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3471 /* If we're reading a type unit, skip over the signature and
3472 type_offset fields. */
3473 if (signature
!= NULL
)
3474 *signature
= read_8_bytes (abfd
, info_ptr
);
3476 if (type_offset_in_tu
!= NULL
)
3477 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3478 header
->offset_size
);
3479 info_ptr
+= header
->offset_size
;
3481 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3483 error_check_comp_unit_head (header
, section
, abbrev_section
);
3488 /* Allocate a new partial symtab for file named NAME and mark this new
3489 partial symtab as being an include of PST. */
3492 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3493 struct objfile
*objfile
)
3495 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3497 subpst
->section_offsets
= pst
->section_offsets
;
3498 subpst
->textlow
= 0;
3499 subpst
->texthigh
= 0;
3501 subpst
->dependencies
= (struct partial_symtab
**)
3502 obstack_alloc (&objfile
->objfile_obstack
,
3503 sizeof (struct partial_symtab
*));
3504 subpst
->dependencies
[0] = pst
;
3505 subpst
->number_of_dependencies
= 1;
3507 subpst
->globals_offset
= 0;
3508 subpst
->n_global_syms
= 0;
3509 subpst
->statics_offset
= 0;
3510 subpst
->n_static_syms
= 0;
3511 subpst
->symtab
= NULL
;
3512 subpst
->read_symtab
= pst
->read_symtab
;
3515 /* No private part is necessary for include psymtabs. This property
3516 can be used to differentiate between such include psymtabs and
3517 the regular ones. */
3518 subpst
->read_symtab_private
= NULL
;
3521 /* Read the Line Number Program data and extract the list of files
3522 included by the source file represented by PST. Build an include
3523 partial symtab for each of these included files. */
3526 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3527 struct die_info
*die
,
3528 struct partial_symtab
*pst
)
3530 struct line_header
*lh
= NULL
;
3531 struct attribute
*attr
;
3533 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3535 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3537 return; /* No linetable, so no includes. */
3539 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3540 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3542 free_line_header (lh
);
3546 hash_signatured_type (const void *item
)
3548 const struct signatured_type
*sig_type
= item
;
3550 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3551 return sig_type
->signature
;
3555 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3557 const struct signatured_type
*lhs
= item_lhs
;
3558 const struct signatured_type
*rhs
= item_rhs
;
3560 return lhs
->signature
== rhs
->signature
;
3563 /* Allocate a hash table for signatured types. */
3566 allocate_signatured_type_table (struct objfile
*objfile
)
3568 return htab_create_alloc_ex (41,
3569 hash_signatured_type
,
3572 &objfile
->objfile_obstack
,
3573 hashtab_obstack_allocate
,
3574 dummy_obstack_deallocate
);
3577 /* A helper function to add a signatured type CU to a table. */
3580 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3582 struct signatured_type
*sigt
= *slot
;
3583 struct dwarf2_per_cu_data
***datap
= datum
;
3585 **datap
= &sigt
->per_cu
;
3591 /* Create the hash table of all entries in the .debug_types section.
3592 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3593 The result is a pointer to the hash table or NULL if there are
3597 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3598 VEC (dwarf2_section_info_def
) *types
)
3600 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3601 htab_t types_htab
= NULL
;
3603 struct dwarf2_section_info
*section
;
3604 struct dwarf2_section_info
*abbrev_section
;
3606 if (VEC_empty (dwarf2_section_info_def
, types
))
3609 abbrev_section
= (dwo_file
!= NULL
3610 ? &dwo_file
->sections
.abbrev
3611 : &dwarf2_per_objfile
->abbrev
);
3614 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3618 gdb_byte
*info_ptr
, *end_ptr
;
3620 dwarf2_read_section (objfile
, section
);
3621 info_ptr
= section
->buffer
;
3623 if (info_ptr
== NULL
)
3626 /* We can't set abfd until now because the section may be empty or
3627 not present, in which case section->asection will be NULL. */
3628 abfd
= section
->asection
->owner
;
3630 if (types_htab
== NULL
)
3633 types_htab
= allocate_dwo_unit_table (objfile
);
3635 types_htab
= allocate_signatured_type_table (objfile
);
3638 if (dwarf2_die_debug
)
3639 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3640 bfd_get_filename (abfd
));
3642 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3643 because we don't need to read any dies: the signature is in the
3646 end_ptr
= info_ptr
+ section
->size
;
3647 while (info_ptr
< end_ptr
)
3650 cu_offset type_offset_in_tu
;
3652 struct signatured_type
*sig_type
;
3653 struct dwo_unit
*dwo_tu
;
3655 gdb_byte
*ptr
= info_ptr
;
3656 struct comp_unit_head header
;
3657 unsigned int length
;
3659 offset
.sect_off
= ptr
- section
->buffer
;
3661 /* We need to read the type's signature in order to build the hash
3662 table, but we don't need anything else just yet. */
3664 ptr
= read_and_check_type_unit_head (&header
, section
,
3665 abbrev_section
, ptr
,
3666 &signature
, &type_offset_in_tu
);
3668 length
= header
.initial_length_size
+ header
.length
;
3670 /* Skip dummy type units. */
3671 if (ptr
>= info_ptr
+ length
3672 || peek_abbrev_code (abfd
, ptr
) == 0)
3674 info_ptr
+= header
.initial_length_size
+ header
.length
;
3681 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3683 dwo_tu
->dwo_file
= dwo_file
;
3684 dwo_tu
->signature
= signature
;
3685 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3686 dwo_tu
->info_or_types_section
= section
;
3687 dwo_tu
->offset
= offset
;
3688 dwo_tu
->length
= length
;
3692 /* N.B.: type_offset is not usable if this type uses a DWO file.
3693 The real type_offset is in the DWO file. */
3695 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3696 struct signatured_type
);
3697 sig_type
->signature
= signature
;
3698 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3699 sig_type
->per_cu
.objfile
= objfile
;
3700 sig_type
->per_cu
.is_debug_types
= 1;
3701 sig_type
->per_cu
.info_or_types_section
= section
;
3702 sig_type
->per_cu
.offset
= offset
;
3703 sig_type
->per_cu
.length
= length
;
3706 slot
= htab_find_slot (types_htab
,
3707 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3709 gdb_assert (slot
!= NULL
);
3712 sect_offset dup_offset
;
3716 const struct dwo_unit
*dup_tu
= *slot
;
3718 dup_offset
= dup_tu
->offset
;
3722 const struct signatured_type
*dup_tu
= *slot
;
3724 dup_offset
= dup_tu
->per_cu
.offset
;
3727 complaint (&symfile_complaints
,
3728 _("debug type entry at offset 0x%x is duplicate to the "
3729 "entry at offset 0x%x, signature 0x%s"),
3730 offset
.sect_off
, dup_offset
.sect_off
,
3731 phex (signature
, sizeof (signature
)));
3733 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3735 if (dwarf2_die_debug
)
3736 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3738 phex (signature
, sizeof (signature
)));
3747 /* Create the hash table of all entries in the .debug_types section,
3748 and initialize all_type_units.
3749 The result is zero if there is an error (e.g. missing .debug_types section),
3750 otherwise non-zero. */
3753 create_all_type_units (struct objfile
*objfile
)
3756 struct dwarf2_per_cu_data
**iter
;
3758 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3759 if (types_htab
== NULL
)
3761 dwarf2_per_objfile
->signatured_types
= NULL
;
3765 dwarf2_per_objfile
->signatured_types
= types_htab
;
3767 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3768 dwarf2_per_objfile
->all_type_units
3769 = obstack_alloc (&objfile
->objfile_obstack
,
3770 dwarf2_per_objfile
->n_type_units
3771 * sizeof (struct dwarf2_per_cu_data
*));
3772 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3773 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3774 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3775 == dwarf2_per_objfile
->n_type_units
);
3780 /* Lookup a signature based type for DW_FORM_ref_sig8.
3781 Returns NULL if signature SIG is not present in the table. */
3783 static struct signatured_type
*
3784 lookup_signatured_type (ULONGEST sig
)
3786 struct signatured_type find_entry
, *entry
;
3788 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3790 complaint (&symfile_complaints
,
3791 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3795 find_entry
.signature
= sig
;
3796 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3800 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3803 init_cu_die_reader (struct die_reader_specs
*reader
,
3804 struct dwarf2_cu
*cu
,
3805 struct dwarf2_section_info
*section
,
3806 struct dwo_file
*dwo_file
)
3808 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3809 reader
->abfd
= section
->asection
->owner
;
3811 reader
->dwo_file
= dwo_file
;
3812 reader
->die_section
= section
;
3813 reader
->buffer
= section
->buffer
;
3814 reader
->buffer_end
= section
->buffer
+ section
->size
;
3817 /* Find the base address of the compilation unit for range lists and
3818 location lists. It will normally be specified by DW_AT_low_pc.
3819 In DWARF-3 draft 4, the base address could be overridden by
3820 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3821 compilation units with discontinuous ranges. */
3824 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3826 struct attribute
*attr
;
3829 cu
->base_address
= 0;
3831 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3834 cu
->base_address
= DW_ADDR (attr
);
3839 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3842 cu
->base_address
= DW_ADDR (attr
);
3848 /* Initialize a CU (or TU) and read its DIEs.
3849 If the CU defers to a DWO file, read the DWO file as well.
3851 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3852 Otherwise, a new CU is allocated with xmalloc.
3854 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3855 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3857 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3858 linker) then DIE_READER_FUNC will not get called. */
3861 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3862 int use_existing_cu
, int keep
,
3863 die_reader_func_ftype
*die_reader_func
,
3866 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3867 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3868 bfd
*abfd
= section
->asection
->owner
;
3869 struct dwarf2_cu
*cu
;
3870 gdb_byte
*begin_info_ptr
, *info_ptr
;
3871 struct die_reader_specs reader
;
3872 struct die_info
*comp_unit_die
;
3874 struct attribute
*attr
;
3875 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3876 struct signatured_type
*sig_type
= NULL
;
3877 struct dwarf2_section_info
*abbrev_section
;
3879 if (use_existing_cu
)
3882 cleanups
= make_cleanup (null_cleanup
, NULL
);
3884 /* This is cheap if the section is already read in. */
3885 dwarf2_read_section (objfile
, section
);
3887 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3888 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
3890 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3893 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3897 /* If !use_existing_cu, this_cu->cu must be NULL. */
3898 gdb_assert (this_cu
->cu
== NULL
);
3900 cu
= xmalloc (sizeof (*cu
));
3901 init_one_comp_unit (cu
, this_cu
);
3903 /* If an error occurs while loading, release our storage. */
3904 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3906 if (this_cu
->is_debug_types
)
3910 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
3911 abbrev_section
, info_ptr
,
3914 /* There's no way to get from PER_CU to its containing
3915 struct signatured_type.
3916 But we have the signature so we can use that. */
3917 sig_type
= lookup_signatured_type (signature
);
3918 /* We've already scanned all the signatured types,
3919 this must succeed. */
3920 gdb_assert (sig_type
!= NULL
);
3921 gdb_assert (&sig_type
->per_cu
== this_cu
);
3922 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3924 /* LENGTH has not been set yet for type units. */
3925 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3927 /* Establish the type offset that can be used to lookup the type. */
3928 sig_type
->type_offset_in_section
.sect_off
=
3929 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3933 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
3937 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3938 gdb_assert (this_cu
->length
3939 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3943 /* Skip dummy compilation units. */
3944 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3945 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3947 do_cleanups (cleanups
);
3951 /* Read the abbrevs for this compilation unit into a table. */
3952 if (cu
->dwarf2_abbrevs
== NULL
)
3954 dwarf2_read_abbrevs (cu
, abbrev_section
);
3955 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3958 /* Read the top level CU/TU die. */
3959 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3960 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3962 /* If we have a DWO stub, process it and then read in the DWO file.
3963 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3964 a DWO CU, that this test will fail. */
3965 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3968 char *dwo_name
= DW_STRING (attr
);
3969 const char *comp_dir
;
3970 struct dwo_unit
*dwo_unit
;
3971 ULONGEST signature
; /* Or dwo_id. */
3972 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3973 int i
,num_extra_attrs
;
3974 struct dwarf2_section_info
*dwo_abbrev_section
;
3977 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3978 " has children (offset 0x%x) [in module %s]"),
3979 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3981 /* These attributes aren't processed until later:
3982 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3983 However, the attribute is found in the stub which we won't have later.
3984 In order to not impose this complication on the rest of the code,
3985 we read them here and copy them to the DWO CU/TU die. */
3986 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3988 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3990 if (! this_cu
->is_debug_types
)
3991 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3992 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3993 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3994 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3996 /* There should be a DW_AT_addr_base attribute here (if needed).
3997 We need the value before we can process DW_FORM_GNU_addr_index. */
3999 cu
->have_addr_base
= 0;
4000 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4003 cu
->addr_base
= DW_UNSND (attr
);
4004 cu
->have_addr_base
= 1;
4007 if (this_cu
->is_debug_types
)
4009 gdb_assert (sig_type
!= NULL
);
4010 signature
= sig_type
->signature
;
4014 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4016 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4018 signature
= DW_UNSND (attr
);
4021 /* We may need the comp_dir in order to find the DWO file. */
4023 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4025 comp_dir
= DW_STRING (attr
);
4027 if (this_cu
->is_debug_types
)
4028 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
4030 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
4033 if (dwo_unit
== NULL
)
4035 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4036 " with ID %s [in module %s]"),
4037 this_cu
->offset
.sect_off
,
4038 phex (signature
, sizeof (signature
)),
4042 /* Set up for reading the DWO CU/TU. */
4043 cu
->dwo_unit
= dwo_unit
;
4044 section
= dwo_unit
->info_or_types_section
;
4045 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4046 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4047 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4049 if (this_cu
->is_debug_types
)
4053 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4057 gdb_assert (sig_type
->signature
== signature
);
4058 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4059 gdb_assert (dwo_unit
->length
4060 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4062 /* Establish the type offset that can be used to lookup the type.
4063 For DWO files, we don't know it until now. */
4064 sig_type
->type_offset_in_section
.sect_off
=
4065 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4069 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4072 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4073 gdb_assert (dwo_unit
->length
4074 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4077 /* Discard the original CU's abbrev table, and read the DWO's. */
4078 dwarf2_free_abbrev_table (cu
);
4079 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4081 /* Read in the die, but leave space to copy over the attributes
4082 from the stub. This has the benefit of simplifying the rest of
4083 the code - all the real work is done here. */
4084 num_extra_attrs
= ((stmt_list
!= NULL
)
4087 + (ranges
!= NULL
));
4088 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4089 &has_children
, num_extra_attrs
);
4091 /* Copy over the attributes from the stub to the DWO die. */
4092 i
= comp_unit_die
->num_attrs
;
4093 if (stmt_list
!= NULL
)
4094 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4096 comp_unit_die
->attrs
[i
++] = *low_pc
;
4097 if (high_pc
!= NULL
)
4098 comp_unit_die
->attrs
[i
++] = *high_pc
;
4100 comp_unit_die
->attrs
[i
++] = *ranges
;
4101 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4103 /* Skip dummy compilation units. */
4104 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4105 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4107 do_cleanups (cleanups
);
4112 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4114 if (free_cu_cleanup
!= NULL
)
4118 /* We've successfully allocated this compilation unit. Let our
4119 caller clean it up when finished with it. */
4120 discard_cleanups (free_cu_cleanup
);
4122 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4123 So we have to manually free the abbrev table. */
4124 dwarf2_free_abbrev_table (cu
);
4126 /* Link this CU into read_in_chain. */
4127 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4128 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4131 do_cleanups (free_cu_cleanup
);
4134 do_cleanups (cleanups
);
4137 /* Read CU/TU THIS_CU in section SECTION,
4138 but do not follow DW_AT_GNU_dwo_name if present.
4139 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4140 have already done the lookup to find the DWO file).
4142 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4143 THIS_CU->is_debug_types, but nothing else.
4145 We fill in THIS_CU->length.
4147 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4148 linker) then DIE_READER_FUNC will not get called.
4150 THIS_CU->cu is always freed when done.
4151 This is done in order to not leave THIS_CU->cu in a state where we have
4152 to care whether it refers to the "main" CU or the DWO CU. */
4155 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4156 struct dwarf2_section_info
*abbrev_section
,
4157 struct dwo_file
*dwo_file
,
4158 die_reader_func_ftype
*die_reader_func
,
4161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4162 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4163 bfd
*abfd
= section
->asection
->owner
;
4164 struct dwarf2_cu cu
;
4165 gdb_byte
*begin_info_ptr
, *info_ptr
;
4166 struct die_reader_specs reader
;
4167 struct cleanup
*cleanups
;
4168 struct die_info
*comp_unit_die
;
4171 gdb_assert (this_cu
->cu
== NULL
);
4173 /* This is cheap if the section is already read in. */
4174 dwarf2_read_section (objfile
, section
);
4176 init_one_comp_unit (&cu
, this_cu
);
4178 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4180 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4181 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4182 abbrev_section
, info_ptr
,
4183 this_cu
->is_debug_types
);
4185 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4187 /* Skip dummy compilation units. */
4188 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4189 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4191 do_cleanups (cleanups
);
4195 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4196 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4198 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4199 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4201 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4203 do_cleanups (cleanups
);
4206 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4207 does not lookup the specified DWO file.
4208 This cannot be used to read DWO files.
4210 THIS_CU->cu is always freed when done.
4211 This is done in order to not leave THIS_CU->cu in a state where we have
4212 to care whether it refers to the "main" CU or the DWO CU.
4213 We can revisit this if the data shows there's a performance issue. */
4216 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4217 die_reader_func_ftype
*die_reader_func
,
4220 init_cutu_and_read_dies_no_follow (this_cu
,
4221 &dwarf2_per_objfile
->abbrev
,
4223 die_reader_func
, data
);
4226 /* die_reader_func for process_psymtab_comp_unit. */
4229 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4231 struct die_info
*comp_unit_die
,
4235 struct dwarf2_cu
*cu
= reader
->cu
;
4236 struct objfile
*objfile
= cu
->objfile
;
4237 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4238 struct attribute
*attr
;
4240 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4241 struct partial_symtab
*pst
;
4243 const char *filename
;
4244 int *want_partial_unit_ptr
= data
;
4246 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4247 && (want_partial_unit_ptr
== NULL
4248 || !*want_partial_unit_ptr
))
4251 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4253 cu
->list_in_scope
= &file_symbols
;
4255 /* Allocate a new partial symbol table structure. */
4256 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4257 if (attr
== NULL
|| !DW_STRING (attr
))
4260 filename
= DW_STRING (attr
);
4261 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4263 /* TEXTLOW and TEXTHIGH are set below. */
4265 objfile
->global_psymbols
.next
,
4266 objfile
->static_psymbols
.next
);
4267 pst
->psymtabs_addrmap_supported
= 1;
4269 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4271 pst
->dirname
= DW_STRING (attr
);
4273 pst
->read_symtab_private
= per_cu
;
4275 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4277 /* Store the function that reads in the rest of the symbol table. */
4278 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4280 per_cu
->v
.psymtab
= pst
;
4282 dwarf2_find_base_address (comp_unit_die
, cu
);
4284 /* Possibly set the default values of LOWPC and HIGHPC from
4286 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4287 &best_highpc
, cu
, pst
);
4288 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4289 /* Store the contiguous range if it is not empty; it can be empty for
4290 CUs with no code. */
4291 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4292 best_lowpc
+ baseaddr
,
4293 best_highpc
+ baseaddr
- 1, pst
);
4295 /* Check if comp unit has_children.
4296 If so, read the rest of the partial symbols from this comp unit.
4297 If not, there's no more debug_info for this comp unit. */
4300 struct partial_die_info
*first_die
;
4301 CORE_ADDR lowpc
, highpc
;
4303 lowpc
= ((CORE_ADDR
) -1);
4304 highpc
= ((CORE_ADDR
) 0);
4306 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4308 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4311 /* If we didn't find a lowpc, set it to highpc to avoid
4312 complaints from `maint check'. */
4313 if (lowpc
== ((CORE_ADDR
) -1))
4316 /* If the compilation unit didn't have an explicit address range,
4317 then use the information extracted from its child dies. */
4321 best_highpc
= highpc
;
4324 pst
->textlow
= best_lowpc
+ baseaddr
;
4325 pst
->texthigh
= best_highpc
+ baseaddr
;
4327 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4328 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4329 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4330 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4331 sort_pst_symbols (pst
);
4333 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4336 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4337 struct dwarf2_per_cu_data
*iter
;
4339 /* Fill in 'dependencies' here; we fill in 'users' in a
4341 pst
->number_of_dependencies
= len
;
4342 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4343 len
* sizeof (struct symtab
*));
4345 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4348 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4350 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4353 if (per_cu
->is_debug_types
)
4355 /* It's not clear we want to do anything with stmt lists here.
4356 Waiting to see what gcc ultimately does. */
4360 /* Get the list of files included in the current compilation unit,
4361 and build a psymtab for each of them. */
4362 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4366 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4367 Process compilation unit THIS_CU for a psymtab. */
4370 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4371 int want_partial_unit
)
4373 /* If this compilation unit was already read in, free the
4374 cached copy in order to read it in again. This is
4375 necessary because we skipped some symbols when we first
4376 read in the compilation unit (see load_partial_dies).
4377 This problem could be avoided, but the benefit is unclear. */
4378 if (this_cu
->cu
!= NULL
)
4379 free_one_cached_comp_unit (this_cu
);
4381 gdb_assert (! this_cu
->is_debug_types
);
4382 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4383 &want_partial_unit
);
4385 /* Age out any secondary CUs. */
4386 age_cached_comp_units ();
4389 /* Traversal function for htab_traverse_noresize.
4390 Process one .debug_types comp-unit. */
4393 process_psymtab_type_unit (void **slot
, void *info
)
4395 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4396 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4398 gdb_assert (per_cu
->is_debug_types
);
4399 gdb_assert (info
== NULL
);
4401 /* If this compilation unit was already read in, free the
4402 cached copy in order to read it in again. This is
4403 necessary because we skipped some symbols when we first
4404 read in the compilation unit (see load_partial_dies).
4405 This problem could be avoided, but the benefit is unclear. */
4406 if (per_cu
->cu
!= NULL
)
4407 free_one_cached_comp_unit (per_cu
);
4409 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4412 /* Age out any secondary CUs. */
4413 age_cached_comp_units ();
4418 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4419 Build partial symbol tables for the .debug_types comp-units. */
4422 build_type_psymtabs (struct objfile
*objfile
)
4424 if (! create_all_type_units (objfile
))
4427 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4428 process_psymtab_type_unit
, NULL
);
4431 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4434 psymtabs_addrmap_cleanup (void *o
)
4436 struct objfile
*objfile
= o
;
4438 objfile
->psymtabs_addrmap
= NULL
;
4441 /* Compute the 'user' field for each psymtab in OBJFILE. */
4444 set_partial_user (struct objfile
*objfile
)
4448 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4450 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4451 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4454 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4456 /* Set the 'user' field only if it is not already set. */
4457 if (pst
->dependencies
[j
]->user
== NULL
)
4458 pst
->dependencies
[j
]->user
= pst
;
4463 /* Build the partial symbol table by doing a quick pass through the
4464 .debug_info and .debug_abbrev sections. */
4467 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4469 struct cleanup
*back_to
, *addrmap_cleanup
;
4470 struct obstack temp_obstack
;
4473 if (dwarf2_read_debug
)
4475 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
4479 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4481 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4483 /* Any cached compilation units will be linked by the per-objfile
4484 read_in_chain. Make sure to free them when we're done. */
4485 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4487 build_type_psymtabs (objfile
);
4489 create_all_comp_units (objfile
);
4491 /* Create a temporary address map on a temporary obstack. We later
4492 copy this to the final obstack. */
4493 obstack_init (&temp_obstack
);
4494 make_cleanup_obstack_free (&temp_obstack
);
4495 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4496 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4498 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4500 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4502 process_psymtab_comp_unit (per_cu
, 0);
4505 set_partial_user (objfile
);
4507 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4508 &objfile
->objfile_obstack
);
4509 discard_cleanups (addrmap_cleanup
);
4511 do_cleanups (back_to
);
4513 if (dwarf2_read_debug
)
4514 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
4518 /* die_reader_func for load_partial_comp_unit. */
4521 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4523 struct die_info
*comp_unit_die
,
4527 struct dwarf2_cu
*cu
= reader
->cu
;
4529 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4531 /* Check if comp unit has_children.
4532 If so, read the rest of the partial symbols from this comp unit.
4533 If not, there's no more debug_info for this comp unit. */
4535 load_partial_dies (reader
, info_ptr
, 0);
4538 /* Load the partial DIEs for a secondary CU into memory.
4539 This is also used when rereading a primary CU with load_all_dies. */
4542 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4544 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4547 /* Create a list of all compilation units in OBJFILE.
4548 This is only done for -readnow and building partial symtabs. */
4551 create_all_comp_units (struct objfile
*objfile
)
4555 struct dwarf2_per_cu_data
**all_comp_units
;
4558 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4559 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4563 all_comp_units
= xmalloc (n_allocated
4564 * sizeof (struct dwarf2_per_cu_data
*));
4566 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4567 + dwarf2_per_objfile
->info
.size
)
4569 unsigned int length
, initial_length_size
;
4570 struct dwarf2_per_cu_data
*this_cu
;
4573 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4575 /* Read just enough information to find out where the next
4576 compilation unit is. */
4577 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4578 &initial_length_size
);
4580 /* Save the compilation unit for later lookup. */
4581 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4582 sizeof (struct dwarf2_per_cu_data
));
4583 memset (this_cu
, 0, sizeof (*this_cu
));
4584 this_cu
->offset
= offset
;
4585 this_cu
->length
= length
+ initial_length_size
;
4586 this_cu
->objfile
= objfile
;
4587 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4589 if (n_comp_units
== n_allocated
)
4592 all_comp_units
= xrealloc (all_comp_units
,
4594 * sizeof (struct dwarf2_per_cu_data
*));
4596 all_comp_units
[n_comp_units
++] = this_cu
;
4598 info_ptr
= info_ptr
+ this_cu
->length
;
4601 dwarf2_per_objfile
->all_comp_units
4602 = obstack_alloc (&objfile
->objfile_obstack
,
4603 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4604 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4605 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4606 xfree (all_comp_units
);
4607 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4610 /* Process all loaded DIEs for compilation unit CU, starting at
4611 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4612 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4613 DW_AT_ranges). If NEED_PC is set, then this function will set
4614 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4615 and record the covered ranges in the addrmap. */
4618 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4619 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4621 struct partial_die_info
*pdi
;
4623 /* Now, march along the PDI's, descending into ones which have
4624 interesting children but skipping the children of the other ones,
4625 until we reach the end of the compilation unit. */
4631 fixup_partial_die (pdi
, cu
);
4633 /* Anonymous namespaces or modules have no name but have interesting
4634 children, so we need to look at them. Ditto for anonymous
4637 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4638 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4639 || pdi
->tag
== DW_TAG_imported_unit
)
4643 case DW_TAG_subprogram
:
4644 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4646 case DW_TAG_constant
:
4647 case DW_TAG_variable
:
4648 case DW_TAG_typedef
:
4649 case DW_TAG_union_type
:
4650 if (!pdi
->is_declaration
)
4652 add_partial_symbol (pdi
, cu
);
4655 case DW_TAG_class_type
:
4656 case DW_TAG_interface_type
:
4657 case DW_TAG_structure_type
:
4658 if (!pdi
->is_declaration
)
4660 add_partial_symbol (pdi
, cu
);
4663 case DW_TAG_enumeration_type
:
4664 if (!pdi
->is_declaration
)
4665 add_partial_enumeration (pdi
, cu
);
4667 case DW_TAG_base_type
:
4668 case DW_TAG_subrange_type
:
4669 /* File scope base type definitions are added to the partial
4671 add_partial_symbol (pdi
, cu
);
4673 case DW_TAG_namespace
:
4674 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4677 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4679 case DW_TAG_imported_unit
:
4681 struct dwarf2_per_cu_data
*per_cu
;
4683 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4686 /* Go read the partial unit, if needed. */
4687 if (per_cu
->v
.psymtab
== NULL
)
4688 process_psymtab_comp_unit (per_cu
, 1);
4690 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4699 /* If the die has a sibling, skip to the sibling. */
4701 pdi
= pdi
->die_sibling
;
4705 /* Functions used to compute the fully scoped name of a partial DIE.
4707 Normally, this is simple. For C++, the parent DIE's fully scoped
4708 name is concatenated with "::" and the partial DIE's name. For
4709 Java, the same thing occurs except that "." is used instead of "::".
4710 Enumerators are an exception; they use the scope of their parent
4711 enumeration type, i.e. the name of the enumeration type is not
4712 prepended to the enumerator.
4714 There are two complexities. One is DW_AT_specification; in this
4715 case "parent" means the parent of the target of the specification,
4716 instead of the direct parent of the DIE. The other is compilers
4717 which do not emit DW_TAG_namespace; in this case we try to guess
4718 the fully qualified name of structure types from their members'
4719 linkage names. This must be done using the DIE's children rather
4720 than the children of any DW_AT_specification target. We only need
4721 to do this for structures at the top level, i.e. if the target of
4722 any DW_AT_specification (if any; otherwise the DIE itself) does not
4725 /* Compute the scope prefix associated with PDI's parent, in
4726 compilation unit CU. The result will be allocated on CU's
4727 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4728 field. NULL is returned if no prefix is necessary. */
4730 partial_die_parent_scope (struct partial_die_info
*pdi
,
4731 struct dwarf2_cu
*cu
)
4733 char *grandparent_scope
;
4734 struct partial_die_info
*parent
, *real_pdi
;
4736 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4737 then this means the parent of the specification DIE. */
4740 while (real_pdi
->has_specification
)
4741 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4743 parent
= real_pdi
->die_parent
;
4747 if (parent
->scope_set
)
4748 return parent
->scope
;
4750 fixup_partial_die (parent
, cu
);
4752 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4754 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4755 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4756 Work around this problem here. */
4757 if (cu
->language
== language_cplus
4758 && parent
->tag
== DW_TAG_namespace
4759 && strcmp (parent
->name
, "::") == 0
4760 && grandparent_scope
== NULL
)
4762 parent
->scope
= NULL
;
4763 parent
->scope_set
= 1;
4767 if (pdi
->tag
== DW_TAG_enumerator
)
4768 /* Enumerators should not get the name of the enumeration as a prefix. */
4769 parent
->scope
= grandparent_scope
;
4770 else if (parent
->tag
== DW_TAG_namespace
4771 || parent
->tag
== DW_TAG_module
4772 || parent
->tag
== DW_TAG_structure_type
4773 || parent
->tag
== DW_TAG_class_type
4774 || parent
->tag
== DW_TAG_interface_type
4775 || parent
->tag
== DW_TAG_union_type
4776 || parent
->tag
== DW_TAG_enumeration_type
)
4778 if (grandparent_scope
== NULL
)
4779 parent
->scope
= parent
->name
;
4781 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4783 parent
->name
, 0, cu
);
4787 /* FIXME drow/2004-04-01: What should we be doing with
4788 function-local names? For partial symbols, we should probably be
4790 complaint (&symfile_complaints
,
4791 _("unhandled containing DIE tag %d for DIE at %d"),
4792 parent
->tag
, pdi
->offset
.sect_off
);
4793 parent
->scope
= grandparent_scope
;
4796 parent
->scope_set
= 1;
4797 return parent
->scope
;
4800 /* Return the fully scoped name associated with PDI, from compilation unit
4801 CU. The result will be allocated with malloc. */
4804 partial_die_full_name (struct partial_die_info
*pdi
,
4805 struct dwarf2_cu
*cu
)
4809 /* If this is a template instantiation, we can not work out the
4810 template arguments from partial DIEs. So, unfortunately, we have
4811 to go through the full DIEs. At least any work we do building
4812 types here will be reused if full symbols are loaded later. */
4813 if (pdi
->has_template_arguments
)
4815 fixup_partial_die (pdi
, cu
);
4817 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4819 struct die_info
*die
;
4820 struct attribute attr
;
4821 struct dwarf2_cu
*ref_cu
= cu
;
4823 /* DW_FORM_ref_addr is using section offset. */
4825 attr
.form
= DW_FORM_ref_addr
;
4826 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4827 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4829 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4833 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4834 if (parent_scope
== NULL
)
4837 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4841 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4843 struct objfile
*objfile
= cu
->objfile
;
4845 char *actual_name
= NULL
;
4847 int built_actual_name
= 0;
4849 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4851 actual_name
= partial_die_full_name (pdi
, cu
);
4853 built_actual_name
= 1;
4855 if (actual_name
== NULL
)
4856 actual_name
= pdi
->name
;
4860 case DW_TAG_subprogram
:
4861 if (pdi
->is_external
|| cu
->language
== language_ada
)
4863 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4864 of the global scope. But in Ada, we want to be able to access
4865 nested procedures globally. So all Ada subprograms are stored
4866 in the global scope. */
4867 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4868 mst_text, objfile); */
4869 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4871 VAR_DOMAIN
, LOC_BLOCK
,
4872 &objfile
->global_psymbols
,
4873 0, pdi
->lowpc
+ baseaddr
,
4874 cu
->language
, objfile
);
4878 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4879 mst_file_text, objfile); */
4880 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4882 VAR_DOMAIN
, LOC_BLOCK
,
4883 &objfile
->static_psymbols
,
4884 0, pdi
->lowpc
+ baseaddr
,
4885 cu
->language
, objfile
);
4888 case DW_TAG_constant
:
4890 struct psymbol_allocation_list
*list
;
4892 if (pdi
->is_external
)
4893 list
= &objfile
->global_psymbols
;
4895 list
= &objfile
->static_psymbols
;
4896 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4897 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4898 list
, 0, 0, cu
->language
, objfile
);
4901 case DW_TAG_variable
:
4903 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4907 && !dwarf2_per_objfile
->has_section_at_zero
)
4909 /* A global or static variable may also have been stripped
4910 out by the linker if unused, in which case its address
4911 will be nullified; do not add such variables into partial
4912 symbol table then. */
4914 else if (pdi
->is_external
)
4917 Don't enter into the minimal symbol tables as there is
4918 a minimal symbol table entry from the ELF symbols already.
4919 Enter into partial symbol table if it has a location
4920 descriptor or a type.
4921 If the location descriptor is missing, new_symbol will create
4922 a LOC_UNRESOLVED symbol, the address of the variable will then
4923 be determined from the minimal symbol table whenever the variable
4925 The address for the partial symbol table entry is not
4926 used by GDB, but it comes in handy for debugging partial symbol
4929 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4930 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4932 VAR_DOMAIN
, LOC_STATIC
,
4933 &objfile
->global_psymbols
,
4935 cu
->language
, objfile
);
4939 /* Static Variable. Skip symbols without location descriptors. */
4940 if (pdi
->d
.locdesc
== NULL
)
4942 if (built_actual_name
)
4943 xfree (actual_name
);
4946 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4947 mst_file_data, objfile); */
4948 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4950 VAR_DOMAIN
, LOC_STATIC
,
4951 &objfile
->static_psymbols
,
4953 cu
->language
, objfile
);
4956 case DW_TAG_typedef
:
4957 case DW_TAG_base_type
:
4958 case DW_TAG_subrange_type
:
4959 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4961 VAR_DOMAIN
, LOC_TYPEDEF
,
4962 &objfile
->static_psymbols
,
4963 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4965 case DW_TAG_namespace
:
4966 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4968 VAR_DOMAIN
, LOC_TYPEDEF
,
4969 &objfile
->global_psymbols
,
4970 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4972 case DW_TAG_class_type
:
4973 case DW_TAG_interface_type
:
4974 case DW_TAG_structure_type
:
4975 case DW_TAG_union_type
:
4976 case DW_TAG_enumeration_type
:
4977 /* Skip external references. The DWARF standard says in the section
4978 about "Structure, Union, and Class Type Entries": "An incomplete
4979 structure, union or class type is represented by a structure,
4980 union or class entry that does not have a byte size attribute
4981 and that has a DW_AT_declaration attribute." */
4982 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4984 if (built_actual_name
)
4985 xfree (actual_name
);
4989 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4990 static vs. global. */
4991 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4993 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4994 (cu
->language
== language_cplus
4995 || cu
->language
== language_java
)
4996 ? &objfile
->global_psymbols
4997 : &objfile
->static_psymbols
,
4998 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5001 case DW_TAG_enumerator
:
5002 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5004 VAR_DOMAIN
, LOC_CONST
,
5005 (cu
->language
== language_cplus
5006 || cu
->language
== language_java
)
5007 ? &objfile
->global_psymbols
5008 : &objfile
->static_psymbols
,
5009 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5015 if (built_actual_name
)
5016 xfree (actual_name
);
5019 /* Read a partial die corresponding to a namespace; also, add a symbol
5020 corresponding to that namespace to the symbol table. NAMESPACE is
5021 the name of the enclosing namespace. */
5024 add_partial_namespace (struct partial_die_info
*pdi
,
5025 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5026 int need_pc
, struct dwarf2_cu
*cu
)
5028 /* Add a symbol for the namespace. */
5030 add_partial_symbol (pdi
, cu
);
5032 /* Now scan partial symbols in that namespace. */
5034 if (pdi
->has_children
)
5035 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5038 /* Read a partial die corresponding to a Fortran module. */
5041 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5042 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5044 /* Now scan partial symbols in that module. */
5046 if (pdi
->has_children
)
5047 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5050 /* Read a partial die corresponding to a subprogram and create a partial
5051 symbol for that subprogram. When the CU language allows it, this
5052 routine also defines a partial symbol for each nested subprogram
5053 that this subprogram contains.
5055 DIE my also be a lexical block, in which case we simply search
5056 recursively for suprograms defined inside that lexical block.
5057 Again, this is only performed when the CU language allows this
5058 type of definitions. */
5061 add_partial_subprogram (struct partial_die_info
*pdi
,
5062 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5063 int need_pc
, struct dwarf2_cu
*cu
)
5065 if (pdi
->tag
== DW_TAG_subprogram
)
5067 if (pdi
->has_pc_info
)
5069 if (pdi
->lowpc
< *lowpc
)
5070 *lowpc
= pdi
->lowpc
;
5071 if (pdi
->highpc
> *highpc
)
5072 *highpc
= pdi
->highpc
;
5076 struct objfile
*objfile
= cu
->objfile
;
5078 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5079 SECT_OFF_TEXT (objfile
));
5080 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5081 pdi
->lowpc
+ baseaddr
,
5082 pdi
->highpc
- 1 + baseaddr
,
5083 cu
->per_cu
->v
.psymtab
);
5087 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5089 if (!pdi
->is_declaration
)
5090 /* Ignore subprogram DIEs that do not have a name, they are
5091 illegal. Do not emit a complaint at this point, we will
5092 do so when we convert this psymtab into a symtab. */
5094 add_partial_symbol (pdi
, cu
);
5098 if (! pdi
->has_children
)
5101 if (cu
->language
== language_ada
)
5103 pdi
= pdi
->die_child
;
5106 fixup_partial_die (pdi
, cu
);
5107 if (pdi
->tag
== DW_TAG_subprogram
5108 || pdi
->tag
== DW_TAG_lexical_block
)
5109 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5110 pdi
= pdi
->die_sibling
;
5115 /* Read a partial die corresponding to an enumeration type. */
5118 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5119 struct dwarf2_cu
*cu
)
5121 struct partial_die_info
*pdi
;
5123 if (enum_pdi
->name
!= NULL
)
5124 add_partial_symbol (enum_pdi
, cu
);
5126 pdi
= enum_pdi
->die_child
;
5129 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5130 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5132 add_partial_symbol (pdi
, cu
);
5133 pdi
= pdi
->die_sibling
;
5137 /* Return the initial uleb128 in the die at INFO_PTR. */
5140 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5142 unsigned int bytes_read
;
5144 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5147 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5148 Return the corresponding abbrev, or NULL if the number is zero (indicating
5149 an empty DIE). In either case *BYTES_READ will be set to the length of
5150 the initial number. */
5152 static struct abbrev_info
*
5153 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5154 struct dwarf2_cu
*cu
)
5156 bfd
*abfd
= cu
->objfile
->obfd
;
5157 unsigned int abbrev_number
;
5158 struct abbrev_info
*abbrev
;
5160 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5162 if (abbrev_number
== 0)
5165 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5168 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5169 abbrev_number
, bfd_get_filename (abfd
));
5175 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5176 Returns a pointer to the end of a series of DIEs, terminated by an empty
5177 DIE. Any children of the skipped DIEs will also be skipped. */
5180 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5182 struct dwarf2_cu
*cu
= reader
->cu
;
5183 struct abbrev_info
*abbrev
;
5184 unsigned int bytes_read
;
5188 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5190 return info_ptr
+ bytes_read
;
5192 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5196 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5197 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5198 abbrev corresponding to that skipped uleb128 should be passed in
5199 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5203 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5204 struct abbrev_info
*abbrev
)
5206 unsigned int bytes_read
;
5207 struct attribute attr
;
5208 bfd
*abfd
= reader
->abfd
;
5209 struct dwarf2_cu
*cu
= reader
->cu
;
5210 gdb_byte
*buffer
= reader
->buffer
;
5211 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5212 gdb_byte
*start_info_ptr
= info_ptr
;
5213 unsigned int form
, i
;
5215 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5217 /* The only abbrev we care about is DW_AT_sibling. */
5218 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5220 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5221 if (attr
.form
== DW_FORM_ref_addr
)
5222 complaint (&symfile_complaints
,
5223 _("ignoring absolute DW_AT_sibling"));
5225 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5228 /* If it isn't DW_AT_sibling, skip this attribute. */
5229 form
= abbrev
->attrs
[i
].form
;
5233 case DW_FORM_ref_addr
:
5234 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5235 and later it is offset sized. */
5236 if (cu
->header
.version
== 2)
5237 info_ptr
+= cu
->header
.addr_size
;
5239 info_ptr
+= cu
->header
.offset_size
;
5242 info_ptr
+= cu
->header
.addr_size
;
5249 case DW_FORM_flag_present
:
5261 case DW_FORM_ref_sig8
:
5264 case DW_FORM_string
:
5265 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5266 info_ptr
+= bytes_read
;
5268 case DW_FORM_sec_offset
:
5270 info_ptr
+= cu
->header
.offset_size
;
5272 case DW_FORM_exprloc
:
5274 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5275 info_ptr
+= bytes_read
;
5277 case DW_FORM_block1
:
5278 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5280 case DW_FORM_block2
:
5281 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5283 case DW_FORM_block4
:
5284 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5288 case DW_FORM_ref_udata
:
5289 case DW_FORM_GNU_addr_index
:
5290 case DW_FORM_GNU_str_index
:
5291 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5293 case DW_FORM_indirect
:
5294 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5295 info_ptr
+= bytes_read
;
5296 /* We need to continue parsing from here, so just go back to
5298 goto skip_attribute
;
5301 error (_("Dwarf Error: Cannot handle %s "
5302 "in DWARF reader [in module %s]"),
5303 dwarf_form_name (form
),
5304 bfd_get_filename (abfd
));
5308 if (abbrev
->has_children
)
5309 return skip_children (reader
, info_ptr
);
5314 /* Locate ORIG_PDI's sibling.
5315 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5318 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5319 struct partial_die_info
*orig_pdi
,
5322 /* Do we know the sibling already? */
5324 if (orig_pdi
->sibling
)
5325 return orig_pdi
->sibling
;
5327 /* Are there any children to deal with? */
5329 if (!orig_pdi
->has_children
)
5332 /* Skip the children the long way. */
5334 return skip_children (reader
, info_ptr
);
5337 /* Expand this partial symbol table into a full symbol table. */
5340 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5346 warning (_("bug: psymtab for %s is already read in."),
5353 printf_filtered (_("Reading in symbols for %s..."),
5355 gdb_flush (gdb_stdout
);
5358 /* Restore our global data. */
5359 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5360 dwarf2_objfile_data_key
);
5362 /* If this psymtab is constructed from a debug-only objfile, the
5363 has_section_at_zero flag will not necessarily be correct. We
5364 can get the correct value for this flag by looking at the data
5365 associated with the (presumably stripped) associated objfile. */
5366 if (pst
->objfile
->separate_debug_objfile_backlink
)
5368 struct dwarf2_per_objfile
*dpo_backlink
5369 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5370 dwarf2_objfile_data_key
);
5372 dwarf2_per_objfile
->has_section_at_zero
5373 = dpo_backlink
->has_section_at_zero
;
5376 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5378 psymtab_to_symtab_1 (pst
);
5380 /* Finish up the debug error message. */
5382 printf_filtered (_("done.\n"));
5386 process_cu_includes ();
5389 /* Reading in full CUs. */
5391 /* Add PER_CU to the queue. */
5394 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5395 enum language pretend_language
)
5397 struct dwarf2_queue_item
*item
;
5400 item
= xmalloc (sizeof (*item
));
5401 item
->per_cu
= per_cu
;
5402 item
->pretend_language
= pretend_language
;
5405 if (dwarf2_queue
== NULL
)
5406 dwarf2_queue
= item
;
5408 dwarf2_queue_tail
->next
= item
;
5410 dwarf2_queue_tail
= item
;
5413 /* Process the queue. */
5416 process_queue (void)
5418 struct dwarf2_queue_item
*item
, *next_item
;
5420 if (dwarf2_read_debug
)
5422 fprintf_unfiltered (gdb_stdlog
,
5423 "Expanding one or more symtabs of objfile %s ...\n",
5424 dwarf2_per_objfile
->objfile
->name
);
5427 /* The queue starts out with one item, but following a DIE reference
5428 may load a new CU, adding it to the end of the queue. */
5429 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5431 if (dwarf2_per_objfile
->using_index
5432 ? !item
->per_cu
->v
.quick
->symtab
5433 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5434 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5436 item
->per_cu
->queued
= 0;
5437 next_item
= item
->next
;
5441 dwarf2_queue_tail
= NULL
;
5443 if (dwarf2_read_debug
)
5445 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
5446 dwarf2_per_objfile
->objfile
->name
);
5450 /* Free all allocated queue entries. This function only releases anything if
5451 an error was thrown; if the queue was processed then it would have been
5452 freed as we went along. */
5455 dwarf2_release_queue (void *dummy
)
5457 struct dwarf2_queue_item
*item
, *last
;
5459 item
= dwarf2_queue
;
5462 /* Anything still marked queued is likely to be in an
5463 inconsistent state, so discard it. */
5464 if (item
->per_cu
->queued
)
5466 if (item
->per_cu
->cu
!= NULL
)
5467 free_one_cached_comp_unit (item
->per_cu
);
5468 item
->per_cu
->queued
= 0;
5476 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5479 /* Read in full symbols for PST, and anything it depends on. */
5482 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5484 struct dwarf2_per_cu_data
*per_cu
;
5490 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5491 if (!pst
->dependencies
[i
]->readin
5492 && pst
->dependencies
[i
]->user
== NULL
)
5494 /* Inform about additional files that need to be read in. */
5497 /* FIXME: i18n: Need to make this a single string. */
5498 fputs_filtered (" ", gdb_stdout
);
5500 fputs_filtered ("and ", gdb_stdout
);
5502 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5503 wrap_here (""); /* Flush output. */
5504 gdb_flush (gdb_stdout
);
5506 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5509 per_cu
= pst
->read_symtab_private
;
5513 /* It's an include file, no symbols to read for it.
5514 Everything is in the parent symtab. */
5519 dw2_do_instantiate_symtab (per_cu
);
5522 /* Trivial hash function for die_info: the hash value of a DIE
5523 is its offset in .debug_info for this objfile. */
5526 die_hash (const void *item
)
5528 const struct die_info
*die
= item
;
5530 return die
->offset
.sect_off
;
5533 /* Trivial comparison function for die_info structures: two DIEs
5534 are equal if they have the same offset. */
5537 die_eq (const void *item_lhs
, const void *item_rhs
)
5539 const struct die_info
*die_lhs
= item_lhs
;
5540 const struct die_info
*die_rhs
= item_rhs
;
5542 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5545 /* die_reader_func for load_full_comp_unit.
5546 This is identical to read_signatured_type_reader,
5547 but is kept separate for now. */
5550 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5552 struct die_info
*comp_unit_die
,
5556 struct dwarf2_cu
*cu
= reader
->cu
;
5557 enum language
*language_ptr
= data
;
5559 gdb_assert (cu
->die_hash
== NULL
);
5561 htab_create_alloc_ex (cu
->header
.length
/ 12,
5565 &cu
->comp_unit_obstack
,
5566 hashtab_obstack_allocate
,
5567 dummy_obstack_deallocate
);
5570 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5571 &info_ptr
, comp_unit_die
);
5572 cu
->dies
= comp_unit_die
;
5573 /* comp_unit_die is not stored in die_hash, no need. */
5575 /* We try not to read any attributes in this function, because not
5576 all CUs needed for references have been loaded yet, and symbol
5577 table processing isn't initialized. But we have to set the CU language,
5578 or we won't be able to build types correctly.
5579 Similarly, if we do not read the producer, we can not apply
5580 producer-specific interpretation. */
5581 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5584 /* Load the DIEs associated with PER_CU into memory. */
5587 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5588 enum language pretend_language
)
5590 gdb_assert (! this_cu
->is_debug_types
);
5592 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5596 /* Add a DIE to the delayed physname list. */
5599 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5600 const char *name
, struct die_info
*die
,
5601 struct dwarf2_cu
*cu
)
5603 struct delayed_method_info mi
;
5605 mi
.fnfield_index
= fnfield_index
;
5609 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5612 /* A cleanup for freeing the delayed method list. */
5615 free_delayed_list (void *ptr
)
5617 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5618 if (cu
->method_list
!= NULL
)
5620 VEC_free (delayed_method_info
, cu
->method_list
);
5621 cu
->method_list
= NULL
;
5625 /* Compute the physnames of any methods on the CU's method list.
5627 The computation of method physnames is delayed in order to avoid the
5628 (bad) condition that one of the method's formal parameters is of an as yet
5632 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5635 struct delayed_method_info
*mi
;
5636 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5638 const char *physname
;
5639 struct fn_fieldlist
*fn_flp
5640 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5641 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5642 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5646 /* Go objects should be embedded in a DW_TAG_module DIE,
5647 and it's not clear if/how imported objects will appear.
5648 To keep Go support simple until that's worked out,
5649 go back through what we've read and create something usable.
5650 We could do this while processing each DIE, and feels kinda cleaner,
5651 but that way is more invasive.
5652 This is to, for example, allow the user to type "p var" or "b main"
5653 without having to specify the package name, and allow lookups
5654 of module.object to work in contexts that use the expression
5658 fixup_go_packaging (struct dwarf2_cu
*cu
)
5660 char *package_name
= NULL
;
5661 struct pending
*list
;
5664 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5666 for (i
= 0; i
< list
->nsyms
; ++i
)
5668 struct symbol
*sym
= list
->symbol
[i
];
5670 if (SYMBOL_LANGUAGE (sym
) == language_go
5671 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5673 char *this_package_name
= go_symbol_package_name (sym
);
5675 if (this_package_name
== NULL
)
5677 if (package_name
== NULL
)
5678 package_name
= this_package_name
;
5681 if (strcmp (package_name
, this_package_name
) != 0)
5682 complaint (&symfile_complaints
,
5683 _("Symtab %s has objects from two different Go packages: %s and %s"),
5684 (sym
->symtab
&& sym
->symtab
->filename
5685 ? sym
->symtab
->filename
5686 : cu
->objfile
->name
),
5687 this_package_name
, package_name
);
5688 xfree (this_package_name
);
5694 if (package_name
!= NULL
)
5696 struct objfile
*objfile
= cu
->objfile
;
5697 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5698 package_name
, objfile
);
5701 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5703 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5704 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5705 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5706 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5707 e.g., "main" finds the "main" module and not C's main(). */
5708 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5709 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5710 SYMBOL_TYPE (sym
) = type
;
5712 add_symbol_to_list (sym
, &global_symbols
);
5714 xfree (package_name
);
5718 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5720 /* Return the symtab for PER_CU. This works properly regardless of
5721 whether we're using the index or psymtabs. */
5723 static struct symtab
*
5724 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5726 return (dwarf2_per_objfile
->using_index
5727 ? per_cu
->v
.quick
->symtab
5728 : per_cu
->v
.psymtab
->symtab
);
5731 /* A helper function for computing the list of all symbol tables
5732 included by PER_CU. */
5735 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5736 htab_t all_children
,
5737 struct dwarf2_per_cu_data
*per_cu
)
5741 struct dwarf2_per_cu_data
*iter
;
5743 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5746 /* This inclusion and its children have been processed. */
5751 /* Only add a CU if it has a symbol table. */
5752 if (get_symtab (per_cu
) != NULL
)
5753 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5756 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5758 recursively_compute_inclusions (result
, all_children
, iter
);
5761 /* Compute the symtab 'includes' fields for the symtab related to
5765 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5767 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5770 struct dwarf2_per_cu_data
*iter
;
5771 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5772 htab_t all_children
;
5773 struct symtab
*symtab
= get_symtab (per_cu
);
5775 /* If we don't have a symtab, we can just skip this case. */
5779 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5780 NULL
, xcalloc
, xfree
);
5783 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5786 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5788 /* Now we have a transitive closure of all the included CUs, so
5789 we can convert it to a list of symtabs. */
5790 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5792 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5793 (len
+ 1) * sizeof (struct symtab
*));
5795 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5797 symtab
->includes
[ix
] = get_symtab (iter
);
5798 symtab
->includes
[len
] = NULL
;
5800 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5801 htab_delete (all_children
);
5805 /* Compute the 'includes' field for the symtabs of all the CUs we just
5809 process_cu_includes (void)
5812 struct dwarf2_per_cu_data
*iter
;
5815 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5818 compute_symtab_includes (iter
);
5820 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5823 /* Generate full symbol information for PER_CU, whose DIEs have
5824 already been loaded into memory. */
5827 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5828 enum language pretend_language
)
5830 struct dwarf2_cu
*cu
= per_cu
->cu
;
5831 struct objfile
*objfile
= per_cu
->objfile
;
5832 CORE_ADDR lowpc
, highpc
;
5833 struct symtab
*symtab
;
5834 struct cleanup
*back_to
, *delayed_list_cleanup
;
5837 if (dwarf2_read_debug
)
5839 fprintf_unfiltered (gdb_stdlog
,
5840 "Expanding symtab of %s at offset 0x%x\n",
5841 per_cu
->is_debug_types
? "TU" : "CU",
5842 per_cu
->offset
.sect_off
);
5845 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5848 back_to
= make_cleanup (really_free_pendings
, NULL
);
5849 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5851 cu
->list_in_scope
= &file_symbols
;
5853 cu
->language
= pretend_language
;
5854 cu
->language_defn
= language_def (cu
->language
);
5856 /* Do line number decoding in read_file_scope () */
5857 process_die (cu
->dies
, cu
);
5859 /* For now fudge the Go package. */
5860 if (cu
->language
== language_go
)
5861 fixup_go_packaging (cu
);
5863 /* Now that we have processed all the DIEs in the CU, all the types
5864 should be complete, and it should now be safe to compute all of the
5866 compute_delayed_physnames (cu
);
5867 do_cleanups (delayed_list_cleanup
);
5869 /* Some compilers don't define a DW_AT_high_pc attribute for the
5870 compilation unit. If the DW_AT_high_pc is missing, synthesize
5871 it, by scanning the DIE's below the compilation unit. */
5872 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5874 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5878 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5880 /* Set symtab language to language from DW_AT_language. If the
5881 compilation is from a C file generated by language preprocessors, do
5882 not set the language if it was already deduced by start_subfile. */
5883 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5884 symtab
->language
= cu
->language
;
5886 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5887 produce DW_AT_location with location lists but it can be possibly
5888 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5889 there were bugs in prologue debug info, fixed later in GCC-4.5
5890 by "unwind info for epilogues" patch (which is not directly related).
5892 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5893 needed, it would be wrong due to missing DW_AT_producer there.
5895 Still one can confuse GDB by using non-standard GCC compilation
5896 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5898 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5899 symtab
->locations_valid
= 1;
5901 if (gcc_4_minor
>= 5)
5902 symtab
->epilogue_unwind_valid
= 1;
5904 symtab
->call_site_htab
= cu
->call_site_htab
;
5907 if (dwarf2_per_objfile
->using_index
)
5908 per_cu
->v
.quick
->symtab
= symtab
;
5911 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5912 pst
->symtab
= symtab
;
5916 /* Push it for inclusion processing later. */
5917 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5919 do_cleanups (back_to
);
5921 if (dwarf2_read_debug
)
5923 fprintf_unfiltered (gdb_stdlog
,
5924 "Done expanding symtab of %s at offset 0x%x\n",
5925 per_cu
->is_debug_types
? "TU" : "CU",
5926 per_cu
->offset
.sect_off
);
5930 /* Process an imported unit DIE. */
5933 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5935 struct attribute
*attr
;
5937 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5940 struct dwarf2_per_cu_data
*per_cu
;
5941 struct symtab
*imported_symtab
;
5944 offset
= dwarf2_get_ref_die_offset (attr
);
5945 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5947 /* Queue the unit, if needed. */
5948 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5949 load_full_comp_unit (per_cu
, cu
->language
);
5951 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5956 /* Process a die and its children. */
5959 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5963 case DW_TAG_padding
:
5965 case DW_TAG_compile_unit
:
5966 case DW_TAG_partial_unit
:
5967 read_file_scope (die
, cu
);
5969 case DW_TAG_type_unit
:
5970 read_type_unit_scope (die
, cu
);
5972 case DW_TAG_subprogram
:
5973 case DW_TAG_inlined_subroutine
:
5974 read_func_scope (die
, cu
);
5976 case DW_TAG_lexical_block
:
5977 case DW_TAG_try_block
:
5978 case DW_TAG_catch_block
:
5979 read_lexical_block_scope (die
, cu
);
5981 case DW_TAG_GNU_call_site
:
5982 read_call_site_scope (die
, cu
);
5984 case DW_TAG_class_type
:
5985 case DW_TAG_interface_type
:
5986 case DW_TAG_structure_type
:
5987 case DW_TAG_union_type
:
5988 process_structure_scope (die
, cu
);
5990 case DW_TAG_enumeration_type
:
5991 process_enumeration_scope (die
, cu
);
5994 /* These dies have a type, but processing them does not create
5995 a symbol or recurse to process the children. Therefore we can
5996 read them on-demand through read_type_die. */
5997 case DW_TAG_subroutine_type
:
5998 case DW_TAG_set_type
:
5999 case DW_TAG_array_type
:
6000 case DW_TAG_pointer_type
:
6001 case DW_TAG_ptr_to_member_type
:
6002 case DW_TAG_reference_type
:
6003 case DW_TAG_string_type
:
6006 case DW_TAG_base_type
:
6007 case DW_TAG_subrange_type
:
6008 case DW_TAG_typedef
:
6009 /* Add a typedef symbol for the type definition, if it has a
6011 new_symbol (die
, read_type_die (die
, cu
), cu
);
6013 case DW_TAG_common_block
:
6014 read_common_block (die
, cu
);
6016 case DW_TAG_common_inclusion
:
6018 case DW_TAG_namespace
:
6019 processing_has_namespace_info
= 1;
6020 read_namespace (die
, cu
);
6023 processing_has_namespace_info
= 1;
6024 read_module (die
, cu
);
6026 case DW_TAG_imported_declaration
:
6027 case DW_TAG_imported_module
:
6028 processing_has_namespace_info
= 1;
6029 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6030 || cu
->language
!= language_fortran
))
6031 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6032 dwarf_tag_name (die
->tag
));
6033 read_import_statement (die
, cu
);
6036 case DW_TAG_imported_unit
:
6037 process_imported_unit_die (die
, cu
);
6041 new_symbol (die
, NULL
, cu
);
6046 /* A helper function for dwarf2_compute_name which determines whether DIE
6047 needs to have the name of the scope prepended to the name listed in the
6051 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6053 struct attribute
*attr
;
6057 case DW_TAG_namespace
:
6058 case DW_TAG_typedef
:
6059 case DW_TAG_class_type
:
6060 case DW_TAG_interface_type
:
6061 case DW_TAG_structure_type
:
6062 case DW_TAG_union_type
:
6063 case DW_TAG_enumeration_type
:
6064 case DW_TAG_enumerator
:
6065 case DW_TAG_subprogram
:
6069 case DW_TAG_variable
:
6070 case DW_TAG_constant
:
6071 /* We only need to prefix "globally" visible variables. These include
6072 any variable marked with DW_AT_external or any variable that
6073 lives in a namespace. [Variables in anonymous namespaces
6074 require prefixing, but they are not DW_AT_external.] */
6076 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6078 struct dwarf2_cu
*spec_cu
= cu
;
6080 return die_needs_namespace (die_specification (die
, &spec_cu
),
6084 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6085 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6086 && die
->parent
->tag
!= DW_TAG_module
)
6088 /* A variable in a lexical block of some kind does not need a
6089 namespace, even though in C++ such variables may be external
6090 and have a mangled name. */
6091 if (die
->parent
->tag
== DW_TAG_lexical_block
6092 || die
->parent
->tag
== DW_TAG_try_block
6093 || die
->parent
->tag
== DW_TAG_catch_block
6094 || die
->parent
->tag
== DW_TAG_subprogram
)
6103 /* Retrieve the last character from a mem_file. */
6106 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6108 char *last_char_p
= (char *) object
;
6111 *last_char_p
= buffer
[length
- 1];
6114 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6115 compute the physname for the object, which include a method's:
6116 - formal parameters (C++/Java),
6117 - receiver type (Go),
6118 - return type (Java).
6120 The term "physname" is a bit confusing.
6121 For C++, for example, it is the demangled name.
6122 For Go, for example, it's the mangled name.
6124 For Ada, return the DIE's linkage name rather than the fully qualified
6125 name. PHYSNAME is ignored..
6127 The result is allocated on the objfile_obstack and canonicalized. */
6130 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6133 struct objfile
*objfile
= cu
->objfile
;
6136 name
= dwarf2_name (die
, cu
);
6138 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6139 compute it by typename_concat inside GDB. */
6140 if (cu
->language
== language_ada
6141 || (cu
->language
== language_fortran
&& physname
))
6143 /* For Ada unit, we prefer the linkage name over the name, as
6144 the former contains the exported name, which the user expects
6145 to be able to reference. Ideally, we want the user to be able
6146 to reference this entity using either natural or linkage name,
6147 but we haven't started looking at this enhancement yet. */
6148 struct attribute
*attr
;
6150 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6152 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6153 if (attr
&& DW_STRING (attr
))
6154 return DW_STRING (attr
);
6157 /* These are the only languages we know how to qualify names in. */
6159 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6160 || cu
->language
== language_fortran
))
6162 if (die_needs_namespace (die
, cu
))
6166 struct ui_file
*buf
;
6168 prefix
= determine_prefix (die
, cu
);
6169 buf
= mem_fileopen ();
6170 if (*prefix
!= '\0')
6172 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
6175 fputs_unfiltered (prefixed_name
, buf
);
6176 xfree (prefixed_name
);
6179 fputs_unfiltered (name
, buf
);
6181 /* Template parameters may be specified in the DIE's DW_AT_name, or
6182 as children with DW_TAG_template_type_param or
6183 DW_TAG_value_type_param. If the latter, add them to the name
6184 here. If the name already has template parameters, then
6185 skip this step; some versions of GCC emit both, and
6186 it is more efficient to use the pre-computed name.
6188 Something to keep in mind about this process: it is very
6189 unlikely, or in some cases downright impossible, to produce
6190 something that will match the mangled name of a function.
6191 If the definition of the function has the same debug info,
6192 we should be able to match up with it anyway. But fallbacks
6193 using the minimal symbol, for instance to find a method
6194 implemented in a stripped copy of libstdc++, will not work.
6195 If we do not have debug info for the definition, we will have to
6196 match them up some other way.
6198 When we do name matching there is a related problem with function
6199 templates; two instantiated function templates are allowed to
6200 differ only by their return types, which we do not add here. */
6202 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6204 struct attribute
*attr
;
6205 struct die_info
*child
;
6208 die
->building_fullname
= 1;
6210 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6215 struct dwarf2_locexpr_baton
*baton
;
6218 if (child
->tag
!= DW_TAG_template_type_param
6219 && child
->tag
!= DW_TAG_template_value_param
)
6224 fputs_unfiltered ("<", buf
);
6228 fputs_unfiltered (", ", buf
);
6230 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6233 complaint (&symfile_complaints
,
6234 _("template parameter missing DW_AT_type"));
6235 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6238 type
= die_type (child
, cu
);
6240 if (child
->tag
== DW_TAG_template_type_param
)
6242 c_print_type (type
, "", buf
, -1, 0);
6246 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6249 complaint (&symfile_complaints
,
6250 _("template parameter missing "
6251 "DW_AT_const_value"));
6252 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6256 dwarf2_const_value_attr (attr
, type
, name
,
6257 &cu
->comp_unit_obstack
, cu
,
6258 &value
, &bytes
, &baton
);
6260 if (TYPE_NOSIGN (type
))
6261 /* GDB prints characters as NUMBER 'CHAR'. If that's
6262 changed, this can use value_print instead. */
6263 c_printchar (value
, type
, buf
);
6266 struct value_print_options opts
;
6269 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6273 else if (bytes
!= NULL
)
6275 v
= allocate_value (type
);
6276 memcpy (value_contents_writeable (v
), bytes
,
6277 TYPE_LENGTH (type
));
6280 v
= value_from_longest (type
, value
);
6282 /* Specify decimal so that we do not depend on
6284 get_formatted_print_options (&opts
, 'd');
6286 value_print (v
, buf
, &opts
);
6292 die
->building_fullname
= 0;
6296 /* Close the argument list, with a space if necessary
6297 (nested templates). */
6298 char last_char
= '\0';
6299 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6300 if (last_char
== '>')
6301 fputs_unfiltered (" >", buf
);
6303 fputs_unfiltered (">", buf
);
6307 /* For Java and C++ methods, append formal parameter type
6308 information, if PHYSNAME. */
6310 if (physname
&& die
->tag
== DW_TAG_subprogram
6311 && (cu
->language
== language_cplus
6312 || cu
->language
== language_java
))
6314 struct type
*type
= read_type_die (die
, cu
);
6316 c_type_print_args (type
, buf
, 1, cu
->language
);
6318 if (cu
->language
== language_java
)
6320 /* For java, we must append the return type to method
6322 if (die
->tag
== DW_TAG_subprogram
)
6323 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6326 else if (cu
->language
== language_cplus
)
6328 /* Assume that an artificial first parameter is
6329 "this", but do not crash if it is not. RealView
6330 marks unnamed (and thus unused) parameters as
6331 artificial; there is no way to differentiate
6333 if (TYPE_NFIELDS (type
) > 0
6334 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6335 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6336 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6338 fputs_unfiltered (" const", buf
);
6342 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6344 ui_file_delete (buf
);
6346 if (cu
->language
== language_cplus
)
6349 = dwarf2_canonicalize_name (name
, cu
,
6350 &objfile
->objfile_obstack
);
6361 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6362 If scope qualifiers are appropriate they will be added. The result
6363 will be allocated on the objfile_obstack, or NULL if the DIE does
6364 not have a name. NAME may either be from a previous call to
6365 dwarf2_name or NULL.
6367 The output string will be canonicalized (if C++/Java). */
6370 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6372 return dwarf2_compute_name (name
, die
, cu
, 0);
6375 /* Construct a physname for the given DIE in CU. NAME may either be
6376 from a previous call to dwarf2_name or NULL. The result will be
6377 allocated on the objfile_objstack or NULL if the DIE does not have a
6380 The output string will be canonicalized (if C++/Java). */
6383 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6385 struct objfile
*objfile
= cu
->objfile
;
6386 struct attribute
*attr
;
6387 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6388 struct cleanup
*back_to
;
6391 /* In this case dwarf2_compute_name is just a shortcut not building anything
6393 if (!die_needs_namespace (die
, cu
))
6394 return dwarf2_compute_name (name
, die
, cu
, 1);
6396 back_to
= make_cleanup (null_cleanup
, NULL
);
6398 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6400 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6402 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6404 if (attr
&& DW_STRING (attr
))
6408 mangled
= DW_STRING (attr
);
6410 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6411 type. It is easier for GDB users to search for such functions as
6412 `name(params)' than `long name(params)'. In such case the minimal
6413 symbol names do not match the full symbol names but for template
6414 functions there is never a need to look up their definition from their
6415 declaration so the only disadvantage remains the minimal symbol
6416 variant `long name(params)' does not have the proper inferior type.
6419 if (cu
->language
== language_go
)
6421 /* This is a lie, but we already lie to the caller new_symbol_full.
6422 new_symbol_full assumes we return the mangled name.
6423 This just undoes that lie until things are cleaned up. */
6428 demangled
= cplus_demangle (mangled
,
6429 (DMGL_PARAMS
| DMGL_ANSI
6430 | (cu
->language
== language_java
6431 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6436 make_cleanup (xfree
, demangled
);
6446 if (canon
== NULL
|| check_physname
)
6448 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6450 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6452 /* It may not mean a bug in GDB. The compiler could also
6453 compute DW_AT_linkage_name incorrectly. But in such case
6454 GDB would need to be bug-to-bug compatible. */
6456 complaint (&symfile_complaints
,
6457 _("Computed physname <%s> does not match demangled <%s> "
6458 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6459 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6461 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6462 is available here - over computed PHYSNAME. It is safer
6463 against both buggy GDB and buggy compilers. */
6477 retval
= obsavestring (retval
, strlen (retval
),
6478 &objfile
->objfile_obstack
);
6480 do_cleanups (back_to
);
6484 /* Read the import statement specified by the given die and record it. */
6487 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6489 struct objfile
*objfile
= cu
->objfile
;
6490 struct attribute
*import_attr
;
6491 struct die_info
*imported_die
, *child_die
;
6492 struct dwarf2_cu
*imported_cu
;
6493 const char *imported_name
;
6494 const char *imported_name_prefix
;
6495 const char *canonical_name
;
6496 const char *import_alias
;
6497 const char *imported_declaration
= NULL
;
6498 const char *import_prefix
;
6499 VEC (const_char_ptr
) *excludes
= NULL
;
6500 struct cleanup
*cleanups
;
6504 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6505 if (import_attr
== NULL
)
6507 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6508 dwarf_tag_name (die
->tag
));
6513 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6514 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6515 if (imported_name
== NULL
)
6517 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6519 The import in the following code:
6533 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6534 <52> DW_AT_decl_file : 1
6535 <53> DW_AT_decl_line : 6
6536 <54> DW_AT_import : <0x75>
6537 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6539 <5b> DW_AT_decl_file : 1
6540 <5c> DW_AT_decl_line : 2
6541 <5d> DW_AT_type : <0x6e>
6543 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6544 <76> DW_AT_byte_size : 4
6545 <77> DW_AT_encoding : 5 (signed)
6547 imports the wrong die ( 0x75 instead of 0x58 ).
6548 This case will be ignored until the gcc bug is fixed. */
6552 /* Figure out the local name after import. */
6553 import_alias
= dwarf2_name (die
, cu
);
6555 /* Figure out where the statement is being imported to. */
6556 import_prefix
= determine_prefix (die
, cu
);
6558 /* Figure out what the scope of the imported die is and prepend it
6559 to the name of the imported die. */
6560 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6562 if (imported_die
->tag
!= DW_TAG_namespace
6563 && imported_die
->tag
!= DW_TAG_module
)
6565 imported_declaration
= imported_name
;
6566 canonical_name
= imported_name_prefix
;
6568 else if (strlen (imported_name_prefix
) > 0)
6570 temp
= alloca (strlen (imported_name_prefix
)
6571 + 2 + strlen (imported_name
) + 1);
6572 strcpy (temp
, imported_name_prefix
);
6573 strcat (temp
, "::");
6574 strcat (temp
, imported_name
);
6575 canonical_name
= temp
;
6578 canonical_name
= imported_name
;
6580 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6582 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6583 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6584 child_die
= sibling_die (child_die
))
6586 /* DWARF-4: A Fortran use statement with a “rename list” may be
6587 represented by an imported module entry with an import attribute
6588 referring to the module and owned entries corresponding to those
6589 entities that are renamed as part of being imported. */
6591 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6593 complaint (&symfile_complaints
,
6594 _("child DW_TAG_imported_declaration expected "
6595 "- DIE at 0x%x [in module %s]"),
6596 child_die
->offset
.sect_off
, objfile
->name
);
6600 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6601 if (import_attr
== NULL
)
6603 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6604 dwarf_tag_name (child_die
->tag
));
6609 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6611 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6612 if (imported_name
== NULL
)
6614 complaint (&symfile_complaints
,
6615 _("child DW_TAG_imported_declaration has unknown "
6616 "imported name - DIE at 0x%x [in module %s]"),
6617 child_die
->offset
.sect_off
, objfile
->name
);
6621 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6623 process_die (child_die
, cu
);
6626 cp_add_using_directive (import_prefix
,
6629 imported_declaration
,
6631 &objfile
->objfile_obstack
);
6633 do_cleanups (cleanups
);
6636 /* Cleanup function for read_file_scope. */
6639 free_cu_line_header (void *arg
)
6641 struct dwarf2_cu
*cu
= arg
;
6643 free_line_header (cu
->line_header
);
6644 cu
->line_header
= NULL
;
6648 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6649 char **name
, char **comp_dir
)
6651 struct attribute
*attr
;
6656 /* Find the filename. Do not use dwarf2_name here, since the filename
6657 is not a source language identifier. */
6658 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6661 *name
= DW_STRING (attr
);
6664 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6666 *comp_dir
= DW_STRING (attr
);
6667 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6669 *comp_dir
= ldirname (*name
);
6670 if (*comp_dir
!= NULL
)
6671 make_cleanup (xfree
, *comp_dir
);
6673 if (*comp_dir
!= NULL
)
6675 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6676 directory, get rid of it. */
6677 char *cp
= strchr (*comp_dir
, ':');
6679 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6684 *name
= "<unknown>";
6687 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6688 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6689 COMP_DIR is the compilation directory.
6690 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6693 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6694 const char *comp_dir
, int want_line_info
)
6696 struct attribute
*attr
;
6698 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6701 unsigned int line_offset
= DW_UNSND (attr
);
6702 struct line_header
*line_header
6703 = dwarf_decode_line_header (line_offset
, cu
);
6707 cu
->line_header
= line_header
;
6708 make_cleanup (free_cu_line_header
, cu
);
6709 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6714 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6717 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6719 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6720 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6721 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6722 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6723 struct attribute
*attr
;
6725 char *comp_dir
= NULL
;
6726 struct die_info
*child_die
;
6727 bfd
*abfd
= objfile
->obfd
;
6730 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6732 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6734 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6735 from finish_block. */
6736 if (lowpc
== ((CORE_ADDR
) -1))
6741 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6743 prepare_one_comp_unit (cu
, die
, cu
->language
);
6745 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6746 standardised yet. As a workaround for the language detection we fall
6747 back to the DW_AT_producer string. */
6748 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6749 cu
->language
= language_opencl
;
6751 /* Similar hack for Go. */
6752 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6753 set_cu_language (DW_LANG_Go
, cu
);
6755 /* We assume that we're processing GCC output. */
6756 processing_gcc_compilation
= 2;
6758 processing_has_namespace_info
= 0;
6760 start_symtab (name
, comp_dir
, lowpc
);
6761 record_debugformat ("DWARF 2");
6762 record_producer (cu
->producer
);
6764 /* Decode line number information if present. We do this before
6765 processing child DIEs, so that the line header table is available
6766 for DW_AT_decl_file. */
6767 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6769 /* Process all dies in compilation unit. */
6770 if (die
->child
!= NULL
)
6772 child_die
= die
->child
;
6773 while (child_die
&& child_die
->tag
)
6775 process_die (child_die
, cu
);
6776 child_die
= sibling_die (child_die
);
6780 /* Decode macro information, if present. Dwarf 2 macro information
6781 refers to information in the line number info statement program
6782 header, so we can only read it if we've read the header
6784 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6785 if (attr
&& cu
->line_header
)
6787 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6788 complaint (&symfile_complaints
,
6789 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6791 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
6795 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6796 if (attr
&& cu
->line_header
)
6798 unsigned int macro_offset
= DW_UNSND (attr
);
6800 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
6804 do_cleanups (back_to
);
6807 /* Process DW_TAG_type_unit.
6808 For TUs we want to skip the first top level sibling if it's not the
6809 actual type being defined by this TU. In this case the first top
6810 level sibling is there to provide context only. */
6813 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6815 struct objfile
*objfile
= cu
->objfile
;
6816 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6818 struct attribute
*attr
;
6820 char *comp_dir
= NULL
;
6821 struct die_info
*child_die
;
6822 bfd
*abfd
= objfile
->obfd
;
6824 /* start_symtab needs a low pc, but we don't really have one.
6825 Do what read_file_scope would do in the absence of such info. */
6826 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6828 /* Find the filename. Do not use dwarf2_name here, since the filename
6829 is not a source language identifier. */
6830 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6832 name
= DW_STRING (attr
);
6834 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6836 comp_dir
= DW_STRING (attr
);
6837 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6839 comp_dir
= ldirname (name
);
6840 if (comp_dir
!= NULL
)
6841 make_cleanup (xfree
, comp_dir
);
6847 prepare_one_comp_unit (cu
, die
, language_minimal
);
6849 /* We assume that we're processing GCC output. */
6850 processing_gcc_compilation
= 2;
6852 processing_has_namespace_info
= 0;
6854 start_symtab (name
, comp_dir
, lowpc
);
6855 record_debugformat ("DWARF 2");
6856 record_producer (cu
->producer
);
6858 /* Decode line number information if present. We do this before
6859 processing child DIEs, so that the line header table is available
6860 for DW_AT_decl_file.
6861 We don't need the pc/line-number mapping for type units. */
6862 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6864 /* Process the dies in the type unit. */
6865 if (die
->child
== NULL
)
6867 dump_die_for_error (die
);
6868 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6869 bfd_get_filename (abfd
));
6872 child_die
= die
->child
;
6874 while (child_die
&& child_die
->tag
)
6876 process_die (child_die
, cu
);
6878 child_die
= sibling_die (child_die
);
6881 do_cleanups (back_to
);
6887 hash_dwo_file (const void *item
)
6889 const struct dwo_file
*dwo_file
= item
;
6891 return htab_hash_string (dwo_file
->dwo_name
);
6895 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6897 const struct dwo_file
*lhs
= item_lhs
;
6898 const struct dwo_file
*rhs
= item_rhs
;
6900 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6903 /* Allocate a hash table for DWO files. */
6906 allocate_dwo_file_hash_table (void)
6908 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6910 return htab_create_alloc_ex (41,
6914 &objfile
->objfile_obstack
,
6915 hashtab_obstack_allocate
,
6916 dummy_obstack_deallocate
);
6920 hash_dwo_unit (const void *item
)
6922 const struct dwo_unit
*dwo_unit
= item
;
6924 /* This drops the top 32 bits of the id, but is ok for a hash. */
6925 return dwo_unit
->signature
;
6929 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6931 const struct dwo_unit
*lhs
= item_lhs
;
6932 const struct dwo_unit
*rhs
= item_rhs
;
6934 /* The signature is assumed to be unique within the DWO file.
6935 So while object file CU dwo_id's always have the value zero,
6936 that's OK, assuming each object file DWO file has only one CU,
6937 and that's the rule for now. */
6938 return lhs
->signature
== rhs
->signature
;
6941 /* Allocate a hash table for DWO CUs,TUs.
6942 There is one of these tables for each of CUs,TUs for each DWO file. */
6945 allocate_dwo_unit_table (struct objfile
*objfile
)
6947 /* Start out with a pretty small number.
6948 Generally DWO files contain only one CU and maybe some TUs. */
6949 return htab_create_alloc_ex (3,
6953 &objfile
->objfile_obstack
,
6954 hashtab_obstack_allocate
,
6955 dummy_obstack_deallocate
);
6958 /* This function is mapped across the sections and remembers the offset and
6959 size of each of the DWO debugging sections we are interested in. */
6962 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6964 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6965 const struct dwo_section_names
*names
= &dwo_section_names
;
6967 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6969 dwo_file
->sections
.abbrev
.asection
= sectp
;
6970 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6972 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6974 dwo_file
->sections
.info
.asection
= sectp
;
6975 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6977 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6979 dwo_file
->sections
.line
.asection
= sectp
;
6980 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6982 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6984 dwo_file
->sections
.loc
.asection
= sectp
;
6985 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6987 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
6989 dwo_file
->sections
.macinfo
.asection
= sectp
;
6990 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
6992 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
6994 dwo_file
->sections
.macro
.asection
= sectp
;
6995 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
6997 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6999 dwo_file
->sections
.str
.asection
= sectp
;
7000 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7002 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7004 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7005 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7007 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7009 struct dwarf2_section_info type_section
;
7011 memset (&type_section
, 0, sizeof (type_section
));
7012 type_section
.asection
= sectp
;
7013 type_section
.size
= bfd_get_section_size (sectp
);
7014 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7019 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7021 struct create_dwo_info_table_data
7023 struct dwo_file
*dwo_file
;
7027 /* die_reader_func for create_debug_info_hash_table. */
7030 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7032 struct die_info
*comp_unit_die
,
7036 struct dwarf2_cu
*cu
= reader
->cu
;
7037 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7038 sect_offset offset
= cu
->per_cu
->offset
;
7039 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7040 struct create_dwo_info_table_data
*data
= datap
;
7041 struct dwo_file
*dwo_file
= data
->dwo_file
;
7042 htab_t cu_htab
= data
->cu_htab
;
7044 struct attribute
*attr
;
7045 struct dwo_unit
*dwo_unit
;
7047 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7050 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
7051 " its dwo_id [in module %s]"),
7052 offset
.sect_off
, dwo_file
->dwo_name
);
7056 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
7057 dwo_unit
->dwo_file
= dwo_file
;
7058 dwo_unit
->signature
= DW_UNSND (attr
);
7059 dwo_unit
->info_or_types_section
= section
;
7060 dwo_unit
->offset
= offset
;
7061 dwo_unit
->length
= cu
->per_cu
->length
;
7063 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7064 gdb_assert (slot
!= NULL
);
7067 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7069 complaint (&symfile_complaints
,
7070 _("debug entry at offset 0x%x is duplicate to the entry at"
7071 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7072 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7073 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7074 dwo_file
->dwo_name
);
7079 if (dwarf2_die_debug
)
7080 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7082 phex (dwo_unit
->signature
,
7083 sizeof (dwo_unit
->signature
)));
7086 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7089 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7091 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7092 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7095 gdb_byte
*info_ptr
, *end_ptr
;
7096 struct create_dwo_info_table_data create_dwo_info_table_data
;
7098 dwarf2_read_section (objfile
, section
);
7099 info_ptr
= section
->buffer
;
7101 if (info_ptr
== NULL
)
7104 /* We can't set abfd until now because the section may be empty or
7105 not present, in which case section->asection will be NULL. */
7106 abfd
= section
->asection
->owner
;
7108 if (dwarf2_die_debug
)
7109 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
7110 bfd_get_filename (abfd
));
7112 cu_htab
= allocate_dwo_unit_table (objfile
);
7114 create_dwo_info_table_data
.dwo_file
= dwo_file
;
7115 create_dwo_info_table_data
.cu_htab
= cu_htab
;
7117 end_ptr
= info_ptr
+ section
->size
;
7118 while (info_ptr
< end_ptr
)
7120 struct dwarf2_per_cu_data per_cu
;
7122 memset (&per_cu
, 0, sizeof (per_cu
));
7123 per_cu
.objfile
= objfile
;
7124 per_cu
.is_debug_types
= 0;
7125 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
7126 per_cu
.info_or_types_section
= section
;
7128 init_cutu_and_read_dies_no_follow (&per_cu
,
7129 &dwo_file
->sections
.abbrev
,
7131 create_debug_info_hash_table_reader
,
7132 &create_dwo_info_table_data
);
7134 info_ptr
+= per_cu
.length
;
7140 /* Subroutine of open_dwo_file to simplify it.
7141 Open the file specified by FILE_NAME and hand it off to BFD for
7142 preliminary analysis. Return a newly initialized bfd *, which
7143 includes a canonicalized copy of FILE_NAME.
7144 In case of trouble, return NULL.
7145 NOTE: This function is derived from symfile_bfd_open. */
7148 try_open_dwo_file (const char *file_name
)
7152 char *absolute_name
;
7154 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
7155 O_RDONLY
| O_BINARY
, &absolute_name
);
7159 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
7162 xfree (absolute_name
);
7165 bfd_set_cacheable (sym_bfd
, 1);
7167 if (!bfd_check_format (sym_bfd
, bfd_object
))
7169 bfd_close (sym_bfd
); /* This also closes desc. */
7170 xfree (absolute_name
);
7174 /* bfd_usrdata exists for applications and libbfd must not touch it. */
7175 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
7180 /* Try to open DWO file DWO_NAME.
7181 COMP_DIR is the DW_AT_comp_dir attribute.
7182 The result is the bfd handle of the file.
7183 If there is a problem finding or opening the file, return NULL.
7184 Upon success, the canonicalized path of the file is stored in the bfd,
7185 same as symfile_bfd_open. */
7188 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
7192 if (IS_ABSOLUTE_PATH (dwo_name
))
7193 return try_open_dwo_file (dwo_name
);
7195 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
7197 if (comp_dir
!= NULL
)
7199 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
7201 /* NOTE: If comp_dir is a relative path, this will also try the
7202 search path, which seems useful. */
7203 abfd
= try_open_dwo_file (path_to_try
);
7204 xfree (path_to_try
);
7209 /* That didn't work, try debug-file-directory, which, despite its name,
7210 is a list of paths. */
7212 if (*debug_file_directory
== '\0')
7215 return try_open_dwo_file (dwo_name
);
7218 /* Initialize the use of the DWO file specified by DWO_NAME. */
7220 static struct dwo_file
*
7221 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7224 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7227 struct cleanup
*cleanups
;
7229 if (dwarf2_die_debug
)
7230 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7232 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7235 dwo_file
->dwo_name
= dwo_name
;
7236 dwo_file
->dwo_bfd
= abfd
;
7238 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7240 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7242 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7244 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7245 dwo_file
->sections
.types
);
7247 discard_cleanups (cleanups
);
7252 /* Lookup DWO file DWO_NAME. */
7254 static struct dwo_file
*
7255 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7257 struct dwo_file
*dwo_file
;
7258 struct dwo_file find_entry
;
7261 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7262 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7264 /* Have we already seen this DWO file? */
7265 find_entry
.dwo_name
= dwo_name
;
7266 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7268 /* If not, read it in and build a table of the DWOs it contains. */
7270 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7272 /* NOTE: This will be NULL if unable to open the file. */
7278 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7279 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7280 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7281 nomenclature as TUs).
7282 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7283 (dwo_id mismatch or couldn't find the DWO file). */
7285 static struct dwo_unit
*
7286 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7287 char *dwo_name
, const char *comp_dir
,
7290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7291 struct dwo_file
*dwo_file
;
7293 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7294 if (dwo_file
== NULL
)
7297 /* Look up the DWO using its signature(dwo_id). */
7299 if (dwo_file
->cus
!= NULL
)
7301 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7303 find_dwo_cu
.signature
= signature
;
7304 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7310 /* We didn't find it. This must mean a dwo_id mismatch. */
7312 complaint (&symfile_complaints
,
7313 _("Could not find DWO CU referenced by CU at offset 0x%x"
7315 this_cu
->offset
.sect_off
, objfile
->name
);
7319 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7320 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7321 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7322 (dwo_id mismatch or couldn't find the DWO file). */
7324 static struct dwo_unit
*
7325 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7326 char *dwo_name
, const char *comp_dir
)
7328 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7329 struct dwo_file
*dwo_file
;
7331 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7332 if (dwo_file
== NULL
)
7335 /* Look up the DWO using its signature(dwo_id). */
7337 if (dwo_file
->tus
!= NULL
)
7339 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7341 find_dwo_tu
.signature
= this_tu
->signature
;
7342 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7348 /* We didn't find it. This must mean a dwo_id mismatch. */
7350 complaint (&symfile_complaints
,
7351 _("Could not find DWO TU referenced by TU at offset 0x%x"
7353 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7357 /* Free all resources associated with DWO_FILE.
7358 Close the DWO file and munmap the sections.
7359 All memory should be on the objfile obstack. */
7362 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7365 struct dwarf2_section_info
*section
;
7367 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7368 bfd_close (dwo_file
->dwo_bfd
);
7370 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7371 munmap_section_buffer (&dwo_file
->sections
.info
);
7372 munmap_section_buffer (&dwo_file
->sections
.line
);
7373 munmap_section_buffer (&dwo_file
->sections
.loc
);
7374 munmap_section_buffer (&dwo_file
->sections
.str
);
7375 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7378 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7381 munmap_section_buffer (section
);
7383 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7386 /* Wrapper for free_dwo_file for use in cleanups. */
7389 free_dwo_file_cleanup (void *arg
)
7391 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7392 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7394 free_dwo_file (dwo_file
, objfile
);
7397 /* Traversal function for free_dwo_files. */
7400 free_dwo_file_from_slot (void **slot
, void *info
)
7402 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7403 struct objfile
*objfile
= (struct objfile
*) info
;
7405 free_dwo_file (dwo_file
, objfile
);
7410 /* Free all resources associated with DWO_FILES. */
7413 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7415 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7418 /* Read in various DIEs. */
7420 /* qsort helper for inherit_abstract_dies. */
7423 unsigned_int_compar (const void *ap
, const void *bp
)
7425 unsigned int a
= *(unsigned int *) ap
;
7426 unsigned int b
= *(unsigned int *) bp
;
7428 return (a
> b
) - (b
> a
);
7431 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7432 Inherit only the children of the DW_AT_abstract_origin DIE not being
7433 already referenced by DW_AT_abstract_origin from the children of the
7437 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7439 struct die_info
*child_die
;
7440 unsigned die_children_count
;
7441 /* CU offsets which were referenced by children of the current DIE. */
7442 sect_offset
*offsets
;
7443 sect_offset
*offsets_end
, *offsetp
;
7444 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7445 struct die_info
*origin_die
;
7446 /* Iterator of the ORIGIN_DIE children. */
7447 struct die_info
*origin_child_die
;
7448 struct cleanup
*cleanups
;
7449 struct attribute
*attr
;
7450 struct dwarf2_cu
*origin_cu
;
7451 struct pending
**origin_previous_list_in_scope
;
7453 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7457 /* Note that following die references may follow to a die in a
7461 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7463 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7465 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7466 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7468 if (die
->tag
!= origin_die
->tag
7469 && !(die
->tag
== DW_TAG_inlined_subroutine
7470 && origin_die
->tag
== DW_TAG_subprogram
))
7471 complaint (&symfile_complaints
,
7472 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7473 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7475 child_die
= die
->child
;
7476 die_children_count
= 0;
7477 while (child_die
&& child_die
->tag
)
7479 child_die
= sibling_die (child_die
);
7480 die_children_count
++;
7482 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7483 cleanups
= make_cleanup (xfree
, offsets
);
7485 offsets_end
= offsets
;
7486 child_die
= die
->child
;
7487 while (child_die
&& child_die
->tag
)
7489 /* For each CHILD_DIE, find the corresponding child of
7490 ORIGIN_DIE. If there is more than one layer of
7491 DW_AT_abstract_origin, follow them all; there shouldn't be,
7492 but GCC versions at least through 4.4 generate this (GCC PR
7494 struct die_info
*child_origin_die
= child_die
;
7495 struct dwarf2_cu
*child_origin_cu
= cu
;
7499 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7503 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7507 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7508 counterpart may exist. */
7509 if (child_origin_die
!= child_die
)
7511 if (child_die
->tag
!= child_origin_die
->tag
7512 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7513 && child_origin_die
->tag
== DW_TAG_subprogram
))
7514 complaint (&symfile_complaints
,
7515 _("Child DIE 0x%x and its abstract origin 0x%x have "
7516 "different tags"), child_die
->offset
.sect_off
,
7517 child_origin_die
->offset
.sect_off
);
7518 if (child_origin_die
->parent
!= origin_die
)
7519 complaint (&symfile_complaints
,
7520 _("Child DIE 0x%x and its abstract origin 0x%x have "
7521 "different parents"), child_die
->offset
.sect_off
,
7522 child_origin_die
->offset
.sect_off
);
7524 *offsets_end
++ = child_origin_die
->offset
;
7526 child_die
= sibling_die (child_die
);
7528 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7529 unsigned_int_compar
);
7530 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7531 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7532 complaint (&symfile_complaints
,
7533 _("Multiple children of DIE 0x%x refer "
7534 "to DIE 0x%x as their abstract origin"),
7535 die
->offset
.sect_off
, offsetp
->sect_off
);
7538 origin_child_die
= origin_die
->child
;
7539 while (origin_child_die
&& origin_child_die
->tag
)
7541 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7542 while (offsetp
< offsets_end
7543 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7545 if (offsetp
>= offsets_end
7546 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7548 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7549 process_die (origin_child_die
, origin_cu
);
7551 origin_child_die
= sibling_die (origin_child_die
);
7553 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7555 do_cleanups (cleanups
);
7559 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7561 struct objfile
*objfile
= cu
->objfile
;
7562 struct context_stack
*new;
7565 struct die_info
*child_die
;
7566 struct attribute
*attr
, *call_line
, *call_file
;
7569 struct block
*block
;
7570 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7571 VEC (symbolp
) *template_args
= NULL
;
7572 struct template_symbol
*templ_func
= NULL
;
7576 /* If we do not have call site information, we can't show the
7577 caller of this inlined function. That's too confusing, so
7578 only use the scope for local variables. */
7579 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7580 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7581 if (call_line
== NULL
|| call_file
== NULL
)
7583 read_lexical_block_scope (die
, cu
);
7588 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7590 name
= dwarf2_name (die
, cu
);
7592 /* Ignore functions with missing or empty names. These are actually
7593 illegal according to the DWARF standard. */
7596 complaint (&symfile_complaints
,
7597 _("missing name for subprogram DIE at %d"),
7598 die
->offset
.sect_off
);
7602 /* Ignore functions with missing or invalid low and high pc attributes. */
7603 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7605 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7606 if (!attr
|| !DW_UNSND (attr
))
7607 complaint (&symfile_complaints
,
7608 _("cannot get low and high bounds "
7609 "for subprogram DIE at %d"),
7610 die
->offset
.sect_off
);
7617 /* If we have any template arguments, then we must allocate a
7618 different sort of symbol. */
7619 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7621 if (child_die
->tag
== DW_TAG_template_type_param
7622 || child_die
->tag
== DW_TAG_template_value_param
)
7624 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7625 struct template_symbol
);
7626 templ_func
->base
.is_cplus_template_function
= 1;
7631 new = push_context (0, lowpc
);
7632 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7633 (struct symbol
*) templ_func
);
7635 /* If there is a location expression for DW_AT_frame_base, record
7637 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7639 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7640 expression is being recorded directly in the function's symbol
7641 and not in a separate frame-base object. I guess this hack is
7642 to avoid adding some sort of frame-base adjunct/annex to the
7643 function's symbol :-(. The problem with doing this is that it
7644 results in a function symbol with a location expression that
7645 has nothing to do with the location of the function, ouch! The
7646 relationship should be: a function's symbol has-a frame base; a
7647 frame-base has-a location expression. */
7648 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7650 cu
->list_in_scope
= &local_symbols
;
7652 if (die
->child
!= NULL
)
7654 child_die
= die
->child
;
7655 while (child_die
&& child_die
->tag
)
7657 if (child_die
->tag
== DW_TAG_template_type_param
7658 || child_die
->tag
== DW_TAG_template_value_param
)
7660 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7663 VEC_safe_push (symbolp
, template_args
, arg
);
7666 process_die (child_die
, cu
);
7667 child_die
= sibling_die (child_die
);
7671 inherit_abstract_dies (die
, cu
);
7673 /* If we have a DW_AT_specification, we might need to import using
7674 directives from the context of the specification DIE. See the
7675 comment in determine_prefix. */
7676 if (cu
->language
== language_cplus
7677 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7679 struct dwarf2_cu
*spec_cu
= cu
;
7680 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7684 child_die
= spec_die
->child
;
7685 while (child_die
&& child_die
->tag
)
7687 if (child_die
->tag
== DW_TAG_imported_module
)
7688 process_die (child_die
, spec_cu
);
7689 child_die
= sibling_die (child_die
);
7692 /* In some cases, GCC generates specification DIEs that
7693 themselves contain DW_AT_specification attributes. */
7694 spec_die
= die_specification (spec_die
, &spec_cu
);
7698 new = pop_context ();
7699 /* Make a block for the local symbols within. */
7700 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7701 lowpc
, highpc
, objfile
);
7703 /* For C++, set the block's scope. */
7704 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7705 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7706 determine_prefix (die
, cu
),
7707 processing_has_namespace_info
);
7709 /* If we have address ranges, record them. */
7710 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7712 /* Attach template arguments to function. */
7713 if (! VEC_empty (symbolp
, template_args
))
7715 gdb_assert (templ_func
!= NULL
);
7717 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7718 templ_func
->template_arguments
7719 = obstack_alloc (&objfile
->objfile_obstack
,
7720 (templ_func
->n_template_arguments
7721 * sizeof (struct symbol
*)));
7722 memcpy (templ_func
->template_arguments
,
7723 VEC_address (symbolp
, template_args
),
7724 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7725 VEC_free (symbolp
, template_args
);
7728 /* In C++, we can have functions nested inside functions (e.g., when
7729 a function declares a class that has methods). This means that
7730 when we finish processing a function scope, we may need to go
7731 back to building a containing block's symbol lists. */
7732 local_symbols
= new->locals
;
7733 param_symbols
= new->params
;
7734 using_directives
= new->using_directives
;
7736 /* If we've finished processing a top-level function, subsequent
7737 symbols go in the file symbol list. */
7738 if (outermost_context_p ())
7739 cu
->list_in_scope
= &file_symbols
;
7742 /* Process all the DIES contained within a lexical block scope. Start
7743 a new scope, process the dies, and then close the scope. */
7746 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7748 struct objfile
*objfile
= cu
->objfile
;
7749 struct context_stack
*new;
7750 CORE_ADDR lowpc
, highpc
;
7751 struct die_info
*child_die
;
7754 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7756 /* Ignore blocks with missing or invalid low and high pc attributes. */
7757 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7758 as multiple lexical blocks? Handling children in a sane way would
7759 be nasty. Might be easier to properly extend generic blocks to
7761 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7766 push_context (0, lowpc
);
7767 if (die
->child
!= NULL
)
7769 child_die
= die
->child
;
7770 while (child_die
&& child_die
->tag
)
7772 process_die (child_die
, cu
);
7773 child_die
= sibling_die (child_die
);
7776 new = pop_context ();
7778 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7781 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7784 /* Note that recording ranges after traversing children, as we
7785 do here, means that recording a parent's ranges entails
7786 walking across all its children's ranges as they appear in
7787 the address map, which is quadratic behavior.
7789 It would be nicer to record the parent's ranges before
7790 traversing its children, simply overriding whatever you find
7791 there. But since we don't even decide whether to create a
7792 block until after we've traversed its children, that's hard
7794 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7796 local_symbols
= new->locals
;
7797 using_directives
= new->using_directives
;
7800 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7803 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7805 struct objfile
*objfile
= cu
->objfile
;
7806 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7807 CORE_ADDR pc
, baseaddr
;
7808 struct attribute
*attr
;
7809 struct call_site
*call_site
, call_site_local
;
7812 struct die_info
*child_die
;
7814 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7816 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7819 complaint (&symfile_complaints
,
7820 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7821 "DIE 0x%x [in module %s]"),
7822 die
->offset
.sect_off
, objfile
->name
);
7825 pc
= DW_ADDR (attr
) + baseaddr
;
7827 if (cu
->call_site_htab
== NULL
)
7828 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7829 NULL
, &objfile
->objfile_obstack
,
7830 hashtab_obstack_allocate
, NULL
);
7831 call_site_local
.pc
= pc
;
7832 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7835 complaint (&symfile_complaints
,
7836 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7837 "DIE 0x%x [in module %s]"),
7838 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7842 /* Count parameters at the caller. */
7845 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7846 child_die
= sibling_die (child_die
))
7848 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7850 complaint (&symfile_complaints
,
7851 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7852 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7853 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7860 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7861 (sizeof (*call_site
)
7862 + (sizeof (*call_site
->parameter
)
7865 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7868 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7870 struct die_info
*func_die
;
7872 /* Skip also over DW_TAG_inlined_subroutine. */
7873 for (func_die
= die
->parent
;
7874 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7875 && func_die
->tag
!= DW_TAG_subroutine_type
;
7876 func_die
= func_die
->parent
);
7878 /* DW_AT_GNU_all_call_sites is a superset
7879 of DW_AT_GNU_all_tail_call_sites. */
7881 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7882 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7884 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7885 not complete. But keep CALL_SITE for look ups via call_site_htab,
7886 both the initial caller containing the real return address PC and
7887 the final callee containing the current PC of a chain of tail
7888 calls do not need to have the tail call list complete. But any
7889 function candidate for a virtual tail call frame searched via
7890 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7891 determined unambiguously. */
7895 struct type
*func_type
= NULL
;
7898 func_type
= get_die_type (func_die
, cu
);
7899 if (func_type
!= NULL
)
7901 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7903 /* Enlist this call site to the function. */
7904 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7905 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7908 complaint (&symfile_complaints
,
7909 _("Cannot find function owning DW_TAG_GNU_call_site "
7910 "DIE 0x%x [in module %s]"),
7911 die
->offset
.sect_off
, objfile
->name
);
7915 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7917 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7918 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7919 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7920 /* Keep NULL DWARF_BLOCK. */;
7921 else if (attr_form_is_block (attr
))
7923 struct dwarf2_locexpr_baton
*dlbaton
;
7925 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7926 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7927 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7928 dlbaton
->per_cu
= cu
->per_cu
;
7930 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7932 else if (is_ref_attr (attr
))
7934 struct dwarf2_cu
*target_cu
= cu
;
7935 struct die_info
*target_die
;
7937 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7938 gdb_assert (target_cu
->objfile
== objfile
);
7939 if (die_is_declaration (target_die
, target_cu
))
7941 const char *target_physname
;
7943 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7944 if (target_physname
== NULL
)
7945 complaint (&symfile_complaints
,
7946 _("DW_AT_GNU_call_site_target target DIE has invalid "
7947 "physname, for referencing DIE 0x%x [in module %s]"),
7948 die
->offset
.sect_off
, objfile
->name
);
7950 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7956 /* DW_AT_entry_pc should be preferred. */
7957 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7958 complaint (&symfile_complaints
,
7959 _("DW_AT_GNU_call_site_target target DIE has invalid "
7960 "low pc, for referencing DIE 0x%x [in module %s]"),
7961 die
->offset
.sect_off
, objfile
->name
);
7963 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7967 complaint (&symfile_complaints
,
7968 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7969 "block nor reference, for DIE 0x%x [in module %s]"),
7970 die
->offset
.sect_off
, objfile
->name
);
7972 call_site
->per_cu
= cu
->per_cu
;
7974 for (child_die
= die
->child
;
7975 child_die
&& child_die
->tag
;
7976 child_die
= sibling_die (child_die
))
7978 struct call_site_parameter
*parameter
;
7979 struct attribute
*loc
, *origin
;
7981 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7983 /* Already printed the complaint above. */
7987 gdb_assert (call_site
->parameter_count
< nparams
);
7988 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7990 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
7991 specifies DW_TAG_formal_parameter. Value of the data assumed for the
7992 register is contained in DW_AT_GNU_call_site_value. */
7994 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7995 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
7996 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8000 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8001 offset
= dwarf2_get_ref_die_offset (origin
);
8002 gdb_assert (offset
.sect_off
>= cu
->header
.offset
.sect_off
);
8003 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8004 - cu
->header
.offset
.sect_off
);
8006 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8008 complaint (&symfile_complaints
,
8009 _("No DW_FORM_block* DW_AT_location for "
8010 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8011 child_die
->offset
.sect_off
, objfile
->name
);
8016 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8017 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8018 if (parameter
->u
.dwarf_reg
!= -1)
8019 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8020 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8021 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8022 ¶meter
->u
.fb_offset
))
8023 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8026 complaint (&symfile_complaints
,
8027 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8028 "for DW_FORM_block* DW_AT_location is supported for "
8029 "DW_TAG_GNU_call_site child DIE 0x%x "
8031 child_die
->offset
.sect_off
, objfile
->name
);
8036 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
8037 if (!attr_form_is_block (attr
))
8039 complaint (&symfile_complaints
,
8040 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
8041 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8042 child_die
->offset
.sect_off
, objfile
->name
);
8045 parameter
->value
= DW_BLOCK (attr
)->data
;
8046 parameter
->value_size
= DW_BLOCK (attr
)->size
;
8048 /* Parameters are not pre-cleared by memset above. */
8049 parameter
->data_value
= NULL
;
8050 parameter
->data_value_size
= 0;
8051 call_site
->parameter_count
++;
8053 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
8056 if (!attr_form_is_block (attr
))
8057 complaint (&symfile_complaints
,
8058 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
8059 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8060 child_die
->offset
.sect_off
, objfile
->name
);
8063 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8064 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8070 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8071 Return 1 if the attributes are present and valid, otherwise, return 0.
8072 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8075 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8076 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8077 struct partial_symtab
*ranges_pst
)
8079 struct objfile
*objfile
= cu
->objfile
;
8080 struct comp_unit_head
*cu_header
= &cu
->header
;
8081 bfd
*obfd
= objfile
->obfd
;
8082 unsigned int addr_size
= cu_header
->addr_size
;
8083 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8084 /* Base address selection entry. */
8095 found_base
= cu
->base_known
;
8096 base
= cu
->base_address
;
8098 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
8099 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8101 complaint (&symfile_complaints
,
8102 _("Offset %d out of bounds for DW_AT_ranges attribute"),
8106 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8108 /* Read in the largest possible address. */
8109 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
8110 if ((marker
& mask
) == mask
)
8112 /* If we found the largest possible address, then
8113 read the base address. */
8114 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8115 buffer
+= 2 * addr_size
;
8116 offset
+= 2 * addr_size
;
8122 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8126 CORE_ADDR range_beginning
, range_end
;
8128 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
8129 buffer
+= addr_size
;
8130 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
8131 buffer
+= addr_size
;
8132 offset
+= 2 * addr_size
;
8134 /* An end of list marker is a pair of zero addresses. */
8135 if (range_beginning
== 0 && range_end
== 0)
8136 /* Found the end of list entry. */
8139 /* Each base address selection entry is a pair of 2 values.
8140 The first is the largest possible address, the second is
8141 the base address. Check for a base address here. */
8142 if ((range_beginning
& mask
) == mask
)
8144 /* If we found the largest possible address, then
8145 read the base address. */
8146 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8153 /* We have no valid base address for the ranges
8155 complaint (&symfile_complaints
,
8156 _("Invalid .debug_ranges data (no base address)"));
8160 if (range_beginning
> range_end
)
8162 /* Inverted range entries are invalid. */
8163 complaint (&symfile_complaints
,
8164 _("Invalid .debug_ranges data (inverted range)"));
8168 /* Empty range entries have no effect. */
8169 if (range_beginning
== range_end
)
8172 range_beginning
+= base
;
8175 if (ranges_pst
!= NULL
)
8176 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8177 range_beginning
+ baseaddr
,
8178 range_end
- 1 + baseaddr
,
8181 /* FIXME: This is recording everything as a low-high
8182 segment of consecutive addresses. We should have a
8183 data structure for discontiguous block ranges
8187 low
= range_beginning
;
8193 if (range_beginning
< low
)
8194 low
= range_beginning
;
8195 if (range_end
> high
)
8201 /* If the first entry is an end-of-list marker, the range
8202 describes an empty scope, i.e. no instructions. */
8208 *high_return
= high
;
8212 /* Get low and high pc attributes from a die. Return 1 if the attributes
8213 are present and valid, otherwise, return 0. Return -1 if the range is
8214 discontinuous, i.e. derived from DW_AT_ranges information. */
8217 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
8218 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
8219 struct partial_symtab
*pst
)
8221 struct attribute
*attr
;
8222 struct attribute
*attr_high
;
8227 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8230 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8233 low
= DW_ADDR (attr
);
8234 if (attr_high
->form
== DW_FORM_addr
8235 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8236 high
= DW_ADDR (attr_high
);
8238 high
= low
+ DW_UNSND (attr_high
);
8241 /* Found high w/o low attribute. */
8244 /* Found consecutive range of addresses. */
8249 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8252 /* Value of the DW_AT_ranges attribute is the offset in the
8253 .debug_ranges section. */
8254 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
8256 /* Found discontinuous range of addresses. */
8261 /* read_partial_die has also the strict LOW < HIGH requirement. */
8265 /* When using the GNU linker, .gnu.linkonce. sections are used to
8266 eliminate duplicate copies of functions and vtables and such.
8267 The linker will arbitrarily choose one and discard the others.
8268 The AT_*_pc values for such functions refer to local labels in
8269 these sections. If the section from that file was discarded, the
8270 labels are not in the output, so the relocs get a value of 0.
8271 If this is a discarded function, mark the pc bounds as invalid,
8272 so that GDB will ignore it. */
8273 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8282 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8283 its low and high PC addresses. Do nothing if these addresses could not
8284 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8285 and HIGHPC to the high address if greater than HIGHPC. */
8288 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8289 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8290 struct dwarf2_cu
*cu
)
8292 CORE_ADDR low
, high
;
8293 struct die_info
*child
= die
->child
;
8295 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8297 *lowpc
= min (*lowpc
, low
);
8298 *highpc
= max (*highpc
, high
);
8301 /* If the language does not allow nested subprograms (either inside
8302 subprograms or lexical blocks), we're done. */
8303 if (cu
->language
!= language_ada
)
8306 /* Check all the children of the given DIE. If it contains nested
8307 subprograms, then check their pc bounds. Likewise, we need to
8308 check lexical blocks as well, as they may also contain subprogram
8310 while (child
&& child
->tag
)
8312 if (child
->tag
== DW_TAG_subprogram
8313 || child
->tag
== DW_TAG_lexical_block
)
8314 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8315 child
= sibling_die (child
);
8319 /* Get the low and high pc's represented by the scope DIE, and store
8320 them in *LOWPC and *HIGHPC. If the correct values can't be
8321 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8324 get_scope_pc_bounds (struct die_info
*die
,
8325 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8326 struct dwarf2_cu
*cu
)
8328 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8329 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8330 CORE_ADDR current_low
, current_high
;
8332 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8334 best_low
= current_low
;
8335 best_high
= current_high
;
8339 struct die_info
*child
= die
->child
;
8341 while (child
&& child
->tag
)
8343 switch (child
->tag
) {
8344 case DW_TAG_subprogram
:
8345 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8347 case DW_TAG_namespace
:
8349 /* FIXME: carlton/2004-01-16: Should we do this for
8350 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8351 that current GCC's always emit the DIEs corresponding
8352 to definitions of methods of classes as children of a
8353 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8354 the DIEs giving the declarations, which could be
8355 anywhere). But I don't see any reason why the
8356 standards says that they have to be there. */
8357 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8359 if (current_low
!= ((CORE_ADDR
) -1))
8361 best_low
= min (best_low
, current_low
);
8362 best_high
= max (best_high
, current_high
);
8370 child
= sibling_die (child
);
8375 *highpc
= best_high
;
8378 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8382 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8383 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8385 struct objfile
*objfile
= cu
->objfile
;
8386 struct attribute
*attr
;
8387 struct attribute
*attr_high
;
8389 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8392 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8395 CORE_ADDR low
= DW_ADDR (attr
);
8397 if (attr_high
->form
== DW_FORM_addr
8398 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8399 high
= DW_ADDR (attr_high
);
8401 high
= low
+ DW_UNSND (attr_high
);
8403 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8407 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8410 bfd
*obfd
= objfile
->obfd
;
8412 /* The value of the DW_AT_ranges attribute is the offset of the
8413 address range list in the .debug_ranges section. */
8414 unsigned long offset
= DW_UNSND (attr
);
8415 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8417 /* For some target architectures, but not others, the
8418 read_address function sign-extends the addresses it returns.
8419 To recognize base address selection entries, we need a
8421 unsigned int addr_size
= cu
->header
.addr_size
;
8422 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8424 /* The base address, to which the next pair is relative. Note
8425 that this 'base' is a DWARF concept: most entries in a range
8426 list are relative, to reduce the number of relocs against the
8427 debugging information. This is separate from this function's
8428 'baseaddr' argument, which GDB uses to relocate debugging
8429 information from a shared library based on the address at
8430 which the library was loaded. */
8431 CORE_ADDR base
= cu
->base_address
;
8432 int base_known
= cu
->base_known
;
8434 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8435 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8437 complaint (&symfile_complaints
,
8438 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8445 unsigned int bytes_read
;
8446 CORE_ADDR start
, end
;
8448 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8449 buffer
+= bytes_read
;
8450 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8451 buffer
+= bytes_read
;
8453 /* Did we find the end of the range list? */
8454 if (start
== 0 && end
== 0)
8457 /* Did we find a base address selection entry? */
8458 else if ((start
& base_select_mask
) == base_select_mask
)
8464 /* We found an ordinary address range. */
8469 complaint (&symfile_complaints
,
8470 _("Invalid .debug_ranges data "
8471 "(no base address)"));
8477 /* Inverted range entries are invalid. */
8478 complaint (&symfile_complaints
,
8479 _("Invalid .debug_ranges data "
8480 "(inverted range)"));
8484 /* Empty range entries have no effect. */
8488 record_block_range (block
,
8489 baseaddr
+ base
+ start
,
8490 baseaddr
+ base
+ end
- 1);
8496 /* Check whether the producer field indicates either of GCC < 4.6, or the
8497 Intel C/C++ compiler, and cache the result in CU. */
8500 check_producer (struct dwarf2_cu
*cu
)
8503 int major
, minor
, release
;
8505 if (cu
->producer
== NULL
)
8507 /* For unknown compilers expect their behavior is DWARF version
8510 GCC started to support .debug_types sections by -gdwarf-4 since
8511 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8512 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8513 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8514 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8516 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
8518 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8520 cs
= &cu
->producer
[strlen ("GNU ")];
8521 while (*cs
&& !isdigit (*cs
))
8523 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8525 /* Not recognized as GCC. */
8528 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
8530 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
8531 cu
->producer_is_icc
= 1;
8534 /* For other non-GCC compilers, expect their behavior is DWARF version
8538 cu
->checked_producer
= 1;
8541 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8542 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8543 during 4.6.0 experimental. */
8546 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8548 if (!cu
->checked_producer
)
8549 check_producer (cu
);
8551 return cu
->producer_is_gxx_lt_4_6
;
8554 /* Return the default accessibility type if it is not overriden by
8555 DW_AT_accessibility. */
8557 static enum dwarf_access_attribute
8558 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8560 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8562 /* The default DWARF 2 accessibility for members is public, the default
8563 accessibility for inheritance is private. */
8565 if (die
->tag
!= DW_TAG_inheritance
)
8566 return DW_ACCESS_public
;
8568 return DW_ACCESS_private
;
8572 /* DWARF 3+ defines the default accessibility a different way. The same
8573 rules apply now for DW_TAG_inheritance as for the members and it only
8574 depends on the container kind. */
8576 if (die
->parent
->tag
== DW_TAG_class_type
)
8577 return DW_ACCESS_private
;
8579 return DW_ACCESS_public
;
8583 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8584 offset. If the attribute was not found return 0, otherwise return
8585 1. If it was found but could not properly be handled, set *OFFSET
8589 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8592 struct attribute
*attr
;
8594 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8599 /* Note that we do not check for a section offset first here.
8600 This is because DW_AT_data_member_location is new in DWARF 4,
8601 so if we see it, we can assume that a constant form is really
8602 a constant and not a section offset. */
8603 if (attr_form_is_constant (attr
))
8604 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8605 else if (attr_form_is_section_offset (attr
))
8606 dwarf2_complex_location_expr_complaint ();
8607 else if (attr_form_is_block (attr
))
8608 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8610 dwarf2_complex_location_expr_complaint ();
8618 /* Add an aggregate field to the field list. */
8621 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8622 struct dwarf2_cu
*cu
)
8624 struct objfile
*objfile
= cu
->objfile
;
8625 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8626 struct nextfield
*new_field
;
8627 struct attribute
*attr
;
8629 char *fieldname
= "";
8631 /* Allocate a new field list entry and link it in. */
8632 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8633 make_cleanup (xfree
, new_field
);
8634 memset (new_field
, 0, sizeof (struct nextfield
));
8636 if (die
->tag
== DW_TAG_inheritance
)
8638 new_field
->next
= fip
->baseclasses
;
8639 fip
->baseclasses
= new_field
;
8643 new_field
->next
= fip
->fields
;
8644 fip
->fields
= new_field
;
8648 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8650 new_field
->accessibility
= DW_UNSND (attr
);
8652 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8653 if (new_field
->accessibility
!= DW_ACCESS_public
)
8654 fip
->non_public_fields
= 1;
8656 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8658 new_field
->virtuality
= DW_UNSND (attr
);
8660 new_field
->virtuality
= DW_VIRTUALITY_none
;
8662 fp
= &new_field
->field
;
8664 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8668 /* Data member other than a C++ static data member. */
8670 /* Get type of field. */
8671 fp
->type
= die_type (die
, cu
);
8673 SET_FIELD_BITPOS (*fp
, 0);
8675 /* Get bit size of field (zero if none). */
8676 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8679 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8683 FIELD_BITSIZE (*fp
) = 0;
8686 /* Get bit offset of field. */
8687 if (handle_data_member_location (die
, cu
, &offset
))
8688 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8689 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8692 if (gdbarch_bits_big_endian (gdbarch
))
8694 /* For big endian bits, the DW_AT_bit_offset gives the
8695 additional bit offset from the MSB of the containing
8696 anonymous object to the MSB of the field. We don't
8697 have to do anything special since we don't need to
8698 know the size of the anonymous object. */
8699 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8703 /* For little endian bits, compute the bit offset to the
8704 MSB of the anonymous object, subtract off the number of
8705 bits from the MSB of the field to the MSB of the
8706 object, and then subtract off the number of bits of
8707 the field itself. The result is the bit offset of
8708 the LSB of the field. */
8710 int bit_offset
= DW_UNSND (attr
);
8712 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8715 /* The size of the anonymous object containing
8716 the bit field is explicit, so use the
8717 indicated size (in bytes). */
8718 anonymous_size
= DW_UNSND (attr
);
8722 /* The size of the anonymous object containing
8723 the bit field must be inferred from the type
8724 attribute of the data member containing the
8726 anonymous_size
= TYPE_LENGTH (fp
->type
);
8728 SET_FIELD_BITPOS (*fp
,
8730 + anonymous_size
* bits_per_byte
8731 - bit_offset
- FIELD_BITSIZE (*fp
)));
8735 /* Get name of field. */
8736 fieldname
= dwarf2_name (die
, cu
);
8737 if (fieldname
== NULL
)
8740 /* The name is already allocated along with this objfile, so we don't
8741 need to duplicate it for the type. */
8742 fp
->name
= fieldname
;
8744 /* Change accessibility for artificial fields (e.g. virtual table
8745 pointer or virtual base class pointer) to private. */
8746 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8748 FIELD_ARTIFICIAL (*fp
) = 1;
8749 new_field
->accessibility
= DW_ACCESS_private
;
8750 fip
->non_public_fields
= 1;
8753 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8755 /* C++ static member. */
8757 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8758 is a declaration, but all versions of G++ as of this writing
8759 (so through at least 3.2.1) incorrectly generate
8760 DW_TAG_variable tags. */
8762 const char *physname
;
8764 /* Get name of field. */
8765 fieldname
= dwarf2_name (die
, cu
);
8766 if (fieldname
== NULL
)
8769 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8771 /* Only create a symbol if this is an external value.
8772 new_symbol checks this and puts the value in the global symbol
8773 table, which we want. If it is not external, new_symbol
8774 will try to put the value in cu->list_in_scope which is wrong. */
8775 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8777 /* A static const member, not much different than an enum as far as
8778 we're concerned, except that we can support more types. */
8779 new_symbol (die
, NULL
, cu
);
8782 /* Get physical name. */
8783 physname
= dwarf2_physname (fieldname
, die
, cu
);
8785 /* The name is already allocated along with this objfile, so we don't
8786 need to duplicate it for the type. */
8787 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8788 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8789 FIELD_NAME (*fp
) = fieldname
;
8791 else if (die
->tag
== DW_TAG_inheritance
)
8795 /* C++ base class field. */
8796 if (handle_data_member_location (die
, cu
, &offset
))
8797 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8798 FIELD_BITSIZE (*fp
) = 0;
8799 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8800 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8801 fip
->nbaseclasses
++;
8805 /* Add a typedef defined in the scope of the FIP's class. */
8808 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8809 struct dwarf2_cu
*cu
)
8811 struct objfile
*objfile
= cu
->objfile
;
8812 struct typedef_field_list
*new_field
;
8813 struct attribute
*attr
;
8814 struct typedef_field
*fp
;
8815 char *fieldname
= "";
8817 /* Allocate a new field list entry and link it in. */
8818 new_field
= xzalloc (sizeof (*new_field
));
8819 make_cleanup (xfree
, new_field
);
8821 gdb_assert (die
->tag
== DW_TAG_typedef
);
8823 fp
= &new_field
->field
;
8825 /* Get name of field. */
8826 fp
->name
= dwarf2_name (die
, cu
);
8827 if (fp
->name
== NULL
)
8830 fp
->type
= read_type_die (die
, cu
);
8832 new_field
->next
= fip
->typedef_field_list
;
8833 fip
->typedef_field_list
= new_field
;
8834 fip
->typedef_field_list_count
++;
8837 /* Create the vector of fields, and attach it to the type. */
8840 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8841 struct dwarf2_cu
*cu
)
8843 int nfields
= fip
->nfields
;
8845 /* Record the field count, allocate space for the array of fields,
8846 and create blank accessibility bitfields if necessary. */
8847 TYPE_NFIELDS (type
) = nfields
;
8848 TYPE_FIELDS (type
) = (struct field
*)
8849 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8850 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8852 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8854 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8856 TYPE_FIELD_PRIVATE_BITS (type
) =
8857 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8858 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8860 TYPE_FIELD_PROTECTED_BITS (type
) =
8861 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8862 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8864 TYPE_FIELD_IGNORE_BITS (type
) =
8865 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8866 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8869 /* If the type has baseclasses, allocate and clear a bit vector for
8870 TYPE_FIELD_VIRTUAL_BITS. */
8871 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8873 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8874 unsigned char *pointer
;
8876 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8877 pointer
= TYPE_ALLOC (type
, num_bytes
);
8878 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8879 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8880 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8883 /* Copy the saved-up fields into the field vector. Start from the head of
8884 the list, adding to the tail of the field array, so that they end up in
8885 the same order in the array in which they were added to the list. */
8886 while (nfields
-- > 0)
8888 struct nextfield
*fieldp
;
8892 fieldp
= fip
->fields
;
8893 fip
->fields
= fieldp
->next
;
8897 fieldp
= fip
->baseclasses
;
8898 fip
->baseclasses
= fieldp
->next
;
8901 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8902 switch (fieldp
->accessibility
)
8904 case DW_ACCESS_private
:
8905 if (cu
->language
!= language_ada
)
8906 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8909 case DW_ACCESS_protected
:
8910 if (cu
->language
!= language_ada
)
8911 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8914 case DW_ACCESS_public
:
8918 /* Unknown accessibility. Complain and treat it as public. */
8920 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8921 fieldp
->accessibility
);
8925 if (nfields
< fip
->nbaseclasses
)
8927 switch (fieldp
->virtuality
)
8929 case DW_VIRTUALITY_virtual
:
8930 case DW_VIRTUALITY_pure_virtual
:
8931 if (cu
->language
== language_ada
)
8932 error (_("unexpected virtuality in component of Ada type"));
8933 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8940 /* Add a member function to the proper fieldlist. */
8943 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8944 struct type
*type
, struct dwarf2_cu
*cu
)
8946 struct objfile
*objfile
= cu
->objfile
;
8947 struct attribute
*attr
;
8948 struct fnfieldlist
*flp
;
8950 struct fn_field
*fnp
;
8952 struct nextfnfield
*new_fnfield
;
8953 struct type
*this_type
;
8954 enum dwarf_access_attribute accessibility
;
8956 if (cu
->language
== language_ada
)
8957 error (_("unexpected member function in Ada type"));
8959 /* Get name of member function. */
8960 fieldname
= dwarf2_name (die
, cu
);
8961 if (fieldname
== NULL
)
8964 /* Look up member function name in fieldlist. */
8965 for (i
= 0; i
< fip
->nfnfields
; i
++)
8967 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8971 /* Create new list element if necessary. */
8972 if (i
< fip
->nfnfields
)
8973 flp
= &fip
->fnfieldlists
[i
];
8976 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8978 fip
->fnfieldlists
= (struct fnfieldlist
*)
8979 xrealloc (fip
->fnfieldlists
,
8980 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8981 * sizeof (struct fnfieldlist
));
8982 if (fip
->nfnfields
== 0)
8983 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8985 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8986 flp
->name
= fieldname
;
8989 i
= fip
->nfnfields
++;
8992 /* Create a new member function field and chain it to the field list
8994 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8995 make_cleanup (xfree
, new_fnfield
);
8996 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8997 new_fnfield
->next
= flp
->head
;
8998 flp
->head
= new_fnfield
;
9001 /* Fill in the member function field info. */
9002 fnp
= &new_fnfield
->fnfield
;
9004 /* Delay processing of the physname until later. */
9005 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9007 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9012 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9013 fnp
->physname
= physname
? physname
: "";
9016 fnp
->type
= alloc_type (objfile
);
9017 this_type
= read_type_die (die
, cu
);
9018 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9020 int nparams
= TYPE_NFIELDS (this_type
);
9022 /* TYPE is the domain of this method, and THIS_TYPE is the type
9023 of the method itself (TYPE_CODE_METHOD). */
9024 smash_to_method_type (fnp
->type
, type
,
9025 TYPE_TARGET_TYPE (this_type
),
9026 TYPE_FIELDS (this_type
),
9027 TYPE_NFIELDS (this_type
),
9028 TYPE_VARARGS (this_type
));
9030 /* Handle static member functions.
9031 Dwarf2 has no clean way to discern C++ static and non-static
9032 member functions. G++ helps GDB by marking the first
9033 parameter for non-static member functions (which is the this
9034 pointer) as artificial. We obtain this information from
9035 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
9036 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
9037 fnp
->voffset
= VOFFSET_STATIC
;
9040 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
9041 dwarf2_full_name (fieldname
, die
, cu
));
9043 /* Get fcontext from DW_AT_containing_type if present. */
9044 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9045 fnp
->fcontext
= die_containing_type (die
, cu
);
9047 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
9048 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
9050 /* Get accessibility. */
9051 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9053 accessibility
= DW_UNSND (attr
);
9055 accessibility
= dwarf2_default_access_attribute (die
, cu
);
9056 switch (accessibility
)
9058 case DW_ACCESS_private
:
9059 fnp
->is_private
= 1;
9061 case DW_ACCESS_protected
:
9062 fnp
->is_protected
= 1;
9066 /* Check for artificial methods. */
9067 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9068 if (attr
&& DW_UNSND (attr
) != 0)
9069 fnp
->is_artificial
= 1;
9071 /* Get index in virtual function table if it is a virtual member
9072 function. For older versions of GCC, this is an offset in the
9073 appropriate virtual table, as specified by DW_AT_containing_type.
9074 For everyone else, it is an expression to be evaluated relative
9075 to the object address. */
9077 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9080 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9082 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9084 /* Old-style GCC. */
9085 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9087 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9088 || (DW_BLOCK (attr
)->size
> 1
9089 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9090 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9092 struct dwarf_block blk
;
9095 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9097 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
9098 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
9099 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9100 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
9101 dwarf2_complex_location_expr_complaint ();
9103 fnp
->voffset
/= cu
->header
.addr_size
;
9107 dwarf2_complex_location_expr_complaint ();
9110 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
9112 else if (attr_form_is_section_offset (attr
))
9114 dwarf2_complex_location_expr_complaint ();
9118 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
9124 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9125 if (attr
&& DW_UNSND (attr
))
9127 /* GCC does this, as of 2008-08-25; PR debug/37237. */
9128 complaint (&symfile_complaints
,
9129 _("Member function \"%s\" (offset %d) is virtual "
9130 "but the vtable offset is not specified"),
9131 fieldname
, die
->offset
.sect_off
);
9132 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9133 TYPE_CPLUS_DYNAMIC (type
) = 1;
9138 /* Create the vector of member function fields, and attach it to the type. */
9141 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
9142 struct dwarf2_cu
*cu
)
9144 struct fnfieldlist
*flp
;
9147 if (cu
->language
== language_ada
)
9148 error (_("unexpected member functions in Ada type"));
9150 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9151 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
9152 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
9154 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
9156 struct nextfnfield
*nfp
= flp
->head
;
9157 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
9160 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
9161 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
9162 fn_flp
->fn_fields
= (struct fn_field
*)
9163 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
9164 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
9165 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
9168 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
9171 /* Returns non-zero if NAME is the name of a vtable member in CU's
9172 language, zero otherwise. */
9174 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
9176 static const char vptr
[] = "_vptr";
9177 static const char vtable
[] = "vtable";
9179 /* Look for the C++ and Java forms of the vtable. */
9180 if ((cu
->language
== language_java
9181 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
9182 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
9183 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
9189 /* GCC outputs unnamed structures that are really pointers to member
9190 functions, with the ABI-specified layout. If TYPE describes
9191 such a structure, smash it into a member function type.
9193 GCC shouldn't do this; it should just output pointer to member DIEs.
9194 This is GCC PR debug/28767. */
9197 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
9199 struct type
*pfn_type
, *domain_type
, *new_type
;
9201 /* Check for a structure with no name and two children. */
9202 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
9205 /* Check for __pfn and __delta members. */
9206 if (TYPE_FIELD_NAME (type
, 0) == NULL
9207 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
9208 || TYPE_FIELD_NAME (type
, 1) == NULL
9209 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
9212 /* Find the type of the method. */
9213 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
9214 if (pfn_type
== NULL
9215 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
9216 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
9219 /* Look for the "this" argument. */
9220 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
9221 if (TYPE_NFIELDS (pfn_type
) == 0
9222 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
9223 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
9226 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9227 new_type
= alloc_type (objfile
);
9228 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9229 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9230 TYPE_VARARGS (pfn_type
));
9231 smash_to_methodptr_type (type
, new_type
);
9234 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
9238 producer_is_icc (struct dwarf2_cu
*cu
)
9240 if (!cu
->checked_producer
)
9241 check_producer (cu
);
9243 return cu
->producer_is_icc
;
9246 /* Called when we find the DIE that starts a structure or union scope
9247 (definition) to create a type for the structure or union. Fill in
9248 the type's name and general properties; the members will not be
9249 processed until process_structure_type.
9251 NOTE: we need to call these functions regardless of whether or not the
9252 DIE has a DW_AT_name attribute, since it might be an anonymous
9253 structure or union. This gets the type entered into our set of
9256 However, if the structure is incomplete (an opaque struct/union)
9257 then suppress creating a symbol table entry for it since gdb only
9258 wants to find the one with the complete definition. Note that if
9259 it is complete, we just call new_symbol, which does it's own
9260 checking about whether the struct/union is anonymous or not (and
9261 suppresses creating a symbol table entry itself). */
9263 static struct type
*
9264 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9266 struct objfile
*objfile
= cu
->objfile
;
9268 struct attribute
*attr
;
9271 /* If the definition of this type lives in .debug_types, read that type.
9272 Don't follow DW_AT_specification though, that will take us back up
9273 the chain and we want to go down. */
9274 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9277 struct dwarf2_cu
*type_cu
= cu
;
9278 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9280 /* We could just recurse on read_structure_type, but we need to call
9281 get_die_type to ensure only one type for this DIE is created.
9282 This is important, for example, because for c++ classes we need
9283 TYPE_NAME set which is only done by new_symbol. Blech. */
9284 type
= read_type_die (type_die
, type_cu
);
9286 /* TYPE_CU may not be the same as CU.
9287 Ensure TYPE is recorded in CU's type_hash table. */
9288 return set_die_type (die
, type
, cu
);
9291 type
= alloc_type (objfile
);
9292 INIT_CPLUS_SPECIFIC (type
);
9294 name
= dwarf2_name (die
, cu
);
9297 if (cu
->language
== language_cplus
9298 || cu
->language
== language_java
)
9300 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9302 /* dwarf2_full_name might have already finished building the DIE's
9303 type. If so, there is no need to continue. */
9304 if (get_die_type (die
, cu
) != NULL
)
9305 return get_die_type (die
, cu
);
9307 TYPE_TAG_NAME (type
) = full_name
;
9308 if (die
->tag
== DW_TAG_structure_type
9309 || die
->tag
== DW_TAG_class_type
)
9310 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9314 /* The name is already allocated along with this objfile, so
9315 we don't need to duplicate it for the type. */
9316 TYPE_TAG_NAME (type
) = (char *) name
;
9317 if (die
->tag
== DW_TAG_class_type
)
9318 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9322 if (die
->tag
== DW_TAG_structure_type
)
9324 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9326 else if (die
->tag
== DW_TAG_union_type
)
9328 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9332 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9335 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9336 TYPE_DECLARED_CLASS (type
) = 1;
9338 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9341 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9345 TYPE_LENGTH (type
) = 0;
9348 if (producer_is_icc (cu
))
9350 /* ICC does not output the required DW_AT_declaration
9351 on incomplete types, but gives them a size of zero. */
9354 TYPE_STUB_SUPPORTED (type
) = 1;
9356 if (die_is_declaration (die
, cu
))
9357 TYPE_STUB (type
) = 1;
9358 else if (attr
== NULL
&& die
->child
== NULL
9359 && producer_is_realview (cu
->producer
))
9360 /* RealView does not output the required DW_AT_declaration
9361 on incomplete types. */
9362 TYPE_STUB (type
) = 1;
9364 /* We need to add the type field to the die immediately so we don't
9365 infinitely recurse when dealing with pointers to the structure
9366 type within the structure itself. */
9367 set_die_type (die
, type
, cu
);
9369 /* set_die_type should be already done. */
9370 set_descriptive_type (type
, die
, cu
);
9375 /* Finish creating a structure or union type, including filling in
9376 its members and creating a symbol for it. */
9379 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9381 struct objfile
*objfile
= cu
->objfile
;
9382 struct die_info
*child_die
= die
->child
;
9385 type
= get_die_type (die
, cu
);
9387 type
= read_structure_type (die
, cu
);
9389 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9391 struct field_info fi
;
9392 struct die_info
*child_die
;
9393 VEC (symbolp
) *template_args
= NULL
;
9394 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9396 memset (&fi
, 0, sizeof (struct field_info
));
9398 child_die
= die
->child
;
9400 while (child_die
&& child_die
->tag
)
9402 if (child_die
->tag
== DW_TAG_member
9403 || child_die
->tag
== DW_TAG_variable
)
9405 /* NOTE: carlton/2002-11-05: A C++ static data member
9406 should be a DW_TAG_member that is a declaration, but
9407 all versions of G++ as of this writing (so through at
9408 least 3.2.1) incorrectly generate DW_TAG_variable
9409 tags for them instead. */
9410 dwarf2_add_field (&fi
, child_die
, cu
);
9412 else if (child_die
->tag
== DW_TAG_subprogram
)
9414 /* C++ member function. */
9415 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9417 else if (child_die
->tag
== DW_TAG_inheritance
)
9419 /* C++ base class field. */
9420 dwarf2_add_field (&fi
, child_die
, cu
);
9422 else if (child_die
->tag
== DW_TAG_typedef
)
9423 dwarf2_add_typedef (&fi
, child_die
, cu
);
9424 else if (child_die
->tag
== DW_TAG_template_type_param
9425 || child_die
->tag
== DW_TAG_template_value_param
)
9427 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9430 VEC_safe_push (symbolp
, template_args
, arg
);
9433 child_die
= sibling_die (child_die
);
9436 /* Attach template arguments to type. */
9437 if (! VEC_empty (symbolp
, template_args
))
9439 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9440 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9441 = VEC_length (symbolp
, template_args
);
9442 TYPE_TEMPLATE_ARGUMENTS (type
)
9443 = obstack_alloc (&objfile
->objfile_obstack
,
9444 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9445 * sizeof (struct symbol
*)));
9446 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9447 VEC_address (symbolp
, template_args
),
9448 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9449 * sizeof (struct symbol
*)));
9450 VEC_free (symbolp
, template_args
);
9453 /* Attach fields and member functions to the type. */
9455 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9458 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9460 /* Get the type which refers to the base class (possibly this
9461 class itself) which contains the vtable pointer for the current
9462 class from the DW_AT_containing_type attribute. This use of
9463 DW_AT_containing_type is a GNU extension. */
9465 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9467 struct type
*t
= die_containing_type (die
, cu
);
9469 TYPE_VPTR_BASETYPE (type
) = t
;
9474 /* Our own class provides vtbl ptr. */
9475 for (i
= TYPE_NFIELDS (t
) - 1;
9476 i
>= TYPE_N_BASECLASSES (t
);
9479 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9481 if (is_vtable_name (fieldname
, cu
))
9483 TYPE_VPTR_FIELDNO (type
) = i
;
9488 /* Complain if virtual function table field not found. */
9489 if (i
< TYPE_N_BASECLASSES (t
))
9490 complaint (&symfile_complaints
,
9491 _("virtual function table pointer "
9492 "not found when defining class '%s'"),
9493 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9498 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9501 else if (cu
->producer
9502 && strncmp (cu
->producer
,
9503 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9505 /* The IBM XLC compiler does not provide direct indication
9506 of the containing type, but the vtable pointer is
9507 always named __vfp. */
9511 for (i
= TYPE_NFIELDS (type
) - 1;
9512 i
>= TYPE_N_BASECLASSES (type
);
9515 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9517 TYPE_VPTR_FIELDNO (type
) = i
;
9518 TYPE_VPTR_BASETYPE (type
) = type
;
9525 /* Copy fi.typedef_field_list linked list elements content into the
9526 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9527 if (fi
.typedef_field_list
)
9529 int i
= fi
.typedef_field_list_count
;
9531 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9532 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9533 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9534 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9536 /* Reverse the list order to keep the debug info elements order. */
9539 struct typedef_field
*dest
, *src
;
9541 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9542 src
= &fi
.typedef_field_list
->field
;
9543 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9548 do_cleanups (back_to
);
9550 if (HAVE_CPLUS_STRUCT (type
))
9551 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9554 quirk_gcc_member_function_pointer (type
, objfile
);
9556 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9557 snapshots) has been known to create a die giving a declaration
9558 for a class that has, as a child, a die giving a definition for a
9559 nested class. So we have to process our children even if the
9560 current die is a declaration. Normally, of course, a declaration
9561 won't have any children at all. */
9563 while (child_die
!= NULL
&& child_die
->tag
)
9565 if (child_die
->tag
== DW_TAG_member
9566 || child_die
->tag
== DW_TAG_variable
9567 || child_die
->tag
== DW_TAG_inheritance
9568 || child_die
->tag
== DW_TAG_template_value_param
9569 || child_die
->tag
== DW_TAG_template_type_param
)
9574 process_die (child_die
, cu
);
9576 child_die
= sibling_die (child_die
);
9579 /* Do not consider external references. According to the DWARF standard,
9580 these DIEs are identified by the fact that they have no byte_size
9581 attribute, and a declaration attribute. */
9582 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9583 || !die_is_declaration (die
, cu
))
9584 new_symbol (die
, type
, cu
);
9587 /* Given a DW_AT_enumeration_type die, set its type. We do not
9588 complete the type's fields yet, or create any symbols. */
9590 static struct type
*
9591 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9593 struct objfile
*objfile
= cu
->objfile
;
9595 struct attribute
*attr
;
9598 /* If the definition of this type lives in .debug_types, read that type.
9599 Don't follow DW_AT_specification though, that will take us back up
9600 the chain and we want to go down. */
9601 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9604 struct dwarf2_cu
*type_cu
= cu
;
9605 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9607 type
= read_type_die (type_die
, type_cu
);
9609 /* TYPE_CU may not be the same as CU.
9610 Ensure TYPE is recorded in CU's type_hash table. */
9611 return set_die_type (die
, type
, cu
);
9614 type
= alloc_type (objfile
);
9616 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9617 name
= dwarf2_full_name (NULL
, die
, cu
);
9619 TYPE_TAG_NAME (type
) = (char *) name
;
9621 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9624 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9628 TYPE_LENGTH (type
) = 0;
9631 /* The enumeration DIE can be incomplete. In Ada, any type can be
9632 declared as private in the package spec, and then defined only
9633 inside the package body. Such types are known as Taft Amendment
9634 Types. When another package uses such a type, an incomplete DIE
9635 may be generated by the compiler. */
9636 if (die_is_declaration (die
, cu
))
9637 TYPE_STUB (type
) = 1;
9639 return set_die_type (die
, type
, cu
);
9642 /* Given a pointer to a die which begins an enumeration, process all
9643 the dies that define the members of the enumeration, and create the
9644 symbol for the enumeration type.
9646 NOTE: We reverse the order of the element list. */
9649 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9651 struct type
*this_type
;
9653 this_type
= get_die_type (die
, cu
);
9654 if (this_type
== NULL
)
9655 this_type
= read_enumeration_type (die
, cu
);
9657 if (die
->child
!= NULL
)
9659 struct die_info
*child_die
;
9661 struct field
*fields
= NULL
;
9663 int unsigned_enum
= 1;
9668 child_die
= die
->child
;
9669 while (child_die
&& child_die
->tag
)
9671 if (child_die
->tag
!= DW_TAG_enumerator
)
9673 process_die (child_die
, cu
);
9677 name
= dwarf2_name (child_die
, cu
);
9680 sym
= new_symbol (child_die
, this_type
, cu
);
9681 if (SYMBOL_VALUE (sym
) < 0)
9686 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9689 mask
|= SYMBOL_VALUE (sym
);
9691 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9693 fields
= (struct field
*)
9695 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9696 * sizeof (struct field
));
9699 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9700 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9701 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9702 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9708 child_die
= sibling_die (child_die
);
9713 TYPE_NFIELDS (this_type
) = num_fields
;
9714 TYPE_FIELDS (this_type
) = (struct field
*)
9715 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9716 memcpy (TYPE_FIELDS (this_type
), fields
,
9717 sizeof (struct field
) * num_fields
);
9721 TYPE_UNSIGNED (this_type
) = 1;
9723 TYPE_FLAG_ENUM (this_type
) = 1;
9726 /* If we are reading an enum from a .debug_types unit, and the enum
9727 is a declaration, and the enum is not the signatured type in the
9728 unit, then we do not want to add a symbol for it. Adding a
9729 symbol would in some cases obscure the true definition of the
9730 enum, giving users an incomplete type when the definition is
9731 actually available. Note that we do not want to do this for all
9732 enums which are just declarations, because C++0x allows forward
9733 enum declarations. */
9734 if (cu
->per_cu
->is_debug_types
9735 && die_is_declaration (die
, cu
))
9737 struct signatured_type
*sig_type
;
9740 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9741 cu
->per_cu
->info_or_types_section
,
9742 cu
->per_cu
->offset
);
9743 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9744 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9748 new_symbol (die
, this_type
, cu
);
9751 /* Extract all information from a DW_TAG_array_type DIE and put it in
9752 the DIE's type field. For now, this only handles one dimensional
9755 static struct type
*
9756 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9758 struct objfile
*objfile
= cu
->objfile
;
9759 struct die_info
*child_die
;
9761 struct type
*element_type
, *range_type
, *index_type
;
9762 struct type
**range_types
= NULL
;
9763 struct attribute
*attr
;
9765 struct cleanup
*back_to
;
9768 element_type
= die_type (die
, cu
);
9770 /* The die_type call above may have already set the type for this DIE. */
9771 type
= get_die_type (die
, cu
);
9775 /* Irix 6.2 native cc creates array types without children for
9776 arrays with unspecified length. */
9777 if (die
->child
== NULL
)
9779 index_type
= objfile_type (objfile
)->builtin_int
;
9780 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9781 type
= create_array_type (NULL
, element_type
, range_type
);
9782 return set_die_type (die
, type
, cu
);
9785 back_to
= make_cleanup (null_cleanup
, NULL
);
9786 child_die
= die
->child
;
9787 while (child_die
&& child_die
->tag
)
9789 if (child_die
->tag
== DW_TAG_subrange_type
)
9791 struct type
*child_type
= read_type_die (child_die
, cu
);
9793 if (child_type
!= NULL
)
9795 /* The range type was succesfully read. Save it for the
9796 array type creation. */
9797 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9799 range_types
= (struct type
**)
9800 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9801 * sizeof (struct type
*));
9803 make_cleanup (free_current_contents
, &range_types
);
9805 range_types
[ndim
++] = child_type
;
9808 child_die
= sibling_die (child_die
);
9811 /* Dwarf2 dimensions are output from left to right, create the
9812 necessary array types in backwards order. */
9814 type
= element_type
;
9816 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9821 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9826 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9829 /* Understand Dwarf2 support for vector types (like they occur on
9830 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9831 array type. This is not part of the Dwarf2/3 standard yet, but a
9832 custom vendor extension. The main difference between a regular
9833 array and the vector variant is that vectors are passed by value
9835 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9837 make_vector_type (type
);
9839 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9840 implementation may choose to implement triple vectors using this
9842 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9845 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9846 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9848 complaint (&symfile_complaints
,
9849 _("DW_AT_byte_size for array type smaller "
9850 "than the total size of elements"));
9853 name
= dwarf2_name (die
, cu
);
9855 TYPE_NAME (type
) = name
;
9857 /* Install the type in the die. */
9858 set_die_type (die
, type
, cu
);
9860 /* set_die_type should be already done. */
9861 set_descriptive_type (type
, die
, cu
);
9863 do_cleanups (back_to
);
9868 static enum dwarf_array_dim_ordering
9869 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9871 struct attribute
*attr
;
9873 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9875 if (attr
) return DW_SND (attr
);
9877 /* GNU F77 is a special case, as at 08/2004 array type info is the
9878 opposite order to the dwarf2 specification, but data is still
9879 laid out as per normal fortran.
9881 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9882 version checking. */
9884 if (cu
->language
== language_fortran
9885 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9887 return DW_ORD_row_major
;
9890 switch (cu
->language_defn
->la_array_ordering
)
9892 case array_column_major
:
9893 return DW_ORD_col_major
;
9894 case array_row_major
:
9896 return DW_ORD_row_major
;
9900 /* Extract all information from a DW_TAG_set_type DIE and put it in
9901 the DIE's type field. */
9903 static struct type
*
9904 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9906 struct type
*domain_type
, *set_type
;
9907 struct attribute
*attr
;
9909 domain_type
= die_type (die
, cu
);
9911 /* The die_type call above may have already set the type for this DIE. */
9912 set_type
= get_die_type (die
, cu
);
9916 set_type
= create_set_type (NULL
, domain_type
);
9918 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9920 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9922 return set_die_type (die
, set_type
, cu
);
9925 /* First cut: install each common block member as a global variable. */
9928 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9930 struct die_info
*child_die
;
9931 struct attribute
*attr
;
9933 CORE_ADDR base
= (CORE_ADDR
) 0;
9935 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9938 /* Support the .debug_loc offsets. */
9939 if (attr_form_is_block (attr
))
9941 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9943 else if (attr_form_is_section_offset (attr
))
9945 dwarf2_complex_location_expr_complaint ();
9949 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9950 "common block member");
9953 if (die
->child
!= NULL
)
9955 child_die
= die
->child
;
9956 while (child_die
&& child_die
->tag
)
9960 sym
= new_symbol (child_die
, NULL
, cu
);
9962 && handle_data_member_location (child_die
, cu
, &offset
))
9964 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9965 add_symbol_to_list (sym
, &global_symbols
);
9967 child_die
= sibling_die (child_die
);
9972 /* Create a type for a C++ namespace. */
9974 static struct type
*
9975 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9977 struct objfile
*objfile
= cu
->objfile
;
9978 const char *previous_prefix
, *name
;
9982 /* For extensions, reuse the type of the original namespace. */
9983 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9985 struct die_info
*ext_die
;
9986 struct dwarf2_cu
*ext_cu
= cu
;
9988 ext_die
= dwarf2_extension (die
, &ext_cu
);
9989 type
= read_type_die (ext_die
, ext_cu
);
9991 /* EXT_CU may not be the same as CU.
9992 Ensure TYPE is recorded in CU's type_hash table. */
9993 return set_die_type (die
, type
, cu
);
9996 name
= namespace_name (die
, &is_anonymous
, cu
);
9998 /* Now build the name of the current namespace. */
10000 previous_prefix
= determine_prefix (die
, cu
);
10001 if (previous_prefix
[0] != '\0')
10002 name
= typename_concat (&objfile
->objfile_obstack
,
10003 previous_prefix
, name
, 0, cu
);
10005 /* Create the type. */
10006 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10008 TYPE_NAME (type
) = (char *) name
;
10009 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10011 return set_die_type (die
, type
, cu
);
10014 /* Read a C++ namespace. */
10017 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10019 struct objfile
*objfile
= cu
->objfile
;
10022 /* Add a symbol associated to this if we haven't seen the namespace
10023 before. Also, add a using directive if it's an anonymous
10026 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10030 type
= read_type_die (die
, cu
);
10031 new_symbol (die
, type
, cu
);
10033 namespace_name (die
, &is_anonymous
, cu
);
10036 const char *previous_prefix
= determine_prefix (die
, cu
);
10038 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
10039 NULL
, NULL
, &objfile
->objfile_obstack
);
10043 if (die
->child
!= NULL
)
10045 struct die_info
*child_die
= die
->child
;
10047 while (child_die
&& child_die
->tag
)
10049 process_die (child_die
, cu
);
10050 child_die
= sibling_die (child_die
);
10055 /* Read a Fortran module as type. This DIE can be only a declaration used for
10056 imported module. Still we need that type as local Fortran "use ... only"
10057 declaration imports depend on the created type in determine_prefix. */
10059 static struct type
*
10060 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10062 struct objfile
*objfile
= cu
->objfile
;
10066 module_name
= dwarf2_name (die
, cu
);
10068 complaint (&symfile_complaints
,
10069 _("DW_TAG_module has no name, offset 0x%x"),
10070 die
->offset
.sect_off
);
10071 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10073 /* determine_prefix uses TYPE_TAG_NAME. */
10074 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10076 return set_die_type (die
, type
, cu
);
10079 /* Read a Fortran module. */
10082 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10084 struct die_info
*child_die
= die
->child
;
10086 while (child_die
&& child_die
->tag
)
10088 process_die (child_die
, cu
);
10089 child_die
= sibling_die (child_die
);
10093 /* Return the name of the namespace represented by DIE. Set
10094 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
10097 static const char *
10098 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
10100 struct die_info
*current_die
;
10101 const char *name
= NULL
;
10103 /* Loop through the extensions until we find a name. */
10105 for (current_die
= die
;
10106 current_die
!= NULL
;
10107 current_die
= dwarf2_extension (die
, &cu
))
10109 name
= dwarf2_name (current_die
, cu
);
10114 /* Is it an anonymous namespace? */
10116 *is_anonymous
= (name
== NULL
);
10118 name
= CP_ANONYMOUS_NAMESPACE_STR
;
10123 /* Extract all information from a DW_TAG_pointer_type DIE and add to
10124 the user defined type vector. */
10126 static struct type
*
10127 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10129 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
10130 struct comp_unit_head
*cu_header
= &cu
->header
;
10132 struct attribute
*attr_byte_size
;
10133 struct attribute
*attr_address_class
;
10134 int byte_size
, addr_class
;
10135 struct type
*target_type
;
10137 target_type
= die_type (die
, cu
);
10139 /* The die_type call above may have already set the type for this DIE. */
10140 type
= get_die_type (die
, cu
);
10144 type
= lookup_pointer_type (target_type
);
10146 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10147 if (attr_byte_size
)
10148 byte_size
= DW_UNSND (attr_byte_size
);
10150 byte_size
= cu_header
->addr_size
;
10152 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
10153 if (attr_address_class
)
10154 addr_class
= DW_UNSND (attr_address_class
);
10156 addr_class
= DW_ADDR_none
;
10158 /* If the pointer size or address class is different than the
10159 default, create a type variant marked as such and set the
10160 length accordingly. */
10161 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
10163 if (gdbarch_address_class_type_flags_p (gdbarch
))
10167 type_flags
= gdbarch_address_class_type_flags
10168 (gdbarch
, byte_size
, addr_class
);
10169 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
10171 type
= make_type_with_address_space (type
, type_flags
);
10173 else if (TYPE_LENGTH (type
) != byte_size
)
10175 complaint (&symfile_complaints
,
10176 _("invalid pointer size %d"), byte_size
);
10180 /* Should we also complain about unhandled address classes? */
10184 TYPE_LENGTH (type
) = byte_size
;
10185 return set_die_type (die
, type
, cu
);
10188 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
10189 the user defined type vector. */
10191 static struct type
*
10192 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10195 struct type
*to_type
;
10196 struct type
*domain
;
10198 to_type
= die_type (die
, cu
);
10199 domain
= die_containing_type (die
, cu
);
10201 /* The calls above may have already set the type for this DIE. */
10202 type
= get_die_type (die
, cu
);
10206 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
10207 type
= lookup_methodptr_type (to_type
);
10209 type
= lookup_memberptr_type (to_type
, domain
);
10211 return set_die_type (die
, type
, cu
);
10214 /* Extract all information from a DW_TAG_reference_type DIE and add to
10215 the user defined type vector. */
10217 static struct type
*
10218 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10220 struct comp_unit_head
*cu_header
= &cu
->header
;
10221 struct type
*type
, *target_type
;
10222 struct attribute
*attr
;
10224 target_type
= die_type (die
, cu
);
10226 /* The die_type call above may have already set the type for this DIE. */
10227 type
= get_die_type (die
, cu
);
10231 type
= lookup_reference_type (target_type
);
10232 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10235 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10239 TYPE_LENGTH (type
) = cu_header
->addr_size
;
10241 return set_die_type (die
, type
, cu
);
10244 static struct type
*
10245 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10247 struct type
*base_type
, *cv_type
;
10249 base_type
= die_type (die
, cu
);
10251 /* The die_type call above may have already set the type for this DIE. */
10252 cv_type
= get_die_type (die
, cu
);
10256 /* In case the const qualifier is applied to an array type, the element type
10257 is so qualified, not the array type (section 6.7.3 of C99). */
10258 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10260 struct type
*el_type
, *inner_array
;
10262 base_type
= copy_type (base_type
);
10263 inner_array
= base_type
;
10265 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10267 TYPE_TARGET_TYPE (inner_array
) =
10268 copy_type (TYPE_TARGET_TYPE (inner_array
));
10269 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10272 el_type
= TYPE_TARGET_TYPE (inner_array
);
10273 TYPE_TARGET_TYPE (inner_array
) =
10274 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10276 return set_die_type (die
, base_type
, cu
);
10279 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10280 return set_die_type (die
, cv_type
, cu
);
10283 static struct type
*
10284 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10286 struct type
*base_type
, *cv_type
;
10288 base_type
= die_type (die
, cu
);
10290 /* The die_type call above may have already set the type for this DIE. */
10291 cv_type
= get_die_type (die
, cu
);
10295 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10296 return set_die_type (die
, cv_type
, cu
);
10299 /* Extract all information from a DW_TAG_string_type DIE and add to
10300 the user defined type vector. It isn't really a user defined type,
10301 but it behaves like one, with other DIE's using an AT_user_def_type
10302 attribute to reference it. */
10304 static struct type
*
10305 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10307 struct objfile
*objfile
= cu
->objfile
;
10308 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10309 struct type
*type
, *range_type
, *index_type
, *char_type
;
10310 struct attribute
*attr
;
10311 unsigned int length
;
10313 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10316 length
= DW_UNSND (attr
);
10320 /* Check for the DW_AT_byte_size attribute. */
10321 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10324 length
= DW_UNSND (attr
);
10332 index_type
= objfile_type (objfile
)->builtin_int
;
10333 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10334 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10335 type
= create_string_type (NULL
, char_type
, range_type
);
10337 return set_die_type (die
, type
, cu
);
10340 /* Handle DIES due to C code like:
10344 int (*funcp)(int a, long l);
10348 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10350 static struct type
*
10351 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10353 struct objfile
*objfile
= cu
->objfile
;
10354 struct type
*type
; /* Type that this function returns. */
10355 struct type
*ftype
; /* Function that returns above type. */
10356 struct attribute
*attr
;
10358 type
= die_type (die
, cu
);
10360 /* The die_type call above may have already set the type for this DIE. */
10361 ftype
= get_die_type (die
, cu
);
10365 ftype
= lookup_function_type (type
);
10367 /* All functions in C++, Pascal and Java have prototypes. */
10368 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10369 if ((attr
&& (DW_UNSND (attr
) != 0))
10370 || cu
->language
== language_cplus
10371 || cu
->language
== language_java
10372 || cu
->language
== language_pascal
)
10373 TYPE_PROTOTYPED (ftype
) = 1;
10374 else if (producer_is_realview (cu
->producer
))
10375 /* RealView does not emit DW_AT_prototyped. We can not
10376 distinguish prototyped and unprototyped functions; default to
10377 prototyped, since that is more common in modern code (and
10378 RealView warns about unprototyped functions). */
10379 TYPE_PROTOTYPED (ftype
) = 1;
10381 /* Store the calling convention in the type if it's available in
10382 the subroutine die. Otherwise set the calling convention to
10383 the default value DW_CC_normal. */
10384 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10386 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10387 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10388 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10390 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10392 /* We need to add the subroutine type to the die immediately so
10393 we don't infinitely recurse when dealing with parameters
10394 declared as the same subroutine type. */
10395 set_die_type (die
, ftype
, cu
);
10397 if (die
->child
!= NULL
)
10399 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10400 struct die_info
*child_die
;
10401 int nparams
, iparams
;
10403 /* Count the number of parameters.
10404 FIXME: GDB currently ignores vararg functions, but knows about
10405 vararg member functions. */
10407 child_die
= die
->child
;
10408 while (child_die
&& child_die
->tag
)
10410 if (child_die
->tag
== DW_TAG_formal_parameter
)
10412 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10413 TYPE_VARARGS (ftype
) = 1;
10414 child_die
= sibling_die (child_die
);
10417 /* Allocate storage for parameters and fill them in. */
10418 TYPE_NFIELDS (ftype
) = nparams
;
10419 TYPE_FIELDS (ftype
) = (struct field
*)
10420 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10422 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10423 even if we error out during the parameters reading below. */
10424 for (iparams
= 0; iparams
< nparams
; iparams
++)
10425 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10428 child_die
= die
->child
;
10429 while (child_die
&& child_die
->tag
)
10431 if (child_die
->tag
== DW_TAG_formal_parameter
)
10433 struct type
*arg_type
;
10435 /* DWARF version 2 has no clean way to discern C++
10436 static and non-static member functions. G++ helps
10437 GDB by marking the first parameter for non-static
10438 member functions (which is the this pointer) as
10439 artificial. We pass this information to
10440 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10442 DWARF version 3 added DW_AT_object_pointer, which GCC
10443 4.5 does not yet generate. */
10444 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10446 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10449 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10451 /* GCC/43521: In java, the formal parameter
10452 "this" is sometimes not marked with DW_AT_artificial. */
10453 if (cu
->language
== language_java
)
10455 const char *name
= dwarf2_name (child_die
, cu
);
10457 if (name
&& !strcmp (name
, "this"))
10458 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10461 arg_type
= die_type (child_die
, cu
);
10463 /* RealView does not mark THIS as const, which the testsuite
10464 expects. GCC marks THIS as const in method definitions,
10465 but not in the class specifications (GCC PR 43053). */
10466 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10467 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10470 struct dwarf2_cu
*arg_cu
= cu
;
10471 const char *name
= dwarf2_name (child_die
, cu
);
10473 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10476 /* If the compiler emits this, use it. */
10477 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10480 else if (name
&& strcmp (name
, "this") == 0)
10481 /* Function definitions will have the argument names. */
10483 else if (name
== NULL
&& iparams
== 0)
10484 /* Declarations may not have the names, so like
10485 elsewhere in GDB, assume an artificial first
10486 argument is "this". */
10490 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10494 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10497 child_die
= sibling_die (child_die
);
10504 static struct type
*
10505 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10507 struct objfile
*objfile
= cu
->objfile
;
10508 const char *name
= NULL
;
10509 struct type
*this_type
, *target_type
;
10511 name
= dwarf2_full_name (NULL
, die
, cu
);
10512 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10513 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10514 TYPE_NAME (this_type
) = (char *) name
;
10515 set_die_type (die
, this_type
, cu
);
10516 target_type
= die_type (die
, cu
);
10517 if (target_type
!= this_type
)
10518 TYPE_TARGET_TYPE (this_type
) = target_type
;
10521 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10522 spec and cause infinite loops in GDB. */
10523 complaint (&symfile_complaints
,
10524 _("Self-referential DW_TAG_typedef "
10525 "- DIE at 0x%x [in module %s]"),
10526 die
->offset
.sect_off
, objfile
->name
);
10527 TYPE_TARGET_TYPE (this_type
) = NULL
;
10532 /* Find a representation of a given base type and install
10533 it in the TYPE field of the die. */
10535 static struct type
*
10536 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10538 struct objfile
*objfile
= cu
->objfile
;
10540 struct attribute
*attr
;
10541 int encoding
= 0, size
= 0;
10543 enum type_code code
= TYPE_CODE_INT
;
10544 int type_flags
= 0;
10545 struct type
*target_type
= NULL
;
10547 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10550 encoding
= DW_UNSND (attr
);
10552 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10555 size
= DW_UNSND (attr
);
10557 name
= dwarf2_name (die
, cu
);
10560 complaint (&symfile_complaints
,
10561 _("DW_AT_name missing from DW_TAG_base_type"));
10566 case DW_ATE_address
:
10567 /* Turn DW_ATE_address into a void * pointer. */
10568 code
= TYPE_CODE_PTR
;
10569 type_flags
|= TYPE_FLAG_UNSIGNED
;
10570 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10572 case DW_ATE_boolean
:
10573 code
= TYPE_CODE_BOOL
;
10574 type_flags
|= TYPE_FLAG_UNSIGNED
;
10576 case DW_ATE_complex_float
:
10577 code
= TYPE_CODE_COMPLEX
;
10578 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10580 case DW_ATE_decimal_float
:
10581 code
= TYPE_CODE_DECFLOAT
;
10584 code
= TYPE_CODE_FLT
;
10586 case DW_ATE_signed
:
10588 case DW_ATE_unsigned
:
10589 type_flags
|= TYPE_FLAG_UNSIGNED
;
10590 if (cu
->language
== language_fortran
10592 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10593 code
= TYPE_CODE_CHAR
;
10595 case DW_ATE_signed_char
:
10596 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10597 || cu
->language
== language_pascal
10598 || cu
->language
== language_fortran
)
10599 code
= TYPE_CODE_CHAR
;
10601 case DW_ATE_unsigned_char
:
10602 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10603 || cu
->language
== language_pascal
10604 || cu
->language
== language_fortran
)
10605 code
= TYPE_CODE_CHAR
;
10606 type_flags
|= TYPE_FLAG_UNSIGNED
;
10609 /* We just treat this as an integer and then recognize the
10610 type by name elsewhere. */
10614 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10615 dwarf_type_encoding_name (encoding
));
10619 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10620 TYPE_NAME (type
) = name
;
10621 TYPE_TARGET_TYPE (type
) = target_type
;
10623 if (name
&& strcmp (name
, "char") == 0)
10624 TYPE_NOSIGN (type
) = 1;
10626 return set_die_type (die
, type
, cu
);
10629 /* Read the given DW_AT_subrange DIE. */
10631 static struct type
*
10632 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10634 struct type
*base_type
;
10635 struct type
*range_type
;
10636 struct attribute
*attr
;
10638 int low_default_is_valid
;
10640 LONGEST negative_mask
;
10642 base_type
= die_type (die
, cu
);
10643 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10644 check_typedef (base_type
);
10646 /* The die_type call above may have already set the type for this DIE. */
10647 range_type
= get_die_type (die
, cu
);
10651 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10652 omitting DW_AT_lower_bound. */
10653 switch (cu
->language
)
10656 case language_cplus
:
10658 low_default_is_valid
= 1;
10660 case language_fortran
:
10662 low_default_is_valid
= 1;
10665 case language_java
:
10666 case language_objc
:
10668 low_default_is_valid
= (cu
->header
.version
>= 4);
10672 case language_pascal
:
10674 low_default_is_valid
= (cu
->header
.version
>= 4);
10678 low_default_is_valid
= 0;
10682 /* FIXME: For variable sized arrays either of these could be
10683 a variable rather than a constant value. We'll allow it,
10684 but we don't know how to handle it. */
10685 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10687 low
= dwarf2_get_attr_constant_value (attr
, low
);
10688 else if (!low_default_is_valid
)
10689 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10690 "- DIE at 0x%x [in module %s]"),
10691 die
->offset
.sect_off
, cu
->objfile
->name
);
10693 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10696 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10698 /* GCC encodes arrays with unspecified or dynamic length
10699 with a DW_FORM_block1 attribute or a reference attribute.
10700 FIXME: GDB does not yet know how to handle dynamic
10701 arrays properly, treat them as arrays with unspecified
10704 FIXME: jimb/2003-09-22: GDB does not really know
10705 how to handle arrays of unspecified length
10706 either; we just represent them as zero-length
10707 arrays. Choose an appropriate upper bound given
10708 the lower bound we've computed above. */
10712 high
= dwarf2_get_attr_constant_value (attr
, 1);
10716 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10719 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10720 high
= low
+ count
- 1;
10724 /* Unspecified array length. */
10729 /* Dwarf-2 specifications explicitly allows to create subrange types
10730 without specifying a base type.
10731 In that case, the base type must be set to the type of
10732 the lower bound, upper bound or count, in that order, if any of these
10733 three attributes references an object that has a type.
10734 If no base type is found, the Dwarf-2 specifications say that
10735 a signed integer type of size equal to the size of an address should
10737 For the following C code: `extern char gdb_int [];'
10738 GCC produces an empty range DIE.
10739 FIXME: muller/2010-05-28: Possible references to object for low bound,
10740 high bound or count are not yet handled by this code. */
10741 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10743 struct objfile
*objfile
= cu
->objfile
;
10744 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10745 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10746 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10748 /* Test "int", "long int", and "long long int" objfile types,
10749 and select the first one having a size above or equal to the
10750 architecture address size. */
10751 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10752 base_type
= int_type
;
10755 int_type
= objfile_type (objfile
)->builtin_long
;
10756 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10757 base_type
= int_type
;
10760 int_type
= objfile_type (objfile
)->builtin_long_long
;
10761 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10762 base_type
= int_type
;
10768 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10769 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10770 low
|= negative_mask
;
10771 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10772 high
|= negative_mask
;
10774 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10776 /* Mark arrays with dynamic length at least as an array of unspecified
10777 length. GDB could check the boundary but before it gets implemented at
10778 least allow accessing the array elements. */
10779 if (attr
&& attr_form_is_block (attr
))
10780 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10782 /* Ada expects an empty array on no boundary attributes. */
10783 if (attr
== NULL
&& cu
->language
!= language_ada
)
10784 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10786 name
= dwarf2_name (die
, cu
);
10788 TYPE_NAME (range_type
) = name
;
10790 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10792 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10794 set_die_type (die
, range_type
, cu
);
10796 /* set_die_type should be already done. */
10797 set_descriptive_type (range_type
, die
, cu
);
10802 static struct type
*
10803 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10807 /* For now, we only support the C meaning of an unspecified type: void. */
10809 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10810 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10812 return set_die_type (die
, type
, cu
);
10815 /* Read a single die and all its descendents. Set the die's sibling
10816 field to NULL; set other fields in the die correctly, and set all
10817 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10818 location of the info_ptr after reading all of those dies. PARENT
10819 is the parent of the die in question. */
10821 static struct die_info
*
10822 read_die_and_children (const struct die_reader_specs
*reader
,
10823 gdb_byte
*info_ptr
,
10824 gdb_byte
**new_info_ptr
,
10825 struct die_info
*parent
)
10827 struct die_info
*die
;
10831 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10834 *new_info_ptr
= cur_ptr
;
10837 store_in_ref_table (die
, reader
->cu
);
10840 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10844 *new_info_ptr
= cur_ptr
;
10847 die
->sibling
= NULL
;
10848 die
->parent
= parent
;
10852 /* Read a die, all of its descendents, and all of its siblings; set
10853 all of the fields of all of the dies correctly. Arguments are as
10854 in read_die_and_children. */
10856 static struct die_info
*
10857 read_die_and_siblings (const struct die_reader_specs
*reader
,
10858 gdb_byte
*info_ptr
,
10859 gdb_byte
**new_info_ptr
,
10860 struct die_info
*parent
)
10862 struct die_info
*first_die
, *last_sibling
;
10865 cur_ptr
= info_ptr
;
10866 first_die
= last_sibling
= NULL
;
10870 struct die_info
*die
10871 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10875 *new_info_ptr
= cur_ptr
;
10882 last_sibling
->sibling
= die
;
10884 last_sibling
= die
;
10888 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10890 The caller is responsible for filling in the extra attributes
10891 and updating (*DIEP)->num_attrs.
10892 Set DIEP to point to a newly allocated die with its information,
10893 except for its child, sibling, and parent fields.
10894 Set HAS_CHILDREN to tell whether the die has children or not. */
10897 read_full_die_1 (const struct die_reader_specs
*reader
,
10898 struct die_info
**diep
, gdb_byte
*info_ptr
,
10899 int *has_children
, int num_extra_attrs
)
10901 unsigned int abbrev_number
, bytes_read
, i
;
10902 sect_offset offset
;
10903 struct abbrev_info
*abbrev
;
10904 struct die_info
*die
;
10905 struct dwarf2_cu
*cu
= reader
->cu
;
10906 bfd
*abfd
= reader
->abfd
;
10908 offset
.sect_off
= info_ptr
- reader
->buffer
;
10909 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10910 info_ptr
+= bytes_read
;
10911 if (!abbrev_number
)
10918 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10920 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10922 bfd_get_filename (abfd
));
10924 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10925 die
->offset
= offset
;
10926 die
->tag
= abbrev
->tag
;
10927 die
->abbrev
= abbrev_number
;
10929 /* Make the result usable.
10930 The caller needs to update num_attrs after adding the extra
10932 die
->num_attrs
= abbrev
->num_attrs
;
10934 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10935 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10939 *has_children
= abbrev
->has_children
;
10943 /* Read a die and all its attributes.
10944 Set DIEP to point to a newly allocated die with its information,
10945 except for its child, sibling, and parent fields.
10946 Set HAS_CHILDREN to tell whether the die has children or not. */
10949 read_full_die (const struct die_reader_specs
*reader
,
10950 struct die_info
**diep
, gdb_byte
*info_ptr
,
10953 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10956 /* In DWARF version 2, the description of the debugging information is
10957 stored in a separate .debug_abbrev section. Before we read any
10958 dies from a section we read in all abbreviations and install them
10959 in a hash table. This function also sets flags in CU describing
10960 the data found in the abbrev table. */
10963 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10964 struct dwarf2_section_info
*abbrev_section
)
10967 bfd
*abfd
= abbrev_section
->asection
->owner
;
10968 struct comp_unit_head
*cu_header
= &cu
->header
;
10969 gdb_byte
*abbrev_ptr
;
10970 struct abbrev_info
*cur_abbrev
;
10971 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10972 unsigned int abbrev_form
, hash_number
;
10973 struct attr_abbrev
*cur_attrs
;
10974 unsigned int allocated_attrs
;
10976 /* Initialize dwarf2 abbrevs. */
10977 obstack_init (&cu
->abbrev_obstack
);
10978 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10980 * sizeof (struct abbrev_info
*)));
10981 memset (cu
->dwarf2_abbrevs
, 0,
10982 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10984 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10985 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10986 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10987 abbrev_ptr
+= bytes_read
;
10989 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10990 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10992 /* Loop until we reach an abbrev number of 0. */
10993 while (abbrev_number
)
10995 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10997 /* read in abbrev header */
10998 cur_abbrev
->number
= abbrev_number
;
10999 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11000 abbrev_ptr
+= bytes_read
;
11001 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
11004 /* now read in declarations */
11005 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11006 abbrev_ptr
+= bytes_read
;
11007 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11008 abbrev_ptr
+= bytes_read
;
11009 while (abbrev_name
)
11011 if (cur_abbrev
->num_attrs
== allocated_attrs
)
11013 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
11015 = xrealloc (cur_attrs
, (allocated_attrs
11016 * sizeof (struct attr_abbrev
)));
11019 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
11020 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
11021 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11022 abbrev_ptr
+= bytes_read
;
11023 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11024 abbrev_ptr
+= bytes_read
;
11027 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
11028 (cur_abbrev
->num_attrs
11029 * sizeof (struct attr_abbrev
)));
11030 memcpy (cur_abbrev
->attrs
, cur_attrs
,
11031 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
11033 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11034 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
11035 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
11037 /* Get next abbreviation.
11038 Under Irix6 the abbreviations for a compilation unit are not
11039 always properly terminated with an abbrev number of 0.
11040 Exit loop if we encounter an abbreviation which we have
11041 already read (which means we are about to read the abbreviations
11042 for the next compile unit) or if the end of the abbreviation
11043 table is reached. */
11044 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
11045 >= abbrev_section
->size
)
11047 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11048 abbrev_ptr
+= bytes_read
;
11049 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
11056 /* Release the memory used by the abbrev table for a compilation unit. */
11059 dwarf2_free_abbrev_table (void *ptr_to_cu
)
11061 struct dwarf2_cu
*cu
= ptr_to_cu
;
11063 obstack_free (&cu
->abbrev_obstack
, NULL
);
11064 cu
->dwarf2_abbrevs
= NULL
;
11067 /* Lookup an abbrev_info structure in the abbrev hash table. */
11069 static struct abbrev_info
*
11070 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
11072 unsigned int hash_number
;
11073 struct abbrev_info
*abbrev
;
11075 hash_number
= number
% ABBREV_HASH_SIZE
;
11076 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
11080 if (abbrev
->number
== number
)
11083 abbrev
= abbrev
->next
;
11088 /* Returns nonzero if TAG represents a type that we might generate a partial
11092 is_type_tag_for_partial (int tag
)
11097 /* Some types that would be reasonable to generate partial symbols for,
11098 that we don't at present. */
11099 case DW_TAG_array_type
:
11100 case DW_TAG_file_type
:
11101 case DW_TAG_ptr_to_member_type
:
11102 case DW_TAG_set_type
:
11103 case DW_TAG_string_type
:
11104 case DW_TAG_subroutine_type
:
11106 case DW_TAG_base_type
:
11107 case DW_TAG_class_type
:
11108 case DW_TAG_interface_type
:
11109 case DW_TAG_enumeration_type
:
11110 case DW_TAG_structure_type
:
11111 case DW_TAG_subrange_type
:
11112 case DW_TAG_typedef
:
11113 case DW_TAG_union_type
:
11120 /* Load all DIEs that are interesting for partial symbols into memory. */
11122 static struct partial_die_info
*
11123 load_partial_dies (const struct die_reader_specs
*reader
,
11124 gdb_byte
*info_ptr
, int building_psymtab
)
11126 struct dwarf2_cu
*cu
= reader
->cu
;
11127 struct objfile
*objfile
= cu
->objfile
;
11128 struct partial_die_info
*part_die
;
11129 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
11130 struct abbrev_info
*abbrev
;
11131 unsigned int bytes_read
;
11132 unsigned int load_all
= 0;
11133 int nesting_level
= 1;
11138 gdb_assert (cu
->per_cu
!= NULL
);
11139 if (cu
->per_cu
->load_all_dies
)
11143 = htab_create_alloc_ex (cu
->header
.length
/ 12,
11147 &cu
->comp_unit_obstack
,
11148 hashtab_obstack_allocate
,
11149 dummy_obstack_deallocate
);
11151 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11152 sizeof (struct partial_die_info
));
11156 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
11158 /* A NULL abbrev means the end of a series of children. */
11159 if (abbrev
== NULL
)
11161 if (--nesting_level
== 0)
11163 /* PART_DIE was probably the last thing allocated on the
11164 comp_unit_obstack, so we could call obstack_free
11165 here. We don't do that because the waste is small,
11166 and will be cleaned up when we're done with this
11167 compilation unit. This way, we're also more robust
11168 against other users of the comp_unit_obstack. */
11171 info_ptr
+= bytes_read
;
11172 last_die
= parent_die
;
11173 parent_die
= parent_die
->die_parent
;
11177 /* Check for template arguments. We never save these; if
11178 they're seen, we just mark the parent, and go on our way. */
11179 if (parent_die
!= NULL
11180 && cu
->language
== language_cplus
11181 && (abbrev
->tag
== DW_TAG_template_type_param
11182 || abbrev
->tag
== DW_TAG_template_value_param
))
11184 parent_die
->has_template_arguments
= 1;
11188 /* We don't need a partial DIE for the template argument. */
11189 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11194 /* We only recurse into c++ subprograms looking for template arguments.
11195 Skip their other children. */
11197 && cu
->language
== language_cplus
11198 && parent_die
!= NULL
11199 && parent_die
->tag
== DW_TAG_subprogram
)
11201 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11205 /* Check whether this DIE is interesting enough to save. Normally
11206 we would not be interested in members here, but there may be
11207 later variables referencing them via DW_AT_specification (for
11208 static members). */
11210 && !is_type_tag_for_partial (abbrev
->tag
)
11211 && abbrev
->tag
!= DW_TAG_constant
11212 && abbrev
->tag
!= DW_TAG_enumerator
11213 && abbrev
->tag
!= DW_TAG_subprogram
11214 && abbrev
->tag
!= DW_TAG_lexical_block
11215 && abbrev
->tag
!= DW_TAG_variable
11216 && abbrev
->tag
!= DW_TAG_namespace
11217 && abbrev
->tag
!= DW_TAG_module
11218 && abbrev
->tag
!= DW_TAG_member
11219 && abbrev
->tag
!= DW_TAG_imported_unit
)
11221 /* Otherwise we skip to the next sibling, if any. */
11222 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11226 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
11229 /* This two-pass algorithm for processing partial symbols has a
11230 high cost in cache pressure. Thus, handle some simple cases
11231 here which cover the majority of C partial symbols. DIEs
11232 which neither have specification tags in them, nor could have
11233 specification tags elsewhere pointing at them, can simply be
11234 processed and discarded.
11236 This segment is also optional; scan_partial_symbols and
11237 add_partial_symbol will handle these DIEs if we chain
11238 them in normally. When compilers which do not emit large
11239 quantities of duplicate debug information are more common,
11240 this code can probably be removed. */
11242 /* Any complete simple types at the top level (pretty much all
11243 of them, for a language without namespaces), can be processed
11245 if (parent_die
== NULL
11246 && part_die
->has_specification
== 0
11247 && part_die
->is_declaration
== 0
11248 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11249 || part_die
->tag
== DW_TAG_base_type
11250 || part_die
->tag
== DW_TAG_subrange_type
))
11252 if (building_psymtab
&& part_die
->name
!= NULL
)
11253 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11254 VAR_DOMAIN
, LOC_TYPEDEF
,
11255 &objfile
->static_psymbols
,
11256 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11257 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11261 /* The exception for DW_TAG_typedef with has_children above is
11262 a workaround of GCC PR debug/47510. In the case of this complaint
11263 type_name_no_tag_or_error will error on such types later.
11265 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11266 it could not find the child DIEs referenced later, this is checked
11267 above. In correct DWARF DW_TAG_typedef should have no children. */
11269 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11270 complaint (&symfile_complaints
,
11271 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11272 "- DIE at 0x%x [in module %s]"),
11273 part_die
->offset
.sect_off
, objfile
->name
);
11275 /* If we're at the second level, and we're an enumerator, and
11276 our parent has no specification (meaning possibly lives in a
11277 namespace elsewhere), then we can add the partial symbol now
11278 instead of queueing it. */
11279 if (part_die
->tag
== DW_TAG_enumerator
11280 && parent_die
!= NULL
11281 && parent_die
->die_parent
== NULL
11282 && parent_die
->tag
== DW_TAG_enumeration_type
11283 && parent_die
->has_specification
== 0)
11285 if (part_die
->name
== NULL
)
11286 complaint (&symfile_complaints
,
11287 _("malformed enumerator DIE ignored"));
11288 else if (building_psymtab
)
11289 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11290 VAR_DOMAIN
, LOC_CONST
,
11291 (cu
->language
== language_cplus
11292 || cu
->language
== language_java
)
11293 ? &objfile
->global_psymbols
11294 : &objfile
->static_psymbols
,
11295 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11297 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11301 /* We'll save this DIE so link it in. */
11302 part_die
->die_parent
= parent_die
;
11303 part_die
->die_sibling
= NULL
;
11304 part_die
->die_child
= NULL
;
11306 if (last_die
&& last_die
== parent_die
)
11307 last_die
->die_child
= part_die
;
11309 last_die
->die_sibling
= part_die
;
11311 last_die
= part_die
;
11313 if (first_die
== NULL
)
11314 first_die
= part_die
;
11316 /* Maybe add the DIE to the hash table. Not all DIEs that we
11317 find interesting need to be in the hash table, because we
11318 also have the parent/sibling/child chains; only those that we
11319 might refer to by offset later during partial symbol reading.
11321 For now this means things that might have be the target of a
11322 DW_AT_specification, DW_AT_abstract_origin, or
11323 DW_AT_extension. DW_AT_extension will refer only to
11324 namespaces; DW_AT_abstract_origin refers to functions (and
11325 many things under the function DIE, but we do not recurse
11326 into function DIEs during partial symbol reading) and
11327 possibly variables as well; DW_AT_specification refers to
11328 declarations. Declarations ought to have the DW_AT_declaration
11329 flag. It happens that GCC forgets to put it in sometimes, but
11330 only for functions, not for types.
11332 Adding more things than necessary to the hash table is harmless
11333 except for the performance cost. Adding too few will result in
11334 wasted time in find_partial_die, when we reread the compilation
11335 unit with load_all_dies set. */
11338 || abbrev
->tag
== DW_TAG_constant
11339 || abbrev
->tag
== DW_TAG_subprogram
11340 || abbrev
->tag
== DW_TAG_variable
11341 || abbrev
->tag
== DW_TAG_namespace
11342 || part_die
->is_declaration
)
11346 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11347 part_die
->offset
.sect_off
, INSERT
);
11351 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11352 sizeof (struct partial_die_info
));
11354 /* For some DIEs we want to follow their children (if any). For C
11355 we have no reason to follow the children of structures; for other
11356 languages we have to, so that we can get at method physnames
11357 to infer fully qualified class names, for DW_AT_specification,
11358 and for C++ template arguments. For C++, we also look one level
11359 inside functions to find template arguments (if the name of the
11360 function does not already contain the template arguments).
11362 For Ada, we need to scan the children of subprograms and lexical
11363 blocks as well because Ada allows the definition of nested
11364 entities that could be interesting for the debugger, such as
11365 nested subprograms for instance. */
11366 if (last_die
->has_children
11368 || last_die
->tag
== DW_TAG_namespace
11369 || last_die
->tag
== DW_TAG_module
11370 || last_die
->tag
== DW_TAG_enumeration_type
11371 || (cu
->language
== language_cplus
11372 && last_die
->tag
== DW_TAG_subprogram
11373 && (last_die
->name
== NULL
11374 || strchr (last_die
->name
, '<') == NULL
))
11375 || (cu
->language
!= language_c
11376 && (last_die
->tag
== DW_TAG_class_type
11377 || last_die
->tag
== DW_TAG_interface_type
11378 || last_die
->tag
== DW_TAG_structure_type
11379 || last_die
->tag
== DW_TAG_union_type
))
11380 || (cu
->language
== language_ada
11381 && (last_die
->tag
== DW_TAG_subprogram
11382 || last_die
->tag
== DW_TAG_lexical_block
))))
11385 parent_die
= last_die
;
11389 /* Otherwise we skip to the next sibling, if any. */
11390 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11392 /* Back to the top, do it again. */
11396 /* Read a minimal amount of information into the minimal die structure. */
11399 read_partial_die (const struct die_reader_specs
*reader
,
11400 struct partial_die_info
*part_die
,
11401 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11402 gdb_byte
*info_ptr
)
11404 struct dwarf2_cu
*cu
= reader
->cu
;
11405 struct objfile
*objfile
= cu
->objfile
;
11406 gdb_byte
*buffer
= reader
->buffer
;
11408 struct attribute attr
;
11409 int has_low_pc_attr
= 0;
11410 int has_high_pc_attr
= 0;
11411 int high_pc_relative
= 0;
11413 memset (part_die
, 0, sizeof (struct partial_die_info
));
11415 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11417 info_ptr
+= abbrev_len
;
11419 if (abbrev
== NULL
)
11422 part_die
->tag
= abbrev
->tag
;
11423 part_die
->has_children
= abbrev
->has_children
;
11425 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11427 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11429 /* Store the data if it is of an attribute we want to keep in a
11430 partial symbol table. */
11434 switch (part_die
->tag
)
11436 case DW_TAG_compile_unit
:
11437 case DW_TAG_partial_unit
:
11438 case DW_TAG_type_unit
:
11439 /* Compilation units have a DW_AT_name that is a filename, not
11440 a source language identifier. */
11441 case DW_TAG_enumeration_type
:
11442 case DW_TAG_enumerator
:
11443 /* These tags always have simple identifiers already; no need
11444 to canonicalize them. */
11445 part_die
->name
= DW_STRING (&attr
);
11449 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11450 &objfile
->objfile_obstack
);
11454 case DW_AT_linkage_name
:
11455 case DW_AT_MIPS_linkage_name
:
11456 /* Note that both forms of linkage name might appear. We
11457 assume they will be the same, and we only store the last
11459 if (cu
->language
== language_ada
)
11460 part_die
->name
= DW_STRING (&attr
);
11461 part_die
->linkage_name
= DW_STRING (&attr
);
11464 has_low_pc_attr
= 1;
11465 part_die
->lowpc
= DW_ADDR (&attr
);
11467 case DW_AT_high_pc
:
11468 has_high_pc_attr
= 1;
11469 if (attr
.form
== DW_FORM_addr
11470 || attr
.form
== DW_FORM_GNU_addr_index
)
11471 part_die
->highpc
= DW_ADDR (&attr
);
11474 high_pc_relative
= 1;
11475 part_die
->highpc
= DW_UNSND (&attr
);
11478 case DW_AT_location
:
11479 /* Support the .debug_loc offsets. */
11480 if (attr_form_is_block (&attr
))
11482 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11484 else if (attr_form_is_section_offset (&attr
))
11486 dwarf2_complex_location_expr_complaint ();
11490 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11491 "partial symbol information");
11494 case DW_AT_external
:
11495 part_die
->is_external
= DW_UNSND (&attr
);
11497 case DW_AT_declaration
:
11498 part_die
->is_declaration
= DW_UNSND (&attr
);
11501 part_die
->has_type
= 1;
11503 case DW_AT_abstract_origin
:
11504 case DW_AT_specification
:
11505 case DW_AT_extension
:
11506 part_die
->has_specification
= 1;
11507 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11509 case DW_AT_sibling
:
11510 /* Ignore absolute siblings, they might point outside of
11511 the current compile unit. */
11512 if (attr
.form
== DW_FORM_ref_addr
)
11513 complaint (&symfile_complaints
,
11514 _("ignoring absolute DW_AT_sibling"));
11516 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11518 case DW_AT_byte_size
:
11519 part_die
->has_byte_size
= 1;
11521 case DW_AT_calling_convention
:
11522 /* DWARF doesn't provide a way to identify a program's source-level
11523 entry point. DW_AT_calling_convention attributes are only meant
11524 to describe functions' calling conventions.
11526 However, because it's a necessary piece of information in
11527 Fortran, and because DW_CC_program is the only piece of debugging
11528 information whose definition refers to a 'main program' at all,
11529 several compilers have begun marking Fortran main programs with
11530 DW_CC_program --- even when those functions use the standard
11531 calling conventions.
11533 So until DWARF specifies a way to provide this information and
11534 compilers pick up the new representation, we'll support this
11536 if (DW_UNSND (&attr
) == DW_CC_program
11537 && cu
->language
== language_fortran
)
11539 set_main_name (part_die
->name
);
11541 /* As this DIE has a static linkage the name would be difficult
11542 to look up later. */
11543 language_of_main
= language_fortran
;
11547 if (DW_UNSND (&attr
) == DW_INL_inlined
11548 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11549 part_die
->may_be_inlined
= 1;
11553 if (part_die
->tag
== DW_TAG_imported_unit
)
11554 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11562 if (high_pc_relative
)
11563 part_die
->highpc
+= part_die
->lowpc
;
11565 if (has_low_pc_attr
&& has_high_pc_attr
)
11567 /* When using the GNU linker, .gnu.linkonce. sections are used to
11568 eliminate duplicate copies of functions and vtables and such.
11569 The linker will arbitrarily choose one and discard the others.
11570 The AT_*_pc values for such functions refer to local labels in
11571 these sections. If the section from that file was discarded, the
11572 labels are not in the output, so the relocs get a value of 0.
11573 If this is a discarded function, mark the pc bounds as invalid,
11574 so that GDB will ignore it. */
11575 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11577 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11579 complaint (&symfile_complaints
,
11580 _("DW_AT_low_pc %s is zero "
11581 "for DIE at 0x%x [in module %s]"),
11582 paddress (gdbarch
, part_die
->lowpc
),
11583 part_die
->offset
.sect_off
, objfile
->name
);
11585 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11586 else if (part_die
->lowpc
>= part_die
->highpc
)
11588 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11590 complaint (&symfile_complaints
,
11591 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11592 "for DIE at 0x%x [in module %s]"),
11593 paddress (gdbarch
, part_die
->lowpc
),
11594 paddress (gdbarch
, part_die
->highpc
),
11595 part_die
->offset
.sect_off
, objfile
->name
);
11598 part_die
->has_pc_info
= 1;
11604 /* Find a cached partial DIE at OFFSET in CU. */
11606 static struct partial_die_info
*
11607 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11609 struct partial_die_info
*lookup_die
= NULL
;
11610 struct partial_die_info part_die
;
11612 part_die
.offset
= offset
;
11613 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11619 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11620 except in the case of .debug_types DIEs which do not reference
11621 outside their CU (they do however referencing other types via
11622 DW_FORM_ref_sig8). */
11624 static struct partial_die_info
*
11625 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11627 struct objfile
*objfile
= cu
->objfile
;
11628 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11629 struct partial_die_info
*pd
= NULL
;
11631 if (offset_in_cu_p (&cu
->header
, offset
))
11633 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11636 /* We missed recording what we needed.
11637 Load all dies and try again. */
11638 per_cu
= cu
->per_cu
;
11642 /* TUs don't reference other CUs/TUs (except via type signatures). */
11643 if (cu
->per_cu
->is_debug_types
)
11645 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11646 " external reference to offset 0x%lx [in module %s].\n"),
11647 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11648 bfd_get_filename (objfile
->obfd
));
11650 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11652 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11653 load_partial_comp_unit (per_cu
);
11655 per_cu
->cu
->last_used
= 0;
11656 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11659 /* If we didn't find it, and not all dies have been loaded,
11660 load them all and try again. */
11662 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11664 per_cu
->load_all_dies
= 1;
11666 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11667 THIS_CU->cu may already be in use. So we can't just free it and
11668 replace its DIEs with the ones we read in. Instead, we leave those
11669 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11670 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11672 load_partial_comp_unit (per_cu
);
11674 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11678 internal_error (__FILE__
, __LINE__
,
11679 _("could not find partial DIE 0x%x "
11680 "in cache [from module %s]\n"),
11681 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11685 /* See if we can figure out if the class lives in a namespace. We do
11686 this by looking for a member function; its demangled name will
11687 contain namespace info, if there is any. */
11690 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11691 struct dwarf2_cu
*cu
)
11693 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11694 what template types look like, because the demangler
11695 frequently doesn't give the same name as the debug info. We
11696 could fix this by only using the demangled name to get the
11697 prefix (but see comment in read_structure_type). */
11699 struct partial_die_info
*real_pdi
;
11700 struct partial_die_info
*child_pdi
;
11702 /* If this DIE (this DIE's specification, if any) has a parent, then
11703 we should not do this. We'll prepend the parent's fully qualified
11704 name when we create the partial symbol. */
11706 real_pdi
= struct_pdi
;
11707 while (real_pdi
->has_specification
)
11708 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11710 if (real_pdi
->die_parent
!= NULL
)
11713 for (child_pdi
= struct_pdi
->die_child
;
11715 child_pdi
= child_pdi
->die_sibling
)
11717 if (child_pdi
->tag
== DW_TAG_subprogram
11718 && child_pdi
->linkage_name
!= NULL
)
11720 char *actual_class_name
11721 = language_class_name_from_physname (cu
->language_defn
,
11722 child_pdi
->linkage_name
);
11723 if (actual_class_name
!= NULL
)
11726 = obsavestring (actual_class_name
,
11727 strlen (actual_class_name
),
11728 &cu
->objfile
->objfile_obstack
);
11729 xfree (actual_class_name
);
11736 /* Adjust PART_DIE before generating a symbol for it. This function
11737 may set the is_external flag or change the DIE's name. */
11740 fixup_partial_die (struct partial_die_info
*part_die
,
11741 struct dwarf2_cu
*cu
)
11743 /* Once we've fixed up a die, there's no point in doing so again.
11744 This also avoids a memory leak if we were to call
11745 guess_partial_die_structure_name multiple times. */
11746 if (part_die
->fixup_called
)
11749 /* If we found a reference attribute and the DIE has no name, try
11750 to find a name in the referred to DIE. */
11752 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11754 struct partial_die_info
*spec_die
;
11756 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11758 fixup_partial_die (spec_die
, cu
);
11760 if (spec_die
->name
)
11762 part_die
->name
= spec_die
->name
;
11764 /* Copy DW_AT_external attribute if it is set. */
11765 if (spec_die
->is_external
)
11766 part_die
->is_external
= spec_die
->is_external
;
11770 /* Set default names for some unnamed DIEs. */
11772 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11773 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11775 /* If there is no parent die to provide a namespace, and there are
11776 children, see if we can determine the namespace from their linkage
11778 if (cu
->language
== language_cplus
11779 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11780 && part_die
->die_parent
== NULL
11781 && part_die
->has_children
11782 && (part_die
->tag
== DW_TAG_class_type
11783 || part_die
->tag
== DW_TAG_structure_type
11784 || part_die
->tag
== DW_TAG_union_type
))
11785 guess_partial_die_structure_name (part_die
, cu
);
11787 /* GCC might emit a nameless struct or union that has a linkage
11788 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11789 if (part_die
->name
== NULL
11790 && (part_die
->tag
== DW_TAG_class_type
11791 || part_die
->tag
== DW_TAG_interface_type
11792 || part_die
->tag
== DW_TAG_structure_type
11793 || part_die
->tag
== DW_TAG_union_type
)
11794 && part_die
->linkage_name
!= NULL
)
11798 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11803 /* Strip any leading namespaces/classes, keep only the base name.
11804 DW_AT_name for named DIEs does not contain the prefixes. */
11805 base
= strrchr (demangled
, ':');
11806 if (base
&& base
> demangled
&& base
[-1] == ':')
11811 part_die
->name
= obsavestring (base
, strlen (base
),
11812 &cu
->objfile
->objfile_obstack
);
11817 part_die
->fixup_called
= 1;
11820 /* Read an attribute value described by an attribute form. */
11823 read_attribute_value (const struct die_reader_specs
*reader
,
11824 struct attribute
*attr
, unsigned form
,
11825 gdb_byte
*info_ptr
)
11827 struct dwarf2_cu
*cu
= reader
->cu
;
11828 bfd
*abfd
= reader
->abfd
;
11829 struct comp_unit_head
*cu_header
= &cu
->header
;
11830 unsigned int bytes_read
;
11831 struct dwarf_block
*blk
;
11836 case DW_FORM_ref_addr
:
11837 if (cu
->header
.version
== 2)
11838 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11840 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11841 &cu
->header
, &bytes_read
);
11842 info_ptr
+= bytes_read
;
11845 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11846 info_ptr
+= bytes_read
;
11848 case DW_FORM_block2
:
11849 blk
= dwarf_alloc_block (cu
);
11850 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11852 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11853 info_ptr
+= blk
->size
;
11854 DW_BLOCK (attr
) = blk
;
11856 case DW_FORM_block4
:
11857 blk
= dwarf_alloc_block (cu
);
11858 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11860 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11861 info_ptr
+= blk
->size
;
11862 DW_BLOCK (attr
) = blk
;
11864 case DW_FORM_data2
:
11865 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11868 case DW_FORM_data4
:
11869 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11872 case DW_FORM_data8
:
11873 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11876 case DW_FORM_sec_offset
:
11877 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11878 info_ptr
+= bytes_read
;
11880 case DW_FORM_string
:
11881 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11882 DW_STRING_IS_CANONICAL (attr
) = 0;
11883 info_ptr
+= bytes_read
;
11886 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11888 DW_STRING_IS_CANONICAL (attr
) = 0;
11889 info_ptr
+= bytes_read
;
11891 case DW_FORM_exprloc
:
11892 case DW_FORM_block
:
11893 blk
= dwarf_alloc_block (cu
);
11894 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11895 info_ptr
+= bytes_read
;
11896 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11897 info_ptr
+= blk
->size
;
11898 DW_BLOCK (attr
) = blk
;
11900 case DW_FORM_block1
:
11901 blk
= dwarf_alloc_block (cu
);
11902 blk
->size
= read_1_byte (abfd
, info_ptr
);
11904 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11905 info_ptr
+= blk
->size
;
11906 DW_BLOCK (attr
) = blk
;
11908 case DW_FORM_data1
:
11909 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11913 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11916 case DW_FORM_flag_present
:
11917 DW_UNSND (attr
) = 1;
11919 case DW_FORM_sdata
:
11920 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11921 info_ptr
+= bytes_read
;
11923 case DW_FORM_udata
:
11924 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11925 info_ptr
+= bytes_read
;
11928 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11929 + read_1_byte (abfd
, info_ptr
));
11933 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11934 + read_2_bytes (abfd
, info_ptr
));
11938 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11939 + read_4_bytes (abfd
, info_ptr
));
11943 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11944 + read_8_bytes (abfd
, info_ptr
));
11947 case DW_FORM_ref_sig8
:
11948 /* Convert the signature to something we can record in DW_UNSND
11950 NOTE: This is NULL if the type wasn't found. */
11951 DW_SIGNATURED_TYPE (attr
) =
11952 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11955 case DW_FORM_ref_udata
:
11956 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11957 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11958 info_ptr
+= bytes_read
;
11960 case DW_FORM_indirect
:
11961 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11962 info_ptr
+= bytes_read
;
11963 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11965 case DW_FORM_GNU_addr_index
:
11966 if (reader
->dwo_file
== NULL
)
11968 /* For now flag a hard error.
11969 Later we can turn this into a complaint. */
11970 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11971 dwarf_form_name (form
),
11972 bfd_get_filename (abfd
));
11974 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11975 info_ptr
+= bytes_read
;
11977 case DW_FORM_GNU_str_index
:
11978 if (reader
->dwo_file
== NULL
)
11980 /* For now flag a hard error.
11981 Later we can turn this into a complaint if warranted. */
11982 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11983 dwarf_form_name (form
),
11984 bfd_get_filename (abfd
));
11987 ULONGEST str_index
=
11988 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11990 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11991 DW_STRING_IS_CANONICAL (attr
) = 0;
11992 info_ptr
+= bytes_read
;
11996 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11997 dwarf_form_name (form
),
11998 bfd_get_filename (abfd
));
12001 /* We have seen instances where the compiler tried to emit a byte
12002 size attribute of -1 which ended up being encoded as an unsigned
12003 0xffffffff. Although 0xffffffff is technically a valid size value,
12004 an object of this size seems pretty unlikely so we can relatively
12005 safely treat these cases as if the size attribute was invalid and
12006 treat them as zero by default. */
12007 if (attr
->name
== DW_AT_byte_size
12008 && form
== DW_FORM_data4
12009 && DW_UNSND (attr
) >= 0xffffffff)
12012 (&symfile_complaints
,
12013 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12014 hex_string (DW_UNSND (attr
)));
12015 DW_UNSND (attr
) = 0;
12021 /* Read an attribute described by an abbreviated attribute. */
12024 read_attribute (const struct die_reader_specs
*reader
,
12025 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12026 gdb_byte
*info_ptr
)
12028 attr
->name
= abbrev
->name
;
12029 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
12032 /* Read dwarf information from a buffer. */
12034 static unsigned int
12035 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
12037 return bfd_get_8 (abfd
, buf
);
12041 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
12043 return bfd_get_signed_8 (abfd
, buf
);
12046 static unsigned int
12047 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
12049 return bfd_get_16 (abfd
, buf
);
12053 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12055 return bfd_get_signed_16 (abfd
, buf
);
12058 static unsigned int
12059 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
12061 return bfd_get_32 (abfd
, buf
);
12065 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12067 return bfd_get_signed_32 (abfd
, buf
);
12071 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12073 return bfd_get_64 (abfd
, buf
);
12077 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12078 unsigned int *bytes_read
)
12080 struct comp_unit_head
*cu_header
= &cu
->header
;
12081 CORE_ADDR retval
= 0;
12083 if (cu_header
->signed_addr_p
)
12085 switch (cu_header
->addr_size
)
12088 retval
= bfd_get_signed_16 (abfd
, buf
);
12091 retval
= bfd_get_signed_32 (abfd
, buf
);
12094 retval
= bfd_get_signed_64 (abfd
, buf
);
12097 internal_error (__FILE__
, __LINE__
,
12098 _("read_address: bad switch, signed [in module %s]"),
12099 bfd_get_filename (abfd
));
12104 switch (cu_header
->addr_size
)
12107 retval
= bfd_get_16 (abfd
, buf
);
12110 retval
= bfd_get_32 (abfd
, buf
);
12113 retval
= bfd_get_64 (abfd
, buf
);
12116 internal_error (__FILE__
, __LINE__
,
12117 _("read_address: bad switch, "
12118 "unsigned [in module %s]"),
12119 bfd_get_filename (abfd
));
12123 *bytes_read
= cu_header
->addr_size
;
12127 /* Read the initial length from a section. The (draft) DWARF 3
12128 specification allows the initial length to take up either 4 bytes
12129 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
12130 bytes describe the length and all offsets will be 8 bytes in length
12133 An older, non-standard 64-bit format is also handled by this
12134 function. The older format in question stores the initial length
12135 as an 8-byte quantity without an escape value. Lengths greater
12136 than 2^32 aren't very common which means that the initial 4 bytes
12137 is almost always zero. Since a length value of zero doesn't make
12138 sense for the 32-bit format, this initial zero can be considered to
12139 be an escape value which indicates the presence of the older 64-bit
12140 format. As written, the code can't detect (old format) lengths
12141 greater than 4GB. If it becomes necessary to handle lengths
12142 somewhat larger than 4GB, we could allow other small values (such
12143 as the non-sensical values of 1, 2, and 3) to also be used as
12144 escape values indicating the presence of the old format.
12146 The value returned via bytes_read should be used to increment the
12147 relevant pointer after calling read_initial_length().
12149 [ Note: read_initial_length() and read_offset() are based on the
12150 document entitled "DWARF Debugging Information Format", revision
12151 3, draft 8, dated November 19, 2001. This document was obtained
12154 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
12156 This document is only a draft and is subject to change. (So beware.)
12158 Details regarding the older, non-standard 64-bit format were
12159 determined empirically by examining 64-bit ELF files produced by
12160 the SGI toolchain on an IRIX 6.5 machine.
12162 - Kevin, July 16, 2002
12166 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
12168 LONGEST length
= bfd_get_32 (abfd
, buf
);
12170 if (length
== 0xffffffff)
12172 length
= bfd_get_64 (abfd
, buf
+ 4);
12175 else if (length
== 0)
12177 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
12178 length
= bfd_get_64 (abfd
, buf
);
12189 /* Cover function for read_initial_length.
12190 Returns the length of the object at BUF, and stores the size of the
12191 initial length in *BYTES_READ and stores the size that offsets will be in
12193 If the initial length size is not equivalent to that specified in
12194 CU_HEADER then issue a complaint.
12195 This is useful when reading non-comp-unit headers. */
12198 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
12199 const struct comp_unit_head
*cu_header
,
12200 unsigned int *bytes_read
,
12201 unsigned int *offset_size
)
12203 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
12205 gdb_assert (cu_header
->initial_length_size
== 4
12206 || cu_header
->initial_length_size
== 8
12207 || cu_header
->initial_length_size
== 12);
12209 if (cu_header
->initial_length_size
!= *bytes_read
)
12210 complaint (&symfile_complaints
,
12211 _("intermixed 32-bit and 64-bit DWARF sections"));
12213 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
12217 /* Read an offset from the data stream. The size of the offset is
12218 given by cu_header->offset_size. */
12221 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
12222 unsigned int *bytes_read
)
12224 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
12226 *bytes_read
= cu_header
->offset_size
;
12230 /* Read an offset from the data stream. */
12233 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
12235 LONGEST retval
= 0;
12237 switch (offset_size
)
12240 retval
= bfd_get_32 (abfd
, buf
);
12243 retval
= bfd_get_64 (abfd
, buf
);
12246 internal_error (__FILE__
, __LINE__
,
12247 _("read_offset_1: bad switch [in module %s]"),
12248 bfd_get_filename (abfd
));
12255 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12257 /* If the size of a host char is 8 bits, we can return a pointer
12258 to the buffer, otherwise we have to copy the data to a buffer
12259 allocated on the temporary obstack. */
12260 gdb_assert (HOST_CHAR_BIT
== 8);
12265 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12267 /* If the size of a host char is 8 bits, we can return a pointer
12268 to the string, otherwise we have to copy the string to a buffer
12269 allocated on the temporary obstack. */
12270 gdb_assert (HOST_CHAR_BIT
== 8);
12273 *bytes_read_ptr
= 1;
12276 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12277 return (char *) buf
;
12281 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12283 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12284 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12285 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12286 bfd_get_filename (abfd
));
12287 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12288 error (_("DW_FORM_strp pointing outside of "
12289 ".debug_str section [in module %s]"),
12290 bfd_get_filename (abfd
));
12291 gdb_assert (HOST_CHAR_BIT
== 8);
12292 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12294 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12298 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12299 const struct comp_unit_head
*cu_header
,
12300 unsigned int *bytes_read_ptr
)
12302 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12304 return read_indirect_string_at_offset (abfd
, str_offset
);
12308 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12311 unsigned int num_read
;
12313 unsigned char byte
;
12321 byte
= bfd_get_8 (abfd
, buf
);
12324 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12325 if ((byte
& 128) == 0)
12331 *bytes_read_ptr
= num_read
;
12336 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12339 int i
, shift
, num_read
;
12340 unsigned char byte
;
12348 byte
= bfd_get_8 (abfd
, buf
);
12351 result
|= ((LONGEST
) (byte
& 127) << shift
);
12353 if ((byte
& 128) == 0)
12358 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12359 result
|= -(((LONGEST
) 1) << shift
);
12360 *bytes_read_ptr
= num_read
;
12364 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12365 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12366 ADDR_SIZE is the size of addresses from the CU header. */
12369 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12371 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12372 bfd
*abfd
= objfile
->obfd
;
12373 const gdb_byte
*info_ptr
;
12375 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12376 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12377 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12379 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12380 error (_("DW_FORM_addr_index pointing outside of "
12381 ".debug_addr section [in module %s]"),
12383 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12384 + addr_base
+ addr_index
* addr_size
);
12385 if (addr_size
== 4)
12386 return bfd_get_32 (abfd
, info_ptr
);
12388 return bfd_get_64 (abfd
, info_ptr
);
12391 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12394 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12396 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12399 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12402 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12403 unsigned int *bytes_read
)
12405 bfd
*abfd
= cu
->objfile
->obfd
;
12406 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12408 return read_addr_index (cu
, addr_index
);
12411 /* Data structure to pass results from dwarf2_read_addr_index_reader
12412 back to dwarf2_read_addr_index. */
12414 struct dwarf2_read_addr_index_data
12416 ULONGEST addr_base
;
12420 /* die_reader_func for dwarf2_read_addr_index. */
12423 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12424 gdb_byte
*info_ptr
,
12425 struct die_info
*comp_unit_die
,
12429 struct dwarf2_cu
*cu
= reader
->cu
;
12430 struct dwarf2_read_addr_index_data
*aidata
=
12431 (struct dwarf2_read_addr_index_data
*) data
;
12433 aidata
->addr_base
= cu
->addr_base
;
12434 aidata
->addr_size
= cu
->header
.addr_size
;
12437 /* Given an index in .debug_addr, fetch the value.
12438 NOTE: This can be called during dwarf expression evaluation,
12439 long after the debug information has been read, and thus per_cu->cu
12440 may no longer exist. */
12443 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12444 unsigned int addr_index
)
12446 struct objfile
*objfile
= per_cu
->objfile
;
12447 struct dwarf2_cu
*cu
= per_cu
->cu
;
12448 ULONGEST addr_base
;
12451 /* This is intended to be called from outside this file. */
12452 dw2_setup (objfile
);
12454 /* We need addr_base and addr_size.
12455 If we don't have PER_CU->cu, we have to get it.
12456 Nasty, but the alternative is storing the needed info in PER_CU,
12457 which at this point doesn't seem justified: it's not clear how frequently
12458 it would get used and it would increase the size of every PER_CU.
12459 Entry points like dwarf2_per_cu_addr_size do a similar thing
12460 so we're not in uncharted territory here.
12461 Alas we need to be a bit more complicated as addr_base is contained
12464 We don't need to read the entire CU(/TU).
12465 We just need the header and top level die.
12466 IWBN to use the aging mechanism to let us lazily later discard the CU.
12467 See however init_cutu_and_read_dies_simple. */
12471 addr_base
= cu
->addr_base
;
12472 addr_size
= cu
->header
.addr_size
;
12476 struct dwarf2_read_addr_index_data aidata
;
12478 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12480 addr_base
= aidata
.addr_base
;
12481 addr_size
= aidata
.addr_size
;
12484 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12487 /* Given a DW_AT_str_index, fetch the string. */
12490 read_str_index (const struct die_reader_specs
*reader
,
12491 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12494 const char *dwo_name
= objfile
->name
;
12495 bfd
*abfd
= objfile
->obfd
;
12496 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12497 gdb_byte
*info_ptr
;
12498 ULONGEST str_offset
;
12500 dwarf2_read_section (objfile
, §ions
->str
);
12501 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12502 if (sections
->str
.buffer
== NULL
)
12503 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12504 " in CU at offset 0x%lx [in module %s]"),
12505 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12506 if (sections
->str_offsets
.buffer
== NULL
)
12507 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12508 " in CU at offset 0x%lx [in module %s]"),
12509 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12510 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12511 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12512 " section in CU at offset 0x%lx [in module %s]"),
12513 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12514 info_ptr
= (sections
->str_offsets
.buffer
12515 + str_index
* cu
->header
.offset_size
);
12516 if (cu
->header
.offset_size
== 4)
12517 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12519 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12520 if (str_offset
>= sections
->str
.size
)
12521 error (_("Offset from DW_FORM_str_index pointing outside of"
12522 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12523 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12524 return (char *) (sections
->str
.buffer
+ str_offset
);
12527 /* Return the length of an LEB128 number in BUF. */
12530 leb128_size (const gdb_byte
*buf
)
12532 const gdb_byte
*begin
= buf
;
12538 if ((byte
& 128) == 0)
12539 return buf
- begin
;
12544 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12551 cu
->language
= language_c
;
12553 case DW_LANG_C_plus_plus
:
12554 cu
->language
= language_cplus
;
12557 cu
->language
= language_d
;
12559 case DW_LANG_Fortran77
:
12560 case DW_LANG_Fortran90
:
12561 case DW_LANG_Fortran95
:
12562 cu
->language
= language_fortran
;
12565 cu
->language
= language_go
;
12567 case DW_LANG_Mips_Assembler
:
12568 cu
->language
= language_asm
;
12571 cu
->language
= language_java
;
12573 case DW_LANG_Ada83
:
12574 case DW_LANG_Ada95
:
12575 cu
->language
= language_ada
;
12577 case DW_LANG_Modula2
:
12578 cu
->language
= language_m2
;
12580 case DW_LANG_Pascal83
:
12581 cu
->language
= language_pascal
;
12584 cu
->language
= language_objc
;
12586 case DW_LANG_Cobol74
:
12587 case DW_LANG_Cobol85
:
12589 cu
->language
= language_minimal
;
12592 cu
->language_defn
= language_def (cu
->language
);
12595 /* Return the named attribute or NULL if not there. */
12597 static struct attribute
*
12598 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12603 struct attribute
*spec
= NULL
;
12605 for (i
= 0; i
< die
->num_attrs
; ++i
)
12607 if (die
->attrs
[i
].name
== name
)
12608 return &die
->attrs
[i
];
12609 if (die
->attrs
[i
].name
== DW_AT_specification
12610 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12611 spec
= &die
->attrs
[i
];
12617 die
= follow_die_ref (die
, spec
, &cu
);
12623 /* Return the named attribute or NULL if not there,
12624 but do not follow DW_AT_specification, etc.
12625 This is for use in contexts where we're reading .debug_types dies.
12626 Following DW_AT_specification, DW_AT_abstract_origin will take us
12627 back up the chain, and we want to go down. */
12629 static struct attribute
*
12630 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12631 struct dwarf2_cu
*cu
)
12635 for (i
= 0; i
< die
->num_attrs
; ++i
)
12636 if (die
->attrs
[i
].name
== name
)
12637 return &die
->attrs
[i
];
12642 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12643 and holds a non-zero value. This function should only be used for
12644 DW_FORM_flag or DW_FORM_flag_present attributes. */
12647 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12649 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12651 return (attr
&& DW_UNSND (attr
));
12655 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12657 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12658 which value is non-zero. However, we have to be careful with
12659 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12660 (via dwarf2_flag_true_p) follows this attribute. So we may
12661 end up accidently finding a declaration attribute that belongs
12662 to a different DIE referenced by the specification attribute,
12663 even though the given DIE does not have a declaration attribute. */
12664 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12665 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12668 /* Return the die giving the specification for DIE, if there is
12669 one. *SPEC_CU is the CU containing DIE on input, and the CU
12670 containing the return value on output. If there is no
12671 specification, but there is an abstract origin, that is
12674 static struct die_info
*
12675 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12677 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12680 if (spec_attr
== NULL
)
12681 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12683 if (spec_attr
== NULL
)
12686 return follow_die_ref (die
, spec_attr
, spec_cu
);
12689 /* Free the line_header structure *LH, and any arrays and strings it
12691 NOTE: This is also used as a "cleanup" function. */
12694 free_line_header (struct line_header
*lh
)
12696 if (lh
->standard_opcode_lengths
)
12697 xfree (lh
->standard_opcode_lengths
);
12699 /* Remember that all the lh->file_names[i].name pointers are
12700 pointers into debug_line_buffer, and don't need to be freed. */
12701 if (lh
->file_names
)
12702 xfree (lh
->file_names
);
12704 /* Similarly for the include directory names. */
12705 if (lh
->include_dirs
)
12706 xfree (lh
->include_dirs
);
12711 /* Add an entry to LH's include directory table. */
12714 add_include_dir (struct line_header
*lh
, char *include_dir
)
12716 /* Grow the array if necessary. */
12717 if (lh
->include_dirs_size
== 0)
12719 lh
->include_dirs_size
= 1; /* for testing */
12720 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12721 * sizeof (*lh
->include_dirs
));
12723 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12725 lh
->include_dirs_size
*= 2;
12726 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12727 (lh
->include_dirs_size
12728 * sizeof (*lh
->include_dirs
)));
12731 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12734 /* Add an entry to LH's file name table. */
12737 add_file_name (struct line_header
*lh
,
12739 unsigned int dir_index
,
12740 unsigned int mod_time
,
12741 unsigned int length
)
12743 struct file_entry
*fe
;
12745 /* Grow the array if necessary. */
12746 if (lh
->file_names_size
== 0)
12748 lh
->file_names_size
= 1; /* for testing */
12749 lh
->file_names
= xmalloc (lh
->file_names_size
12750 * sizeof (*lh
->file_names
));
12752 else if (lh
->num_file_names
>= lh
->file_names_size
)
12754 lh
->file_names_size
*= 2;
12755 lh
->file_names
= xrealloc (lh
->file_names
,
12756 (lh
->file_names_size
12757 * sizeof (*lh
->file_names
)));
12760 fe
= &lh
->file_names
[lh
->num_file_names
++];
12762 fe
->dir_index
= dir_index
;
12763 fe
->mod_time
= mod_time
;
12764 fe
->length
= length
;
12765 fe
->included_p
= 0;
12769 /* Read the statement program header starting at OFFSET in
12770 .debug_line, or .debug_line.dwo. Return a pointer
12771 to a struct line_header, allocated using xmalloc.
12773 NOTE: the strings in the include directory and file name tables of
12774 the returned object point into the dwarf line section buffer,
12775 and must not be freed. */
12777 static struct line_header
*
12778 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12780 struct cleanup
*back_to
;
12781 struct line_header
*lh
;
12782 gdb_byte
*line_ptr
;
12783 unsigned int bytes_read
, offset_size
;
12785 char *cur_dir
, *cur_file
;
12786 struct dwarf2_section_info
*section
;
12789 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12791 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12792 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12794 section
= &dwarf2_per_objfile
->line
;
12796 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12797 if (section
->buffer
== NULL
)
12799 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12800 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12802 complaint (&symfile_complaints
, _("missing .debug_line section"));
12806 /* We can't do this until we know the section is non-empty.
12807 Only then do we know we have such a section. */
12808 abfd
= section
->asection
->owner
;
12810 /* Make sure that at least there's room for the total_length field.
12811 That could be 12 bytes long, but we're just going to fudge that. */
12812 if (offset
+ 4 >= section
->size
)
12814 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12818 lh
= xmalloc (sizeof (*lh
));
12819 memset (lh
, 0, sizeof (*lh
));
12820 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12823 line_ptr
= section
->buffer
+ offset
;
12825 /* Read in the header. */
12827 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12828 &bytes_read
, &offset_size
);
12829 line_ptr
+= bytes_read
;
12830 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12832 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12835 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12836 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12838 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12839 line_ptr
+= offset_size
;
12840 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12842 if (lh
->version
>= 4)
12844 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12848 lh
->maximum_ops_per_instruction
= 1;
12850 if (lh
->maximum_ops_per_instruction
== 0)
12852 lh
->maximum_ops_per_instruction
= 1;
12853 complaint (&symfile_complaints
,
12854 _("invalid maximum_ops_per_instruction "
12855 "in `.debug_line' section"));
12858 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12860 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12862 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12864 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12866 lh
->standard_opcode_lengths
12867 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12869 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12870 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12872 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12876 /* Read directory table. */
12877 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12879 line_ptr
+= bytes_read
;
12880 add_include_dir (lh
, cur_dir
);
12882 line_ptr
+= bytes_read
;
12884 /* Read file name table. */
12885 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12887 unsigned int dir_index
, mod_time
, length
;
12889 line_ptr
+= bytes_read
;
12890 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12891 line_ptr
+= bytes_read
;
12892 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12893 line_ptr
+= bytes_read
;
12894 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12895 line_ptr
+= bytes_read
;
12897 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12899 line_ptr
+= bytes_read
;
12900 lh
->statement_program_start
= line_ptr
;
12902 if (line_ptr
> (section
->buffer
+ section
->size
))
12903 complaint (&symfile_complaints
,
12904 _("line number info header doesn't "
12905 "fit in `.debug_line' section"));
12907 discard_cleanups (back_to
);
12911 /* Subroutine of dwarf_decode_lines to simplify it.
12912 Return the file name of the psymtab for included file FILE_INDEX
12913 in line header LH of PST.
12914 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12915 If space for the result is malloc'd, it will be freed by a cleanup.
12916 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12919 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12920 const struct partial_symtab
*pst
,
12921 const char *comp_dir
)
12923 const struct file_entry fe
= lh
->file_names
[file_index
];
12924 char *include_name
= fe
.name
;
12925 char *include_name_to_compare
= include_name
;
12926 char *dir_name
= NULL
;
12927 const char *pst_filename
;
12928 char *copied_name
= NULL
;
12932 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12934 if (!IS_ABSOLUTE_PATH (include_name
)
12935 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12937 /* Avoid creating a duplicate psymtab for PST.
12938 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12939 Before we do the comparison, however, we need to account
12940 for DIR_NAME and COMP_DIR.
12941 First prepend dir_name (if non-NULL). If we still don't
12942 have an absolute path prepend comp_dir (if non-NULL).
12943 However, the directory we record in the include-file's
12944 psymtab does not contain COMP_DIR (to match the
12945 corresponding symtab(s)).
12950 bash$ gcc -g ./hello.c
12951 include_name = "hello.c"
12953 DW_AT_comp_dir = comp_dir = "/tmp"
12954 DW_AT_name = "./hello.c" */
12956 if (dir_name
!= NULL
)
12958 include_name
= concat (dir_name
, SLASH_STRING
,
12959 include_name
, (char *)NULL
);
12960 include_name_to_compare
= include_name
;
12961 make_cleanup (xfree
, include_name
);
12963 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12965 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12966 include_name
, (char *)NULL
);
12970 pst_filename
= pst
->filename
;
12971 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12973 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12974 pst_filename
, (char *)NULL
);
12975 pst_filename
= copied_name
;
12978 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12980 if (include_name_to_compare
!= include_name
)
12981 xfree (include_name_to_compare
);
12982 if (copied_name
!= NULL
)
12983 xfree (copied_name
);
12987 return include_name
;
12990 /* Ignore this record_line request. */
12993 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12998 /* Subroutine of dwarf_decode_lines to simplify it.
12999 Process the line number information in LH. */
13002 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13003 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13005 gdb_byte
*line_ptr
, *extended_end
;
13006 gdb_byte
*line_end
;
13007 unsigned int bytes_read
, extended_len
;
13008 unsigned char op_code
, extended_op
, adj_opcode
;
13009 CORE_ADDR baseaddr
;
13010 struct objfile
*objfile
= cu
->objfile
;
13011 bfd
*abfd
= objfile
->obfd
;
13012 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13013 const int decode_for_pst_p
= (pst
!= NULL
);
13014 struct subfile
*last_subfile
= NULL
;
13015 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13018 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13020 line_ptr
= lh
->statement_program_start
;
13021 line_end
= lh
->statement_program_end
;
13023 /* Read the statement sequences until there's nothing left. */
13024 while (line_ptr
< line_end
)
13026 /* state machine registers */
13027 CORE_ADDR address
= 0;
13028 unsigned int file
= 1;
13029 unsigned int line
= 1;
13030 unsigned int column
= 0;
13031 int is_stmt
= lh
->default_is_stmt
;
13032 int basic_block
= 0;
13033 int end_sequence
= 0;
13035 unsigned char op_index
= 0;
13037 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
13039 /* Start a subfile for the current file of the state machine. */
13040 /* lh->include_dirs and lh->file_names are 0-based, but the
13041 directory and file name numbers in the statement program
13043 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13047 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13049 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13052 /* Decode the table. */
13053 while (!end_sequence
)
13055 op_code
= read_1_byte (abfd
, line_ptr
);
13057 if (line_ptr
> line_end
)
13059 dwarf2_debug_line_missing_end_sequence_complaint ();
13063 if (op_code
>= lh
->opcode_base
)
13065 /* Special operand. */
13066 adj_opcode
= op_code
- lh
->opcode_base
;
13067 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13068 / lh
->maximum_ops_per_instruction
)
13069 * lh
->minimum_instruction_length
);
13070 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13071 % lh
->maximum_ops_per_instruction
);
13072 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13073 if (lh
->num_file_names
< file
|| file
== 0)
13074 dwarf2_debug_line_missing_file_complaint ();
13075 /* For now we ignore lines not starting on an
13076 instruction boundary. */
13077 else if (op_index
== 0)
13079 lh
->file_names
[file
- 1].included_p
= 1;
13080 if (!decode_for_pst_p
&& is_stmt
)
13082 if (last_subfile
!= current_subfile
)
13084 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13086 (*p_record_line
) (last_subfile
, 0, addr
);
13087 last_subfile
= current_subfile
;
13089 /* Append row to matrix using current values. */
13090 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13091 (*p_record_line
) (current_subfile
, line
, addr
);
13096 else switch (op_code
)
13098 case DW_LNS_extended_op
:
13099 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13101 line_ptr
+= bytes_read
;
13102 extended_end
= line_ptr
+ extended_len
;
13103 extended_op
= read_1_byte (abfd
, line_ptr
);
13105 switch (extended_op
)
13107 case DW_LNE_end_sequence
:
13108 p_record_line
= record_line
;
13111 case DW_LNE_set_address
:
13112 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
13114 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13116 /* This line table is for a function which has been
13117 GCd by the linker. Ignore it. PR gdb/12528 */
13120 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
13122 complaint (&symfile_complaints
,
13123 _(".debug_line address at offset 0x%lx is 0 "
13125 line_offset
, objfile
->name
);
13126 p_record_line
= noop_record_line
;
13130 line_ptr
+= bytes_read
;
13131 address
+= baseaddr
;
13133 case DW_LNE_define_file
:
13136 unsigned int dir_index
, mod_time
, length
;
13138 cur_file
= read_direct_string (abfd
, line_ptr
,
13140 line_ptr
+= bytes_read
;
13142 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13143 line_ptr
+= bytes_read
;
13145 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13146 line_ptr
+= bytes_read
;
13148 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13149 line_ptr
+= bytes_read
;
13150 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13153 case DW_LNE_set_discriminator
:
13154 /* The discriminator is not interesting to the debugger;
13156 line_ptr
= extended_end
;
13159 complaint (&symfile_complaints
,
13160 _("mangled .debug_line section"));
13163 /* Make sure that we parsed the extended op correctly. If e.g.
13164 we expected a different address size than the producer used,
13165 we may have read the wrong number of bytes. */
13166 if (line_ptr
!= extended_end
)
13168 complaint (&symfile_complaints
,
13169 _("mangled .debug_line section"));
13174 if (lh
->num_file_names
< file
|| file
== 0)
13175 dwarf2_debug_line_missing_file_complaint ();
13178 lh
->file_names
[file
- 1].included_p
= 1;
13179 if (!decode_for_pst_p
&& is_stmt
)
13181 if (last_subfile
!= current_subfile
)
13183 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13185 (*p_record_line
) (last_subfile
, 0, addr
);
13186 last_subfile
= current_subfile
;
13188 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13189 (*p_record_line
) (current_subfile
, line
, addr
);
13194 case DW_LNS_advance_pc
:
13197 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13199 address
+= (((op_index
+ adjust
)
13200 / lh
->maximum_ops_per_instruction
)
13201 * lh
->minimum_instruction_length
);
13202 op_index
= ((op_index
+ adjust
)
13203 % lh
->maximum_ops_per_instruction
);
13204 line_ptr
+= bytes_read
;
13207 case DW_LNS_advance_line
:
13208 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
13209 line_ptr
+= bytes_read
;
13211 case DW_LNS_set_file
:
13213 /* The arrays lh->include_dirs and lh->file_names are
13214 0-based, but the directory and file name numbers in
13215 the statement program are 1-based. */
13216 struct file_entry
*fe
;
13219 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13220 line_ptr
+= bytes_read
;
13221 if (lh
->num_file_names
< file
|| file
== 0)
13222 dwarf2_debug_line_missing_file_complaint ();
13225 fe
= &lh
->file_names
[file
- 1];
13227 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13228 if (!decode_for_pst_p
)
13230 last_subfile
= current_subfile
;
13231 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13236 case DW_LNS_set_column
:
13237 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13238 line_ptr
+= bytes_read
;
13240 case DW_LNS_negate_stmt
:
13241 is_stmt
= (!is_stmt
);
13243 case DW_LNS_set_basic_block
:
13246 /* Add to the address register of the state machine the
13247 address increment value corresponding to special opcode
13248 255. I.e., this value is scaled by the minimum
13249 instruction length since special opcode 255 would have
13250 scaled the increment. */
13251 case DW_LNS_const_add_pc
:
13253 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13255 address
+= (((op_index
+ adjust
)
13256 / lh
->maximum_ops_per_instruction
)
13257 * lh
->minimum_instruction_length
);
13258 op_index
= ((op_index
+ adjust
)
13259 % lh
->maximum_ops_per_instruction
);
13262 case DW_LNS_fixed_advance_pc
:
13263 address
+= read_2_bytes (abfd
, line_ptr
);
13269 /* Unknown standard opcode, ignore it. */
13272 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13274 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13275 line_ptr
+= bytes_read
;
13280 if (lh
->num_file_names
< file
|| file
== 0)
13281 dwarf2_debug_line_missing_file_complaint ();
13284 lh
->file_names
[file
- 1].included_p
= 1;
13285 if (!decode_for_pst_p
)
13287 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13288 (*p_record_line
) (current_subfile
, 0, addr
);
13294 /* Decode the Line Number Program (LNP) for the given line_header
13295 structure and CU. The actual information extracted and the type
13296 of structures created from the LNP depends on the value of PST.
13298 1. If PST is NULL, then this procedure uses the data from the program
13299 to create all necessary symbol tables, and their linetables.
13301 2. If PST is not NULL, this procedure reads the program to determine
13302 the list of files included by the unit represented by PST, and
13303 builds all the associated partial symbol tables.
13305 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13306 It is used for relative paths in the line table.
13307 NOTE: When processing partial symtabs (pst != NULL),
13308 comp_dir == pst->dirname.
13310 NOTE: It is important that psymtabs have the same file name (via strcmp)
13311 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13312 symtab we don't use it in the name of the psymtabs we create.
13313 E.g. expand_line_sal requires this when finding psymtabs to expand.
13314 A good testcase for this is mb-inline.exp. */
13317 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13318 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13319 int want_line_info
)
13321 struct objfile
*objfile
= cu
->objfile
;
13322 const int decode_for_pst_p
= (pst
!= NULL
);
13323 struct subfile
*first_subfile
= current_subfile
;
13325 if (want_line_info
)
13326 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13328 if (decode_for_pst_p
)
13332 /* Now that we're done scanning the Line Header Program, we can
13333 create the psymtab of each included file. */
13334 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13335 if (lh
->file_names
[file_index
].included_p
== 1)
13337 char *include_name
=
13338 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13339 if (include_name
!= NULL
)
13340 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13345 /* Make sure a symtab is created for every file, even files
13346 which contain only variables (i.e. no code with associated
13350 for (i
= 0; i
< lh
->num_file_names
; i
++)
13353 struct file_entry
*fe
;
13355 fe
= &lh
->file_names
[i
];
13357 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13358 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13360 /* Skip the main file; we don't need it, and it must be
13361 allocated last, so that it will show up before the
13362 non-primary symtabs in the objfile's symtab list. */
13363 if (current_subfile
== first_subfile
)
13366 if (current_subfile
->symtab
== NULL
)
13367 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13369 fe
->symtab
= current_subfile
->symtab
;
13374 /* Start a subfile for DWARF. FILENAME is the name of the file and
13375 DIRNAME the name of the source directory which contains FILENAME
13376 or NULL if not known. COMP_DIR is the compilation directory for the
13377 linetable's compilation unit or NULL if not known.
13378 This routine tries to keep line numbers from identical absolute and
13379 relative file names in a common subfile.
13381 Using the `list' example from the GDB testsuite, which resides in
13382 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13383 of /srcdir/list0.c yields the following debugging information for list0.c:
13385 DW_AT_name: /srcdir/list0.c
13386 DW_AT_comp_dir: /compdir
13387 files.files[0].name: list0.h
13388 files.files[0].dir: /srcdir
13389 files.files[1].name: list0.c
13390 files.files[1].dir: /srcdir
13392 The line number information for list0.c has to end up in a single
13393 subfile, so that `break /srcdir/list0.c:1' works as expected.
13394 start_subfile will ensure that this happens provided that we pass the
13395 concatenation of files.files[1].dir and files.files[1].name as the
13399 dwarf2_start_subfile (char *filename
, const char *dirname
,
13400 const char *comp_dir
)
13404 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13405 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13406 second argument to start_subfile. To be consistent, we do the
13407 same here. In order not to lose the line information directory,
13408 we concatenate it to the filename when it makes sense.
13409 Note that the Dwarf3 standard says (speaking of filenames in line
13410 information): ``The directory index is ignored for file names
13411 that represent full path names''. Thus ignoring dirname in the
13412 `else' branch below isn't an issue. */
13414 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13415 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13417 fullname
= filename
;
13419 start_subfile (fullname
, comp_dir
);
13421 if (fullname
!= filename
)
13426 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13427 struct dwarf2_cu
*cu
)
13429 struct objfile
*objfile
= cu
->objfile
;
13430 struct comp_unit_head
*cu_header
= &cu
->header
;
13432 /* NOTE drow/2003-01-30: There used to be a comment and some special
13433 code here to turn a symbol with DW_AT_external and a
13434 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13435 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13436 with some versions of binutils) where shared libraries could have
13437 relocations against symbols in their debug information - the
13438 minimal symbol would have the right address, but the debug info
13439 would not. It's no longer necessary, because we will explicitly
13440 apply relocations when we read in the debug information now. */
13442 /* A DW_AT_location attribute with no contents indicates that a
13443 variable has been optimized away. */
13444 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13446 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13450 /* Handle one degenerate form of location expression specially, to
13451 preserve GDB's previous behavior when section offsets are
13452 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13453 then mark this symbol as LOC_STATIC. */
13455 if (attr_form_is_block (attr
)
13456 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13457 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13458 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13459 && (DW_BLOCK (attr
)->size
13460 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13462 unsigned int dummy
;
13464 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13465 SYMBOL_VALUE_ADDRESS (sym
) =
13466 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13468 SYMBOL_VALUE_ADDRESS (sym
) =
13469 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13470 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13471 fixup_symbol_section (sym
, objfile
);
13472 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13473 SYMBOL_SECTION (sym
));
13477 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13478 expression evaluator, and use LOC_COMPUTED only when necessary
13479 (i.e. when the value of a register or memory location is
13480 referenced, or a thread-local block, etc.). Then again, it might
13481 not be worthwhile. I'm assuming that it isn't unless performance
13482 or memory numbers show me otherwise. */
13484 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13485 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13487 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13488 cu
->has_loclist
= 1;
13491 /* Given a pointer to a DWARF information entry, figure out if we need
13492 to make a symbol table entry for it, and if so, create a new entry
13493 and return a pointer to it.
13494 If TYPE is NULL, determine symbol type from the die, otherwise
13495 used the passed type.
13496 If SPACE is not NULL, use it to hold the new symbol. If it is
13497 NULL, allocate a new symbol on the objfile's obstack. */
13499 static struct symbol
*
13500 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13501 struct symbol
*space
)
13503 struct objfile
*objfile
= cu
->objfile
;
13504 struct symbol
*sym
= NULL
;
13506 struct attribute
*attr
= NULL
;
13507 struct attribute
*attr2
= NULL
;
13508 CORE_ADDR baseaddr
;
13509 struct pending
**list_to_add
= NULL
;
13511 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13513 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13515 name
= dwarf2_name (die
, cu
);
13518 const char *linkagename
;
13519 int suppress_add
= 0;
13524 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13525 OBJSTAT (objfile
, n_syms
++);
13527 /* Cache this symbol's name and the name's demangled form (if any). */
13528 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13529 linkagename
= dwarf2_physname (name
, die
, cu
);
13530 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13532 /* Fortran does not have mangling standard and the mangling does differ
13533 between gfortran, iFort etc. */
13534 if (cu
->language
== language_fortran
13535 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13536 symbol_set_demangled_name (&(sym
->ginfo
),
13537 (char *) dwarf2_full_name (name
, die
, cu
),
13540 /* Default assumptions.
13541 Use the passed type or decode it from the die. */
13542 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13543 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13545 SYMBOL_TYPE (sym
) = type
;
13547 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13548 attr
= dwarf2_attr (die
,
13549 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13553 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13556 attr
= dwarf2_attr (die
,
13557 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13561 int file_index
= DW_UNSND (attr
);
13563 if (cu
->line_header
== NULL
13564 || file_index
> cu
->line_header
->num_file_names
)
13565 complaint (&symfile_complaints
,
13566 _("file index out of range"));
13567 else if (file_index
> 0)
13569 struct file_entry
*fe
;
13571 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13572 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13579 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13582 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13584 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13585 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13586 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13587 add_symbol_to_list (sym
, cu
->list_in_scope
);
13589 case DW_TAG_subprogram
:
13590 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13592 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13593 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13594 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13595 || cu
->language
== language_ada
)
13597 /* Subprograms marked external are stored as a global symbol.
13598 Ada subprograms, whether marked external or not, are always
13599 stored as a global symbol, because we want to be able to
13600 access them globally. For instance, we want to be able
13601 to break on a nested subprogram without having to
13602 specify the context. */
13603 list_to_add
= &global_symbols
;
13607 list_to_add
= cu
->list_in_scope
;
13610 case DW_TAG_inlined_subroutine
:
13611 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13613 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13614 SYMBOL_INLINED (sym
) = 1;
13615 list_to_add
= cu
->list_in_scope
;
13617 case DW_TAG_template_value_param
:
13619 /* Fall through. */
13620 case DW_TAG_constant
:
13621 case DW_TAG_variable
:
13622 case DW_TAG_member
:
13623 /* Compilation with minimal debug info may result in
13624 variables with missing type entries. Change the
13625 misleading `void' type to something sensible. */
13626 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13628 = objfile_type (objfile
)->nodebug_data_symbol
;
13630 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13631 /* In the case of DW_TAG_member, we should only be called for
13632 static const members. */
13633 if (die
->tag
== DW_TAG_member
)
13635 /* dwarf2_add_field uses die_is_declaration,
13636 so we do the same. */
13637 gdb_assert (die_is_declaration (die
, cu
));
13642 dwarf2_const_value (attr
, sym
, cu
);
13643 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13646 if (attr2
&& (DW_UNSND (attr2
) != 0))
13647 list_to_add
= &global_symbols
;
13649 list_to_add
= cu
->list_in_scope
;
13653 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13656 var_decode_location (attr
, sym
, cu
);
13657 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13658 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13659 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13660 && !dwarf2_per_objfile
->has_section_at_zero
)
13662 /* When a static variable is eliminated by the linker,
13663 the corresponding debug information is not stripped
13664 out, but the variable address is set to null;
13665 do not add such variables into symbol table. */
13667 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13669 /* Workaround gfortran PR debug/40040 - it uses
13670 DW_AT_location for variables in -fPIC libraries which may
13671 get overriden by other libraries/executable and get
13672 a different address. Resolve it by the minimal symbol
13673 which may come from inferior's executable using copy
13674 relocation. Make this workaround only for gfortran as for
13675 other compilers GDB cannot guess the minimal symbol
13676 Fortran mangling kind. */
13677 if (cu
->language
== language_fortran
&& die
->parent
13678 && die
->parent
->tag
== DW_TAG_module
13680 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13681 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13683 /* A variable with DW_AT_external is never static,
13684 but it may be block-scoped. */
13685 list_to_add
= (cu
->list_in_scope
== &file_symbols
13686 ? &global_symbols
: cu
->list_in_scope
);
13689 list_to_add
= cu
->list_in_scope
;
13693 /* We do not know the address of this symbol.
13694 If it is an external symbol and we have type information
13695 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13696 The address of the variable will then be determined from
13697 the minimal symbol table whenever the variable is
13699 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13700 if (attr2
&& (DW_UNSND (attr2
) != 0)
13701 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13703 /* A variable with DW_AT_external is never static, but it
13704 may be block-scoped. */
13705 list_to_add
= (cu
->list_in_scope
== &file_symbols
13706 ? &global_symbols
: cu
->list_in_scope
);
13708 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13710 else if (!die_is_declaration (die
, cu
))
13712 /* Use the default LOC_OPTIMIZED_OUT class. */
13713 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13715 list_to_add
= cu
->list_in_scope
;
13719 case DW_TAG_formal_parameter
:
13720 /* If we are inside a function, mark this as an argument. If
13721 not, we might be looking at an argument to an inlined function
13722 when we do not have enough information to show inlined frames;
13723 pretend it's a local variable in that case so that the user can
13725 if (context_stack_depth
> 0
13726 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13727 SYMBOL_IS_ARGUMENT (sym
) = 1;
13728 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13731 var_decode_location (attr
, sym
, cu
);
13733 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13736 dwarf2_const_value (attr
, sym
, cu
);
13739 list_to_add
= cu
->list_in_scope
;
13741 case DW_TAG_unspecified_parameters
:
13742 /* From varargs functions; gdb doesn't seem to have any
13743 interest in this information, so just ignore it for now.
13746 case DW_TAG_template_type_param
:
13748 /* Fall through. */
13749 case DW_TAG_class_type
:
13750 case DW_TAG_interface_type
:
13751 case DW_TAG_structure_type
:
13752 case DW_TAG_union_type
:
13753 case DW_TAG_set_type
:
13754 case DW_TAG_enumeration_type
:
13755 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13756 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13759 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13760 really ever be static objects: otherwise, if you try
13761 to, say, break of a class's method and you're in a file
13762 which doesn't mention that class, it won't work unless
13763 the check for all static symbols in lookup_symbol_aux
13764 saves you. See the OtherFileClass tests in
13765 gdb.c++/namespace.exp. */
13769 list_to_add
= (cu
->list_in_scope
== &file_symbols
13770 && (cu
->language
== language_cplus
13771 || cu
->language
== language_java
)
13772 ? &global_symbols
: cu
->list_in_scope
);
13774 /* The semantics of C++ state that "struct foo {
13775 ... }" also defines a typedef for "foo". A Java
13776 class declaration also defines a typedef for the
13778 if (cu
->language
== language_cplus
13779 || cu
->language
== language_java
13780 || cu
->language
== language_ada
)
13782 /* The symbol's name is already allocated along
13783 with this objfile, so we don't need to
13784 duplicate it for the type. */
13785 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13786 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13791 case DW_TAG_typedef
:
13792 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13793 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13794 list_to_add
= cu
->list_in_scope
;
13796 case DW_TAG_base_type
:
13797 case DW_TAG_subrange_type
:
13798 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13799 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13800 list_to_add
= cu
->list_in_scope
;
13802 case DW_TAG_enumerator
:
13803 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13806 dwarf2_const_value (attr
, sym
, cu
);
13809 /* NOTE: carlton/2003-11-10: See comment above in the
13810 DW_TAG_class_type, etc. block. */
13812 list_to_add
= (cu
->list_in_scope
== &file_symbols
13813 && (cu
->language
== language_cplus
13814 || cu
->language
== language_java
)
13815 ? &global_symbols
: cu
->list_in_scope
);
13818 case DW_TAG_namespace
:
13819 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13820 list_to_add
= &global_symbols
;
13823 /* Not a tag we recognize. Hopefully we aren't processing
13824 trash data, but since we must specifically ignore things
13825 we don't recognize, there is nothing else we should do at
13827 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13828 dwarf_tag_name (die
->tag
));
13834 sym
->hash_next
= objfile
->template_symbols
;
13835 objfile
->template_symbols
= sym
;
13836 list_to_add
= NULL
;
13839 if (list_to_add
!= NULL
)
13840 add_symbol_to_list (sym
, list_to_add
);
13842 /* For the benefit of old versions of GCC, check for anonymous
13843 namespaces based on the demangled name. */
13844 if (!processing_has_namespace_info
13845 && cu
->language
== language_cplus
)
13846 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13851 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13853 static struct symbol
*
13854 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13856 return new_symbol_full (die
, type
, cu
, NULL
);
13859 /* Given an attr with a DW_FORM_dataN value in host byte order,
13860 zero-extend it as appropriate for the symbol's type. The DWARF
13861 standard (v4) is not entirely clear about the meaning of using
13862 DW_FORM_dataN for a constant with a signed type, where the type is
13863 wider than the data. The conclusion of a discussion on the DWARF
13864 list was that this is unspecified. We choose to always zero-extend
13865 because that is the interpretation long in use by GCC. */
13868 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13869 const char *name
, struct obstack
*obstack
,
13870 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13872 struct objfile
*objfile
= cu
->objfile
;
13873 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13874 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13875 LONGEST l
= DW_UNSND (attr
);
13877 if (bits
< sizeof (*value
) * 8)
13879 l
&= ((LONGEST
) 1 << bits
) - 1;
13882 else if (bits
== sizeof (*value
) * 8)
13886 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13887 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13894 /* Read a constant value from an attribute. Either set *VALUE, or if
13895 the value does not fit in *VALUE, set *BYTES - either already
13896 allocated on the objfile obstack, or newly allocated on OBSTACK,
13897 or, set *BATON, if we translated the constant to a location
13901 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13902 const char *name
, struct obstack
*obstack
,
13903 struct dwarf2_cu
*cu
,
13904 LONGEST
*value
, gdb_byte
**bytes
,
13905 struct dwarf2_locexpr_baton
**baton
)
13907 struct objfile
*objfile
= cu
->objfile
;
13908 struct comp_unit_head
*cu_header
= &cu
->header
;
13909 struct dwarf_block
*blk
;
13910 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13911 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13917 switch (attr
->form
)
13920 case DW_FORM_GNU_addr_index
:
13924 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13925 dwarf2_const_value_length_mismatch_complaint (name
,
13926 cu_header
->addr_size
,
13927 TYPE_LENGTH (type
));
13928 /* Symbols of this form are reasonably rare, so we just
13929 piggyback on the existing location code rather than writing
13930 a new implementation of symbol_computed_ops. */
13931 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13932 sizeof (struct dwarf2_locexpr_baton
));
13933 (*baton
)->per_cu
= cu
->per_cu
;
13934 gdb_assert ((*baton
)->per_cu
);
13936 (*baton
)->size
= 2 + cu_header
->addr_size
;
13937 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13938 (*baton
)->data
= data
;
13940 data
[0] = DW_OP_addr
;
13941 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13942 byte_order
, DW_ADDR (attr
));
13943 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13946 case DW_FORM_string
:
13948 case DW_FORM_GNU_str_index
:
13949 /* DW_STRING is already allocated on the objfile obstack, point
13951 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13953 case DW_FORM_block1
:
13954 case DW_FORM_block2
:
13955 case DW_FORM_block4
:
13956 case DW_FORM_block
:
13957 case DW_FORM_exprloc
:
13958 blk
= DW_BLOCK (attr
);
13959 if (TYPE_LENGTH (type
) != blk
->size
)
13960 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13961 TYPE_LENGTH (type
));
13962 *bytes
= blk
->data
;
13965 /* The DW_AT_const_value attributes are supposed to carry the
13966 symbol's value "represented as it would be on the target
13967 architecture." By the time we get here, it's already been
13968 converted to host endianness, so we just need to sign- or
13969 zero-extend it as appropriate. */
13970 case DW_FORM_data1
:
13971 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13972 obstack
, cu
, value
, 8);
13974 case DW_FORM_data2
:
13975 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13976 obstack
, cu
, value
, 16);
13978 case DW_FORM_data4
:
13979 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13980 obstack
, cu
, value
, 32);
13982 case DW_FORM_data8
:
13983 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13984 obstack
, cu
, value
, 64);
13987 case DW_FORM_sdata
:
13988 *value
= DW_SND (attr
);
13991 case DW_FORM_udata
:
13992 *value
= DW_UNSND (attr
);
13996 complaint (&symfile_complaints
,
13997 _("unsupported const value attribute form: '%s'"),
13998 dwarf_form_name (attr
->form
));
14005 /* Copy constant value from an attribute to a symbol. */
14008 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14009 struct dwarf2_cu
*cu
)
14011 struct objfile
*objfile
= cu
->objfile
;
14012 struct comp_unit_head
*cu_header
= &cu
->header
;
14015 struct dwarf2_locexpr_baton
*baton
;
14017 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
14018 SYMBOL_PRINT_NAME (sym
),
14019 &objfile
->objfile_obstack
, cu
,
14020 &value
, &bytes
, &baton
);
14024 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14025 SYMBOL_LOCATION_BATON (sym
) = baton
;
14026 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14028 else if (bytes
!= NULL
)
14030 SYMBOL_VALUE_BYTES (sym
) = bytes
;
14031 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
14035 SYMBOL_VALUE (sym
) = value
;
14036 SYMBOL_CLASS (sym
) = LOC_CONST
;
14040 /* Return the type of the die in question using its DW_AT_type attribute. */
14042 static struct type
*
14043 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14045 struct attribute
*type_attr
;
14047 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14050 /* A missing DW_AT_type represents a void type. */
14051 return objfile_type (cu
->objfile
)->builtin_void
;
14054 return lookup_die_type (die
, type_attr
, cu
);
14057 /* True iff CU's producer generates GNAT Ada auxiliary information
14058 that allows to find parallel types through that information instead
14059 of having to do expensive parallel lookups by type name. */
14062 need_gnat_info (struct dwarf2_cu
*cu
)
14064 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14065 of GNAT produces this auxiliary information, without any indication
14066 that it is produced. Part of enhancing the FSF version of GNAT
14067 to produce that information will be to put in place an indicator
14068 that we can use in order to determine whether the descriptive type
14069 info is available or not. One suggestion that has been made is
14070 to use a new attribute, attached to the CU die. For now, assume
14071 that the descriptive type info is not available. */
14075 /* Return the auxiliary type of the die in question using its
14076 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14077 attribute is not present. */
14079 static struct type
*
14080 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14082 struct attribute
*type_attr
;
14084 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
14088 return lookup_die_type (die
, type_attr
, cu
);
14091 /* If DIE has a descriptive_type attribute, then set the TYPE's
14092 descriptive type accordingly. */
14095 set_descriptive_type (struct type
*type
, struct die_info
*die
,
14096 struct dwarf2_cu
*cu
)
14098 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
14100 if (descriptive_type
)
14102 ALLOCATE_GNAT_AUX_TYPE (type
);
14103 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
14107 /* Return the containing type of the die in question using its
14108 DW_AT_containing_type attribute. */
14110 static struct type
*
14111 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14113 struct attribute
*type_attr
;
14115 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
14117 error (_("Dwarf Error: Problem turning containing type into gdb type "
14118 "[in module %s]"), cu
->objfile
->name
);
14120 return lookup_die_type (die
, type_attr
, cu
);
14123 /* Look up the type of DIE in CU using its type attribute ATTR.
14124 If there is no type substitute an error marker. */
14126 static struct type
*
14127 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
14128 struct dwarf2_cu
*cu
)
14130 struct objfile
*objfile
= cu
->objfile
;
14131 struct type
*this_type
;
14133 /* First see if we have it cached. */
14135 if (is_ref_attr (attr
))
14137 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14139 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
14141 else if (attr
->form
== DW_FORM_ref_sig8
)
14143 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14145 /* sig_type will be NULL if the signatured type is missing from
14147 if (sig_type
== NULL
)
14148 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14149 "at 0x%x [in module %s]"),
14150 die
->offset
.sect_off
, objfile
->name
);
14152 gdb_assert (sig_type
->per_cu
.is_debug_types
);
14153 /* If we haven't filled in type_offset_in_section yet, then we
14154 haven't read the type in yet. */
14156 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
14159 get_die_type_at_offset (sig_type
->type_offset_in_section
,
14160 &sig_type
->per_cu
);
14165 dump_die_for_error (die
);
14166 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
14167 dwarf_attr_name (attr
->name
), objfile
->name
);
14170 /* If not cached we need to read it in. */
14172 if (this_type
== NULL
)
14174 struct die_info
*type_die
;
14175 struct dwarf2_cu
*type_cu
= cu
;
14177 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
14178 /* If we found the type now, it's probably because the type came
14179 from an inter-CU reference and the type's CU got expanded before
14181 this_type
= get_die_type (type_die
, type_cu
);
14182 if (this_type
== NULL
)
14183 this_type
= read_type_die_1 (type_die
, type_cu
);
14186 /* If we still don't have a type use an error marker. */
14188 if (this_type
== NULL
)
14190 char *message
, *saved
;
14192 /* read_type_die already issued a complaint. */
14193 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
14195 cu
->header
.offset
.sect_off
,
14196 die
->offset
.sect_off
);
14197 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
14198 message
, strlen (message
));
14201 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
14207 /* Return the type in DIE, CU.
14208 Returns NULL for invalid types.
14210 This first does a lookup in the appropriate type_hash table,
14211 and only reads the die in if necessary.
14213 NOTE: This can be called when reading in partial or full symbols. */
14215 static struct type
*
14216 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
14218 struct type
*this_type
;
14220 this_type
= get_die_type (die
, cu
);
14224 return read_type_die_1 (die
, cu
);
14227 /* Read the type in DIE, CU.
14228 Returns NULL for invalid types. */
14230 static struct type
*
14231 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14233 struct type
*this_type
= NULL
;
14237 case DW_TAG_class_type
:
14238 case DW_TAG_interface_type
:
14239 case DW_TAG_structure_type
:
14240 case DW_TAG_union_type
:
14241 this_type
= read_structure_type (die
, cu
);
14243 case DW_TAG_enumeration_type
:
14244 this_type
= read_enumeration_type (die
, cu
);
14246 case DW_TAG_subprogram
:
14247 case DW_TAG_subroutine_type
:
14248 case DW_TAG_inlined_subroutine
:
14249 this_type
= read_subroutine_type (die
, cu
);
14251 case DW_TAG_array_type
:
14252 this_type
= read_array_type (die
, cu
);
14254 case DW_TAG_set_type
:
14255 this_type
= read_set_type (die
, cu
);
14257 case DW_TAG_pointer_type
:
14258 this_type
= read_tag_pointer_type (die
, cu
);
14260 case DW_TAG_ptr_to_member_type
:
14261 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14263 case DW_TAG_reference_type
:
14264 this_type
= read_tag_reference_type (die
, cu
);
14266 case DW_TAG_const_type
:
14267 this_type
= read_tag_const_type (die
, cu
);
14269 case DW_TAG_volatile_type
:
14270 this_type
= read_tag_volatile_type (die
, cu
);
14272 case DW_TAG_string_type
:
14273 this_type
= read_tag_string_type (die
, cu
);
14275 case DW_TAG_typedef
:
14276 this_type
= read_typedef (die
, cu
);
14278 case DW_TAG_subrange_type
:
14279 this_type
= read_subrange_type (die
, cu
);
14281 case DW_TAG_base_type
:
14282 this_type
= read_base_type (die
, cu
);
14284 case DW_TAG_unspecified_type
:
14285 this_type
= read_unspecified_type (die
, cu
);
14287 case DW_TAG_namespace
:
14288 this_type
= read_namespace_type (die
, cu
);
14290 case DW_TAG_module
:
14291 this_type
= read_module_type (die
, cu
);
14294 complaint (&symfile_complaints
,
14295 _("unexpected tag in read_type_die: '%s'"),
14296 dwarf_tag_name (die
->tag
));
14303 /* See if we can figure out if the class lives in a namespace. We do
14304 this by looking for a member function; its demangled name will
14305 contain namespace info, if there is any.
14306 Return the computed name or NULL.
14307 Space for the result is allocated on the objfile's obstack.
14308 This is the full-die version of guess_partial_die_structure_name.
14309 In this case we know DIE has no useful parent. */
14312 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14314 struct die_info
*spec_die
;
14315 struct dwarf2_cu
*spec_cu
;
14316 struct die_info
*child
;
14319 spec_die
= die_specification (die
, &spec_cu
);
14320 if (spec_die
!= NULL
)
14326 for (child
= die
->child
;
14328 child
= child
->sibling
)
14330 if (child
->tag
== DW_TAG_subprogram
)
14332 struct attribute
*attr
;
14334 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14336 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14340 = language_class_name_from_physname (cu
->language_defn
,
14344 if (actual_name
!= NULL
)
14346 char *die_name
= dwarf2_name (die
, cu
);
14348 if (die_name
!= NULL
14349 && strcmp (die_name
, actual_name
) != 0)
14351 /* Strip off the class name from the full name.
14352 We want the prefix. */
14353 int die_name_len
= strlen (die_name
);
14354 int actual_name_len
= strlen (actual_name
);
14356 /* Test for '::' as a sanity check. */
14357 if (actual_name_len
> die_name_len
+ 2
14358 && actual_name
[actual_name_len
14359 - die_name_len
- 1] == ':')
14361 obsavestring (actual_name
,
14362 actual_name_len
- die_name_len
- 2,
14363 &cu
->objfile
->objfile_obstack
);
14366 xfree (actual_name
);
14375 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14376 prefix part in such case. See
14377 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14380 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14382 struct attribute
*attr
;
14385 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14386 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14389 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14390 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14393 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14395 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14396 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14399 /* dwarf2_name had to be already called. */
14400 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14402 /* Strip the base name, keep any leading namespaces/classes. */
14403 base
= strrchr (DW_STRING (attr
), ':');
14404 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14407 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14408 &cu
->objfile
->objfile_obstack
);
14411 /* Return the name of the namespace/class that DIE is defined within,
14412 or "" if we can't tell. The caller should not xfree the result.
14414 For example, if we're within the method foo() in the following
14424 then determine_prefix on foo's die will return "N::C". */
14426 static const char *
14427 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14429 struct die_info
*parent
, *spec_die
;
14430 struct dwarf2_cu
*spec_cu
;
14431 struct type
*parent_type
;
14434 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14435 && cu
->language
!= language_fortran
)
14438 retval
= anonymous_struct_prefix (die
, cu
);
14442 /* We have to be careful in the presence of DW_AT_specification.
14443 For example, with GCC 3.4, given the code
14447 // Definition of N::foo.
14451 then we'll have a tree of DIEs like this:
14453 1: DW_TAG_compile_unit
14454 2: DW_TAG_namespace // N
14455 3: DW_TAG_subprogram // declaration of N::foo
14456 4: DW_TAG_subprogram // definition of N::foo
14457 DW_AT_specification // refers to die #3
14459 Thus, when processing die #4, we have to pretend that we're in
14460 the context of its DW_AT_specification, namely the contex of die
14463 spec_die
= die_specification (die
, &spec_cu
);
14464 if (spec_die
== NULL
)
14465 parent
= die
->parent
;
14468 parent
= spec_die
->parent
;
14472 if (parent
== NULL
)
14474 else if (parent
->building_fullname
)
14477 const char *parent_name
;
14479 /* It has been seen on RealView 2.2 built binaries,
14480 DW_TAG_template_type_param types actually _defined_ as
14481 children of the parent class:
14484 template class <class Enum> Class{};
14485 Class<enum E> class_e;
14487 1: DW_TAG_class_type (Class)
14488 2: DW_TAG_enumeration_type (E)
14489 3: DW_TAG_enumerator (enum1:0)
14490 3: DW_TAG_enumerator (enum2:1)
14492 2: DW_TAG_template_type_param
14493 DW_AT_type DW_FORM_ref_udata (E)
14495 Besides being broken debug info, it can put GDB into an
14496 infinite loop. Consider:
14498 When we're building the full name for Class<E>, we'll start
14499 at Class, and go look over its template type parameters,
14500 finding E. We'll then try to build the full name of E, and
14501 reach here. We're now trying to build the full name of E,
14502 and look over the parent DIE for containing scope. In the
14503 broken case, if we followed the parent DIE of E, we'd again
14504 find Class, and once again go look at its template type
14505 arguments, etc., etc. Simply don't consider such parent die
14506 as source-level parent of this die (it can't be, the language
14507 doesn't allow it), and break the loop here. */
14508 name
= dwarf2_name (die
, cu
);
14509 parent_name
= dwarf2_name (parent
, cu
);
14510 complaint (&symfile_complaints
,
14511 _("template param type '%s' defined within parent '%s'"),
14512 name
? name
: "<unknown>",
14513 parent_name
? parent_name
: "<unknown>");
14517 switch (parent
->tag
)
14519 case DW_TAG_namespace
:
14520 parent_type
= read_type_die (parent
, cu
);
14521 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14522 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14523 Work around this problem here. */
14524 if (cu
->language
== language_cplus
14525 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14527 /* We give a name to even anonymous namespaces. */
14528 return TYPE_TAG_NAME (parent_type
);
14529 case DW_TAG_class_type
:
14530 case DW_TAG_interface_type
:
14531 case DW_TAG_structure_type
:
14532 case DW_TAG_union_type
:
14533 case DW_TAG_module
:
14534 parent_type
= read_type_die (parent
, cu
);
14535 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14536 return TYPE_TAG_NAME (parent_type
);
14538 /* An anonymous structure is only allowed non-static data
14539 members; no typedefs, no member functions, et cetera.
14540 So it does not need a prefix. */
14542 case DW_TAG_compile_unit
:
14543 case DW_TAG_partial_unit
:
14544 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14545 if (cu
->language
== language_cplus
14546 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14547 && die
->child
!= NULL
14548 && (die
->tag
== DW_TAG_class_type
14549 || die
->tag
== DW_TAG_structure_type
14550 || die
->tag
== DW_TAG_union_type
))
14552 char *name
= guess_full_die_structure_name (die
, cu
);
14558 return determine_prefix (parent
, cu
);
14562 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14563 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14564 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14565 an obconcat, otherwise allocate storage for the result. The CU argument is
14566 used to determine the language and hence, the appropriate separator. */
14568 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14571 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14572 int physname
, struct dwarf2_cu
*cu
)
14574 const char *lead
= "";
14577 if (suffix
== NULL
|| suffix
[0] == '\0'
14578 || prefix
== NULL
|| prefix
[0] == '\0')
14580 else if (cu
->language
== language_java
)
14582 else if (cu
->language
== language_fortran
&& physname
)
14584 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14585 DW_AT_MIPS_linkage_name is preferred and used instead. */
14593 if (prefix
== NULL
)
14595 if (suffix
== NULL
)
14601 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14603 strcpy (retval
, lead
);
14604 strcat (retval
, prefix
);
14605 strcat (retval
, sep
);
14606 strcat (retval
, suffix
);
14611 /* We have an obstack. */
14612 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14616 /* Return sibling of die, NULL if no sibling. */
14618 static struct die_info
*
14619 sibling_die (struct die_info
*die
)
14621 return die
->sibling
;
14624 /* Get name of a die, return NULL if not found. */
14627 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14628 struct obstack
*obstack
)
14630 if (name
&& cu
->language
== language_cplus
)
14632 char *canon_name
= cp_canonicalize_string (name
);
14634 if (canon_name
!= NULL
)
14636 if (strcmp (canon_name
, name
) != 0)
14637 name
= obsavestring (canon_name
, strlen (canon_name
),
14639 xfree (canon_name
);
14646 /* Get name of a die, return NULL if not found. */
14649 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14651 struct attribute
*attr
;
14653 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14654 if ((!attr
|| !DW_STRING (attr
))
14655 && die
->tag
!= DW_TAG_class_type
14656 && die
->tag
!= DW_TAG_interface_type
14657 && die
->tag
!= DW_TAG_structure_type
14658 && die
->tag
!= DW_TAG_union_type
)
14663 case DW_TAG_compile_unit
:
14664 case DW_TAG_partial_unit
:
14665 /* Compilation units have a DW_AT_name that is a filename, not
14666 a source language identifier. */
14667 case DW_TAG_enumeration_type
:
14668 case DW_TAG_enumerator
:
14669 /* These tags always have simple identifiers already; no need
14670 to canonicalize them. */
14671 return DW_STRING (attr
);
14673 case DW_TAG_subprogram
:
14674 /* Java constructors will all be named "<init>", so return
14675 the class name when we see this special case. */
14676 if (cu
->language
== language_java
14677 && DW_STRING (attr
) != NULL
14678 && strcmp (DW_STRING (attr
), "<init>") == 0)
14680 struct dwarf2_cu
*spec_cu
= cu
;
14681 struct die_info
*spec_die
;
14683 /* GCJ will output '<init>' for Java constructor names.
14684 For this special case, return the name of the parent class. */
14686 /* GCJ may output suprogram DIEs with AT_specification set.
14687 If so, use the name of the specified DIE. */
14688 spec_die
= die_specification (die
, &spec_cu
);
14689 if (spec_die
!= NULL
)
14690 return dwarf2_name (spec_die
, spec_cu
);
14695 if (die
->tag
== DW_TAG_class_type
)
14696 return dwarf2_name (die
, cu
);
14698 while (die
->tag
!= DW_TAG_compile_unit
14699 && die
->tag
!= DW_TAG_partial_unit
);
14703 case DW_TAG_class_type
:
14704 case DW_TAG_interface_type
:
14705 case DW_TAG_structure_type
:
14706 case DW_TAG_union_type
:
14707 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14708 structures or unions. These were of the form "._%d" in GCC 4.1,
14709 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14710 and GCC 4.4. We work around this problem by ignoring these. */
14711 if (attr
&& DW_STRING (attr
)
14712 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14713 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14716 /* GCC might emit a nameless typedef that has a linkage name. See
14717 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14718 if (!attr
|| DW_STRING (attr
) == NULL
)
14720 char *demangled
= NULL
;
14722 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14724 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14726 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14729 /* Avoid demangling DW_STRING (attr) the second time on a second
14730 call for the same DIE. */
14731 if (!DW_STRING_IS_CANONICAL (attr
))
14732 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14738 /* FIXME: we already did this for the partial symbol... */
14739 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14740 &cu
->objfile
->objfile_obstack
);
14741 DW_STRING_IS_CANONICAL (attr
) = 1;
14744 /* Strip any leading namespaces/classes, keep only the base name.
14745 DW_AT_name for named DIEs does not contain the prefixes. */
14746 base
= strrchr (DW_STRING (attr
), ':');
14747 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14750 return DW_STRING (attr
);
14759 if (!DW_STRING_IS_CANONICAL (attr
))
14762 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14763 &cu
->objfile
->objfile_obstack
);
14764 DW_STRING_IS_CANONICAL (attr
) = 1;
14766 return DW_STRING (attr
);
14769 /* Return the die that this die in an extension of, or NULL if there
14770 is none. *EXT_CU is the CU containing DIE on input, and the CU
14771 containing the return value on output. */
14773 static struct die_info
*
14774 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14776 struct attribute
*attr
;
14778 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14782 return follow_die_ref (die
, attr
, ext_cu
);
14785 /* Convert a DIE tag into its string name. */
14787 static const char *
14788 dwarf_tag_name (unsigned tag
)
14790 const char *name
= get_DW_TAG_name (tag
);
14793 return "DW_TAG_<unknown>";
14798 /* Convert a DWARF attribute code into its string name. */
14800 static const char *
14801 dwarf_attr_name (unsigned attr
)
14805 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14806 if (attr
== DW_AT_MIPS_fde
)
14807 return "DW_AT_MIPS_fde";
14809 if (attr
== DW_AT_HP_block_index
)
14810 return "DW_AT_HP_block_index";
14813 name
= get_DW_AT_name (attr
);
14816 return "DW_AT_<unknown>";
14821 /* Convert a DWARF value form code into its string name. */
14823 static const char *
14824 dwarf_form_name (unsigned form
)
14826 const char *name
= get_DW_FORM_name (form
);
14829 return "DW_FORM_<unknown>";
14835 dwarf_bool_name (unsigned mybool
)
14843 /* Convert a DWARF type code into its string name. */
14845 static const char *
14846 dwarf_type_encoding_name (unsigned enc
)
14848 const char *name
= get_DW_ATE_name (enc
);
14851 return "DW_ATE_<unknown>";
14857 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14861 print_spaces (indent
, f
);
14862 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14863 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14865 if (die
->parent
!= NULL
)
14867 print_spaces (indent
, f
);
14868 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14869 die
->parent
->offset
.sect_off
);
14872 print_spaces (indent
, f
);
14873 fprintf_unfiltered (f
, " has children: %s\n",
14874 dwarf_bool_name (die
->child
!= NULL
));
14876 print_spaces (indent
, f
);
14877 fprintf_unfiltered (f
, " attributes:\n");
14879 for (i
= 0; i
< die
->num_attrs
; ++i
)
14881 print_spaces (indent
, f
);
14882 fprintf_unfiltered (f
, " %s (%s) ",
14883 dwarf_attr_name (die
->attrs
[i
].name
),
14884 dwarf_form_name (die
->attrs
[i
].form
));
14886 switch (die
->attrs
[i
].form
)
14889 case DW_FORM_GNU_addr_index
:
14890 fprintf_unfiltered (f
, "address: ");
14891 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14893 case DW_FORM_block2
:
14894 case DW_FORM_block4
:
14895 case DW_FORM_block
:
14896 case DW_FORM_block1
:
14897 fprintf_unfiltered (f
, "block: size %d",
14898 DW_BLOCK (&die
->attrs
[i
])->size
);
14900 case DW_FORM_exprloc
:
14901 fprintf_unfiltered (f
, "expression: size %u",
14902 DW_BLOCK (&die
->attrs
[i
])->size
);
14904 case DW_FORM_ref_addr
:
14905 fprintf_unfiltered (f
, "ref address: ");
14906 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14912 case DW_FORM_ref_udata
:
14913 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14914 (long) (DW_UNSND (&die
->attrs
[i
])));
14916 case DW_FORM_data1
:
14917 case DW_FORM_data2
:
14918 case DW_FORM_data4
:
14919 case DW_FORM_data8
:
14920 case DW_FORM_udata
:
14921 case DW_FORM_sdata
:
14922 fprintf_unfiltered (f
, "constant: %s",
14923 pulongest (DW_UNSND (&die
->attrs
[i
])));
14925 case DW_FORM_sec_offset
:
14926 fprintf_unfiltered (f
, "section offset: %s",
14927 pulongest (DW_UNSND (&die
->attrs
[i
])));
14929 case DW_FORM_ref_sig8
:
14930 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14931 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14932 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14934 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14936 case DW_FORM_string
:
14938 case DW_FORM_GNU_str_index
:
14939 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14940 DW_STRING (&die
->attrs
[i
])
14941 ? DW_STRING (&die
->attrs
[i
]) : "",
14942 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14945 if (DW_UNSND (&die
->attrs
[i
]))
14946 fprintf_unfiltered (f
, "flag: TRUE");
14948 fprintf_unfiltered (f
, "flag: FALSE");
14950 case DW_FORM_flag_present
:
14951 fprintf_unfiltered (f
, "flag: TRUE");
14953 case DW_FORM_indirect
:
14954 /* The reader will have reduced the indirect form to
14955 the "base form" so this form should not occur. */
14956 fprintf_unfiltered (f
,
14957 "unexpected attribute form: DW_FORM_indirect");
14960 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14961 die
->attrs
[i
].form
);
14964 fprintf_unfiltered (f
, "\n");
14969 dump_die_for_error (struct die_info
*die
)
14971 dump_die_shallow (gdb_stderr
, 0, die
);
14975 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14977 int indent
= level
* 4;
14979 gdb_assert (die
!= NULL
);
14981 if (level
>= max_level
)
14984 dump_die_shallow (f
, indent
, die
);
14986 if (die
->child
!= NULL
)
14988 print_spaces (indent
, f
);
14989 fprintf_unfiltered (f
, " Children:");
14990 if (level
+ 1 < max_level
)
14992 fprintf_unfiltered (f
, "\n");
14993 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14997 fprintf_unfiltered (f
,
14998 " [not printed, max nesting level reached]\n");
15002 if (die
->sibling
!= NULL
&& level
> 0)
15004 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15008 /* This is called from the pdie macro in gdbinit.in.
15009 It's not static so gcc will keep a copy callable from gdb. */
15012 dump_die (struct die_info
*die
, int max_level
)
15014 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15018 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15022 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15028 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15029 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15032 is_ref_attr (struct attribute
*attr
)
15034 switch (attr
->form
)
15036 case DW_FORM_ref_addr
:
15041 case DW_FORM_ref_udata
:
15048 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15052 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15054 sect_offset retval
= { DW_UNSND (attr
) };
15056 if (is_ref_attr (attr
))
15059 retval
.sect_off
= 0;
15060 complaint (&symfile_complaints
,
15061 _("unsupported die ref attribute form: '%s'"),
15062 dwarf_form_name (attr
->form
));
15066 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15067 * the value held by the attribute is not constant. */
15070 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15072 if (attr
->form
== DW_FORM_sdata
)
15073 return DW_SND (attr
);
15074 else if (attr
->form
== DW_FORM_udata
15075 || attr
->form
== DW_FORM_data1
15076 || attr
->form
== DW_FORM_data2
15077 || attr
->form
== DW_FORM_data4
15078 || attr
->form
== DW_FORM_data8
)
15079 return DW_UNSND (attr
);
15082 complaint (&symfile_complaints
,
15083 _("Attribute value is not a constant (%s)"),
15084 dwarf_form_name (attr
->form
));
15085 return default_value
;
15089 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15090 unit and add it to our queue.
15091 The result is non-zero if PER_CU was queued, otherwise the result is zero
15092 meaning either PER_CU is already queued or it is already loaded. */
15095 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15096 struct dwarf2_per_cu_data
*per_cu
,
15097 enum language pretend_language
)
15099 /* We may arrive here during partial symbol reading, if we need full
15100 DIEs to process an unusual case (e.g. template arguments). Do
15101 not queue PER_CU, just tell our caller to load its DIEs. */
15102 if (dwarf2_per_objfile
->reading_partial_symbols
)
15104 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15109 /* Mark the dependence relation so that we don't flush PER_CU
15111 dwarf2_add_dependence (this_cu
, per_cu
);
15113 /* If it's already on the queue, we have nothing to do. */
15114 if (per_cu
->queued
)
15117 /* If the compilation unit is already loaded, just mark it as
15119 if (per_cu
->cu
!= NULL
)
15121 per_cu
->cu
->last_used
= 0;
15125 /* Add it to the queue. */
15126 queue_comp_unit (per_cu
, pretend_language
);
15131 /* Follow reference or signature attribute ATTR of SRC_DIE.
15132 On entry *REF_CU is the CU of SRC_DIE.
15133 On exit *REF_CU is the CU of the result. */
15135 static struct die_info
*
15136 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15137 struct dwarf2_cu
**ref_cu
)
15139 struct die_info
*die
;
15141 if (is_ref_attr (attr
))
15142 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15143 else if (attr
->form
== DW_FORM_ref_sig8
)
15144 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15147 dump_die_for_error (src_die
);
15148 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15149 (*ref_cu
)->objfile
->name
);
15155 /* Follow reference OFFSET.
15156 On entry *REF_CU is the CU of the source die referencing OFFSET.
15157 On exit *REF_CU is the CU of the result.
15158 Returns NULL if OFFSET is invalid. */
15160 static struct die_info
*
15161 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15163 struct die_info temp_die
;
15164 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15166 gdb_assert (cu
->per_cu
!= NULL
);
15170 if (cu
->per_cu
->is_debug_types
)
15172 /* .debug_types CUs cannot reference anything outside their CU.
15173 If they need to, they have to reference a signatured type via
15174 DW_FORM_ref_sig8. */
15175 if (! offset_in_cu_p (&cu
->header
, offset
))
15178 else if (! offset_in_cu_p (&cu
->header
, offset
))
15180 struct dwarf2_per_cu_data
*per_cu
;
15182 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15184 /* If necessary, add it to the queue and load its DIEs. */
15185 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
15186 load_full_comp_unit (per_cu
, cu
->language
);
15188 target_cu
= per_cu
->cu
;
15190 else if (cu
->dies
== NULL
)
15192 /* We're loading full DIEs during partial symbol reading. */
15193 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15194 load_full_comp_unit (cu
->per_cu
, language_minimal
);
15197 *ref_cu
= target_cu
;
15198 temp_die
.offset
= offset
;
15199 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15202 /* Follow reference attribute ATTR of SRC_DIE.
15203 On entry *REF_CU is the CU of SRC_DIE.
15204 On exit *REF_CU is the CU of the result. */
15206 static struct die_info
*
15207 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15208 struct dwarf2_cu
**ref_cu
)
15210 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15211 struct dwarf2_cu
*cu
= *ref_cu
;
15212 struct die_info
*die
;
15214 die
= follow_die_offset (offset
, ref_cu
);
15216 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15217 "at 0x%x [in module %s]"),
15218 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15223 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15224 Returned value is intended for DW_OP_call*. Returned
15225 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15227 struct dwarf2_locexpr_baton
15228 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15229 struct dwarf2_per_cu_data
*per_cu
,
15230 CORE_ADDR (*get_frame_pc
) (void *baton
),
15233 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15234 struct dwarf2_cu
*cu
;
15235 struct die_info
*die
;
15236 struct attribute
*attr
;
15237 struct dwarf2_locexpr_baton retval
;
15239 dw2_setup (per_cu
->objfile
);
15241 if (per_cu
->cu
== NULL
)
15245 die
= follow_die_offset (offset
, &cu
);
15247 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15248 offset
.sect_off
, per_cu
->objfile
->name
);
15250 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15253 /* DWARF: "If there is no such attribute, then there is no effect.".
15254 DATA is ignored if SIZE is 0. */
15256 retval
.data
= NULL
;
15259 else if (attr_form_is_section_offset (attr
))
15261 struct dwarf2_loclist_baton loclist_baton
;
15262 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15265 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15267 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15269 retval
.size
= size
;
15273 if (!attr_form_is_block (attr
))
15274 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15275 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15276 offset
.sect_off
, per_cu
->objfile
->name
);
15278 retval
.data
= DW_BLOCK (attr
)->data
;
15279 retval
.size
= DW_BLOCK (attr
)->size
;
15281 retval
.per_cu
= cu
->per_cu
;
15283 age_cached_comp_units ();
15288 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15292 dwarf2_get_die_type (cu_offset die_offset
,
15293 struct dwarf2_per_cu_data
*per_cu
)
15295 sect_offset die_offset_sect
;
15297 dw2_setup (per_cu
->objfile
);
15299 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15300 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15303 /* Follow the signature attribute ATTR in SRC_DIE.
15304 On entry *REF_CU is the CU of SRC_DIE.
15305 On exit *REF_CU is the CU of the result. */
15307 static struct die_info
*
15308 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15309 struct dwarf2_cu
**ref_cu
)
15311 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15312 struct die_info temp_die
;
15313 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15314 struct dwarf2_cu
*sig_cu
;
15315 struct die_info
*die
;
15317 /* sig_type will be NULL if the signatured type is missing from
15319 if (sig_type
== NULL
)
15320 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15321 "at 0x%x [in module %s]"),
15322 src_die
->offset
.sect_off
, objfile
->name
);
15324 /* If necessary, add it to the queue and load its DIEs. */
15326 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15327 read_signatured_type (sig_type
);
15329 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15331 sig_cu
= sig_type
->per_cu
.cu
;
15332 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15333 temp_die
.offset
= sig_type
->type_offset_in_section
;
15334 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15335 temp_die
.offset
.sect_off
);
15342 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15343 "from DIE at 0x%x [in module %s]"),
15344 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15347 /* Given an offset of a signatured type, return its signatured_type. */
15349 static struct signatured_type
*
15350 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15351 struct dwarf2_section_info
*section
,
15352 sect_offset offset
)
15354 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15355 unsigned int length
, initial_length_size
;
15356 unsigned int sig_offset
;
15357 struct signatured_type find_entry
, *sig_type
;
15359 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15360 sig_offset
= (initial_length_size
15362 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15363 + 1 /*address_size*/);
15364 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15365 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15367 /* This is only used to lookup previously recorded types.
15368 If we didn't find it, it's our bug. */
15369 gdb_assert (sig_type
!= NULL
);
15370 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15375 /* Load the DIEs associated with type unit PER_CU into memory. */
15378 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15380 struct objfile
*objfile
= per_cu
->objfile
;
15381 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15382 sect_offset offset
= per_cu
->offset
;
15383 struct signatured_type
*sig_type
;
15385 dwarf2_read_section (objfile
, sect
);
15387 /* We have the section offset, but we need the signature to do the
15388 hash table lookup. */
15389 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15390 the signature to assert we found the right one.
15391 Ok, but it's a lot of work. We should simplify things so any needed
15392 assert doesn't require all this clumsiness. */
15393 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15395 gdb_assert (&sig_type
->per_cu
== per_cu
);
15396 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15398 read_signatured_type (sig_type
);
15400 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15403 /* die_reader_func for read_signatured_type.
15404 This is identical to load_full_comp_unit_reader,
15405 but is kept separate for now. */
15408 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15409 gdb_byte
*info_ptr
,
15410 struct die_info
*comp_unit_die
,
15414 struct dwarf2_cu
*cu
= reader
->cu
;
15416 gdb_assert (cu
->die_hash
== NULL
);
15418 htab_create_alloc_ex (cu
->header
.length
/ 12,
15422 &cu
->comp_unit_obstack
,
15423 hashtab_obstack_allocate
,
15424 dummy_obstack_deallocate
);
15427 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15428 &info_ptr
, comp_unit_die
);
15429 cu
->dies
= comp_unit_die
;
15430 /* comp_unit_die is not stored in die_hash, no need. */
15432 /* We try not to read any attributes in this function, because not
15433 all CUs needed for references have been loaded yet, and symbol
15434 table processing isn't initialized. But we have to set the CU language,
15435 or we won't be able to build types correctly.
15436 Similarly, if we do not read the producer, we can not apply
15437 producer-specific interpretation. */
15438 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15441 /* Read in a signatured type and build its CU and DIEs.
15442 If the type is a stub for the real type in a DWO file,
15443 read in the real type from the DWO file as well. */
15446 read_signatured_type (struct signatured_type
*sig_type
)
15448 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15450 gdb_assert (per_cu
->is_debug_types
);
15451 gdb_assert (per_cu
->cu
== NULL
);
15453 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15456 /* Decode simple location descriptions.
15457 Given a pointer to a dwarf block that defines a location, compute
15458 the location and return the value.
15460 NOTE drow/2003-11-18: This function is called in two situations
15461 now: for the address of static or global variables (partial symbols
15462 only) and for offsets into structures which are expected to be
15463 (more or less) constant. The partial symbol case should go away,
15464 and only the constant case should remain. That will let this
15465 function complain more accurately. A few special modes are allowed
15466 without complaint for global variables (for instance, global
15467 register values and thread-local values).
15469 A location description containing no operations indicates that the
15470 object is optimized out. The return value is 0 for that case.
15471 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15472 callers will only want a very basic result and this can become a
15475 Note that stack[0] is unused except as a default error return. */
15478 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15480 struct objfile
*objfile
= cu
->objfile
;
15482 int size
= blk
->size
;
15483 gdb_byte
*data
= blk
->data
;
15484 CORE_ADDR stack
[64];
15486 unsigned int bytes_read
, unsnd
;
15492 stack
[++stacki
] = 0;
15531 stack
[++stacki
] = op
- DW_OP_lit0
;
15566 stack
[++stacki
] = op
- DW_OP_reg0
;
15568 dwarf2_complex_location_expr_complaint ();
15572 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15574 stack
[++stacki
] = unsnd
;
15576 dwarf2_complex_location_expr_complaint ();
15580 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15585 case DW_OP_const1u
:
15586 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15590 case DW_OP_const1s
:
15591 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15595 case DW_OP_const2u
:
15596 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15600 case DW_OP_const2s
:
15601 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15605 case DW_OP_const4u
:
15606 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15610 case DW_OP_const4s
:
15611 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15615 case DW_OP_const8u
:
15616 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15621 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15627 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15632 stack
[stacki
+ 1] = stack
[stacki
];
15637 stack
[stacki
- 1] += stack
[stacki
];
15641 case DW_OP_plus_uconst
:
15642 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15648 stack
[stacki
- 1] -= stack
[stacki
];
15653 /* If we're not the last op, then we definitely can't encode
15654 this using GDB's address_class enum. This is valid for partial
15655 global symbols, although the variable's address will be bogus
15658 dwarf2_complex_location_expr_complaint ();
15661 case DW_OP_GNU_push_tls_address
:
15662 /* The top of the stack has the offset from the beginning
15663 of the thread control block at which the variable is located. */
15664 /* Nothing should follow this operator, so the top of stack would
15666 /* This is valid for partial global symbols, but the variable's
15667 address will be bogus in the psymtab. Make it always at least
15668 non-zero to not look as a variable garbage collected by linker
15669 which have DW_OP_addr 0. */
15671 dwarf2_complex_location_expr_complaint ();
15675 case DW_OP_GNU_uninit
:
15678 case DW_OP_GNU_addr_index
:
15679 case DW_OP_GNU_const_index
:
15680 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15687 const char *name
= get_DW_OP_name (op
);
15690 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15693 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15697 return (stack
[stacki
]);
15700 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15701 outside of the allocated space. Also enforce minimum>0. */
15702 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15704 complaint (&symfile_complaints
,
15705 _("location description stack overflow"));
15711 complaint (&symfile_complaints
,
15712 _("location description stack underflow"));
15716 return (stack
[stacki
]);
15719 /* memory allocation interface */
15721 static struct dwarf_block
*
15722 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15724 struct dwarf_block
*blk
;
15726 blk
= (struct dwarf_block
*)
15727 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15731 static struct abbrev_info
*
15732 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15734 struct abbrev_info
*abbrev
;
15736 abbrev
= (struct abbrev_info
*)
15737 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15738 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15742 static struct die_info
*
15743 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15745 struct die_info
*die
;
15746 size_t size
= sizeof (struct die_info
);
15749 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15751 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15752 memset (die
, 0, sizeof (struct die_info
));
15757 /* Macro support. */
15759 /* Return the full name of file number I in *LH's file name table.
15760 Use COMP_DIR as the name of the current directory of the
15761 compilation. The result is allocated using xmalloc; the caller is
15762 responsible for freeing it. */
15764 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15766 /* Is the file number a valid index into the line header's file name
15767 table? Remember that file numbers start with one, not zero. */
15768 if (1 <= file
&& file
<= lh
->num_file_names
)
15770 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15772 if (IS_ABSOLUTE_PATH (fe
->name
))
15773 return xstrdup (fe
->name
);
15781 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15787 dir_len
= strlen (dir
);
15788 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15789 strcpy (full_name
, dir
);
15790 full_name
[dir_len
] = '/';
15791 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15795 return xstrdup (fe
->name
);
15800 /* The compiler produced a bogus file number. We can at least
15801 record the macro definitions made in the file, even if we
15802 won't be able to find the file by name. */
15803 char fake_name
[80];
15805 sprintf (fake_name
, "<bad macro file number %d>", file
);
15807 complaint (&symfile_complaints
,
15808 _("bad file number in macro information (%d)"),
15811 return xstrdup (fake_name
);
15816 static struct macro_source_file
*
15817 macro_start_file (int file
, int line
,
15818 struct macro_source_file
*current_file
,
15819 const char *comp_dir
,
15820 struct line_header
*lh
, struct objfile
*objfile
)
15822 /* The full name of this source file. */
15823 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15825 /* We don't create a macro table for this compilation unit
15826 at all until we actually get a filename. */
15827 if (! pending_macros
)
15828 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15829 objfile
->macro_cache
);
15831 if (! current_file
)
15833 /* If we have no current file, then this must be the start_file
15834 directive for the compilation unit's main source file. */
15835 current_file
= macro_set_main (pending_macros
, full_name
);
15836 macro_define_special (pending_macros
);
15839 current_file
= macro_include (current_file
, line
, full_name
);
15843 return current_file
;
15847 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15848 followed by a null byte. */
15850 copy_string (const char *buf
, int len
)
15852 char *s
= xmalloc (len
+ 1);
15854 memcpy (s
, buf
, len
);
15860 static const char *
15861 consume_improper_spaces (const char *p
, const char *body
)
15865 complaint (&symfile_complaints
,
15866 _("macro definition contains spaces "
15867 "in formal argument list:\n`%s'"),
15879 parse_macro_definition (struct macro_source_file
*file
, int line
,
15884 /* The body string takes one of two forms. For object-like macro
15885 definitions, it should be:
15887 <macro name> " " <definition>
15889 For function-like macro definitions, it should be:
15891 <macro name> "() " <definition>
15893 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15895 Spaces may appear only where explicitly indicated, and in the
15898 The Dwarf 2 spec says that an object-like macro's name is always
15899 followed by a space, but versions of GCC around March 2002 omit
15900 the space when the macro's definition is the empty string.
15902 The Dwarf 2 spec says that there should be no spaces between the
15903 formal arguments in a function-like macro's formal argument list,
15904 but versions of GCC around March 2002 include spaces after the
15908 /* Find the extent of the macro name. The macro name is terminated
15909 by either a space or null character (for an object-like macro) or
15910 an opening paren (for a function-like macro). */
15911 for (p
= body
; *p
; p
++)
15912 if (*p
== ' ' || *p
== '(')
15915 if (*p
== ' ' || *p
== '\0')
15917 /* It's an object-like macro. */
15918 int name_len
= p
- body
;
15919 char *name
= copy_string (body
, name_len
);
15920 const char *replacement
;
15923 replacement
= body
+ name_len
+ 1;
15926 dwarf2_macro_malformed_definition_complaint (body
);
15927 replacement
= body
+ name_len
;
15930 macro_define_object (file
, line
, name
, replacement
);
15934 else if (*p
== '(')
15936 /* It's a function-like macro. */
15937 char *name
= copy_string (body
, p
- body
);
15940 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15944 p
= consume_improper_spaces (p
, body
);
15946 /* Parse the formal argument list. */
15947 while (*p
&& *p
!= ')')
15949 /* Find the extent of the current argument name. */
15950 const char *arg_start
= p
;
15952 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15955 if (! *p
|| p
== arg_start
)
15956 dwarf2_macro_malformed_definition_complaint (body
);
15959 /* Make sure argv has room for the new argument. */
15960 if (argc
>= argv_size
)
15963 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15966 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15969 p
= consume_improper_spaces (p
, body
);
15971 /* Consume the comma, if present. */
15976 p
= consume_improper_spaces (p
, body
);
15985 /* Perfectly formed definition, no complaints. */
15986 macro_define_function (file
, line
, name
,
15987 argc
, (const char **) argv
,
15989 else if (*p
== '\0')
15991 /* Complain, but do define it. */
15992 dwarf2_macro_malformed_definition_complaint (body
);
15993 macro_define_function (file
, line
, name
,
15994 argc
, (const char **) argv
,
15998 /* Just complain. */
15999 dwarf2_macro_malformed_definition_complaint (body
);
16002 /* Just complain. */
16003 dwarf2_macro_malformed_definition_complaint (body
);
16009 for (i
= 0; i
< argc
; i
++)
16015 dwarf2_macro_malformed_definition_complaint (body
);
16018 /* Skip some bytes from BYTES according to the form given in FORM.
16019 Returns the new pointer. */
16022 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16023 enum dwarf_form form
,
16024 unsigned int offset_size
,
16025 struct dwarf2_section_info
*section
)
16027 unsigned int bytes_read
;
16031 case DW_FORM_data1
:
16036 case DW_FORM_data2
:
16040 case DW_FORM_data4
:
16044 case DW_FORM_data8
:
16048 case DW_FORM_string
:
16049 read_direct_string (abfd
, bytes
, &bytes_read
);
16050 bytes
+= bytes_read
;
16053 case DW_FORM_sec_offset
:
16055 bytes
+= offset_size
;
16058 case DW_FORM_block
:
16059 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16060 bytes
+= bytes_read
;
16063 case DW_FORM_block1
:
16064 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16066 case DW_FORM_block2
:
16067 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16069 case DW_FORM_block4
:
16070 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16073 case DW_FORM_sdata
:
16074 case DW_FORM_udata
:
16075 case DW_FORM_GNU_addr_index
:
16076 case DW_FORM_GNU_str_index
:
16077 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16080 dwarf2_section_buffer_overflow_complaint (section
);
16088 complaint (&symfile_complaints
,
16089 _("invalid form 0x%x in `%s'"),
16091 section
->asection
->name
);
16099 /* A helper for dwarf_decode_macros that handles skipping an unknown
16100 opcode. Returns an updated pointer to the macro data buffer; or,
16101 on error, issues a complaint and returns NULL. */
16104 skip_unknown_opcode (unsigned int opcode
,
16105 gdb_byte
**opcode_definitions
,
16106 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16108 unsigned int offset_size
,
16109 struct dwarf2_section_info
*section
)
16111 unsigned int bytes_read
, i
;
16115 if (opcode_definitions
[opcode
] == NULL
)
16117 complaint (&symfile_complaints
,
16118 _("unrecognized DW_MACFINO opcode 0x%x"),
16123 defn
= opcode_definitions
[opcode
];
16124 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16125 defn
+= bytes_read
;
16127 for (i
= 0; i
< arg
; ++i
)
16129 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16131 if (mac_ptr
== NULL
)
16133 /* skip_form_bytes already issued the complaint. */
16141 /* A helper function which parses the header of a macro section.
16142 If the macro section is the extended (for now called "GNU") type,
16143 then this updates *OFFSET_SIZE. Returns a pointer to just after
16144 the header, or issues a complaint and returns NULL on error. */
16147 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16150 unsigned int *offset_size
,
16151 int section_is_gnu
)
16153 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16155 if (section_is_gnu
)
16157 unsigned int version
, flags
;
16159 version
= read_2_bytes (abfd
, mac_ptr
);
16162 complaint (&symfile_complaints
,
16163 _("unrecognized version `%d' in .debug_macro section"),
16169 flags
= read_1_byte (abfd
, mac_ptr
);
16171 *offset_size
= (flags
& 1) ? 8 : 4;
16173 if ((flags
& 2) != 0)
16174 /* We don't need the line table offset. */
16175 mac_ptr
+= *offset_size
;
16177 /* Vendor opcode descriptions. */
16178 if ((flags
& 4) != 0)
16180 unsigned int i
, count
;
16182 count
= read_1_byte (abfd
, mac_ptr
);
16184 for (i
= 0; i
< count
; ++i
)
16186 unsigned int opcode
, bytes_read
;
16189 opcode
= read_1_byte (abfd
, mac_ptr
);
16191 opcode_definitions
[opcode
] = mac_ptr
;
16192 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16193 mac_ptr
+= bytes_read
;
16202 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16203 including DW_MACRO_GNU_transparent_include. */
16206 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16207 struct macro_source_file
*current_file
,
16208 struct line_header
*lh
, char *comp_dir
,
16209 struct dwarf2_section_info
*section
,
16210 int section_is_gnu
,
16211 unsigned int offset_size
,
16212 struct objfile
*objfile
,
16213 htab_t include_hash
)
16215 enum dwarf_macro_record_type macinfo_type
;
16216 int at_commandline
;
16217 gdb_byte
*opcode_definitions
[256];
16219 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16220 &offset_size
, section_is_gnu
);
16221 if (mac_ptr
== NULL
)
16223 /* We already issued a complaint. */
16227 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16228 GDB is still reading the definitions from command line. First
16229 DW_MACINFO_start_file will need to be ignored as it was already executed
16230 to create CURRENT_FILE for the main source holding also the command line
16231 definitions. On first met DW_MACINFO_start_file this flag is reset to
16232 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16234 at_commandline
= 1;
16238 /* Do we at least have room for a macinfo type byte? */
16239 if (mac_ptr
>= mac_end
)
16241 dwarf2_section_buffer_overflow_complaint (section
);
16245 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16248 /* Note that we rely on the fact that the corresponding GNU and
16249 DWARF constants are the same. */
16250 switch (macinfo_type
)
16252 /* A zero macinfo type indicates the end of the macro
16257 case DW_MACRO_GNU_define
:
16258 case DW_MACRO_GNU_undef
:
16259 case DW_MACRO_GNU_define_indirect
:
16260 case DW_MACRO_GNU_undef_indirect
:
16262 unsigned int bytes_read
;
16267 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16268 mac_ptr
+= bytes_read
;
16270 if (macinfo_type
== DW_MACRO_GNU_define
16271 || macinfo_type
== DW_MACRO_GNU_undef
)
16273 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16274 mac_ptr
+= bytes_read
;
16278 LONGEST str_offset
;
16280 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16281 mac_ptr
+= offset_size
;
16283 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16286 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16287 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16288 if (! current_file
)
16290 /* DWARF violation as no main source is present. */
16291 complaint (&symfile_complaints
,
16292 _("debug info with no main source gives macro %s "
16294 is_define
? _("definition") : _("undefinition"),
16298 if ((line
== 0 && !at_commandline
)
16299 || (line
!= 0 && at_commandline
))
16300 complaint (&symfile_complaints
,
16301 _("debug info gives %s macro %s with %s line %d: %s"),
16302 at_commandline
? _("command-line") : _("in-file"),
16303 is_define
? _("definition") : _("undefinition"),
16304 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16307 parse_macro_definition (current_file
, line
, body
);
16310 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16311 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16312 macro_undef (current_file
, line
, body
);
16317 case DW_MACRO_GNU_start_file
:
16319 unsigned int bytes_read
;
16322 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16323 mac_ptr
+= bytes_read
;
16324 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16325 mac_ptr
+= bytes_read
;
16327 if ((line
== 0 && !at_commandline
)
16328 || (line
!= 0 && at_commandline
))
16329 complaint (&symfile_complaints
,
16330 _("debug info gives source %d included "
16331 "from %s at %s line %d"),
16332 file
, at_commandline
? _("command-line") : _("file"),
16333 line
== 0 ? _("zero") : _("non-zero"), line
);
16335 if (at_commandline
)
16337 /* This DW_MACRO_GNU_start_file was executed in the
16339 at_commandline
= 0;
16342 current_file
= macro_start_file (file
, line
,
16343 current_file
, comp_dir
,
16348 case DW_MACRO_GNU_end_file
:
16349 if (! current_file
)
16350 complaint (&symfile_complaints
,
16351 _("macro debug info has an unmatched "
16352 "`close_file' directive"));
16355 current_file
= current_file
->included_by
;
16356 if (! current_file
)
16358 enum dwarf_macro_record_type next_type
;
16360 /* GCC circa March 2002 doesn't produce the zero
16361 type byte marking the end of the compilation
16362 unit. Complain if it's not there, but exit no
16365 /* Do we at least have room for a macinfo type byte? */
16366 if (mac_ptr
>= mac_end
)
16368 dwarf2_section_buffer_overflow_complaint (section
);
16372 /* We don't increment mac_ptr here, so this is just
16374 next_type
= read_1_byte (abfd
, mac_ptr
);
16375 if (next_type
!= 0)
16376 complaint (&symfile_complaints
,
16377 _("no terminating 0-type entry for "
16378 "macros in `.debug_macinfo' section"));
16385 case DW_MACRO_GNU_transparent_include
:
16390 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16391 mac_ptr
+= offset_size
;
16393 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16396 /* This has actually happened; see
16397 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16398 complaint (&symfile_complaints
,
16399 _("recursive DW_MACRO_GNU_transparent_include in "
16400 ".debug_macro section"));
16406 dwarf_decode_macro_bytes (abfd
,
16407 section
->buffer
+ offset
,
16408 mac_end
, current_file
,
16410 section
, section_is_gnu
,
16411 offset_size
, objfile
, include_hash
);
16413 htab_remove_elt (include_hash
, mac_ptr
);
16418 case DW_MACINFO_vendor_ext
:
16419 if (!section_is_gnu
)
16421 unsigned int bytes_read
;
16424 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16425 mac_ptr
+= bytes_read
;
16426 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16427 mac_ptr
+= bytes_read
;
16429 /* We don't recognize any vendor extensions. */
16435 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16436 mac_ptr
, mac_end
, abfd
, offset_size
,
16438 if (mac_ptr
== NULL
)
16442 } while (macinfo_type
!= 0);
16446 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
16447 char *comp_dir
, int section_is_gnu
)
16449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16450 struct line_header
*lh
= cu
->line_header
;
16452 gdb_byte
*mac_ptr
, *mac_end
;
16453 struct macro_source_file
*current_file
= 0;
16454 enum dwarf_macro_record_type macinfo_type
;
16455 unsigned int offset_size
= cu
->header
.offset_size
;
16456 gdb_byte
*opcode_definitions
[256];
16457 struct cleanup
*cleanup
;
16458 htab_t include_hash
;
16460 struct dwarf2_section_info
*section
;
16461 const char *section_name
;
16463 if (cu
->dwo_unit
!= NULL
)
16465 if (section_is_gnu
)
16467 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
16468 section_name
= ".debug_macro.dwo";
16472 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
16473 section_name
= ".debug_macinfo.dwo";
16478 if (section_is_gnu
)
16480 section
= &dwarf2_per_objfile
->macro
;
16481 section_name
= ".debug_macro";
16485 section
= &dwarf2_per_objfile
->macinfo
;
16486 section_name
= ".debug_macinfo";
16490 dwarf2_read_section (objfile
, section
);
16491 if (section
->buffer
== NULL
)
16493 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16496 abfd
= section
->asection
->owner
;
16498 /* First pass: Find the name of the base filename.
16499 This filename is needed in order to process all macros whose definition
16500 (or undefinition) comes from the command line. These macros are defined
16501 before the first DW_MACINFO_start_file entry, and yet still need to be
16502 associated to the base file.
16504 To determine the base file name, we scan the macro definitions until we
16505 reach the first DW_MACINFO_start_file entry. We then initialize
16506 CURRENT_FILE accordingly so that any macro definition found before the
16507 first DW_MACINFO_start_file can still be associated to the base file. */
16509 mac_ptr
= section
->buffer
+ offset
;
16510 mac_end
= section
->buffer
+ section
->size
;
16512 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16513 &offset_size
, section_is_gnu
);
16514 if (mac_ptr
== NULL
)
16516 /* We already issued a complaint. */
16522 /* Do we at least have room for a macinfo type byte? */
16523 if (mac_ptr
>= mac_end
)
16525 /* Complaint is printed during the second pass as GDB will probably
16526 stop the first pass earlier upon finding
16527 DW_MACINFO_start_file. */
16531 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16534 /* Note that we rely on the fact that the corresponding GNU and
16535 DWARF constants are the same. */
16536 switch (macinfo_type
)
16538 /* A zero macinfo type indicates the end of the macro
16543 case DW_MACRO_GNU_define
:
16544 case DW_MACRO_GNU_undef
:
16545 /* Only skip the data by MAC_PTR. */
16547 unsigned int bytes_read
;
16549 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16550 mac_ptr
+= bytes_read
;
16551 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16552 mac_ptr
+= bytes_read
;
16556 case DW_MACRO_GNU_start_file
:
16558 unsigned int bytes_read
;
16561 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16562 mac_ptr
+= bytes_read
;
16563 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16564 mac_ptr
+= bytes_read
;
16566 current_file
= macro_start_file (file
, line
, current_file
,
16567 comp_dir
, lh
, objfile
);
16571 case DW_MACRO_GNU_end_file
:
16572 /* No data to skip by MAC_PTR. */
16575 case DW_MACRO_GNU_define_indirect
:
16576 case DW_MACRO_GNU_undef_indirect
:
16578 unsigned int bytes_read
;
16580 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16581 mac_ptr
+= bytes_read
;
16582 mac_ptr
+= offset_size
;
16586 case DW_MACRO_GNU_transparent_include
:
16587 /* Note that, according to the spec, a transparent include
16588 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16589 skip this opcode. */
16590 mac_ptr
+= offset_size
;
16593 case DW_MACINFO_vendor_ext
:
16594 /* Only skip the data by MAC_PTR. */
16595 if (!section_is_gnu
)
16597 unsigned int bytes_read
;
16599 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16600 mac_ptr
+= bytes_read
;
16601 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16602 mac_ptr
+= bytes_read
;
16607 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16608 mac_ptr
, mac_end
, abfd
, offset_size
,
16610 if (mac_ptr
== NULL
)
16614 } while (macinfo_type
!= 0 && current_file
== NULL
);
16616 /* Second pass: Process all entries.
16618 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16619 command-line macro definitions/undefinitions. This flag is unset when we
16620 reach the first DW_MACINFO_start_file entry. */
16622 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16623 NULL
, xcalloc
, xfree
);
16624 cleanup
= make_cleanup_htab_delete (include_hash
);
16625 mac_ptr
= section
->buffer
+ offset
;
16626 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16628 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16629 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16630 offset_size
, objfile
, include_hash
);
16631 do_cleanups (cleanup
);
16634 /* Check if the attribute's form is a DW_FORM_block*
16635 if so return true else false. */
16638 attr_form_is_block (struct attribute
*attr
)
16640 return (attr
== NULL
? 0 :
16641 attr
->form
== DW_FORM_block1
16642 || attr
->form
== DW_FORM_block2
16643 || attr
->form
== DW_FORM_block4
16644 || attr
->form
== DW_FORM_block
16645 || attr
->form
== DW_FORM_exprloc
);
16648 /* Return non-zero if ATTR's value is a section offset --- classes
16649 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16650 You may use DW_UNSND (attr) to retrieve such offsets.
16652 Section 7.5.4, "Attribute Encodings", explains that no attribute
16653 may have a value that belongs to more than one of these classes; it
16654 would be ambiguous if we did, because we use the same forms for all
16658 attr_form_is_section_offset (struct attribute
*attr
)
16660 return (attr
->form
== DW_FORM_data4
16661 || attr
->form
== DW_FORM_data8
16662 || attr
->form
== DW_FORM_sec_offset
);
16665 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16666 zero otherwise. When this function returns true, you can apply
16667 dwarf2_get_attr_constant_value to it.
16669 However, note that for some attributes you must check
16670 attr_form_is_section_offset before using this test. DW_FORM_data4
16671 and DW_FORM_data8 are members of both the constant class, and of
16672 the classes that contain offsets into other debug sections
16673 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16674 that, if an attribute's can be either a constant or one of the
16675 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16676 taken as section offsets, not constants. */
16679 attr_form_is_constant (struct attribute
*attr
)
16681 switch (attr
->form
)
16683 case DW_FORM_sdata
:
16684 case DW_FORM_udata
:
16685 case DW_FORM_data1
:
16686 case DW_FORM_data2
:
16687 case DW_FORM_data4
:
16688 case DW_FORM_data8
:
16695 /* Return the .debug_loc section to use for CU.
16696 For DWO files use .debug_loc.dwo. */
16698 static struct dwarf2_section_info
*
16699 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16702 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16703 return &dwarf2_per_objfile
->loc
;
16706 /* A helper function that fills in a dwarf2_loclist_baton. */
16709 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16710 struct dwarf2_loclist_baton
*baton
,
16711 struct attribute
*attr
)
16713 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16715 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16717 baton
->per_cu
= cu
->per_cu
;
16718 gdb_assert (baton
->per_cu
);
16719 /* We don't know how long the location list is, but make sure we
16720 don't run off the edge of the section. */
16721 baton
->size
= section
->size
- DW_UNSND (attr
);
16722 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16723 baton
->base_address
= cu
->base_address
;
16724 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16728 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16729 struct dwarf2_cu
*cu
)
16731 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16732 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16734 if (attr_form_is_section_offset (attr
)
16735 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16736 the section. If so, fall through to the complaint in the
16738 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16740 struct dwarf2_loclist_baton
*baton
;
16742 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16743 sizeof (struct dwarf2_loclist_baton
));
16745 fill_in_loclist_baton (cu
, baton
, attr
);
16747 if (cu
->base_known
== 0)
16748 complaint (&symfile_complaints
,
16749 _("Location list used without "
16750 "specifying the CU base address."));
16752 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16753 SYMBOL_LOCATION_BATON (sym
) = baton
;
16757 struct dwarf2_locexpr_baton
*baton
;
16759 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16760 sizeof (struct dwarf2_locexpr_baton
));
16761 baton
->per_cu
= cu
->per_cu
;
16762 gdb_assert (baton
->per_cu
);
16764 if (attr_form_is_block (attr
))
16766 /* Note that we're just copying the block's data pointer
16767 here, not the actual data. We're still pointing into the
16768 info_buffer for SYM's objfile; right now we never release
16769 that buffer, but when we do clean up properly this may
16771 baton
->size
= DW_BLOCK (attr
)->size
;
16772 baton
->data
= DW_BLOCK (attr
)->data
;
16776 dwarf2_invalid_attrib_class_complaint ("location description",
16777 SYMBOL_NATURAL_NAME (sym
));
16781 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16782 SYMBOL_LOCATION_BATON (sym
) = baton
;
16786 /* Return the OBJFILE associated with the compilation unit CU. If CU
16787 came from a separate debuginfo file, then the master objfile is
16791 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16793 struct objfile
*objfile
= per_cu
->objfile
;
16795 /* Return the master objfile, so that we can report and look up the
16796 correct file containing this variable. */
16797 if (objfile
->separate_debug_objfile_backlink
)
16798 objfile
= objfile
->separate_debug_objfile_backlink
;
16803 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16804 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16805 CU_HEADERP first. */
16807 static const struct comp_unit_head
*
16808 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16809 struct dwarf2_per_cu_data
*per_cu
)
16811 struct objfile
*objfile
;
16812 struct dwarf2_per_objfile
*per_objfile
;
16813 gdb_byte
*info_ptr
;
16816 return &per_cu
->cu
->header
;
16818 objfile
= per_cu
->objfile
;
16819 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16820 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16822 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16823 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16828 /* Return the address size given in the compilation unit header for CU. */
16831 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16833 struct comp_unit_head cu_header_local
;
16834 const struct comp_unit_head
*cu_headerp
;
16836 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16838 return cu_headerp
->addr_size
;
16841 /* Return the offset size given in the compilation unit header for CU. */
16844 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16846 struct comp_unit_head cu_header_local
;
16847 const struct comp_unit_head
*cu_headerp
;
16849 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16851 return cu_headerp
->offset_size
;
16854 /* See its dwarf2loc.h declaration. */
16857 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16859 struct comp_unit_head cu_header_local
;
16860 const struct comp_unit_head
*cu_headerp
;
16862 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16864 if (cu_headerp
->version
== 2)
16865 return cu_headerp
->addr_size
;
16867 return cu_headerp
->offset_size
;
16870 /* Return the text offset of the CU. The returned offset comes from
16871 this CU's objfile. If this objfile came from a separate debuginfo
16872 file, then the offset may be different from the corresponding
16873 offset in the parent objfile. */
16876 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16878 struct objfile
*objfile
= per_cu
->objfile
;
16880 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16883 /* Locate the .debug_info compilation unit from CU's objfile which contains
16884 the DIE at OFFSET. Raises an error on failure. */
16886 static struct dwarf2_per_cu_data
*
16887 dwarf2_find_containing_comp_unit (sect_offset offset
,
16888 struct objfile
*objfile
)
16890 struct dwarf2_per_cu_data
*this_cu
;
16894 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16897 int mid
= low
+ (high
- low
) / 2;
16899 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16900 >= offset
.sect_off
)
16905 gdb_assert (low
== high
);
16906 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16910 error (_("Dwarf Error: could not find partial DIE containing "
16911 "offset 0x%lx [in module %s]"),
16912 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16914 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16915 <= offset
.sect_off
);
16916 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16920 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16921 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16922 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16923 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16924 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16929 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16932 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16934 memset (cu
, 0, sizeof (*cu
));
16936 cu
->per_cu
= per_cu
;
16937 cu
->objfile
= per_cu
->objfile
;
16938 obstack_init (&cu
->comp_unit_obstack
);
16941 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16944 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
16945 enum language pretend_language
)
16947 struct attribute
*attr
;
16949 /* Set the language we're debugging. */
16950 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16952 set_cu_language (DW_UNSND (attr
), cu
);
16955 cu
->language
= pretend_language
;
16956 cu
->language_defn
= language_def (cu
->language
);
16959 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16961 cu
->producer
= DW_STRING (attr
);
16964 /* Release one cached compilation unit, CU. We unlink it from the tree
16965 of compilation units, but we don't remove it from the read_in_chain;
16966 the caller is responsible for that.
16967 NOTE: DATA is a void * because this function is also used as a
16968 cleanup routine. */
16971 free_heap_comp_unit (void *data
)
16973 struct dwarf2_cu
*cu
= data
;
16975 gdb_assert (cu
->per_cu
!= NULL
);
16976 cu
->per_cu
->cu
= NULL
;
16979 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16984 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16985 when we're finished with it. We can't free the pointer itself, but be
16986 sure to unlink it from the cache. Also release any associated storage. */
16989 free_stack_comp_unit (void *data
)
16991 struct dwarf2_cu
*cu
= data
;
16993 gdb_assert (cu
->per_cu
!= NULL
);
16994 cu
->per_cu
->cu
= NULL
;
16997 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16998 cu
->partial_dies
= NULL
;
17001 /* Free all cached compilation units. */
17004 free_cached_comp_units (void *data
)
17006 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17008 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17009 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17010 while (per_cu
!= NULL
)
17012 struct dwarf2_per_cu_data
*next_cu
;
17014 next_cu
= per_cu
->cu
->read_in_chain
;
17016 free_heap_comp_unit (per_cu
->cu
);
17017 *last_chain
= next_cu
;
17023 /* Increase the age counter on each cached compilation unit, and free
17024 any that are too old. */
17027 age_cached_comp_units (void)
17029 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17031 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17032 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17033 while (per_cu
!= NULL
)
17035 per_cu
->cu
->last_used
++;
17036 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17037 dwarf2_mark (per_cu
->cu
);
17038 per_cu
= per_cu
->cu
->read_in_chain
;
17041 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17042 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17043 while (per_cu
!= NULL
)
17045 struct dwarf2_per_cu_data
*next_cu
;
17047 next_cu
= per_cu
->cu
->read_in_chain
;
17049 if (!per_cu
->cu
->mark
)
17051 free_heap_comp_unit (per_cu
->cu
);
17052 *last_chain
= next_cu
;
17055 last_chain
= &per_cu
->cu
->read_in_chain
;
17061 /* Remove a single compilation unit from the cache. */
17064 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17066 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17068 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17069 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17070 while (per_cu
!= NULL
)
17072 struct dwarf2_per_cu_data
*next_cu
;
17074 next_cu
= per_cu
->cu
->read_in_chain
;
17076 if (per_cu
== target_per_cu
)
17078 free_heap_comp_unit (per_cu
->cu
);
17080 *last_chain
= next_cu
;
17084 last_chain
= &per_cu
->cu
->read_in_chain
;
17090 /* Release all extra memory associated with OBJFILE. */
17093 dwarf2_free_objfile (struct objfile
*objfile
)
17095 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17097 if (dwarf2_per_objfile
== NULL
)
17100 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17101 free_cached_comp_units (NULL
);
17103 if (dwarf2_per_objfile
->quick_file_names_table
)
17104 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17106 /* Everything else should be on the objfile obstack. */
17109 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17110 We store these in a hash table separate from the DIEs, and preserve them
17111 when the DIEs are flushed out of cache.
17113 The CU "per_cu" pointer is needed because offset alone is not enough to
17114 uniquely identify the type. A file may have multiple .debug_types sections,
17115 or the type may come from a DWO file. We have to use something in
17116 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17117 routine, get_die_type_at_offset, from outside this file, and thus won't
17118 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17121 struct dwarf2_per_cu_offset_and_type
17123 const struct dwarf2_per_cu_data
*per_cu
;
17124 sect_offset offset
;
17128 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17131 per_cu_offset_and_type_hash (const void *item
)
17133 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17135 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17138 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17141 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17143 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17144 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17146 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17147 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17150 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17151 table if necessary. For convenience, return TYPE.
17153 The DIEs reading must have careful ordering to:
17154 * Not cause infite loops trying to read in DIEs as a prerequisite for
17155 reading current DIE.
17156 * Not trying to dereference contents of still incompletely read in types
17157 while reading in other DIEs.
17158 * Enable referencing still incompletely read in types just by a pointer to
17159 the type without accessing its fields.
17161 Therefore caller should follow these rules:
17162 * Try to fetch any prerequisite types we may need to build this DIE type
17163 before building the type and calling set_die_type.
17164 * After building type call set_die_type for current DIE as soon as
17165 possible before fetching more types to complete the current type.
17166 * Make the type as complete as possible before fetching more types. */
17168 static struct type
*
17169 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17171 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17172 struct objfile
*objfile
= cu
->objfile
;
17174 /* For Ada types, make sure that the gnat-specific data is always
17175 initialized (if not already set). There are a few types where
17176 we should not be doing so, because the type-specific area is
17177 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17178 where the type-specific area is used to store the floatformat).
17179 But this is not a problem, because the gnat-specific information
17180 is actually not needed for these types. */
17181 if (need_gnat_info (cu
)
17182 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17183 && TYPE_CODE (type
) != TYPE_CODE_FLT
17184 && !HAVE_GNAT_AUX_INFO (type
))
17185 INIT_GNAT_SPECIFIC (type
);
17187 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17189 dwarf2_per_objfile
->die_type_hash
=
17190 htab_create_alloc_ex (127,
17191 per_cu_offset_and_type_hash
,
17192 per_cu_offset_and_type_eq
,
17194 &objfile
->objfile_obstack
,
17195 hashtab_obstack_allocate
,
17196 dummy_obstack_deallocate
);
17199 ofs
.per_cu
= cu
->per_cu
;
17200 ofs
.offset
= die
->offset
;
17202 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17203 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17205 complaint (&symfile_complaints
,
17206 _("A problem internal to GDB: DIE 0x%x has type already set"),
17207 die
->offset
.sect_off
);
17208 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17213 /* Look up the type for the die at OFFSET in the appropriate type_hash
17214 table, or return NULL if the die does not have a saved type. */
17216 static struct type
*
17217 get_die_type_at_offset (sect_offset offset
,
17218 struct dwarf2_per_cu_data
*per_cu
)
17220 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17222 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17225 ofs
.per_cu
= per_cu
;
17226 ofs
.offset
= offset
;
17227 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17234 /* Look up the type for DIE in the appropriate type_hash table,
17235 or return NULL if DIE does not have a saved type. */
17237 static struct type
*
17238 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17240 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17243 /* Add a dependence relationship from CU to REF_PER_CU. */
17246 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17247 struct dwarf2_per_cu_data
*ref_per_cu
)
17251 if (cu
->dependencies
== NULL
)
17253 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17254 NULL
, &cu
->comp_unit_obstack
,
17255 hashtab_obstack_allocate
,
17256 dummy_obstack_deallocate
);
17258 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17260 *slot
= ref_per_cu
;
17263 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17264 Set the mark field in every compilation unit in the
17265 cache that we must keep because we are keeping CU. */
17268 dwarf2_mark_helper (void **slot
, void *data
)
17270 struct dwarf2_per_cu_data
*per_cu
;
17272 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17274 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17275 reading of the chain. As such dependencies remain valid it is not much
17276 useful to track and undo them during QUIT cleanups. */
17277 if (per_cu
->cu
== NULL
)
17280 if (per_cu
->cu
->mark
)
17282 per_cu
->cu
->mark
= 1;
17284 if (per_cu
->cu
->dependencies
!= NULL
)
17285 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17290 /* Set the mark field in CU and in every other compilation unit in the
17291 cache that we must keep because we are keeping CU. */
17294 dwarf2_mark (struct dwarf2_cu
*cu
)
17299 if (cu
->dependencies
!= NULL
)
17300 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17304 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17308 per_cu
->cu
->mark
= 0;
17309 per_cu
= per_cu
->cu
->read_in_chain
;
17313 /* Trivial hash function for partial_die_info: the hash value of a DIE
17314 is its offset in .debug_info for this objfile. */
17317 partial_die_hash (const void *item
)
17319 const struct partial_die_info
*part_die
= item
;
17321 return part_die
->offset
.sect_off
;
17324 /* Trivial comparison function for partial_die_info structures: two DIEs
17325 are equal if they have the same offset. */
17328 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17330 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17331 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17333 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17336 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17337 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17340 set_dwarf2_cmd (char *args
, int from_tty
)
17342 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17346 show_dwarf2_cmd (char *args
, int from_tty
)
17348 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17351 /* If section described by INFO was mmapped, munmap it now. */
17354 munmap_section_buffer (struct dwarf2_section_info
*info
)
17356 if (info
->map_addr
!= NULL
)
17361 res
= munmap (info
->map_addr
, info
->map_len
);
17362 gdb_assert (res
== 0);
17364 /* Without HAVE_MMAP, we should never be here to begin with. */
17365 gdb_assert_not_reached ("no mmap support");
17370 /* munmap debug sections for OBJFILE, if necessary. */
17373 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17375 struct dwarf2_per_objfile
*data
= d
;
17377 struct dwarf2_section_info
*section
;
17379 /* This is sorted according to the order they're defined in to make it easier
17380 to keep in sync. */
17381 munmap_section_buffer (&data
->info
);
17382 munmap_section_buffer (&data
->abbrev
);
17383 munmap_section_buffer (&data
->line
);
17384 munmap_section_buffer (&data
->loc
);
17385 munmap_section_buffer (&data
->macinfo
);
17386 munmap_section_buffer (&data
->macro
);
17387 munmap_section_buffer (&data
->str
);
17388 munmap_section_buffer (&data
->ranges
);
17389 munmap_section_buffer (&data
->addr
);
17390 munmap_section_buffer (&data
->frame
);
17391 munmap_section_buffer (&data
->eh_frame
);
17392 munmap_section_buffer (&data
->gdb_index
);
17395 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17397 munmap_section_buffer (section
);
17399 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17400 VEC_free (dwarf2_per_cu_ptr
,
17401 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17403 VEC_free (dwarf2_section_info_def
, data
->types
);
17405 if (data
->dwo_files
)
17406 free_dwo_files (data
->dwo_files
, objfile
);
17410 /* The "save gdb-index" command. */
17412 /* The contents of the hash table we create when building the string
17414 struct strtab_entry
17416 offset_type offset
;
17420 /* Hash function for a strtab_entry.
17422 Function is used only during write_hash_table so no index format backward
17423 compatibility is needed. */
17426 hash_strtab_entry (const void *e
)
17428 const struct strtab_entry
*entry
= e
;
17429 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17432 /* Equality function for a strtab_entry. */
17435 eq_strtab_entry (const void *a
, const void *b
)
17437 const struct strtab_entry
*ea
= a
;
17438 const struct strtab_entry
*eb
= b
;
17439 return !strcmp (ea
->str
, eb
->str
);
17442 /* Create a strtab_entry hash table. */
17445 create_strtab (void)
17447 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17448 xfree
, xcalloc
, xfree
);
17451 /* Add a string to the constant pool. Return the string's offset in
17455 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17458 struct strtab_entry entry
;
17459 struct strtab_entry
*result
;
17462 slot
= htab_find_slot (table
, &entry
, INSERT
);
17467 result
= XNEW (struct strtab_entry
);
17468 result
->offset
= obstack_object_size (cpool
);
17470 obstack_grow_str0 (cpool
, str
);
17473 return result
->offset
;
17476 /* An entry in the symbol table. */
17477 struct symtab_index_entry
17479 /* The name of the symbol. */
17481 /* The offset of the name in the constant pool. */
17482 offset_type index_offset
;
17483 /* A sorted vector of the indices of all the CUs that hold an object
17485 VEC (offset_type
) *cu_indices
;
17488 /* The symbol table. This is a power-of-2-sized hash table. */
17489 struct mapped_symtab
17491 offset_type n_elements
;
17493 struct symtab_index_entry
**data
;
17496 /* Hash function for a symtab_index_entry. */
17499 hash_symtab_entry (const void *e
)
17501 const struct symtab_index_entry
*entry
= e
;
17502 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17503 sizeof (offset_type
) * VEC_length (offset_type
,
17504 entry
->cu_indices
),
17508 /* Equality function for a symtab_index_entry. */
17511 eq_symtab_entry (const void *a
, const void *b
)
17513 const struct symtab_index_entry
*ea
= a
;
17514 const struct symtab_index_entry
*eb
= b
;
17515 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17516 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17518 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17519 VEC_address (offset_type
, eb
->cu_indices
),
17520 sizeof (offset_type
) * len
);
17523 /* Destroy a symtab_index_entry. */
17526 delete_symtab_entry (void *p
)
17528 struct symtab_index_entry
*entry
= p
;
17529 VEC_free (offset_type
, entry
->cu_indices
);
17533 /* Create a hash table holding symtab_index_entry objects. */
17536 create_symbol_hash_table (void)
17538 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17539 delete_symtab_entry
, xcalloc
, xfree
);
17542 /* Create a new mapped symtab object. */
17544 static struct mapped_symtab
*
17545 create_mapped_symtab (void)
17547 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17548 symtab
->n_elements
= 0;
17549 symtab
->size
= 1024;
17550 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17554 /* Destroy a mapped_symtab. */
17557 cleanup_mapped_symtab (void *p
)
17559 struct mapped_symtab
*symtab
= p
;
17560 /* The contents of the array are freed when the other hash table is
17562 xfree (symtab
->data
);
17566 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17569 Function is used only during write_hash_table so no index format backward
17570 compatibility is needed. */
17572 static struct symtab_index_entry
**
17573 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17575 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17577 index
= hash
& (symtab
->size
- 1);
17578 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17582 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17583 return &symtab
->data
[index
];
17584 index
= (index
+ step
) & (symtab
->size
- 1);
17588 /* Expand SYMTAB's hash table. */
17591 hash_expand (struct mapped_symtab
*symtab
)
17593 offset_type old_size
= symtab
->size
;
17595 struct symtab_index_entry
**old_entries
= symtab
->data
;
17598 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17600 for (i
= 0; i
< old_size
; ++i
)
17602 if (old_entries
[i
])
17604 struct symtab_index_entry
**slot
= find_slot (symtab
,
17605 old_entries
[i
]->name
);
17606 *slot
= old_entries
[i
];
17610 xfree (old_entries
);
17613 /* Add an entry to SYMTAB. NAME is the name of the symbol.
17614 CU_INDEX is the index of the CU in which the symbol appears.
17615 IS_STATIC is one if the symbol is static, otherwise zero (global). */
17618 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17619 int is_static
, gdb_index_symbol_kind kind
,
17620 offset_type cu_index
)
17622 struct symtab_index_entry
**slot
;
17623 offset_type cu_index_and_attrs
;
17625 ++symtab
->n_elements
;
17626 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17627 hash_expand (symtab
);
17629 slot
= find_slot (symtab
, name
);
17632 *slot
= XNEW (struct symtab_index_entry
);
17633 (*slot
)->name
= name
;
17634 /* index_offset is set later. */
17635 (*slot
)->cu_indices
= NULL
;
17638 cu_index_and_attrs
= 0;
17639 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
17640 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
17641 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
17643 /* We don't want to record an index value twice as we want to avoid the
17645 We process all global symbols and then all static symbols
17646 (which would allow us to avoid the duplication by only having to check
17647 the last entry pushed), but a symbol could have multiple kinds in one CU.
17648 To keep things simple we don't worry about the duplication here and
17649 sort and uniqufy the list after we've processed all symbols. */
17650 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
17653 /* qsort helper routine for uniquify_cu_indices. */
17656 offset_type_compare (const void *ap
, const void *bp
)
17658 offset_type a
= *(offset_type
*) ap
;
17659 offset_type b
= *(offset_type
*) bp
;
17661 return (a
> b
) - (b
> a
);
17664 /* Sort and remove duplicates of all symbols' cu_indices lists. */
17667 uniquify_cu_indices (struct mapped_symtab
*symtab
)
17671 for (i
= 0; i
< symtab
->size
; ++i
)
17673 struct symtab_index_entry
*entry
= symtab
->data
[i
];
17676 && entry
->cu_indices
!= NULL
)
17678 unsigned int next_to_insert
, next_to_check
;
17679 offset_type last_value
;
17681 qsort (VEC_address (offset_type
, entry
->cu_indices
),
17682 VEC_length (offset_type
, entry
->cu_indices
),
17683 sizeof (offset_type
), offset_type_compare
);
17685 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
17686 next_to_insert
= 1;
17687 for (next_to_check
= 1;
17688 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
17691 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
17694 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
17696 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
17701 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
17706 /* Add a vector of indices to the constant pool. */
17709 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17710 struct symtab_index_entry
*entry
)
17714 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17717 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17718 offset_type val
= MAYBE_SWAP (len
);
17723 entry
->index_offset
= obstack_object_size (cpool
);
17725 obstack_grow (cpool
, &val
, sizeof (val
));
17727 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17730 val
= MAYBE_SWAP (iter
);
17731 obstack_grow (cpool
, &val
, sizeof (val
));
17736 struct symtab_index_entry
*old_entry
= *slot
;
17737 entry
->index_offset
= old_entry
->index_offset
;
17740 return entry
->index_offset
;
17743 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17744 constant pool entries going into the obstack CPOOL. */
17747 write_hash_table (struct mapped_symtab
*symtab
,
17748 struct obstack
*output
, struct obstack
*cpool
)
17751 htab_t symbol_hash_table
;
17754 symbol_hash_table
= create_symbol_hash_table ();
17755 str_table
= create_strtab ();
17757 /* We add all the index vectors to the constant pool first, to
17758 ensure alignment is ok. */
17759 for (i
= 0; i
< symtab
->size
; ++i
)
17761 if (symtab
->data
[i
])
17762 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17765 /* Now write out the hash table. */
17766 for (i
= 0; i
< symtab
->size
; ++i
)
17768 offset_type str_off
, vec_off
;
17770 if (symtab
->data
[i
])
17772 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17773 vec_off
= symtab
->data
[i
]->index_offset
;
17777 /* While 0 is a valid constant pool index, it is not valid
17778 to have 0 for both offsets. */
17783 str_off
= MAYBE_SWAP (str_off
);
17784 vec_off
= MAYBE_SWAP (vec_off
);
17786 obstack_grow (output
, &str_off
, sizeof (str_off
));
17787 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17790 htab_delete (str_table
);
17791 htab_delete (symbol_hash_table
);
17794 /* Struct to map psymtab to CU index in the index file. */
17795 struct psymtab_cu_index_map
17797 struct partial_symtab
*psymtab
;
17798 unsigned int cu_index
;
17802 hash_psymtab_cu_index (const void *item
)
17804 const struct psymtab_cu_index_map
*map
= item
;
17806 return htab_hash_pointer (map
->psymtab
);
17810 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17812 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17813 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17815 return lhs
->psymtab
== rhs
->psymtab
;
17818 /* Helper struct for building the address table. */
17819 struct addrmap_index_data
17821 struct objfile
*objfile
;
17822 struct obstack
*addr_obstack
;
17823 htab_t cu_index_htab
;
17825 /* Non-zero if the previous_* fields are valid.
17826 We can't write an entry until we see the next entry (since it is only then
17827 that we know the end of the entry). */
17828 int previous_valid
;
17829 /* Index of the CU in the table of all CUs in the index file. */
17830 unsigned int previous_cu_index
;
17831 /* Start address of the CU. */
17832 CORE_ADDR previous_cu_start
;
17835 /* Write an address entry to OBSTACK. */
17838 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17839 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17841 offset_type cu_index_to_write
;
17843 CORE_ADDR baseaddr
;
17845 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17847 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17848 obstack_grow (obstack
, addr
, 8);
17849 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17850 obstack_grow (obstack
, addr
, 8);
17851 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17852 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17855 /* Worker function for traversing an addrmap to build the address table. */
17858 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17860 struct addrmap_index_data
*data
= datap
;
17861 struct partial_symtab
*pst
= obj
;
17863 if (data
->previous_valid
)
17864 add_address_entry (data
->objfile
, data
->addr_obstack
,
17865 data
->previous_cu_start
, start_addr
,
17866 data
->previous_cu_index
);
17868 data
->previous_cu_start
= start_addr
;
17871 struct psymtab_cu_index_map find_map
, *map
;
17872 find_map
.psymtab
= pst
;
17873 map
= htab_find (data
->cu_index_htab
, &find_map
);
17874 gdb_assert (map
!= NULL
);
17875 data
->previous_cu_index
= map
->cu_index
;
17876 data
->previous_valid
= 1;
17879 data
->previous_valid
= 0;
17884 /* Write OBJFILE's address map to OBSTACK.
17885 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17886 in the index file. */
17889 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17890 htab_t cu_index_htab
)
17892 struct addrmap_index_data addrmap_index_data
;
17894 /* When writing the address table, we have to cope with the fact that
17895 the addrmap iterator only provides the start of a region; we have to
17896 wait until the next invocation to get the start of the next region. */
17898 addrmap_index_data
.objfile
= objfile
;
17899 addrmap_index_data
.addr_obstack
= obstack
;
17900 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17901 addrmap_index_data
.previous_valid
= 0;
17903 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17904 &addrmap_index_data
);
17906 /* It's highly unlikely the last entry (end address = 0xff...ff)
17907 is valid, but we should still handle it.
17908 The end address is recorded as the start of the next region, but that
17909 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17911 if (addrmap_index_data
.previous_valid
)
17912 add_address_entry (objfile
, obstack
,
17913 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17914 addrmap_index_data
.previous_cu_index
);
17917 /* Return the symbol kind of PSYM. */
17919 static gdb_index_symbol_kind
17920 symbol_kind (struct partial_symbol
*psym
)
17922 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
17923 enum address_class aclass
= PSYMBOL_CLASS (psym
);
17931 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
17933 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17935 case LOC_CONST_BYTES
:
17936 case LOC_OPTIMIZED_OUT
:
17938 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
17940 /* Note: It's currently impossible to recognize psyms as enum values
17941 short of reading the type info. For now punt. */
17942 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
17944 /* There are other LOC_FOO values that one might want to classify
17945 as variables, but dwarf2read.c doesn't currently use them. */
17946 return GDB_INDEX_SYMBOL_KIND_OTHER
;
17948 case STRUCT_DOMAIN
:
17949 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17951 return GDB_INDEX_SYMBOL_KIND_OTHER
;
17955 /* Add a list of partial symbols to SYMTAB. */
17958 write_psymbols (struct mapped_symtab
*symtab
,
17960 struct partial_symbol
**psymp
,
17962 offset_type cu_index
,
17965 for (; count
-- > 0; ++psymp
)
17967 struct partial_symbol
*psym
= *psymp
;
17970 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
17971 error (_("Ada is not currently supported by the index"));
17973 /* Only add a given psymbol once. */
17974 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
17977 gdb_index_symbol_kind kind
= symbol_kind (psym
);
17980 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
17981 is_static
, kind
, cu_index
);
17986 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17987 exception if there is an error. */
17990 write_obstack (FILE *file
, struct obstack
*obstack
)
17992 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17994 != obstack_object_size (obstack
))
17995 error (_("couldn't data write to file"));
17998 /* Unlink a file if the argument is not NULL. */
18001 unlink_if_set (void *p
)
18003 char **filename
= p
;
18005 unlink (*filename
);
18008 /* A helper struct used when iterating over debug_types. */
18009 struct signatured_type_index_data
18011 struct objfile
*objfile
;
18012 struct mapped_symtab
*symtab
;
18013 struct obstack
*types_list
;
18018 /* A helper function that writes a single signatured_type to an
18022 write_one_signatured_type (void **slot
, void *d
)
18024 struct signatured_type_index_data
*info
= d
;
18025 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18026 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18027 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18030 write_psymbols (info
->symtab
,
18032 info
->objfile
->global_psymbols
.list
18033 + psymtab
->globals_offset
,
18034 psymtab
->n_global_syms
, info
->cu_index
,
18036 write_psymbols (info
->symtab
,
18038 info
->objfile
->static_psymbols
.list
18039 + psymtab
->statics_offset
,
18040 psymtab
->n_static_syms
, info
->cu_index
,
18043 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18044 entry
->per_cu
.offset
.sect_off
);
18045 obstack_grow (info
->types_list
, val
, 8);
18046 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18047 entry
->type_offset_in_tu
.cu_off
);
18048 obstack_grow (info
->types_list
, val
, 8);
18049 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18050 obstack_grow (info
->types_list
, val
, 8);
18057 /* Recurse into all "included" dependencies and write their symbols as
18058 if they appeared in this psymtab. */
18061 recursively_write_psymbols (struct objfile
*objfile
,
18062 struct partial_symtab
*psymtab
,
18063 struct mapped_symtab
*symtab
,
18065 offset_type cu_index
)
18069 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18070 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18071 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18072 symtab
, psyms_seen
, cu_index
);
18074 write_psymbols (symtab
,
18076 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18077 psymtab
->n_global_syms
, cu_index
,
18079 write_psymbols (symtab
,
18081 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18082 psymtab
->n_static_syms
, cu_index
,
18086 /* Create an index file for OBJFILE in the directory DIR. */
18089 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18091 struct cleanup
*cleanup
;
18092 char *filename
, *cleanup_filename
;
18093 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18094 struct obstack cu_list
, types_cu_list
;
18097 struct mapped_symtab
*symtab
;
18098 offset_type val
, size_of_contents
, total_len
;
18101 htab_t cu_index_htab
;
18102 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18104 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18107 if (dwarf2_per_objfile
->using_index
)
18108 error (_("Cannot use an index to create the index"));
18110 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18111 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18113 if (stat (objfile
->name
, &st
) < 0)
18114 perror_with_name (objfile
->name
);
18116 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18117 INDEX_SUFFIX
, (char *) NULL
);
18118 cleanup
= make_cleanup (xfree
, filename
);
18120 out_file
= fopen (filename
, "wb");
18122 error (_("Can't open `%s' for writing"), filename
);
18124 cleanup_filename
= filename
;
18125 make_cleanup (unlink_if_set
, &cleanup_filename
);
18127 symtab
= create_mapped_symtab ();
18128 make_cleanup (cleanup_mapped_symtab
, symtab
);
18130 obstack_init (&addr_obstack
);
18131 make_cleanup_obstack_free (&addr_obstack
);
18133 obstack_init (&cu_list
);
18134 make_cleanup_obstack_free (&cu_list
);
18136 obstack_init (&types_cu_list
);
18137 make_cleanup_obstack_free (&types_cu_list
);
18139 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18140 NULL
, xcalloc
, xfree
);
18141 make_cleanup_htab_delete (psyms_seen
);
18143 /* While we're scanning CU's create a table that maps a psymtab pointer
18144 (which is what addrmap records) to its index (which is what is recorded
18145 in the index file). This will later be needed to write the address
18147 cu_index_htab
= htab_create_alloc (100,
18148 hash_psymtab_cu_index
,
18149 eq_psymtab_cu_index
,
18150 NULL
, xcalloc
, xfree
);
18151 make_cleanup_htab_delete (cu_index_htab
);
18152 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18153 xmalloc (sizeof (struct psymtab_cu_index_map
)
18154 * dwarf2_per_objfile
->n_comp_units
);
18155 make_cleanup (xfree
, psymtab_cu_index_map
);
18157 /* The CU list is already sorted, so we don't need to do additional
18158 work here. Also, the debug_types entries do not appear in
18159 all_comp_units, but only in their own hash table. */
18160 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18162 struct dwarf2_per_cu_data
*per_cu
18163 = dwarf2_per_objfile
->all_comp_units
[i
];
18164 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18166 struct psymtab_cu_index_map
*map
;
18169 if (psymtab
->user
== NULL
)
18170 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18172 map
= &psymtab_cu_index_map
[i
];
18173 map
->psymtab
= psymtab
;
18175 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18176 gdb_assert (slot
!= NULL
);
18177 gdb_assert (*slot
== NULL
);
18180 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18181 per_cu
->offset
.sect_off
);
18182 obstack_grow (&cu_list
, val
, 8);
18183 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18184 obstack_grow (&cu_list
, val
, 8);
18187 /* Dump the address map. */
18188 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18190 /* Write out the .debug_type entries, if any. */
18191 if (dwarf2_per_objfile
->signatured_types
)
18193 struct signatured_type_index_data sig_data
;
18195 sig_data
.objfile
= objfile
;
18196 sig_data
.symtab
= symtab
;
18197 sig_data
.types_list
= &types_cu_list
;
18198 sig_data
.psyms_seen
= psyms_seen
;
18199 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18200 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18201 write_one_signatured_type
, &sig_data
);
18204 /* Now that we've processed all symbols we can shrink their cu_indices
18206 uniquify_cu_indices (symtab
);
18208 obstack_init (&constant_pool
);
18209 make_cleanup_obstack_free (&constant_pool
);
18210 obstack_init (&symtab_obstack
);
18211 make_cleanup_obstack_free (&symtab_obstack
);
18212 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18214 obstack_init (&contents
);
18215 make_cleanup_obstack_free (&contents
);
18216 size_of_contents
= 6 * sizeof (offset_type
);
18217 total_len
= size_of_contents
;
18219 /* The version number. */
18220 val
= MAYBE_SWAP (7);
18221 obstack_grow (&contents
, &val
, sizeof (val
));
18223 /* The offset of the CU list from the start of the file. */
18224 val
= MAYBE_SWAP (total_len
);
18225 obstack_grow (&contents
, &val
, sizeof (val
));
18226 total_len
+= obstack_object_size (&cu_list
);
18228 /* The offset of the types CU list from the start of the file. */
18229 val
= MAYBE_SWAP (total_len
);
18230 obstack_grow (&contents
, &val
, sizeof (val
));
18231 total_len
+= obstack_object_size (&types_cu_list
);
18233 /* The offset of the address table from the start of the file. */
18234 val
= MAYBE_SWAP (total_len
);
18235 obstack_grow (&contents
, &val
, sizeof (val
));
18236 total_len
+= obstack_object_size (&addr_obstack
);
18238 /* The offset of the symbol table from the start of the file. */
18239 val
= MAYBE_SWAP (total_len
);
18240 obstack_grow (&contents
, &val
, sizeof (val
));
18241 total_len
+= obstack_object_size (&symtab_obstack
);
18243 /* The offset of the constant pool from the start of the file. */
18244 val
= MAYBE_SWAP (total_len
);
18245 obstack_grow (&contents
, &val
, sizeof (val
));
18246 total_len
+= obstack_object_size (&constant_pool
);
18248 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18250 write_obstack (out_file
, &contents
);
18251 write_obstack (out_file
, &cu_list
);
18252 write_obstack (out_file
, &types_cu_list
);
18253 write_obstack (out_file
, &addr_obstack
);
18254 write_obstack (out_file
, &symtab_obstack
);
18255 write_obstack (out_file
, &constant_pool
);
18259 /* We want to keep the file, so we set cleanup_filename to NULL
18260 here. See unlink_if_set. */
18261 cleanup_filename
= NULL
;
18263 do_cleanups (cleanup
);
18266 /* Implementation of the `save gdb-index' command.
18268 Note that the file format used by this command is documented in the
18269 GDB manual. Any changes here must be documented there. */
18272 save_gdb_index_command (char *arg
, int from_tty
)
18274 struct objfile
*objfile
;
18277 error (_("usage: save gdb-index DIRECTORY"));
18279 ALL_OBJFILES (objfile
)
18283 /* If the objfile does not correspond to an actual file, skip it. */
18284 if (stat (objfile
->name
, &st
) < 0)
18287 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18288 if (dwarf2_per_objfile
)
18290 volatile struct gdb_exception except
;
18292 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18294 write_psymtabs_to_index (objfile
, arg
);
18296 if (except
.reason
< 0)
18297 exception_fprintf (gdb_stderr
, except
,
18298 _("Error while writing index for `%s': "),
18306 int dwarf2_always_disassemble
;
18309 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18310 struct cmd_list_element
*c
, const char *value
)
18312 fprintf_filtered (file
,
18313 _("Whether to always disassemble "
18314 "DWARF expressions is %s.\n"),
18319 show_check_physname (struct ui_file
*file
, int from_tty
,
18320 struct cmd_list_element
*c
, const char *value
)
18322 fprintf_filtered (file
,
18323 _("Whether to check \"physname\" is %s.\n"),
18327 void _initialize_dwarf2_read (void);
18330 _initialize_dwarf2_read (void)
18332 struct cmd_list_element
*c
;
18334 dwarf2_objfile_data_key
18335 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18337 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18338 Set DWARF 2 specific variables.\n\
18339 Configure DWARF 2 variables such as the cache size"),
18340 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18341 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18343 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18344 Show DWARF 2 specific variables\n\
18345 Show DWARF 2 variables such as the cache size"),
18346 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18347 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18349 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18350 &dwarf2_max_cache_age
, _("\
18351 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18352 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18353 A higher limit means that cached compilation units will be stored\n\
18354 in memory longer, and more total memory will be used. Zero disables\n\
18355 caching, which can slow down startup."),
18357 show_dwarf2_max_cache_age
,
18358 &set_dwarf2_cmdlist
,
18359 &show_dwarf2_cmdlist
);
18361 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18362 &dwarf2_always_disassemble
, _("\
18363 Set whether `info address' always disassembles DWARF expressions."), _("\
18364 Show whether `info address' always disassembles DWARF expressions."), _("\
18365 When enabled, DWARF expressions are always printed in an assembly-like\n\
18366 syntax. When disabled, expressions will be printed in a more\n\
18367 conversational style, when possible."),
18369 show_dwarf2_always_disassemble
,
18370 &set_dwarf2_cmdlist
,
18371 &show_dwarf2_cmdlist
);
18373 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
18374 Set debugging of the dwarf2 reader."), _("\
18375 Show debugging of the dwarf2 reader."), _("\
18376 When enabled, debugging messages are printed during dwarf2 reading\n\
18377 and symtab expansion."),
18380 &setdebuglist
, &showdebuglist
);
18382 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18383 Set debugging of the dwarf2 DIE reader."), _("\
18384 Show debugging of the dwarf2 DIE reader."), _("\
18385 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18386 The value is the maximum depth to print."),
18389 &setdebuglist
, &showdebuglist
);
18391 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18392 Set cross-checking of \"physname\" code against demangler."), _("\
18393 Show cross-checking of \"physname\" code against demangler."), _("\
18394 When enabled, GDB's internal \"physname\" code is checked against\n\
18396 NULL
, show_check_physname
,
18397 &setdebuglist
, &showdebuglist
);
18399 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18401 Save a gdb-index file.\n\
18402 Usage: save gdb-index DIRECTORY"),
18404 set_cmd_completer (c
, filename_completer
);