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 /* Read in the comp unit header information from the debug_info at info_ptr.
3375 NOTE: This leaves members offset, first_die_offset to be filled in
3379 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3380 gdb_byte
*info_ptr
, bfd
*abfd
)
3383 unsigned int bytes_read
;
3385 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3386 cu_header
->initial_length_size
= bytes_read
;
3387 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3388 info_ptr
+= bytes_read
;
3389 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3391 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3393 info_ptr
+= bytes_read
;
3394 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3396 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3397 if (signed_addr
< 0)
3398 internal_error (__FILE__
, __LINE__
,
3399 _("read_comp_unit_head: dwarf from non elf file"));
3400 cu_header
->signed_addr_p
= signed_addr
;
3405 /* Subroutine of read_and_check_comp_unit_head and
3406 read_and_check_type_unit_head to simplify them.
3407 Perform various error checking on the header. */
3410 error_check_comp_unit_head (struct comp_unit_head
*header
,
3411 struct dwarf2_section_info
*section
,
3412 struct dwarf2_section_info
*abbrev_section
)
3414 bfd
*abfd
= section
->asection
->owner
;
3415 const char *filename
= bfd_get_filename (abfd
);
3417 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3418 error (_("Dwarf Error: wrong version in compilation unit header "
3419 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3422 if (header
->abbrev_offset
.sect_off
3423 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3424 &dwarf2_per_objfile
->abbrev
))
3425 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3426 "(offset 0x%lx + 6) [in module %s]"),
3427 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3430 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3431 avoid potential 32-bit overflow. */
3432 if (((unsigned long) header
->offset
.sect_off
3433 + header
->length
+ header
->initial_length_size
)
3435 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3436 "(offset 0x%lx + 0) [in module %s]"),
3437 (long) header
->length
, (long) header
->offset
.sect_off
,
3441 /* Read in a CU/TU header and perform some basic error checking.
3442 The contents of the header are stored in HEADER.
3443 The result is a pointer to the start of the first DIE. */
3446 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3447 struct dwarf2_section_info
*section
,
3448 struct dwarf2_section_info
*abbrev_section
,
3450 int is_debug_types_section
)
3452 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3453 bfd
*abfd
= section
->asection
->owner
;
3455 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3457 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3459 /* If we're reading a type unit, skip over the signature and
3460 type_offset fields. */
3461 if (is_debug_types_section
)
3462 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3464 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3466 error_check_comp_unit_head (header
, section
, abbrev_section
);
3471 /* Read in the types comp unit header information from .debug_types entry at
3472 types_ptr. The result is a pointer to one past the end of the header. */
3475 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3476 struct dwarf2_section_info
*section
,
3477 struct dwarf2_section_info
*abbrev_section
,
3479 ULONGEST
*signature
,
3480 cu_offset
*type_offset_in_tu
)
3482 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3483 bfd
*abfd
= section
->asection
->owner
;
3485 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3487 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3489 /* If we're reading a type unit, skip over the signature and
3490 type_offset fields. */
3491 if (signature
!= NULL
)
3492 *signature
= read_8_bytes (abfd
, info_ptr
);
3494 if (type_offset_in_tu
!= NULL
)
3495 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3496 header
->offset_size
);
3497 info_ptr
+= header
->offset_size
;
3499 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3501 error_check_comp_unit_head (header
, section
, abbrev_section
);
3506 /* Allocate a new partial symtab for file named NAME and mark this new
3507 partial symtab as being an include of PST. */
3510 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3511 struct objfile
*objfile
)
3513 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3515 subpst
->section_offsets
= pst
->section_offsets
;
3516 subpst
->textlow
= 0;
3517 subpst
->texthigh
= 0;
3519 subpst
->dependencies
= (struct partial_symtab
**)
3520 obstack_alloc (&objfile
->objfile_obstack
,
3521 sizeof (struct partial_symtab
*));
3522 subpst
->dependencies
[0] = pst
;
3523 subpst
->number_of_dependencies
= 1;
3525 subpst
->globals_offset
= 0;
3526 subpst
->n_global_syms
= 0;
3527 subpst
->statics_offset
= 0;
3528 subpst
->n_static_syms
= 0;
3529 subpst
->symtab
= NULL
;
3530 subpst
->read_symtab
= pst
->read_symtab
;
3533 /* No private part is necessary for include psymtabs. This property
3534 can be used to differentiate between such include psymtabs and
3535 the regular ones. */
3536 subpst
->read_symtab_private
= NULL
;
3539 /* Read the Line Number Program data and extract the list of files
3540 included by the source file represented by PST. Build an include
3541 partial symtab for each of these included files. */
3544 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3545 struct die_info
*die
,
3546 struct partial_symtab
*pst
)
3548 struct line_header
*lh
= NULL
;
3549 struct attribute
*attr
;
3551 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3553 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3555 return; /* No linetable, so no includes. */
3557 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3558 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3560 free_line_header (lh
);
3564 hash_signatured_type (const void *item
)
3566 const struct signatured_type
*sig_type
= item
;
3568 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3569 return sig_type
->signature
;
3573 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3575 const struct signatured_type
*lhs
= item_lhs
;
3576 const struct signatured_type
*rhs
= item_rhs
;
3578 return lhs
->signature
== rhs
->signature
;
3581 /* Allocate a hash table for signatured types. */
3584 allocate_signatured_type_table (struct objfile
*objfile
)
3586 return htab_create_alloc_ex (41,
3587 hash_signatured_type
,
3590 &objfile
->objfile_obstack
,
3591 hashtab_obstack_allocate
,
3592 dummy_obstack_deallocate
);
3595 /* A helper function to add a signatured type CU to a table. */
3598 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3600 struct signatured_type
*sigt
= *slot
;
3601 struct dwarf2_per_cu_data
***datap
= datum
;
3603 **datap
= &sigt
->per_cu
;
3609 /* Create the hash table of all entries in the .debug_types section.
3610 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3611 The result is a pointer to the hash table or NULL if there are
3615 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3616 VEC (dwarf2_section_info_def
) *types
)
3618 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3619 htab_t types_htab
= NULL
;
3621 struct dwarf2_section_info
*section
;
3622 struct dwarf2_section_info
*abbrev_section
;
3624 if (VEC_empty (dwarf2_section_info_def
, types
))
3627 abbrev_section
= (dwo_file
!= NULL
3628 ? &dwo_file
->sections
.abbrev
3629 : &dwarf2_per_objfile
->abbrev
);
3632 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3636 gdb_byte
*info_ptr
, *end_ptr
;
3638 dwarf2_read_section (objfile
, section
);
3639 info_ptr
= section
->buffer
;
3641 if (info_ptr
== NULL
)
3644 /* We can't set abfd until now because the section may be empty or
3645 not present, in which case section->asection will be NULL. */
3646 abfd
= section
->asection
->owner
;
3648 if (types_htab
== NULL
)
3651 types_htab
= allocate_dwo_unit_table (objfile
);
3653 types_htab
= allocate_signatured_type_table (objfile
);
3656 if (dwarf2_die_debug
)
3657 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3658 bfd_get_filename (abfd
));
3660 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3661 because we don't need to read any dies: the signature is in the
3664 end_ptr
= info_ptr
+ section
->size
;
3665 while (info_ptr
< end_ptr
)
3668 cu_offset type_offset_in_tu
;
3670 struct signatured_type
*sig_type
;
3671 struct dwo_unit
*dwo_tu
;
3673 gdb_byte
*ptr
= info_ptr
;
3674 struct comp_unit_head header
;
3675 unsigned int length
;
3677 offset
.sect_off
= ptr
- section
->buffer
;
3679 /* We need to read the type's signature in order to build the hash
3680 table, but we don't need anything else just yet. */
3682 ptr
= read_and_check_type_unit_head (&header
, section
,
3683 abbrev_section
, ptr
,
3684 &signature
, &type_offset_in_tu
);
3686 length
= header
.initial_length_size
+ header
.length
;
3688 /* Skip dummy type units. */
3689 if (ptr
>= info_ptr
+ length
3690 || peek_abbrev_code (abfd
, ptr
) == 0)
3692 info_ptr
+= header
.initial_length_size
+ header
.length
;
3699 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3701 dwo_tu
->dwo_file
= dwo_file
;
3702 dwo_tu
->signature
= signature
;
3703 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3704 dwo_tu
->info_or_types_section
= section
;
3705 dwo_tu
->offset
= offset
;
3706 dwo_tu
->length
= length
;
3710 /* N.B.: type_offset is not usable if this type uses a DWO file.
3711 The real type_offset is in the DWO file. */
3713 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3714 struct signatured_type
);
3715 sig_type
->signature
= signature
;
3716 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3717 sig_type
->per_cu
.objfile
= objfile
;
3718 sig_type
->per_cu
.is_debug_types
= 1;
3719 sig_type
->per_cu
.info_or_types_section
= section
;
3720 sig_type
->per_cu
.offset
= offset
;
3721 sig_type
->per_cu
.length
= length
;
3724 slot
= htab_find_slot (types_htab
,
3725 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3727 gdb_assert (slot
!= NULL
);
3730 sect_offset dup_offset
;
3734 const struct dwo_unit
*dup_tu
= *slot
;
3736 dup_offset
= dup_tu
->offset
;
3740 const struct signatured_type
*dup_tu
= *slot
;
3742 dup_offset
= dup_tu
->per_cu
.offset
;
3745 complaint (&symfile_complaints
,
3746 _("debug type entry at offset 0x%x is duplicate to the "
3747 "entry at offset 0x%x, signature 0x%s"),
3748 offset
.sect_off
, dup_offset
.sect_off
,
3749 phex (signature
, sizeof (signature
)));
3751 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3753 if (dwarf2_die_debug
)
3754 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3756 phex (signature
, sizeof (signature
)));
3765 /* Create the hash table of all entries in the .debug_types section,
3766 and initialize all_type_units.
3767 The result is zero if there is an error (e.g. missing .debug_types section),
3768 otherwise non-zero. */
3771 create_all_type_units (struct objfile
*objfile
)
3774 struct dwarf2_per_cu_data
**iter
;
3776 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3777 if (types_htab
== NULL
)
3779 dwarf2_per_objfile
->signatured_types
= NULL
;
3783 dwarf2_per_objfile
->signatured_types
= types_htab
;
3785 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3786 dwarf2_per_objfile
->all_type_units
3787 = obstack_alloc (&objfile
->objfile_obstack
,
3788 dwarf2_per_objfile
->n_type_units
3789 * sizeof (struct dwarf2_per_cu_data
*));
3790 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3791 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3792 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3793 == dwarf2_per_objfile
->n_type_units
);
3798 /* Lookup a signature based type for DW_FORM_ref_sig8.
3799 Returns NULL if signature SIG is not present in the table. */
3801 static struct signatured_type
*
3802 lookup_signatured_type (ULONGEST sig
)
3804 struct signatured_type find_entry
, *entry
;
3806 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3808 complaint (&symfile_complaints
,
3809 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3813 find_entry
.signature
= sig
;
3814 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3818 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3821 init_cu_die_reader (struct die_reader_specs
*reader
,
3822 struct dwarf2_cu
*cu
,
3823 struct dwarf2_section_info
*section
,
3824 struct dwo_file
*dwo_file
)
3826 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3827 reader
->abfd
= section
->asection
->owner
;
3829 reader
->dwo_file
= dwo_file
;
3830 reader
->die_section
= section
;
3831 reader
->buffer
= section
->buffer
;
3832 reader
->buffer_end
= section
->buffer
+ section
->size
;
3835 /* Find the base address of the compilation unit for range lists and
3836 location lists. It will normally be specified by DW_AT_low_pc.
3837 In DWARF-3 draft 4, the base address could be overridden by
3838 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3839 compilation units with discontinuous ranges. */
3842 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3844 struct attribute
*attr
;
3847 cu
->base_address
= 0;
3849 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3852 cu
->base_address
= DW_ADDR (attr
);
3857 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3860 cu
->base_address
= DW_ADDR (attr
);
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
)
11148 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
11151 /* Release the memory used by the abbrev table for a compilation unit. */
11154 dwarf2_free_abbrev_table (void *ptr_to_cu
)
11156 struct dwarf2_cu
*cu
= ptr_to_cu
;
11158 abbrev_table_free (cu
->abbrev_table
);
11159 /* Set this to NULL so that we SEGV if we try to read it later,
11160 and also because free_comp_unit verifies this is NULL. */
11161 cu
->abbrev_table
= NULL
;
11164 /* Returns nonzero if TAG represents a type that we might generate a partial
11168 is_type_tag_for_partial (int tag
)
11173 /* Some types that would be reasonable to generate partial symbols for,
11174 that we don't at present. */
11175 case DW_TAG_array_type
:
11176 case DW_TAG_file_type
:
11177 case DW_TAG_ptr_to_member_type
:
11178 case DW_TAG_set_type
:
11179 case DW_TAG_string_type
:
11180 case DW_TAG_subroutine_type
:
11182 case DW_TAG_base_type
:
11183 case DW_TAG_class_type
:
11184 case DW_TAG_interface_type
:
11185 case DW_TAG_enumeration_type
:
11186 case DW_TAG_structure_type
:
11187 case DW_TAG_subrange_type
:
11188 case DW_TAG_typedef
:
11189 case DW_TAG_union_type
:
11196 /* Load all DIEs that are interesting for partial symbols into memory. */
11198 static struct partial_die_info
*
11199 load_partial_dies (const struct die_reader_specs
*reader
,
11200 gdb_byte
*info_ptr
, int building_psymtab
)
11202 struct dwarf2_cu
*cu
= reader
->cu
;
11203 struct objfile
*objfile
= cu
->objfile
;
11204 struct partial_die_info
*part_die
;
11205 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
11206 struct abbrev_info
*abbrev
;
11207 unsigned int bytes_read
;
11208 unsigned int load_all
= 0;
11209 int nesting_level
= 1;
11214 gdb_assert (cu
->per_cu
!= NULL
);
11215 if (cu
->per_cu
->load_all_dies
)
11219 = htab_create_alloc_ex (cu
->header
.length
/ 12,
11223 &cu
->comp_unit_obstack
,
11224 hashtab_obstack_allocate
,
11225 dummy_obstack_deallocate
);
11227 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11228 sizeof (struct partial_die_info
));
11232 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
11234 /* A NULL abbrev means the end of a series of children. */
11235 if (abbrev
== NULL
)
11237 if (--nesting_level
== 0)
11239 /* PART_DIE was probably the last thing allocated on the
11240 comp_unit_obstack, so we could call obstack_free
11241 here. We don't do that because the waste is small,
11242 and will be cleaned up when we're done with this
11243 compilation unit. This way, we're also more robust
11244 against other users of the comp_unit_obstack. */
11247 info_ptr
+= bytes_read
;
11248 last_die
= parent_die
;
11249 parent_die
= parent_die
->die_parent
;
11253 /* Check for template arguments. We never save these; if
11254 they're seen, we just mark the parent, and go on our way. */
11255 if (parent_die
!= NULL
11256 && cu
->language
== language_cplus
11257 && (abbrev
->tag
== DW_TAG_template_type_param
11258 || abbrev
->tag
== DW_TAG_template_value_param
))
11260 parent_die
->has_template_arguments
= 1;
11264 /* We don't need a partial DIE for the template argument. */
11265 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11270 /* We only recurse into c++ subprograms looking for template arguments.
11271 Skip their other children. */
11273 && cu
->language
== language_cplus
11274 && parent_die
!= NULL
11275 && parent_die
->tag
== DW_TAG_subprogram
)
11277 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11281 /* Check whether this DIE is interesting enough to save. Normally
11282 we would not be interested in members here, but there may be
11283 later variables referencing them via DW_AT_specification (for
11284 static members). */
11286 && !is_type_tag_for_partial (abbrev
->tag
)
11287 && abbrev
->tag
!= DW_TAG_constant
11288 && abbrev
->tag
!= DW_TAG_enumerator
11289 && abbrev
->tag
!= DW_TAG_subprogram
11290 && abbrev
->tag
!= DW_TAG_lexical_block
11291 && abbrev
->tag
!= DW_TAG_variable
11292 && abbrev
->tag
!= DW_TAG_namespace
11293 && abbrev
->tag
!= DW_TAG_module
11294 && abbrev
->tag
!= DW_TAG_member
11295 && abbrev
->tag
!= DW_TAG_imported_unit
)
11297 /* Otherwise we skip to the next sibling, if any. */
11298 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11302 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
11305 /* This two-pass algorithm for processing partial symbols has a
11306 high cost in cache pressure. Thus, handle some simple cases
11307 here which cover the majority of C partial symbols. DIEs
11308 which neither have specification tags in them, nor could have
11309 specification tags elsewhere pointing at them, can simply be
11310 processed and discarded.
11312 This segment is also optional; scan_partial_symbols and
11313 add_partial_symbol will handle these DIEs if we chain
11314 them in normally. When compilers which do not emit large
11315 quantities of duplicate debug information are more common,
11316 this code can probably be removed. */
11318 /* Any complete simple types at the top level (pretty much all
11319 of them, for a language without namespaces), can be processed
11321 if (parent_die
== NULL
11322 && part_die
->has_specification
== 0
11323 && part_die
->is_declaration
== 0
11324 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11325 || part_die
->tag
== DW_TAG_base_type
11326 || part_die
->tag
== DW_TAG_subrange_type
))
11328 if (building_psymtab
&& part_die
->name
!= NULL
)
11329 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11330 VAR_DOMAIN
, LOC_TYPEDEF
,
11331 &objfile
->static_psymbols
,
11332 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11333 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11337 /* The exception for DW_TAG_typedef with has_children above is
11338 a workaround of GCC PR debug/47510. In the case of this complaint
11339 type_name_no_tag_or_error will error on such types later.
11341 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11342 it could not find the child DIEs referenced later, this is checked
11343 above. In correct DWARF DW_TAG_typedef should have no children. */
11345 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11346 complaint (&symfile_complaints
,
11347 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11348 "- DIE at 0x%x [in module %s]"),
11349 part_die
->offset
.sect_off
, objfile
->name
);
11351 /* If we're at the second level, and we're an enumerator, and
11352 our parent has no specification (meaning possibly lives in a
11353 namespace elsewhere), then we can add the partial symbol now
11354 instead of queueing it. */
11355 if (part_die
->tag
== DW_TAG_enumerator
11356 && parent_die
!= NULL
11357 && parent_die
->die_parent
== NULL
11358 && parent_die
->tag
== DW_TAG_enumeration_type
11359 && parent_die
->has_specification
== 0)
11361 if (part_die
->name
== NULL
)
11362 complaint (&symfile_complaints
,
11363 _("malformed enumerator DIE ignored"));
11364 else if (building_psymtab
)
11365 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11366 VAR_DOMAIN
, LOC_CONST
,
11367 (cu
->language
== language_cplus
11368 || cu
->language
== language_java
)
11369 ? &objfile
->global_psymbols
11370 : &objfile
->static_psymbols
,
11371 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11373 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11377 /* We'll save this DIE so link it in. */
11378 part_die
->die_parent
= parent_die
;
11379 part_die
->die_sibling
= NULL
;
11380 part_die
->die_child
= NULL
;
11382 if (last_die
&& last_die
== parent_die
)
11383 last_die
->die_child
= part_die
;
11385 last_die
->die_sibling
= part_die
;
11387 last_die
= part_die
;
11389 if (first_die
== NULL
)
11390 first_die
= part_die
;
11392 /* Maybe add the DIE to the hash table. Not all DIEs that we
11393 find interesting need to be in the hash table, because we
11394 also have the parent/sibling/child chains; only those that we
11395 might refer to by offset later during partial symbol reading.
11397 For now this means things that might have be the target of a
11398 DW_AT_specification, DW_AT_abstract_origin, or
11399 DW_AT_extension. DW_AT_extension will refer only to
11400 namespaces; DW_AT_abstract_origin refers to functions (and
11401 many things under the function DIE, but we do not recurse
11402 into function DIEs during partial symbol reading) and
11403 possibly variables as well; DW_AT_specification refers to
11404 declarations. Declarations ought to have the DW_AT_declaration
11405 flag. It happens that GCC forgets to put it in sometimes, but
11406 only for functions, not for types.
11408 Adding more things than necessary to the hash table is harmless
11409 except for the performance cost. Adding too few will result in
11410 wasted time in find_partial_die, when we reread the compilation
11411 unit with load_all_dies set. */
11414 || abbrev
->tag
== DW_TAG_constant
11415 || abbrev
->tag
== DW_TAG_subprogram
11416 || abbrev
->tag
== DW_TAG_variable
11417 || abbrev
->tag
== DW_TAG_namespace
11418 || part_die
->is_declaration
)
11422 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11423 part_die
->offset
.sect_off
, INSERT
);
11427 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11428 sizeof (struct partial_die_info
));
11430 /* For some DIEs we want to follow their children (if any). For C
11431 we have no reason to follow the children of structures; for other
11432 languages we have to, so that we can get at method physnames
11433 to infer fully qualified class names, for DW_AT_specification,
11434 and for C++ template arguments. For C++, we also look one level
11435 inside functions to find template arguments (if the name of the
11436 function does not already contain the template arguments).
11438 For Ada, we need to scan the children of subprograms and lexical
11439 blocks as well because Ada allows the definition of nested
11440 entities that could be interesting for the debugger, such as
11441 nested subprograms for instance. */
11442 if (last_die
->has_children
11444 || last_die
->tag
== DW_TAG_namespace
11445 || last_die
->tag
== DW_TAG_module
11446 || last_die
->tag
== DW_TAG_enumeration_type
11447 || (cu
->language
== language_cplus
11448 && last_die
->tag
== DW_TAG_subprogram
11449 && (last_die
->name
== NULL
11450 || strchr (last_die
->name
, '<') == NULL
))
11451 || (cu
->language
!= language_c
11452 && (last_die
->tag
== DW_TAG_class_type
11453 || last_die
->tag
== DW_TAG_interface_type
11454 || last_die
->tag
== DW_TAG_structure_type
11455 || last_die
->tag
== DW_TAG_union_type
))
11456 || (cu
->language
== language_ada
11457 && (last_die
->tag
== DW_TAG_subprogram
11458 || last_die
->tag
== DW_TAG_lexical_block
))))
11461 parent_die
= last_die
;
11465 /* Otherwise we skip to the next sibling, if any. */
11466 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11468 /* Back to the top, do it again. */
11472 /* Read a minimal amount of information into the minimal die structure. */
11475 read_partial_die (const struct die_reader_specs
*reader
,
11476 struct partial_die_info
*part_die
,
11477 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11478 gdb_byte
*info_ptr
)
11480 struct dwarf2_cu
*cu
= reader
->cu
;
11481 struct objfile
*objfile
= cu
->objfile
;
11482 gdb_byte
*buffer
= reader
->buffer
;
11484 struct attribute attr
;
11485 int has_low_pc_attr
= 0;
11486 int has_high_pc_attr
= 0;
11487 int high_pc_relative
= 0;
11489 memset (part_die
, 0, sizeof (struct partial_die_info
));
11491 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11493 info_ptr
+= abbrev_len
;
11495 if (abbrev
== NULL
)
11498 part_die
->tag
= abbrev
->tag
;
11499 part_die
->has_children
= abbrev
->has_children
;
11501 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11503 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11505 /* Store the data if it is of an attribute we want to keep in a
11506 partial symbol table. */
11510 switch (part_die
->tag
)
11512 case DW_TAG_compile_unit
:
11513 case DW_TAG_partial_unit
:
11514 case DW_TAG_type_unit
:
11515 /* Compilation units have a DW_AT_name that is a filename, not
11516 a source language identifier. */
11517 case DW_TAG_enumeration_type
:
11518 case DW_TAG_enumerator
:
11519 /* These tags always have simple identifiers already; no need
11520 to canonicalize them. */
11521 part_die
->name
= DW_STRING (&attr
);
11525 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11526 &objfile
->objfile_obstack
);
11530 case DW_AT_linkage_name
:
11531 case DW_AT_MIPS_linkage_name
:
11532 /* Note that both forms of linkage name might appear. We
11533 assume they will be the same, and we only store the last
11535 if (cu
->language
== language_ada
)
11536 part_die
->name
= DW_STRING (&attr
);
11537 part_die
->linkage_name
= DW_STRING (&attr
);
11540 has_low_pc_attr
= 1;
11541 part_die
->lowpc
= DW_ADDR (&attr
);
11543 case DW_AT_high_pc
:
11544 has_high_pc_attr
= 1;
11545 if (attr
.form
== DW_FORM_addr
11546 || attr
.form
== DW_FORM_GNU_addr_index
)
11547 part_die
->highpc
= DW_ADDR (&attr
);
11550 high_pc_relative
= 1;
11551 part_die
->highpc
= DW_UNSND (&attr
);
11554 case DW_AT_location
:
11555 /* Support the .debug_loc offsets. */
11556 if (attr_form_is_block (&attr
))
11558 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11560 else if (attr_form_is_section_offset (&attr
))
11562 dwarf2_complex_location_expr_complaint ();
11566 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11567 "partial symbol information");
11570 case DW_AT_external
:
11571 part_die
->is_external
= DW_UNSND (&attr
);
11573 case DW_AT_declaration
:
11574 part_die
->is_declaration
= DW_UNSND (&attr
);
11577 part_die
->has_type
= 1;
11579 case DW_AT_abstract_origin
:
11580 case DW_AT_specification
:
11581 case DW_AT_extension
:
11582 part_die
->has_specification
= 1;
11583 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11585 case DW_AT_sibling
:
11586 /* Ignore absolute siblings, they might point outside of
11587 the current compile unit. */
11588 if (attr
.form
== DW_FORM_ref_addr
)
11589 complaint (&symfile_complaints
,
11590 _("ignoring absolute DW_AT_sibling"));
11592 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11594 case DW_AT_byte_size
:
11595 part_die
->has_byte_size
= 1;
11597 case DW_AT_calling_convention
:
11598 /* DWARF doesn't provide a way to identify a program's source-level
11599 entry point. DW_AT_calling_convention attributes are only meant
11600 to describe functions' calling conventions.
11602 However, because it's a necessary piece of information in
11603 Fortran, and because DW_CC_program is the only piece of debugging
11604 information whose definition refers to a 'main program' at all,
11605 several compilers have begun marking Fortran main programs with
11606 DW_CC_program --- even when those functions use the standard
11607 calling conventions.
11609 So until DWARF specifies a way to provide this information and
11610 compilers pick up the new representation, we'll support this
11612 if (DW_UNSND (&attr
) == DW_CC_program
11613 && cu
->language
== language_fortran
)
11615 set_main_name (part_die
->name
);
11617 /* As this DIE has a static linkage the name would be difficult
11618 to look up later. */
11619 language_of_main
= language_fortran
;
11623 if (DW_UNSND (&attr
) == DW_INL_inlined
11624 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11625 part_die
->may_be_inlined
= 1;
11629 if (part_die
->tag
== DW_TAG_imported_unit
)
11630 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11638 if (high_pc_relative
)
11639 part_die
->highpc
+= part_die
->lowpc
;
11641 if (has_low_pc_attr
&& has_high_pc_attr
)
11643 /* When using the GNU linker, .gnu.linkonce. sections are used to
11644 eliminate duplicate copies of functions and vtables and such.
11645 The linker will arbitrarily choose one and discard the others.
11646 The AT_*_pc values for such functions refer to local labels in
11647 these sections. If the section from that file was discarded, the
11648 labels are not in the output, so the relocs get a value of 0.
11649 If this is a discarded function, mark the pc bounds as invalid,
11650 so that GDB will ignore it. */
11651 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11653 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11655 complaint (&symfile_complaints
,
11656 _("DW_AT_low_pc %s is zero "
11657 "for DIE at 0x%x [in module %s]"),
11658 paddress (gdbarch
, part_die
->lowpc
),
11659 part_die
->offset
.sect_off
, objfile
->name
);
11661 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11662 else if (part_die
->lowpc
>= part_die
->highpc
)
11664 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11666 complaint (&symfile_complaints
,
11667 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11668 "for DIE at 0x%x [in module %s]"),
11669 paddress (gdbarch
, part_die
->lowpc
),
11670 paddress (gdbarch
, part_die
->highpc
),
11671 part_die
->offset
.sect_off
, objfile
->name
);
11674 part_die
->has_pc_info
= 1;
11680 /* Find a cached partial DIE at OFFSET in CU. */
11682 static struct partial_die_info
*
11683 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11685 struct partial_die_info
*lookup_die
= NULL
;
11686 struct partial_die_info part_die
;
11688 part_die
.offset
= offset
;
11689 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11695 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11696 except in the case of .debug_types DIEs which do not reference
11697 outside their CU (they do however referencing other types via
11698 DW_FORM_ref_sig8). */
11700 static struct partial_die_info
*
11701 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11703 struct objfile
*objfile
= cu
->objfile
;
11704 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11705 struct partial_die_info
*pd
= NULL
;
11707 if (offset_in_cu_p (&cu
->header
, offset
))
11709 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11712 /* We missed recording what we needed.
11713 Load all dies and try again. */
11714 per_cu
= cu
->per_cu
;
11718 /* TUs don't reference other CUs/TUs (except via type signatures). */
11719 if (cu
->per_cu
->is_debug_types
)
11721 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11722 " external reference to offset 0x%lx [in module %s].\n"),
11723 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11724 bfd_get_filename (objfile
->obfd
));
11726 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11728 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11729 load_partial_comp_unit (per_cu
);
11731 per_cu
->cu
->last_used
= 0;
11732 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11735 /* If we didn't find it, and not all dies have been loaded,
11736 load them all and try again. */
11738 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11740 per_cu
->load_all_dies
= 1;
11742 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11743 THIS_CU->cu may already be in use. So we can't just free it and
11744 replace its DIEs with the ones we read in. Instead, we leave those
11745 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11746 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11748 load_partial_comp_unit (per_cu
);
11750 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11754 internal_error (__FILE__
, __LINE__
,
11755 _("could not find partial DIE 0x%x "
11756 "in cache [from module %s]\n"),
11757 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11761 /* See if we can figure out if the class lives in a namespace. We do
11762 this by looking for a member function; its demangled name will
11763 contain namespace info, if there is any. */
11766 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11767 struct dwarf2_cu
*cu
)
11769 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11770 what template types look like, because the demangler
11771 frequently doesn't give the same name as the debug info. We
11772 could fix this by only using the demangled name to get the
11773 prefix (but see comment in read_structure_type). */
11775 struct partial_die_info
*real_pdi
;
11776 struct partial_die_info
*child_pdi
;
11778 /* If this DIE (this DIE's specification, if any) has a parent, then
11779 we should not do this. We'll prepend the parent's fully qualified
11780 name when we create the partial symbol. */
11782 real_pdi
= struct_pdi
;
11783 while (real_pdi
->has_specification
)
11784 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11786 if (real_pdi
->die_parent
!= NULL
)
11789 for (child_pdi
= struct_pdi
->die_child
;
11791 child_pdi
= child_pdi
->die_sibling
)
11793 if (child_pdi
->tag
== DW_TAG_subprogram
11794 && child_pdi
->linkage_name
!= NULL
)
11796 char *actual_class_name
11797 = language_class_name_from_physname (cu
->language_defn
,
11798 child_pdi
->linkage_name
);
11799 if (actual_class_name
!= NULL
)
11802 = obsavestring (actual_class_name
,
11803 strlen (actual_class_name
),
11804 &cu
->objfile
->objfile_obstack
);
11805 xfree (actual_class_name
);
11812 /* Adjust PART_DIE before generating a symbol for it. This function
11813 may set the is_external flag or change the DIE's name. */
11816 fixup_partial_die (struct partial_die_info
*part_die
,
11817 struct dwarf2_cu
*cu
)
11819 /* Once we've fixed up a die, there's no point in doing so again.
11820 This also avoids a memory leak if we were to call
11821 guess_partial_die_structure_name multiple times. */
11822 if (part_die
->fixup_called
)
11825 /* If we found a reference attribute and the DIE has no name, try
11826 to find a name in the referred to DIE. */
11828 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11830 struct partial_die_info
*spec_die
;
11832 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11834 fixup_partial_die (spec_die
, cu
);
11836 if (spec_die
->name
)
11838 part_die
->name
= spec_die
->name
;
11840 /* Copy DW_AT_external attribute if it is set. */
11841 if (spec_die
->is_external
)
11842 part_die
->is_external
= spec_die
->is_external
;
11846 /* Set default names for some unnamed DIEs. */
11848 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11849 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11851 /* If there is no parent die to provide a namespace, and there are
11852 children, see if we can determine the namespace from their linkage
11854 if (cu
->language
== language_cplus
11855 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11856 && part_die
->die_parent
== NULL
11857 && part_die
->has_children
11858 && (part_die
->tag
== DW_TAG_class_type
11859 || part_die
->tag
== DW_TAG_structure_type
11860 || part_die
->tag
== DW_TAG_union_type
))
11861 guess_partial_die_structure_name (part_die
, cu
);
11863 /* GCC might emit a nameless struct or union that has a linkage
11864 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11865 if (part_die
->name
== NULL
11866 && (part_die
->tag
== DW_TAG_class_type
11867 || part_die
->tag
== DW_TAG_interface_type
11868 || part_die
->tag
== DW_TAG_structure_type
11869 || part_die
->tag
== DW_TAG_union_type
)
11870 && part_die
->linkage_name
!= NULL
)
11874 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11879 /* Strip any leading namespaces/classes, keep only the base name.
11880 DW_AT_name for named DIEs does not contain the prefixes. */
11881 base
= strrchr (demangled
, ':');
11882 if (base
&& base
> demangled
&& base
[-1] == ':')
11887 part_die
->name
= obsavestring (base
, strlen (base
),
11888 &cu
->objfile
->objfile_obstack
);
11893 part_die
->fixup_called
= 1;
11896 /* Read an attribute value described by an attribute form. */
11899 read_attribute_value (const struct die_reader_specs
*reader
,
11900 struct attribute
*attr
, unsigned form
,
11901 gdb_byte
*info_ptr
)
11903 struct dwarf2_cu
*cu
= reader
->cu
;
11904 bfd
*abfd
= reader
->abfd
;
11905 struct comp_unit_head
*cu_header
= &cu
->header
;
11906 unsigned int bytes_read
;
11907 struct dwarf_block
*blk
;
11912 case DW_FORM_ref_addr
:
11913 if (cu
->header
.version
== 2)
11914 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11916 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11917 &cu
->header
, &bytes_read
);
11918 info_ptr
+= bytes_read
;
11921 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11922 info_ptr
+= bytes_read
;
11924 case DW_FORM_block2
:
11925 blk
= dwarf_alloc_block (cu
);
11926 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11928 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11929 info_ptr
+= blk
->size
;
11930 DW_BLOCK (attr
) = blk
;
11932 case DW_FORM_block4
:
11933 blk
= dwarf_alloc_block (cu
);
11934 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11936 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11937 info_ptr
+= blk
->size
;
11938 DW_BLOCK (attr
) = blk
;
11940 case DW_FORM_data2
:
11941 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11944 case DW_FORM_data4
:
11945 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11948 case DW_FORM_data8
:
11949 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11952 case DW_FORM_sec_offset
:
11953 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11954 info_ptr
+= bytes_read
;
11956 case DW_FORM_string
:
11957 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11958 DW_STRING_IS_CANONICAL (attr
) = 0;
11959 info_ptr
+= bytes_read
;
11962 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11964 DW_STRING_IS_CANONICAL (attr
) = 0;
11965 info_ptr
+= bytes_read
;
11967 case DW_FORM_exprloc
:
11968 case DW_FORM_block
:
11969 blk
= dwarf_alloc_block (cu
);
11970 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11971 info_ptr
+= bytes_read
;
11972 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11973 info_ptr
+= blk
->size
;
11974 DW_BLOCK (attr
) = blk
;
11976 case DW_FORM_block1
:
11977 blk
= dwarf_alloc_block (cu
);
11978 blk
->size
= read_1_byte (abfd
, info_ptr
);
11980 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11981 info_ptr
+= blk
->size
;
11982 DW_BLOCK (attr
) = blk
;
11984 case DW_FORM_data1
:
11985 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11989 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11992 case DW_FORM_flag_present
:
11993 DW_UNSND (attr
) = 1;
11995 case DW_FORM_sdata
:
11996 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11997 info_ptr
+= bytes_read
;
11999 case DW_FORM_udata
:
12000 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12001 info_ptr
+= bytes_read
;
12004 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12005 + read_1_byte (abfd
, info_ptr
));
12009 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12010 + read_2_bytes (abfd
, info_ptr
));
12014 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12015 + read_4_bytes (abfd
, info_ptr
));
12019 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12020 + read_8_bytes (abfd
, info_ptr
));
12023 case DW_FORM_ref_sig8
:
12024 /* Convert the signature to something we can record in DW_UNSND
12026 NOTE: This is NULL if the type wasn't found. */
12027 DW_SIGNATURED_TYPE (attr
) =
12028 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12031 case DW_FORM_ref_udata
:
12032 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12033 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12034 info_ptr
+= bytes_read
;
12036 case DW_FORM_indirect
:
12037 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12038 info_ptr
+= bytes_read
;
12039 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
12041 case DW_FORM_GNU_addr_index
:
12042 if (reader
->dwo_file
== NULL
)
12044 /* For now flag a hard error.
12045 Later we can turn this into a complaint. */
12046 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12047 dwarf_form_name (form
),
12048 bfd_get_filename (abfd
));
12050 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
12051 info_ptr
+= bytes_read
;
12053 case DW_FORM_GNU_str_index
:
12054 if (reader
->dwo_file
== NULL
)
12056 /* For now flag a hard error.
12057 Later we can turn this into a complaint if warranted. */
12058 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12059 dwarf_form_name (form
),
12060 bfd_get_filename (abfd
));
12063 ULONGEST str_index
=
12064 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12066 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
12067 DW_STRING_IS_CANONICAL (attr
) = 0;
12068 info_ptr
+= bytes_read
;
12072 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
12073 dwarf_form_name (form
),
12074 bfd_get_filename (abfd
));
12077 /* We have seen instances where the compiler tried to emit a byte
12078 size attribute of -1 which ended up being encoded as an unsigned
12079 0xffffffff. Although 0xffffffff is technically a valid size value,
12080 an object of this size seems pretty unlikely so we can relatively
12081 safely treat these cases as if the size attribute was invalid and
12082 treat them as zero by default. */
12083 if (attr
->name
== DW_AT_byte_size
12084 && form
== DW_FORM_data4
12085 && DW_UNSND (attr
) >= 0xffffffff)
12088 (&symfile_complaints
,
12089 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12090 hex_string (DW_UNSND (attr
)));
12091 DW_UNSND (attr
) = 0;
12097 /* Read an attribute described by an abbreviated attribute. */
12100 read_attribute (const struct die_reader_specs
*reader
,
12101 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12102 gdb_byte
*info_ptr
)
12104 attr
->name
= abbrev
->name
;
12105 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
12108 /* Read dwarf information from a buffer. */
12110 static unsigned int
12111 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
12113 return bfd_get_8 (abfd
, buf
);
12117 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
12119 return bfd_get_signed_8 (abfd
, buf
);
12122 static unsigned int
12123 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
12125 return bfd_get_16 (abfd
, buf
);
12129 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12131 return bfd_get_signed_16 (abfd
, buf
);
12134 static unsigned int
12135 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
12137 return bfd_get_32 (abfd
, buf
);
12141 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12143 return bfd_get_signed_32 (abfd
, buf
);
12147 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12149 return bfd_get_64 (abfd
, buf
);
12153 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12154 unsigned int *bytes_read
)
12156 struct comp_unit_head
*cu_header
= &cu
->header
;
12157 CORE_ADDR retval
= 0;
12159 if (cu_header
->signed_addr_p
)
12161 switch (cu_header
->addr_size
)
12164 retval
= bfd_get_signed_16 (abfd
, buf
);
12167 retval
= bfd_get_signed_32 (abfd
, buf
);
12170 retval
= bfd_get_signed_64 (abfd
, buf
);
12173 internal_error (__FILE__
, __LINE__
,
12174 _("read_address: bad switch, signed [in module %s]"),
12175 bfd_get_filename (abfd
));
12180 switch (cu_header
->addr_size
)
12183 retval
= bfd_get_16 (abfd
, buf
);
12186 retval
= bfd_get_32 (abfd
, buf
);
12189 retval
= bfd_get_64 (abfd
, buf
);
12192 internal_error (__FILE__
, __LINE__
,
12193 _("read_address: bad switch, "
12194 "unsigned [in module %s]"),
12195 bfd_get_filename (abfd
));
12199 *bytes_read
= cu_header
->addr_size
;
12203 /* Read the initial length from a section. The (draft) DWARF 3
12204 specification allows the initial length to take up either 4 bytes
12205 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
12206 bytes describe the length and all offsets will be 8 bytes in length
12209 An older, non-standard 64-bit format is also handled by this
12210 function. The older format in question stores the initial length
12211 as an 8-byte quantity without an escape value. Lengths greater
12212 than 2^32 aren't very common which means that the initial 4 bytes
12213 is almost always zero. Since a length value of zero doesn't make
12214 sense for the 32-bit format, this initial zero can be considered to
12215 be an escape value which indicates the presence of the older 64-bit
12216 format. As written, the code can't detect (old format) lengths
12217 greater than 4GB. If it becomes necessary to handle lengths
12218 somewhat larger than 4GB, we could allow other small values (such
12219 as the non-sensical values of 1, 2, and 3) to also be used as
12220 escape values indicating the presence of the old format.
12222 The value returned via bytes_read should be used to increment the
12223 relevant pointer after calling read_initial_length().
12225 [ Note: read_initial_length() and read_offset() are based on the
12226 document entitled "DWARF Debugging Information Format", revision
12227 3, draft 8, dated November 19, 2001. This document was obtained
12230 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
12232 This document is only a draft and is subject to change. (So beware.)
12234 Details regarding the older, non-standard 64-bit format were
12235 determined empirically by examining 64-bit ELF files produced by
12236 the SGI toolchain on an IRIX 6.5 machine.
12238 - Kevin, July 16, 2002
12242 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
12244 LONGEST length
= bfd_get_32 (abfd
, buf
);
12246 if (length
== 0xffffffff)
12248 length
= bfd_get_64 (abfd
, buf
+ 4);
12251 else if (length
== 0)
12253 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
12254 length
= bfd_get_64 (abfd
, buf
);
12265 /* Cover function for read_initial_length.
12266 Returns the length of the object at BUF, and stores the size of the
12267 initial length in *BYTES_READ and stores the size that offsets will be in
12269 If the initial length size is not equivalent to that specified in
12270 CU_HEADER then issue a complaint.
12271 This is useful when reading non-comp-unit headers. */
12274 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
12275 const struct comp_unit_head
*cu_header
,
12276 unsigned int *bytes_read
,
12277 unsigned int *offset_size
)
12279 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
12281 gdb_assert (cu_header
->initial_length_size
== 4
12282 || cu_header
->initial_length_size
== 8
12283 || cu_header
->initial_length_size
== 12);
12285 if (cu_header
->initial_length_size
!= *bytes_read
)
12286 complaint (&symfile_complaints
,
12287 _("intermixed 32-bit and 64-bit DWARF sections"));
12289 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
12293 /* Read an offset from the data stream. The size of the offset is
12294 given by cu_header->offset_size. */
12297 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
12298 unsigned int *bytes_read
)
12300 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
12302 *bytes_read
= cu_header
->offset_size
;
12306 /* Read an offset from the data stream. */
12309 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
12311 LONGEST retval
= 0;
12313 switch (offset_size
)
12316 retval
= bfd_get_32 (abfd
, buf
);
12319 retval
= bfd_get_64 (abfd
, buf
);
12322 internal_error (__FILE__
, __LINE__
,
12323 _("read_offset_1: bad switch [in module %s]"),
12324 bfd_get_filename (abfd
));
12331 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12333 /* If the size of a host char is 8 bits, we can return a pointer
12334 to the buffer, otherwise we have to copy the data to a buffer
12335 allocated on the temporary obstack. */
12336 gdb_assert (HOST_CHAR_BIT
== 8);
12341 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12343 /* If the size of a host char is 8 bits, we can return a pointer
12344 to the string, otherwise we have to copy the string to a buffer
12345 allocated on the temporary obstack. */
12346 gdb_assert (HOST_CHAR_BIT
== 8);
12349 *bytes_read_ptr
= 1;
12352 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12353 return (char *) buf
;
12357 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12359 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12360 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12361 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12362 bfd_get_filename (abfd
));
12363 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12364 error (_("DW_FORM_strp pointing outside of "
12365 ".debug_str section [in module %s]"),
12366 bfd_get_filename (abfd
));
12367 gdb_assert (HOST_CHAR_BIT
== 8);
12368 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12370 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12374 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12375 const struct comp_unit_head
*cu_header
,
12376 unsigned int *bytes_read_ptr
)
12378 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12380 return read_indirect_string_at_offset (abfd
, str_offset
);
12384 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12387 unsigned int num_read
;
12389 unsigned char byte
;
12397 byte
= bfd_get_8 (abfd
, buf
);
12400 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12401 if ((byte
& 128) == 0)
12407 *bytes_read_ptr
= num_read
;
12412 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12415 int i
, shift
, num_read
;
12416 unsigned char byte
;
12424 byte
= bfd_get_8 (abfd
, buf
);
12427 result
|= ((LONGEST
) (byte
& 127) << shift
);
12429 if ((byte
& 128) == 0)
12434 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12435 result
|= -(((LONGEST
) 1) << shift
);
12436 *bytes_read_ptr
= num_read
;
12440 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12441 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12442 ADDR_SIZE is the size of addresses from the CU header. */
12445 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12447 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12448 bfd
*abfd
= objfile
->obfd
;
12449 const gdb_byte
*info_ptr
;
12451 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12452 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12453 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12455 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12456 error (_("DW_FORM_addr_index pointing outside of "
12457 ".debug_addr section [in module %s]"),
12459 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12460 + addr_base
+ addr_index
* addr_size
);
12461 if (addr_size
== 4)
12462 return bfd_get_32 (abfd
, info_ptr
);
12464 return bfd_get_64 (abfd
, info_ptr
);
12467 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12470 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12472 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12475 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12478 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12479 unsigned int *bytes_read
)
12481 bfd
*abfd
= cu
->objfile
->obfd
;
12482 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12484 return read_addr_index (cu
, addr_index
);
12487 /* Data structure to pass results from dwarf2_read_addr_index_reader
12488 back to dwarf2_read_addr_index. */
12490 struct dwarf2_read_addr_index_data
12492 ULONGEST addr_base
;
12496 /* die_reader_func for dwarf2_read_addr_index. */
12499 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12500 gdb_byte
*info_ptr
,
12501 struct die_info
*comp_unit_die
,
12505 struct dwarf2_cu
*cu
= reader
->cu
;
12506 struct dwarf2_read_addr_index_data
*aidata
=
12507 (struct dwarf2_read_addr_index_data
*) data
;
12509 aidata
->addr_base
= cu
->addr_base
;
12510 aidata
->addr_size
= cu
->header
.addr_size
;
12513 /* Given an index in .debug_addr, fetch the value.
12514 NOTE: This can be called during dwarf expression evaluation,
12515 long after the debug information has been read, and thus per_cu->cu
12516 may no longer exist. */
12519 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12520 unsigned int addr_index
)
12522 struct objfile
*objfile
= per_cu
->objfile
;
12523 struct dwarf2_cu
*cu
= per_cu
->cu
;
12524 ULONGEST addr_base
;
12527 /* This is intended to be called from outside this file. */
12528 dw2_setup (objfile
);
12530 /* We need addr_base and addr_size.
12531 If we don't have PER_CU->cu, we have to get it.
12532 Nasty, but the alternative is storing the needed info in PER_CU,
12533 which at this point doesn't seem justified: it's not clear how frequently
12534 it would get used and it would increase the size of every PER_CU.
12535 Entry points like dwarf2_per_cu_addr_size do a similar thing
12536 so we're not in uncharted territory here.
12537 Alas we need to be a bit more complicated as addr_base is contained
12540 We don't need to read the entire CU(/TU).
12541 We just need the header and top level die.
12542 IWBN to use the aging mechanism to let us lazily later discard the CU.
12543 See however init_cutu_and_read_dies_simple. */
12547 addr_base
= cu
->addr_base
;
12548 addr_size
= cu
->header
.addr_size
;
12552 struct dwarf2_read_addr_index_data aidata
;
12554 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12556 addr_base
= aidata
.addr_base
;
12557 addr_size
= aidata
.addr_size
;
12560 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12563 /* Given a DW_AT_str_index, fetch the string. */
12566 read_str_index (const struct die_reader_specs
*reader
,
12567 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12570 const char *dwo_name
= objfile
->name
;
12571 bfd
*abfd
= objfile
->obfd
;
12572 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12573 gdb_byte
*info_ptr
;
12574 ULONGEST str_offset
;
12576 dwarf2_read_section (objfile
, §ions
->str
);
12577 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12578 if (sections
->str
.buffer
== NULL
)
12579 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12580 " in CU at offset 0x%lx [in module %s]"),
12581 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12582 if (sections
->str_offsets
.buffer
== NULL
)
12583 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12584 " in CU at offset 0x%lx [in module %s]"),
12585 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12586 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12587 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12588 " section in CU at offset 0x%lx [in module %s]"),
12589 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12590 info_ptr
= (sections
->str_offsets
.buffer
12591 + str_index
* cu
->header
.offset_size
);
12592 if (cu
->header
.offset_size
== 4)
12593 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12595 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12596 if (str_offset
>= sections
->str
.size
)
12597 error (_("Offset from DW_FORM_str_index pointing outside of"
12598 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12599 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12600 return (char *) (sections
->str
.buffer
+ str_offset
);
12603 /* Return the length of an LEB128 number in BUF. */
12606 leb128_size (const gdb_byte
*buf
)
12608 const gdb_byte
*begin
= buf
;
12614 if ((byte
& 128) == 0)
12615 return buf
- begin
;
12620 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12627 cu
->language
= language_c
;
12629 case DW_LANG_C_plus_plus
:
12630 cu
->language
= language_cplus
;
12633 cu
->language
= language_d
;
12635 case DW_LANG_Fortran77
:
12636 case DW_LANG_Fortran90
:
12637 case DW_LANG_Fortran95
:
12638 cu
->language
= language_fortran
;
12641 cu
->language
= language_go
;
12643 case DW_LANG_Mips_Assembler
:
12644 cu
->language
= language_asm
;
12647 cu
->language
= language_java
;
12649 case DW_LANG_Ada83
:
12650 case DW_LANG_Ada95
:
12651 cu
->language
= language_ada
;
12653 case DW_LANG_Modula2
:
12654 cu
->language
= language_m2
;
12656 case DW_LANG_Pascal83
:
12657 cu
->language
= language_pascal
;
12660 cu
->language
= language_objc
;
12662 case DW_LANG_Cobol74
:
12663 case DW_LANG_Cobol85
:
12665 cu
->language
= language_minimal
;
12668 cu
->language_defn
= language_def (cu
->language
);
12671 /* Return the named attribute or NULL if not there. */
12673 static struct attribute
*
12674 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12679 struct attribute
*spec
= NULL
;
12681 for (i
= 0; i
< die
->num_attrs
; ++i
)
12683 if (die
->attrs
[i
].name
== name
)
12684 return &die
->attrs
[i
];
12685 if (die
->attrs
[i
].name
== DW_AT_specification
12686 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12687 spec
= &die
->attrs
[i
];
12693 die
= follow_die_ref (die
, spec
, &cu
);
12699 /* Return the named attribute or NULL if not there,
12700 but do not follow DW_AT_specification, etc.
12701 This is for use in contexts where we're reading .debug_types dies.
12702 Following DW_AT_specification, DW_AT_abstract_origin will take us
12703 back up the chain, and we want to go down. */
12705 static struct attribute
*
12706 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12707 struct dwarf2_cu
*cu
)
12711 for (i
= 0; i
< die
->num_attrs
; ++i
)
12712 if (die
->attrs
[i
].name
== name
)
12713 return &die
->attrs
[i
];
12718 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12719 and holds a non-zero value. This function should only be used for
12720 DW_FORM_flag or DW_FORM_flag_present attributes. */
12723 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12725 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12727 return (attr
&& DW_UNSND (attr
));
12731 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12733 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12734 which value is non-zero. However, we have to be careful with
12735 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12736 (via dwarf2_flag_true_p) follows this attribute. So we may
12737 end up accidently finding a declaration attribute that belongs
12738 to a different DIE referenced by the specification attribute,
12739 even though the given DIE does not have a declaration attribute. */
12740 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12741 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12744 /* Return the die giving the specification for DIE, if there is
12745 one. *SPEC_CU is the CU containing DIE on input, and the CU
12746 containing the return value on output. If there is no
12747 specification, but there is an abstract origin, that is
12750 static struct die_info
*
12751 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12753 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12756 if (spec_attr
== NULL
)
12757 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12759 if (spec_attr
== NULL
)
12762 return follow_die_ref (die
, spec_attr
, spec_cu
);
12765 /* Free the line_header structure *LH, and any arrays and strings it
12767 NOTE: This is also used as a "cleanup" function. */
12770 free_line_header (struct line_header
*lh
)
12772 if (lh
->standard_opcode_lengths
)
12773 xfree (lh
->standard_opcode_lengths
);
12775 /* Remember that all the lh->file_names[i].name pointers are
12776 pointers into debug_line_buffer, and don't need to be freed. */
12777 if (lh
->file_names
)
12778 xfree (lh
->file_names
);
12780 /* Similarly for the include directory names. */
12781 if (lh
->include_dirs
)
12782 xfree (lh
->include_dirs
);
12787 /* Add an entry to LH's include directory table. */
12790 add_include_dir (struct line_header
*lh
, char *include_dir
)
12792 /* Grow the array if necessary. */
12793 if (lh
->include_dirs_size
== 0)
12795 lh
->include_dirs_size
= 1; /* for testing */
12796 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12797 * sizeof (*lh
->include_dirs
));
12799 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12801 lh
->include_dirs_size
*= 2;
12802 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12803 (lh
->include_dirs_size
12804 * sizeof (*lh
->include_dirs
)));
12807 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12810 /* Add an entry to LH's file name table. */
12813 add_file_name (struct line_header
*lh
,
12815 unsigned int dir_index
,
12816 unsigned int mod_time
,
12817 unsigned int length
)
12819 struct file_entry
*fe
;
12821 /* Grow the array if necessary. */
12822 if (lh
->file_names_size
== 0)
12824 lh
->file_names_size
= 1; /* for testing */
12825 lh
->file_names
= xmalloc (lh
->file_names_size
12826 * sizeof (*lh
->file_names
));
12828 else if (lh
->num_file_names
>= lh
->file_names_size
)
12830 lh
->file_names_size
*= 2;
12831 lh
->file_names
= xrealloc (lh
->file_names
,
12832 (lh
->file_names_size
12833 * sizeof (*lh
->file_names
)));
12836 fe
= &lh
->file_names
[lh
->num_file_names
++];
12838 fe
->dir_index
= dir_index
;
12839 fe
->mod_time
= mod_time
;
12840 fe
->length
= length
;
12841 fe
->included_p
= 0;
12845 /* Read the statement program header starting at OFFSET in
12846 .debug_line, or .debug_line.dwo. Return a pointer
12847 to a struct line_header, allocated using xmalloc.
12849 NOTE: the strings in the include directory and file name tables of
12850 the returned object point into the dwarf line section buffer,
12851 and must not be freed. */
12853 static struct line_header
*
12854 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12856 struct cleanup
*back_to
;
12857 struct line_header
*lh
;
12858 gdb_byte
*line_ptr
;
12859 unsigned int bytes_read
, offset_size
;
12861 char *cur_dir
, *cur_file
;
12862 struct dwarf2_section_info
*section
;
12865 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12867 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12868 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12870 section
= &dwarf2_per_objfile
->line
;
12872 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12873 if (section
->buffer
== NULL
)
12875 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12876 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12878 complaint (&symfile_complaints
, _("missing .debug_line section"));
12882 /* We can't do this until we know the section is non-empty.
12883 Only then do we know we have such a section. */
12884 abfd
= section
->asection
->owner
;
12886 /* Make sure that at least there's room for the total_length field.
12887 That could be 12 bytes long, but we're just going to fudge that. */
12888 if (offset
+ 4 >= section
->size
)
12890 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12894 lh
= xmalloc (sizeof (*lh
));
12895 memset (lh
, 0, sizeof (*lh
));
12896 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12899 line_ptr
= section
->buffer
+ offset
;
12901 /* Read in the header. */
12903 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12904 &bytes_read
, &offset_size
);
12905 line_ptr
+= bytes_read
;
12906 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12908 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12911 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12912 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12914 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12915 line_ptr
+= offset_size
;
12916 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12918 if (lh
->version
>= 4)
12920 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12924 lh
->maximum_ops_per_instruction
= 1;
12926 if (lh
->maximum_ops_per_instruction
== 0)
12928 lh
->maximum_ops_per_instruction
= 1;
12929 complaint (&symfile_complaints
,
12930 _("invalid maximum_ops_per_instruction "
12931 "in `.debug_line' section"));
12934 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12936 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12938 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12940 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12942 lh
->standard_opcode_lengths
12943 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12945 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12946 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12948 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12952 /* Read directory table. */
12953 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12955 line_ptr
+= bytes_read
;
12956 add_include_dir (lh
, cur_dir
);
12958 line_ptr
+= bytes_read
;
12960 /* Read file name table. */
12961 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12963 unsigned int dir_index
, mod_time
, length
;
12965 line_ptr
+= bytes_read
;
12966 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12967 line_ptr
+= bytes_read
;
12968 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12969 line_ptr
+= bytes_read
;
12970 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12971 line_ptr
+= bytes_read
;
12973 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12975 line_ptr
+= bytes_read
;
12976 lh
->statement_program_start
= line_ptr
;
12978 if (line_ptr
> (section
->buffer
+ section
->size
))
12979 complaint (&symfile_complaints
,
12980 _("line number info header doesn't "
12981 "fit in `.debug_line' section"));
12983 discard_cleanups (back_to
);
12987 /* Subroutine of dwarf_decode_lines to simplify it.
12988 Return the file name of the psymtab for included file FILE_INDEX
12989 in line header LH of PST.
12990 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12991 If space for the result is malloc'd, it will be freed by a cleanup.
12992 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12995 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12996 const struct partial_symtab
*pst
,
12997 const char *comp_dir
)
12999 const struct file_entry fe
= lh
->file_names
[file_index
];
13000 char *include_name
= fe
.name
;
13001 char *include_name_to_compare
= include_name
;
13002 char *dir_name
= NULL
;
13003 const char *pst_filename
;
13004 char *copied_name
= NULL
;
13008 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13010 if (!IS_ABSOLUTE_PATH (include_name
)
13011 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13013 /* Avoid creating a duplicate psymtab for PST.
13014 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13015 Before we do the comparison, however, we need to account
13016 for DIR_NAME and COMP_DIR.
13017 First prepend dir_name (if non-NULL). If we still don't
13018 have an absolute path prepend comp_dir (if non-NULL).
13019 However, the directory we record in the include-file's
13020 psymtab does not contain COMP_DIR (to match the
13021 corresponding symtab(s)).
13026 bash$ gcc -g ./hello.c
13027 include_name = "hello.c"
13029 DW_AT_comp_dir = comp_dir = "/tmp"
13030 DW_AT_name = "./hello.c" */
13032 if (dir_name
!= NULL
)
13034 include_name
= concat (dir_name
, SLASH_STRING
,
13035 include_name
, (char *)NULL
);
13036 include_name_to_compare
= include_name
;
13037 make_cleanup (xfree
, include_name
);
13039 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
13041 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
13042 include_name
, (char *)NULL
);
13046 pst_filename
= pst
->filename
;
13047 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
13049 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
13050 pst_filename
, (char *)NULL
);
13051 pst_filename
= copied_name
;
13054 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
13056 if (include_name_to_compare
!= include_name
)
13057 xfree (include_name_to_compare
);
13058 if (copied_name
!= NULL
)
13059 xfree (copied_name
);
13063 return include_name
;
13066 /* Ignore this record_line request. */
13069 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13074 /* Subroutine of dwarf_decode_lines to simplify it.
13075 Process the line number information in LH. */
13078 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13079 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13081 gdb_byte
*line_ptr
, *extended_end
;
13082 gdb_byte
*line_end
;
13083 unsigned int bytes_read
, extended_len
;
13084 unsigned char op_code
, extended_op
, adj_opcode
;
13085 CORE_ADDR baseaddr
;
13086 struct objfile
*objfile
= cu
->objfile
;
13087 bfd
*abfd
= objfile
->obfd
;
13088 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13089 const int decode_for_pst_p
= (pst
!= NULL
);
13090 struct subfile
*last_subfile
= NULL
;
13091 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13094 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13096 line_ptr
= lh
->statement_program_start
;
13097 line_end
= lh
->statement_program_end
;
13099 /* Read the statement sequences until there's nothing left. */
13100 while (line_ptr
< line_end
)
13102 /* state machine registers */
13103 CORE_ADDR address
= 0;
13104 unsigned int file
= 1;
13105 unsigned int line
= 1;
13106 unsigned int column
= 0;
13107 int is_stmt
= lh
->default_is_stmt
;
13108 int basic_block
= 0;
13109 int end_sequence
= 0;
13111 unsigned char op_index
= 0;
13113 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
13115 /* Start a subfile for the current file of the state machine. */
13116 /* lh->include_dirs and lh->file_names are 0-based, but the
13117 directory and file name numbers in the statement program
13119 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13123 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13125 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13128 /* Decode the table. */
13129 while (!end_sequence
)
13131 op_code
= read_1_byte (abfd
, line_ptr
);
13133 if (line_ptr
> line_end
)
13135 dwarf2_debug_line_missing_end_sequence_complaint ();
13139 if (op_code
>= lh
->opcode_base
)
13141 /* Special operand. */
13142 adj_opcode
= op_code
- lh
->opcode_base
;
13143 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13144 / lh
->maximum_ops_per_instruction
)
13145 * lh
->minimum_instruction_length
);
13146 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13147 % lh
->maximum_ops_per_instruction
);
13148 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13149 if (lh
->num_file_names
< file
|| file
== 0)
13150 dwarf2_debug_line_missing_file_complaint ();
13151 /* For now we ignore lines not starting on an
13152 instruction boundary. */
13153 else if (op_index
== 0)
13155 lh
->file_names
[file
- 1].included_p
= 1;
13156 if (!decode_for_pst_p
&& is_stmt
)
13158 if (last_subfile
!= current_subfile
)
13160 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13162 (*p_record_line
) (last_subfile
, 0, addr
);
13163 last_subfile
= current_subfile
;
13165 /* Append row to matrix using current values. */
13166 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13167 (*p_record_line
) (current_subfile
, line
, addr
);
13172 else switch (op_code
)
13174 case DW_LNS_extended_op
:
13175 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13177 line_ptr
+= bytes_read
;
13178 extended_end
= line_ptr
+ extended_len
;
13179 extended_op
= read_1_byte (abfd
, line_ptr
);
13181 switch (extended_op
)
13183 case DW_LNE_end_sequence
:
13184 p_record_line
= record_line
;
13187 case DW_LNE_set_address
:
13188 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
13190 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13192 /* This line table is for a function which has been
13193 GCd by the linker. Ignore it. PR gdb/12528 */
13196 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
13198 complaint (&symfile_complaints
,
13199 _(".debug_line address at offset 0x%lx is 0 "
13201 line_offset
, objfile
->name
);
13202 p_record_line
= noop_record_line
;
13206 line_ptr
+= bytes_read
;
13207 address
+= baseaddr
;
13209 case DW_LNE_define_file
:
13212 unsigned int dir_index
, mod_time
, length
;
13214 cur_file
= read_direct_string (abfd
, line_ptr
,
13216 line_ptr
+= bytes_read
;
13218 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13219 line_ptr
+= bytes_read
;
13221 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13222 line_ptr
+= bytes_read
;
13224 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13225 line_ptr
+= bytes_read
;
13226 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13229 case DW_LNE_set_discriminator
:
13230 /* The discriminator is not interesting to the debugger;
13232 line_ptr
= extended_end
;
13235 complaint (&symfile_complaints
,
13236 _("mangled .debug_line section"));
13239 /* Make sure that we parsed the extended op correctly. If e.g.
13240 we expected a different address size than the producer used,
13241 we may have read the wrong number of bytes. */
13242 if (line_ptr
!= extended_end
)
13244 complaint (&symfile_complaints
,
13245 _("mangled .debug_line section"));
13250 if (lh
->num_file_names
< file
|| file
== 0)
13251 dwarf2_debug_line_missing_file_complaint ();
13254 lh
->file_names
[file
- 1].included_p
= 1;
13255 if (!decode_for_pst_p
&& is_stmt
)
13257 if (last_subfile
!= current_subfile
)
13259 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13261 (*p_record_line
) (last_subfile
, 0, addr
);
13262 last_subfile
= current_subfile
;
13264 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13265 (*p_record_line
) (current_subfile
, line
, addr
);
13270 case DW_LNS_advance_pc
:
13273 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13275 address
+= (((op_index
+ adjust
)
13276 / lh
->maximum_ops_per_instruction
)
13277 * lh
->minimum_instruction_length
);
13278 op_index
= ((op_index
+ adjust
)
13279 % lh
->maximum_ops_per_instruction
);
13280 line_ptr
+= bytes_read
;
13283 case DW_LNS_advance_line
:
13284 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
13285 line_ptr
+= bytes_read
;
13287 case DW_LNS_set_file
:
13289 /* The arrays lh->include_dirs and lh->file_names are
13290 0-based, but the directory and file name numbers in
13291 the statement program are 1-based. */
13292 struct file_entry
*fe
;
13295 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13296 line_ptr
+= bytes_read
;
13297 if (lh
->num_file_names
< file
|| file
== 0)
13298 dwarf2_debug_line_missing_file_complaint ();
13301 fe
= &lh
->file_names
[file
- 1];
13303 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13304 if (!decode_for_pst_p
)
13306 last_subfile
= current_subfile
;
13307 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13312 case DW_LNS_set_column
:
13313 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13314 line_ptr
+= bytes_read
;
13316 case DW_LNS_negate_stmt
:
13317 is_stmt
= (!is_stmt
);
13319 case DW_LNS_set_basic_block
:
13322 /* Add to the address register of the state machine the
13323 address increment value corresponding to special opcode
13324 255. I.e., this value is scaled by the minimum
13325 instruction length since special opcode 255 would have
13326 scaled the increment. */
13327 case DW_LNS_const_add_pc
:
13329 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13331 address
+= (((op_index
+ adjust
)
13332 / lh
->maximum_ops_per_instruction
)
13333 * lh
->minimum_instruction_length
);
13334 op_index
= ((op_index
+ adjust
)
13335 % lh
->maximum_ops_per_instruction
);
13338 case DW_LNS_fixed_advance_pc
:
13339 address
+= read_2_bytes (abfd
, line_ptr
);
13345 /* Unknown standard opcode, ignore it. */
13348 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13350 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13351 line_ptr
+= bytes_read
;
13356 if (lh
->num_file_names
< file
|| file
== 0)
13357 dwarf2_debug_line_missing_file_complaint ();
13360 lh
->file_names
[file
- 1].included_p
= 1;
13361 if (!decode_for_pst_p
)
13363 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13364 (*p_record_line
) (current_subfile
, 0, addr
);
13370 /* Decode the Line Number Program (LNP) for the given line_header
13371 structure and CU. The actual information extracted and the type
13372 of structures created from the LNP depends on the value of PST.
13374 1. If PST is NULL, then this procedure uses the data from the program
13375 to create all necessary symbol tables, and their linetables.
13377 2. If PST is not NULL, this procedure reads the program to determine
13378 the list of files included by the unit represented by PST, and
13379 builds all the associated partial symbol tables.
13381 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13382 It is used for relative paths in the line table.
13383 NOTE: When processing partial symtabs (pst != NULL),
13384 comp_dir == pst->dirname.
13386 NOTE: It is important that psymtabs have the same file name (via strcmp)
13387 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13388 symtab we don't use it in the name of the psymtabs we create.
13389 E.g. expand_line_sal requires this when finding psymtabs to expand.
13390 A good testcase for this is mb-inline.exp. */
13393 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13394 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13395 int want_line_info
)
13397 struct objfile
*objfile
= cu
->objfile
;
13398 const int decode_for_pst_p
= (pst
!= NULL
);
13399 struct subfile
*first_subfile
= current_subfile
;
13401 if (want_line_info
)
13402 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13404 if (decode_for_pst_p
)
13408 /* Now that we're done scanning the Line Header Program, we can
13409 create the psymtab of each included file. */
13410 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13411 if (lh
->file_names
[file_index
].included_p
== 1)
13413 char *include_name
=
13414 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13415 if (include_name
!= NULL
)
13416 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13421 /* Make sure a symtab is created for every file, even files
13422 which contain only variables (i.e. no code with associated
13426 for (i
= 0; i
< lh
->num_file_names
; i
++)
13429 struct file_entry
*fe
;
13431 fe
= &lh
->file_names
[i
];
13433 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13434 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13436 /* Skip the main file; we don't need it, and it must be
13437 allocated last, so that it will show up before the
13438 non-primary symtabs in the objfile's symtab list. */
13439 if (current_subfile
== first_subfile
)
13442 if (current_subfile
->symtab
== NULL
)
13443 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13445 fe
->symtab
= current_subfile
->symtab
;
13450 /* Start a subfile for DWARF. FILENAME is the name of the file and
13451 DIRNAME the name of the source directory which contains FILENAME
13452 or NULL if not known. COMP_DIR is the compilation directory for the
13453 linetable's compilation unit or NULL if not known.
13454 This routine tries to keep line numbers from identical absolute and
13455 relative file names in a common subfile.
13457 Using the `list' example from the GDB testsuite, which resides in
13458 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13459 of /srcdir/list0.c yields the following debugging information for list0.c:
13461 DW_AT_name: /srcdir/list0.c
13462 DW_AT_comp_dir: /compdir
13463 files.files[0].name: list0.h
13464 files.files[0].dir: /srcdir
13465 files.files[1].name: list0.c
13466 files.files[1].dir: /srcdir
13468 The line number information for list0.c has to end up in a single
13469 subfile, so that `break /srcdir/list0.c:1' works as expected.
13470 start_subfile will ensure that this happens provided that we pass the
13471 concatenation of files.files[1].dir and files.files[1].name as the
13475 dwarf2_start_subfile (char *filename
, const char *dirname
,
13476 const char *comp_dir
)
13480 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13481 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13482 second argument to start_subfile. To be consistent, we do the
13483 same here. In order not to lose the line information directory,
13484 we concatenate it to the filename when it makes sense.
13485 Note that the Dwarf3 standard says (speaking of filenames in line
13486 information): ``The directory index is ignored for file names
13487 that represent full path names''. Thus ignoring dirname in the
13488 `else' branch below isn't an issue. */
13490 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13491 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13493 fullname
= filename
;
13495 start_subfile (fullname
, comp_dir
);
13497 if (fullname
!= filename
)
13502 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13503 struct dwarf2_cu
*cu
)
13505 struct objfile
*objfile
= cu
->objfile
;
13506 struct comp_unit_head
*cu_header
= &cu
->header
;
13508 /* NOTE drow/2003-01-30: There used to be a comment and some special
13509 code here to turn a symbol with DW_AT_external and a
13510 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13511 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13512 with some versions of binutils) where shared libraries could have
13513 relocations against symbols in their debug information - the
13514 minimal symbol would have the right address, but the debug info
13515 would not. It's no longer necessary, because we will explicitly
13516 apply relocations when we read in the debug information now. */
13518 /* A DW_AT_location attribute with no contents indicates that a
13519 variable has been optimized away. */
13520 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13522 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13526 /* Handle one degenerate form of location expression specially, to
13527 preserve GDB's previous behavior when section offsets are
13528 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13529 then mark this symbol as LOC_STATIC. */
13531 if (attr_form_is_block (attr
)
13532 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13533 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13534 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13535 && (DW_BLOCK (attr
)->size
13536 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13538 unsigned int dummy
;
13540 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13541 SYMBOL_VALUE_ADDRESS (sym
) =
13542 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13544 SYMBOL_VALUE_ADDRESS (sym
) =
13545 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13546 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13547 fixup_symbol_section (sym
, objfile
);
13548 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13549 SYMBOL_SECTION (sym
));
13553 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13554 expression evaluator, and use LOC_COMPUTED only when necessary
13555 (i.e. when the value of a register or memory location is
13556 referenced, or a thread-local block, etc.). Then again, it might
13557 not be worthwhile. I'm assuming that it isn't unless performance
13558 or memory numbers show me otherwise. */
13560 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13561 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13563 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13564 cu
->has_loclist
= 1;
13567 /* Given a pointer to a DWARF information entry, figure out if we need
13568 to make a symbol table entry for it, and if so, create a new entry
13569 and return a pointer to it.
13570 If TYPE is NULL, determine symbol type from the die, otherwise
13571 used the passed type.
13572 If SPACE is not NULL, use it to hold the new symbol. If it is
13573 NULL, allocate a new symbol on the objfile's obstack. */
13575 static struct symbol
*
13576 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13577 struct symbol
*space
)
13579 struct objfile
*objfile
= cu
->objfile
;
13580 struct symbol
*sym
= NULL
;
13582 struct attribute
*attr
= NULL
;
13583 struct attribute
*attr2
= NULL
;
13584 CORE_ADDR baseaddr
;
13585 struct pending
**list_to_add
= NULL
;
13587 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13589 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13591 name
= dwarf2_name (die
, cu
);
13594 const char *linkagename
;
13595 int suppress_add
= 0;
13600 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13601 OBJSTAT (objfile
, n_syms
++);
13603 /* Cache this symbol's name and the name's demangled form (if any). */
13604 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13605 linkagename
= dwarf2_physname (name
, die
, cu
);
13606 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13608 /* Fortran does not have mangling standard and the mangling does differ
13609 between gfortran, iFort etc. */
13610 if (cu
->language
== language_fortran
13611 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13612 symbol_set_demangled_name (&(sym
->ginfo
),
13613 (char *) dwarf2_full_name (name
, die
, cu
),
13616 /* Default assumptions.
13617 Use the passed type or decode it from the die. */
13618 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13619 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13621 SYMBOL_TYPE (sym
) = type
;
13623 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13624 attr
= dwarf2_attr (die
,
13625 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13629 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13632 attr
= dwarf2_attr (die
,
13633 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13637 int file_index
= DW_UNSND (attr
);
13639 if (cu
->line_header
== NULL
13640 || file_index
> cu
->line_header
->num_file_names
)
13641 complaint (&symfile_complaints
,
13642 _("file index out of range"));
13643 else if (file_index
> 0)
13645 struct file_entry
*fe
;
13647 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13648 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13655 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13658 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13660 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13661 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13662 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13663 add_symbol_to_list (sym
, cu
->list_in_scope
);
13665 case DW_TAG_subprogram
:
13666 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13668 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13669 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13670 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13671 || cu
->language
== language_ada
)
13673 /* Subprograms marked external are stored as a global symbol.
13674 Ada subprograms, whether marked external or not, are always
13675 stored as a global symbol, because we want to be able to
13676 access them globally. For instance, we want to be able
13677 to break on a nested subprogram without having to
13678 specify the context. */
13679 list_to_add
= &global_symbols
;
13683 list_to_add
= cu
->list_in_scope
;
13686 case DW_TAG_inlined_subroutine
:
13687 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13689 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13690 SYMBOL_INLINED (sym
) = 1;
13691 list_to_add
= cu
->list_in_scope
;
13693 case DW_TAG_template_value_param
:
13695 /* Fall through. */
13696 case DW_TAG_constant
:
13697 case DW_TAG_variable
:
13698 case DW_TAG_member
:
13699 /* Compilation with minimal debug info may result in
13700 variables with missing type entries. Change the
13701 misleading `void' type to something sensible. */
13702 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13704 = objfile_type (objfile
)->nodebug_data_symbol
;
13706 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13707 /* In the case of DW_TAG_member, we should only be called for
13708 static const members. */
13709 if (die
->tag
== DW_TAG_member
)
13711 /* dwarf2_add_field uses die_is_declaration,
13712 so we do the same. */
13713 gdb_assert (die_is_declaration (die
, cu
));
13718 dwarf2_const_value (attr
, sym
, cu
);
13719 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13722 if (attr2
&& (DW_UNSND (attr2
) != 0))
13723 list_to_add
= &global_symbols
;
13725 list_to_add
= cu
->list_in_scope
;
13729 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13732 var_decode_location (attr
, sym
, cu
);
13733 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13734 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13735 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13736 && !dwarf2_per_objfile
->has_section_at_zero
)
13738 /* When a static variable is eliminated by the linker,
13739 the corresponding debug information is not stripped
13740 out, but the variable address is set to null;
13741 do not add such variables into symbol table. */
13743 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13745 /* Workaround gfortran PR debug/40040 - it uses
13746 DW_AT_location for variables in -fPIC libraries which may
13747 get overriden by other libraries/executable and get
13748 a different address. Resolve it by the minimal symbol
13749 which may come from inferior's executable using copy
13750 relocation. Make this workaround only for gfortran as for
13751 other compilers GDB cannot guess the minimal symbol
13752 Fortran mangling kind. */
13753 if (cu
->language
== language_fortran
&& die
->parent
13754 && die
->parent
->tag
== DW_TAG_module
13756 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13757 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13759 /* A variable with DW_AT_external is never static,
13760 but it may be block-scoped. */
13761 list_to_add
= (cu
->list_in_scope
== &file_symbols
13762 ? &global_symbols
: cu
->list_in_scope
);
13765 list_to_add
= cu
->list_in_scope
;
13769 /* We do not know the address of this symbol.
13770 If it is an external symbol and we have type information
13771 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13772 The address of the variable will then be determined from
13773 the minimal symbol table whenever the variable is
13775 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13776 if (attr2
&& (DW_UNSND (attr2
) != 0)
13777 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13779 /* A variable with DW_AT_external is never static, but it
13780 may be block-scoped. */
13781 list_to_add
= (cu
->list_in_scope
== &file_symbols
13782 ? &global_symbols
: cu
->list_in_scope
);
13784 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13786 else if (!die_is_declaration (die
, cu
))
13788 /* Use the default LOC_OPTIMIZED_OUT class. */
13789 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13791 list_to_add
= cu
->list_in_scope
;
13795 case DW_TAG_formal_parameter
:
13796 /* If we are inside a function, mark this as an argument. If
13797 not, we might be looking at an argument to an inlined function
13798 when we do not have enough information to show inlined frames;
13799 pretend it's a local variable in that case so that the user can
13801 if (context_stack_depth
> 0
13802 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13803 SYMBOL_IS_ARGUMENT (sym
) = 1;
13804 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13807 var_decode_location (attr
, sym
, cu
);
13809 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13812 dwarf2_const_value (attr
, sym
, cu
);
13815 list_to_add
= cu
->list_in_scope
;
13817 case DW_TAG_unspecified_parameters
:
13818 /* From varargs functions; gdb doesn't seem to have any
13819 interest in this information, so just ignore it for now.
13822 case DW_TAG_template_type_param
:
13824 /* Fall through. */
13825 case DW_TAG_class_type
:
13826 case DW_TAG_interface_type
:
13827 case DW_TAG_structure_type
:
13828 case DW_TAG_union_type
:
13829 case DW_TAG_set_type
:
13830 case DW_TAG_enumeration_type
:
13831 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13832 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13835 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13836 really ever be static objects: otherwise, if you try
13837 to, say, break of a class's method and you're in a file
13838 which doesn't mention that class, it won't work unless
13839 the check for all static symbols in lookup_symbol_aux
13840 saves you. See the OtherFileClass tests in
13841 gdb.c++/namespace.exp. */
13845 list_to_add
= (cu
->list_in_scope
== &file_symbols
13846 && (cu
->language
== language_cplus
13847 || cu
->language
== language_java
)
13848 ? &global_symbols
: cu
->list_in_scope
);
13850 /* The semantics of C++ state that "struct foo {
13851 ... }" also defines a typedef for "foo". A Java
13852 class declaration also defines a typedef for the
13854 if (cu
->language
== language_cplus
13855 || cu
->language
== language_java
13856 || cu
->language
== language_ada
)
13858 /* The symbol's name is already allocated along
13859 with this objfile, so we don't need to
13860 duplicate it for the type. */
13861 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13862 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13867 case DW_TAG_typedef
:
13868 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13869 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13870 list_to_add
= cu
->list_in_scope
;
13872 case DW_TAG_base_type
:
13873 case DW_TAG_subrange_type
:
13874 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13875 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13876 list_to_add
= cu
->list_in_scope
;
13878 case DW_TAG_enumerator
:
13879 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13882 dwarf2_const_value (attr
, sym
, cu
);
13885 /* NOTE: carlton/2003-11-10: See comment above in the
13886 DW_TAG_class_type, etc. block. */
13888 list_to_add
= (cu
->list_in_scope
== &file_symbols
13889 && (cu
->language
== language_cplus
13890 || cu
->language
== language_java
)
13891 ? &global_symbols
: cu
->list_in_scope
);
13894 case DW_TAG_namespace
:
13895 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13896 list_to_add
= &global_symbols
;
13899 /* Not a tag we recognize. Hopefully we aren't processing
13900 trash data, but since we must specifically ignore things
13901 we don't recognize, there is nothing else we should do at
13903 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13904 dwarf_tag_name (die
->tag
));
13910 sym
->hash_next
= objfile
->template_symbols
;
13911 objfile
->template_symbols
= sym
;
13912 list_to_add
= NULL
;
13915 if (list_to_add
!= NULL
)
13916 add_symbol_to_list (sym
, list_to_add
);
13918 /* For the benefit of old versions of GCC, check for anonymous
13919 namespaces based on the demangled name. */
13920 if (!processing_has_namespace_info
13921 && cu
->language
== language_cplus
)
13922 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13927 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13929 static struct symbol
*
13930 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13932 return new_symbol_full (die
, type
, cu
, NULL
);
13935 /* Given an attr with a DW_FORM_dataN value in host byte order,
13936 zero-extend it as appropriate for the symbol's type. The DWARF
13937 standard (v4) is not entirely clear about the meaning of using
13938 DW_FORM_dataN for a constant with a signed type, where the type is
13939 wider than the data. The conclusion of a discussion on the DWARF
13940 list was that this is unspecified. We choose to always zero-extend
13941 because that is the interpretation long in use by GCC. */
13944 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13945 const char *name
, struct obstack
*obstack
,
13946 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13948 struct objfile
*objfile
= cu
->objfile
;
13949 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13950 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13951 LONGEST l
= DW_UNSND (attr
);
13953 if (bits
< sizeof (*value
) * 8)
13955 l
&= ((LONGEST
) 1 << bits
) - 1;
13958 else if (bits
== sizeof (*value
) * 8)
13962 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13963 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13970 /* Read a constant value from an attribute. Either set *VALUE, or if
13971 the value does not fit in *VALUE, set *BYTES - either already
13972 allocated on the objfile obstack, or newly allocated on OBSTACK,
13973 or, set *BATON, if we translated the constant to a location
13977 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13978 const char *name
, struct obstack
*obstack
,
13979 struct dwarf2_cu
*cu
,
13980 LONGEST
*value
, gdb_byte
**bytes
,
13981 struct dwarf2_locexpr_baton
**baton
)
13983 struct objfile
*objfile
= cu
->objfile
;
13984 struct comp_unit_head
*cu_header
= &cu
->header
;
13985 struct dwarf_block
*blk
;
13986 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13987 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13993 switch (attr
->form
)
13996 case DW_FORM_GNU_addr_index
:
14000 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14001 dwarf2_const_value_length_mismatch_complaint (name
,
14002 cu_header
->addr_size
,
14003 TYPE_LENGTH (type
));
14004 /* Symbols of this form are reasonably rare, so we just
14005 piggyback on the existing location code rather than writing
14006 a new implementation of symbol_computed_ops. */
14007 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14008 sizeof (struct dwarf2_locexpr_baton
));
14009 (*baton
)->per_cu
= cu
->per_cu
;
14010 gdb_assert ((*baton
)->per_cu
);
14012 (*baton
)->size
= 2 + cu_header
->addr_size
;
14013 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14014 (*baton
)->data
= data
;
14016 data
[0] = DW_OP_addr
;
14017 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14018 byte_order
, DW_ADDR (attr
));
14019 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14022 case DW_FORM_string
:
14024 case DW_FORM_GNU_str_index
:
14025 /* DW_STRING is already allocated on the objfile obstack, point
14027 *bytes
= (gdb_byte
*) DW_STRING (attr
);
14029 case DW_FORM_block1
:
14030 case DW_FORM_block2
:
14031 case DW_FORM_block4
:
14032 case DW_FORM_block
:
14033 case DW_FORM_exprloc
:
14034 blk
= DW_BLOCK (attr
);
14035 if (TYPE_LENGTH (type
) != blk
->size
)
14036 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
14037 TYPE_LENGTH (type
));
14038 *bytes
= blk
->data
;
14041 /* The DW_AT_const_value attributes are supposed to carry the
14042 symbol's value "represented as it would be on the target
14043 architecture." By the time we get here, it's already been
14044 converted to host endianness, so we just need to sign- or
14045 zero-extend it as appropriate. */
14046 case DW_FORM_data1
:
14047 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14048 obstack
, cu
, value
, 8);
14050 case DW_FORM_data2
:
14051 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14052 obstack
, cu
, value
, 16);
14054 case DW_FORM_data4
:
14055 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14056 obstack
, cu
, value
, 32);
14058 case DW_FORM_data8
:
14059 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14060 obstack
, cu
, value
, 64);
14063 case DW_FORM_sdata
:
14064 *value
= DW_SND (attr
);
14067 case DW_FORM_udata
:
14068 *value
= DW_UNSND (attr
);
14072 complaint (&symfile_complaints
,
14073 _("unsupported const value attribute form: '%s'"),
14074 dwarf_form_name (attr
->form
));
14081 /* Copy constant value from an attribute to a symbol. */
14084 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14085 struct dwarf2_cu
*cu
)
14087 struct objfile
*objfile
= cu
->objfile
;
14088 struct comp_unit_head
*cu_header
= &cu
->header
;
14091 struct dwarf2_locexpr_baton
*baton
;
14093 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
14094 SYMBOL_PRINT_NAME (sym
),
14095 &objfile
->objfile_obstack
, cu
,
14096 &value
, &bytes
, &baton
);
14100 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14101 SYMBOL_LOCATION_BATON (sym
) = baton
;
14102 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14104 else if (bytes
!= NULL
)
14106 SYMBOL_VALUE_BYTES (sym
) = bytes
;
14107 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
14111 SYMBOL_VALUE (sym
) = value
;
14112 SYMBOL_CLASS (sym
) = LOC_CONST
;
14116 /* Return the type of the die in question using its DW_AT_type attribute. */
14118 static struct type
*
14119 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14121 struct attribute
*type_attr
;
14123 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14126 /* A missing DW_AT_type represents a void type. */
14127 return objfile_type (cu
->objfile
)->builtin_void
;
14130 return lookup_die_type (die
, type_attr
, cu
);
14133 /* True iff CU's producer generates GNAT Ada auxiliary information
14134 that allows to find parallel types through that information instead
14135 of having to do expensive parallel lookups by type name. */
14138 need_gnat_info (struct dwarf2_cu
*cu
)
14140 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14141 of GNAT produces this auxiliary information, without any indication
14142 that it is produced. Part of enhancing the FSF version of GNAT
14143 to produce that information will be to put in place an indicator
14144 that we can use in order to determine whether the descriptive type
14145 info is available or not. One suggestion that has been made is
14146 to use a new attribute, attached to the CU die. For now, assume
14147 that the descriptive type info is not available. */
14151 /* Return the auxiliary type of the die in question using its
14152 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14153 attribute is not present. */
14155 static struct type
*
14156 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14158 struct attribute
*type_attr
;
14160 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
14164 return lookup_die_type (die
, type_attr
, cu
);
14167 /* If DIE has a descriptive_type attribute, then set the TYPE's
14168 descriptive type accordingly. */
14171 set_descriptive_type (struct type
*type
, struct die_info
*die
,
14172 struct dwarf2_cu
*cu
)
14174 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
14176 if (descriptive_type
)
14178 ALLOCATE_GNAT_AUX_TYPE (type
);
14179 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
14183 /* Return the containing type of the die in question using its
14184 DW_AT_containing_type attribute. */
14186 static struct type
*
14187 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14189 struct attribute
*type_attr
;
14191 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
14193 error (_("Dwarf Error: Problem turning containing type into gdb type "
14194 "[in module %s]"), cu
->objfile
->name
);
14196 return lookup_die_type (die
, type_attr
, cu
);
14199 /* Look up the type of DIE in CU using its type attribute ATTR.
14200 If there is no type substitute an error marker. */
14202 static struct type
*
14203 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
14204 struct dwarf2_cu
*cu
)
14206 struct objfile
*objfile
= cu
->objfile
;
14207 struct type
*this_type
;
14209 /* First see if we have it cached. */
14211 if (is_ref_attr (attr
))
14213 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14215 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
14217 else if (attr
->form
== DW_FORM_ref_sig8
)
14219 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14221 /* sig_type will be NULL if the signatured type is missing from
14223 if (sig_type
== NULL
)
14224 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14225 "at 0x%x [in module %s]"),
14226 die
->offset
.sect_off
, objfile
->name
);
14228 gdb_assert (sig_type
->per_cu
.is_debug_types
);
14229 /* If we haven't filled in type_offset_in_section yet, then we
14230 haven't read the type in yet. */
14232 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
14235 get_die_type_at_offset (sig_type
->type_offset_in_section
,
14236 &sig_type
->per_cu
);
14241 dump_die_for_error (die
);
14242 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
14243 dwarf_attr_name (attr
->name
), objfile
->name
);
14246 /* If not cached we need to read it in. */
14248 if (this_type
== NULL
)
14250 struct die_info
*type_die
;
14251 struct dwarf2_cu
*type_cu
= cu
;
14253 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
14254 /* If we found the type now, it's probably because the type came
14255 from an inter-CU reference and the type's CU got expanded before
14257 this_type
= get_die_type (type_die
, type_cu
);
14258 if (this_type
== NULL
)
14259 this_type
= read_type_die_1 (type_die
, type_cu
);
14262 /* If we still don't have a type use an error marker. */
14264 if (this_type
== NULL
)
14266 char *message
, *saved
;
14268 /* read_type_die already issued a complaint. */
14269 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
14271 cu
->header
.offset
.sect_off
,
14272 die
->offset
.sect_off
);
14273 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
14274 message
, strlen (message
));
14277 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
14283 /* Return the type in DIE, CU.
14284 Returns NULL for invalid types.
14286 This first does a lookup in the appropriate type_hash table,
14287 and only reads the die in if necessary.
14289 NOTE: This can be called when reading in partial or full symbols. */
14291 static struct type
*
14292 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
14294 struct type
*this_type
;
14296 this_type
= get_die_type (die
, cu
);
14300 return read_type_die_1 (die
, cu
);
14303 /* Read the type in DIE, CU.
14304 Returns NULL for invalid types. */
14306 static struct type
*
14307 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14309 struct type
*this_type
= NULL
;
14313 case DW_TAG_class_type
:
14314 case DW_TAG_interface_type
:
14315 case DW_TAG_structure_type
:
14316 case DW_TAG_union_type
:
14317 this_type
= read_structure_type (die
, cu
);
14319 case DW_TAG_enumeration_type
:
14320 this_type
= read_enumeration_type (die
, cu
);
14322 case DW_TAG_subprogram
:
14323 case DW_TAG_subroutine_type
:
14324 case DW_TAG_inlined_subroutine
:
14325 this_type
= read_subroutine_type (die
, cu
);
14327 case DW_TAG_array_type
:
14328 this_type
= read_array_type (die
, cu
);
14330 case DW_TAG_set_type
:
14331 this_type
= read_set_type (die
, cu
);
14333 case DW_TAG_pointer_type
:
14334 this_type
= read_tag_pointer_type (die
, cu
);
14336 case DW_TAG_ptr_to_member_type
:
14337 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14339 case DW_TAG_reference_type
:
14340 this_type
= read_tag_reference_type (die
, cu
);
14342 case DW_TAG_const_type
:
14343 this_type
= read_tag_const_type (die
, cu
);
14345 case DW_TAG_volatile_type
:
14346 this_type
= read_tag_volatile_type (die
, cu
);
14348 case DW_TAG_string_type
:
14349 this_type
= read_tag_string_type (die
, cu
);
14351 case DW_TAG_typedef
:
14352 this_type
= read_typedef (die
, cu
);
14354 case DW_TAG_subrange_type
:
14355 this_type
= read_subrange_type (die
, cu
);
14357 case DW_TAG_base_type
:
14358 this_type
= read_base_type (die
, cu
);
14360 case DW_TAG_unspecified_type
:
14361 this_type
= read_unspecified_type (die
, cu
);
14363 case DW_TAG_namespace
:
14364 this_type
= read_namespace_type (die
, cu
);
14366 case DW_TAG_module
:
14367 this_type
= read_module_type (die
, cu
);
14370 complaint (&symfile_complaints
,
14371 _("unexpected tag in read_type_die: '%s'"),
14372 dwarf_tag_name (die
->tag
));
14379 /* See if we can figure out if the class lives in a namespace. We do
14380 this by looking for a member function; its demangled name will
14381 contain namespace info, if there is any.
14382 Return the computed name or NULL.
14383 Space for the result is allocated on the objfile's obstack.
14384 This is the full-die version of guess_partial_die_structure_name.
14385 In this case we know DIE has no useful parent. */
14388 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14390 struct die_info
*spec_die
;
14391 struct dwarf2_cu
*spec_cu
;
14392 struct die_info
*child
;
14395 spec_die
= die_specification (die
, &spec_cu
);
14396 if (spec_die
!= NULL
)
14402 for (child
= die
->child
;
14404 child
= child
->sibling
)
14406 if (child
->tag
== DW_TAG_subprogram
)
14408 struct attribute
*attr
;
14410 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14412 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14416 = language_class_name_from_physname (cu
->language_defn
,
14420 if (actual_name
!= NULL
)
14422 char *die_name
= dwarf2_name (die
, cu
);
14424 if (die_name
!= NULL
14425 && strcmp (die_name
, actual_name
) != 0)
14427 /* Strip off the class name from the full name.
14428 We want the prefix. */
14429 int die_name_len
= strlen (die_name
);
14430 int actual_name_len
= strlen (actual_name
);
14432 /* Test for '::' as a sanity check. */
14433 if (actual_name_len
> die_name_len
+ 2
14434 && actual_name
[actual_name_len
14435 - die_name_len
- 1] == ':')
14437 obsavestring (actual_name
,
14438 actual_name_len
- die_name_len
- 2,
14439 &cu
->objfile
->objfile_obstack
);
14442 xfree (actual_name
);
14451 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14452 prefix part in such case. See
14453 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14456 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14458 struct attribute
*attr
;
14461 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14462 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14465 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14466 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14469 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14471 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14472 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14475 /* dwarf2_name had to be already called. */
14476 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14478 /* Strip the base name, keep any leading namespaces/classes. */
14479 base
= strrchr (DW_STRING (attr
), ':');
14480 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14483 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14484 &cu
->objfile
->objfile_obstack
);
14487 /* Return the name of the namespace/class that DIE is defined within,
14488 or "" if we can't tell. The caller should not xfree the result.
14490 For example, if we're within the method foo() in the following
14500 then determine_prefix on foo's die will return "N::C". */
14502 static const char *
14503 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14505 struct die_info
*parent
, *spec_die
;
14506 struct dwarf2_cu
*spec_cu
;
14507 struct type
*parent_type
;
14510 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14511 && cu
->language
!= language_fortran
)
14514 retval
= anonymous_struct_prefix (die
, cu
);
14518 /* We have to be careful in the presence of DW_AT_specification.
14519 For example, with GCC 3.4, given the code
14523 // Definition of N::foo.
14527 then we'll have a tree of DIEs like this:
14529 1: DW_TAG_compile_unit
14530 2: DW_TAG_namespace // N
14531 3: DW_TAG_subprogram // declaration of N::foo
14532 4: DW_TAG_subprogram // definition of N::foo
14533 DW_AT_specification // refers to die #3
14535 Thus, when processing die #4, we have to pretend that we're in
14536 the context of its DW_AT_specification, namely the contex of die
14539 spec_die
= die_specification (die
, &spec_cu
);
14540 if (spec_die
== NULL
)
14541 parent
= die
->parent
;
14544 parent
= spec_die
->parent
;
14548 if (parent
== NULL
)
14550 else if (parent
->building_fullname
)
14553 const char *parent_name
;
14555 /* It has been seen on RealView 2.2 built binaries,
14556 DW_TAG_template_type_param types actually _defined_ as
14557 children of the parent class:
14560 template class <class Enum> Class{};
14561 Class<enum E> class_e;
14563 1: DW_TAG_class_type (Class)
14564 2: DW_TAG_enumeration_type (E)
14565 3: DW_TAG_enumerator (enum1:0)
14566 3: DW_TAG_enumerator (enum2:1)
14568 2: DW_TAG_template_type_param
14569 DW_AT_type DW_FORM_ref_udata (E)
14571 Besides being broken debug info, it can put GDB into an
14572 infinite loop. Consider:
14574 When we're building the full name for Class<E>, we'll start
14575 at Class, and go look over its template type parameters,
14576 finding E. We'll then try to build the full name of E, and
14577 reach here. We're now trying to build the full name of E,
14578 and look over the parent DIE for containing scope. In the
14579 broken case, if we followed the parent DIE of E, we'd again
14580 find Class, and once again go look at its template type
14581 arguments, etc., etc. Simply don't consider such parent die
14582 as source-level parent of this die (it can't be, the language
14583 doesn't allow it), and break the loop here. */
14584 name
= dwarf2_name (die
, cu
);
14585 parent_name
= dwarf2_name (parent
, cu
);
14586 complaint (&symfile_complaints
,
14587 _("template param type '%s' defined within parent '%s'"),
14588 name
? name
: "<unknown>",
14589 parent_name
? parent_name
: "<unknown>");
14593 switch (parent
->tag
)
14595 case DW_TAG_namespace
:
14596 parent_type
= read_type_die (parent
, cu
);
14597 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14598 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14599 Work around this problem here. */
14600 if (cu
->language
== language_cplus
14601 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14603 /* We give a name to even anonymous namespaces. */
14604 return TYPE_TAG_NAME (parent_type
);
14605 case DW_TAG_class_type
:
14606 case DW_TAG_interface_type
:
14607 case DW_TAG_structure_type
:
14608 case DW_TAG_union_type
:
14609 case DW_TAG_module
:
14610 parent_type
= read_type_die (parent
, cu
);
14611 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14612 return TYPE_TAG_NAME (parent_type
);
14614 /* An anonymous structure is only allowed non-static data
14615 members; no typedefs, no member functions, et cetera.
14616 So it does not need a prefix. */
14618 case DW_TAG_compile_unit
:
14619 case DW_TAG_partial_unit
:
14620 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14621 if (cu
->language
== language_cplus
14622 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14623 && die
->child
!= NULL
14624 && (die
->tag
== DW_TAG_class_type
14625 || die
->tag
== DW_TAG_structure_type
14626 || die
->tag
== DW_TAG_union_type
))
14628 char *name
= guess_full_die_structure_name (die
, cu
);
14634 return determine_prefix (parent
, cu
);
14638 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14639 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14640 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14641 an obconcat, otherwise allocate storage for the result. The CU argument is
14642 used to determine the language and hence, the appropriate separator. */
14644 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14647 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14648 int physname
, struct dwarf2_cu
*cu
)
14650 const char *lead
= "";
14653 if (suffix
== NULL
|| suffix
[0] == '\0'
14654 || prefix
== NULL
|| prefix
[0] == '\0')
14656 else if (cu
->language
== language_java
)
14658 else if (cu
->language
== language_fortran
&& physname
)
14660 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14661 DW_AT_MIPS_linkage_name is preferred and used instead. */
14669 if (prefix
== NULL
)
14671 if (suffix
== NULL
)
14677 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14679 strcpy (retval
, lead
);
14680 strcat (retval
, prefix
);
14681 strcat (retval
, sep
);
14682 strcat (retval
, suffix
);
14687 /* We have an obstack. */
14688 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14692 /* Return sibling of die, NULL if no sibling. */
14694 static struct die_info
*
14695 sibling_die (struct die_info
*die
)
14697 return die
->sibling
;
14700 /* Get name of a die, return NULL if not found. */
14703 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14704 struct obstack
*obstack
)
14706 if (name
&& cu
->language
== language_cplus
)
14708 char *canon_name
= cp_canonicalize_string (name
);
14710 if (canon_name
!= NULL
)
14712 if (strcmp (canon_name
, name
) != 0)
14713 name
= obsavestring (canon_name
, strlen (canon_name
),
14715 xfree (canon_name
);
14722 /* Get name of a die, return NULL if not found. */
14725 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14727 struct attribute
*attr
;
14729 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14730 if ((!attr
|| !DW_STRING (attr
))
14731 && die
->tag
!= DW_TAG_class_type
14732 && die
->tag
!= DW_TAG_interface_type
14733 && die
->tag
!= DW_TAG_structure_type
14734 && die
->tag
!= DW_TAG_union_type
)
14739 case DW_TAG_compile_unit
:
14740 case DW_TAG_partial_unit
:
14741 /* Compilation units have a DW_AT_name that is a filename, not
14742 a source language identifier. */
14743 case DW_TAG_enumeration_type
:
14744 case DW_TAG_enumerator
:
14745 /* These tags always have simple identifiers already; no need
14746 to canonicalize them. */
14747 return DW_STRING (attr
);
14749 case DW_TAG_subprogram
:
14750 /* Java constructors will all be named "<init>", so return
14751 the class name when we see this special case. */
14752 if (cu
->language
== language_java
14753 && DW_STRING (attr
) != NULL
14754 && strcmp (DW_STRING (attr
), "<init>") == 0)
14756 struct dwarf2_cu
*spec_cu
= cu
;
14757 struct die_info
*spec_die
;
14759 /* GCJ will output '<init>' for Java constructor names.
14760 For this special case, return the name of the parent class. */
14762 /* GCJ may output suprogram DIEs with AT_specification set.
14763 If so, use the name of the specified DIE. */
14764 spec_die
= die_specification (die
, &spec_cu
);
14765 if (spec_die
!= NULL
)
14766 return dwarf2_name (spec_die
, spec_cu
);
14771 if (die
->tag
== DW_TAG_class_type
)
14772 return dwarf2_name (die
, cu
);
14774 while (die
->tag
!= DW_TAG_compile_unit
14775 && die
->tag
!= DW_TAG_partial_unit
);
14779 case DW_TAG_class_type
:
14780 case DW_TAG_interface_type
:
14781 case DW_TAG_structure_type
:
14782 case DW_TAG_union_type
:
14783 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14784 structures or unions. These were of the form "._%d" in GCC 4.1,
14785 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14786 and GCC 4.4. We work around this problem by ignoring these. */
14787 if (attr
&& DW_STRING (attr
)
14788 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14789 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14792 /* GCC might emit a nameless typedef that has a linkage name. See
14793 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14794 if (!attr
|| DW_STRING (attr
) == NULL
)
14796 char *demangled
= NULL
;
14798 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14800 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14802 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14805 /* Avoid demangling DW_STRING (attr) the second time on a second
14806 call for the same DIE. */
14807 if (!DW_STRING_IS_CANONICAL (attr
))
14808 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14814 /* FIXME: we already did this for the partial symbol... */
14815 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14816 &cu
->objfile
->objfile_obstack
);
14817 DW_STRING_IS_CANONICAL (attr
) = 1;
14820 /* Strip any leading namespaces/classes, keep only the base name.
14821 DW_AT_name for named DIEs does not contain the prefixes. */
14822 base
= strrchr (DW_STRING (attr
), ':');
14823 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14826 return DW_STRING (attr
);
14835 if (!DW_STRING_IS_CANONICAL (attr
))
14838 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14839 &cu
->objfile
->objfile_obstack
);
14840 DW_STRING_IS_CANONICAL (attr
) = 1;
14842 return DW_STRING (attr
);
14845 /* Return the die that this die in an extension of, or NULL if there
14846 is none. *EXT_CU is the CU containing DIE on input, and the CU
14847 containing the return value on output. */
14849 static struct die_info
*
14850 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14852 struct attribute
*attr
;
14854 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14858 return follow_die_ref (die
, attr
, ext_cu
);
14861 /* Convert a DIE tag into its string name. */
14863 static const char *
14864 dwarf_tag_name (unsigned tag
)
14866 const char *name
= get_DW_TAG_name (tag
);
14869 return "DW_TAG_<unknown>";
14874 /* Convert a DWARF attribute code into its string name. */
14876 static const char *
14877 dwarf_attr_name (unsigned attr
)
14881 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14882 if (attr
== DW_AT_MIPS_fde
)
14883 return "DW_AT_MIPS_fde";
14885 if (attr
== DW_AT_HP_block_index
)
14886 return "DW_AT_HP_block_index";
14889 name
= get_DW_AT_name (attr
);
14892 return "DW_AT_<unknown>";
14897 /* Convert a DWARF value form code into its string name. */
14899 static const char *
14900 dwarf_form_name (unsigned form
)
14902 const char *name
= get_DW_FORM_name (form
);
14905 return "DW_FORM_<unknown>";
14911 dwarf_bool_name (unsigned mybool
)
14919 /* Convert a DWARF type code into its string name. */
14921 static const char *
14922 dwarf_type_encoding_name (unsigned enc
)
14924 const char *name
= get_DW_ATE_name (enc
);
14927 return "DW_ATE_<unknown>";
14933 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14937 print_spaces (indent
, f
);
14938 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14939 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14941 if (die
->parent
!= NULL
)
14943 print_spaces (indent
, f
);
14944 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14945 die
->parent
->offset
.sect_off
);
14948 print_spaces (indent
, f
);
14949 fprintf_unfiltered (f
, " has children: %s\n",
14950 dwarf_bool_name (die
->child
!= NULL
));
14952 print_spaces (indent
, f
);
14953 fprintf_unfiltered (f
, " attributes:\n");
14955 for (i
= 0; i
< die
->num_attrs
; ++i
)
14957 print_spaces (indent
, f
);
14958 fprintf_unfiltered (f
, " %s (%s) ",
14959 dwarf_attr_name (die
->attrs
[i
].name
),
14960 dwarf_form_name (die
->attrs
[i
].form
));
14962 switch (die
->attrs
[i
].form
)
14965 case DW_FORM_GNU_addr_index
:
14966 fprintf_unfiltered (f
, "address: ");
14967 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14969 case DW_FORM_block2
:
14970 case DW_FORM_block4
:
14971 case DW_FORM_block
:
14972 case DW_FORM_block1
:
14973 fprintf_unfiltered (f
, "block: size %d",
14974 DW_BLOCK (&die
->attrs
[i
])->size
);
14976 case DW_FORM_exprloc
:
14977 fprintf_unfiltered (f
, "expression: size %u",
14978 DW_BLOCK (&die
->attrs
[i
])->size
);
14980 case DW_FORM_ref_addr
:
14981 fprintf_unfiltered (f
, "ref address: ");
14982 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14988 case DW_FORM_ref_udata
:
14989 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14990 (long) (DW_UNSND (&die
->attrs
[i
])));
14992 case DW_FORM_data1
:
14993 case DW_FORM_data2
:
14994 case DW_FORM_data4
:
14995 case DW_FORM_data8
:
14996 case DW_FORM_udata
:
14997 case DW_FORM_sdata
:
14998 fprintf_unfiltered (f
, "constant: %s",
14999 pulongest (DW_UNSND (&die
->attrs
[i
])));
15001 case DW_FORM_sec_offset
:
15002 fprintf_unfiltered (f
, "section offset: %s",
15003 pulongest (DW_UNSND (&die
->attrs
[i
])));
15005 case DW_FORM_ref_sig8
:
15006 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15007 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15008 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15010 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15012 case DW_FORM_string
:
15014 case DW_FORM_GNU_str_index
:
15015 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15016 DW_STRING (&die
->attrs
[i
])
15017 ? DW_STRING (&die
->attrs
[i
]) : "",
15018 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15021 if (DW_UNSND (&die
->attrs
[i
]))
15022 fprintf_unfiltered (f
, "flag: TRUE");
15024 fprintf_unfiltered (f
, "flag: FALSE");
15026 case DW_FORM_flag_present
:
15027 fprintf_unfiltered (f
, "flag: TRUE");
15029 case DW_FORM_indirect
:
15030 /* The reader will have reduced the indirect form to
15031 the "base form" so this form should not occur. */
15032 fprintf_unfiltered (f
,
15033 "unexpected attribute form: DW_FORM_indirect");
15036 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15037 die
->attrs
[i
].form
);
15040 fprintf_unfiltered (f
, "\n");
15045 dump_die_for_error (struct die_info
*die
)
15047 dump_die_shallow (gdb_stderr
, 0, die
);
15051 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15053 int indent
= level
* 4;
15055 gdb_assert (die
!= NULL
);
15057 if (level
>= max_level
)
15060 dump_die_shallow (f
, indent
, die
);
15062 if (die
->child
!= NULL
)
15064 print_spaces (indent
, f
);
15065 fprintf_unfiltered (f
, " Children:");
15066 if (level
+ 1 < max_level
)
15068 fprintf_unfiltered (f
, "\n");
15069 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15073 fprintf_unfiltered (f
,
15074 " [not printed, max nesting level reached]\n");
15078 if (die
->sibling
!= NULL
&& level
> 0)
15080 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15084 /* This is called from the pdie macro in gdbinit.in.
15085 It's not static so gcc will keep a copy callable from gdb. */
15088 dump_die (struct die_info
*die
, int max_level
)
15090 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15094 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15098 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15104 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15105 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15108 is_ref_attr (struct attribute
*attr
)
15110 switch (attr
->form
)
15112 case DW_FORM_ref_addr
:
15117 case DW_FORM_ref_udata
:
15124 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15128 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15130 sect_offset retval
= { DW_UNSND (attr
) };
15132 if (is_ref_attr (attr
))
15135 retval
.sect_off
= 0;
15136 complaint (&symfile_complaints
,
15137 _("unsupported die ref attribute form: '%s'"),
15138 dwarf_form_name (attr
->form
));
15142 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15143 * the value held by the attribute is not constant. */
15146 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15148 if (attr
->form
== DW_FORM_sdata
)
15149 return DW_SND (attr
);
15150 else if (attr
->form
== DW_FORM_udata
15151 || attr
->form
== DW_FORM_data1
15152 || attr
->form
== DW_FORM_data2
15153 || attr
->form
== DW_FORM_data4
15154 || attr
->form
== DW_FORM_data8
)
15155 return DW_UNSND (attr
);
15158 complaint (&symfile_complaints
,
15159 _("Attribute value is not a constant (%s)"),
15160 dwarf_form_name (attr
->form
));
15161 return default_value
;
15165 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15166 unit and add it to our queue.
15167 The result is non-zero if PER_CU was queued, otherwise the result is zero
15168 meaning either PER_CU is already queued or it is already loaded. */
15171 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15172 struct dwarf2_per_cu_data
*per_cu
,
15173 enum language pretend_language
)
15175 /* We may arrive here during partial symbol reading, if we need full
15176 DIEs to process an unusual case (e.g. template arguments). Do
15177 not queue PER_CU, just tell our caller to load its DIEs. */
15178 if (dwarf2_per_objfile
->reading_partial_symbols
)
15180 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15185 /* Mark the dependence relation so that we don't flush PER_CU
15187 dwarf2_add_dependence (this_cu
, per_cu
);
15189 /* If it's already on the queue, we have nothing to do. */
15190 if (per_cu
->queued
)
15193 /* If the compilation unit is already loaded, just mark it as
15195 if (per_cu
->cu
!= NULL
)
15197 per_cu
->cu
->last_used
= 0;
15201 /* Add it to the queue. */
15202 queue_comp_unit (per_cu
, pretend_language
);
15207 /* Follow reference or signature attribute ATTR of SRC_DIE.
15208 On entry *REF_CU is the CU of SRC_DIE.
15209 On exit *REF_CU is the CU of the result. */
15211 static struct die_info
*
15212 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15213 struct dwarf2_cu
**ref_cu
)
15215 struct die_info
*die
;
15217 if (is_ref_attr (attr
))
15218 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15219 else if (attr
->form
== DW_FORM_ref_sig8
)
15220 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15223 dump_die_for_error (src_die
);
15224 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15225 (*ref_cu
)->objfile
->name
);
15231 /* Follow reference OFFSET.
15232 On entry *REF_CU is the CU of the source die referencing OFFSET.
15233 On exit *REF_CU is the CU of the result.
15234 Returns NULL if OFFSET is invalid. */
15236 static struct die_info
*
15237 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15239 struct die_info temp_die
;
15240 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15242 gdb_assert (cu
->per_cu
!= NULL
);
15246 if (cu
->per_cu
->is_debug_types
)
15248 /* .debug_types CUs cannot reference anything outside their CU.
15249 If they need to, they have to reference a signatured type via
15250 DW_FORM_ref_sig8. */
15251 if (! offset_in_cu_p (&cu
->header
, offset
))
15254 else if (! offset_in_cu_p (&cu
->header
, offset
))
15256 struct dwarf2_per_cu_data
*per_cu
;
15258 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15260 /* If necessary, add it to the queue and load its DIEs. */
15261 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
15262 load_full_comp_unit (per_cu
, cu
->language
);
15264 target_cu
= per_cu
->cu
;
15266 else if (cu
->dies
== NULL
)
15268 /* We're loading full DIEs during partial symbol reading. */
15269 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15270 load_full_comp_unit (cu
->per_cu
, language_minimal
);
15273 *ref_cu
= target_cu
;
15274 temp_die
.offset
= offset
;
15275 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15278 /* Follow reference attribute ATTR of SRC_DIE.
15279 On entry *REF_CU is the CU of SRC_DIE.
15280 On exit *REF_CU is the CU of the result. */
15282 static struct die_info
*
15283 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15284 struct dwarf2_cu
**ref_cu
)
15286 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15287 struct dwarf2_cu
*cu
= *ref_cu
;
15288 struct die_info
*die
;
15290 die
= follow_die_offset (offset
, ref_cu
);
15292 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15293 "at 0x%x [in module %s]"),
15294 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15299 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15300 Returned value is intended for DW_OP_call*. Returned
15301 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15303 struct dwarf2_locexpr_baton
15304 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15305 struct dwarf2_per_cu_data
*per_cu
,
15306 CORE_ADDR (*get_frame_pc
) (void *baton
),
15309 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15310 struct dwarf2_cu
*cu
;
15311 struct die_info
*die
;
15312 struct attribute
*attr
;
15313 struct dwarf2_locexpr_baton retval
;
15315 dw2_setup (per_cu
->objfile
);
15317 if (per_cu
->cu
== NULL
)
15321 die
= follow_die_offset (offset
, &cu
);
15323 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15324 offset
.sect_off
, per_cu
->objfile
->name
);
15326 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15329 /* DWARF: "If there is no such attribute, then there is no effect.".
15330 DATA is ignored if SIZE is 0. */
15332 retval
.data
= NULL
;
15335 else if (attr_form_is_section_offset (attr
))
15337 struct dwarf2_loclist_baton loclist_baton
;
15338 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15341 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15343 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15345 retval
.size
= size
;
15349 if (!attr_form_is_block (attr
))
15350 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15351 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15352 offset
.sect_off
, per_cu
->objfile
->name
);
15354 retval
.data
= DW_BLOCK (attr
)->data
;
15355 retval
.size
= DW_BLOCK (attr
)->size
;
15357 retval
.per_cu
= cu
->per_cu
;
15359 age_cached_comp_units ();
15364 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15368 dwarf2_get_die_type (cu_offset die_offset
,
15369 struct dwarf2_per_cu_data
*per_cu
)
15371 sect_offset die_offset_sect
;
15373 dw2_setup (per_cu
->objfile
);
15375 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15376 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15379 /* Follow the signature attribute ATTR in SRC_DIE.
15380 On entry *REF_CU is the CU of SRC_DIE.
15381 On exit *REF_CU is the CU of the result. */
15383 static struct die_info
*
15384 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15385 struct dwarf2_cu
**ref_cu
)
15387 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15388 struct die_info temp_die
;
15389 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15390 struct dwarf2_cu
*sig_cu
;
15391 struct die_info
*die
;
15393 /* sig_type will be NULL if the signatured type is missing from
15395 if (sig_type
== NULL
)
15396 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15397 "at 0x%x [in module %s]"),
15398 src_die
->offset
.sect_off
, objfile
->name
);
15400 /* If necessary, add it to the queue and load its DIEs. */
15402 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15403 read_signatured_type (sig_type
);
15405 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15407 sig_cu
= sig_type
->per_cu
.cu
;
15408 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15409 temp_die
.offset
= sig_type
->type_offset_in_section
;
15410 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15411 temp_die
.offset
.sect_off
);
15418 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15419 "from DIE at 0x%x [in module %s]"),
15420 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15423 /* Given an offset of a signatured type, return its signatured_type. */
15425 static struct signatured_type
*
15426 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15427 struct dwarf2_section_info
*section
,
15428 sect_offset offset
)
15430 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15431 unsigned int length
, initial_length_size
;
15432 unsigned int sig_offset
;
15433 struct signatured_type find_entry
, *sig_type
;
15435 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15436 sig_offset
= (initial_length_size
15438 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15439 + 1 /*address_size*/);
15440 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15441 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15443 /* This is only used to lookup previously recorded types.
15444 If we didn't find it, it's our bug. */
15445 gdb_assert (sig_type
!= NULL
);
15446 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15451 /* Load the DIEs associated with type unit PER_CU into memory. */
15454 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15456 struct objfile
*objfile
= per_cu
->objfile
;
15457 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15458 sect_offset offset
= per_cu
->offset
;
15459 struct signatured_type
*sig_type
;
15461 dwarf2_read_section (objfile
, sect
);
15463 /* We have the section offset, but we need the signature to do the
15464 hash table lookup. */
15465 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15466 the signature to assert we found the right one.
15467 Ok, but it's a lot of work. We should simplify things so any needed
15468 assert doesn't require all this clumsiness. */
15469 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15471 gdb_assert (&sig_type
->per_cu
== per_cu
);
15472 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15474 read_signatured_type (sig_type
);
15476 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15479 /* die_reader_func for read_signatured_type.
15480 This is identical to load_full_comp_unit_reader,
15481 but is kept separate for now. */
15484 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15485 gdb_byte
*info_ptr
,
15486 struct die_info
*comp_unit_die
,
15490 struct dwarf2_cu
*cu
= reader
->cu
;
15492 gdb_assert (cu
->die_hash
== NULL
);
15494 htab_create_alloc_ex (cu
->header
.length
/ 12,
15498 &cu
->comp_unit_obstack
,
15499 hashtab_obstack_allocate
,
15500 dummy_obstack_deallocate
);
15503 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15504 &info_ptr
, comp_unit_die
);
15505 cu
->dies
= comp_unit_die
;
15506 /* comp_unit_die is not stored in die_hash, no need. */
15508 /* We try not to read any attributes in this function, because not
15509 all CUs needed for references have been loaded yet, and symbol
15510 table processing isn't initialized. But we have to set the CU language,
15511 or we won't be able to build types correctly.
15512 Similarly, if we do not read the producer, we can not apply
15513 producer-specific interpretation. */
15514 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15517 /* Read in a signatured type and build its CU and DIEs.
15518 If the type is a stub for the real type in a DWO file,
15519 read in the real type from the DWO file as well. */
15522 read_signatured_type (struct signatured_type
*sig_type
)
15524 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15526 gdb_assert (per_cu
->is_debug_types
);
15527 gdb_assert (per_cu
->cu
== NULL
);
15529 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15532 /* Decode simple location descriptions.
15533 Given a pointer to a dwarf block that defines a location, compute
15534 the location and return the value.
15536 NOTE drow/2003-11-18: This function is called in two situations
15537 now: for the address of static or global variables (partial symbols
15538 only) and for offsets into structures which are expected to be
15539 (more or less) constant. The partial symbol case should go away,
15540 and only the constant case should remain. That will let this
15541 function complain more accurately. A few special modes are allowed
15542 without complaint for global variables (for instance, global
15543 register values and thread-local values).
15545 A location description containing no operations indicates that the
15546 object is optimized out. The return value is 0 for that case.
15547 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15548 callers will only want a very basic result and this can become a
15551 Note that stack[0] is unused except as a default error return. */
15554 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15556 struct objfile
*objfile
= cu
->objfile
;
15558 int size
= blk
->size
;
15559 gdb_byte
*data
= blk
->data
;
15560 CORE_ADDR stack
[64];
15562 unsigned int bytes_read
, unsnd
;
15568 stack
[++stacki
] = 0;
15607 stack
[++stacki
] = op
- DW_OP_lit0
;
15642 stack
[++stacki
] = op
- DW_OP_reg0
;
15644 dwarf2_complex_location_expr_complaint ();
15648 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15650 stack
[++stacki
] = unsnd
;
15652 dwarf2_complex_location_expr_complaint ();
15656 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15661 case DW_OP_const1u
:
15662 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15666 case DW_OP_const1s
:
15667 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15671 case DW_OP_const2u
:
15672 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15676 case DW_OP_const2s
:
15677 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15681 case DW_OP_const4u
:
15682 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15686 case DW_OP_const4s
:
15687 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15691 case DW_OP_const8u
:
15692 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15697 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15703 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15708 stack
[stacki
+ 1] = stack
[stacki
];
15713 stack
[stacki
- 1] += stack
[stacki
];
15717 case DW_OP_plus_uconst
:
15718 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15724 stack
[stacki
- 1] -= stack
[stacki
];
15729 /* If we're not the last op, then we definitely can't encode
15730 this using GDB's address_class enum. This is valid for partial
15731 global symbols, although the variable's address will be bogus
15734 dwarf2_complex_location_expr_complaint ();
15737 case DW_OP_GNU_push_tls_address
:
15738 /* The top of the stack has the offset from the beginning
15739 of the thread control block at which the variable is located. */
15740 /* Nothing should follow this operator, so the top of stack would
15742 /* This is valid for partial global symbols, but the variable's
15743 address will be bogus in the psymtab. Make it always at least
15744 non-zero to not look as a variable garbage collected by linker
15745 which have DW_OP_addr 0. */
15747 dwarf2_complex_location_expr_complaint ();
15751 case DW_OP_GNU_uninit
:
15754 case DW_OP_GNU_addr_index
:
15755 case DW_OP_GNU_const_index
:
15756 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15763 const char *name
= get_DW_OP_name (op
);
15766 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15769 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15773 return (stack
[stacki
]);
15776 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15777 outside of the allocated space. Also enforce minimum>0. */
15778 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15780 complaint (&symfile_complaints
,
15781 _("location description stack overflow"));
15787 complaint (&symfile_complaints
,
15788 _("location description stack underflow"));
15792 return (stack
[stacki
]);
15795 /* memory allocation interface */
15797 static struct dwarf_block
*
15798 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15800 struct dwarf_block
*blk
;
15802 blk
= (struct dwarf_block
*)
15803 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15807 static struct die_info
*
15808 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15810 struct die_info
*die
;
15811 size_t size
= sizeof (struct die_info
);
15814 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15816 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15817 memset (die
, 0, sizeof (struct die_info
));
15822 /* Macro support. */
15824 /* Return the full name of file number I in *LH's file name table.
15825 Use COMP_DIR as the name of the current directory of the
15826 compilation. The result is allocated using xmalloc; the caller is
15827 responsible for freeing it. */
15829 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15831 /* Is the file number a valid index into the line header's file name
15832 table? Remember that file numbers start with one, not zero. */
15833 if (1 <= file
&& file
<= lh
->num_file_names
)
15835 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15837 if (IS_ABSOLUTE_PATH (fe
->name
))
15838 return xstrdup (fe
->name
);
15846 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15852 dir_len
= strlen (dir
);
15853 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15854 strcpy (full_name
, dir
);
15855 full_name
[dir_len
] = '/';
15856 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15860 return xstrdup (fe
->name
);
15865 /* The compiler produced a bogus file number. We can at least
15866 record the macro definitions made in the file, even if we
15867 won't be able to find the file by name. */
15868 char fake_name
[80];
15870 sprintf (fake_name
, "<bad macro file number %d>", file
);
15872 complaint (&symfile_complaints
,
15873 _("bad file number in macro information (%d)"),
15876 return xstrdup (fake_name
);
15881 static struct macro_source_file
*
15882 macro_start_file (int file
, int line
,
15883 struct macro_source_file
*current_file
,
15884 const char *comp_dir
,
15885 struct line_header
*lh
, struct objfile
*objfile
)
15887 /* The full name of this source file. */
15888 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15890 /* We don't create a macro table for this compilation unit
15891 at all until we actually get a filename. */
15892 if (! pending_macros
)
15893 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15894 objfile
->macro_cache
);
15896 if (! current_file
)
15898 /* If we have no current file, then this must be the start_file
15899 directive for the compilation unit's main source file. */
15900 current_file
= macro_set_main (pending_macros
, full_name
);
15901 macro_define_special (pending_macros
);
15904 current_file
= macro_include (current_file
, line
, full_name
);
15908 return current_file
;
15912 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15913 followed by a null byte. */
15915 copy_string (const char *buf
, int len
)
15917 char *s
= xmalloc (len
+ 1);
15919 memcpy (s
, buf
, len
);
15925 static const char *
15926 consume_improper_spaces (const char *p
, const char *body
)
15930 complaint (&symfile_complaints
,
15931 _("macro definition contains spaces "
15932 "in formal argument list:\n`%s'"),
15944 parse_macro_definition (struct macro_source_file
*file
, int line
,
15949 /* The body string takes one of two forms. For object-like macro
15950 definitions, it should be:
15952 <macro name> " " <definition>
15954 For function-like macro definitions, it should be:
15956 <macro name> "() " <definition>
15958 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15960 Spaces may appear only where explicitly indicated, and in the
15963 The Dwarf 2 spec says that an object-like macro's name is always
15964 followed by a space, but versions of GCC around March 2002 omit
15965 the space when the macro's definition is the empty string.
15967 The Dwarf 2 spec says that there should be no spaces between the
15968 formal arguments in a function-like macro's formal argument list,
15969 but versions of GCC around March 2002 include spaces after the
15973 /* Find the extent of the macro name. The macro name is terminated
15974 by either a space or null character (for an object-like macro) or
15975 an opening paren (for a function-like macro). */
15976 for (p
= body
; *p
; p
++)
15977 if (*p
== ' ' || *p
== '(')
15980 if (*p
== ' ' || *p
== '\0')
15982 /* It's an object-like macro. */
15983 int name_len
= p
- body
;
15984 char *name
= copy_string (body
, name_len
);
15985 const char *replacement
;
15988 replacement
= body
+ name_len
+ 1;
15991 dwarf2_macro_malformed_definition_complaint (body
);
15992 replacement
= body
+ name_len
;
15995 macro_define_object (file
, line
, name
, replacement
);
15999 else if (*p
== '(')
16001 /* It's a function-like macro. */
16002 char *name
= copy_string (body
, p
- body
);
16005 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16009 p
= consume_improper_spaces (p
, body
);
16011 /* Parse the formal argument list. */
16012 while (*p
&& *p
!= ')')
16014 /* Find the extent of the current argument name. */
16015 const char *arg_start
= p
;
16017 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16020 if (! *p
|| p
== arg_start
)
16021 dwarf2_macro_malformed_definition_complaint (body
);
16024 /* Make sure argv has room for the new argument. */
16025 if (argc
>= argv_size
)
16028 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16031 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16034 p
= consume_improper_spaces (p
, body
);
16036 /* Consume the comma, if present. */
16041 p
= consume_improper_spaces (p
, body
);
16050 /* Perfectly formed definition, no complaints. */
16051 macro_define_function (file
, line
, name
,
16052 argc
, (const char **) argv
,
16054 else if (*p
== '\0')
16056 /* Complain, but do define it. */
16057 dwarf2_macro_malformed_definition_complaint (body
);
16058 macro_define_function (file
, line
, name
,
16059 argc
, (const char **) argv
,
16063 /* Just complain. */
16064 dwarf2_macro_malformed_definition_complaint (body
);
16067 /* Just complain. */
16068 dwarf2_macro_malformed_definition_complaint (body
);
16074 for (i
= 0; i
< argc
; i
++)
16080 dwarf2_macro_malformed_definition_complaint (body
);
16083 /* Skip some bytes from BYTES according to the form given in FORM.
16084 Returns the new pointer. */
16087 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16088 enum dwarf_form form
,
16089 unsigned int offset_size
,
16090 struct dwarf2_section_info
*section
)
16092 unsigned int bytes_read
;
16096 case DW_FORM_data1
:
16101 case DW_FORM_data2
:
16105 case DW_FORM_data4
:
16109 case DW_FORM_data8
:
16113 case DW_FORM_string
:
16114 read_direct_string (abfd
, bytes
, &bytes_read
);
16115 bytes
+= bytes_read
;
16118 case DW_FORM_sec_offset
:
16120 bytes
+= offset_size
;
16123 case DW_FORM_block
:
16124 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16125 bytes
+= bytes_read
;
16128 case DW_FORM_block1
:
16129 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16131 case DW_FORM_block2
:
16132 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16134 case DW_FORM_block4
:
16135 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16138 case DW_FORM_sdata
:
16139 case DW_FORM_udata
:
16140 case DW_FORM_GNU_addr_index
:
16141 case DW_FORM_GNU_str_index
:
16142 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16145 dwarf2_section_buffer_overflow_complaint (section
);
16153 complaint (&symfile_complaints
,
16154 _("invalid form 0x%x in `%s'"),
16156 section
->asection
->name
);
16164 /* A helper for dwarf_decode_macros that handles skipping an unknown
16165 opcode. Returns an updated pointer to the macro data buffer; or,
16166 on error, issues a complaint and returns NULL. */
16169 skip_unknown_opcode (unsigned int opcode
,
16170 gdb_byte
**opcode_definitions
,
16171 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16173 unsigned int offset_size
,
16174 struct dwarf2_section_info
*section
)
16176 unsigned int bytes_read
, i
;
16180 if (opcode_definitions
[opcode
] == NULL
)
16182 complaint (&symfile_complaints
,
16183 _("unrecognized DW_MACFINO opcode 0x%x"),
16188 defn
= opcode_definitions
[opcode
];
16189 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16190 defn
+= bytes_read
;
16192 for (i
= 0; i
< arg
; ++i
)
16194 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16196 if (mac_ptr
== NULL
)
16198 /* skip_form_bytes already issued the complaint. */
16206 /* A helper function which parses the header of a macro section.
16207 If the macro section is the extended (for now called "GNU") type,
16208 then this updates *OFFSET_SIZE. Returns a pointer to just after
16209 the header, or issues a complaint and returns NULL on error. */
16212 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16215 unsigned int *offset_size
,
16216 int section_is_gnu
)
16218 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16220 if (section_is_gnu
)
16222 unsigned int version
, flags
;
16224 version
= read_2_bytes (abfd
, mac_ptr
);
16227 complaint (&symfile_complaints
,
16228 _("unrecognized version `%d' in .debug_macro section"),
16234 flags
= read_1_byte (abfd
, mac_ptr
);
16236 *offset_size
= (flags
& 1) ? 8 : 4;
16238 if ((flags
& 2) != 0)
16239 /* We don't need the line table offset. */
16240 mac_ptr
+= *offset_size
;
16242 /* Vendor opcode descriptions. */
16243 if ((flags
& 4) != 0)
16245 unsigned int i
, count
;
16247 count
= read_1_byte (abfd
, mac_ptr
);
16249 for (i
= 0; i
< count
; ++i
)
16251 unsigned int opcode
, bytes_read
;
16254 opcode
= read_1_byte (abfd
, mac_ptr
);
16256 opcode_definitions
[opcode
] = mac_ptr
;
16257 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16258 mac_ptr
+= bytes_read
;
16267 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16268 including DW_MACRO_GNU_transparent_include. */
16271 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16272 struct macro_source_file
*current_file
,
16273 struct line_header
*lh
, char *comp_dir
,
16274 struct dwarf2_section_info
*section
,
16275 int section_is_gnu
,
16276 unsigned int offset_size
,
16277 struct objfile
*objfile
,
16278 htab_t include_hash
)
16280 enum dwarf_macro_record_type macinfo_type
;
16281 int at_commandline
;
16282 gdb_byte
*opcode_definitions
[256];
16284 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16285 &offset_size
, section_is_gnu
);
16286 if (mac_ptr
== NULL
)
16288 /* We already issued a complaint. */
16292 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16293 GDB is still reading the definitions from command line. First
16294 DW_MACINFO_start_file will need to be ignored as it was already executed
16295 to create CURRENT_FILE for the main source holding also the command line
16296 definitions. On first met DW_MACINFO_start_file this flag is reset to
16297 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16299 at_commandline
= 1;
16303 /* Do we at least have room for a macinfo type byte? */
16304 if (mac_ptr
>= mac_end
)
16306 dwarf2_section_buffer_overflow_complaint (section
);
16310 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16313 /* Note that we rely on the fact that the corresponding GNU and
16314 DWARF constants are the same. */
16315 switch (macinfo_type
)
16317 /* A zero macinfo type indicates the end of the macro
16322 case DW_MACRO_GNU_define
:
16323 case DW_MACRO_GNU_undef
:
16324 case DW_MACRO_GNU_define_indirect
:
16325 case DW_MACRO_GNU_undef_indirect
:
16327 unsigned int bytes_read
;
16332 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16333 mac_ptr
+= bytes_read
;
16335 if (macinfo_type
== DW_MACRO_GNU_define
16336 || macinfo_type
== DW_MACRO_GNU_undef
)
16338 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16339 mac_ptr
+= bytes_read
;
16343 LONGEST str_offset
;
16345 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16346 mac_ptr
+= offset_size
;
16348 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16351 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16352 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16353 if (! current_file
)
16355 /* DWARF violation as no main source is present. */
16356 complaint (&symfile_complaints
,
16357 _("debug info with no main source gives macro %s "
16359 is_define
? _("definition") : _("undefinition"),
16363 if ((line
== 0 && !at_commandline
)
16364 || (line
!= 0 && at_commandline
))
16365 complaint (&symfile_complaints
,
16366 _("debug info gives %s macro %s with %s line %d: %s"),
16367 at_commandline
? _("command-line") : _("in-file"),
16368 is_define
? _("definition") : _("undefinition"),
16369 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16372 parse_macro_definition (current_file
, line
, body
);
16375 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16376 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16377 macro_undef (current_file
, line
, body
);
16382 case DW_MACRO_GNU_start_file
:
16384 unsigned int bytes_read
;
16387 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16388 mac_ptr
+= bytes_read
;
16389 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16390 mac_ptr
+= bytes_read
;
16392 if ((line
== 0 && !at_commandline
)
16393 || (line
!= 0 && at_commandline
))
16394 complaint (&symfile_complaints
,
16395 _("debug info gives source %d included "
16396 "from %s at %s line %d"),
16397 file
, at_commandline
? _("command-line") : _("file"),
16398 line
== 0 ? _("zero") : _("non-zero"), line
);
16400 if (at_commandline
)
16402 /* This DW_MACRO_GNU_start_file was executed in the
16404 at_commandline
= 0;
16407 current_file
= macro_start_file (file
, line
,
16408 current_file
, comp_dir
,
16413 case DW_MACRO_GNU_end_file
:
16414 if (! current_file
)
16415 complaint (&symfile_complaints
,
16416 _("macro debug info has an unmatched "
16417 "`close_file' directive"));
16420 current_file
= current_file
->included_by
;
16421 if (! current_file
)
16423 enum dwarf_macro_record_type next_type
;
16425 /* GCC circa March 2002 doesn't produce the zero
16426 type byte marking the end of the compilation
16427 unit. Complain if it's not there, but exit no
16430 /* Do we at least have room for a macinfo type byte? */
16431 if (mac_ptr
>= mac_end
)
16433 dwarf2_section_buffer_overflow_complaint (section
);
16437 /* We don't increment mac_ptr here, so this is just
16439 next_type
= read_1_byte (abfd
, mac_ptr
);
16440 if (next_type
!= 0)
16441 complaint (&symfile_complaints
,
16442 _("no terminating 0-type entry for "
16443 "macros in `.debug_macinfo' section"));
16450 case DW_MACRO_GNU_transparent_include
:
16455 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16456 mac_ptr
+= offset_size
;
16458 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16461 /* This has actually happened; see
16462 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16463 complaint (&symfile_complaints
,
16464 _("recursive DW_MACRO_GNU_transparent_include in "
16465 ".debug_macro section"));
16471 dwarf_decode_macro_bytes (abfd
,
16472 section
->buffer
+ offset
,
16473 mac_end
, current_file
,
16475 section
, section_is_gnu
,
16476 offset_size
, objfile
, include_hash
);
16478 htab_remove_elt (include_hash
, mac_ptr
);
16483 case DW_MACINFO_vendor_ext
:
16484 if (!section_is_gnu
)
16486 unsigned int bytes_read
;
16489 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16490 mac_ptr
+= bytes_read
;
16491 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16492 mac_ptr
+= bytes_read
;
16494 /* We don't recognize any vendor extensions. */
16500 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16501 mac_ptr
, mac_end
, abfd
, offset_size
,
16503 if (mac_ptr
== NULL
)
16507 } while (macinfo_type
!= 0);
16511 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
16512 char *comp_dir
, int section_is_gnu
)
16514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16515 struct line_header
*lh
= cu
->line_header
;
16517 gdb_byte
*mac_ptr
, *mac_end
;
16518 struct macro_source_file
*current_file
= 0;
16519 enum dwarf_macro_record_type macinfo_type
;
16520 unsigned int offset_size
= cu
->header
.offset_size
;
16521 gdb_byte
*opcode_definitions
[256];
16522 struct cleanup
*cleanup
;
16523 htab_t include_hash
;
16525 struct dwarf2_section_info
*section
;
16526 const char *section_name
;
16528 if (cu
->dwo_unit
!= NULL
)
16530 if (section_is_gnu
)
16532 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
16533 section_name
= ".debug_macro.dwo";
16537 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
16538 section_name
= ".debug_macinfo.dwo";
16543 if (section_is_gnu
)
16545 section
= &dwarf2_per_objfile
->macro
;
16546 section_name
= ".debug_macro";
16550 section
= &dwarf2_per_objfile
->macinfo
;
16551 section_name
= ".debug_macinfo";
16555 dwarf2_read_section (objfile
, section
);
16556 if (section
->buffer
== NULL
)
16558 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16561 abfd
= section
->asection
->owner
;
16563 /* First pass: Find the name of the base filename.
16564 This filename is needed in order to process all macros whose definition
16565 (or undefinition) comes from the command line. These macros are defined
16566 before the first DW_MACINFO_start_file entry, and yet still need to be
16567 associated to the base file.
16569 To determine the base file name, we scan the macro definitions until we
16570 reach the first DW_MACINFO_start_file entry. We then initialize
16571 CURRENT_FILE accordingly so that any macro definition found before the
16572 first DW_MACINFO_start_file can still be associated to the base file. */
16574 mac_ptr
= section
->buffer
+ offset
;
16575 mac_end
= section
->buffer
+ section
->size
;
16577 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16578 &offset_size
, section_is_gnu
);
16579 if (mac_ptr
== NULL
)
16581 /* We already issued a complaint. */
16587 /* Do we at least have room for a macinfo type byte? */
16588 if (mac_ptr
>= mac_end
)
16590 /* Complaint is printed during the second pass as GDB will probably
16591 stop the first pass earlier upon finding
16592 DW_MACINFO_start_file. */
16596 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16599 /* Note that we rely on the fact that the corresponding GNU and
16600 DWARF constants are the same. */
16601 switch (macinfo_type
)
16603 /* A zero macinfo type indicates the end of the macro
16608 case DW_MACRO_GNU_define
:
16609 case DW_MACRO_GNU_undef
:
16610 /* Only skip the data by MAC_PTR. */
16612 unsigned int bytes_read
;
16614 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16615 mac_ptr
+= bytes_read
;
16616 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16617 mac_ptr
+= bytes_read
;
16621 case DW_MACRO_GNU_start_file
:
16623 unsigned int bytes_read
;
16626 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16627 mac_ptr
+= bytes_read
;
16628 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16629 mac_ptr
+= bytes_read
;
16631 current_file
= macro_start_file (file
, line
, current_file
,
16632 comp_dir
, lh
, objfile
);
16636 case DW_MACRO_GNU_end_file
:
16637 /* No data to skip by MAC_PTR. */
16640 case DW_MACRO_GNU_define_indirect
:
16641 case DW_MACRO_GNU_undef_indirect
:
16643 unsigned int bytes_read
;
16645 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16646 mac_ptr
+= bytes_read
;
16647 mac_ptr
+= offset_size
;
16651 case DW_MACRO_GNU_transparent_include
:
16652 /* Note that, according to the spec, a transparent include
16653 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16654 skip this opcode. */
16655 mac_ptr
+= offset_size
;
16658 case DW_MACINFO_vendor_ext
:
16659 /* Only skip the data by MAC_PTR. */
16660 if (!section_is_gnu
)
16662 unsigned int bytes_read
;
16664 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16665 mac_ptr
+= bytes_read
;
16666 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16667 mac_ptr
+= bytes_read
;
16672 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16673 mac_ptr
, mac_end
, abfd
, offset_size
,
16675 if (mac_ptr
== NULL
)
16679 } while (macinfo_type
!= 0 && current_file
== NULL
);
16681 /* Second pass: Process all entries.
16683 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16684 command-line macro definitions/undefinitions. This flag is unset when we
16685 reach the first DW_MACINFO_start_file entry. */
16687 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16688 NULL
, xcalloc
, xfree
);
16689 cleanup
= make_cleanup_htab_delete (include_hash
);
16690 mac_ptr
= section
->buffer
+ offset
;
16691 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16693 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16694 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16695 offset_size
, objfile
, include_hash
);
16696 do_cleanups (cleanup
);
16699 /* Check if the attribute's form is a DW_FORM_block*
16700 if so return true else false. */
16703 attr_form_is_block (struct attribute
*attr
)
16705 return (attr
== NULL
? 0 :
16706 attr
->form
== DW_FORM_block1
16707 || attr
->form
== DW_FORM_block2
16708 || attr
->form
== DW_FORM_block4
16709 || attr
->form
== DW_FORM_block
16710 || attr
->form
== DW_FORM_exprloc
);
16713 /* Return non-zero if ATTR's value is a section offset --- classes
16714 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16715 You may use DW_UNSND (attr) to retrieve such offsets.
16717 Section 7.5.4, "Attribute Encodings", explains that no attribute
16718 may have a value that belongs to more than one of these classes; it
16719 would be ambiguous if we did, because we use the same forms for all
16723 attr_form_is_section_offset (struct attribute
*attr
)
16725 return (attr
->form
== DW_FORM_data4
16726 || attr
->form
== DW_FORM_data8
16727 || attr
->form
== DW_FORM_sec_offset
);
16730 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16731 zero otherwise. When this function returns true, you can apply
16732 dwarf2_get_attr_constant_value to it.
16734 However, note that for some attributes you must check
16735 attr_form_is_section_offset before using this test. DW_FORM_data4
16736 and DW_FORM_data8 are members of both the constant class, and of
16737 the classes that contain offsets into other debug sections
16738 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16739 that, if an attribute's can be either a constant or one of the
16740 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16741 taken as section offsets, not constants. */
16744 attr_form_is_constant (struct attribute
*attr
)
16746 switch (attr
->form
)
16748 case DW_FORM_sdata
:
16749 case DW_FORM_udata
:
16750 case DW_FORM_data1
:
16751 case DW_FORM_data2
:
16752 case DW_FORM_data4
:
16753 case DW_FORM_data8
:
16760 /* Return the .debug_loc section to use for CU.
16761 For DWO files use .debug_loc.dwo. */
16763 static struct dwarf2_section_info
*
16764 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16767 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16768 return &dwarf2_per_objfile
->loc
;
16771 /* A helper function that fills in a dwarf2_loclist_baton. */
16774 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16775 struct dwarf2_loclist_baton
*baton
,
16776 struct attribute
*attr
)
16778 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16780 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16782 baton
->per_cu
= cu
->per_cu
;
16783 gdb_assert (baton
->per_cu
);
16784 /* We don't know how long the location list is, but make sure we
16785 don't run off the edge of the section. */
16786 baton
->size
= section
->size
- DW_UNSND (attr
);
16787 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16788 baton
->base_address
= cu
->base_address
;
16789 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16793 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16794 struct dwarf2_cu
*cu
)
16796 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16797 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16799 if (attr_form_is_section_offset (attr
)
16800 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16801 the section. If so, fall through to the complaint in the
16803 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16805 struct dwarf2_loclist_baton
*baton
;
16807 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16808 sizeof (struct dwarf2_loclist_baton
));
16810 fill_in_loclist_baton (cu
, baton
, attr
);
16812 if (cu
->base_known
== 0)
16813 complaint (&symfile_complaints
,
16814 _("Location list used without "
16815 "specifying the CU base address."));
16817 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16818 SYMBOL_LOCATION_BATON (sym
) = baton
;
16822 struct dwarf2_locexpr_baton
*baton
;
16824 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16825 sizeof (struct dwarf2_locexpr_baton
));
16826 baton
->per_cu
= cu
->per_cu
;
16827 gdb_assert (baton
->per_cu
);
16829 if (attr_form_is_block (attr
))
16831 /* Note that we're just copying the block's data pointer
16832 here, not the actual data. We're still pointing into the
16833 info_buffer for SYM's objfile; right now we never release
16834 that buffer, but when we do clean up properly this may
16836 baton
->size
= DW_BLOCK (attr
)->size
;
16837 baton
->data
= DW_BLOCK (attr
)->data
;
16841 dwarf2_invalid_attrib_class_complaint ("location description",
16842 SYMBOL_NATURAL_NAME (sym
));
16846 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16847 SYMBOL_LOCATION_BATON (sym
) = baton
;
16851 /* Return the OBJFILE associated with the compilation unit CU. If CU
16852 came from a separate debuginfo file, then the master objfile is
16856 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16858 struct objfile
*objfile
= per_cu
->objfile
;
16860 /* Return the master objfile, so that we can report and look up the
16861 correct file containing this variable. */
16862 if (objfile
->separate_debug_objfile_backlink
)
16863 objfile
= objfile
->separate_debug_objfile_backlink
;
16868 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16869 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16870 CU_HEADERP first. */
16872 static const struct comp_unit_head
*
16873 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16874 struct dwarf2_per_cu_data
*per_cu
)
16876 gdb_byte
*info_ptr
;
16879 return &per_cu
->cu
->header
;
16881 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
16883 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16884 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
16889 /* Return the address size given in the compilation unit header for CU. */
16892 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16894 struct comp_unit_head cu_header_local
;
16895 const struct comp_unit_head
*cu_headerp
;
16897 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16899 return cu_headerp
->addr_size
;
16902 /* Return the offset size given in the compilation unit header for CU. */
16905 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16907 struct comp_unit_head cu_header_local
;
16908 const struct comp_unit_head
*cu_headerp
;
16910 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16912 return cu_headerp
->offset_size
;
16915 /* See its dwarf2loc.h declaration. */
16918 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16920 struct comp_unit_head cu_header_local
;
16921 const struct comp_unit_head
*cu_headerp
;
16923 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16925 if (cu_headerp
->version
== 2)
16926 return cu_headerp
->addr_size
;
16928 return cu_headerp
->offset_size
;
16931 /* Return the text offset of the CU. The returned offset comes from
16932 this CU's objfile. If this objfile came from a separate debuginfo
16933 file, then the offset may be different from the corresponding
16934 offset in the parent objfile. */
16937 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16939 struct objfile
*objfile
= per_cu
->objfile
;
16941 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16944 /* Locate the .debug_info compilation unit from CU's objfile which contains
16945 the DIE at OFFSET. Raises an error on failure. */
16947 static struct dwarf2_per_cu_data
*
16948 dwarf2_find_containing_comp_unit (sect_offset offset
,
16949 struct objfile
*objfile
)
16951 struct dwarf2_per_cu_data
*this_cu
;
16955 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16958 int mid
= low
+ (high
- low
) / 2;
16960 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16961 >= offset
.sect_off
)
16966 gdb_assert (low
== high
);
16967 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16971 error (_("Dwarf Error: could not find partial DIE containing "
16972 "offset 0x%lx [in module %s]"),
16973 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16975 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16976 <= offset
.sect_off
);
16977 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16981 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16982 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16983 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16984 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16985 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16990 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16993 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16995 memset (cu
, 0, sizeof (*cu
));
16997 cu
->per_cu
= per_cu
;
16998 cu
->objfile
= per_cu
->objfile
;
16999 obstack_init (&cu
->comp_unit_obstack
);
17002 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17005 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17006 enum language pretend_language
)
17008 struct attribute
*attr
;
17010 /* Set the language we're debugging. */
17011 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17013 set_cu_language (DW_UNSND (attr
), cu
);
17016 cu
->language
= pretend_language
;
17017 cu
->language_defn
= language_def (cu
->language
);
17020 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17022 cu
->producer
= DW_STRING (attr
);
17025 /* Release one cached compilation unit, CU. We unlink it from the tree
17026 of compilation units, but we don't remove it from the read_in_chain;
17027 the caller is responsible for that.
17028 NOTE: DATA is a void * because this function is also used as a
17029 cleanup routine. */
17032 free_heap_comp_unit (void *data
)
17034 struct dwarf2_cu
*cu
= data
;
17036 gdb_assert (cu
->per_cu
!= NULL
);
17037 cu
->per_cu
->cu
= NULL
;
17040 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17045 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17046 when we're finished with it. We can't free the pointer itself, but be
17047 sure to unlink it from the cache. Also release any associated storage. */
17050 free_stack_comp_unit (void *data
)
17052 struct dwarf2_cu
*cu
= data
;
17054 gdb_assert (cu
->per_cu
!= NULL
);
17055 cu
->per_cu
->cu
= NULL
;
17058 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17059 cu
->partial_dies
= NULL
;
17062 /* Free all cached compilation units. */
17065 free_cached_comp_units (void *data
)
17067 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17069 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17070 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17071 while (per_cu
!= NULL
)
17073 struct dwarf2_per_cu_data
*next_cu
;
17075 next_cu
= per_cu
->cu
->read_in_chain
;
17077 free_heap_comp_unit (per_cu
->cu
);
17078 *last_chain
= next_cu
;
17084 /* Increase the age counter on each cached compilation unit, and free
17085 any that are too old. */
17088 age_cached_comp_units (void)
17090 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17092 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17093 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17094 while (per_cu
!= NULL
)
17096 per_cu
->cu
->last_used
++;
17097 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17098 dwarf2_mark (per_cu
->cu
);
17099 per_cu
= per_cu
->cu
->read_in_chain
;
17102 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17103 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17104 while (per_cu
!= NULL
)
17106 struct dwarf2_per_cu_data
*next_cu
;
17108 next_cu
= per_cu
->cu
->read_in_chain
;
17110 if (!per_cu
->cu
->mark
)
17112 free_heap_comp_unit (per_cu
->cu
);
17113 *last_chain
= next_cu
;
17116 last_chain
= &per_cu
->cu
->read_in_chain
;
17122 /* Remove a single compilation unit from the cache. */
17125 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17127 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17129 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17130 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17131 while (per_cu
!= NULL
)
17133 struct dwarf2_per_cu_data
*next_cu
;
17135 next_cu
= per_cu
->cu
->read_in_chain
;
17137 if (per_cu
== target_per_cu
)
17139 free_heap_comp_unit (per_cu
->cu
);
17141 *last_chain
= next_cu
;
17145 last_chain
= &per_cu
->cu
->read_in_chain
;
17151 /* Release all extra memory associated with OBJFILE. */
17154 dwarf2_free_objfile (struct objfile
*objfile
)
17156 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17158 if (dwarf2_per_objfile
== NULL
)
17161 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17162 free_cached_comp_units (NULL
);
17164 if (dwarf2_per_objfile
->quick_file_names_table
)
17165 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17167 /* Everything else should be on the objfile obstack. */
17170 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17171 We store these in a hash table separate from the DIEs, and preserve them
17172 when the DIEs are flushed out of cache.
17174 The CU "per_cu" pointer is needed because offset alone is not enough to
17175 uniquely identify the type. A file may have multiple .debug_types sections,
17176 or the type may come from a DWO file. We have to use something in
17177 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17178 routine, get_die_type_at_offset, from outside this file, and thus won't
17179 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17182 struct dwarf2_per_cu_offset_and_type
17184 const struct dwarf2_per_cu_data
*per_cu
;
17185 sect_offset offset
;
17189 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17192 per_cu_offset_and_type_hash (const void *item
)
17194 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17196 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17199 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17202 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17204 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17205 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17207 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17208 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17211 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17212 table if necessary. For convenience, return TYPE.
17214 The DIEs reading must have careful ordering to:
17215 * Not cause infite loops trying to read in DIEs as a prerequisite for
17216 reading current DIE.
17217 * Not trying to dereference contents of still incompletely read in types
17218 while reading in other DIEs.
17219 * Enable referencing still incompletely read in types just by a pointer to
17220 the type without accessing its fields.
17222 Therefore caller should follow these rules:
17223 * Try to fetch any prerequisite types we may need to build this DIE type
17224 before building the type and calling set_die_type.
17225 * After building type call set_die_type for current DIE as soon as
17226 possible before fetching more types to complete the current type.
17227 * Make the type as complete as possible before fetching more types. */
17229 static struct type
*
17230 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17232 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17233 struct objfile
*objfile
= cu
->objfile
;
17235 /* For Ada types, make sure that the gnat-specific data is always
17236 initialized (if not already set). There are a few types where
17237 we should not be doing so, because the type-specific area is
17238 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17239 where the type-specific area is used to store the floatformat).
17240 But this is not a problem, because the gnat-specific information
17241 is actually not needed for these types. */
17242 if (need_gnat_info (cu
)
17243 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17244 && TYPE_CODE (type
) != TYPE_CODE_FLT
17245 && !HAVE_GNAT_AUX_INFO (type
))
17246 INIT_GNAT_SPECIFIC (type
);
17248 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17250 dwarf2_per_objfile
->die_type_hash
=
17251 htab_create_alloc_ex (127,
17252 per_cu_offset_and_type_hash
,
17253 per_cu_offset_and_type_eq
,
17255 &objfile
->objfile_obstack
,
17256 hashtab_obstack_allocate
,
17257 dummy_obstack_deallocate
);
17260 ofs
.per_cu
= cu
->per_cu
;
17261 ofs
.offset
= die
->offset
;
17263 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17264 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17266 complaint (&symfile_complaints
,
17267 _("A problem internal to GDB: DIE 0x%x has type already set"),
17268 die
->offset
.sect_off
);
17269 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17274 /* Look up the type for the die at OFFSET in the appropriate type_hash
17275 table, or return NULL if the die does not have a saved type. */
17277 static struct type
*
17278 get_die_type_at_offset (sect_offset offset
,
17279 struct dwarf2_per_cu_data
*per_cu
)
17281 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17283 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17286 ofs
.per_cu
= per_cu
;
17287 ofs
.offset
= offset
;
17288 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17295 /* Look up the type for DIE in the appropriate type_hash table,
17296 or return NULL if DIE does not have a saved type. */
17298 static struct type
*
17299 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17301 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17304 /* Add a dependence relationship from CU to REF_PER_CU. */
17307 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17308 struct dwarf2_per_cu_data
*ref_per_cu
)
17312 if (cu
->dependencies
== NULL
)
17314 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17315 NULL
, &cu
->comp_unit_obstack
,
17316 hashtab_obstack_allocate
,
17317 dummy_obstack_deallocate
);
17319 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17321 *slot
= ref_per_cu
;
17324 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17325 Set the mark field in every compilation unit in the
17326 cache that we must keep because we are keeping CU. */
17329 dwarf2_mark_helper (void **slot
, void *data
)
17331 struct dwarf2_per_cu_data
*per_cu
;
17333 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17335 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17336 reading of the chain. As such dependencies remain valid it is not much
17337 useful to track and undo them during QUIT cleanups. */
17338 if (per_cu
->cu
== NULL
)
17341 if (per_cu
->cu
->mark
)
17343 per_cu
->cu
->mark
= 1;
17345 if (per_cu
->cu
->dependencies
!= NULL
)
17346 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17351 /* Set the mark field in CU and in every other compilation unit in the
17352 cache that we must keep because we are keeping CU. */
17355 dwarf2_mark (struct dwarf2_cu
*cu
)
17360 if (cu
->dependencies
!= NULL
)
17361 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17365 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17369 per_cu
->cu
->mark
= 0;
17370 per_cu
= per_cu
->cu
->read_in_chain
;
17374 /* Trivial hash function for partial_die_info: the hash value of a DIE
17375 is its offset in .debug_info for this objfile. */
17378 partial_die_hash (const void *item
)
17380 const struct partial_die_info
*part_die
= item
;
17382 return part_die
->offset
.sect_off
;
17385 /* Trivial comparison function for partial_die_info structures: two DIEs
17386 are equal if they have the same offset. */
17389 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17391 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17392 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17394 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17397 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17398 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17401 set_dwarf2_cmd (char *args
, int from_tty
)
17403 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17407 show_dwarf2_cmd (char *args
, int from_tty
)
17409 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17412 /* If section described by INFO was mmapped, munmap it now. */
17415 munmap_section_buffer (struct dwarf2_section_info
*info
)
17417 if (info
->map_addr
!= NULL
)
17422 res
= munmap (info
->map_addr
, info
->map_len
);
17423 gdb_assert (res
== 0);
17425 /* Without HAVE_MMAP, we should never be here to begin with. */
17426 gdb_assert_not_reached ("no mmap support");
17431 /* munmap debug sections for OBJFILE, if necessary. */
17434 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17436 struct dwarf2_per_objfile
*data
= d
;
17438 struct dwarf2_section_info
*section
;
17440 /* This is sorted according to the order they're defined in to make it easier
17441 to keep in sync. */
17442 munmap_section_buffer (&data
->info
);
17443 munmap_section_buffer (&data
->abbrev
);
17444 munmap_section_buffer (&data
->line
);
17445 munmap_section_buffer (&data
->loc
);
17446 munmap_section_buffer (&data
->macinfo
);
17447 munmap_section_buffer (&data
->macro
);
17448 munmap_section_buffer (&data
->str
);
17449 munmap_section_buffer (&data
->ranges
);
17450 munmap_section_buffer (&data
->addr
);
17451 munmap_section_buffer (&data
->frame
);
17452 munmap_section_buffer (&data
->eh_frame
);
17453 munmap_section_buffer (&data
->gdb_index
);
17456 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17458 munmap_section_buffer (section
);
17460 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17461 VEC_free (dwarf2_per_cu_ptr
,
17462 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17464 VEC_free (dwarf2_section_info_def
, data
->types
);
17466 if (data
->dwo_files
)
17467 free_dwo_files (data
->dwo_files
, objfile
);
17471 /* The "save gdb-index" command. */
17473 /* The contents of the hash table we create when building the string
17475 struct strtab_entry
17477 offset_type offset
;
17481 /* Hash function for a strtab_entry.
17483 Function is used only during write_hash_table so no index format backward
17484 compatibility is needed. */
17487 hash_strtab_entry (const void *e
)
17489 const struct strtab_entry
*entry
= e
;
17490 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17493 /* Equality function for a strtab_entry. */
17496 eq_strtab_entry (const void *a
, const void *b
)
17498 const struct strtab_entry
*ea
= a
;
17499 const struct strtab_entry
*eb
= b
;
17500 return !strcmp (ea
->str
, eb
->str
);
17503 /* Create a strtab_entry hash table. */
17506 create_strtab (void)
17508 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17509 xfree
, xcalloc
, xfree
);
17512 /* Add a string to the constant pool. Return the string's offset in
17516 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17519 struct strtab_entry entry
;
17520 struct strtab_entry
*result
;
17523 slot
= htab_find_slot (table
, &entry
, INSERT
);
17528 result
= XNEW (struct strtab_entry
);
17529 result
->offset
= obstack_object_size (cpool
);
17531 obstack_grow_str0 (cpool
, str
);
17534 return result
->offset
;
17537 /* An entry in the symbol table. */
17538 struct symtab_index_entry
17540 /* The name of the symbol. */
17542 /* The offset of the name in the constant pool. */
17543 offset_type index_offset
;
17544 /* A sorted vector of the indices of all the CUs that hold an object
17546 VEC (offset_type
) *cu_indices
;
17549 /* The symbol table. This is a power-of-2-sized hash table. */
17550 struct mapped_symtab
17552 offset_type n_elements
;
17554 struct symtab_index_entry
**data
;
17557 /* Hash function for a symtab_index_entry. */
17560 hash_symtab_entry (const void *e
)
17562 const struct symtab_index_entry
*entry
= e
;
17563 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17564 sizeof (offset_type
) * VEC_length (offset_type
,
17565 entry
->cu_indices
),
17569 /* Equality function for a symtab_index_entry. */
17572 eq_symtab_entry (const void *a
, const void *b
)
17574 const struct symtab_index_entry
*ea
= a
;
17575 const struct symtab_index_entry
*eb
= b
;
17576 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17577 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17579 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17580 VEC_address (offset_type
, eb
->cu_indices
),
17581 sizeof (offset_type
) * len
);
17584 /* Destroy a symtab_index_entry. */
17587 delete_symtab_entry (void *p
)
17589 struct symtab_index_entry
*entry
= p
;
17590 VEC_free (offset_type
, entry
->cu_indices
);
17594 /* Create a hash table holding symtab_index_entry objects. */
17597 create_symbol_hash_table (void)
17599 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17600 delete_symtab_entry
, xcalloc
, xfree
);
17603 /* Create a new mapped symtab object. */
17605 static struct mapped_symtab
*
17606 create_mapped_symtab (void)
17608 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17609 symtab
->n_elements
= 0;
17610 symtab
->size
= 1024;
17611 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17615 /* Destroy a mapped_symtab. */
17618 cleanup_mapped_symtab (void *p
)
17620 struct mapped_symtab
*symtab
= p
;
17621 /* The contents of the array are freed when the other hash table is
17623 xfree (symtab
->data
);
17627 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17630 Function is used only during write_hash_table so no index format backward
17631 compatibility is needed. */
17633 static struct symtab_index_entry
**
17634 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17636 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17638 index
= hash
& (symtab
->size
- 1);
17639 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17643 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17644 return &symtab
->data
[index
];
17645 index
= (index
+ step
) & (symtab
->size
- 1);
17649 /* Expand SYMTAB's hash table. */
17652 hash_expand (struct mapped_symtab
*symtab
)
17654 offset_type old_size
= symtab
->size
;
17656 struct symtab_index_entry
**old_entries
= symtab
->data
;
17659 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17661 for (i
= 0; i
< old_size
; ++i
)
17663 if (old_entries
[i
])
17665 struct symtab_index_entry
**slot
= find_slot (symtab
,
17666 old_entries
[i
]->name
);
17667 *slot
= old_entries
[i
];
17671 xfree (old_entries
);
17674 /* Add an entry to SYMTAB. NAME is the name of the symbol.
17675 CU_INDEX is the index of the CU in which the symbol appears.
17676 IS_STATIC is one if the symbol is static, otherwise zero (global). */
17679 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17680 int is_static
, gdb_index_symbol_kind kind
,
17681 offset_type cu_index
)
17683 struct symtab_index_entry
**slot
;
17684 offset_type cu_index_and_attrs
;
17686 ++symtab
->n_elements
;
17687 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17688 hash_expand (symtab
);
17690 slot
= find_slot (symtab
, name
);
17693 *slot
= XNEW (struct symtab_index_entry
);
17694 (*slot
)->name
= name
;
17695 /* index_offset is set later. */
17696 (*slot
)->cu_indices
= NULL
;
17699 cu_index_and_attrs
= 0;
17700 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
17701 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
17702 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
17704 /* We don't want to record an index value twice as we want to avoid the
17706 We process all global symbols and then all static symbols
17707 (which would allow us to avoid the duplication by only having to check
17708 the last entry pushed), but a symbol could have multiple kinds in one CU.
17709 To keep things simple we don't worry about the duplication here and
17710 sort and uniqufy the list after we've processed all symbols. */
17711 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
17714 /* qsort helper routine for uniquify_cu_indices. */
17717 offset_type_compare (const void *ap
, const void *bp
)
17719 offset_type a
= *(offset_type
*) ap
;
17720 offset_type b
= *(offset_type
*) bp
;
17722 return (a
> b
) - (b
> a
);
17725 /* Sort and remove duplicates of all symbols' cu_indices lists. */
17728 uniquify_cu_indices (struct mapped_symtab
*symtab
)
17732 for (i
= 0; i
< symtab
->size
; ++i
)
17734 struct symtab_index_entry
*entry
= symtab
->data
[i
];
17737 && entry
->cu_indices
!= NULL
)
17739 unsigned int next_to_insert
, next_to_check
;
17740 offset_type last_value
;
17742 qsort (VEC_address (offset_type
, entry
->cu_indices
),
17743 VEC_length (offset_type
, entry
->cu_indices
),
17744 sizeof (offset_type
), offset_type_compare
);
17746 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
17747 next_to_insert
= 1;
17748 for (next_to_check
= 1;
17749 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
17752 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
17755 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
17757 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
17762 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
17767 /* Add a vector of indices to the constant pool. */
17770 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17771 struct symtab_index_entry
*entry
)
17775 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17778 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17779 offset_type val
= MAYBE_SWAP (len
);
17784 entry
->index_offset
= obstack_object_size (cpool
);
17786 obstack_grow (cpool
, &val
, sizeof (val
));
17788 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17791 val
= MAYBE_SWAP (iter
);
17792 obstack_grow (cpool
, &val
, sizeof (val
));
17797 struct symtab_index_entry
*old_entry
= *slot
;
17798 entry
->index_offset
= old_entry
->index_offset
;
17801 return entry
->index_offset
;
17804 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17805 constant pool entries going into the obstack CPOOL. */
17808 write_hash_table (struct mapped_symtab
*symtab
,
17809 struct obstack
*output
, struct obstack
*cpool
)
17812 htab_t symbol_hash_table
;
17815 symbol_hash_table
= create_symbol_hash_table ();
17816 str_table
= create_strtab ();
17818 /* We add all the index vectors to the constant pool first, to
17819 ensure alignment is ok. */
17820 for (i
= 0; i
< symtab
->size
; ++i
)
17822 if (symtab
->data
[i
])
17823 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17826 /* Now write out the hash table. */
17827 for (i
= 0; i
< symtab
->size
; ++i
)
17829 offset_type str_off
, vec_off
;
17831 if (symtab
->data
[i
])
17833 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17834 vec_off
= symtab
->data
[i
]->index_offset
;
17838 /* While 0 is a valid constant pool index, it is not valid
17839 to have 0 for both offsets. */
17844 str_off
= MAYBE_SWAP (str_off
);
17845 vec_off
= MAYBE_SWAP (vec_off
);
17847 obstack_grow (output
, &str_off
, sizeof (str_off
));
17848 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17851 htab_delete (str_table
);
17852 htab_delete (symbol_hash_table
);
17855 /* Struct to map psymtab to CU index in the index file. */
17856 struct psymtab_cu_index_map
17858 struct partial_symtab
*psymtab
;
17859 unsigned int cu_index
;
17863 hash_psymtab_cu_index (const void *item
)
17865 const struct psymtab_cu_index_map
*map
= item
;
17867 return htab_hash_pointer (map
->psymtab
);
17871 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17873 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17874 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17876 return lhs
->psymtab
== rhs
->psymtab
;
17879 /* Helper struct for building the address table. */
17880 struct addrmap_index_data
17882 struct objfile
*objfile
;
17883 struct obstack
*addr_obstack
;
17884 htab_t cu_index_htab
;
17886 /* Non-zero if the previous_* fields are valid.
17887 We can't write an entry until we see the next entry (since it is only then
17888 that we know the end of the entry). */
17889 int previous_valid
;
17890 /* Index of the CU in the table of all CUs in the index file. */
17891 unsigned int previous_cu_index
;
17892 /* Start address of the CU. */
17893 CORE_ADDR previous_cu_start
;
17896 /* Write an address entry to OBSTACK. */
17899 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17900 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17902 offset_type cu_index_to_write
;
17904 CORE_ADDR baseaddr
;
17906 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17908 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17909 obstack_grow (obstack
, addr
, 8);
17910 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17911 obstack_grow (obstack
, addr
, 8);
17912 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17913 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17916 /* Worker function for traversing an addrmap to build the address table. */
17919 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17921 struct addrmap_index_data
*data
= datap
;
17922 struct partial_symtab
*pst
= obj
;
17924 if (data
->previous_valid
)
17925 add_address_entry (data
->objfile
, data
->addr_obstack
,
17926 data
->previous_cu_start
, start_addr
,
17927 data
->previous_cu_index
);
17929 data
->previous_cu_start
= start_addr
;
17932 struct psymtab_cu_index_map find_map
, *map
;
17933 find_map
.psymtab
= pst
;
17934 map
= htab_find (data
->cu_index_htab
, &find_map
);
17935 gdb_assert (map
!= NULL
);
17936 data
->previous_cu_index
= map
->cu_index
;
17937 data
->previous_valid
= 1;
17940 data
->previous_valid
= 0;
17945 /* Write OBJFILE's address map to OBSTACK.
17946 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17947 in the index file. */
17950 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17951 htab_t cu_index_htab
)
17953 struct addrmap_index_data addrmap_index_data
;
17955 /* When writing the address table, we have to cope with the fact that
17956 the addrmap iterator only provides the start of a region; we have to
17957 wait until the next invocation to get the start of the next region. */
17959 addrmap_index_data
.objfile
= objfile
;
17960 addrmap_index_data
.addr_obstack
= obstack
;
17961 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17962 addrmap_index_data
.previous_valid
= 0;
17964 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17965 &addrmap_index_data
);
17967 /* It's highly unlikely the last entry (end address = 0xff...ff)
17968 is valid, but we should still handle it.
17969 The end address is recorded as the start of the next region, but that
17970 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17972 if (addrmap_index_data
.previous_valid
)
17973 add_address_entry (objfile
, obstack
,
17974 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17975 addrmap_index_data
.previous_cu_index
);
17978 /* Return the symbol kind of PSYM. */
17980 static gdb_index_symbol_kind
17981 symbol_kind (struct partial_symbol
*psym
)
17983 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
17984 enum address_class aclass
= PSYMBOL_CLASS (psym
);
17992 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
17994 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17996 case LOC_CONST_BYTES
:
17997 case LOC_OPTIMIZED_OUT
:
17999 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18001 /* Note: It's currently impossible to recognize psyms as enum values
18002 short of reading the type info. For now punt. */
18003 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18005 /* There are other LOC_FOO values that one might want to classify
18006 as variables, but dwarf2read.c doesn't currently use them. */
18007 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18009 case STRUCT_DOMAIN
:
18010 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18012 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18016 /* Add a list of partial symbols to SYMTAB. */
18019 write_psymbols (struct mapped_symtab
*symtab
,
18021 struct partial_symbol
**psymp
,
18023 offset_type cu_index
,
18026 for (; count
-- > 0; ++psymp
)
18028 struct partial_symbol
*psym
= *psymp
;
18031 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18032 error (_("Ada is not currently supported by the index"));
18034 /* Only add a given psymbol once. */
18035 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18038 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18041 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18042 is_static
, kind
, cu_index
);
18047 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18048 exception if there is an error. */
18051 write_obstack (FILE *file
, struct obstack
*obstack
)
18053 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18055 != obstack_object_size (obstack
))
18056 error (_("couldn't data write to file"));
18059 /* Unlink a file if the argument is not NULL. */
18062 unlink_if_set (void *p
)
18064 char **filename
= p
;
18066 unlink (*filename
);
18069 /* A helper struct used when iterating over debug_types. */
18070 struct signatured_type_index_data
18072 struct objfile
*objfile
;
18073 struct mapped_symtab
*symtab
;
18074 struct obstack
*types_list
;
18079 /* A helper function that writes a single signatured_type to an
18083 write_one_signatured_type (void **slot
, void *d
)
18085 struct signatured_type_index_data
*info
= d
;
18086 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18087 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18088 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18091 write_psymbols (info
->symtab
,
18093 info
->objfile
->global_psymbols
.list
18094 + psymtab
->globals_offset
,
18095 psymtab
->n_global_syms
, info
->cu_index
,
18097 write_psymbols (info
->symtab
,
18099 info
->objfile
->static_psymbols
.list
18100 + psymtab
->statics_offset
,
18101 psymtab
->n_static_syms
, info
->cu_index
,
18104 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18105 entry
->per_cu
.offset
.sect_off
);
18106 obstack_grow (info
->types_list
, val
, 8);
18107 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18108 entry
->type_offset_in_tu
.cu_off
);
18109 obstack_grow (info
->types_list
, val
, 8);
18110 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18111 obstack_grow (info
->types_list
, val
, 8);
18118 /* Recurse into all "included" dependencies and write their symbols as
18119 if they appeared in this psymtab. */
18122 recursively_write_psymbols (struct objfile
*objfile
,
18123 struct partial_symtab
*psymtab
,
18124 struct mapped_symtab
*symtab
,
18126 offset_type cu_index
)
18130 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18131 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18132 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18133 symtab
, psyms_seen
, cu_index
);
18135 write_psymbols (symtab
,
18137 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18138 psymtab
->n_global_syms
, cu_index
,
18140 write_psymbols (symtab
,
18142 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18143 psymtab
->n_static_syms
, cu_index
,
18147 /* Create an index file for OBJFILE in the directory DIR. */
18150 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18152 struct cleanup
*cleanup
;
18153 char *filename
, *cleanup_filename
;
18154 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18155 struct obstack cu_list
, types_cu_list
;
18158 struct mapped_symtab
*symtab
;
18159 offset_type val
, size_of_contents
, total_len
;
18162 htab_t cu_index_htab
;
18163 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18165 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18168 if (dwarf2_per_objfile
->using_index
)
18169 error (_("Cannot use an index to create the index"));
18171 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18172 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18174 if (stat (objfile
->name
, &st
) < 0)
18175 perror_with_name (objfile
->name
);
18177 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18178 INDEX_SUFFIX
, (char *) NULL
);
18179 cleanup
= make_cleanup (xfree
, filename
);
18181 out_file
= fopen (filename
, "wb");
18183 error (_("Can't open `%s' for writing"), filename
);
18185 cleanup_filename
= filename
;
18186 make_cleanup (unlink_if_set
, &cleanup_filename
);
18188 symtab
= create_mapped_symtab ();
18189 make_cleanup (cleanup_mapped_symtab
, symtab
);
18191 obstack_init (&addr_obstack
);
18192 make_cleanup_obstack_free (&addr_obstack
);
18194 obstack_init (&cu_list
);
18195 make_cleanup_obstack_free (&cu_list
);
18197 obstack_init (&types_cu_list
);
18198 make_cleanup_obstack_free (&types_cu_list
);
18200 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18201 NULL
, xcalloc
, xfree
);
18202 make_cleanup_htab_delete (psyms_seen
);
18204 /* While we're scanning CU's create a table that maps a psymtab pointer
18205 (which is what addrmap records) to its index (which is what is recorded
18206 in the index file). This will later be needed to write the address
18208 cu_index_htab
= htab_create_alloc (100,
18209 hash_psymtab_cu_index
,
18210 eq_psymtab_cu_index
,
18211 NULL
, xcalloc
, xfree
);
18212 make_cleanup_htab_delete (cu_index_htab
);
18213 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18214 xmalloc (sizeof (struct psymtab_cu_index_map
)
18215 * dwarf2_per_objfile
->n_comp_units
);
18216 make_cleanup (xfree
, psymtab_cu_index_map
);
18218 /* The CU list is already sorted, so we don't need to do additional
18219 work here. Also, the debug_types entries do not appear in
18220 all_comp_units, but only in their own hash table. */
18221 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18223 struct dwarf2_per_cu_data
*per_cu
18224 = dwarf2_per_objfile
->all_comp_units
[i
];
18225 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18227 struct psymtab_cu_index_map
*map
;
18230 if (psymtab
->user
== NULL
)
18231 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18233 map
= &psymtab_cu_index_map
[i
];
18234 map
->psymtab
= psymtab
;
18236 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18237 gdb_assert (slot
!= NULL
);
18238 gdb_assert (*slot
== NULL
);
18241 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18242 per_cu
->offset
.sect_off
);
18243 obstack_grow (&cu_list
, val
, 8);
18244 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18245 obstack_grow (&cu_list
, val
, 8);
18248 /* Dump the address map. */
18249 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18251 /* Write out the .debug_type entries, if any. */
18252 if (dwarf2_per_objfile
->signatured_types
)
18254 struct signatured_type_index_data sig_data
;
18256 sig_data
.objfile
= objfile
;
18257 sig_data
.symtab
= symtab
;
18258 sig_data
.types_list
= &types_cu_list
;
18259 sig_data
.psyms_seen
= psyms_seen
;
18260 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18261 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18262 write_one_signatured_type
, &sig_data
);
18265 /* Now that we've processed all symbols we can shrink their cu_indices
18267 uniquify_cu_indices (symtab
);
18269 obstack_init (&constant_pool
);
18270 make_cleanup_obstack_free (&constant_pool
);
18271 obstack_init (&symtab_obstack
);
18272 make_cleanup_obstack_free (&symtab_obstack
);
18273 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18275 obstack_init (&contents
);
18276 make_cleanup_obstack_free (&contents
);
18277 size_of_contents
= 6 * sizeof (offset_type
);
18278 total_len
= size_of_contents
;
18280 /* The version number. */
18281 val
= MAYBE_SWAP (7);
18282 obstack_grow (&contents
, &val
, sizeof (val
));
18284 /* The offset of the CU list from the start of the file. */
18285 val
= MAYBE_SWAP (total_len
);
18286 obstack_grow (&contents
, &val
, sizeof (val
));
18287 total_len
+= obstack_object_size (&cu_list
);
18289 /* The offset of the types CU list from the start of the file. */
18290 val
= MAYBE_SWAP (total_len
);
18291 obstack_grow (&contents
, &val
, sizeof (val
));
18292 total_len
+= obstack_object_size (&types_cu_list
);
18294 /* The offset of the address table from the start of the file. */
18295 val
= MAYBE_SWAP (total_len
);
18296 obstack_grow (&contents
, &val
, sizeof (val
));
18297 total_len
+= obstack_object_size (&addr_obstack
);
18299 /* The offset of the symbol table from the start of the file. */
18300 val
= MAYBE_SWAP (total_len
);
18301 obstack_grow (&contents
, &val
, sizeof (val
));
18302 total_len
+= obstack_object_size (&symtab_obstack
);
18304 /* The offset of the constant pool from the start of the file. */
18305 val
= MAYBE_SWAP (total_len
);
18306 obstack_grow (&contents
, &val
, sizeof (val
));
18307 total_len
+= obstack_object_size (&constant_pool
);
18309 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18311 write_obstack (out_file
, &contents
);
18312 write_obstack (out_file
, &cu_list
);
18313 write_obstack (out_file
, &types_cu_list
);
18314 write_obstack (out_file
, &addr_obstack
);
18315 write_obstack (out_file
, &symtab_obstack
);
18316 write_obstack (out_file
, &constant_pool
);
18320 /* We want to keep the file, so we set cleanup_filename to NULL
18321 here. See unlink_if_set. */
18322 cleanup_filename
= NULL
;
18324 do_cleanups (cleanup
);
18327 /* Implementation of the `save gdb-index' command.
18329 Note that the file format used by this command is documented in the
18330 GDB manual. Any changes here must be documented there. */
18333 save_gdb_index_command (char *arg
, int from_tty
)
18335 struct objfile
*objfile
;
18338 error (_("usage: save gdb-index DIRECTORY"));
18340 ALL_OBJFILES (objfile
)
18344 /* If the objfile does not correspond to an actual file, skip it. */
18345 if (stat (objfile
->name
, &st
) < 0)
18348 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18349 if (dwarf2_per_objfile
)
18351 volatile struct gdb_exception except
;
18353 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18355 write_psymtabs_to_index (objfile
, arg
);
18357 if (except
.reason
< 0)
18358 exception_fprintf (gdb_stderr
, except
,
18359 _("Error while writing index for `%s': "),
18367 int dwarf2_always_disassemble
;
18370 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18371 struct cmd_list_element
*c
, const char *value
)
18373 fprintf_filtered (file
,
18374 _("Whether to always disassemble "
18375 "DWARF expressions is %s.\n"),
18380 show_check_physname (struct ui_file
*file
, int from_tty
,
18381 struct cmd_list_element
*c
, const char *value
)
18383 fprintf_filtered (file
,
18384 _("Whether to check \"physname\" is %s.\n"),
18388 void _initialize_dwarf2_read (void);
18391 _initialize_dwarf2_read (void)
18393 struct cmd_list_element
*c
;
18395 dwarf2_objfile_data_key
18396 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18398 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18399 Set DWARF 2 specific variables.\n\
18400 Configure DWARF 2 variables such as the cache size"),
18401 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18402 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18404 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18405 Show DWARF 2 specific variables\n\
18406 Show DWARF 2 variables such as the cache size"),
18407 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18408 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18410 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18411 &dwarf2_max_cache_age
, _("\
18412 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18413 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18414 A higher limit means that cached compilation units will be stored\n\
18415 in memory longer, and more total memory will be used. Zero disables\n\
18416 caching, which can slow down startup."),
18418 show_dwarf2_max_cache_age
,
18419 &set_dwarf2_cmdlist
,
18420 &show_dwarf2_cmdlist
);
18422 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18423 &dwarf2_always_disassemble
, _("\
18424 Set whether `info address' always disassembles DWARF expressions."), _("\
18425 Show whether `info address' always disassembles DWARF expressions."), _("\
18426 When enabled, DWARF expressions are always printed in an assembly-like\n\
18427 syntax. When disabled, expressions will be printed in a more\n\
18428 conversational style, when possible."),
18430 show_dwarf2_always_disassemble
,
18431 &set_dwarf2_cmdlist
,
18432 &show_dwarf2_cmdlist
);
18434 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
18435 Set debugging of the dwarf2 reader."), _("\
18436 Show debugging of the dwarf2 reader."), _("\
18437 When enabled, debugging messages are printed during dwarf2 reading\n\
18438 and symtab expansion."),
18441 &setdebuglist
, &showdebuglist
);
18443 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18444 Set debugging of the dwarf2 DIE reader."), _("\
18445 Show debugging of the dwarf2 DIE reader."), _("\
18446 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18447 The value is the maximum depth to print."),
18450 &setdebuglist
, &showdebuglist
);
18452 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18453 Set cross-checking of \"physname\" code against demangler."), _("\
18454 Show cross-checking of \"physname\" code against demangler."), _("\
18455 When enabled, GDB's internal \"physname\" code is checked against\n\
18457 NULL
, show_check_physname
,
18458 &setdebuglist
, &showdebuglist
);
18460 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18462 Save a gdb-index file.\n\
18463 Usage: save gdb-index DIRECTORY"),
18465 set_cmd_completer (c
, filename_completer
);