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, dump DIEs after they are read in. */
86 static int dwarf2_die_debug
= 0;
88 /* When non-zero, cross-check physname against demangler. */
89 static int check_physname
= 0;
91 /* When non-zero, do not reject deprecated .gdb_index sections. */
92 int use_deprecated_index_sections
= 0;
96 /* When set, the file that we're processing is known to have debugging
97 info for C++ namespaces. GCC 3.3.x did not produce this information,
98 but later versions do. */
100 static int processing_has_namespace_info
;
102 static const struct objfile_data
*dwarf2_objfile_data_key
;
104 struct dwarf2_section_info
109 /* Not NULL if the section was actually mmapped. */
111 /* Page aligned size of mmapped area. */
112 bfd_size_type map_len
;
113 /* True if we have tried to read this section. */
117 typedef struct dwarf2_section_info dwarf2_section_info_def
;
118 DEF_VEC_O (dwarf2_section_info_def
);
120 /* All offsets in the index are of this type. It must be
121 architecture-independent. */
122 typedef uint32_t offset_type
;
124 DEF_VEC_I (offset_type
);
126 /* Ensure only legit values are used. */
127 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
129 gdb_assert ((unsigned int) (value) <= 1); \
130 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
133 /* Ensure only legit values are used. */
134 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
136 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
137 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
138 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
141 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
142 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
144 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
145 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
148 /* A description of the mapped index. The file format is described in
149 a comment by the code that writes the index. */
152 /* Index data format version. */
155 /* The total length of the buffer. */
158 /* A pointer to the address table data. */
159 const gdb_byte
*address_table
;
161 /* Size of the address table data in bytes. */
162 offset_type address_table_size
;
164 /* The symbol table, implemented as a hash table. */
165 const offset_type
*symbol_table
;
167 /* Size in slots, each slot is 2 offset_types. */
168 offset_type symbol_table_slots
;
170 /* A pointer to the constant pool. */
171 const char *constant_pool
;
174 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
175 DEF_VEC_P (dwarf2_per_cu_ptr
);
177 /* Collection of data recorded per objfile.
178 This hangs off of dwarf2_objfile_data_key. */
180 struct dwarf2_per_objfile
182 struct dwarf2_section_info info
;
183 struct dwarf2_section_info abbrev
;
184 struct dwarf2_section_info line
;
185 struct dwarf2_section_info loc
;
186 struct dwarf2_section_info macinfo
;
187 struct dwarf2_section_info macro
;
188 struct dwarf2_section_info str
;
189 struct dwarf2_section_info ranges
;
190 struct dwarf2_section_info addr
;
191 struct dwarf2_section_info frame
;
192 struct dwarf2_section_info eh_frame
;
193 struct dwarf2_section_info gdb_index
;
195 VEC (dwarf2_section_info_def
) *types
;
198 struct objfile
*objfile
;
200 /* Table of all the compilation units. This is used to locate
201 the target compilation unit of a particular reference. */
202 struct dwarf2_per_cu_data
**all_comp_units
;
204 /* The number of compilation units in ALL_COMP_UNITS. */
207 /* The number of .debug_types-related CUs. */
210 /* The .debug_types-related CUs (TUs). */
211 struct dwarf2_per_cu_data
**all_type_units
;
213 /* A chain of compilation units that are currently read in, so that
214 they can be freed later. */
215 struct dwarf2_per_cu_data
*read_in_chain
;
217 /* A table mapping .debug_types signatures to its signatured_type entry.
218 This is NULL if the .debug_types section hasn't been read in yet. */
219 htab_t signatured_types
;
221 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
222 This is NULL if the table hasn't been allocated yet. */
225 /* A flag indicating wether this objfile has a section loaded at a
227 int has_section_at_zero
;
229 /* True if we are using the mapped index,
230 or we are faking it for OBJF_READNOW's sake. */
231 unsigned char using_index
;
233 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
234 struct mapped_index
*index_table
;
236 /* When using index_table, this keeps track of all quick_file_names entries.
237 TUs can share line table entries with CUs or other TUs, and there can be
238 a lot more TUs than unique line tables, so we maintain a separate table
239 of all line table entries to support the sharing. */
240 htab_t quick_file_names_table
;
242 /* Set during partial symbol reading, to prevent queueing of full
244 int reading_partial_symbols
;
246 /* Table mapping type DIEs to their struct type *.
247 This is NULL if not allocated yet.
248 The mapping is done via (CU/TU signature + DIE offset) -> type. */
249 htab_t die_type_hash
;
251 /* The CUs we recently read. */
252 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
255 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
257 /* Default names of the debugging sections. */
259 /* Note that if the debugging section has been compressed, it might
260 have a name like .zdebug_info. */
262 static const struct dwarf2_debug_sections dwarf2_elf_names
=
264 { ".debug_info", ".zdebug_info" },
265 { ".debug_abbrev", ".zdebug_abbrev" },
266 { ".debug_line", ".zdebug_line" },
267 { ".debug_loc", ".zdebug_loc" },
268 { ".debug_macinfo", ".zdebug_macinfo" },
269 { ".debug_macro", ".zdebug_macro" },
270 { ".debug_str", ".zdebug_str" },
271 { ".debug_ranges", ".zdebug_ranges" },
272 { ".debug_types", ".zdebug_types" },
273 { ".debug_addr", ".zdebug_addr" },
274 { ".debug_frame", ".zdebug_frame" },
275 { ".eh_frame", NULL
},
276 { ".gdb_index", ".zgdb_index" },
280 /* List of DWO sections. */
282 static const struct dwo_section_names
284 struct dwarf2_section_names abbrev_dwo
;
285 struct dwarf2_section_names info_dwo
;
286 struct dwarf2_section_names line_dwo
;
287 struct dwarf2_section_names loc_dwo
;
288 struct dwarf2_section_names str_dwo
;
289 struct dwarf2_section_names str_offsets_dwo
;
290 struct dwarf2_section_names types_dwo
;
294 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
295 { ".debug_info.dwo", ".zdebug_info.dwo" },
296 { ".debug_line.dwo", ".zdebug_line.dwo" },
297 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
298 { ".debug_str.dwo", ".zdebug_str.dwo" },
299 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
300 { ".debug_types.dwo", ".zdebug_types.dwo" },
303 /* local data types */
305 /* We hold several abbreviation tables in memory at the same time. */
306 #ifndef ABBREV_HASH_SIZE
307 #define ABBREV_HASH_SIZE 121
310 /* The data in a compilation unit header, after target2host
311 translation, looks like this. */
312 struct comp_unit_head
316 unsigned char addr_size
;
317 unsigned char signed_addr_p
;
318 sect_offset abbrev_offset
;
320 /* Size of file offsets; either 4 or 8. */
321 unsigned int offset_size
;
323 /* Size of the length field; either 4 or 12. */
324 unsigned int initial_length_size
;
326 /* Offset to the first byte of this compilation unit header in the
327 .debug_info section, for resolving relative reference dies. */
330 /* Offset to first die in this cu from the start of the cu.
331 This will be the first byte following the compilation unit header. */
332 cu_offset first_die_offset
;
335 /* Type used for delaying computation of method physnames.
336 See comments for compute_delayed_physnames. */
337 struct delayed_method_info
339 /* The type to which the method is attached, i.e., its parent class. */
342 /* The index of the method in the type's function fieldlists. */
345 /* The index of the method in the fieldlist. */
348 /* The name of the DIE. */
351 /* The DIE associated with this method. */
352 struct die_info
*die
;
355 typedef struct delayed_method_info delayed_method_info
;
356 DEF_VEC_O (delayed_method_info
);
358 /* Internal state when decoding a particular compilation unit. */
361 /* The objfile containing this compilation unit. */
362 struct objfile
*objfile
;
364 /* The header of the compilation unit. */
365 struct comp_unit_head header
;
367 /* Base address of this compilation unit. */
368 CORE_ADDR base_address
;
370 /* Non-zero if base_address has been set. */
373 /* The language we are debugging. */
374 enum language language
;
375 const struct language_defn
*language_defn
;
377 const char *producer
;
379 /* The generic symbol table building routines have separate lists for
380 file scope symbols and all all other scopes (local scopes). So
381 we need to select the right one to pass to add_symbol_to_list().
382 We do it by keeping a pointer to the correct list in list_in_scope.
384 FIXME: The original dwarf code just treated the file scope as the
385 first local scope, and all other local scopes as nested local
386 scopes, and worked fine. Check to see if we really need to
387 distinguish these in buildsym.c. */
388 struct pending
**list_in_scope
;
390 /* DWARF abbreviation table associated with this compilation unit. */
391 struct abbrev_info
**dwarf2_abbrevs
;
393 /* Storage for the abbrev table. */
394 struct obstack abbrev_obstack
;
396 /* Hash table holding all the loaded partial DIEs
397 with partial_die->offset.SECT_OFF as hash. */
400 /* Storage for things with the same lifetime as this read-in compilation
401 unit, including partial DIEs. */
402 struct obstack comp_unit_obstack
;
404 /* When multiple dwarf2_cu structures are living in memory, this field
405 chains them all together, so that they can be released efficiently.
406 We will probably also want a generation counter so that most-recently-used
407 compilation units are cached... */
408 struct dwarf2_per_cu_data
*read_in_chain
;
410 /* Backchain to our per_cu entry if the tree has been built. */
411 struct dwarf2_per_cu_data
*per_cu
;
413 /* How many compilation units ago was this CU last referenced? */
416 /* A hash table of DIE cu_offset for following references with
417 die_info->offset.sect_off as hash. */
420 /* Full DIEs if read in. */
421 struct die_info
*dies
;
423 /* A set of pointers to dwarf2_per_cu_data objects for compilation
424 units referenced by this one. Only set during full symbol processing;
425 partial symbol tables do not have dependencies. */
428 /* Header data from the line table, during full symbol processing. */
429 struct line_header
*line_header
;
431 /* A list of methods which need to have physnames computed
432 after all type information has been read. */
433 VEC (delayed_method_info
) *method_list
;
435 /* To be copied to symtab->call_site_htab. */
436 htab_t call_site_htab
;
438 /* Non-NULL if this CU came from a DWO file.
439 There is an invariant here that is important to remember:
440 Except for attributes copied from the top level DIE in the "main"
441 (or "stub") file in preparation for reading the DWO file
442 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
443 Either there isn't a DWO file (in which case this is NULL and the point
444 is moot), or there is and either we're not going to read it (in which
445 case this is NULL) or there is and we are reading it (in which case this
447 struct dwo_unit
*dwo_unit
;
449 /* The DW_AT_addr_base attribute if present, zero otherwise
450 (zero is a valid value though).
451 Note this value comes from the stub CU/TU's DIE. */
454 /* Mark used when releasing cached dies. */
455 unsigned int mark
: 1;
457 /* This CU references .debug_loc. See the symtab->locations_valid field.
458 This test is imperfect as there may exist optimized debug code not using
459 any location list and still facing inlining issues if handled as
460 unoptimized code. For a future better test see GCC PR other/32998. */
461 unsigned int has_loclist
: 1;
463 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
464 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
465 are valid. This information is cached because profiling CU expansion
466 showed excessive time spent in producer_is_gxx_lt_4_6. */
467 unsigned int checked_producer
: 1;
468 unsigned int producer_is_gxx_lt_4_6
: 1;
469 unsigned int producer_is_icc
: 1;
471 /* Non-zero if DW_AT_addr_base was found.
472 Used when processing DWO files. */
473 unsigned int have_addr_base
: 1;
476 /* Persistent data held for a compilation unit, even when not
477 processing it. We put a pointer to this structure in the
478 read_symtab_private field of the psymtab. */
480 struct dwarf2_per_cu_data
482 /* The start offset and length of this compilation unit. 2**29-1
483 bytes should suffice to store the length of any compilation unit
484 - if it doesn't, GDB will fall over anyway.
485 NOTE: Unlike comp_unit_head.length, this length includes
487 If the DIE refers to a DWO file, this is always of the original die,
490 unsigned int length
: 29;
492 /* Flag indicating this compilation unit will be read in before
493 any of the current compilation units are processed. */
494 unsigned int queued
: 1;
496 /* This flag will be set when reading partial DIEs if we need to load
497 absolutely all DIEs for this compilation unit, instead of just the ones
498 we think are interesting. It gets set if we look for a DIE in the
499 hash table and don't find it. */
500 unsigned int load_all_dies
: 1;
502 /* Non-zero if this CU is from .debug_types. */
503 unsigned int is_debug_types
: 1;
505 /* The section this CU/TU lives in.
506 If the DIE refers to a DWO file, this is always the original die,
508 struct dwarf2_section_info
*info_or_types_section
;
510 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
511 of the CU cache it gets reset to NULL again. */
512 struct dwarf2_cu
*cu
;
514 /* The corresponding objfile.
515 Normally we can get the objfile from dwarf2_per_objfile.
516 However we can enter this file with just a "per_cu" handle. */
517 struct objfile
*objfile
;
519 /* When using partial symbol tables, the 'psymtab' field is active.
520 Otherwise the 'quick' field is active. */
523 /* The partial symbol table associated with this compilation unit,
524 or NULL for unread partial units. */
525 struct partial_symtab
*psymtab
;
527 /* Data needed by the "quick" functions. */
528 struct dwarf2_per_cu_quick_data
*quick
;
531 /* The CUs we import using DW_TAG_imported_unit. This is filled in
532 while reading psymtabs, used to compute the psymtab dependencies,
533 and then cleared. Then it is filled in again while reading full
534 symbols, and only deleted when the objfile is destroyed. */
535 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
538 /* Entry in the signatured_types hash table. */
540 struct signatured_type
542 /* The type's signature. */
545 /* Offset in the TU of the type's DIE, as read from the TU header.
546 If the definition lives in a DWO file, this value is unusable. */
547 cu_offset type_offset_in_tu
;
549 /* Offset in the section of the type's DIE.
550 If the definition lives in a DWO file, this is the offset in the
551 .debug_types.dwo section.
552 The value is zero until the actual value is known.
553 Zero is otherwise not a valid section offset. */
554 sect_offset type_offset_in_section
;
556 /* The CU(/TU) of this type. */
557 struct dwarf2_per_cu_data per_cu
;
560 /* These sections are what may appear in a "dwo" file. */
564 struct dwarf2_section_info abbrev
;
565 struct dwarf2_section_info info
;
566 struct dwarf2_section_info line
;
567 struct dwarf2_section_info loc
;
568 struct dwarf2_section_info str
;
569 struct dwarf2_section_info str_offsets
;
570 VEC (dwarf2_section_info_def
) *types
;
573 /* Common bits of DWO CUs/TUs. */
577 /* Backlink to the containing struct dwo_file. */
578 struct dwo_file
*dwo_file
;
580 /* The "id" that distinguishes this CU/TU.
581 .debug_info calls this "dwo_id", .debug_types calls this "signature".
582 Since signatures came first, we stick with it for consistency. */
585 /* The section this CU/TU lives in, in the DWO file. */
586 struct dwarf2_section_info
*info_or_types_section
;
588 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
592 /* For types, offset in the type's DIE of the type defined by this TU. */
593 cu_offset type_offset_in_tu
;
596 /* Data for one DWO file. */
600 /* The DW_AT_GNU_dwo_name attribute.
601 We don't manage space for this, it's an attribute. */
602 const char *dwo_name
;
604 /* The bfd, when the file is open. Otherwise this is NULL. */
607 /* Section info for this file. */
608 struct dwo_sections sections
;
610 /* Table of CUs in the file.
611 Each element is a struct dwo_unit. */
614 /* Table of TUs in the file.
615 Each element is a struct dwo_unit. */
619 /* Struct used to pass misc. parameters to read_die_and_children, et
620 al. which are used for both .debug_info and .debug_types dies.
621 All parameters here are unchanging for the life of the call. This
622 struct exists to abstract away the constant parameters of die reading. */
624 struct die_reader_specs
626 /* die_section->asection->owner. */
629 /* The CU of the DIE we are parsing. */
630 struct dwarf2_cu
*cu
;
632 /* Non-NULL if reading a DWO file. */
633 struct dwo_file
*dwo_file
;
635 /* The section the die comes from.
636 This is either .debug_info or .debug_types, or the .dwo variants. */
637 struct dwarf2_section_info
*die_section
;
639 /* die_section->buffer. */
642 /* The end of the buffer. */
643 const gdb_byte
*buffer_end
;
646 /* Type of function passed to init_cutu_and_read_dies, et.al. */
647 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
649 struct die_info
*comp_unit_die
,
653 /* The line number information for a compilation unit (found in the
654 .debug_line section) begins with a "statement program header",
655 which contains the following information. */
658 unsigned int total_length
;
659 unsigned short version
;
660 unsigned int header_length
;
661 unsigned char minimum_instruction_length
;
662 unsigned char maximum_ops_per_instruction
;
663 unsigned char default_is_stmt
;
665 unsigned char line_range
;
666 unsigned char opcode_base
;
668 /* standard_opcode_lengths[i] is the number of operands for the
669 standard opcode whose value is i. This means that
670 standard_opcode_lengths[0] is unused, and the last meaningful
671 element is standard_opcode_lengths[opcode_base - 1]. */
672 unsigned char *standard_opcode_lengths
;
674 /* The include_directories table. NOTE! These strings are not
675 allocated with xmalloc; instead, they are pointers into
676 debug_line_buffer. If you try to free them, `free' will get
678 unsigned int num_include_dirs
, include_dirs_size
;
681 /* The file_names table. NOTE! These strings are not allocated
682 with xmalloc; instead, they are pointers into debug_line_buffer.
683 Don't try to free them directly. */
684 unsigned int num_file_names
, file_names_size
;
688 unsigned int dir_index
;
689 unsigned int mod_time
;
691 int included_p
; /* Non-zero if referenced by the Line Number Program. */
692 struct symtab
*symtab
; /* The associated symbol table, if any. */
695 /* The start and end of the statement program following this
696 header. These point into dwarf2_per_objfile->line_buffer. */
697 gdb_byte
*statement_program_start
, *statement_program_end
;
700 /* When we construct a partial symbol table entry we only
701 need this much information. */
702 struct partial_die_info
704 /* Offset of this DIE. */
707 /* DWARF-2 tag for this DIE. */
708 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
710 /* Assorted flags describing the data found in this DIE. */
711 unsigned int has_children
: 1;
712 unsigned int is_external
: 1;
713 unsigned int is_declaration
: 1;
714 unsigned int has_type
: 1;
715 unsigned int has_specification
: 1;
716 unsigned int has_pc_info
: 1;
717 unsigned int may_be_inlined
: 1;
719 /* Flag set if the SCOPE field of this structure has been
721 unsigned int scope_set
: 1;
723 /* Flag set if the DIE has a byte_size attribute. */
724 unsigned int has_byte_size
: 1;
726 /* Flag set if any of the DIE's children are template arguments. */
727 unsigned int has_template_arguments
: 1;
729 /* Flag set if fixup_partial_die has been called on this die. */
730 unsigned int fixup_called
: 1;
732 /* The name of this DIE. Normally the value of DW_AT_name, but
733 sometimes a default name for unnamed DIEs. */
736 /* The linkage name, if present. */
737 const char *linkage_name
;
739 /* The scope to prepend to our children. This is generally
740 allocated on the comp_unit_obstack, so will disappear
741 when this compilation unit leaves the cache. */
744 /* Some data associated with the partial DIE. The tag determines
745 which field is live. */
748 /* The location description associated with this DIE, if any. */
749 struct dwarf_block
*locdesc
;
750 /* The offset of an import, for DW_TAG_imported_unit. */
754 /* If HAS_PC_INFO, the PC range associated with this DIE. */
758 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
759 DW_AT_sibling, if any. */
760 /* NOTE: This member isn't strictly necessary, read_partial_die could
761 return DW_AT_sibling values to its caller load_partial_dies. */
764 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
765 DW_AT_specification (or DW_AT_abstract_origin or
767 sect_offset spec_offset
;
769 /* Pointers to this DIE's parent, first child, and next sibling,
771 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
774 /* This data structure holds the information of an abbrev. */
777 unsigned int number
; /* number identifying abbrev */
778 enum dwarf_tag tag
; /* dwarf tag */
779 unsigned short has_children
; /* boolean */
780 unsigned short num_attrs
; /* number of attributes */
781 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
782 struct abbrev_info
*next
; /* next in chain */
787 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
788 ENUM_BITFIELD(dwarf_form
) form
: 16;
791 /* Attributes have a name and a value. */
794 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
795 ENUM_BITFIELD(dwarf_form
) form
: 15;
797 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
798 field should be in u.str (existing only for DW_STRING) but it is kept
799 here for better struct attribute alignment. */
800 unsigned int string_is_canonical
: 1;
805 struct dwarf_block
*blk
;
809 struct signatured_type
*signatured_type
;
814 /* This data structure holds a complete die structure. */
817 /* DWARF-2 tag for this DIE. */
818 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
820 /* Number of attributes */
821 unsigned char num_attrs
;
823 /* True if we're presently building the full type name for the
824 type derived from this DIE. */
825 unsigned char building_fullname
: 1;
830 /* Offset in .debug_info or .debug_types section. */
833 /* The dies in a compilation unit form an n-ary tree. PARENT
834 points to this die's parent; CHILD points to the first child of
835 this node; and all the children of a given node are chained
836 together via their SIBLING fields. */
837 struct die_info
*child
; /* Its first child, if any. */
838 struct die_info
*sibling
; /* Its next sibling, if any. */
839 struct die_info
*parent
; /* Its parent, if any. */
841 /* An array of attributes, with NUM_ATTRS elements. There may be
842 zero, but it's not common and zero-sized arrays are not
843 sufficiently portable C. */
844 struct attribute attrs
[1];
847 /* Get at parts of an attribute structure. */
849 #define DW_STRING(attr) ((attr)->u.str)
850 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
851 #define DW_UNSND(attr) ((attr)->u.unsnd)
852 #define DW_BLOCK(attr) ((attr)->u.blk)
853 #define DW_SND(attr) ((attr)->u.snd)
854 #define DW_ADDR(attr) ((attr)->u.addr)
855 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
857 /* Blocks are a bunch of untyped bytes. */
862 /* Valid only if SIZE is not zero. */
866 #ifndef ATTR_ALLOC_CHUNK
867 #define ATTR_ALLOC_CHUNK 4
870 /* Allocate fields for structs, unions and enums in this size. */
871 #ifndef DW_FIELD_ALLOC_CHUNK
872 #define DW_FIELD_ALLOC_CHUNK 4
875 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
876 but this would require a corresponding change in unpack_field_as_long
878 static int bits_per_byte
= 8;
880 /* The routines that read and process dies for a C struct or C++ class
881 pass lists of data member fields and lists of member function fields
882 in an instance of a field_info structure, as defined below. */
885 /* List of data member and baseclasses fields. */
888 struct nextfield
*next
;
893 *fields
, *baseclasses
;
895 /* Number of fields (including baseclasses). */
898 /* Number of baseclasses. */
901 /* Set if the accesibility of one of the fields is not public. */
902 int non_public_fields
;
904 /* Member function fields array, entries are allocated in the order they
905 are encountered in the object file. */
908 struct nextfnfield
*next
;
909 struct fn_field fnfield
;
913 /* Member function fieldlist array, contains name of possibly overloaded
914 member function, number of overloaded member functions and a pointer
915 to the head of the member function field chain. */
920 struct nextfnfield
*head
;
924 /* Number of entries in the fnfieldlists array. */
927 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
928 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
929 struct typedef_field_list
931 struct typedef_field field
;
932 struct typedef_field_list
*next
;
935 unsigned typedef_field_list_count
;
938 /* One item on the queue of compilation units to read in full symbols
940 struct dwarf2_queue_item
942 struct dwarf2_per_cu_data
*per_cu
;
943 enum language pretend_language
;
944 struct dwarf2_queue_item
*next
;
947 /* The current queue. */
948 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
950 /* Loaded secondary compilation units are kept in memory until they
951 have not been referenced for the processing of this many
952 compilation units. Set this to zero to disable caching. Cache
953 sizes of up to at least twenty will improve startup time for
954 typical inter-CU-reference binaries, at an obvious memory cost. */
955 static int dwarf2_max_cache_age
= 5;
957 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
958 struct cmd_list_element
*c
, const char *value
)
960 fprintf_filtered (file
, _("The upper bound on the age of cached "
961 "dwarf2 compilation units is %s.\n"),
966 /* Various complaints about symbol reading that don't abort the process. */
969 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
971 complaint (&symfile_complaints
,
972 _("statement list doesn't fit in .debug_line section"));
976 dwarf2_debug_line_missing_file_complaint (void)
978 complaint (&symfile_complaints
,
979 _(".debug_line section has line data without a file"));
983 dwarf2_debug_line_missing_end_sequence_complaint (void)
985 complaint (&symfile_complaints
,
986 _(".debug_line section has line "
987 "program sequence without an end"));
991 dwarf2_complex_location_expr_complaint (void)
993 complaint (&symfile_complaints
, _("location expression too complex"));
997 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1000 complaint (&symfile_complaints
,
1001 _("const value length mismatch for '%s', got %d, expected %d"),
1006 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1008 complaint (&symfile_complaints
,
1009 _("debug info runs off end of %s section"
1011 section
->asection
->name
,
1012 bfd_get_filename (section
->asection
->owner
));
1016 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1018 complaint (&symfile_complaints
,
1019 _("macro debug info contains a "
1020 "malformed macro definition:\n`%s'"),
1025 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1027 complaint (&symfile_complaints
,
1028 _("invalid attribute class or form for '%s' in '%s'"),
1032 /* local function prototypes */
1034 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1036 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1039 static void dwarf2_find_base_address (struct die_info
*die
,
1040 struct dwarf2_cu
*cu
);
1042 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1044 static void scan_partial_symbols (struct partial_die_info
*,
1045 CORE_ADDR
*, CORE_ADDR
*,
1046 int, struct dwarf2_cu
*);
1048 static void add_partial_symbol (struct partial_die_info
*,
1049 struct dwarf2_cu
*);
1051 static void add_partial_namespace (struct partial_die_info
*pdi
,
1052 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1053 int need_pc
, struct dwarf2_cu
*cu
);
1055 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1056 CORE_ADDR
*highpc
, int need_pc
,
1057 struct dwarf2_cu
*cu
);
1059 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1060 struct dwarf2_cu
*cu
);
1062 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1063 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1064 int need_pc
, struct dwarf2_cu
*cu
);
1066 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1068 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1070 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1071 struct dwarf2_section_info
*);
1073 static void dwarf2_free_abbrev_table (void *);
1075 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1077 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1078 struct dwarf2_cu
*);
1080 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1081 struct dwarf2_cu
*);
1083 static struct partial_die_info
*load_partial_dies
1084 (const struct die_reader_specs
*, gdb_byte
*, int);
1086 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1087 struct partial_die_info
*,
1088 struct abbrev_info
*,
1092 static struct partial_die_info
*find_partial_die (sect_offset
,
1093 struct dwarf2_cu
*);
1095 static void fixup_partial_die (struct partial_die_info
*,
1096 struct dwarf2_cu
*);
1098 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1099 struct attribute
*, struct attr_abbrev
*,
1102 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1104 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1106 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1108 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1110 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1112 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1115 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1117 static LONGEST read_checked_initial_length_and_offset
1118 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1119 unsigned int *, unsigned int *);
1121 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1124 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1126 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1128 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1130 static char *read_indirect_string (bfd
*, gdb_byte
*,
1131 const struct comp_unit_head
*,
1134 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1136 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1138 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1141 static char *read_str_index (const struct die_reader_specs
*reader
,
1142 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1144 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1146 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1147 struct dwarf2_cu
*);
1149 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1151 struct dwarf2_cu
*);
1153 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1154 struct dwarf2_cu
*cu
);
1156 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1158 static struct die_info
*die_specification (struct die_info
*die
,
1159 struct dwarf2_cu
**);
1161 static void free_line_header (struct line_header
*lh
);
1163 static void add_file_name (struct line_header
*, char *, unsigned int,
1164 unsigned int, unsigned int);
1166 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1167 struct dwarf2_cu
*cu
);
1169 static void dwarf_decode_lines (struct line_header
*, const char *,
1170 struct dwarf2_cu
*, struct partial_symtab
*,
1173 static void dwarf2_start_subfile (char *, const char *, const char *);
1175 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1176 struct dwarf2_cu
*);
1178 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1179 struct dwarf2_cu
*, struct symbol
*);
1181 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1182 struct dwarf2_cu
*);
1184 static void dwarf2_const_value_attr (struct attribute
*attr
,
1187 struct obstack
*obstack
,
1188 struct dwarf2_cu
*cu
, LONGEST
*value
,
1190 struct dwarf2_locexpr_baton
**baton
);
1192 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1194 static int need_gnat_info (struct dwarf2_cu
*);
1196 static struct type
*die_descriptive_type (struct die_info
*,
1197 struct dwarf2_cu
*);
1199 static void set_descriptive_type (struct type
*, struct die_info
*,
1200 struct dwarf2_cu
*);
1202 static struct type
*die_containing_type (struct die_info
*,
1203 struct dwarf2_cu
*);
1205 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1206 struct dwarf2_cu
*);
1208 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1210 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1212 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1214 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1215 const char *suffix
, int physname
,
1216 struct dwarf2_cu
*cu
);
1218 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1220 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1222 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1224 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1226 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1228 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1229 struct dwarf2_cu
*, struct partial_symtab
*);
1231 static int dwarf2_get_pc_bounds (struct die_info
*,
1232 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1233 struct partial_symtab
*);
1235 static void get_scope_pc_bounds (struct die_info
*,
1236 CORE_ADDR
*, CORE_ADDR
*,
1237 struct dwarf2_cu
*);
1239 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1240 CORE_ADDR
, struct dwarf2_cu
*);
1242 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1243 struct dwarf2_cu
*);
1245 static void dwarf2_attach_fields_to_type (struct field_info
*,
1246 struct type
*, struct dwarf2_cu
*);
1248 static void dwarf2_add_member_fn (struct field_info
*,
1249 struct die_info
*, struct type
*,
1250 struct dwarf2_cu
*);
1252 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1254 struct dwarf2_cu
*);
1256 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1258 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1260 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1262 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1264 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1266 static struct type
*read_module_type (struct die_info
*die
,
1267 struct dwarf2_cu
*cu
);
1269 static const char *namespace_name (struct die_info
*die
,
1270 int *is_anonymous
, struct dwarf2_cu
*);
1272 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1274 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1276 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1277 struct dwarf2_cu
*);
1279 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1281 gdb_byte
**new_info_ptr
,
1282 struct die_info
*parent
);
1284 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1286 gdb_byte
**new_info_ptr
,
1287 struct die_info
*parent
);
1289 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1290 struct die_info
**, gdb_byte
*, int *, int);
1292 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1293 struct die_info
**, gdb_byte
*, int *);
1295 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1297 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1300 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1302 static const char *dwarf2_full_name (char *name
,
1303 struct die_info
*die
,
1304 struct dwarf2_cu
*cu
);
1306 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1307 struct dwarf2_cu
**);
1309 static const char *dwarf_tag_name (unsigned int);
1311 static const char *dwarf_attr_name (unsigned int);
1313 static const char *dwarf_form_name (unsigned int);
1315 static char *dwarf_bool_name (unsigned int);
1317 static const char *dwarf_type_encoding_name (unsigned int);
1319 static struct die_info
*sibling_die (struct die_info
*);
1321 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1323 static void dump_die_for_error (struct die_info
*);
1325 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1328 /*static*/ void dump_die (struct die_info
*, int max_level
);
1330 static void store_in_ref_table (struct die_info
*,
1331 struct dwarf2_cu
*);
1333 static int is_ref_attr (struct attribute
*);
1335 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1337 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1339 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1341 struct dwarf2_cu
**);
1343 static struct die_info
*follow_die_ref (struct die_info
*,
1345 struct dwarf2_cu
**);
1347 static struct die_info
*follow_die_sig (struct die_info
*,
1349 struct dwarf2_cu
**);
1351 static struct signatured_type
*lookup_signatured_type_at_offset
1352 (struct objfile
*objfile
,
1353 struct dwarf2_section_info
*section
, sect_offset offset
);
1355 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1357 static void read_signatured_type (struct signatured_type
*);
1359 /* memory allocation interface */
1361 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1363 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1365 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1367 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1368 char *, bfd
*, struct dwarf2_cu
*,
1369 struct dwarf2_section_info
*,
1372 static int attr_form_is_block (struct attribute
*);
1374 static int attr_form_is_section_offset (struct attribute
*);
1376 static int attr_form_is_constant (struct attribute
*);
1378 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1379 struct dwarf2_loclist_baton
*baton
,
1380 struct attribute
*attr
);
1382 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1384 struct dwarf2_cu
*cu
);
1386 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1388 struct abbrev_info
*abbrev
);
1390 static void free_stack_comp_unit (void *);
1392 static hashval_t
partial_die_hash (const void *item
);
1394 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1396 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1397 (sect_offset offset
, struct objfile
*objfile
);
1399 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1400 struct dwarf2_per_cu_data
*per_cu
);
1402 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1403 struct die_info
*comp_unit_die
,
1404 enum language pretend_language
);
1406 static void free_heap_comp_unit (void *);
1408 static void free_cached_comp_units (void *);
1410 static void age_cached_comp_units (void);
1412 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1414 static struct type
*set_die_type (struct die_info
*, struct type
*,
1415 struct dwarf2_cu
*);
1417 static void create_all_comp_units (struct objfile
*);
1419 static int create_all_type_units (struct objfile
*);
1421 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1424 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1427 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1428 struct dwarf2_per_cu_data
*);
1430 static void dwarf2_mark (struct dwarf2_cu
*);
1432 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1434 static struct type
*get_die_type_at_offset (sect_offset
,
1435 struct dwarf2_per_cu_data
*per_cu
);
1437 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1439 static void dwarf2_release_queue (void *dummy
);
1441 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1442 enum language pretend_language
);
1444 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1445 struct dwarf2_per_cu_data
*per_cu
,
1446 enum language pretend_language
);
1448 static void process_queue (void);
1450 static void find_file_and_directory (struct die_info
*die
,
1451 struct dwarf2_cu
*cu
,
1452 char **name
, char **comp_dir
);
1454 static char *file_full_name (int file
, struct line_header
*lh
,
1455 const char *comp_dir
);
1457 static gdb_byte
*read_and_check_comp_unit_head
1458 (struct comp_unit_head
*header
,
1459 struct dwarf2_section_info
*section
, gdb_byte
*info_ptr
,
1460 int is_debug_types_section
);
1462 static void init_cutu_and_read_dies
1463 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1464 die_reader_func_ftype
*die_reader_func
, void *data
);
1466 static void init_cutu_and_read_dies_simple
1467 (struct dwarf2_per_cu_data
*this_cu
,
1468 die_reader_func_ftype
*die_reader_func
, void *data
);
1470 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1472 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1474 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1476 static struct dwo_unit
*lookup_dwo_comp_unit
1477 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1479 static struct dwo_unit
*lookup_dwo_type_unit
1480 (struct signatured_type
*, char *, const char *);
1482 static void free_dwo_file_cleanup (void *);
1484 static void munmap_section_buffer (struct dwarf2_section_info
*);
1486 static void process_cu_includes (void);
1490 /* Convert VALUE between big- and little-endian. */
1492 byte_swap (offset_type value
)
1496 result
= (value
& 0xff) << 24;
1497 result
|= (value
& 0xff00) << 8;
1498 result
|= (value
& 0xff0000) >> 8;
1499 result
|= (value
& 0xff000000) >> 24;
1503 #define MAYBE_SWAP(V) byte_swap (V)
1506 #define MAYBE_SWAP(V) (V)
1507 #endif /* WORDS_BIGENDIAN */
1509 /* The suffix for an index file. */
1510 #define INDEX_SUFFIX ".gdb-index"
1512 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1513 struct dwarf2_cu
*cu
);
1515 /* Try to locate the sections we need for DWARF 2 debugging
1516 information and return true if we have enough to do something.
1517 NAMES points to the dwarf2 section names, or is NULL if the standard
1518 ELF names are used. */
1521 dwarf2_has_info (struct objfile
*objfile
,
1522 const struct dwarf2_debug_sections
*names
)
1524 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1525 if (!dwarf2_per_objfile
)
1527 /* Initialize per-objfile state. */
1528 struct dwarf2_per_objfile
*data
1529 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1531 memset (data
, 0, sizeof (*data
));
1532 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1533 dwarf2_per_objfile
= data
;
1535 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1537 dwarf2_per_objfile
->objfile
= objfile
;
1539 return (dwarf2_per_objfile
->info
.asection
!= NULL
1540 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1543 /* When loading sections, we look either for uncompressed section or for
1544 compressed section names. */
1547 section_is_p (const char *section_name
,
1548 const struct dwarf2_section_names
*names
)
1550 if (names
->normal
!= NULL
1551 && strcmp (section_name
, names
->normal
) == 0)
1553 if (names
->compressed
!= NULL
1554 && strcmp (section_name
, names
->compressed
) == 0)
1559 /* This function is mapped across the sections and remembers the
1560 offset and size of each of the debugging sections we are interested
1564 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1566 const struct dwarf2_debug_sections
*names
;
1569 names
= &dwarf2_elf_names
;
1571 names
= (const struct dwarf2_debug_sections
*) vnames
;
1573 if (section_is_p (sectp
->name
, &names
->info
))
1575 dwarf2_per_objfile
->info
.asection
= sectp
;
1576 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1578 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1580 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1581 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1583 else if (section_is_p (sectp
->name
, &names
->line
))
1585 dwarf2_per_objfile
->line
.asection
= sectp
;
1586 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1588 else if (section_is_p (sectp
->name
, &names
->loc
))
1590 dwarf2_per_objfile
->loc
.asection
= sectp
;
1591 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1593 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1595 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1596 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1598 else if (section_is_p (sectp
->name
, &names
->macro
))
1600 dwarf2_per_objfile
->macro
.asection
= sectp
;
1601 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1603 else if (section_is_p (sectp
->name
, &names
->str
))
1605 dwarf2_per_objfile
->str
.asection
= sectp
;
1606 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1608 else if (section_is_p (sectp
->name
, &names
->addr
))
1610 dwarf2_per_objfile
->addr
.asection
= sectp
;
1611 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1613 else if (section_is_p (sectp
->name
, &names
->frame
))
1615 dwarf2_per_objfile
->frame
.asection
= sectp
;
1616 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1618 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1620 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1622 if (aflag
& SEC_HAS_CONTENTS
)
1624 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1625 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1628 else if (section_is_p (sectp
->name
, &names
->ranges
))
1630 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1631 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1633 else if (section_is_p (sectp
->name
, &names
->types
))
1635 struct dwarf2_section_info type_section
;
1637 memset (&type_section
, 0, sizeof (type_section
));
1638 type_section
.asection
= sectp
;
1639 type_section
.size
= bfd_get_section_size (sectp
);
1641 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1644 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1646 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1647 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1650 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1651 && bfd_section_vma (abfd
, sectp
) == 0)
1652 dwarf2_per_objfile
->has_section_at_zero
= 1;
1655 /* Decompress a section that was compressed using zlib. Store the
1656 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1659 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1660 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1662 bfd
*abfd
= sectp
->owner
;
1664 error (_("Support for zlib-compressed DWARF data (from '%s') "
1665 "is disabled in this copy of GDB"),
1666 bfd_get_filename (abfd
));
1668 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1669 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1670 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1671 bfd_size_type uncompressed_size
;
1672 gdb_byte
*uncompressed_buffer
;
1675 int header_size
= 12;
1677 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1678 || bfd_bread (compressed_buffer
,
1679 compressed_size
, abfd
) != compressed_size
)
1680 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1681 bfd_get_filename (abfd
));
1683 /* Read the zlib header. In this case, it should be "ZLIB" followed
1684 by the uncompressed section size, 8 bytes in big-endian order. */
1685 if (compressed_size
< header_size
1686 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1687 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1688 bfd_get_filename (abfd
));
1689 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1690 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1691 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1692 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1693 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1694 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1695 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1696 uncompressed_size
+= compressed_buffer
[11];
1698 /* It is possible the section consists of several compressed
1699 buffers concatenated together, so we uncompress in a loop. */
1703 strm
.avail_in
= compressed_size
- header_size
;
1704 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1705 strm
.avail_out
= uncompressed_size
;
1706 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1708 rc
= inflateInit (&strm
);
1709 while (strm
.avail_in
> 0)
1712 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1713 bfd_get_filename (abfd
), rc
);
1714 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1715 + (uncompressed_size
- strm
.avail_out
));
1716 rc
= inflate (&strm
, Z_FINISH
);
1717 if (rc
!= Z_STREAM_END
)
1718 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1719 bfd_get_filename (abfd
), rc
);
1720 rc
= inflateReset (&strm
);
1722 rc
= inflateEnd (&strm
);
1724 || strm
.avail_out
!= 0)
1725 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1726 bfd_get_filename (abfd
), rc
);
1728 do_cleanups (cleanup
);
1729 *outbuf
= uncompressed_buffer
;
1730 *outsize
= uncompressed_size
;
1734 /* A helper function that decides whether a section is empty,
1738 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1740 return info
->asection
== NULL
|| info
->size
== 0;
1743 /* Read the contents of the section INFO.
1744 OBJFILE is the main object file, but not necessarily the file where
1745 the section comes from. E.g., for DWO files INFO->asection->owner
1746 is the bfd of the DWO file.
1747 If the section is compressed, uncompress it before returning. */
1750 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1752 asection
*sectp
= info
->asection
;
1754 gdb_byte
*buf
, *retbuf
;
1755 unsigned char header
[4];
1759 info
->buffer
= NULL
;
1760 info
->map_addr
= NULL
;
1763 if (dwarf2_section_empty_p (info
))
1766 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1767 abfd
= sectp
->owner
;
1769 /* Check if the file has a 4-byte header indicating compression. */
1770 if (info
->size
> sizeof (header
)
1771 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1772 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1774 /* Upon decompression, update the buffer and its size. */
1775 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1777 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1785 pagesize
= getpagesize ();
1787 /* Only try to mmap sections which are large enough: we don't want to
1788 waste space due to fragmentation. Also, only try mmap for sections
1789 without relocations. */
1791 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1793 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1794 MAP_PRIVATE
, sectp
->filepos
,
1795 &info
->map_addr
, &info
->map_len
);
1797 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1799 #if HAVE_POSIX_MADVISE
1800 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1807 /* If we get here, we are a normal, not-compressed section. */
1809 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1811 /* When debugging .o files, we may need to apply relocations; see
1812 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1813 We never compress sections in .o files, so we only need to
1814 try this when the section is not compressed. */
1815 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1818 info
->buffer
= retbuf
;
1822 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1823 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1824 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1825 bfd_get_filename (abfd
));
1828 /* A helper function that returns the size of a section in a safe way.
1829 If you are positive that the section has been read before using the
1830 size, then it is safe to refer to the dwarf2_section_info object's
1831 "size" field directly. In other cases, you must call this
1832 function, because for compressed sections the size field is not set
1833 correctly until the section has been read. */
1835 static bfd_size_type
1836 dwarf2_section_size (struct objfile
*objfile
,
1837 struct dwarf2_section_info
*info
)
1840 dwarf2_read_section (objfile
, info
);
1844 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1848 dwarf2_get_section_info (struct objfile
*objfile
,
1849 enum dwarf2_section_enum sect
,
1850 asection
**sectp
, gdb_byte
**bufp
,
1851 bfd_size_type
*sizep
)
1853 struct dwarf2_per_objfile
*data
1854 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1855 struct dwarf2_section_info
*info
;
1857 /* We may see an objfile without any DWARF, in which case we just
1868 case DWARF2_DEBUG_FRAME
:
1869 info
= &data
->frame
;
1871 case DWARF2_EH_FRAME
:
1872 info
= &data
->eh_frame
;
1875 gdb_assert_not_reached ("unexpected section");
1878 dwarf2_read_section (objfile
, info
);
1880 *sectp
= info
->asection
;
1881 *bufp
= info
->buffer
;
1882 *sizep
= info
->size
;
1886 /* DWARF quick_symbols_functions support. */
1888 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1889 unique line tables, so we maintain a separate table of all .debug_line
1890 derived entries to support the sharing.
1891 All the quick functions need is the list of file names. We discard the
1892 line_header when we're done and don't need to record it here. */
1893 struct quick_file_names
1895 /* The offset in .debug_line of the line table. We hash on this. */
1896 unsigned int offset
;
1898 /* The number of entries in file_names, real_names. */
1899 unsigned int num_file_names
;
1901 /* The file names from the line table, after being run through
1903 const char **file_names
;
1905 /* The file names from the line table after being run through
1906 gdb_realpath. These are computed lazily. */
1907 const char **real_names
;
1910 /* When using the index (and thus not using psymtabs), each CU has an
1911 object of this type. This is used to hold information needed by
1912 the various "quick" methods. */
1913 struct dwarf2_per_cu_quick_data
1915 /* The file table. This can be NULL if there was no file table
1916 or it's currently not read in.
1917 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1918 struct quick_file_names
*file_names
;
1920 /* The corresponding symbol table. This is NULL if symbols for this
1921 CU have not yet been read. */
1922 struct symtab
*symtab
;
1924 /* A temporary mark bit used when iterating over all CUs in
1925 expand_symtabs_matching. */
1926 unsigned int mark
: 1;
1928 /* True if we've tried to read the file table and found there isn't one.
1929 There will be no point in trying to read it again next time. */
1930 unsigned int no_file_data
: 1;
1933 /* Hash function for a quick_file_names. */
1936 hash_file_name_entry (const void *e
)
1938 const struct quick_file_names
*file_data
= e
;
1940 return file_data
->offset
;
1943 /* Equality function for a quick_file_names. */
1946 eq_file_name_entry (const void *a
, const void *b
)
1948 const struct quick_file_names
*ea
= a
;
1949 const struct quick_file_names
*eb
= b
;
1951 return ea
->offset
== eb
->offset
;
1954 /* Delete function for a quick_file_names. */
1957 delete_file_name_entry (void *e
)
1959 struct quick_file_names
*file_data
= e
;
1962 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1964 xfree ((void*) file_data
->file_names
[i
]);
1965 if (file_data
->real_names
)
1966 xfree ((void*) file_data
->real_names
[i
]);
1969 /* The space for the struct itself lives on objfile_obstack,
1970 so we don't free it here. */
1973 /* Create a quick_file_names hash table. */
1976 create_quick_file_names_table (unsigned int nr_initial_entries
)
1978 return htab_create_alloc (nr_initial_entries
,
1979 hash_file_name_entry
, eq_file_name_entry
,
1980 delete_file_name_entry
, xcalloc
, xfree
);
1983 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1984 have to be created afterwards. You should call age_cached_comp_units after
1985 processing PER_CU->CU. dw2_setup must have been already called. */
1988 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1990 if (per_cu
->is_debug_types
)
1991 load_full_type_unit (per_cu
);
1993 load_full_comp_unit (per_cu
, language_minimal
);
1995 gdb_assert (per_cu
->cu
!= NULL
);
1997 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2000 /* Read in the symbols for PER_CU. */
2003 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2005 struct cleanup
*back_to
;
2007 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2009 if (dwarf2_per_objfile
->using_index
2010 ? per_cu
->v
.quick
->symtab
== NULL
2011 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2013 queue_comp_unit (per_cu
, language_minimal
);
2019 /* Age the cache, releasing compilation units that have not
2020 been used recently. */
2021 age_cached_comp_units ();
2023 do_cleanups (back_to
);
2026 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2027 the objfile from which this CU came. Returns the resulting symbol
2030 static struct symtab
*
2031 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2033 gdb_assert (dwarf2_per_objfile
->using_index
);
2034 if (!per_cu
->v
.quick
->symtab
)
2036 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2037 increment_reading_symtab ();
2038 dw2_do_instantiate_symtab (per_cu
);
2039 process_cu_includes ();
2040 do_cleanups (back_to
);
2042 return per_cu
->v
.quick
->symtab
;
2045 /* Return the CU given its index. */
2047 static struct dwarf2_per_cu_data
*
2048 dw2_get_cu (int index
)
2050 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2052 index
-= dwarf2_per_objfile
->n_comp_units
;
2053 return dwarf2_per_objfile
->all_type_units
[index
];
2055 return dwarf2_per_objfile
->all_comp_units
[index
];
2058 /* A helper function that knows how to read a 64-bit value in a way
2059 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2063 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2065 if (sizeof (ULONGEST
) < 8)
2069 /* Ignore the upper 4 bytes if they are all zero. */
2070 for (i
= 0; i
< 4; ++i
)
2071 if (bytes
[i
+ 4] != 0)
2074 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2077 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2081 /* Read the CU list from the mapped index, and use it to create all
2082 the CU objects for this objfile. Return 0 if something went wrong,
2083 1 if everything went ok. */
2086 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2087 offset_type cu_list_elements
)
2091 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2092 dwarf2_per_objfile
->all_comp_units
2093 = obstack_alloc (&objfile
->objfile_obstack
,
2094 dwarf2_per_objfile
->n_comp_units
2095 * sizeof (struct dwarf2_per_cu_data
*));
2097 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2099 struct dwarf2_per_cu_data
*the_cu
;
2100 ULONGEST offset
, length
;
2102 if (!extract_cu_value (cu_list
, &offset
)
2103 || !extract_cu_value (cu_list
+ 8, &length
))
2107 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2108 struct dwarf2_per_cu_data
);
2109 the_cu
->offset
.sect_off
= offset
;
2110 the_cu
->length
= length
;
2111 the_cu
->objfile
= objfile
;
2112 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2113 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2114 struct dwarf2_per_cu_quick_data
);
2115 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2121 /* Create the signatured type hash table from the index. */
2124 create_signatured_type_table_from_index (struct objfile
*objfile
,
2125 struct dwarf2_section_info
*section
,
2126 const gdb_byte
*bytes
,
2127 offset_type elements
)
2130 htab_t sig_types_hash
;
2132 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2133 dwarf2_per_objfile
->all_type_units
2134 = obstack_alloc (&objfile
->objfile_obstack
,
2135 dwarf2_per_objfile
->n_type_units
2136 * sizeof (struct dwarf2_per_cu_data
*));
2138 sig_types_hash
= allocate_signatured_type_table (objfile
);
2140 for (i
= 0; i
< elements
; i
+= 3)
2142 struct signatured_type
*sig_type
;
2143 ULONGEST offset
, type_offset_in_tu
, signature
;
2146 if (!extract_cu_value (bytes
, &offset
)
2147 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2149 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2152 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2153 struct signatured_type
);
2154 sig_type
->signature
= signature
;
2155 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2156 sig_type
->per_cu
.is_debug_types
= 1;
2157 sig_type
->per_cu
.info_or_types_section
= section
;
2158 sig_type
->per_cu
.offset
.sect_off
= offset
;
2159 sig_type
->per_cu
.objfile
= objfile
;
2160 sig_type
->per_cu
.v
.quick
2161 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2162 struct dwarf2_per_cu_quick_data
);
2164 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2167 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2170 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2175 /* Read the address map data from the mapped index, and use it to
2176 populate the objfile's psymtabs_addrmap. */
2179 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2181 const gdb_byte
*iter
, *end
;
2182 struct obstack temp_obstack
;
2183 struct addrmap
*mutable_map
;
2184 struct cleanup
*cleanup
;
2187 obstack_init (&temp_obstack
);
2188 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2189 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2191 iter
= index
->address_table
;
2192 end
= iter
+ index
->address_table_size
;
2194 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2198 ULONGEST hi
, lo
, cu_index
;
2199 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2201 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2203 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2206 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2207 dw2_get_cu (cu_index
));
2210 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2211 &objfile
->objfile_obstack
);
2212 do_cleanups (cleanup
);
2215 /* The hash function for strings in the mapped index. This is the same as
2216 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2217 implementation. This is necessary because the hash function is tied to the
2218 format of the mapped index file. The hash values do not have to match with
2221 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2224 mapped_index_string_hash (int index_version
, const void *p
)
2226 const unsigned char *str
= (const unsigned char *) p
;
2230 while ((c
= *str
++) != 0)
2232 if (index_version
>= 5)
2234 r
= r
* 67 + c
- 113;
2240 /* Find a slot in the mapped index INDEX for the object named NAME.
2241 If NAME is found, set *VEC_OUT to point to the CU vector in the
2242 constant pool and return 1. If NAME cannot be found, return 0. */
2245 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2246 offset_type
**vec_out
)
2248 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2250 offset_type slot
, step
;
2251 int (*cmp
) (const char *, const char *);
2253 if (current_language
->la_language
== language_cplus
2254 || current_language
->la_language
== language_java
2255 || current_language
->la_language
== language_fortran
)
2257 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2259 const char *paren
= strchr (name
, '(');
2265 dup
= xmalloc (paren
- name
+ 1);
2266 memcpy (dup
, name
, paren
- name
);
2267 dup
[paren
- name
] = 0;
2269 make_cleanup (xfree
, dup
);
2274 /* Index version 4 did not support case insensitive searches. But the
2275 indices for case insensitive languages are built in lowercase, therefore
2276 simulate our NAME being searched is also lowercased. */
2277 hash
= mapped_index_string_hash ((index
->version
== 4
2278 && case_sensitivity
== case_sensitive_off
2279 ? 5 : index
->version
),
2282 slot
= hash
& (index
->symbol_table_slots
- 1);
2283 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2284 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2288 /* Convert a slot number to an offset into the table. */
2289 offset_type i
= 2 * slot
;
2291 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2293 do_cleanups (back_to
);
2297 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2298 if (!cmp (name
, str
))
2300 *vec_out
= (offset_type
*) (index
->constant_pool
2301 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2302 do_cleanups (back_to
);
2306 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2310 /* Read the index file. If everything went ok, initialize the "quick"
2311 elements of all the CUs and return 1. Otherwise, return 0. */
2314 dwarf2_read_index (struct objfile
*objfile
)
2317 struct mapped_index
*map
;
2318 offset_type
*metadata
;
2319 const gdb_byte
*cu_list
;
2320 const gdb_byte
*types_list
= NULL
;
2321 offset_type version
, cu_list_elements
;
2322 offset_type types_list_elements
= 0;
2325 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2328 /* Older elfutils strip versions could keep the section in the main
2329 executable while splitting it for the separate debug info file. */
2330 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2331 & SEC_HAS_CONTENTS
) == 0)
2334 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2336 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2337 /* Version check. */
2338 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2339 /* Versions earlier than 3 emitted every copy of a psymbol. This
2340 causes the index to behave very poorly for certain requests. Version 3
2341 contained incomplete addrmap. So, it seems better to just ignore such
2345 static int warning_printed
= 0;
2346 if (!warning_printed
)
2348 warning (_("Skipping obsolete .gdb_index section in %s."),
2350 warning_printed
= 1;
2354 /* Index version 4 uses a different hash function than index version
2357 Versions earlier than 6 did not emit psymbols for inlined
2358 functions. Using these files will cause GDB not to be able to
2359 set breakpoints on inlined functions by name, so we ignore these
2360 indices unless the --use-deprecated-index-sections command line
2361 option was supplied. */
2362 if (version
< 6 && !use_deprecated_index_sections
)
2364 static int warning_printed
= 0;
2365 if (!warning_printed
)
2367 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2368 "--use-deprecated-index-sections to use them anyway"),
2370 warning_printed
= 1;
2374 /* Indexes with higher version than the one supported by GDB may be no
2375 longer backward compatible. */
2379 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2380 map
->version
= version
;
2381 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2383 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2386 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2387 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2391 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2392 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2393 - MAYBE_SWAP (metadata
[i
]))
2397 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2398 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2399 - MAYBE_SWAP (metadata
[i
]));
2402 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2403 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2404 - MAYBE_SWAP (metadata
[i
]))
2405 / (2 * sizeof (offset_type
)));
2408 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2410 /* Don't use the index if it's empty. */
2411 if (map
->symbol_table_slots
== 0)
2414 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2417 if (types_list_elements
)
2419 struct dwarf2_section_info
*section
;
2421 /* We can only handle a single .debug_types when we have an
2423 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2426 section
= VEC_index (dwarf2_section_info_def
,
2427 dwarf2_per_objfile
->types
, 0);
2429 if (!create_signatured_type_table_from_index (objfile
, section
,
2431 types_list_elements
))
2435 create_addrmap_from_index (objfile
, map
);
2437 dwarf2_per_objfile
->index_table
= map
;
2438 dwarf2_per_objfile
->using_index
= 1;
2439 dwarf2_per_objfile
->quick_file_names_table
=
2440 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2445 /* A helper for the "quick" functions which sets the global
2446 dwarf2_per_objfile according to OBJFILE. */
2449 dw2_setup (struct objfile
*objfile
)
2451 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2452 gdb_assert (dwarf2_per_objfile
);
2455 /* die_reader_func for dw2_get_file_names. */
2458 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2460 struct die_info
*comp_unit_die
,
2464 struct dwarf2_cu
*cu
= reader
->cu
;
2465 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2466 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2467 struct line_header
*lh
;
2468 struct attribute
*attr
;
2470 char *name
, *comp_dir
;
2472 struct quick_file_names
*qfn
;
2473 unsigned int line_offset
;
2475 /* Our callers never want to match partial units -- instead they
2476 will match the enclosing full CU. */
2477 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2479 this_cu
->v
.quick
->no_file_data
= 1;
2487 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2490 struct quick_file_names find_entry
;
2492 line_offset
= DW_UNSND (attr
);
2494 /* We may have already read in this line header (TU line header sharing).
2495 If we have we're done. */
2496 find_entry
.offset
= line_offset
;
2497 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2498 &find_entry
, INSERT
);
2501 this_cu
->v
.quick
->file_names
= *slot
;
2505 lh
= dwarf_decode_line_header (line_offset
, cu
);
2509 this_cu
->v
.quick
->no_file_data
= 1;
2513 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2514 qfn
->offset
= line_offset
;
2515 gdb_assert (slot
!= NULL
);
2518 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2520 qfn
->num_file_names
= lh
->num_file_names
;
2521 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2522 lh
->num_file_names
* sizeof (char *));
2523 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2524 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2525 qfn
->real_names
= NULL
;
2527 free_line_header (lh
);
2529 this_cu
->v
.quick
->file_names
= qfn
;
2532 /* A helper for the "quick" functions which attempts to read the line
2533 table for THIS_CU. */
2535 static struct quick_file_names
*
2536 dw2_get_file_names (struct objfile
*objfile
,
2537 struct dwarf2_per_cu_data
*this_cu
)
2539 if (this_cu
->v
.quick
->file_names
!= NULL
)
2540 return this_cu
->v
.quick
->file_names
;
2541 /* If we know there is no line data, no point in looking again. */
2542 if (this_cu
->v
.quick
->no_file_data
)
2545 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2546 in the stub for CUs, there's is no need to lookup the DWO file.
2547 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2549 if (this_cu
->is_debug_types
)
2550 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2552 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2554 if (this_cu
->v
.quick
->no_file_data
)
2556 return this_cu
->v
.quick
->file_names
;
2559 /* A helper for the "quick" functions which computes and caches the
2560 real path for a given file name from the line table. */
2563 dw2_get_real_path (struct objfile
*objfile
,
2564 struct quick_file_names
*qfn
, int index
)
2566 if (qfn
->real_names
== NULL
)
2567 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2568 qfn
->num_file_names
, sizeof (char *));
2570 if (qfn
->real_names
[index
] == NULL
)
2571 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2573 return qfn
->real_names
[index
];
2576 static struct symtab
*
2577 dw2_find_last_source_symtab (struct objfile
*objfile
)
2581 dw2_setup (objfile
);
2582 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2583 return dw2_instantiate_symtab (dw2_get_cu (index
));
2586 /* Traversal function for dw2_forget_cached_source_info. */
2589 dw2_free_cached_file_names (void **slot
, void *info
)
2591 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2593 if (file_data
->real_names
)
2597 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2599 xfree ((void*) file_data
->real_names
[i
]);
2600 file_data
->real_names
[i
] = NULL
;
2608 dw2_forget_cached_source_info (struct objfile
*objfile
)
2610 dw2_setup (objfile
);
2612 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2613 dw2_free_cached_file_names
, NULL
);
2616 /* Helper function for dw2_map_symtabs_matching_filename that expands
2617 the symtabs and calls the iterator. */
2620 dw2_map_expand_apply (struct objfile
*objfile
,
2621 struct dwarf2_per_cu_data
*per_cu
,
2623 const char *full_path
, const char *real_path
,
2624 int (*callback
) (struct symtab
*, void *),
2627 struct symtab
*last_made
= objfile
->symtabs
;
2629 /* Don't visit already-expanded CUs. */
2630 if (per_cu
->v
.quick
->symtab
)
2633 /* This may expand more than one symtab, and we want to iterate over
2635 dw2_instantiate_symtab (per_cu
);
2637 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2638 objfile
->symtabs
, last_made
);
2641 /* Implementation of the map_symtabs_matching_filename method. */
2644 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2645 const char *full_path
, const char *real_path
,
2646 int (*callback
) (struct symtab
*, void *),
2650 const char *name_basename
= lbasename (name
);
2651 int name_len
= strlen (name
);
2652 int is_abs
= IS_ABSOLUTE_PATH (name
);
2654 dw2_setup (objfile
);
2656 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2657 + dwarf2_per_objfile
->n_type_units
); ++i
)
2660 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2661 struct quick_file_names
*file_data
;
2663 /* We only need to look at symtabs not already expanded. */
2664 if (per_cu
->v
.quick
->symtab
)
2667 file_data
= dw2_get_file_names (objfile
, per_cu
);
2668 if (file_data
== NULL
)
2671 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2673 const char *this_name
= file_data
->file_names
[j
];
2675 if (FILENAME_CMP (name
, this_name
) == 0
2676 || (!is_abs
&& compare_filenames_for_search (this_name
,
2679 if (dw2_map_expand_apply (objfile
, per_cu
,
2680 name
, full_path
, real_path
,
2685 /* Before we invoke realpath, which can get expensive when many
2686 files are involved, do a quick comparison of the basenames. */
2687 if (! basenames_may_differ
2688 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2691 if (full_path
!= NULL
)
2693 const char *this_real_name
= dw2_get_real_path (objfile
,
2696 if (this_real_name
!= NULL
2697 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2699 && compare_filenames_for_search (this_real_name
,
2702 if (dw2_map_expand_apply (objfile
, per_cu
,
2703 name
, full_path
, real_path
,
2709 if (real_path
!= NULL
)
2711 const char *this_real_name
= dw2_get_real_path (objfile
,
2714 if (this_real_name
!= NULL
2715 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2717 && compare_filenames_for_search (this_real_name
,
2720 if (dw2_map_expand_apply (objfile
, per_cu
,
2721 name
, full_path
, real_path
,
2732 static struct symtab
*
2733 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2734 const char *name
, domain_enum domain
)
2736 /* We do all the work in the pre_expand_symtabs_matching hook
2741 /* A helper function that expands all symtabs that hold an object
2742 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2743 symbols in block BLOCK_KIND. */
2746 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2747 int want_specific_block
,
2748 enum block_enum block_kind
,
2749 const char *name
, domain_enum domain
)
2751 struct mapped_index
*index
;
2753 dw2_setup (objfile
);
2755 index
= dwarf2_per_objfile
->index_table
;
2757 /* index_table is NULL if OBJF_READNOW. */
2762 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2764 offset_type i
, len
= MAYBE_SWAP (*vec
);
2765 for (i
= 0; i
< len
; ++i
)
2767 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2768 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2769 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2770 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2771 /* This value is only valid for index versions >= 7. */
2772 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2773 gdb_index_symbol_kind symbol_kind
=
2774 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2776 if (want_specific_block
2777 && index
->version
>= 7
2778 && want_static
!= is_static
)
2781 /* Only check the symbol's kind if it has one.
2782 Indices prior to version 7 don't record it. */
2783 if (index
->version
>= 7)
2788 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2789 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2790 /* Some types are also in VAR_DOMAIN. */
2791 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2795 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2799 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
2807 dw2_instantiate_symtab (per_cu
);
2814 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2815 enum block_enum block_kind
, const char *name
,
2818 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
2822 dw2_print_stats (struct objfile
*objfile
)
2826 dw2_setup (objfile
);
2828 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2829 + dwarf2_per_objfile
->n_type_units
); ++i
)
2831 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2833 if (!per_cu
->v
.quick
->symtab
)
2836 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2840 dw2_dump (struct objfile
*objfile
)
2842 /* Nothing worth printing. */
2846 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2847 struct section_offsets
*delta
)
2849 /* There's nothing to relocate here. */
2853 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2854 const char *func_name
)
2856 /* Note: It doesn't matter what we pass for block_kind here. */
2857 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
2862 dw2_expand_all_symtabs (struct objfile
*objfile
)
2866 dw2_setup (objfile
);
2868 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2869 + dwarf2_per_objfile
->n_type_units
); ++i
)
2871 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2873 dw2_instantiate_symtab (per_cu
);
2878 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2879 const char *filename
)
2883 dw2_setup (objfile
);
2885 /* We don't need to consider type units here.
2886 This is only called for examining code, e.g. expand_line_sal.
2887 There can be an order of magnitude (or more) more type units
2888 than comp units, and we avoid them if we can. */
2890 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2893 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2894 struct quick_file_names
*file_data
;
2896 /* We only need to look at symtabs not already expanded. */
2897 if (per_cu
->v
.quick
->symtab
)
2900 file_data
= dw2_get_file_names (objfile
, per_cu
);
2901 if (file_data
== NULL
)
2904 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2906 const char *this_name
= file_data
->file_names
[j
];
2907 if (FILENAME_CMP (this_name
, filename
) == 0)
2909 dw2_instantiate_symtab (per_cu
);
2916 /* A helper function for dw2_find_symbol_file that finds the primary
2917 file name for a given CU. This is a die_reader_func. */
2920 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
2922 struct die_info
*comp_unit_die
,
2926 const char **result_ptr
= data
;
2927 struct dwarf2_cu
*cu
= reader
->cu
;
2928 struct attribute
*attr
;
2930 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
2934 *result_ptr
= DW_STRING (attr
);
2938 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2940 struct dwarf2_per_cu_data
*per_cu
;
2942 struct quick_file_names
*file_data
;
2943 const char *filename
;
2945 dw2_setup (objfile
);
2947 /* index_table is NULL if OBJF_READNOW. */
2948 if (!dwarf2_per_objfile
->index_table
)
2952 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
2954 struct blockvector
*bv
= BLOCKVECTOR (s
);
2955 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2956 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2959 return sym
->symtab
->filename
;
2964 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2968 /* Note that this just looks at the very first one named NAME -- but
2969 actually we are looking for a function. find_main_filename
2970 should be rewritten so that it doesn't require a custom hook. It
2971 could just use the ordinary symbol tables. */
2972 /* vec[0] is the length, which must always be >0. */
2973 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
2975 if (per_cu
->v
.quick
->symtab
!= NULL
)
2976 return per_cu
->v
.quick
->symtab
->filename
;
2978 init_cutu_and_read_dies (per_cu
, 0, 0, dw2_get_primary_filename_reader
,
2985 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2986 struct objfile
*objfile
, int global
,
2987 int (*callback
) (struct block
*,
2988 struct symbol
*, void *),
2989 void *data
, symbol_compare_ftype
*match
,
2990 symbol_compare_ftype
*ordered_compare
)
2992 /* Currently unimplemented; used for Ada. The function can be called if the
2993 current language is Ada for a non-Ada objfile using GNU index. As Ada
2994 does not look for non-Ada symbols this function should just return. */
2998 dw2_expand_symtabs_matching
2999 (struct objfile
*objfile
,
3000 int (*file_matcher
) (const char *, void *),
3001 int (*name_matcher
) (const char *, void *),
3002 enum search_domain kind
,
3007 struct mapped_index
*index
;
3009 dw2_setup (objfile
);
3011 /* index_table is NULL if OBJF_READNOW. */
3012 if (!dwarf2_per_objfile
->index_table
)
3014 index
= dwarf2_per_objfile
->index_table
;
3016 if (file_matcher
!= NULL
)
3018 struct cleanup
*cleanup
;
3019 htab_t visited_found
, visited_not_found
;
3021 visited_found
= htab_create_alloc (10,
3022 htab_hash_pointer
, htab_eq_pointer
,
3023 NULL
, xcalloc
, xfree
);
3024 cleanup
= make_cleanup_htab_delete (visited_found
);
3025 visited_not_found
= htab_create_alloc (10,
3026 htab_hash_pointer
, htab_eq_pointer
,
3027 NULL
, xcalloc
, xfree
);
3028 make_cleanup_htab_delete (visited_not_found
);
3030 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3031 + dwarf2_per_objfile
->n_type_units
); ++i
)
3034 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3035 struct quick_file_names
*file_data
;
3038 per_cu
->v
.quick
->mark
= 0;
3040 /* We only need to look at symtabs not already expanded. */
3041 if (per_cu
->v
.quick
->symtab
)
3044 file_data
= dw2_get_file_names (objfile
, per_cu
);
3045 if (file_data
== NULL
)
3048 if (htab_find (visited_not_found
, file_data
) != NULL
)
3050 else if (htab_find (visited_found
, file_data
) != NULL
)
3052 per_cu
->v
.quick
->mark
= 1;
3056 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3058 if (file_matcher (file_data
->file_names
[j
], data
))
3060 per_cu
->v
.quick
->mark
= 1;
3065 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3067 : visited_not_found
,
3072 do_cleanups (cleanup
);
3075 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3077 offset_type idx
= 2 * iter
;
3079 offset_type
*vec
, vec_len
, vec_idx
;
3081 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3084 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3086 if (! (*name_matcher
) (name
, data
))
3089 /* The name was matched, now expand corresponding CUs that were
3091 vec
= (offset_type
*) (index
->constant_pool
3092 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3093 vec_len
= MAYBE_SWAP (vec
[0]);
3094 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3096 struct dwarf2_per_cu_data
*per_cu
;
3097 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3098 gdb_index_symbol_kind symbol_kind
=
3099 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3100 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3102 /* Don't crash on bad data. */
3103 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3104 + dwarf2_per_objfile
->n_comp_units
))
3107 /* Only check the symbol's kind if it has one.
3108 Indices prior to version 7 don't record it. */
3109 if (index
->version
>= 7)
3113 case VARIABLES_DOMAIN
:
3114 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3117 case FUNCTIONS_DOMAIN
:
3118 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3122 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3130 per_cu
= dw2_get_cu (cu_index
);
3131 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3132 dw2_instantiate_symtab (per_cu
);
3137 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3140 static struct symtab
*
3141 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3145 if (BLOCKVECTOR (symtab
) != NULL
3146 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3149 if (symtab
->includes
== NULL
)
3152 for (i
= 0; symtab
->includes
[i
]; ++i
)
3154 struct symtab
*s
= symtab
->includes
[i
];
3156 s
= recursively_find_pc_sect_symtab (s
, pc
);
3164 static struct symtab
*
3165 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3166 struct minimal_symbol
*msymbol
,
3168 struct obj_section
*section
,
3171 struct dwarf2_per_cu_data
*data
;
3172 struct symtab
*result
;
3174 dw2_setup (objfile
);
3176 if (!objfile
->psymtabs_addrmap
)
3179 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3183 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3184 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3185 paddress (get_objfile_arch (objfile
), pc
));
3187 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3188 gdb_assert (result
!= NULL
);
3193 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3194 void *data
, int need_fullname
)
3197 struct cleanup
*cleanup
;
3198 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3199 NULL
, xcalloc
, xfree
);
3201 cleanup
= make_cleanup_htab_delete (visited
);
3202 dw2_setup (objfile
);
3204 /* We can ignore file names coming from already-expanded CUs. */
3205 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3206 + dwarf2_per_objfile
->n_type_units
); ++i
)
3208 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3210 if (per_cu
->v
.quick
->symtab
)
3212 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3215 *slot
= per_cu
->v
.quick
->file_names
;
3219 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3220 + dwarf2_per_objfile
->n_type_units
); ++i
)
3223 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3224 struct quick_file_names
*file_data
;
3227 /* We only need to look at symtabs not already expanded. */
3228 if (per_cu
->v
.quick
->symtab
)
3231 file_data
= dw2_get_file_names (objfile
, per_cu
);
3232 if (file_data
== NULL
)
3235 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3238 /* Already visited. */
3243 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3245 const char *this_real_name
;
3248 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3250 this_real_name
= NULL
;
3251 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3255 do_cleanups (cleanup
);
3259 dw2_has_symbols (struct objfile
*objfile
)
3264 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3267 dw2_find_last_source_symtab
,
3268 dw2_forget_cached_source_info
,
3269 dw2_map_symtabs_matching_filename
,
3271 dw2_pre_expand_symtabs_matching
,
3275 dw2_expand_symtabs_for_function
,
3276 dw2_expand_all_symtabs
,
3277 dw2_expand_symtabs_with_filename
,
3278 dw2_find_symbol_file
,
3279 dw2_map_matching_symbols
,
3280 dw2_expand_symtabs_matching
,
3281 dw2_find_pc_sect_symtab
,
3282 dw2_map_symbol_filenames
3285 /* Initialize for reading DWARF for this objfile. Return 0 if this
3286 file will use psymtabs, or 1 if using the GNU index. */
3289 dwarf2_initialize_objfile (struct objfile
*objfile
)
3291 /* If we're about to read full symbols, don't bother with the
3292 indices. In this case we also don't care if some other debug
3293 format is making psymtabs, because they are all about to be
3295 if ((objfile
->flags
& OBJF_READNOW
))
3299 dwarf2_per_objfile
->using_index
= 1;
3300 create_all_comp_units (objfile
);
3301 create_all_type_units (objfile
);
3302 dwarf2_per_objfile
->quick_file_names_table
=
3303 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3305 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3306 + dwarf2_per_objfile
->n_type_units
); ++i
)
3308 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3310 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3311 struct dwarf2_per_cu_quick_data
);
3314 /* Return 1 so that gdb sees the "quick" functions. However,
3315 these functions will be no-ops because we will have expanded
3320 if (dwarf2_read_index (objfile
))
3328 /* Build a partial symbol table. */
3331 dwarf2_build_psymtabs (struct objfile
*objfile
)
3333 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3335 init_psymbol_list (objfile
, 1024);
3338 dwarf2_build_psymtabs_hard (objfile
);
3341 /* Return TRUE if OFFSET is within CU_HEADER. */
3344 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3346 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3347 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3348 + cu_header
->initial_length_size
) };
3350 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3353 /* Read in the comp unit header information from the debug_info at info_ptr.
3354 NOTE: This leaves members offset, first_die_offset to be filled in
3358 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3359 gdb_byte
*info_ptr
, bfd
*abfd
)
3362 unsigned int bytes_read
;
3364 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3365 cu_header
->initial_length_size
= bytes_read
;
3366 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3367 info_ptr
+= bytes_read
;
3368 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3370 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3372 info_ptr
+= bytes_read
;
3373 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3375 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3376 if (signed_addr
< 0)
3377 internal_error (__FILE__
, __LINE__
,
3378 _("read_comp_unit_head: dwarf from non elf file"));
3379 cu_header
->signed_addr_p
= signed_addr
;
3384 /* Subroutine of read_and_check_comp_unit_head and
3385 read_and_check_type_unit_head to simplify them.
3386 Perform various error checking on the header. */
3389 error_check_comp_unit_head (struct comp_unit_head
*header
,
3390 struct dwarf2_section_info
*section
)
3392 bfd
*abfd
= section
->asection
->owner
;
3393 const char *filename
= bfd_get_filename (abfd
);
3395 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3396 error (_("Dwarf Error: wrong version in compilation unit header "
3397 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3400 if (header
->abbrev_offset
.sect_off
3401 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3402 &dwarf2_per_objfile
->abbrev
))
3403 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3404 "(offset 0x%lx + 6) [in module %s]"),
3405 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3408 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3409 avoid potential 32-bit overflow. */
3410 if (((unsigned long) header
->offset
.sect_off
3411 + header
->length
+ header
->initial_length_size
)
3413 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3414 "(offset 0x%lx + 0) [in module %s]"),
3415 (long) header
->length
, (long) header
->offset
.sect_off
,
3419 /* Read in a CU/TU header and perform some basic error checking.
3420 The contents of the header are stored in HEADER.
3421 The result is a pointer to the start of the first DIE. */
3424 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3425 struct dwarf2_section_info
*section
,
3427 int is_debug_types_section
)
3429 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3430 bfd
*abfd
= section
->asection
->owner
;
3432 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3434 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3436 /* If we're reading a type unit, skip over the signature and
3437 type_offset fields. */
3438 if (is_debug_types_section
)
3439 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3441 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3443 error_check_comp_unit_head (header
, section
);
3448 /* Read in the types comp unit header information from .debug_types entry at
3449 types_ptr. The result is a pointer to one past the end of the header. */
3452 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3453 struct dwarf2_section_info
*section
,
3455 ULONGEST
*signature
,
3456 cu_offset
*type_offset_in_tu
)
3458 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3459 bfd
*abfd
= section
->asection
->owner
;
3461 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3463 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3465 /* If we're reading a type unit, skip over the signature and
3466 type_offset fields. */
3467 if (signature
!= NULL
)
3468 *signature
= read_8_bytes (abfd
, info_ptr
);
3470 if (type_offset_in_tu
!= NULL
)
3471 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3472 header
->offset_size
);
3473 info_ptr
+= header
->offset_size
;
3475 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3477 error_check_comp_unit_head (header
, section
);
3482 /* Allocate a new partial symtab for file named NAME and mark this new
3483 partial symtab as being an include of PST. */
3486 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3487 struct objfile
*objfile
)
3489 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3491 subpst
->section_offsets
= pst
->section_offsets
;
3492 subpst
->textlow
= 0;
3493 subpst
->texthigh
= 0;
3495 subpst
->dependencies
= (struct partial_symtab
**)
3496 obstack_alloc (&objfile
->objfile_obstack
,
3497 sizeof (struct partial_symtab
*));
3498 subpst
->dependencies
[0] = pst
;
3499 subpst
->number_of_dependencies
= 1;
3501 subpst
->globals_offset
= 0;
3502 subpst
->n_global_syms
= 0;
3503 subpst
->statics_offset
= 0;
3504 subpst
->n_static_syms
= 0;
3505 subpst
->symtab
= NULL
;
3506 subpst
->read_symtab
= pst
->read_symtab
;
3509 /* No private part is necessary for include psymtabs. This property
3510 can be used to differentiate between such include psymtabs and
3511 the regular ones. */
3512 subpst
->read_symtab_private
= NULL
;
3515 /* Read the Line Number Program data and extract the list of files
3516 included by the source file represented by PST. Build an include
3517 partial symtab for each of these included files. */
3520 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3521 struct die_info
*die
,
3522 struct partial_symtab
*pst
)
3524 struct line_header
*lh
= NULL
;
3525 struct attribute
*attr
;
3527 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3529 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3531 return; /* No linetable, so no includes. */
3533 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3534 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3536 free_line_header (lh
);
3540 hash_signatured_type (const void *item
)
3542 const struct signatured_type
*sig_type
= item
;
3544 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3545 return sig_type
->signature
;
3549 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3551 const struct signatured_type
*lhs
= item_lhs
;
3552 const struct signatured_type
*rhs
= item_rhs
;
3554 return lhs
->signature
== rhs
->signature
;
3557 /* Allocate a hash table for signatured types. */
3560 allocate_signatured_type_table (struct objfile
*objfile
)
3562 return htab_create_alloc_ex (41,
3563 hash_signatured_type
,
3566 &objfile
->objfile_obstack
,
3567 hashtab_obstack_allocate
,
3568 dummy_obstack_deallocate
);
3571 /* A helper function to add a signatured type CU to a table. */
3574 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3576 struct signatured_type
*sigt
= *slot
;
3577 struct dwarf2_per_cu_data
***datap
= datum
;
3579 **datap
= &sigt
->per_cu
;
3585 /* Create the hash table of all entries in the .debug_types section.
3586 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3587 The result is a pointer to the hash table or NULL if there are
3591 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3592 VEC (dwarf2_section_info_def
) *types
)
3594 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3595 htab_t types_htab
= NULL
;
3597 struct dwarf2_section_info
*section
;
3599 if (VEC_empty (dwarf2_section_info_def
, types
))
3603 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3607 gdb_byte
*info_ptr
, *end_ptr
;
3609 dwarf2_read_section (objfile
, section
);
3610 info_ptr
= section
->buffer
;
3612 if (info_ptr
== NULL
)
3615 /* We can't set abfd until now because the section may be empty or
3616 not present, in which case section->asection will be NULL. */
3617 abfd
= section
->asection
->owner
;
3619 if (types_htab
== NULL
)
3622 types_htab
= allocate_dwo_unit_table (objfile
);
3624 types_htab
= allocate_signatured_type_table (objfile
);
3627 if (dwarf2_die_debug
)
3628 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3629 bfd_get_filename (abfd
));
3631 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3632 because we don't need to read any dies: the signature is in the
3635 end_ptr
= info_ptr
+ section
->size
;
3636 while (info_ptr
< end_ptr
)
3639 cu_offset type_offset_in_tu
;
3641 struct signatured_type
*sig_type
;
3642 struct dwo_unit
*dwo_tu
;
3644 gdb_byte
*ptr
= info_ptr
;
3645 struct comp_unit_head header
;
3646 unsigned int length
;
3648 offset
.sect_off
= ptr
- section
->buffer
;
3650 /* We need to read the type's signature in order to build the hash
3651 table, but we don't need anything else just yet. */
3653 ptr
= read_and_check_type_unit_head (&header
, section
, ptr
,
3654 &signature
, &type_offset_in_tu
);
3656 length
= header
.initial_length_size
+ header
.length
;
3658 /* Skip dummy type units. */
3659 if (ptr
>= info_ptr
+ length
3660 || peek_abbrev_code (abfd
, ptr
) == 0)
3662 info_ptr
+= header
.initial_length_size
+ header
.length
;
3669 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3671 dwo_tu
->dwo_file
= dwo_file
;
3672 dwo_tu
->signature
= signature
;
3673 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3674 dwo_tu
->info_or_types_section
= section
;
3675 dwo_tu
->offset
= offset
;
3676 dwo_tu
->length
= length
;
3680 /* N.B.: type_offset is not usable if this type uses a DWO file.
3681 The real type_offset is in the DWO file. */
3683 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3684 struct signatured_type
);
3685 sig_type
->signature
= signature
;
3686 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3687 sig_type
->per_cu
.objfile
= objfile
;
3688 sig_type
->per_cu
.is_debug_types
= 1;
3689 sig_type
->per_cu
.info_or_types_section
= section
;
3690 sig_type
->per_cu
.offset
= offset
;
3691 sig_type
->per_cu
.length
= length
;
3694 slot
= htab_find_slot (types_htab
,
3695 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3697 gdb_assert (slot
!= NULL
);
3700 sect_offset dup_offset
;
3704 const struct dwo_unit
*dup_tu
= *slot
;
3706 dup_offset
= dup_tu
->offset
;
3710 const struct signatured_type
*dup_tu
= *slot
;
3712 dup_offset
= dup_tu
->per_cu
.offset
;
3715 complaint (&symfile_complaints
,
3716 _("debug type entry at offset 0x%x is duplicate to the "
3717 "entry at offset 0x%x, signature 0x%s"),
3718 offset
.sect_off
, dup_offset
.sect_off
,
3719 phex (signature
, sizeof (signature
)));
3721 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3723 if (dwarf2_die_debug
)
3724 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3726 phex (signature
, sizeof (signature
)));
3735 /* Create the hash table of all entries in the .debug_types section,
3736 and initialize all_type_units.
3737 The result is zero if there is an error (e.g. missing .debug_types section),
3738 otherwise non-zero. */
3741 create_all_type_units (struct objfile
*objfile
)
3744 struct dwarf2_per_cu_data
**iter
;
3746 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3747 if (types_htab
== NULL
)
3749 dwarf2_per_objfile
->signatured_types
= NULL
;
3753 dwarf2_per_objfile
->signatured_types
= types_htab
;
3755 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3756 dwarf2_per_objfile
->all_type_units
3757 = obstack_alloc (&objfile
->objfile_obstack
,
3758 dwarf2_per_objfile
->n_type_units
3759 * sizeof (struct dwarf2_per_cu_data
*));
3760 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3761 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3762 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3763 == dwarf2_per_objfile
->n_type_units
);
3768 /* Lookup a signature based type for DW_FORM_ref_sig8.
3769 Returns NULL if signature SIG is not present in the table. */
3771 static struct signatured_type
*
3772 lookup_signatured_type (ULONGEST sig
)
3774 struct signatured_type find_entry
, *entry
;
3776 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3778 complaint (&symfile_complaints
,
3779 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3783 find_entry
.signature
= sig
;
3784 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3788 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3791 init_cu_die_reader (struct die_reader_specs
*reader
,
3792 struct dwarf2_cu
*cu
,
3793 struct dwarf2_section_info
*section
,
3794 struct dwo_file
*dwo_file
)
3796 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3797 reader
->abfd
= section
->asection
->owner
;
3799 reader
->dwo_file
= dwo_file
;
3800 reader
->die_section
= section
;
3801 reader
->buffer
= section
->buffer
;
3802 reader
->buffer_end
= section
->buffer
+ section
->size
;
3805 /* Find the base address of the compilation unit for range lists and
3806 location lists. It will normally be specified by DW_AT_low_pc.
3807 In DWARF-3 draft 4, the base address could be overridden by
3808 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3809 compilation units with discontinuous ranges. */
3812 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3814 struct attribute
*attr
;
3817 cu
->base_address
= 0;
3819 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3822 cu
->base_address
= DW_ADDR (attr
);
3827 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3830 cu
->base_address
= DW_ADDR (attr
);
3836 /* Initialize a CU (or TU) and read its DIEs.
3837 If the CU defers to a DWO file, read the DWO file as well.
3839 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3840 Otherwise, a new CU is allocated with xmalloc.
3842 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3843 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3845 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3846 linker) then DIE_READER_FUNC will not get called. */
3849 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3850 int use_existing_cu
, int keep
,
3851 die_reader_func_ftype
*die_reader_func
,
3854 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3855 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3856 bfd
*abfd
= section
->asection
->owner
;
3857 struct dwarf2_cu
*cu
;
3858 gdb_byte
*begin_info_ptr
, *info_ptr
;
3859 struct die_reader_specs reader
;
3860 struct die_info
*comp_unit_die
;
3862 struct attribute
*attr
;
3863 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3864 struct signatured_type
*sig_type
= NULL
;
3866 if (use_existing_cu
)
3869 cleanups
= make_cleanup (null_cleanup
, NULL
);
3871 /* This is cheap if the section is already read in. */
3872 dwarf2_read_section (objfile
, section
);
3874 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3876 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3879 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3883 /* If !use_existing_cu, this_cu->cu must be NULL. */
3884 gdb_assert (this_cu
->cu
== NULL
);
3886 cu
= xmalloc (sizeof (*cu
));
3887 init_one_comp_unit (cu
, this_cu
);
3889 /* If an error occurs while loading, release our storage. */
3890 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3892 if (this_cu
->is_debug_types
)
3896 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
3900 /* There's no way to get from PER_CU to its containing
3901 struct signatured_type.
3902 But we have the signature so we can use that. */
3903 sig_type
= lookup_signatured_type (signature
);
3904 /* We've already scanned all the signatured types,
3905 this must succeed. */
3906 gdb_assert (sig_type
!= NULL
);
3907 gdb_assert (&sig_type
->per_cu
== this_cu
);
3908 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3910 /* LENGTH has not been set yet for type units. */
3911 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3913 /* Establish the type offset that can be used to lookup the type. */
3914 sig_type
->type_offset_in_section
.sect_off
=
3915 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3919 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
3920 section
, info_ptr
, 0);
3922 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3923 gdb_assert (this_cu
->length
3924 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3928 /* Skip dummy compilation units. */
3929 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3930 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3932 do_cleanups (cleanups
);
3936 /* Read the abbrevs for this compilation unit into a table. */
3937 if (cu
->dwarf2_abbrevs
== NULL
)
3939 dwarf2_read_abbrevs (cu
, &dwarf2_per_objfile
->abbrev
);
3940 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3943 /* Read the top level CU/TU die. */
3944 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3945 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3947 /* If we have a DWO stub, process it and then read in the DWO file.
3948 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3949 a DWO CU, that this test will fail. */
3950 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3953 char *dwo_name
= DW_STRING (attr
);
3954 const char *comp_dir
;
3955 struct dwo_unit
*dwo_unit
;
3956 ULONGEST signature
; /* Or dwo_id. */
3957 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3958 int i
,num_extra_attrs
;
3961 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3962 " has children (offset 0x%x) [in module %s]"),
3963 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3965 /* These attributes aren't processed until later:
3966 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3967 However, the attribute is found in the stub which we won't have later.
3968 In order to not impose this complication on the rest of the code,
3969 we read them here and copy them to the DWO CU/TU die. */
3970 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3972 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3974 if (! this_cu
->is_debug_types
)
3975 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3976 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3977 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3978 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3980 /* There should be a DW_AT_addr_base attribute here (if needed).
3981 We need the value before we can process DW_FORM_GNU_addr_index. */
3983 cu
->have_addr_base
= 0;
3984 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
3987 cu
->addr_base
= DW_UNSND (attr
);
3988 cu
->have_addr_base
= 1;
3991 if (this_cu
->is_debug_types
)
3993 gdb_assert (sig_type
!= NULL
);
3994 signature
= sig_type
->signature
;
3998 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4000 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4002 signature
= DW_UNSND (attr
);
4005 /* We may need the comp_dir in order to find the DWO file. */
4007 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4009 comp_dir
= DW_STRING (attr
);
4011 if (this_cu
->is_debug_types
)
4012 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
4014 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
4017 if (dwo_unit
== NULL
)
4019 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4020 " with ID %s [in module %s]"),
4021 this_cu
->offset
.sect_off
,
4022 phex (signature
, sizeof (signature
)),
4026 /* Set up for reading the DWO CU/TU. */
4027 cu
->dwo_unit
= dwo_unit
;
4028 section
= dwo_unit
->info_or_types_section
;
4029 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4030 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4032 if (this_cu
->is_debug_types
)
4036 info_ptr
= read_and_check_type_unit_head (&cu
->header
,
4039 gdb_assert (sig_type
->signature
== signature
);
4040 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4041 gdb_assert (dwo_unit
->length
4042 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4044 /* Establish the type offset that can be used to lookup the type.
4045 For DWO files, we don't know it until now. */
4046 sig_type
->type_offset_in_section
.sect_off
=
4047 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4051 info_ptr
= read_and_check_comp_unit_head (&cu
->header
,
4052 section
, info_ptr
, 0);
4053 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4054 gdb_assert (dwo_unit
->length
4055 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4058 /* Discard the original CU's abbrev table, and read the DWO's. */
4059 dwarf2_free_abbrev_table (cu
);
4060 dwarf2_read_abbrevs (cu
, &dwo_unit
->dwo_file
->sections
.abbrev
);
4062 /* Read in the die, but leave space to copy over the attributes
4063 from the stub. This has the benefit of simplifying the rest of
4064 the code - all the real work is done here. */
4065 num_extra_attrs
= ((stmt_list
!= NULL
)
4068 + (ranges
!= NULL
));
4069 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4070 &has_children
, num_extra_attrs
);
4072 /* Copy over the attributes from the stub to the DWO die. */
4073 i
= comp_unit_die
->num_attrs
;
4074 if (stmt_list
!= NULL
)
4075 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4077 comp_unit_die
->attrs
[i
++] = *low_pc
;
4078 if (high_pc
!= NULL
)
4079 comp_unit_die
->attrs
[i
++] = *high_pc
;
4081 comp_unit_die
->attrs
[i
++] = *ranges
;
4082 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4084 /* Skip dummy compilation units. */
4085 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4086 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4088 do_cleanups (cleanups
);
4093 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4095 if (free_cu_cleanup
!= NULL
)
4099 /* We've successfully allocated this compilation unit. Let our
4100 caller clean it up when finished with it. */
4101 discard_cleanups (free_cu_cleanup
);
4103 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4104 So we have to manually free the abbrev table. */
4105 dwarf2_free_abbrev_table (cu
);
4107 /* Link this CU into read_in_chain. */
4108 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4109 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4112 do_cleanups (free_cu_cleanup
);
4115 do_cleanups (cleanups
);
4118 /* Read CU/TU THIS_CU in section SECTION,
4119 but do not follow DW_AT_GNU_dwo_name if present.
4120 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4121 have already done the lookup to find the DWO file).
4123 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4124 THIS_CU->is_debug_types, but nothing else.
4126 We fill in THIS_CU->length.
4128 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4129 linker) then DIE_READER_FUNC will not get called.
4131 THIS_CU->cu is always freed when done.
4132 This is done in order to not leave THIS_CU->cu in a state where we have
4133 to care whether it refers to the "main" CU or the DWO CU. */
4136 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4137 struct dwarf2_section_info
*abbrev_section
,
4138 struct dwo_file
*dwo_file
,
4139 die_reader_func_ftype
*die_reader_func
,
4142 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4143 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4144 bfd
*abfd
= section
->asection
->owner
;
4145 struct dwarf2_cu cu
;
4146 gdb_byte
*begin_info_ptr
, *info_ptr
;
4147 struct die_reader_specs reader
;
4148 struct cleanup
*cleanups
;
4149 struct die_info
*comp_unit_die
;
4152 gdb_assert (this_cu
->cu
== NULL
);
4154 /* This is cheap if the section is already read in. */
4155 dwarf2_read_section (objfile
, section
);
4157 init_one_comp_unit (&cu
, this_cu
);
4159 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4161 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4162 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
, info_ptr
,
4163 this_cu
->is_debug_types
);
4165 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4167 /* Skip dummy compilation units. */
4168 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4169 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4171 do_cleanups (cleanups
);
4175 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4176 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4178 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4179 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4181 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4183 do_cleanups (cleanups
);
4186 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4187 does not lookup the specified DWO file.
4188 This cannot be used to read DWO files.
4190 THIS_CU->cu is always freed when done.
4191 This is done in order to not leave THIS_CU->cu in a state where we have
4192 to care whether it refers to the "main" CU or the DWO CU.
4193 We can revisit this if the data shows there's a performance issue. */
4196 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4197 die_reader_func_ftype
*die_reader_func
,
4200 init_cutu_and_read_dies_no_follow (this_cu
,
4201 &dwarf2_per_objfile
->abbrev
,
4203 die_reader_func
, data
);
4206 /* die_reader_func for process_psymtab_comp_unit. */
4209 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4211 struct die_info
*comp_unit_die
,
4215 struct dwarf2_cu
*cu
= reader
->cu
;
4216 struct objfile
*objfile
= cu
->objfile
;
4217 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4218 struct attribute
*attr
;
4220 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4221 struct partial_symtab
*pst
;
4223 const char *filename
;
4224 int *want_partial_unit_ptr
= data
;
4226 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4227 && (want_partial_unit_ptr
== NULL
4228 || !*want_partial_unit_ptr
))
4231 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4233 cu
->list_in_scope
= &file_symbols
;
4235 /* Allocate a new partial symbol table structure. */
4236 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4237 if (attr
== NULL
|| !DW_STRING (attr
))
4240 filename
= DW_STRING (attr
);
4241 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4243 /* TEXTLOW and TEXTHIGH are set below. */
4245 objfile
->global_psymbols
.next
,
4246 objfile
->static_psymbols
.next
);
4247 pst
->psymtabs_addrmap_supported
= 1;
4249 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4251 pst
->dirname
= DW_STRING (attr
);
4253 pst
->read_symtab_private
= per_cu
;
4255 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4257 /* Store the function that reads in the rest of the symbol table. */
4258 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4260 per_cu
->v
.psymtab
= pst
;
4262 dwarf2_find_base_address (comp_unit_die
, cu
);
4264 /* Possibly set the default values of LOWPC and HIGHPC from
4266 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4267 &best_highpc
, cu
, pst
);
4268 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4269 /* Store the contiguous range if it is not empty; it can be empty for
4270 CUs with no code. */
4271 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4272 best_lowpc
+ baseaddr
,
4273 best_highpc
+ baseaddr
- 1, pst
);
4275 /* Check if comp unit has_children.
4276 If so, read the rest of the partial symbols from this comp unit.
4277 If not, there's no more debug_info for this comp unit. */
4280 struct partial_die_info
*first_die
;
4281 CORE_ADDR lowpc
, highpc
;
4283 lowpc
= ((CORE_ADDR
) -1);
4284 highpc
= ((CORE_ADDR
) 0);
4286 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4288 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4291 /* If we didn't find a lowpc, set it to highpc to avoid
4292 complaints from `maint check'. */
4293 if (lowpc
== ((CORE_ADDR
) -1))
4296 /* If the compilation unit didn't have an explicit address range,
4297 then use the information extracted from its child dies. */
4301 best_highpc
= highpc
;
4304 pst
->textlow
= best_lowpc
+ baseaddr
;
4305 pst
->texthigh
= best_highpc
+ baseaddr
;
4307 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4308 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4309 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4310 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4311 sort_pst_symbols (pst
);
4313 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4316 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4317 struct dwarf2_per_cu_data
*iter
;
4319 /* Fill in 'dependencies' here; we fill in 'users' in a
4321 pst
->number_of_dependencies
= len
;
4322 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4323 len
* sizeof (struct symtab
*));
4325 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4328 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4330 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4333 if (per_cu
->is_debug_types
)
4335 /* It's not clear we want to do anything with stmt lists here.
4336 Waiting to see what gcc ultimately does. */
4340 /* Get the list of files included in the current compilation unit,
4341 and build a psymtab for each of them. */
4342 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4346 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4347 Process compilation unit THIS_CU for a psymtab. */
4350 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4351 int want_partial_unit
)
4353 /* If this compilation unit was already read in, free the
4354 cached copy in order to read it in again. This is
4355 necessary because we skipped some symbols when we first
4356 read in the compilation unit (see load_partial_dies).
4357 This problem could be avoided, but the benefit is unclear. */
4358 if (this_cu
->cu
!= NULL
)
4359 free_one_cached_comp_unit (this_cu
);
4361 gdb_assert (! this_cu
->is_debug_types
);
4362 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4363 &want_partial_unit
);
4365 /* Age out any secondary CUs. */
4366 age_cached_comp_units ();
4369 /* Traversal function for htab_traverse_noresize.
4370 Process one .debug_types comp-unit. */
4373 process_psymtab_type_unit (void **slot
, void *info
)
4375 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4376 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4378 gdb_assert (per_cu
->is_debug_types
);
4379 gdb_assert (info
== NULL
);
4381 /* If this compilation unit was already read in, free the
4382 cached copy in order to read it in again. This is
4383 necessary because we skipped some symbols when we first
4384 read in the compilation unit (see load_partial_dies).
4385 This problem could be avoided, but the benefit is unclear. */
4386 if (per_cu
->cu
!= NULL
)
4387 free_one_cached_comp_unit (per_cu
);
4389 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4392 /* Age out any secondary CUs. */
4393 age_cached_comp_units ();
4398 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4399 Build partial symbol tables for the .debug_types comp-units. */
4402 build_type_psymtabs (struct objfile
*objfile
)
4404 if (! create_all_type_units (objfile
))
4407 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4408 process_psymtab_type_unit
, NULL
);
4411 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4414 psymtabs_addrmap_cleanup (void *o
)
4416 struct objfile
*objfile
= o
;
4418 objfile
->psymtabs_addrmap
= NULL
;
4421 /* Compute the 'user' field for each psymtab in OBJFILE. */
4424 set_partial_user (struct objfile
*objfile
)
4428 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4430 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4431 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4434 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4436 /* Set the 'user' field only if it is not already set. */
4437 if (pst
->dependencies
[j
]->user
== NULL
)
4438 pst
->dependencies
[j
]->user
= pst
;
4443 /* Build the partial symbol table by doing a quick pass through the
4444 .debug_info and .debug_abbrev sections. */
4447 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4449 struct cleanup
*back_to
, *addrmap_cleanup
;
4450 struct obstack temp_obstack
;
4453 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4455 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4457 /* Any cached compilation units will be linked by the per-objfile
4458 read_in_chain. Make sure to free them when we're done. */
4459 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4461 build_type_psymtabs (objfile
);
4463 create_all_comp_units (objfile
);
4465 /* Create a temporary address map on a temporary obstack. We later
4466 copy this to the final obstack. */
4467 obstack_init (&temp_obstack
);
4468 make_cleanup_obstack_free (&temp_obstack
);
4469 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4470 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4472 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4474 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4476 process_psymtab_comp_unit (per_cu
, 0);
4479 set_partial_user (objfile
);
4481 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4482 &objfile
->objfile_obstack
);
4483 discard_cleanups (addrmap_cleanup
);
4485 do_cleanups (back_to
);
4488 /* die_reader_func for load_partial_comp_unit. */
4491 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4493 struct die_info
*comp_unit_die
,
4497 struct dwarf2_cu
*cu
= reader
->cu
;
4499 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4501 /* Check if comp unit has_children.
4502 If so, read the rest of the partial symbols from this comp unit.
4503 If not, there's no more debug_info for this comp unit. */
4505 load_partial_dies (reader
, info_ptr
, 0);
4508 /* Load the partial DIEs for a secondary CU into memory.
4509 This is also used when rereading a primary CU with load_all_dies. */
4512 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4514 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4517 /* Create a list of all compilation units in OBJFILE.
4518 This is only done for -readnow and building partial symtabs. */
4521 create_all_comp_units (struct objfile
*objfile
)
4525 struct dwarf2_per_cu_data
**all_comp_units
;
4528 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4529 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4533 all_comp_units
= xmalloc (n_allocated
4534 * sizeof (struct dwarf2_per_cu_data
*));
4536 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4537 + dwarf2_per_objfile
->info
.size
)
4539 unsigned int length
, initial_length_size
;
4540 struct dwarf2_per_cu_data
*this_cu
;
4543 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4545 /* Read just enough information to find out where the next
4546 compilation unit is. */
4547 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4548 &initial_length_size
);
4550 /* Save the compilation unit for later lookup. */
4551 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4552 sizeof (struct dwarf2_per_cu_data
));
4553 memset (this_cu
, 0, sizeof (*this_cu
));
4554 this_cu
->offset
= offset
;
4555 this_cu
->length
= length
+ initial_length_size
;
4556 this_cu
->objfile
= objfile
;
4557 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4559 if (n_comp_units
== n_allocated
)
4562 all_comp_units
= xrealloc (all_comp_units
,
4564 * sizeof (struct dwarf2_per_cu_data
*));
4566 all_comp_units
[n_comp_units
++] = this_cu
;
4568 info_ptr
= info_ptr
+ this_cu
->length
;
4571 dwarf2_per_objfile
->all_comp_units
4572 = obstack_alloc (&objfile
->objfile_obstack
,
4573 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4574 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4575 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4576 xfree (all_comp_units
);
4577 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4580 /* Process all loaded DIEs for compilation unit CU, starting at
4581 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4582 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4583 DW_AT_ranges). If NEED_PC is set, then this function will set
4584 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4585 and record the covered ranges in the addrmap. */
4588 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4589 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4591 struct partial_die_info
*pdi
;
4593 /* Now, march along the PDI's, descending into ones which have
4594 interesting children but skipping the children of the other ones,
4595 until we reach the end of the compilation unit. */
4601 fixup_partial_die (pdi
, cu
);
4603 /* Anonymous namespaces or modules have no name but have interesting
4604 children, so we need to look at them. Ditto for anonymous
4607 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4608 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4609 || pdi
->tag
== DW_TAG_imported_unit
)
4613 case DW_TAG_subprogram
:
4614 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4616 case DW_TAG_constant
:
4617 case DW_TAG_variable
:
4618 case DW_TAG_typedef
:
4619 case DW_TAG_union_type
:
4620 if (!pdi
->is_declaration
)
4622 add_partial_symbol (pdi
, cu
);
4625 case DW_TAG_class_type
:
4626 case DW_TAG_interface_type
:
4627 case DW_TAG_structure_type
:
4628 if (!pdi
->is_declaration
)
4630 add_partial_symbol (pdi
, cu
);
4633 case DW_TAG_enumeration_type
:
4634 if (!pdi
->is_declaration
)
4635 add_partial_enumeration (pdi
, cu
);
4637 case DW_TAG_base_type
:
4638 case DW_TAG_subrange_type
:
4639 /* File scope base type definitions are added to the partial
4641 add_partial_symbol (pdi
, cu
);
4643 case DW_TAG_namespace
:
4644 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4647 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4649 case DW_TAG_imported_unit
:
4651 struct dwarf2_per_cu_data
*per_cu
;
4653 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4656 /* Go read the partial unit, if needed. */
4657 if (per_cu
->v
.psymtab
== NULL
)
4658 process_psymtab_comp_unit (per_cu
, 1);
4660 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4669 /* If the die has a sibling, skip to the sibling. */
4671 pdi
= pdi
->die_sibling
;
4675 /* Functions used to compute the fully scoped name of a partial DIE.
4677 Normally, this is simple. For C++, the parent DIE's fully scoped
4678 name is concatenated with "::" and the partial DIE's name. For
4679 Java, the same thing occurs except that "." is used instead of "::".
4680 Enumerators are an exception; they use the scope of their parent
4681 enumeration type, i.e. the name of the enumeration type is not
4682 prepended to the enumerator.
4684 There are two complexities. One is DW_AT_specification; in this
4685 case "parent" means the parent of the target of the specification,
4686 instead of the direct parent of the DIE. The other is compilers
4687 which do not emit DW_TAG_namespace; in this case we try to guess
4688 the fully qualified name of structure types from their members'
4689 linkage names. This must be done using the DIE's children rather
4690 than the children of any DW_AT_specification target. We only need
4691 to do this for structures at the top level, i.e. if the target of
4692 any DW_AT_specification (if any; otherwise the DIE itself) does not
4695 /* Compute the scope prefix associated with PDI's parent, in
4696 compilation unit CU. The result will be allocated on CU's
4697 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4698 field. NULL is returned if no prefix is necessary. */
4700 partial_die_parent_scope (struct partial_die_info
*pdi
,
4701 struct dwarf2_cu
*cu
)
4703 char *grandparent_scope
;
4704 struct partial_die_info
*parent
, *real_pdi
;
4706 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4707 then this means the parent of the specification DIE. */
4710 while (real_pdi
->has_specification
)
4711 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4713 parent
= real_pdi
->die_parent
;
4717 if (parent
->scope_set
)
4718 return parent
->scope
;
4720 fixup_partial_die (parent
, cu
);
4722 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4724 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4725 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4726 Work around this problem here. */
4727 if (cu
->language
== language_cplus
4728 && parent
->tag
== DW_TAG_namespace
4729 && strcmp (parent
->name
, "::") == 0
4730 && grandparent_scope
== NULL
)
4732 parent
->scope
= NULL
;
4733 parent
->scope_set
= 1;
4737 if (pdi
->tag
== DW_TAG_enumerator
)
4738 /* Enumerators should not get the name of the enumeration as a prefix. */
4739 parent
->scope
= grandparent_scope
;
4740 else if (parent
->tag
== DW_TAG_namespace
4741 || parent
->tag
== DW_TAG_module
4742 || parent
->tag
== DW_TAG_structure_type
4743 || parent
->tag
== DW_TAG_class_type
4744 || parent
->tag
== DW_TAG_interface_type
4745 || parent
->tag
== DW_TAG_union_type
4746 || parent
->tag
== DW_TAG_enumeration_type
)
4748 if (grandparent_scope
== NULL
)
4749 parent
->scope
= parent
->name
;
4751 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4753 parent
->name
, 0, cu
);
4757 /* FIXME drow/2004-04-01: What should we be doing with
4758 function-local names? For partial symbols, we should probably be
4760 complaint (&symfile_complaints
,
4761 _("unhandled containing DIE tag %d for DIE at %d"),
4762 parent
->tag
, pdi
->offset
.sect_off
);
4763 parent
->scope
= grandparent_scope
;
4766 parent
->scope_set
= 1;
4767 return parent
->scope
;
4770 /* Return the fully scoped name associated with PDI, from compilation unit
4771 CU. The result will be allocated with malloc. */
4774 partial_die_full_name (struct partial_die_info
*pdi
,
4775 struct dwarf2_cu
*cu
)
4779 /* If this is a template instantiation, we can not work out the
4780 template arguments from partial DIEs. So, unfortunately, we have
4781 to go through the full DIEs. At least any work we do building
4782 types here will be reused if full symbols are loaded later. */
4783 if (pdi
->has_template_arguments
)
4785 fixup_partial_die (pdi
, cu
);
4787 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4789 struct die_info
*die
;
4790 struct attribute attr
;
4791 struct dwarf2_cu
*ref_cu
= cu
;
4793 /* DW_FORM_ref_addr is using section offset. */
4795 attr
.form
= DW_FORM_ref_addr
;
4796 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4797 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4799 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4803 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4804 if (parent_scope
== NULL
)
4807 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4811 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4813 struct objfile
*objfile
= cu
->objfile
;
4815 char *actual_name
= NULL
;
4817 int built_actual_name
= 0;
4819 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4821 actual_name
= partial_die_full_name (pdi
, cu
);
4823 built_actual_name
= 1;
4825 if (actual_name
== NULL
)
4826 actual_name
= pdi
->name
;
4830 case DW_TAG_subprogram
:
4831 if (pdi
->is_external
|| cu
->language
== language_ada
)
4833 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4834 of the global scope. But in Ada, we want to be able to access
4835 nested procedures globally. So all Ada subprograms are stored
4836 in the global scope. */
4837 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4838 mst_text, objfile); */
4839 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4841 VAR_DOMAIN
, LOC_BLOCK
,
4842 &objfile
->global_psymbols
,
4843 0, pdi
->lowpc
+ baseaddr
,
4844 cu
->language
, objfile
);
4848 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4849 mst_file_text, objfile); */
4850 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4852 VAR_DOMAIN
, LOC_BLOCK
,
4853 &objfile
->static_psymbols
,
4854 0, pdi
->lowpc
+ baseaddr
,
4855 cu
->language
, objfile
);
4858 case DW_TAG_constant
:
4860 struct psymbol_allocation_list
*list
;
4862 if (pdi
->is_external
)
4863 list
= &objfile
->global_psymbols
;
4865 list
= &objfile
->static_psymbols
;
4866 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4867 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4868 list
, 0, 0, cu
->language
, objfile
);
4871 case DW_TAG_variable
:
4873 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4877 && !dwarf2_per_objfile
->has_section_at_zero
)
4879 /* A global or static variable may also have been stripped
4880 out by the linker if unused, in which case its address
4881 will be nullified; do not add such variables into partial
4882 symbol table then. */
4884 else if (pdi
->is_external
)
4887 Don't enter into the minimal symbol tables as there is
4888 a minimal symbol table entry from the ELF symbols already.
4889 Enter into partial symbol table if it has a location
4890 descriptor or a type.
4891 If the location descriptor is missing, new_symbol will create
4892 a LOC_UNRESOLVED symbol, the address of the variable will then
4893 be determined from the minimal symbol table whenever the variable
4895 The address for the partial symbol table entry is not
4896 used by GDB, but it comes in handy for debugging partial symbol
4899 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4900 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4902 VAR_DOMAIN
, LOC_STATIC
,
4903 &objfile
->global_psymbols
,
4905 cu
->language
, objfile
);
4909 /* Static Variable. Skip symbols without location descriptors. */
4910 if (pdi
->d
.locdesc
== NULL
)
4912 if (built_actual_name
)
4913 xfree (actual_name
);
4916 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4917 mst_file_data, objfile); */
4918 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4920 VAR_DOMAIN
, LOC_STATIC
,
4921 &objfile
->static_psymbols
,
4923 cu
->language
, objfile
);
4926 case DW_TAG_typedef
:
4927 case DW_TAG_base_type
:
4928 case DW_TAG_subrange_type
:
4929 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4931 VAR_DOMAIN
, LOC_TYPEDEF
,
4932 &objfile
->static_psymbols
,
4933 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4935 case DW_TAG_namespace
:
4936 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4938 VAR_DOMAIN
, LOC_TYPEDEF
,
4939 &objfile
->global_psymbols
,
4940 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4942 case DW_TAG_class_type
:
4943 case DW_TAG_interface_type
:
4944 case DW_TAG_structure_type
:
4945 case DW_TAG_union_type
:
4946 case DW_TAG_enumeration_type
:
4947 /* Skip external references. The DWARF standard says in the section
4948 about "Structure, Union, and Class Type Entries": "An incomplete
4949 structure, union or class type is represented by a structure,
4950 union or class entry that does not have a byte size attribute
4951 and that has a DW_AT_declaration attribute." */
4952 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4954 if (built_actual_name
)
4955 xfree (actual_name
);
4959 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4960 static vs. global. */
4961 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4963 STRUCT_DOMAIN
, LOC_TYPEDEF
,
4964 (cu
->language
== language_cplus
4965 || cu
->language
== language_java
)
4966 ? &objfile
->global_psymbols
4967 : &objfile
->static_psymbols
,
4968 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4971 case DW_TAG_enumerator
:
4972 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4974 VAR_DOMAIN
, LOC_CONST
,
4975 (cu
->language
== language_cplus
4976 || cu
->language
== language_java
)
4977 ? &objfile
->global_psymbols
4978 : &objfile
->static_psymbols
,
4979 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4985 if (built_actual_name
)
4986 xfree (actual_name
);
4989 /* Read a partial die corresponding to a namespace; also, add a symbol
4990 corresponding to that namespace to the symbol table. NAMESPACE is
4991 the name of the enclosing namespace. */
4994 add_partial_namespace (struct partial_die_info
*pdi
,
4995 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4996 int need_pc
, struct dwarf2_cu
*cu
)
4998 /* Add a symbol for the namespace. */
5000 add_partial_symbol (pdi
, cu
);
5002 /* Now scan partial symbols in that namespace. */
5004 if (pdi
->has_children
)
5005 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5008 /* Read a partial die corresponding to a Fortran module. */
5011 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5012 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5014 /* Now scan partial symbols in that module. */
5016 if (pdi
->has_children
)
5017 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5020 /* Read a partial die corresponding to a subprogram and create a partial
5021 symbol for that subprogram. When the CU language allows it, this
5022 routine also defines a partial symbol for each nested subprogram
5023 that this subprogram contains.
5025 DIE my also be a lexical block, in which case we simply search
5026 recursively for suprograms defined inside that lexical block.
5027 Again, this is only performed when the CU language allows this
5028 type of definitions. */
5031 add_partial_subprogram (struct partial_die_info
*pdi
,
5032 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5033 int need_pc
, struct dwarf2_cu
*cu
)
5035 if (pdi
->tag
== DW_TAG_subprogram
)
5037 if (pdi
->has_pc_info
)
5039 if (pdi
->lowpc
< *lowpc
)
5040 *lowpc
= pdi
->lowpc
;
5041 if (pdi
->highpc
> *highpc
)
5042 *highpc
= pdi
->highpc
;
5046 struct objfile
*objfile
= cu
->objfile
;
5048 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5049 SECT_OFF_TEXT (objfile
));
5050 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5051 pdi
->lowpc
+ baseaddr
,
5052 pdi
->highpc
- 1 + baseaddr
,
5053 cu
->per_cu
->v
.psymtab
);
5057 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5059 if (!pdi
->is_declaration
)
5060 /* Ignore subprogram DIEs that do not have a name, they are
5061 illegal. Do not emit a complaint at this point, we will
5062 do so when we convert this psymtab into a symtab. */
5064 add_partial_symbol (pdi
, cu
);
5068 if (! pdi
->has_children
)
5071 if (cu
->language
== language_ada
)
5073 pdi
= pdi
->die_child
;
5076 fixup_partial_die (pdi
, cu
);
5077 if (pdi
->tag
== DW_TAG_subprogram
5078 || pdi
->tag
== DW_TAG_lexical_block
)
5079 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5080 pdi
= pdi
->die_sibling
;
5085 /* Read a partial die corresponding to an enumeration type. */
5088 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5089 struct dwarf2_cu
*cu
)
5091 struct partial_die_info
*pdi
;
5093 if (enum_pdi
->name
!= NULL
)
5094 add_partial_symbol (enum_pdi
, cu
);
5096 pdi
= enum_pdi
->die_child
;
5099 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5100 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5102 add_partial_symbol (pdi
, cu
);
5103 pdi
= pdi
->die_sibling
;
5107 /* Return the initial uleb128 in the die at INFO_PTR. */
5110 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5112 unsigned int bytes_read
;
5114 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5117 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5118 Return the corresponding abbrev, or NULL if the number is zero (indicating
5119 an empty DIE). In either case *BYTES_READ will be set to the length of
5120 the initial number. */
5122 static struct abbrev_info
*
5123 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5124 struct dwarf2_cu
*cu
)
5126 bfd
*abfd
= cu
->objfile
->obfd
;
5127 unsigned int abbrev_number
;
5128 struct abbrev_info
*abbrev
;
5130 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5132 if (abbrev_number
== 0)
5135 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5138 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5139 abbrev_number
, bfd_get_filename (abfd
));
5145 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5146 Returns a pointer to the end of a series of DIEs, terminated by an empty
5147 DIE. Any children of the skipped DIEs will also be skipped. */
5150 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5152 struct dwarf2_cu
*cu
= reader
->cu
;
5153 struct abbrev_info
*abbrev
;
5154 unsigned int bytes_read
;
5158 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5160 return info_ptr
+ bytes_read
;
5162 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5166 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5167 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5168 abbrev corresponding to that skipped uleb128 should be passed in
5169 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5173 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5174 struct abbrev_info
*abbrev
)
5176 unsigned int bytes_read
;
5177 struct attribute attr
;
5178 bfd
*abfd
= reader
->abfd
;
5179 struct dwarf2_cu
*cu
= reader
->cu
;
5180 gdb_byte
*buffer
= reader
->buffer
;
5181 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5182 gdb_byte
*start_info_ptr
= info_ptr
;
5183 unsigned int form
, i
;
5185 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5187 /* The only abbrev we care about is DW_AT_sibling. */
5188 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5190 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5191 if (attr
.form
== DW_FORM_ref_addr
)
5192 complaint (&symfile_complaints
,
5193 _("ignoring absolute DW_AT_sibling"));
5195 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5198 /* If it isn't DW_AT_sibling, skip this attribute. */
5199 form
= abbrev
->attrs
[i
].form
;
5203 case DW_FORM_ref_addr
:
5204 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5205 and later it is offset sized. */
5206 if (cu
->header
.version
== 2)
5207 info_ptr
+= cu
->header
.addr_size
;
5209 info_ptr
+= cu
->header
.offset_size
;
5212 info_ptr
+= cu
->header
.addr_size
;
5219 case DW_FORM_flag_present
:
5231 case DW_FORM_ref_sig8
:
5234 case DW_FORM_string
:
5235 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5236 info_ptr
+= bytes_read
;
5238 case DW_FORM_sec_offset
:
5240 info_ptr
+= cu
->header
.offset_size
;
5242 case DW_FORM_exprloc
:
5244 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5245 info_ptr
+= bytes_read
;
5247 case DW_FORM_block1
:
5248 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5250 case DW_FORM_block2
:
5251 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5253 case DW_FORM_block4
:
5254 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5258 case DW_FORM_ref_udata
:
5259 case DW_FORM_GNU_addr_index
:
5260 case DW_FORM_GNU_str_index
:
5261 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5263 case DW_FORM_indirect
:
5264 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5265 info_ptr
+= bytes_read
;
5266 /* We need to continue parsing from here, so just go back to
5268 goto skip_attribute
;
5271 error (_("Dwarf Error: Cannot handle %s "
5272 "in DWARF reader [in module %s]"),
5273 dwarf_form_name (form
),
5274 bfd_get_filename (abfd
));
5278 if (abbrev
->has_children
)
5279 return skip_children (reader
, info_ptr
);
5284 /* Locate ORIG_PDI's sibling.
5285 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5288 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5289 struct partial_die_info
*orig_pdi
,
5292 /* Do we know the sibling already? */
5294 if (orig_pdi
->sibling
)
5295 return orig_pdi
->sibling
;
5297 /* Are there any children to deal with? */
5299 if (!orig_pdi
->has_children
)
5302 /* Skip the children the long way. */
5304 return skip_children (reader
, info_ptr
);
5307 /* Expand this partial symbol table into a full symbol table. */
5310 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5316 warning (_("bug: psymtab for %s is already read in."),
5323 printf_filtered (_("Reading in symbols for %s..."),
5325 gdb_flush (gdb_stdout
);
5328 /* Restore our global data. */
5329 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5330 dwarf2_objfile_data_key
);
5332 /* If this psymtab is constructed from a debug-only objfile, the
5333 has_section_at_zero flag will not necessarily be correct. We
5334 can get the correct value for this flag by looking at the data
5335 associated with the (presumably stripped) associated objfile. */
5336 if (pst
->objfile
->separate_debug_objfile_backlink
)
5338 struct dwarf2_per_objfile
*dpo_backlink
5339 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5340 dwarf2_objfile_data_key
);
5342 dwarf2_per_objfile
->has_section_at_zero
5343 = dpo_backlink
->has_section_at_zero
;
5346 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5348 psymtab_to_symtab_1 (pst
);
5350 /* Finish up the debug error message. */
5352 printf_filtered (_("done.\n"));
5356 process_cu_includes ();
5359 /* Reading in full CUs. */
5361 /* Add PER_CU to the queue. */
5364 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5365 enum language pretend_language
)
5367 struct dwarf2_queue_item
*item
;
5370 item
= xmalloc (sizeof (*item
));
5371 item
->per_cu
= per_cu
;
5372 item
->pretend_language
= pretend_language
;
5375 if (dwarf2_queue
== NULL
)
5376 dwarf2_queue
= item
;
5378 dwarf2_queue_tail
->next
= item
;
5380 dwarf2_queue_tail
= item
;
5383 /* Process the queue. */
5386 process_queue (void)
5388 struct dwarf2_queue_item
*item
, *next_item
;
5390 /* The queue starts out with one item, but following a DIE reference
5391 may load a new CU, adding it to the end of the queue. */
5392 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5394 if (dwarf2_per_objfile
->using_index
5395 ? !item
->per_cu
->v
.quick
->symtab
5396 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5397 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5399 item
->per_cu
->queued
= 0;
5400 next_item
= item
->next
;
5404 dwarf2_queue_tail
= NULL
;
5407 /* Free all allocated queue entries. This function only releases anything if
5408 an error was thrown; if the queue was processed then it would have been
5409 freed as we went along. */
5412 dwarf2_release_queue (void *dummy
)
5414 struct dwarf2_queue_item
*item
, *last
;
5416 item
= dwarf2_queue
;
5419 /* Anything still marked queued is likely to be in an
5420 inconsistent state, so discard it. */
5421 if (item
->per_cu
->queued
)
5423 if (item
->per_cu
->cu
!= NULL
)
5424 free_one_cached_comp_unit (item
->per_cu
);
5425 item
->per_cu
->queued
= 0;
5433 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5436 /* Read in full symbols for PST, and anything it depends on. */
5439 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5441 struct dwarf2_per_cu_data
*per_cu
;
5447 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5448 if (!pst
->dependencies
[i
]->readin
5449 && pst
->dependencies
[i
]->user
== NULL
)
5451 /* Inform about additional files that need to be read in. */
5454 /* FIXME: i18n: Need to make this a single string. */
5455 fputs_filtered (" ", gdb_stdout
);
5457 fputs_filtered ("and ", gdb_stdout
);
5459 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5460 wrap_here (""); /* Flush output. */
5461 gdb_flush (gdb_stdout
);
5463 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5466 per_cu
= pst
->read_symtab_private
;
5470 /* It's an include file, no symbols to read for it.
5471 Everything is in the parent symtab. */
5476 dw2_do_instantiate_symtab (per_cu
);
5479 /* Trivial hash function for die_info: the hash value of a DIE
5480 is its offset in .debug_info for this objfile. */
5483 die_hash (const void *item
)
5485 const struct die_info
*die
= item
;
5487 return die
->offset
.sect_off
;
5490 /* Trivial comparison function for die_info structures: two DIEs
5491 are equal if they have the same offset. */
5494 die_eq (const void *item_lhs
, const void *item_rhs
)
5496 const struct die_info
*die_lhs
= item_lhs
;
5497 const struct die_info
*die_rhs
= item_rhs
;
5499 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5502 /* die_reader_func for load_full_comp_unit.
5503 This is identical to read_signatured_type_reader,
5504 but is kept separate for now. */
5507 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5509 struct die_info
*comp_unit_die
,
5513 struct dwarf2_cu
*cu
= reader
->cu
;
5514 enum language
*language_ptr
= data
;
5516 gdb_assert (cu
->die_hash
== NULL
);
5518 htab_create_alloc_ex (cu
->header
.length
/ 12,
5522 &cu
->comp_unit_obstack
,
5523 hashtab_obstack_allocate
,
5524 dummy_obstack_deallocate
);
5527 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5528 &info_ptr
, comp_unit_die
);
5529 cu
->dies
= comp_unit_die
;
5530 /* comp_unit_die is not stored in die_hash, no need. */
5532 /* We try not to read any attributes in this function, because not
5533 all CUs needed for references have been loaded yet, and symbol
5534 table processing isn't initialized. But we have to set the CU language,
5535 or we won't be able to build types correctly.
5536 Similarly, if we do not read the producer, we can not apply
5537 producer-specific interpretation. */
5538 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5541 /* Load the DIEs associated with PER_CU into memory. */
5544 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5545 enum language pretend_language
)
5547 gdb_assert (! this_cu
->is_debug_types
);
5549 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5553 /* Add a DIE to the delayed physname list. */
5556 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5557 const char *name
, struct die_info
*die
,
5558 struct dwarf2_cu
*cu
)
5560 struct delayed_method_info mi
;
5562 mi
.fnfield_index
= fnfield_index
;
5566 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5569 /* A cleanup for freeing the delayed method list. */
5572 free_delayed_list (void *ptr
)
5574 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5575 if (cu
->method_list
!= NULL
)
5577 VEC_free (delayed_method_info
, cu
->method_list
);
5578 cu
->method_list
= NULL
;
5582 /* Compute the physnames of any methods on the CU's method list.
5584 The computation of method physnames is delayed in order to avoid the
5585 (bad) condition that one of the method's formal parameters is of an as yet
5589 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5592 struct delayed_method_info
*mi
;
5593 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5595 const char *physname
;
5596 struct fn_fieldlist
*fn_flp
5597 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5598 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5599 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5603 /* Go objects should be embedded in a DW_TAG_module DIE,
5604 and it's not clear if/how imported objects will appear.
5605 To keep Go support simple until that's worked out,
5606 go back through what we've read and create something usable.
5607 We could do this while processing each DIE, and feels kinda cleaner,
5608 but that way is more invasive.
5609 This is to, for example, allow the user to type "p var" or "b main"
5610 without having to specify the package name, and allow lookups
5611 of module.object to work in contexts that use the expression
5615 fixup_go_packaging (struct dwarf2_cu
*cu
)
5617 char *package_name
= NULL
;
5618 struct pending
*list
;
5621 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5623 for (i
= 0; i
< list
->nsyms
; ++i
)
5625 struct symbol
*sym
= list
->symbol
[i
];
5627 if (SYMBOL_LANGUAGE (sym
) == language_go
5628 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5630 char *this_package_name
= go_symbol_package_name (sym
);
5632 if (this_package_name
== NULL
)
5634 if (package_name
== NULL
)
5635 package_name
= this_package_name
;
5638 if (strcmp (package_name
, this_package_name
) != 0)
5639 complaint (&symfile_complaints
,
5640 _("Symtab %s has objects from two different Go packages: %s and %s"),
5641 (sym
->symtab
&& sym
->symtab
->filename
5642 ? sym
->symtab
->filename
5643 : cu
->objfile
->name
),
5644 this_package_name
, package_name
);
5645 xfree (this_package_name
);
5651 if (package_name
!= NULL
)
5653 struct objfile
*objfile
= cu
->objfile
;
5654 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5655 package_name
, objfile
);
5658 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5660 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5661 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5662 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5663 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5664 e.g., "main" finds the "main" module and not C's main(). */
5665 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5666 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5667 SYMBOL_TYPE (sym
) = type
;
5669 add_symbol_to_list (sym
, &global_symbols
);
5671 xfree (package_name
);
5675 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5677 /* Return the symtab for PER_CU. This works properly regardless of
5678 whether we're using the index or psymtabs. */
5680 static struct symtab
*
5681 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5683 return (dwarf2_per_objfile
->using_index
5684 ? per_cu
->v
.quick
->symtab
5685 : per_cu
->v
.psymtab
->symtab
);
5688 /* A helper function for computing the list of all symbol tables
5689 included by PER_CU. */
5692 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5693 htab_t all_children
,
5694 struct dwarf2_per_cu_data
*per_cu
)
5698 struct dwarf2_per_cu_data
*iter
;
5700 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5703 /* This inclusion and its children have been processed. */
5708 /* Only add a CU if it has a symbol table. */
5709 if (get_symtab (per_cu
) != NULL
)
5710 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5713 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5715 recursively_compute_inclusions (result
, all_children
, iter
);
5718 /* Compute the symtab 'includes' fields for the symtab related to
5722 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5724 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5727 struct dwarf2_per_cu_data
*iter
;
5728 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5729 htab_t all_children
;
5730 struct symtab
*symtab
= get_symtab (per_cu
);
5732 /* If we don't have a symtab, we can just skip this case. */
5736 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5737 NULL
, xcalloc
, xfree
);
5740 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5743 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5745 /* Now we have a transitive closure of all the included CUs, so
5746 we can convert it to a list of symtabs. */
5747 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5749 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5750 (len
+ 1) * sizeof (struct symtab
*));
5752 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5754 symtab
->includes
[ix
] = get_symtab (iter
);
5755 symtab
->includes
[len
] = NULL
;
5757 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5758 htab_delete (all_children
);
5762 /* Compute the 'includes' field for the symtabs of all the CUs we just
5766 process_cu_includes (void)
5769 struct dwarf2_per_cu_data
*iter
;
5772 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5775 compute_symtab_includes (iter
);
5777 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5780 /* Generate full symbol information for PER_CU, whose DIEs have
5781 already been loaded into memory. */
5784 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5785 enum language pretend_language
)
5787 struct dwarf2_cu
*cu
= per_cu
->cu
;
5788 struct objfile
*objfile
= per_cu
->objfile
;
5789 CORE_ADDR lowpc
, highpc
;
5790 struct symtab
*symtab
;
5791 struct cleanup
*back_to
, *delayed_list_cleanup
;
5794 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5797 back_to
= make_cleanup (really_free_pendings
, NULL
);
5798 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5800 cu
->list_in_scope
= &file_symbols
;
5802 cu
->language
= pretend_language
;
5803 cu
->language_defn
= language_def (cu
->language
);
5805 /* Do line number decoding in read_file_scope () */
5806 process_die (cu
->dies
, cu
);
5808 /* For now fudge the Go package. */
5809 if (cu
->language
== language_go
)
5810 fixup_go_packaging (cu
);
5812 /* Now that we have processed all the DIEs in the CU, all the types
5813 should be complete, and it should now be safe to compute all of the
5815 compute_delayed_physnames (cu
);
5816 do_cleanups (delayed_list_cleanup
);
5818 /* Some compilers don't define a DW_AT_high_pc attribute for the
5819 compilation unit. If the DW_AT_high_pc is missing, synthesize
5820 it, by scanning the DIE's below the compilation unit. */
5821 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5823 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5827 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5829 /* Set symtab language to language from DW_AT_language. If the
5830 compilation is from a C file generated by language preprocessors, do
5831 not set the language if it was already deduced by start_subfile. */
5832 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5833 symtab
->language
= cu
->language
;
5835 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5836 produce DW_AT_location with location lists but it can be possibly
5837 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5838 there were bugs in prologue debug info, fixed later in GCC-4.5
5839 by "unwind info for epilogues" patch (which is not directly related).
5841 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5842 needed, it would be wrong due to missing DW_AT_producer there.
5844 Still one can confuse GDB by using non-standard GCC compilation
5845 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5847 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5848 symtab
->locations_valid
= 1;
5850 if (gcc_4_minor
>= 5)
5851 symtab
->epilogue_unwind_valid
= 1;
5853 symtab
->call_site_htab
= cu
->call_site_htab
;
5856 if (dwarf2_per_objfile
->using_index
)
5857 per_cu
->v
.quick
->symtab
= symtab
;
5860 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5861 pst
->symtab
= symtab
;
5865 /* Push it for inclusion processing later. */
5866 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5868 do_cleanups (back_to
);
5871 /* Process an imported unit DIE. */
5874 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5876 struct attribute
*attr
;
5878 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5881 struct dwarf2_per_cu_data
*per_cu
;
5882 struct symtab
*imported_symtab
;
5885 offset
= dwarf2_get_ref_die_offset (attr
);
5886 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5888 /* Queue the unit, if needed. */
5889 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5890 load_full_comp_unit (per_cu
, cu
->language
);
5892 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5897 /* Process a die and its children. */
5900 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5904 case DW_TAG_padding
:
5906 case DW_TAG_compile_unit
:
5907 case DW_TAG_partial_unit
:
5908 read_file_scope (die
, cu
);
5910 case DW_TAG_type_unit
:
5911 read_type_unit_scope (die
, cu
);
5913 case DW_TAG_subprogram
:
5914 case DW_TAG_inlined_subroutine
:
5915 read_func_scope (die
, cu
);
5917 case DW_TAG_lexical_block
:
5918 case DW_TAG_try_block
:
5919 case DW_TAG_catch_block
:
5920 read_lexical_block_scope (die
, cu
);
5922 case DW_TAG_GNU_call_site
:
5923 read_call_site_scope (die
, cu
);
5925 case DW_TAG_class_type
:
5926 case DW_TAG_interface_type
:
5927 case DW_TAG_structure_type
:
5928 case DW_TAG_union_type
:
5929 process_structure_scope (die
, cu
);
5931 case DW_TAG_enumeration_type
:
5932 process_enumeration_scope (die
, cu
);
5935 /* These dies have a type, but processing them does not create
5936 a symbol or recurse to process the children. Therefore we can
5937 read them on-demand through read_type_die. */
5938 case DW_TAG_subroutine_type
:
5939 case DW_TAG_set_type
:
5940 case DW_TAG_array_type
:
5941 case DW_TAG_pointer_type
:
5942 case DW_TAG_ptr_to_member_type
:
5943 case DW_TAG_reference_type
:
5944 case DW_TAG_string_type
:
5947 case DW_TAG_base_type
:
5948 case DW_TAG_subrange_type
:
5949 case DW_TAG_typedef
:
5950 /* Add a typedef symbol for the type definition, if it has a
5952 new_symbol (die
, read_type_die (die
, cu
), cu
);
5954 case DW_TAG_common_block
:
5955 read_common_block (die
, cu
);
5957 case DW_TAG_common_inclusion
:
5959 case DW_TAG_namespace
:
5960 processing_has_namespace_info
= 1;
5961 read_namespace (die
, cu
);
5964 processing_has_namespace_info
= 1;
5965 read_module (die
, cu
);
5967 case DW_TAG_imported_declaration
:
5968 case DW_TAG_imported_module
:
5969 processing_has_namespace_info
= 1;
5970 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
5971 || cu
->language
!= language_fortran
))
5972 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
5973 dwarf_tag_name (die
->tag
));
5974 read_import_statement (die
, cu
);
5977 case DW_TAG_imported_unit
:
5978 process_imported_unit_die (die
, cu
);
5982 new_symbol (die
, NULL
, cu
);
5987 /* A helper function for dwarf2_compute_name which determines whether DIE
5988 needs to have the name of the scope prepended to the name listed in the
5992 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5994 struct attribute
*attr
;
5998 case DW_TAG_namespace
:
5999 case DW_TAG_typedef
:
6000 case DW_TAG_class_type
:
6001 case DW_TAG_interface_type
:
6002 case DW_TAG_structure_type
:
6003 case DW_TAG_union_type
:
6004 case DW_TAG_enumeration_type
:
6005 case DW_TAG_enumerator
:
6006 case DW_TAG_subprogram
:
6010 case DW_TAG_variable
:
6011 case DW_TAG_constant
:
6012 /* We only need to prefix "globally" visible variables. These include
6013 any variable marked with DW_AT_external or any variable that
6014 lives in a namespace. [Variables in anonymous namespaces
6015 require prefixing, but they are not DW_AT_external.] */
6017 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6019 struct dwarf2_cu
*spec_cu
= cu
;
6021 return die_needs_namespace (die_specification (die
, &spec_cu
),
6025 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6026 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6027 && die
->parent
->tag
!= DW_TAG_module
)
6029 /* A variable in a lexical block of some kind does not need a
6030 namespace, even though in C++ such variables may be external
6031 and have a mangled name. */
6032 if (die
->parent
->tag
== DW_TAG_lexical_block
6033 || die
->parent
->tag
== DW_TAG_try_block
6034 || die
->parent
->tag
== DW_TAG_catch_block
6035 || die
->parent
->tag
== DW_TAG_subprogram
)
6044 /* Retrieve the last character from a mem_file. */
6047 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6049 char *last_char_p
= (char *) object
;
6052 *last_char_p
= buffer
[length
- 1];
6055 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6056 compute the physname for the object, which include a method's:
6057 - formal parameters (C++/Java),
6058 - receiver type (Go),
6059 - return type (Java).
6061 The term "physname" is a bit confusing.
6062 For C++, for example, it is the demangled name.
6063 For Go, for example, it's the mangled name.
6065 For Ada, return the DIE's linkage name rather than the fully qualified
6066 name. PHYSNAME is ignored..
6068 The result is allocated on the objfile_obstack and canonicalized. */
6071 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6074 struct objfile
*objfile
= cu
->objfile
;
6077 name
= dwarf2_name (die
, cu
);
6079 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6080 compute it by typename_concat inside GDB. */
6081 if (cu
->language
== language_ada
6082 || (cu
->language
== language_fortran
&& physname
))
6084 /* For Ada unit, we prefer the linkage name over the name, as
6085 the former contains the exported name, which the user expects
6086 to be able to reference. Ideally, we want the user to be able
6087 to reference this entity using either natural or linkage name,
6088 but we haven't started looking at this enhancement yet. */
6089 struct attribute
*attr
;
6091 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6093 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6094 if (attr
&& DW_STRING (attr
))
6095 return DW_STRING (attr
);
6098 /* These are the only languages we know how to qualify names in. */
6100 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6101 || cu
->language
== language_fortran
))
6103 if (die_needs_namespace (die
, cu
))
6107 struct ui_file
*buf
;
6109 prefix
= determine_prefix (die
, cu
);
6110 buf
= mem_fileopen ();
6111 if (*prefix
!= '\0')
6113 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
6116 fputs_unfiltered (prefixed_name
, buf
);
6117 xfree (prefixed_name
);
6120 fputs_unfiltered (name
, buf
);
6122 /* Template parameters may be specified in the DIE's DW_AT_name, or
6123 as children with DW_TAG_template_type_param or
6124 DW_TAG_value_type_param. If the latter, add them to the name
6125 here. If the name already has template parameters, then
6126 skip this step; some versions of GCC emit both, and
6127 it is more efficient to use the pre-computed name.
6129 Something to keep in mind about this process: it is very
6130 unlikely, or in some cases downright impossible, to produce
6131 something that will match the mangled name of a function.
6132 If the definition of the function has the same debug info,
6133 we should be able to match up with it anyway. But fallbacks
6134 using the minimal symbol, for instance to find a method
6135 implemented in a stripped copy of libstdc++, will not work.
6136 If we do not have debug info for the definition, we will have to
6137 match them up some other way.
6139 When we do name matching there is a related problem with function
6140 templates; two instantiated function templates are allowed to
6141 differ only by their return types, which we do not add here. */
6143 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6145 struct attribute
*attr
;
6146 struct die_info
*child
;
6149 die
->building_fullname
= 1;
6151 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6156 struct dwarf2_locexpr_baton
*baton
;
6159 if (child
->tag
!= DW_TAG_template_type_param
6160 && child
->tag
!= DW_TAG_template_value_param
)
6165 fputs_unfiltered ("<", buf
);
6169 fputs_unfiltered (", ", buf
);
6171 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6174 complaint (&symfile_complaints
,
6175 _("template parameter missing DW_AT_type"));
6176 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6179 type
= die_type (child
, cu
);
6181 if (child
->tag
== DW_TAG_template_type_param
)
6183 c_print_type (type
, "", buf
, -1, 0);
6187 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6190 complaint (&symfile_complaints
,
6191 _("template parameter missing "
6192 "DW_AT_const_value"));
6193 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6197 dwarf2_const_value_attr (attr
, type
, name
,
6198 &cu
->comp_unit_obstack
, cu
,
6199 &value
, &bytes
, &baton
);
6201 if (TYPE_NOSIGN (type
))
6202 /* GDB prints characters as NUMBER 'CHAR'. If that's
6203 changed, this can use value_print instead. */
6204 c_printchar (value
, type
, buf
);
6207 struct value_print_options opts
;
6210 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6214 else if (bytes
!= NULL
)
6216 v
= allocate_value (type
);
6217 memcpy (value_contents_writeable (v
), bytes
,
6218 TYPE_LENGTH (type
));
6221 v
= value_from_longest (type
, value
);
6223 /* Specify decimal so that we do not depend on
6225 get_formatted_print_options (&opts
, 'd');
6227 value_print (v
, buf
, &opts
);
6233 die
->building_fullname
= 0;
6237 /* Close the argument list, with a space if necessary
6238 (nested templates). */
6239 char last_char
= '\0';
6240 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6241 if (last_char
== '>')
6242 fputs_unfiltered (" >", buf
);
6244 fputs_unfiltered (">", buf
);
6248 /* For Java and C++ methods, append formal parameter type
6249 information, if PHYSNAME. */
6251 if (physname
&& die
->tag
== DW_TAG_subprogram
6252 && (cu
->language
== language_cplus
6253 || cu
->language
== language_java
))
6255 struct type
*type
= read_type_die (die
, cu
);
6257 c_type_print_args (type
, buf
, 1, cu
->language
);
6259 if (cu
->language
== language_java
)
6261 /* For java, we must append the return type to method
6263 if (die
->tag
== DW_TAG_subprogram
)
6264 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6267 else if (cu
->language
== language_cplus
)
6269 /* Assume that an artificial first parameter is
6270 "this", but do not crash if it is not. RealView
6271 marks unnamed (and thus unused) parameters as
6272 artificial; there is no way to differentiate
6274 if (TYPE_NFIELDS (type
) > 0
6275 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6276 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6277 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6279 fputs_unfiltered (" const", buf
);
6283 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6285 ui_file_delete (buf
);
6287 if (cu
->language
== language_cplus
)
6290 = dwarf2_canonicalize_name (name
, cu
,
6291 &objfile
->objfile_obstack
);
6302 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6303 If scope qualifiers are appropriate they will be added. The result
6304 will be allocated on the objfile_obstack, or NULL if the DIE does
6305 not have a name. NAME may either be from a previous call to
6306 dwarf2_name or NULL.
6308 The output string will be canonicalized (if C++/Java). */
6311 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6313 return dwarf2_compute_name (name
, die
, cu
, 0);
6316 /* Construct a physname for the given DIE in CU. NAME may either be
6317 from a previous call to dwarf2_name or NULL. The result will be
6318 allocated on the objfile_objstack or NULL if the DIE does not have a
6321 The output string will be canonicalized (if C++/Java). */
6324 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6326 struct objfile
*objfile
= cu
->objfile
;
6327 struct attribute
*attr
;
6328 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6329 struct cleanup
*back_to
;
6332 /* In this case dwarf2_compute_name is just a shortcut not building anything
6334 if (!die_needs_namespace (die
, cu
))
6335 return dwarf2_compute_name (name
, die
, cu
, 1);
6337 back_to
= make_cleanup (null_cleanup
, NULL
);
6339 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6341 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6343 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6345 if (attr
&& DW_STRING (attr
))
6349 mangled
= DW_STRING (attr
);
6351 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6352 type. It is easier for GDB users to search for such functions as
6353 `name(params)' than `long name(params)'. In such case the minimal
6354 symbol names do not match the full symbol names but for template
6355 functions there is never a need to look up their definition from their
6356 declaration so the only disadvantage remains the minimal symbol
6357 variant `long name(params)' does not have the proper inferior type.
6360 if (cu
->language
== language_go
)
6362 /* This is a lie, but we already lie to the caller new_symbol_full.
6363 new_symbol_full assumes we return the mangled name.
6364 This just undoes that lie until things are cleaned up. */
6369 demangled
= cplus_demangle (mangled
,
6370 (DMGL_PARAMS
| DMGL_ANSI
6371 | (cu
->language
== language_java
6372 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6377 make_cleanup (xfree
, demangled
);
6387 if (canon
== NULL
|| check_physname
)
6389 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6391 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6393 /* It may not mean a bug in GDB. The compiler could also
6394 compute DW_AT_linkage_name incorrectly. But in such case
6395 GDB would need to be bug-to-bug compatible. */
6397 complaint (&symfile_complaints
,
6398 _("Computed physname <%s> does not match demangled <%s> "
6399 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6400 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6402 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6403 is available here - over computed PHYSNAME. It is safer
6404 against both buggy GDB and buggy compilers. */
6418 retval
= obsavestring (retval
, strlen (retval
),
6419 &objfile
->objfile_obstack
);
6421 do_cleanups (back_to
);
6425 /* Read the import statement specified by the given die and record it. */
6428 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6430 struct objfile
*objfile
= cu
->objfile
;
6431 struct attribute
*import_attr
;
6432 struct die_info
*imported_die
, *child_die
;
6433 struct dwarf2_cu
*imported_cu
;
6434 const char *imported_name
;
6435 const char *imported_name_prefix
;
6436 const char *canonical_name
;
6437 const char *import_alias
;
6438 const char *imported_declaration
= NULL
;
6439 const char *import_prefix
;
6440 VEC (const_char_ptr
) *excludes
= NULL
;
6441 struct cleanup
*cleanups
;
6445 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6446 if (import_attr
== NULL
)
6448 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6449 dwarf_tag_name (die
->tag
));
6454 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6455 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6456 if (imported_name
== NULL
)
6458 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6460 The import in the following code:
6474 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6475 <52> DW_AT_decl_file : 1
6476 <53> DW_AT_decl_line : 6
6477 <54> DW_AT_import : <0x75>
6478 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6480 <5b> DW_AT_decl_file : 1
6481 <5c> DW_AT_decl_line : 2
6482 <5d> DW_AT_type : <0x6e>
6484 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6485 <76> DW_AT_byte_size : 4
6486 <77> DW_AT_encoding : 5 (signed)
6488 imports the wrong die ( 0x75 instead of 0x58 ).
6489 This case will be ignored until the gcc bug is fixed. */
6493 /* Figure out the local name after import. */
6494 import_alias
= dwarf2_name (die
, cu
);
6496 /* Figure out where the statement is being imported to. */
6497 import_prefix
= determine_prefix (die
, cu
);
6499 /* Figure out what the scope of the imported die is and prepend it
6500 to the name of the imported die. */
6501 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6503 if (imported_die
->tag
!= DW_TAG_namespace
6504 && imported_die
->tag
!= DW_TAG_module
)
6506 imported_declaration
= imported_name
;
6507 canonical_name
= imported_name_prefix
;
6509 else if (strlen (imported_name_prefix
) > 0)
6511 temp
= alloca (strlen (imported_name_prefix
)
6512 + 2 + strlen (imported_name
) + 1);
6513 strcpy (temp
, imported_name_prefix
);
6514 strcat (temp
, "::");
6515 strcat (temp
, imported_name
);
6516 canonical_name
= temp
;
6519 canonical_name
= imported_name
;
6521 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6523 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6524 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6525 child_die
= sibling_die (child_die
))
6527 /* DWARF-4: A Fortran use statement with a “rename list” may be
6528 represented by an imported module entry with an import attribute
6529 referring to the module and owned entries corresponding to those
6530 entities that are renamed as part of being imported. */
6532 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6534 complaint (&symfile_complaints
,
6535 _("child DW_TAG_imported_declaration expected "
6536 "- DIE at 0x%x [in module %s]"),
6537 child_die
->offset
.sect_off
, objfile
->name
);
6541 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6542 if (import_attr
== NULL
)
6544 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6545 dwarf_tag_name (child_die
->tag
));
6550 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6552 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6553 if (imported_name
== NULL
)
6555 complaint (&symfile_complaints
,
6556 _("child DW_TAG_imported_declaration has unknown "
6557 "imported name - DIE at 0x%x [in module %s]"),
6558 child_die
->offset
.sect_off
, objfile
->name
);
6562 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6564 process_die (child_die
, cu
);
6567 cp_add_using_directive (import_prefix
,
6570 imported_declaration
,
6572 &objfile
->objfile_obstack
);
6574 do_cleanups (cleanups
);
6577 /* Cleanup function for read_file_scope. */
6580 free_cu_line_header (void *arg
)
6582 struct dwarf2_cu
*cu
= arg
;
6584 free_line_header (cu
->line_header
);
6585 cu
->line_header
= NULL
;
6589 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6590 char **name
, char **comp_dir
)
6592 struct attribute
*attr
;
6597 /* Find the filename. Do not use dwarf2_name here, since the filename
6598 is not a source language identifier. */
6599 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6602 *name
= DW_STRING (attr
);
6605 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6607 *comp_dir
= DW_STRING (attr
);
6608 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6610 *comp_dir
= ldirname (*name
);
6611 if (*comp_dir
!= NULL
)
6612 make_cleanup (xfree
, *comp_dir
);
6614 if (*comp_dir
!= NULL
)
6616 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6617 directory, get rid of it. */
6618 char *cp
= strchr (*comp_dir
, ':');
6620 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6625 *name
= "<unknown>";
6628 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6629 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6630 COMP_DIR is the compilation directory.
6631 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6634 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6635 const char *comp_dir
, int want_line_info
)
6637 struct attribute
*attr
;
6639 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6642 unsigned int line_offset
= DW_UNSND (attr
);
6643 struct line_header
*line_header
6644 = dwarf_decode_line_header (line_offset
, cu
);
6648 cu
->line_header
= line_header
;
6649 make_cleanup (free_cu_line_header
, cu
);
6650 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6655 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6658 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6661 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6662 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6663 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6664 struct attribute
*attr
;
6666 char *comp_dir
= NULL
;
6667 struct die_info
*child_die
;
6668 bfd
*abfd
= objfile
->obfd
;
6671 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6673 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6675 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6676 from finish_block. */
6677 if (lowpc
== ((CORE_ADDR
) -1))
6682 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6684 prepare_one_comp_unit (cu
, die
, cu
->language
);
6686 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6687 standardised yet. As a workaround for the language detection we fall
6688 back to the DW_AT_producer string. */
6689 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6690 cu
->language
= language_opencl
;
6692 /* Similar hack for Go. */
6693 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6694 set_cu_language (DW_LANG_Go
, cu
);
6696 /* We assume that we're processing GCC output. */
6697 processing_gcc_compilation
= 2;
6699 processing_has_namespace_info
= 0;
6701 start_symtab (name
, comp_dir
, lowpc
);
6702 record_debugformat ("DWARF 2");
6703 record_producer (cu
->producer
);
6705 /* Decode line number information if present. We do this before
6706 processing child DIEs, so that the line header table is available
6707 for DW_AT_decl_file. */
6708 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6710 /* Process all dies in compilation unit. */
6711 if (die
->child
!= NULL
)
6713 child_die
= die
->child
;
6714 while (child_die
&& child_die
->tag
)
6716 process_die (child_die
, cu
);
6717 child_die
= sibling_die (child_die
);
6721 /* Decode macro information, if present. Dwarf 2 macro information
6722 refers to information in the line number info statement program
6723 header, so we can only read it if we've read the header
6725 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6726 if (attr
&& cu
->line_header
)
6728 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6729 complaint (&symfile_complaints
,
6730 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6732 dwarf_decode_macros (cu
->line_header
, DW_UNSND (attr
),
6734 &dwarf2_per_objfile
->macro
, 1,
6739 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6740 if (attr
&& cu
->line_header
)
6742 unsigned int macro_offset
= DW_UNSND (attr
);
6744 dwarf_decode_macros (cu
->line_header
, macro_offset
,
6746 &dwarf2_per_objfile
->macinfo
, 0,
6751 do_cleanups (back_to
);
6754 /* Process DW_TAG_type_unit.
6755 For TUs we want to skip the first top level sibling if it's not the
6756 actual type being defined by this TU. In this case the first top
6757 level sibling is there to provide context only. */
6760 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6762 struct objfile
*objfile
= cu
->objfile
;
6763 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6765 struct attribute
*attr
;
6767 char *comp_dir
= NULL
;
6768 struct die_info
*child_die
;
6769 bfd
*abfd
= objfile
->obfd
;
6771 /* start_symtab needs a low pc, but we don't really have one.
6772 Do what read_file_scope would do in the absence of such info. */
6773 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6775 /* Find the filename. Do not use dwarf2_name here, since the filename
6776 is not a source language identifier. */
6777 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6779 name
= DW_STRING (attr
);
6781 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6783 comp_dir
= DW_STRING (attr
);
6784 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6786 comp_dir
= ldirname (name
);
6787 if (comp_dir
!= NULL
)
6788 make_cleanup (xfree
, comp_dir
);
6794 prepare_one_comp_unit (cu
, die
, language_minimal
);
6796 /* We assume that we're processing GCC output. */
6797 processing_gcc_compilation
= 2;
6799 processing_has_namespace_info
= 0;
6801 start_symtab (name
, comp_dir
, lowpc
);
6802 record_debugformat ("DWARF 2");
6803 record_producer (cu
->producer
);
6805 /* Decode line number information if present. We do this before
6806 processing child DIEs, so that the line header table is available
6807 for DW_AT_decl_file.
6808 We don't need the pc/line-number mapping for type units. */
6809 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6811 /* Process the dies in the type unit. */
6812 if (die
->child
== NULL
)
6814 dump_die_for_error (die
);
6815 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6816 bfd_get_filename (abfd
));
6819 child_die
= die
->child
;
6821 while (child_die
&& child_die
->tag
)
6823 process_die (child_die
, cu
);
6825 child_die
= sibling_die (child_die
);
6828 do_cleanups (back_to
);
6834 hash_dwo_file (const void *item
)
6836 const struct dwo_file
*dwo_file
= item
;
6838 return htab_hash_string (dwo_file
->dwo_name
);
6842 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6844 const struct dwo_file
*lhs
= item_lhs
;
6845 const struct dwo_file
*rhs
= item_rhs
;
6847 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6850 /* Allocate a hash table for DWO files. */
6853 allocate_dwo_file_hash_table (void)
6855 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6857 return htab_create_alloc_ex (41,
6861 &objfile
->objfile_obstack
,
6862 hashtab_obstack_allocate
,
6863 dummy_obstack_deallocate
);
6867 hash_dwo_unit (const void *item
)
6869 const struct dwo_unit
*dwo_unit
= item
;
6871 /* This drops the top 32 bits of the id, but is ok for a hash. */
6872 return dwo_unit
->signature
;
6876 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6878 const struct dwo_unit
*lhs
= item_lhs
;
6879 const struct dwo_unit
*rhs
= item_rhs
;
6881 /* The signature is assumed to be unique within the DWO file.
6882 So while object file CU dwo_id's always have the value zero,
6883 that's OK, assuming each object file DWO file has only one CU,
6884 and that's the rule for now. */
6885 return lhs
->signature
== rhs
->signature
;
6888 /* Allocate a hash table for DWO CUs,TUs.
6889 There is one of these tables for each of CUs,TUs for each DWO file. */
6892 allocate_dwo_unit_table (struct objfile
*objfile
)
6894 /* Start out with a pretty small number.
6895 Generally DWO files contain only one CU and maybe some TUs. */
6896 return htab_create_alloc_ex (3,
6900 &objfile
->objfile_obstack
,
6901 hashtab_obstack_allocate
,
6902 dummy_obstack_deallocate
);
6905 /* This function is mapped across the sections and remembers the offset and
6906 size of each of the DWO debugging sections we are interested in. */
6909 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6911 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6912 const struct dwo_section_names
*names
= &dwo_section_names
;
6914 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6916 dwo_file
->sections
.abbrev
.asection
= sectp
;
6917 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6919 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6921 dwo_file
->sections
.info
.asection
= sectp
;
6922 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6924 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6926 dwo_file
->sections
.line
.asection
= sectp
;
6927 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6929 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6931 dwo_file
->sections
.loc
.asection
= sectp
;
6932 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6934 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
6936 dwo_file
->sections
.str
.asection
= sectp
;
6937 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
6939 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
6941 dwo_file
->sections
.str_offsets
.asection
= sectp
;
6942 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
6944 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
6946 struct dwarf2_section_info type_section
;
6948 memset (&type_section
, 0, sizeof (type_section
));
6949 type_section
.asection
= sectp
;
6950 type_section
.size
= bfd_get_section_size (sectp
);
6951 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
6956 /* Structure used to pass data to create_debug_info_hash_table_reader. */
6958 struct create_dwo_info_table_data
6960 struct dwo_file
*dwo_file
;
6964 /* die_reader_func for create_debug_info_hash_table. */
6967 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
6969 struct die_info
*comp_unit_die
,
6973 struct dwarf2_cu
*cu
= reader
->cu
;
6974 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6975 sect_offset offset
= cu
->per_cu
->offset
;
6976 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
6977 struct create_dwo_info_table_data
*data
= datap
;
6978 struct dwo_file
*dwo_file
= data
->dwo_file
;
6979 htab_t cu_htab
= data
->cu_htab
;
6981 struct attribute
*attr
;
6982 struct dwo_unit
*dwo_unit
;
6984 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6987 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
6988 " its dwo_id [in module %s]"),
6989 offset
.sect_off
, dwo_file
->dwo_name
);
6993 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
6994 dwo_unit
->dwo_file
= dwo_file
;
6995 dwo_unit
->signature
= DW_UNSND (attr
);
6996 dwo_unit
->info_or_types_section
= section
;
6997 dwo_unit
->offset
= offset
;
6998 dwo_unit
->length
= cu
->per_cu
->length
;
7000 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7001 gdb_assert (slot
!= NULL
);
7004 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7006 complaint (&symfile_complaints
,
7007 _("debug entry at offset 0x%x is duplicate to the entry at"
7008 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7009 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7010 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7011 dwo_file
->dwo_name
);
7016 if (dwarf2_die_debug
)
7017 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7019 phex (dwo_unit
->signature
,
7020 sizeof (dwo_unit
->signature
)));
7023 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7026 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7028 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7029 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7032 gdb_byte
*info_ptr
, *end_ptr
;
7033 struct create_dwo_info_table_data create_dwo_info_table_data
;
7035 dwarf2_read_section (objfile
, section
);
7036 info_ptr
= section
->buffer
;
7038 if (info_ptr
== NULL
)
7041 /* We can't set abfd until now because the section may be empty or
7042 not present, in which case section->asection will be NULL. */
7043 abfd
= section
->asection
->owner
;
7045 if (dwarf2_die_debug
)
7046 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
7047 bfd_get_filename (abfd
));
7049 cu_htab
= allocate_dwo_unit_table (objfile
);
7051 create_dwo_info_table_data
.dwo_file
= dwo_file
;
7052 create_dwo_info_table_data
.cu_htab
= cu_htab
;
7054 end_ptr
= info_ptr
+ section
->size
;
7055 while (info_ptr
< end_ptr
)
7057 struct dwarf2_per_cu_data per_cu
;
7059 memset (&per_cu
, 0, sizeof (per_cu
));
7060 per_cu
.objfile
= objfile
;
7061 per_cu
.is_debug_types
= 0;
7062 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
7063 per_cu
.info_or_types_section
= section
;
7065 init_cutu_and_read_dies_no_follow (&per_cu
,
7066 &dwo_file
->sections
.abbrev
,
7068 create_debug_info_hash_table_reader
,
7069 &create_dwo_info_table_data
);
7071 info_ptr
+= per_cu
.length
;
7077 /* Subroutine of open_dwo_file to simplify it.
7078 Open the file specified by FILE_NAME and hand it off to BFD for
7079 preliminary analysis. Return a newly initialized bfd *, which
7080 includes a canonicalized copy of FILE_NAME.
7081 In case of trouble, return NULL.
7082 NOTE: This function is derived from symfile_bfd_open. */
7085 try_open_dwo_file (const char *file_name
)
7089 char *absolute_name
;
7091 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
7092 O_RDONLY
| O_BINARY
, &absolute_name
);
7096 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
7099 xfree (absolute_name
);
7102 bfd_set_cacheable (sym_bfd
, 1);
7104 if (!bfd_check_format (sym_bfd
, bfd_object
))
7106 bfd_close (sym_bfd
); /* This also closes desc. */
7107 xfree (absolute_name
);
7111 /* bfd_usrdata exists for applications and libbfd must not touch it. */
7112 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
7117 /* Try to open DWO file DWO_NAME.
7118 COMP_DIR is the DW_AT_comp_dir attribute.
7119 The result is the bfd handle of the file.
7120 If there is a problem finding or opening the file, return NULL.
7121 Upon success, the canonicalized path of the file is stored in the bfd,
7122 same as symfile_bfd_open. */
7125 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
7129 if (IS_ABSOLUTE_PATH (dwo_name
))
7130 return try_open_dwo_file (dwo_name
);
7132 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
7134 if (comp_dir
!= NULL
)
7136 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
7138 /* NOTE: If comp_dir is a relative path, this will also try the
7139 search path, which seems useful. */
7140 abfd
= try_open_dwo_file (path_to_try
);
7141 xfree (path_to_try
);
7146 /* That didn't work, try debug-file-directory, which, despite its name,
7147 is a list of paths. */
7149 if (*debug_file_directory
== '\0')
7152 return try_open_dwo_file (dwo_name
);
7155 /* Initialize the use of the DWO file specified by DWO_NAME. */
7157 static struct dwo_file
*
7158 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7160 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7161 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7164 struct cleanup
*cleanups
;
7166 if (dwarf2_die_debug
)
7167 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7169 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7172 dwo_file
->dwo_name
= dwo_name
;
7173 dwo_file
->dwo_bfd
= abfd
;
7175 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7177 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7179 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7181 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7182 dwo_file
->sections
.types
);
7184 discard_cleanups (cleanups
);
7189 /* Lookup DWO file DWO_NAME. */
7191 static struct dwo_file
*
7192 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7194 struct dwo_file
*dwo_file
;
7195 struct dwo_file find_entry
;
7198 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7199 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7201 /* Have we already seen this DWO file? */
7202 find_entry
.dwo_name
= dwo_name
;
7203 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7205 /* If not, read it in and build a table of the DWOs it contains. */
7207 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7209 /* NOTE: This will be NULL if unable to open the file. */
7215 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7216 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7217 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7218 nomenclature as TUs).
7219 The result is the DWO CU or NULL if we didn't find it
7220 (dwo_id mismatch or couldn't find the DWO file). */
7222 static struct dwo_unit
*
7223 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7224 char *dwo_name
, const char *comp_dir
,
7227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7228 struct dwo_file
*dwo_file
;
7230 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7231 if (dwo_file
== NULL
)
7234 /* Look up the DWO using its signature(dwo_id). */
7236 if (dwo_file
->cus
!= NULL
)
7238 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7240 find_dwo_cu
.signature
= signature
;
7241 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7247 /* We didn't find it. This must mean a dwo_id mismatch. */
7249 complaint (&symfile_complaints
,
7250 _("Could not find DWO CU referenced by CU at offset 0x%x"
7252 this_cu
->offset
.sect_off
, objfile
->name
);
7256 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7257 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7258 The result is the DWO CU or NULL if we didn't find it
7259 (dwo_id mismatch or couldn't find the DWO file). */
7261 static struct dwo_unit
*
7262 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7263 char *dwo_name
, const char *comp_dir
)
7265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7266 struct dwo_file
*dwo_file
;
7268 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7269 if (dwo_file
== NULL
)
7272 /* Look up the DWO using its signature(dwo_id). */
7274 if (dwo_file
->tus
!= NULL
)
7276 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7278 find_dwo_tu
.signature
= this_tu
->signature
;
7279 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7285 /* We didn't find it. This must mean a dwo_id mismatch. */
7287 complaint (&symfile_complaints
,
7288 _("Could not find DWO TU referenced by TU at offset 0x%x"
7290 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7294 /* Free all resources associated with DWO_FILE.
7295 Close the DWO file and munmap the sections.
7296 All memory should be on the objfile obstack. */
7299 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7302 struct dwarf2_section_info
*section
;
7304 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7305 bfd_close (dwo_file
->dwo_bfd
);
7307 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7308 munmap_section_buffer (&dwo_file
->sections
.info
);
7309 munmap_section_buffer (&dwo_file
->sections
.line
);
7310 munmap_section_buffer (&dwo_file
->sections
.loc
);
7311 munmap_section_buffer (&dwo_file
->sections
.str
);
7312 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7315 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7318 munmap_section_buffer (section
);
7320 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7323 /* Wrapper for free_dwo_file for use in cleanups. */
7326 free_dwo_file_cleanup (void *arg
)
7328 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7331 free_dwo_file (dwo_file
, objfile
);
7334 /* Traversal function for free_dwo_files. */
7337 free_dwo_file_from_slot (void **slot
, void *info
)
7339 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7340 struct objfile
*objfile
= (struct objfile
*) info
;
7342 free_dwo_file (dwo_file
, objfile
);
7347 /* Free all resources associated with DWO_FILES. */
7350 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7352 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7355 /* Read in various DIEs. */
7357 /* qsort helper for inherit_abstract_dies. */
7360 unsigned_int_compar (const void *ap
, const void *bp
)
7362 unsigned int a
= *(unsigned int *) ap
;
7363 unsigned int b
= *(unsigned int *) bp
;
7365 return (a
> b
) - (b
> a
);
7368 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7369 Inherit only the children of the DW_AT_abstract_origin DIE not being
7370 already referenced by DW_AT_abstract_origin from the children of the
7374 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7376 struct die_info
*child_die
;
7377 unsigned die_children_count
;
7378 /* CU offsets which were referenced by children of the current DIE. */
7379 sect_offset
*offsets
;
7380 sect_offset
*offsets_end
, *offsetp
;
7381 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7382 struct die_info
*origin_die
;
7383 /* Iterator of the ORIGIN_DIE children. */
7384 struct die_info
*origin_child_die
;
7385 struct cleanup
*cleanups
;
7386 struct attribute
*attr
;
7387 struct dwarf2_cu
*origin_cu
;
7388 struct pending
**origin_previous_list_in_scope
;
7390 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7394 /* Note that following die references may follow to a die in a
7398 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7400 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7402 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7403 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7405 if (die
->tag
!= origin_die
->tag
7406 && !(die
->tag
== DW_TAG_inlined_subroutine
7407 && origin_die
->tag
== DW_TAG_subprogram
))
7408 complaint (&symfile_complaints
,
7409 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7410 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7412 child_die
= die
->child
;
7413 die_children_count
= 0;
7414 while (child_die
&& child_die
->tag
)
7416 child_die
= sibling_die (child_die
);
7417 die_children_count
++;
7419 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7420 cleanups
= make_cleanup (xfree
, offsets
);
7422 offsets_end
= offsets
;
7423 child_die
= die
->child
;
7424 while (child_die
&& child_die
->tag
)
7426 /* For each CHILD_DIE, find the corresponding child of
7427 ORIGIN_DIE. If there is more than one layer of
7428 DW_AT_abstract_origin, follow them all; there shouldn't be,
7429 but GCC versions at least through 4.4 generate this (GCC PR
7431 struct die_info
*child_origin_die
= child_die
;
7432 struct dwarf2_cu
*child_origin_cu
= cu
;
7436 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7440 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7444 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7445 counterpart may exist. */
7446 if (child_origin_die
!= child_die
)
7448 if (child_die
->tag
!= child_origin_die
->tag
7449 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7450 && child_origin_die
->tag
== DW_TAG_subprogram
))
7451 complaint (&symfile_complaints
,
7452 _("Child DIE 0x%x and its abstract origin 0x%x have "
7453 "different tags"), child_die
->offset
.sect_off
,
7454 child_origin_die
->offset
.sect_off
);
7455 if (child_origin_die
->parent
!= origin_die
)
7456 complaint (&symfile_complaints
,
7457 _("Child DIE 0x%x and its abstract origin 0x%x have "
7458 "different parents"), child_die
->offset
.sect_off
,
7459 child_origin_die
->offset
.sect_off
);
7461 *offsets_end
++ = child_origin_die
->offset
;
7463 child_die
= sibling_die (child_die
);
7465 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7466 unsigned_int_compar
);
7467 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7468 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7469 complaint (&symfile_complaints
,
7470 _("Multiple children of DIE 0x%x refer "
7471 "to DIE 0x%x as their abstract origin"),
7472 die
->offset
.sect_off
, offsetp
->sect_off
);
7475 origin_child_die
= origin_die
->child
;
7476 while (origin_child_die
&& origin_child_die
->tag
)
7478 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7479 while (offsetp
< offsets_end
7480 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7482 if (offsetp
>= offsets_end
7483 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7485 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7486 process_die (origin_child_die
, origin_cu
);
7488 origin_child_die
= sibling_die (origin_child_die
);
7490 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7492 do_cleanups (cleanups
);
7496 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7498 struct objfile
*objfile
= cu
->objfile
;
7499 struct context_stack
*new;
7502 struct die_info
*child_die
;
7503 struct attribute
*attr
, *call_line
, *call_file
;
7506 struct block
*block
;
7507 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7508 VEC (symbolp
) *template_args
= NULL
;
7509 struct template_symbol
*templ_func
= NULL
;
7513 /* If we do not have call site information, we can't show the
7514 caller of this inlined function. That's too confusing, so
7515 only use the scope for local variables. */
7516 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7517 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7518 if (call_line
== NULL
|| call_file
== NULL
)
7520 read_lexical_block_scope (die
, cu
);
7525 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7527 name
= dwarf2_name (die
, cu
);
7529 /* Ignore functions with missing or empty names. These are actually
7530 illegal according to the DWARF standard. */
7533 complaint (&symfile_complaints
,
7534 _("missing name for subprogram DIE at %d"),
7535 die
->offset
.sect_off
);
7539 /* Ignore functions with missing or invalid low and high pc attributes. */
7540 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7542 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7543 if (!attr
|| !DW_UNSND (attr
))
7544 complaint (&symfile_complaints
,
7545 _("cannot get low and high bounds "
7546 "for subprogram DIE at %d"),
7547 die
->offset
.sect_off
);
7554 /* If we have any template arguments, then we must allocate a
7555 different sort of symbol. */
7556 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7558 if (child_die
->tag
== DW_TAG_template_type_param
7559 || child_die
->tag
== DW_TAG_template_value_param
)
7561 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7562 struct template_symbol
);
7563 templ_func
->base
.is_cplus_template_function
= 1;
7568 new = push_context (0, lowpc
);
7569 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7570 (struct symbol
*) templ_func
);
7572 /* If there is a location expression for DW_AT_frame_base, record
7574 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7576 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7577 expression is being recorded directly in the function's symbol
7578 and not in a separate frame-base object. I guess this hack is
7579 to avoid adding some sort of frame-base adjunct/annex to the
7580 function's symbol :-(. The problem with doing this is that it
7581 results in a function symbol with a location expression that
7582 has nothing to do with the location of the function, ouch! The
7583 relationship should be: a function's symbol has-a frame base; a
7584 frame-base has-a location expression. */
7585 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7587 cu
->list_in_scope
= &local_symbols
;
7589 if (die
->child
!= NULL
)
7591 child_die
= die
->child
;
7592 while (child_die
&& child_die
->tag
)
7594 if (child_die
->tag
== DW_TAG_template_type_param
7595 || child_die
->tag
== DW_TAG_template_value_param
)
7597 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7600 VEC_safe_push (symbolp
, template_args
, arg
);
7603 process_die (child_die
, cu
);
7604 child_die
= sibling_die (child_die
);
7608 inherit_abstract_dies (die
, cu
);
7610 /* If we have a DW_AT_specification, we might need to import using
7611 directives from the context of the specification DIE. See the
7612 comment in determine_prefix. */
7613 if (cu
->language
== language_cplus
7614 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7616 struct dwarf2_cu
*spec_cu
= cu
;
7617 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7621 child_die
= spec_die
->child
;
7622 while (child_die
&& child_die
->tag
)
7624 if (child_die
->tag
== DW_TAG_imported_module
)
7625 process_die (child_die
, spec_cu
);
7626 child_die
= sibling_die (child_die
);
7629 /* In some cases, GCC generates specification DIEs that
7630 themselves contain DW_AT_specification attributes. */
7631 spec_die
= die_specification (spec_die
, &spec_cu
);
7635 new = pop_context ();
7636 /* Make a block for the local symbols within. */
7637 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7638 lowpc
, highpc
, objfile
);
7640 /* For C++, set the block's scope. */
7641 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7642 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7643 determine_prefix (die
, cu
),
7644 processing_has_namespace_info
);
7646 /* If we have address ranges, record them. */
7647 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7649 /* Attach template arguments to function. */
7650 if (! VEC_empty (symbolp
, template_args
))
7652 gdb_assert (templ_func
!= NULL
);
7654 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7655 templ_func
->template_arguments
7656 = obstack_alloc (&objfile
->objfile_obstack
,
7657 (templ_func
->n_template_arguments
7658 * sizeof (struct symbol
*)));
7659 memcpy (templ_func
->template_arguments
,
7660 VEC_address (symbolp
, template_args
),
7661 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7662 VEC_free (symbolp
, template_args
);
7665 /* In C++, we can have functions nested inside functions (e.g., when
7666 a function declares a class that has methods). This means that
7667 when we finish processing a function scope, we may need to go
7668 back to building a containing block's symbol lists. */
7669 local_symbols
= new->locals
;
7670 param_symbols
= new->params
;
7671 using_directives
= new->using_directives
;
7673 /* If we've finished processing a top-level function, subsequent
7674 symbols go in the file symbol list. */
7675 if (outermost_context_p ())
7676 cu
->list_in_scope
= &file_symbols
;
7679 /* Process all the DIES contained within a lexical block scope. Start
7680 a new scope, process the dies, and then close the scope. */
7683 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7685 struct objfile
*objfile
= cu
->objfile
;
7686 struct context_stack
*new;
7687 CORE_ADDR lowpc
, highpc
;
7688 struct die_info
*child_die
;
7691 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7693 /* Ignore blocks with missing or invalid low and high pc attributes. */
7694 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7695 as multiple lexical blocks? Handling children in a sane way would
7696 be nasty. Might be easier to properly extend generic blocks to
7698 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7703 push_context (0, lowpc
);
7704 if (die
->child
!= NULL
)
7706 child_die
= die
->child
;
7707 while (child_die
&& child_die
->tag
)
7709 process_die (child_die
, cu
);
7710 child_die
= sibling_die (child_die
);
7713 new = pop_context ();
7715 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7718 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7721 /* Note that recording ranges after traversing children, as we
7722 do here, means that recording a parent's ranges entails
7723 walking across all its children's ranges as they appear in
7724 the address map, which is quadratic behavior.
7726 It would be nicer to record the parent's ranges before
7727 traversing its children, simply overriding whatever you find
7728 there. But since we don't even decide whether to create a
7729 block until after we've traversed its children, that's hard
7731 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7733 local_symbols
= new->locals
;
7734 using_directives
= new->using_directives
;
7737 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7740 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7742 struct objfile
*objfile
= cu
->objfile
;
7743 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7744 CORE_ADDR pc
, baseaddr
;
7745 struct attribute
*attr
;
7746 struct call_site
*call_site
, call_site_local
;
7749 struct die_info
*child_die
;
7751 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7753 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7756 complaint (&symfile_complaints
,
7757 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7758 "DIE 0x%x [in module %s]"),
7759 die
->offset
.sect_off
, objfile
->name
);
7762 pc
= DW_ADDR (attr
) + baseaddr
;
7764 if (cu
->call_site_htab
== NULL
)
7765 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7766 NULL
, &objfile
->objfile_obstack
,
7767 hashtab_obstack_allocate
, NULL
);
7768 call_site_local
.pc
= pc
;
7769 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7772 complaint (&symfile_complaints
,
7773 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7774 "DIE 0x%x [in module %s]"),
7775 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7779 /* Count parameters at the caller. */
7782 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7783 child_die
= sibling_die (child_die
))
7785 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7787 complaint (&symfile_complaints
,
7788 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7789 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7790 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7797 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7798 (sizeof (*call_site
)
7799 + (sizeof (*call_site
->parameter
)
7802 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7805 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7807 struct die_info
*func_die
;
7809 /* Skip also over DW_TAG_inlined_subroutine. */
7810 for (func_die
= die
->parent
;
7811 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7812 && func_die
->tag
!= DW_TAG_subroutine_type
;
7813 func_die
= func_die
->parent
);
7815 /* DW_AT_GNU_all_call_sites is a superset
7816 of DW_AT_GNU_all_tail_call_sites. */
7818 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7819 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7821 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7822 not complete. But keep CALL_SITE for look ups via call_site_htab,
7823 both the initial caller containing the real return address PC and
7824 the final callee containing the current PC of a chain of tail
7825 calls do not need to have the tail call list complete. But any
7826 function candidate for a virtual tail call frame searched via
7827 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7828 determined unambiguously. */
7832 struct type
*func_type
= NULL
;
7835 func_type
= get_die_type (func_die
, cu
);
7836 if (func_type
!= NULL
)
7838 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7840 /* Enlist this call site to the function. */
7841 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7842 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7845 complaint (&symfile_complaints
,
7846 _("Cannot find function owning DW_TAG_GNU_call_site "
7847 "DIE 0x%x [in module %s]"),
7848 die
->offset
.sect_off
, objfile
->name
);
7852 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7854 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7855 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7856 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7857 /* Keep NULL DWARF_BLOCK. */;
7858 else if (attr_form_is_block (attr
))
7860 struct dwarf2_locexpr_baton
*dlbaton
;
7862 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7863 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7864 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7865 dlbaton
->per_cu
= cu
->per_cu
;
7867 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7869 else if (is_ref_attr (attr
))
7871 struct dwarf2_cu
*target_cu
= cu
;
7872 struct die_info
*target_die
;
7874 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7875 gdb_assert (target_cu
->objfile
== objfile
);
7876 if (die_is_declaration (target_die
, target_cu
))
7878 const char *target_physname
;
7880 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7881 if (target_physname
== NULL
)
7882 complaint (&symfile_complaints
,
7883 _("DW_AT_GNU_call_site_target target DIE has invalid "
7884 "physname, for referencing DIE 0x%x [in module %s]"),
7885 die
->offset
.sect_off
, objfile
->name
);
7887 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7893 /* DW_AT_entry_pc should be preferred. */
7894 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7895 complaint (&symfile_complaints
,
7896 _("DW_AT_GNU_call_site_target target DIE has invalid "
7897 "low pc, for referencing DIE 0x%x [in module %s]"),
7898 die
->offset
.sect_off
, objfile
->name
);
7900 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7904 complaint (&symfile_complaints
,
7905 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7906 "block nor reference, for DIE 0x%x [in module %s]"),
7907 die
->offset
.sect_off
, objfile
->name
);
7909 call_site
->per_cu
= cu
->per_cu
;
7911 for (child_die
= die
->child
;
7912 child_die
&& child_die
->tag
;
7913 child_die
= sibling_die (child_die
))
7915 struct call_site_parameter
*parameter
;
7916 struct attribute
*loc
, *origin
;
7918 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7920 /* Already printed the complaint above. */
7924 gdb_assert (call_site
->parameter_count
< nparams
);
7925 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7927 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
7928 specifies DW_TAG_formal_parameter. Value of the data assumed for the
7929 register is contained in DW_AT_GNU_call_site_value. */
7931 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
7932 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
7933 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
7937 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
7938 offset
= dwarf2_get_ref_die_offset (origin
);
7939 gdb_assert (offset
.sect_off
>= cu
->header
.offset
.sect_off
);
7940 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
7941 - cu
->header
.offset
.sect_off
);
7943 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
7945 complaint (&symfile_complaints
,
7946 _("No DW_FORM_block* DW_AT_location for "
7947 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7948 child_die
->offset
.sect_off
, objfile
->name
);
7953 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
7954 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
7955 if (parameter
->u
.dwarf_reg
!= -1)
7956 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
7957 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
7958 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
7959 ¶meter
->u
.fb_offset
))
7960 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
7963 complaint (&symfile_complaints
,
7964 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
7965 "for DW_FORM_block* DW_AT_location is supported for "
7966 "DW_TAG_GNU_call_site child DIE 0x%x "
7968 child_die
->offset
.sect_off
, objfile
->name
);
7973 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
7974 if (!attr_form_is_block (attr
))
7976 complaint (&symfile_complaints
,
7977 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
7978 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7979 child_die
->offset
.sect_off
, objfile
->name
);
7982 parameter
->value
= DW_BLOCK (attr
)->data
;
7983 parameter
->value_size
= DW_BLOCK (attr
)->size
;
7985 /* Parameters are not pre-cleared by memset above. */
7986 parameter
->data_value
= NULL
;
7987 parameter
->data_value_size
= 0;
7988 call_site
->parameter_count
++;
7990 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
7993 if (!attr_form_is_block (attr
))
7994 complaint (&symfile_complaints
,
7995 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
7996 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7997 child_die
->offset
.sect_off
, objfile
->name
);
8000 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8001 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8007 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8008 Return 1 if the attributes are present and valid, otherwise, return 0.
8009 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8012 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8013 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8014 struct partial_symtab
*ranges_pst
)
8016 struct objfile
*objfile
= cu
->objfile
;
8017 struct comp_unit_head
*cu_header
= &cu
->header
;
8018 bfd
*obfd
= objfile
->obfd
;
8019 unsigned int addr_size
= cu_header
->addr_size
;
8020 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8021 /* Base address selection entry. */
8032 found_base
= cu
->base_known
;
8033 base
= cu
->base_address
;
8035 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
8036 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8038 complaint (&symfile_complaints
,
8039 _("Offset %d out of bounds for DW_AT_ranges attribute"),
8043 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8045 /* Read in the largest possible address. */
8046 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
8047 if ((marker
& mask
) == mask
)
8049 /* If we found the largest possible address, then
8050 read the base address. */
8051 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8052 buffer
+= 2 * addr_size
;
8053 offset
+= 2 * addr_size
;
8059 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8063 CORE_ADDR range_beginning
, range_end
;
8065 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
8066 buffer
+= addr_size
;
8067 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
8068 buffer
+= addr_size
;
8069 offset
+= 2 * addr_size
;
8071 /* An end of list marker is a pair of zero addresses. */
8072 if (range_beginning
== 0 && range_end
== 0)
8073 /* Found the end of list entry. */
8076 /* Each base address selection entry is a pair of 2 values.
8077 The first is the largest possible address, the second is
8078 the base address. Check for a base address here. */
8079 if ((range_beginning
& mask
) == mask
)
8081 /* If we found the largest possible address, then
8082 read the base address. */
8083 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8090 /* We have no valid base address for the ranges
8092 complaint (&symfile_complaints
,
8093 _("Invalid .debug_ranges data (no base address)"));
8097 if (range_beginning
> range_end
)
8099 /* Inverted range entries are invalid. */
8100 complaint (&symfile_complaints
,
8101 _("Invalid .debug_ranges data (inverted range)"));
8105 /* Empty range entries have no effect. */
8106 if (range_beginning
== range_end
)
8109 range_beginning
+= base
;
8112 if (ranges_pst
!= NULL
)
8113 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8114 range_beginning
+ baseaddr
,
8115 range_end
- 1 + baseaddr
,
8118 /* FIXME: This is recording everything as a low-high
8119 segment of consecutive addresses. We should have a
8120 data structure for discontiguous block ranges
8124 low
= range_beginning
;
8130 if (range_beginning
< low
)
8131 low
= range_beginning
;
8132 if (range_end
> high
)
8138 /* If the first entry is an end-of-list marker, the range
8139 describes an empty scope, i.e. no instructions. */
8145 *high_return
= high
;
8149 /* Get low and high pc attributes from a die. Return 1 if the attributes
8150 are present and valid, otherwise, return 0. Return -1 if the range is
8151 discontinuous, i.e. derived from DW_AT_ranges information. */
8154 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
8155 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
8156 struct partial_symtab
*pst
)
8158 struct attribute
*attr
;
8159 struct attribute
*attr_high
;
8164 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8167 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8170 low
= DW_ADDR (attr
);
8171 if (attr_high
->form
== DW_FORM_addr
8172 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8173 high
= DW_ADDR (attr_high
);
8175 high
= low
+ DW_UNSND (attr_high
);
8178 /* Found high w/o low attribute. */
8181 /* Found consecutive range of addresses. */
8186 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8189 /* Value of the DW_AT_ranges attribute is the offset in the
8190 .debug_ranges section. */
8191 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
8193 /* Found discontinuous range of addresses. */
8198 /* read_partial_die has also the strict LOW < HIGH requirement. */
8202 /* When using the GNU linker, .gnu.linkonce. sections are used to
8203 eliminate duplicate copies of functions and vtables and such.
8204 The linker will arbitrarily choose one and discard the others.
8205 The AT_*_pc values for such functions refer to local labels in
8206 these sections. If the section from that file was discarded, the
8207 labels are not in the output, so the relocs get a value of 0.
8208 If this is a discarded function, mark the pc bounds as invalid,
8209 so that GDB will ignore it. */
8210 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8219 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8220 its low and high PC addresses. Do nothing if these addresses could not
8221 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8222 and HIGHPC to the high address if greater than HIGHPC. */
8225 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8226 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8227 struct dwarf2_cu
*cu
)
8229 CORE_ADDR low
, high
;
8230 struct die_info
*child
= die
->child
;
8232 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8234 *lowpc
= min (*lowpc
, low
);
8235 *highpc
= max (*highpc
, high
);
8238 /* If the language does not allow nested subprograms (either inside
8239 subprograms or lexical blocks), we're done. */
8240 if (cu
->language
!= language_ada
)
8243 /* Check all the children of the given DIE. If it contains nested
8244 subprograms, then check their pc bounds. Likewise, we need to
8245 check lexical blocks as well, as they may also contain subprogram
8247 while (child
&& child
->tag
)
8249 if (child
->tag
== DW_TAG_subprogram
8250 || child
->tag
== DW_TAG_lexical_block
)
8251 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8252 child
= sibling_die (child
);
8256 /* Get the low and high pc's represented by the scope DIE, and store
8257 them in *LOWPC and *HIGHPC. If the correct values can't be
8258 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8261 get_scope_pc_bounds (struct die_info
*die
,
8262 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8263 struct dwarf2_cu
*cu
)
8265 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8266 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8267 CORE_ADDR current_low
, current_high
;
8269 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8271 best_low
= current_low
;
8272 best_high
= current_high
;
8276 struct die_info
*child
= die
->child
;
8278 while (child
&& child
->tag
)
8280 switch (child
->tag
) {
8281 case DW_TAG_subprogram
:
8282 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8284 case DW_TAG_namespace
:
8286 /* FIXME: carlton/2004-01-16: Should we do this for
8287 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8288 that current GCC's always emit the DIEs corresponding
8289 to definitions of methods of classes as children of a
8290 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8291 the DIEs giving the declarations, which could be
8292 anywhere). But I don't see any reason why the
8293 standards says that they have to be there. */
8294 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8296 if (current_low
!= ((CORE_ADDR
) -1))
8298 best_low
= min (best_low
, current_low
);
8299 best_high
= max (best_high
, current_high
);
8307 child
= sibling_die (child
);
8312 *highpc
= best_high
;
8315 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8319 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8320 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8322 struct objfile
*objfile
= cu
->objfile
;
8323 struct attribute
*attr
;
8324 struct attribute
*attr_high
;
8326 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8329 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8332 CORE_ADDR low
= DW_ADDR (attr
);
8334 if (attr_high
->form
== DW_FORM_addr
8335 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8336 high
= DW_ADDR (attr_high
);
8338 high
= low
+ DW_UNSND (attr_high
);
8340 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8344 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8347 bfd
*obfd
= objfile
->obfd
;
8349 /* The value of the DW_AT_ranges attribute is the offset of the
8350 address range list in the .debug_ranges section. */
8351 unsigned long offset
= DW_UNSND (attr
);
8352 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8354 /* For some target architectures, but not others, the
8355 read_address function sign-extends the addresses it returns.
8356 To recognize base address selection entries, we need a
8358 unsigned int addr_size
= cu
->header
.addr_size
;
8359 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8361 /* The base address, to which the next pair is relative. Note
8362 that this 'base' is a DWARF concept: most entries in a range
8363 list are relative, to reduce the number of relocs against the
8364 debugging information. This is separate from this function's
8365 'baseaddr' argument, which GDB uses to relocate debugging
8366 information from a shared library based on the address at
8367 which the library was loaded. */
8368 CORE_ADDR base
= cu
->base_address
;
8369 int base_known
= cu
->base_known
;
8371 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8372 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8374 complaint (&symfile_complaints
,
8375 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8382 unsigned int bytes_read
;
8383 CORE_ADDR start
, end
;
8385 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8386 buffer
+= bytes_read
;
8387 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8388 buffer
+= bytes_read
;
8390 /* Did we find the end of the range list? */
8391 if (start
== 0 && end
== 0)
8394 /* Did we find a base address selection entry? */
8395 else if ((start
& base_select_mask
) == base_select_mask
)
8401 /* We found an ordinary address range. */
8406 complaint (&symfile_complaints
,
8407 _("Invalid .debug_ranges data "
8408 "(no base address)"));
8414 /* Inverted range entries are invalid. */
8415 complaint (&symfile_complaints
,
8416 _("Invalid .debug_ranges data "
8417 "(inverted range)"));
8421 /* Empty range entries have no effect. */
8425 record_block_range (block
,
8426 baseaddr
+ base
+ start
,
8427 baseaddr
+ base
+ end
- 1);
8433 /* Check whether the producer field indicates either of GCC < 4.6, or the
8434 Intel C/C++ compiler, and cache the result in CU. */
8437 check_producer (struct dwarf2_cu
*cu
)
8440 int major
, minor
, release
;
8442 if (cu
->producer
== NULL
)
8444 /* For unknown compilers expect their behavior is DWARF version
8447 GCC started to support .debug_types sections by -gdwarf-4 since
8448 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8449 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8450 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8451 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8453 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
8455 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8457 cs
= &cu
->producer
[strlen ("GNU ")];
8458 while (*cs
&& !isdigit (*cs
))
8460 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8462 /* Not recognized as GCC. */
8465 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
8467 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
8468 cu
->producer_is_icc
= 1;
8471 /* For other non-GCC compilers, expect their behavior is DWARF version
8475 cu
->checked_producer
= 1;
8478 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8479 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8480 during 4.6.0 experimental. */
8483 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8485 if (!cu
->checked_producer
)
8486 check_producer (cu
);
8488 return cu
->producer_is_gxx_lt_4_6
;
8491 /* Return the default accessibility type if it is not overriden by
8492 DW_AT_accessibility. */
8494 static enum dwarf_access_attribute
8495 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8497 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8499 /* The default DWARF 2 accessibility for members is public, the default
8500 accessibility for inheritance is private. */
8502 if (die
->tag
!= DW_TAG_inheritance
)
8503 return DW_ACCESS_public
;
8505 return DW_ACCESS_private
;
8509 /* DWARF 3+ defines the default accessibility a different way. The same
8510 rules apply now for DW_TAG_inheritance as for the members and it only
8511 depends on the container kind. */
8513 if (die
->parent
->tag
== DW_TAG_class_type
)
8514 return DW_ACCESS_private
;
8516 return DW_ACCESS_public
;
8520 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8521 offset. If the attribute was not found return 0, otherwise return
8522 1. If it was found but could not properly be handled, set *OFFSET
8526 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8529 struct attribute
*attr
;
8531 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8536 /* Note that we do not check for a section offset first here.
8537 This is because DW_AT_data_member_location is new in DWARF 4,
8538 so if we see it, we can assume that a constant form is really
8539 a constant and not a section offset. */
8540 if (attr_form_is_constant (attr
))
8541 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8542 else if (attr_form_is_section_offset (attr
))
8543 dwarf2_complex_location_expr_complaint ();
8544 else if (attr_form_is_block (attr
))
8545 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8547 dwarf2_complex_location_expr_complaint ();
8555 /* Add an aggregate field to the field list. */
8558 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8559 struct dwarf2_cu
*cu
)
8561 struct objfile
*objfile
= cu
->objfile
;
8562 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8563 struct nextfield
*new_field
;
8564 struct attribute
*attr
;
8566 char *fieldname
= "";
8568 /* Allocate a new field list entry and link it in. */
8569 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8570 make_cleanup (xfree
, new_field
);
8571 memset (new_field
, 0, sizeof (struct nextfield
));
8573 if (die
->tag
== DW_TAG_inheritance
)
8575 new_field
->next
= fip
->baseclasses
;
8576 fip
->baseclasses
= new_field
;
8580 new_field
->next
= fip
->fields
;
8581 fip
->fields
= new_field
;
8585 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8587 new_field
->accessibility
= DW_UNSND (attr
);
8589 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8590 if (new_field
->accessibility
!= DW_ACCESS_public
)
8591 fip
->non_public_fields
= 1;
8593 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8595 new_field
->virtuality
= DW_UNSND (attr
);
8597 new_field
->virtuality
= DW_VIRTUALITY_none
;
8599 fp
= &new_field
->field
;
8601 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8605 /* Data member other than a C++ static data member. */
8607 /* Get type of field. */
8608 fp
->type
= die_type (die
, cu
);
8610 SET_FIELD_BITPOS (*fp
, 0);
8612 /* Get bit size of field (zero if none). */
8613 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8616 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8620 FIELD_BITSIZE (*fp
) = 0;
8623 /* Get bit offset of field. */
8624 if (handle_data_member_location (die
, cu
, &offset
))
8625 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8626 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8629 if (gdbarch_bits_big_endian (gdbarch
))
8631 /* For big endian bits, the DW_AT_bit_offset gives the
8632 additional bit offset from the MSB of the containing
8633 anonymous object to the MSB of the field. We don't
8634 have to do anything special since we don't need to
8635 know the size of the anonymous object. */
8636 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8640 /* For little endian bits, compute the bit offset to the
8641 MSB of the anonymous object, subtract off the number of
8642 bits from the MSB of the field to the MSB of the
8643 object, and then subtract off the number of bits of
8644 the field itself. The result is the bit offset of
8645 the LSB of the field. */
8647 int bit_offset
= DW_UNSND (attr
);
8649 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8652 /* The size of the anonymous object containing
8653 the bit field is explicit, so use the
8654 indicated size (in bytes). */
8655 anonymous_size
= DW_UNSND (attr
);
8659 /* The size of the anonymous object containing
8660 the bit field must be inferred from the type
8661 attribute of the data member containing the
8663 anonymous_size
= TYPE_LENGTH (fp
->type
);
8665 SET_FIELD_BITPOS (*fp
,
8667 + anonymous_size
* bits_per_byte
8668 - bit_offset
- FIELD_BITSIZE (*fp
)));
8672 /* Get name of field. */
8673 fieldname
= dwarf2_name (die
, cu
);
8674 if (fieldname
== NULL
)
8677 /* The name is already allocated along with this objfile, so we don't
8678 need to duplicate it for the type. */
8679 fp
->name
= fieldname
;
8681 /* Change accessibility for artificial fields (e.g. virtual table
8682 pointer or virtual base class pointer) to private. */
8683 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8685 FIELD_ARTIFICIAL (*fp
) = 1;
8686 new_field
->accessibility
= DW_ACCESS_private
;
8687 fip
->non_public_fields
= 1;
8690 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8692 /* C++ static member. */
8694 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8695 is a declaration, but all versions of G++ as of this writing
8696 (so through at least 3.2.1) incorrectly generate
8697 DW_TAG_variable tags. */
8699 const char *physname
;
8701 /* Get name of field. */
8702 fieldname
= dwarf2_name (die
, cu
);
8703 if (fieldname
== NULL
)
8706 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8708 /* Only create a symbol if this is an external value.
8709 new_symbol checks this and puts the value in the global symbol
8710 table, which we want. If it is not external, new_symbol
8711 will try to put the value in cu->list_in_scope which is wrong. */
8712 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8714 /* A static const member, not much different than an enum as far as
8715 we're concerned, except that we can support more types. */
8716 new_symbol (die
, NULL
, cu
);
8719 /* Get physical name. */
8720 physname
= dwarf2_physname (fieldname
, die
, cu
);
8722 /* The name is already allocated along with this objfile, so we don't
8723 need to duplicate it for the type. */
8724 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8725 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8726 FIELD_NAME (*fp
) = fieldname
;
8728 else if (die
->tag
== DW_TAG_inheritance
)
8732 /* C++ base class field. */
8733 if (handle_data_member_location (die
, cu
, &offset
))
8734 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8735 FIELD_BITSIZE (*fp
) = 0;
8736 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8737 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8738 fip
->nbaseclasses
++;
8742 /* Add a typedef defined in the scope of the FIP's class. */
8745 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8746 struct dwarf2_cu
*cu
)
8748 struct objfile
*objfile
= cu
->objfile
;
8749 struct typedef_field_list
*new_field
;
8750 struct attribute
*attr
;
8751 struct typedef_field
*fp
;
8752 char *fieldname
= "";
8754 /* Allocate a new field list entry and link it in. */
8755 new_field
= xzalloc (sizeof (*new_field
));
8756 make_cleanup (xfree
, new_field
);
8758 gdb_assert (die
->tag
== DW_TAG_typedef
);
8760 fp
= &new_field
->field
;
8762 /* Get name of field. */
8763 fp
->name
= dwarf2_name (die
, cu
);
8764 if (fp
->name
== NULL
)
8767 fp
->type
= read_type_die (die
, cu
);
8769 new_field
->next
= fip
->typedef_field_list
;
8770 fip
->typedef_field_list
= new_field
;
8771 fip
->typedef_field_list_count
++;
8774 /* Create the vector of fields, and attach it to the type. */
8777 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8778 struct dwarf2_cu
*cu
)
8780 int nfields
= fip
->nfields
;
8782 /* Record the field count, allocate space for the array of fields,
8783 and create blank accessibility bitfields if necessary. */
8784 TYPE_NFIELDS (type
) = nfields
;
8785 TYPE_FIELDS (type
) = (struct field
*)
8786 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8787 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8789 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8791 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8793 TYPE_FIELD_PRIVATE_BITS (type
) =
8794 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8795 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8797 TYPE_FIELD_PROTECTED_BITS (type
) =
8798 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8799 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8801 TYPE_FIELD_IGNORE_BITS (type
) =
8802 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8803 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8806 /* If the type has baseclasses, allocate and clear a bit vector for
8807 TYPE_FIELD_VIRTUAL_BITS. */
8808 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8810 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8811 unsigned char *pointer
;
8813 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8814 pointer
= TYPE_ALLOC (type
, num_bytes
);
8815 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8816 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8817 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8820 /* Copy the saved-up fields into the field vector. Start from the head of
8821 the list, adding to the tail of the field array, so that they end up in
8822 the same order in the array in which they were added to the list. */
8823 while (nfields
-- > 0)
8825 struct nextfield
*fieldp
;
8829 fieldp
= fip
->fields
;
8830 fip
->fields
= fieldp
->next
;
8834 fieldp
= fip
->baseclasses
;
8835 fip
->baseclasses
= fieldp
->next
;
8838 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8839 switch (fieldp
->accessibility
)
8841 case DW_ACCESS_private
:
8842 if (cu
->language
!= language_ada
)
8843 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8846 case DW_ACCESS_protected
:
8847 if (cu
->language
!= language_ada
)
8848 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8851 case DW_ACCESS_public
:
8855 /* Unknown accessibility. Complain and treat it as public. */
8857 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8858 fieldp
->accessibility
);
8862 if (nfields
< fip
->nbaseclasses
)
8864 switch (fieldp
->virtuality
)
8866 case DW_VIRTUALITY_virtual
:
8867 case DW_VIRTUALITY_pure_virtual
:
8868 if (cu
->language
== language_ada
)
8869 error (_("unexpected virtuality in component of Ada type"));
8870 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8877 /* Add a member function to the proper fieldlist. */
8880 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8881 struct type
*type
, struct dwarf2_cu
*cu
)
8883 struct objfile
*objfile
= cu
->objfile
;
8884 struct attribute
*attr
;
8885 struct fnfieldlist
*flp
;
8887 struct fn_field
*fnp
;
8889 struct nextfnfield
*new_fnfield
;
8890 struct type
*this_type
;
8891 enum dwarf_access_attribute accessibility
;
8893 if (cu
->language
== language_ada
)
8894 error (_("unexpected member function in Ada type"));
8896 /* Get name of member function. */
8897 fieldname
= dwarf2_name (die
, cu
);
8898 if (fieldname
== NULL
)
8901 /* Look up member function name in fieldlist. */
8902 for (i
= 0; i
< fip
->nfnfields
; i
++)
8904 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8908 /* Create new list element if necessary. */
8909 if (i
< fip
->nfnfields
)
8910 flp
= &fip
->fnfieldlists
[i
];
8913 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8915 fip
->fnfieldlists
= (struct fnfieldlist
*)
8916 xrealloc (fip
->fnfieldlists
,
8917 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8918 * sizeof (struct fnfieldlist
));
8919 if (fip
->nfnfields
== 0)
8920 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8922 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8923 flp
->name
= fieldname
;
8926 i
= fip
->nfnfields
++;
8929 /* Create a new member function field and chain it to the field list
8931 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
8932 make_cleanup (xfree
, new_fnfield
);
8933 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
8934 new_fnfield
->next
= flp
->head
;
8935 flp
->head
= new_fnfield
;
8938 /* Fill in the member function field info. */
8939 fnp
= &new_fnfield
->fnfield
;
8941 /* Delay processing of the physname until later. */
8942 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
8944 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
8949 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
8950 fnp
->physname
= physname
? physname
: "";
8953 fnp
->type
= alloc_type (objfile
);
8954 this_type
= read_type_die (die
, cu
);
8955 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
8957 int nparams
= TYPE_NFIELDS (this_type
);
8959 /* TYPE is the domain of this method, and THIS_TYPE is the type
8960 of the method itself (TYPE_CODE_METHOD). */
8961 smash_to_method_type (fnp
->type
, type
,
8962 TYPE_TARGET_TYPE (this_type
),
8963 TYPE_FIELDS (this_type
),
8964 TYPE_NFIELDS (this_type
),
8965 TYPE_VARARGS (this_type
));
8967 /* Handle static member functions.
8968 Dwarf2 has no clean way to discern C++ static and non-static
8969 member functions. G++ helps GDB by marking the first
8970 parameter for non-static member functions (which is the this
8971 pointer) as artificial. We obtain this information from
8972 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
8973 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
8974 fnp
->voffset
= VOFFSET_STATIC
;
8977 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
8978 dwarf2_full_name (fieldname
, die
, cu
));
8980 /* Get fcontext from DW_AT_containing_type if present. */
8981 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
8982 fnp
->fcontext
= die_containing_type (die
, cu
);
8984 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
8985 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
8987 /* Get accessibility. */
8988 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8990 accessibility
= DW_UNSND (attr
);
8992 accessibility
= dwarf2_default_access_attribute (die
, cu
);
8993 switch (accessibility
)
8995 case DW_ACCESS_private
:
8996 fnp
->is_private
= 1;
8998 case DW_ACCESS_protected
:
8999 fnp
->is_protected
= 1;
9003 /* Check for artificial methods. */
9004 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9005 if (attr
&& DW_UNSND (attr
) != 0)
9006 fnp
->is_artificial
= 1;
9008 /* Get index in virtual function table if it is a virtual member
9009 function. For older versions of GCC, this is an offset in the
9010 appropriate virtual table, as specified by DW_AT_containing_type.
9011 For everyone else, it is an expression to be evaluated relative
9012 to the object address. */
9014 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9017 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9019 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9021 /* Old-style GCC. */
9022 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9024 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9025 || (DW_BLOCK (attr
)->size
> 1
9026 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9027 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9029 struct dwarf_block blk
;
9032 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9034 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
9035 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
9036 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9037 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
9038 dwarf2_complex_location_expr_complaint ();
9040 fnp
->voffset
/= cu
->header
.addr_size
;
9044 dwarf2_complex_location_expr_complaint ();
9047 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
9049 else if (attr_form_is_section_offset (attr
))
9051 dwarf2_complex_location_expr_complaint ();
9055 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
9061 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9062 if (attr
&& DW_UNSND (attr
))
9064 /* GCC does this, as of 2008-08-25; PR debug/37237. */
9065 complaint (&symfile_complaints
,
9066 _("Member function \"%s\" (offset %d) is virtual "
9067 "but the vtable offset is not specified"),
9068 fieldname
, die
->offset
.sect_off
);
9069 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9070 TYPE_CPLUS_DYNAMIC (type
) = 1;
9075 /* Create the vector of member function fields, and attach it to the type. */
9078 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
9079 struct dwarf2_cu
*cu
)
9081 struct fnfieldlist
*flp
;
9084 if (cu
->language
== language_ada
)
9085 error (_("unexpected member functions in Ada type"));
9087 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9088 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
9089 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
9091 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
9093 struct nextfnfield
*nfp
= flp
->head
;
9094 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
9097 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
9098 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
9099 fn_flp
->fn_fields
= (struct fn_field
*)
9100 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
9101 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
9102 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
9105 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
9108 /* Returns non-zero if NAME is the name of a vtable member in CU's
9109 language, zero otherwise. */
9111 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
9113 static const char vptr
[] = "_vptr";
9114 static const char vtable
[] = "vtable";
9116 /* Look for the C++ and Java forms of the vtable. */
9117 if ((cu
->language
== language_java
9118 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
9119 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
9120 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
9126 /* GCC outputs unnamed structures that are really pointers to member
9127 functions, with the ABI-specified layout. If TYPE describes
9128 such a structure, smash it into a member function type.
9130 GCC shouldn't do this; it should just output pointer to member DIEs.
9131 This is GCC PR debug/28767. */
9134 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
9136 struct type
*pfn_type
, *domain_type
, *new_type
;
9138 /* Check for a structure with no name and two children. */
9139 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
9142 /* Check for __pfn and __delta members. */
9143 if (TYPE_FIELD_NAME (type
, 0) == NULL
9144 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
9145 || TYPE_FIELD_NAME (type
, 1) == NULL
9146 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
9149 /* Find the type of the method. */
9150 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
9151 if (pfn_type
== NULL
9152 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
9153 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
9156 /* Look for the "this" argument. */
9157 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
9158 if (TYPE_NFIELDS (pfn_type
) == 0
9159 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
9160 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
9163 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9164 new_type
= alloc_type (objfile
);
9165 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9166 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9167 TYPE_VARARGS (pfn_type
));
9168 smash_to_methodptr_type (type
, new_type
);
9171 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
9175 producer_is_icc (struct dwarf2_cu
*cu
)
9177 if (!cu
->checked_producer
)
9178 check_producer (cu
);
9180 return cu
->producer_is_icc
;
9183 /* Called when we find the DIE that starts a structure or union scope
9184 (definition) to create a type for the structure or union. Fill in
9185 the type's name and general properties; the members will not be
9186 processed until process_structure_type.
9188 NOTE: we need to call these functions regardless of whether or not the
9189 DIE has a DW_AT_name attribute, since it might be an anonymous
9190 structure or union. This gets the type entered into our set of
9193 However, if the structure is incomplete (an opaque struct/union)
9194 then suppress creating a symbol table entry for it since gdb only
9195 wants to find the one with the complete definition. Note that if
9196 it is complete, we just call new_symbol, which does it's own
9197 checking about whether the struct/union is anonymous or not (and
9198 suppresses creating a symbol table entry itself). */
9200 static struct type
*
9201 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9203 struct objfile
*objfile
= cu
->objfile
;
9205 struct attribute
*attr
;
9208 /* If the definition of this type lives in .debug_types, read that type.
9209 Don't follow DW_AT_specification though, that will take us back up
9210 the chain and we want to go down. */
9211 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9214 struct dwarf2_cu
*type_cu
= cu
;
9215 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9217 /* We could just recurse on read_structure_type, but we need to call
9218 get_die_type to ensure only one type for this DIE is created.
9219 This is important, for example, because for c++ classes we need
9220 TYPE_NAME set which is only done by new_symbol. Blech. */
9221 type
= read_type_die (type_die
, type_cu
);
9223 /* TYPE_CU may not be the same as CU.
9224 Ensure TYPE is recorded in CU's type_hash table. */
9225 return set_die_type (die
, type
, cu
);
9228 type
= alloc_type (objfile
);
9229 INIT_CPLUS_SPECIFIC (type
);
9231 name
= dwarf2_name (die
, cu
);
9234 if (cu
->language
== language_cplus
9235 || cu
->language
== language_java
)
9237 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9239 /* dwarf2_full_name might have already finished building the DIE's
9240 type. If so, there is no need to continue. */
9241 if (get_die_type (die
, cu
) != NULL
)
9242 return get_die_type (die
, cu
);
9244 TYPE_TAG_NAME (type
) = full_name
;
9245 if (die
->tag
== DW_TAG_structure_type
9246 || die
->tag
== DW_TAG_class_type
)
9247 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9251 /* The name is already allocated along with this objfile, so
9252 we don't need to duplicate it for the type. */
9253 TYPE_TAG_NAME (type
) = (char *) name
;
9254 if (die
->tag
== DW_TAG_class_type
)
9255 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9259 if (die
->tag
== DW_TAG_structure_type
)
9261 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9263 else if (die
->tag
== DW_TAG_union_type
)
9265 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9269 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9272 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9273 TYPE_DECLARED_CLASS (type
) = 1;
9275 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9278 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9282 TYPE_LENGTH (type
) = 0;
9285 if (producer_is_icc (cu
))
9287 /* ICC does not output the required DW_AT_declaration
9288 on incomplete types, but gives them a size of zero. */
9291 TYPE_STUB_SUPPORTED (type
) = 1;
9293 if (die_is_declaration (die
, cu
))
9294 TYPE_STUB (type
) = 1;
9295 else if (attr
== NULL
&& die
->child
== NULL
9296 && producer_is_realview (cu
->producer
))
9297 /* RealView does not output the required DW_AT_declaration
9298 on incomplete types. */
9299 TYPE_STUB (type
) = 1;
9301 /* We need to add the type field to the die immediately so we don't
9302 infinitely recurse when dealing with pointers to the structure
9303 type within the structure itself. */
9304 set_die_type (die
, type
, cu
);
9306 /* set_die_type should be already done. */
9307 set_descriptive_type (type
, die
, cu
);
9312 /* Finish creating a structure or union type, including filling in
9313 its members and creating a symbol for it. */
9316 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9318 struct objfile
*objfile
= cu
->objfile
;
9319 struct die_info
*child_die
= die
->child
;
9322 type
= get_die_type (die
, cu
);
9324 type
= read_structure_type (die
, cu
);
9326 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9328 struct field_info fi
;
9329 struct die_info
*child_die
;
9330 VEC (symbolp
) *template_args
= NULL
;
9331 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9333 memset (&fi
, 0, sizeof (struct field_info
));
9335 child_die
= die
->child
;
9337 while (child_die
&& child_die
->tag
)
9339 if (child_die
->tag
== DW_TAG_member
9340 || child_die
->tag
== DW_TAG_variable
)
9342 /* NOTE: carlton/2002-11-05: A C++ static data member
9343 should be a DW_TAG_member that is a declaration, but
9344 all versions of G++ as of this writing (so through at
9345 least 3.2.1) incorrectly generate DW_TAG_variable
9346 tags for them instead. */
9347 dwarf2_add_field (&fi
, child_die
, cu
);
9349 else if (child_die
->tag
== DW_TAG_subprogram
)
9351 /* C++ member function. */
9352 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9354 else if (child_die
->tag
== DW_TAG_inheritance
)
9356 /* C++ base class field. */
9357 dwarf2_add_field (&fi
, child_die
, cu
);
9359 else if (child_die
->tag
== DW_TAG_typedef
)
9360 dwarf2_add_typedef (&fi
, child_die
, cu
);
9361 else if (child_die
->tag
== DW_TAG_template_type_param
9362 || child_die
->tag
== DW_TAG_template_value_param
)
9364 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9367 VEC_safe_push (symbolp
, template_args
, arg
);
9370 child_die
= sibling_die (child_die
);
9373 /* Attach template arguments to type. */
9374 if (! VEC_empty (symbolp
, template_args
))
9376 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9377 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9378 = VEC_length (symbolp
, template_args
);
9379 TYPE_TEMPLATE_ARGUMENTS (type
)
9380 = obstack_alloc (&objfile
->objfile_obstack
,
9381 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9382 * sizeof (struct symbol
*)));
9383 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9384 VEC_address (symbolp
, template_args
),
9385 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9386 * sizeof (struct symbol
*)));
9387 VEC_free (symbolp
, template_args
);
9390 /* Attach fields and member functions to the type. */
9392 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9395 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9397 /* Get the type which refers to the base class (possibly this
9398 class itself) which contains the vtable pointer for the current
9399 class from the DW_AT_containing_type attribute. This use of
9400 DW_AT_containing_type is a GNU extension. */
9402 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9404 struct type
*t
= die_containing_type (die
, cu
);
9406 TYPE_VPTR_BASETYPE (type
) = t
;
9411 /* Our own class provides vtbl ptr. */
9412 for (i
= TYPE_NFIELDS (t
) - 1;
9413 i
>= TYPE_N_BASECLASSES (t
);
9416 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9418 if (is_vtable_name (fieldname
, cu
))
9420 TYPE_VPTR_FIELDNO (type
) = i
;
9425 /* Complain if virtual function table field not found. */
9426 if (i
< TYPE_N_BASECLASSES (t
))
9427 complaint (&symfile_complaints
,
9428 _("virtual function table pointer "
9429 "not found when defining class '%s'"),
9430 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9435 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9438 else if (cu
->producer
9439 && strncmp (cu
->producer
,
9440 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9442 /* The IBM XLC compiler does not provide direct indication
9443 of the containing type, but the vtable pointer is
9444 always named __vfp. */
9448 for (i
= TYPE_NFIELDS (type
) - 1;
9449 i
>= TYPE_N_BASECLASSES (type
);
9452 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9454 TYPE_VPTR_FIELDNO (type
) = i
;
9455 TYPE_VPTR_BASETYPE (type
) = type
;
9462 /* Copy fi.typedef_field_list linked list elements content into the
9463 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9464 if (fi
.typedef_field_list
)
9466 int i
= fi
.typedef_field_list_count
;
9468 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9469 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9470 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9471 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9473 /* Reverse the list order to keep the debug info elements order. */
9476 struct typedef_field
*dest
, *src
;
9478 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9479 src
= &fi
.typedef_field_list
->field
;
9480 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9485 do_cleanups (back_to
);
9487 if (HAVE_CPLUS_STRUCT (type
))
9488 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9491 quirk_gcc_member_function_pointer (type
, objfile
);
9493 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9494 snapshots) has been known to create a die giving a declaration
9495 for a class that has, as a child, a die giving a definition for a
9496 nested class. So we have to process our children even if the
9497 current die is a declaration. Normally, of course, a declaration
9498 won't have any children at all. */
9500 while (child_die
!= NULL
&& child_die
->tag
)
9502 if (child_die
->tag
== DW_TAG_member
9503 || child_die
->tag
== DW_TAG_variable
9504 || child_die
->tag
== DW_TAG_inheritance
9505 || child_die
->tag
== DW_TAG_template_value_param
9506 || child_die
->tag
== DW_TAG_template_type_param
)
9511 process_die (child_die
, cu
);
9513 child_die
= sibling_die (child_die
);
9516 /* Do not consider external references. According to the DWARF standard,
9517 these DIEs are identified by the fact that they have no byte_size
9518 attribute, and a declaration attribute. */
9519 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9520 || !die_is_declaration (die
, cu
))
9521 new_symbol (die
, type
, cu
);
9524 /* Given a DW_AT_enumeration_type die, set its type. We do not
9525 complete the type's fields yet, or create any symbols. */
9527 static struct type
*
9528 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9530 struct objfile
*objfile
= cu
->objfile
;
9532 struct attribute
*attr
;
9535 /* If the definition of this type lives in .debug_types, read that type.
9536 Don't follow DW_AT_specification though, that will take us back up
9537 the chain and we want to go down. */
9538 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9541 struct dwarf2_cu
*type_cu
= cu
;
9542 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9544 type
= read_type_die (type_die
, type_cu
);
9546 /* TYPE_CU may not be the same as CU.
9547 Ensure TYPE is recorded in CU's type_hash table. */
9548 return set_die_type (die
, type
, cu
);
9551 type
= alloc_type (objfile
);
9553 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9554 name
= dwarf2_full_name (NULL
, die
, cu
);
9556 TYPE_TAG_NAME (type
) = (char *) name
;
9558 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9561 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9565 TYPE_LENGTH (type
) = 0;
9568 /* The enumeration DIE can be incomplete. In Ada, any type can be
9569 declared as private in the package spec, and then defined only
9570 inside the package body. Such types are known as Taft Amendment
9571 Types. When another package uses such a type, an incomplete DIE
9572 may be generated by the compiler. */
9573 if (die_is_declaration (die
, cu
))
9574 TYPE_STUB (type
) = 1;
9576 return set_die_type (die
, type
, cu
);
9579 /* Given a pointer to a die which begins an enumeration, process all
9580 the dies that define the members of the enumeration, and create the
9581 symbol for the enumeration type.
9583 NOTE: We reverse the order of the element list. */
9586 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9588 struct type
*this_type
;
9590 this_type
= get_die_type (die
, cu
);
9591 if (this_type
== NULL
)
9592 this_type
= read_enumeration_type (die
, cu
);
9594 if (die
->child
!= NULL
)
9596 struct die_info
*child_die
;
9598 struct field
*fields
= NULL
;
9600 int unsigned_enum
= 1;
9605 child_die
= die
->child
;
9606 while (child_die
&& child_die
->tag
)
9608 if (child_die
->tag
!= DW_TAG_enumerator
)
9610 process_die (child_die
, cu
);
9614 name
= dwarf2_name (child_die
, cu
);
9617 sym
= new_symbol (child_die
, this_type
, cu
);
9618 if (SYMBOL_VALUE (sym
) < 0)
9623 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9626 mask
|= SYMBOL_VALUE (sym
);
9628 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9630 fields
= (struct field
*)
9632 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9633 * sizeof (struct field
));
9636 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9637 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9638 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9639 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9645 child_die
= sibling_die (child_die
);
9650 TYPE_NFIELDS (this_type
) = num_fields
;
9651 TYPE_FIELDS (this_type
) = (struct field
*)
9652 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9653 memcpy (TYPE_FIELDS (this_type
), fields
,
9654 sizeof (struct field
) * num_fields
);
9658 TYPE_UNSIGNED (this_type
) = 1;
9660 TYPE_FLAG_ENUM (this_type
) = 1;
9663 /* If we are reading an enum from a .debug_types unit, and the enum
9664 is a declaration, and the enum is not the signatured type in the
9665 unit, then we do not want to add a symbol for it. Adding a
9666 symbol would in some cases obscure the true definition of the
9667 enum, giving users an incomplete type when the definition is
9668 actually available. Note that we do not want to do this for all
9669 enums which are just declarations, because C++0x allows forward
9670 enum declarations. */
9671 if (cu
->per_cu
->is_debug_types
9672 && die_is_declaration (die
, cu
))
9674 struct signatured_type
*sig_type
;
9677 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9678 cu
->per_cu
->info_or_types_section
,
9679 cu
->per_cu
->offset
);
9680 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9681 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9685 new_symbol (die
, this_type
, cu
);
9688 /* Extract all information from a DW_TAG_array_type DIE and put it in
9689 the DIE's type field. For now, this only handles one dimensional
9692 static struct type
*
9693 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9695 struct objfile
*objfile
= cu
->objfile
;
9696 struct die_info
*child_die
;
9698 struct type
*element_type
, *range_type
, *index_type
;
9699 struct type
**range_types
= NULL
;
9700 struct attribute
*attr
;
9702 struct cleanup
*back_to
;
9705 element_type
= die_type (die
, cu
);
9707 /* The die_type call above may have already set the type for this DIE. */
9708 type
= get_die_type (die
, cu
);
9712 /* Irix 6.2 native cc creates array types without children for
9713 arrays with unspecified length. */
9714 if (die
->child
== NULL
)
9716 index_type
= objfile_type (objfile
)->builtin_int
;
9717 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9718 type
= create_array_type (NULL
, element_type
, range_type
);
9719 return set_die_type (die
, type
, cu
);
9722 back_to
= make_cleanup (null_cleanup
, NULL
);
9723 child_die
= die
->child
;
9724 while (child_die
&& child_die
->tag
)
9726 if (child_die
->tag
== DW_TAG_subrange_type
)
9728 struct type
*child_type
= read_type_die (child_die
, cu
);
9730 if (child_type
!= NULL
)
9732 /* The range type was succesfully read. Save it for the
9733 array type creation. */
9734 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9736 range_types
= (struct type
**)
9737 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9738 * sizeof (struct type
*));
9740 make_cleanup (free_current_contents
, &range_types
);
9742 range_types
[ndim
++] = child_type
;
9745 child_die
= sibling_die (child_die
);
9748 /* Dwarf2 dimensions are output from left to right, create the
9749 necessary array types in backwards order. */
9751 type
= element_type
;
9753 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9758 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9763 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9766 /* Understand Dwarf2 support for vector types (like they occur on
9767 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9768 array type. This is not part of the Dwarf2/3 standard yet, but a
9769 custom vendor extension. The main difference between a regular
9770 array and the vector variant is that vectors are passed by value
9772 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9774 make_vector_type (type
);
9776 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9777 implementation may choose to implement triple vectors using this
9779 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9782 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9783 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9785 complaint (&symfile_complaints
,
9786 _("DW_AT_byte_size for array type smaller "
9787 "than the total size of elements"));
9790 name
= dwarf2_name (die
, cu
);
9792 TYPE_NAME (type
) = name
;
9794 /* Install the type in the die. */
9795 set_die_type (die
, type
, cu
);
9797 /* set_die_type should be already done. */
9798 set_descriptive_type (type
, die
, cu
);
9800 do_cleanups (back_to
);
9805 static enum dwarf_array_dim_ordering
9806 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9808 struct attribute
*attr
;
9810 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9812 if (attr
) return DW_SND (attr
);
9814 /* GNU F77 is a special case, as at 08/2004 array type info is the
9815 opposite order to the dwarf2 specification, but data is still
9816 laid out as per normal fortran.
9818 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9819 version checking. */
9821 if (cu
->language
== language_fortran
9822 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9824 return DW_ORD_row_major
;
9827 switch (cu
->language_defn
->la_array_ordering
)
9829 case array_column_major
:
9830 return DW_ORD_col_major
;
9831 case array_row_major
:
9833 return DW_ORD_row_major
;
9837 /* Extract all information from a DW_TAG_set_type DIE and put it in
9838 the DIE's type field. */
9840 static struct type
*
9841 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9843 struct type
*domain_type
, *set_type
;
9844 struct attribute
*attr
;
9846 domain_type
= die_type (die
, cu
);
9848 /* The die_type call above may have already set the type for this DIE. */
9849 set_type
= get_die_type (die
, cu
);
9853 set_type
= create_set_type (NULL
, domain_type
);
9855 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9857 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9859 return set_die_type (die
, set_type
, cu
);
9862 /* First cut: install each common block member as a global variable. */
9865 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9867 struct die_info
*child_die
;
9868 struct attribute
*attr
;
9870 CORE_ADDR base
= (CORE_ADDR
) 0;
9872 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9875 /* Support the .debug_loc offsets. */
9876 if (attr_form_is_block (attr
))
9878 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9880 else if (attr_form_is_section_offset (attr
))
9882 dwarf2_complex_location_expr_complaint ();
9886 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9887 "common block member");
9890 if (die
->child
!= NULL
)
9892 child_die
= die
->child
;
9893 while (child_die
&& child_die
->tag
)
9897 sym
= new_symbol (child_die
, NULL
, cu
);
9899 && handle_data_member_location (child_die
, cu
, &offset
))
9901 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9902 add_symbol_to_list (sym
, &global_symbols
);
9904 child_die
= sibling_die (child_die
);
9909 /* Create a type for a C++ namespace. */
9911 static struct type
*
9912 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9914 struct objfile
*objfile
= cu
->objfile
;
9915 const char *previous_prefix
, *name
;
9919 /* For extensions, reuse the type of the original namespace. */
9920 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9922 struct die_info
*ext_die
;
9923 struct dwarf2_cu
*ext_cu
= cu
;
9925 ext_die
= dwarf2_extension (die
, &ext_cu
);
9926 type
= read_type_die (ext_die
, ext_cu
);
9928 /* EXT_CU may not be the same as CU.
9929 Ensure TYPE is recorded in CU's type_hash table. */
9930 return set_die_type (die
, type
, cu
);
9933 name
= namespace_name (die
, &is_anonymous
, cu
);
9935 /* Now build the name of the current namespace. */
9937 previous_prefix
= determine_prefix (die
, cu
);
9938 if (previous_prefix
[0] != '\0')
9939 name
= typename_concat (&objfile
->objfile_obstack
,
9940 previous_prefix
, name
, 0, cu
);
9942 /* Create the type. */
9943 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
9945 TYPE_NAME (type
) = (char *) name
;
9946 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
9948 return set_die_type (die
, type
, cu
);
9951 /* Read a C++ namespace. */
9954 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9956 struct objfile
*objfile
= cu
->objfile
;
9959 /* Add a symbol associated to this if we haven't seen the namespace
9960 before. Also, add a using directive if it's an anonymous
9963 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
9967 type
= read_type_die (die
, cu
);
9968 new_symbol (die
, type
, cu
);
9970 namespace_name (die
, &is_anonymous
, cu
);
9973 const char *previous_prefix
= determine_prefix (die
, cu
);
9975 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
9976 NULL
, NULL
, &objfile
->objfile_obstack
);
9980 if (die
->child
!= NULL
)
9982 struct die_info
*child_die
= die
->child
;
9984 while (child_die
&& child_die
->tag
)
9986 process_die (child_die
, cu
);
9987 child_die
= sibling_die (child_die
);
9992 /* Read a Fortran module as type. This DIE can be only a declaration used for
9993 imported module. Still we need that type as local Fortran "use ... only"
9994 declaration imports depend on the created type in determine_prefix. */
9996 static struct type
*
9997 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9999 struct objfile
*objfile
= cu
->objfile
;
10003 module_name
= dwarf2_name (die
, cu
);
10005 complaint (&symfile_complaints
,
10006 _("DW_TAG_module has no name, offset 0x%x"),
10007 die
->offset
.sect_off
);
10008 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10010 /* determine_prefix uses TYPE_TAG_NAME. */
10011 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10013 return set_die_type (die
, type
, cu
);
10016 /* Read a Fortran module. */
10019 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10021 struct die_info
*child_die
= die
->child
;
10023 while (child_die
&& child_die
->tag
)
10025 process_die (child_die
, cu
);
10026 child_die
= sibling_die (child_die
);
10030 /* Return the name of the namespace represented by DIE. Set
10031 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
10034 static const char *
10035 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
10037 struct die_info
*current_die
;
10038 const char *name
= NULL
;
10040 /* Loop through the extensions until we find a name. */
10042 for (current_die
= die
;
10043 current_die
!= NULL
;
10044 current_die
= dwarf2_extension (die
, &cu
))
10046 name
= dwarf2_name (current_die
, cu
);
10051 /* Is it an anonymous namespace? */
10053 *is_anonymous
= (name
== NULL
);
10055 name
= CP_ANONYMOUS_NAMESPACE_STR
;
10060 /* Extract all information from a DW_TAG_pointer_type DIE and add to
10061 the user defined type vector. */
10063 static struct type
*
10064 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10066 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
10067 struct comp_unit_head
*cu_header
= &cu
->header
;
10069 struct attribute
*attr_byte_size
;
10070 struct attribute
*attr_address_class
;
10071 int byte_size
, addr_class
;
10072 struct type
*target_type
;
10074 target_type
= die_type (die
, cu
);
10076 /* The die_type call above may have already set the type for this DIE. */
10077 type
= get_die_type (die
, cu
);
10081 type
= lookup_pointer_type (target_type
);
10083 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10084 if (attr_byte_size
)
10085 byte_size
= DW_UNSND (attr_byte_size
);
10087 byte_size
= cu_header
->addr_size
;
10089 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
10090 if (attr_address_class
)
10091 addr_class
= DW_UNSND (attr_address_class
);
10093 addr_class
= DW_ADDR_none
;
10095 /* If the pointer size or address class is different than the
10096 default, create a type variant marked as such and set the
10097 length accordingly. */
10098 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
10100 if (gdbarch_address_class_type_flags_p (gdbarch
))
10104 type_flags
= gdbarch_address_class_type_flags
10105 (gdbarch
, byte_size
, addr_class
);
10106 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
10108 type
= make_type_with_address_space (type
, type_flags
);
10110 else if (TYPE_LENGTH (type
) != byte_size
)
10112 complaint (&symfile_complaints
,
10113 _("invalid pointer size %d"), byte_size
);
10117 /* Should we also complain about unhandled address classes? */
10121 TYPE_LENGTH (type
) = byte_size
;
10122 return set_die_type (die
, type
, cu
);
10125 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
10126 the user defined type vector. */
10128 static struct type
*
10129 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10132 struct type
*to_type
;
10133 struct type
*domain
;
10135 to_type
= die_type (die
, cu
);
10136 domain
= die_containing_type (die
, cu
);
10138 /* The calls above may have already set the type for this DIE. */
10139 type
= get_die_type (die
, cu
);
10143 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
10144 type
= lookup_methodptr_type (to_type
);
10146 type
= lookup_memberptr_type (to_type
, domain
);
10148 return set_die_type (die
, type
, cu
);
10151 /* Extract all information from a DW_TAG_reference_type DIE and add to
10152 the user defined type vector. */
10154 static struct type
*
10155 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10157 struct comp_unit_head
*cu_header
= &cu
->header
;
10158 struct type
*type
, *target_type
;
10159 struct attribute
*attr
;
10161 target_type
= die_type (die
, cu
);
10163 /* The die_type call above may have already set the type for this DIE. */
10164 type
= get_die_type (die
, cu
);
10168 type
= lookup_reference_type (target_type
);
10169 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10172 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10176 TYPE_LENGTH (type
) = cu_header
->addr_size
;
10178 return set_die_type (die
, type
, cu
);
10181 static struct type
*
10182 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10184 struct type
*base_type
, *cv_type
;
10186 base_type
= die_type (die
, cu
);
10188 /* The die_type call above may have already set the type for this DIE. */
10189 cv_type
= get_die_type (die
, cu
);
10193 /* In case the const qualifier is applied to an array type, the element type
10194 is so qualified, not the array type (section 6.7.3 of C99). */
10195 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10197 struct type
*el_type
, *inner_array
;
10199 base_type
= copy_type (base_type
);
10200 inner_array
= base_type
;
10202 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10204 TYPE_TARGET_TYPE (inner_array
) =
10205 copy_type (TYPE_TARGET_TYPE (inner_array
));
10206 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10209 el_type
= TYPE_TARGET_TYPE (inner_array
);
10210 TYPE_TARGET_TYPE (inner_array
) =
10211 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10213 return set_die_type (die
, base_type
, cu
);
10216 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10217 return set_die_type (die
, cv_type
, cu
);
10220 static struct type
*
10221 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10223 struct type
*base_type
, *cv_type
;
10225 base_type
= die_type (die
, cu
);
10227 /* The die_type call above may have already set the type for this DIE. */
10228 cv_type
= get_die_type (die
, cu
);
10232 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10233 return set_die_type (die
, cv_type
, cu
);
10236 /* Extract all information from a DW_TAG_string_type DIE and add to
10237 the user defined type vector. It isn't really a user defined type,
10238 but it behaves like one, with other DIE's using an AT_user_def_type
10239 attribute to reference it. */
10241 static struct type
*
10242 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10244 struct objfile
*objfile
= cu
->objfile
;
10245 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10246 struct type
*type
, *range_type
, *index_type
, *char_type
;
10247 struct attribute
*attr
;
10248 unsigned int length
;
10250 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10253 length
= DW_UNSND (attr
);
10257 /* Check for the DW_AT_byte_size attribute. */
10258 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10261 length
= DW_UNSND (attr
);
10269 index_type
= objfile_type (objfile
)->builtin_int
;
10270 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10271 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10272 type
= create_string_type (NULL
, char_type
, range_type
);
10274 return set_die_type (die
, type
, cu
);
10277 /* Handle DIES due to C code like:
10281 int (*funcp)(int a, long l);
10285 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10287 static struct type
*
10288 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10290 struct objfile
*objfile
= cu
->objfile
;
10291 struct type
*type
; /* Type that this function returns. */
10292 struct type
*ftype
; /* Function that returns above type. */
10293 struct attribute
*attr
;
10295 type
= die_type (die
, cu
);
10297 /* The die_type call above may have already set the type for this DIE. */
10298 ftype
= get_die_type (die
, cu
);
10302 ftype
= lookup_function_type (type
);
10304 /* All functions in C++, Pascal and Java have prototypes. */
10305 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10306 if ((attr
&& (DW_UNSND (attr
) != 0))
10307 || cu
->language
== language_cplus
10308 || cu
->language
== language_java
10309 || cu
->language
== language_pascal
)
10310 TYPE_PROTOTYPED (ftype
) = 1;
10311 else if (producer_is_realview (cu
->producer
))
10312 /* RealView does not emit DW_AT_prototyped. We can not
10313 distinguish prototyped and unprototyped functions; default to
10314 prototyped, since that is more common in modern code (and
10315 RealView warns about unprototyped functions). */
10316 TYPE_PROTOTYPED (ftype
) = 1;
10318 /* Store the calling convention in the type if it's available in
10319 the subroutine die. Otherwise set the calling convention to
10320 the default value DW_CC_normal. */
10321 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10323 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10324 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10325 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10327 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10329 /* We need to add the subroutine type to the die immediately so
10330 we don't infinitely recurse when dealing with parameters
10331 declared as the same subroutine type. */
10332 set_die_type (die
, ftype
, cu
);
10334 if (die
->child
!= NULL
)
10336 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10337 struct die_info
*child_die
;
10338 int nparams
, iparams
;
10340 /* Count the number of parameters.
10341 FIXME: GDB currently ignores vararg functions, but knows about
10342 vararg member functions. */
10344 child_die
= die
->child
;
10345 while (child_die
&& child_die
->tag
)
10347 if (child_die
->tag
== DW_TAG_formal_parameter
)
10349 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10350 TYPE_VARARGS (ftype
) = 1;
10351 child_die
= sibling_die (child_die
);
10354 /* Allocate storage for parameters and fill them in. */
10355 TYPE_NFIELDS (ftype
) = nparams
;
10356 TYPE_FIELDS (ftype
) = (struct field
*)
10357 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10359 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10360 even if we error out during the parameters reading below. */
10361 for (iparams
= 0; iparams
< nparams
; iparams
++)
10362 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10365 child_die
= die
->child
;
10366 while (child_die
&& child_die
->tag
)
10368 if (child_die
->tag
== DW_TAG_formal_parameter
)
10370 struct type
*arg_type
;
10372 /* DWARF version 2 has no clean way to discern C++
10373 static and non-static member functions. G++ helps
10374 GDB by marking the first parameter for non-static
10375 member functions (which is the this pointer) as
10376 artificial. We pass this information to
10377 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10379 DWARF version 3 added DW_AT_object_pointer, which GCC
10380 4.5 does not yet generate. */
10381 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10383 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10386 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10388 /* GCC/43521: In java, the formal parameter
10389 "this" is sometimes not marked with DW_AT_artificial. */
10390 if (cu
->language
== language_java
)
10392 const char *name
= dwarf2_name (child_die
, cu
);
10394 if (name
&& !strcmp (name
, "this"))
10395 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10398 arg_type
= die_type (child_die
, cu
);
10400 /* RealView does not mark THIS as const, which the testsuite
10401 expects. GCC marks THIS as const in method definitions,
10402 but not in the class specifications (GCC PR 43053). */
10403 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10404 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10407 struct dwarf2_cu
*arg_cu
= cu
;
10408 const char *name
= dwarf2_name (child_die
, cu
);
10410 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10413 /* If the compiler emits this, use it. */
10414 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10417 else if (name
&& strcmp (name
, "this") == 0)
10418 /* Function definitions will have the argument names. */
10420 else if (name
== NULL
&& iparams
== 0)
10421 /* Declarations may not have the names, so like
10422 elsewhere in GDB, assume an artificial first
10423 argument is "this". */
10427 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10431 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10434 child_die
= sibling_die (child_die
);
10441 static struct type
*
10442 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10444 struct objfile
*objfile
= cu
->objfile
;
10445 const char *name
= NULL
;
10446 struct type
*this_type
, *target_type
;
10448 name
= dwarf2_full_name (NULL
, die
, cu
);
10449 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10450 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10451 TYPE_NAME (this_type
) = (char *) name
;
10452 set_die_type (die
, this_type
, cu
);
10453 target_type
= die_type (die
, cu
);
10454 if (target_type
!= this_type
)
10455 TYPE_TARGET_TYPE (this_type
) = target_type
;
10458 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10459 spec and cause infinite loops in GDB. */
10460 complaint (&symfile_complaints
,
10461 _("Self-referential DW_TAG_typedef "
10462 "- DIE at 0x%x [in module %s]"),
10463 die
->offset
.sect_off
, objfile
->name
);
10464 TYPE_TARGET_TYPE (this_type
) = NULL
;
10469 /* Find a representation of a given base type and install
10470 it in the TYPE field of the die. */
10472 static struct type
*
10473 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10475 struct objfile
*objfile
= cu
->objfile
;
10477 struct attribute
*attr
;
10478 int encoding
= 0, size
= 0;
10480 enum type_code code
= TYPE_CODE_INT
;
10481 int type_flags
= 0;
10482 struct type
*target_type
= NULL
;
10484 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10487 encoding
= DW_UNSND (attr
);
10489 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10492 size
= DW_UNSND (attr
);
10494 name
= dwarf2_name (die
, cu
);
10497 complaint (&symfile_complaints
,
10498 _("DW_AT_name missing from DW_TAG_base_type"));
10503 case DW_ATE_address
:
10504 /* Turn DW_ATE_address into a void * pointer. */
10505 code
= TYPE_CODE_PTR
;
10506 type_flags
|= TYPE_FLAG_UNSIGNED
;
10507 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10509 case DW_ATE_boolean
:
10510 code
= TYPE_CODE_BOOL
;
10511 type_flags
|= TYPE_FLAG_UNSIGNED
;
10513 case DW_ATE_complex_float
:
10514 code
= TYPE_CODE_COMPLEX
;
10515 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10517 case DW_ATE_decimal_float
:
10518 code
= TYPE_CODE_DECFLOAT
;
10521 code
= TYPE_CODE_FLT
;
10523 case DW_ATE_signed
:
10525 case DW_ATE_unsigned
:
10526 type_flags
|= TYPE_FLAG_UNSIGNED
;
10527 if (cu
->language
== language_fortran
10529 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10530 code
= TYPE_CODE_CHAR
;
10532 case DW_ATE_signed_char
:
10533 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10534 || cu
->language
== language_pascal
10535 || cu
->language
== language_fortran
)
10536 code
= TYPE_CODE_CHAR
;
10538 case DW_ATE_unsigned_char
:
10539 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10540 || cu
->language
== language_pascal
10541 || cu
->language
== language_fortran
)
10542 code
= TYPE_CODE_CHAR
;
10543 type_flags
|= TYPE_FLAG_UNSIGNED
;
10546 /* We just treat this as an integer and then recognize the
10547 type by name elsewhere. */
10551 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10552 dwarf_type_encoding_name (encoding
));
10556 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10557 TYPE_NAME (type
) = name
;
10558 TYPE_TARGET_TYPE (type
) = target_type
;
10560 if (name
&& strcmp (name
, "char") == 0)
10561 TYPE_NOSIGN (type
) = 1;
10563 return set_die_type (die
, type
, cu
);
10566 /* Read the given DW_AT_subrange DIE. */
10568 static struct type
*
10569 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10571 struct type
*base_type
;
10572 struct type
*range_type
;
10573 struct attribute
*attr
;
10575 int low_default_is_valid
;
10577 LONGEST negative_mask
;
10579 base_type
= die_type (die
, cu
);
10580 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10581 check_typedef (base_type
);
10583 /* The die_type call above may have already set the type for this DIE. */
10584 range_type
= get_die_type (die
, cu
);
10588 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10589 omitting DW_AT_lower_bound. */
10590 switch (cu
->language
)
10593 case language_cplus
:
10595 low_default_is_valid
= 1;
10597 case language_fortran
:
10599 low_default_is_valid
= 1;
10602 case language_java
:
10603 case language_objc
:
10605 low_default_is_valid
= (cu
->header
.version
>= 4);
10609 case language_pascal
:
10611 low_default_is_valid
= (cu
->header
.version
>= 4);
10615 low_default_is_valid
= 0;
10619 /* FIXME: For variable sized arrays either of these could be
10620 a variable rather than a constant value. We'll allow it,
10621 but we don't know how to handle it. */
10622 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10624 low
= dwarf2_get_attr_constant_value (attr
, low
);
10625 else if (!low_default_is_valid
)
10626 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10627 "- DIE at 0x%x [in module %s]"),
10628 die
->offset
.sect_off
, cu
->objfile
->name
);
10630 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10633 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10635 /* GCC encodes arrays with unspecified or dynamic length
10636 with a DW_FORM_block1 attribute or a reference attribute.
10637 FIXME: GDB does not yet know how to handle dynamic
10638 arrays properly, treat them as arrays with unspecified
10641 FIXME: jimb/2003-09-22: GDB does not really know
10642 how to handle arrays of unspecified length
10643 either; we just represent them as zero-length
10644 arrays. Choose an appropriate upper bound given
10645 the lower bound we've computed above. */
10649 high
= dwarf2_get_attr_constant_value (attr
, 1);
10653 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10656 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10657 high
= low
+ count
- 1;
10661 /* Unspecified array length. */
10666 /* Dwarf-2 specifications explicitly allows to create subrange types
10667 without specifying a base type.
10668 In that case, the base type must be set to the type of
10669 the lower bound, upper bound or count, in that order, if any of these
10670 three attributes references an object that has a type.
10671 If no base type is found, the Dwarf-2 specifications say that
10672 a signed integer type of size equal to the size of an address should
10674 For the following C code: `extern char gdb_int [];'
10675 GCC produces an empty range DIE.
10676 FIXME: muller/2010-05-28: Possible references to object for low bound,
10677 high bound or count are not yet handled by this code. */
10678 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10680 struct objfile
*objfile
= cu
->objfile
;
10681 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10682 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10683 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10685 /* Test "int", "long int", and "long long int" objfile types,
10686 and select the first one having a size above or equal to the
10687 architecture address size. */
10688 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10689 base_type
= int_type
;
10692 int_type
= objfile_type (objfile
)->builtin_long
;
10693 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10694 base_type
= int_type
;
10697 int_type
= objfile_type (objfile
)->builtin_long_long
;
10698 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10699 base_type
= int_type
;
10705 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10706 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10707 low
|= negative_mask
;
10708 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10709 high
|= negative_mask
;
10711 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10713 /* Mark arrays with dynamic length at least as an array of unspecified
10714 length. GDB could check the boundary but before it gets implemented at
10715 least allow accessing the array elements. */
10716 if (attr
&& attr_form_is_block (attr
))
10717 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10719 /* Ada expects an empty array on no boundary attributes. */
10720 if (attr
== NULL
&& cu
->language
!= language_ada
)
10721 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10723 name
= dwarf2_name (die
, cu
);
10725 TYPE_NAME (range_type
) = name
;
10727 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10729 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10731 set_die_type (die
, range_type
, cu
);
10733 /* set_die_type should be already done. */
10734 set_descriptive_type (range_type
, die
, cu
);
10739 static struct type
*
10740 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10744 /* For now, we only support the C meaning of an unspecified type: void. */
10746 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10747 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10749 return set_die_type (die
, type
, cu
);
10752 /* Read a single die and all its descendents. Set the die's sibling
10753 field to NULL; set other fields in the die correctly, and set all
10754 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10755 location of the info_ptr after reading all of those dies. PARENT
10756 is the parent of the die in question. */
10758 static struct die_info
*
10759 read_die_and_children (const struct die_reader_specs
*reader
,
10760 gdb_byte
*info_ptr
,
10761 gdb_byte
**new_info_ptr
,
10762 struct die_info
*parent
)
10764 struct die_info
*die
;
10768 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10771 *new_info_ptr
= cur_ptr
;
10774 store_in_ref_table (die
, reader
->cu
);
10777 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10781 *new_info_ptr
= cur_ptr
;
10784 die
->sibling
= NULL
;
10785 die
->parent
= parent
;
10789 /* Read a die, all of its descendents, and all of its siblings; set
10790 all of the fields of all of the dies correctly. Arguments are as
10791 in read_die_and_children. */
10793 static struct die_info
*
10794 read_die_and_siblings (const struct die_reader_specs
*reader
,
10795 gdb_byte
*info_ptr
,
10796 gdb_byte
**new_info_ptr
,
10797 struct die_info
*parent
)
10799 struct die_info
*first_die
, *last_sibling
;
10802 cur_ptr
= info_ptr
;
10803 first_die
= last_sibling
= NULL
;
10807 struct die_info
*die
10808 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10812 *new_info_ptr
= cur_ptr
;
10819 last_sibling
->sibling
= die
;
10821 last_sibling
= die
;
10825 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10827 The caller is responsible for filling in the extra attributes
10828 and updating (*DIEP)->num_attrs.
10829 Set DIEP to point to a newly allocated die with its information,
10830 except for its child, sibling, and parent fields.
10831 Set HAS_CHILDREN to tell whether the die has children or not. */
10834 read_full_die_1 (const struct die_reader_specs
*reader
,
10835 struct die_info
**diep
, gdb_byte
*info_ptr
,
10836 int *has_children
, int num_extra_attrs
)
10838 unsigned int abbrev_number
, bytes_read
, i
;
10839 sect_offset offset
;
10840 struct abbrev_info
*abbrev
;
10841 struct die_info
*die
;
10842 struct dwarf2_cu
*cu
= reader
->cu
;
10843 bfd
*abfd
= reader
->abfd
;
10845 offset
.sect_off
= info_ptr
- reader
->buffer
;
10846 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10847 info_ptr
+= bytes_read
;
10848 if (!abbrev_number
)
10855 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10857 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10859 bfd_get_filename (abfd
));
10861 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10862 die
->offset
= offset
;
10863 die
->tag
= abbrev
->tag
;
10864 die
->abbrev
= abbrev_number
;
10866 /* Make the result usable.
10867 The caller needs to update num_attrs after adding the extra
10869 die
->num_attrs
= abbrev
->num_attrs
;
10871 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10872 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10876 *has_children
= abbrev
->has_children
;
10880 /* Read a die and all its attributes.
10881 Set DIEP to point to a newly allocated die with its information,
10882 except for its child, sibling, and parent fields.
10883 Set HAS_CHILDREN to tell whether the die has children or not. */
10886 read_full_die (const struct die_reader_specs
*reader
,
10887 struct die_info
**diep
, gdb_byte
*info_ptr
,
10890 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10893 /* In DWARF version 2, the description of the debugging information is
10894 stored in a separate .debug_abbrev section. Before we read any
10895 dies from a section we read in all abbreviations and install them
10896 in a hash table. This function also sets flags in CU describing
10897 the data found in the abbrev table. */
10900 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10901 struct dwarf2_section_info
*abbrev_section
)
10904 bfd
*abfd
= abbrev_section
->asection
->owner
;
10905 struct comp_unit_head
*cu_header
= &cu
->header
;
10906 gdb_byte
*abbrev_ptr
;
10907 struct abbrev_info
*cur_abbrev
;
10908 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10909 unsigned int abbrev_form
, hash_number
;
10910 struct attr_abbrev
*cur_attrs
;
10911 unsigned int allocated_attrs
;
10913 /* Initialize dwarf2 abbrevs. */
10914 obstack_init (&cu
->abbrev_obstack
);
10915 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10917 * sizeof (struct abbrev_info
*)));
10918 memset (cu
->dwarf2_abbrevs
, 0,
10919 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10921 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10922 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10923 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10924 abbrev_ptr
+= bytes_read
;
10926 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10927 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
10929 /* Loop until we reach an abbrev number of 0. */
10930 while (abbrev_number
)
10932 cur_abbrev
= dwarf_alloc_abbrev (cu
);
10934 /* read in abbrev header */
10935 cur_abbrev
->number
= abbrev_number
;
10936 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10937 abbrev_ptr
+= bytes_read
;
10938 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
10941 /* now read in declarations */
10942 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10943 abbrev_ptr
+= bytes_read
;
10944 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10945 abbrev_ptr
+= bytes_read
;
10946 while (abbrev_name
)
10948 if (cur_abbrev
->num_attrs
== allocated_attrs
)
10950 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
10952 = xrealloc (cur_attrs
, (allocated_attrs
10953 * sizeof (struct attr_abbrev
)));
10956 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
10957 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
10958 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10959 abbrev_ptr
+= bytes_read
;
10960 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10961 abbrev_ptr
+= bytes_read
;
10964 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
10965 (cur_abbrev
->num_attrs
10966 * sizeof (struct attr_abbrev
)));
10967 memcpy (cur_abbrev
->attrs
, cur_attrs
,
10968 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
10970 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
10971 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
10972 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
10974 /* Get next abbreviation.
10975 Under Irix6 the abbreviations for a compilation unit are not
10976 always properly terminated with an abbrev number of 0.
10977 Exit loop if we encounter an abbreviation which we have
10978 already read (which means we are about to read the abbreviations
10979 for the next compile unit) or if the end of the abbreviation
10980 table is reached. */
10981 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
10982 >= abbrev_section
->size
)
10984 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10985 abbrev_ptr
+= bytes_read
;
10986 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
10993 /* Release the memory used by the abbrev table for a compilation unit. */
10996 dwarf2_free_abbrev_table (void *ptr_to_cu
)
10998 struct dwarf2_cu
*cu
= ptr_to_cu
;
11000 obstack_free (&cu
->abbrev_obstack
, NULL
);
11001 cu
->dwarf2_abbrevs
= NULL
;
11004 /* Lookup an abbrev_info structure in the abbrev hash table. */
11006 static struct abbrev_info
*
11007 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
11009 unsigned int hash_number
;
11010 struct abbrev_info
*abbrev
;
11012 hash_number
= number
% ABBREV_HASH_SIZE
;
11013 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
11017 if (abbrev
->number
== number
)
11020 abbrev
= abbrev
->next
;
11025 /* Returns nonzero if TAG represents a type that we might generate a partial
11029 is_type_tag_for_partial (int tag
)
11034 /* Some types that would be reasonable to generate partial symbols for,
11035 that we don't at present. */
11036 case DW_TAG_array_type
:
11037 case DW_TAG_file_type
:
11038 case DW_TAG_ptr_to_member_type
:
11039 case DW_TAG_set_type
:
11040 case DW_TAG_string_type
:
11041 case DW_TAG_subroutine_type
:
11043 case DW_TAG_base_type
:
11044 case DW_TAG_class_type
:
11045 case DW_TAG_interface_type
:
11046 case DW_TAG_enumeration_type
:
11047 case DW_TAG_structure_type
:
11048 case DW_TAG_subrange_type
:
11049 case DW_TAG_typedef
:
11050 case DW_TAG_union_type
:
11057 /* Load all DIEs that are interesting for partial symbols into memory. */
11059 static struct partial_die_info
*
11060 load_partial_dies (const struct die_reader_specs
*reader
,
11061 gdb_byte
*info_ptr
, int building_psymtab
)
11063 struct dwarf2_cu
*cu
= reader
->cu
;
11064 struct objfile
*objfile
= cu
->objfile
;
11065 struct partial_die_info
*part_die
;
11066 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
11067 struct abbrev_info
*abbrev
;
11068 unsigned int bytes_read
;
11069 unsigned int load_all
= 0;
11070 int nesting_level
= 1;
11075 gdb_assert (cu
->per_cu
!= NULL
);
11076 if (cu
->per_cu
->load_all_dies
)
11080 = htab_create_alloc_ex (cu
->header
.length
/ 12,
11084 &cu
->comp_unit_obstack
,
11085 hashtab_obstack_allocate
,
11086 dummy_obstack_deallocate
);
11088 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11089 sizeof (struct partial_die_info
));
11093 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
11095 /* A NULL abbrev means the end of a series of children. */
11096 if (abbrev
== NULL
)
11098 if (--nesting_level
== 0)
11100 /* PART_DIE was probably the last thing allocated on the
11101 comp_unit_obstack, so we could call obstack_free
11102 here. We don't do that because the waste is small,
11103 and will be cleaned up when we're done with this
11104 compilation unit. This way, we're also more robust
11105 against other users of the comp_unit_obstack. */
11108 info_ptr
+= bytes_read
;
11109 last_die
= parent_die
;
11110 parent_die
= parent_die
->die_parent
;
11114 /* Check for template arguments. We never save these; if
11115 they're seen, we just mark the parent, and go on our way. */
11116 if (parent_die
!= NULL
11117 && cu
->language
== language_cplus
11118 && (abbrev
->tag
== DW_TAG_template_type_param
11119 || abbrev
->tag
== DW_TAG_template_value_param
))
11121 parent_die
->has_template_arguments
= 1;
11125 /* We don't need a partial DIE for the template argument. */
11126 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11131 /* We only recurse into c++ subprograms looking for template arguments.
11132 Skip their other children. */
11134 && cu
->language
== language_cplus
11135 && parent_die
!= NULL
11136 && parent_die
->tag
== DW_TAG_subprogram
)
11138 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11142 /* Check whether this DIE is interesting enough to save. Normally
11143 we would not be interested in members here, but there may be
11144 later variables referencing them via DW_AT_specification (for
11145 static members). */
11147 && !is_type_tag_for_partial (abbrev
->tag
)
11148 && abbrev
->tag
!= DW_TAG_constant
11149 && abbrev
->tag
!= DW_TAG_enumerator
11150 && abbrev
->tag
!= DW_TAG_subprogram
11151 && abbrev
->tag
!= DW_TAG_lexical_block
11152 && abbrev
->tag
!= DW_TAG_variable
11153 && abbrev
->tag
!= DW_TAG_namespace
11154 && abbrev
->tag
!= DW_TAG_module
11155 && abbrev
->tag
!= DW_TAG_member
11156 && abbrev
->tag
!= DW_TAG_imported_unit
)
11158 /* Otherwise we skip to the next sibling, if any. */
11159 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11163 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
11166 /* This two-pass algorithm for processing partial symbols has a
11167 high cost in cache pressure. Thus, handle some simple cases
11168 here which cover the majority of C partial symbols. DIEs
11169 which neither have specification tags in them, nor could have
11170 specification tags elsewhere pointing at them, can simply be
11171 processed and discarded.
11173 This segment is also optional; scan_partial_symbols and
11174 add_partial_symbol will handle these DIEs if we chain
11175 them in normally. When compilers which do not emit large
11176 quantities of duplicate debug information are more common,
11177 this code can probably be removed. */
11179 /* Any complete simple types at the top level (pretty much all
11180 of them, for a language without namespaces), can be processed
11182 if (parent_die
== NULL
11183 && part_die
->has_specification
== 0
11184 && part_die
->is_declaration
== 0
11185 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11186 || part_die
->tag
== DW_TAG_base_type
11187 || part_die
->tag
== DW_TAG_subrange_type
))
11189 if (building_psymtab
&& part_die
->name
!= NULL
)
11190 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11191 VAR_DOMAIN
, LOC_TYPEDEF
,
11192 &objfile
->static_psymbols
,
11193 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11194 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11198 /* The exception for DW_TAG_typedef with has_children above is
11199 a workaround of GCC PR debug/47510. In the case of this complaint
11200 type_name_no_tag_or_error will error on such types later.
11202 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11203 it could not find the child DIEs referenced later, this is checked
11204 above. In correct DWARF DW_TAG_typedef should have no children. */
11206 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11207 complaint (&symfile_complaints
,
11208 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11209 "- DIE at 0x%x [in module %s]"),
11210 part_die
->offset
.sect_off
, objfile
->name
);
11212 /* If we're at the second level, and we're an enumerator, and
11213 our parent has no specification (meaning possibly lives in a
11214 namespace elsewhere), then we can add the partial symbol now
11215 instead of queueing it. */
11216 if (part_die
->tag
== DW_TAG_enumerator
11217 && parent_die
!= NULL
11218 && parent_die
->die_parent
== NULL
11219 && parent_die
->tag
== DW_TAG_enumeration_type
11220 && parent_die
->has_specification
== 0)
11222 if (part_die
->name
== NULL
)
11223 complaint (&symfile_complaints
,
11224 _("malformed enumerator DIE ignored"));
11225 else if (building_psymtab
)
11226 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11227 VAR_DOMAIN
, LOC_CONST
,
11228 (cu
->language
== language_cplus
11229 || cu
->language
== language_java
)
11230 ? &objfile
->global_psymbols
11231 : &objfile
->static_psymbols
,
11232 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11234 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11238 /* We'll save this DIE so link it in. */
11239 part_die
->die_parent
= parent_die
;
11240 part_die
->die_sibling
= NULL
;
11241 part_die
->die_child
= NULL
;
11243 if (last_die
&& last_die
== parent_die
)
11244 last_die
->die_child
= part_die
;
11246 last_die
->die_sibling
= part_die
;
11248 last_die
= part_die
;
11250 if (first_die
== NULL
)
11251 first_die
= part_die
;
11253 /* Maybe add the DIE to the hash table. Not all DIEs that we
11254 find interesting need to be in the hash table, because we
11255 also have the parent/sibling/child chains; only those that we
11256 might refer to by offset later during partial symbol reading.
11258 For now this means things that might have be the target of a
11259 DW_AT_specification, DW_AT_abstract_origin, or
11260 DW_AT_extension. DW_AT_extension will refer only to
11261 namespaces; DW_AT_abstract_origin refers to functions (and
11262 many things under the function DIE, but we do not recurse
11263 into function DIEs during partial symbol reading) and
11264 possibly variables as well; DW_AT_specification refers to
11265 declarations. Declarations ought to have the DW_AT_declaration
11266 flag. It happens that GCC forgets to put it in sometimes, but
11267 only for functions, not for types.
11269 Adding more things than necessary to the hash table is harmless
11270 except for the performance cost. Adding too few will result in
11271 wasted time in find_partial_die, when we reread the compilation
11272 unit with load_all_dies set. */
11275 || abbrev
->tag
== DW_TAG_constant
11276 || abbrev
->tag
== DW_TAG_subprogram
11277 || abbrev
->tag
== DW_TAG_variable
11278 || abbrev
->tag
== DW_TAG_namespace
11279 || part_die
->is_declaration
)
11283 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11284 part_die
->offset
.sect_off
, INSERT
);
11288 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11289 sizeof (struct partial_die_info
));
11291 /* For some DIEs we want to follow their children (if any). For C
11292 we have no reason to follow the children of structures; for other
11293 languages we have to, so that we can get at method physnames
11294 to infer fully qualified class names, for DW_AT_specification,
11295 and for C++ template arguments. For C++, we also look one level
11296 inside functions to find template arguments (if the name of the
11297 function does not already contain the template arguments).
11299 For Ada, we need to scan the children of subprograms and lexical
11300 blocks as well because Ada allows the definition of nested
11301 entities that could be interesting for the debugger, such as
11302 nested subprograms for instance. */
11303 if (last_die
->has_children
11305 || last_die
->tag
== DW_TAG_namespace
11306 || last_die
->tag
== DW_TAG_module
11307 || last_die
->tag
== DW_TAG_enumeration_type
11308 || (cu
->language
== language_cplus
11309 && last_die
->tag
== DW_TAG_subprogram
11310 && (last_die
->name
== NULL
11311 || strchr (last_die
->name
, '<') == NULL
))
11312 || (cu
->language
!= language_c
11313 && (last_die
->tag
== DW_TAG_class_type
11314 || last_die
->tag
== DW_TAG_interface_type
11315 || last_die
->tag
== DW_TAG_structure_type
11316 || last_die
->tag
== DW_TAG_union_type
))
11317 || (cu
->language
== language_ada
11318 && (last_die
->tag
== DW_TAG_subprogram
11319 || last_die
->tag
== DW_TAG_lexical_block
))))
11322 parent_die
= last_die
;
11326 /* Otherwise we skip to the next sibling, if any. */
11327 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11329 /* Back to the top, do it again. */
11333 /* Read a minimal amount of information into the minimal die structure. */
11336 read_partial_die (const struct die_reader_specs
*reader
,
11337 struct partial_die_info
*part_die
,
11338 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11339 gdb_byte
*info_ptr
)
11341 struct dwarf2_cu
*cu
= reader
->cu
;
11342 struct objfile
*objfile
= cu
->objfile
;
11343 gdb_byte
*buffer
= reader
->buffer
;
11345 struct attribute attr
;
11346 int has_low_pc_attr
= 0;
11347 int has_high_pc_attr
= 0;
11348 int high_pc_relative
= 0;
11350 memset (part_die
, 0, sizeof (struct partial_die_info
));
11352 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11354 info_ptr
+= abbrev_len
;
11356 if (abbrev
== NULL
)
11359 part_die
->tag
= abbrev
->tag
;
11360 part_die
->has_children
= abbrev
->has_children
;
11362 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11364 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11366 /* Store the data if it is of an attribute we want to keep in a
11367 partial symbol table. */
11371 switch (part_die
->tag
)
11373 case DW_TAG_compile_unit
:
11374 case DW_TAG_partial_unit
:
11375 case DW_TAG_type_unit
:
11376 /* Compilation units have a DW_AT_name that is a filename, not
11377 a source language identifier. */
11378 case DW_TAG_enumeration_type
:
11379 case DW_TAG_enumerator
:
11380 /* These tags always have simple identifiers already; no need
11381 to canonicalize them. */
11382 part_die
->name
= DW_STRING (&attr
);
11386 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11387 &objfile
->objfile_obstack
);
11391 case DW_AT_linkage_name
:
11392 case DW_AT_MIPS_linkage_name
:
11393 /* Note that both forms of linkage name might appear. We
11394 assume they will be the same, and we only store the last
11396 if (cu
->language
== language_ada
)
11397 part_die
->name
= DW_STRING (&attr
);
11398 part_die
->linkage_name
= DW_STRING (&attr
);
11401 has_low_pc_attr
= 1;
11402 part_die
->lowpc
= DW_ADDR (&attr
);
11404 case DW_AT_high_pc
:
11405 has_high_pc_attr
= 1;
11406 if (attr
.form
== DW_FORM_addr
11407 || attr
.form
== DW_FORM_GNU_addr_index
)
11408 part_die
->highpc
= DW_ADDR (&attr
);
11411 high_pc_relative
= 1;
11412 part_die
->highpc
= DW_UNSND (&attr
);
11415 case DW_AT_location
:
11416 /* Support the .debug_loc offsets. */
11417 if (attr_form_is_block (&attr
))
11419 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11421 else if (attr_form_is_section_offset (&attr
))
11423 dwarf2_complex_location_expr_complaint ();
11427 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11428 "partial symbol information");
11431 case DW_AT_external
:
11432 part_die
->is_external
= DW_UNSND (&attr
);
11434 case DW_AT_declaration
:
11435 part_die
->is_declaration
= DW_UNSND (&attr
);
11438 part_die
->has_type
= 1;
11440 case DW_AT_abstract_origin
:
11441 case DW_AT_specification
:
11442 case DW_AT_extension
:
11443 part_die
->has_specification
= 1;
11444 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11446 case DW_AT_sibling
:
11447 /* Ignore absolute siblings, they might point outside of
11448 the current compile unit. */
11449 if (attr
.form
== DW_FORM_ref_addr
)
11450 complaint (&symfile_complaints
,
11451 _("ignoring absolute DW_AT_sibling"));
11453 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11455 case DW_AT_byte_size
:
11456 part_die
->has_byte_size
= 1;
11458 case DW_AT_calling_convention
:
11459 /* DWARF doesn't provide a way to identify a program's source-level
11460 entry point. DW_AT_calling_convention attributes are only meant
11461 to describe functions' calling conventions.
11463 However, because it's a necessary piece of information in
11464 Fortran, and because DW_CC_program is the only piece of debugging
11465 information whose definition refers to a 'main program' at all,
11466 several compilers have begun marking Fortran main programs with
11467 DW_CC_program --- even when those functions use the standard
11468 calling conventions.
11470 So until DWARF specifies a way to provide this information and
11471 compilers pick up the new representation, we'll support this
11473 if (DW_UNSND (&attr
) == DW_CC_program
11474 && cu
->language
== language_fortran
)
11476 set_main_name (part_die
->name
);
11478 /* As this DIE has a static linkage the name would be difficult
11479 to look up later. */
11480 language_of_main
= language_fortran
;
11484 if (DW_UNSND (&attr
) == DW_INL_inlined
11485 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11486 part_die
->may_be_inlined
= 1;
11490 if (part_die
->tag
== DW_TAG_imported_unit
)
11491 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11499 if (high_pc_relative
)
11500 part_die
->highpc
+= part_die
->lowpc
;
11502 if (has_low_pc_attr
&& has_high_pc_attr
)
11504 /* When using the GNU linker, .gnu.linkonce. sections are used to
11505 eliminate duplicate copies of functions and vtables and such.
11506 The linker will arbitrarily choose one and discard the others.
11507 The AT_*_pc values for such functions refer to local labels in
11508 these sections. If the section from that file was discarded, the
11509 labels are not in the output, so the relocs get a value of 0.
11510 If this is a discarded function, mark the pc bounds as invalid,
11511 so that GDB will ignore it. */
11512 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11514 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11516 complaint (&symfile_complaints
,
11517 _("DW_AT_low_pc %s is zero "
11518 "for DIE at 0x%x [in module %s]"),
11519 paddress (gdbarch
, part_die
->lowpc
),
11520 part_die
->offset
.sect_off
, objfile
->name
);
11522 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11523 else if (part_die
->lowpc
>= part_die
->highpc
)
11525 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11527 complaint (&symfile_complaints
,
11528 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11529 "for DIE at 0x%x [in module %s]"),
11530 paddress (gdbarch
, part_die
->lowpc
),
11531 paddress (gdbarch
, part_die
->highpc
),
11532 part_die
->offset
.sect_off
, objfile
->name
);
11535 part_die
->has_pc_info
= 1;
11541 /* Find a cached partial DIE at OFFSET in CU. */
11543 static struct partial_die_info
*
11544 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11546 struct partial_die_info
*lookup_die
= NULL
;
11547 struct partial_die_info part_die
;
11549 part_die
.offset
= offset
;
11550 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11556 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11557 except in the case of .debug_types DIEs which do not reference
11558 outside their CU (they do however referencing other types via
11559 DW_FORM_ref_sig8). */
11561 static struct partial_die_info
*
11562 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11564 struct objfile
*objfile
= cu
->objfile
;
11565 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11566 struct partial_die_info
*pd
= NULL
;
11568 if (offset_in_cu_p (&cu
->header
, offset
))
11570 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11573 /* We missed recording what we needed.
11574 Load all dies and try again. */
11575 per_cu
= cu
->per_cu
;
11579 /* TUs don't reference other CUs/TUs (except via type signatures). */
11580 if (cu
->per_cu
->is_debug_types
)
11582 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11583 " external reference to offset 0x%lx [in module %s].\n"),
11584 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11585 bfd_get_filename (objfile
->obfd
));
11587 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11589 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11590 load_partial_comp_unit (per_cu
);
11592 per_cu
->cu
->last_used
= 0;
11593 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11596 /* If we didn't find it, and not all dies have been loaded,
11597 load them all and try again. */
11599 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11601 per_cu
->load_all_dies
= 1;
11603 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11604 THIS_CU->cu may already be in use. So we can't just free it and
11605 replace its DIEs with the ones we read in. Instead, we leave those
11606 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11607 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11609 load_partial_comp_unit (per_cu
);
11611 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11615 internal_error (__FILE__
, __LINE__
,
11616 _("could not find partial DIE 0x%x "
11617 "in cache [from module %s]\n"),
11618 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11622 /* See if we can figure out if the class lives in a namespace. We do
11623 this by looking for a member function; its demangled name will
11624 contain namespace info, if there is any. */
11627 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11628 struct dwarf2_cu
*cu
)
11630 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11631 what template types look like, because the demangler
11632 frequently doesn't give the same name as the debug info. We
11633 could fix this by only using the demangled name to get the
11634 prefix (but see comment in read_structure_type). */
11636 struct partial_die_info
*real_pdi
;
11637 struct partial_die_info
*child_pdi
;
11639 /* If this DIE (this DIE's specification, if any) has a parent, then
11640 we should not do this. We'll prepend the parent's fully qualified
11641 name when we create the partial symbol. */
11643 real_pdi
= struct_pdi
;
11644 while (real_pdi
->has_specification
)
11645 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11647 if (real_pdi
->die_parent
!= NULL
)
11650 for (child_pdi
= struct_pdi
->die_child
;
11652 child_pdi
= child_pdi
->die_sibling
)
11654 if (child_pdi
->tag
== DW_TAG_subprogram
11655 && child_pdi
->linkage_name
!= NULL
)
11657 char *actual_class_name
11658 = language_class_name_from_physname (cu
->language_defn
,
11659 child_pdi
->linkage_name
);
11660 if (actual_class_name
!= NULL
)
11663 = obsavestring (actual_class_name
,
11664 strlen (actual_class_name
),
11665 &cu
->objfile
->objfile_obstack
);
11666 xfree (actual_class_name
);
11673 /* Adjust PART_DIE before generating a symbol for it. This function
11674 may set the is_external flag or change the DIE's name. */
11677 fixup_partial_die (struct partial_die_info
*part_die
,
11678 struct dwarf2_cu
*cu
)
11680 /* Once we've fixed up a die, there's no point in doing so again.
11681 This also avoids a memory leak if we were to call
11682 guess_partial_die_structure_name multiple times. */
11683 if (part_die
->fixup_called
)
11686 /* If we found a reference attribute and the DIE has no name, try
11687 to find a name in the referred to DIE. */
11689 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11691 struct partial_die_info
*spec_die
;
11693 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11695 fixup_partial_die (spec_die
, cu
);
11697 if (spec_die
->name
)
11699 part_die
->name
= spec_die
->name
;
11701 /* Copy DW_AT_external attribute if it is set. */
11702 if (spec_die
->is_external
)
11703 part_die
->is_external
= spec_die
->is_external
;
11707 /* Set default names for some unnamed DIEs. */
11709 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11710 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11712 /* If there is no parent die to provide a namespace, and there are
11713 children, see if we can determine the namespace from their linkage
11715 if (cu
->language
== language_cplus
11716 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11717 && part_die
->die_parent
== NULL
11718 && part_die
->has_children
11719 && (part_die
->tag
== DW_TAG_class_type
11720 || part_die
->tag
== DW_TAG_structure_type
11721 || part_die
->tag
== DW_TAG_union_type
))
11722 guess_partial_die_structure_name (part_die
, cu
);
11724 /* GCC might emit a nameless struct or union that has a linkage
11725 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11726 if (part_die
->name
== NULL
11727 && (part_die
->tag
== DW_TAG_class_type
11728 || part_die
->tag
== DW_TAG_interface_type
11729 || part_die
->tag
== DW_TAG_structure_type
11730 || part_die
->tag
== DW_TAG_union_type
)
11731 && part_die
->linkage_name
!= NULL
)
11735 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11740 /* Strip any leading namespaces/classes, keep only the base name.
11741 DW_AT_name for named DIEs does not contain the prefixes. */
11742 base
= strrchr (demangled
, ':');
11743 if (base
&& base
> demangled
&& base
[-1] == ':')
11748 part_die
->name
= obsavestring (base
, strlen (base
),
11749 &cu
->objfile
->objfile_obstack
);
11754 part_die
->fixup_called
= 1;
11757 /* Read an attribute value described by an attribute form. */
11760 read_attribute_value (const struct die_reader_specs
*reader
,
11761 struct attribute
*attr
, unsigned form
,
11762 gdb_byte
*info_ptr
)
11764 struct dwarf2_cu
*cu
= reader
->cu
;
11765 bfd
*abfd
= reader
->abfd
;
11766 struct comp_unit_head
*cu_header
= &cu
->header
;
11767 unsigned int bytes_read
;
11768 struct dwarf_block
*blk
;
11773 case DW_FORM_ref_addr
:
11774 if (cu
->header
.version
== 2)
11775 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11777 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11778 &cu
->header
, &bytes_read
);
11779 info_ptr
+= bytes_read
;
11782 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11783 info_ptr
+= bytes_read
;
11785 case DW_FORM_block2
:
11786 blk
= dwarf_alloc_block (cu
);
11787 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11789 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11790 info_ptr
+= blk
->size
;
11791 DW_BLOCK (attr
) = blk
;
11793 case DW_FORM_block4
:
11794 blk
= dwarf_alloc_block (cu
);
11795 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11797 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11798 info_ptr
+= blk
->size
;
11799 DW_BLOCK (attr
) = blk
;
11801 case DW_FORM_data2
:
11802 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11805 case DW_FORM_data4
:
11806 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11809 case DW_FORM_data8
:
11810 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11813 case DW_FORM_sec_offset
:
11814 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11815 info_ptr
+= bytes_read
;
11817 case DW_FORM_string
:
11818 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11819 DW_STRING_IS_CANONICAL (attr
) = 0;
11820 info_ptr
+= bytes_read
;
11823 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11825 DW_STRING_IS_CANONICAL (attr
) = 0;
11826 info_ptr
+= bytes_read
;
11828 case DW_FORM_exprloc
:
11829 case DW_FORM_block
:
11830 blk
= dwarf_alloc_block (cu
);
11831 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11832 info_ptr
+= bytes_read
;
11833 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11834 info_ptr
+= blk
->size
;
11835 DW_BLOCK (attr
) = blk
;
11837 case DW_FORM_block1
:
11838 blk
= dwarf_alloc_block (cu
);
11839 blk
->size
= read_1_byte (abfd
, info_ptr
);
11841 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11842 info_ptr
+= blk
->size
;
11843 DW_BLOCK (attr
) = blk
;
11845 case DW_FORM_data1
:
11846 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11850 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11853 case DW_FORM_flag_present
:
11854 DW_UNSND (attr
) = 1;
11856 case DW_FORM_sdata
:
11857 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11858 info_ptr
+= bytes_read
;
11860 case DW_FORM_udata
:
11861 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11862 info_ptr
+= bytes_read
;
11865 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11866 + read_1_byte (abfd
, info_ptr
));
11870 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11871 + read_2_bytes (abfd
, info_ptr
));
11875 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11876 + read_4_bytes (abfd
, info_ptr
));
11880 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11881 + read_8_bytes (abfd
, info_ptr
));
11884 case DW_FORM_ref_sig8
:
11885 /* Convert the signature to something we can record in DW_UNSND
11887 NOTE: This is NULL if the type wasn't found. */
11888 DW_SIGNATURED_TYPE (attr
) =
11889 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11892 case DW_FORM_ref_udata
:
11893 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11894 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11895 info_ptr
+= bytes_read
;
11897 case DW_FORM_indirect
:
11898 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11899 info_ptr
+= bytes_read
;
11900 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11902 case DW_FORM_GNU_addr_index
:
11903 if (reader
->dwo_file
== NULL
)
11905 /* For now flag a hard error.
11906 Later we can turn this into a complaint. */
11907 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11908 dwarf_form_name (form
),
11909 bfd_get_filename (abfd
));
11911 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11912 info_ptr
+= bytes_read
;
11914 case DW_FORM_GNU_str_index
:
11915 if (reader
->dwo_file
== NULL
)
11917 /* For now flag a hard error.
11918 Later we can turn this into a complaint if warranted. */
11919 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11920 dwarf_form_name (form
),
11921 bfd_get_filename (abfd
));
11924 ULONGEST str_index
=
11925 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11927 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11928 DW_STRING_IS_CANONICAL (attr
) = 0;
11929 info_ptr
+= bytes_read
;
11933 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
11934 dwarf_form_name (form
),
11935 bfd_get_filename (abfd
));
11938 /* We have seen instances where the compiler tried to emit a byte
11939 size attribute of -1 which ended up being encoded as an unsigned
11940 0xffffffff. Although 0xffffffff is technically a valid size value,
11941 an object of this size seems pretty unlikely so we can relatively
11942 safely treat these cases as if the size attribute was invalid and
11943 treat them as zero by default. */
11944 if (attr
->name
== DW_AT_byte_size
11945 && form
== DW_FORM_data4
11946 && DW_UNSND (attr
) >= 0xffffffff)
11949 (&symfile_complaints
,
11950 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
11951 hex_string (DW_UNSND (attr
)));
11952 DW_UNSND (attr
) = 0;
11958 /* Read an attribute described by an abbreviated attribute. */
11961 read_attribute (const struct die_reader_specs
*reader
,
11962 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
11963 gdb_byte
*info_ptr
)
11965 attr
->name
= abbrev
->name
;
11966 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
11969 /* Read dwarf information from a buffer. */
11971 static unsigned int
11972 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
11974 return bfd_get_8 (abfd
, buf
);
11978 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
11980 return bfd_get_signed_8 (abfd
, buf
);
11983 static unsigned int
11984 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
11986 return bfd_get_16 (abfd
, buf
);
11990 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
11992 return bfd_get_signed_16 (abfd
, buf
);
11995 static unsigned int
11996 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
11998 return bfd_get_32 (abfd
, buf
);
12002 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12004 return bfd_get_signed_32 (abfd
, buf
);
12008 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12010 return bfd_get_64 (abfd
, buf
);
12014 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12015 unsigned int *bytes_read
)
12017 struct comp_unit_head
*cu_header
= &cu
->header
;
12018 CORE_ADDR retval
= 0;
12020 if (cu_header
->signed_addr_p
)
12022 switch (cu_header
->addr_size
)
12025 retval
= bfd_get_signed_16 (abfd
, buf
);
12028 retval
= bfd_get_signed_32 (abfd
, buf
);
12031 retval
= bfd_get_signed_64 (abfd
, buf
);
12034 internal_error (__FILE__
, __LINE__
,
12035 _("read_address: bad switch, signed [in module %s]"),
12036 bfd_get_filename (abfd
));
12041 switch (cu_header
->addr_size
)
12044 retval
= bfd_get_16 (abfd
, buf
);
12047 retval
= bfd_get_32 (abfd
, buf
);
12050 retval
= bfd_get_64 (abfd
, buf
);
12053 internal_error (__FILE__
, __LINE__
,
12054 _("read_address: bad switch, "
12055 "unsigned [in module %s]"),
12056 bfd_get_filename (abfd
));
12060 *bytes_read
= cu_header
->addr_size
;
12064 /* Read the initial length from a section. The (draft) DWARF 3
12065 specification allows the initial length to take up either 4 bytes
12066 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
12067 bytes describe the length and all offsets will be 8 bytes in length
12070 An older, non-standard 64-bit format is also handled by this
12071 function. The older format in question stores the initial length
12072 as an 8-byte quantity without an escape value. Lengths greater
12073 than 2^32 aren't very common which means that the initial 4 bytes
12074 is almost always zero. Since a length value of zero doesn't make
12075 sense for the 32-bit format, this initial zero can be considered to
12076 be an escape value which indicates the presence of the older 64-bit
12077 format. As written, the code can't detect (old format) lengths
12078 greater than 4GB. If it becomes necessary to handle lengths
12079 somewhat larger than 4GB, we could allow other small values (such
12080 as the non-sensical values of 1, 2, and 3) to also be used as
12081 escape values indicating the presence of the old format.
12083 The value returned via bytes_read should be used to increment the
12084 relevant pointer after calling read_initial_length().
12086 [ Note: read_initial_length() and read_offset() are based on the
12087 document entitled "DWARF Debugging Information Format", revision
12088 3, draft 8, dated November 19, 2001. This document was obtained
12091 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
12093 This document is only a draft and is subject to change. (So beware.)
12095 Details regarding the older, non-standard 64-bit format were
12096 determined empirically by examining 64-bit ELF files produced by
12097 the SGI toolchain on an IRIX 6.5 machine.
12099 - Kevin, July 16, 2002
12103 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
12105 LONGEST length
= bfd_get_32 (abfd
, buf
);
12107 if (length
== 0xffffffff)
12109 length
= bfd_get_64 (abfd
, buf
+ 4);
12112 else if (length
== 0)
12114 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
12115 length
= bfd_get_64 (abfd
, buf
);
12126 /* Cover function for read_initial_length.
12127 Returns the length of the object at BUF, and stores the size of the
12128 initial length in *BYTES_READ and stores the size that offsets will be in
12130 If the initial length size is not equivalent to that specified in
12131 CU_HEADER then issue a complaint.
12132 This is useful when reading non-comp-unit headers. */
12135 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
12136 const struct comp_unit_head
*cu_header
,
12137 unsigned int *bytes_read
,
12138 unsigned int *offset_size
)
12140 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
12142 gdb_assert (cu_header
->initial_length_size
== 4
12143 || cu_header
->initial_length_size
== 8
12144 || cu_header
->initial_length_size
== 12);
12146 if (cu_header
->initial_length_size
!= *bytes_read
)
12147 complaint (&symfile_complaints
,
12148 _("intermixed 32-bit and 64-bit DWARF sections"));
12150 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
12154 /* Read an offset from the data stream. The size of the offset is
12155 given by cu_header->offset_size. */
12158 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
12159 unsigned int *bytes_read
)
12161 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
12163 *bytes_read
= cu_header
->offset_size
;
12167 /* Read an offset from the data stream. */
12170 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
12172 LONGEST retval
= 0;
12174 switch (offset_size
)
12177 retval
= bfd_get_32 (abfd
, buf
);
12180 retval
= bfd_get_64 (abfd
, buf
);
12183 internal_error (__FILE__
, __LINE__
,
12184 _("read_offset_1: bad switch [in module %s]"),
12185 bfd_get_filename (abfd
));
12192 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12194 /* If the size of a host char is 8 bits, we can return a pointer
12195 to the buffer, otherwise we have to copy the data to a buffer
12196 allocated on the temporary obstack. */
12197 gdb_assert (HOST_CHAR_BIT
== 8);
12202 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12204 /* If the size of a host char is 8 bits, we can return a pointer
12205 to the string, otherwise we have to copy the string to a buffer
12206 allocated on the temporary obstack. */
12207 gdb_assert (HOST_CHAR_BIT
== 8);
12210 *bytes_read_ptr
= 1;
12213 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12214 return (char *) buf
;
12218 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12220 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12221 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12222 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12223 bfd_get_filename (abfd
));
12224 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12225 error (_("DW_FORM_strp pointing outside of "
12226 ".debug_str section [in module %s]"),
12227 bfd_get_filename (abfd
));
12228 gdb_assert (HOST_CHAR_BIT
== 8);
12229 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12231 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12235 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12236 const struct comp_unit_head
*cu_header
,
12237 unsigned int *bytes_read_ptr
)
12239 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12241 return read_indirect_string_at_offset (abfd
, str_offset
);
12245 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12248 unsigned int num_read
;
12250 unsigned char byte
;
12258 byte
= bfd_get_8 (abfd
, buf
);
12261 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12262 if ((byte
& 128) == 0)
12268 *bytes_read_ptr
= num_read
;
12273 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12276 int i
, shift
, num_read
;
12277 unsigned char byte
;
12285 byte
= bfd_get_8 (abfd
, buf
);
12288 result
|= ((LONGEST
) (byte
& 127) << shift
);
12290 if ((byte
& 128) == 0)
12295 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12296 result
|= -(((LONGEST
) 1) << shift
);
12297 *bytes_read_ptr
= num_read
;
12301 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12302 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12303 ADDR_SIZE is the size of addresses from the CU header. */
12306 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12308 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12309 bfd
*abfd
= objfile
->obfd
;
12310 const gdb_byte
*info_ptr
;
12312 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12313 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12314 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12316 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12317 error (_("DW_FORM_addr_index pointing outside of "
12318 ".debug_addr section [in module %s]"),
12320 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12321 + addr_base
+ addr_index
* addr_size
);
12322 if (addr_size
== 4)
12323 return bfd_get_32 (abfd
, info_ptr
);
12325 return bfd_get_64 (abfd
, info_ptr
);
12328 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12331 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12333 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12336 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12339 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12340 unsigned int *bytes_read
)
12342 bfd
*abfd
= cu
->objfile
->obfd
;
12343 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12345 return read_addr_index (cu
, addr_index
);
12348 /* Data structure to pass results from dwarf2_read_addr_index_reader
12349 back to dwarf2_read_addr_index. */
12351 struct dwarf2_read_addr_index_data
12353 ULONGEST addr_base
;
12357 /* die_reader_func for dwarf2_read_addr_index. */
12360 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12361 gdb_byte
*info_ptr
,
12362 struct die_info
*comp_unit_die
,
12366 struct dwarf2_cu
*cu
= reader
->cu
;
12367 struct dwarf2_read_addr_index_data
*aidata
=
12368 (struct dwarf2_read_addr_index_data
*) data
;
12370 aidata
->addr_base
= cu
->addr_base
;
12371 aidata
->addr_size
= cu
->header
.addr_size
;
12374 /* Given an index in .debug_addr, fetch the value.
12375 NOTE: This can be called during dwarf expression evaluation,
12376 long after the debug information has been read, and thus per_cu->cu
12377 may no longer exist. */
12380 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12381 unsigned int addr_index
)
12383 struct objfile
*objfile
= per_cu
->objfile
;
12384 struct dwarf2_cu
*cu
= per_cu
->cu
;
12385 ULONGEST addr_base
;
12388 /* This is intended to be called from outside this file. */
12389 dw2_setup (objfile
);
12391 /* We need addr_base and addr_size.
12392 If we don't have PER_CU->cu, we have to get it.
12393 Nasty, but the alternative is storing the needed info in PER_CU,
12394 which at this point doesn't seem justified: it's not clear how frequently
12395 it would get used and it would increase the size of every PER_CU.
12396 Entry points like dwarf2_per_cu_addr_size do a similar thing
12397 so we're not in uncharted territory here.
12398 Alas we need to be a bit more complicated as addr_base is contained
12401 We don't need to read the entire CU(/TU).
12402 We just need the header and top level die.
12403 IWBN to use the aging mechanism to let us lazily later discard the CU.
12404 See however init_cutu_and_read_dies_simple. */
12408 addr_base
= cu
->addr_base
;
12409 addr_size
= cu
->header
.addr_size
;
12413 struct dwarf2_read_addr_index_data aidata
;
12415 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12417 addr_base
= aidata
.addr_base
;
12418 addr_size
= aidata
.addr_size
;
12421 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12424 /* Given a DW_AT_str_index, fetch the string. */
12427 read_str_index (const struct die_reader_specs
*reader
,
12428 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12430 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12431 const char *dwo_name
= objfile
->name
;
12432 bfd
*abfd
= objfile
->obfd
;
12433 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12434 gdb_byte
*info_ptr
;
12435 ULONGEST str_offset
;
12437 dwarf2_read_section (objfile
, §ions
->str
);
12438 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12439 if (sections
->str
.buffer
== NULL
)
12440 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12441 " in CU at offset 0x%lx [in module %s]"),
12442 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12443 if (sections
->str_offsets
.buffer
== NULL
)
12444 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12445 " in CU at offset 0x%lx [in module %s]"),
12446 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12447 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12448 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12449 " section in CU at offset 0x%lx [in module %s]"),
12450 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12451 info_ptr
= (sections
->str_offsets
.buffer
12452 + str_index
* cu
->header
.offset_size
);
12453 if (cu
->header
.offset_size
== 4)
12454 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12456 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12457 if (str_offset
>= sections
->str
.size
)
12458 error (_("Offset from DW_FORM_str_index pointing outside of"
12459 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12460 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12461 return (char *) (sections
->str
.buffer
+ str_offset
);
12464 /* Return the length of an LEB128 number in BUF. */
12467 leb128_size (const gdb_byte
*buf
)
12469 const gdb_byte
*begin
= buf
;
12475 if ((byte
& 128) == 0)
12476 return buf
- begin
;
12481 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12488 cu
->language
= language_c
;
12490 case DW_LANG_C_plus_plus
:
12491 cu
->language
= language_cplus
;
12494 cu
->language
= language_d
;
12496 case DW_LANG_Fortran77
:
12497 case DW_LANG_Fortran90
:
12498 case DW_LANG_Fortran95
:
12499 cu
->language
= language_fortran
;
12502 cu
->language
= language_go
;
12504 case DW_LANG_Mips_Assembler
:
12505 cu
->language
= language_asm
;
12508 cu
->language
= language_java
;
12510 case DW_LANG_Ada83
:
12511 case DW_LANG_Ada95
:
12512 cu
->language
= language_ada
;
12514 case DW_LANG_Modula2
:
12515 cu
->language
= language_m2
;
12517 case DW_LANG_Pascal83
:
12518 cu
->language
= language_pascal
;
12521 cu
->language
= language_objc
;
12523 case DW_LANG_Cobol74
:
12524 case DW_LANG_Cobol85
:
12526 cu
->language
= language_minimal
;
12529 cu
->language_defn
= language_def (cu
->language
);
12532 /* Return the named attribute or NULL if not there. */
12534 static struct attribute
*
12535 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12540 struct attribute
*spec
= NULL
;
12542 for (i
= 0; i
< die
->num_attrs
; ++i
)
12544 if (die
->attrs
[i
].name
== name
)
12545 return &die
->attrs
[i
];
12546 if (die
->attrs
[i
].name
== DW_AT_specification
12547 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12548 spec
= &die
->attrs
[i
];
12554 die
= follow_die_ref (die
, spec
, &cu
);
12560 /* Return the named attribute or NULL if not there,
12561 but do not follow DW_AT_specification, etc.
12562 This is for use in contexts where we're reading .debug_types dies.
12563 Following DW_AT_specification, DW_AT_abstract_origin will take us
12564 back up the chain, and we want to go down. */
12566 static struct attribute
*
12567 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12568 struct dwarf2_cu
*cu
)
12572 for (i
= 0; i
< die
->num_attrs
; ++i
)
12573 if (die
->attrs
[i
].name
== name
)
12574 return &die
->attrs
[i
];
12579 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12580 and holds a non-zero value. This function should only be used for
12581 DW_FORM_flag or DW_FORM_flag_present attributes. */
12584 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12586 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12588 return (attr
&& DW_UNSND (attr
));
12592 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12594 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12595 which value is non-zero. However, we have to be careful with
12596 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12597 (via dwarf2_flag_true_p) follows this attribute. So we may
12598 end up accidently finding a declaration attribute that belongs
12599 to a different DIE referenced by the specification attribute,
12600 even though the given DIE does not have a declaration attribute. */
12601 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12602 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12605 /* Return the die giving the specification for DIE, if there is
12606 one. *SPEC_CU is the CU containing DIE on input, and the CU
12607 containing the return value on output. If there is no
12608 specification, but there is an abstract origin, that is
12611 static struct die_info
*
12612 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12614 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12617 if (spec_attr
== NULL
)
12618 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12620 if (spec_attr
== NULL
)
12623 return follow_die_ref (die
, spec_attr
, spec_cu
);
12626 /* Free the line_header structure *LH, and any arrays and strings it
12628 NOTE: This is also used as a "cleanup" function. */
12631 free_line_header (struct line_header
*lh
)
12633 if (lh
->standard_opcode_lengths
)
12634 xfree (lh
->standard_opcode_lengths
);
12636 /* Remember that all the lh->file_names[i].name pointers are
12637 pointers into debug_line_buffer, and don't need to be freed. */
12638 if (lh
->file_names
)
12639 xfree (lh
->file_names
);
12641 /* Similarly for the include directory names. */
12642 if (lh
->include_dirs
)
12643 xfree (lh
->include_dirs
);
12648 /* Add an entry to LH's include directory table. */
12651 add_include_dir (struct line_header
*lh
, char *include_dir
)
12653 /* Grow the array if necessary. */
12654 if (lh
->include_dirs_size
== 0)
12656 lh
->include_dirs_size
= 1; /* for testing */
12657 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12658 * sizeof (*lh
->include_dirs
));
12660 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12662 lh
->include_dirs_size
*= 2;
12663 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12664 (lh
->include_dirs_size
12665 * sizeof (*lh
->include_dirs
)));
12668 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12671 /* Add an entry to LH's file name table. */
12674 add_file_name (struct line_header
*lh
,
12676 unsigned int dir_index
,
12677 unsigned int mod_time
,
12678 unsigned int length
)
12680 struct file_entry
*fe
;
12682 /* Grow the array if necessary. */
12683 if (lh
->file_names_size
== 0)
12685 lh
->file_names_size
= 1; /* for testing */
12686 lh
->file_names
= xmalloc (lh
->file_names_size
12687 * sizeof (*lh
->file_names
));
12689 else if (lh
->num_file_names
>= lh
->file_names_size
)
12691 lh
->file_names_size
*= 2;
12692 lh
->file_names
= xrealloc (lh
->file_names
,
12693 (lh
->file_names_size
12694 * sizeof (*lh
->file_names
)));
12697 fe
= &lh
->file_names
[lh
->num_file_names
++];
12699 fe
->dir_index
= dir_index
;
12700 fe
->mod_time
= mod_time
;
12701 fe
->length
= length
;
12702 fe
->included_p
= 0;
12706 /* Read the statement program header starting at OFFSET in
12707 .debug_line, or .debug_line.dwo. Return a pointer
12708 to a struct line_header, allocated using xmalloc.
12710 NOTE: the strings in the include directory and file name tables of
12711 the returned object point into the dwarf line section buffer,
12712 and must not be freed. */
12714 static struct line_header
*
12715 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12717 struct cleanup
*back_to
;
12718 struct line_header
*lh
;
12719 gdb_byte
*line_ptr
;
12720 unsigned int bytes_read
, offset_size
;
12722 char *cur_dir
, *cur_file
;
12723 struct dwarf2_section_info
*section
;
12726 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12728 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12729 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12731 section
= &dwarf2_per_objfile
->line
;
12733 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12734 if (section
->buffer
== NULL
)
12736 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12737 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12739 complaint (&symfile_complaints
, _("missing .debug_line section"));
12743 /* We can't do this until we know the section is non-empty.
12744 Only then do we know we have such a section. */
12745 abfd
= section
->asection
->owner
;
12747 /* Make sure that at least there's room for the total_length field.
12748 That could be 12 bytes long, but we're just going to fudge that. */
12749 if (offset
+ 4 >= section
->size
)
12751 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12755 lh
= xmalloc (sizeof (*lh
));
12756 memset (lh
, 0, sizeof (*lh
));
12757 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12760 line_ptr
= section
->buffer
+ offset
;
12762 /* Read in the header. */
12764 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12765 &bytes_read
, &offset_size
);
12766 line_ptr
+= bytes_read
;
12767 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12769 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12772 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12773 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12775 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12776 line_ptr
+= offset_size
;
12777 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12779 if (lh
->version
>= 4)
12781 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12785 lh
->maximum_ops_per_instruction
= 1;
12787 if (lh
->maximum_ops_per_instruction
== 0)
12789 lh
->maximum_ops_per_instruction
= 1;
12790 complaint (&symfile_complaints
,
12791 _("invalid maximum_ops_per_instruction "
12792 "in `.debug_line' section"));
12795 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12797 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12799 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12801 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12803 lh
->standard_opcode_lengths
12804 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12806 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12807 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12809 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12813 /* Read directory table. */
12814 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12816 line_ptr
+= bytes_read
;
12817 add_include_dir (lh
, cur_dir
);
12819 line_ptr
+= bytes_read
;
12821 /* Read file name table. */
12822 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12824 unsigned int dir_index
, mod_time
, length
;
12826 line_ptr
+= bytes_read
;
12827 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12828 line_ptr
+= bytes_read
;
12829 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12830 line_ptr
+= bytes_read
;
12831 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12832 line_ptr
+= bytes_read
;
12834 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12836 line_ptr
+= bytes_read
;
12837 lh
->statement_program_start
= line_ptr
;
12839 if (line_ptr
> (section
->buffer
+ section
->size
))
12840 complaint (&symfile_complaints
,
12841 _("line number info header doesn't "
12842 "fit in `.debug_line' section"));
12844 discard_cleanups (back_to
);
12848 /* Subroutine of dwarf_decode_lines to simplify it.
12849 Return the file name of the psymtab for included file FILE_INDEX
12850 in line header LH of PST.
12851 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12852 If space for the result is malloc'd, it will be freed by a cleanup.
12853 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12856 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12857 const struct partial_symtab
*pst
,
12858 const char *comp_dir
)
12860 const struct file_entry fe
= lh
->file_names
[file_index
];
12861 char *include_name
= fe
.name
;
12862 char *include_name_to_compare
= include_name
;
12863 char *dir_name
= NULL
;
12864 const char *pst_filename
;
12865 char *copied_name
= NULL
;
12869 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12871 if (!IS_ABSOLUTE_PATH (include_name
)
12872 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12874 /* Avoid creating a duplicate psymtab for PST.
12875 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12876 Before we do the comparison, however, we need to account
12877 for DIR_NAME and COMP_DIR.
12878 First prepend dir_name (if non-NULL). If we still don't
12879 have an absolute path prepend comp_dir (if non-NULL).
12880 However, the directory we record in the include-file's
12881 psymtab does not contain COMP_DIR (to match the
12882 corresponding symtab(s)).
12887 bash$ gcc -g ./hello.c
12888 include_name = "hello.c"
12890 DW_AT_comp_dir = comp_dir = "/tmp"
12891 DW_AT_name = "./hello.c" */
12893 if (dir_name
!= NULL
)
12895 include_name
= concat (dir_name
, SLASH_STRING
,
12896 include_name
, (char *)NULL
);
12897 include_name_to_compare
= include_name
;
12898 make_cleanup (xfree
, include_name
);
12900 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12902 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12903 include_name
, (char *)NULL
);
12907 pst_filename
= pst
->filename
;
12908 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12910 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12911 pst_filename
, (char *)NULL
);
12912 pst_filename
= copied_name
;
12915 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12917 if (include_name_to_compare
!= include_name
)
12918 xfree (include_name_to_compare
);
12919 if (copied_name
!= NULL
)
12920 xfree (copied_name
);
12924 return include_name
;
12927 /* Ignore this record_line request. */
12930 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12935 /* Subroutine of dwarf_decode_lines to simplify it.
12936 Process the line number information in LH. */
12939 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
12940 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
12942 gdb_byte
*line_ptr
, *extended_end
;
12943 gdb_byte
*line_end
;
12944 unsigned int bytes_read
, extended_len
;
12945 unsigned char op_code
, extended_op
, adj_opcode
;
12946 CORE_ADDR baseaddr
;
12947 struct objfile
*objfile
= cu
->objfile
;
12948 bfd
*abfd
= objfile
->obfd
;
12949 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12950 const int decode_for_pst_p
= (pst
!= NULL
);
12951 struct subfile
*last_subfile
= NULL
;
12952 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
12955 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
12957 line_ptr
= lh
->statement_program_start
;
12958 line_end
= lh
->statement_program_end
;
12960 /* Read the statement sequences until there's nothing left. */
12961 while (line_ptr
< line_end
)
12963 /* state machine registers */
12964 CORE_ADDR address
= 0;
12965 unsigned int file
= 1;
12966 unsigned int line
= 1;
12967 unsigned int column
= 0;
12968 int is_stmt
= lh
->default_is_stmt
;
12969 int basic_block
= 0;
12970 int end_sequence
= 0;
12972 unsigned char op_index
= 0;
12974 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
12976 /* Start a subfile for the current file of the state machine. */
12977 /* lh->include_dirs and lh->file_names are 0-based, but the
12978 directory and file name numbers in the statement program
12980 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12984 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12986 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
12989 /* Decode the table. */
12990 while (!end_sequence
)
12992 op_code
= read_1_byte (abfd
, line_ptr
);
12994 if (line_ptr
> line_end
)
12996 dwarf2_debug_line_missing_end_sequence_complaint ();
13000 if (op_code
>= lh
->opcode_base
)
13002 /* Special operand. */
13003 adj_opcode
= op_code
- lh
->opcode_base
;
13004 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13005 / lh
->maximum_ops_per_instruction
)
13006 * lh
->minimum_instruction_length
);
13007 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13008 % lh
->maximum_ops_per_instruction
);
13009 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13010 if (lh
->num_file_names
< file
|| file
== 0)
13011 dwarf2_debug_line_missing_file_complaint ();
13012 /* For now we ignore lines not starting on an
13013 instruction boundary. */
13014 else if (op_index
== 0)
13016 lh
->file_names
[file
- 1].included_p
= 1;
13017 if (!decode_for_pst_p
&& is_stmt
)
13019 if (last_subfile
!= current_subfile
)
13021 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13023 (*p_record_line
) (last_subfile
, 0, addr
);
13024 last_subfile
= current_subfile
;
13026 /* Append row to matrix using current values. */
13027 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13028 (*p_record_line
) (current_subfile
, line
, addr
);
13033 else switch (op_code
)
13035 case DW_LNS_extended_op
:
13036 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13038 line_ptr
+= bytes_read
;
13039 extended_end
= line_ptr
+ extended_len
;
13040 extended_op
= read_1_byte (abfd
, line_ptr
);
13042 switch (extended_op
)
13044 case DW_LNE_end_sequence
:
13045 p_record_line
= record_line
;
13048 case DW_LNE_set_address
:
13049 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
13051 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13053 /* This line table is for a function which has been
13054 GCd by the linker. Ignore it. PR gdb/12528 */
13057 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
13059 complaint (&symfile_complaints
,
13060 _(".debug_line address at offset 0x%lx is 0 "
13062 line_offset
, objfile
->name
);
13063 p_record_line
= noop_record_line
;
13067 line_ptr
+= bytes_read
;
13068 address
+= baseaddr
;
13070 case DW_LNE_define_file
:
13073 unsigned int dir_index
, mod_time
, length
;
13075 cur_file
= read_direct_string (abfd
, line_ptr
,
13077 line_ptr
+= bytes_read
;
13079 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13080 line_ptr
+= bytes_read
;
13082 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13083 line_ptr
+= bytes_read
;
13085 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13086 line_ptr
+= bytes_read
;
13087 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13090 case DW_LNE_set_discriminator
:
13091 /* The discriminator is not interesting to the debugger;
13093 line_ptr
= extended_end
;
13096 complaint (&symfile_complaints
,
13097 _("mangled .debug_line section"));
13100 /* Make sure that we parsed the extended op correctly. If e.g.
13101 we expected a different address size than the producer used,
13102 we may have read the wrong number of bytes. */
13103 if (line_ptr
!= extended_end
)
13105 complaint (&symfile_complaints
,
13106 _("mangled .debug_line section"));
13111 if (lh
->num_file_names
< file
|| file
== 0)
13112 dwarf2_debug_line_missing_file_complaint ();
13115 lh
->file_names
[file
- 1].included_p
= 1;
13116 if (!decode_for_pst_p
&& is_stmt
)
13118 if (last_subfile
!= current_subfile
)
13120 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13122 (*p_record_line
) (last_subfile
, 0, addr
);
13123 last_subfile
= current_subfile
;
13125 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13126 (*p_record_line
) (current_subfile
, line
, addr
);
13131 case DW_LNS_advance_pc
:
13134 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13136 address
+= (((op_index
+ adjust
)
13137 / lh
->maximum_ops_per_instruction
)
13138 * lh
->minimum_instruction_length
);
13139 op_index
= ((op_index
+ adjust
)
13140 % lh
->maximum_ops_per_instruction
);
13141 line_ptr
+= bytes_read
;
13144 case DW_LNS_advance_line
:
13145 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
13146 line_ptr
+= bytes_read
;
13148 case DW_LNS_set_file
:
13150 /* The arrays lh->include_dirs and lh->file_names are
13151 0-based, but the directory and file name numbers in
13152 the statement program are 1-based. */
13153 struct file_entry
*fe
;
13156 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13157 line_ptr
+= bytes_read
;
13158 if (lh
->num_file_names
< file
|| file
== 0)
13159 dwarf2_debug_line_missing_file_complaint ();
13162 fe
= &lh
->file_names
[file
- 1];
13164 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13165 if (!decode_for_pst_p
)
13167 last_subfile
= current_subfile
;
13168 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13173 case DW_LNS_set_column
:
13174 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13175 line_ptr
+= bytes_read
;
13177 case DW_LNS_negate_stmt
:
13178 is_stmt
= (!is_stmt
);
13180 case DW_LNS_set_basic_block
:
13183 /* Add to the address register of the state machine the
13184 address increment value corresponding to special opcode
13185 255. I.e., this value is scaled by the minimum
13186 instruction length since special opcode 255 would have
13187 scaled the increment. */
13188 case DW_LNS_const_add_pc
:
13190 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13192 address
+= (((op_index
+ adjust
)
13193 / lh
->maximum_ops_per_instruction
)
13194 * lh
->minimum_instruction_length
);
13195 op_index
= ((op_index
+ adjust
)
13196 % lh
->maximum_ops_per_instruction
);
13199 case DW_LNS_fixed_advance_pc
:
13200 address
+= read_2_bytes (abfd
, line_ptr
);
13206 /* Unknown standard opcode, ignore it. */
13209 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13211 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13212 line_ptr
+= bytes_read
;
13217 if (lh
->num_file_names
< file
|| file
== 0)
13218 dwarf2_debug_line_missing_file_complaint ();
13221 lh
->file_names
[file
- 1].included_p
= 1;
13222 if (!decode_for_pst_p
)
13224 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13225 (*p_record_line
) (current_subfile
, 0, addr
);
13231 /* Decode the Line Number Program (LNP) for the given line_header
13232 structure and CU. The actual information extracted and the type
13233 of structures created from the LNP depends on the value of PST.
13235 1. If PST is NULL, then this procedure uses the data from the program
13236 to create all necessary symbol tables, and their linetables.
13238 2. If PST is not NULL, this procedure reads the program to determine
13239 the list of files included by the unit represented by PST, and
13240 builds all the associated partial symbol tables.
13242 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13243 It is used for relative paths in the line table.
13244 NOTE: When processing partial symtabs (pst != NULL),
13245 comp_dir == pst->dirname.
13247 NOTE: It is important that psymtabs have the same file name (via strcmp)
13248 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13249 symtab we don't use it in the name of the psymtabs we create.
13250 E.g. expand_line_sal requires this when finding psymtabs to expand.
13251 A good testcase for this is mb-inline.exp. */
13254 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13255 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13256 int want_line_info
)
13258 struct objfile
*objfile
= cu
->objfile
;
13259 const int decode_for_pst_p
= (pst
!= NULL
);
13260 struct subfile
*first_subfile
= current_subfile
;
13262 if (want_line_info
)
13263 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13265 if (decode_for_pst_p
)
13269 /* Now that we're done scanning the Line Header Program, we can
13270 create the psymtab of each included file. */
13271 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13272 if (lh
->file_names
[file_index
].included_p
== 1)
13274 char *include_name
=
13275 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13276 if (include_name
!= NULL
)
13277 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13282 /* Make sure a symtab is created for every file, even files
13283 which contain only variables (i.e. no code with associated
13287 for (i
= 0; i
< lh
->num_file_names
; i
++)
13290 struct file_entry
*fe
;
13292 fe
= &lh
->file_names
[i
];
13294 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13295 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13297 /* Skip the main file; we don't need it, and it must be
13298 allocated last, so that it will show up before the
13299 non-primary symtabs in the objfile's symtab list. */
13300 if (current_subfile
== first_subfile
)
13303 if (current_subfile
->symtab
== NULL
)
13304 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13306 fe
->symtab
= current_subfile
->symtab
;
13311 /* Start a subfile for DWARF. FILENAME is the name of the file and
13312 DIRNAME the name of the source directory which contains FILENAME
13313 or NULL if not known. COMP_DIR is the compilation directory for the
13314 linetable's compilation unit or NULL if not known.
13315 This routine tries to keep line numbers from identical absolute and
13316 relative file names in a common subfile.
13318 Using the `list' example from the GDB testsuite, which resides in
13319 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13320 of /srcdir/list0.c yields the following debugging information for list0.c:
13322 DW_AT_name: /srcdir/list0.c
13323 DW_AT_comp_dir: /compdir
13324 files.files[0].name: list0.h
13325 files.files[0].dir: /srcdir
13326 files.files[1].name: list0.c
13327 files.files[1].dir: /srcdir
13329 The line number information for list0.c has to end up in a single
13330 subfile, so that `break /srcdir/list0.c:1' works as expected.
13331 start_subfile will ensure that this happens provided that we pass the
13332 concatenation of files.files[1].dir and files.files[1].name as the
13336 dwarf2_start_subfile (char *filename
, const char *dirname
,
13337 const char *comp_dir
)
13341 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13342 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13343 second argument to start_subfile. To be consistent, we do the
13344 same here. In order not to lose the line information directory,
13345 we concatenate it to the filename when it makes sense.
13346 Note that the Dwarf3 standard says (speaking of filenames in line
13347 information): ``The directory index is ignored for file names
13348 that represent full path names''. Thus ignoring dirname in the
13349 `else' branch below isn't an issue. */
13351 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13352 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13354 fullname
= filename
;
13356 start_subfile (fullname
, comp_dir
);
13358 if (fullname
!= filename
)
13363 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13364 struct dwarf2_cu
*cu
)
13366 struct objfile
*objfile
= cu
->objfile
;
13367 struct comp_unit_head
*cu_header
= &cu
->header
;
13369 /* NOTE drow/2003-01-30: There used to be a comment and some special
13370 code here to turn a symbol with DW_AT_external and a
13371 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13372 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13373 with some versions of binutils) where shared libraries could have
13374 relocations against symbols in their debug information - the
13375 minimal symbol would have the right address, but the debug info
13376 would not. It's no longer necessary, because we will explicitly
13377 apply relocations when we read in the debug information now. */
13379 /* A DW_AT_location attribute with no contents indicates that a
13380 variable has been optimized away. */
13381 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13383 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13387 /* Handle one degenerate form of location expression specially, to
13388 preserve GDB's previous behavior when section offsets are
13389 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13390 then mark this symbol as LOC_STATIC. */
13392 if (attr_form_is_block (attr
)
13393 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13394 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13395 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13396 && (DW_BLOCK (attr
)->size
13397 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13399 unsigned int dummy
;
13401 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13402 SYMBOL_VALUE_ADDRESS (sym
) =
13403 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13405 SYMBOL_VALUE_ADDRESS (sym
) =
13406 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13407 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13408 fixup_symbol_section (sym
, objfile
);
13409 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13410 SYMBOL_SECTION (sym
));
13414 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13415 expression evaluator, and use LOC_COMPUTED only when necessary
13416 (i.e. when the value of a register or memory location is
13417 referenced, or a thread-local block, etc.). Then again, it might
13418 not be worthwhile. I'm assuming that it isn't unless performance
13419 or memory numbers show me otherwise. */
13421 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13422 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13424 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13425 cu
->has_loclist
= 1;
13428 /* Given a pointer to a DWARF information entry, figure out if we need
13429 to make a symbol table entry for it, and if so, create a new entry
13430 and return a pointer to it.
13431 If TYPE is NULL, determine symbol type from the die, otherwise
13432 used the passed type.
13433 If SPACE is not NULL, use it to hold the new symbol. If it is
13434 NULL, allocate a new symbol on the objfile's obstack. */
13436 static struct symbol
*
13437 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13438 struct symbol
*space
)
13440 struct objfile
*objfile
= cu
->objfile
;
13441 struct symbol
*sym
= NULL
;
13443 struct attribute
*attr
= NULL
;
13444 struct attribute
*attr2
= NULL
;
13445 CORE_ADDR baseaddr
;
13446 struct pending
**list_to_add
= NULL
;
13448 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13450 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13452 name
= dwarf2_name (die
, cu
);
13455 const char *linkagename
;
13456 int suppress_add
= 0;
13461 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13462 OBJSTAT (objfile
, n_syms
++);
13464 /* Cache this symbol's name and the name's demangled form (if any). */
13465 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13466 linkagename
= dwarf2_physname (name
, die
, cu
);
13467 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13469 /* Fortran does not have mangling standard and the mangling does differ
13470 between gfortran, iFort etc. */
13471 if (cu
->language
== language_fortran
13472 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13473 symbol_set_demangled_name (&(sym
->ginfo
),
13474 (char *) dwarf2_full_name (name
, die
, cu
),
13477 /* Default assumptions.
13478 Use the passed type or decode it from the die. */
13479 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13480 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13482 SYMBOL_TYPE (sym
) = type
;
13484 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13485 attr
= dwarf2_attr (die
,
13486 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13490 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13493 attr
= dwarf2_attr (die
,
13494 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13498 int file_index
= DW_UNSND (attr
);
13500 if (cu
->line_header
== NULL
13501 || file_index
> cu
->line_header
->num_file_names
)
13502 complaint (&symfile_complaints
,
13503 _("file index out of range"));
13504 else if (file_index
> 0)
13506 struct file_entry
*fe
;
13508 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13509 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13516 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13519 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13521 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13522 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13523 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13524 add_symbol_to_list (sym
, cu
->list_in_scope
);
13526 case DW_TAG_subprogram
:
13527 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13529 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13530 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13531 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13532 || cu
->language
== language_ada
)
13534 /* Subprograms marked external are stored as a global symbol.
13535 Ada subprograms, whether marked external or not, are always
13536 stored as a global symbol, because we want to be able to
13537 access them globally. For instance, we want to be able
13538 to break on a nested subprogram without having to
13539 specify the context. */
13540 list_to_add
= &global_symbols
;
13544 list_to_add
= cu
->list_in_scope
;
13547 case DW_TAG_inlined_subroutine
:
13548 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13550 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13551 SYMBOL_INLINED (sym
) = 1;
13552 list_to_add
= cu
->list_in_scope
;
13554 case DW_TAG_template_value_param
:
13556 /* Fall through. */
13557 case DW_TAG_constant
:
13558 case DW_TAG_variable
:
13559 case DW_TAG_member
:
13560 /* Compilation with minimal debug info may result in
13561 variables with missing type entries. Change the
13562 misleading `void' type to something sensible. */
13563 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13565 = objfile_type (objfile
)->nodebug_data_symbol
;
13567 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13568 /* In the case of DW_TAG_member, we should only be called for
13569 static const members. */
13570 if (die
->tag
== DW_TAG_member
)
13572 /* dwarf2_add_field uses die_is_declaration,
13573 so we do the same. */
13574 gdb_assert (die_is_declaration (die
, cu
));
13579 dwarf2_const_value (attr
, sym
, cu
);
13580 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13583 if (attr2
&& (DW_UNSND (attr2
) != 0))
13584 list_to_add
= &global_symbols
;
13586 list_to_add
= cu
->list_in_scope
;
13590 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13593 var_decode_location (attr
, sym
, cu
);
13594 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13595 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13596 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13597 && !dwarf2_per_objfile
->has_section_at_zero
)
13599 /* When a static variable is eliminated by the linker,
13600 the corresponding debug information is not stripped
13601 out, but the variable address is set to null;
13602 do not add such variables into symbol table. */
13604 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13606 /* Workaround gfortran PR debug/40040 - it uses
13607 DW_AT_location for variables in -fPIC libraries which may
13608 get overriden by other libraries/executable and get
13609 a different address. Resolve it by the minimal symbol
13610 which may come from inferior's executable using copy
13611 relocation. Make this workaround only for gfortran as for
13612 other compilers GDB cannot guess the minimal symbol
13613 Fortran mangling kind. */
13614 if (cu
->language
== language_fortran
&& die
->parent
13615 && die
->parent
->tag
== DW_TAG_module
13617 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13618 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13620 /* A variable with DW_AT_external is never static,
13621 but it may be block-scoped. */
13622 list_to_add
= (cu
->list_in_scope
== &file_symbols
13623 ? &global_symbols
: cu
->list_in_scope
);
13626 list_to_add
= cu
->list_in_scope
;
13630 /* We do not know the address of this symbol.
13631 If it is an external symbol and we have type information
13632 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13633 The address of the variable will then be determined from
13634 the minimal symbol table whenever the variable is
13636 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13637 if (attr2
&& (DW_UNSND (attr2
) != 0)
13638 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13640 /* A variable with DW_AT_external is never static, but it
13641 may be block-scoped. */
13642 list_to_add
= (cu
->list_in_scope
== &file_symbols
13643 ? &global_symbols
: cu
->list_in_scope
);
13645 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13647 else if (!die_is_declaration (die
, cu
))
13649 /* Use the default LOC_OPTIMIZED_OUT class. */
13650 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13652 list_to_add
= cu
->list_in_scope
;
13656 case DW_TAG_formal_parameter
:
13657 /* If we are inside a function, mark this as an argument. If
13658 not, we might be looking at an argument to an inlined function
13659 when we do not have enough information to show inlined frames;
13660 pretend it's a local variable in that case so that the user can
13662 if (context_stack_depth
> 0
13663 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13664 SYMBOL_IS_ARGUMENT (sym
) = 1;
13665 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13668 var_decode_location (attr
, sym
, cu
);
13670 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13673 dwarf2_const_value (attr
, sym
, cu
);
13676 list_to_add
= cu
->list_in_scope
;
13678 case DW_TAG_unspecified_parameters
:
13679 /* From varargs functions; gdb doesn't seem to have any
13680 interest in this information, so just ignore it for now.
13683 case DW_TAG_template_type_param
:
13685 /* Fall through. */
13686 case DW_TAG_class_type
:
13687 case DW_TAG_interface_type
:
13688 case DW_TAG_structure_type
:
13689 case DW_TAG_union_type
:
13690 case DW_TAG_set_type
:
13691 case DW_TAG_enumeration_type
:
13692 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13693 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13696 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13697 really ever be static objects: otherwise, if you try
13698 to, say, break of a class's method and you're in a file
13699 which doesn't mention that class, it won't work unless
13700 the check for all static symbols in lookup_symbol_aux
13701 saves you. See the OtherFileClass tests in
13702 gdb.c++/namespace.exp. */
13706 list_to_add
= (cu
->list_in_scope
== &file_symbols
13707 && (cu
->language
== language_cplus
13708 || cu
->language
== language_java
)
13709 ? &global_symbols
: cu
->list_in_scope
);
13711 /* The semantics of C++ state that "struct foo {
13712 ... }" also defines a typedef for "foo". A Java
13713 class declaration also defines a typedef for the
13715 if (cu
->language
== language_cplus
13716 || cu
->language
== language_java
13717 || cu
->language
== language_ada
)
13719 /* The symbol's name is already allocated along
13720 with this objfile, so we don't need to
13721 duplicate it for the type. */
13722 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13723 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13728 case DW_TAG_typedef
:
13729 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13730 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13731 list_to_add
= cu
->list_in_scope
;
13733 case DW_TAG_base_type
:
13734 case DW_TAG_subrange_type
:
13735 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13736 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13737 list_to_add
= cu
->list_in_scope
;
13739 case DW_TAG_enumerator
:
13740 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13743 dwarf2_const_value (attr
, sym
, cu
);
13746 /* NOTE: carlton/2003-11-10: See comment above in the
13747 DW_TAG_class_type, etc. block. */
13749 list_to_add
= (cu
->list_in_scope
== &file_symbols
13750 && (cu
->language
== language_cplus
13751 || cu
->language
== language_java
)
13752 ? &global_symbols
: cu
->list_in_scope
);
13755 case DW_TAG_namespace
:
13756 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13757 list_to_add
= &global_symbols
;
13760 /* Not a tag we recognize. Hopefully we aren't processing
13761 trash data, but since we must specifically ignore things
13762 we don't recognize, there is nothing else we should do at
13764 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13765 dwarf_tag_name (die
->tag
));
13771 sym
->hash_next
= objfile
->template_symbols
;
13772 objfile
->template_symbols
= sym
;
13773 list_to_add
= NULL
;
13776 if (list_to_add
!= NULL
)
13777 add_symbol_to_list (sym
, list_to_add
);
13779 /* For the benefit of old versions of GCC, check for anonymous
13780 namespaces based on the demangled name. */
13781 if (!processing_has_namespace_info
13782 && cu
->language
== language_cplus
)
13783 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13788 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13790 static struct symbol
*
13791 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13793 return new_symbol_full (die
, type
, cu
, NULL
);
13796 /* Given an attr with a DW_FORM_dataN value in host byte order,
13797 zero-extend it as appropriate for the symbol's type. The DWARF
13798 standard (v4) is not entirely clear about the meaning of using
13799 DW_FORM_dataN for a constant with a signed type, where the type is
13800 wider than the data. The conclusion of a discussion on the DWARF
13801 list was that this is unspecified. We choose to always zero-extend
13802 because that is the interpretation long in use by GCC. */
13805 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13806 const char *name
, struct obstack
*obstack
,
13807 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13809 struct objfile
*objfile
= cu
->objfile
;
13810 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13811 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13812 LONGEST l
= DW_UNSND (attr
);
13814 if (bits
< sizeof (*value
) * 8)
13816 l
&= ((LONGEST
) 1 << bits
) - 1;
13819 else if (bits
== sizeof (*value
) * 8)
13823 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13824 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13831 /* Read a constant value from an attribute. Either set *VALUE, or if
13832 the value does not fit in *VALUE, set *BYTES - either already
13833 allocated on the objfile obstack, or newly allocated on OBSTACK,
13834 or, set *BATON, if we translated the constant to a location
13838 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13839 const char *name
, struct obstack
*obstack
,
13840 struct dwarf2_cu
*cu
,
13841 LONGEST
*value
, gdb_byte
**bytes
,
13842 struct dwarf2_locexpr_baton
**baton
)
13844 struct objfile
*objfile
= cu
->objfile
;
13845 struct comp_unit_head
*cu_header
= &cu
->header
;
13846 struct dwarf_block
*blk
;
13847 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13848 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13854 switch (attr
->form
)
13857 case DW_FORM_GNU_addr_index
:
13861 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13862 dwarf2_const_value_length_mismatch_complaint (name
,
13863 cu_header
->addr_size
,
13864 TYPE_LENGTH (type
));
13865 /* Symbols of this form are reasonably rare, so we just
13866 piggyback on the existing location code rather than writing
13867 a new implementation of symbol_computed_ops. */
13868 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13869 sizeof (struct dwarf2_locexpr_baton
));
13870 (*baton
)->per_cu
= cu
->per_cu
;
13871 gdb_assert ((*baton
)->per_cu
);
13873 (*baton
)->size
= 2 + cu_header
->addr_size
;
13874 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13875 (*baton
)->data
= data
;
13877 data
[0] = DW_OP_addr
;
13878 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13879 byte_order
, DW_ADDR (attr
));
13880 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13883 case DW_FORM_string
:
13885 case DW_FORM_GNU_str_index
:
13886 /* DW_STRING is already allocated on the objfile obstack, point
13888 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13890 case DW_FORM_block1
:
13891 case DW_FORM_block2
:
13892 case DW_FORM_block4
:
13893 case DW_FORM_block
:
13894 case DW_FORM_exprloc
:
13895 blk
= DW_BLOCK (attr
);
13896 if (TYPE_LENGTH (type
) != blk
->size
)
13897 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13898 TYPE_LENGTH (type
));
13899 *bytes
= blk
->data
;
13902 /* The DW_AT_const_value attributes are supposed to carry the
13903 symbol's value "represented as it would be on the target
13904 architecture." By the time we get here, it's already been
13905 converted to host endianness, so we just need to sign- or
13906 zero-extend it as appropriate. */
13907 case DW_FORM_data1
:
13908 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13909 obstack
, cu
, value
, 8);
13911 case DW_FORM_data2
:
13912 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13913 obstack
, cu
, value
, 16);
13915 case DW_FORM_data4
:
13916 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13917 obstack
, cu
, value
, 32);
13919 case DW_FORM_data8
:
13920 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13921 obstack
, cu
, value
, 64);
13924 case DW_FORM_sdata
:
13925 *value
= DW_SND (attr
);
13928 case DW_FORM_udata
:
13929 *value
= DW_UNSND (attr
);
13933 complaint (&symfile_complaints
,
13934 _("unsupported const value attribute form: '%s'"),
13935 dwarf_form_name (attr
->form
));
13942 /* Copy constant value from an attribute to a symbol. */
13945 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
13946 struct dwarf2_cu
*cu
)
13948 struct objfile
*objfile
= cu
->objfile
;
13949 struct comp_unit_head
*cu_header
= &cu
->header
;
13952 struct dwarf2_locexpr_baton
*baton
;
13954 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
13955 SYMBOL_PRINT_NAME (sym
),
13956 &objfile
->objfile_obstack
, cu
,
13957 &value
, &bytes
, &baton
);
13961 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13962 SYMBOL_LOCATION_BATON (sym
) = baton
;
13963 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13965 else if (bytes
!= NULL
)
13967 SYMBOL_VALUE_BYTES (sym
) = bytes
;
13968 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
13972 SYMBOL_VALUE (sym
) = value
;
13973 SYMBOL_CLASS (sym
) = LOC_CONST
;
13977 /* Return the type of the die in question using its DW_AT_type attribute. */
13979 static struct type
*
13980 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13982 struct attribute
*type_attr
;
13984 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13987 /* A missing DW_AT_type represents a void type. */
13988 return objfile_type (cu
->objfile
)->builtin_void
;
13991 return lookup_die_type (die
, type_attr
, cu
);
13994 /* True iff CU's producer generates GNAT Ada auxiliary information
13995 that allows to find parallel types through that information instead
13996 of having to do expensive parallel lookups by type name. */
13999 need_gnat_info (struct dwarf2_cu
*cu
)
14001 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14002 of GNAT produces this auxiliary information, without any indication
14003 that it is produced. Part of enhancing the FSF version of GNAT
14004 to produce that information will be to put in place an indicator
14005 that we can use in order to determine whether the descriptive type
14006 info is available or not. One suggestion that has been made is
14007 to use a new attribute, attached to the CU die. For now, assume
14008 that the descriptive type info is not available. */
14012 /* Return the auxiliary type of the die in question using its
14013 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14014 attribute is not present. */
14016 static struct type
*
14017 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14019 struct attribute
*type_attr
;
14021 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
14025 return lookup_die_type (die
, type_attr
, cu
);
14028 /* If DIE has a descriptive_type attribute, then set the TYPE's
14029 descriptive type accordingly. */
14032 set_descriptive_type (struct type
*type
, struct die_info
*die
,
14033 struct dwarf2_cu
*cu
)
14035 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
14037 if (descriptive_type
)
14039 ALLOCATE_GNAT_AUX_TYPE (type
);
14040 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
14044 /* Return the containing type of the die in question using its
14045 DW_AT_containing_type attribute. */
14047 static struct type
*
14048 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14050 struct attribute
*type_attr
;
14052 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
14054 error (_("Dwarf Error: Problem turning containing type into gdb type "
14055 "[in module %s]"), cu
->objfile
->name
);
14057 return lookup_die_type (die
, type_attr
, cu
);
14060 /* Look up the type of DIE in CU using its type attribute ATTR.
14061 If there is no type substitute an error marker. */
14063 static struct type
*
14064 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
14065 struct dwarf2_cu
*cu
)
14067 struct objfile
*objfile
= cu
->objfile
;
14068 struct type
*this_type
;
14070 /* First see if we have it cached. */
14072 if (is_ref_attr (attr
))
14074 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14076 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
14078 else if (attr
->form
== DW_FORM_ref_sig8
)
14080 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14082 /* sig_type will be NULL if the signatured type is missing from
14084 if (sig_type
== NULL
)
14085 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14086 "at 0x%x [in module %s]"),
14087 die
->offset
.sect_off
, objfile
->name
);
14089 gdb_assert (sig_type
->per_cu
.is_debug_types
);
14090 /* If we haven't filled in type_offset_in_section yet, then we
14091 haven't read the type in yet. */
14093 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
14096 get_die_type_at_offset (sig_type
->type_offset_in_section
,
14097 &sig_type
->per_cu
);
14102 dump_die_for_error (die
);
14103 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
14104 dwarf_attr_name (attr
->name
), objfile
->name
);
14107 /* If not cached we need to read it in. */
14109 if (this_type
== NULL
)
14111 struct die_info
*type_die
;
14112 struct dwarf2_cu
*type_cu
= cu
;
14114 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
14115 /* If we found the type now, it's probably because the type came
14116 from an inter-CU reference and the type's CU got expanded before
14118 this_type
= get_die_type (type_die
, type_cu
);
14119 if (this_type
== NULL
)
14120 this_type
= read_type_die_1 (type_die
, type_cu
);
14123 /* If we still don't have a type use an error marker. */
14125 if (this_type
== NULL
)
14127 char *message
, *saved
;
14129 /* read_type_die already issued a complaint. */
14130 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
14132 cu
->header
.offset
.sect_off
,
14133 die
->offset
.sect_off
);
14134 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
14135 message
, strlen (message
));
14138 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
14144 /* Return the type in DIE, CU.
14145 Returns NULL for invalid types.
14147 This first does a lookup in the appropriate type_hash table,
14148 and only reads the die in if necessary.
14150 NOTE: This can be called when reading in partial or full symbols. */
14152 static struct type
*
14153 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
14155 struct type
*this_type
;
14157 this_type
= get_die_type (die
, cu
);
14161 return read_type_die_1 (die
, cu
);
14164 /* Read the type in DIE, CU.
14165 Returns NULL for invalid types. */
14167 static struct type
*
14168 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14170 struct type
*this_type
= NULL
;
14174 case DW_TAG_class_type
:
14175 case DW_TAG_interface_type
:
14176 case DW_TAG_structure_type
:
14177 case DW_TAG_union_type
:
14178 this_type
= read_structure_type (die
, cu
);
14180 case DW_TAG_enumeration_type
:
14181 this_type
= read_enumeration_type (die
, cu
);
14183 case DW_TAG_subprogram
:
14184 case DW_TAG_subroutine_type
:
14185 case DW_TAG_inlined_subroutine
:
14186 this_type
= read_subroutine_type (die
, cu
);
14188 case DW_TAG_array_type
:
14189 this_type
= read_array_type (die
, cu
);
14191 case DW_TAG_set_type
:
14192 this_type
= read_set_type (die
, cu
);
14194 case DW_TAG_pointer_type
:
14195 this_type
= read_tag_pointer_type (die
, cu
);
14197 case DW_TAG_ptr_to_member_type
:
14198 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14200 case DW_TAG_reference_type
:
14201 this_type
= read_tag_reference_type (die
, cu
);
14203 case DW_TAG_const_type
:
14204 this_type
= read_tag_const_type (die
, cu
);
14206 case DW_TAG_volatile_type
:
14207 this_type
= read_tag_volatile_type (die
, cu
);
14209 case DW_TAG_string_type
:
14210 this_type
= read_tag_string_type (die
, cu
);
14212 case DW_TAG_typedef
:
14213 this_type
= read_typedef (die
, cu
);
14215 case DW_TAG_subrange_type
:
14216 this_type
= read_subrange_type (die
, cu
);
14218 case DW_TAG_base_type
:
14219 this_type
= read_base_type (die
, cu
);
14221 case DW_TAG_unspecified_type
:
14222 this_type
= read_unspecified_type (die
, cu
);
14224 case DW_TAG_namespace
:
14225 this_type
= read_namespace_type (die
, cu
);
14227 case DW_TAG_module
:
14228 this_type
= read_module_type (die
, cu
);
14231 complaint (&symfile_complaints
,
14232 _("unexpected tag in read_type_die: '%s'"),
14233 dwarf_tag_name (die
->tag
));
14240 /* See if we can figure out if the class lives in a namespace. We do
14241 this by looking for a member function; its demangled name will
14242 contain namespace info, if there is any.
14243 Return the computed name or NULL.
14244 Space for the result is allocated on the objfile's obstack.
14245 This is the full-die version of guess_partial_die_structure_name.
14246 In this case we know DIE has no useful parent. */
14249 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14251 struct die_info
*spec_die
;
14252 struct dwarf2_cu
*spec_cu
;
14253 struct die_info
*child
;
14256 spec_die
= die_specification (die
, &spec_cu
);
14257 if (spec_die
!= NULL
)
14263 for (child
= die
->child
;
14265 child
= child
->sibling
)
14267 if (child
->tag
== DW_TAG_subprogram
)
14269 struct attribute
*attr
;
14271 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14273 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14277 = language_class_name_from_physname (cu
->language_defn
,
14281 if (actual_name
!= NULL
)
14283 char *die_name
= dwarf2_name (die
, cu
);
14285 if (die_name
!= NULL
14286 && strcmp (die_name
, actual_name
) != 0)
14288 /* Strip off the class name from the full name.
14289 We want the prefix. */
14290 int die_name_len
= strlen (die_name
);
14291 int actual_name_len
= strlen (actual_name
);
14293 /* Test for '::' as a sanity check. */
14294 if (actual_name_len
> die_name_len
+ 2
14295 && actual_name
[actual_name_len
14296 - die_name_len
- 1] == ':')
14298 obsavestring (actual_name
,
14299 actual_name_len
- die_name_len
- 2,
14300 &cu
->objfile
->objfile_obstack
);
14303 xfree (actual_name
);
14312 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14313 prefix part in such case. See
14314 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14317 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14319 struct attribute
*attr
;
14322 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14323 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14326 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14327 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14330 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14332 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14333 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14336 /* dwarf2_name had to be already called. */
14337 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14339 /* Strip the base name, keep any leading namespaces/classes. */
14340 base
= strrchr (DW_STRING (attr
), ':');
14341 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14344 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14345 &cu
->objfile
->objfile_obstack
);
14348 /* Return the name of the namespace/class that DIE is defined within,
14349 or "" if we can't tell. The caller should not xfree the result.
14351 For example, if we're within the method foo() in the following
14361 then determine_prefix on foo's die will return "N::C". */
14363 static const char *
14364 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14366 struct die_info
*parent
, *spec_die
;
14367 struct dwarf2_cu
*spec_cu
;
14368 struct type
*parent_type
;
14371 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14372 && cu
->language
!= language_fortran
)
14375 retval
= anonymous_struct_prefix (die
, cu
);
14379 /* We have to be careful in the presence of DW_AT_specification.
14380 For example, with GCC 3.4, given the code
14384 // Definition of N::foo.
14388 then we'll have a tree of DIEs like this:
14390 1: DW_TAG_compile_unit
14391 2: DW_TAG_namespace // N
14392 3: DW_TAG_subprogram // declaration of N::foo
14393 4: DW_TAG_subprogram // definition of N::foo
14394 DW_AT_specification // refers to die #3
14396 Thus, when processing die #4, we have to pretend that we're in
14397 the context of its DW_AT_specification, namely the contex of die
14400 spec_die
= die_specification (die
, &spec_cu
);
14401 if (spec_die
== NULL
)
14402 parent
= die
->parent
;
14405 parent
= spec_die
->parent
;
14409 if (parent
== NULL
)
14411 else if (parent
->building_fullname
)
14414 const char *parent_name
;
14416 /* It has been seen on RealView 2.2 built binaries,
14417 DW_TAG_template_type_param types actually _defined_ as
14418 children of the parent class:
14421 template class <class Enum> Class{};
14422 Class<enum E> class_e;
14424 1: DW_TAG_class_type (Class)
14425 2: DW_TAG_enumeration_type (E)
14426 3: DW_TAG_enumerator (enum1:0)
14427 3: DW_TAG_enumerator (enum2:1)
14429 2: DW_TAG_template_type_param
14430 DW_AT_type DW_FORM_ref_udata (E)
14432 Besides being broken debug info, it can put GDB into an
14433 infinite loop. Consider:
14435 When we're building the full name for Class<E>, we'll start
14436 at Class, and go look over its template type parameters,
14437 finding E. We'll then try to build the full name of E, and
14438 reach here. We're now trying to build the full name of E,
14439 and look over the parent DIE for containing scope. In the
14440 broken case, if we followed the parent DIE of E, we'd again
14441 find Class, and once again go look at its template type
14442 arguments, etc., etc. Simply don't consider such parent die
14443 as source-level parent of this die (it can't be, the language
14444 doesn't allow it), and break the loop here. */
14445 name
= dwarf2_name (die
, cu
);
14446 parent_name
= dwarf2_name (parent
, cu
);
14447 complaint (&symfile_complaints
,
14448 _("template param type '%s' defined within parent '%s'"),
14449 name
? name
: "<unknown>",
14450 parent_name
? parent_name
: "<unknown>");
14454 switch (parent
->tag
)
14456 case DW_TAG_namespace
:
14457 parent_type
= read_type_die (parent
, cu
);
14458 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14459 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14460 Work around this problem here. */
14461 if (cu
->language
== language_cplus
14462 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14464 /* We give a name to even anonymous namespaces. */
14465 return TYPE_TAG_NAME (parent_type
);
14466 case DW_TAG_class_type
:
14467 case DW_TAG_interface_type
:
14468 case DW_TAG_structure_type
:
14469 case DW_TAG_union_type
:
14470 case DW_TAG_module
:
14471 parent_type
= read_type_die (parent
, cu
);
14472 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14473 return TYPE_TAG_NAME (parent_type
);
14475 /* An anonymous structure is only allowed non-static data
14476 members; no typedefs, no member functions, et cetera.
14477 So it does not need a prefix. */
14479 case DW_TAG_compile_unit
:
14480 case DW_TAG_partial_unit
:
14481 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14482 if (cu
->language
== language_cplus
14483 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14484 && die
->child
!= NULL
14485 && (die
->tag
== DW_TAG_class_type
14486 || die
->tag
== DW_TAG_structure_type
14487 || die
->tag
== DW_TAG_union_type
))
14489 char *name
= guess_full_die_structure_name (die
, cu
);
14495 return determine_prefix (parent
, cu
);
14499 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14500 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14501 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14502 an obconcat, otherwise allocate storage for the result. The CU argument is
14503 used to determine the language and hence, the appropriate separator. */
14505 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14508 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14509 int physname
, struct dwarf2_cu
*cu
)
14511 const char *lead
= "";
14514 if (suffix
== NULL
|| suffix
[0] == '\0'
14515 || prefix
== NULL
|| prefix
[0] == '\0')
14517 else if (cu
->language
== language_java
)
14519 else if (cu
->language
== language_fortran
&& physname
)
14521 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14522 DW_AT_MIPS_linkage_name is preferred and used instead. */
14530 if (prefix
== NULL
)
14532 if (suffix
== NULL
)
14538 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14540 strcpy (retval
, lead
);
14541 strcat (retval
, prefix
);
14542 strcat (retval
, sep
);
14543 strcat (retval
, suffix
);
14548 /* We have an obstack. */
14549 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14553 /* Return sibling of die, NULL if no sibling. */
14555 static struct die_info
*
14556 sibling_die (struct die_info
*die
)
14558 return die
->sibling
;
14561 /* Get name of a die, return NULL if not found. */
14564 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14565 struct obstack
*obstack
)
14567 if (name
&& cu
->language
== language_cplus
)
14569 char *canon_name
= cp_canonicalize_string (name
);
14571 if (canon_name
!= NULL
)
14573 if (strcmp (canon_name
, name
) != 0)
14574 name
= obsavestring (canon_name
, strlen (canon_name
),
14576 xfree (canon_name
);
14583 /* Get name of a die, return NULL if not found. */
14586 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14588 struct attribute
*attr
;
14590 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14591 if ((!attr
|| !DW_STRING (attr
))
14592 && die
->tag
!= DW_TAG_class_type
14593 && die
->tag
!= DW_TAG_interface_type
14594 && die
->tag
!= DW_TAG_structure_type
14595 && die
->tag
!= DW_TAG_union_type
)
14600 case DW_TAG_compile_unit
:
14601 case DW_TAG_partial_unit
:
14602 /* Compilation units have a DW_AT_name that is a filename, not
14603 a source language identifier. */
14604 case DW_TAG_enumeration_type
:
14605 case DW_TAG_enumerator
:
14606 /* These tags always have simple identifiers already; no need
14607 to canonicalize them. */
14608 return DW_STRING (attr
);
14610 case DW_TAG_subprogram
:
14611 /* Java constructors will all be named "<init>", so return
14612 the class name when we see this special case. */
14613 if (cu
->language
== language_java
14614 && DW_STRING (attr
) != NULL
14615 && strcmp (DW_STRING (attr
), "<init>") == 0)
14617 struct dwarf2_cu
*spec_cu
= cu
;
14618 struct die_info
*spec_die
;
14620 /* GCJ will output '<init>' for Java constructor names.
14621 For this special case, return the name of the parent class. */
14623 /* GCJ may output suprogram DIEs with AT_specification set.
14624 If so, use the name of the specified DIE. */
14625 spec_die
= die_specification (die
, &spec_cu
);
14626 if (spec_die
!= NULL
)
14627 return dwarf2_name (spec_die
, spec_cu
);
14632 if (die
->tag
== DW_TAG_class_type
)
14633 return dwarf2_name (die
, cu
);
14635 while (die
->tag
!= DW_TAG_compile_unit
14636 && die
->tag
!= DW_TAG_partial_unit
);
14640 case DW_TAG_class_type
:
14641 case DW_TAG_interface_type
:
14642 case DW_TAG_structure_type
:
14643 case DW_TAG_union_type
:
14644 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14645 structures or unions. These were of the form "._%d" in GCC 4.1,
14646 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14647 and GCC 4.4. We work around this problem by ignoring these. */
14648 if (attr
&& DW_STRING (attr
)
14649 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14650 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14653 /* GCC might emit a nameless typedef that has a linkage name. See
14654 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14655 if (!attr
|| DW_STRING (attr
) == NULL
)
14657 char *demangled
= NULL
;
14659 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14661 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14663 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14666 /* Avoid demangling DW_STRING (attr) the second time on a second
14667 call for the same DIE. */
14668 if (!DW_STRING_IS_CANONICAL (attr
))
14669 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14675 /* FIXME: we already did this for the partial symbol... */
14676 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14677 &cu
->objfile
->objfile_obstack
);
14678 DW_STRING_IS_CANONICAL (attr
) = 1;
14681 /* Strip any leading namespaces/classes, keep only the base name.
14682 DW_AT_name for named DIEs does not contain the prefixes. */
14683 base
= strrchr (DW_STRING (attr
), ':');
14684 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14687 return DW_STRING (attr
);
14696 if (!DW_STRING_IS_CANONICAL (attr
))
14699 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14700 &cu
->objfile
->objfile_obstack
);
14701 DW_STRING_IS_CANONICAL (attr
) = 1;
14703 return DW_STRING (attr
);
14706 /* Return the die that this die in an extension of, or NULL if there
14707 is none. *EXT_CU is the CU containing DIE on input, and the CU
14708 containing the return value on output. */
14710 static struct die_info
*
14711 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14713 struct attribute
*attr
;
14715 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14719 return follow_die_ref (die
, attr
, ext_cu
);
14722 /* Convert a DIE tag into its string name. */
14724 static const char *
14725 dwarf_tag_name (unsigned tag
)
14727 const char *name
= get_DW_TAG_name (tag
);
14730 return "DW_TAG_<unknown>";
14735 /* Convert a DWARF attribute code into its string name. */
14737 static const char *
14738 dwarf_attr_name (unsigned attr
)
14742 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14743 if (attr
== DW_AT_MIPS_fde
)
14744 return "DW_AT_MIPS_fde";
14746 if (attr
== DW_AT_HP_block_index
)
14747 return "DW_AT_HP_block_index";
14750 name
= get_DW_AT_name (attr
);
14753 return "DW_AT_<unknown>";
14758 /* Convert a DWARF value form code into its string name. */
14760 static const char *
14761 dwarf_form_name (unsigned form
)
14763 const char *name
= get_DW_FORM_name (form
);
14766 return "DW_FORM_<unknown>";
14772 dwarf_bool_name (unsigned mybool
)
14780 /* Convert a DWARF type code into its string name. */
14782 static const char *
14783 dwarf_type_encoding_name (unsigned enc
)
14785 const char *name
= get_DW_ATE_name (enc
);
14788 return "DW_ATE_<unknown>";
14794 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14798 print_spaces (indent
, f
);
14799 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14800 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14802 if (die
->parent
!= NULL
)
14804 print_spaces (indent
, f
);
14805 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14806 die
->parent
->offset
.sect_off
);
14809 print_spaces (indent
, f
);
14810 fprintf_unfiltered (f
, " has children: %s\n",
14811 dwarf_bool_name (die
->child
!= NULL
));
14813 print_spaces (indent
, f
);
14814 fprintf_unfiltered (f
, " attributes:\n");
14816 for (i
= 0; i
< die
->num_attrs
; ++i
)
14818 print_spaces (indent
, f
);
14819 fprintf_unfiltered (f
, " %s (%s) ",
14820 dwarf_attr_name (die
->attrs
[i
].name
),
14821 dwarf_form_name (die
->attrs
[i
].form
));
14823 switch (die
->attrs
[i
].form
)
14826 case DW_FORM_GNU_addr_index
:
14827 fprintf_unfiltered (f
, "address: ");
14828 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14830 case DW_FORM_block2
:
14831 case DW_FORM_block4
:
14832 case DW_FORM_block
:
14833 case DW_FORM_block1
:
14834 fprintf_unfiltered (f
, "block: size %d",
14835 DW_BLOCK (&die
->attrs
[i
])->size
);
14837 case DW_FORM_exprloc
:
14838 fprintf_unfiltered (f
, "expression: size %u",
14839 DW_BLOCK (&die
->attrs
[i
])->size
);
14841 case DW_FORM_ref_addr
:
14842 fprintf_unfiltered (f
, "ref address: ");
14843 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14849 case DW_FORM_ref_udata
:
14850 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14851 (long) (DW_UNSND (&die
->attrs
[i
])));
14853 case DW_FORM_data1
:
14854 case DW_FORM_data2
:
14855 case DW_FORM_data4
:
14856 case DW_FORM_data8
:
14857 case DW_FORM_udata
:
14858 case DW_FORM_sdata
:
14859 fprintf_unfiltered (f
, "constant: %s",
14860 pulongest (DW_UNSND (&die
->attrs
[i
])));
14862 case DW_FORM_sec_offset
:
14863 fprintf_unfiltered (f
, "section offset: %s",
14864 pulongest (DW_UNSND (&die
->attrs
[i
])));
14866 case DW_FORM_ref_sig8
:
14867 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14868 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14869 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14871 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14873 case DW_FORM_string
:
14875 case DW_FORM_GNU_str_index
:
14876 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14877 DW_STRING (&die
->attrs
[i
])
14878 ? DW_STRING (&die
->attrs
[i
]) : "",
14879 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14882 if (DW_UNSND (&die
->attrs
[i
]))
14883 fprintf_unfiltered (f
, "flag: TRUE");
14885 fprintf_unfiltered (f
, "flag: FALSE");
14887 case DW_FORM_flag_present
:
14888 fprintf_unfiltered (f
, "flag: TRUE");
14890 case DW_FORM_indirect
:
14891 /* The reader will have reduced the indirect form to
14892 the "base form" so this form should not occur. */
14893 fprintf_unfiltered (f
,
14894 "unexpected attribute form: DW_FORM_indirect");
14897 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14898 die
->attrs
[i
].form
);
14901 fprintf_unfiltered (f
, "\n");
14906 dump_die_for_error (struct die_info
*die
)
14908 dump_die_shallow (gdb_stderr
, 0, die
);
14912 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14914 int indent
= level
* 4;
14916 gdb_assert (die
!= NULL
);
14918 if (level
>= max_level
)
14921 dump_die_shallow (f
, indent
, die
);
14923 if (die
->child
!= NULL
)
14925 print_spaces (indent
, f
);
14926 fprintf_unfiltered (f
, " Children:");
14927 if (level
+ 1 < max_level
)
14929 fprintf_unfiltered (f
, "\n");
14930 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
14934 fprintf_unfiltered (f
,
14935 " [not printed, max nesting level reached]\n");
14939 if (die
->sibling
!= NULL
&& level
> 0)
14941 dump_die_1 (f
, level
, max_level
, die
->sibling
);
14945 /* This is called from the pdie macro in gdbinit.in.
14946 It's not static so gcc will keep a copy callable from gdb. */
14949 dump_die (struct die_info
*die
, int max_level
)
14951 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
14955 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
14959 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
14965 /* DW_ADDR is always stored already as sect_offset; despite for the forms
14966 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
14969 is_ref_attr (struct attribute
*attr
)
14971 switch (attr
->form
)
14973 case DW_FORM_ref_addr
:
14978 case DW_FORM_ref_udata
:
14985 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
14989 dwarf2_get_ref_die_offset (struct attribute
*attr
)
14991 sect_offset retval
= { DW_UNSND (attr
) };
14993 if (is_ref_attr (attr
))
14996 retval
.sect_off
= 0;
14997 complaint (&symfile_complaints
,
14998 _("unsupported die ref attribute form: '%s'"),
14999 dwarf_form_name (attr
->form
));
15003 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15004 * the value held by the attribute is not constant. */
15007 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15009 if (attr
->form
== DW_FORM_sdata
)
15010 return DW_SND (attr
);
15011 else if (attr
->form
== DW_FORM_udata
15012 || attr
->form
== DW_FORM_data1
15013 || attr
->form
== DW_FORM_data2
15014 || attr
->form
== DW_FORM_data4
15015 || attr
->form
== DW_FORM_data8
)
15016 return DW_UNSND (attr
);
15019 complaint (&symfile_complaints
,
15020 _("Attribute value is not a constant (%s)"),
15021 dwarf_form_name (attr
->form
));
15022 return default_value
;
15026 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15027 unit and add it to our queue.
15028 The result is non-zero if PER_CU was queued, otherwise the result is zero
15029 meaning either PER_CU is already queued or it is already loaded. */
15032 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15033 struct dwarf2_per_cu_data
*per_cu
,
15034 enum language pretend_language
)
15036 /* We may arrive here during partial symbol reading, if we need full
15037 DIEs to process an unusual case (e.g. template arguments). Do
15038 not queue PER_CU, just tell our caller to load its DIEs. */
15039 if (dwarf2_per_objfile
->reading_partial_symbols
)
15041 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15046 /* Mark the dependence relation so that we don't flush PER_CU
15048 dwarf2_add_dependence (this_cu
, per_cu
);
15050 /* If it's already on the queue, we have nothing to do. */
15051 if (per_cu
->queued
)
15054 /* If the compilation unit is already loaded, just mark it as
15056 if (per_cu
->cu
!= NULL
)
15058 per_cu
->cu
->last_used
= 0;
15062 /* Add it to the queue. */
15063 queue_comp_unit (per_cu
, pretend_language
);
15068 /* Follow reference or signature attribute ATTR of SRC_DIE.
15069 On entry *REF_CU is the CU of SRC_DIE.
15070 On exit *REF_CU is the CU of the result. */
15072 static struct die_info
*
15073 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15074 struct dwarf2_cu
**ref_cu
)
15076 struct die_info
*die
;
15078 if (is_ref_attr (attr
))
15079 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15080 else if (attr
->form
== DW_FORM_ref_sig8
)
15081 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15084 dump_die_for_error (src_die
);
15085 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15086 (*ref_cu
)->objfile
->name
);
15092 /* Follow reference OFFSET.
15093 On entry *REF_CU is the CU of the source die referencing OFFSET.
15094 On exit *REF_CU is the CU of the result.
15095 Returns NULL if OFFSET is invalid. */
15097 static struct die_info
*
15098 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15100 struct die_info temp_die
;
15101 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15103 gdb_assert (cu
->per_cu
!= NULL
);
15107 if (cu
->per_cu
->is_debug_types
)
15109 /* .debug_types CUs cannot reference anything outside their CU.
15110 If they need to, they have to reference a signatured type via
15111 DW_FORM_ref_sig8. */
15112 if (! offset_in_cu_p (&cu
->header
, offset
))
15115 else if (! offset_in_cu_p (&cu
->header
, offset
))
15117 struct dwarf2_per_cu_data
*per_cu
;
15119 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15121 /* If necessary, add it to the queue and load its DIEs. */
15122 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
15123 load_full_comp_unit (per_cu
, cu
->language
);
15125 target_cu
= per_cu
->cu
;
15127 else if (cu
->dies
== NULL
)
15129 /* We're loading full DIEs during partial symbol reading. */
15130 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15131 load_full_comp_unit (cu
->per_cu
, language_minimal
);
15134 *ref_cu
= target_cu
;
15135 temp_die
.offset
= offset
;
15136 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15139 /* Follow reference attribute ATTR of SRC_DIE.
15140 On entry *REF_CU is the CU of SRC_DIE.
15141 On exit *REF_CU is the CU of the result. */
15143 static struct die_info
*
15144 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15145 struct dwarf2_cu
**ref_cu
)
15147 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15148 struct dwarf2_cu
*cu
= *ref_cu
;
15149 struct die_info
*die
;
15151 die
= follow_die_offset (offset
, ref_cu
);
15153 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15154 "at 0x%x [in module %s]"),
15155 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15160 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15161 Returned value is intended for DW_OP_call*. Returned
15162 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15164 struct dwarf2_locexpr_baton
15165 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15166 struct dwarf2_per_cu_data
*per_cu
,
15167 CORE_ADDR (*get_frame_pc
) (void *baton
),
15170 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15171 struct dwarf2_cu
*cu
;
15172 struct die_info
*die
;
15173 struct attribute
*attr
;
15174 struct dwarf2_locexpr_baton retval
;
15176 dw2_setup (per_cu
->objfile
);
15178 if (per_cu
->cu
== NULL
)
15182 die
= follow_die_offset (offset
, &cu
);
15184 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15185 offset
.sect_off
, per_cu
->objfile
->name
);
15187 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15190 /* DWARF: "If there is no such attribute, then there is no effect.".
15191 DATA is ignored if SIZE is 0. */
15193 retval
.data
= NULL
;
15196 else if (attr_form_is_section_offset (attr
))
15198 struct dwarf2_loclist_baton loclist_baton
;
15199 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15202 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15204 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15206 retval
.size
= size
;
15210 if (!attr_form_is_block (attr
))
15211 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15212 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15213 offset
.sect_off
, per_cu
->objfile
->name
);
15215 retval
.data
= DW_BLOCK (attr
)->data
;
15216 retval
.size
= DW_BLOCK (attr
)->size
;
15218 retval
.per_cu
= cu
->per_cu
;
15220 age_cached_comp_units ();
15225 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15229 dwarf2_get_die_type (cu_offset die_offset
,
15230 struct dwarf2_per_cu_data
*per_cu
)
15232 sect_offset die_offset_sect
;
15234 dw2_setup (per_cu
->objfile
);
15236 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15237 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15240 /* Follow the signature attribute ATTR in SRC_DIE.
15241 On entry *REF_CU is the CU of SRC_DIE.
15242 On exit *REF_CU is the CU of the result. */
15244 static struct die_info
*
15245 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15246 struct dwarf2_cu
**ref_cu
)
15248 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15249 struct die_info temp_die
;
15250 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15251 struct dwarf2_cu
*sig_cu
;
15252 struct die_info
*die
;
15254 /* sig_type will be NULL if the signatured type is missing from
15256 if (sig_type
== NULL
)
15257 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15258 "at 0x%x [in module %s]"),
15259 src_die
->offset
.sect_off
, objfile
->name
);
15261 /* If necessary, add it to the queue and load its DIEs. */
15263 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15264 read_signatured_type (sig_type
);
15266 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15268 sig_cu
= sig_type
->per_cu
.cu
;
15269 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15270 temp_die
.offset
= sig_type
->type_offset_in_section
;
15271 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15272 temp_die
.offset
.sect_off
);
15279 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15280 "from DIE at 0x%x [in module %s]"),
15281 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15284 /* Given an offset of a signatured type, return its signatured_type. */
15286 static struct signatured_type
*
15287 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15288 struct dwarf2_section_info
*section
,
15289 sect_offset offset
)
15291 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15292 unsigned int length
, initial_length_size
;
15293 unsigned int sig_offset
;
15294 struct signatured_type find_entry
, *sig_type
;
15296 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15297 sig_offset
= (initial_length_size
15299 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15300 + 1 /*address_size*/);
15301 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15302 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15304 /* This is only used to lookup previously recorded types.
15305 If we didn't find it, it's our bug. */
15306 gdb_assert (sig_type
!= NULL
);
15307 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15312 /* Load the DIEs associated with type unit PER_CU into memory. */
15315 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15317 struct objfile
*objfile
= per_cu
->objfile
;
15318 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15319 sect_offset offset
= per_cu
->offset
;
15320 struct signatured_type
*sig_type
;
15322 dwarf2_read_section (objfile
, sect
);
15324 /* We have the section offset, but we need the signature to do the
15325 hash table lookup. */
15326 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15327 the signature to assert we found the right one.
15328 Ok, but it's a lot of work. We should simplify things so any needed
15329 assert doesn't require all this clumsiness. */
15330 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15332 gdb_assert (&sig_type
->per_cu
== per_cu
);
15333 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15335 read_signatured_type (sig_type
);
15337 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15340 /* die_reader_func for read_signatured_type.
15341 This is identical to load_full_comp_unit_reader,
15342 but is kept separate for now. */
15345 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15346 gdb_byte
*info_ptr
,
15347 struct die_info
*comp_unit_die
,
15351 struct dwarf2_cu
*cu
= reader
->cu
;
15353 gdb_assert (cu
->die_hash
== NULL
);
15355 htab_create_alloc_ex (cu
->header
.length
/ 12,
15359 &cu
->comp_unit_obstack
,
15360 hashtab_obstack_allocate
,
15361 dummy_obstack_deallocate
);
15364 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15365 &info_ptr
, comp_unit_die
);
15366 cu
->dies
= comp_unit_die
;
15367 /* comp_unit_die is not stored in die_hash, no need. */
15369 /* We try not to read any attributes in this function, because not
15370 all CUs needed for references have been loaded yet, and symbol
15371 table processing isn't initialized. But we have to set the CU language,
15372 or we won't be able to build types correctly.
15373 Similarly, if we do not read the producer, we can not apply
15374 producer-specific interpretation. */
15375 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15378 /* Read in a signatured type and build its CU and DIEs.
15379 If the type is a stub for the real type in a DWO file,
15380 read in the real type from the DWO file as well. */
15383 read_signatured_type (struct signatured_type
*sig_type
)
15385 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15387 gdb_assert (per_cu
->is_debug_types
);
15388 gdb_assert (per_cu
->cu
== NULL
);
15390 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15393 /* Decode simple location descriptions.
15394 Given a pointer to a dwarf block that defines a location, compute
15395 the location and return the value.
15397 NOTE drow/2003-11-18: This function is called in two situations
15398 now: for the address of static or global variables (partial symbols
15399 only) and for offsets into structures which are expected to be
15400 (more or less) constant. The partial symbol case should go away,
15401 and only the constant case should remain. That will let this
15402 function complain more accurately. A few special modes are allowed
15403 without complaint for global variables (for instance, global
15404 register values and thread-local values).
15406 A location description containing no operations indicates that the
15407 object is optimized out. The return value is 0 for that case.
15408 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15409 callers will only want a very basic result and this can become a
15412 Note that stack[0] is unused except as a default error return. */
15415 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15417 struct objfile
*objfile
= cu
->objfile
;
15419 int size
= blk
->size
;
15420 gdb_byte
*data
= blk
->data
;
15421 CORE_ADDR stack
[64];
15423 unsigned int bytes_read
, unsnd
;
15429 stack
[++stacki
] = 0;
15468 stack
[++stacki
] = op
- DW_OP_lit0
;
15503 stack
[++stacki
] = op
- DW_OP_reg0
;
15505 dwarf2_complex_location_expr_complaint ();
15509 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15511 stack
[++stacki
] = unsnd
;
15513 dwarf2_complex_location_expr_complaint ();
15517 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15522 case DW_OP_const1u
:
15523 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15527 case DW_OP_const1s
:
15528 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15532 case DW_OP_const2u
:
15533 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15537 case DW_OP_const2s
:
15538 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15542 case DW_OP_const4u
:
15543 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15547 case DW_OP_const4s
:
15548 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15552 case DW_OP_const8u
:
15553 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15558 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15564 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15569 stack
[stacki
+ 1] = stack
[stacki
];
15574 stack
[stacki
- 1] += stack
[stacki
];
15578 case DW_OP_plus_uconst
:
15579 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15585 stack
[stacki
- 1] -= stack
[stacki
];
15590 /* If we're not the last op, then we definitely can't encode
15591 this using GDB's address_class enum. This is valid for partial
15592 global symbols, although the variable's address will be bogus
15595 dwarf2_complex_location_expr_complaint ();
15598 case DW_OP_GNU_push_tls_address
:
15599 /* The top of the stack has the offset from the beginning
15600 of the thread control block at which the variable is located. */
15601 /* Nothing should follow this operator, so the top of stack would
15603 /* This is valid for partial global symbols, but the variable's
15604 address will be bogus in the psymtab. Make it always at least
15605 non-zero to not look as a variable garbage collected by linker
15606 which have DW_OP_addr 0. */
15608 dwarf2_complex_location_expr_complaint ();
15612 case DW_OP_GNU_uninit
:
15615 case DW_OP_GNU_addr_index
:
15616 case DW_OP_GNU_const_index
:
15617 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15624 const char *name
= get_DW_OP_name (op
);
15627 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15630 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15634 return (stack
[stacki
]);
15637 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15638 outside of the allocated space. Also enforce minimum>0. */
15639 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15641 complaint (&symfile_complaints
,
15642 _("location description stack overflow"));
15648 complaint (&symfile_complaints
,
15649 _("location description stack underflow"));
15653 return (stack
[stacki
]);
15656 /* memory allocation interface */
15658 static struct dwarf_block
*
15659 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15661 struct dwarf_block
*blk
;
15663 blk
= (struct dwarf_block
*)
15664 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15668 static struct abbrev_info
*
15669 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15671 struct abbrev_info
*abbrev
;
15673 abbrev
= (struct abbrev_info
*)
15674 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15675 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15679 static struct die_info
*
15680 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15682 struct die_info
*die
;
15683 size_t size
= sizeof (struct die_info
);
15686 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15688 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15689 memset (die
, 0, sizeof (struct die_info
));
15694 /* Macro support. */
15696 /* Return the full name of file number I in *LH's file name table.
15697 Use COMP_DIR as the name of the current directory of the
15698 compilation. The result is allocated using xmalloc; the caller is
15699 responsible for freeing it. */
15701 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15703 /* Is the file number a valid index into the line header's file name
15704 table? Remember that file numbers start with one, not zero. */
15705 if (1 <= file
&& file
<= lh
->num_file_names
)
15707 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15709 if (IS_ABSOLUTE_PATH (fe
->name
))
15710 return xstrdup (fe
->name
);
15718 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15724 dir_len
= strlen (dir
);
15725 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15726 strcpy (full_name
, dir
);
15727 full_name
[dir_len
] = '/';
15728 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15732 return xstrdup (fe
->name
);
15737 /* The compiler produced a bogus file number. We can at least
15738 record the macro definitions made in the file, even if we
15739 won't be able to find the file by name. */
15740 char fake_name
[80];
15742 sprintf (fake_name
, "<bad macro file number %d>", file
);
15744 complaint (&symfile_complaints
,
15745 _("bad file number in macro information (%d)"),
15748 return xstrdup (fake_name
);
15753 static struct macro_source_file
*
15754 macro_start_file (int file
, int line
,
15755 struct macro_source_file
*current_file
,
15756 const char *comp_dir
,
15757 struct line_header
*lh
, struct objfile
*objfile
)
15759 /* The full name of this source file. */
15760 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15762 /* We don't create a macro table for this compilation unit
15763 at all until we actually get a filename. */
15764 if (! pending_macros
)
15765 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15766 objfile
->macro_cache
);
15768 if (! current_file
)
15770 /* If we have no current file, then this must be the start_file
15771 directive for the compilation unit's main source file. */
15772 current_file
= macro_set_main (pending_macros
, full_name
);
15773 macro_define_special (pending_macros
);
15776 current_file
= macro_include (current_file
, line
, full_name
);
15780 return current_file
;
15784 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15785 followed by a null byte. */
15787 copy_string (const char *buf
, int len
)
15789 char *s
= xmalloc (len
+ 1);
15791 memcpy (s
, buf
, len
);
15797 static const char *
15798 consume_improper_spaces (const char *p
, const char *body
)
15802 complaint (&symfile_complaints
,
15803 _("macro definition contains spaces "
15804 "in formal argument list:\n`%s'"),
15816 parse_macro_definition (struct macro_source_file
*file
, int line
,
15821 /* The body string takes one of two forms. For object-like macro
15822 definitions, it should be:
15824 <macro name> " " <definition>
15826 For function-like macro definitions, it should be:
15828 <macro name> "() " <definition>
15830 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15832 Spaces may appear only where explicitly indicated, and in the
15835 The Dwarf 2 spec says that an object-like macro's name is always
15836 followed by a space, but versions of GCC around March 2002 omit
15837 the space when the macro's definition is the empty string.
15839 The Dwarf 2 spec says that there should be no spaces between the
15840 formal arguments in a function-like macro's formal argument list,
15841 but versions of GCC around March 2002 include spaces after the
15845 /* Find the extent of the macro name. The macro name is terminated
15846 by either a space or null character (for an object-like macro) or
15847 an opening paren (for a function-like macro). */
15848 for (p
= body
; *p
; p
++)
15849 if (*p
== ' ' || *p
== '(')
15852 if (*p
== ' ' || *p
== '\0')
15854 /* It's an object-like macro. */
15855 int name_len
= p
- body
;
15856 char *name
= copy_string (body
, name_len
);
15857 const char *replacement
;
15860 replacement
= body
+ name_len
+ 1;
15863 dwarf2_macro_malformed_definition_complaint (body
);
15864 replacement
= body
+ name_len
;
15867 macro_define_object (file
, line
, name
, replacement
);
15871 else if (*p
== '(')
15873 /* It's a function-like macro. */
15874 char *name
= copy_string (body
, p
- body
);
15877 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15881 p
= consume_improper_spaces (p
, body
);
15883 /* Parse the formal argument list. */
15884 while (*p
&& *p
!= ')')
15886 /* Find the extent of the current argument name. */
15887 const char *arg_start
= p
;
15889 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15892 if (! *p
|| p
== arg_start
)
15893 dwarf2_macro_malformed_definition_complaint (body
);
15896 /* Make sure argv has room for the new argument. */
15897 if (argc
>= argv_size
)
15900 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15903 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15906 p
= consume_improper_spaces (p
, body
);
15908 /* Consume the comma, if present. */
15913 p
= consume_improper_spaces (p
, body
);
15922 /* Perfectly formed definition, no complaints. */
15923 macro_define_function (file
, line
, name
,
15924 argc
, (const char **) argv
,
15926 else if (*p
== '\0')
15928 /* Complain, but do define it. */
15929 dwarf2_macro_malformed_definition_complaint (body
);
15930 macro_define_function (file
, line
, name
,
15931 argc
, (const char **) argv
,
15935 /* Just complain. */
15936 dwarf2_macro_malformed_definition_complaint (body
);
15939 /* Just complain. */
15940 dwarf2_macro_malformed_definition_complaint (body
);
15946 for (i
= 0; i
< argc
; i
++)
15952 dwarf2_macro_malformed_definition_complaint (body
);
15955 /* Skip some bytes from BYTES according to the form given in FORM.
15956 Returns the new pointer. */
15959 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
15960 enum dwarf_form form
,
15961 unsigned int offset_size
,
15962 struct dwarf2_section_info
*section
)
15964 unsigned int bytes_read
;
15968 case DW_FORM_data1
:
15973 case DW_FORM_data2
:
15977 case DW_FORM_data4
:
15981 case DW_FORM_data8
:
15985 case DW_FORM_string
:
15986 read_direct_string (abfd
, bytes
, &bytes_read
);
15987 bytes
+= bytes_read
;
15990 case DW_FORM_sec_offset
:
15992 bytes
+= offset_size
;
15995 case DW_FORM_block
:
15996 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
15997 bytes
+= bytes_read
;
16000 case DW_FORM_block1
:
16001 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16003 case DW_FORM_block2
:
16004 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16006 case DW_FORM_block4
:
16007 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16010 case DW_FORM_sdata
:
16011 case DW_FORM_udata
:
16012 case DW_FORM_GNU_addr_index
:
16013 case DW_FORM_GNU_str_index
:
16014 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16017 dwarf2_section_buffer_overflow_complaint (section
);
16025 complaint (&symfile_complaints
,
16026 _("invalid form 0x%x in `%s'"),
16028 section
->asection
->name
);
16036 /* A helper for dwarf_decode_macros that handles skipping an unknown
16037 opcode. Returns an updated pointer to the macro data buffer; or,
16038 on error, issues a complaint and returns NULL. */
16041 skip_unknown_opcode (unsigned int opcode
,
16042 gdb_byte
**opcode_definitions
,
16043 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16045 unsigned int offset_size
,
16046 struct dwarf2_section_info
*section
)
16048 unsigned int bytes_read
, i
;
16052 if (opcode_definitions
[opcode
] == NULL
)
16054 complaint (&symfile_complaints
,
16055 _("unrecognized DW_MACFINO opcode 0x%x"),
16060 defn
= opcode_definitions
[opcode
];
16061 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16062 defn
+= bytes_read
;
16064 for (i
= 0; i
< arg
; ++i
)
16066 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16068 if (mac_ptr
== NULL
)
16070 /* skip_form_bytes already issued the complaint. */
16078 /* A helper function which parses the header of a macro section.
16079 If the macro section is the extended (for now called "GNU") type,
16080 then this updates *OFFSET_SIZE. Returns a pointer to just after
16081 the header, or issues a complaint and returns NULL on error. */
16084 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16087 unsigned int *offset_size
,
16088 int section_is_gnu
)
16090 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16092 if (section_is_gnu
)
16094 unsigned int version
, flags
;
16096 version
= read_2_bytes (abfd
, mac_ptr
);
16099 complaint (&symfile_complaints
,
16100 _("unrecognized version `%d' in .debug_macro section"),
16106 flags
= read_1_byte (abfd
, mac_ptr
);
16108 *offset_size
= (flags
& 1) ? 8 : 4;
16110 if ((flags
& 2) != 0)
16111 /* We don't need the line table offset. */
16112 mac_ptr
+= *offset_size
;
16114 /* Vendor opcode descriptions. */
16115 if ((flags
& 4) != 0)
16117 unsigned int i
, count
;
16119 count
= read_1_byte (abfd
, mac_ptr
);
16121 for (i
= 0; i
< count
; ++i
)
16123 unsigned int opcode
, bytes_read
;
16126 opcode
= read_1_byte (abfd
, mac_ptr
);
16128 opcode_definitions
[opcode
] = mac_ptr
;
16129 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16130 mac_ptr
+= bytes_read
;
16139 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16140 including DW_MACRO_GNU_transparent_include. */
16143 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16144 struct macro_source_file
*current_file
,
16145 struct line_header
*lh
, char *comp_dir
,
16146 struct dwarf2_section_info
*section
,
16147 int section_is_gnu
,
16148 unsigned int offset_size
,
16149 struct objfile
*objfile
,
16150 htab_t include_hash
)
16152 enum dwarf_macro_record_type macinfo_type
;
16153 int at_commandline
;
16154 gdb_byte
*opcode_definitions
[256];
16156 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16157 &offset_size
, section_is_gnu
);
16158 if (mac_ptr
== NULL
)
16160 /* We already issued a complaint. */
16164 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16165 GDB is still reading the definitions from command line. First
16166 DW_MACINFO_start_file will need to be ignored as it was already executed
16167 to create CURRENT_FILE for the main source holding also the command line
16168 definitions. On first met DW_MACINFO_start_file this flag is reset to
16169 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16171 at_commandline
= 1;
16175 /* Do we at least have room for a macinfo type byte? */
16176 if (mac_ptr
>= mac_end
)
16178 dwarf2_section_buffer_overflow_complaint (section
);
16182 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16185 /* Note that we rely on the fact that the corresponding GNU and
16186 DWARF constants are the same. */
16187 switch (macinfo_type
)
16189 /* A zero macinfo type indicates the end of the macro
16194 case DW_MACRO_GNU_define
:
16195 case DW_MACRO_GNU_undef
:
16196 case DW_MACRO_GNU_define_indirect
:
16197 case DW_MACRO_GNU_undef_indirect
:
16199 unsigned int bytes_read
;
16204 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16205 mac_ptr
+= bytes_read
;
16207 if (macinfo_type
== DW_MACRO_GNU_define
16208 || macinfo_type
== DW_MACRO_GNU_undef
)
16210 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16211 mac_ptr
+= bytes_read
;
16215 LONGEST str_offset
;
16217 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16218 mac_ptr
+= offset_size
;
16220 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16223 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16224 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16225 if (! current_file
)
16227 /* DWARF violation as no main source is present. */
16228 complaint (&symfile_complaints
,
16229 _("debug info with no main source gives macro %s "
16231 is_define
? _("definition") : _("undefinition"),
16235 if ((line
== 0 && !at_commandline
)
16236 || (line
!= 0 && at_commandline
))
16237 complaint (&symfile_complaints
,
16238 _("debug info gives %s macro %s with %s line %d: %s"),
16239 at_commandline
? _("command-line") : _("in-file"),
16240 is_define
? _("definition") : _("undefinition"),
16241 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16244 parse_macro_definition (current_file
, line
, body
);
16247 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16248 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16249 macro_undef (current_file
, line
, body
);
16254 case DW_MACRO_GNU_start_file
:
16256 unsigned int bytes_read
;
16259 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16260 mac_ptr
+= bytes_read
;
16261 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16262 mac_ptr
+= bytes_read
;
16264 if ((line
== 0 && !at_commandline
)
16265 || (line
!= 0 && at_commandline
))
16266 complaint (&symfile_complaints
,
16267 _("debug info gives source %d included "
16268 "from %s at %s line %d"),
16269 file
, at_commandline
? _("command-line") : _("file"),
16270 line
== 0 ? _("zero") : _("non-zero"), line
);
16272 if (at_commandline
)
16274 /* This DW_MACRO_GNU_start_file was executed in the
16276 at_commandline
= 0;
16279 current_file
= macro_start_file (file
, line
,
16280 current_file
, comp_dir
,
16285 case DW_MACRO_GNU_end_file
:
16286 if (! current_file
)
16287 complaint (&symfile_complaints
,
16288 _("macro debug info has an unmatched "
16289 "`close_file' directive"));
16292 current_file
= current_file
->included_by
;
16293 if (! current_file
)
16295 enum dwarf_macro_record_type next_type
;
16297 /* GCC circa March 2002 doesn't produce the zero
16298 type byte marking the end of the compilation
16299 unit. Complain if it's not there, but exit no
16302 /* Do we at least have room for a macinfo type byte? */
16303 if (mac_ptr
>= mac_end
)
16305 dwarf2_section_buffer_overflow_complaint (section
);
16309 /* We don't increment mac_ptr here, so this is just
16311 next_type
= read_1_byte (abfd
, mac_ptr
);
16312 if (next_type
!= 0)
16313 complaint (&symfile_complaints
,
16314 _("no terminating 0-type entry for "
16315 "macros in `.debug_macinfo' section"));
16322 case DW_MACRO_GNU_transparent_include
:
16327 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16328 mac_ptr
+= offset_size
;
16330 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16333 /* This has actually happened; see
16334 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16335 complaint (&symfile_complaints
,
16336 _("recursive DW_MACRO_GNU_transparent_include in "
16337 ".debug_macro section"));
16343 dwarf_decode_macro_bytes (abfd
,
16344 section
->buffer
+ offset
,
16345 mac_end
, current_file
,
16347 section
, section_is_gnu
,
16348 offset_size
, objfile
, include_hash
);
16350 htab_remove_elt (include_hash
, mac_ptr
);
16355 case DW_MACINFO_vendor_ext
:
16356 if (!section_is_gnu
)
16358 unsigned int bytes_read
;
16361 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16362 mac_ptr
+= bytes_read
;
16363 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16364 mac_ptr
+= bytes_read
;
16366 /* We don't recognize any vendor extensions. */
16372 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16373 mac_ptr
, mac_end
, abfd
, offset_size
,
16375 if (mac_ptr
== NULL
)
16379 } while (macinfo_type
!= 0);
16383 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
16384 char *comp_dir
, bfd
*abfd
,
16385 struct dwarf2_cu
*cu
,
16386 struct dwarf2_section_info
*section
,
16387 int section_is_gnu
, const char *section_name
)
16389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16390 gdb_byte
*mac_ptr
, *mac_end
;
16391 struct macro_source_file
*current_file
= 0;
16392 enum dwarf_macro_record_type macinfo_type
;
16393 unsigned int offset_size
= cu
->header
.offset_size
;
16394 gdb_byte
*opcode_definitions
[256];
16395 struct cleanup
*cleanup
;
16396 htab_t include_hash
;
16399 dwarf2_read_section (objfile
, section
);
16400 if (section
->buffer
== NULL
)
16402 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16406 /* First pass: Find the name of the base filename.
16407 This filename is needed in order to process all macros whose definition
16408 (or undefinition) comes from the command line. These macros are defined
16409 before the first DW_MACINFO_start_file entry, and yet still need to be
16410 associated to the base file.
16412 To determine the base file name, we scan the macro definitions until we
16413 reach the first DW_MACINFO_start_file entry. We then initialize
16414 CURRENT_FILE accordingly so that any macro definition found before the
16415 first DW_MACINFO_start_file can still be associated to the base file. */
16417 mac_ptr
= section
->buffer
+ offset
;
16418 mac_end
= section
->buffer
+ section
->size
;
16420 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16421 &offset_size
, section_is_gnu
);
16422 if (mac_ptr
== NULL
)
16424 /* We already issued a complaint. */
16430 /* Do we at least have room for a macinfo type byte? */
16431 if (mac_ptr
>= mac_end
)
16433 /* Complaint is printed during the second pass as GDB will probably
16434 stop the first pass earlier upon finding
16435 DW_MACINFO_start_file. */
16439 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16442 /* Note that we rely on the fact that the corresponding GNU and
16443 DWARF constants are the same. */
16444 switch (macinfo_type
)
16446 /* A zero macinfo type indicates the end of the macro
16451 case DW_MACRO_GNU_define
:
16452 case DW_MACRO_GNU_undef
:
16453 /* Only skip the data by MAC_PTR. */
16455 unsigned int bytes_read
;
16457 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16458 mac_ptr
+= bytes_read
;
16459 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16460 mac_ptr
+= bytes_read
;
16464 case DW_MACRO_GNU_start_file
:
16466 unsigned int bytes_read
;
16469 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16470 mac_ptr
+= bytes_read
;
16471 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16472 mac_ptr
+= bytes_read
;
16474 current_file
= macro_start_file (file
, line
, current_file
,
16475 comp_dir
, lh
, objfile
);
16479 case DW_MACRO_GNU_end_file
:
16480 /* No data to skip by MAC_PTR. */
16483 case DW_MACRO_GNU_define_indirect
:
16484 case DW_MACRO_GNU_undef_indirect
:
16486 unsigned int bytes_read
;
16488 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16489 mac_ptr
+= bytes_read
;
16490 mac_ptr
+= offset_size
;
16494 case DW_MACRO_GNU_transparent_include
:
16495 /* Note that, according to the spec, a transparent include
16496 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16497 skip this opcode. */
16498 mac_ptr
+= offset_size
;
16501 case DW_MACINFO_vendor_ext
:
16502 /* Only skip the data by MAC_PTR. */
16503 if (!section_is_gnu
)
16505 unsigned int bytes_read
;
16507 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16508 mac_ptr
+= bytes_read
;
16509 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16510 mac_ptr
+= bytes_read
;
16515 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16516 mac_ptr
, mac_end
, abfd
, offset_size
,
16518 if (mac_ptr
== NULL
)
16522 } while (macinfo_type
!= 0 && current_file
== NULL
);
16524 /* Second pass: Process all entries.
16526 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16527 command-line macro definitions/undefinitions. This flag is unset when we
16528 reach the first DW_MACINFO_start_file entry. */
16530 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16531 NULL
, xcalloc
, xfree
);
16532 cleanup
= make_cleanup_htab_delete (include_hash
);
16533 mac_ptr
= section
->buffer
+ offset
;
16534 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16536 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16537 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16538 offset_size
, objfile
, include_hash
);
16539 do_cleanups (cleanup
);
16542 /* Check if the attribute's form is a DW_FORM_block*
16543 if so return true else false. */
16546 attr_form_is_block (struct attribute
*attr
)
16548 return (attr
== NULL
? 0 :
16549 attr
->form
== DW_FORM_block1
16550 || attr
->form
== DW_FORM_block2
16551 || attr
->form
== DW_FORM_block4
16552 || attr
->form
== DW_FORM_block
16553 || attr
->form
== DW_FORM_exprloc
);
16556 /* Return non-zero if ATTR's value is a section offset --- classes
16557 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16558 You may use DW_UNSND (attr) to retrieve such offsets.
16560 Section 7.5.4, "Attribute Encodings", explains that no attribute
16561 may have a value that belongs to more than one of these classes; it
16562 would be ambiguous if we did, because we use the same forms for all
16566 attr_form_is_section_offset (struct attribute
*attr
)
16568 return (attr
->form
== DW_FORM_data4
16569 || attr
->form
== DW_FORM_data8
16570 || attr
->form
== DW_FORM_sec_offset
);
16573 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16574 zero otherwise. When this function returns true, you can apply
16575 dwarf2_get_attr_constant_value to it.
16577 However, note that for some attributes you must check
16578 attr_form_is_section_offset before using this test. DW_FORM_data4
16579 and DW_FORM_data8 are members of both the constant class, and of
16580 the classes that contain offsets into other debug sections
16581 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16582 that, if an attribute's can be either a constant or one of the
16583 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16584 taken as section offsets, not constants. */
16587 attr_form_is_constant (struct attribute
*attr
)
16589 switch (attr
->form
)
16591 case DW_FORM_sdata
:
16592 case DW_FORM_udata
:
16593 case DW_FORM_data1
:
16594 case DW_FORM_data2
:
16595 case DW_FORM_data4
:
16596 case DW_FORM_data8
:
16603 /* Return the .debug_loc section to use for CU.
16604 For DWO files use .debug_loc.dwo. */
16606 static struct dwarf2_section_info
*
16607 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16610 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16611 return &dwarf2_per_objfile
->loc
;
16614 /* A helper function that fills in a dwarf2_loclist_baton. */
16617 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16618 struct dwarf2_loclist_baton
*baton
,
16619 struct attribute
*attr
)
16621 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16623 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16625 baton
->per_cu
= cu
->per_cu
;
16626 gdb_assert (baton
->per_cu
);
16627 /* We don't know how long the location list is, but make sure we
16628 don't run off the edge of the section. */
16629 baton
->size
= section
->size
- DW_UNSND (attr
);
16630 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16631 baton
->base_address
= cu
->base_address
;
16632 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16636 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16637 struct dwarf2_cu
*cu
)
16639 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16640 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16642 if (attr_form_is_section_offset (attr
)
16643 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16644 the section. If so, fall through to the complaint in the
16646 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16648 struct dwarf2_loclist_baton
*baton
;
16650 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16651 sizeof (struct dwarf2_loclist_baton
));
16653 fill_in_loclist_baton (cu
, baton
, attr
);
16655 if (cu
->base_known
== 0)
16656 complaint (&symfile_complaints
,
16657 _("Location list used without "
16658 "specifying the CU base address."));
16660 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16661 SYMBOL_LOCATION_BATON (sym
) = baton
;
16665 struct dwarf2_locexpr_baton
*baton
;
16667 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16668 sizeof (struct dwarf2_locexpr_baton
));
16669 baton
->per_cu
= cu
->per_cu
;
16670 gdb_assert (baton
->per_cu
);
16672 if (attr_form_is_block (attr
))
16674 /* Note that we're just copying the block's data pointer
16675 here, not the actual data. We're still pointing into the
16676 info_buffer for SYM's objfile; right now we never release
16677 that buffer, but when we do clean up properly this may
16679 baton
->size
= DW_BLOCK (attr
)->size
;
16680 baton
->data
= DW_BLOCK (attr
)->data
;
16684 dwarf2_invalid_attrib_class_complaint ("location description",
16685 SYMBOL_NATURAL_NAME (sym
));
16689 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16690 SYMBOL_LOCATION_BATON (sym
) = baton
;
16694 /* Return the OBJFILE associated with the compilation unit CU. If CU
16695 came from a separate debuginfo file, then the master objfile is
16699 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16701 struct objfile
*objfile
= per_cu
->objfile
;
16703 /* Return the master objfile, so that we can report and look up the
16704 correct file containing this variable. */
16705 if (objfile
->separate_debug_objfile_backlink
)
16706 objfile
= objfile
->separate_debug_objfile_backlink
;
16711 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16712 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16713 CU_HEADERP first. */
16715 static const struct comp_unit_head
*
16716 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16717 struct dwarf2_per_cu_data
*per_cu
)
16719 struct objfile
*objfile
;
16720 struct dwarf2_per_objfile
*per_objfile
;
16721 gdb_byte
*info_ptr
;
16724 return &per_cu
->cu
->header
;
16726 objfile
= per_cu
->objfile
;
16727 per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16728 info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
.sect_off
;
16730 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16731 read_comp_unit_head (cu_headerp
, info_ptr
, objfile
->obfd
);
16736 /* Return the address size given in the compilation unit header for CU. */
16739 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16741 struct comp_unit_head cu_header_local
;
16742 const struct comp_unit_head
*cu_headerp
;
16744 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16746 return cu_headerp
->addr_size
;
16749 /* Return the offset size given in the compilation unit header for CU. */
16752 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16754 struct comp_unit_head cu_header_local
;
16755 const struct comp_unit_head
*cu_headerp
;
16757 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16759 return cu_headerp
->offset_size
;
16762 /* See its dwarf2loc.h declaration. */
16765 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16767 struct comp_unit_head cu_header_local
;
16768 const struct comp_unit_head
*cu_headerp
;
16770 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16772 if (cu_headerp
->version
== 2)
16773 return cu_headerp
->addr_size
;
16775 return cu_headerp
->offset_size
;
16778 /* Return the text offset of the CU. The returned offset comes from
16779 this CU's objfile. If this objfile came from a separate debuginfo
16780 file, then the offset may be different from the corresponding
16781 offset in the parent objfile. */
16784 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16786 struct objfile
*objfile
= per_cu
->objfile
;
16788 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16791 /* Locate the .debug_info compilation unit from CU's objfile which contains
16792 the DIE at OFFSET. Raises an error on failure. */
16794 static struct dwarf2_per_cu_data
*
16795 dwarf2_find_containing_comp_unit (sect_offset offset
,
16796 struct objfile
*objfile
)
16798 struct dwarf2_per_cu_data
*this_cu
;
16802 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16805 int mid
= low
+ (high
- low
) / 2;
16807 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16808 >= offset
.sect_off
)
16813 gdb_assert (low
== high
);
16814 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16818 error (_("Dwarf Error: could not find partial DIE containing "
16819 "offset 0x%lx [in module %s]"),
16820 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16822 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16823 <= offset
.sect_off
);
16824 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16828 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16829 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16830 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16831 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16832 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16837 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16840 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16842 memset (cu
, 0, sizeof (*cu
));
16844 cu
->per_cu
= per_cu
;
16845 cu
->objfile
= per_cu
->objfile
;
16846 obstack_init (&cu
->comp_unit_obstack
);
16849 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16852 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
16853 enum language pretend_language
)
16855 struct attribute
*attr
;
16857 /* Set the language we're debugging. */
16858 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16860 set_cu_language (DW_UNSND (attr
), cu
);
16863 cu
->language
= pretend_language
;
16864 cu
->language_defn
= language_def (cu
->language
);
16867 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16869 cu
->producer
= DW_STRING (attr
);
16872 /* Release one cached compilation unit, CU. We unlink it from the tree
16873 of compilation units, but we don't remove it from the read_in_chain;
16874 the caller is responsible for that.
16875 NOTE: DATA is a void * because this function is also used as a
16876 cleanup routine. */
16879 free_heap_comp_unit (void *data
)
16881 struct dwarf2_cu
*cu
= data
;
16883 gdb_assert (cu
->per_cu
!= NULL
);
16884 cu
->per_cu
->cu
= NULL
;
16887 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16892 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16893 when we're finished with it. We can't free the pointer itself, but be
16894 sure to unlink it from the cache. Also release any associated storage. */
16897 free_stack_comp_unit (void *data
)
16899 struct dwarf2_cu
*cu
= data
;
16901 gdb_assert (cu
->per_cu
!= NULL
);
16902 cu
->per_cu
->cu
= NULL
;
16905 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16906 cu
->partial_dies
= NULL
;
16909 /* Free all cached compilation units. */
16912 free_cached_comp_units (void *data
)
16914 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16916 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16917 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16918 while (per_cu
!= NULL
)
16920 struct dwarf2_per_cu_data
*next_cu
;
16922 next_cu
= per_cu
->cu
->read_in_chain
;
16924 free_heap_comp_unit (per_cu
->cu
);
16925 *last_chain
= next_cu
;
16931 /* Increase the age counter on each cached compilation unit, and free
16932 any that are too old. */
16935 age_cached_comp_units (void)
16937 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16939 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
16940 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16941 while (per_cu
!= NULL
)
16943 per_cu
->cu
->last_used
++;
16944 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
16945 dwarf2_mark (per_cu
->cu
);
16946 per_cu
= per_cu
->cu
->read_in_chain
;
16949 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16950 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16951 while (per_cu
!= NULL
)
16953 struct dwarf2_per_cu_data
*next_cu
;
16955 next_cu
= per_cu
->cu
->read_in_chain
;
16957 if (!per_cu
->cu
->mark
)
16959 free_heap_comp_unit (per_cu
->cu
);
16960 *last_chain
= next_cu
;
16963 last_chain
= &per_cu
->cu
->read_in_chain
;
16969 /* Remove a single compilation unit from the cache. */
16972 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
16974 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
16976 per_cu
= dwarf2_per_objfile
->read_in_chain
;
16977 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
16978 while (per_cu
!= NULL
)
16980 struct dwarf2_per_cu_data
*next_cu
;
16982 next_cu
= per_cu
->cu
->read_in_chain
;
16984 if (per_cu
== target_per_cu
)
16986 free_heap_comp_unit (per_cu
->cu
);
16988 *last_chain
= next_cu
;
16992 last_chain
= &per_cu
->cu
->read_in_chain
;
16998 /* Release all extra memory associated with OBJFILE. */
17001 dwarf2_free_objfile (struct objfile
*objfile
)
17003 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17005 if (dwarf2_per_objfile
== NULL
)
17008 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17009 free_cached_comp_units (NULL
);
17011 if (dwarf2_per_objfile
->quick_file_names_table
)
17012 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17014 /* Everything else should be on the objfile obstack. */
17017 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17018 We store these in a hash table separate from the DIEs, and preserve them
17019 when the DIEs are flushed out of cache.
17021 The CU "per_cu" pointer is needed because offset alone is not enough to
17022 uniquely identify the type. A file may have multiple .debug_types sections,
17023 or the type may come from a DWO file. We have to use something in
17024 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17025 routine, get_die_type_at_offset, from outside this file, and thus won't
17026 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17029 struct dwarf2_per_cu_offset_and_type
17031 const struct dwarf2_per_cu_data
*per_cu
;
17032 sect_offset offset
;
17036 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17039 per_cu_offset_and_type_hash (const void *item
)
17041 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17043 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17046 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17049 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17051 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17052 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17054 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17055 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17058 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17059 table if necessary. For convenience, return TYPE.
17061 The DIEs reading must have careful ordering to:
17062 * Not cause infite loops trying to read in DIEs as a prerequisite for
17063 reading current DIE.
17064 * Not trying to dereference contents of still incompletely read in types
17065 while reading in other DIEs.
17066 * Enable referencing still incompletely read in types just by a pointer to
17067 the type without accessing its fields.
17069 Therefore caller should follow these rules:
17070 * Try to fetch any prerequisite types we may need to build this DIE type
17071 before building the type and calling set_die_type.
17072 * After building type call set_die_type for current DIE as soon as
17073 possible before fetching more types to complete the current type.
17074 * Make the type as complete as possible before fetching more types. */
17076 static struct type
*
17077 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17079 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17080 struct objfile
*objfile
= cu
->objfile
;
17082 /* For Ada types, make sure that the gnat-specific data is always
17083 initialized (if not already set). There are a few types where
17084 we should not be doing so, because the type-specific area is
17085 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17086 where the type-specific area is used to store the floatformat).
17087 But this is not a problem, because the gnat-specific information
17088 is actually not needed for these types. */
17089 if (need_gnat_info (cu
)
17090 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17091 && TYPE_CODE (type
) != TYPE_CODE_FLT
17092 && !HAVE_GNAT_AUX_INFO (type
))
17093 INIT_GNAT_SPECIFIC (type
);
17095 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17097 dwarf2_per_objfile
->die_type_hash
=
17098 htab_create_alloc_ex (127,
17099 per_cu_offset_and_type_hash
,
17100 per_cu_offset_and_type_eq
,
17102 &objfile
->objfile_obstack
,
17103 hashtab_obstack_allocate
,
17104 dummy_obstack_deallocate
);
17107 ofs
.per_cu
= cu
->per_cu
;
17108 ofs
.offset
= die
->offset
;
17110 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17111 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17113 complaint (&symfile_complaints
,
17114 _("A problem internal to GDB: DIE 0x%x has type already set"),
17115 die
->offset
.sect_off
);
17116 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17121 /* Look up the type for the die at OFFSET in the appropriate type_hash
17122 table, or return NULL if the die does not have a saved type. */
17124 static struct type
*
17125 get_die_type_at_offset (sect_offset offset
,
17126 struct dwarf2_per_cu_data
*per_cu
)
17128 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17130 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17133 ofs
.per_cu
= per_cu
;
17134 ofs
.offset
= offset
;
17135 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17142 /* Look up the type for DIE in the appropriate type_hash table,
17143 or return NULL if DIE does not have a saved type. */
17145 static struct type
*
17146 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17148 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17151 /* Add a dependence relationship from CU to REF_PER_CU. */
17154 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17155 struct dwarf2_per_cu_data
*ref_per_cu
)
17159 if (cu
->dependencies
== NULL
)
17161 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17162 NULL
, &cu
->comp_unit_obstack
,
17163 hashtab_obstack_allocate
,
17164 dummy_obstack_deallocate
);
17166 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17168 *slot
= ref_per_cu
;
17171 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17172 Set the mark field in every compilation unit in the
17173 cache that we must keep because we are keeping CU. */
17176 dwarf2_mark_helper (void **slot
, void *data
)
17178 struct dwarf2_per_cu_data
*per_cu
;
17180 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17182 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17183 reading of the chain. As such dependencies remain valid it is not much
17184 useful to track and undo them during QUIT cleanups. */
17185 if (per_cu
->cu
== NULL
)
17188 if (per_cu
->cu
->mark
)
17190 per_cu
->cu
->mark
= 1;
17192 if (per_cu
->cu
->dependencies
!= NULL
)
17193 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17198 /* Set the mark field in CU and in every other compilation unit in the
17199 cache that we must keep because we are keeping CU. */
17202 dwarf2_mark (struct dwarf2_cu
*cu
)
17207 if (cu
->dependencies
!= NULL
)
17208 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17212 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17216 per_cu
->cu
->mark
= 0;
17217 per_cu
= per_cu
->cu
->read_in_chain
;
17221 /* Trivial hash function for partial_die_info: the hash value of a DIE
17222 is its offset in .debug_info for this objfile. */
17225 partial_die_hash (const void *item
)
17227 const struct partial_die_info
*part_die
= item
;
17229 return part_die
->offset
.sect_off
;
17232 /* Trivial comparison function for partial_die_info structures: two DIEs
17233 are equal if they have the same offset. */
17236 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17238 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17239 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17241 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17244 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17245 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17248 set_dwarf2_cmd (char *args
, int from_tty
)
17250 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17254 show_dwarf2_cmd (char *args
, int from_tty
)
17256 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17259 /* If section described by INFO was mmapped, munmap it now. */
17262 munmap_section_buffer (struct dwarf2_section_info
*info
)
17264 if (info
->map_addr
!= NULL
)
17269 res
= munmap (info
->map_addr
, info
->map_len
);
17270 gdb_assert (res
== 0);
17272 /* Without HAVE_MMAP, we should never be here to begin with. */
17273 gdb_assert_not_reached ("no mmap support");
17278 /* munmap debug sections for OBJFILE, if necessary. */
17281 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17283 struct dwarf2_per_objfile
*data
= d
;
17285 struct dwarf2_section_info
*section
;
17287 /* This is sorted according to the order they're defined in to make it easier
17288 to keep in sync. */
17289 munmap_section_buffer (&data
->info
);
17290 munmap_section_buffer (&data
->abbrev
);
17291 munmap_section_buffer (&data
->line
);
17292 munmap_section_buffer (&data
->loc
);
17293 munmap_section_buffer (&data
->macinfo
);
17294 munmap_section_buffer (&data
->macro
);
17295 munmap_section_buffer (&data
->str
);
17296 munmap_section_buffer (&data
->ranges
);
17297 munmap_section_buffer (&data
->addr
);
17298 munmap_section_buffer (&data
->frame
);
17299 munmap_section_buffer (&data
->eh_frame
);
17300 munmap_section_buffer (&data
->gdb_index
);
17303 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17305 munmap_section_buffer (section
);
17307 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17308 VEC_free (dwarf2_per_cu_ptr
,
17309 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17311 VEC_free (dwarf2_section_info_def
, data
->types
);
17313 if (data
->dwo_files
)
17314 free_dwo_files (data
->dwo_files
, objfile
);
17318 /* The "save gdb-index" command. */
17320 /* The contents of the hash table we create when building the string
17322 struct strtab_entry
17324 offset_type offset
;
17328 /* Hash function for a strtab_entry.
17330 Function is used only during write_hash_table so no index format backward
17331 compatibility is needed. */
17334 hash_strtab_entry (const void *e
)
17336 const struct strtab_entry
*entry
= e
;
17337 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17340 /* Equality function for a strtab_entry. */
17343 eq_strtab_entry (const void *a
, const void *b
)
17345 const struct strtab_entry
*ea
= a
;
17346 const struct strtab_entry
*eb
= b
;
17347 return !strcmp (ea
->str
, eb
->str
);
17350 /* Create a strtab_entry hash table. */
17353 create_strtab (void)
17355 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17356 xfree
, xcalloc
, xfree
);
17359 /* Add a string to the constant pool. Return the string's offset in
17363 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17366 struct strtab_entry entry
;
17367 struct strtab_entry
*result
;
17370 slot
= htab_find_slot (table
, &entry
, INSERT
);
17375 result
= XNEW (struct strtab_entry
);
17376 result
->offset
= obstack_object_size (cpool
);
17378 obstack_grow_str0 (cpool
, str
);
17381 return result
->offset
;
17384 /* An entry in the symbol table. */
17385 struct symtab_index_entry
17387 /* The name of the symbol. */
17389 /* The offset of the name in the constant pool. */
17390 offset_type index_offset
;
17391 /* A sorted vector of the indices of all the CUs that hold an object
17393 VEC (offset_type
) *cu_indices
;
17396 /* The symbol table. This is a power-of-2-sized hash table. */
17397 struct mapped_symtab
17399 offset_type n_elements
;
17401 struct symtab_index_entry
**data
;
17404 /* Hash function for a symtab_index_entry. */
17407 hash_symtab_entry (const void *e
)
17409 const struct symtab_index_entry
*entry
= e
;
17410 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17411 sizeof (offset_type
) * VEC_length (offset_type
,
17412 entry
->cu_indices
),
17416 /* Equality function for a symtab_index_entry. */
17419 eq_symtab_entry (const void *a
, const void *b
)
17421 const struct symtab_index_entry
*ea
= a
;
17422 const struct symtab_index_entry
*eb
= b
;
17423 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17424 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17426 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17427 VEC_address (offset_type
, eb
->cu_indices
),
17428 sizeof (offset_type
) * len
);
17431 /* Destroy a symtab_index_entry. */
17434 delete_symtab_entry (void *p
)
17436 struct symtab_index_entry
*entry
= p
;
17437 VEC_free (offset_type
, entry
->cu_indices
);
17441 /* Create a hash table holding symtab_index_entry objects. */
17444 create_symbol_hash_table (void)
17446 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17447 delete_symtab_entry
, xcalloc
, xfree
);
17450 /* Create a new mapped symtab object. */
17452 static struct mapped_symtab
*
17453 create_mapped_symtab (void)
17455 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17456 symtab
->n_elements
= 0;
17457 symtab
->size
= 1024;
17458 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17462 /* Destroy a mapped_symtab. */
17465 cleanup_mapped_symtab (void *p
)
17467 struct mapped_symtab
*symtab
= p
;
17468 /* The contents of the array are freed when the other hash table is
17470 xfree (symtab
->data
);
17474 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17477 Function is used only during write_hash_table so no index format backward
17478 compatibility is needed. */
17480 static struct symtab_index_entry
**
17481 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17483 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17485 index
= hash
& (symtab
->size
- 1);
17486 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17490 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17491 return &symtab
->data
[index
];
17492 index
= (index
+ step
) & (symtab
->size
- 1);
17496 /* Expand SYMTAB's hash table. */
17499 hash_expand (struct mapped_symtab
*symtab
)
17501 offset_type old_size
= symtab
->size
;
17503 struct symtab_index_entry
**old_entries
= symtab
->data
;
17506 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17508 for (i
= 0; i
< old_size
; ++i
)
17510 if (old_entries
[i
])
17512 struct symtab_index_entry
**slot
= find_slot (symtab
,
17513 old_entries
[i
]->name
);
17514 *slot
= old_entries
[i
];
17518 xfree (old_entries
);
17521 /* Add an entry to SYMTAB. NAME is the name of the symbol.
17522 CU_INDEX is the index of the CU in which the symbol appears.
17523 IS_STATIC is one if the symbol is static, otherwise zero (global). */
17526 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17527 int is_static
, gdb_index_symbol_kind kind
,
17528 offset_type cu_index
)
17530 struct symtab_index_entry
**slot
;
17531 offset_type cu_index_and_attrs
;
17533 ++symtab
->n_elements
;
17534 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17535 hash_expand (symtab
);
17537 slot
= find_slot (symtab
, name
);
17540 *slot
= XNEW (struct symtab_index_entry
);
17541 (*slot
)->name
= name
;
17542 /* index_offset is set later. */
17543 (*slot
)->cu_indices
= NULL
;
17546 cu_index_and_attrs
= 0;
17547 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
17548 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
17549 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
17551 /* We don't want to record an index value twice as we want to avoid the
17553 We process all global symbols and then all static symbols
17554 (which would allow us to avoid the duplication by only having to check
17555 the last entry pushed), but a symbol could have multiple kinds in one CU.
17556 To keep things simple we don't worry about the duplication here and
17557 sort and uniqufy the list after we've processed all symbols. */
17558 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
17561 /* qsort helper routine for uniquify_cu_indices. */
17564 offset_type_compare (const void *ap
, const void *bp
)
17566 offset_type a
= *(offset_type
*) ap
;
17567 offset_type b
= *(offset_type
*) bp
;
17569 return (a
> b
) - (b
> a
);
17572 /* Sort and remove duplicates of all symbols' cu_indices lists. */
17575 uniquify_cu_indices (struct mapped_symtab
*symtab
)
17579 for (i
= 0; i
< symtab
->size
; ++i
)
17581 struct symtab_index_entry
*entry
= symtab
->data
[i
];
17584 && entry
->cu_indices
!= NULL
)
17586 unsigned int next_to_insert
, next_to_check
;
17587 offset_type last_value
;
17589 qsort (VEC_address (offset_type
, entry
->cu_indices
),
17590 VEC_length (offset_type
, entry
->cu_indices
),
17591 sizeof (offset_type
), offset_type_compare
);
17593 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
17594 next_to_insert
= 1;
17595 for (next_to_check
= 1;
17596 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
17599 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
17602 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
17604 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
17609 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
17614 /* Add a vector of indices to the constant pool. */
17617 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17618 struct symtab_index_entry
*entry
)
17622 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17625 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17626 offset_type val
= MAYBE_SWAP (len
);
17631 entry
->index_offset
= obstack_object_size (cpool
);
17633 obstack_grow (cpool
, &val
, sizeof (val
));
17635 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17638 val
= MAYBE_SWAP (iter
);
17639 obstack_grow (cpool
, &val
, sizeof (val
));
17644 struct symtab_index_entry
*old_entry
= *slot
;
17645 entry
->index_offset
= old_entry
->index_offset
;
17648 return entry
->index_offset
;
17651 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17652 constant pool entries going into the obstack CPOOL. */
17655 write_hash_table (struct mapped_symtab
*symtab
,
17656 struct obstack
*output
, struct obstack
*cpool
)
17659 htab_t symbol_hash_table
;
17662 symbol_hash_table
= create_symbol_hash_table ();
17663 str_table
= create_strtab ();
17665 /* We add all the index vectors to the constant pool first, to
17666 ensure alignment is ok. */
17667 for (i
= 0; i
< symtab
->size
; ++i
)
17669 if (symtab
->data
[i
])
17670 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17673 /* Now write out the hash table. */
17674 for (i
= 0; i
< symtab
->size
; ++i
)
17676 offset_type str_off
, vec_off
;
17678 if (symtab
->data
[i
])
17680 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17681 vec_off
= symtab
->data
[i
]->index_offset
;
17685 /* While 0 is a valid constant pool index, it is not valid
17686 to have 0 for both offsets. */
17691 str_off
= MAYBE_SWAP (str_off
);
17692 vec_off
= MAYBE_SWAP (vec_off
);
17694 obstack_grow (output
, &str_off
, sizeof (str_off
));
17695 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17698 htab_delete (str_table
);
17699 htab_delete (symbol_hash_table
);
17702 /* Struct to map psymtab to CU index in the index file. */
17703 struct psymtab_cu_index_map
17705 struct partial_symtab
*psymtab
;
17706 unsigned int cu_index
;
17710 hash_psymtab_cu_index (const void *item
)
17712 const struct psymtab_cu_index_map
*map
= item
;
17714 return htab_hash_pointer (map
->psymtab
);
17718 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17720 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17721 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17723 return lhs
->psymtab
== rhs
->psymtab
;
17726 /* Helper struct for building the address table. */
17727 struct addrmap_index_data
17729 struct objfile
*objfile
;
17730 struct obstack
*addr_obstack
;
17731 htab_t cu_index_htab
;
17733 /* Non-zero if the previous_* fields are valid.
17734 We can't write an entry until we see the next entry (since it is only then
17735 that we know the end of the entry). */
17736 int previous_valid
;
17737 /* Index of the CU in the table of all CUs in the index file. */
17738 unsigned int previous_cu_index
;
17739 /* Start address of the CU. */
17740 CORE_ADDR previous_cu_start
;
17743 /* Write an address entry to OBSTACK. */
17746 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17747 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17749 offset_type cu_index_to_write
;
17751 CORE_ADDR baseaddr
;
17753 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17755 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17756 obstack_grow (obstack
, addr
, 8);
17757 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17758 obstack_grow (obstack
, addr
, 8);
17759 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17760 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17763 /* Worker function for traversing an addrmap to build the address table. */
17766 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17768 struct addrmap_index_data
*data
= datap
;
17769 struct partial_symtab
*pst
= obj
;
17771 if (data
->previous_valid
)
17772 add_address_entry (data
->objfile
, data
->addr_obstack
,
17773 data
->previous_cu_start
, start_addr
,
17774 data
->previous_cu_index
);
17776 data
->previous_cu_start
= start_addr
;
17779 struct psymtab_cu_index_map find_map
, *map
;
17780 find_map
.psymtab
= pst
;
17781 map
= htab_find (data
->cu_index_htab
, &find_map
);
17782 gdb_assert (map
!= NULL
);
17783 data
->previous_cu_index
= map
->cu_index
;
17784 data
->previous_valid
= 1;
17787 data
->previous_valid
= 0;
17792 /* Write OBJFILE's address map to OBSTACK.
17793 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17794 in the index file. */
17797 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17798 htab_t cu_index_htab
)
17800 struct addrmap_index_data addrmap_index_data
;
17802 /* When writing the address table, we have to cope with the fact that
17803 the addrmap iterator only provides the start of a region; we have to
17804 wait until the next invocation to get the start of the next region. */
17806 addrmap_index_data
.objfile
= objfile
;
17807 addrmap_index_data
.addr_obstack
= obstack
;
17808 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17809 addrmap_index_data
.previous_valid
= 0;
17811 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17812 &addrmap_index_data
);
17814 /* It's highly unlikely the last entry (end address = 0xff...ff)
17815 is valid, but we should still handle it.
17816 The end address is recorded as the start of the next region, but that
17817 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17819 if (addrmap_index_data
.previous_valid
)
17820 add_address_entry (objfile
, obstack
,
17821 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17822 addrmap_index_data
.previous_cu_index
);
17825 /* Return the symbol kind of PSYM. */
17827 static gdb_index_symbol_kind
17828 symbol_kind (struct partial_symbol
*psym
)
17830 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
17831 enum address_class aclass
= PSYMBOL_CLASS (psym
);
17839 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
17841 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17843 case LOC_CONST_BYTES
:
17844 case LOC_OPTIMIZED_OUT
:
17846 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
17848 /* Note: It's currently impossible to recognize psyms as enum values
17849 short of reading the type info. For now punt. */
17850 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
17852 /* There are other LOC_FOO values that one might want to classify
17853 as variables, but dwarf2read.c doesn't currently use them. */
17854 return GDB_INDEX_SYMBOL_KIND_OTHER
;
17856 case STRUCT_DOMAIN
:
17857 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17859 return GDB_INDEX_SYMBOL_KIND_OTHER
;
17863 /* Add a list of partial symbols to SYMTAB. */
17866 write_psymbols (struct mapped_symtab
*symtab
,
17868 struct partial_symbol
**psymp
,
17870 offset_type cu_index
,
17873 for (; count
-- > 0; ++psymp
)
17875 struct partial_symbol
*psym
= *psymp
;
17878 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
17879 error (_("Ada is not currently supported by the index"));
17881 /* Only add a given psymbol once. */
17882 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
17885 gdb_index_symbol_kind kind
= symbol_kind (psym
);
17888 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
17889 is_static
, kind
, cu_index
);
17894 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17895 exception if there is an error. */
17898 write_obstack (FILE *file
, struct obstack
*obstack
)
17900 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17902 != obstack_object_size (obstack
))
17903 error (_("couldn't data write to file"));
17906 /* Unlink a file if the argument is not NULL. */
17909 unlink_if_set (void *p
)
17911 char **filename
= p
;
17913 unlink (*filename
);
17916 /* A helper struct used when iterating over debug_types. */
17917 struct signatured_type_index_data
17919 struct objfile
*objfile
;
17920 struct mapped_symtab
*symtab
;
17921 struct obstack
*types_list
;
17926 /* A helper function that writes a single signatured_type to an
17930 write_one_signatured_type (void **slot
, void *d
)
17932 struct signatured_type_index_data
*info
= d
;
17933 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
17934 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
17935 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
17938 write_psymbols (info
->symtab
,
17940 info
->objfile
->global_psymbols
.list
17941 + psymtab
->globals_offset
,
17942 psymtab
->n_global_syms
, info
->cu_index
,
17944 write_psymbols (info
->symtab
,
17946 info
->objfile
->static_psymbols
.list
17947 + psymtab
->statics_offset
,
17948 psymtab
->n_static_syms
, info
->cu_index
,
17951 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17952 entry
->per_cu
.offset
.sect_off
);
17953 obstack_grow (info
->types_list
, val
, 8);
17954 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
17955 entry
->type_offset_in_tu
.cu_off
);
17956 obstack_grow (info
->types_list
, val
, 8);
17957 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
17958 obstack_grow (info
->types_list
, val
, 8);
17965 /* Recurse into all "included" dependencies and write their symbols as
17966 if they appeared in this psymtab. */
17969 recursively_write_psymbols (struct objfile
*objfile
,
17970 struct partial_symtab
*psymtab
,
17971 struct mapped_symtab
*symtab
,
17973 offset_type cu_index
)
17977 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
17978 if (psymtab
->dependencies
[i
]->user
!= NULL
)
17979 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
17980 symtab
, psyms_seen
, cu_index
);
17982 write_psymbols (symtab
,
17984 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
17985 psymtab
->n_global_syms
, cu_index
,
17987 write_psymbols (symtab
,
17989 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
17990 psymtab
->n_static_syms
, cu_index
,
17994 /* Create an index file for OBJFILE in the directory DIR. */
17997 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
17999 struct cleanup
*cleanup
;
18000 char *filename
, *cleanup_filename
;
18001 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18002 struct obstack cu_list
, types_cu_list
;
18005 struct mapped_symtab
*symtab
;
18006 offset_type val
, size_of_contents
, total_len
;
18009 htab_t cu_index_htab
;
18010 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18012 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18015 if (dwarf2_per_objfile
->using_index
)
18016 error (_("Cannot use an index to create the index"));
18018 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18019 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18021 if (stat (objfile
->name
, &st
) < 0)
18022 perror_with_name (objfile
->name
);
18024 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18025 INDEX_SUFFIX
, (char *) NULL
);
18026 cleanup
= make_cleanup (xfree
, filename
);
18028 out_file
= fopen (filename
, "wb");
18030 error (_("Can't open `%s' for writing"), filename
);
18032 cleanup_filename
= filename
;
18033 make_cleanup (unlink_if_set
, &cleanup_filename
);
18035 symtab
= create_mapped_symtab ();
18036 make_cleanup (cleanup_mapped_symtab
, symtab
);
18038 obstack_init (&addr_obstack
);
18039 make_cleanup_obstack_free (&addr_obstack
);
18041 obstack_init (&cu_list
);
18042 make_cleanup_obstack_free (&cu_list
);
18044 obstack_init (&types_cu_list
);
18045 make_cleanup_obstack_free (&types_cu_list
);
18047 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18048 NULL
, xcalloc
, xfree
);
18049 make_cleanup_htab_delete (psyms_seen
);
18051 /* While we're scanning CU's create a table that maps a psymtab pointer
18052 (which is what addrmap records) to its index (which is what is recorded
18053 in the index file). This will later be needed to write the address
18055 cu_index_htab
= htab_create_alloc (100,
18056 hash_psymtab_cu_index
,
18057 eq_psymtab_cu_index
,
18058 NULL
, xcalloc
, xfree
);
18059 make_cleanup_htab_delete (cu_index_htab
);
18060 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18061 xmalloc (sizeof (struct psymtab_cu_index_map
)
18062 * dwarf2_per_objfile
->n_comp_units
);
18063 make_cleanup (xfree
, psymtab_cu_index_map
);
18065 /* The CU list is already sorted, so we don't need to do additional
18066 work here. Also, the debug_types entries do not appear in
18067 all_comp_units, but only in their own hash table. */
18068 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18070 struct dwarf2_per_cu_data
*per_cu
18071 = dwarf2_per_objfile
->all_comp_units
[i
];
18072 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18074 struct psymtab_cu_index_map
*map
;
18077 if (psymtab
->user
== NULL
)
18078 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18080 map
= &psymtab_cu_index_map
[i
];
18081 map
->psymtab
= psymtab
;
18083 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18084 gdb_assert (slot
!= NULL
);
18085 gdb_assert (*slot
== NULL
);
18088 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18089 per_cu
->offset
.sect_off
);
18090 obstack_grow (&cu_list
, val
, 8);
18091 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18092 obstack_grow (&cu_list
, val
, 8);
18095 /* Dump the address map. */
18096 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18098 /* Write out the .debug_type entries, if any. */
18099 if (dwarf2_per_objfile
->signatured_types
)
18101 struct signatured_type_index_data sig_data
;
18103 sig_data
.objfile
= objfile
;
18104 sig_data
.symtab
= symtab
;
18105 sig_data
.types_list
= &types_cu_list
;
18106 sig_data
.psyms_seen
= psyms_seen
;
18107 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18108 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18109 write_one_signatured_type
, &sig_data
);
18112 /* Now that we've processed all symbols we can shrink their cu_indices
18114 uniquify_cu_indices (symtab
);
18116 obstack_init (&constant_pool
);
18117 make_cleanup_obstack_free (&constant_pool
);
18118 obstack_init (&symtab_obstack
);
18119 make_cleanup_obstack_free (&symtab_obstack
);
18120 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18122 obstack_init (&contents
);
18123 make_cleanup_obstack_free (&contents
);
18124 size_of_contents
= 6 * sizeof (offset_type
);
18125 total_len
= size_of_contents
;
18127 /* The version number. */
18128 val
= MAYBE_SWAP (7);
18129 obstack_grow (&contents
, &val
, sizeof (val
));
18131 /* The offset of the CU list from the start of the file. */
18132 val
= MAYBE_SWAP (total_len
);
18133 obstack_grow (&contents
, &val
, sizeof (val
));
18134 total_len
+= obstack_object_size (&cu_list
);
18136 /* The offset of the types CU list from the start of the file. */
18137 val
= MAYBE_SWAP (total_len
);
18138 obstack_grow (&contents
, &val
, sizeof (val
));
18139 total_len
+= obstack_object_size (&types_cu_list
);
18141 /* The offset of the address table from the start of the file. */
18142 val
= MAYBE_SWAP (total_len
);
18143 obstack_grow (&contents
, &val
, sizeof (val
));
18144 total_len
+= obstack_object_size (&addr_obstack
);
18146 /* The offset of the symbol table from the start of the file. */
18147 val
= MAYBE_SWAP (total_len
);
18148 obstack_grow (&contents
, &val
, sizeof (val
));
18149 total_len
+= obstack_object_size (&symtab_obstack
);
18151 /* The offset of the constant pool from the start of the file. */
18152 val
= MAYBE_SWAP (total_len
);
18153 obstack_grow (&contents
, &val
, sizeof (val
));
18154 total_len
+= obstack_object_size (&constant_pool
);
18156 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18158 write_obstack (out_file
, &contents
);
18159 write_obstack (out_file
, &cu_list
);
18160 write_obstack (out_file
, &types_cu_list
);
18161 write_obstack (out_file
, &addr_obstack
);
18162 write_obstack (out_file
, &symtab_obstack
);
18163 write_obstack (out_file
, &constant_pool
);
18167 /* We want to keep the file, so we set cleanup_filename to NULL
18168 here. See unlink_if_set. */
18169 cleanup_filename
= NULL
;
18171 do_cleanups (cleanup
);
18174 /* Implementation of the `save gdb-index' command.
18176 Note that the file format used by this command is documented in the
18177 GDB manual. Any changes here must be documented there. */
18180 save_gdb_index_command (char *arg
, int from_tty
)
18182 struct objfile
*objfile
;
18185 error (_("usage: save gdb-index DIRECTORY"));
18187 ALL_OBJFILES (objfile
)
18191 /* If the objfile does not correspond to an actual file, skip it. */
18192 if (stat (objfile
->name
, &st
) < 0)
18195 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18196 if (dwarf2_per_objfile
)
18198 volatile struct gdb_exception except
;
18200 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18202 write_psymtabs_to_index (objfile
, arg
);
18204 if (except
.reason
< 0)
18205 exception_fprintf (gdb_stderr
, except
,
18206 _("Error while writing index for `%s': "),
18214 int dwarf2_always_disassemble
;
18217 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18218 struct cmd_list_element
*c
, const char *value
)
18220 fprintf_filtered (file
,
18221 _("Whether to always disassemble "
18222 "DWARF expressions is %s.\n"),
18227 show_check_physname (struct ui_file
*file
, int from_tty
,
18228 struct cmd_list_element
*c
, const char *value
)
18230 fprintf_filtered (file
,
18231 _("Whether to check \"physname\" is %s.\n"),
18235 void _initialize_dwarf2_read (void);
18238 _initialize_dwarf2_read (void)
18240 struct cmd_list_element
*c
;
18242 dwarf2_objfile_data_key
18243 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18245 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18246 Set DWARF 2 specific variables.\n\
18247 Configure DWARF 2 variables such as the cache size"),
18248 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18249 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18251 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18252 Show DWARF 2 specific variables\n\
18253 Show DWARF 2 variables such as the cache size"),
18254 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18255 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18257 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18258 &dwarf2_max_cache_age
, _("\
18259 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18260 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18261 A higher limit means that cached compilation units will be stored\n\
18262 in memory longer, and more total memory will be used. Zero disables\n\
18263 caching, which can slow down startup."),
18265 show_dwarf2_max_cache_age
,
18266 &set_dwarf2_cmdlist
,
18267 &show_dwarf2_cmdlist
);
18269 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18270 &dwarf2_always_disassemble
, _("\
18271 Set whether `info address' always disassembles DWARF expressions."), _("\
18272 Show whether `info address' always disassembles DWARF expressions."), _("\
18273 When enabled, DWARF expressions are always printed in an assembly-like\n\
18274 syntax. When disabled, expressions will be printed in a more\n\
18275 conversational style, when possible."),
18277 show_dwarf2_always_disassemble
,
18278 &set_dwarf2_cmdlist
,
18279 &show_dwarf2_cmdlist
);
18281 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18282 Set debugging of the dwarf2 DIE reader."), _("\
18283 Show debugging of the dwarf2 DIE reader."), _("\
18284 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18285 The value is the maximum depth to print."),
18288 &setdebuglist
, &showdebuglist
);
18290 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18291 Set cross-checking of \"physname\" code against demangler."), _("\
18292 Show cross-checking of \"physname\" code against demangler."), _("\
18293 When enabled, GDB's internal \"physname\" code is checked against\n\
18295 NULL
, show_check_physname
,
18296 &setdebuglist
, &showdebuglist
);
18298 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18300 Save a gdb-index file.\n\
18301 Usage: save gdb-index DIRECTORY"),
18303 set_cmd_completer (c
, filename_completer
);