1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
69 #include "gdb_string.h"
70 #include "gdb_assert.h"
71 #include <sys/types.h>
78 #define MAP_FAILED ((void *) -1)
82 typedef struct symbol
*symbolp
;
85 /* When non-zero, print basic high level tracing messages.
86 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
87 static int dwarf2_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static int dwarf2_die_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 int use_deprecated_index_sections
= 0;
100 /* When set, the file that we're processing is known to have debugging
101 info for C++ namespaces. GCC 3.3.x did not produce this information,
102 but later versions do. */
104 static int processing_has_namespace_info
;
106 static const struct objfile_data
*dwarf2_objfile_data_key
;
108 struct dwarf2_section_info
113 /* Not NULL if the section was actually mmapped. */
115 /* Page aligned size of mmapped area. */
116 bfd_size_type map_len
;
117 /* True if we have tried to read this section. */
121 typedef struct dwarf2_section_info dwarf2_section_info_def
;
122 DEF_VEC_O (dwarf2_section_info_def
);
124 /* All offsets in the index are of this type. It must be
125 architecture-independent. */
126 typedef uint32_t offset_type
;
128 DEF_VEC_I (offset_type
);
130 /* Ensure only legit values are used. */
131 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
133 gdb_assert ((unsigned int) (value) <= 1); \
134 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
137 /* Ensure only legit values are used. */
138 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
140 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
141 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
142 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
145 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
146 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
148 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
149 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
152 /* A description of the mapped index. The file format is described in
153 a comment by the code that writes the index. */
156 /* Index data format version. */
159 /* The total length of the buffer. */
162 /* A pointer to the address table data. */
163 const gdb_byte
*address_table
;
165 /* Size of the address table data in bytes. */
166 offset_type address_table_size
;
168 /* The symbol table, implemented as a hash table. */
169 const offset_type
*symbol_table
;
171 /* Size in slots, each slot is 2 offset_types. */
172 offset_type symbol_table_slots
;
174 /* A pointer to the constant pool. */
175 const char *constant_pool
;
178 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
179 DEF_VEC_P (dwarf2_per_cu_ptr
);
181 /* Collection of data recorded per objfile.
182 This hangs off of dwarf2_objfile_data_key. */
184 struct dwarf2_per_objfile
186 struct dwarf2_section_info info
;
187 struct dwarf2_section_info abbrev
;
188 struct dwarf2_section_info line
;
189 struct dwarf2_section_info loc
;
190 struct dwarf2_section_info macinfo
;
191 struct dwarf2_section_info macro
;
192 struct dwarf2_section_info str
;
193 struct dwarf2_section_info ranges
;
194 struct dwarf2_section_info addr
;
195 struct dwarf2_section_info frame
;
196 struct dwarf2_section_info eh_frame
;
197 struct dwarf2_section_info gdb_index
;
199 VEC (dwarf2_section_info_def
) *types
;
202 struct objfile
*objfile
;
204 /* Table of all the compilation units. This is used to locate
205 the target compilation unit of a particular reference. */
206 struct dwarf2_per_cu_data
**all_comp_units
;
208 /* The number of compilation units in ALL_COMP_UNITS. */
211 /* The number of .debug_types-related CUs. */
214 /* The .debug_types-related CUs (TUs). */
215 struct dwarf2_per_cu_data
**all_type_units
;
217 /* A chain of compilation units that are currently read in, so that
218 they can be freed later. */
219 struct dwarf2_per_cu_data
*read_in_chain
;
221 /* A table mapping .debug_types signatures to its signatured_type entry.
222 This is NULL if the .debug_types section hasn't been read in yet. */
223 htab_t signatured_types
;
225 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
226 This is NULL if the table hasn't been allocated yet. */
229 /* A flag indicating wether this objfile has a section loaded at a
231 int has_section_at_zero
;
233 /* True if we are using the mapped index,
234 or we are faking it for OBJF_READNOW's sake. */
235 unsigned char using_index
;
237 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
238 struct mapped_index
*index_table
;
240 /* When using index_table, this keeps track of all quick_file_names entries.
241 TUs can share line table entries with CUs or other TUs, and there can be
242 a lot more TUs than unique line tables, so we maintain a separate table
243 of all line table entries to support the sharing. */
244 htab_t quick_file_names_table
;
246 /* Set during partial symbol reading, to prevent queueing of full
248 int reading_partial_symbols
;
250 /* Table mapping type DIEs to their struct type *.
251 This is NULL if not allocated yet.
252 The mapping is done via (CU/TU signature + DIE offset) -> type. */
253 htab_t die_type_hash
;
255 /* The CUs we recently read. */
256 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
259 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
261 /* Default names of the debugging sections. */
263 /* Note that if the debugging section has been compressed, it might
264 have a name like .zdebug_info. */
266 static const struct dwarf2_debug_sections dwarf2_elf_names
=
268 { ".debug_info", ".zdebug_info" },
269 { ".debug_abbrev", ".zdebug_abbrev" },
270 { ".debug_line", ".zdebug_line" },
271 { ".debug_loc", ".zdebug_loc" },
272 { ".debug_macinfo", ".zdebug_macinfo" },
273 { ".debug_macro", ".zdebug_macro" },
274 { ".debug_str", ".zdebug_str" },
275 { ".debug_ranges", ".zdebug_ranges" },
276 { ".debug_types", ".zdebug_types" },
277 { ".debug_addr", ".zdebug_addr" },
278 { ".debug_frame", ".zdebug_frame" },
279 { ".eh_frame", NULL
},
280 { ".gdb_index", ".zgdb_index" },
284 /* List of DWO sections. */
286 static const struct dwo_section_names
288 struct dwarf2_section_names abbrev_dwo
;
289 struct dwarf2_section_names info_dwo
;
290 struct dwarf2_section_names line_dwo
;
291 struct dwarf2_section_names loc_dwo
;
292 struct dwarf2_section_names macinfo_dwo
;
293 struct dwarf2_section_names macro_dwo
;
294 struct dwarf2_section_names str_dwo
;
295 struct dwarf2_section_names str_offsets_dwo
;
296 struct dwarf2_section_names types_dwo
;
300 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
301 { ".debug_info.dwo", ".zdebug_info.dwo" },
302 { ".debug_line.dwo", ".zdebug_line.dwo" },
303 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
304 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
305 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
306 { ".debug_str.dwo", ".zdebug_str.dwo" },
307 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
308 { ".debug_types.dwo", ".zdebug_types.dwo" },
311 /* local data types */
313 /* The data in a compilation unit header, after target2host
314 translation, looks like this. */
315 struct comp_unit_head
319 unsigned char addr_size
;
320 unsigned char signed_addr_p
;
321 sect_offset abbrev_offset
;
323 /* Size of file offsets; either 4 or 8. */
324 unsigned int offset_size
;
326 /* Size of the length field; either 4 or 12. */
327 unsigned int initial_length_size
;
329 /* Offset to the first byte of this compilation unit header in the
330 .debug_info section, for resolving relative reference dies. */
333 /* Offset to first die in this cu from the start of the cu.
334 This will be the first byte following the compilation unit header. */
335 cu_offset first_die_offset
;
338 /* Type used for delaying computation of method physnames.
339 See comments for compute_delayed_physnames. */
340 struct delayed_method_info
342 /* The type to which the method is attached, i.e., its parent class. */
345 /* The index of the method in the type's function fieldlists. */
348 /* The index of the method in the fieldlist. */
351 /* The name of the DIE. */
354 /* The DIE associated with this method. */
355 struct die_info
*die
;
358 typedef struct delayed_method_info delayed_method_info
;
359 DEF_VEC_O (delayed_method_info
);
361 /* Internal state when decoding a particular compilation unit. */
364 /* The objfile containing this compilation unit. */
365 struct objfile
*objfile
;
367 /* The header of the compilation unit. */
368 struct comp_unit_head header
;
370 /* Base address of this compilation unit. */
371 CORE_ADDR base_address
;
373 /* Non-zero if base_address has been set. */
376 /* The language we are debugging. */
377 enum language language
;
378 const struct language_defn
*language_defn
;
380 const char *producer
;
382 /* The generic symbol table building routines have separate lists for
383 file scope symbols and all all other scopes (local scopes). So
384 we need to select the right one to pass to add_symbol_to_list().
385 We do it by keeping a pointer to the correct list in list_in_scope.
387 FIXME: The original dwarf code just treated the file scope as the
388 first local scope, and all other local scopes as nested local
389 scopes, and worked fine. Check to see if we really need to
390 distinguish these in buildsym.c. */
391 struct pending
**list_in_scope
;
393 /* The abbrev table for this CU.
394 Normally this points to the abbrev table in the objfile.
395 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
396 struct abbrev_table
*abbrev_table
;
398 /* Hash table holding all the loaded partial DIEs
399 with partial_die->offset.SECT_OFF as hash. */
402 /* Storage for things with the same lifetime as this read-in compilation
403 unit, including partial DIEs. */
404 struct obstack comp_unit_obstack
;
406 /* When multiple dwarf2_cu structures are living in memory, this field
407 chains them all together, so that they can be released efficiently.
408 We will probably also want a generation counter so that most-recently-used
409 compilation units are cached... */
410 struct dwarf2_per_cu_data
*read_in_chain
;
412 /* Backchain to our per_cu entry if the tree has been built. */
413 struct dwarf2_per_cu_data
*per_cu
;
415 /* How many compilation units ago was this CU last referenced? */
418 /* A hash table of DIE cu_offset for following references with
419 die_info->offset.sect_off as hash. */
422 /* Full DIEs if read in. */
423 struct die_info
*dies
;
425 /* A set of pointers to dwarf2_per_cu_data objects for compilation
426 units referenced by this one. Only set during full symbol processing;
427 partial symbol tables do not have dependencies. */
430 /* Header data from the line table, during full symbol processing. */
431 struct line_header
*line_header
;
433 /* A list of methods which need to have physnames computed
434 after all type information has been read. */
435 VEC (delayed_method_info
) *method_list
;
437 /* To be copied to symtab->call_site_htab. */
438 htab_t call_site_htab
;
440 /* Non-NULL if this CU came from a DWO file.
441 There is an invariant here that is important to remember:
442 Except for attributes copied from the top level DIE in the "main"
443 (or "stub") file in preparation for reading the DWO file
444 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
445 Either there isn't a DWO file (in which case this is NULL and the point
446 is moot), or there is and either we're not going to read it (in which
447 case this is NULL) or there is and we are reading it (in which case this
449 struct dwo_unit
*dwo_unit
;
451 /* The DW_AT_addr_base attribute if present, zero otherwise
452 (zero is a valid value though).
453 Note this value comes from the stub CU/TU's DIE. */
456 /* The DW_AT_ranges_base attribute if present, zero otherwise
457 (zero is a valid value though).
458 Note this value comes from the stub CU/TU's DIE.
459 Also note that the value is zero in the non-DWO case so this value can
460 be used without needing to know whether DWO files are in use or not. */
461 ULONGEST ranges_base
;
463 /* Mark used when releasing cached dies. */
464 unsigned int mark
: 1;
466 /* This CU references .debug_loc. See the symtab->locations_valid field.
467 This test is imperfect as there may exist optimized debug code not using
468 any location list and still facing inlining issues if handled as
469 unoptimized code. For a future better test see GCC PR other/32998. */
470 unsigned int has_loclist
: 1;
472 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
473 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
474 are valid. This information is cached because profiling CU expansion
475 showed excessive time spent in producer_is_gxx_lt_4_6. */
476 unsigned int checked_producer
: 1;
477 unsigned int producer_is_gxx_lt_4_6
: 1;
478 unsigned int producer_is_icc
: 1;
481 /* Persistent data held for a compilation unit, even when not
482 processing it. We put a pointer to this structure in the
483 read_symtab_private field of the psymtab. */
485 struct dwarf2_per_cu_data
487 /* The start offset and length of this compilation unit. 2**29-1
488 bytes should suffice to store the length of any compilation unit
489 - if it doesn't, GDB will fall over anyway.
490 NOTE: Unlike comp_unit_head.length, this length includes
492 If the DIE refers to a DWO file, this is always of the original die,
495 unsigned int length
: 29;
497 /* Flag indicating this compilation unit will be read in before
498 any of the current compilation units are processed. */
499 unsigned int queued
: 1;
501 /* This flag will be set when reading partial DIEs if we need to load
502 absolutely all DIEs for this compilation unit, instead of just the ones
503 we think are interesting. It gets set if we look for a DIE in the
504 hash table and don't find it. */
505 unsigned int load_all_dies
: 1;
507 /* Non-zero if this CU is from .debug_types. */
508 unsigned int is_debug_types
: 1;
510 /* The section this CU/TU lives in.
511 If the DIE refers to a DWO file, this is always the original die,
513 struct dwarf2_section_info
*info_or_types_section
;
515 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
516 of the CU cache it gets reset to NULL again. */
517 struct dwarf2_cu
*cu
;
519 /* The corresponding objfile.
520 Normally we can get the objfile from dwarf2_per_objfile.
521 However we can enter this file with just a "per_cu" handle. */
522 struct objfile
*objfile
;
524 /* When using partial symbol tables, the 'psymtab' field is active.
525 Otherwise the 'quick' field is active. */
528 /* The partial symbol table associated with this compilation unit,
529 or NULL for unread partial units. */
530 struct partial_symtab
*psymtab
;
532 /* Data needed by the "quick" functions. */
533 struct dwarf2_per_cu_quick_data
*quick
;
536 /* The CUs we import using DW_TAG_imported_unit. This is filled in
537 while reading psymtabs, used to compute the psymtab dependencies,
538 and then cleared. Then it is filled in again while reading full
539 symbols, and only deleted when the objfile is destroyed. */
540 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
543 /* Entry in the signatured_types hash table. */
545 struct signatured_type
547 /* The type's signature. */
550 /* Offset in the TU of the type's DIE, as read from the TU header.
551 If the definition lives in a DWO file, this value is unusable. */
552 cu_offset type_offset_in_tu
;
554 /* Offset in the section of the type's DIE.
555 If the definition lives in a DWO file, this is the offset in the
556 .debug_types.dwo section.
557 The value is zero until the actual value is known.
558 Zero is otherwise not a valid section offset. */
559 sect_offset type_offset_in_section
;
561 /* The CU(/TU) of this type. */
562 struct dwarf2_per_cu_data per_cu
;
565 /* These sections are what may appear in a "dwo" file. */
569 struct dwarf2_section_info abbrev
;
570 struct dwarf2_section_info info
;
571 struct dwarf2_section_info line
;
572 struct dwarf2_section_info loc
;
573 struct dwarf2_section_info macinfo
;
574 struct dwarf2_section_info macro
;
575 struct dwarf2_section_info str
;
576 struct dwarf2_section_info str_offsets
;
577 VEC (dwarf2_section_info_def
) *types
;
580 /* Common bits of DWO CUs/TUs. */
584 /* Backlink to the containing struct dwo_file. */
585 struct dwo_file
*dwo_file
;
587 /* The "id" that distinguishes this CU/TU.
588 .debug_info calls this "dwo_id", .debug_types calls this "signature".
589 Since signatures came first, we stick with it for consistency. */
592 /* The section this CU/TU lives in, in the DWO file. */
593 struct dwarf2_section_info
*info_or_types_section
;
595 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
599 /* For types, offset in the type's DIE of the type defined by this TU. */
600 cu_offset type_offset_in_tu
;
603 /* Data for one DWO file. */
607 /* The DW_AT_GNU_dwo_name attribute.
608 We don't manage space for this, it's an attribute. */
609 const char *dwo_name
;
611 /* The bfd, when the file is open. Otherwise this is NULL. */
614 /* Section info for this file. */
615 struct dwo_sections sections
;
617 /* Table of CUs in the file.
618 Each element is a struct dwo_unit. */
621 /* Table of TUs in the file.
622 Each element is a struct dwo_unit. */
626 /* Struct used to pass misc. parameters to read_die_and_children, et
627 al. which are used for both .debug_info and .debug_types dies.
628 All parameters here are unchanging for the life of the call. This
629 struct exists to abstract away the constant parameters of die reading. */
631 struct die_reader_specs
633 /* die_section->asection->owner. */
636 /* The CU of the DIE we are parsing. */
637 struct dwarf2_cu
*cu
;
639 /* Non-NULL if reading a DWO file. */
640 struct dwo_file
*dwo_file
;
642 /* The section the die comes from.
643 This is either .debug_info or .debug_types, or the .dwo variants. */
644 struct dwarf2_section_info
*die_section
;
646 /* die_section->buffer. */
649 /* The end of the buffer. */
650 const gdb_byte
*buffer_end
;
653 /* Type of function passed to init_cutu_and_read_dies, et.al. */
654 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
656 struct die_info
*comp_unit_die
,
660 /* The line number information for a compilation unit (found in the
661 .debug_line section) begins with a "statement program header",
662 which contains the following information. */
665 unsigned int total_length
;
666 unsigned short version
;
667 unsigned int header_length
;
668 unsigned char minimum_instruction_length
;
669 unsigned char maximum_ops_per_instruction
;
670 unsigned char default_is_stmt
;
672 unsigned char line_range
;
673 unsigned char opcode_base
;
675 /* standard_opcode_lengths[i] is the number of operands for the
676 standard opcode whose value is i. This means that
677 standard_opcode_lengths[0] is unused, and the last meaningful
678 element is standard_opcode_lengths[opcode_base - 1]. */
679 unsigned char *standard_opcode_lengths
;
681 /* The include_directories table. NOTE! These strings are not
682 allocated with xmalloc; instead, they are pointers into
683 debug_line_buffer. If you try to free them, `free' will get
685 unsigned int num_include_dirs
, include_dirs_size
;
688 /* The file_names table. NOTE! These strings are not allocated
689 with xmalloc; instead, they are pointers into debug_line_buffer.
690 Don't try to free them directly. */
691 unsigned int num_file_names
, file_names_size
;
695 unsigned int dir_index
;
696 unsigned int mod_time
;
698 int included_p
; /* Non-zero if referenced by the Line Number Program. */
699 struct symtab
*symtab
; /* The associated symbol table, if any. */
702 /* The start and end of the statement program following this
703 header. These point into dwarf2_per_objfile->line_buffer. */
704 gdb_byte
*statement_program_start
, *statement_program_end
;
707 /* When we construct a partial symbol table entry we only
708 need this much information. */
709 struct partial_die_info
711 /* Offset of this DIE. */
714 /* DWARF-2 tag for this DIE. */
715 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
717 /* Assorted flags describing the data found in this DIE. */
718 unsigned int has_children
: 1;
719 unsigned int is_external
: 1;
720 unsigned int is_declaration
: 1;
721 unsigned int has_type
: 1;
722 unsigned int has_specification
: 1;
723 unsigned int has_pc_info
: 1;
724 unsigned int may_be_inlined
: 1;
726 /* Flag set if the SCOPE field of this structure has been
728 unsigned int scope_set
: 1;
730 /* Flag set if the DIE has a byte_size attribute. */
731 unsigned int has_byte_size
: 1;
733 /* Flag set if any of the DIE's children are template arguments. */
734 unsigned int has_template_arguments
: 1;
736 /* Flag set if fixup_partial_die has been called on this die. */
737 unsigned int fixup_called
: 1;
739 /* The name of this DIE. Normally the value of DW_AT_name, but
740 sometimes a default name for unnamed DIEs. */
743 /* The linkage name, if present. */
744 const char *linkage_name
;
746 /* The scope to prepend to our children. This is generally
747 allocated on the comp_unit_obstack, so will disappear
748 when this compilation unit leaves the cache. */
751 /* Some data associated with the partial DIE. The tag determines
752 which field is live. */
755 /* The location description associated with this DIE, if any. */
756 struct dwarf_block
*locdesc
;
757 /* The offset of an import, for DW_TAG_imported_unit. */
761 /* If HAS_PC_INFO, the PC range associated with this DIE. */
765 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
766 DW_AT_sibling, if any. */
767 /* NOTE: This member isn't strictly necessary, read_partial_die could
768 return DW_AT_sibling values to its caller load_partial_dies. */
771 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
772 DW_AT_specification (or DW_AT_abstract_origin or
774 sect_offset spec_offset
;
776 /* Pointers to this DIE's parent, first child, and next sibling,
778 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
781 /* This data structure holds the information of an abbrev. */
784 unsigned int number
; /* number identifying abbrev */
785 enum dwarf_tag tag
; /* dwarf tag */
786 unsigned short has_children
; /* boolean */
787 unsigned short num_attrs
; /* number of attributes */
788 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
789 struct abbrev_info
*next
; /* next in chain */
794 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
795 ENUM_BITFIELD(dwarf_form
) form
: 16;
798 /* Size of abbrev_table.abbrev_hash_table. */
799 #define ABBREV_HASH_SIZE 121
801 /* Top level data structure to contain an abbreviation table. */
805 /* Where the abbrev table came from. */
806 struct dwarf2_section_info
*section
;
809 /* Storage for the abbrev table. */
810 struct obstack abbrev_obstack
;
812 /* Hash table of abbrevs.
813 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
814 It could be statically allocated, but the previous code didn't so we
816 struct abbrev_info
**abbrevs
;
819 /* Attributes have a name and a value. */
822 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
823 ENUM_BITFIELD(dwarf_form
) form
: 15;
825 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
826 field should be in u.str (existing only for DW_STRING) but it is kept
827 here for better struct attribute alignment. */
828 unsigned int string_is_canonical
: 1;
833 struct dwarf_block
*blk
;
837 struct signatured_type
*signatured_type
;
842 /* This data structure holds a complete die structure. */
845 /* DWARF-2 tag for this DIE. */
846 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
848 /* Number of attributes */
849 unsigned char num_attrs
;
851 /* True if we're presently building the full type name for the
852 type derived from this DIE. */
853 unsigned char building_fullname
: 1;
858 /* Offset in .debug_info or .debug_types section. */
861 /* The dies in a compilation unit form an n-ary tree. PARENT
862 points to this die's parent; CHILD points to the first child of
863 this node; and all the children of a given node are chained
864 together via their SIBLING fields. */
865 struct die_info
*child
; /* Its first child, if any. */
866 struct die_info
*sibling
; /* Its next sibling, if any. */
867 struct die_info
*parent
; /* Its parent, if any. */
869 /* An array of attributes, with NUM_ATTRS elements. There may be
870 zero, but it's not common and zero-sized arrays are not
871 sufficiently portable C. */
872 struct attribute attrs
[1];
875 /* Get at parts of an attribute structure. */
877 #define DW_STRING(attr) ((attr)->u.str)
878 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
879 #define DW_UNSND(attr) ((attr)->u.unsnd)
880 #define DW_BLOCK(attr) ((attr)->u.blk)
881 #define DW_SND(attr) ((attr)->u.snd)
882 #define DW_ADDR(attr) ((attr)->u.addr)
883 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
885 /* Blocks are a bunch of untyped bytes. */
890 /* Valid only if SIZE is not zero. */
894 #ifndef ATTR_ALLOC_CHUNK
895 #define ATTR_ALLOC_CHUNK 4
898 /* Allocate fields for structs, unions and enums in this size. */
899 #ifndef DW_FIELD_ALLOC_CHUNK
900 #define DW_FIELD_ALLOC_CHUNK 4
903 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
904 but this would require a corresponding change in unpack_field_as_long
906 static int bits_per_byte
= 8;
908 /* The routines that read and process dies for a C struct or C++ class
909 pass lists of data member fields and lists of member function fields
910 in an instance of a field_info structure, as defined below. */
913 /* List of data member and baseclasses fields. */
916 struct nextfield
*next
;
921 *fields
, *baseclasses
;
923 /* Number of fields (including baseclasses). */
926 /* Number of baseclasses. */
929 /* Set if the accesibility of one of the fields is not public. */
930 int non_public_fields
;
932 /* Member function fields array, entries are allocated in the order they
933 are encountered in the object file. */
936 struct nextfnfield
*next
;
937 struct fn_field fnfield
;
941 /* Member function fieldlist array, contains name of possibly overloaded
942 member function, number of overloaded member functions and a pointer
943 to the head of the member function field chain. */
948 struct nextfnfield
*head
;
952 /* Number of entries in the fnfieldlists array. */
955 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
956 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
957 struct typedef_field_list
959 struct typedef_field field
;
960 struct typedef_field_list
*next
;
963 unsigned typedef_field_list_count
;
966 /* One item on the queue of compilation units to read in full symbols
968 struct dwarf2_queue_item
970 struct dwarf2_per_cu_data
*per_cu
;
971 enum language pretend_language
;
972 struct dwarf2_queue_item
*next
;
975 /* The current queue. */
976 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
978 /* Loaded secondary compilation units are kept in memory until they
979 have not been referenced for the processing of this many
980 compilation units. Set this to zero to disable caching. Cache
981 sizes of up to at least twenty will improve startup time for
982 typical inter-CU-reference binaries, at an obvious memory cost. */
983 static int dwarf2_max_cache_age
= 5;
985 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
986 struct cmd_list_element
*c
, const char *value
)
988 fprintf_filtered (file
, _("The upper bound on the age of cached "
989 "dwarf2 compilation units is %s.\n"),
994 /* Various complaints about symbol reading that don't abort the process. */
997 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
999 complaint (&symfile_complaints
,
1000 _("statement list doesn't fit in .debug_line section"));
1004 dwarf2_debug_line_missing_file_complaint (void)
1006 complaint (&symfile_complaints
,
1007 _(".debug_line section has line data without a file"));
1011 dwarf2_debug_line_missing_end_sequence_complaint (void)
1013 complaint (&symfile_complaints
,
1014 _(".debug_line section has line "
1015 "program sequence without an end"));
1019 dwarf2_complex_location_expr_complaint (void)
1021 complaint (&symfile_complaints
, _("location expression too complex"));
1025 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1028 complaint (&symfile_complaints
,
1029 _("const value length mismatch for '%s', got %d, expected %d"),
1034 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1036 complaint (&symfile_complaints
,
1037 _("debug info runs off end of %s section"
1039 section
->asection
->name
,
1040 bfd_get_filename (section
->asection
->owner
));
1044 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1046 complaint (&symfile_complaints
,
1047 _("macro debug info contains a "
1048 "malformed macro definition:\n`%s'"),
1053 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1055 complaint (&symfile_complaints
,
1056 _("invalid attribute class or form for '%s' in '%s'"),
1060 /* local function prototypes */
1062 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1064 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1067 static void dwarf2_find_base_address (struct die_info
*die
,
1068 struct dwarf2_cu
*cu
);
1070 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1072 static void scan_partial_symbols (struct partial_die_info
*,
1073 CORE_ADDR
*, CORE_ADDR
*,
1074 int, struct dwarf2_cu
*);
1076 static void add_partial_symbol (struct partial_die_info
*,
1077 struct dwarf2_cu
*);
1079 static void add_partial_namespace (struct partial_die_info
*pdi
,
1080 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1081 int need_pc
, struct dwarf2_cu
*cu
);
1083 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1084 CORE_ADDR
*highpc
, int need_pc
,
1085 struct dwarf2_cu
*cu
);
1087 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1088 struct dwarf2_cu
*cu
);
1090 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1091 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1092 int need_pc
, struct dwarf2_cu
*cu
);
1094 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1096 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1098 static struct abbrev_info
*abbrev_table_lookup_abbrev
1099 (const struct abbrev_table
*, unsigned int);
1101 static struct abbrev_table
*abbrev_table_read_table
1102 (struct dwarf2_section_info
*, sect_offset
);
1104 static void abbrev_table_free (struct abbrev_table
*);
1106 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1107 struct dwarf2_section_info
*);
1109 static void dwarf2_free_abbrev_table (void *);
1111 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1113 static struct partial_die_info
*load_partial_dies
1114 (const struct die_reader_specs
*, gdb_byte
*, int);
1116 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1117 struct partial_die_info
*,
1118 struct abbrev_info
*,
1122 static struct partial_die_info
*find_partial_die (sect_offset
,
1123 struct dwarf2_cu
*);
1125 static void fixup_partial_die (struct partial_die_info
*,
1126 struct dwarf2_cu
*);
1128 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1129 struct attribute
*, struct attr_abbrev
*,
1132 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1134 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1136 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1138 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1140 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1142 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1145 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1147 static LONGEST read_checked_initial_length_and_offset
1148 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1149 unsigned int *, unsigned int *);
1151 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1154 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1156 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1158 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1160 static char *read_indirect_string (bfd
*, gdb_byte
*,
1161 const struct comp_unit_head
*,
1164 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1166 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1168 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1171 static char *read_str_index (const struct die_reader_specs
*reader
,
1172 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1174 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1176 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1177 struct dwarf2_cu
*);
1179 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1181 struct dwarf2_cu
*);
1183 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1184 struct dwarf2_cu
*cu
);
1186 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1188 static struct die_info
*die_specification (struct die_info
*die
,
1189 struct dwarf2_cu
**);
1191 static void free_line_header (struct line_header
*lh
);
1193 static void add_file_name (struct line_header
*, char *, unsigned int,
1194 unsigned int, unsigned int);
1196 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1197 struct dwarf2_cu
*cu
);
1199 static void dwarf_decode_lines (struct line_header
*, const char *,
1200 struct dwarf2_cu
*, struct partial_symtab
*,
1203 static void dwarf2_start_subfile (char *, const char *, const char *);
1205 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1206 struct dwarf2_cu
*);
1208 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1209 struct dwarf2_cu
*, struct symbol
*);
1211 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1212 struct dwarf2_cu
*);
1214 static void dwarf2_const_value_attr (struct attribute
*attr
,
1217 struct obstack
*obstack
,
1218 struct dwarf2_cu
*cu
, LONGEST
*value
,
1220 struct dwarf2_locexpr_baton
**baton
);
1222 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1224 static int need_gnat_info (struct dwarf2_cu
*);
1226 static struct type
*die_descriptive_type (struct die_info
*,
1227 struct dwarf2_cu
*);
1229 static void set_descriptive_type (struct type
*, struct die_info
*,
1230 struct dwarf2_cu
*);
1232 static struct type
*die_containing_type (struct die_info
*,
1233 struct dwarf2_cu
*);
1235 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1236 struct dwarf2_cu
*);
1238 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1240 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1242 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1244 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1245 const char *suffix
, int physname
,
1246 struct dwarf2_cu
*cu
);
1248 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1250 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1252 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1254 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1256 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1258 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1259 struct dwarf2_cu
*, struct partial_symtab
*);
1261 static int dwarf2_get_pc_bounds (struct die_info
*,
1262 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1263 struct partial_symtab
*);
1265 static void get_scope_pc_bounds (struct die_info
*,
1266 CORE_ADDR
*, CORE_ADDR
*,
1267 struct dwarf2_cu
*);
1269 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1270 CORE_ADDR
, struct dwarf2_cu
*);
1272 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1273 struct dwarf2_cu
*);
1275 static void dwarf2_attach_fields_to_type (struct field_info
*,
1276 struct type
*, struct dwarf2_cu
*);
1278 static void dwarf2_add_member_fn (struct field_info
*,
1279 struct die_info
*, struct type
*,
1280 struct dwarf2_cu
*);
1282 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1284 struct dwarf2_cu
*);
1286 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1288 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1290 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1292 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1294 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1296 static struct type
*read_module_type (struct die_info
*die
,
1297 struct dwarf2_cu
*cu
);
1299 static const char *namespace_name (struct die_info
*die
,
1300 int *is_anonymous
, struct dwarf2_cu
*);
1302 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1304 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1306 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1307 struct dwarf2_cu
*);
1309 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1311 gdb_byte
**new_info_ptr
,
1312 struct die_info
*parent
);
1314 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1316 gdb_byte
**new_info_ptr
,
1317 struct die_info
*parent
);
1319 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1320 struct die_info
**, gdb_byte
*, int *, int);
1322 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1323 struct die_info
**, gdb_byte
*, int *);
1325 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1327 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1330 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1332 static const char *dwarf2_full_name (char *name
,
1333 struct die_info
*die
,
1334 struct dwarf2_cu
*cu
);
1336 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1337 struct dwarf2_cu
**);
1339 static const char *dwarf_tag_name (unsigned int);
1341 static const char *dwarf_attr_name (unsigned int);
1343 static const char *dwarf_form_name (unsigned int);
1345 static char *dwarf_bool_name (unsigned int);
1347 static const char *dwarf_type_encoding_name (unsigned int);
1349 static struct die_info
*sibling_die (struct die_info
*);
1351 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1353 static void dump_die_for_error (struct die_info
*);
1355 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1358 /*static*/ void dump_die (struct die_info
*, int max_level
);
1360 static void store_in_ref_table (struct die_info
*,
1361 struct dwarf2_cu
*);
1363 static int is_ref_attr (struct attribute
*);
1365 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1367 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1369 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1371 struct dwarf2_cu
**);
1373 static struct die_info
*follow_die_ref (struct die_info
*,
1375 struct dwarf2_cu
**);
1377 static struct die_info
*follow_die_sig (struct die_info
*,
1379 struct dwarf2_cu
**);
1381 static struct signatured_type
*lookup_signatured_type_at_offset
1382 (struct objfile
*objfile
,
1383 struct dwarf2_section_info
*section
, sect_offset offset
);
1385 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1387 static void read_signatured_type (struct signatured_type
*);
1389 /* memory allocation interface */
1391 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1393 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1395 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1398 static int attr_form_is_block (struct attribute
*);
1400 static int attr_form_is_section_offset (struct attribute
*);
1402 static int attr_form_is_constant (struct attribute
*);
1404 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1405 struct dwarf2_loclist_baton
*baton
,
1406 struct attribute
*attr
);
1408 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1410 struct dwarf2_cu
*cu
);
1412 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1414 struct abbrev_info
*abbrev
);
1416 static void free_stack_comp_unit (void *);
1418 static hashval_t
partial_die_hash (const void *item
);
1420 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1422 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1423 (sect_offset offset
, struct objfile
*objfile
);
1425 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1426 struct dwarf2_per_cu_data
*per_cu
);
1428 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1429 struct die_info
*comp_unit_die
,
1430 enum language pretend_language
);
1432 static void free_heap_comp_unit (void *);
1434 static void free_cached_comp_units (void *);
1436 static void age_cached_comp_units (void);
1438 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1440 static struct type
*set_die_type (struct die_info
*, struct type
*,
1441 struct dwarf2_cu
*);
1443 static void create_all_comp_units (struct objfile
*);
1445 static int create_all_type_units (struct objfile
*);
1447 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1450 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1453 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1454 struct dwarf2_per_cu_data
*);
1456 static void dwarf2_mark (struct dwarf2_cu
*);
1458 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1460 static struct type
*get_die_type_at_offset (sect_offset
,
1461 struct dwarf2_per_cu_data
*per_cu
);
1463 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1465 static void dwarf2_release_queue (void *dummy
);
1467 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1468 enum language pretend_language
);
1470 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1471 struct dwarf2_per_cu_data
*per_cu
,
1472 enum language pretend_language
);
1474 static void process_queue (void);
1476 static void find_file_and_directory (struct die_info
*die
,
1477 struct dwarf2_cu
*cu
,
1478 char **name
, char **comp_dir
);
1480 static char *file_full_name (int file
, struct line_header
*lh
,
1481 const char *comp_dir
);
1483 static void init_cutu_and_read_dies
1484 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1485 die_reader_func_ftype
*die_reader_func
, void *data
);
1487 static void init_cutu_and_read_dies_simple
1488 (struct dwarf2_per_cu_data
*this_cu
,
1489 die_reader_func_ftype
*die_reader_func
, void *data
);
1491 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1493 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1495 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1497 static struct dwo_unit
*lookup_dwo_comp_unit
1498 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1500 static struct dwo_unit
*lookup_dwo_type_unit
1501 (struct signatured_type
*, char *, const char *);
1503 static void free_dwo_file_cleanup (void *);
1505 static void munmap_section_buffer (struct dwarf2_section_info
*);
1507 static void process_cu_includes (void);
1511 /* Convert VALUE between big- and little-endian. */
1513 byte_swap (offset_type value
)
1517 result
= (value
& 0xff) << 24;
1518 result
|= (value
& 0xff00) << 8;
1519 result
|= (value
& 0xff0000) >> 8;
1520 result
|= (value
& 0xff000000) >> 24;
1524 #define MAYBE_SWAP(V) byte_swap (V)
1527 #define MAYBE_SWAP(V) (V)
1528 #endif /* WORDS_BIGENDIAN */
1530 /* The suffix for an index file. */
1531 #define INDEX_SUFFIX ".gdb-index"
1533 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1534 struct dwarf2_cu
*cu
);
1536 /* Try to locate the sections we need for DWARF 2 debugging
1537 information and return true if we have enough to do something.
1538 NAMES points to the dwarf2 section names, or is NULL if the standard
1539 ELF names are used. */
1542 dwarf2_has_info (struct objfile
*objfile
,
1543 const struct dwarf2_debug_sections
*names
)
1545 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1546 if (!dwarf2_per_objfile
)
1548 /* Initialize per-objfile state. */
1549 struct dwarf2_per_objfile
*data
1550 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1552 memset (data
, 0, sizeof (*data
));
1553 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1554 dwarf2_per_objfile
= data
;
1556 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1558 dwarf2_per_objfile
->objfile
= objfile
;
1560 return (dwarf2_per_objfile
->info
.asection
!= NULL
1561 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1564 /* When loading sections, we look either for uncompressed section or for
1565 compressed section names. */
1568 section_is_p (const char *section_name
,
1569 const struct dwarf2_section_names
*names
)
1571 if (names
->normal
!= NULL
1572 && strcmp (section_name
, names
->normal
) == 0)
1574 if (names
->compressed
!= NULL
1575 && strcmp (section_name
, names
->compressed
) == 0)
1580 /* This function is mapped across the sections and remembers the
1581 offset and size of each of the debugging sections we are interested
1585 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1587 const struct dwarf2_debug_sections
*names
;
1590 names
= &dwarf2_elf_names
;
1592 names
= (const struct dwarf2_debug_sections
*) vnames
;
1594 if (section_is_p (sectp
->name
, &names
->info
))
1596 dwarf2_per_objfile
->info
.asection
= sectp
;
1597 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1599 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1601 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1602 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1604 else if (section_is_p (sectp
->name
, &names
->line
))
1606 dwarf2_per_objfile
->line
.asection
= sectp
;
1607 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1609 else if (section_is_p (sectp
->name
, &names
->loc
))
1611 dwarf2_per_objfile
->loc
.asection
= sectp
;
1612 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1614 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1616 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1617 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1619 else if (section_is_p (sectp
->name
, &names
->macro
))
1621 dwarf2_per_objfile
->macro
.asection
= sectp
;
1622 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1624 else if (section_is_p (sectp
->name
, &names
->str
))
1626 dwarf2_per_objfile
->str
.asection
= sectp
;
1627 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1629 else if (section_is_p (sectp
->name
, &names
->addr
))
1631 dwarf2_per_objfile
->addr
.asection
= sectp
;
1632 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1634 else if (section_is_p (sectp
->name
, &names
->frame
))
1636 dwarf2_per_objfile
->frame
.asection
= sectp
;
1637 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1639 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1641 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1643 if (aflag
& SEC_HAS_CONTENTS
)
1645 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1646 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1649 else if (section_is_p (sectp
->name
, &names
->ranges
))
1651 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1652 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1654 else if (section_is_p (sectp
->name
, &names
->types
))
1656 struct dwarf2_section_info type_section
;
1658 memset (&type_section
, 0, sizeof (type_section
));
1659 type_section
.asection
= sectp
;
1660 type_section
.size
= bfd_get_section_size (sectp
);
1662 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1665 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1667 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1668 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1671 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1672 && bfd_section_vma (abfd
, sectp
) == 0)
1673 dwarf2_per_objfile
->has_section_at_zero
= 1;
1676 /* Decompress a section that was compressed using zlib. Store the
1677 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1680 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1681 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1683 bfd
*abfd
= sectp
->owner
;
1685 error (_("Support for zlib-compressed DWARF data (from '%s') "
1686 "is disabled in this copy of GDB"),
1687 bfd_get_filename (abfd
));
1689 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1690 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1691 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1692 bfd_size_type uncompressed_size
;
1693 gdb_byte
*uncompressed_buffer
;
1696 int header_size
= 12;
1698 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1699 || bfd_bread (compressed_buffer
,
1700 compressed_size
, abfd
) != compressed_size
)
1701 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1702 bfd_get_filename (abfd
));
1704 /* Read the zlib header. In this case, it should be "ZLIB" followed
1705 by the uncompressed section size, 8 bytes in big-endian order. */
1706 if (compressed_size
< header_size
1707 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1708 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1709 bfd_get_filename (abfd
));
1710 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1711 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1712 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1713 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1714 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1715 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1716 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1717 uncompressed_size
+= compressed_buffer
[11];
1719 /* It is possible the section consists of several compressed
1720 buffers concatenated together, so we uncompress in a loop. */
1724 strm
.avail_in
= compressed_size
- header_size
;
1725 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1726 strm
.avail_out
= uncompressed_size
;
1727 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1729 rc
= inflateInit (&strm
);
1730 while (strm
.avail_in
> 0)
1733 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1734 bfd_get_filename (abfd
), rc
);
1735 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1736 + (uncompressed_size
- strm
.avail_out
));
1737 rc
= inflate (&strm
, Z_FINISH
);
1738 if (rc
!= Z_STREAM_END
)
1739 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1740 bfd_get_filename (abfd
), rc
);
1741 rc
= inflateReset (&strm
);
1743 rc
= inflateEnd (&strm
);
1745 || strm
.avail_out
!= 0)
1746 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1747 bfd_get_filename (abfd
), rc
);
1749 do_cleanups (cleanup
);
1750 *outbuf
= uncompressed_buffer
;
1751 *outsize
= uncompressed_size
;
1755 /* A helper function that decides whether a section is empty,
1759 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1761 return info
->asection
== NULL
|| info
->size
== 0;
1764 /* Read the contents of the section INFO.
1765 OBJFILE is the main object file, but not necessarily the file where
1766 the section comes from. E.g., for DWO files INFO->asection->owner
1767 is the bfd of the DWO file.
1768 If the section is compressed, uncompress it before returning. */
1771 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1773 asection
*sectp
= info
->asection
;
1775 gdb_byte
*buf
, *retbuf
;
1776 unsigned char header
[4];
1780 info
->buffer
= NULL
;
1781 info
->map_addr
= NULL
;
1784 if (dwarf2_section_empty_p (info
))
1787 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1788 abfd
= sectp
->owner
;
1790 /* Check if the file has a 4-byte header indicating compression. */
1791 if (info
->size
> sizeof (header
)
1792 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1793 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1795 /* Upon decompression, update the buffer and its size. */
1796 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1798 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1806 pagesize
= getpagesize ();
1808 /* Only try to mmap sections which are large enough: we don't want to
1809 waste space due to fragmentation. Also, only try mmap for sections
1810 without relocations. */
1812 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1814 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1815 MAP_PRIVATE
, sectp
->filepos
,
1816 &info
->map_addr
, &info
->map_len
);
1818 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1820 #if HAVE_POSIX_MADVISE
1821 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1828 /* If we get here, we are a normal, not-compressed section. */
1830 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1832 /* When debugging .o files, we may need to apply relocations; see
1833 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1834 We never compress sections in .o files, so we only need to
1835 try this when the section is not compressed. */
1836 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1839 info
->buffer
= retbuf
;
1843 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1844 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1845 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1846 bfd_get_filename (abfd
));
1849 /* A helper function that returns the size of a section in a safe way.
1850 If you are positive that the section has been read before using the
1851 size, then it is safe to refer to the dwarf2_section_info object's
1852 "size" field directly. In other cases, you must call this
1853 function, because for compressed sections the size field is not set
1854 correctly until the section has been read. */
1856 static bfd_size_type
1857 dwarf2_section_size (struct objfile
*objfile
,
1858 struct dwarf2_section_info
*info
)
1861 dwarf2_read_section (objfile
, info
);
1865 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1869 dwarf2_get_section_info (struct objfile
*objfile
,
1870 enum dwarf2_section_enum sect
,
1871 asection
**sectp
, gdb_byte
**bufp
,
1872 bfd_size_type
*sizep
)
1874 struct dwarf2_per_objfile
*data
1875 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1876 struct dwarf2_section_info
*info
;
1878 /* We may see an objfile without any DWARF, in which case we just
1889 case DWARF2_DEBUG_FRAME
:
1890 info
= &data
->frame
;
1892 case DWARF2_EH_FRAME
:
1893 info
= &data
->eh_frame
;
1896 gdb_assert_not_reached ("unexpected section");
1899 dwarf2_read_section (objfile
, info
);
1901 *sectp
= info
->asection
;
1902 *bufp
= info
->buffer
;
1903 *sizep
= info
->size
;
1907 /* DWARF quick_symbols_functions support. */
1909 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1910 unique line tables, so we maintain a separate table of all .debug_line
1911 derived entries to support the sharing.
1912 All the quick functions need is the list of file names. We discard the
1913 line_header when we're done and don't need to record it here. */
1914 struct quick_file_names
1916 /* The offset in .debug_line of the line table. We hash on this. */
1917 unsigned int offset
;
1919 /* The number of entries in file_names, real_names. */
1920 unsigned int num_file_names
;
1922 /* The file names from the line table, after being run through
1924 const char **file_names
;
1926 /* The file names from the line table after being run through
1927 gdb_realpath. These are computed lazily. */
1928 const char **real_names
;
1931 /* When using the index (and thus not using psymtabs), each CU has an
1932 object of this type. This is used to hold information needed by
1933 the various "quick" methods. */
1934 struct dwarf2_per_cu_quick_data
1936 /* The file table. This can be NULL if there was no file table
1937 or it's currently not read in.
1938 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1939 struct quick_file_names
*file_names
;
1941 /* The corresponding symbol table. This is NULL if symbols for this
1942 CU have not yet been read. */
1943 struct symtab
*symtab
;
1945 /* A temporary mark bit used when iterating over all CUs in
1946 expand_symtabs_matching. */
1947 unsigned int mark
: 1;
1949 /* True if we've tried to read the file table and found there isn't one.
1950 There will be no point in trying to read it again next time. */
1951 unsigned int no_file_data
: 1;
1954 /* Hash function for a quick_file_names. */
1957 hash_file_name_entry (const void *e
)
1959 const struct quick_file_names
*file_data
= e
;
1961 return file_data
->offset
;
1964 /* Equality function for a quick_file_names. */
1967 eq_file_name_entry (const void *a
, const void *b
)
1969 const struct quick_file_names
*ea
= a
;
1970 const struct quick_file_names
*eb
= b
;
1972 return ea
->offset
== eb
->offset
;
1975 /* Delete function for a quick_file_names. */
1978 delete_file_name_entry (void *e
)
1980 struct quick_file_names
*file_data
= e
;
1983 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1985 xfree ((void*) file_data
->file_names
[i
]);
1986 if (file_data
->real_names
)
1987 xfree ((void*) file_data
->real_names
[i
]);
1990 /* The space for the struct itself lives on objfile_obstack,
1991 so we don't free it here. */
1994 /* Create a quick_file_names hash table. */
1997 create_quick_file_names_table (unsigned int nr_initial_entries
)
1999 return htab_create_alloc (nr_initial_entries
,
2000 hash_file_name_entry
, eq_file_name_entry
,
2001 delete_file_name_entry
, xcalloc
, xfree
);
2004 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2005 have to be created afterwards. You should call age_cached_comp_units after
2006 processing PER_CU->CU. dw2_setup must have been already called. */
2009 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2011 if (per_cu
->is_debug_types
)
2012 load_full_type_unit (per_cu
);
2014 load_full_comp_unit (per_cu
, language_minimal
);
2016 gdb_assert (per_cu
->cu
!= NULL
);
2018 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2021 /* Read in the symbols for PER_CU. */
2024 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2026 struct cleanup
*back_to
;
2028 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2030 if (dwarf2_per_objfile
->using_index
2031 ? per_cu
->v
.quick
->symtab
== NULL
2032 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2034 queue_comp_unit (per_cu
, language_minimal
);
2040 /* Age the cache, releasing compilation units that have not
2041 been used recently. */
2042 age_cached_comp_units ();
2044 do_cleanups (back_to
);
2047 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2048 the objfile from which this CU came. Returns the resulting symbol
2051 static struct symtab
*
2052 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2054 gdb_assert (dwarf2_per_objfile
->using_index
);
2055 if (!per_cu
->v
.quick
->symtab
)
2057 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2058 increment_reading_symtab ();
2059 dw2_do_instantiate_symtab (per_cu
);
2060 process_cu_includes ();
2061 do_cleanups (back_to
);
2063 return per_cu
->v
.quick
->symtab
;
2066 /* Return the CU given its index. */
2068 static struct dwarf2_per_cu_data
*
2069 dw2_get_cu (int index
)
2071 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2073 index
-= dwarf2_per_objfile
->n_comp_units
;
2074 return dwarf2_per_objfile
->all_type_units
[index
];
2076 return dwarf2_per_objfile
->all_comp_units
[index
];
2079 /* A helper function that knows how to read a 64-bit value in a way
2080 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2084 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2086 if (sizeof (ULONGEST
) < 8)
2090 /* Ignore the upper 4 bytes if they are all zero. */
2091 for (i
= 0; i
< 4; ++i
)
2092 if (bytes
[i
+ 4] != 0)
2095 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2098 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2102 /* Read the CU list from the mapped index, and use it to create all
2103 the CU objects for this objfile. Return 0 if something went wrong,
2104 1 if everything went ok. */
2107 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2108 offset_type cu_list_elements
)
2112 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2113 dwarf2_per_objfile
->all_comp_units
2114 = obstack_alloc (&objfile
->objfile_obstack
,
2115 dwarf2_per_objfile
->n_comp_units
2116 * sizeof (struct dwarf2_per_cu_data
*));
2118 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2120 struct dwarf2_per_cu_data
*the_cu
;
2121 ULONGEST offset
, length
;
2123 if (!extract_cu_value (cu_list
, &offset
)
2124 || !extract_cu_value (cu_list
+ 8, &length
))
2128 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2129 struct dwarf2_per_cu_data
);
2130 the_cu
->offset
.sect_off
= offset
;
2131 the_cu
->length
= length
;
2132 the_cu
->objfile
= objfile
;
2133 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2134 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2135 struct dwarf2_per_cu_quick_data
);
2136 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2142 /* Create the signatured type hash table from the index. */
2145 create_signatured_type_table_from_index (struct objfile
*objfile
,
2146 struct dwarf2_section_info
*section
,
2147 const gdb_byte
*bytes
,
2148 offset_type elements
)
2151 htab_t sig_types_hash
;
2153 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2154 dwarf2_per_objfile
->all_type_units
2155 = obstack_alloc (&objfile
->objfile_obstack
,
2156 dwarf2_per_objfile
->n_type_units
2157 * sizeof (struct dwarf2_per_cu_data
*));
2159 sig_types_hash
= allocate_signatured_type_table (objfile
);
2161 for (i
= 0; i
< elements
; i
+= 3)
2163 struct signatured_type
*sig_type
;
2164 ULONGEST offset
, type_offset_in_tu
, signature
;
2167 if (!extract_cu_value (bytes
, &offset
)
2168 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2170 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2173 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2174 struct signatured_type
);
2175 sig_type
->signature
= signature
;
2176 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2177 sig_type
->per_cu
.is_debug_types
= 1;
2178 sig_type
->per_cu
.info_or_types_section
= section
;
2179 sig_type
->per_cu
.offset
.sect_off
= offset
;
2180 sig_type
->per_cu
.objfile
= objfile
;
2181 sig_type
->per_cu
.v
.quick
2182 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2183 struct dwarf2_per_cu_quick_data
);
2185 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2188 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2191 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2196 /* Read the address map data from the mapped index, and use it to
2197 populate the objfile's psymtabs_addrmap. */
2200 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2202 const gdb_byte
*iter
, *end
;
2203 struct obstack temp_obstack
;
2204 struct addrmap
*mutable_map
;
2205 struct cleanup
*cleanup
;
2208 obstack_init (&temp_obstack
);
2209 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2210 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2212 iter
= index
->address_table
;
2213 end
= iter
+ index
->address_table_size
;
2215 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2219 ULONGEST hi
, lo
, cu_index
;
2220 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2222 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2224 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2227 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2228 dw2_get_cu (cu_index
));
2231 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2232 &objfile
->objfile_obstack
);
2233 do_cleanups (cleanup
);
2236 /* The hash function for strings in the mapped index. This is the same as
2237 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2238 implementation. This is necessary because the hash function is tied to the
2239 format of the mapped index file. The hash values do not have to match with
2242 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2245 mapped_index_string_hash (int index_version
, const void *p
)
2247 const unsigned char *str
= (const unsigned char *) p
;
2251 while ((c
= *str
++) != 0)
2253 if (index_version
>= 5)
2255 r
= r
* 67 + c
- 113;
2261 /* Find a slot in the mapped index INDEX for the object named NAME.
2262 If NAME is found, set *VEC_OUT to point to the CU vector in the
2263 constant pool and return 1. If NAME cannot be found, return 0. */
2266 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2267 offset_type
**vec_out
)
2269 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2271 offset_type slot
, step
;
2272 int (*cmp
) (const char *, const char *);
2274 if (current_language
->la_language
== language_cplus
2275 || current_language
->la_language
== language_java
2276 || current_language
->la_language
== language_fortran
)
2278 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2280 const char *paren
= strchr (name
, '(');
2286 dup
= xmalloc (paren
- name
+ 1);
2287 memcpy (dup
, name
, paren
- name
);
2288 dup
[paren
- name
] = 0;
2290 make_cleanup (xfree
, dup
);
2295 /* Index version 4 did not support case insensitive searches. But the
2296 indices for case insensitive languages are built in lowercase, therefore
2297 simulate our NAME being searched is also lowercased. */
2298 hash
= mapped_index_string_hash ((index
->version
== 4
2299 && case_sensitivity
== case_sensitive_off
2300 ? 5 : index
->version
),
2303 slot
= hash
& (index
->symbol_table_slots
- 1);
2304 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2305 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2309 /* Convert a slot number to an offset into the table. */
2310 offset_type i
= 2 * slot
;
2312 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2314 do_cleanups (back_to
);
2318 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2319 if (!cmp (name
, str
))
2321 *vec_out
= (offset_type
*) (index
->constant_pool
2322 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2323 do_cleanups (back_to
);
2327 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2331 /* Read the index file. If everything went ok, initialize the "quick"
2332 elements of all the CUs and return 1. Otherwise, return 0. */
2335 dwarf2_read_index (struct objfile
*objfile
)
2338 struct mapped_index
*map
;
2339 offset_type
*metadata
;
2340 const gdb_byte
*cu_list
;
2341 const gdb_byte
*types_list
= NULL
;
2342 offset_type version
, cu_list_elements
;
2343 offset_type types_list_elements
= 0;
2346 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2349 /* Older elfutils strip versions could keep the section in the main
2350 executable while splitting it for the separate debug info file. */
2351 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2352 & SEC_HAS_CONTENTS
) == 0)
2355 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2357 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2358 /* Version check. */
2359 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2360 /* Versions earlier than 3 emitted every copy of a psymbol. This
2361 causes the index to behave very poorly for certain requests. Version 3
2362 contained incomplete addrmap. So, it seems better to just ignore such
2366 static int warning_printed
= 0;
2367 if (!warning_printed
)
2369 warning (_("Skipping obsolete .gdb_index section in %s."),
2371 warning_printed
= 1;
2375 /* Index version 4 uses a different hash function than index version
2378 Versions earlier than 6 did not emit psymbols for inlined
2379 functions. Using these files will cause GDB not to be able to
2380 set breakpoints on inlined functions by name, so we ignore these
2381 indices unless the --use-deprecated-index-sections command line
2382 option was supplied. */
2383 if (version
< 6 && !use_deprecated_index_sections
)
2385 static int warning_printed
= 0;
2386 if (!warning_printed
)
2388 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2389 "--use-deprecated-index-sections to use them anyway"),
2391 warning_printed
= 1;
2395 /* Indexes with higher version than the one supported by GDB may be no
2396 longer backward compatible. */
2400 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2401 map
->version
= version
;
2402 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2404 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2407 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2408 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2412 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2413 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2414 - MAYBE_SWAP (metadata
[i
]))
2418 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2419 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2420 - MAYBE_SWAP (metadata
[i
]));
2423 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2424 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2425 - MAYBE_SWAP (metadata
[i
]))
2426 / (2 * sizeof (offset_type
)));
2429 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2431 /* Don't use the index if it's empty. */
2432 if (map
->symbol_table_slots
== 0)
2435 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2438 if (types_list_elements
)
2440 struct dwarf2_section_info
*section
;
2442 /* We can only handle a single .debug_types when we have an
2444 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2447 section
= VEC_index (dwarf2_section_info_def
,
2448 dwarf2_per_objfile
->types
, 0);
2450 if (!create_signatured_type_table_from_index (objfile
, section
,
2452 types_list_elements
))
2456 create_addrmap_from_index (objfile
, map
);
2458 dwarf2_per_objfile
->index_table
= map
;
2459 dwarf2_per_objfile
->using_index
= 1;
2460 dwarf2_per_objfile
->quick_file_names_table
=
2461 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2466 /* A helper for the "quick" functions which sets the global
2467 dwarf2_per_objfile according to OBJFILE. */
2470 dw2_setup (struct objfile
*objfile
)
2472 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2473 gdb_assert (dwarf2_per_objfile
);
2476 /* die_reader_func for dw2_get_file_names. */
2479 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2481 struct die_info
*comp_unit_die
,
2485 struct dwarf2_cu
*cu
= reader
->cu
;
2486 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2487 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2488 struct line_header
*lh
;
2489 struct attribute
*attr
;
2491 char *name
, *comp_dir
;
2493 struct quick_file_names
*qfn
;
2494 unsigned int line_offset
;
2496 /* Our callers never want to match partial units -- instead they
2497 will match the enclosing full CU. */
2498 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2500 this_cu
->v
.quick
->no_file_data
= 1;
2508 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2511 struct quick_file_names find_entry
;
2513 line_offset
= DW_UNSND (attr
);
2515 /* We may have already read in this line header (TU line header sharing).
2516 If we have we're done. */
2517 find_entry
.offset
= line_offset
;
2518 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2519 &find_entry
, INSERT
);
2522 this_cu
->v
.quick
->file_names
= *slot
;
2526 lh
= dwarf_decode_line_header (line_offset
, cu
);
2530 this_cu
->v
.quick
->no_file_data
= 1;
2534 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2535 qfn
->offset
= line_offset
;
2536 gdb_assert (slot
!= NULL
);
2539 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2541 qfn
->num_file_names
= lh
->num_file_names
;
2542 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2543 lh
->num_file_names
* sizeof (char *));
2544 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2545 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2546 qfn
->real_names
= NULL
;
2548 free_line_header (lh
);
2550 this_cu
->v
.quick
->file_names
= qfn
;
2553 /* A helper for the "quick" functions which attempts to read the line
2554 table for THIS_CU. */
2556 static struct quick_file_names
*
2557 dw2_get_file_names (struct objfile
*objfile
,
2558 struct dwarf2_per_cu_data
*this_cu
)
2560 if (this_cu
->v
.quick
->file_names
!= NULL
)
2561 return this_cu
->v
.quick
->file_names
;
2562 /* If we know there is no line data, no point in looking again. */
2563 if (this_cu
->v
.quick
->no_file_data
)
2566 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2567 in the stub for CUs, there's is no need to lookup the DWO file.
2568 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2570 if (this_cu
->is_debug_types
)
2571 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2573 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2575 if (this_cu
->v
.quick
->no_file_data
)
2577 return this_cu
->v
.quick
->file_names
;
2580 /* A helper for the "quick" functions which computes and caches the
2581 real path for a given file name from the line table. */
2584 dw2_get_real_path (struct objfile
*objfile
,
2585 struct quick_file_names
*qfn
, int index
)
2587 if (qfn
->real_names
== NULL
)
2588 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2589 qfn
->num_file_names
, sizeof (char *));
2591 if (qfn
->real_names
[index
] == NULL
)
2592 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2594 return qfn
->real_names
[index
];
2597 static struct symtab
*
2598 dw2_find_last_source_symtab (struct objfile
*objfile
)
2602 dw2_setup (objfile
);
2603 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2604 return dw2_instantiate_symtab (dw2_get_cu (index
));
2607 /* Traversal function for dw2_forget_cached_source_info. */
2610 dw2_free_cached_file_names (void **slot
, void *info
)
2612 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2614 if (file_data
->real_names
)
2618 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2620 xfree ((void*) file_data
->real_names
[i
]);
2621 file_data
->real_names
[i
] = NULL
;
2629 dw2_forget_cached_source_info (struct objfile
*objfile
)
2631 dw2_setup (objfile
);
2633 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2634 dw2_free_cached_file_names
, NULL
);
2637 /* Helper function for dw2_map_symtabs_matching_filename that expands
2638 the symtabs and calls the iterator. */
2641 dw2_map_expand_apply (struct objfile
*objfile
,
2642 struct dwarf2_per_cu_data
*per_cu
,
2644 const char *full_path
, const char *real_path
,
2645 int (*callback
) (struct symtab
*, void *),
2648 struct symtab
*last_made
= objfile
->symtabs
;
2650 /* Don't visit already-expanded CUs. */
2651 if (per_cu
->v
.quick
->symtab
)
2654 /* This may expand more than one symtab, and we want to iterate over
2656 dw2_instantiate_symtab (per_cu
);
2658 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2659 objfile
->symtabs
, last_made
);
2662 /* Implementation of the map_symtabs_matching_filename method. */
2665 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2666 const char *full_path
, const char *real_path
,
2667 int (*callback
) (struct symtab
*, void *),
2671 const char *name_basename
= lbasename (name
);
2672 int name_len
= strlen (name
);
2673 int is_abs
= IS_ABSOLUTE_PATH (name
);
2675 dw2_setup (objfile
);
2677 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2678 + dwarf2_per_objfile
->n_type_units
); ++i
)
2681 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2682 struct quick_file_names
*file_data
;
2684 /* We only need to look at symtabs not already expanded. */
2685 if (per_cu
->v
.quick
->symtab
)
2688 file_data
= dw2_get_file_names (objfile
, per_cu
);
2689 if (file_data
== NULL
)
2692 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2694 const char *this_name
= file_data
->file_names
[j
];
2696 if (FILENAME_CMP (name
, this_name
) == 0
2697 || (!is_abs
&& compare_filenames_for_search (this_name
,
2700 if (dw2_map_expand_apply (objfile
, per_cu
,
2701 name
, full_path
, real_path
,
2706 /* Before we invoke realpath, which can get expensive when many
2707 files are involved, do a quick comparison of the basenames. */
2708 if (! basenames_may_differ
2709 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2712 if (full_path
!= NULL
)
2714 const char *this_real_name
= dw2_get_real_path (objfile
,
2717 if (this_real_name
!= NULL
2718 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2720 && compare_filenames_for_search (this_real_name
,
2723 if (dw2_map_expand_apply (objfile
, per_cu
,
2724 name
, full_path
, real_path
,
2730 if (real_path
!= NULL
)
2732 const char *this_real_name
= dw2_get_real_path (objfile
,
2735 if (this_real_name
!= NULL
2736 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2738 && compare_filenames_for_search (this_real_name
,
2741 if (dw2_map_expand_apply (objfile
, per_cu
,
2742 name
, full_path
, real_path
,
2753 static struct symtab
*
2754 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2755 const char *name
, domain_enum domain
)
2757 /* We do all the work in the pre_expand_symtabs_matching hook
2762 /* A helper function that expands all symtabs that hold an object
2763 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2764 symbols in block BLOCK_KIND. */
2767 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2768 int want_specific_block
,
2769 enum block_enum block_kind
,
2770 const char *name
, domain_enum domain
)
2772 struct mapped_index
*index
;
2774 dw2_setup (objfile
);
2776 index
= dwarf2_per_objfile
->index_table
;
2778 /* index_table is NULL if OBJF_READNOW. */
2783 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2785 offset_type i
, len
= MAYBE_SWAP (*vec
);
2786 for (i
= 0; i
< len
; ++i
)
2788 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2789 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2790 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2791 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2792 /* This value is only valid for index versions >= 7. */
2793 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2794 gdb_index_symbol_kind symbol_kind
=
2795 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2797 if (want_specific_block
2798 && index
->version
>= 7
2799 && want_static
!= is_static
)
2802 /* Only check the symbol's kind if it has one.
2803 Indices prior to version 7 don't record it. */
2804 if (index
->version
>= 7)
2809 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2810 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2811 /* Some types are also in VAR_DOMAIN. */
2812 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2816 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2820 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
2828 dw2_instantiate_symtab (per_cu
);
2835 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2836 enum block_enum block_kind
, const char *name
,
2839 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
2843 dw2_print_stats (struct objfile
*objfile
)
2847 dw2_setup (objfile
);
2849 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2850 + dwarf2_per_objfile
->n_type_units
); ++i
)
2852 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2854 if (!per_cu
->v
.quick
->symtab
)
2857 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2861 dw2_dump (struct objfile
*objfile
)
2863 /* Nothing worth printing. */
2867 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2868 struct section_offsets
*delta
)
2870 /* There's nothing to relocate here. */
2874 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2875 const char *func_name
)
2877 /* Note: It doesn't matter what we pass for block_kind here. */
2878 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
2883 dw2_expand_all_symtabs (struct objfile
*objfile
)
2887 dw2_setup (objfile
);
2889 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2890 + dwarf2_per_objfile
->n_type_units
); ++i
)
2892 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2894 dw2_instantiate_symtab (per_cu
);
2899 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2900 const char *filename
)
2904 dw2_setup (objfile
);
2906 /* We don't need to consider type units here.
2907 This is only called for examining code, e.g. expand_line_sal.
2908 There can be an order of magnitude (or more) more type units
2909 than comp units, and we avoid them if we can. */
2911 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2914 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2915 struct quick_file_names
*file_data
;
2917 /* We only need to look at symtabs not already expanded. */
2918 if (per_cu
->v
.quick
->symtab
)
2921 file_data
= dw2_get_file_names (objfile
, per_cu
);
2922 if (file_data
== NULL
)
2925 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2927 const char *this_name
= file_data
->file_names
[j
];
2928 if (FILENAME_CMP (this_name
, filename
) == 0)
2930 dw2_instantiate_symtab (per_cu
);
2937 /* A helper function for dw2_find_symbol_file that finds the primary
2938 file name for a given CU. This is a die_reader_func. */
2941 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
2943 struct die_info
*comp_unit_die
,
2947 const char **result_ptr
= data
;
2948 struct dwarf2_cu
*cu
= reader
->cu
;
2949 struct attribute
*attr
;
2951 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
2955 *result_ptr
= DW_STRING (attr
);
2959 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2961 struct dwarf2_per_cu_data
*per_cu
;
2963 struct quick_file_names
*file_data
;
2964 const char *filename
;
2966 dw2_setup (objfile
);
2968 /* index_table is NULL if OBJF_READNOW. */
2969 if (!dwarf2_per_objfile
->index_table
)
2973 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
2975 struct blockvector
*bv
= BLOCKVECTOR (s
);
2976 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2977 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2980 return sym
->symtab
->filename
;
2985 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2989 /* Note that this just looks at the very first one named NAME -- but
2990 actually we are looking for a function. find_main_filename
2991 should be rewritten so that it doesn't require a custom hook. It
2992 could just use the ordinary symbol tables. */
2993 /* vec[0] is the length, which must always be >0. */
2994 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
2996 if (per_cu
->v
.quick
->symtab
!= NULL
)
2997 return per_cu
->v
.quick
->symtab
->filename
;
2999 init_cutu_and_read_dies (per_cu
, 0, 0, dw2_get_primary_filename_reader
,
3006 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3007 struct objfile
*objfile
, int global
,
3008 int (*callback
) (struct block
*,
3009 struct symbol
*, void *),
3010 void *data
, symbol_compare_ftype
*match
,
3011 symbol_compare_ftype
*ordered_compare
)
3013 /* Currently unimplemented; used for Ada. The function can be called if the
3014 current language is Ada for a non-Ada objfile using GNU index. As Ada
3015 does not look for non-Ada symbols this function should just return. */
3019 dw2_expand_symtabs_matching
3020 (struct objfile
*objfile
,
3021 int (*file_matcher
) (const char *, void *),
3022 int (*name_matcher
) (const char *, void *),
3023 enum search_domain kind
,
3028 struct mapped_index
*index
;
3030 dw2_setup (objfile
);
3032 /* index_table is NULL if OBJF_READNOW. */
3033 if (!dwarf2_per_objfile
->index_table
)
3035 index
= dwarf2_per_objfile
->index_table
;
3037 if (file_matcher
!= NULL
)
3039 struct cleanup
*cleanup
;
3040 htab_t visited_found
, visited_not_found
;
3042 visited_found
= htab_create_alloc (10,
3043 htab_hash_pointer
, htab_eq_pointer
,
3044 NULL
, xcalloc
, xfree
);
3045 cleanup
= make_cleanup_htab_delete (visited_found
);
3046 visited_not_found
= htab_create_alloc (10,
3047 htab_hash_pointer
, htab_eq_pointer
,
3048 NULL
, xcalloc
, xfree
);
3049 make_cleanup_htab_delete (visited_not_found
);
3051 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3052 + dwarf2_per_objfile
->n_type_units
); ++i
)
3055 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3056 struct quick_file_names
*file_data
;
3059 per_cu
->v
.quick
->mark
= 0;
3061 /* We only need to look at symtabs not already expanded. */
3062 if (per_cu
->v
.quick
->symtab
)
3065 file_data
= dw2_get_file_names (objfile
, per_cu
);
3066 if (file_data
== NULL
)
3069 if (htab_find (visited_not_found
, file_data
) != NULL
)
3071 else if (htab_find (visited_found
, file_data
) != NULL
)
3073 per_cu
->v
.quick
->mark
= 1;
3077 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3079 if (file_matcher (file_data
->file_names
[j
], data
))
3081 per_cu
->v
.quick
->mark
= 1;
3086 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3088 : visited_not_found
,
3093 do_cleanups (cleanup
);
3096 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3098 offset_type idx
= 2 * iter
;
3100 offset_type
*vec
, vec_len
, vec_idx
;
3102 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3105 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3107 if (! (*name_matcher
) (name
, data
))
3110 /* The name was matched, now expand corresponding CUs that were
3112 vec
= (offset_type
*) (index
->constant_pool
3113 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3114 vec_len
= MAYBE_SWAP (vec
[0]);
3115 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3117 struct dwarf2_per_cu_data
*per_cu
;
3118 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3119 gdb_index_symbol_kind symbol_kind
=
3120 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3121 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3123 /* Don't crash on bad data. */
3124 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3125 + dwarf2_per_objfile
->n_comp_units
))
3128 /* Only check the symbol's kind if it has one.
3129 Indices prior to version 7 don't record it. */
3130 if (index
->version
>= 7)
3134 case VARIABLES_DOMAIN
:
3135 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3138 case FUNCTIONS_DOMAIN
:
3139 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3143 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3151 per_cu
= dw2_get_cu (cu_index
);
3152 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3153 dw2_instantiate_symtab (per_cu
);
3158 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3161 static struct symtab
*
3162 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3166 if (BLOCKVECTOR (symtab
) != NULL
3167 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3170 if (symtab
->includes
== NULL
)
3173 for (i
= 0; symtab
->includes
[i
]; ++i
)
3175 struct symtab
*s
= symtab
->includes
[i
];
3177 s
= recursively_find_pc_sect_symtab (s
, pc
);
3185 static struct symtab
*
3186 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3187 struct minimal_symbol
*msymbol
,
3189 struct obj_section
*section
,
3192 struct dwarf2_per_cu_data
*data
;
3193 struct symtab
*result
;
3195 dw2_setup (objfile
);
3197 if (!objfile
->psymtabs_addrmap
)
3200 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3204 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3205 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3206 paddress (get_objfile_arch (objfile
), pc
));
3208 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3209 gdb_assert (result
!= NULL
);
3214 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3215 void *data
, int need_fullname
)
3218 struct cleanup
*cleanup
;
3219 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3220 NULL
, xcalloc
, xfree
);
3222 cleanup
= make_cleanup_htab_delete (visited
);
3223 dw2_setup (objfile
);
3225 /* We can ignore file names coming from already-expanded CUs. */
3226 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3227 + dwarf2_per_objfile
->n_type_units
); ++i
)
3229 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3231 if (per_cu
->v
.quick
->symtab
)
3233 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3236 *slot
= per_cu
->v
.quick
->file_names
;
3240 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3241 + dwarf2_per_objfile
->n_type_units
); ++i
)
3244 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3245 struct quick_file_names
*file_data
;
3248 /* We only need to look at symtabs not already expanded. */
3249 if (per_cu
->v
.quick
->symtab
)
3252 file_data
= dw2_get_file_names (objfile
, per_cu
);
3253 if (file_data
== NULL
)
3256 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3259 /* Already visited. */
3264 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3266 const char *this_real_name
;
3269 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3271 this_real_name
= NULL
;
3272 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3276 do_cleanups (cleanup
);
3280 dw2_has_symbols (struct objfile
*objfile
)
3285 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3288 dw2_find_last_source_symtab
,
3289 dw2_forget_cached_source_info
,
3290 dw2_map_symtabs_matching_filename
,
3292 dw2_pre_expand_symtabs_matching
,
3296 dw2_expand_symtabs_for_function
,
3297 dw2_expand_all_symtabs
,
3298 dw2_expand_symtabs_with_filename
,
3299 dw2_find_symbol_file
,
3300 dw2_map_matching_symbols
,
3301 dw2_expand_symtabs_matching
,
3302 dw2_find_pc_sect_symtab
,
3303 dw2_map_symbol_filenames
3306 /* Initialize for reading DWARF for this objfile. Return 0 if this
3307 file will use psymtabs, or 1 if using the GNU index. */
3310 dwarf2_initialize_objfile (struct objfile
*objfile
)
3312 /* If we're about to read full symbols, don't bother with the
3313 indices. In this case we also don't care if some other debug
3314 format is making psymtabs, because they are all about to be
3316 if ((objfile
->flags
& OBJF_READNOW
))
3320 dwarf2_per_objfile
->using_index
= 1;
3321 create_all_comp_units (objfile
);
3322 create_all_type_units (objfile
);
3323 dwarf2_per_objfile
->quick_file_names_table
=
3324 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3326 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3327 + dwarf2_per_objfile
->n_type_units
); ++i
)
3329 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3331 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3332 struct dwarf2_per_cu_quick_data
);
3335 /* Return 1 so that gdb sees the "quick" functions. However,
3336 these functions will be no-ops because we will have expanded
3341 if (dwarf2_read_index (objfile
))
3349 /* Build a partial symbol table. */
3352 dwarf2_build_psymtabs (struct objfile
*objfile
)
3354 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3356 init_psymbol_list (objfile
, 1024);
3359 dwarf2_build_psymtabs_hard (objfile
);
3362 /* Return TRUE if OFFSET is within CU_HEADER. */
3365 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3367 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3368 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3369 + cu_header
->initial_length_size
) };
3371 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3374 /* Find the base address of the compilation unit for range lists and
3375 location lists. It will normally be specified by DW_AT_low_pc.
3376 In DWARF-3 draft 4, the base address could be overridden by
3377 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3378 compilation units with discontinuous ranges. */
3381 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3383 struct attribute
*attr
;
3386 cu
->base_address
= 0;
3388 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3391 cu
->base_address
= DW_ADDR (attr
);
3396 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3399 cu
->base_address
= DW_ADDR (attr
);
3405 /* Read in the comp unit header information from the debug_info at info_ptr.
3406 NOTE: This leaves members offset, first_die_offset to be filled in
3410 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3411 gdb_byte
*info_ptr
, bfd
*abfd
)
3414 unsigned int bytes_read
;
3416 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3417 cu_header
->initial_length_size
= bytes_read
;
3418 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3419 info_ptr
+= bytes_read
;
3420 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3422 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3424 info_ptr
+= bytes_read
;
3425 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3427 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3428 if (signed_addr
< 0)
3429 internal_error (__FILE__
, __LINE__
,
3430 _("read_comp_unit_head: dwarf from non elf file"));
3431 cu_header
->signed_addr_p
= signed_addr
;
3436 /* Subroutine of read_and_check_comp_unit_head and
3437 read_and_check_type_unit_head to simplify them.
3438 Perform various error checking on the header. */
3441 error_check_comp_unit_head (struct comp_unit_head
*header
,
3442 struct dwarf2_section_info
*section
,
3443 struct dwarf2_section_info
*abbrev_section
)
3445 bfd
*abfd
= section
->asection
->owner
;
3446 const char *filename
= bfd_get_filename (abfd
);
3448 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3449 error (_("Dwarf Error: wrong version in compilation unit header "
3450 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3453 if (header
->abbrev_offset
.sect_off
3454 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3455 &dwarf2_per_objfile
->abbrev
))
3456 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3457 "(offset 0x%lx + 6) [in module %s]"),
3458 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3461 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3462 avoid potential 32-bit overflow. */
3463 if (((unsigned long) header
->offset
.sect_off
3464 + header
->length
+ header
->initial_length_size
)
3466 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3467 "(offset 0x%lx + 0) [in module %s]"),
3468 (long) header
->length
, (long) header
->offset
.sect_off
,
3472 /* Read in a CU/TU header and perform some basic error checking.
3473 The contents of the header are stored in HEADER.
3474 The result is a pointer to the start of the first DIE. */
3477 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3478 struct dwarf2_section_info
*section
,
3479 struct dwarf2_section_info
*abbrev_section
,
3481 int is_debug_types_section
)
3483 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3484 bfd
*abfd
= section
->asection
->owner
;
3486 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3488 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3490 /* If we're reading a type unit, skip over the signature and
3491 type_offset fields. */
3492 if (is_debug_types_section
)
3493 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3495 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3497 error_check_comp_unit_head (header
, section
, abbrev_section
);
3502 /* Read in the types comp unit header information from .debug_types entry at
3503 types_ptr. The result is a pointer to one past the end of the header. */
3506 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3507 struct dwarf2_section_info
*section
,
3508 struct dwarf2_section_info
*abbrev_section
,
3510 ULONGEST
*signature
,
3511 cu_offset
*type_offset_in_tu
)
3513 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3514 bfd
*abfd
= section
->asection
->owner
;
3516 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3518 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3520 /* If we're reading a type unit, skip over the signature and
3521 type_offset fields. */
3522 if (signature
!= NULL
)
3523 *signature
= read_8_bytes (abfd
, info_ptr
);
3525 if (type_offset_in_tu
!= NULL
)
3526 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3527 header
->offset_size
);
3528 info_ptr
+= header
->offset_size
;
3530 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3532 error_check_comp_unit_head (header
, section
, abbrev_section
);
3537 /* Allocate a new partial symtab for file named NAME and mark this new
3538 partial symtab as being an include of PST. */
3541 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3542 struct objfile
*objfile
)
3544 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3546 subpst
->section_offsets
= pst
->section_offsets
;
3547 subpst
->textlow
= 0;
3548 subpst
->texthigh
= 0;
3550 subpst
->dependencies
= (struct partial_symtab
**)
3551 obstack_alloc (&objfile
->objfile_obstack
,
3552 sizeof (struct partial_symtab
*));
3553 subpst
->dependencies
[0] = pst
;
3554 subpst
->number_of_dependencies
= 1;
3556 subpst
->globals_offset
= 0;
3557 subpst
->n_global_syms
= 0;
3558 subpst
->statics_offset
= 0;
3559 subpst
->n_static_syms
= 0;
3560 subpst
->symtab
= NULL
;
3561 subpst
->read_symtab
= pst
->read_symtab
;
3564 /* No private part is necessary for include psymtabs. This property
3565 can be used to differentiate between such include psymtabs and
3566 the regular ones. */
3567 subpst
->read_symtab_private
= NULL
;
3570 /* Read the Line Number Program data and extract the list of files
3571 included by the source file represented by PST. Build an include
3572 partial symtab for each of these included files. */
3575 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3576 struct die_info
*die
,
3577 struct partial_symtab
*pst
)
3579 struct line_header
*lh
= NULL
;
3580 struct attribute
*attr
;
3582 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3584 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3586 return; /* No linetable, so no includes. */
3588 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3589 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3591 free_line_header (lh
);
3595 hash_signatured_type (const void *item
)
3597 const struct signatured_type
*sig_type
= item
;
3599 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3600 return sig_type
->signature
;
3604 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3606 const struct signatured_type
*lhs
= item_lhs
;
3607 const struct signatured_type
*rhs
= item_rhs
;
3609 return lhs
->signature
== rhs
->signature
;
3612 /* Allocate a hash table for signatured types. */
3615 allocate_signatured_type_table (struct objfile
*objfile
)
3617 return htab_create_alloc_ex (41,
3618 hash_signatured_type
,
3621 &objfile
->objfile_obstack
,
3622 hashtab_obstack_allocate
,
3623 dummy_obstack_deallocate
);
3626 /* A helper function to add a signatured type CU to a table. */
3629 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3631 struct signatured_type
*sigt
= *slot
;
3632 struct dwarf2_per_cu_data
***datap
= datum
;
3634 **datap
= &sigt
->per_cu
;
3640 /* Create the hash table of all entries in the .debug_types section.
3641 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3642 The result is a pointer to the hash table or NULL if there are
3646 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3647 VEC (dwarf2_section_info_def
) *types
)
3649 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3650 htab_t types_htab
= NULL
;
3652 struct dwarf2_section_info
*section
;
3653 struct dwarf2_section_info
*abbrev_section
;
3655 if (VEC_empty (dwarf2_section_info_def
, types
))
3658 abbrev_section
= (dwo_file
!= NULL
3659 ? &dwo_file
->sections
.abbrev
3660 : &dwarf2_per_objfile
->abbrev
);
3663 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3667 gdb_byte
*info_ptr
, *end_ptr
;
3669 dwarf2_read_section (objfile
, section
);
3670 info_ptr
= section
->buffer
;
3672 if (info_ptr
== NULL
)
3675 /* We can't set abfd until now because the section may be empty or
3676 not present, in which case section->asection will be NULL. */
3677 abfd
= section
->asection
->owner
;
3679 if (types_htab
== NULL
)
3682 types_htab
= allocate_dwo_unit_table (objfile
);
3684 types_htab
= allocate_signatured_type_table (objfile
);
3687 if (dwarf2_die_debug
)
3688 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3689 bfd_get_filename (abfd
));
3691 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3692 because we don't need to read any dies: the signature is in the
3695 end_ptr
= info_ptr
+ section
->size
;
3696 while (info_ptr
< end_ptr
)
3699 cu_offset type_offset_in_tu
;
3701 struct signatured_type
*sig_type
;
3702 struct dwo_unit
*dwo_tu
;
3704 gdb_byte
*ptr
= info_ptr
;
3705 struct comp_unit_head header
;
3706 unsigned int length
;
3708 offset
.sect_off
= ptr
- section
->buffer
;
3710 /* We need to read the type's signature in order to build the hash
3711 table, but we don't need anything else just yet. */
3713 ptr
= read_and_check_type_unit_head (&header
, section
,
3714 abbrev_section
, ptr
,
3715 &signature
, &type_offset_in_tu
);
3717 length
= header
.initial_length_size
+ header
.length
;
3719 /* Skip dummy type units. */
3720 if (ptr
>= info_ptr
+ length
3721 || peek_abbrev_code (abfd
, ptr
) == 0)
3723 info_ptr
+= header
.initial_length_size
+ header
.length
;
3730 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3732 dwo_tu
->dwo_file
= dwo_file
;
3733 dwo_tu
->signature
= signature
;
3734 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3735 dwo_tu
->info_or_types_section
= section
;
3736 dwo_tu
->offset
= offset
;
3737 dwo_tu
->length
= length
;
3741 /* N.B.: type_offset is not usable if this type uses a DWO file.
3742 The real type_offset is in the DWO file. */
3744 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3745 struct signatured_type
);
3746 sig_type
->signature
= signature
;
3747 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3748 sig_type
->per_cu
.objfile
= objfile
;
3749 sig_type
->per_cu
.is_debug_types
= 1;
3750 sig_type
->per_cu
.info_or_types_section
= section
;
3751 sig_type
->per_cu
.offset
= offset
;
3752 sig_type
->per_cu
.length
= length
;
3755 slot
= htab_find_slot (types_htab
,
3756 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3758 gdb_assert (slot
!= NULL
);
3761 sect_offset dup_offset
;
3765 const struct dwo_unit
*dup_tu
= *slot
;
3767 dup_offset
= dup_tu
->offset
;
3771 const struct signatured_type
*dup_tu
= *slot
;
3773 dup_offset
= dup_tu
->per_cu
.offset
;
3776 complaint (&symfile_complaints
,
3777 _("debug type entry at offset 0x%x is duplicate to the "
3778 "entry at offset 0x%x, signature 0x%s"),
3779 offset
.sect_off
, dup_offset
.sect_off
,
3780 phex (signature
, sizeof (signature
)));
3782 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3784 if (dwarf2_die_debug
)
3785 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3787 phex (signature
, sizeof (signature
)));
3796 /* Create the hash table of all entries in the .debug_types section,
3797 and initialize all_type_units.
3798 The result is zero if there is an error (e.g. missing .debug_types section),
3799 otherwise non-zero. */
3802 create_all_type_units (struct objfile
*objfile
)
3805 struct dwarf2_per_cu_data
**iter
;
3807 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3808 if (types_htab
== NULL
)
3810 dwarf2_per_objfile
->signatured_types
= NULL
;
3814 dwarf2_per_objfile
->signatured_types
= types_htab
;
3816 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3817 dwarf2_per_objfile
->all_type_units
3818 = obstack_alloc (&objfile
->objfile_obstack
,
3819 dwarf2_per_objfile
->n_type_units
3820 * sizeof (struct dwarf2_per_cu_data
*));
3821 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3822 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3823 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3824 == dwarf2_per_objfile
->n_type_units
);
3829 /* Lookup a signature based type for DW_FORM_ref_sig8.
3830 Returns NULL if signature SIG is not present in the table. */
3832 static struct signatured_type
*
3833 lookup_signatured_type (ULONGEST sig
)
3835 struct signatured_type find_entry
, *entry
;
3837 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3839 complaint (&symfile_complaints
,
3840 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3844 find_entry
.signature
= sig
;
3845 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3849 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3852 init_cu_die_reader (struct die_reader_specs
*reader
,
3853 struct dwarf2_cu
*cu
,
3854 struct dwarf2_section_info
*section
,
3855 struct dwo_file
*dwo_file
)
3857 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3858 reader
->abfd
= section
->asection
->owner
;
3860 reader
->dwo_file
= dwo_file
;
3861 reader
->die_section
= section
;
3862 reader
->buffer
= section
->buffer
;
3863 reader
->buffer_end
= section
->buffer
+ section
->size
;
3866 /* Initialize a CU (or TU) and read its DIEs.
3867 If the CU defers to a DWO file, read the DWO file as well.
3869 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3870 Otherwise, a new CU is allocated with xmalloc.
3872 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3873 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3875 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3876 linker) then DIE_READER_FUNC will not get called. */
3879 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3880 int use_existing_cu
, int keep
,
3881 die_reader_func_ftype
*die_reader_func
,
3884 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3885 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3886 bfd
*abfd
= section
->asection
->owner
;
3887 struct dwarf2_cu
*cu
;
3888 gdb_byte
*begin_info_ptr
, *info_ptr
;
3889 struct die_reader_specs reader
;
3890 struct die_info
*comp_unit_die
;
3892 struct attribute
*attr
;
3893 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3894 struct signatured_type
*sig_type
= NULL
;
3895 struct dwarf2_section_info
*abbrev_section
;
3897 if (use_existing_cu
)
3900 cleanups
= make_cleanup (null_cleanup
, NULL
);
3902 /* This is cheap if the section is already read in. */
3903 dwarf2_read_section (objfile
, section
);
3905 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3906 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
3908 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3911 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3915 /* If !use_existing_cu, this_cu->cu must be NULL. */
3916 gdb_assert (this_cu
->cu
== NULL
);
3918 cu
= xmalloc (sizeof (*cu
));
3919 init_one_comp_unit (cu
, this_cu
);
3921 /* If an error occurs while loading, release our storage. */
3922 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3924 if (this_cu
->is_debug_types
)
3928 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
3929 abbrev_section
, info_ptr
,
3932 /* There's no way to get from PER_CU to its containing
3933 struct signatured_type.
3934 But we have the signature so we can use that. */
3935 sig_type
= lookup_signatured_type (signature
);
3936 /* We've already scanned all the signatured types,
3937 this must succeed. */
3938 gdb_assert (sig_type
!= NULL
);
3939 gdb_assert (&sig_type
->per_cu
== this_cu
);
3940 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3942 /* LENGTH has not been set yet for type units. */
3943 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3945 /* Establish the type offset that can be used to lookup the type. */
3946 sig_type
->type_offset_in_section
.sect_off
=
3947 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3951 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
3955 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3956 gdb_assert (this_cu
->length
3957 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3961 /* Skip dummy compilation units. */
3962 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3963 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3965 do_cleanups (cleanups
);
3969 /* If we don't have them yet, read the abbrevs for this compilation unit.
3970 And if we need to read them now, make sure they're freed when we're
3972 if (cu
->abbrev_table
== NULL
)
3974 dwarf2_read_abbrevs (cu
, abbrev_section
);
3975 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3978 /* Read the top level CU/TU die. */
3979 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3980 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3982 /* If we have a DWO stub, process it and then read in the DWO file.
3983 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3984 a DWO CU, that this test will fail. */
3985 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3988 char *dwo_name
= DW_STRING (attr
);
3989 const char *comp_dir
;
3990 struct dwo_unit
*dwo_unit
;
3991 ULONGEST signature
; /* Or dwo_id. */
3992 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3993 int i
,num_extra_attrs
;
3994 struct dwarf2_section_info
*dwo_abbrev_section
;
3997 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3998 " has children (offset 0x%x) [in module %s]"),
3999 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4001 /* These attributes aren't processed until later:
4002 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4003 However, the attribute is found in the stub which we won't have later.
4004 In order to not impose this complication on the rest of the code,
4005 we read them here and copy them to the DWO CU/TU die. */
4006 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
4008 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4010 if (! this_cu
->is_debug_types
)
4011 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4012 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4013 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4014 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4016 /* There should be a DW_AT_addr_base attribute here (if needed).
4017 We need the value before we can process DW_FORM_GNU_addr_index. */
4019 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4021 cu
->addr_base
= DW_UNSND (attr
);
4023 /* There should be a DW_AT_ranges_base attribute here (if needed).
4024 We need the value before we can process DW_AT_ranges. */
4025 cu
->ranges_base
= 0;
4026 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4028 cu
->ranges_base
= DW_UNSND (attr
);
4030 if (this_cu
->is_debug_types
)
4032 gdb_assert (sig_type
!= NULL
);
4033 signature
= sig_type
->signature
;
4037 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4039 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4041 signature
= DW_UNSND (attr
);
4044 /* We may need the comp_dir in order to find the DWO file. */
4046 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4048 comp_dir
= DW_STRING (attr
);
4050 if (this_cu
->is_debug_types
)
4051 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
4053 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
4056 if (dwo_unit
== NULL
)
4058 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4059 " with ID %s [in module %s]"),
4060 this_cu
->offset
.sect_off
,
4061 phex (signature
, sizeof (signature
)),
4065 /* Set up for reading the DWO CU/TU. */
4066 cu
->dwo_unit
= dwo_unit
;
4067 section
= dwo_unit
->info_or_types_section
;
4068 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4069 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4070 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4072 if (this_cu
->is_debug_types
)
4076 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4080 gdb_assert (sig_type
->signature
== signature
);
4081 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4082 gdb_assert (dwo_unit
->length
4083 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4085 /* Establish the type offset that can be used to lookup the type.
4086 For DWO files, we don't know it until now. */
4087 sig_type
->type_offset_in_section
.sect_off
=
4088 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4092 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4095 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4096 gdb_assert (dwo_unit
->length
4097 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4100 /* Discard the original CU's abbrev table, and read the DWO's. */
4101 dwarf2_free_abbrev_table (cu
);
4102 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4104 /* Read in the die, but leave space to copy over the attributes
4105 from the stub. This has the benefit of simplifying the rest of
4106 the code - all the real work is done here. */
4107 num_extra_attrs
= ((stmt_list
!= NULL
)
4110 + (ranges
!= NULL
));
4111 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4112 &has_children
, num_extra_attrs
);
4114 /* Copy over the attributes from the stub to the DWO die. */
4115 i
= comp_unit_die
->num_attrs
;
4116 if (stmt_list
!= NULL
)
4117 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4119 comp_unit_die
->attrs
[i
++] = *low_pc
;
4120 if (high_pc
!= NULL
)
4121 comp_unit_die
->attrs
[i
++] = *high_pc
;
4123 comp_unit_die
->attrs
[i
++] = *ranges
;
4124 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4126 /* Skip dummy compilation units. */
4127 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4128 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4130 do_cleanups (cleanups
);
4135 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4137 if (free_cu_cleanup
!= NULL
)
4141 /* We've successfully allocated this compilation unit. Let our
4142 caller clean it up when finished with it. */
4143 discard_cleanups (free_cu_cleanup
);
4145 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4146 So we have to manually free the abbrev table. */
4147 dwarf2_free_abbrev_table (cu
);
4149 /* Link this CU into read_in_chain. */
4150 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4151 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4154 do_cleanups (free_cu_cleanup
);
4157 do_cleanups (cleanups
);
4160 /* Read CU/TU THIS_CU in section SECTION,
4161 but do not follow DW_AT_GNU_dwo_name if present.
4162 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4163 have already done the lookup to find the DWO file).
4165 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4166 THIS_CU->is_debug_types, but nothing else.
4168 We fill in THIS_CU->length.
4170 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4171 linker) then DIE_READER_FUNC will not get called.
4173 THIS_CU->cu is always freed when done.
4174 This is done in order to not leave THIS_CU->cu in a state where we have
4175 to care whether it refers to the "main" CU or the DWO CU. */
4178 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4179 struct dwarf2_section_info
*abbrev_section
,
4180 struct dwo_file
*dwo_file
,
4181 die_reader_func_ftype
*die_reader_func
,
4184 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4185 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4186 bfd
*abfd
= section
->asection
->owner
;
4187 struct dwarf2_cu cu
;
4188 gdb_byte
*begin_info_ptr
, *info_ptr
;
4189 struct die_reader_specs reader
;
4190 struct cleanup
*cleanups
;
4191 struct die_info
*comp_unit_die
;
4194 gdb_assert (this_cu
->cu
== NULL
);
4196 /* This is cheap if the section is already read in. */
4197 dwarf2_read_section (objfile
, section
);
4199 init_one_comp_unit (&cu
, this_cu
);
4201 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4203 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4204 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4205 abbrev_section
, info_ptr
,
4206 this_cu
->is_debug_types
);
4208 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4210 /* Skip dummy compilation units. */
4211 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4212 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4214 do_cleanups (cleanups
);
4218 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4219 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4221 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4222 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4224 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4226 do_cleanups (cleanups
);
4229 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4230 does not lookup the specified DWO file.
4231 This cannot be used to read DWO files.
4233 THIS_CU->cu is always freed when done.
4234 This is done in order to not leave THIS_CU->cu in a state where we have
4235 to care whether it refers to the "main" CU or the DWO CU.
4236 We can revisit this if the data shows there's a performance issue. */
4239 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4240 die_reader_func_ftype
*die_reader_func
,
4243 init_cutu_and_read_dies_no_follow (this_cu
,
4244 &dwarf2_per_objfile
->abbrev
,
4246 die_reader_func
, data
);
4249 /* die_reader_func for process_psymtab_comp_unit. */
4252 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4254 struct die_info
*comp_unit_die
,
4258 struct dwarf2_cu
*cu
= reader
->cu
;
4259 struct objfile
*objfile
= cu
->objfile
;
4260 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4261 struct attribute
*attr
;
4263 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4264 struct partial_symtab
*pst
;
4266 const char *filename
;
4267 int *want_partial_unit_ptr
= data
;
4269 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4270 && (want_partial_unit_ptr
== NULL
4271 || !*want_partial_unit_ptr
))
4274 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4276 cu
->list_in_scope
= &file_symbols
;
4278 /* Allocate a new partial symbol table structure. */
4279 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4280 if (attr
== NULL
|| !DW_STRING (attr
))
4283 filename
= DW_STRING (attr
);
4284 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4286 /* TEXTLOW and TEXTHIGH are set below. */
4288 objfile
->global_psymbols
.next
,
4289 objfile
->static_psymbols
.next
);
4290 pst
->psymtabs_addrmap_supported
= 1;
4292 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4294 pst
->dirname
= DW_STRING (attr
);
4296 pst
->read_symtab_private
= per_cu
;
4298 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4300 /* Store the function that reads in the rest of the symbol table. */
4301 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4303 per_cu
->v
.psymtab
= pst
;
4305 dwarf2_find_base_address (comp_unit_die
, cu
);
4307 /* Possibly set the default values of LOWPC and HIGHPC from
4309 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4310 &best_highpc
, cu
, pst
);
4311 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4312 /* Store the contiguous range if it is not empty; it can be empty for
4313 CUs with no code. */
4314 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4315 best_lowpc
+ baseaddr
,
4316 best_highpc
+ baseaddr
- 1, pst
);
4318 /* Check if comp unit has_children.
4319 If so, read the rest of the partial symbols from this comp unit.
4320 If not, there's no more debug_info for this comp unit. */
4323 struct partial_die_info
*first_die
;
4324 CORE_ADDR lowpc
, highpc
;
4326 lowpc
= ((CORE_ADDR
) -1);
4327 highpc
= ((CORE_ADDR
) 0);
4329 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4331 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4334 /* If we didn't find a lowpc, set it to highpc to avoid
4335 complaints from `maint check'. */
4336 if (lowpc
== ((CORE_ADDR
) -1))
4339 /* If the compilation unit didn't have an explicit address range,
4340 then use the information extracted from its child dies. */
4344 best_highpc
= highpc
;
4347 pst
->textlow
= best_lowpc
+ baseaddr
;
4348 pst
->texthigh
= best_highpc
+ baseaddr
;
4350 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4351 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4352 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4353 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4354 sort_pst_symbols (pst
);
4356 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4359 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4360 struct dwarf2_per_cu_data
*iter
;
4362 /* Fill in 'dependencies' here; we fill in 'users' in a
4364 pst
->number_of_dependencies
= len
;
4365 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4366 len
* sizeof (struct symtab
*));
4368 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4371 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4373 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4376 if (per_cu
->is_debug_types
)
4378 /* It's not clear we want to do anything with stmt lists here.
4379 Waiting to see what gcc ultimately does. */
4383 /* Get the list of files included in the current compilation unit,
4384 and build a psymtab for each of them. */
4385 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4389 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4390 Process compilation unit THIS_CU for a psymtab. */
4393 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4394 int want_partial_unit
)
4396 /* If this compilation unit was already read in, free the
4397 cached copy in order to read it in again. This is
4398 necessary because we skipped some symbols when we first
4399 read in the compilation unit (see load_partial_dies).
4400 This problem could be avoided, but the benefit is unclear. */
4401 if (this_cu
->cu
!= NULL
)
4402 free_one_cached_comp_unit (this_cu
);
4404 gdb_assert (! this_cu
->is_debug_types
);
4405 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4406 &want_partial_unit
);
4408 /* Age out any secondary CUs. */
4409 age_cached_comp_units ();
4412 /* Traversal function for htab_traverse_noresize.
4413 Process one .debug_types comp-unit. */
4416 process_psymtab_type_unit (void **slot
, void *info
)
4418 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4419 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4421 gdb_assert (per_cu
->is_debug_types
);
4422 gdb_assert (info
== NULL
);
4424 /* If this compilation unit was already read in, free the
4425 cached copy in order to read it in again. This is
4426 necessary because we skipped some symbols when we first
4427 read in the compilation unit (see load_partial_dies).
4428 This problem could be avoided, but the benefit is unclear. */
4429 if (per_cu
->cu
!= NULL
)
4430 free_one_cached_comp_unit (per_cu
);
4432 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4435 /* Age out any secondary CUs. */
4436 age_cached_comp_units ();
4441 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4442 Build partial symbol tables for the .debug_types comp-units. */
4445 build_type_psymtabs (struct objfile
*objfile
)
4447 if (! create_all_type_units (objfile
))
4450 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4451 process_psymtab_type_unit
, NULL
);
4454 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4457 psymtabs_addrmap_cleanup (void *o
)
4459 struct objfile
*objfile
= o
;
4461 objfile
->psymtabs_addrmap
= NULL
;
4464 /* Compute the 'user' field for each psymtab in OBJFILE. */
4467 set_partial_user (struct objfile
*objfile
)
4471 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4473 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4474 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4477 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4479 /* Set the 'user' field only if it is not already set. */
4480 if (pst
->dependencies
[j
]->user
== NULL
)
4481 pst
->dependencies
[j
]->user
= pst
;
4486 /* Build the partial symbol table by doing a quick pass through the
4487 .debug_info and .debug_abbrev sections. */
4490 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4492 struct cleanup
*back_to
, *addrmap_cleanup
;
4493 struct obstack temp_obstack
;
4496 if (dwarf2_read_debug
)
4498 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
4502 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4504 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4506 /* Any cached compilation units will be linked by the per-objfile
4507 read_in_chain. Make sure to free them when we're done. */
4508 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4510 build_type_psymtabs (objfile
);
4512 create_all_comp_units (objfile
);
4514 /* Create a temporary address map on a temporary obstack. We later
4515 copy this to the final obstack. */
4516 obstack_init (&temp_obstack
);
4517 make_cleanup_obstack_free (&temp_obstack
);
4518 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4519 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4521 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4523 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4525 process_psymtab_comp_unit (per_cu
, 0);
4528 set_partial_user (objfile
);
4530 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4531 &objfile
->objfile_obstack
);
4532 discard_cleanups (addrmap_cleanup
);
4534 do_cleanups (back_to
);
4536 if (dwarf2_read_debug
)
4537 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
4541 /* die_reader_func for load_partial_comp_unit. */
4544 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4546 struct die_info
*comp_unit_die
,
4550 struct dwarf2_cu
*cu
= reader
->cu
;
4552 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4554 /* Check if comp unit has_children.
4555 If so, read the rest of the partial symbols from this comp unit.
4556 If not, there's no more debug_info for this comp unit. */
4558 load_partial_dies (reader
, info_ptr
, 0);
4561 /* Load the partial DIEs for a secondary CU into memory.
4562 This is also used when rereading a primary CU with load_all_dies. */
4565 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4567 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4570 /* Create a list of all compilation units in OBJFILE.
4571 This is only done for -readnow and building partial symtabs. */
4574 create_all_comp_units (struct objfile
*objfile
)
4578 struct dwarf2_per_cu_data
**all_comp_units
;
4581 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4582 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4586 all_comp_units
= xmalloc (n_allocated
4587 * sizeof (struct dwarf2_per_cu_data
*));
4589 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4590 + dwarf2_per_objfile
->info
.size
)
4592 unsigned int length
, initial_length_size
;
4593 struct dwarf2_per_cu_data
*this_cu
;
4596 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4598 /* Read just enough information to find out where the next
4599 compilation unit is. */
4600 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4601 &initial_length_size
);
4603 /* Save the compilation unit for later lookup. */
4604 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4605 sizeof (struct dwarf2_per_cu_data
));
4606 memset (this_cu
, 0, sizeof (*this_cu
));
4607 this_cu
->offset
= offset
;
4608 this_cu
->length
= length
+ initial_length_size
;
4609 this_cu
->objfile
= objfile
;
4610 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4612 if (n_comp_units
== n_allocated
)
4615 all_comp_units
= xrealloc (all_comp_units
,
4617 * sizeof (struct dwarf2_per_cu_data
*));
4619 all_comp_units
[n_comp_units
++] = this_cu
;
4621 info_ptr
= info_ptr
+ this_cu
->length
;
4624 dwarf2_per_objfile
->all_comp_units
4625 = obstack_alloc (&objfile
->objfile_obstack
,
4626 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4627 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4628 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4629 xfree (all_comp_units
);
4630 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4633 /* Process all loaded DIEs for compilation unit CU, starting at
4634 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4635 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4636 DW_AT_ranges). If NEED_PC is set, then this function will set
4637 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4638 and record the covered ranges in the addrmap. */
4641 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4642 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4644 struct partial_die_info
*pdi
;
4646 /* Now, march along the PDI's, descending into ones which have
4647 interesting children but skipping the children of the other ones,
4648 until we reach the end of the compilation unit. */
4654 fixup_partial_die (pdi
, cu
);
4656 /* Anonymous namespaces or modules have no name but have interesting
4657 children, so we need to look at them. Ditto for anonymous
4660 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4661 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4662 || pdi
->tag
== DW_TAG_imported_unit
)
4666 case DW_TAG_subprogram
:
4667 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4669 case DW_TAG_constant
:
4670 case DW_TAG_variable
:
4671 case DW_TAG_typedef
:
4672 case DW_TAG_union_type
:
4673 if (!pdi
->is_declaration
)
4675 add_partial_symbol (pdi
, cu
);
4678 case DW_TAG_class_type
:
4679 case DW_TAG_interface_type
:
4680 case DW_TAG_structure_type
:
4681 if (!pdi
->is_declaration
)
4683 add_partial_symbol (pdi
, cu
);
4686 case DW_TAG_enumeration_type
:
4687 if (!pdi
->is_declaration
)
4688 add_partial_enumeration (pdi
, cu
);
4690 case DW_TAG_base_type
:
4691 case DW_TAG_subrange_type
:
4692 /* File scope base type definitions are added to the partial
4694 add_partial_symbol (pdi
, cu
);
4696 case DW_TAG_namespace
:
4697 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4700 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4702 case DW_TAG_imported_unit
:
4704 struct dwarf2_per_cu_data
*per_cu
;
4706 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4709 /* Go read the partial unit, if needed. */
4710 if (per_cu
->v
.psymtab
== NULL
)
4711 process_psymtab_comp_unit (per_cu
, 1);
4713 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4722 /* If the die has a sibling, skip to the sibling. */
4724 pdi
= pdi
->die_sibling
;
4728 /* Functions used to compute the fully scoped name of a partial DIE.
4730 Normally, this is simple. For C++, the parent DIE's fully scoped
4731 name is concatenated with "::" and the partial DIE's name. For
4732 Java, the same thing occurs except that "." is used instead of "::".
4733 Enumerators are an exception; they use the scope of their parent
4734 enumeration type, i.e. the name of the enumeration type is not
4735 prepended to the enumerator.
4737 There are two complexities. One is DW_AT_specification; in this
4738 case "parent" means the parent of the target of the specification,
4739 instead of the direct parent of the DIE. The other is compilers
4740 which do not emit DW_TAG_namespace; in this case we try to guess
4741 the fully qualified name of structure types from their members'
4742 linkage names. This must be done using the DIE's children rather
4743 than the children of any DW_AT_specification target. We only need
4744 to do this for structures at the top level, i.e. if the target of
4745 any DW_AT_specification (if any; otherwise the DIE itself) does not
4748 /* Compute the scope prefix associated with PDI's parent, in
4749 compilation unit CU. The result will be allocated on CU's
4750 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4751 field. NULL is returned if no prefix is necessary. */
4753 partial_die_parent_scope (struct partial_die_info
*pdi
,
4754 struct dwarf2_cu
*cu
)
4756 char *grandparent_scope
;
4757 struct partial_die_info
*parent
, *real_pdi
;
4759 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4760 then this means the parent of the specification DIE. */
4763 while (real_pdi
->has_specification
)
4764 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4766 parent
= real_pdi
->die_parent
;
4770 if (parent
->scope_set
)
4771 return parent
->scope
;
4773 fixup_partial_die (parent
, cu
);
4775 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4777 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4778 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4779 Work around this problem here. */
4780 if (cu
->language
== language_cplus
4781 && parent
->tag
== DW_TAG_namespace
4782 && strcmp (parent
->name
, "::") == 0
4783 && grandparent_scope
== NULL
)
4785 parent
->scope
= NULL
;
4786 parent
->scope_set
= 1;
4790 if (pdi
->tag
== DW_TAG_enumerator
)
4791 /* Enumerators should not get the name of the enumeration as a prefix. */
4792 parent
->scope
= grandparent_scope
;
4793 else if (parent
->tag
== DW_TAG_namespace
4794 || parent
->tag
== DW_TAG_module
4795 || parent
->tag
== DW_TAG_structure_type
4796 || parent
->tag
== DW_TAG_class_type
4797 || parent
->tag
== DW_TAG_interface_type
4798 || parent
->tag
== DW_TAG_union_type
4799 || parent
->tag
== DW_TAG_enumeration_type
)
4801 if (grandparent_scope
== NULL
)
4802 parent
->scope
= parent
->name
;
4804 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4806 parent
->name
, 0, cu
);
4810 /* FIXME drow/2004-04-01: What should we be doing with
4811 function-local names? For partial symbols, we should probably be
4813 complaint (&symfile_complaints
,
4814 _("unhandled containing DIE tag %d for DIE at %d"),
4815 parent
->tag
, pdi
->offset
.sect_off
);
4816 parent
->scope
= grandparent_scope
;
4819 parent
->scope_set
= 1;
4820 return parent
->scope
;
4823 /* Return the fully scoped name associated with PDI, from compilation unit
4824 CU. The result will be allocated with malloc. */
4827 partial_die_full_name (struct partial_die_info
*pdi
,
4828 struct dwarf2_cu
*cu
)
4832 /* If this is a template instantiation, we can not work out the
4833 template arguments from partial DIEs. So, unfortunately, we have
4834 to go through the full DIEs. At least any work we do building
4835 types here will be reused if full symbols are loaded later. */
4836 if (pdi
->has_template_arguments
)
4838 fixup_partial_die (pdi
, cu
);
4840 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4842 struct die_info
*die
;
4843 struct attribute attr
;
4844 struct dwarf2_cu
*ref_cu
= cu
;
4846 /* DW_FORM_ref_addr is using section offset. */
4848 attr
.form
= DW_FORM_ref_addr
;
4849 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4850 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4852 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4856 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4857 if (parent_scope
== NULL
)
4860 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4864 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4866 struct objfile
*objfile
= cu
->objfile
;
4868 char *actual_name
= NULL
;
4870 int built_actual_name
= 0;
4872 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4874 actual_name
= partial_die_full_name (pdi
, cu
);
4876 built_actual_name
= 1;
4878 if (actual_name
== NULL
)
4879 actual_name
= pdi
->name
;
4883 case DW_TAG_subprogram
:
4884 if (pdi
->is_external
|| cu
->language
== language_ada
)
4886 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4887 of the global scope. But in Ada, we want to be able to access
4888 nested procedures globally. So all Ada subprograms are stored
4889 in the global scope. */
4890 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4891 mst_text, objfile); */
4892 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4894 VAR_DOMAIN
, LOC_BLOCK
,
4895 &objfile
->global_psymbols
,
4896 0, pdi
->lowpc
+ baseaddr
,
4897 cu
->language
, objfile
);
4901 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4902 mst_file_text, objfile); */
4903 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4905 VAR_DOMAIN
, LOC_BLOCK
,
4906 &objfile
->static_psymbols
,
4907 0, pdi
->lowpc
+ baseaddr
,
4908 cu
->language
, objfile
);
4911 case DW_TAG_constant
:
4913 struct psymbol_allocation_list
*list
;
4915 if (pdi
->is_external
)
4916 list
= &objfile
->global_psymbols
;
4918 list
= &objfile
->static_psymbols
;
4919 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4920 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4921 list
, 0, 0, cu
->language
, objfile
);
4924 case DW_TAG_variable
:
4926 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4930 && !dwarf2_per_objfile
->has_section_at_zero
)
4932 /* A global or static variable may also have been stripped
4933 out by the linker if unused, in which case its address
4934 will be nullified; do not add such variables into partial
4935 symbol table then. */
4937 else if (pdi
->is_external
)
4940 Don't enter into the minimal symbol tables as there is
4941 a minimal symbol table entry from the ELF symbols already.
4942 Enter into partial symbol table if it has a location
4943 descriptor or a type.
4944 If the location descriptor is missing, new_symbol will create
4945 a LOC_UNRESOLVED symbol, the address of the variable will then
4946 be determined from the minimal symbol table whenever the variable
4948 The address for the partial symbol table entry is not
4949 used by GDB, but it comes in handy for debugging partial symbol
4952 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4953 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4955 VAR_DOMAIN
, LOC_STATIC
,
4956 &objfile
->global_psymbols
,
4958 cu
->language
, objfile
);
4962 /* Static Variable. Skip symbols without location descriptors. */
4963 if (pdi
->d
.locdesc
== NULL
)
4965 if (built_actual_name
)
4966 xfree (actual_name
);
4969 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4970 mst_file_data, objfile); */
4971 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4973 VAR_DOMAIN
, LOC_STATIC
,
4974 &objfile
->static_psymbols
,
4976 cu
->language
, objfile
);
4979 case DW_TAG_typedef
:
4980 case DW_TAG_base_type
:
4981 case DW_TAG_subrange_type
:
4982 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4984 VAR_DOMAIN
, LOC_TYPEDEF
,
4985 &objfile
->static_psymbols
,
4986 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4988 case DW_TAG_namespace
:
4989 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4991 VAR_DOMAIN
, LOC_TYPEDEF
,
4992 &objfile
->global_psymbols
,
4993 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4995 case DW_TAG_class_type
:
4996 case DW_TAG_interface_type
:
4997 case DW_TAG_structure_type
:
4998 case DW_TAG_union_type
:
4999 case DW_TAG_enumeration_type
:
5000 /* Skip external references. The DWARF standard says in the section
5001 about "Structure, Union, and Class Type Entries": "An incomplete
5002 structure, union or class type is represented by a structure,
5003 union or class entry that does not have a byte size attribute
5004 and that has a DW_AT_declaration attribute." */
5005 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5007 if (built_actual_name
)
5008 xfree (actual_name
);
5012 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5013 static vs. global. */
5014 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5016 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5017 (cu
->language
== language_cplus
5018 || cu
->language
== language_java
)
5019 ? &objfile
->global_psymbols
5020 : &objfile
->static_psymbols
,
5021 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5024 case DW_TAG_enumerator
:
5025 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5027 VAR_DOMAIN
, LOC_CONST
,
5028 (cu
->language
== language_cplus
5029 || cu
->language
== language_java
)
5030 ? &objfile
->global_psymbols
5031 : &objfile
->static_psymbols
,
5032 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5038 if (built_actual_name
)
5039 xfree (actual_name
);
5042 /* Read a partial die corresponding to a namespace; also, add a symbol
5043 corresponding to that namespace to the symbol table. NAMESPACE is
5044 the name of the enclosing namespace. */
5047 add_partial_namespace (struct partial_die_info
*pdi
,
5048 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5049 int need_pc
, struct dwarf2_cu
*cu
)
5051 /* Add a symbol for the namespace. */
5053 add_partial_symbol (pdi
, cu
);
5055 /* Now scan partial symbols in that namespace. */
5057 if (pdi
->has_children
)
5058 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5061 /* Read a partial die corresponding to a Fortran module. */
5064 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5065 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5067 /* Now scan partial symbols in that module. */
5069 if (pdi
->has_children
)
5070 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5073 /* Read a partial die corresponding to a subprogram and create a partial
5074 symbol for that subprogram. When the CU language allows it, this
5075 routine also defines a partial symbol for each nested subprogram
5076 that this subprogram contains.
5078 DIE my also be a lexical block, in which case we simply search
5079 recursively for suprograms defined inside that lexical block.
5080 Again, this is only performed when the CU language allows this
5081 type of definitions. */
5084 add_partial_subprogram (struct partial_die_info
*pdi
,
5085 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5086 int need_pc
, struct dwarf2_cu
*cu
)
5088 if (pdi
->tag
== DW_TAG_subprogram
)
5090 if (pdi
->has_pc_info
)
5092 if (pdi
->lowpc
< *lowpc
)
5093 *lowpc
= pdi
->lowpc
;
5094 if (pdi
->highpc
> *highpc
)
5095 *highpc
= pdi
->highpc
;
5099 struct objfile
*objfile
= cu
->objfile
;
5101 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5102 SECT_OFF_TEXT (objfile
));
5103 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5104 pdi
->lowpc
+ baseaddr
,
5105 pdi
->highpc
- 1 + baseaddr
,
5106 cu
->per_cu
->v
.psymtab
);
5110 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5112 if (!pdi
->is_declaration
)
5113 /* Ignore subprogram DIEs that do not have a name, they are
5114 illegal. Do not emit a complaint at this point, we will
5115 do so when we convert this psymtab into a symtab. */
5117 add_partial_symbol (pdi
, cu
);
5121 if (! pdi
->has_children
)
5124 if (cu
->language
== language_ada
)
5126 pdi
= pdi
->die_child
;
5129 fixup_partial_die (pdi
, cu
);
5130 if (pdi
->tag
== DW_TAG_subprogram
5131 || pdi
->tag
== DW_TAG_lexical_block
)
5132 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5133 pdi
= pdi
->die_sibling
;
5138 /* Read a partial die corresponding to an enumeration type. */
5141 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5142 struct dwarf2_cu
*cu
)
5144 struct partial_die_info
*pdi
;
5146 if (enum_pdi
->name
!= NULL
)
5147 add_partial_symbol (enum_pdi
, cu
);
5149 pdi
= enum_pdi
->die_child
;
5152 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5153 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5155 add_partial_symbol (pdi
, cu
);
5156 pdi
= pdi
->die_sibling
;
5160 /* Return the initial uleb128 in the die at INFO_PTR. */
5163 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5165 unsigned int bytes_read
;
5167 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5170 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5171 Return the corresponding abbrev, or NULL if the number is zero (indicating
5172 an empty DIE). In either case *BYTES_READ will be set to the length of
5173 the initial number. */
5175 static struct abbrev_info
*
5176 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5177 struct dwarf2_cu
*cu
)
5179 bfd
*abfd
= cu
->objfile
->obfd
;
5180 unsigned int abbrev_number
;
5181 struct abbrev_info
*abbrev
;
5183 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5185 if (abbrev_number
== 0)
5188 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
5191 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5192 abbrev_number
, bfd_get_filename (abfd
));
5198 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5199 Returns a pointer to the end of a series of DIEs, terminated by an empty
5200 DIE. Any children of the skipped DIEs will also be skipped. */
5203 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5205 struct dwarf2_cu
*cu
= reader
->cu
;
5206 struct abbrev_info
*abbrev
;
5207 unsigned int bytes_read
;
5211 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5213 return info_ptr
+ bytes_read
;
5215 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5219 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5220 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5221 abbrev corresponding to that skipped uleb128 should be passed in
5222 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5226 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5227 struct abbrev_info
*abbrev
)
5229 unsigned int bytes_read
;
5230 struct attribute attr
;
5231 bfd
*abfd
= reader
->abfd
;
5232 struct dwarf2_cu
*cu
= reader
->cu
;
5233 gdb_byte
*buffer
= reader
->buffer
;
5234 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5235 gdb_byte
*start_info_ptr
= info_ptr
;
5236 unsigned int form
, i
;
5238 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5240 /* The only abbrev we care about is DW_AT_sibling. */
5241 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5243 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5244 if (attr
.form
== DW_FORM_ref_addr
)
5245 complaint (&symfile_complaints
,
5246 _("ignoring absolute DW_AT_sibling"));
5248 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5251 /* If it isn't DW_AT_sibling, skip this attribute. */
5252 form
= abbrev
->attrs
[i
].form
;
5256 case DW_FORM_ref_addr
:
5257 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5258 and later it is offset sized. */
5259 if (cu
->header
.version
== 2)
5260 info_ptr
+= cu
->header
.addr_size
;
5262 info_ptr
+= cu
->header
.offset_size
;
5265 info_ptr
+= cu
->header
.addr_size
;
5272 case DW_FORM_flag_present
:
5284 case DW_FORM_ref_sig8
:
5287 case DW_FORM_string
:
5288 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5289 info_ptr
+= bytes_read
;
5291 case DW_FORM_sec_offset
:
5293 info_ptr
+= cu
->header
.offset_size
;
5295 case DW_FORM_exprloc
:
5297 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5298 info_ptr
+= bytes_read
;
5300 case DW_FORM_block1
:
5301 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5303 case DW_FORM_block2
:
5304 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5306 case DW_FORM_block4
:
5307 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5311 case DW_FORM_ref_udata
:
5312 case DW_FORM_GNU_addr_index
:
5313 case DW_FORM_GNU_str_index
:
5314 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5316 case DW_FORM_indirect
:
5317 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5318 info_ptr
+= bytes_read
;
5319 /* We need to continue parsing from here, so just go back to
5321 goto skip_attribute
;
5324 error (_("Dwarf Error: Cannot handle %s "
5325 "in DWARF reader [in module %s]"),
5326 dwarf_form_name (form
),
5327 bfd_get_filename (abfd
));
5331 if (abbrev
->has_children
)
5332 return skip_children (reader
, info_ptr
);
5337 /* Locate ORIG_PDI's sibling.
5338 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5341 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5342 struct partial_die_info
*orig_pdi
,
5345 /* Do we know the sibling already? */
5347 if (orig_pdi
->sibling
)
5348 return orig_pdi
->sibling
;
5350 /* Are there any children to deal with? */
5352 if (!orig_pdi
->has_children
)
5355 /* Skip the children the long way. */
5357 return skip_children (reader
, info_ptr
);
5360 /* Expand this partial symbol table into a full symbol table. */
5363 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5369 warning (_("bug: psymtab for %s is already read in."),
5376 printf_filtered (_("Reading in symbols for %s..."),
5378 gdb_flush (gdb_stdout
);
5381 /* Restore our global data. */
5382 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5383 dwarf2_objfile_data_key
);
5385 /* If this psymtab is constructed from a debug-only objfile, the
5386 has_section_at_zero flag will not necessarily be correct. We
5387 can get the correct value for this flag by looking at the data
5388 associated with the (presumably stripped) associated objfile. */
5389 if (pst
->objfile
->separate_debug_objfile_backlink
)
5391 struct dwarf2_per_objfile
*dpo_backlink
5392 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5393 dwarf2_objfile_data_key
);
5395 dwarf2_per_objfile
->has_section_at_zero
5396 = dpo_backlink
->has_section_at_zero
;
5399 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5401 psymtab_to_symtab_1 (pst
);
5403 /* Finish up the debug error message. */
5405 printf_filtered (_("done.\n"));
5409 process_cu_includes ();
5412 /* Reading in full CUs. */
5414 /* Add PER_CU to the queue. */
5417 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5418 enum language pretend_language
)
5420 struct dwarf2_queue_item
*item
;
5423 item
= xmalloc (sizeof (*item
));
5424 item
->per_cu
= per_cu
;
5425 item
->pretend_language
= pretend_language
;
5428 if (dwarf2_queue
== NULL
)
5429 dwarf2_queue
= item
;
5431 dwarf2_queue_tail
->next
= item
;
5433 dwarf2_queue_tail
= item
;
5436 /* Process the queue. */
5439 process_queue (void)
5441 struct dwarf2_queue_item
*item
, *next_item
;
5443 if (dwarf2_read_debug
)
5445 fprintf_unfiltered (gdb_stdlog
,
5446 "Expanding one or more symtabs of objfile %s ...\n",
5447 dwarf2_per_objfile
->objfile
->name
);
5450 /* The queue starts out with one item, but following a DIE reference
5451 may load a new CU, adding it to the end of the queue. */
5452 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5454 if (dwarf2_per_objfile
->using_index
5455 ? !item
->per_cu
->v
.quick
->symtab
5456 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5457 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5459 item
->per_cu
->queued
= 0;
5460 next_item
= item
->next
;
5464 dwarf2_queue_tail
= NULL
;
5466 if (dwarf2_read_debug
)
5468 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
5469 dwarf2_per_objfile
->objfile
->name
);
5473 /* Free all allocated queue entries. This function only releases anything if
5474 an error was thrown; if the queue was processed then it would have been
5475 freed as we went along. */
5478 dwarf2_release_queue (void *dummy
)
5480 struct dwarf2_queue_item
*item
, *last
;
5482 item
= dwarf2_queue
;
5485 /* Anything still marked queued is likely to be in an
5486 inconsistent state, so discard it. */
5487 if (item
->per_cu
->queued
)
5489 if (item
->per_cu
->cu
!= NULL
)
5490 free_one_cached_comp_unit (item
->per_cu
);
5491 item
->per_cu
->queued
= 0;
5499 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5502 /* Read in full symbols for PST, and anything it depends on. */
5505 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5507 struct dwarf2_per_cu_data
*per_cu
;
5513 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5514 if (!pst
->dependencies
[i
]->readin
5515 && pst
->dependencies
[i
]->user
== NULL
)
5517 /* Inform about additional files that need to be read in. */
5520 /* FIXME: i18n: Need to make this a single string. */
5521 fputs_filtered (" ", gdb_stdout
);
5523 fputs_filtered ("and ", gdb_stdout
);
5525 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5526 wrap_here (""); /* Flush output. */
5527 gdb_flush (gdb_stdout
);
5529 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5532 per_cu
= pst
->read_symtab_private
;
5536 /* It's an include file, no symbols to read for it.
5537 Everything is in the parent symtab. */
5542 dw2_do_instantiate_symtab (per_cu
);
5545 /* Trivial hash function for die_info: the hash value of a DIE
5546 is its offset in .debug_info for this objfile. */
5549 die_hash (const void *item
)
5551 const struct die_info
*die
= item
;
5553 return die
->offset
.sect_off
;
5556 /* Trivial comparison function for die_info structures: two DIEs
5557 are equal if they have the same offset. */
5560 die_eq (const void *item_lhs
, const void *item_rhs
)
5562 const struct die_info
*die_lhs
= item_lhs
;
5563 const struct die_info
*die_rhs
= item_rhs
;
5565 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5568 /* die_reader_func for load_full_comp_unit.
5569 This is identical to read_signatured_type_reader,
5570 but is kept separate for now. */
5573 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5575 struct die_info
*comp_unit_die
,
5579 struct dwarf2_cu
*cu
= reader
->cu
;
5580 enum language
*language_ptr
= data
;
5582 gdb_assert (cu
->die_hash
== NULL
);
5584 htab_create_alloc_ex (cu
->header
.length
/ 12,
5588 &cu
->comp_unit_obstack
,
5589 hashtab_obstack_allocate
,
5590 dummy_obstack_deallocate
);
5593 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5594 &info_ptr
, comp_unit_die
);
5595 cu
->dies
= comp_unit_die
;
5596 /* comp_unit_die is not stored in die_hash, no need. */
5598 /* We try not to read any attributes in this function, because not
5599 all CUs needed for references have been loaded yet, and symbol
5600 table processing isn't initialized. But we have to set the CU language,
5601 or we won't be able to build types correctly.
5602 Similarly, if we do not read the producer, we can not apply
5603 producer-specific interpretation. */
5604 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5607 /* Load the DIEs associated with PER_CU into memory. */
5610 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5611 enum language pretend_language
)
5613 gdb_assert (! this_cu
->is_debug_types
);
5615 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5619 /* Add a DIE to the delayed physname list. */
5622 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5623 const char *name
, struct die_info
*die
,
5624 struct dwarf2_cu
*cu
)
5626 struct delayed_method_info mi
;
5628 mi
.fnfield_index
= fnfield_index
;
5632 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5635 /* A cleanup for freeing the delayed method list. */
5638 free_delayed_list (void *ptr
)
5640 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5641 if (cu
->method_list
!= NULL
)
5643 VEC_free (delayed_method_info
, cu
->method_list
);
5644 cu
->method_list
= NULL
;
5648 /* Compute the physnames of any methods on the CU's method list.
5650 The computation of method physnames is delayed in order to avoid the
5651 (bad) condition that one of the method's formal parameters is of an as yet
5655 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5658 struct delayed_method_info
*mi
;
5659 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5661 const char *physname
;
5662 struct fn_fieldlist
*fn_flp
5663 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5664 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5665 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5669 /* Go objects should be embedded in a DW_TAG_module DIE,
5670 and it's not clear if/how imported objects will appear.
5671 To keep Go support simple until that's worked out,
5672 go back through what we've read and create something usable.
5673 We could do this while processing each DIE, and feels kinda cleaner,
5674 but that way is more invasive.
5675 This is to, for example, allow the user to type "p var" or "b main"
5676 without having to specify the package name, and allow lookups
5677 of module.object to work in contexts that use the expression
5681 fixup_go_packaging (struct dwarf2_cu
*cu
)
5683 char *package_name
= NULL
;
5684 struct pending
*list
;
5687 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5689 for (i
= 0; i
< list
->nsyms
; ++i
)
5691 struct symbol
*sym
= list
->symbol
[i
];
5693 if (SYMBOL_LANGUAGE (sym
) == language_go
5694 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5696 char *this_package_name
= go_symbol_package_name (sym
);
5698 if (this_package_name
== NULL
)
5700 if (package_name
== NULL
)
5701 package_name
= this_package_name
;
5704 if (strcmp (package_name
, this_package_name
) != 0)
5705 complaint (&symfile_complaints
,
5706 _("Symtab %s has objects from two different Go packages: %s and %s"),
5707 (sym
->symtab
&& sym
->symtab
->filename
5708 ? sym
->symtab
->filename
5709 : cu
->objfile
->name
),
5710 this_package_name
, package_name
);
5711 xfree (this_package_name
);
5717 if (package_name
!= NULL
)
5719 struct objfile
*objfile
= cu
->objfile
;
5720 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5721 package_name
, objfile
);
5724 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5726 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5727 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5728 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5729 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5730 e.g., "main" finds the "main" module and not C's main(). */
5731 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5732 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5733 SYMBOL_TYPE (sym
) = type
;
5735 add_symbol_to_list (sym
, &global_symbols
);
5737 xfree (package_name
);
5741 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5743 /* Return the symtab for PER_CU. This works properly regardless of
5744 whether we're using the index or psymtabs. */
5746 static struct symtab
*
5747 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5749 return (dwarf2_per_objfile
->using_index
5750 ? per_cu
->v
.quick
->symtab
5751 : per_cu
->v
.psymtab
->symtab
);
5754 /* A helper function for computing the list of all symbol tables
5755 included by PER_CU. */
5758 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5759 htab_t all_children
,
5760 struct dwarf2_per_cu_data
*per_cu
)
5764 struct dwarf2_per_cu_data
*iter
;
5766 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5769 /* This inclusion and its children have been processed. */
5774 /* Only add a CU if it has a symbol table. */
5775 if (get_symtab (per_cu
) != NULL
)
5776 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5779 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5781 recursively_compute_inclusions (result
, all_children
, iter
);
5784 /* Compute the symtab 'includes' fields for the symtab related to
5788 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5790 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5793 struct dwarf2_per_cu_data
*iter
;
5794 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5795 htab_t all_children
;
5796 struct symtab
*symtab
= get_symtab (per_cu
);
5798 /* If we don't have a symtab, we can just skip this case. */
5802 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5803 NULL
, xcalloc
, xfree
);
5806 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5809 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5811 /* Now we have a transitive closure of all the included CUs, so
5812 we can convert it to a list of symtabs. */
5813 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5815 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5816 (len
+ 1) * sizeof (struct symtab
*));
5818 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5820 symtab
->includes
[ix
] = get_symtab (iter
);
5821 symtab
->includes
[len
] = NULL
;
5823 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5824 htab_delete (all_children
);
5828 /* Compute the 'includes' field for the symtabs of all the CUs we just
5832 process_cu_includes (void)
5835 struct dwarf2_per_cu_data
*iter
;
5838 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5841 compute_symtab_includes (iter
);
5843 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5846 /* Generate full symbol information for PER_CU, whose DIEs have
5847 already been loaded into memory. */
5850 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5851 enum language pretend_language
)
5853 struct dwarf2_cu
*cu
= per_cu
->cu
;
5854 struct objfile
*objfile
= per_cu
->objfile
;
5855 CORE_ADDR lowpc
, highpc
;
5856 struct symtab
*symtab
;
5857 struct cleanup
*back_to
, *delayed_list_cleanup
;
5860 if (dwarf2_read_debug
)
5862 fprintf_unfiltered (gdb_stdlog
,
5863 "Expanding symtab of %s at offset 0x%x\n",
5864 per_cu
->is_debug_types
? "TU" : "CU",
5865 per_cu
->offset
.sect_off
);
5868 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5871 back_to
= make_cleanup (really_free_pendings
, NULL
);
5872 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5874 cu
->list_in_scope
= &file_symbols
;
5876 cu
->language
= pretend_language
;
5877 cu
->language_defn
= language_def (cu
->language
);
5879 /* Do line number decoding in read_file_scope () */
5880 process_die (cu
->dies
, cu
);
5882 /* For now fudge the Go package. */
5883 if (cu
->language
== language_go
)
5884 fixup_go_packaging (cu
);
5886 /* Now that we have processed all the DIEs in the CU, all the types
5887 should be complete, and it should now be safe to compute all of the
5889 compute_delayed_physnames (cu
);
5890 do_cleanups (delayed_list_cleanup
);
5892 /* Some compilers don't define a DW_AT_high_pc attribute for the
5893 compilation unit. If the DW_AT_high_pc is missing, synthesize
5894 it, by scanning the DIE's below the compilation unit. */
5895 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5897 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5901 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5903 /* Set symtab language to language from DW_AT_language. If the
5904 compilation is from a C file generated by language preprocessors, do
5905 not set the language if it was already deduced by start_subfile. */
5906 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5907 symtab
->language
= cu
->language
;
5909 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5910 produce DW_AT_location with location lists but it can be possibly
5911 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5912 there were bugs in prologue debug info, fixed later in GCC-4.5
5913 by "unwind info for epilogues" patch (which is not directly related).
5915 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5916 needed, it would be wrong due to missing DW_AT_producer there.
5918 Still one can confuse GDB by using non-standard GCC compilation
5919 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5921 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5922 symtab
->locations_valid
= 1;
5924 if (gcc_4_minor
>= 5)
5925 symtab
->epilogue_unwind_valid
= 1;
5927 symtab
->call_site_htab
= cu
->call_site_htab
;
5930 if (dwarf2_per_objfile
->using_index
)
5931 per_cu
->v
.quick
->symtab
= symtab
;
5934 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5935 pst
->symtab
= symtab
;
5939 /* Push it for inclusion processing later. */
5940 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5942 do_cleanups (back_to
);
5944 if (dwarf2_read_debug
)
5946 fprintf_unfiltered (gdb_stdlog
,
5947 "Done expanding symtab of %s at offset 0x%x\n",
5948 per_cu
->is_debug_types
? "TU" : "CU",
5949 per_cu
->offset
.sect_off
);
5953 /* Process an imported unit DIE. */
5956 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5958 struct attribute
*attr
;
5960 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5963 struct dwarf2_per_cu_data
*per_cu
;
5964 struct symtab
*imported_symtab
;
5967 offset
= dwarf2_get_ref_die_offset (attr
);
5968 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5970 /* Queue the unit, if needed. */
5971 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5972 load_full_comp_unit (per_cu
, cu
->language
);
5974 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5979 /* Process a die and its children. */
5982 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5986 case DW_TAG_padding
:
5988 case DW_TAG_compile_unit
:
5989 case DW_TAG_partial_unit
:
5990 read_file_scope (die
, cu
);
5992 case DW_TAG_type_unit
:
5993 read_type_unit_scope (die
, cu
);
5995 case DW_TAG_subprogram
:
5996 case DW_TAG_inlined_subroutine
:
5997 read_func_scope (die
, cu
);
5999 case DW_TAG_lexical_block
:
6000 case DW_TAG_try_block
:
6001 case DW_TAG_catch_block
:
6002 read_lexical_block_scope (die
, cu
);
6004 case DW_TAG_GNU_call_site
:
6005 read_call_site_scope (die
, cu
);
6007 case DW_TAG_class_type
:
6008 case DW_TAG_interface_type
:
6009 case DW_TAG_structure_type
:
6010 case DW_TAG_union_type
:
6011 process_structure_scope (die
, cu
);
6013 case DW_TAG_enumeration_type
:
6014 process_enumeration_scope (die
, cu
);
6017 /* These dies have a type, but processing them does not create
6018 a symbol or recurse to process the children. Therefore we can
6019 read them on-demand through read_type_die. */
6020 case DW_TAG_subroutine_type
:
6021 case DW_TAG_set_type
:
6022 case DW_TAG_array_type
:
6023 case DW_TAG_pointer_type
:
6024 case DW_TAG_ptr_to_member_type
:
6025 case DW_TAG_reference_type
:
6026 case DW_TAG_string_type
:
6029 case DW_TAG_base_type
:
6030 case DW_TAG_subrange_type
:
6031 case DW_TAG_typedef
:
6032 /* Add a typedef symbol for the type definition, if it has a
6034 new_symbol (die
, read_type_die (die
, cu
), cu
);
6036 case DW_TAG_common_block
:
6037 read_common_block (die
, cu
);
6039 case DW_TAG_common_inclusion
:
6041 case DW_TAG_namespace
:
6042 processing_has_namespace_info
= 1;
6043 read_namespace (die
, cu
);
6046 processing_has_namespace_info
= 1;
6047 read_module (die
, cu
);
6049 case DW_TAG_imported_declaration
:
6050 case DW_TAG_imported_module
:
6051 processing_has_namespace_info
= 1;
6052 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6053 || cu
->language
!= language_fortran
))
6054 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6055 dwarf_tag_name (die
->tag
));
6056 read_import_statement (die
, cu
);
6059 case DW_TAG_imported_unit
:
6060 process_imported_unit_die (die
, cu
);
6064 new_symbol (die
, NULL
, cu
);
6069 /* A helper function for dwarf2_compute_name which determines whether DIE
6070 needs to have the name of the scope prepended to the name listed in the
6074 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6076 struct attribute
*attr
;
6080 case DW_TAG_namespace
:
6081 case DW_TAG_typedef
:
6082 case DW_TAG_class_type
:
6083 case DW_TAG_interface_type
:
6084 case DW_TAG_structure_type
:
6085 case DW_TAG_union_type
:
6086 case DW_TAG_enumeration_type
:
6087 case DW_TAG_enumerator
:
6088 case DW_TAG_subprogram
:
6092 case DW_TAG_variable
:
6093 case DW_TAG_constant
:
6094 /* We only need to prefix "globally" visible variables. These include
6095 any variable marked with DW_AT_external or any variable that
6096 lives in a namespace. [Variables in anonymous namespaces
6097 require prefixing, but they are not DW_AT_external.] */
6099 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6101 struct dwarf2_cu
*spec_cu
= cu
;
6103 return die_needs_namespace (die_specification (die
, &spec_cu
),
6107 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6108 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6109 && die
->parent
->tag
!= DW_TAG_module
)
6111 /* A variable in a lexical block of some kind does not need a
6112 namespace, even though in C++ such variables may be external
6113 and have a mangled name. */
6114 if (die
->parent
->tag
== DW_TAG_lexical_block
6115 || die
->parent
->tag
== DW_TAG_try_block
6116 || die
->parent
->tag
== DW_TAG_catch_block
6117 || die
->parent
->tag
== DW_TAG_subprogram
)
6126 /* Retrieve the last character from a mem_file. */
6129 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6131 char *last_char_p
= (char *) object
;
6134 *last_char_p
= buffer
[length
- 1];
6137 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6138 compute the physname for the object, which include a method's:
6139 - formal parameters (C++/Java),
6140 - receiver type (Go),
6141 - return type (Java).
6143 The term "physname" is a bit confusing.
6144 For C++, for example, it is the demangled name.
6145 For Go, for example, it's the mangled name.
6147 For Ada, return the DIE's linkage name rather than the fully qualified
6148 name. PHYSNAME is ignored..
6150 The result is allocated on the objfile_obstack and canonicalized. */
6153 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6156 struct objfile
*objfile
= cu
->objfile
;
6159 name
= dwarf2_name (die
, cu
);
6161 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6162 compute it by typename_concat inside GDB. */
6163 if (cu
->language
== language_ada
6164 || (cu
->language
== language_fortran
&& physname
))
6166 /* For Ada unit, we prefer the linkage name over the name, as
6167 the former contains the exported name, which the user expects
6168 to be able to reference. Ideally, we want the user to be able
6169 to reference this entity using either natural or linkage name,
6170 but we haven't started looking at this enhancement yet. */
6171 struct attribute
*attr
;
6173 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6175 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6176 if (attr
&& DW_STRING (attr
))
6177 return DW_STRING (attr
);
6180 /* These are the only languages we know how to qualify names in. */
6182 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6183 || cu
->language
== language_fortran
))
6185 if (die_needs_namespace (die
, cu
))
6189 struct ui_file
*buf
;
6191 prefix
= determine_prefix (die
, cu
);
6192 buf
= mem_fileopen ();
6193 if (*prefix
!= '\0')
6195 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
6198 fputs_unfiltered (prefixed_name
, buf
);
6199 xfree (prefixed_name
);
6202 fputs_unfiltered (name
, buf
);
6204 /* Template parameters may be specified in the DIE's DW_AT_name, or
6205 as children with DW_TAG_template_type_param or
6206 DW_TAG_value_type_param. If the latter, add them to the name
6207 here. If the name already has template parameters, then
6208 skip this step; some versions of GCC emit both, and
6209 it is more efficient to use the pre-computed name.
6211 Something to keep in mind about this process: it is very
6212 unlikely, or in some cases downright impossible, to produce
6213 something that will match the mangled name of a function.
6214 If the definition of the function has the same debug info,
6215 we should be able to match up with it anyway. But fallbacks
6216 using the minimal symbol, for instance to find a method
6217 implemented in a stripped copy of libstdc++, will not work.
6218 If we do not have debug info for the definition, we will have to
6219 match them up some other way.
6221 When we do name matching there is a related problem with function
6222 templates; two instantiated function templates are allowed to
6223 differ only by their return types, which we do not add here. */
6225 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6227 struct attribute
*attr
;
6228 struct die_info
*child
;
6231 die
->building_fullname
= 1;
6233 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6238 struct dwarf2_locexpr_baton
*baton
;
6241 if (child
->tag
!= DW_TAG_template_type_param
6242 && child
->tag
!= DW_TAG_template_value_param
)
6247 fputs_unfiltered ("<", buf
);
6251 fputs_unfiltered (", ", buf
);
6253 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6256 complaint (&symfile_complaints
,
6257 _("template parameter missing DW_AT_type"));
6258 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6261 type
= die_type (child
, cu
);
6263 if (child
->tag
== DW_TAG_template_type_param
)
6265 c_print_type (type
, "", buf
, -1, 0);
6269 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6272 complaint (&symfile_complaints
,
6273 _("template parameter missing "
6274 "DW_AT_const_value"));
6275 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6279 dwarf2_const_value_attr (attr
, type
, name
,
6280 &cu
->comp_unit_obstack
, cu
,
6281 &value
, &bytes
, &baton
);
6283 if (TYPE_NOSIGN (type
))
6284 /* GDB prints characters as NUMBER 'CHAR'. If that's
6285 changed, this can use value_print instead. */
6286 c_printchar (value
, type
, buf
);
6289 struct value_print_options opts
;
6292 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6296 else if (bytes
!= NULL
)
6298 v
= allocate_value (type
);
6299 memcpy (value_contents_writeable (v
), bytes
,
6300 TYPE_LENGTH (type
));
6303 v
= value_from_longest (type
, value
);
6305 /* Specify decimal so that we do not depend on
6307 get_formatted_print_options (&opts
, 'd');
6309 value_print (v
, buf
, &opts
);
6315 die
->building_fullname
= 0;
6319 /* Close the argument list, with a space if necessary
6320 (nested templates). */
6321 char last_char
= '\0';
6322 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6323 if (last_char
== '>')
6324 fputs_unfiltered (" >", buf
);
6326 fputs_unfiltered (">", buf
);
6330 /* For Java and C++ methods, append formal parameter type
6331 information, if PHYSNAME. */
6333 if (physname
&& die
->tag
== DW_TAG_subprogram
6334 && (cu
->language
== language_cplus
6335 || cu
->language
== language_java
))
6337 struct type
*type
= read_type_die (die
, cu
);
6339 c_type_print_args (type
, buf
, 1, cu
->language
);
6341 if (cu
->language
== language_java
)
6343 /* For java, we must append the return type to method
6345 if (die
->tag
== DW_TAG_subprogram
)
6346 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6349 else if (cu
->language
== language_cplus
)
6351 /* Assume that an artificial first parameter is
6352 "this", but do not crash if it is not. RealView
6353 marks unnamed (and thus unused) parameters as
6354 artificial; there is no way to differentiate
6356 if (TYPE_NFIELDS (type
) > 0
6357 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6358 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6359 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6361 fputs_unfiltered (" const", buf
);
6365 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6367 ui_file_delete (buf
);
6369 if (cu
->language
== language_cplus
)
6372 = dwarf2_canonicalize_name (name
, cu
,
6373 &objfile
->objfile_obstack
);
6384 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6385 If scope qualifiers are appropriate they will be added. The result
6386 will be allocated on the objfile_obstack, or NULL if the DIE does
6387 not have a name. NAME may either be from a previous call to
6388 dwarf2_name or NULL.
6390 The output string will be canonicalized (if C++/Java). */
6393 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6395 return dwarf2_compute_name (name
, die
, cu
, 0);
6398 /* Construct a physname for the given DIE in CU. NAME may either be
6399 from a previous call to dwarf2_name or NULL. The result will be
6400 allocated on the objfile_objstack or NULL if the DIE does not have a
6403 The output string will be canonicalized (if C++/Java). */
6406 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6408 struct objfile
*objfile
= cu
->objfile
;
6409 struct attribute
*attr
;
6410 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6411 struct cleanup
*back_to
;
6414 /* In this case dwarf2_compute_name is just a shortcut not building anything
6416 if (!die_needs_namespace (die
, cu
))
6417 return dwarf2_compute_name (name
, die
, cu
, 1);
6419 back_to
= make_cleanup (null_cleanup
, NULL
);
6421 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6423 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6425 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6427 if (attr
&& DW_STRING (attr
))
6431 mangled
= DW_STRING (attr
);
6433 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6434 type. It is easier for GDB users to search for such functions as
6435 `name(params)' than `long name(params)'. In such case the minimal
6436 symbol names do not match the full symbol names but for template
6437 functions there is never a need to look up their definition from their
6438 declaration so the only disadvantage remains the minimal symbol
6439 variant `long name(params)' does not have the proper inferior type.
6442 if (cu
->language
== language_go
)
6444 /* This is a lie, but we already lie to the caller new_symbol_full.
6445 new_symbol_full assumes we return the mangled name.
6446 This just undoes that lie until things are cleaned up. */
6451 demangled
= cplus_demangle (mangled
,
6452 (DMGL_PARAMS
| DMGL_ANSI
6453 | (cu
->language
== language_java
6454 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6459 make_cleanup (xfree
, demangled
);
6469 if (canon
== NULL
|| check_physname
)
6471 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6473 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6475 /* It may not mean a bug in GDB. The compiler could also
6476 compute DW_AT_linkage_name incorrectly. But in such case
6477 GDB would need to be bug-to-bug compatible. */
6479 complaint (&symfile_complaints
,
6480 _("Computed physname <%s> does not match demangled <%s> "
6481 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6482 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6484 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6485 is available here - over computed PHYSNAME. It is safer
6486 against both buggy GDB and buggy compilers. */
6500 retval
= obsavestring (retval
, strlen (retval
),
6501 &objfile
->objfile_obstack
);
6503 do_cleanups (back_to
);
6507 /* Read the import statement specified by the given die and record it. */
6510 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6512 struct objfile
*objfile
= cu
->objfile
;
6513 struct attribute
*import_attr
;
6514 struct die_info
*imported_die
, *child_die
;
6515 struct dwarf2_cu
*imported_cu
;
6516 const char *imported_name
;
6517 const char *imported_name_prefix
;
6518 const char *canonical_name
;
6519 const char *import_alias
;
6520 const char *imported_declaration
= NULL
;
6521 const char *import_prefix
;
6522 VEC (const_char_ptr
) *excludes
= NULL
;
6523 struct cleanup
*cleanups
;
6527 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6528 if (import_attr
== NULL
)
6530 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6531 dwarf_tag_name (die
->tag
));
6536 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6537 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6538 if (imported_name
== NULL
)
6540 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6542 The import in the following code:
6556 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6557 <52> DW_AT_decl_file : 1
6558 <53> DW_AT_decl_line : 6
6559 <54> DW_AT_import : <0x75>
6560 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6562 <5b> DW_AT_decl_file : 1
6563 <5c> DW_AT_decl_line : 2
6564 <5d> DW_AT_type : <0x6e>
6566 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6567 <76> DW_AT_byte_size : 4
6568 <77> DW_AT_encoding : 5 (signed)
6570 imports the wrong die ( 0x75 instead of 0x58 ).
6571 This case will be ignored until the gcc bug is fixed. */
6575 /* Figure out the local name after import. */
6576 import_alias
= dwarf2_name (die
, cu
);
6578 /* Figure out where the statement is being imported to. */
6579 import_prefix
= determine_prefix (die
, cu
);
6581 /* Figure out what the scope of the imported die is and prepend it
6582 to the name of the imported die. */
6583 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6585 if (imported_die
->tag
!= DW_TAG_namespace
6586 && imported_die
->tag
!= DW_TAG_module
)
6588 imported_declaration
= imported_name
;
6589 canonical_name
= imported_name_prefix
;
6591 else if (strlen (imported_name_prefix
) > 0)
6593 temp
= alloca (strlen (imported_name_prefix
)
6594 + 2 + strlen (imported_name
) + 1);
6595 strcpy (temp
, imported_name_prefix
);
6596 strcat (temp
, "::");
6597 strcat (temp
, imported_name
);
6598 canonical_name
= temp
;
6601 canonical_name
= imported_name
;
6603 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6605 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6606 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6607 child_die
= sibling_die (child_die
))
6609 /* DWARF-4: A Fortran use statement with a “rename list” may be
6610 represented by an imported module entry with an import attribute
6611 referring to the module and owned entries corresponding to those
6612 entities that are renamed as part of being imported. */
6614 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6616 complaint (&symfile_complaints
,
6617 _("child DW_TAG_imported_declaration expected "
6618 "- DIE at 0x%x [in module %s]"),
6619 child_die
->offset
.sect_off
, objfile
->name
);
6623 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6624 if (import_attr
== NULL
)
6626 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6627 dwarf_tag_name (child_die
->tag
));
6632 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6634 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6635 if (imported_name
== NULL
)
6637 complaint (&symfile_complaints
,
6638 _("child DW_TAG_imported_declaration has unknown "
6639 "imported name - DIE at 0x%x [in module %s]"),
6640 child_die
->offset
.sect_off
, objfile
->name
);
6644 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6646 process_die (child_die
, cu
);
6649 cp_add_using_directive (import_prefix
,
6652 imported_declaration
,
6654 &objfile
->objfile_obstack
);
6656 do_cleanups (cleanups
);
6659 /* Cleanup function for read_file_scope. */
6662 free_cu_line_header (void *arg
)
6664 struct dwarf2_cu
*cu
= arg
;
6666 free_line_header (cu
->line_header
);
6667 cu
->line_header
= NULL
;
6671 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6672 char **name
, char **comp_dir
)
6674 struct attribute
*attr
;
6679 /* Find the filename. Do not use dwarf2_name here, since the filename
6680 is not a source language identifier. */
6681 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6684 *name
= DW_STRING (attr
);
6687 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6689 *comp_dir
= DW_STRING (attr
);
6690 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6692 *comp_dir
= ldirname (*name
);
6693 if (*comp_dir
!= NULL
)
6694 make_cleanup (xfree
, *comp_dir
);
6696 if (*comp_dir
!= NULL
)
6698 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6699 directory, get rid of it. */
6700 char *cp
= strchr (*comp_dir
, ':');
6702 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6707 *name
= "<unknown>";
6710 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6711 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6712 COMP_DIR is the compilation directory.
6713 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6716 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6717 const char *comp_dir
, int want_line_info
)
6719 struct attribute
*attr
;
6721 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6724 unsigned int line_offset
= DW_UNSND (attr
);
6725 struct line_header
*line_header
6726 = dwarf_decode_line_header (line_offset
, cu
);
6730 cu
->line_header
= line_header
;
6731 make_cleanup (free_cu_line_header
, cu
);
6732 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6737 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6740 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6742 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6743 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6744 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6745 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6746 struct attribute
*attr
;
6748 char *comp_dir
= NULL
;
6749 struct die_info
*child_die
;
6750 bfd
*abfd
= objfile
->obfd
;
6753 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6755 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6757 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6758 from finish_block. */
6759 if (lowpc
== ((CORE_ADDR
) -1))
6764 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6766 prepare_one_comp_unit (cu
, die
, cu
->language
);
6768 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6769 standardised yet. As a workaround for the language detection we fall
6770 back to the DW_AT_producer string. */
6771 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6772 cu
->language
= language_opencl
;
6774 /* Similar hack for Go. */
6775 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6776 set_cu_language (DW_LANG_Go
, cu
);
6778 /* We assume that we're processing GCC output. */
6779 processing_gcc_compilation
= 2;
6781 processing_has_namespace_info
= 0;
6783 start_symtab (name
, comp_dir
, lowpc
);
6784 record_debugformat ("DWARF 2");
6785 record_producer (cu
->producer
);
6787 /* Decode line number information if present. We do this before
6788 processing child DIEs, so that the line header table is available
6789 for DW_AT_decl_file. */
6790 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6792 /* Process all dies in compilation unit. */
6793 if (die
->child
!= NULL
)
6795 child_die
= die
->child
;
6796 while (child_die
&& child_die
->tag
)
6798 process_die (child_die
, cu
);
6799 child_die
= sibling_die (child_die
);
6803 /* Decode macro information, if present. Dwarf 2 macro information
6804 refers to information in the line number info statement program
6805 header, so we can only read it if we've read the header
6807 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6808 if (attr
&& cu
->line_header
)
6810 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6811 complaint (&symfile_complaints
,
6812 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6814 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
6818 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6819 if (attr
&& cu
->line_header
)
6821 unsigned int macro_offset
= DW_UNSND (attr
);
6823 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
6827 do_cleanups (back_to
);
6830 /* Process DW_TAG_type_unit.
6831 For TUs we want to skip the first top level sibling if it's not the
6832 actual type being defined by this TU. In this case the first top
6833 level sibling is there to provide context only. */
6836 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6838 struct objfile
*objfile
= cu
->objfile
;
6839 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6841 struct attribute
*attr
;
6843 char *comp_dir
= NULL
;
6844 struct die_info
*child_die
;
6845 bfd
*abfd
= objfile
->obfd
;
6847 /* start_symtab needs a low pc, but we don't really have one.
6848 Do what read_file_scope would do in the absence of such info. */
6849 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6851 /* Find the filename. Do not use dwarf2_name here, since the filename
6852 is not a source language identifier. */
6853 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6855 name
= DW_STRING (attr
);
6857 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6859 comp_dir
= DW_STRING (attr
);
6860 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6862 comp_dir
= ldirname (name
);
6863 if (comp_dir
!= NULL
)
6864 make_cleanup (xfree
, comp_dir
);
6870 prepare_one_comp_unit (cu
, die
, language_minimal
);
6872 /* We assume that we're processing GCC output. */
6873 processing_gcc_compilation
= 2;
6875 processing_has_namespace_info
= 0;
6877 start_symtab (name
, comp_dir
, lowpc
);
6878 record_debugformat ("DWARF 2");
6879 record_producer (cu
->producer
);
6881 /* Decode line number information if present. We do this before
6882 processing child DIEs, so that the line header table is available
6883 for DW_AT_decl_file.
6884 We don't need the pc/line-number mapping for type units. */
6885 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6887 /* Process the dies in the type unit. */
6888 if (die
->child
== NULL
)
6890 dump_die_for_error (die
);
6891 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6892 bfd_get_filename (abfd
));
6895 child_die
= die
->child
;
6897 while (child_die
&& child_die
->tag
)
6899 process_die (child_die
, cu
);
6901 child_die
= sibling_die (child_die
);
6904 do_cleanups (back_to
);
6910 hash_dwo_file (const void *item
)
6912 const struct dwo_file
*dwo_file
= item
;
6914 return htab_hash_string (dwo_file
->dwo_name
);
6918 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6920 const struct dwo_file
*lhs
= item_lhs
;
6921 const struct dwo_file
*rhs
= item_rhs
;
6923 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6926 /* Allocate a hash table for DWO files. */
6929 allocate_dwo_file_hash_table (void)
6931 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6933 return htab_create_alloc_ex (41,
6937 &objfile
->objfile_obstack
,
6938 hashtab_obstack_allocate
,
6939 dummy_obstack_deallocate
);
6943 hash_dwo_unit (const void *item
)
6945 const struct dwo_unit
*dwo_unit
= item
;
6947 /* This drops the top 32 bits of the id, but is ok for a hash. */
6948 return dwo_unit
->signature
;
6952 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6954 const struct dwo_unit
*lhs
= item_lhs
;
6955 const struct dwo_unit
*rhs
= item_rhs
;
6957 /* The signature is assumed to be unique within the DWO file.
6958 So while object file CU dwo_id's always have the value zero,
6959 that's OK, assuming each object file DWO file has only one CU,
6960 and that's the rule for now. */
6961 return lhs
->signature
== rhs
->signature
;
6964 /* Allocate a hash table for DWO CUs,TUs.
6965 There is one of these tables for each of CUs,TUs for each DWO file. */
6968 allocate_dwo_unit_table (struct objfile
*objfile
)
6970 /* Start out with a pretty small number.
6971 Generally DWO files contain only one CU and maybe some TUs. */
6972 return htab_create_alloc_ex (3,
6976 &objfile
->objfile_obstack
,
6977 hashtab_obstack_allocate
,
6978 dummy_obstack_deallocate
);
6981 /* This function is mapped across the sections and remembers the offset and
6982 size of each of the DWO debugging sections we are interested in. */
6985 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6987 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6988 const struct dwo_section_names
*names
= &dwo_section_names
;
6990 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6992 dwo_file
->sections
.abbrev
.asection
= sectp
;
6993 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6995 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6997 dwo_file
->sections
.info
.asection
= sectp
;
6998 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
7000 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
7002 dwo_file
->sections
.line
.asection
= sectp
;
7003 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
7005 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
7007 dwo_file
->sections
.loc
.asection
= sectp
;
7008 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
7010 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
7012 dwo_file
->sections
.macinfo
.asection
= sectp
;
7013 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
7015 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7017 dwo_file
->sections
.macro
.asection
= sectp
;
7018 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7020 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7022 dwo_file
->sections
.str
.asection
= sectp
;
7023 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7025 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7027 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7028 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7030 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7032 struct dwarf2_section_info type_section
;
7034 memset (&type_section
, 0, sizeof (type_section
));
7035 type_section
.asection
= sectp
;
7036 type_section
.size
= bfd_get_section_size (sectp
);
7037 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7042 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7044 struct create_dwo_info_table_data
7046 struct dwo_file
*dwo_file
;
7050 /* die_reader_func for create_debug_info_hash_table. */
7053 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7055 struct die_info
*comp_unit_die
,
7059 struct dwarf2_cu
*cu
= reader
->cu
;
7060 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7061 sect_offset offset
= cu
->per_cu
->offset
;
7062 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7063 struct create_dwo_info_table_data
*data
= datap
;
7064 struct dwo_file
*dwo_file
= data
->dwo_file
;
7065 htab_t cu_htab
= data
->cu_htab
;
7067 struct attribute
*attr
;
7068 struct dwo_unit
*dwo_unit
;
7070 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7073 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
7074 " its dwo_id [in module %s]"),
7075 offset
.sect_off
, dwo_file
->dwo_name
);
7079 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
7080 dwo_unit
->dwo_file
= dwo_file
;
7081 dwo_unit
->signature
= DW_UNSND (attr
);
7082 dwo_unit
->info_or_types_section
= section
;
7083 dwo_unit
->offset
= offset
;
7084 dwo_unit
->length
= cu
->per_cu
->length
;
7086 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7087 gdb_assert (slot
!= NULL
);
7090 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7092 complaint (&symfile_complaints
,
7093 _("debug entry at offset 0x%x is duplicate to the entry at"
7094 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7095 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7096 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7097 dwo_file
->dwo_name
);
7102 if (dwarf2_die_debug
)
7103 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7105 phex (dwo_unit
->signature
,
7106 sizeof (dwo_unit
->signature
)));
7109 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7112 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7114 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7115 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7118 gdb_byte
*info_ptr
, *end_ptr
;
7119 struct create_dwo_info_table_data create_dwo_info_table_data
;
7121 dwarf2_read_section (objfile
, section
);
7122 info_ptr
= section
->buffer
;
7124 if (info_ptr
== NULL
)
7127 /* We can't set abfd until now because the section may be empty or
7128 not present, in which case section->asection will be NULL. */
7129 abfd
= section
->asection
->owner
;
7131 if (dwarf2_die_debug
)
7132 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
7133 bfd_get_filename (abfd
));
7135 cu_htab
= allocate_dwo_unit_table (objfile
);
7137 create_dwo_info_table_data
.dwo_file
= dwo_file
;
7138 create_dwo_info_table_data
.cu_htab
= cu_htab
;
7140 end_ptr
= info_ptr
+ section
->size
;
7141 while (info_ptr
< end_ptr
)
7143 struct dwarf2_per_cu_data per_cu
;
7145 memset (&per_cu
, 0, sizeof (per_cu
));
7146 per_cu
.objfile
= objfile
;
7147 per_cu
.is_debug_types
= 0;
7148 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
7149 per_cu
.info_or_types_section
= section
;
7151 init_cutu_and_read_dies_no_follow (&per_cu
,
7152 &dwo_file
->sections
.abbrev
,
7154 create_debug_info_hash_table_reader
,
7155 &create_dwo_info_table_data
);
7157 info_ptr
+= per_cu
.length
;
7163 /* Subroutine of open_dwo_file to simplify it.
7164 Open the file specified by FILE_NAME and hand it off to BFD for
7165 preliminary analysis. Return a newly initialized bfd *, which
7166 includes a canonicalized copy of FILE_NAME.
7167 In case of trouble, return NULL.
7168 NOTE: This function is derived from symfile_bfd_open. */
7171 try_open_dwo_file (const char *file_name
)
7175 char *absolute_name
;
7177 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
7178 O_RDONLY
| O_BINARY
, &absolute_name
);
7182 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
7185 xfree (absolute_name
);
7188 bfd_set_cacheable (sym_bfd
, 1);
7190 if (!bfd_check_format (sym_bfd
, bfd_object
))
7192 bfd_close (sym_bfd
); /* This also closes desc. */
7193 xfree (absolute_name
);
7197 /* bfd_usrdata exists for applications and libbfd must not touch it. */
7198 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
7203 /* Try to open DWO file DWO_NAME.
7204 COMP_DIR is the DW_AT_comp_dir attribute.
7205 The result is the bfd handle of the file.
7206 If there is a problem finding or opening the file, return NULL.
7207 Upon success, the canonicalized path of the file is stored in the bfd,
7208 same as symfile_bfd_open. */
7211 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
7215 if (IS_ABSOLUTE_PATH (dwo_name
))
7216 return try_open_dwo_file (dwo_name
);
7218 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
7220 if (comp_dir
!= NULL
)
7222 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
7224 /* NOTE: If comp_dir is a relative path, this will also try the
7225 search path, which seems useful. */
7226 abfd
= try_open_dwo_file (path_to_try
);
7227 xfree (path_to_try
);
7232 /* That didn't work, try debug-file-directory, which, despite its name,
7233 is a list of paths. */
7235 if (*debug_file_directory
== '\0')
7238 return try_open_dwo_file (dwo_name
);
7241 /* Initialize the use of the DWO file specified by DWO_NAME. */
7243 static struct dwo_file
*
7244 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7246 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7247 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7250 struct cleanup
*cleanups
;
7252 if (dwarf2_die_debug
)
7253 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7255 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7258 dwo_file
->dwo_name
= dwo_name
;
7259 dwo_file
->dwo_bfd
= abfd
;
7261 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7263 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7265 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7267 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7268 dwo_file
->sections
.types
);
7270 discard_cleanups (cleanups
);
7275 /* Lookup DWO file DWO_NAME. */
7277 static struct dwo_file
*
7278 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7280 struct dwo_file
*dwo_file
;
7281 struct dwo_file find_entry
;
7284 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7285 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7287 /* Have we already seen this DWO file? */
7288 find_entry
.dwo_name
= dwo_name
;
7289 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7291 /* If not, read it in and build a table of the DWOs it contains. */
7293 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7295 /* NOTE: This will be NULL if unable to open the file. */
7301 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7302 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7303 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7304 nomenclature as TUs).
7305 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7306 (dwo_id mismatch or couldn't find the DWO file). */
7308 static struct dwo_unit
*
7309 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7310 char *dwo_name
, const char *comp_dir
,
7313 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7314 struct dwo_file
*dwo_file
;
7316 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7317 if (dwo_file
== NULL
)
7320 /* Look up the DWO using its signature(dwo_id). */
7322 if (dwo_file
->cus
!= NULL
)
7324 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7326 find_dwo_cu
.signature
= signature
;
7327 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7333 /* We didn't find it. This must mean a dwo_id mismatch. */
7335 complaint (&symfile_complaints
,
7336 _("Could not find DWO CU referenced by CU at offset 0x%x"
7338 this_cu
->offset
.sect_off
, objfile
->name
);
7342 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7343 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7344 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7345 (dwo_id mismatch or couldn't find the DWO file). */
7347 static struct dwo_unit
*
7348 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7349 char *dwo_name
, const char *comp_dir
)
7351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7352 struct dwo_file
*dwo_file
;
7354 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7355 if (dwo_file
== NULL
)
7358 /* Look up the DWO using its signature(dwo_id). */
7360 if (dwo_file
->tus
!= NULL
)
7362 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7364 find_dwo_tu
.signature
= this_tu
->signature
;
7365 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7371 /* We didn't find it. This must mean a dwo_id mismatch. */
7373 complaint (&symfile_complaints
,
7374 _("Could not find DWO TU referenced by TU at offset 0x%x"
7376 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7380 /* Free all resources associated with DWO_FILE.
7381 Close the DWO file and munmap the sections.
7382 All memory should be on the objfile obstack. */
7385 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7388 struct dwarf2_section_info
*section
;
7390 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7391 bfd_close (dwo_file
->dwo_bfd
);
7393 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7394 munmap_section_buffer (&dwo_file
->sections
.info
);
7395 munmap_section_buffer (&dwo_file
->sections
.line
);
7396 munmap_section_buffer (&dwo_file
->sections
.loc
);
7397 munmap_section_buffer (&dwo_file
->sections
.str
);
7398 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7401 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7404 munmap_section_buffer (section
);
7406 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7409 /* Wrapper for free_dwo_file for use in cleanups. */
7412 free_dwo_file_cleanup (void *arg
)
7414 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7415 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7417 free_dwo_file (dwo_file
, objfile
);
7420 /* Traversal function for free_dwo_files. */
7423 free_dwo_file_from_slot (void **slot
, void *info
)
7425 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7426 struct objfile
*objfile
= (struct objfile
*) info
;
7428 free_dwo_file (dwo_file
, objfile
);
7433 /* Free all resources associated with DWO_FILES. */
7436 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7438 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7441 /* Read in various DIEs. */
7443 /* qsort helper for inherit_abstract_dies. */
7446 unsigned_int_compar (const void *ap
, const void *bp
)
7448 unsigned int a
= *(unsigned int *) ap
;
7449 unsigned int b
= *(unsigned int *) bp
;
7451 return (a
> b
) - (b
> a
);
7454 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7455 Inherit only the children of the DW_AT_abstract_origin DIE not being
7456 already referenced by DW_AT_abstract_origin from the children of the
7460 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7462 struct die_info
*child_die
;
7463 unsigned die_children_count
;
7464 /* CU offsets which were referenced by children of the current DIE. */
7465 sect_offset
*offsets
;
7466 sect_offset
*offsets_end
, *offsetp
;
7467 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7468 struct die_info
*origin_die
;
7469 /* Iterator of the ORIGIN_DIE children. */
7470 struct die_info
*origin_child_die
;
7471 struct cleanup
*cleanups
;
7472 struct attribute
*attr
;
7473 struct dwarf2_cu
*origin_cu
;
7474 struct pending
**origin_previous_list_in_scope
;
7476 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7480 /* Note that following die references may follow to a die in a
7484 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7486 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7488 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7489 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7491 if (die
->tag
!= origin_die
->tag
7492 && !(die
->tag
== DW_TAG_inlined_subroutine
7493 && origin_die
->tag
== DW_TAG_subprogram
))
7494 complaint (&symfile_complaints
,
7495 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7496 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7498 child_die
= die
->child
;
7499 die_children_count
= 0;
7500 while (child_die
&& child_die
->tag
)
7502 child_die
= sibling_die (child_die
);
7503 die_children_count
++;
7505 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7506 cleanups
= make_cleanup (xfree
, offsets
);
7508 offsets_end
= offsets
;
7509 child_die
= die
->child
;
7510 while (child_die
&& child_die
->tag
)
7512 /* For each CHILD_DIE, find the corresponding child of
7513 ORIGIN_DIE. If there is more than one layer of
7514 DW_AT_abstract_origin, follow them all; there shouldn't be,
7515 but GCC versions at least through 4.4 generate this (GCC PR
7517 struct die_info
*child_origin_die
= child_die
;
7518 struct dwarf2_cu
*child_origin_cu
= cu
;
7522 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7526 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7530 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7531 counterpart may exist. */
7532 if (child_origin_die
!= child_die
)
7534 if (child_die
->tag
!= child_origin_die
->tag
7535 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7536 && child_origin_die
->tag
== DW_TAG_subprogram
))
7537 complaint (&symfile_complaints
,
7538 _("Child DIE 0x%x and its abstract origin 0x%x have "
7539 "different tags"), child_die
->offset
.sect_off
,
7540 child_origin_die
->offset
.sect_off
);
7541 if (child_origin_die
->parent
!= origin_die
)
7542 complaint (&symfile_complaints
,
7543 _("Child DIE 0x%x and its abstract origin 0x%x have "
7544 "different parents"), child_die
->offset
.sect_off
,
7545 child_origin_die
->offset
.sect_off
);
7547 *offsets_end
++ = child_origin_die
->offset
;
7549 child_die
= sibling_die (child_die
);
7551 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7552 unsigned_int_compar
);
7553 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7554 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7555 complaint (&symfile_complaints
,
7556 _("Multiple children of DIE 0x%x refer "
7557 "to DIE 0x%x as their abstract origin"),
7558 die
->offset
.sect_off
, offsetp
->sect_off
);
7561 origin_child_die
= origin_die
->child
;
7562 while (origin_child_die
&& origin_child_die
->tag
)
7564 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7565 while (offsetp
< offsets_end
7566 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7568 if (offsetp
>= offsets_end
7569 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7571 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7572 process_die (origin_child_die
, origin_cu
);
7574 origin_child_die
= sibling_die (origin_child_die
);
7576 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7578 do_cleanups (cleanups
);
7582 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7584 struct objfile
*objfile
= cu
->objfile
;
7585 struct context_stack
*new;
7588 struct die_info
*child_die
;
7589 struct attribute
*attr
, *call_line
, *call_file
;
7592 struct block
*block
;
7593 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7594 VEC (symbolp
) *template_args
= NULL
;
7595 struct template_symbol
*templ_func
= NULL
;
7599 /* If we do not have call site information, we can't show the
7600 caller of this inlined function. That's too confusing, so
7601 only use the scope for local variables. */
7602 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7603 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7604 if (call_line
== NULL
|| call_file
== NULL
)
7606 read_lexical_block_scope (die
, cu
);
7611 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7613 name
= dwarf2_name (die
, cu
);
7615 /* Ignore functions with missing or empty names. These are actually
7616 illegal according to the DWARF standard. */
7619 complaint (&symfile_complaints
,
7620 _("missing name for subprogram DIE at %d"),
7621 die
->offset
.sect_off
);
7625 /* Ignore functions with missing or invalid low and high pc attributes. */
7626 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7628 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7629 if (!attr
|| !DW_UNSND (attr
))
7630 complaint (&symfile_complaints
,
7631 _("cannot get low and high bounds "
7632 "for subprogram DIE at %d"),
7633 die
->offset
.sect_off
);
7640 /* If we have any template arguments, then we must allocate a
7641 different sort of symbol. */
7642 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7644 if (child_die
->tag
== DW_TAG_template_type_param
7645 || child_die
->tag
== DW_TAG_template_value_param
)
7647 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7648 struct template_symbol
);
7649 templ_func
->base
.is_cplus_template_function
= 1;
7654 new = push_context (0, lowpc
);
7655 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7656 (struct symbol
*) templ_func
);
7658 /* If there is a location expression for DW_AT_frame_base, record
7660 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7662 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7663 expression is being recorded directly in the function's symbol
7664 and not in a separate frame-base object. I guess this hack is
7665 to avoid adding some sort of frame-base adjunct/annex to the
7666 function's symbol :-(. The problem with doing this is that it
7667 results in a function symbol with a location expression that
7668 has nothing to do with the location of the function, ouch! The
7669 relationship should be: a function's symbol has-a frame base; a
7670 frame-base has-a location expression. */
7671 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7673 cu
->list_in_scope
= &local_symbols
;
7675 if (die
->child
!= NULL
)
7677 child_die
= die
->child
;
7678 while (child_die
&& child_die
->tag
)
7680 if (child_die
->tag
== DW_TAG_template_type_param
7681 || child_die
->tag
== DW_TAG_template_value_param
)
7683 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7686 VEC_safe_push (symbolp
, template_args
, arg
);
7689 process_die (child_die
, cu
);
7690 child_die
= sibling_die (child_die
);
7694 inherit_abstract_dies (die
, cu
);
7696 /* If we have a DW_AT_specification, we might need to import using
7697 directives from the context of the specification DIE. See the
7698 comment in determine_prefix. */
7699 if (cu
->language
== language_cplus
7700 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7702 struct dwarf2_cu
*spec_cu
= cu
;
7703 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7707 child_die
= spec_die
->child
;
7708 while (child_die
&& child_die
->tag
)
7710 if (child_die
->tag
== DW_TAG_imported_module
)
7711 process_die (child_die
, spec_cu
);
7712 child_die
= sibling_die (child_die
);
7715 /* In some cases, GCC generates specification DIEs that
7716 themselves contain DW_AT_specification attributes. */
7717 spec_die
= die_specification (spec_die
, &spec_cu
);
7721 new = pop_context ();
7722 /* Make a block for the local symbols within. */
7723 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7724 lowpc
, highpc
, objfile
);
7726 /* For C++, set the block's scope. */
7727 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7728 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7729 determine_prefix (die
, cu
),
7730 processing_has_namespace_info
);
7732 /* If we have address ranges, record them. */
7733 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7735 /* Attach template arguments to function. */
7736 if (! VEC_empty (symbolp
, template_args
))
7738 gdb_assert (templ_func
!= NULL
);
7740 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7741 templ_func
->template_arguments
7742 = obstack_alloc (&objfile
->objfile_obstack
,
7743 (templ_func
->n_template_arguments
7744 * sizeof (struct symbol
*)));
7745 memcpy (templ_func
->template_arguments
,
7746 VEC_address (symbolp
, template_args
),
7747 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7748 VEC_free (symbolp
, template_args
);
7751 /* In C++, we can have functions nested inside functions (e.g., when
7752 a function declares a class that has methods). This means that
7753 when we finish processing a function scope, we may need to go
7754 back to building a containing block's symbol lists. */
7755 local_symbols
= new->locals
;
7756 param_symbols
= new->params
;
7757 using_directives
= new->using_directives
;
7759 /* If we've finished processing a top-level function, subsequent
7760 symbols go in the file symbol list. */
7761 if (outermost_context_p ())
7762 cu
->list_in_scope
= &file_symbols
;
7765 /* Process all the DIES contained within a lexical block scope. Start
7766 a new scope, process the dies, and then close the scope. */
7769 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7771 struct objfile
*objfile
= cu
->objfile
;
7772 struct context_stack
*new;
7773 CORE_ADDR lowpc
, highpc
;
7774 struct die_info
*child_die
;
7777 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7779 /* Ignore blocks with missing or invalid low and high pc attributes. */
7780 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7781 as multiple lexical blocks? Handling children in a sane way would
7782 be nasty. Might be easier to properly extend generic blocks to
7784 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7789 push_context (0, lowpc
);
7790 if (die
->child
!= NULL
)
7792 child_die
= die
->child
;
7793 while (child_die
&& child_die
->tag
)
7795 process_die (child_die
, cu
);
7796 child_die
= sibling_die (child_die
);
7799 new = pop_context ();
7801 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7804 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7807 /* Note that recording ranges after traversing children, as we
7808 do here, means that recording a parent's ranges entails
7809 walking across all its children's ranges as they appear in
7810 the address map, which is quadratic behavior.
7812 It would be nicer to record the parent's ranges before
7813 traversing its children, simply overriding whatever you find
7814 there. But since we don't even decide whether to create a
7815 block until after we've traversed its children, that's hard
7817 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7819 local_symbols
= new->locals
;
7820 using_directives
= new->using_directives
;
7823 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7826 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7828 struct objfile
*objfile
= cu
->objfile
;
7829 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7830 CORE_ADDR pc
, baseaddr
;
7831 struct attribute
*attr
;
7832 struct call_site
*call_site
, call_site_local
;
7835 struct die_info
*child_die
;
7837 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7839 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7842 complaint (&symfile_complaints
,
7843 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7844 "DIE 0x%x [in module %s]"),
7845 die
->offset
.sect_off
, objfile
->name
);
7848 pc
= DW_ADDR (attr
) + baseaddr
;
7850 if (cu
->call_site_htab
== NULL
)
7851 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7852 NULL
, &objfile
->objfile_obstack
,
7853 hashtab_obstack_allocate
, NULL
);
7854 call_site_local
.pc
= pc
;
7855 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7858 complaint (&symfile_complaints
,
7859 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7860 "DIE 0x%x [in module %s]"),
7861 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7865 /* Count parameters at the caller. */
7868 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7869 child_die
= sibling_die (child_die
))
7871 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7873 complaint (&symfile_complaints
,
7874 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7875 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7876 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7883 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7884 (sizeof (*call_site
)
7885 + (sizeof (*call_site
->parameter
)
7888 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7891 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7893 struct die_info
*func_die
;
7895 /* Skip also over DW_TAG_inlined_subroutine. */
7896 for (func_die
= die
->parent
;
7897 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7898 && func_die
->tag
!= DW_TAG_subroutine_type
;
7899 func_die
= func_die
->parent
);
7901 /* DW_AT_GNU_all_call_sites is a superset
7902 of DW_AT_GNU_all_tail_call_sites. */
7904 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7905 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7907 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7908 not complete. But keep CALL_SITE for look ups via call_site_htab,
7909 both the initial caller containing the real return address PC and
7910 the final callee containing the current PC of a chain of tail
7911 calls do not need to have the tail call list complete. But any
7912 function candidate for a virtual tail call frame searched via
7913 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7914 determined unambiguously. */
7918 struct type
*func_type
= NULL
;
7921 func_type
= get_die_type (func_die
, cu
);
7922 if (func_type
!= NULL
)
7924 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7926 /* Enlist this call site to the function. */
7927 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7928 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7931 complaint (&symfile_complaints
,
7932 _("Cannot find function owning DW_TAG_GNU_call_site "
7933 "DIE 0x%x [in module %s]"),
7934 die
->offset
.sect_off
, objfile
->name
);
7938 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7940 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7941 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7942 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7943 /* Keep NULL DWARF_BLOCK. */;
7944 else if (attr_form_is_block (attr
))
7946 struct dwarf2_locexpr_baton
*dlbaton
;
7948 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7949 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7950 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7951 dlbaton
->per_cu
= cu
->per_cu
;
7953 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7955 else if (is_ref_attr (attr
))
7957 struct dwarf2_cu
*target_cu
= cu
;
7958 struct die_info
*target_die
;
7960 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7961 gdb_assert (target_cu
->objfile
== objfile
);
7962 if (die_is_declaration (target_die
, target_cu
))
7964 const char *target_physname
;
7966 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7967 if (target_physname
== NULL
)
7968 complaint (&symfile_complaints
,
7969 _("DW_AT_GNU_call_site_target target DIE has invalid "
7970 "physname, for referencing DIE 0x%x [in module %s]"),
7971 die
->offset
.sect_off
, objfile
->name
);
7973 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7979 /* DW_AT_entry_pc should be preferred. */
7980 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7981 complaint (&symfile_complaints
,
7982 _("DW_AT_GNU_call_site_target target DIE has invalid "
7983 "low pc, for referencing DIE 0x%x [in module %s]"),
7984 die
->offset
.sect_off
, objfile
->name
);
7986 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7990 complaint (&symfile_complaints
,
7991 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7992 "block nor reference, for DIE 0x%x [in module %s]"),
7993 die
->offset
.sect_off
, objfile
->name
);
7995 call_site
->per_cu
= cu
->per_cu
;
7997 for (child_die
= die
->child
;
7998 child_die
&& child_die
->tag
;
7999 child_die
= sibling_die (child_die
))
8001 struct call_site_parameter
*parameter
;
8002 struct attribute
*loc
, *origin
;
8004 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8006 /* Already printed the complaint above. */
8010 gdb_assert (call_site
->parameter_count
< nparams
);
8011 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8013 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8014 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8015 register is contained in DW_AT_GNU_call_site_value. */
8017 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8018 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8019 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8023 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8024 offset
= dwarf2_get_ref_die_offset (origin
);
8025 gdb_assert (offset
.sect_off
>= cu
->header
.offset
.sect_off
);
8026 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8027 - cu
->header
.offset
.sect_off
);
8029 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8031 complaint (&symfile_complaints
,
8032 _("No DW_FORM_block* DW_AT_location for "
8033 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8034 child_die
->offset
.sect_off
, objfile
->name
);
8039 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8040 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8041 if (parameter
->u
.dwarf_reg
!= -1)
8042 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8043 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8044 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8045 ¶meter
->u
.fb_offset
))
8046 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8049 complaint (&symfile_complaints
,
8050 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8051 "for DW_FORM_block* DW_AT_location is supported for "
8052 "DW_TAG_GNU_call_site child DIE 0x%x "
8054 child_die
->offset
.sect_off
, objfile
->name
);
8059 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
8060 if (!attr_form_is_block (attr
))
8062 complaint (&symfile_complaints
,
8063 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
8064 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8065 child_die
->offset
.sect_off
, objfile
->name
);
8068 parameter
->value
= DW_BLOCK (attr
)->data
;
8069 parameter
->value_size
= DW_BLOCK (attr
)->size
;
8071 /* Parameters are not pre-cleared by memset above. */
8072 parameter
->data_value
= NULL
;
8073 parameter
->data_value_size
= 0;
8074 call_site
->parameter_count
++;
8076 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
8079 if (!attr_form_is_block (attr
))
8080 complaint (&symfile_complaints
,
8081 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
8082 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8083 child_die
->offset
.sect_off
, objfile
->name
);
8086 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8087 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8093 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8094 Return 1 if the attributes are present and valid, otherwise, return 0.
8095 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8098 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8099 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8100 struct partial_symtab
*ranges_pst
)
8102 struct objfile
*objfile
= cu
->objfile
;
8103 struct comp_unit_head
*cu_header
= &cu
->header
;
8104 bfd
*obfd
= objfile
->obfd
;
8105 unsigned int addr_size
= cu_header
->addr_size
;
8106 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8107 /* Base address selection entry. */
8118 found_base
= cu
->base_known
;
8119 base
= cu
->base_address
;
8121 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
8122 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8124 complaint (&symfile_complaints
,
8125 _("Offset %d out of bounds for DW_AT_ranges attribute"),
8129 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8131 /* Read in the largest possible address. */
8132 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
8133 if ((marker
& mask
) == mask
)
8135 /* If we found the largest possible address, then
8136 read the base address. */
8137 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8138 buffer
+= 2 * addr_size
;
8139 offset
+= 2 * addr_size
;
8145 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8149 CORE_ADDR range_beginning
, range_end
;
8151 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
8152 buffer
+= addr_size
;
8153 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
8154 buffer
+= addr_size
;
8155 offset
+= 2 * addr_size
;
8157 /* An end of list marker is a pair of zero addresses. */
8158 if (range_beginning
== 0 && range_end
== 0)
8159 /* Found the end of list entry. */
8162 /* Each base address selection entry is a pair of 2 values.
8163 The first is the largest possible address, the second is
8164 the base address. Check for a base address here. */
8165 if ((range_beginning
& mask
) == mask
)
8167 /* If we found the largest possible address, then
8168 read the base address. */
8169 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8176 /* We have no valid base address for the ranges
8178 complaint (&symfile_complaints
,
8179 _("Invalid .debug_ranges data (no base address)"));
8183 if (range_beginning
> range_end
)
8185 /* Inverted range entries are invalid. */
8186 complaint (&symfile_complaints
,
8187 _("Invalid .debug_ranges data (inverted range)"));
8191 /* Empty range entries have no effect. */
8192 if (range_beginning
== range_end
)
8195 range_beginning
+= base
;
8198 if (ranges_pst
!= NULL
)
8199 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8200 range_beginning
+ baseaddr
,
8201 range_end
- 1 + baseaddr
,
8204 /* FIXME: This is recording everything as a low-high
8205 segment of consecutive addresses. We should have a
8206 data structure for discontiguous block ranges
8210 low
= range_beginning
;
8216 if (range_beginning
< low
)
8217 low
= range_beginning
;
8218 if (range_end
> high
)
8224 /* If the first entry is an end-of-list marker, the range
8225 describes an empty scope, i.e. no instructions. */
8231 *high_return
= high
;
8235 /* Get low and high pc attributes from a die. Return 1 if the attributes
8236 are present and valid, otherwise, return 0. Return -1 if the range is
8237 discontinuous, i.e. derived from DW_AT_ranges information. */
8240 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
8241 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
8242 struct partial_symtab
*pst
)
8244 struct attribute
*attr
;
8245 struct attribute
*attr_high
;
8250 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8253 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8256 low
= DW_ADDR (attr
);
8257 if (attr_high
->form
== DW_FORM_addr
8258 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8259 high
= DW_ADDR (attr_high
);
8261 high
= low
+ DW_UNSND (attr_high
);
8264 /* Found high w/o low attribute. */
8267 /* Found consecutive range of addresses. */
8272 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8275 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
8277 /* Value of the DW_AT_ranges attribute is the offset in the
8278 .debug_ranges section. */
8279 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
8281 /* Found discontinuous range of addresses. */
8286 /* read_partial_die has also the strict LOW < HIGH requirement. */
8290 /* When using the GNU linker, .gnu.linkonce. sections are used to
8291 eliminate duplicate copies of functions and vtables and such.
8292 The linker will arbitrarily choose one and discard the others.
8293 The AT_*_pc values for such functions refer to local labels in
8294 these sections. If the section from that file was discarded, the
8295 labels are not in the output, so the relocs get a value of 0.
8296 If this is a discarded function, mark the pc bounds as invalid,
8297 so that GDB will ignore it. */
8298 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8307 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8308 its low and high PC addresses. Do nothing if these addresses could not
8309 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8310 and HIGHPC to the high address if greater than HIGHPC. */
8313 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8314 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8315 struct dwarf2_cu
*cu
)
8317 CORE_ADDR low
, high
;
8318 struct die_info
*child
= die
->child
;
8320 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8322 *lowpc
= min (*lowpc
, low
);
8323 *highpc
= max (*highpc
, high
);
8326 /* If the language does not allow nested subprograms (either inside
8327 subprograms or lexical blocks), we're done. */
8328 if (cu
->language
!= language_ada
)
8331 /* Check all the children of the given DIE. If it contains nested
8332 subprograms, then check their pc bounds. Likewise, we need to
8333 check lexical blocks as well, as they may also contain subprogram
8335 while (child
&& child
->tag
)
8337 if (child
->tag
== DW_TAG_subprogram
8338 || child
->tag
== DW_TAG_lexical_block
)
8339 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8340 child
= sibling_die (child
);
8344 /* Get the low and high pc's represented by the scope DIE, and store
8345 them in *LOWPC and *HIGHPC. If the correct values can't be
8346 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8349 get_scope_pc_bounds (struct die_info
*die
,
8350 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8351 struct dwarf2_cu
*cu
)
8353 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8354 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8355 CORE_ADDR current_low
, current_high
;
8357 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8359 best_low
= current_low
;
8360 best_high
= current_high
;
8364 struct die_info
*child
= die
->child
;
8366 while (child
&& child
->tag
)
8368 switch (child
->tag
) {
8369 case DW_TAG_subprogram
:
8370 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8372 case DW_TAG_namespace
:
8374 /* FIXME: carlton/2004-01-16: Should we do this for
8375 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8376 that current GCC's always emit the DIEs corresponding
8377 to definitions of methods of classes as children of a
8378 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8379 the DIEs giving the declarations, which could be
8380 anywhere). But I don't see any reason why the
8381 standards says that they have to be there. */
8382 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8384 if (current_low
!= ((CORE_ADDR
) -1))
8386 best_low
= min (best_low
, current_low
);
8387 best_high
= max (best_high
, current_high
);
8395 child
= sibling_die (child
);
8400 *highpc
= best_high
;
8403 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8407 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8408 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8410 struct objfile
*objfile
= cu
->objfile
;
8411 struct attribute
*attr
;
8412 struct attribute
*attr_high
;
8414 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8417 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8420 CORE_ADDR low
= DW_ADDR (attr
);
8422 if (attr_high
->form
== DW_FORM_addr
8423 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8424 high
= DW_ADDR (attr_high
);
8426 high
= low
+ DW_UNSND (attr_high
);
8428 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8432 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8435 bfd
*obfd
= objfile
->obfd
;
8437 /* The value of the DW_AT_ranges attribute is the offset of the
8438 address range list in the .debug_ranges section. */
8439 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
8440 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8442 /* For some target architectures, but not others, the
8443 read_address function sign-extends the addresses it returns.
8444 To recognize base address selection entries, we need a
8446 unsigned int addr_size
= cu
->header
.addr_size
;
8447 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8449 /* The base address, to which the next pair is relative. Note
8450 that this 'base' is a DWARF concept: most entries in a range
8451 list are relative, to reduce the number of relocs against the
8452 debugging information. This is separate from this function's
8453 'baseaddr' argument, which GDB uses to relocate debugging
8454 information from a shared library based on the address at
8455 which the library was loaded. */
8456 CORE_ADDR base
= cu
->base_address
;
8457 int base_known
= cu
->base_known
;
8459 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8460 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8462 complaint (&symfile_complaints
,
8463 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8470 unsigned int bytes_read
;
8471 CORE_ADDR start
, end
;
8473 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8474 buffer
+= bytes_read
;
8475 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8476 buffer
+= bytes_read
;
8478 /* Did we find the end of the range list? */
8479 if (start
== 0 && end
== 0)
8482 /* Did we find a base address selection entry? */
8483 else if ((start
& base_select_mask
) == base_select_mask
)
8489 /* We found an ordinary address range. */
8494 complaint (&symfile_complaints
,
8495 _("Invalid .debug_ranges data "
8496 "(no base address)"));
8502 /* Inverted range entries are invalid. */
8503 complaint (&symfile_complaints
,
8504 _("Invalid .debug_ranges data "
8505 "(inverted range)"));
8509 /* Empty range entries have no effect. */
8513 record_block_range (block
,
8514 baseaddr
+ base
+ start
,
8515 baseaddr
+ base
+ end
- 1);
8521 /* Check whether the producer field indicates either of GCC < 4.6, or the
8522 Intel C/C++ compiler, and cache the result in CU. */
8525 check_producer (struct dwarf2_cu
*cu
)
8528 int major
, minor
, release
;
8530 if (cu
->producer
== NULL
)
8532 /* For unknown compilers expect their behavior is DWARF version
8535 GCC started to support .debug_types sections by -gdwarf-4 since
8536 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8537 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8538 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8539 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8541 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
8543 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8545 cs
= &cu
->producer
[strlen ("GNU ")];
8546 while (*cs
&& !isdigit (*cs
))
8548 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8550 /* Not recognized as GCC. */
8553 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
8555 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
8556 cu
->producer_is_icc
= 1;
8559 /* For other non-GCC compilers, expect their behavior is DWARF version
8563 cu
->checked_producer
= 1;
8566 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8567 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8568 during 4.6.0 experimental. */
8571 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8573 if (!cu
->checked_producer
)
8574 check_producer (cu
);
8576 return cu
->producer_is_gxx_lt_4_6
;
8579 /* Return the default accessibility type if it is not overriden by
8580 DW_AT_accessibility. */
8582 static enum dwarf_access_attribute
8583 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8585 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8587 /* The default DWARF 2 accessibility for members is public, the default
8588 accessibility for inheritance is private. */
8590 if (die
->tag
!= DW_TAG_inheritance
)
8591 return DW_ACCESS_public
;
8593 return DW_ACCESS_private
;
8597 /* DWARF 3+ defines the default accessibility a different way. The same
8598 rules apply now for DW_TAG_inheritance as for the members and it only
8599 depends on the container kind. */
8601 if (die
->parent
->tag
== DW_TAG_class_type
)
8602 return DW_ACCESS_private
;
8604 return DW_ACCESS_public
;
8608 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8609 offset. If the attribute was not found return 0, otherwise return
8610 1. If it was found but could not properly be handled, set *OFFSET
8614 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8617 struct attribute
*attr
;
8619 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8624 /* Note that we do not check for a section offset first here.
8625 This is because DW_AT_data_member_location is new in DWARF 4,
8626 so if we see it, we can assume that a constant form is really
8627 a constant and not a section offset. */
8628 if (attr_form_is_constant (attr
))
8629 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8630 else if (attr_form_is_section_offset (attr
))
8631 dwarf2_complex_location_expr_complaint ();
8632 else if (attr_form_is_block (attr
))
8633 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8635 dwarf2_complex_location_expr_complaint ();
8643 /* Add an aggregate field to the field list. */
8646 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8647 struct dwarf2_cu
*cu
)
8649 struct objfile
*objfile
= cu
->objfile
;
8650 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8651 struct nextfield
*new_field
;
8652 struct attribute
*attr
;
8654 char *fieldname
= "";
8656 /* Allocate a new field list entry and link it in. */
8657 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8658 make_cleanup (xfree
, new_field
);
8659 memset (new_field
, 0, sizeof (struct nextfield
));
8661 if (die
->tag
== DW_TAG_inheritance
)
8663 new_field
->next
= fip
->baseclasses
;
8664 fip
->baseclasses
= new_field
;
8668 new_field
->next
= fip
->fields
;
8669 fip
->fields
= new_field
;
8673 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8675 new_field
->accessibility
= DW_UNSND (attr
);
8677 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8678 if (new_field
->accessibility
!= DW_ACCESS_public
)
8679 fip
->non_public_fields
= 1;
8681 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8683 new_field
->virtuality
= DW_UNSND (attr
);
8685 new_field
->virtuality
= DW_VIRTUALITY_none
;
8687 fp
= &new_field
->field
;
8689 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8693 /* Data member other than a C++ static data member. */
8695 /* Get type of field. */
8696 fp
->type
= die_type (die
, cu
);
8698 SET_FIELD_BITPOS (*fp
, 0);
8700 /* Get bit size of field (zero if none). */
8701 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8704 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8708 FIELD_BITSIZE (*fp
) = 0;
8711 /* Get bit offset of field. */
8712 if (handle_data_member_location (die
, cu
, &offset
))
8713 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8714 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8717 if (gdbarch_bits_big_endian (gdbarch
))
8719 /* For big endian bits, the DW_AT_bit_offset gives the
8720 additional bit offset from the MSB of the containing
8721 anonymous object to the MSB of the field. We don't
8722 have to do anything special since we don't need to
8723 know the size of the anonymous object. */
8724 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8728 /* For little endian bits, compute the bit offset to the
8729 MSB of the anonymous object, subtract off the number of
8730 bits from the MSB of the field to the MSB of the
8731 object, and then subtract off the number of bits of
8732 the field itself. The result is the bit offset of
8733 the LSB of the field. */
8735 int bit_offset
= DW_UNSND (attr
);
8737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8740 /* The size of the anonymous object containing
8741 the bit field is explicit, so use the
8742 indicated size (in bytes). */
8743 anonymous_size
= DW_UNSND (attr
);
8747 /* The size of the anonymous object containing
8748 the bit field must be inferred from the type
8749 attribute of the data member containing the
8751 anonymous_size
= TYPE_LENGTH (fp
->type
);
8753 SET_FIELD_BITPOS (*fp
,
8755 + anonymous_size
* bits_per_byte
8756 - bit_offset
- FIELD_BITSIZE (*fp
)));
8760 /* Get name of field. */
8761 fieldname
= dwarf2_name (die
, cu
);
8762 if (fieldname
== NULL
)
8765 /* The name is already allocated along with this objfile, so we don't
8766 need to duplicate it for the type. */
8767 fp
->name
= fieldname
;
8769 /* Change accessibility for artificial fields (e.g. virtual table
8770 pointer or virtual base class pointer) to private. */
8771 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8773 FIELD_ARTIFICIAL (*fp
) = 1;
8774 new_field
->accessibility
= DW_ACCESS_private
;
8775 fip
->non_public_fields
= 1;
8778 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8780 /* C++ static member. */
8782 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8783 is a declaration, but all versions of G++ as of this writing
8784 (so through at least 3.2.1) incorrectly generate
8785 DW_TAG_variable tags. */
8787 const char *physname
;
8789 /* Get name of field. */
8790 fieldname
= dwarf2_name (die
, cu
);
8791 if (fieldname
== NULL
)
8794 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8796 /* Only create a symbol if this is an external value.
8797 new_symbol checks this and puts the value in the global symbol
8798 table, which we want. If it is not external, new_symbol
8799 will try to put the value in cu->list_in_scope which is wrong. */
8800 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8802 /* A static const member, not much different than an enum as far as
8803 we're concerned, except that we can support more types. */
8804 new_symbol (die
, NULL
, cu
);
8807 /* Get physical name. */
8808 physname
= dwarf2_physname (fieldname
, die
, cu
);
8810 /* The name is already allocated along with this objfile, so we don't
8811 need to duplicate it for the type. */
8812 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8813 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8814 FIELD_NAME (*fp
) = fieldname
;
8816 else if (die
->tag
== DW_TAG_inheritance
)
8820 /* C++ base class field. */
8821 if (handle_data_member_location (die
, cu
, &offset
))
8822 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8823 FIELD_BITSIZE (*fp
) = 0;
8824 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8825 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8826 fip
->nbaseclasses
++;
8830 /* Add a typedef defined in the scope of the FIP's class. */
8833 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8834 struct dwarf2_cu
*cu
)
8836 struct objfile
*objfile
= cu
->objfile
;
8837 struct typedef_field_list
*new_field
;
8838 struct attribute
*attr
;
8839 struct typedef_field
*fp
;
8840 char *fieldname
= "";
8842 /* Allocate a new field list entry and link it in. */
8843 new_field
= xzalloc (sizeof (*new_field
));
8844 make_cleanup (xfree
, new_field
);
8846 gdb_assert (die
->tag
== DW_TAG_typedef
);
8848 fp
= &new_field
->field
;
8850 /* Get name of field. */
8851 fp
->name
= dwarf2_name (die
, cu
);
8852 if (fp
->name
== NULL
)
8855 fp
->type
= read_type_die (die
, cu
);
8857 new_field
->next
= fip
->typedef_field_list
;
8858 fip
->typedef_field_list
= new_field
;
8859 fip
->typedef_field_list_count
++;
8862 /* Create the vector of fields, and attach it to the type. */
8865 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8866 struct dwarf2_cu
*cu
)
8868 int nfields
= fip
->nfields
;
8870 /* Record the field count, allocate space for the array of fields,
8871 and create blank accessibility bitfields if necessary. */
8872 TYPE_NFIELDS (type
) = nfields
;
8873 TYPE_FIELDS (type
) = (struct field
*)
8874 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8875 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8877 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8879 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8881 TYPE_FIELD_PRIVATE_BITS (type
) =
8882 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8883 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8885 TYPE_FIELD_PROTECTED_BITS (type
) =
8886 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8887 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8889 TYPE_FIELD_IGNORE_BITS (type
) =
8890 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8891 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8894 /* If the type has baseclasses, allocate and clear a bit vector for
8895 TYPE_FIELD_VIRTUAL_BITS. */
8896 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8898 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8899 unsigned char *pointer
;
8901 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8902 pointer
= TYPE_ALLOC (type
, num_bytes
);
8903 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8904 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8905 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8908 /* Copy the saved-up fields into the field vector. Start from the head of
8909 the list, adding to the tail of the field array, so that they end up in
8910 the same order in the array in which they were added to the list. */
8911 while (nfields
-- > 0)
8913 struct nextfield
*fieldp
;
8917 fieldp
= fip
->fields
;
8918 fip
->fields
= fieldp
->next
;
8922 fieldp
= fip
->baseclasses
;
8923 fip
->baseclasses
= fieldp
->next
;
8926 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8927 switch (fieldp
->accessibility
)
8929 case DW_ACCESS_private
:
8930 if (cu
->language
!= language_ada
)
8931 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8934 case DW_ACCESS_protected
:
8935 if (cu
->language
!= language_ada
)
8936 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8939 case DW_ACCESS_public
:
8943 /* Unknown accessibility. Complain and treat it as public. */
8945 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8946 fieldp
->accessibility
);
8950 if (nfields
< fip
->nbaseclasses
)
8952 switch (fieldp
->virtuality
)
8954 case DW_VIRTUALITY_virtual
:
8955 case DW_VIRTUALITY_pure_virtual
:
8956 if (cu
->language
== language_ada
)
8957 error (_("unexpected virtuality in component of Ada type"));
8958 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8965 /* Add a member function to the proper fieldlist. */
8968 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8969 struct type
*type
, struct dwarf2_cu
*cu
)
8971 struct objfile
*objfile
= cu
->objfile
;
8972 struct attribute
*attr
;
8973 struct fnfieldlist
*flp
;
8975 struct fn_field
*fnp
;
8977 struct nextfnfield
*new_fnfield
;
8978 struct type
*this_type
;
8979 enum dwarf_access_attribute accessibility
;
8981 if (cu
->language
== language_ada
)
8982 error (_("unexpected member function in Ada type"));
8984 /* Get name of member function. */
8985 fieldname
= dwarf2_name (die
, cu
);
8986 if (fieldname
== NULL
)
8989 /* Look up member function name in fieldlist. */
8990 for (i
= 0; i
< fip
->nfnfields
; i
++)
8992 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8996 /* Create new list element if necessary. */
8997 if (i
< fip
->nfnfields
)
8998 flp
= &fip
->fnfieldlists
[i
];
9001 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9003 fip
->fnfieldlists
= (struct fnfieldlist
*)
9004 xrealloc (fip
->fnfieldlists
,
9005 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9006 * sizeof (struct fnfieldlist
));
9007 if (fip
->nfnfields
== 0)
9008 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9010 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9011 flp
->name
= fieldname
;
9014 i
= fip
->nfnfields
++;
9017 /* Create a new member function field and chain it to the field list
9019 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9020 make_cleanup (xfree
, new_fnfield
);
9021 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9022 new_fnfield
->next
= flp
->head
;
9023 flp
->head
= new_fnfield
;
9026 /* Fill in the member function field info. */
9027 fnp
= &new_fnfield
->fnfield
;
9029 /* Delay processing of the physname until later. */
9030 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9032 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9037 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9038 fnp
->physname
= physname
? physname
: "";
9041 fnp
->type
= alloc_type (objfile
);
9042 this_type
= read_type_die (die
, cu
);
9043 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9045 int nparams
= TYPE_NFIELDS (this_type
);
9047 /* TYPE is the domain of this method, and THIS_TYPE is the type
9048 of the method itself (TYPE_CODE_METHOD). */
9049 smash_to_method_type (fnp
->type
, type
,
9050 TYPE_TARGET_TYPE (this_type
),
9051 TYPE_FIELDS (this_type
),
9052 TYPE_NFIELDS (this_type
),
9053 TYPE_VARARGS (this_type
));
9055 /* Handle static member functions.
9056 Dwarf2 has no clean way to discern C++ static and non-static
9057 member functions. G++ helps GDB by marking the first
9058 parameter for non-static member functions (which is the this
9059 pointer) as artificial. We obtain this information from
9060 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
9061 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
9062 fnp
->voffset
= VOFFSET_STATIC
;
9065 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
9066 dwarf2_full_name (fieldname
, die
, cu
));
9068 /* Get fcontext from DW_AT_containing_type if present. */
9069 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9070 fnp
->fcontext
= die_containing_type (die
, cu
);
9072 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
9073 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
9075 /* Get accessibility. */
9076 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9078 accessibility
= DW_UNSND (attr
);
9080 accessibility
= dwarf2_default_access_attribute (die
, cu
);
9081 switch (accessibility
)
9083 case DW_ACCESS_private
:
9084 fnp
->is_private
= 1;
9086 case DW_ACCESS_protected
:
9087 fnp
->is_protected
= 1;
9091 /* Check for artificial methods. */
9092 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9093 if (attr
&& DW_UNSND (attr
) != 0)
9094 fnp
->is_artificial
= 1;
9096 /* Get index in virtual function table if it is a virtual member
9097 function. For older versions of GCC, this is an offset in the
9098 appropriate virtual table, as specified by DW_AT_containing_type.
9099 For everyone else, it is an expression to be evaluated relative
9100 to the object address. */
9102 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9105 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9107 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9109 /* Old-style GCC. */
9110 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9112 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9113 || (DW_BLOCK (attr
)->size
> 1
9114 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9115 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9117 struct dwarf_block blk
;
9120 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9122 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
9123 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
9124 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9125 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
9126 dwarf2_complex_location_expr_complaint ();
9128 fnp
->voffset
/= cu
->header
.addr_size
;
9132 dwarf2_complex_location_expr_complaint ();
9135 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
9137 else if (attr_form_is_section_offset (attr
))
9139 dwarf2_complex_location_expr_complaint ();
9143 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
9149 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9150 if (attr
&& DW_UNSND (attr
))
9152 /* GCC does this, as of 2008-08-25; PR debug/37237. */
9153 complaint (&symfile_complaints
,
9154 _("Member function \"%s\" (offset %d) is virtual "
9155 "but the vtable offset is not specified"),
9156 fieldname
, die
->offset
.sect_off
);
9157 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9158 TYPE_CPLUS_DYNAMIC (type
) = 1;
9163 /* Create the vector of member function fields, and attach it to the type. */
9166 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
9167 struct dwarf2_cu
*cu
)
9169 struct fnfieldlist
*flp
;
9172 if (cu
->language
== language_ada
)
9173 error (_("unexpected member functions in Ada type"));
9175 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9176 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
9177 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
9179 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
9181 struct nextfnfield
*nfp
= flp
->head
;
9182 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
9185 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
9186 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
9187 fn_flp
->fn_fields
= (struct fn_field
*)
9188 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
9189 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
9190 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
9193 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
9196 /* Returns non-zero if NAME is the name of a vtable member in CU's
9197 language, zero otherwise. */
9199 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
9201 static const char vptr
[] = "_vptr";
9202 static const char vtable
[] = "vtable";
9204 /* Look for the C++ and Java forms of the vtable. */
9205 if ((cu
->language
== language_java
9206 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
9207 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
9208 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
9214 /* GCC outputs unnamed structures that are really pointers to member
9215 functions, with the ABI-specified layout. If TYPE describes
9216 such a structure, smash it into a member function type.
9218 GCC shouldn't do this; it should just output pointer to member DIEs.
9219 This is GCC PR debug/28767. */
9222 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
9224 struct type
*pfn_type
, *domain_type
, *new_type
;
9226 /* Check for a structure with no name and two children. */
9227 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
9230 /* Check for __pfn and __delta members. */
9231 if (TYPE_FIELD_NAME (type
, 0) == NULL
9232 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
9233 || TYPE_FIELD_NAME (type
, 1) == NULL
9234 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
9237 /* Find the type of the method. */
9238 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
9239 if (pfn_type
== NULL
9240 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
9241 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
9244 /* Look for the "this" argument. */
9245 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
9246 if (TYPE_NFIELDS (pfn_type
) == 0
9247 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
9248 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
9251 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9252 new_type
= alloc_type (objfile
);
9253 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9254 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9255 TYPE_VARARGS (pfn_type
));
9256 smash_to_methodptr_type (type
, new_type
);
9259 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
9263 producer_is_icc (struct dwarf2_cu
*cu
)
9265 if (!cu
->checked_producer
)
9266 check_producer (cu
);
9268 return cu
->producer_is_icc
;
9271 /* Called when we find the DIE that starts a structure or union scope
9272 (definition) to create a type for the structure or union. Fill in
9273 the type's name and general properties; the members will not be
9274 processed until process_structure_type.
9276 NOTE: we need to call these functions regardless of whether or not the
9277 DIE has a DW_AT_name attribute, since it might be an anonymous
9278 structure or union. This gets the type entered into our set of
9281 However, if the structure is incomplete (an opaque struct/union)
9282 then suppress creating a symbol table entry for it since gdb only
9283 wants to find the one with the complete definition. Note that if
9284 it is complete, we just call new_symbol, which does it's own
9285 checking about whether the struct/union is anonymous or not (and
9286 suppresses creating a symbol table entry itself). */
9288 static struct type
*
9289 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9291 struct objfile
*objfile
= cu
->objfile
;
9293 struct attribute
*attr
;
9296 /* If the definition of this type lives in .debug_types, read that type.
9297 Don't follow DW_AT_specification though, that will take us back up
9298 the chain and we want to go down. */
9299 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9302 struct dwarf2_cu
*type_cu
= cu
;
9303 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9305 /* We could just recurse on read_structure_type, but we need to call
9306 get_die_type to ensure only one type for this DIE is created.
9307 This is important, for example, because for c++ classes we need
9308 TYPE_NAME set which is only done by new_symbol. Blech. */
9309 type
= read_type_die (type_die
, type_cu
);
9311 /* TYPE_CU may not be the same as CU.
9312 Ensure TYPE is recorded in CU's type_hash table. */
9313 return set_die_type (die
, type
, cu
);
9316 type
= alloc_type (objfile
);
9317 INIT_CPLUS_SPECIFIC (type
);
9319 name
= dwarf2_name (die
, cu
);
9322 if (cu
->language
== language_cplus
9323 || cu
->language
== language_java
)
9325 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9327 /* dwarf2_full_name might have already finished building the DIE's
9328 type. If so, there is no need to continue. */
9329 if (get_die_type (die
, cu
) != NULL
)
9330 return get_die_type (die
, cu
);
9332 TYPE_TAG_NAME (type
) = full_name
;
9333 if (die
->tag
== DW_TAG_structure_type
9334 || die
->tag
== DW_TAG_class_type
)
9335 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9339 /* The name is already allocated along with this objfile, so
9340 we don't need to duplicate it for the type. */
9341 TYPE_TAG_NAME (type
) = (char *) name
;
9342 if (die
->tag
== DW_TAG_class_type
)
9343 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9347 if (die
->tag
== DW_TAG_structure_type
)
9349 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9351 else if (die
->tag
== DW_TAG_union_type
)
9353 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9357 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9360 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9361 TYPE_DECLARED_CLASS (type
) = 1;
9363 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9366 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9370 TYPE_LENGTH (type
) = 0;
9373 if (producer_is_icc (cu
))
9375 /* ICC does not output the required DW_AT_declaration
9376 on incomplete types, but gives them a size of zero. */
9379 TYPE_STUB_SUPPORTED (type
) = 1;
9381 if (die_is_declaration (die
, cu
))
9382 TYPE_STUB (type
) = 1;
9383 else if (attr
== NULL
&& die
->child
== NULL
9384 && producer_is_realview (cu
->producer
))
9385 /* RealView does not output the required DW_AT_declaration
9386 on incomplete types. */
9387 TYPE_STUB (type
) = 1;
9389 /* We need to add the type field to the die immediately so we don't
9390 infinitely recurse when dealing with pointers to the structure
9391 type within the structure itself. */
9392 set_die_type (die
, type
, cu
);
9394 /* set_die_type should be already done. */
9395 set_descriptive_type (type
, die
, cu
);
9400 /* Finish creating a structure or union type, including filling in
9401 its members and creating a symbol for it. */
9404 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9406 struct objfile
*objfile
= cu
->objfile
;
9407 struct die_info
*child_die
= die
->child
;
9410 type
= get_die_type (die
, cu
);
9412 type
= read_structure_type (die
, cu
);
9414 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9416 struct field_info fi
;
9417 struct die_info
*child_die
;
9418 VEC (symbolp
) *template_args
= NULL
;
9419 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9421 memset (&fi
, 0, sizeof (struct field_info
));
9423 child_die
= die
->child
;
9425 while (child_die
&& child_die
->tag
)
9427 if (child_die
->tag
== DW_TAG_member
9428 || child_die
->tag
== DW_TAG_variable
)
9430 /* NOTE: carlton/2002-11-05: A C++ static data member
9431 should be a DW_TAG_member that is a declaration, but
9432 all versions of G++ as of this writing (so through at
9433 least 3.2.1) incorrectly generate DW_TAG_variable
9434 tags for them instead. */
9435 dwarf2_add_field (&fi
, child_die
, cu
);
9437 else if (child_die
->tag
== DW_TAG_subprogram
)
9439 /* C++ member function. */
9440 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9442 else if (child_die
->tag
== DW_TAG_inheritance
)
9444 /* C++ base class field. */
9445 dwarf2_add_field (&fi
, child_die
, cu
);
9447 else if (child_die
->tag
== DW_TAG_typedef
)
9448 dwarf2_add_typedef (&fi
, child_die
, cu
);
9449 else if (child_die
->tag
== DW_TAG_template_type_param
9450 || child_die
->tag
== DW_TAG_template_value_param
)
9452 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9455 VEC_safe_push (symbolp
, template_args
, arg
);
9458 child_die
= sibling_die (child_die
);
9461 /* Attach template arguments to type. */
9462 if (! VEC_empty (symbolp
, template_args
))
9464 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9465 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9466 = VEC_length (symbolp
, template_args
);
9467 TYPE_TEMPLATE_ARGUMENTS (type
)
9468 = obstack_alloc (&objfile
->objfile_obstack
,
9469 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9470 * sizeof (struct symbol
*)));
9471 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9472 VEC_address (symbolp
, template_args
),
9473 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9474 * sizeof (struct symbol
*)));
9475 VEC_free (symbolp
, template_args
);
9478 /* Attach fields and member functions to the type. */
9480 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9483 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9485 /* Get the type which refers to the base class (possibly this
9486 class itself) which contains the vtable pointer for the current
9487 class from the DW_AT_containing_type attribute. This use of
9488 DW_AT_containing_type is a GNU extension. */
9490 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9492 struct type
*t
= die_containing_type (die
, cu
);
9494 TYPE_VPTR_BASETYPE (type
) = t
;
9499 /* Our own class provides vtbl ptr. */
9500 for (i
= TYPE_NFIELDS (t
) - 1;
9501 i
>= TYPE_N_BASECLASSES (t
);
9504 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9506 if (is_vtable_name (fieldname
, cu
))
9508 TYPE_VPTR_FIELDNO (type
) = i
;
9513 /* Complain if virtual function table field not found. */
9514 if (i
< TYPE_N_BASECLASSES (t
))
9515 complaint (&symfile_complaints
,
9516 _("virtual function table pointer "
9517 "not found when defining class '%s'"),
9518 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9523 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9526 else if (cu
->producer
9527 && strncmp (cu
->producer
,
9528 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9530 /* The IBM XLC compiler does not provide direct indication
9531 of the containing type, but the vtable pointer is
9532 always named __vfp. */
9536 for (i
= TYPE_NFIELDS (type
) - 1;
9537 i
>= TYPE_N_BASECLASSES (type
);
9540 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9542 TYPE_VPTR_FIELDNO (type
) = i
;
9543 TYPE_VPTR_BASETYPE (type
) = type
;
9550 /* Copy fi.typedef_field_list linked list elements content into the
9551 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9552 if (fi
.typedef_field_list
)
9554 int i
= fi
.typedef_field_list_count
;
9556 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9557 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9558 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9559 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9561 /* Reverse the list order to keep the debug info elements order. */
9564 struct typedef_field
*dest
, *src
;
9566 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9567 src
= &fi
.typedef_field_list
->field
;
9568 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9573 do_cleanups (back_to
);
9575 if (HAVE_CPLUS_STRUCT (type
))
9576 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9579 quirk_gcc_member_function_pointer (type
, objfile
);
9581 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9582 snapshots) has been known to create a die giving a declaration
9583 for a class that has, as a child, a die giving a definition for a
9584 nested class. So we have to process our children even if the
9585 current die is a declaration. Normally, of course, a declaration
9586 won't have any children at all. */
9588 while (child_die
!= NULL
&& child_die
->tag
)
9590 if (child_die
->tag
== DW_TAG_member
9591 || child_die
->tag
== DW_TAG_variable
9592 || child_die
->tag
== DW_TAG_inheritance
9593 || child_die
->tag
== DW_TAG_template_value_param
9594 || child_die
->tag
== DW_TAG_template_type_param
)
9599 process_die (child_die
, cu
);
9601 child_die
= sibling_die (child_die
);
9604 /* Do not consider external references. According to the DWARF standard,
9605 these DIEs are identified by the fact that they have no byte_size
9606 attribute, and a declaration attribute. */
9607 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9608 || !die_is_declaration (die
, cu
))
9609 new_symbol (die
, type
, cu
);
9612 /* Given a DW_AT_enumeration_type die, set its type. We do not
9613 complete the type's fields yet, or create any symbols. */
9615 static struct type
*
9616 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9618 struct objfile
*objfile
= cu
->objfile
;
9620 struct attribute
*attr
;
9623 /* If the definition of this type lives in .debug_types, read that type.
9624 Don't follow DW_AT_specification though, that will take us back up
9625 the chain and we want to go down. */
9626 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9629 struct dwarf2_cu
*type_cu
= cu
;
9630 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9632 type
= read_type_die (type_die
, type_cu
);
9634 /* TYPE_CU may not be the same as CU.
9635 Ensure TYPE is recorded in CU's type_hash table. */
9636 return set_die_type (die
, type
, cu
);
9639 type
= alloc_type (objfile
);
9641 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9642 name
= dwarf2_full_name (NULL
, die
, cu
);
9644 TYPE_TAG_NAME (type
) = (char *) name
;
9646 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9649 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9653 TYPE_LENGTH (type
) = 0;
9656 /* The enumeration DIE can be incomplete. In Ada, any type can be
9657 declared as private in the package spec, and then defined only
9658 inside the package body. Such types are known as Taft Amendment
9659 Types. When another package uses such a type, an incomplete DIE
9660 may be generated by the compiler. */
9661 if (die_is_declaration (die
, cu
))
9662 TYPE_STUB (type
) = 1;
9664 return set_die_type (die
, type
, cu
);
9667 /* Given a pointer to a die which begins an enumeration, process all
9668 the dies that define the members of the enumeration, and create the
9669 symbol for the enumeration type.
9671 NOTE: We reverse the order of the element list. */
9674 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9676 struct type
*this_type
;
9678 this_type
= get_die_type (die
, cu
);
9679 if (this_type
== NULL
)
9680 this_type
= read_enumeration_type (die
, cu
);
9682 if (die
->child
!= NULL
)
9684 struct die_info
*child_die
;
9686 struct field
*fields
= NULL
;
9688 int unsigned_enum
= 1;
9693 child_die
= die
->child
;
9694 while (child_die
&& child_die
->tag
)
9696 if (child_die
->tag
!= DW_TAG_enumerator
)
9698 process_die (child_die
, cu
);
9702 name
= dwarf2_name (child_die
, cu
);
9705 sym
= new_symbol (child_die
, this_type
, cu
);
9706 if (SYMBOL_VALUE (sym
) < 0)
9711 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9714 mask
|= SYMBOL_VALUE (sym
);
9716 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9718 fields
= (struct field
*)
9720 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9721 * sizeof (struct field
));
9724 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9725 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9726 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9727 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9733 child_die
= sibling_die (child_die
);
9738 TYPE_NFIELDS (this_type
) = num_fields
;
9739 TYPE_FIELDS (this_type
) = (struct field
*)
9740 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9741 memcpy (TYPE_FIELDS (this_type
), fields
,
9742 sizeof (struct field
) * num_fields
);
9746 TYPE_UNSIGNED (this_type
) = 1;
9748 TYPE_FLAG_ENUM (this_type
) = 1;
9751 /* If we are reading an enum from a .debug_types unit, and the enum
9752 is a declaration, and the enum is not the signatured type in the
9753 unit, then we do not want to add a symbol for it. Adding a
9754 symbol would in some cases obscure the true definition of the
9755 enum, giving users an incomplete type when the definition is
9756 actually available. Note that we do not want to do this for all
9757 enums which are just declarations, because C++0x allows forward
9758 enum declarations. */
9759 if (cu
->per_cu
->is_debug_types
9760 && die_is_declaration (die
, cu
))
9762 struct signatured_type
*sig_type
;
9765 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9766 cu
->per_cu
->info_or_types_section
,
9767 cu
->per_cu
->offset
);
9768 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9769 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9773 new_symbol (die
, this_type
, cu
);
9776 /* Extract all information from a DW_TAG_array_type DIE and put it in
9777 the DIE's type field. For now, this only handles one dimensional
9780 static struct type
*
9781 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9783 struct objfile
*objfile
= cu
->objfile
;
9784 struct die_info
*child_die
;
9786 struct type
*element_type
, *range_type
, *index_type
;
9787 struct type
**range_types
= NULL
;
9788 struct attribute
*attr
;
9790 struct cleanup
*back_to
;
9793 element_type
= die_type (die
, cu
);
9795 /* The die_type call above may have already set the type for this DIE. */
9796 type
= get_die_type (die
, cu
);
9800 /* Irix 6.2 native cc creates array types without children for
9801 arrays with unspecified length. */
9802 if (die
->child
== NULL
)
9804 index_type
= objfile_type (objfile
)->builtin_int
;
9805 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9806 type
= create_array_type (NULL
, element_type
, range_type
);
9807 return set_die_type (die
, type
, cu
);
9810 back_to
= make_cleanup (null_cleanup
, NULL
);
9811 child_die
= die
->child
;
9812 while (child_die
&& child_die
->tag
)
9814 if (child_die
->tag
== DW_TAG_subrange_type
)
9816 struct type
*child_type
= read_type_die (child_die
, cu
);
9818 if (child_type
!= NULL
)
9820 /* The range type was succesfully read. Save it for the
9821 array type creation. */
9822 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9824 range_types
= (struct type
**)
9825 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9826 * sizeof (struct type
*));
9828 make_cleanup (free_current_contents
, &range_types
);
9830 range_types
[ndim
++] = child_type
;
9833 child_die
= sibling_die (child_die
);
9836 /* Dwarf2 dimensions are output from left to right, create the
9837 necessary array types in backwards order. */
9839 type
= element_type
;
9841 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9846 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9851 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9854 /* Understand Dwarf2 support for vector types (like they occur on
9855 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9856 array type. This is not part of the Dwarf2/3 standard yet, but a
9857 custom vendor extension. The main difference between a regular
9858 array and the vector variant is that vectors are passed by value
9860 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9862 make_vector_type (type
);
9864 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9865 implementation may choose to implement triple vectors using this
9867 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9870 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9871 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9873 complaint (&symfile_complaints
,
9874 _("DW_AT_byte_size for array type smaller "
9875 "than the total size of elements"));
9878 name
= dwarf2_name (die
, cu
);
9880 TYPE_NAME (type
) = name
;
9882 /* Install the type in the die. */
9883 set_die_type (die
, type
, cu
);
9885 /* set_die_type should be already done. */
9886 set_descriptive_type (type
, die
, cu
);
9888 do_cleanups (back_to
);
9893 static enum dwarf_array_dim_ordering
9894 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9896 struct attribute
*attr
;
9898 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9900 if (attr
) return DW_SND (attr
);
9902 /* GNU F77 is a special case, as at 08/2004 array type info is the
9903 opposite order to the dwarf2 specification, but data is still
9904 laid out as per normal fortran.
9906 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9907 version checking. */
9909 if (cu
->language
== language_fortran
9910 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9912 return DW_ORD_row_major
;
9915 switch (cu
->language_defn
->la_array_ordering
)
9917 case array_column_major
:
9918 return DW_ORD_col_major
;
9919 case array_row_major
:
9921 return DW_ORD_row_major
;
9925 /* Extract all information from a DW_TAG_set_type DIE and put it in
9926 the DIE's type field. */
9928 static struct type
*
9929 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9931 struct type
*domain_type
, *set_type
;
9932 struct attribute
*attr
;
9934 domain_type
= die_type (die
, cu
);
9936 /* The die_type call above may have already set the type for this DIE. */
9937 set_type
= get_die_type (die
, cu
);
9941 set_type
= create_set_type (NULL
, domain_type
);
9943 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9945 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9947 return set_die_type (die
, set_type
, cu
);
9950 /* First cut: install each common block member as a global variable. */
9953 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9955 struct die_info
*child_die
;
9956 struct attribute
*attr
;
9958 CORE_ADDR base
= (CORE_ADDR
) 0;
9960 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9963 /* Support the .debug_loc offsets. */
9964 if (attr_form_is_block (attr
))
9966 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9968 else if (attr_form_is_section_offset (attr
))
9970 dwarf2_complex_location_expr_complaint ();
9974 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9975 "common block member");
9978 if (die
->child
!= NULL
)
9980 child_die
= die
->child
;
9981 while (child_die
&& child_die
->tag
)
9985 sym
= new_symbol (child_die
, NULL
, cu
);
9987 && handle_data_member_location (child_die
, cu
, &offset
))
9989 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9990 add_symbol_to_list (sym
, &global_symbols
);
9992 child_die
= sibling_die (child_die
);
9997 /* Create a type for a C++ namespace. */
9999 static struct type
*
10000 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10002 struct objfile
*objfile
= cu
->objfile
;
10003 const char *previous_prefix
, *name
;
10007 /* For extensions, reuse the type of the original namespace. */
10008 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10010 struct die_info
*ext_die
;
10011 struct dwarf2_cu
*ext_cu
= cu
;
10013 ext_die
= dwarf2_extension (die
, &ext_cu
);
10014 type
= read_type_die (ext_die
, ext_cu
);
10016 /* EXT_CU may not be the same as CU.
10017 Ensure TYPE is recorded in CU's type_hash table. */
10018 return set_die_type (die
, type
, cu
);
10021 name
= namespace_name (die
, &is_anonymous
, cu
);
10023 /* Now build the name of the current namespace. */
10025 previous_prefix
= determine_prefix (die
, cu
);
10026 if (previous_prefix
[0] != '\0')
10027 name
= typename_concat (&objfile
->objfile_obstack
,
10028 previous_prefix
, name
, 0, cu
);
10030 /* Create the type. */
10031 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10033 TYPE_NAME (type
) = (char *) name
;
10034 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10036 return set_die_type (die
, type
, cu
);
10039 /* Read a C++ namespace. */
10042 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10044 struct objfile
*objfile
= cu
->objfile
;
10047 /* Add a symbol associated to this if we haven't seen the namespace
10048 before. Also, add a using directive if it's an anonymous
10051 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10055 type
= read_type_die (die
, cu
);
10056 new_symbol (die
, type
, cu
);
10058 namespace_name (die
, &is_anonymous
, cu
);
10061 const char *previous_prefix
= determine_prefix (die
, cu
);
10063 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
10064 NULL
, NULL
, &objfile
->objfile_obstack
);
10068 if (die
->child
!= NULL
)
10070 struct die_info
*child_die
= die
->child
;
10072 while (child_die
&& child_die
->tag
)
10074 process_die (child_die
, cu
);
10075 child_die
= sibling_die (child_die
);
10080 /* Read a Fortran module as type. This DIE can be only a declaration used for
10081 imported module. Still we need that type as local Fortran "use ... only"
10082 declaration imports depend on the created type in determine_prefix. */
10084 static struct type
*
10085 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10087 struct objfile
*objfile
= cu
->objfile
;
10091 module_name
= dwarf2_name (die
, cu
);
10093 complaint (&symfile_complaints
,
10094 _("DW_TAG_module has no name, offset 0x%x"),
10095 die
->offset
.sect_off
);
10096 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10098 /* determine_prefix uses TYPE_TAG_NAME. */
10099 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10101 return set_die_type (die
, type
, cu
);
10104 /* Read a Fortran module. */
10107 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10109 struct die_info
*child_die
= die
->child
;
10111 while (child_die
&& child_die
->tag
)
10113 process_die (child_die
, cu
);
10114 child_die
= sibling_die (child_die
);
10118 /* Return the name of the namespace represented by DIE. Set
10119 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
10122 static const char *
10123 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
10125 struct die_info
*current_die
;
10126 const char *name
= NULL
;
10128 /* Loop through the extensions until we find a name. */
10130 for (current_die
= die
;
10131 current_die
!= NULL
;
10132 current_die
= dwarf2_extension (die
, &cu
))
10134 name
= dwarf2_name (current_die
, cu
);
10139 /* Is it an anonymous namespace? */
10141 *is_anonymous
= (name
== NULL
);
10143 name
= CP_ANONYMOUS_NAMESPACE_STR
;
10148 /* Extract all information from a DW_TAG_pointer_type DIE and add to
10149 the user defined type vector. */
10151 static struct type
*
10152 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10154 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
10155 struct comp_unit_head
*cu_header
= &cu
->header
;
10157 struct attribute
*attr_byte_size
;
10158 struct attribute
*attr_address_class
;
10159 int byte_size
, addr_class
;
10160 struct type
*target_type
;
10162 target_type
= die_type (die
, cu
);
10164 /* The die_type call above may have already set the type for this DIE. */
10165 type
= get_die_type (die
, cu
);
10169 type
= lookup_pointer_type (target_type
);
10171 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10172 if (attr_byte_size
)
10173 byte_size
= DW_UNSND (attr_byte_size
);
10175 byte_size
= cu_header
->addr_size
;
10177 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
10178 if (attr_address_class
)
10179 addr_class
= DW_UNSND (attr_address_class
);
10181 addr_class
= DW_ADDR_none
;
10183 /* If the pointer size or address class is different than the
10184 default, create a type variant marked as such and set the
10185 length accordingly. */
10186 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
10188 if (gdbarch_address_class_type_flags_p (gdbarch
))
10192 type_flags
= gdbarch_address_class_type_flags
10193 (gdbarch
, byte_size
, addr_class
);
10194 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
10196 type
= make_type_with_address_space (type
, type_flags
);
10198 else if (TYPE_LENGTH (type
) != byte_size
)
10200 complaint (&symfile_complaints
,
10201 _("invalid pointer size %d"), byte_size
);
10205 /* Should we also complain about unhandled address classes? */
10209 TYPE_LENGTH (type
) = byte_size
;
10210 return set_die_type (die
, type
, cu
);
10213 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
10214 the user defined type vector. */
10216 static struct type
*
10217 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10220 struct type
*to_type
;
10221 struct type
*domain
;
10223 to_type
= die_type (die
, cu
);
10224 domain
= die_containing_type (die
, cu
);
10226 /* The calls above may have already set the type for this DIE. */
10227 type
= get_die_type (die
, cu
);
10231 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
10232 type
= lookup_methodptr_type (to_type
);
10234 type
= lookup_memberptr_type (to_type
, domain
);
10236 return set_die_type (die
, type
, cu
);
10239 /* Extract all information from a DW_TAG_reference_type DIE and add to
10240 the user defined type vector. */
10242 static struct type
*
10243 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10245 struct comp_unit_head
*cu_header
= &cu
->header
;
10246 struct type
*type
, *target_type
;
10247 struct attribute
*attr
;
10249 target_type
= die_type (die
, cu
);
10251 /* The die_type call above may have already set the type for this DIE. */
10252 type
= get_die_type (die
, cu
);
10256 type
= lookup_reference_type (target_type
);
10257 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10260 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10264 TYPE_LENGTH (type
) = cu_header
->addr_size
;
10266 return set_die_type (die
, type
, cu
);
10269 static struct type
*
10270 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10272 struct type
*base_type
, *cv_type
;
10274 base_type
= die_type (die
, cu
);
10276 /* The die_type call above may have already set the type for this DIE. */
10277 cv_type
= get_die_type (die
, cu
);
10281 /* In case the const qualifier is applied to an array type, the element type
10282 is so qualified, not the array type (section 6.7.3 of C99). */
10283 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10285 struct type
*el_type
, *inner_array
;
10287 base_type
= copy_type (base_type
);
10288 inner_array
= base_type
;
10290 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10292 TYPE_TARGET_TYPE (inner_array
) =
10293 copy_type (TYPE_TARGET_TYPE (inner_array
));
10294 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10297 el_type
= TYPE_TARGET_TYPE (inner_array
);
10298 TYPE_TARGET_TYPE (inner_array
) =
10299 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10301 return set_die_type (die
, base_type
, cu
);
10304 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10305 return set_die_type (die
, cv_type
, cu
);
10308 static struct type
*
10309 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10311 struct type
*base_type
, *cv_type
;
10313 base_type
= die_type (die
, cu
);
10315 /* The die_type call above may have already set the type for this DIE. */
10316 cv_type
= get_die_type (die
, cu
);
10320 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10321 return set_die_type (die
, cv_type
, cu
);
10324 /* Extract all information from a DW_TAG_string_type DIE and add to
10325 the user defined type vector. It isn't really a user defined type,
10326 but it behaves like one, with other DIE's using an AT_user_def_type
10327 attribute to reference it. */
10329 static struct type
*
10330 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10332 struct objfile
*objfile
= cu
->objfile
;
10333 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10334 struct type
*type
, *range_type
, *index_type
, *char_type
;
10335 struct attribute
*attr
;
10336 unsigned int length
;
10338 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10341 length
= DW_UNSND (attr
);
10345 /* Check for the DW_AT_byte_size attribute. */
10346 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10349 length
= DW_UNSND (attr
);
10357 index_type
= objfile_type (objfile
)->builtin_int
;
10358 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10359 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10360 type
= create_string_type (NULL
, char_type
, range_type
);
10362 return set_die_type (die
, type
, cu
);
10365 /* Handle DIES due to C code like:
10369 int (*funcp)(int a, long l);
10373 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10375 static struct type
*
10376 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10378 struct objfile
*objfile
= cu
->objfile
;
10379 struct type
*type
; /* Type that this function returns. */
10380 struct type
*ftype
; /* Function that returns above type. */
10381 struct attribute
*attr
;
10383 type
= die_type (die
, cu
);
10385 /* The die_type call above may have already set the type for this DIE. */
10386 ftype
= get_die_type (die
, cu
);
10390 ftype
= lookup_function_type (type
);
10392 /* All functions in C++, Pascal and Java have prototypes. */
10393 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10394 if ((attr
&& (DW_UNSND (attr
) != 0))
10395 || cu
->language
== language_cplus
10396 || cu
->language
== language_java
10397 || cu
->language
== language_pascal
)
10398 TYPE_PROTOTYPED (ftype
) = 1;
10399 else if (producer_is_realview (cu
->producer
))
10400 /* RealView does not emit DW_AT_prototyped. We can not
10401 distinguish prototyped and unprototyped functions; default to
10402 prototyped, since that is more common in modern code (and
10403 RealView warns about unprototyped functions). */
10404 TYPE_PROTOTYPED (ftype
) = 1;
10406 /* Store the calling convention in the type if it's available in
10407 the subroutine die. Otherwise set the calling convention to
10408 the default value DW_CC_normal. */
10409 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10411 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10412 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10413 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10415 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10417 /* We need to add the subroutine type to the die immediately so
10418 we don't infinitely recurse when dealing with parameters
10419 declared as the same subroutine type. */
10420 set_die_type (die
, ftype
, cu
);
10422 if (die
->child
!= NULL
)
10424 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10425 struct die_info
*child_die
;
10426 int nparams
, iparams
;
10428 /* Count the number of parameters.
10429 FIXME: GDB currently ignores vararg functions, but knows about
10430 vararg member functions. */
10432 child_die
= die
->child
;
10433 while (child_die
&& child_die
->tag
)
10435 if (child_die
->tag
== DW_TAG_formal_parameter
)
10437 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10438 TYPE_VARARGS (ftype
) = 1;
10439 child_die
= sibling_die (child_die
);
10442 /* Allocate storage for parameters and fill them in. */
10443 TYPE_NFIELDS (ftype
) = nparams
;
10444 TYPE_FIELDS (ftype
) = (struct field
*)
10445 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10447 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10448 even if we error out during the parameters reading below. */
10449 for (iparams
= 0; iparams
< nparams
; iparams
++)
10450 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10453 child_die
= die
->child
;
10454 while (child_die
&& child_die
->tag
)
10456 if (child_die
->tag
== DW_TAG_formal_parameter
)
10458 struct type
*arg_type
;
10460 /* DWARF version 2 has no clean way to discern C++
10461 static and non-static member functions. G++ helps
10462 GDB by marking the first parameter for non-static
10463 member functions (which is the this pointer) as
10464 artificial. We pass this information to
10465 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10467 DWARF version 3 added DW_AT_object_pointer, which GCC
10468 4.5 does not yet generate. */
10469 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10471 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10474 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10476 /* GCC/43521: In java, the formal parameter
10477 "this" is sometimes not marked with DW_AT_artificial. */
10478 if (cu
->language
== language_java
)
10480 const char *name
= dwarf2_name (child_die
, cu
);
10482 if (name
&& !strcmp (name
, "this"))
10483 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10486 arg_type
= die_type (child_die
, cu
);
10488 /* RealView does not mark THIS as const, which the testsuite
10489 expects. GCC marks THIS as const in method definitions,
10490 but not in the class specifications (GCC PR 43053). */
10491 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10492 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10495 struct dwarf2_cu
*arg_cu
= cu
;
10496 const char *name
= dwarf2_name (child_die
, cu
);
10498 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10501 /* If the compiler emits this, use it. */
10502 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10505 else if (name
&& strcmp (name
, "this") == 0)
10506 /* Function definitions will have the argument names. */
10508 else if (name
== NULL
&& iparams
== 0)
10509 /* Declarations may not have the names, so like
10510 elsewhere in GDB, assume an artificial first
10511 argument is "this". */
10515 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10519 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10522 child_die
= sibling_die (child_die
);
10529 static struct type
*
10530 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10532 struct objfile
*objfile
= cu
->objfile
;
10533 const char *name
= NULL
;
10534 struct type
*this_type
, *target_type
;
10536 name
= dwarf2_full_name (NULL
, die
, cu
);
10537 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10538 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10539 TYPE_NAME (this_type
) = (char *) name
;
10540 set_die_type (die
, this_type
, cu
);
10541 target_type
= die_type (die
, cu
);
10542 if (target_type
!= this_type
)
10543 TYPE_TARGET_TYPE (this_type
) = target_type
;
10546 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10547 spec and cause infinite loops in GDB. */
10548 complaint (&symfile_complaints
,
10549 _("Self-referential DW_TAG_typedef "
10550 "- DIE at 0x%x [in module %s]"),
10551 die
->offset
.sect_off
, objfile
->name
);
10552 TYPE_TARGET_TYPE (this_type
) = NULL
;
10557 /* Find a representation of a given base type and install
10558 it in the TYPE field of the die. */
10560 static struct type
*
10561 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10563 struct objfile
*objfile
= cu
->objfile
;
10565 struct attribute
*attr
;
10566 int encoding
= 0, size
= 0;
10568 enum type_code code
= TYPE_CODE_INT
;
10569 int type_flags
= 0;
10570 struct type
*target_type
= NULL
;
10572 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10575 encoding
= DW_UNSND (attr
);
10577 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10580 size
= DW_UNSND (attr
);
10582 name
= dwarf2_name (die
, cu
);
10585 complaint (&symfile_complaints
,
10586 _("DW_AT_name missing from DW_TAG_base_type"));
10591 case DW_ATE_address
:
10592 /* Turn DW_ATE_address into a void * pointer. */
10593 code
= TYPE_CODE_PTR
;
10594 type_flags
|= TYPE_FLAG_UNSIGNED
;
10595 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10597 case DW_ATE_boolean
:
10598 code
= TYPE_CODE_BOOL
;
10599 type_flags
|= TYPE_FLAG_UNSIGNED
;
10601 case DW_ATE_complex_float
:
10602 code
= TYPE_CODE_COMPLEX
;
10603 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10605 case DW_ATE_decimal_float
:
10606 code
= TYPE_CODE_DECFLOAT
;
10609 code
= TYPE_CODE_FLT
;
10611 case DW_ATE_signed
:
10613 case DW_ATE_unsigned
:
10614 type_flags
|= TYPE_FLAG_UNSIGNED
;
10615 if (cu
->language
== language_fortran
10617 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10618 code
= TYPE_CODE_CHAR
;
10620 case DW_ATE_signed_char
:
10621 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10622 || cu
->language
== language_pascal
10623 || cu
->language
== language_fortran
)
10624 code
= TYPE_CODE_CHAR
;
10626 case DW_ATE_unsigned_char
:
10627 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10628 || cu
->language
== language_pascal
10629 || cu
->language
== language_fortran
)
10630 code
= TYPE_CODE_CHAR
;
10631 type_flags
|= TYPE_FLAG_UNSIGNED
;
10634 /* We just treat this as an integer and then recognize the
10635 type by name elsewhere. */
10639 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10640 dwarf_type_encoding_name (encoding
));
10644 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10645 TYPE_NAME (type
) = name
;
10646 TYPE_TARGET_TYPE (type
) = target_type
;
10648 if (name
&& strcmp (name
, "char") == 0)
10649 TYPE_NOSIGN (type
) = 1;
10651 return set_die_type (die
, type
, cu
);
10654 /* Read the given DW_AT_subrange DIE. */
10656 static struct type
*
10657 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10659 struct type
*base_type
;
10660 struct type
*range_type
;
10661 struct attribute
*attr
;
10663 int low_default_is_valid
;
10665 LONGEST negative_mask
;
10667 base_type
= die_type (die
, cu
);
10668 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10669 check_typedef (base_type
);
10671 /* The die_type call above may have already set the type for this DIE. */
10672 range_type
= get_die_type (die
, cu
);
10676 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10677 omitting DW_AT_lower_bound. */
10678 switch (cu
->language
)
10681 case language_cplus
:
10683 low_default_is_valid
= 1;
10685 case language_fortran
:
10687 low_default_is_valid
= 1;
10690 case language_java
:
10691 case language_objc
:
10693 low_default_is_valid
= (cu
->header
.version
>= 4);
10697 case language_pascal
:
10699 low_default_is_valid
= (cu
->header
.version
>= 4);
10703 low_default_is_valid
= 0;
10707 /* FIXME: For variable sized arrays either of these could be
10708 a variable rather than a constant value. We'll allow it,
10709 but we don't know how to handle it. */
10710 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10712 low
= dwarf2_get_attr_constant_value (attr
, low
);
10713 else if (!low_default_is_valid
)
10714 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10715 "- DIE at 0x%x [in module %s]"),
10716 die
->offset
.sect_off
, cu
->objfile
->name
);
10718 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10721 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10723 /* GCC encodes arrays with unspecified or dynamic length
10724 with a DW_FORM_block1 attribute or a reference attribute.
10725 FIXME: GDB does not yet know how to handle dynamic
10726 arrays properly, treat them as arrays with unspecified
10729 FIXME: jimb/2003-09-22: GDB does not really know
10730 how to handle arrays of unspecified length
10731 either; we just represent them as zero-length
10732 arrays. Choose an appropriate upper bound given
10733 the lower bound we've computed above. */
10737 high
= dwarf2_get_attr_constant_value (attr
, 1);
10741 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10744 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10745 high
= low
+ count
- 1;
10749 /* Unspecified array length. */
10754 /* Dwarf-2 specifications explicitly allows to create subrange types
10755 without specifying a base type.
10756 In that case, the base type must be set to the type of
10757 the lower bound, upper bound or count, in that order, if any of these
10758 three attributes references an object that has a type.
10759 If no base type is found, the Dwarf-2 specifications say that
10760 a signed integer type of size equal to the size of an address should
10762 For the following C code: `extern char gdb_int [];'
10763 GCC produces an empty range DIE.
10764 FIXME: muller/2010-05-28: Possible references to object for low bound,
10765 high bound or count are not yet handled by this code. */
10766 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10768 struct objfile
*objfile
= cu
->objfile
;
10769 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10770 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10771 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10773 /* Test "int", "long int", and "long long int" objfile types,
10774 and select the first one having a size above or equal to the
10775 architecture address size. */
10776 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10777 base_type
= int_type
;
10780 int_type
= objfile_type (objfile
)->builtin_long
;
10781 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10782 base_type
= int_type
;
10785 int_type
= objfile_type (objfile
)->builtin_long_long
;
10786 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10787 base_type
= int_type
;
10793 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10794 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10795 low
|= negative_mask
;
10796 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10797 high
|= negative_mask
;
10799 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10801 /* Mark arrays with dynamic length at least as an array of unspecified
10802 length. GDB could check the boundary but before it gets implemented at
10803 least allow accessing the array elements. */
10804 if (attr
&& attr_form_is_block (attr
))
10805 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10807 /* Ada expects an empty array on no boundary attributes. */
10808 if (attr
== NULL
&& cu
->language
!= language_ada
)
10809 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10811 name
= dwarf2_name (die
, cu
);
10813 TYPE_NAME (range_type
) = name
;
10815 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10817 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10819 set_die_type (die
, range_type
, cu
);
10821 /* set_die_type should be already done. */
10822 set_descriptive_type (range_type
, die
, cu
);
10827 static struct type
*
10828 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10832 /* For now, we only support the C meaning of an unspecified type: void. */
10834 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10835 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10837 return set_die_type (die
, type
, cu
);
10840 /* Read a single die and all its descendents. Set the die's sibling
10841 field to NULL; set other fields in the die correctly, and set all
10842 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10843 location of the info_ptr after reading all of those dies. PARENT
10844 is the parent of the die in question. */
10846 static struct die_info
*
10847 read_die_and_children (const struct die_reader_specs
*reader
,
10848 gdb_byte
*info_ptr
,
10849 gdb_byte
**new_info_ptr
,
10850 struct die_info
*parent
)
10852 struct die_info
*die
;
10856 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10859 *new_info_ptr
= cur_ptr
;
10862 store_in_ref_table (die
, reader
->cu
);
10865 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10869 *new_info_ptr
= cur_ptr
;
10872 die
->sibling
= NULL
;
10873 die
->parent
= parent
;
10877 /* Read a die, all of its descendents, and all of its siblings; set
10878 all of the fields of all of the dies correctly. Arguments are as
10879 in read_die_and_children. */
10881 static struct die_info
*
10882 read_die_and_siblings (const struct die_reader_specs
*reader
,
10883 gdb_byte
*info_ptr
,
10884 gdb_byte
**new_info_ptr
,
10885 struct die_info
*parent
)
10887 struct die_info
*first_die
, *last_sibling
;
10890 cur_ptr
= info_ptr
;
10891 first_die
= last_sibling
= NULL
;
10895 struct die_info
*die
10896 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10900 *new_info_ptr
= cur_ptr
;
10907 last_sibling
->sibling
= die
;
10909 last_sibling
= die
;
10913 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10915 The caller is responsible for filling in the extra attributes
10916 and updating (*DIEP)->num_attrs.
10917 Set DIEP to point to a newly allocated die with its information,
10918 except for its child, sibling, and parent fields.
10919 Set HAS_CHILDREN to tell whether the die has children or not. */
10922 read_full_die_1 (const struct die_reader_specs
*reader
,
10923 struct die_info
**diep
, gdb_byte
*info_ptr
,
10924 int *has_children
, int num_extra_attrs
)
10926 unsigned int abbrev_number
, bytes_read
, i
;
10927 sect_offset offset
;
10928 struct abbrev_info
*abbrev
;
10929 struct die_info
*die
;
10930 struct dwarf2_cu
*cu
= reader
->cu
;
10931 bfd
*abfd
= reader
->abfd
;
10933 offset
.sect_off
= info_ptr
- reader
->buffer
;
10934 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10935 info_ptr
+= bytes_read
;
10936 if (!abbrev_number
)
10943 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
10945 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10947 bfd_get_filename (abfd
));
10949 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10950 die
->offset
= offset
;
10951 die
->tag
= abbrev
->tag
;
10952 die
->abbrev
= abbrev_number
;
10954 /* Make the result usable.
10955 The caller needs to update num_attrs after adding the extra
10957 die
->num_attrs
= abbrev
->num_attrs
;
10959 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10960 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10964 *has_children
= abbrev
->has_children
;
10968 /* Read a die and all its attributes.
10969 Set DIEP to point to a newly allocated die with its information,
10970 except for its child, sibling, and parent fields.
10971 Set HAS_CHILDREN to tell whether the die has children or not. */
10974 read_full_die (const struct die_reader_specs
*reader
,
10975 struct die_info
**diep
, gdb_byte
*info_ptr
,
10978 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10981 /* Abbreviation tables.
10983 In DWARF version 2, the description of the debugging information is
10984 stored in a separate .debug_abbrev section. Before we read any
10985 dies from a section we read in all abbreviations and install them
10986 in a hash table. */
10988 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
10990 static struct abbrev_info
*
10991 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
10993 struct abbrev_info
*abbrev
;
10995 abbrev
= (struct abbrev_info
*)
10996 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
10997 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11001 /* Add an abbreviation to the table. */
11004 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11005 unsigned int abbrev_number
,
11006 struct abbrev_info
*abbrev
)
11008 unsigned int hash_number
;
11010 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11011 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11012 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11015 /* Look up an abbrev in the table.
11016 Returns NULL if the abbrev is not found. */
11018 static struct abbrev_info
*
11019 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11020 unsigned int abbrev_number
)
11022 unsigned int hash_number
;
11023 struct abbrev_info
*abbrev
;
11025 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11026 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11030 if (abbrev
->number
== abbrev_number
)
11032 abbrev
= abbrev
->next
;
11037 /* Read in an abbrev table. */
11039 static struct abbrev_table
*
11040 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11041 sect_offset offset
)
11043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11044 bfd
*abfd
= section
->asection
->owner
;
11045 struct abbrev_table
*abbrev_table
;
11046 gdb_byte
*abbrev_ptr
;
11047 struct abbrev_info
*cur_abbrev
;
11048 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11049 unsigned int abbrev_form
;
11050 struct attr_abbrev
*cur_attrs
;
11051 unsigned int allocated_attrs
;
11053 abbrev_table
= XMALLOC (struct abbrev_table
);
11054 obstack_init (&abbrev_table
->abbrev_obstack
);
11055 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11057 * sizeof (struct abbrev_info
*)));
11058 memset (abbrev_table
->abbrevs
, 0,
11059 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
11061 dwarf2_read_section (objfile
, section
);
11062 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
11063 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11064 abbrev_ptr
+= bytes_read
;
11066 allocated_attrs
= ATTR_ALLOC_CHUNK
;
11067 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
11069 /* Loop until we reach an abbrev number of 0. */
11070 while (abbrev_number
)
11072 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
11074 /* read in abbrev header */
11075 cur_abbrev
->number
= abbrev_number
;
11076 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11077 abbrev_ptr
+= bytes_read
;
11078 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
11081 /* now read in declarations */
11082 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11083 abbrev_ptr
+= bytes_read
;
11084 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11085 abbrev_ptr
+= bytes_read
;
11086 while (abbrev_name
)
11088 if (cur_abbrev
->num_attrs
== allocated_attrs
)
11090 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
11092 = xrealloc (cur_attrs
, (allocated_attrs
11093 * sizeof (struct attr_abbrev
)));
11096 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
11097 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
11098 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11099 abbrev_ptr
+= bytes_read
;
11100 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11101 abbrev_ptr
+= bytes_read
;
11104 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11105 (cur_abbrev
->num_attrs
11106 * sizeof (struct attr_abbrev
)));
11107 memcpy (cur_abbrev
->attrs
, cur_attrs
,
11108 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
11110 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
11112 /* Get next abbreviation.
11113 Under Irix6 the abbreviations for a compilation unit are not
11114 always properly terminated with an abbrev number of 0.
11115 Exit loop if we encounter an abbreviation which we have
11116 already read (which means we are about to read the abbreviations
11117 for the next compile unit) or if the end of the abbreviation
11118 table is reached. */
11119 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
11121 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11122 abbrev_ptr
+= bytes_read
;
11123 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
11128 return abbrev_table
;
11131 /* Free the resources held by ABBREV_TABLE. */
11134 abbrev_table_free (struct abbrev_table
*abbrev_table
)
11136 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
11137 xfree (abbrev_table
);
11140 /* Read the abbrev table for CU from ABBREV_SECTION. */
11143 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
11144 struct dwarf2_section_info
*abbrev_section
)
11147 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
11150 /* Release the memory used by the abbrev table for a compilation unit. */
11153 dwarf2_free_abbrev_table (void *ptr_to_cu
)
11155 struct dwarf2_cu
*cu
= ptr_to_cu
;
11157 abbrev_table_free (cu
->abbrev_table
);
11158 /* Set this to NULL so that we SEGV if we try to read it later,
11159 and also because free_comp_unit verifies this is NULL. */
11160 cu
->abbrev_table
= NULL
;
11163 /* Returns nonzero if TAG represents a type that we might generate a partial
11167 is_type_tag_for_partial (int tag
)
11172 /* Some types that would be reasonable to generate partial symbols for,
11173 that we don't at present. */
11174 case DW_TAG_array_type
:
11175 case DW_TAG_file_type
:
11176 case DW_TAG_ptr_to_member_type
:
11177 case DW_TAG_set_type
:
11178 case DW_TAG_string_type
:
11179 case DW_TAG_subroutine_type
:
11181 case DW_TAG_base_type
:
11182 case DW_TAG_class_type
:
11183 case DW_TAG_interface_type
:
11184 case DW_TAG_enumeration_type
:
11185 case DW_TAG_structure_type
:
11186 case DW_TAG_subrange_type
:
11187 case DW_TAG_typedef
:
11188 case DW_TAG_union_type
:
11195 /* Load all DIEs that are interesting for partial symbols into memory. */
11197 static struct partial_die_info
*
11198 load_partial_dies (const struct die_reader_specs
*reader
,
11199 gdb_byte
*info_ptr
, int building_psymtab
)
11201 struct dwarf2_cu
*cu
= reader
->cu
;
11202 struct objfile
*objfile
= cu
->objfile
;
11203 struct partial_die_info
*part_die
;
11204 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
11205 struct abbrev_info
*abbrev
;
11206 unsigned int bytes_read
;
11207 unsigned int load_all
= 0;
11208 int nesting_level
= 1;
11213 gdb_assert (cu
->per_cu
!= NULL
);
11214 if (cu
->per_cu
->load_all_dies
)
11218 = htab_create_alloc_ex (cu
->header
.length
/ 12,
11222 &cu
->comp_unit_obstack
,
11223 hashtab_obstack_allocate
,
11224 dummy_obstack_deallocate
);
11226 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11227 sizeof (struct partial_die_info
));
11231 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
11233 /* A NULL abbrev means the end of a series of children. */
11234 if (abbrev
== NULL
)
11236 if (--nesting_level
== 0)
11238 /* PART_DIE was probably the last thing allocated on the
11239 comp_unit_obstack, so we could call obstack_free
11240 here. We don't do that because the waste is small,
11241 and will be cleaned up when we're done with this
11242 compilation unit. This way, we're also more robust
11243 against other users of the comp_unit_obstack. */
11246 info_ptr
+= bytes_read
;
11247 last_die
= parent_die
;
11248 parent_die
= parent_die
->die_parent
;
11252 /* Check for template arguments. We never save these; if
11253 they're seen, we just mark the parent, and go on our way. */
11254 if (parent_die
!= NULL
11255 && cu
->language
== language_cplus
11256 && (abbrev
->tag
== DW_TAG_template_type_param
11257 || abbrev
->tag
== DW_TAG_template_value_param
))
11259 parent_die
->has_template_arguments
= 1;
11263 /* We don't need a partial DIE for the template argument. */
11264 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11269 /* We only recurse into c++ subprograms looking for template arguments.
11270 Skip their other children. */
11272 && cu
->language
== language_cplus
11273 && parent_die
!= NULL
11274 && parent_die
->tag
== DW_TAG_subprogram
)
11276 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11280 /* Check whether this DIE is interesting enough to save. Normally
11281 we would not be interested in members here, but there may be
11282 later variables referencing them via DW_AT_specification (for
11283 static members). */
11285 && !is_type_tag_for_partial (abbrev
->tag
)
11286 && abbrev
->tag
!= DW_TAG_constant
11287 && abbrev
->tag
!= DW_TAG_enumerator
11288 && abbrev
->tag
!= DW_TAG_subprogram
11289 && abbrev
->tag
!= DW_TAG_lexical_block
11290 && abbrev
->tag
!= DW_TAG_variable
11291 && abbrev
->tag
!= DW_TAG_namespace
11292 && abbrev
->tag
!= DW_TAG_module
11293 && abbrev
->tag
!= DW_TAG_member
11294 && abbrev
->tag
!= DW_TAG_imported_unit
)
11296 /* Otherwise we skip to the next sibling, if any. */
11297 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11301 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
11304 /* This two-pass algorithm for processing partial symbols has a
11305 high cost in cache pressure. Thus, handle some simple cases
11306 here which cover the majority of C partial symbols. DIEs
11307 which neither have specification tags in them, nor could have
11308 specification tags elsewhere pointing at them, can simply be
11309 processed and discarded.
11311 This segment is also optional; scan_partial_symbols and
11312 add_partial_symbol will handle these DIEs if we chain
11313 them in normally. When compilers which do not emit large
11314 quantities of duplicate debug information are more common,
11315 this code can probably be removed. */
11317 /* Any complete simple types at the top level (pretty much all
11318 of them, for a language without namespaces), can be processed
11320 if (parent_die
== NULL
11321 && part_die
->has_specification
== 0
11322 && part_die
->is_declaration
== 0
11323 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11324 || part_die
->tag
== DW_TAG_base_type
11325 || part_die
->tag
== DW_TAG_subrange_type
))
11327 if (building_psymtab
&& part_die
->name
!= NULL
)
11328 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11329 VAR_DOMAIN
, LOC_TYPEDEF
,
11330 &objfile
->static_psymbols
,
11331 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11332 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11336 /* The exception for DW_TAG_typedef with has_children above is
11337 a workaround of GCC PR debug/47510. In the case of this complaint
11338 type_name_no_tag_or_error will error on such types later.
11340 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11341 it could not find the child DIEs referenced later, this is checked
11342 above. In correct DWARF DW_TAG_typedef should have no children. */
11344 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11345 complaint (&symfile_complaints
,
11346 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11347 "- DIE at 0x%x [in module %s]"),
11348 part_die
->offset
.sect_off
, objfile
->name
);
11350 /* If we're at the second level, and we're an enumerator, and
11351 our parent has no specification (meaning possibly lives in a
11352 namespace elsewhere), then we can add the partial symbol now
11353 instead of queueing it. */
11354 if (part_die
->tag
== DW_TAG_enumerator
11355 && parent_die
!= NULL
11356 && parent_die
->die_parent
== NULL
11357 && parent_die
->tag
== DW_TAG_enumeration_type
11358 && parent_die
->has_specification
== 0)
11360 if (part_die
->name
== NULL
)
11361 complaint (&symfile_complaints
,
11362 _("malformed enumerator DIE ignored"));
11363 else if (building_psymtab
)
11364 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11365 VAR_DOMAIN
, LOC_CONST
,
11366 (cu
->language
== language_cplus
11367 || cu
->language
== language_java
)
11368 ? &objfile
->global_psymbols
11369 : &objfile
->static_psymbols
,
11370 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11372 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11376 /* We'll save this DIE so link it in. */
11377 part_die
->die_parent
= parent_die
;
11378 part_die
->die_sibling
= NULL
;
11379 part_die
->die_child
= NULL
;
11381 if (last_die
&& last_die
== parent_die
)
11382 last_die
->die_child
= part_die
;
11384 last_die
->die_sibling
= part_die
;
11386 last_die
= part_die
;
11388 if (first_die
== NULL
)
11389 first_die
= part_die
;
11391 /* Maybe add the DIE to the hash table. Not all DIEs that we
11392 find interesting need to be in the hash table, because we
11393 also have the parent/sibling/child chains; only those that we
11394 might refer to by offset later during partial symbol reading.
11396 For now this means things that might have be the target of a
11397 DW_AT_specification, DW_AT_abstract_origin, or
11398 DW_AT_extension. DW_AT_extension will refer only to
11399 namespaces; DW_AT_abstract_origin refers to functions (and
11400 many things under the function DIE, but we do not recurse
11401 into function DIEs during partial symbol reading) and
11402 possibly variables as well; DW_AT_specification refers to
11403 declarations. Declarations ought to have the DW_AT_declaration
11404 flag. It happens that GCC forgets to put it in sometimes, but
11405 only for functions, not for types.
11407 Adding more things than necessary to the hash table is harmless
11408 except for the performance cost. Adding too few will result in
11409 wasted time in find_partial_die, when we reread the compilation
11410 unit with load_all_dies set. */
11413 || abbrev
->tag
== DW_TAG_constant
11414 || abbrev
->tag
== DW_TAG_subprogram
11415 || abbrev
->tag
== DW_TAG_variable
11416 || abbrev
->tag
== DW_TAG_namespace
11417 || part_die
->is_declaration
)
11421 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11422 part_die
->offset
.sect_off
, INSERT
);
11426 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11427 sizeof (struct partial_die_info
));
11429 /* For some DIEs we want to follow their children (if any). For C
11430 we have no reason to follow the children of structures; for other
11431 languages we have to, so that we can get at method physnames
11432 to infer fully qualified class names, for DW_AT_specification,
11433 and for C++ template arguments. For C++, we also look one level
11434 inside functions to find template arguments (if the name of the
11435 function does not already contain the template arguments).
11437 For Ada, we need to scan the children of subprograms and lexical
11438 blocks as well because Ada allows the definition of nested
11439 entities that could be interesting for the debugger, such as
11440 nested subprograms for instance. */
11441 if (last_die
->has_children
11443 || last_die
->tag
== DW_TAG_namespace
11444 || last_die
->tag
== DW_TAG_module
11445 || last_die
->tag
== DW_TAG_enumeration_type
11446 || (cu
->language
== language_cplus
11447 && last_die
->tag
== DW_TAG_subprogram
11448 && (last_die
->name
== NULL
11449 || strchr (last_die
->name
, '<') == NULL
))
11450 || (cu
->language
!= language_c
11451 && (last_die
->tag
== DW_TAG_class_type
11452 || last_die
->tag
== DW_TAG_interface_type
11453 || last_die
->tag
== DW_TAG_structure_type
11454 || last_die
->tag
== DW_TAG_union_type
))
11455 || (cu
->language
== language_ada
11456 && (last_die
->tag
== DW_TAG_subprogram
11457 || last_die
->tag
== DW_TAG_lexical_block
))))
11460 parent_die
= last_die
;
11464 /* Otherwise we skip to the next sibling, if any. */
11465 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11467 /* Back to the top, do it again. */
11471 /* Read a minimal amount of information into the minimal die structure. */
11474 read_partial_die (const struct die_reader_specs
*reader
,
11475 struct partial_die_info
*part_die
,
11476 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11477 gdb_byte
*info_ptr
)
11479 struct dwarf2_cu
*cu
= reader
->cu
;
11480 struct objfile
*objfile
= cu
->objfile
;
11481 gdb_byte
*buffer
= reader
->buffer
;
11483 struct attribute attr
;
11484 int has_low_pc_attr
= 0;
11485 int has_high_pc_attr
= 0;
11486 int high_pc_relative
= 0;
11488 memset (part_die
, 0, sizeof (struct partial_die_info
));
11490 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11492 info_ptr
+= abbrev_len
;
11494 if (abbrev
== NULL
)
11497 part_die
->tag
= abbrev
->tag
;
11498 part_die
->has_children
= abbrev
->has_children
;
11500 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11502 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11504 /* Store the data if it is of an attribute we want to keep in a
11505 partial symbol table. */
11509 switch (part_die
->tag
)
11511 case DW_TAG_compile_unit
:
11512 case DW_TAG_partial_unit
:
11513 case DW_TAG_type_unit
:
11514 /* Compilation units have a DW_AT_name that is a filename, not
11515 a source language identifier. */
11516 case DW_TAG_enumeration_type
:
11517 case DW_TAG_enumerator
:
11518 /* These tags always have simple identifiers already; no need
11519 to canonicalize them. */
11520 part_die
->name
= DW_STRING (&attr
);
11524 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11525 &objfile
->objfile_obstack
);
11529 case DW_AT_linkage_name
:
11530 case DW_AT_MIPS_linkage_name
:
11531 /* Note that both forms of linkage name might appear. We
11532 assume they will be the same, and we only store the last
11534 if (cu
->language
== language_ada
)
11535 part_die
->name
= DW_STRING (&attr
);
11536 part_die
->linkage_name
= DW_STRING (&attr
);
11539 has_low_pc_attr
= 1;
11540 part_die
->lowpc
= DW_ADDR (&attr
);
11542 case DW_AT_high_pc
:
11543 has_high_pc_attr
= 1;
11544 if (attr
.form
== DW_FORM_addr
11545 || attr
.form
== DW_FORM_GNU_addr_index
)
11546 part_die
->highpc
= DW_ADDR (&attr
);
11549 high_pc_relative
= 1;
11550 part_die
->highpc
= DW_UNSND (&attr
);
11553 case DW_AT_location
:
11554 /* Support the .debug_loc offsets. */
11555 if (attr_form_is_block (&attr
))
11557 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11559 else if (attr_form_is_section_offset (&attr
))
11561 dwarf2_complex_location_expr_complaint ();
11565 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11566 "partial symbol information");
11569 case DW_AT_external
:
11570 part_die
->is_external
= DW_UNSND (&attr
);
11572 case DW_AT_declaration
:
11573 part_die
->is_declaration
= DW_UNSND (&attr
);
11576 part_die
->has_type
= 1;
11578 case DW_AT_abstract_origin
:
11579 case DW_AT_specification
:
11580 case DW_AT_extension
:
11581 part_die
->has_specification
= 1;
11582 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11584 case DW_AT_sibling
:
11585 /* Ignore absolute siblings, they might point outside of
11586 the current compile unit. */
11587 if (attr
.form
== DW_FORM_ref_addr
)
11588 complaint (&symfile_complaints
,
11589 _("ignoring absolute DW_AT_sibling"));
11591 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11593 case DW_AT_byte_size
:
11594 part_die
->has_byte_size
= 1;
11596 case DW_AT_calling_convention
:
11597 /* DWARF doesn't provide a way to identify a program's source-level
11598 entry point. DW_AT_calling_convention attributes are only meant
11599 to describe functions' calling conventions.
11601 However, because it's a necessary piece of information in
11602 Fortran, and because DW_CC_program is the only piece of debugging
11603 information whose definition refers to a 'main program' at all,
11604 several compilers have begun marking Fortran main programs with
11605 DW_CC_program --- even when those functions use the standard
11606 calling conventions.
11608 So until DWARF specifies a way to provide this information and
11609 compilers pick up the new representation, we'll support this
11611 if (DW_UNSND (&attr
) == DW_CC_program
11612 && cu
->language
== language_fortran
)
11614 set_main_name (part_die
->name
);
11616 /* As this DIE has a static linkage the name would be difficult
11617 to look up later. */
11618 language_of_main
= language_fortran
;
11622 if (DW_UNSND (&attr
) == DW_INL_inlined
11623 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11624 part_die
->may_be_inlined
= 1;
11628 if (part_die
->tag
== DW_TAG_imported_unit
)
11629 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11637 if (high_pc_relative
)
11638 part_die
->highpc
+= part_die
->lowpc
;
11640 if (has_low_pc_attr
&& has_high_pc_attr
)
11642 /* When using the GNU linker, .gnu.linkonce. sections are used to
11643 eliminate duplicate copies of functions and vtables and such.
11644 The linker will arbitrarily choose one and discard the others.
11645 The AT_*_pc values for such functions refer to local labels in
11646 these sections. If the section from that file was discarded, the
11647 labels are not in the output, so the relocs get a value of 0.
11648 If this is a discarded function, mark the pc bounds as invalid,
11649 so that GDB will ignore it. */
11650 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11652 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11654 complaint (&symfile_complaints
,
11655 _("DW_AT_low_pc %s is zero "
11656 "for DIE at 0x%x [in module %s]"),
11657 paddress (gdbarch
, part_die
->lowpc
),
11658 part_die
->offset
.sect_off
, objfile
->name
);
11660 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11661 else if (part_die
->lowpc
>= part_die
->highpc
)
11663 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11665 complaint (&symfile_complaints
,
11666 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11667 "for DIE at 0x%x [in module %s]"),
11668 paddress (gdbarch
, part_die
->lowpc
),
11669 paddress (gdbarch
, part_die
->highpc
),
11670 part_die
->offset
.sect_off
, objfile
->name
);
11673 part_die
->has_pc_info
= 1;
11679 /* Find a cached partial DIE at OFFSET in CU. */
11681 static struct partial_die_info
*
11682 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11684 struct partial_die_info
*lookup_die
= NULL
;
11685 struct partial_die_info part_die
;
11687 part_die
.offset
= offset
;
11688 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11694 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11695 except in the case of .debug_types DIEs which do not reference
11696 outside their CU (they do however referencing other types via
11697 DW_FORM_ref_sig8). */
11699 static struct partial_die_info
*
11700 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11702 struct objfile
*objfile
= cu
->objfile
;
11703 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11704 struct partial_die_info
*pd
= NULL
;
11706 if (offset_in_cu_p (&cu
->header
, offset
))
11708 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11711 /* We missed recording what we needed.
11712 Load all dies and try again. */
11713 per_cu
= cu
->per_cu
;
11717 /* TUs don't reference other CUs/TUs (except via type signatures). */
11718 if (cu
->per_cu
->is_debug_types
)
11720 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11721 " external reference to offset 0x%lx [in module %s].\n"),
11722 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11723 bfd_get_filename (objfile
->obfd
));
11725 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11727 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11728 load_partial_comp_unit (per_cu
);
11730 per_cu
->cu
->last_used
= 0;
11731 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11734 /* If we didn't find it, and not all dies have been loaded,
11735 load them all and try again. */
11737 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11739 per_cu
->load_all_dies
= 1;
11741 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11742 THIS_CU->cu may already be in use. So we can't just free it and
11743 replace its DIEs with the ones we read in. Instead, we leave those
11744 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11745 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11747 load_partial_comp_unit (per_cu
);
11749 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11753 internal_error (__FILE__
, __LINE__
,
11754 _("could not find partial DIE 0x%x "
11755 "in cache [from module %s]\n"),
11756 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11760 /* See if we can figure out if the class lives in a namespace. We do
11761 this by looking for a member function; its demangled name will
11762 contain namespace info, if there is any. */
11765 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11766 struct dwarf2_cu
*cu
)
11768 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11769 what template types look like, because the demangler
11770 frequently doesn't give the same name as the debug info. We
11771 could fix this by only using the demangled name to get the
11772 prefix (but see comment in read_structure_type). */
11774 struct partial_die_info
*real_pdi
;
11775 struct partial_die_info
*child_pdi
;
11777 /* If this DIE (this DIE's specification, if any) has a parent, then
11778 we should not do this. We'll prepend the parent's fully qualified
11779 name when we create the partial symbol. */
11781 real_pdi
= struct_pdi
;
11782 while (real_pdi
->has_specification
)
11783 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11785 if (real_pdi
->die_parent
!= NULL
)
11788 for (child_pdi
= struct_pdi
->die_child
;
11790 child_pdi
= child_pdi
->die_sibling
)
11792 if (child_pdi
->tag
== DW_TAG_subprogram
11793 && child_pdi
->linkage_name
!= NULL
)
11795 char *actual_class_name
11796 = language_class_name_from_physname (cu
->language_defn
,
11797 child_pdi
->linkage_name
);
11798 if (actual_class_name
!= NULL
)
11801 = obsavestring (actual_class_name
,
11802 strlen (actual_class_name
),
11803 &cu
->objfile
->objfile_obstack
);
11804 xfree (actual_class_name
);
11811 /* Adjust PART_DIE before generating a symbol for it. This function
11812 may set the is_external flag or change the DIE's name. */
11815 fixup_partial_die (struct partial_die_info
*part_die
,
11816 struct dwarf2_cu
*cu
)
11818 /* Once we've fixed up a die, there's no point in doing so again.
11819 This also avoids a memory leak if we were to call
11820 guess_partial_die_structure_name multiple times. */
11821 if (part_die
->fixup_called
)
11824 /* If we found a reference attribute and the DIE has no name, try
11825 to find a name in the referred to DIE. */
11827 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11829 struct partial_die_info
*spec_die
;
11831 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11833 fixup_partial_die (spec_die
, cu
);
11835 if (spec_die
->name
)
11837 part_die
->name
= spec_die
->name
;
11839 /* Copy DW_AT_external attribute if it is set. */
11840 if (spec_die
->is_external
)
11841 part_die
->is_external
= spec_die
->is_external
;
11845 /* Set default names for some unnamed DIEs. */
11847 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11848 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11850 /* If there is no parent die to provide a namespace, and there are
11851 children, see if we can determine the namespace from their linkage
11853 if (cu
->language
== language_cplus
11854 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11855 && part_die
->die_parent
== NULL
11856 && part_die
->has_children
11857 && (part_die
->tag
== DW_TAG_class_type
11858 || part_die
->tag
== DW_TAG_structure_type
11859 || part_die
->tag
== DW_TAG_union_type
))
11860 guess_partial_die_structure_name (part_die
, cu
);
11862 /* GCC might emit a nameless struct or union that has a linkage
11863 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11864 if (part_die
->name
== NULL
11865 && (part_die
->tag
== DW_TAG_class_type
11866 || part_die
->tag
== DW_TAG_interface_type
11867 || part_die
->tag
== DW_TAG_structure_type
11868 || part_die
->tag
== DW_TAG_union_type
)
11869 && part_die
->linkage_name
!= NULL
)
11873 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11878 /* Strip any leading namespaces/classes, keep only the base name.
11879 DW_AT_name for named DIEs does not contain the prefixes. */
11880 base
= strrchr (demangled
, ':');
11881 if (base
&& base
> demangled
&& base
[-1] == ':')
11886 part_die
->name
= obsavestring (base
, strlen (base
),
11887 &cu
->objfile
->objfile_obstack
);
11892 part_die
->fixup_called
= 1;
11895 /* Read an attribute value described by an attribute form. */
11898 read_attribute_value (const struct die_reader_specs
*reader
,
11899 struct attribute
*attr
, unsigned form
,
11900 gdb_byte
*info_ptr
)
11902 struct dwarf2_cu
*cu
= reader
->cu
;
11903 bfd
*abfd
= reader
->abfd
;
11904 struct comp_unit_head
*cu_header
= &cu
->header
;
11905 unsigned int bytes_read
;
11906 struct dwarf_block
*blk
;
11911 case DW_FORM_ref_addr
:
11912 if (cu
->header
.version
== 2)
11913 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11915 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11916 &cu
->header
, &bytes_read
);
11917 info_ptr
+= bytes_read
;
11920 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11921 info_ptr
+= bytes_read
;
11923 case DW_FORM_block2
:
11924 blk
= dwarf_alloc_block (cu
);
11925 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11927 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11928 info_ptr
+= blk
->size
;
11929 DW_BLOCK (attr
) = blk
;
11931 case DW_FORM_block4
:
11932 blk
= dwarf_alloc_block (cu
);
11933 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11935 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11936 info_ptr
+= blk
->size
;
11937 DW_BLOCK (attr
) = blk
;
11939 case DW_FORM_data2
:
11940 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11943 case DW_FORM_data4
:
11944 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11947 case DW_FORM_data8
:
11948 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11951 case DW_FORM_sec_offset
:
11952 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11953 info_ptr
+= bytes_read
;
11955 case DW_FORM_string
:
11956 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11957 DW_STRING_IS_CANONICAL (attr
) = 0;
11958 info_ptr
+= bytes_read
;
11961 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11963 DW_STRING_IS_CANONICAL (attr
) = 0;
11964 info_ptr
+= bytes_read
;
11966 case DW_FORM_exprloc
:
11967 case DW_FORM_block
:
11968 blk
= dwarf_alloc_block (cu
);
11969 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11970 info_ptr
+= bytes_read
;
11971 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11972 info_ptr
+= blk
->size
;
11973 DW_BLOCK (attr
) = blk
;
11975 case DW_FORM_block1
:
11976 blk
= dwarf_alloc_block (cu
);
11977 blk
->size
= read_1_byte (abfd
, info_ptr
);
11979 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11980 info_ptr
+= blk
->size
;
11981 DW_BLOCK (attr
) = blk
;
11983 case DW_FORM_data1
:
11984 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11988 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11991 case DW_FORM_flag_present
:
11992 DW_UNSND (attr
) = 1;
11994 case DW_FORM_sdata
:
11995 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11996 info_ptr
+= bytes_read
;
11998 case DW_FORM_udata
:
11999 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12000 info_ptr
+= bytes_read
;
12003 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12004 + read_1_byte (abfd
, info_ptr
));
12008 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12009 + read_2_bytes (abfd
, info_ptr
));
12013 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12014 + read_4_bytes (abfd
, info_ptr
));
12018 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12019 + read_8_bytes (abfd
, info_ptr
));
12022 case DW_FORM_ref_sig8
:
12023 /* Convert the signature to something we can record in DW_UNSND
12025 NOTE: This is NULL if the type wasn't found. */
12026 DW_SIGNATURED_TYPE (attr
) =
12027 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12030 case DW_FORM_ref_udata
:
12031 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12032 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12033 info_ptr
+= bytes_read
;
12035 case DW_FORM_indirect
:
12036 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12037 info_ptr
+= bytes_read
;
12038 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
12040 case DW_FORM_GNU_addr_index
:
12041 if (reader
->dwo_file
== NULL
)
12043 /* For now flag a hard error.
12044 Later we can turn this into a complaint. */
12045 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12046 dwarf_form_name (form
),
12047 bfd_get_filename (abfd
));
12049 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
12050 info_ptr
+= bytes_read
;
12052 case DW_FORM_GNU_str_index
:
12053 if (reader
->dwo_file
== NULL
)
12055 /* For now flag a hard error.
12056 Later we can turn this into a complaint if warranted. */
12057 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12058 dwarf_form_name (form
),
12059 bfd_get_filename (abfd
));
12062 ULONGEST str_index
=
12063 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12065 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
12066 DW_STRING_IS_CANONICAL (attr
) = 0;
12067 info_ptr
+= bytes_read
;
12071 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
12072 dwarf_form_name (form
),
12073 bfd_get_filename (abfd
));
12076 /* We have seen instances where the compiler tried to emit a byte
12077 size attribute of -1 which ended up being encoded as an unsigned
12078 0xffffffff. Although 0xffffffff is technically a valid size value,
12079 an object of this size seems pretty unlikely so we can relatively
12080 safely treat these cases as if the size attribute was invalid and
12081 treat them as zero by default. */
12082 if (attr
->name
== DW_AT_byte_size
12083 && form
== DW_FORM_data4
12084 && DW_UNSND (attr
) >= 0xffffffff)
12087 (&symfile_complaints
,
12088 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12089 hex_string (DW_UNSND (attr
)));
12090 DW_UNSND (attr
) = 0;
12096 /* Read an attribute described by an abbreviated attribute. */
12099 read_attribute (const struct die_reader_specs
*reader
,
12100 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12101 gdb_byte
*info_ptr
)
12103 attr
->name
= abbrev
->name
;
12104 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
12107 /* Read dwarf information from a buffer. */
12109 static unsigned int
12110 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
12112 return bfd_get_8 (abfd
, buf
);
12116 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
12118 return bfd_get_signed_8 (abfd
, buf
);
12121 static unsigned int
12122 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
12124 return bfd_get_16 (abfd
, buf
);
12128 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12130 return bfd_get_signed_16 (abfd
, buf
);
12133 static unsigned int
12134 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
12136 return bfd_get_32 (abfd
, buf
);
12140 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12142 return bfd_get_signed_32 (abfd
, buf
);
12146 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12148 return bfd_get_64 (abfd
, buf
);
12152 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12153 unsigned int *bytes_read
)
12155 struct comp_unit_head
*cu_header
= &cu
->header
;
12156 CORE_ADDR retval
= 0;
12158 if (cu_header
->signed_addr_p
)
12160 switch (cu_header
->addr_size
)
12163 retval
= bfd_get_signed_16 (abfd
, buf
);
12166 retval
= bfd_get_signed_32 (abfd
, buf
);
12169 retval
= bfd_get_signed_64 (abfd
, buf
);
12172 internal_error (__FILE__
, __LINE__
,
12173 _("read_address: bad switch, signed [in module %s]"),
12174 bfd_get_filename (abfd
));
12179 switch (cu_header
->addr_size
)
12182 retval
= bfd_get_16 (abfd
, buf
);
12185 retval
= bfd_get_32 (abfd
, buf
);
12188 retval
= bfd_get_64 (abfd
, buf
);
12191 internal_error (__FILE__
, __LINE__
,
12192 _("read_address: bad switch, "
12193 "unsigned [in module %s]"),
12194 bfd_get_filename (abfd
));
12198 *bytes_read
= cu_header
->addr_size
;
12202 /* Read the initial length from a section. The (draft) DWARF 3
12203 specification allows the initial length to take up either 4 bytes
12204 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
12205 bytes describe the length and all offsets will be 8 bytes in length
12208 An older, non-standard 64-bit format is also handled by this
12209 function. The older format in question stores the initial length
12210 as an 8-byte quantity without an escape value. Lengths greater
12211 than 2^32 aren't very common which means that the initial 4 bytes
12212 is almost always zero. Since a length value of zero doesn't make
12213 sense for the 32-bit format, this initial zero can be considered to
12214 be an escape value which indicates the presence of the older 64-bit
12215 format. As written, the code can't detect (old format) lengths
12216 greater than 4GB. If it becomes necessary to handle lengths
12217 somewhat larger than 4GB, we could allow other small values (such
12218 as the non-sensical values of 1, 2, and 3) to also be used as
12219 escape values indicating the presence of the old format.
12221 The value returned via bytes_read should be used to increment the
12222 relevant pointer after calling read_initial_length().
12224 [ Note: read_initial_length() and read_offset() are based on the
12225 document entitled "DWARF Debugging Information Format", revision
12226 3, draft 8, dated November 19, 2001. This document was obtained
12229 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
12231 This document is only a draft and is subject to change. (So beware.)
12233 Details regarding the older, non-standard 64-bit format were
12234 determined empirically by examining 64-bit ELF files produced by
12235 the SGI toolchain on an IRIX 6.5 machine.
12237 - Kevin, July 16, 2002
12241 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
12243 LONGEST length
= bfd_get_32 (abfd
, buf
);
12245 if (length
== 0xffffffff)
12247 length
= bfd_get_64 (abfd
, buf
+ 4);
12250 else if (length
== 0)
12252 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
12253 length
= bfd_get_64 (abfd
, buf
);
12264 /* Cover function for read_initial_length.
12265 Returns the length of the object at BUF, and stores the size of the
12266 initial length in *BYTES_READ and stores the size that offsets will be in
12268 If the initial length size is not equivalent to that specified in
12269 CU_HEADER then issue a complaint.
12270 This is useful when reading non-comp-unit headers. */
12273 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
12274 const struct comp_unit_head
*cu_header
,
12275 unsigned int *bytes_read
,
12276 unsigned int *offset_size
)
12278 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
12280 gdb_assert (cu_header
->initial_length_size
== 4
12281 || cu_header
->initial_length_size
== 8
12282 || cu_header
->initial_length_size
== 12);
12284 if (cu_header
->initial_length_size
!= *bytes_read
)
12285 complaint (&symfile_complaints
,
12286 _("intermixed 32-bit and 64-bit DWARF sections"));
12288 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
12292 /* Read an offset from the data stream. The size of the offset is
12293 given by cu_header->offset_size. */
12296 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
12297 unsigned int *bytes_read
)
12299 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
12301 *bytes_read
= cu_header
->offset_size
;
12305 /* Read an offset from the data stream. */
12308 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
12310 LONGEST retval
= 0;
12312 switch (offset_size
)
12315 retval
= bfd_get_32 (abfd
, buf
);
12318 retval
= bfd_get_64 (abfd
, buf
);
12321 internal_error (__FILE__
, __LINE__
,
12322 _("read_offset_1: bad switch [in module %s]"),
12323 bfd_get_filename (abfd
));
12330 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12332 /* If the size of a host char is 8 bits, we can return a pointer
12333 to the buffer, otherwise we have to copy the data to a buffer
12334 allocated on the temporary obstack. */
12335 gdb_assert (HOST_CHAR_BIT
== 8);
12340 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12342 /* If the size of a host char is 8 bits, we can return a pointer
12343 to the string, otherwise we have to copy the string to a buffer
12344 allocated on the temporary obstack. */
12345 gdb_assert (HOST_CHAR_BIT
== 8);
12348 *bytes_read_ptr
= 1;
12351 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12352 return (char *) buf
;
12356 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12358 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12359 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12360 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12361 bfd_get_filename (abfd
));
12362 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12363 error (_("DW_FORM_strp pointing outside of "
12364 ".debug_str section [in module %s]"),
12365 bfd_get_filename (abfd
));
12366 gdb_assert (HOST_CHAR_BIT
== 8);
12367 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12369 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12373 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12374 const struct comp_unit_head
*cu_header
,
12375 unsigned int *bytes_read_ptr
)
12377 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12379 return read_indirect_string_at_offset (abfd
, str_offset
);
12383 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12386 unsigned int num_read
;
12388 unsigned char byte
;
12396 byte
= bfd_get_8 (abfd
, buf
);
12399 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12400 if ((byte
& 128) == 0)
12406 *bytes_read_ptr
= num_read
;
12411 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12414 int i
, shift
, num_read
;
12415 unsigned char byte
;
12423 byte
= bfd_get_8 (abfd
, buf
);
12426 result
|= ((LONGEST
) (byte
& 127) << shift
);
12428 if ((byte
& 128) == 0)
12433 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12434 result
|= -(((LONGEST
) 1) << shift
);
12435 *bytes_read_ptr
= num_read
;
12439 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12440 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12441 ADDR_SIZE is the size of addresses from the CU header. */
12444 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12446 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12447 bfd
*abfd
= objfile
->obfd
;
12448 const gdb_byte
*info_ptr
;
12450 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12451 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12452 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12454 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12455 error (_("DW_FORM_addr_index pointing outside of "
12456 ".debug_addr section [in module %s]"),
12458 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12459 + addr_base
+ addr_index
* addr_size
);
12460 if (addr_size
== 4)
12461 return bfd_get_32 (abfd
, info_ptr
);
12463 return bfd_get_64 (abfd
, info_ptr
);
12466 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12469 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12471 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12474 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12477 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12478 unsigned int *bytes_read
)
12480 bfd
*abfd
= cu
->objfile
->obfd
;
12481 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12483 return read_addr_index (cu
, addr_index
);
12486 /* Data structure to pass results from dwarf2_read_addr_index_reader
12487 back to dwarf2_read_addr_index. */
12489 struct dwarf2_read_addr_index_data
12491 ULONGEST addr_base
;
12495 /* die_reader_func for dwarf2_read_addr_index. */
12498 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12499 gdb_byte
*info_ptr
,
12500 struct die_info
*comp_unit_die
,
12504 struct dwarf2_cu
*cu
= reader
->cu
;
12505 struct dwarf2_read_addr_index_data
*aidata
=
12506 (struct dwarf2_read_addr_index_data
*) data
;
12508 aidata
->addr_base
= cu
->addr_base
;
12509 aidata
->addr_size
= cu
->header
.addr_size
;
12512 /* Given an index in .debug_addr, fetch the value.
12513 NOTE: This can be called during dwarf expression evaluation,
12514 long after the debug information has been read, and thus per_cu->cu
12515 may no longer exist. */
12518 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12519 unsigned int addr_index
)
12521 struct objfile
*objfile
= per_cu
->objfile
;
12522 struct dwarf2_cu
*cu
= per_cu
->cu
;
12523 ULONGEST addr_base
;
12526 /* This is intended to be called from outside this file. */
12527 dw2_setup (objfile
);
12529 /* We need addr_base and addr_size.
12530 If we don't have PER_CU->cu, we have to get it.
12531 Nasty, but the alternative is storing the needed info in PER_CU,
12532 which at this point doesn't seem justified: it's not clear how frequently
12533 it would get used and it would increase the size of every PER_CU.
12534 Entry points like dwarf2_per_cu_addr_size do a similar thing
12535 so we're not in uncharted territory here.
12536 Alas we need to be a bit more complicated as addr_base is contained
12539 We don't need to read the entire CU(/TU).
12540 We just need the header and top level die.
12541 IWBN to use the aging mechanism to let us lazily later discard the CU.
12542 See however init_cutu_and_read_dies_simple. */
12546 addr_base
= cu
->addr_base
;
12547 addr_size
= cu
->header
.addr_size
;
12551 struct dwarf2_read_addr_index_data aidata
;
12553 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12555 addr_base
= aidata
.addr_base
;
12556 addr_size
= aidata
.addr_size
;
12559 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12562 /* Given a DW_AT_str_index, fetch the string. */
12565 read_str_index (const struct die_reader_specs
*reader
,
12566 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12568 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12569 const char *dwo_name
= objfile
->name
;
12570 bfd
*abfd
= objfile
->obfd
;
12571 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12572 gdb_byte
*info_ptr
;
12573 ULONGEST str_offset
;
12575 dwarf2_read_section (objfile
, §ions
->str
);
12576 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12577 if (sections
->str
.buffer
== NULL
)
12578 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12579 " in CU at offset 0x%lx [in module %s]"),
12580 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12581 if (sections
->str_offsets
.buffer
== NULL
)
12582 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12583 " in CU at offset 0x%lx [in module %s]"),
12584 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12585 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12586 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12587 " section in CU at offset 0x%lx [in module %s]"),
12588 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12589 info_ptr
= (sections
->str_offsets
.buffer
12590 + str_index
* cu
->header
.offset_size
);
12591 if (cu
->header
.offset_size
== 4)
12592 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12594 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12595 if (str_offset
>= sections
->str
.size
)
12596 error (_("Offset from DW_FORM_str_index pointing outside of"
12597 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12598 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12599 return (char *) (sections
->str
.buffer
+ str_offset
);
12602 /* Return the length of an LEB128 number in BUF. */
12605 leb128_size (const gdb_byte
*buf
)
12607 const gdb_byte
*begin
= buf
;
12613 if ((byte
& 128) == 0)
12614 return buf
- begin
;
12619 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12626 cu
->language
= language_c
;
12628 case DW_LANG_C_plus_plus
:
12629 cu
->language
= language_cplus
;
12632 cu
->language
= language_d
;
12634 case DW_LANG_Fortran77
:
12635 case DW_LANG_Fortran90
:
12636 case DW_LANG_Fortran95
:
12637 cu
->language
= language_fortran
;
12640 cu
->language
= language_go
;
12642 case DW_LANG_Mips_Assembler
:
12643 cu
->language
= language_asm
;
12646 cu
->language
= language_java
;
12648 case DW_LANG_Ada83
:
12649 case DW_LANG_Ada95
:
12650 cu
->language
= language_ada
;
12652 case DW_LANG_Modula2
:
12653 cu
->language
= language_m2
;
12655 case DW_LANG_Pascal83
:
12656 cu
->language
= language_pascal
;
12659 cu
->language
= language_objc
;
12661 case DW_LANG_Cobol74
:
12662 case DW_LANG_Cobol85
:
12664 cu
->language
= language_minimal
;
12667 cu
->language_defn
= language_def (cu
->language
);
12670 /* Return the named attribute or NULL if not there. */
12672 static struct attribute
*
12673 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12678 struct attribute
*spec
= NULL
;
12680 for (i
= 0; i
< die
->num_attrs
; ++i
)
12682 if (die
->attrs
[i
].name
== name
)
12683 return &die
->attrs
[i
];
12684 if (die
->attrs
[i
].name
== DW_AT_specification
12685 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12686 spec
= &die
->attrs
[i
];
12692 die
= follow_die_ref (die
, spec
, &cu
);
12698 /* Return the named attribute or NULL if not there,
12699 but do not follow DW_AT_specification, etc.
12700 This is for use in contexts where we're reading .debug_types dies.
12701 Following DW_AT_specification, DW_AT_abstract_origin will take us
12702 back up the chain, and we want to go down. */
12704 static struct attribute
*
12705 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12706 struct dwarf2_cu
*cu
)
12710 for (i
= 0; i
< die
->num_attrs
; ++i
)
12711 if (die
->attrs
[i
].name
== name
)
12712 return &die
->attrs
[i
];
12717 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12718 and holds a non-zero value. This function should only be used for
12719 DW_FORM_flag or DW_FORM_flag_present attributes. */
12722 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12724 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12726 return (attr
&& DW_UNSND (attr
));
12730 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12732 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12733 which value is non-zero. However, we have to be careful with
12734 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12735 (via dwarf2_flag_true_p) follows this attribute. So we may
12736 end up accidently finding a declaration attribute that belongs
12737 to a different DIE referenced by the specification attribute,
12738 even though the given DIE does not have a declaration attribute. */
12739 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12740 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12743 /* Return the die giving the specification for DIE, if there is
12744 one. *SPEC_CU is the CU containing DIE on input, and the CU
12745 containing the return value on output. If there is no
12746 specification, but there is an abstract origin, that is
12749 static struct die_info
*
12750 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12752 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12755 if (spec_attr
== NULL
)
12756 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12758 if (spec_attr
== NULL
)
12761 return follow_die_ref (die
, spec_attr
, spec_cu
);
12764 /* Free the line_header structure *LH, and any arrays and strings it
12766 NOTE: This is also used as a "cleanup" function. */
12769 free_line_header (struct line_header
*lh
)
12771 if (lh
->standard_opcode_lengths
)
12772 xfree (lh
->standard_opcode_lengths
);
12774 /* Remember that all the lh->file_names[i].name pointers are
12775 pointers into debug_line_buffer, and don't need to be freed. */
12776 if (lh
->file_names
)
12777 xfree (lh
->file_names
);
12779 /* Similarly for the include directory names. */
12780 if (lh
->include_dirs
)
12781 xfree (lh
->include_dirs
);
12786 /* Add an entry to LH's include directory table. */
12789 add_include_dir (struct line_header
*lh
, char *include_dir
)
12791 /* Grow the array if necessary. */
12792 if (lh
->include_dirs_size
== 0)
12794 lh
->include_dirs_size
= 1; /* for testing */
12795 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12796 * sizeof (*lh
->include_dirs
));
12798 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12800 lh
->include_dirs_size
*= 2;
12801 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12802 (lh
->include_dirs_size
12803 * sizeof (*lh
->include_dirs
)));
12806 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12809 /* Add an entry to LH's file name table. */
12812 add_file_name (struct line_header
*lh
,
12814 unsigned int dir_index
,
12815 unsigned int mod_time
,
12816 unsigned int length
)
12818 struct file_entry
*fe
;
12820 /* Grow the array if necessary. */
12821 if (lh
->file_names_size
== 0)
12823 lh
->file_names_size
= 1; /* for testing */
12824 lh
->file_names
= xmalloc (lh
->file_names_size
12825 * sizeof (*lh
->file_names
));
12827 else if (lh
->num_file_names
>= lh
->file_names_size
)
12829 lh
->file_names_size
*= 2;
12830 lh
->file_names
= xrealloc (lh
->file_names
,
12831 (lh
->file_names_size
12832 * sizeof (*lh
->file_names
)));
12835 fe
= &lh
->file_names
[lh
->num_file_names
++];
12837 fe
->dir_index
= dir_index
;
12838 fe
->mod_time
= mod_time
;
12839 fe
->length
= length
;
12840 fe
->included_p
= 0;
12844 /* Read the statement program header starting at OFFSET in
12845 .debug_line, or .debug_line.dwo. Return a pointer
12846 to a struct line_header, allocated using xmalloc.
12848 NOTE: the strings in the include directory and file name tables of
12849 the returned object point into the dwarf line section buffer,
12850 and must not be freed. */
12852 static struct line_header
*
12853 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12855 struct cleanup
*back_to
;
12856 struct line_header
*lh
;
12857 gdb_byte
*line_ptr
;
12858 unsigned int bytes_read
, offset_size
;
12860 char *cur_dir
, *cur_file
;
12861 struct dwarf2_section_info
*section
;
12864 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12866 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12867 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12869 section
= &dwarf2_per_objfile
->line
;
12871 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12872 if (section
->buffer
== NULL
)
12874 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12875 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12877 complaint (&symfile_complaints
, _("missing .debug_line section"));
12881 /* We can't do this until we know the section is non-empty.
12882 Only then do we know we have such a section. */
12883 abfd
= section
->asection
->owner
;
12885 /* Make sure that at least there's room for the total_length field.
12886 That could be 12 bytes long, but we're just going to fudge that. */
12887 if (offset
+ 4 >= section
->size
)
12889 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12893 lh
= xmalloc (sizeof (*lh
));
12894 memset (lh
, 0, sizeof (*lh
));
12895 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12898 line_ptr
= section
->buffer
+ offset
;
12900 /* Read in the header. */
12902 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12903 &bytes_read
, &offset_size
);
12904 line_ptr
+= bytes_read
;
12905 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12907 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12910 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12911 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12913 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12914 line_ptr
+= offset_size
;
12915 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12917 if (lh
->version
>= 4)
12919 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12923 lh
->maximum_ops_per_instruction
= 1;
12925 if (lh
->maximum_ops_per_instruction
== 0)
12927 lh
->maximum_ops_per_instruction
= 1;
12928 complaint (&symfile_complaints
,
12929 _("invalid maximum_ops_per_instruction "
12930 "in `.debug_line' section"));
12933 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12935 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12937 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12939 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12941 lh
->standard_opcode_lengths
12942 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12944 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12945 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12947 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12951 /* Read directory table. */
12952 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12954 line_ptr
+= bytes_read
;
12955 add_include_dir (lh
, cur_dir
);
12957 line_ptr
+= bytes_read
;
12959 /* Read file name table. */
12960 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12962 unsigned int dir_index
, mod_time
, length
;
12964 line_ptr
+= bytes_read
;
12965 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12966 line_ptr
+= bytes_read
;
12967 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12968 line_ptr
+= bytes_read
;
12969 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12970 line_ptr
+= bytes_read
;
12972 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12974 line_ptr
+= bytes_read
;
12975 lh
->statement_program_start
= line_ptr
;
12977 if (line_ptr
> (section
->buffer
+ section
->size
))
12978 complaint (&symfile_complaints
,
12979 _("line number info header doesn't "
12980 "fit in `.debug_line' section"));
12982 discard_cleanups (back_to
);
12986 /* Subroutine of dwarf_decode_lines to simplify it.
12987 Return the file name of the psymtab for included file FILE_INDEX
12988 in line header LH of PST.
12989 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12990 If space for the result is malloc'd, it will be freed by a cleanup.
12991 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12994 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12995 const struct partial_symtab
*pst
,
12996 const char *comp_dir
)
12998 const struct file_entry fe
= lh
->file_names
[file_index
];
12999 char *include_name
= fe
.name
;
13000 char *include_name_to_compare
= include_name
;
13001 char *dir_name
= NULL
;
13002 const char *pst_filename
;
13003 char *copied_name
= NULL
;
13007 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13009 if (!IS_ABSOLUTE_PATH (include_name
)
13010 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13012 /* Avoid creating a duplicate psymtab for PST.
13013 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13014 Before we do the comparison, however, we need to account
13015 for DIR_NAME and COMP_DIR.
13016 First prepend dir_name (if non-NULL). If we still don't
13017 have an absolute path prepend comp_dir (if non-NULL).
13018 However, the directory we record in the include-file's
13019 psymtab does not contain COMP_DIR (to match the
13020 corresponding symtab(s)).
13025 bash$ gcc -g ./hello.c
13026 include_name = "hello.c"
13028 DW_AT_comp_dir = comp_dir = "/tmp"
13029 DW_AT_name = "./hello.c" */
13031 if (dir_name
!= NULL
)
13033 include_name
= concat (dir_name
, SLASH_STRING
,
13034 include_name
, (char *)NULL
);
13035 include_name_to_compare
= include_name
;
13036 make_cleanup (xfree
, include_name
);
13038 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
13040 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
13041 include_name
, (char *)NULL
);
13045 pst_filename
= pst
->filename
;
13046 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
13048 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
13049 pst_filename
, (char *)NULL
);
13050 pst_filename
= copied_name
;
13053 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
13055 if (include_name_to_compare
!= include_name
)
13056 xfree (include_name_to_compare
);
13057 if (copied_name
!= NULL
)
13058 xfree (copied_name
);
13062 return include_name
;
13065 /* Ignore this record_line request. */
13068 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13073 /* Subroutine of dwarf_decode_lines to simplify it.
13074 Process the line number information in LH. */
13077 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13078 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13080 gdb_byte
*line_ptr
, *extended_end
;
13081 gdb_byte
*line_end
;
13082 unsigned int bytes_read
, extended_len
;
13083 unsigned char op_code
, extended_op
, adj_opcode
;
13084 CORE_ADDR baseaddr
;
13085 struct objfile
*objfile
= cu
->objfile
;
13086 bfd
*abfd
= objfile
->obfd
;
13087 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13088 const int decode_for_pst_p
= (pst
!= NULL
);
13089 struct subfile
*last_subfile
= NULL
;
13090 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13093 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13095 line_ptr
= lh
->statement_program_start
;
13096 line_end
= lh
->statement_program_end
;
13098 /* Read the statement sequences until there's nothing left. */
13099 while (line_ptr
< line_end
)
13101 /* state machine registers */
13102 CORE_ADDR address
= 0;
13103 unsigned int file
= 1;
13104 unsigned int line
= 1;
13105 unsigned int column
= 0;
13106 int is_stmt
= lh
->default_is_stmt
;
13107 int basic_block
= 0;
13108 int end_sequence
= 0;
13110 unsigned char op_index
= 0;
13112 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
13114 /* Start a subfile for the current file of the state machine. */
13115 /* lh->include_dirs and lh->file_names are 0-based, but the
13116 directory and file name numbers in the statement program
13118 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13122 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13124 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13127 /* Decode the table. */
13128 while (!end_sequence
)
13130 op_code
= read_1_byte (abfd
, line_ptr
);
13132 if (line_ptr
> line_end
)
13134 dwarf2_debug_line_missing_end_sequence_complaint ();
13138 if (op_code
>= lh
->opcode_base
)
13140 /* Special operand. */
13141 adj_opcode
= op_code
- lh
->opcode_base
;
13142 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13143 / lh
->maximum_ops_per_instruction
)
13144 * lh
->minimum_instruction_length
);
13145 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13146 % lh
->maximum_ops_per_instruction
);
13147 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13148 if (lh
->num_file_names
< file
|| file
== 0)
13149 dwarf2_debug_line_missing_file_complaint ();
13150 /* For now we ignore lines not starting on an
13151 instruction boundary. */
13152 else if (op_index
== 0)
13154 lh
->file_names
[file
- 1].included_p
= 1;
13155 if (!decode_for_pst_p
&& is_stmt
)
13157 if (last_subfile
!= current_subfile
)
13159 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13161 (*p_record_line
) (last_subfile
, 0, addr
);
13162 last_subfile
= current_subfile
;
13164 /* Append row to matrix using current values. */
13165 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13166 (*p_record_line
) (current_subfile
, line
, addr
);
13171 else switch (op_code
)
13173 case DW_LNS_extended_op
:
13174 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13176 line_ptr
+= bytes_read
;
13177 extended_end
= line_ptr
+ extended_len
;
13178 extended_op
= read_1_byte (abfd
, line_ptr
);
13180 switch (extended_op
)
13182 case DW_LNE_end_sequence
:
13183 p_record_line
= record_line
;
13186 case DW_LNE_set_address
:
13187 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
13189 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13191 /* This line table is for a function which has been
13192 GCd by the linker. Ignore it. PR gdb/12528 */
13195 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
13197 complaint (&symfile_complaints
,
13198 _(".debug_line address at offset 0x%lx is 0 "
13200 line_offset
, objfile
->name
);
13201 p_record_line
= noop_record_line
;
13205 line_ptr
+= bytes_read
;
13206 address
+= baseaddr
;
13208 case DW_LNE_define_file
:
13211 unsigned int dir_index
, mod_time
, length
;
13213 cur_file
= read_direct_string (abfd
, line_ptr
,
13215 line_ptr
+= bytes_read
;
13217 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13218 line_ptr
+= bytes_read
;
13220 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13221 line_ptr
+= bytes_read
;
13223 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13224 line_ptr
+= bytes_read
;
13225 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13228 case DW_LNE_set_discriminator
:
13229 /* The discriminator is not interesting to the debugger;
13231 line_ptr
= extended_end
;
13234 complaint (&symfile_complaints
,
13235 _("mangled .debug_line section"));
13238 /* Make sure that we parsed the extended op correctly. If e.g.
13239 we expected a different address size than the producer used,
13240 we may have read the wrong number of bytes. */
13241 if (line_ptr
!= extended_end
)
13243 complaint (&symfile_complaints
,
13244 _("mangled .debug_line section"));
13249 if (lh
->num_file_names
< file
|| file
== 0)
13250 dwarf2_debug_line_missing_file_complaint ();
13253 lh
->file_names
[file
- 1].included_p
= 1;
13254 if (!decode_for_pst_p
&& is_stmt
)
13256 if (last_subfile
!= current_subfile
)
13258 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13260 (*p_record_line
) (last_subfile
, 0, addr
);
13261 last_subfile
= current_subfile
;
13263 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13264 (*p_record_line
) (current_subfile
, line
, addr
);
13269 case DW_LNS_advance_pc
:
13272 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13274 address
+= (((op_index
+ adjust
)
13275 / lh
->maximum_ops_per_instruction
)
13276 * lh
->minimum_instruction_length
);
13277 op_index
= ((op_index
+ adjust
)
13278 % lh
->maximum_ops_per_instruction
);
13279 line_ptr
+= bytes_read
;
13282 case DW_LNS_advance_line
:
13283 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
13284 line_ptr
+= bytes_read
;
13286 case DW_LNS_set_file
:
13288 /* The arrays lh->include_dirs and lh->file_names are
13289 0-based, but the directory and file name numbers in
13290 the statement program are 1-based. */
13291 struct file_entry
*fe
;
13294 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13295 line_ptr
+= bytes_read
;
13296 if (lh
->num_file_names
< file
|| file
== 0)
13297 dwarf2_debug_line_missing_file_complaint ();
13300 fe
= &lh
->file_names
[file
- 1];
13302 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13303 if (!decode_for_pst_p
)
13305 last_subfile
= current_subfile
;
13306 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13311 case DW_LNS_set_column
:
13312 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13313 line_ptr
+= bytes_read
;
13315 case DW_LNS_negate_stmt
:
13316 is_stmt
= (!is_stmt
);
13318 case DW_LNS_set_basic_block
:
13321 /* Add to the address register of the state machine the
13322 address increment value corresponding to special opcode
13323 255. I.e., this value is scaled by the minimum
13324 instruction length since special opcode 255 would have
13325 scaled the increment. */
13326 case DW_LNS_const_add_pc
:
13328 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13330 address
+= (((op_index
+ adjust
)
13331 / lh
->maximum_ops_per_instruction
)
13332 * lh
->minimum_instruction_length
);
13333 op_index
= ((op_index
+ adjust
)
13334 % lh
->maximum_ops_per_instruction
);
13337 case DW_LNS_fixed_advance_pc
:
13338 address
+= read_2_bytes (abfd
, line_ptr
);
13344 /* Unknown standard opcode, ignore it. */
13347 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13349 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13350 line_ptr
+= bytes_read
;
13355 if (lh
->num_file_names
< file
|| file
== 0)
13356 dwarf2_debug_line_missing_file_complaint ();
13359 lh
->file_names
[file
- 1].included_p
= 1;
13360 if (!decode_for_pst_p
)
13362 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13363 (*p_record_line
) (current_subfile
, 0, addr
);
13369 /* Decode the Line Number Program (LNP) for the given line_header
13370 structure and CU. The actual information extracted and the type
13371 of structures created from the LNP depends on the value of PST.
13373 1. If PST is NULL, then this procedure uses the data from the program
13374 to create all necessary symbol tables, and their linetables.
13376 2. If PST is not NULL, this procedure reads the program to determine
13377 the list of files included by the unit represented by PST, and
13378 builds all the associated partial symbol tables.
13380 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13381 It is used for relative paths in the line table.
13382 NOTE: When processing partial symtabs (pst != NULL),
13383 comp_dir == pst->dirname.
13385 NOTE: It is important that psymtabs have the same file name (via strcmp)
13386 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13387 symtab we don't use it in the name of the psymtabs we create.
13388 E.g. expand_line_sal requires this when finding psymtabs to expand.
13389 A good testcase for this is mb-inline.exp. */
13392 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13393 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13394 int want_line_info
)
13396 struct objfile
*objfile
= cu
->objfile
;
13397 const int decode_for_pst_p
= (pst
!= NULL
);
13398 struct subfile
*first_subfile
= current_subfile
;
13400 if (want_line_info
)
13401 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13403 if (decode_for_pst_p
)
13407 /* Now that we're done scanning the Line Header Program, we can
13408 create the psymtab of each included file. */
13409 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13410 if (lh
->file_names
[file_index
].included_p
== 1)
13412 char *include_name
=
13413 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13414 if (include_name
!= NULL
)
13415 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13420 /* Make sure a symtab is created for every file, even files
13421 which contain only variables (i.e. no code with associated
13425 for (i
= 0; i
< lh
->num_file_names
; i
++)
13428 struct file_entry
*fe
;
13430 fe
= &lh
->file_names
[i
];
13432 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13433 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13435 /* Skip the main file; we don't need it, and it must be
13436 allocated last, so that it will show up before the
13437 non-primary symtabs in the objfile's symtab list. */
13438 if (current_subfile
== first_subfile
)
13441 if (current_subfile
->symtab
== NULL
)
13442 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13444 fe
->symtab
= current_subfile
->symtab
;
13449 /* Start a subfile for DWARF. FILENAME is the name of the file and
13450 DIRNAME the name of the source directory which contains FILENAME
13451 or NULL if not known. COMP_DIR is the compilation directory for the
13452 linetable's compilation unit or NULL if not known.
13453 This routine tries to keep line numbers from identical absolute and
13454 relative file names in a common subfile.
13456 Using the `list' example from the GDB testsuite, which resides in
13457 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13458 of /srcdir/list0.c yields the following debugging information for list0.c:
13460 DW_AT_name: /srcdir/list0.c
13461 DW_AT_comp_dir: /compdir
13462 files.files[0].name: list0.h
13463 files.files[0].dir: /srcdir
13464 files.files[1].name: list0.c
13465 files.files[1].dir: /srcdir
13467 The line number information for list0.c has to end up in a single
13468 subfile, so that `break /srcdir/list0.c:1' works as expected.
13469 start_subfile will ensure that this happens provided that we pass the
13470 concatenation of files.files[1].dir and files.files[1].name as the
13474 dwarf2_start_subfile (char *filename
, const char *dirname
,
13475 const char *comp_dir
)
13479 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13480 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13481 second argument to start_subfile. To be consistent, we do the
13482 same here. In order not to lose the line information directory,
13483 we concatenate it to the filename when it makes sense.
13484 Note that the Dwarf3 standard says (speaking of filenames in line
13485 information): ``The directory index is ignored for file names
13486 that represent full path names''. Thus ignoring dirname in the
13487 `else' branch below isn't an issue. */
13489 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13490 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13492 fullname
= filename
;
13494 start_subfile (fullname
, comp_dir
);
13496 if (fullname
!= filename
)
13501 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13502 struct dwarf2_cu
*cu
)
13504 struct objfile
*objfile
= cu
->objfile
;
13505 struct comp_unit_head
*cu_header
= &cu
->header
;
13507 /* NOTE drow/2003-01-30: There used to be a comment and some special
13508 code here to turn a symbol with DW_AT_external and a
13509 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13510 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13511 with some versions of binutils) where shared libraries could have
13512 relocations against symbols in their debug information - the
13513 minimal symbol would have the right address, but the debug info
13514 would not. It's no longer necessary, because we will explicitly
13515 apply relocations when we read in the debug information now. */
13517 /* A DW_AT_location attribute with no contents indicates that a
13518 variable has been optimized away. */
13519 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13521 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13525 /* Handle one degenerate form of location expression specially, to
13526 preserve GDB's previous behavior when section offsets are
13527 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13528 then mark this symbol as LOC_STATIC. */
13530 if (attr_form_is_block (attr
)
13531 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13532 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13533 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13534 && (DW_BLOCK (attr
)->size
13535 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13537 unsigned int dummy
;
13539 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13540 SYMBOL_VALUE_ADDRESS (sym
) =
13541 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13543 SYMBOL_VALUE_ADDRESS (sym
) =
13544 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13545 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13546 fixup_symbol_section (sym
, objfile
);
13547 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13548 SYMBOL_SECTION (sym
));
13552 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13553 expression evaluator, and use LOC_COMPUTED only when necessary
13554 (i.e. when the value of a register or memory location is
13555 referenced, or a thread-local block, etc.). Then again, it might
13556 not be worthwhile. I'm assuming that it isn't unless performance
13557 or memory numbers show me otherwise. */
13559 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13560 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13562 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13563 cu
->has_loclist
= 1;
13566 /* Given a pointer to a DWARF information entry, figure out if we need
13567 to make a symbol table entry for it, and if so, create a new entry
13568 and return a pointer to it.
13569 If TYPE is NULL, determine symbol type from the die, otherwise
13570 used the passed type.
13571 If SPACE is not NULL, use it to hold the new symbol. If it is
13572 NULL, allocate a new symbol on the objfile's obstack. */
13574 static struct symbol
*
13575 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13576 struct symbol
*space
)
13578 struct objfile
*objfile
= cu
->objfile
;
13579 struct symbol
*sym
= NULL
;
13581 struct attribute
*attr
= NULL
;
13582 struct attribute
*attr2
= NULL
;
13583 CORE_ADDR baseaddr
;
13584 struct pending
**list_to_add
= NULL
;
13586 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13588 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13590 name
= dwarf2_name (die
, cu
);
13593 const char *linkagename
;
13594 int suppress_add
= 0;
13599 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13600 OBJSTAT (objfile
, n_syms
++);
13602 /* Cache this symbol's name and the name's demangled form (if any). */
13603 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13604 linkagename
= dwarf2_physname (name
, die
, cu
);
13605 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13607 /* Fortran does not have mangling standard and the mangling does differ
13608 between gfortran, iFort etc. */
13609 if (cu
->language
== language_fortran
13610 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13611 symbol_set_demangled_name (&(sym
->ginfo
),
13612 (char *) dwarf2_full_name (name
, die
, cu
),
13615 /* Default assumptions.
13616 Use the passed type or decode it from the die. */
13617 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13618 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13620 SYMBOL_TYPE (sym
) = type
;
13622 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13623 attr
= dwarf2_attr (die
,
13624 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13628 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13631 attr
= dwarf2_attr (die
,
13632 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13636 int file_index
= DW_UNSND (attr
);
13638 if (cu
->line_header
== NULL
13639 || file_index
> cu
->line_header
->num_file_names
)
13640 complaint (&symfile_complaints
,
13641 _("file index out of range"));
13642 else if (file_index
> 0)
13644 struct file_entry
*fe
;
13646 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13647 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13654 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13657 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13659 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13660 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13661 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13662 add_symbol_to_list (sym
, cu
->list_in_scope
);
13664 case DW_TAG_subprogram
:
13665 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13667 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13668 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13669 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13670 || cu
->language
== language_ada
)
13672 /* Subprograms marked external are stored as a global symbol.
13673 Ada subprograms, whether marked external or not, are always
13674 stored as a global symbol, because we want to be able to
13675 access them globally. For instance, we want to be able
13676 to break on a nested subprogram without having to
13677 specify the context. */
13678 list_to_add
= &global_symbols
;
13682 list_to_add
= cu
->list_in_scope
;
13685 case DW_TAG_inlined_subroutine
:
13686 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13688 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13689 SYMBOL_INLINED (sym
) = 1;
13690 list_to_add
= cu
->list_in_scope
;
13692 case DW_TAG_template_value_param
:
13694 /* Fall through. */
13695 case DW_TAG_constant
:
13696 case DW_TAG_variable
:
13697 case DW_TAG_member
:
13698 /* Compilation with minimal debug info may result in
13699 variables with missing type entries. Change the
13700 misleading `void' type to something sensible. */
13701 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13703 = objfile_type (objfile
)->nodebug_data_symbol
;
13705 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13706 /* In the case of DW_TAG_member, we should only be called for
13707 static const members. */
13708 if (die
->tag
== DW_TAG_member
)
13710 /* dwarf2_add_field uses die_is_declaration,
13711 so we do the same. */
13712 gdb_assert (die_is_declaration (die
, cu
));
13717 dwarf2_const_value (attr
, sym
, cu
);
13718 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13721 if (attr2
&& (DW_UNSND (attr2
) != 0))
13722 list_to_add
= &global_symbols
;
13724 list_to_add
= cu
->list_in_scope
;
13728 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13731 var_decode_location (attr
, sym
, cu
);
13732 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13733 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13734 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13735 && !dwarf2_per_objfile
->has_section_at_zero
)
13737 /* When a static variable is eliminated by the linker,
13738 the corresponding debug information is not stripped
13739 out, but the variable address is set to null;
13740 do not add such variables into symbol table. */
13742 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13744 /* Workaround gfortran PR debug/40040 - it uses
13745 DW_AT_location for variables in -fPIC libraries which may
13746 get overriden by other libraries/executable and get
13747 a different address. Resolve it by the minimal symbol
13748 which may come from inferior's executable using copy
13749 relocation. Make this workaround only for gfortran as for
13750 other compilers GDB cannot guess the minimal symbol
13751 Fortran mangling kind. */
13752 if (cu
->language
== language_fortran
&& die
->parent
13753 && die
->parent
->tag
== DW_TAG_module
13755 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13756 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13758 /* A variable with DW_AT_external is never static,
13759 but it may be block-scoped. */
13760 list_to_add
= (cu
->list_in_scope
== &file_symbols
13761 ? &global_symbols
: cu
->list_in_scope
);
13764 list_to_add
= cu
->list_in_scope
;
13768 /* We do not know the address of this symbol.
13769 If it is an external symbol and we have type information
13770 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13771 The address of the variable will then be determined from
13772 the minimal symbol table whenever the variable is
13774 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13775 if (attr2
&& (DW_UNSND (attr2
) != 0)
13776 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13778 /* A variable with DW_AT_external is never static, but it
13779 may be block-scoped. */
13780 list_to_add
= (cu
->list_in_scope
== &file_symbols
13781 ? &global_symbols
: cu
->list_in_scope
);
13783 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13785 else if (!die_is_declaration (die
, cu
))
13787 /* Use the default LOC_OPTIMIZED_OUT class. */
13788 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13790 list_to_add
= cu
->list_in_scope
;
13794 case DW_TAG_formal_parameter
:
13795 /* If we are inside a function, mark this as an argument. If
13796 not, we might be looking at an argument to an inlined function
13797 when we do not have enough information to show inlined frames;
13798 pretend it's a local variable in that case so that the user can
13800 if (context_stack_depth
> 0
13801 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13802 SYMBOL_IS_ARGUMENT (sym
) = 1;
13803 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13806 var_decode_location (attr
, sym
, cu
);
13808 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13811 dwarf2_const_value (attr
, sym
, cu
);
13814 list_to_add
= cu
->list_in_scope
;
13816 case DW_TAG_unspecified_parameters
:
13817 /* From varargs functions; gdb doesn't seem to have any
13818 interest in this information, so just ignore it for now.
13821 case DW_TAG_template_type_param
:
13823 /* Fall through. */
13824 case DW_TAG_class_type
:
13825 case DW_TAG_interface_type
:
13826 case DW_TAG_structure_type
:
13827 case DW_TAG_union_type
:
13828 case DW_TAG_set_type
:
13829 case DW_TAG_enumeration_type
:
13830 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13831 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13834 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13835 really ever be static objects: otherwise, if you try
13836 to, say, break of a class's method and you're in a file
13837 which doesn't mention that class, it won't work unless
13838 the check for all static symbols in lookup_symbol_aux
13839 saves you. See the OtherFileClass tests in
13840 gdb.c++/namespace.exp. */
13844 list_to_add
= (cu
->list_in_scope
== &file_symbols
13845 && (cu
->language
== language_cplus
13846 || cu
->language
== language_java
)
13847 ? &global_symbols
: cu
->list_in_scope
);
13849 /* The semantics of C++ state that "struct foo {
13850 ... }" also defines a typedef for "foo". A Java
13851 class declaration also defines a typedef for the
13853 if (cu
->language
== language_cplus
13854 || cu
->language
== language_java
13855 || cu
->language
== language_ada
)
13857 /* The symbol's name is already allocated along
13858 with this objfile, so we don't need to
13859 duplicate it for the type. */
13860 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13861 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13866 case DW_TAG_typedef
:
13867 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13868 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13869 list_to_add
= cu
->list_in_scope
;
13871 case DW_TAG_base_type
:
13872 case DW_TAG_subrange_type
:
13873 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13874 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13875 list_to_add
= cu
->list_in_scope
;
13877 case DW_TAG_enumerator
:
13878 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13881 dwarf2_const_value (attr
, sym
, cu
);
13884 /* NOTE: carlton/2003-11-10: See comment above in the
13885 DW_TAG_class_type, etc. block. */
13887 list_to_add
= (cu
->list_in_scope
== &file_symbols
13888 && (cu
->language
== language_cplus
13889 || cu
->language
== language_java
)
13890 ? &global_symbols
: cu
->list_in_scope
);
13893 case DW_TAG_namespace
:
13894 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13895 list_to_add
= &global_symbols
;
13898 /* Not a tag we recognize. Hopefully we aren't processing
13899 trash data, but since we must specifically ignore things
13900 we don't recognize, there is nothing else we should do at
13902 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13903 dwarf_tag_name (die
->tag
));
13909 sym
->hash_next
= objfile
->template_symbols
;
13910 objfile
->template_symbols
= sym
;
13911 list_to_add
= NULL
;
13914 if (list_to_add
!= NULL
)
13915 add_symbol_to_list (sym
, list_to_add
);
13917 /* For the benefit of old versions of GCC, check for anonymous
13918 namespaces based on the demangled name. */
13919 if (!processing_has_namespace_info
13920 && cu
->language
== language_cplus
)
13921 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13926 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13928 static struct symbol
*
13929 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13931 return new_symbol_full (die
, type
, cu
, NULL
);
13934 /* Given an attr with a DW_FORM_dataN value in host byte order,
13935 zero-extend it as appropriate for the symbol's type. The DWARF
13936 standard (v4) is not entirely clear about the meaning of using
13937 DW_FORM_dataN for a constant with a signed type, where the type is
13938 wider than the data. The conclusion of a discussion on the DWARF
13939 list was that this is unspecified. We choose to always zero-extend
13940 because that is the interpretation long in use by GCC. */
13943 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13944 const char *name
, struct obstack
*obstack
,
13945 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13947 struct objfile
*objfile
= cu
->objfile
;
13948 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13949 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13950 LONGEST l
= DW_UNSND (attr
);
13952 if (bits
< sizeof (*value
) * 8)
13954 l
&= ((LONGEST
) 1 << bits
) - 1;
13957 else if (bits
== sizeof (*value
) * 8)
13961 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13962 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13969 /* Read a constant value from an attribute. Either set *VALUE, or if
13970 the value does not fit in *VALUE, set *BYTES - either already
13971 allocated on the objfile obstack, or newly allocated on OBSTACK,
13972 or, set *BATON, if we translated the constant to a location
13976 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13977 const char *name
, struct obstack
*obstack
,
13978 struct dwarf2_cu
*cu
,
13979 LONGEST
*value
, gdb_byte
**bytes
,
13980 struct dwarf2_locexpr_baton
**baton
)
13982 struct objfile
*objfile
= cu
->objfile
;
13983 struct comp_unit_head
*cu_header
= &cu
->header
;
13984 struct dwarf_block
*blk
;
13985 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13986 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13992 switch (attr
->form
)
13995 case DW_FORM_GNU_addr_index
:
13999 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14000 dwarf2_const_value_length_mismatch_complaint (name
,
14001 cu_header
->addr_size
,
14002 TYPE_LENGTH (type
));
14003 /* Symbols of this form are reasonably rare, so we just
14004 piggyback on the existing location code rather than writing
14005 a new implementation of symbol_computed_ops. */
14006 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14007 sizeof (struct dwarf2_locexpr_baton
));
14008 (*baton
)->per_cu
= cu
->per_cu
;
14009 gdb_assert ((*baton
)->per_cu
);
14011 (*baton
)->size
= 2 + cu_header
->addr_size
;
14012 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14013 (*baton
)->data
= data
;
14015 data
[0] = DW_OP_addr
;
14016 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14017 byte_order
, DW_ADDR (attr
));
14018 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14021 case DW_FORM_string
:
14023 case DW_FORM_GNU_str_index
:
14024 /* DW_STRING is already allocated on the objfile obstack, point
14026 *bytes
= (gdb_byte
*) DW_STRING (attr
);
14028 case DW_FORM_block1
:
14029 case DW_FORM_block2
:
14030 case DW_FORM_block4
:
14031 case DW_FORM_block
:
14032 case DW_FORM_exprloc
:
14033 blk
= DW_BLOCK (attr
);
14034 if (TYPE_LENGTH (type
) != blk
->size
)
14035 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
14036 TYPE_LENGTH (type
));
14037 *bytes
= blk
->data
;
14040 /* The DW_AT_const_value attributes are supposed to carry the
14041 symbol's value "represented as it would be on the target
14042 architecture." By the time we get here, it's already been
14043 converted to host endianness, so we just need to sign- or
14044 zero-extend it as appropriate. */
14045 case DW_FORM_data1
:
14046 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14047 obstack
, cu
, value
, 8);
14049 case DW_FORM_data2
:
14050 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14051 obstack
, cu
, value
, 16);
14053 case DW_FORM_data4
:
14054 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14055 obstack
, cu
, value
, 32);
14057 case DW_FORM_data8
:
14058 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14059 obstack
, cu
, value
, 64);
14062 case DW_FORM_sdata
:
14063 *value
= DW_SND (attr
);
14066 case DW_FORM_udata
:
14067 *value
= DW_UNSND (attr
);
14071 complaint (&symfile_complaints
,
14072 _("unsupported const value attribute form: '%s'"),
14073 dwarf_form_name (attr
->form
));
14080 /* Copy constant value from an attribute to a symbol. */
14083 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14084 struct dwarf2_cu
*cu
)
14086 struct objfile
*objfile
= cu
->objfile
;
14087 struct comp_unit_head
*cu_header
= &cu
->header
;
14090 struct dwarf2_locexpr_baton
*baton
;
14092 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
14093 SYMBOL_PRINT_NAME (sym
),
14094 &objfile
->objfile_obstack
, cu
,
14095 &value
, &bytes
, &baton
);
14099 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14100 SYMBOL_LOCATION_BATON (sym
) = baton
;
14101 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14103 else if (bytes
!= NULL
)
14105 SYMBOL_VALUE_BYTES (sym
) = bytes
;
14106 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
14110 SYMBOL_VALUE (sym
) = value
;
14111 SYMBOL_CLASS (sym
) = LOC_CONST
;
14115 /* Return the type of the die in question using its DW_AT_type attribute. */
14117 static struct type
*
14118 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14120 struct attribute
*type_attr
;
14122 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14125 /* A missing DW_AT_type represents a void type. */
14126 return objfile_type (cu
->objfile
)->builtin_void
;
14129 return lookup_die_type (die
, type_attr
, cu
);
14132 /* True iff CU's producer generates GNAT Ada auxiliary information
14133 that allows to find parallel types through that information instead
14134 of having to do expensive parallel lookups by type name. */
14137 need_gnat_info (struct dwarf2_cu
*cu
)
14139 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14140 of GNAT produces this auxiliary information, without any indication
14141 that it is produced. Part of enhancing the FSF version of GNAT
14142 to produce that information will be to put in place an indicator
14143 that we can use in order to determine whether the descriptive type
14144 info is available or not. One suggestion that has been made is
14145 to use a new attribute, attached to the CU die. For now, assume
14146 that the descriptive type info is not available. */
14150 /* Return the auxiliary type of the die in question using its
14151 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14152 attribute is not present. */
14154 static struct type
*
14155 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14157 struct attribute
*type_attr
;
14159 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
14163 return lookup_die_type (die
, type_attr
, cu
);
14166 /* If DIE has a descriptive_type attribute, then set the TYPE's
14167 descriptive type accordingly. */
14170 set_descriptive_type (struct type
*type
, struct die_info
*die
,
14171 struct dwarf2_cu
*cu
)
14173 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
14175 if (descriptive_type
)
14177 ALLOCATE_GNAT_AUX_TYPE (type
);
14178 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
14182 /* Return the containing type of the die in question using its
14183 DW_AT_containing_type attribute. */
14185 static struct type
*
14186 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14188 struct attribute
*type_attr
;
14190 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
14192 error (_("Dwarf Error: Problem turning containing type into gdb type "
14193 "[in module %s]"), cu
->objfile
->name
);
14195 return lookup_die_type (die
, type_attr
, cu
);
14198 /* Look up the type of DIE in CU using its type attribute ATTR.
14199 If there is no type substitute an error marker. */
14201 static struct type
*
14202 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
14203 struct dwarf2_cu
*cu
)
14205 struct objfile
*objfile
= cu
->objfile
;
14206 struct type
*this_type
;
14208 /* First see if we have it cached. */
14210 if (is_ref_attr (attr
))
14212 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14214 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
14216 else if (attr
->form
== DW_FORM_ref_sig8
)
14218 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14220 /* sig_type will be NULL if the signatured type is missing from
14222 if (sig_type
== NULL
)
14223 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14224 "at 0x%x [in module %s]"),
14225 die
->offset
.sect_off
, objfile
->name
);
14227 gdb_assert (sig_type
->per_cu
.is_debug_types
);
14228 /* If we haven't filled in type_offset_in_section yet, then we
14229 haven't read the type in yet. */
14231 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
14234 get_die_type_at_offset (sig_type
->type_offset_in_section
,
14235 &sig_type
->per_cu
);
14240 dump_die_for_error (die
);
14241 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
14242 dwarf_attr_name (attr
->name
), objfile
->name
);
14245 /* If not cached we need to read it in. */
14247 if (this_type
== NULL
)
14249 struct die_info
*type_die
;
14250 struct dwarf2_cu
*type_cu
= cu
;
14252 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
14253 /* If we found the type now, it's probably because the type came
14254 from an inter-CU reference and the type's CU got expanded before
14256 this_type
= get_die_type (type_die
, type_cu
);
14257 if (this_type
== NULL
)
14258 this_type
= read_type_die_1 (type_die
, type_cu
);
14261 /* If we still don't have a type use an error marker. */
14263 if (this_type
== NULL
)
14265 char *message
, *saved
;
14267 /* read_type_die already issued a complaint. */
14268 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
14270 cu
->header
.offset
.sect_off
,
14271 die
->offset
.sect_off
);
14272 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
14273 message
, strlen (message
));
14276 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
14282 /* Return the type in DIE, CU.
14283 Returns NULL for invalid types.
14285 This first does a lookup in the appropriate type_hash table,
14286 and only reads the die in if necessary.
14288 NOTE: This can be called when reading in partial or full symbols. */
14290 static struct type
*
14291 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
14293 struct type
*this_type
;
14295 this_type
= get_die_type (die
, cu
);
14299 return read_type_die_1 (die
, cu
);
14302 /* Read the type in DIE, CU.
14303 Returns NULL for invalid types. */
14305 static struct type
*
14306 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14308 struct type
*this_type
= NULL
;
14312 case DW_TAG_class_type
:
14313 case DW_TAG_interface_type
:
14314 case DW_TAG_structure_type
:
14315 case DW_TAG_union_type
:
14316 this_type
= read_structure_type (die
, cu
);
14318 case DW_TAG_enumeration_type
:
14319 this_type
= read_enumeration_type (die
, cu
);
14321 case DW_TAG_subprogram
:
14322 case DW_TAG_subroutine_type
:
14323 case DW_TAG_inlined_subroutine
:
14324 this_type
= read_subroutine_type (die
, cu
);
14326 case DW_TAG_array_type
:
14327 this_type
= read_array_type (die
, cu
);
14329 case DW_TAG_set_type
:
14330 this_type
= read_set_type (die
, cu
);
14332 case DW_TAG_pointer_type
:
14333 this_type
= read_tag_pointer_type (die
, cu
);
14335 case DW_TAG_ptr_to_member_type
:
14336 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14338 case DW_TAG_reference_type
:
14339 this_type
= read_tag_reference_type (die
, cu
);
14341 case DW_TAG_const_type
:
14342 this_type
= read_tag_const_type (die
, cu
);
14344 case DW_TAG_volatile_type
:
14345 this_type
= read_tag_volatile_type (die
, cu
);
14347 case DW_TAG_string_type
:
14348 this_type
= read_tag_string_type (die
, cu
);
14350 case DW_TAG_typedef
:
14351 this_type
= read_typedef (die
, cu
);
14353 case DW_TAG_subrange_type
:
14354 this_type
= read_subrange_type (die
, cu
);
14356 case DW_TAG_base_type
:
14357 this_type
= read_base_type (die
, cu
);
14359 case DW_TAG_unspecified_type
:
14360 this_type
= read_unspecified_type (die
, cu
);
14362 case DW_TAG_namespace
:
14363 this_type
= read_namespace_type (die
, cu
);
14365 case DW_TAG_module
:
14366 this_type
= read_module_type (die
, cu
);
14369 complaint (&symfile_complaints
,
14370 _("unexpected tag in read_type_die: '%s'"),
14371 dwarf_tag_name (die
->tag
));
14378 /* See if we can figure out if the class lives in a namespace. We do
14379 this by looking for a member function; its demangled name will
14380 contain namespace info, if there is any.
14381 Return the computed name or NULL.
14382 Space for the result is allocated on the objfile's obstack.
14383 This is the full-die version of guess_partial_die_structure_name.
14384 In this case we know DIE has no useful parent. */
14387 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14389 struct die_info
*spec_die
;
14390 struct dwarf2_cu
*spec_cu
;
14391 struct die_info
*child
;
14394 spec_die
= die_specification (die
, &spec_cu
);
14395 if (spec_die
!= NULL
)
14401 for (child
= die
->child
;
14403 child
= child
->sibling
)
14405 if (child
->tag
== DW_TAG_subprogram
)
14407 struct attribute
*attr
;
14409 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14411 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14415 = language_class_name_from_physname (cu
->language_defn
,
14419 if (actual_name
!= NULL
)
14421 char *die_name
= dwarf2_name (die
, cu
);
14423 if (die_name
!= NULL
14424 && strcmp (die_name
, actual_name
) != 0)
14426 /* Strip off the class name from the full name.
14427 We want the prefix. */
14428 int die_name_len
= strlen (die_name
);
14429 int actual_name_len
= strlen (actual_name
);
14431 /* Test for '::' as a sanity check. */
14432 if (actual_name_len
> die_name_len
+ 2
14433 && actual_name
[actual_name_len
14434 - die_name_len
- 1] == ':')
14436 obsavestring (actual_name
,
14437 actual_name_len
- die_name_len
- 2,
14438 &cu
->objfile
->objfile_obstack
);
14441 xfree (actual_name
);
14450 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14451 prefix part in such case. See
14452 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14455 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14457 struct attribute
*attr
;
14460 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14461 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14464 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14465 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14468 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14470 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14471 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14474 /* dwarf2_name had to be already called. */
14475 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14477 /* Strip the base name, keep any leading namespaces/classes. */
14478 base
= strrchr (DW_STRING (attr
), ':');
14479 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14482 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14483 &cu
->objfile
->objfile_obstack
);
14486 /* Return the name of the namespace/class that DIE is defined within,
14487 or "" if we can't tell. The caller should not xfree the result.
14489 For example, if we're within the method foo() in the following
14499 then determine_prefix on foo's die will return "N::C". */
14501 static const char *
14502 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14504 struct die_info
*parent
, *spec_die
;
14505 struct dwarf2_cu
*spec_cu
;
14506 struct type
*parent_type
;
14509 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14510 && cu
->language
!= language_fortran
)
14513 retval
= anonymous_struct_prefix (die
, cu
);
14517 /* We have to be careful in the presence of DW_AT_specification.
14518 For example, with GCC 3.4, given the code
14522 // Definition of N::foo.
14526 then we'll have a tree of DIEs like this:
14528 1: DW_TAG_compile_unit
14529 2: DW_TAG_namespace // N
14530 3: DW_TAG_subprogram // declaration of N::foo
14531 4: DW_TAG_subprogram // definition of N::foo
14532 DW_AT_specification // refers to die #3
14534 Thus, when processing die #4, we have to pretend that we're in
14535 the context of its DW_AT_specification, namely the contex of die
14538 spec_die
= die_specification (die
, &spec_cu
);
14539 if (spec_die
== NULL
)
14540 parent
= die
->parent
;
14543 parent
= spec_die
->parent
;
14547 if (parent
== NULL
)
14549 else if (parent
->building_fullname
)
14552 const char *parent_name
;
14554 /* It has been seen on RealView 2.2 built binaries,
14555 DW_TAG_template_type_param types actually _defined_ as
14556 children of the parent class:
14559 template class <class Enum> Class{};
14560 Class<enum E> class_e;
14562 1: DW_TAG_class_type (Class)
14563 2: DW_TAG_enumeration_type (E)
14564 3: DW_TAG_enumerator (enum1:0)
14565 3: DW_TAG_enumerator (enum2:1)
14567 2: DW_TAG_template_type_param
14568 DW_AT_type DW_FORM_ref_udata (E)
14570 Besides being broken debug info, it can put GDB into an
14571 infinite loop. Consider:
14573 When we're building the full name for Class<E>, we'll start
14574 at Class, and go look over its template type parameters,
14575 finding E. We'll then try to build the full name of E, and
14576 reach here. We're now trying to build the full name of E,
14577 and look over the parent DIE for containing scope. In the
14578 broken case, if we followed the parent DIE of E, we'd again
14579 find Class, and once again go look at its template type
14580 arguments, etc., etc. Simply don't consider such parent die
14581 as source-level parent of this die (it can't be, the language
14582 doesn't allow it), and break the loop here. */
14583 name
= dwarf2_name (die
, cu
);
14584 parent_name
= dwarf2_name (parent
, cu
);
14585 complaint (&symfile_complaints
,
14586 _("template param type '%s' defined within parent '%s'"),
14587 name
? name
: "<unknown>",
14588 parent_name
? parent_name
: "<unknown>");
14592 switch (parent
->tag
)
14594 case DW_TAG_namespace
:
14595 parent_type
= read_type_die (parent
, cu
);
14596 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14597 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14598 Work around this problem here. */
14599 if (cu
->language
== language_cplus
14600 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14602 /* We give a name to even anonymous namespaces. */
14603 return TYPE_TAG_NAME (parent_type
);
14604 case DW_TAG_class_type
:
14605 case DW_TAG_interface_type
:
14606 case DW_TAG_structure_type
:
14607 case DW_TAG_union_type
:
14608 case DW_TAG_module
:
14609 parent_type
= read_type_die (parent
, cu
);
14610 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14611 return TYPE_TAG_NAME (parent_type
);
14613 /* An anonymous structure is only allowed non-static data
14614 members; no typedefs, no member functions, et cetera.
14615 So it does not need a prefix. */
14617 case DW_TAG_compile_unit
:
14618 case DW_TAG_partial_unit
:
14619 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14620 if (cu
->language
== language_cplus
14621 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14622 && die
->child
!= NULL
14623 && (die
->tag
== DW_TAG_class_type
14624 || die
->tag
== DW_TAG_structure_type
14625 || die
->tag
== DW_TAG_union_type
))
14627 char *name
= guess_full_die_structure_name (die
, cu
);
14633 return determine_prefix (parent
, cu
);
14637 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14638 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14639 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14640 an obconcat, otherwise allocate storage for the result. The CU argument is
14641 used to determine the language and hence, the appropriate separator. */
14643 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14646 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14647 int physname
, struct dwarf2_cu
*cu
)
14649 const char *lead
= "";
14652 if (suffix
== NULL
|| suffix
[0] == '\0'
14653 || prefix
== NULL
|| prefix
[0] == '\0')
14655 else if (cu
->language
== language_java
)
14657 else if (cu
->language
== language_fortran
&& physname
)
14659 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14660 DW_AT_MIPS_linkage_name is preferred and used instead. */
14668 if (prefix
== NULL
)
14670 if (suffix
== NULL
)
14676 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14678 strcpy (retval
, lead
);
14679 strcat (retval
, prefix
);
14680 strcat (retval
, sep
);
14681 strcat (retval
, suffix
);
14686 /* We have an obstack. */
14687 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14691 /* Return sibling of die, NULL if no sibling. */
14693 static struct die_info
*
14694 sibling_die (struct die_info
*die
)
14696 return die
->sibling
;
14699 /* Get name of a die, return NULL if not found. */
14702 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14703 struct obstack
*obstack
)
14705 if (name
&& cu
->language
== language_cplus
)
14707 char *canon_name
= cp_canonicalize_string (name
);
14709 if (canon_name
!= NULL
)
14711 if (strcmp (canon_name
, name
) != 0)
14712 name
= obsavestring (canon_name
, strlen (canon_name
),
14714 xfree (canon_name
);
14721 /* Get name of a die, return NULL if not found. */
14724 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14726 struct attribute
*attr
;
14728 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14729 if ((!attr
|| !DW_STRING (attr
))
14730 && die
->tag
!= DW_TAG_class_type
14731 && die
->tag
!= DW_TAG_interface_type
14732 && die
->tag
!= DW_TAG_structure_type
14733 && die
->tag
!= DW_TAG_union_type
)
14738 case DW_TAG_compile_unit
:
14739 case DW_TAG_partial_unit
:
14740 /* Compilation units have a DW_AT_name that is a filename, not
14741 a source language identifier. */
14742 case DW_TAG_enumeration_type
:
14743 case DW_TAG_enumerator
:
14744 /* These tags always have simple identifiers already; no need
14745 to canonicalize them. */
14746 return DW_STRING (attr
);
14748 case DW_TAG_subprogram
:
14749 /* Java constructors will all be named "<init>", so return
14750 the class name when we see this special case. */
14751 if (cu
->language
== language_java
14752 && DW_STRING (attr
) != NULL
14753 && strcmp (DW_STRING (attr
), "<init>") == 0)
14755 struct dwarf2_cu
*spec_cu
= cu
;
14756 struct die_info
*spec_die
;
14758 /* GCJ will output '<init>' for Java constructor names.
14759 For this special case, return the name of the parent class. */
14761 /* GCJ may output suprogram DIEs with AT_specification set.
14762 If so, use the name of the specified DIE. */
14763 spec_die
= die_specification (die
, &spec_cu
);
14764 if (spec_die
!= NULL
)
14765 return dwarf2_name (spec_die
, spec_cu
);
14770 if (die
->tag
== DW_TAG_class_type
)
14771 return dwarf2_name (die
, cu
);
14773 while (die
->tag
!= DW_TAG_compile_unit
14774 && die
->tag
!= DW_TAG_partial_unit
);
14778 case DW_TAG_class_type
:
14779 case DW_TAG_interface_type
:
14780 case DW_TAG_structure_type
:
14781 case DW_TAG_union_type
:
14782 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14783 structures or unions. These were of the form "._%d" in GCC 4.1,
14784 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14785 and GCC 4.4. We work around this problem by ignoring these. */
14786 if (attr
&& DW_STRING (attr
)
14787 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14788 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14791 /* GCC might emit a nameless typedef that has a linkage name. See
14792 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14793 if (!attr
|| DW_STRING (attr
) == NULL
)
14795 char *demangled
= NULL
;
14797 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14799 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14801 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14804 /* Avoid demangling DW_STRING (attr) the second time on a second
14805 call for the same DIE. */
14806 if (!DW_STRING_IS_CANONICAL (attr
))
14807 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14813 /* FIXME: we already did this for the partial symbol... */
14814 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14815 &cu
->objfile
->objfile_obstack
);
14816 DW_STRING_IS_CANONICAL (attr
) = 1;
14819 /* Strip any leading namespaces/classes, keep only the base name.
14820 DW_AT_name for named DIEs does not contain the prefixes. */
14821 base
= strrchr (DW_STRING (attr
), ':');
14822 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14825 return DW_STRING (attr
);
14834 if (!DW_STRING_IS_CANONICAL (attr
))
14837 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14838 &cu
->objfile
->objfile_obstack
);
14839 DW_STRING_IS_CANONICAL (attr
) = 1;
14841 return DW_STRING (attr
);
14844 /* Return the die that this die in an extension of, or NULL if there
14845 is none. *EXT_CU is the CU containing DIE on input, and the CU
14846 containing the return value on output. */
14848 static struct die_info
*
14849 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14851 struct attribute
*attr
;
14853 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14857 return follow_die_ref (die
, attr
, ext_cu
);
14860 /* Convert a DIE tag into its string name. */
14862 static const char *
14863 dwarf_tag_name (unsigned tag
)
14865 const char *name
= get_DW_TAG_name (tag
);
14868 return "DW_TAG_<unknown>";
14873 /* Convert a DWARF attribute code into its string name. */
14875 static const char *
14876 dwarf_attr_name (unsigned attr
)
14880 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14881 if (attr
== DW_AT_MIPS_fde
)
14882 return "DW_AT_MIPS_fde";
14884 if (attr
== DW_AT_HP_block_index
)
14885 return "DW_AT_HP_block_index";
14888 name
= get_DW_AT_name (attr
);
14891 return "DW_AT_<unknown>";
14896 /* Convert a DWARF value form code into its string name. */
14898 static const char *
14899 dwarf_form_name (unsigned form
)
14901 const char *name
= get_DW_FORM_name (form
);
14904 return "DW_FORM_<unknown>";
14910 dwarf_bool_name (unsigned mybool
)
14918 /* Convert a DWARF type code into its string name. */
14920 static const char *
14921 dwarf_type_encoding_name (unsigned enc
)
14923 const char *name
= get_DW_ATE_name (enc
);
14926 return "DW_ATE_<unknown>";
14932 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14936 print_spaces (indent
, f
);
14937 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14938 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14940 if (die
->parent
!= NULL
)
14942 print_spaces (indent
, f
);
14943 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14944 die
->parent
->offset
.sect_off
);
14947 print_spaces (indent
, f
);
14948 fprintf_unfiltered (f
, " has children: %s\n",
14949 dwarf_bool_name (die
->child
!= NULL
));
14951 print_spaces (indent
, f
);
14952 fprintf_unfiltered (f
, " attributes:\n");
14954 for (i
= 0; i
< die
->num_attrs
; ++i
)
14956 print_spaces (indent
, f
);
14957 fprintf_unfiltered (f
, " %s (%s) ",
14958 dwarf_attr_name (die
->attrs
[i
].name
),
14959 dwarf_form_name (die
->attrs
[i
].form
));
14961 switch (die
->attrs
[i
].form
)
14964 case DW_FORM_GNU_addr_index
:
14965 fprintf_unfiltered (f
, "address: ");
14966 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14968 case DW_FORM_block2
:
14969 case DW_FORM_block4
:
14970 case DW_FORM_block
:
14971 case DW_FORM_block1
:
14972 fprintf_unfiltered (f
, "block: size %d",
14973 DW_BLOCK (&die
->attrs
[i
])->size
);
14975 case DW_FORM_exprloc
:
14976 fprintf_unfiltered (f
, "expression: size %u",
14977 DW_BLOCK (&die
->attrs
[i
])->size
);
14979 case DW_FORM_ref_addr
:
14980 fprintf_unfiltered (f
, "ref address: ");
14981 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14987 case DW_FORM_ref_udata
:
14988 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14989 (long) (DW_UNSND (&die
->attrs
[i
])));
14991 case DW_FORM_data1
:
14992 case DW_FORM_data2
:
14993 case DW_FORM_data4
:
14994 case DW_FORM_data8
:
14995 case DW_FORM_udata
:
14996 case DW_FORM_sdata
:
14997 fprintf_unfiltered (f
, "constant: %s",
14998 pulongest (DW_UNSND (&die
->attrs
[i
])));
15000 case DW_FORM_sec_offset
:
15001 fprintf_unfiltered (f
, "section offset: %s",
15002 pulongest (DW_UNSND (&die
->attrs
[i
])));
15004 case DW_FORM_ref_sig8
:
15005 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15006 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15007 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15009 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15011 case DW_FORM_string
:
15013 case DW_FORM_GNU_str_index
:
15014 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15015 DW_STRING (&die
->attrs
[i
])
15016 ? DW_STRING (&die
->attrs
[i
]) : "",
15017 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15020 if (DW_UNSND (&die
->attrs
[i
]))
15021 fprintf_unfiltered (f
, "flag: TRUE");
15023 fprintf_unfiltered (f
, "flag: FALSE");
15025 case DW_FORM_flag_present
:
15026 fprintf_unfiltered (f
, "flag: TRUE");
15028 case DW_FORM_indirect
:
15029 /* The reader will have reduced the indirect form to
15030 the "base form" so this form should not occur. */
15031 fprintf_unfiltered (f
,
15032 "unexpected attribute form: DW_FORM_indirect");
15035 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15036 die
->attrs
[i
].form
);
15039 fprintf_unfiltered (f
, "\n");
15044 dump_die_for_error (struct die_info
*die
)
15046 dump_die_shallow (gdb_stderr
, 0, die
);
15050 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15052 int indent
= level
* 4;
15054 gdb_assert (die
!= NULL
);
15056 if (level
>= max_level
)
15059 dump_die_shallow (f
, indent
, die
);
15061 if (die
->child
!= NULL
)
15063 print_spaces (indent
, f
);
15064 fprintf_unfiltered (f
, " Children:");
15065 if (level
+ 1 < max_level
)
15067 fprintf_unfiltered (f
, "\n");
15068 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15072 fprintf_unfiltered (f
,
15073 " [not printed, max nesting level reached]\n");
15077 if (die
->sibling
!= NULL
&& level
> 0)
15079 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15083 /* This is called from the pdie macro in gdbinit.in.
15084 It's not static so gcc will keep a copy callable from gdb. */
15087 dump_die (struct die_info
*die
, int max_level
)
15089 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15093 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15097 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15103 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15104 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15107 is_ref_attr (struct attribute
*attr
)
15109 switch (attr
->form
)
15111 case DW_FORM_ref_addr
:
15116 case DW_FORM_ref_udata
:
15123 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15127 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15129 sect_offset retval
= { DW_UNSND (attr
) };
15131 if (is_ref_attr (attr
))
15134 retval
.sect_off
= 0;
15135 complaint (&symfile_complaints
,
15136 _("unsupported die ref attribute form: '%s'"),
15137 dwarf_form_name (attr
->form
));
15141 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15142 * the value held by the attribute is not constant. */
15145 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15147 if (attr
->form
== DW_FORM_sdata
)
15148 return DW_SND (attr
);
15149 else if (attr
->form
== DW_FORM_udata
15150 || attr
->form
== DW_FORM_data1
15151 || attr
->form
== DW_FORM_data2
15152 || attr
->form
== DW_FORM_data4
15153 || attr
->form
== DW_FORM_data8
)
15154 return DW_UNSND (attr
);
15157 complaint (&symfile_complaints
,
15158 _("Attribute value is not a constant (%s)"),
15159 dwarf_form_name (attr
->form
));
15160 return default_value
;
15164 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15165 unit and add it to our queue.
15166 The result is non-zero if PER_CU was queued, otherwise the result is zero
15167 meaning either PER_CU is already queued or it is already loaded. */
15170 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15171 struct dwarf2_per_cu_data
*per_cu
,
15172 enum language pretend_language
)
15174 /* We may arrive here during partial symbol reading, if we need full
15175 DIEs to process an unusual case (e.g. template arguments). Do
15176 not queue PER_CU, just tell our caller to load its DIEs. */
15177 if (dwarf2_per_objfile
->reading_partial_symbols
)
15179 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15184 /* Mark the dependence relation so that we don't flush PER_CU
15186 dwarf2_add_dependence (this_cu
, per_cu
);
15188 /* If it's already on the queue, we have nothing to do. */
15189 if (per_cu
->queued
)
15192 /* If the compilation unit is already loaded, just mark it as
15194 if (per_cu
->cu
!= NULL
)
15196 per_cu
->cu
->last_used
= 0;
15200 /* Add it to the queue. */
15201 queue_comp_unit (per_cu
, pretend_language
);
15206 /* Follow reference or signature attribute ATTR of SRC_DIE.
15207 On entry *REF_CU is the CU of SRC_DIE.
15208 On exit *REF_CU is the CU of the result. */
15210 static struct die_info
*
15211 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15212 struct dwarf2_cu
**ref_cu
)
15214 struct die_info
*die
;
15216 if (is_ref_attr (attr
))
15217 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15218 else if (attr
->form
== DW_FORM_ref_sig8
)
15219 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15222 dump_die_for_error (src_die
);
15223 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15224 (*ref_cu
)->objfile
->name
);
15230 /* Follow reference OFFSET.
15231 On entry *REF_CU is the CU of the source die referencing OFFSET.
15232 On exit *REF_CU is the CU of the result.
15233 Returns NULL if OFFSET is invalid. */
15235 static struct die_info
*
15236 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15238 struct die_info temp_die
;
15239 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15241 gdb_assert (cu
->per_cu
!= NULL
);
15245 if (cu
->per_cu
->is_debug_types
)
15247 /* .debug_types CUs cannot reference anything outside their CU.
15248 If they need to, they have to reference a signatured type via
15249 DW_FORM_ref_sig8. */
15250 if (! offset_in_cu_p (&cu
->header
, offset
))
15253 else if (! offset_in_cu_p (&cu
->header
, offset
))
15255 struct dwarf2_per_cu_data
*per_cu
;
15257 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15259 /* If necessary, add it to the queue and load its DIEs. */
15260 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
15261 load_full_comp_unit (per_cu
, cu
->language
);
15263 target_cu
= per_cu
->cu
;
15265 else if (cu
->dies
== NULL
)
15267 /* We're loading full DIEs during partial symbol reading. */
15268 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15269 load_full_comp_unit (cu
->per_cu
, language_minimal
);
15272 *ref_cu
= target_cu
;
15273 temp_die
.offset
= offset
;
15274 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15277 /* Follow reference attribute ATTR of SRC_DIE.
15278 On entry *REF_CU is the CU of SRC_DIE.
15279 On exit *REF_CU is the CU of the result. */
15281 static struct die_info
*
15282 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15283 struct dwarf2_cu
**ref_cu
)
15285 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15286 struct dwarf2_cu
*cu
= *ref_cu
;
15287 struct die_info
*die
;
15289 die
= follow_die_offset (offset
, ref_cu
);
15291 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15292 "at 0x%x [in module %s]"),
15293 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15298 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15299 Returned value is intended for DW_OP_call*. Returned
15300 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15302 struct dwarf2_locexpr_baton
15303 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15304 struct dwarf2_per_cu_data
*per_cu
,
15305 CORE_ADDR (*get_frame_pc
) (void *baton
),
15308 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15309 struct dwarf2_cu
*cu
;
15310 struct die_info
*die
;
15311 struct attribute
*attr
;
15312 struct dwarf2_locexpr_baton retval
;
15314 dw2_setup (per_cu
->objfile
);
15316 if (per_cu
->cu
== NULL
)
15320 die
= follow_die_offset (offset
, &cu
);
15322 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15323 offset
.sect_off
, per_cu
->objfile
->name
);
15325 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15328 /* DWARF: "If there is no such attribute, then there is no effect.".
15329 DATA is ignored if SIZE is 0. */
15331 retval
.data
= NULL
;
15334 else if (attr_form_is_section_offset (attr
))
15336 struct dwarf2_loclist_baton loclist_baton
;
15337 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15340 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15342 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15344 retval
.size
= size
;
15348 if (!attr_form_is_block (attr
))
15349 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15350 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15351 offset
.sect_off
, per_cu
->objfile
->name
);
15353 retval
.data
= DW_BLOCK (attr
)->data
;
15354 retval
.size
= DW_BLOCK (attr
)->size
;
15356 retval
.per_cu
= cu
->per_cu
;
15358 age_cached_comp_units ();
15363 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15367 dwarf2_get_die_type (cu_offset die_offset
,
15368 struct dwarf2_per_cu_data
*per_cu
)
15370 sect_offset die_offset_sect
;
15372 dw2_setup (per_cu
->objfile
);
15374 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15375 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15378 /* Follow the signature attribute ATTR in SRC_DIE.
15379 On entry *REF_CU is the CU of SRC_DIE.
15380 On exit *REF_CU is the CU of the result. */
15382 static struct die_info
*
15383 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15384 struct dwarf2_cu
**ref_cu
)
15386 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15387 struct die_info temp_die
;
15388 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15389 struct dwarf2_cu
*sig_cu
;
15390 struct die_info
*die
;
15392 /* sig_type will be NULL if the signatured type is missing from
15394 if (sig_type
== NULL
)
15395 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15396 "at 0x%x [in module %s]"),
15397 src_die
->offset
.sect_off
, objfile
->name
);
15399 /* If necessary, add it to the queue and load its DIEs. */
15401 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15402 read_signatured_type (sig_type
);
15404 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15406 sig_cu
= sig_type
->per_cu
.cu
;
15407 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15408 temp_die
.offset
= sig_type
->type_offset_in_section
;
15409 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15410 temp_die
.offset
.sect_off
);
15417 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15418 "from DIE at 0x%x [in module %s]"),
15419 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15422 /* Given an offset of a signatured type, return its signatured_type. */
15424 static struct signatured_type
*
15425 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15426 struct dwarf2_section_info
*section
,
15427 sect_offset offset
)
15429 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15430 unsigned int length
, initial_length_size
;
15431 unsigned int sig_offset
;
15432 struct signatured_type find_entry
, *sig_type
;
15434 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15435 sig_offset
= (initial_length_size
15437 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15438 + 1 /*address_size*/);
15439 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15440 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15442 /* This is only used to lookup previously recorded types.
15443 If we didn't find it, it's our bug. */
15444 gdb_assert (sig_type
!= NULL
);
15445 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15450 /* Load the DIEs associated with type unit PER_CU into memory. */
15453 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15455 struct objfile
*objfile
= per_cu
->objfile
;
15456 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15457 sect_offset offset
= per_cu
->offset
;
15458 struct signatured_type
*sig_type
;
15460 dwarf2_read_section (objfile
, sect
);
15462 /* We have the section offset, but we need the signature to do the
15463 hash table lookup. */
15464 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15465 the signature to assert we found the right one.
15466 Ok, but it's a lot of work. We should simplify things so any needed
15467 assert doesn't require all this clumsiness. */
15468 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15470 gdb_assert (&sig_type
->per_cu
== per_cu
);
15471 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15473 read_signatured_type (sig_type
);
15475 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15478 /* die_reader_func for read_signatured_type.
15479 This is identical to load_full_comp_unit_reader,
15480 but is kept separate for now. */
15483 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15484 gdb_byte
*info_ptr
,
15485 struct die_info
*comp_unit_die
,
15489 struct dwarf2_cu
*cu
= reader
->cu
;
15491 gdb_assert (cu
->die_hash
== NULL
);
15493 htab_create_alloc_ex (cu
->header
.length
/ 12,
15497 &cu
->comp_unit_obstack
,
15498 hashtab_obstack_allocate
,
15499 dummy_obstack_deallocate
);
15502 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15503 &info_ptr
, comp_unit_die
);
15504 cu
->dies
= comp_unit_die
;
15505 /* comp_unit_die is not stored in die_hash, no need. */
15507 /* We try not to read any attributes in this function, because not
15508 all CUs needed for references have been loaded yet, and symbol
15509 table processing isn't initialized. But we have to set the CU language,
15510 or we won't be able to build types correctly.
15511 Similarly, if we do not read the producer, we can not apply
15512 producer-specific interpretation. */
15513 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15516 /* Read in a signatured type and build its CU and DIEs.
15517 If the type is a stub for the real type in a DWO file,
15518 read in the real type from the DWO file as well. */
15521 read_signatured_type (struct signatured_type
*sig_type
)
15523 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15525 gdb_assert (per_cu
->is_debug_types
);
15526 gdb_assert (per_cu
->cu
== NULL
);
15528 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15531 /* Decode simple location descriptions.
15532 Given a pointer to a dwarf block that defines a location, compute
15533 the location and return the value.
15535 NOTE drow/2003-11-18: This function is called in two situations
15536 now: for the address of static or global variables (partial symbols
15537 only) and for offsets into structures which are expected to be
15538 (more or less) constant. The partial symbol case should go away,
15539 and only the constant case should remain. That will let this
15540 function complain more accurately. A few special modes are allowed
15541 without complaint for global variables (for instance, global
15542 register values and thread-local values).
15544 A location description containing no operations indicates that the
15545 object is optimized out. The return value is 0 for that case.
15546 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15547 callers will only want a very basic result and this can become a
15550 Note that stack[0] is unused except as a default error return. */
15553 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15555 struct objfile
*objfile
= cu
->objfile
;
15557 int size
= blk
->size
;
15558 gdb_byte
*data
= blk
->data
;
15559 CORE_ADDR stack
[64];
15561 unsigned int bytes_read
, unsnd
;
15567 stack
[++stacki
] = 0;
15606 stack
[++stacki
] = op
- DW_OP_lit0
;
15641 stack
[++stacki
] = op
- DW_OP_reg0
;
15643 dwarf2_complex_location_expr_complaint ();
15647 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15649 stack
[++stacki
] = unsnd
;
15651 dwarf2_complex_location_expr_complaint ();
15655 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15660 case DW_OP_const1u
:
15661 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15665 case DW_OP_const1s
:
15666 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15670 case DW_OP_const2u
:
15671 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15675 case DW_OP_const2s
:
15676 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15680 case DW_OP_const4u
:
15681 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15685 case DW_OP_const4s
:
15686 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15690 case DW_OP_const8u
:
15691 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15696 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15702 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15707 stack
[stacki
+ 1] = stack
[stacki
];
15712 stack
[stacki
- 1] += stack
[stacki
];
15716 case DW_OP_plus_uconst
:
15717 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15723 stack
[stacki
- 1] -= stack
[stacki
];
15728 /* If we're not the last op, then we definitely can't encode
15729 this using GDB's address_class enum. This is valid for partial
15730 global symbols, although the variable's address will be bogus
15733 dwarf2_complex_location_expr_complaint ();
15736 case DW_OP_GNU_push_tls_address
:
15737 /* The top of the stack has the offset from the beginning
15738 of the thread control block at which the variable is located. */
15739 /* Nothing should follow this operator, so the top of stack would
15741 /* This is valid for partial global symbols, but the variable's
15742 address will be bogus in the psymtab. Make it always at least
15743 non-zero to not look as a variable garbage collected by linker
15744 which have DW_OP_addr 0. */
15746 dwarf2_complex_location_expr_complaint ();
15750 case DW_OP_GNU_uninit
:
15753 case DW_OP_GNU_addr_index
:
15754 case DW_OP_GNU_const_index
:
15755 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15762 const char *name
= get_DW_OP_name (op
);
15765 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15768 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15772 return (stack
[stacki
]);
15775 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15776 outside of the allocated space. Also enforce minimum>0. */
15777 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15779 complaint (&symfile_complaints
,
15780 _("location description stack overflow"));
15786 complaint (&symfile_complaints
,
15787 _("location description stack underflow"));
15791 return (stack
[stacki
]);
15794 /* memory allocation interface */
15796 static struct dwarf_block
*
15797 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15799 struct dwarf_block
*blk
;
15801 blk
= (struct dwarf_block
*)
15802 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15806 static struct die_info
*
15807 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15809 struct die_info
*die
;
15810 size_t size
= sizeof (struct die_info
);
15813 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15815 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15816 memset (die
, 0, sizeof (struct die_info
));
15821 /* Macro support. */
15823 /* Return the full name of file number I in *LH's file name table.
15824 Use COMP_DIR as the name of the current directory of the
15825 compilation. The result is allocated using xmalloc; the caller is
15826 responsible for freeing it. */
15828 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15830 /* Is the file number a valid index into the line header's file name
15831 table? Remember that file numbers start with one, not zero. */
15832 if (1 <= file
&& file
<= lh
->num_file_names
)
15834 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15836 if (IS_ABSOLUTE_PATH (fe
->name
))
15837 return xstrdup (fe
->name
);
15845 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15851 dir_len
= strlen (dir
);
15852 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15853 strcpy (full_name
, dir
);
15854 full_name
[dir_len
] = '/';
15855 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15859 return xstrdup (fe
->name
);
15864 /* The compiler produced a bogus file number. We can at least
15865 record the macro definitions made in the file, even if we
15866 won't be able to find the file by name. */
15867 char fake_name
[80];
15869 sprintf (fake_name
, "<bad macro file number %d>", file
);
15871 complaint (&symfile_complaints
,
15872 _("bad file number in macro information (%d)"),
15875 return xstrdup (fake_name
);
15880 static struct macro_source_file
*
15881 macro_start_file (int file
, int line
,
15882 struct macro_source_file
*current_file
,
15883 const char *comp_dir
,
15884 struct line_header
*lh
, struct objfile
*objfile
)
15886 /* The full name of this source file. */
15887 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15889 /* We don't create a macro table for this compilation unit
15890 at all until we actually get a filename. */
15891 if (! pending_macros
)
15892 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15893 objfile
->macro_cache
);
15895 if (! current_file
)
15897 /* If we have no current file, then this must be the start_file
15898 directive for the compilation unit's main source file. */
15899 current_file
= macro_set_main (pending_macros
, full_name
);
15900 macro_define_special (pending_macros
);
15903 current_file
= macro_include (current_file
, line
, full_name
);
15907 return current_file
;
15911 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15912 followed by a null byte. */
15914 copy_string (const char *buf
, int len
)
15916 char *s
= xmalloc (len
+ 1);
15918 memcpy (s
, buf
, len
);
15924 static const char *
15925 consume_improper_spaces (const char *p
, const char *body
)
15929 complaint (&symfile_complaints
,
15930 _("macro definition contains spaces "
15931 "in formal argument list:\n`%s'"),
15943 parse_macro_definition (struct macro_source_file
*file
, int line
,
15948 /* The body string takes one of two forms. For object-like macro
15949 definitions, it should be:
15951 <macro name> " " <definition>
15953 For function-like macro definitions, it should be:
15955 <macro name> "() " <definition>
15957 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15959 Spaces may appear only where explicitly indicated, and in the
15962 The Dwarf 2 spec says that an object-like macro's name is always
15963 followed by a space, but versions of GCC around March 2002 omit
15964 the space when the macro's definition is the empty string.
15966 The Dwarf 2 spec says that there should be no spaces between the
15967 formal arguments in a function-like macro's formal argument list,
15968 but versions of GCC around March 2002 include spaces after the
15972 /* Find the extent of the macro name. The macro name is terminated
15973 by either a space or null character (for an object-like macro) or
15974 an opening paren (for a function-like macro). */
15975 for (p
= body
; *p
; p
++)
15976 if (*p
== ' ' || *p
== '(')
15979 if (*p
== ' ' || *p
== '\0')
15981 /* It's an object-like macro. */
15982 int name_len
= p
- body
;
15983 char *name
= copy_string (body
, name_len
);
15984 const char *replacement
;
15987 replacement
= body
+ name_len
+ 1;
15990 dwarf2_macro_malformed_definition_complaint (body
);
15991 replacement
= body
+ name_len
;
15994 macro_define_object (file
, line
, name
, replacement
);
15998 else if (*p
== '(')
16000 /* It's a function-like macro. */
16001 char *name
= copy_string (body
, p
- body
);
16004 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16008 p
= consume_improper_spaces (p
, body
);
16010 /* Parse the formal argument list. */
16011 while (*p
&& *p
!= ')')
16013 /* Find the extent of the current argument name. */
16014 const char *arg_start
= p
;
16016 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16019 if (! *p
|| p
== arg_start
)
16020 dwarf2_macro_malformed_definition_complaint (body
);
16023 /* Make sure argv has room for the new argument. */
16024 if (argc
>= argv_size
)
16027 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16030 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16033 p
= consume_improper_spaces (p
, body
);
16035 /* Consume the comma, if present. */
16040 p
= consume_improper_spaces (p
, body
);
16049 /* Perfectly formed definition, no complaints. */
16050 macro_define_function (file
, line
, name
,
16051 argc
, (const char **) argv
,
16053 else if (*p
== '\0')
16055 /* Complain, but do define it. */
16056 dwarf2_macro_malformed_definition_complaint (body
);
16057 macro_define_function (file
, line
, name
,
16058 argc
, (const char **) argv
,
16062 /* Just complain. */
16063 dwarf2_macro_malformed_definition_complaint (body
);
16066 /* Just complain. */
16067 dwarf2_macro_malformed_definition_complaint (body
);
16073 for (i
= 0; i
< argc
; i
++)
16079 dwarf2_macro_malformed_definition_complaint (body
);
16082 /* Skip some bytes from BYTES according to the form given in FORM.
16083 Returns the new pointer. */
16086 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16087 enum dwarf_form form
,
16088 unsigned int offset_size
,
16089 struct dwarf2_section_info
*section
)
16091 unsigned int bytes_read
;
16095 case DW_FORM_data1
:
16100 case DW_FORM_data2
:
16104 case DW_FORM_data4
:
16108 case DW_FORM_data8
:
16112 case DW_FORM_string
:
16113 read_direct_string (abfd
, bytes
, &bytes_read
);
16114 bytes
+= bytes_read
;
16117 case DW_FORM_sec_offset
:
16119 bytes
+= offset_size
;
16122 case DW_FORM_block
:
16123 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16124 bytes
+= bytes_read
;
16127 case DW_FORM_block1
:
16128 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16130 case DW_FORM_block2
:
16131 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16133 case DW_FORM_block4
:
16134 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16137 case DW_FORM_sdata
:
16138 case DW_FORM_udata
:
16139 case DW_FORM_GNU_addr_index
:
16140 case DW_FORM_GNU_str_index
:
16141 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16144 dwarf2_section_buffer_overflow_complaint (section
);
16152 complaint (&symfile_complaints
,
16153 _("invalid form 0x%x in `%s'"),
16155 section
->asection
->name
);
16163 /* A helper for dwarf_decode_macros that handles skipping an unknown
16164 opcode. Returns an updated pointer to the macro data buffer; or,
16165 on error, issues a complaint and returns NULL. */
16168 skip_unknown_opcode (unsigned int opcode
,
16169 gdb_byte
**opcode_definitions
,
16170 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16172 unsigned int offset_size
,
16173 struct dwarf2_section_info
*section
)
16175 unsigned int bytes_read
, i
;
16179 if (opcode_definitions
[opcode
] == NULL
)
16181 complaint (&symfile_complaints
,
16182 _("unrecognized DW_MACFINO opcode 0x%x"),
16187 defn
= opcode_definitions
[opcode
];
16188 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16189 defn
+= bytes_read
;
16191 for (i
= 0; i
< arg
; ++i
)
16193 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16195 if (mac_ptr
== NULL
)
16197 /* skip_form_bytes already issued the complaint. */
16205 /* A helper function which parses the header of a macro section.
16206 If the macro section is the extended (for now called "GNU") type,
16207 then this updates *OFFSET_SIZE. Returns a pointer to just after
16208 the header, or issues a complaint and returns NULL on error. */
16211 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16214 unsigned int *offset_size
,
16215 int section_is_gnu
)
16217 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16219 if (section_is_gnu
)
16221 unsigned int version
, flags
;
16223 version
= read_2_bytes (abfd
, mac_ptr
);
16226 complaint (&symfile_complaints
,
16227 _("unrecognized version `%d' in .debug_macro section"),
16233 flags
= read_1_byte (abfd
, mac_ptr
);
16235 *offset_size
= (flags
& 1) ? 8 : 4;
16237 if ((flags
& 2) != 0)
16238 /* We don't need the line table offset. */
16239 mac_ptr
+= *offset_size
;
16241 /* Vendor opcode descriptions. */
16242 if ((flags
& 4) != 0)
16244 unsigned int i
, count
;
16246 count
= read_1_byte (abfd
, mac_ptr
);
16248 for (i
= 0; i
< count
; ++i
)
16250 unsigned int opcode
, bytes_read
;
16253 opcode
= read_1_byte (abfd
, mac_ptr
);
16255 opcode_definitions
[opcode
] = mac_ptr
;
16256 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16257 mac_ptr
+= bytes_read
;
16266 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16267 including DW_MACRO_GNU_transparent_include. */
16270 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16271 struct macro_source_file
*current_file
,
16272 struct line_header
*lh
, char *comp_dir
,
16273 struct dwarf2_section_info
*section
,
16274 int section_is_gnu
,
16275 unsigned int offset_size
,
16276 struct objfile
*objfile
,
16277 htab_t include_hash
)
16279 enum dwarf_macro_record_type macinfo_type
;
16280 int at_commandline
;
16281 gdb_byte
*opcode_definitions
[256];
16283 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16284 &offset_size
, section_is_gnu
);
16285 if (mac_ptr
== NULL
)
16287 /* We already issued a complaint. */
16291 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16292 GDB is still reading the definitions from command line. First
16293 DW_MACINFO_start_file will need to be ignored as it was already executed
16294 to create CURRENT_FILE for the main source holding also the command line
16295 definitions. On first met DW_MACINFO_start_file this flag is reset to
16296 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16298 at_commandline
= 1;
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 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16312 /* Note that we rely on the fact that the corresponding GNU and
16313 DWARF constants are the same. */
16314 switch (macinfo_type
)
16316 /* A zero macinfo type indicates the end of the macro
16321 case DW_MACRO_GNU_define
:
16322 case DW_MACRO_GNU_undef
:
16323 case DW_MACRO_GNU_define_indirect
:
16324 case DW_MACRO_GNU_undef_indirect
:
16326 unsigned int bytes_read
;
16331 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16332 mac_ptr
+= bytes_read
;
16334 if (macinfo_type
== DW_MACRO_GNU_define
16335 || macinfo_type
== DW_MACRO_GNU_undef
)
16337 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16338 mac_ptr
+= bytes_read
;
16342 LONGEST str_offset
;
16344 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16345 mac_ptr
+= offset_size
;
16347 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16350 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16351 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16352 if (! current_file
)
16354 /* DWARF violation as no main source is present. */
16355 complaint (&symfile_complaints
,
16356 _("debug info with no main source gives macro %s "
16358 is_define
? _("definition") : _("undefinition"),
16362 if ((line
== 0 && !at_commandline
)
16363 || (line
!= 0 && at_commandline
))
16364 complaint (&symfile_complaints
,
16365 _("debug info gives %s macro %s with %s line %d: %s"),
16366 at_commandline
? _("command-line") : _("in-file"),
16367 is_define
? _("definition") : _("undefinition"),
16368 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16371 parse_macro_definition (current_file
, line
, body
);
16374 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16375 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16376 macro_undef (current_file
, line
, body
);
16381 case DW_MACRO_GNU_start_file
:
16383 unsigned int bytes_read
;
16386 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16387 mac_ptr
+= bytes_read
;
16388 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16389 mac_ptr
+= bytes_read
;
16391 if ((line
== 0 && !at_commandline
)
16392 || (line
!= 0 && at_commandline
))
16393 complaint (&symfile_complaints
,
16394 _("debug info gives source %d included "
16395 "from %s at %s line %d"),
16396 file
, at_commandline
? _("command-line") : _("file"),
16397 line
== 0 ? _("zero") : _("non-zero"), line
);
16399 if (at_commandline
)
16401 /* This DW_MACRO_GNU_start_file was executed in the
16403 at_commandline
= 0;
16406 current_file
= macro_start_file (file
, line
,
16407 current_file
, comp_dir
,
16412 case DW_MACRO_GNU_end_file
:
16413 if (! current_file
)
16414 complaint (&symfile_complaints
,
16415 _("macro debug info has an unmatched "
16416 "`close_file' directive"));
16419 current_file
= current_file
->included_by
;
16420 if (! current_file
)
16422 enum dwarf_macro_record_type next_type
;
16424 /* GCC circa March 2002 doesn't produce the zero
16425 type byte marking the end of the compilation
16426 unit. Complain if it's not there, but exit no
16429 /* Do we at least have room for a macinfo type byte? */
16430 if (mac_ptr
>= mac_end
)
16432 dwarf2_section_buffer_overflow_complaint (section
);
16436 /* We don't increment mac_ptr here, so this is just
16438 next_type
= read_1_byte (abfd
, mac_ptr
);
16439 if (next_type
!= 0)
16440 complaint (&symfile_complaints
,
16441 _("no terminating 0-type entry for "
16442 "macros in `.debug_macinfo' section"));
16449 case DW_MACRO_GNU_transparent_include
:
16454 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16455 mac_ptr
+= offset_size
;
16457 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16460 /* This has actually happened; see
16461 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16462 complaint (&symfile_complaints
,
16463 _("recursive DW_MACRO_GNU_transparent_include in "
16464 ".debug_macro section"));
16470 dwarf_decode_macro_bytes (abfd
,
16471 section
->buffer
+ offset
,
16472 mac_end
, current_file
,
16474 section
, section_is_gnu
,
16475 offset_size
, objfile
, include_hash
);
16477 htab_remove_elt (include_hash
, mac_ptr
);
16482 case DW_MACINFO_vendor_ext
:
16483 if (!section_is_gnu
)
16485 unsigned int bytes_read
;
16488 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16489 mac_ptr
+= bytes_read
;
16490 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16491 mac_ptr
+= bytes_read
;
16493 /* We don't recognize any vendor extensions. */
16499 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16500 mac_ptr
, mac_end
, abfd
, offset_size
,
16502 if (mac_ptr
== NULL
)
16506 } while (macinfo_type
!= 0);
16510 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
16511 char *comp_dir
, int section_is_gnu
)
16513 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16514 struct line_header
*lh
= cu
->line_header
;
16516 gdb_byte
*mac_ptr
, *mac_end
;
16517 struct macro_source_file
*current_file
= 0;
16518 enum dwarf_macro_record_type macinfo_type
;
16519 unsigned int offset_size
= cu
->header
.offset_size
;
16520 gdb_byte
*opcode_definitions
[256];
16521 struct cleanup
*cleanup
;
16522 htab_t include_hash
;
16524 struct dwarf2_section_info
*section
;
16525 const char *section_name
;
16527 if (cu
->dwo_unit
!= NULL
)
16529 if (section_is_gnu
)
16531 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
16532 section_name
= ".debug_macro.dwo";
16536 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
16537 section_name
= ".debug_macinfo.dwo";
16542 if (section_is_gnu
)
16544 section
= &dwarf2_per_objfile
->macro
;
16545 section_name
= ".debug_macro";
16549 section
= &dwarf2_per_objfile
->macinfo
;
16550 section_name
= ".debug_macinfo";
16554 dwarf2_read_section (objfile
, section
);
16555 if (section
->buffer
== NULL
)
16557 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16560 abfd
= section
->asection
->owner
;
16562 /* First pass: Find the name of the base filename.
16563 This filename is needed in order to process all macros whose definition
16564 (or undefinition) comes from the command line. These macros are defined
16565 before the first DW_MACINFO_start_file entry, and yet still need to be
16566 associated to the base file.
16568 To determine the base file name, we scan the macro definitions until we
16569 reach the first DW_MACINFO_start_file entry. We then initialize
16570 CURRENT_FILE accordingly so that any macro definition found before the
16571 first DW_MACINFO_start_file can still be associated to the base file. */
16573 mac_ptr
= section
->buffer
+ offset
;
16574 mac_end
= section
->buffer
+ section
->size
;
16576 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16577 &offset_size
, section_is_gnu
);
16578 if (mac_ptr
== NULL
)
16580 /* We already issued a complaint. */
16586 /* Do we at least have room for a macinfo type byte? */
16587 if (mac_ptr
>= mac_end
)
16589 /* Complaint is printed during the second pass as GDB will probably
16590 stop the first pass earlier upon finding
16591 DW_MACINFO_start_file. */
16595 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16598 /* Note that we rely on the fact that the corresponding GNU and
16599 DWARF constants are the same. */
16600 switch (macinfo_type
)
16602 /* A zero macinfo type indicates the end of the macro
16607 case DW_MACRO_GNU_define
:
16608 case DW_MACRO_GNU_undef
:
16609 /* Only skip the data by MAC_PTR. */
16611 unsigned int bytes_read
;
16613 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16614 mac_ptr
+= bytes_read
;
16615 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16616 mac_ptr
+= bytes_read
;
16620 case DW_MACRO_GNU_start_file
:
16622 unsigned int bytes_read
;
16625 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16626 mac_ptr
+= bytes_read
;
16627 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16628 mac_ptr
+= bytes_read
;
16630 current_file
= macro_start_file (file
, line
, current_file
,
16631 comp_dir
, lh
, objfile
);
16635 case DW_MACRO_GNU_end_file
:
16636 /* No data to skip by MAC_PTR. */
16639 case DW_MACRO_GNU_define_indirect
:
16640 case DW_MACRO_GNU_undef_indirect
:
16642 unsigned int bytes_read
;
16644 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16645 mac_ptr
+= bytes_read
;
16646 mac_ptr
+= offset_size
;
16650 case DW_MACRO_GNU_transparent_include
:
16651 /* Note that, according to the spec, a transparent include
16652 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16653 skip this opcode. */
16654 mac_ptr
+= offset_size
;
16657 case DW_MACINFO_vendor_ext
:
16658 /* Only skip the data by MAC_PTR. */
16659 if (!section_is_gnu
)
16661 unsigned int bytes_read
;
16663 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16664 mac_ptr
+= bytes_read
;
16665 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16666 mac_ptr
+= bytes_read
;
16671 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16672 mac_ptr
, mac_end
, abfd
, offset_size
,
16674 if (mac_ptr
== NULL
)
16678 } while (macinfo_type
!= 0 && current_file
== NULL
);
16680 /* Second pass: Process all entries.
16682 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16683 command-line macro definitions/undefinitions. This flag is unset when we
16684 reach the first DW_MACINFO_start_file entry. */
16686 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16687 NULL
, xcalloc
, xfree
);
16688 cleanup
= make_cleanup_htab_delete (include_hash
);
16689 mac_ptr
= section
->buffer
+ offset
;
16690 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16692 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16693 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16694 offset_size
, objfile
, include_hash
);
16695 do_cleanups (cleanup
);
16698 /* Check if the attribute's form is a DW_FORM_block*
16699 if so return true else false. */
16702 attr_form_is_block (struct attribute
*attr
)
16704 return (attr
== NULL
? 0 :
16705 attr
->form
== DW_FORM_block1
16706 || attr
->form
== DW_FORM_block2
16707 || attr
->form
== DW_FORM_block4
16708 || attr
->form
== DW_FORM_block
16709 || attr
->form
== DW_FORM_exprloc
);
16712 /* Return non-zero if ATTR's value is a section offset --- classes
16713 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16714 You may use DW_UNSND (attr) to retrieve such offsets.
16716 Section 7.5.4, "Attribute Encodings", explains that no attribute
16717 may have a value that belongs to more than one of these classes; it
16718 would be ambiguous if we did, because we use the same forms for all
16722 attr_form_is_section_offset (struct attribute
*attr
)
16724 return (attr
->form
== DW_FORM_data4
16725 || attr
->form
== DW_FORM_data8
16726 || attr
->form
== DW_FORM_sec_offset
);
16729 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16730 zero otherwise. When this function returns true, you can apply
16731 dwarf2_get_attr_constant_value to it.
16733 However, note that for some attributes you must check
16734 attr_form_is_section_offset before using this test. DW_FORM_data4
16735 and DW_FORM_data8 are members of both the constant class, and of
16736 the classes that contain offsets into other debug sections
16737 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16738 that, if an attribute's can be either a constant or one of the
16739 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16740 taken as section offsets, not constants. */
16743 attr_form_is_constant (struct attribute
*attr
)
16745 switch (attr
->form
)
16747 case DW_FORM_sdata
:
16748 case DW_FORM_udata
:
16749 case DW_FORM_data1
:
16750 case DW_FORM_data2
:
16751 case DW_FORM_data4
:
16752 case DW_FORM_data8
:
16759 /* Return the .debug_loc section to use for CU.
16760 For DWO files use .debug_loc.dwo. */
16762 static struct dwarf2_section_info
*
16763 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16766 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16767 return &dwarf2_per_objfile
->loc
;
16770 /* A helper function that fills in a dwarf2_loclist_baton. */
16773 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16774 struct dwarf2_loclist_baton
*baton
,
16775 struct attribute
*attr
)
16777 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16779 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16781 baton
->per_cu
= cu
->per_cu
;
16782 gdb_assert (baton
->per_cu
);
16783 /* We don't know how long the location list is, but make sure we
16784 don't run off the edge of the section. */
16785 baton
->size
= section
->size
- DW_UNSND (attr
);
16786 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16787 baton
->base_address
= cu
->base_address
;
16788 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16792 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16793 struct dwarf2_cu
*cu
)
16795 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16796 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16798 if (attr_form_is_section_offset (attr
)
16799 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16800 the section. If so, fall through to the complaint in the
16802 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16804 struct dwarf2_loclist_baton
*baton
;
16806 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16807 sizeof (struct dwarf2_loclist_baton
));
16809 fill_in_loclist_baton (cu
, baton
, attr
);
16811 if (cu
->base_known
== 0)
16812 complaint (&symfile_complaints
,
16813 _("Location list used without "
16814 "specifying the CU base address."));
16816 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16817 SYMBOL_LOCATION_BATON (sym
) = baton
;
16821 struct dwarf2_locexpr_baton
*baton
;
16823 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16824 sizeof (struct dwarf2_locexpr_baton
));
16825 baton
->per_cu
= cu
->per_cu
;
16826 gdb_assert (baton
->per_cu
);
16828 if (attr_form_is_block (attr
))
16830 /* Note that we're just copying the block's data pointer
16831 here, not the actual data. We're still pointing into the
16832 info_buffer for SYM's objfile; right now we never release
16833 that buffer, but when we do clean up properly this may
16835 baton
->size
= DW_BLOCK (attr
)->size
;
16836 baton
->data
= DW_BLOCK (attr
)->data
;
16840 dwarf2_invalid_attrib_class_complaint ("location description",
16841 SYMBOL_NATURAL_NAME (sym
));
16845 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16846 SYMBOL_LOCATION_BATON (sym
) = baton
;
16850 /* Return the OBJFILE associated with the compilation unit CU. If CU
16851 came from a separate debuginfo file, then the master objfile is
16855 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16857 struct objfile
*objfile
= per_cu
->objfile
;
16859 /* Return the master objfile, so that we can report and look up the
16860 correct file containing this variable. */
16861 if (objfile
->separate_debug_objfile_backlink
)
16862 objfile
= objfile
->separate_debug_objfile_backlink
;
16867 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16868 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16869 CU_HEADERP first. */
16871 static const struct comp_unit_head
*
16872 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16873 struct dwarf2_per_cu_data
*per_cu
)
16875 gdb_byte
*info_ptr
;
16878 return &per_cu
->cu
->header
;
16880 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
16882 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16883 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
16888 /* Return the address size given in the compilation unit header for CU. */
16891 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16893 struct comp_unit_head cu_header_local
;
16894 const struct comp_unit_head
*cu_headerp
;
16896 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16898 return cu_headerp
->addr_size
;
16901 /* Return the offset size given in the compilation unit header for CU. */
16904 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16906 struct comp_unit_head cu_header_local
;
16907 const struct comp_unit_head
*cu_headerp
;
16909 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16911 return cu_headerp
->offset_size
;
16914 /* See its dwarf2loc.h declaration. */
16917 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16919 struct comp_unit_head cu_header_local
;
16920 const struct comp_unit_head
*cu_headerp
;
16922 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16924 if (cu_headerp
->version
== 2)
16925 return cu_headerp
->addr_size
;
16927 return cu_headerp
->offset_size
;
16930 /* Return the text offset of the CU. The returned offset comes from
16931 this CU's objfile. If this objfile came from a separate debuginfo
16932 file, then the offset may be different from the corresponding
16933 offset in the parent objfile. */
16936 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16938 struct objfile
*objfile
= per_cu
->objfile
;
16940 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16943 /* Locate the .debug_info compilation unit from CU's objfile which contains
16944 the DIE at OFFSET. Raises an error on failure. */
16946 static struct dwarf2_per_cu_data
*
16947 dwarf2_find_containing_comp_unit (sect_offset offset
,
16948 struct objfile
*objfile
)
16950 struct dwarf2_per_cu_data
*this_cu
;
16954 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16957 int mid
= low
+ (high
- low
) / 2;
16959 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16960 >= offset
.sect_off
)
16965 gdb_assert (low
== high
);
16966 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16970 error (_("Dwarf Error: could not find partial DIE containing "
16971 "offset 0x%lx [in module %s]"),
16972 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16974 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16975 <= offset
.sect_off
);
16976 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16980 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16981 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16982 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16983 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16984 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16989 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16992 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16994 memset (cu
, 0, sizeof (*cu
));
16996 cu
->per_cu
= per_cu
;
16997 cu
->objfile
= per_cu
->objfile
;
16998 obstack_init (&cu
->comp_unit_obstack
);
17001 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17004 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17005 enum language pretend_language
)
17007 struct attribute
*attr
;
17009 /* Set the language we're debugging. */
17010 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17012 set_cu_language (DW_UNSND (attr
), cu
);
17015 cu
->language
= pretend_language
;
17016 cu
->language_defn
= language_def (cu
->language
);
17019 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17021 cu
->producer
= DW_STRING (attr
);
17024 /* Release one cached compilation unit, CU. We unlink it from the tree
17025 of compilation units, but we don't remove it from the read_in_chain;
17026 the caller is responsible for that.
17027 NOTE: DATA is a void * because this function is also used as a
17028 cleanup routine. */
17031 free_heap_comp_unit (void *data
)
17033 struct dwarf2_cu
*cu
= data
;
17035 gdb_assert (cu
->per_cu
!= NULL
);
17036 cu
->per_cu
->cu
= NULL
;
17039 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17044 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17045 when we're finished with it. We can't free the pointer itself, but be
17046 sure to unlink it from the cache. Also release any associated storage. */
17049 free_stack_comp_unit (void *data
)
17051 struct dwarf2_cu
*cu
= data
;
17053 gdb_assert (cu
->per_cu
!= NULL
);
17054 cu
->per_cu
->cu
= NULL
;
17057 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17058 cu
->partial_dies
= NULL
;
17061 /* Free all cached compilation units. */
17064 free_cached_comp_units (void *data
)
17066 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17068 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17069 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17070 while (per_cu
!= NULL
)
17072 struct dwarf2_per_cu_data
*next_cu
;
17074 next_cu
= per_cu
->cu
->read_in_chain
;
17076 free_heap_comp_unit (per_cu
->cu
);
17077 *last_chain
= next_cu
;
17083 /* Increase the age counter on each cached compilation unit, and free
17084 any that are too old. */
17087 age_cached_comp_units (void)
17089 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17091 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17092 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17093 while (per_cu
!= NULL
)
17095 per_cu
->cu
->last_used
++;
17096 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17097 dwarf2_mark (per_cu
->cu
);
17098 per_cu
= per_cu
->cu
->read_in_chain
;
17101 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17102 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17103 while (per_cu
!= NULL
)
17105 struct dwarf2_per_cu_data
*next_cu
;
17107 next_cu
= per_cu
->cu
->read_in_chain
;
17109 if (!per_cu
->cu
->mark
)
17111 free_heap_comp_unit (per_cu
->cu
);
17112 *last_chain
= next_cu
;
17115 last_chain
= &per_cu
->cu
->read_in_chain
;
17121 /* Remove a single compilation unit from the cache. */
17124 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17126 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17128 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17129 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17130 while (per_cu
!= NULL
)
17132 struct dwarf2_per_cu_data
*next_cu
;
17134 next_cu
= per_cu
->cu
->read_in_chain
;
17136 if (per_cu
== target_per_cu
)
17138 free_heap_comp_unit (per_cu
->cu
);
17140 *last_chain
= next_cu
;
17144 last_chain
= &per_cu
->cu
->read_in_chain
;
17150 /* Release all extra memory associated with OBJFILE. */
17153 dwarf2_free_objfile (struct objfile
*objfile
)
17155 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17157 if (dwarf2_per_objfile
== NULL
)
17160 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17161 free_cached_comp_units (NULL
);
17163 if (dwarf2_per_objfile
->quick_file_names_table
)
17164 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17166 /* Everything else should be on the objfile obstack. */
17169 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17170 We store these in a hash table separate from the DIEs, and preserve them
17171 when the DIEs are flushed out of cache.
17173 The CU "per_cu" pointer is needed because offset alone is not enough to
17174 uniquely identify the type. A file may have multiple .debug_types sections,
17175 or the type may come from a DWO file. We have to use something in
17176 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17177 routine, get_die_type_at_offset, from outside this file, and thus won't
17178 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17181 struct dwarf2_per_cu_offset_and_type
17183 const struct dwarf2_per_cu_data
*per_cu
;
17184 sect_offset offset
;
17188 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17191 per_cu_offset_and_type_hash (const void *item
)
17193 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17195 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17198 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17201 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17203 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17204 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17206 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17207 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17210 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17211 table if necessary. For convenience, return TYPE.
17213 The DIEs reading must have careful ordering to:
17214 * Not cause infite loops trying to read in DIEs as a prerequisite for
17215 reading current DIE.
17216 * Not trying to dereference contents of still incompletely read in types
17217 while reading in other DIEs.
17218 * Enable referencing still incompletely read in types just by a pointer to
17219 the type without accessing its fields.
17221 Therefore caller should follow these rules:
17222 * Try to fetch any prerequisite types we may need to build this DIE type
17223 before building the type and calling set_die_type.
17224 * After building type call set_die_type for current DIE as soon as
17225 possible before fetching more types to complete the current type.
17226 * Make the type as complete as possible before fetching more types. */
17228 static struct type
*
17229 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17231 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17232 struct objfile
*objfile
= cu
->objfile
;
17234 /* For Ada types, make sure that the gnat-specific data is always
17235 initialized (if not already set). There are a few types where
17236 we should not be doing so, because the type-specific area is
17237 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17238 where the type-specific area is used to store the floatformat).
17239 But this is not a problem, because the gnat-specific information
17240 is actually not needed for these types. */
17241 if (need_gnat_info (cu
)
17242 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17243 && TYPE_CODE (type
) != TYPE_CODE_FLT
17244 && !HAVE_GNAT_AUX_INFO (type
))
17245 INIT_GNAT_SPECIFIC (type
);
17247 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17249 dwarf2_per_objfile
->die_type_hash
=
17250 htab_create_alloc_ex (127,
17251 per_cu_offset_and_type_hash
,
17252 per_cu_offset_and_type_eq
,
17254 &objfile
->objfile_obstack
,
17255 hashtab_obstack_allocate
,
17256 dummy_obstack_deallocate
);
17259 ofs
.per_cu
= cu
->per_cu
;
17260 ofs
.offset
= die
->offset
;
17262 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17263 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17265 complaint (&symfile_complaints
,
17266 _("A problem internal to GDB: DIE 0x%x has type already set"),
17267 die
->offset
.sect_off
);
17268 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17273 /* Look up the type for the die at OFFSET in the appropriate type_hash
17274 table, or return NULL if the die does not have a saved type. */
17276 static struct type
*
17277 get_die_type_at_offset (sect_offset offset
,
17278 struct dwarf2_per_cu_data
*per_cu
)
17280 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17282 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17285 ofs
.per_cu
= per_cu
;
17286 ofs
.offset
= offset
;
17287 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17294 /* Look up the type for DIE in the appropriate type_hash table,
17295 or return NULL if DIE does not have a saved type. */
17297 static struct type
*
17298 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17300 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17303 /* Add a dependence relationship from CU to REF_PER_CU. */
17306 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17307 struct dwarf2_per_cu_data
*ref_per_cu
)
17311 if (cu
->dependencies
== NULL
)
17313 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17314 NULL
, &cu
->comp_unit_obstack
,
17315 hashtab_obstack_allocate
,
17316 dummy_obstack_deallocate
);
17318 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17320 *slot
= ref_per_cu
;
17323 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17324 Set the mark field in every compilation unit in the
17325 cache that we must keep because we are keeping CU. */
17328 dwarf2_mark_helper (void **slot
, void *data
)
17330 struct dwarf2_per_cu_data
*per_cu
;
17332 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17334 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17335 reading of the chain. As such dependencies remain valid it is not much
17336 useful to track and undo them during QUIT cleanups. */
17337 if (per_cu
->cu
== NULL
)
17340 if (per_cu
->cu
->mark
)
17342 per_cu
->cu
->mark
= 1;
17344 if (per_cu
->cu
->dependencies
!= NULL
)
17345 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17350 /* Set the mark field in CU and in every other compilation unit in the
17351 cache that we must keep because we are keeping CU. */
17354 dwarf2_mark (struct dwarf2_cu
*cu
)
17359 if (cu
->dependencies
!= NULL
)
17360 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17364 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17368 per_cu
->cu
->mark
= 0;
17369 per_cu
= per_cu
->cu
->read_in_chain
;
17373 /* Trivial hash function for partial_die_info: the hash value of a DIE
17374 is its offset in .debug_info for this objfile. */
17377 partial_die_hash (const void *item
)
17379 const struct partial_die_info
*part_die
= item
;
17381 return part_die
->offset
.sect_off
;
17384 /* Trivial comparison function for partial_die_info structures: two DIEs
17385 are equal if they have the same offset. */
17388 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17390 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17391 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17393 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17396 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17397 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17400 set_dwarf2_cmd (char *args
, int from_tty
)
17402 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17406 show_dwarf2_cmd (char *args
, int from_tty
)
17408 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17411 /* If section described by INFO was mmapped, munmap it now. */
17414 munmap_section_buffer (struct dwarf2_section_info
*info
)
17416 if (info
->map_addr
!= NULL
)
17421 res
= munmap (info
->map_addr
, info
->map_len
);
17422 gdb_assert (res
== 0);
17424 /* Without HAVE_MMAP, we should never be here to begin with. */
17425 gdb_assert_not_reached ("no mmap support");
17430 /* munmap debug sections for OBJFILE, if necessary. */
17433 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17435 struct dwarf2_per_objfile
*data
= d
;
17437 struct dwarf2_section_info
*section
;
17439 /* This is sorted according to the order they're defined in to make it easier
17440 to keep in sync. */
17441 munmap_section_buffer (&data
->info
);
17442 munmap_section_buffer (&data
->abbrev
);
17443 munmap_section_buffer (&data
->line
);
17444 munmap_section_buffer (&data
->loc
);
17445 munmap_section_buffer (&data
->macinfo
);
17446 munmap_section_buffer (&data
->macro
);
17447 munmap_section_buffer (&data
->str
);
17448 munmap_section_buffer (&data
->ranges
);
17449 munmap_section_buffer (&data
->addr
);
17450 munmap_section_buffer (&data
->frame
);
17451 munmap_section_buffer (&data
->eh_frame
);
17452 munmap_section_buffer (&data
->gdb_index
);
17455 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17457 munmap_section_buffer (section
);
17459 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17460 VEC_free (dwarf2_per_cu_ptr
,
17461 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17463 VEC_free (dwarf2_section_info_def
, data
->types
);
17465 if (data
->dwo_files
)
17466 free_dwo_files (data
->dwo_files
, objfile
);
17470 /* The "save gdb-index" command. */
17472 /* The contents of the hash table we create when building the string
17474 struct strtab_entry
17476 offset_type offset
;
17480 /* Hash function for a strtab_entry.
17482 Function is used only during write_hash_table so no index format backward
17483 compatibility is needed. */
17486 hash_strtab_entry (const void *e
)
17488 const struct strtab_entry
*entry
= e
;
17489 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17492 /* Equality function for a strtab_entry. */
17495 eq_strtab_entry (const void *a
, const void *b
)
17497 const struct strtab_entry
*ea
= a
;
17498 const struct strtab_entry
*eb
= b
;
17499 return !strcmp (ea
->str
, eb
->str
);
17502 /* Create a strtab_entry hash table. */
17505 create_strtab (void)
17507 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17508 xfree
, xcalloc
, xfree
);
17511 /* Add a string to the constant pool. Return the string's offset in
17515 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17518 struct strtab_entry entry
;
17519 struct strtab_entry
*result
;
17522 slot
= htab_find_slot (table
, &entry
, INSERT
);
17527 result
= XNEW (struct strtab_entry
);
17528 result
->offset
= obstack_object_size (cpool
);
17530 obstack_grow_str0 (cpool
, str
);
17533 return result
->offset
;
17536 /* An entry in the symbol table. */
17537 struct symtab_index_entry
17539 /* The name of the symbol. */
17541 /* The offset of the name in the constant pool. */
17542 offset_type index_offset
;
17543 /* A sorted vector of the indices of all the CUs that hold an object
17545 VEC (offset_type
) *cu_indices
;
17548 /* The symbol table. This is a power-of-2-sized hash table. */
17549 struct mapped_symtab
17551 offset_type n_elements
;
17553 struct symtab_index_entry
**data
;
17556 /* Hash function for a symtab_index_entry. */
17559 hash_symtab_entry (const void *e
)
17561 const struct symtab_index_entry
*entry
= e
;
17562 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17563 sizeof (offset_type
) * VEC_length (offset_type
,
17564 entry
->cu_indices
),
17568 /* Equality function for a symtab_index_entry. */
17571 eq_symtab_entry (const void *a
, const void *b
)
17573 const struct symtab_index_entry
*ea
= a
;
17574 const struct symtab_index_entry
*eb
= b
;
17575 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17576 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17578 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17579 VEC_address (offset_type
, eb
->cu_indices
),
17580 sizeof (offset_type
) * len
);
17583 /* Destroy a symtab_index_entry. */
17586 delete_symtab_entry (void *p
)
17588 struct symtab_index_entry
*entry
= p
;
17589 VEC_free (offset_type
, entry
->cu_indices
);
17593 /* Create a hash table holding symtab_index_entry objects. */
17596 create_symbol_hash_table (void)
17598 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17599 delete_symtab_entry
, xcalloc
, xfree
);
17602 /* Create a new mapped symtab object. */
17604 static struct mapped_symtab
*
17605 create_mapped_symtab (void)
17607 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17608 symtab
->n_elements
= 0;
17609 symtab
->size
= 1024;
17610 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17614 /* Destroy a mapped_symtab. */
17617 cleanup_mapped_symtab (void *p
)
17619 struct mapped_symtab
*symtab
= p
;
17620 /* The contents of the array are freed when the other hash table is
17622 xfree (symtab
->data
);
17626 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17629 Function is used only during write_hash_table so no index format backward
17630 compatibility is needed. */
17632 static struct symtab_index_entry
**
17633 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17635 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17637 index
= hash
& (symtab
->size
- 1);
17638 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17642 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17643 return &symtab
->data
[index
];
17644 index
= (index
+ step
) & (symtab
->size
- 1);
17648 /* Expand SYMTAB's hash table. */
17651 hash_expand (struct mapped_symtab
*symtab
)
17653 offset_type old_size
= symtab
->size
;
17655 struct symtab_index_entry
**old_entries
= symtab
->data
;
17658 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17660 for (i
= 0; i
< old_size
; ++i
)
17662 if (old_entries
[i
])
17664 struct symtab_index_entry
**slot
= find_slot (symtab
,
17665 old_entries
[i
]->name
);
17666 *slot
= old_entries
[i
];
17670 xfree (old_entries
);
17673 /* Add an entry to SYMTAB. NAME is the name of the symbol.
17674 CU_INDEX is the index of the CU in which the symbol appears.
17675 IS_STATIC is one if the symbol is static, otherwise zero (global). */
17678 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17679 int is_static
, gdb_index_symbol_kind kind
,
17680 offset_type cu_index
)
17682 struct symtab_index_entry
**slot
;
17683 offset_type cu_index_and_attrs
;
17685 ++symtab
->n_elements
;
17686 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17687 hash_expand (symtab
);
17689 slot
= find_slot (symtab
, name
);
17692 *slot
= XNEW (struct symtab_index_entry
);
17693 (*slot
)->name
= name
;
17694 /* index_offset is set later. */
17695 (*slot
)->cu_indices
= NULL
;
17698 cu_index_and_attrs
= 0;
17699 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
17700 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
17701 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
17703 /* We don't want to record an index value twice as we want to avoid the
17705 We process all global symbols and then all static symbols
17706 (which would allow us to avoid the duplication by only having to check
17707 the last entry pushed), but a symbol could have multiple kinds in one CU.
17708 To keep things simple we don't worry about the duplication here and
17709 sort and uniqufy the list after we've processed all symbols. */
17710 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
17713 /* qsort helper routine for uniquify_cu_indices. */
17716 offset_type_compare (const void *ap
, const void *bp
)
17718 offset_type a
= *(offset_type
*) ap
;
17719 offset_type b
= *(offset_type
*) bp
;
17721 return (a
> b
) - (b
> a
);
17724 /* Sort and remove duplicates of all symbols' cu_indices lists. */
17727 uniquify_cu_indices (struct mapped_symtab
*symtab
)
17731 for (i
= 0; i
< symtab
->size
; ++i
)
17733 struct symtab_index_entry
*entry
= symtab
->data
[i
];
17736 && entry
->cu_indices
!= NULL
)
17738 unsigned int next_to_insert
, next_to_check
;
17739 offset_type last_value
;
17741 qsort (VEC_address (offset_type
, entry
->cu_indices
),
17742 VEC_length (offset_type
, entry
->cu_indices
),
17743 sizeof (offset_type
), offset_type_compare
);
17745 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
17746 next_to_insert
= 1;
17747 for (next_to_check
= 1;
17748 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
17751 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
17754 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
17756 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
17761 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
17766 /* Add a vector of indices to the constant pool. */
17769 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17770 struct symtab_index_entry
*entry
)
17774 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17777 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17778 offset_type val
= MAYBE_SWAP (len
);
17783 entry
->index_offset
= obstack_object_size (cpool
);
17785 obstack_grow (cpool
, &val
, sizeof (val
));
17787 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17790 val
= MAYBE_SWAP (iter
);
17791 obstack_grow (cpool
, &val
, sizeof (val
));
17796 struct symtab_index_entry
*old_entry
= *slot
;
17797 entry
->index_offset
= old_entry
->index_offset
;
17800 return entry
->index_offset
;
17803 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17804 constant pool entries going into the obstack CPOOL. */
17807 write_hash_table (struct mapped_symtab
*symtab
,
17808 struct obstack
*output
, struct obstack
*cpool
)
17811 htab_t symbol_hash_table
;
17814 symbol_hash_table
= create_symbol_hash_table ();
17815 str_table
= create_strtab ();
17817 /* We add all the index vectors to the constant pool first, to
17818 ensure alignment is ok. */
17819 for (i
= 0; i
< symtab
->size
; ++i
)
17821 if (symtab
->data
[i
])
17822 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17825 /* Now write out the hash table. */
17826 for (i
= 0; i
< symtab
->size
; ++i
)
17828 offset_type str_off
, vec_off
;
17830 if (symtab
->data
[i
])
17832 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17833 vec_off
= symtab
->data
[i
]->index_offset
;
17837 /* While 0 is a valid constant pool index, it is not valid
17838 to have 0 for both offsets. */
17843 str_off
= MAYBE_SWAP (str_off
);
17844 vec_off
= MAYBE_SWAP (vec_off
);
17846 obstack_grow (output
, &str_off
, sizeof (str_off
));
17847 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17850 htab_delete (str_table
);
17851 htab_delete (symbol_hash_table
);
17854 /* Struct to map psymtab to CU index in the index file. */
17855 struct psymtab_cu_index_map
17857 struct partial_symtab
*psymtab
;
17858 unsigned int cu_index
;
17862 hash_psymtab_cu_index (const void *item
)
17864 const struct psymtab_cu_index_map
*map
= item
;
17866 return htab_hash_pointer (map
->psymtab
);
17870 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17872 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17873 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17875 return lhs
->psymtab
== rhs
->psymtab
;
17878 /* Helper struct for building the address table. */
17879 struct addrmap_index_data
17881 struct objfile
*objfile
;
17882 struct obstack
*addr_obstack
;
17883 htab_t cu_index_htab
;
17885 /* Non-zero if the previous_* fields are valid.
17886 We can't write an entry until we see the next entry (since it is only then
17887 that we know the end of the entry). */
17888 int previous_valid
;
17889 /* Index of the CU in the table of all CUs in the index file. */
17890 unsigned int previous_cu_index
;
17891 /* Start address of the CU. */
17892 CORE_ADDR previous_cu_start
;
17895 /* Write an address entry to OBSTACK. */
17898 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17899 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17901 offset_type cu_index_to_write
;
17903 CORE_ADDR baseaddr
;
17905 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17907 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17908 obstack_grow (obstack
, addr
, 8);
17909 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17910 obstack_grow (obstack
, addr
, 8);
17911 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17912 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17915 /* Worker function for traversing an addrmap to build the address table. */
17918 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17920 struct addrmap_index_data
*data
= datap
;
17921 struct partial_symtab
*pst
= obj
;
17923 if (data
->previous_valid
)
17924 add_address_entry (data
->objfile
, data
->addr_obstack
,
17925 data
->previous_cu_start
, start_addr
,
17926 data
->previous_cu_index
);
17928 data
->previous_cu_start
= start_addr
;
17931 struct psymtab_cu_index_map find_map
, *map
;
17932 find_map
.psymtab
= pst
;
17933 map
= htab_find (data
->cu_index_htab
, &find_map
);
17934 gdb_assert (map
!= NULL
);
17935 data
->previous_cu_index
= map
->cu_index
;
17936 data
->previous_valid
= 1;
17939 data
->previous_valid
= 0;
17944 /* Write OBJFILE's address map to OBSTACK.
17945 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17946 in the index file. */
17949 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17950 htab_t cu_index_htab
)
17952 struct addrmap_index_data addrmap_index_data
;
17954 /* When writing the address table, we have to cope with the fact that
17955 the addrmap iterator only provides the start of a region; we have to
17956 wait until the next invocation to get the start of the next region. */
17958 addrmap_index_data
.objfile
= objfile
;
17959 addrmap_index_data
.addr_obstack
= obstack
;
17960 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17961 addrmap_index_data
.previous_valid
= 0;
17963 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17964 &addrmap_index_data
);
17966 /* It's highly unlikely the last entry (end address = 0xff...ff)
17967 is valid, but we should still handle it.
17968 The end address is recorded as the start of the next region, but that
17969 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17971 if (addrmap_index_data
.previous_valid
)
17972 add_address_entry (objfile
, obstack
,
17973 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17974 addrmap_index_data
.previous_cu_index
);
17977 /* Return the symbol kind of PSYM. */
17979 static gdb_index_symbol_kind
17980 symbol_kind (struct partial_symbol
*psym
)
17982 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
17983 enum address_class aclass
= PSYMBOL_CLASS (psym
);
17991 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
17993 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17995 case LOC_CONST_BYTES
:
17996 case LOC_OPTIMIZED_OUT
:
17998 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18000 /* Note: It's currently impossible to recognize psyms as enum values
18001 short of reading the type info. For now punt. */
18002 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18004 /* There are other LOC_FOO values that one might want to classify
18005 as variables, but dwarf2read.c doesn't currently use them. */
18006 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18008 case STRUCT_DOMAIN
:
18009 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18011 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18015 /* Add a list of partial symbols to SYMTAB. */
18018 write_psymbols (struct mapped_symtab
*symtab
,
18020 struct partial_symbol
**psymp
,
18022 offset_type cu_index
,
18025 for (; count
-- > 0; ++psymp
)
18027 struct partial_symbol
*psym
= *psymp
;
18030 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18031 error (_("Ada is not currently supported by the index"));
18033 /* Only add a given psymbol once. */
18034 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18037 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18040 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18041 is_static
, kind
, cu_index
);
18046 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18047 exception if there is an error. */
18050 write_obstack (FILE *file
, struct obstack
*obstack
)
18052 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18054 != obstack_object_size (obstack
))
18055 error (_("couldn't data write to file"));
18058 /* Unlink a file if the argument is not NULL. */
18061 unlink_if_set (void *p
)
18063 char **filename
= p
;
18065 unlink (*filename
);
18068 /* A helper struct used when iterating over debug_types. */
18069 struct signatured_type_index_data
18071 struct objfile
*objfile
;
18072 struct mapped_symtab
*symtab
;
18073 struct obstack
*types_list
;
18078 /* A helper function that writes a single signatured_type to an
18082 write_one_signatured_type (void **slot
, void *d
)
18084 struct signatured_type_index_data
*info
= d
;
18085 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18086 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18087 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18090 write_psymbols (info
->symtab
,
18092 info
->objfile
->global_psymbols
.list
18093 + psymtab
->globals_offset
,
18094 psymtab
->n_global_syms
, info
->cu_index
,
18096 write_psymbols (info
->symtab
,
18098 info
->objfile
->static_psymbols
.list
18099 + psymtab
->statics_offset
,
18100 psymtab
->n_static_syms
, info
->cu_index
,
18103 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18104 entry
->per_cu
.offset
.sect_off
);
18105 obstack_grow (info
->types_list
, val
, 8);
18106 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18107 entry
->type_offset_in_tu
.cu_off
);
18108 obstack_grow (info
->types_list
, val
, 8);
18109 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18110 obstack_grow (info
->types_list
, val
, 8);
18117 /* Recurse into all "included" dependencies and write their symbols as
18118 if they appeared in this psymtab. */
18121 recursively_write_psymbols (struct objfile
*objfile
,
18122 struct partial_symtab
*psymtab
,
18123 struct mapped_symtab
*symtab
,
18125 offset_type cu_index
)
18129 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18130 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18131 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18132 symtab
, psyms_seen
, cu_index
);
18134 write_psymbols (symtab
,
18136 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18137 psymtab
->n_global_syms
, cu_index
,
18139 write_psymbols (symtab
,
18141 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18142 psymtab
->n_static_syms
, cu_index
,
18146 /* Create an index file for OBJFILE in the directory DIR. */
18149 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18151 struct cleanup
*cleanup
;
18152 char *filename
, *cleanup_filename
;
18153 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18154 struct obstack cu_list
, types_cu_list
;
18157 struct mapped_symtab
*symtab
;
18158 offset_type val
, size_of_contents
, total_len
;
18161 htab_t cu_index_htab
;
18162 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18164 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18167 if (dwarf2_per_objfile
->using_index
)
18168 error (_("Cannot use an index to create the index"));
18170 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18171 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18173 if (stat (objfile
->name
, &st
) < 0)
18174 perror_with_name (objfile
->name
);
18176 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18177 INDEX_SUFFIX
, (char *) NULL
);
18178 cleanup
= make_cleanup (xfree
, filename
);
18180 out_file
= fopen (filename
, "wb");
18182 error (_("Can't open `%s' for writing"), filename
);
18184 cleanup_filename
= filename
;
18185 make_cleanup (unlink_if_set
, &cleanup_filename
);
18187 symtab
= create_mapped_symtab ();
18188 make_cleanup (cleanup_mapped_symtab
, symtab
);
18190 obstack_init (&addr_obstack
);
18191 make_cleanup_obstack_free (&addr_obstack
);
18193 obstack_init (&cu_list
);
18194 make_cleanup_obstack_free (&cu_list
);
18196 obstack_init (&types_cu_list
);
18197 make_cleanup_obstack_free (&types_cu_list
);
18199 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18200 NULL
, xcalloc
, xfree
);
18201 make_cleanup_htab_delete (psyms_seen
);
18203 /* While we're scanning CU's create a table that maps a psymtab pointer
18204 (which is what addrmap records) to its index (which is what is recorded
18205 in the index file). This will later be needed to write the address
18207 cu_index_htab
= htab_create_alloc (100,
18208 hash_psymtab_cu_index
,
18209 eq_psymtab_cu_index
,
18210 NULL
, xcalloc
, xfree
);
18211 make_cleanup_htab_delete (cu_index_htab
);
18212 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18213 xmalloc (sizeof (struct psymtab_cu_index_map
)
18214 * dwarf2_per_objfile
->n_comp_units
);
18215 make_cleanup (xfree
, psymtab_cu_index_map
);
18217 /* The CU list is already sorted, so we don't need to do additional
18218 work here. Also, the debug_types entries do not appear in
18219 all_comp_units, but only in their own hash table. */
18220 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18222 struct dwarf2_per_cu_data
*per_cu
18223 = dwarf2_per_objfile
->all_comp_units
[i
];
18224 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18226 struct psymtab_cu_index_map
*map
;
18229 if (psymtab
->user
== NULL
)
18230 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18232 map
= &psymtab_cu_index_map
[i
];
18233 map
->psymtab
= psymtab
;
18235 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18236 gdb_assert (slot
!= NULL
);
18237 gdb_assert (*slot
== NULL
);
18240 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18241 per_cu
->offset
.sect_off
);
18242 obstack_grow (&cu_list
, val
, 8);
18243 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18244 obstack_grow (&cu_list
, val
, 8);
18247 /* Dump the address map. */
18248 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18250 /* Write out the .debug_type entries, if any. */
18251 if (dwarf2_per_objfile
->signatured_types
)
18253 struct signatured_type_index_data sig_data
;
18255 sig_data
.objfile
= objfile
;
18256 sig_data
.symtab
= symtab
;
18257 sig_data
.types_list
= &types_cu_list
;
18258 sig_data
.psyms_seen
= psyms_seen
;
18259 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18260 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18261 write_one_signatured_type
, &sig_data
);
18264 /* Now that we've processed all symbols we can shrink their cu_indices
18266 uniquify_cu_indices (symtab
);
18268 obstack_init (&constant_pool
);
18269 make_cleanup_obstack_free (&constant_pool
);
18270 obstack_init (&symtab_obstack
);
18271 make_cleanup_obstack_free (&symtab_obstack
);
18272 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18274 obstack_init (&contents
);
18275 make_cleanup_obstack_free (&contents
);
18276 size_of_contents
= 6 * sizeof (offset_type
);
18277 total_len
= size_of_contents
;
18279 /* The version number. */
18280 val
= MAYBE_SWAP (7);
18281 obstack_grow (&contents
, &val
, sizeof (val
));
18283 /* The offset of the CU list from the start of the file. */
18284 val
= MAYBE_SWAP (total_len
);
18285 obstack_grow (&contents
, &val
, sizeof (val
));
18286 total_len
+= obstack_object_size (&cu_list
);
18288 /* The offset of the types CU list from the start of the file. */
18289 val
= MAYBE_SWAP (total_len
);
18290 obstack_grow (&contents
, &val
, sizeof (val
));
18291 total_len
+= obstack_object_size (&types_cu_list
);
18293 /* The offset of the address table from the start of the file. */
18294 val
= MAYBE_SWAP (total_len
);
18295 obstack_grow (&contents
, &val
, sizeof (val
));
18296 total_len
+= obstack_object_size (&addr_obstack
);
18298 /* The offset of the symbol table from the start of the file. */
18299 val
= MAYBE_SWAP (total_len
);
18300 obstack_grow (&contents
, &val
, sizeof (val
));
18301 total_len
+= obstack_object_size (&symtab_obstack
);
18303 /* The offset of the constant pool from the start of the file. */
18304 val
= MAYBE_SWAP (total_len
);
18305 obstack_grow (&contents
, &val
, sizeof (val
));
18306 total_len
+= obstack_object_size (&constant_pool
);
18308 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18310 write_obstack (out_file
, &contents
);
18311 write_obstack (out_file
, &cu_list
);
18312 write_obstack (out_file
, &types_cu_list
);
18313 write_obstack (out_file
, &addr_obstack
);
18314 write_obstack (out_file
, &symtab_obstack
);
18315 write_obstack (out_file
, &constant_pool
);
18319 /* We want to keep the file, so we set cleanup_filename to NULL
18320 here. See unlink_if_set. */
18321 cleanup_filename
= NULL
;
18323 do_cleanups (cleanup
);
18326 /* Implementation of the `save gdb-index' command.
18328 Note that the file format used by this command is documented in the
18329 GDB manual. Any changes here must be documented there. */
18332 save_gdb_index_command (char *arg
, int from_tty
)
18334 struct objfile
*objfile
;
18337 error (_("usage: save gdb-index DIRECTORY"));
18339 ALL_OBJFILES (objfile
)
18343 /* If the objfile does not correspond to an actual file, skip it. */
18344 if (stat (objfile
->name
, &st
) < 0)
18347 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18348 if (dwarf2_per_objfile
)
18350 volatile struct gdb_exception except
;
18352 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18354 write_psymtabs_to_index (objfile
, arg
);
18356 if (except
.reason
< 0)
18357 exception_fprintf (gdb_stderr
, except
,
18358 _("Error while writing index for `%s': "),
18366 int dwarf2_always_disassemble
;
18369 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18370 struct cmd_list_element
*c
, const char *value
)
18372 fprintf_filtered (file
,
18373 _("Whether to always disassemble "
18374 "DWARF expressions is %s.\n"),
18379 show_check_physname (struct ui_file
*file
, int from_tty
,
18380 struct cmd_list_element
*c
, const char *value
)
18382 fprintf_filtered (file
,
18383 _("Whether to check \"physname\" is %s.\n"),
18387 void _initialize_dwarf2_read (void);
18390 _initialize_dwarf2_read (void)
18392 struct cmd_list_element
*c
;
18394 dwarf2_objfile_data_key
18395 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18397 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18398 Set DWARF 2 specific variables.\n\
18399 Configure DWARF 2 variables such as the cache size"),
18400 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18401 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18403 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18404 Show DWARF 2 specific variables\n\
18405 Show DWARF 2 variables such as the cache size"),
18406 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18407 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18409 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18410 &dwarf2_max_cache_age
, _("\
18411 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18412 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18413 A higher limit means that cached compilation units will be stored\n\
18414 in memory longer, and more total memory will be used. Zero disables\n\
18415 caching, which can slow down startup."),
18417 show_dwarf2_max_cache_age
,
18418 &set_dwarf2_cmdlist
,
18419 &show_dwarf2_cmdlist
);
18421 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18422 &dwarf2_always_disassemble
, _("\
18423 Set whether `info address' always disassembles DWARF expressions."), _("\
18424 Show whether `info address' always disassembles DWARF expressions."), _("\
18425 When enabled, DWARF expressions are always printed in an assembly-like\n\
18426 syntax. When disabled, expressions will be printed in a more\n\
18427 conversational style, when possible."),
18429 show_dwarf2_always_disassemble
,
18430 &set_dwarf2_cmdlist
,
18431 &show_dwarf2_cmdlist
);
18433 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
18434 Set debugging of the dwarf2 reader."), _("\
18435 Show debugging of the dwarf2 reader."), _("\
18436 When enabled, debugging messages are printed during dwarf2 reading\n\
18437 and symtab expansion."),
18440 &setdebuglist
, &showdebuglist
);
18442 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18443 Set debugging of the dwarf2 DIE reader."), _("\
18444 Show debugging of the dwarf2 DIE reader."), _("\
18445 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18446 The value is the maximum depth to print."),
18449 &setdebuglist
, &showdebuglist
);
18451 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18452 Set cross-checking of \"physname\" code against demangler."), _("\
18453 Show cross-checking of \"physname\" code against demangler."), _("\
18454 When enabled, GDB's internal \"physname\" code is checked against\n\
18456 NULL
, show_check_physname
,
18457 &setdebuglist
, &showdebuglist
);
18459 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18461 Save a gdb-index file.\n\
18462 Usage: save gdb-index DIRECTORY"),
18464 set_cmd_completer (c
, filename_completer
);