1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
69 #include "gdb_string.h"
70 #include "gdb_assert.h"
71 #include <sys/types.h>
78 #define MAP_FAILED ((void *) -1)
82 typedef struct symbol
*symbolp
;
85 /* When non-zero, print basic high level tracing messages.
86 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
87 static int dwarf2_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static int dwarf2_die_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 int use_deprecated_index_sections
= 0;
100 /* When set, the file that we're processing is known to have debugging
101 info for C++ namespaces. GCC 3.3.x did not produce this information,
102 but later versions do. */
104 static int processing_has_namespace_info
;
106 static const struct objfile_data
*dwarf2_objfile_data_key
;
108 struct dwarf2_section_info
113 /* Not NULL if the section was actually mmapped. */
115 /* Page aligned size of mmapped area. */
116 bfd_size_type map_len
;
117 /* True if we have tried to read this section. */
121 typedef struct dwarf2_section_info dwarf2_section_info_def
;
122 DEF_VEC_O (dwarf2_section_info_def
);
124 /* All offsets in the index are of this type. It must be
125 architecture-independent. */
126 typedef uint32_t offset_type
;
128 DEF_VEC_I (offset_type
);
130 /* Ensure only legit values are used. */
131 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
133 gdb_assert ((unsigned int) (value) <= 1); \
134 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
137 /* Ensure only legit values are used. */
138 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
140 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
141 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
142 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
145 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
146 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
148 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
149 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
152 /* A description of the mapped index. The file format is described in
153 a comment by the code that writes the index. */
156 /* Index data format version. */
159 /* The total length of the buffer. */
162 /* A pointer to the address table data. */
163 const gdb_byte
*address_table
;
165 /* Size of the address table data in bytes. */
166 offset_type address_table_size
;
168 /* The symbol table, implemented as a hash table. */
169 const offset_type
*symbol_table
;
171 /* Size in slots, each slot is 2 offset_types. */
172 offset_type symbol_table_slots
;
174 /* A pointer to the constant pool. */
175 const char *constant_pool
;
178 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
179 DEF_VEC_P (dwarf2_per_cu_ptr
);
181 /* Collection of data recorded per objfile.
182 This hangs off of dwarf2_objfile_data_key. */
184 struct dwarf2_per_objfile
186 struct dwarf2_section_info info
;
187 struct dwarf2_section_info abbrev
;
188 struct dwarf2_section_info line
;
189 struct dwarf2_section_info loc
;
190 struct dwarf2_section_info macinfo
;
191 struct dwarf2_section_info macro
;
192 struct dwarf2_section_info str
;
193 struct dwarf2_section_info ranges
;
194 struct dwarf2_section_info addr
;
195 struct dwarf2_section_info frame
;
196 struct dwarf2_section_info eh_frame
;
197 struct dwarf2_section_info gdb_index
;
199 VEC (dwarf2_section_info_def
) *types
;
202 struct objfile
*objfile
;
204 /* Table of all the compilation units. This is used to locate
205 the target compilation unit of a particular reference. */
206 struct dwarf2_per_cu_data
**all_comp_units
;
208 /* The number of compilation units in ALL_COMP_UNITS. */
211 /* The number of .debug_types-related CUs. */
214 /* The .debug_types-related CUs (TUs). */
215 struct dwarf2_per_cu_data
**all_type_units
;
217 /* A chain of compilation units that are currently read in, so that
218 they can be freed later. */
219 struct dwarf2_per_cu_data
*read_in_chain
;
221 /* A table mapping .debug_types signatures to its signatured_type entry.
222 This is NULL if the .debug_types section hasn't been read in yet. */
223 htab_t signatured_types
;
225 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
226 This is NULL if the table hasn't been allocated yet. */
229 /* A flag indicating wether this objfile has a section loaded at a
231 int has_section_at_zero
;
233 /* True if we are using the mapped index,
234 or we are faking it for OBJF_READNOW's sake. */
235 unsigned char using_index
;
237 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
238 struct mapped_index
*index_table
;
240 /* When using index_table, this keeps track of all quick_file_names entries.
241 TUs can share line table entries with CUs or other TUs, and there can be
242 a lot more TUs than unique line tables, so we maintain a separate table
243 of all line table entries to support the sharing. */
244 htab_t quick_file_names_table
;
246 /* Set during partial symbol reading, to prevent queueing of full
248 int reading_partial_symbols
;
250 /* Table mapping type DIEs to their struct type *.
251 This is NULL if not allocated yet.
252 The mapping is done via (CU/TU signature + DIE offset) -> type. */
253 htab_t die_type_hash
;
255 /* The CUs we recently read. */
256 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
259 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
261 /* Default names of the debugging sections. */
263 /* Note that if the debugging section has been compressed, it might
264 have a name like .zdebug_info. */
266 static const struct dwarf2_debug_sections dwarf2_elf_names
=
268 { ".debug_info", ".zdebug_info" },
269 { ".debug_abbrev", ".zdebug_abbrev" },
270 { ".debug_line", ".zdebug_line" },
271 { ".debug_loc", ".zdebug_loc" },
272 { ".debug_macinfo", ".zdebug_macinfo" },
273 { ".debug_macro", ".zdebug_macro" },
274 { ".debug_str", ".zdebug_str" },
275 { ".debug_ranges", ".zdebug_ranges" },
276 { ".debug_types", ".zdebug_types" },
277 { ".debug_addr", ".zdebug_addr" },
278 { ".debug_frame", ".zdebug_frame" },
279 { ".eh_frame", NULL
},
280 { ".gdb_index", ".zgdb_index" },
284 /* List of DWO sections. */
286 static const struct dwo_section_names
288 struct dwarf2_section_names abbrev_dwo
;
289 struct dwarf2_section_names info_dwo
;
290 struct dwarf2_section_names line_dwo
;
291 struct dwarf2_section_names loc_dwo
;
292 struct dwarf2_section_names macinfo_dwo
;
293 struct dwarf2_section_names macro_dwo
;
294 struct dwarf2_section_names str_dwo
;
295 struct dwarf2_section_names str_offsets_dwo
;
296 struct dwarf2_section_names types_dwo
;
300 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
301 { ".debug_info.dwo", ".zdebug_info.dwo" },
302 { ".debug_line.dwo", ".zdebug_line.dwo" },
303 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
304 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
305 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
306 { ".debug_str.dwo", ".zdebug_str.dwo" },
307 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
308 { ".debug_types.dwo", ".zdebug_types.dwo" },
311 /* local data types */
313 /* We hold several abbreviation tables in memory at the same time. */
314 #ifndef ABBREV_HASH_SIZE
315 #define ABBREV_HASH_SIZE 121
318 /* The data in a compilation unit header, after target2host
319 translation, looks like this. */
320 struct comp_unit_head
324 unsigned char addr_size
;
325 unsigned char signed_addr_p
;
326 sect_offset abbrev_offset
;
328 /* Size of file offsets; either 4 or 8. */
329 unsigned int offset_size
;
331 /* Size of the length field; either 4 or 12. */
332 unsigned int initial_length_size
;
334 /* Offset to the first byte of this compilation unit header in the
335 .debug_info section, for resolving relative reference dies. */
338 /* Offset to first die in this cu from the start of the cu.
339 This will be the first byte following the compilation unit header. */
340 cu_offset first_die_offset
;
343 /* Type used for delaying computation of method physnames.
344 See comments for compute_delayed_physnames. */
345 struct delayed_method_info
347 /* The type to which the method is attached, i.e., its parent class. */
350 /* The index of the method in the type's function fieldlists. */
353 /* The index of the method in the fieldlist. */
356 /* The name of the DIE. */
359 /* The DIE associated with this method. */
360 struct die_info
*die
;
363 typedef struct delayed_method_info delayed_method_info
;
364 DEF_VEC_O (delayed_method_info
);
366 /* Internal state when decoding a particular compilation unit. */
369 /* The objfile containing this compilation unit. */
370 struct objfile
*objfile
;
372 /* The header of the compilation unit. */
373 struct comp_unit_head header
;
375 /* Base address of this compilation unit. */
376 CORE_ADDR base_address
;
378 /* Non-zero if base_address has been set. */
381 /* The language we are debugging. */
382 enum language language
;
383 const struct language_defn
*language_defn
;
385 const char *producer
;
387 /* The generic symbol table building routines have separate lists for
388 file scope symbols and all all other scopes (local scopes). So
389 we need to select the right one to pass to add_symbol_to_list().
390 We do it by keeping a pointer to the correct list in list_in_scope.
392 FIXME: The original dwarf code just treated the file scope as the
393 first local scope, and all other local scopes as nested local
394 scopes, and worked fine. Check to see if we really need to
395 distinguish these in buildsym.c. */
396 struct pending
**list_in_scope
;
398 /* DWARF abbreviation table associated with this compilation unit. */
399 struct abbrev_info
**dwarf2_abbrevs
;
401 /* Storage for the abbrev table. */
402 struct obstack abbrev_obstack
;
404 /* Hash table holding all the loaded partial DIEs
405 with partial_die->offset.SECT_OFF as hash. */
408 /* Storage for things with the same lifetime as this read-in compilation
409 unit, including partial DIEs. */
410 struct obstack comp_unit_obstack
;
412 /* When multiple dwarf2_cu structures are living in memory, this field
413 chains them all together, so that they can be released efficiently.
414 We will probably also want a generation counter so that most-recently-used
415 compilation units are cached... */
416 struct dwarf2_per_cu_data
*read_in_chain
;
418 /* Backchain to our per_cu entry if the tree has been built. */
419 struct dwarf2_per_cu_data
*per_cu
;
421 /* How many compilation units ago was this CU last referenced? */
424 /* A hash table of DIE cu_offset for following references with
425 die_info->offset.sect_off as hash. */
428 /* Full DIEs if read in. */
429 struct die_info
*dies
;
431 /* A set of pointers to dwarf2_per_cu_data objects for compilation
432 units referenced by this one. Only set during full symbol processing;
433 partial symbol tables do not have dependencies. */
436 /* Header data from the line table, during full symbol processing. */
437 struct line_header
*line_header
;
439 /* A list of methods which need to have physnames computed
440 after all type information has been read. */
441 VEC (delayed_method_info
) *method_list
;
443 /* To be copied to symtab->call_site_htab. */
444 htab_t call_site_htab
;
446 /* Non-NULL if this CU came from a DWO file.
447 There is an invariant here that is important to remember:
448 Except for attributes copied from the top level DIE in the "main"
449 (or "stub") file in preparation for reading the DWO file
450 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
451 Either there isn't a DWO file (in which case this is NULL and the point
452 is moot), or there is and either we're not going to read it (in which
453 case this is NULL) or there is and we are reading it (in which case this
455 struct dwo_unit
*dwo_unit
;
457 /* The DW_AT_addr_base attribute if present, zero otherwise
458 (zero is a valid value though).
459 Note this value comes from the stub CU/TU's DIE. */
462 /* The DW_AT_ranges_base attribute if present, zero otherwise
463 (zero is a valid value though).
464 Note this value comes from the stub CU/TU's DIE.
465 Also note that the value is zero in the non-DWO case so this value can
466 be used without needing to know whether DWO files are in use or not. */
467 ULONGEST ranges_base
;
469 /* Mark used when releasing cached dies. */
470 unsigned int mark
: 1;
472 /* This CU references .debug_loc. See the symtab->locations_valid field.
473 This test is imperfect as there may exist optimized debug code not using
474 any location list and still facing inlining issues if handled as
475 unoptimized code. For a future better test see GCC PR other/32998. */
476 unsigned int has_loclist
: 1;
478 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
479 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
480 are valid. This information is cached because profiling CU expansion
481 showed excessive time spent in producer_is_gxx_lt_4_6. */
482 unsigned int checked_producer
: 1;
483 unsigned int producer_is_gxx_lt_4_6
: 1;
484 unsigned int producer_is_icc
: 1;
487 /* Persistent data held for a compilation unit, even when not
488 processing it. We put a pointer to this structure in the
489 read_symtab_private field of the psymtab. */
491 struct dwarf2_per_cu_data
493 /* The start offset and length of this compilation unit. 2**29-1
494 bytes should suffice to store the length of any compilation unit
495 - if it doesn't, GDB will fall over anyway.
496 NOTE: Unlike comp_unit_head.length, this length includes
498 If the DIE refers to a DWO file, this is always of the original die,
501 unsigned int length
: 29;
503 /* Flag indicating this compilation unit will be read in before
504 any of the current compilation units are processed. */
505 unsigned int queued
: 1;
507 /* This flag will be set when reading partial DIEs if we need to load
508 absolutely all DIEs for this compilation unit, instead of just the ones
509 we think are interesting. It gets set if we look for a DIE in the
510 hash table and don't find it. */
511 unsigned int load_all_dies
: 1;
513 /* Non-zero if this CU is from .debug_types. */
514 unsigned int is_debug_types
: 1;
516 /* The section this CU/TU lives in.
517 If the DIE refers to a DWO file, this is always the original die,
519 struct dwarf2_section_info
*info_or_types_section
;
521 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
522 of the CU cache it gets reset to NULL again. */
523 struct dwarf2_cu
*cu
;
525 /* The corresponding objfile.
526 Normally we can get the objfile from dwarf2_per_objfile.
527 However we can enter this file with just a "per_cu" handle. */
528 struct objfile
*objfile
;
530 /* When using partial symbol tables, the 'psymtab' field is active.
531 Otherwise the 'quick' field is active. */
534 /* The partial symbol table associated with this compilation unit,
535 or NULL for unread partial units. */
536 struct partial_symtab
*psymtab
;
538 /* Data needed by the "quick" functions. */
539 struct dwarf2_per_cu_quick_data
*quick
;
542 /* The CUs we import using DW_TAG_imported_unit. This is filled in
543 while reading psymtabs, used to compute the psymtab dependencies,
544 and then cleared. Then it is filled in again while reading full
545 symbols, and only deleted when the objfile is destroyed. */
546 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
549 /* Entry in the signatured_types hash table. */
551 struct signatured_type
553 /* The type's signature. */
556 /* Offset in the TU of the type's DIE, as read from the TU header.
557 If the definition lives in a DWO file, this value is unusable. */
558 cu_offset type_offset_in_tu
;
560 /* Offset in the section of the type's DIE.
561 If the definition lives in a DWO file, this is the offset in the
562 .debug_types.dwo section.
563 The value is zero until the actual value is known.
564 Zero is otherwise not a valid section offset. */
565 sect_offset type_offset_in_section
;
567 /* The CU(/TU) of this type. */
568 struct dwarf2_per_cu_data per_cu
;
571 /* These sections are what may appear in a "dwo" file. */
575 struct dwarf2_section_info abbrev
;
576 struct dwarf2_section_info info
;
577 struct dwarf2_section_info line
;
578 struct dwarf2_section_info loc
;
579 struct dwarf2_section_info macinfo
;
580 struct dwarf2_section_info macro
;
581 struct dwarf2_section_info str
;
582 struct dwarf2_section_info str_offsets
;
583 VEC (dwarf2_section_info_def
) *types
;
586 /* Common bits of DWO CUs/TUs. */
590 /* Backlink to the containing struct dwo_file. */
591 struct dwo_file
*dwo_file
;
593 /* The "id" that distinguishes this CU/TU.
594 .debug_info calls this "dwo_id", .debug_types calls this "signature".
595 Since signatures came first, we stick with it for consistency. */
598 /* The section this CU/TU lives in, in the DWO file. */
599 struct dwarf2_section_info
*info_or_types_section
;
601 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
605 /* For types, offset in the type's DIE of the type defined by this TU. */
606 cu_offset type_offset_in_tu
;
609 /* Data for one DWO file. */
613 /* The DW_AT_GNU_dwo_name attribute.
614 We don't manage space for this, it's an attribute. */
615 const char *dwo_name
;
617 /* The bfd, when the file is open. Otherwise this is NULL. */
620 /* Section info for this file. */
621 struct dwo_sections sections
;
623 /* Table of CUs in the file.
624 Each element is a struct dwo_unit. */
627 /* Table of TUs in the file.
628 Each element is a struct dwo_unit. */
632 /* Struct used to pass misc. parameters to read_die_and_children, et
633 al. which are used for both .debug_info and .debug_types dies.
634 All parameters here are unchanging for the life of the call. This
635 struct exists to abstract away the constant parameters of die reading. */
637 struct die_reader_specs
639 /* die_section->asection->owner. */
642 /* The CU of the DIE we are parsing. */
643 struct dwarf2_cu
*cu
;
645 /* Non-NULL if reading a DWO file. */
646 struct dwo_file
*dwo_file
;
648 /* The section the die comes from.
649 This is either .debug_info or .debug_types, or the .dwo variants. */
650 struct dwarf2_section_info
*die_section
;
652 /* die_section->buffer. */
655 /* The end of the buffer. */
656 const gdb_byte
*buffer_end
;
659 /* Type of function passed to init_cutu_and_read_dies, et.al. */
660 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
662 struct die_info
*comp_unit_die
,
666 /* The line number information for a compilation unit (found in the
667 .debug_line section) begins with a "statement program header",
668 which contains the following information. */
671 unsigned int total_length
;
672 unsigned short version
;
673 unsigned int header_length
;
674 unsigned char minimum_instruction_length
;
675 unsigned char maximum_ops_per_instruction
;
676 unsigned char default_is_stmt
;
678 unsigned char line_range
;
679 unsigned char opcode_base
;
681 /* standard_opcode_lengths[i] is the number of operands for the
682 standard opcode whose value is i. This means that
683 standard_opcode_lengths[0] is unused, and the last meaningful
684 element is standard_opcode_lengths[opcode_base - 1]. */
685 unsigned char *standard_opcode_lengths
;
687 /* The include_directories table. NOTE! These strings are not
688 allocated with xmalloc; instead, they are pointers into
689 debug_line_buffer. If you try to free them, `free' will get
691 unsigned int num_include_dirs
, include_dirs_size
;
694 /* The file_names table. NOTE! These strings are not allocated
695 with xmalloc; instead, they are pointers into debug_line_buffer.
696 Don't try to free them directly. */
697 unsigned int num_file_names
, file_names_size
;
701 unsigned int dir_index
;
702 unsigned int mod_time
;
704 int included_p
; /* Non-zero if referenced by the Line Number Program. */
705 struct symtab
*symtab
; /* The associated symbol table, if any. */
708 /* The start and end of the statement program following this
709 header. These point into dwarf2_per_objfile->line_buffer. */
710 gdb_byte
*statement_program_start
, *statement_program_end
;
713 /* When we construct a partial symbol table entry we only
714 need this much information. */
715 struct partial_die_info
717 /* Offset of this DIE. */
720 /* DWARF-2 tag for this DIE. */
721 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
723 /* Assorted flags describing the data found in this DIE. */
724 unsigned int has_children
: 1;
725 unsigned int is_external
: 1;
726 unsigned int is_declaration
: 1;
727 unsigned int has_type
: 1;
728 unsigned int has_specification
: 1;
729 unsigned int has_pc_info
: 1;
730 unsigned int may_be_inlined
: 1;
732 /* Flag set if the SCOPE field of this structure has been
734 unsigned int scope_set
: 1;
736 /* Flag set if the DIE has a byte_size attribute. */
737 unsigned int has_byte_size
: 1;
739 /* Flag set if any of the DIE's children are template arguments. */
740 unsigned int has_template_arguments
: 1;
742 /* Flag set if fixup_partial_die has been called on this die. */
743 unsigned int fixup_called
: 1;
745 /* The name of this DIE. Normally the value of DW_AT_name, but
746 sometimes a default name for unnamed DIEs. */
749 /* The linkage name, if present. */
750 const char *linkage_name
;
752 /* The scope to prepend to our children. This is generally
753 allocated on the comp_unit_obstack, so will disappear
754 when this compilation unit leaves the cache. */
757 /* Some data associated with the partial DIE. The tag determines
758 which field is live. */
761 /* The location description associated with this DIE, if any. */
762 struct dwarf_block
*locdesc
;
763 /* The offset of an import, for DW_TAG_imported_unit. */
767 /* If HAS_PC_INFO, the PC range associated with this DIE. */
771 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
772 DW_AT_sibling, if any. */
773 /* NOTE: This member isn't strictly necessary, read_partial_die could
774 return DW_AT_sibling values to its caller load_partial_dies. */
777 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
778 DW_AT_specification (or DW_AT_abstract_origin or
780 sect_offset spec_offset
;
782 /* Pointers to this DIE's parent, first child, and next sibling,
784 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
787 /* This data structure holds the information of an abbrev. */
790 unsigned int number
; /* number identifying abbrev */
791 enum dwarf_tag tag
; /* dwarf tag */
792 unsigned short has_children
; /* boolean */
793 unsigned short num_attrs
; /* number of attributes */
794 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
795 struct abbrev_info
*next
; /* next in chain */
800 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
801 ENUM_BITFIELD(dwarf_form
) form
: 16;
804 /* Attributes have a name and a value. */
807 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
808 ENUM_BITFIELD(dwarf_form
) form
: 15;
810 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
811 field should be in u.str (existing only for DW_STRING) but it is kept
812 here for better struct attribute alignment. */
813 unsigned int string_is_canonical
: 1;
818 struct dwarf_block
*blk
;
822 struct signatured_type
*signatured_type
;
827 /* This data structure holds a complete die structure. */
830 /* DWARF-2 tag for this DIE. */
831 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
833 /* Number of attributes */
834 unsigned char num_attrs
;
836 /* True if we're presently building the full type name for the
837 type derived from this DIE. */
838 unsigned char building_fullname
: 1;
843 /* Offset in .debug_info or .debug_types section. */
846 /* The dies in a compilation unit form an n-ary tree. PARENT
847 points to this die's parent; CHILD points to the first child of
848 this node; and all the children of a given node are chained
849 together via their SIBLING fields. */
850 struct die_info
*child
; /* Its first child, if any. */
851 struct die_info
*sibling
; /* Its next sibling, if any. */
852 struct die_info
*parent
; /* Its parent, if any. */
854 /* An array of attributes, with NUM_ATTRS elements. There may be
855 zero, but it's not common and zero-sized arrays are not
856 sufficiently portable C. */
857 struct attribute attrs
[1];
860 /* Get at parts of an attribute structure. */
862 #define DW_STRING(attr) ((attr)->u.str)
863 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
864 #define DW_UNSND(attr) ((attr)->u.unsnd)
865 #define DW_BLOCK(attr) ((attr)->u.blk)
866 #define DW_SND(attr) ((attr)->u.snd)
867 #define DW_ADDR(attr) ((attr)->u.addr)
868 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
870 /* Blocks are a bunch of untyped bytes. */
875 /* Valid only if SIZE is not zero. */
879 #ifndef ATTR_ALLOC_CHUNK
880 #define ATTR_ALLOC_CHUNK 4
883 /* Allocate fields for structs, unions and enums in this size. */
884 #ifndef DW_FIELD_ALLOC_CHUNK
885 #define DW_FIELD_ALLOC_CHUNK 4
888 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
889 but this would require a corresponding change in unpack_field_as_long
891 static int bits_per_byte
= 8;
893 /* The routines that read and process dies for a C struct or C++ class
894 pass lists of data member fields and lists of member function fields
895 in an instance of a field_info structure, as defined below. */
898 /* List of data member and baseclasses fields. */
901 struct nextfield
*next
;
906 *fields
, *baseclasses
;
908 /* Number of fields (including baseclasses). */
911 /* Number of baseclasses. */
914 /* Set if the accesibility of one of the fields is not public. */
915 int non_public_fields
;
917 /* Member function fields array, entries are allocated in the order they
918 are encountered in the object file. */
921 struct nextfnfield
*next
;
922 struct fn_field fnfield
;
926 /* Member function fieldlist array, contains name of possibly overloaded
927 member function, number of overloaded member functions and a pointer
928 to the head of the member function field chain. */
933 struct nextfnfield
*head
;
937 /* Number of entries in the fnfieldlists array. */
940 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
941 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
942 struct typedef_field_list
944 struct typedef_field field
;
945 struct typedef_field_list
*next
;
948 unsigned typedef_field_list_count
;
951 /* One item on the queue of compilation units to read in full symbols
953 struct dwarf2_queue_item
955 struct dwarf2_per_cu_data
*per_cu
;
956 enum language pretend_language
;
957 struct dwarf2_queue_item
*next
;
960 /* The current queue. */
961 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
963 /* Loaded secondary compilation units are kept in memory until they
964 have not been referenced for the processing of this many
965 compilation units. Set this to zero to disable caching. Cache
966 sizes of up to at least twenty will improve startup time for
967 typical inter-CU-reference binaries, at an obvious memory cost. */
968 static int dwarf2_max_cache_age
= 5;
970 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
971 struct cmd_list_element
*c
, const char *value
)
973 fprintf_filtered (file
, _("The upper bound on the age of cached "
974 "dwarf2 compilation units is %s.\n"),
979 /* Various complaints about symbol reading that don't abort the process. */
982 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
984 complaint (&symfile_complaints
,
985 _("statement list doesn't fit in .debug_line section"));
989 dwarf2_debug_line_missing_file_complaint (void)
991 complaint (&symfile_complaints
,
992 _(".debug_line section has line data without a file"));
996 dwarf2_debug_line_missing_end_sequence_complaint (void)
998 complaint (&symfile_complaints
,
999 _(".debug_line section has line "
1000 "program sequence without an end"));
1004 dwarf2_complex_location_expr_complaint (void)
1006 complaint (&symfile_complaints
, _("location expression too complex"));
1010 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1013 complaint (&symfile_complaints
,
1014 _("const value length mismatch for '%s', got %d, expected %d"),
1019 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1021 complaint (&symfile_complaints
,
1022 _("debug info runs off end of %s section"
1024 section
->asection
->name
,
1025 bfd_get_filename (section
->asection
->owner
));
1029 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1031 complaint (&symfile_complaints
,
1032 _("macro debug info contains a "
1033 "malformed macro definition:\n`%s'"),
1038 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1040 complaint (&symfile_complaints
,
1041 _("invalid attribute class or form for '%s' in '%s'"),
1045 /* local function prototypes */
1047 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1049 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1052 static void dwarf2_find_base_address (struct die_info
*die
,
1053 struct dwarf2_cu
*cu
);
1055 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1057 static void scan_partial_symbols (struct partial_die_info
*,
1058 CORE_ADDR
*, CORE_ADDR
*,
1059 int, struct dwarf2_cu
*);
1061 static void add_partial_symbol (struct partial_die_info
*,
1062 struct dwarf2_cu
*);
1064 static void add_partial_namespace (struct partial_die_info
*pdi
,
1065 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1066 int need_pc
, struct dwarf2_cu
*cu
);
1068 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1069 CORE_ADDR
*highpc
, int need_pc
,
1070 struct dwarf2_cu
*cu
);
1072 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1073 struct dwarf2_cu
*cu
);
1075 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1076 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1077 int need_pc
, struct dwarf2_cu
*cu
);
1079 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1081 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1083 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1084 struct dwarf2_section_info
*);
1086 static void dwarf2_free_abbrev_table (void *);
1088 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1090 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
1091 struct dwarf2_cu
*);
1093 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
1094 struct dwarf2_cu
*);
1096 static struct partial_die_info
*load_partial_dies
1097 (const struct die_reader_specs
*, gdb_byte
*, int);
1099 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1100 struct partial_die_info
*,
1101 struct abbrev_info
*,
1105 static struct partial_die_info
*find_partial_die (sect_offset
,
1106 struct dwarf2_cu
*);
1108 static void fixup_partial_die (struct partial_die_info
*,
1109 struct dwarf2_cu
*);
1111 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1112 struct attribute
*, struct attr_abbrev
*,
1115 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1117 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1119 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1121 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1123 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1125 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1128 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1130 static LONGEST read_checked_initial_length_and_offset
1131 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1132 unsigned int *, unsigned int *);
1134 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1137 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1139 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1141 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1143 static char *read_indirect_string (bfd
*, gdb_byte
*,
1144 const struct comp_unit_head
*,
1147 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1149 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1151 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1154 static char *read_str_index (const struct die_reader_specs
*reader
,
1155 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1157 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1159 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1160 struct dwarf2_cu
*);
1162 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1164 struct dwarf2_cu
*);
1166 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1167 struct dwarf2_cu
*cu
);
1169 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1171 static struct die_info
*die_specification (struct die_info
*die
,
1172 struct dwarf2_cu
**);
1174 static void free_line_header (struct line_header
*lh
);
1176 static void add_file_name (struct line_header
*, char *, unsigned int,
1177 unsigned int, unsigned int);
1179 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1180 struct dwarf2_cu
*cu
);
1182 static void dwarf_decode_lines (struct line_header
*, const char *,
1183 struct dwarf2_cu
*, struct partial_symtab
*,
1186 static void dwarf2_start_subfile (char *, const char *, const char *);
1188 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1189 struct dwarf2_cu
*);
1191 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1192 struct dwarf2_cu
*, struct symbol
*);
1194 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1195 struct dwarf2_cu
*);
1197 static void dwarf2_const_value_attr (struct attribute
*attr
,
1200 struct obstack
*obstack
,
1201 struct dwarf2_cu
*cu
, LONGEST
*value
,
1203 struct dwarf2_locexpr_baton
**baton
);
1205 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1207 static int need_gnat_info (struct dwarf2_cu
*);
1209 static struct type
*die_descriptive_type (struct die_info
*,
1210 struct dwarf2_cu
*);
1212 static void set_descriptive_type (struct type
*, struct die_info
*,
1213 struct dwarf2_cu
*);
1215 static struct type
*die_containing_type (struct die_info
*,
1216 struct dwarf2_cu
*);
1218 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1219 struct dwarf2_cu
*);
1221 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1223 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1225 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1227 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1228 const char *suffix
, int physname
,
1229 struct dwarf2_cu
*cu
);
1231 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1233 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1235 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1237 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1239 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1241 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1242 struct dwarf2_cu
*, struct partial_symtab
*);
1244 static int dwarf2_get_pc_bounds (struct die_info
*,
1245 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1246 struct partial_symtab
*);
1248 static void get_scope_pc_bounds (struct die_info
*,
1249 CORE_ADDR
*, CORE_ADDR
*,
1250 struct dwarf2_cu
*);
1252 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1253 CORE_ADDR
, struct dwarf2_cu
*);
1255 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1256 struct dwarf2_cu
*);
1258 static void dwarf2_attach_fields_to_type (struct field_info
*,
1259 struct type
*, struct dwarf2_cu
*);
1261 static void dwarf2_add_member_fn (struct field_info
*,
1262 struct die_info
*, struct type
*,
1263 struct dwarf2_cu
*);
1265 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1267 struct dwarf2_cu
*);
1269 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1271 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1273 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1275 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1277 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1279 static struct type
*read_module_type (struct die_info
*die
,
1280 struct dwarf2_cu
*cu
);
1282 static const char *namespace_name (struct die_info
*die
,
1283 int *is_anonymous
, struct dwarf2_cu
*);
1285 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1287 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1289 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1290 struct dwarf2_cu
*);
1292 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1294 gdb_byte
**new_info_ptr
,
1295 struct die_info
*parent
);
1297 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1299 gdb_byte
**new_info_ptr
,
1300 struct die_info
*parent
);
1302 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1303 struct die_info
**, gdb_byte
*, int *, int);
1305 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1306 struct die_info
**, gdb_byte
*, int *);
1308 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1310 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1313 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1315 static const char *dwarf2_full_name (char *name
,
1316 struct die_info
*die
,
1317 struct dwarf2_cu
*cu
);
1319 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1320 struct dwarf2_cu
**);
1322 static const char *dwarf_tag_name (unsigned int);
1324 static const char *dwarf_attr_name (unsigned int);
1326 static const char *dwarf_form_name (unsigned int);
1328 static char *dwarf_bool_name (unsigned int);
1330 static const char *dwarf_type_encoding_name (unsigned int);
1332 static struct die_info
*sibling_die (struct die_info
*);
1334 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1336 static void dump_die_for_error (struct die_info
*);
1338 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1341 /*static*/ void dump_die (struct die_info
*, int max_level
);
1343 static void store_in_ref_table (struct die_info
*,
1344 struct dwarf2_cu
*);
1346 static int is_ref_attr (struct attribute
*);
1348 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1350 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1352 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1354 struct dwarf2_cu
**);
1356 static struct die_info
*follow_die_ref (struct die_info
*,
1358 struct dwarf2_cu
**);
1360 static struct die_info
*follow_die_sig (struct die_info
*,
1362 struct dwarf2_cu
**);
1364 static struct signatured_type
*lookup_signatured_type_at_offset
1365 (struct objfile
*objfile
,
1366 struct dwarf2_section_info
*section
, sect_offset offset
);
1368 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1370 static void read_signatured_type (struct signatured_type
*);
1372 /* memory allocation interface */
1374 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1376 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1378 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1380 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1383 static int attr_form_is_block (struct attribute
*);
1385 static int attr_form_is_section_offset (struct attribute
*);
1387 static int attr_form_is_constant (struct attribute
*);
1389 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1390 struct dwarf2_loclist_baton
*baton
,
1391 struct attribute
*attr
);
1393 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1395 struct dwarf2_cu
*cu
);
1397 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1399 struct abbrev_info
*abbrev
);
1401 static void free_stack_comp_unit (void *);
1403 static hashval_t
partial_die_hash (const void *item
);
1405 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1407 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1408 (sect_offset offset
, struct objfile
*objfile
);
1410 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1411 struct dwarf2_per_cu_data
*per_cu
);
1413 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1414 struct die_info
*comp_unit_die
,
1415 enum language pretend_language
);
1417 static void free_heap_comp_unit (void *);
1419 static void free_cached_comp_units (void *);
1421 static void age_cached_comp_units (void);
1423 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1425 static struct type
*set_die_type (struct die_info
*, struct type
*,
1426 struct dwarf2_cu
*);
1428 static void create_all_comp_units (struct objfile
*);
1430 static int create_all_type_units (struct objfile
*);
1432 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1435 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1438 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1439 struct dwarf2_per_cu_data
*);
1441 static void dwarf2_mark (struct dwarf2_cu
*);
1443 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1445 static struct type
*get_die_type_at_offset (sect_offset
,
1446 struct dwarf2_per_cu_data
*per_cu
);
1448 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1450 static void dwarf2_release_queue (void *dummy
);
1452 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1453 enum language pretend_language
);
1455 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1456 struct dwarf2_per_cu_data
*per_cu
,
1457 enum language pretend_language
);
1459 static void process_queue (void);
1461 static void find_file_and_directory (struct die_info
*die
,
1462 struct dwarf2_cu
*cu
,
1463 char **name
, char **comp_dir
);
1465 static char *file_full_name (int file
, struct line_header
*lh
,
1466 const char *comp_dir
);
1468 static void init_cutu_and_read_dies
1469 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1470 die_reader_func_ftype
*die_reader_func
, void *data
);
1472 static void init_cutu_and_read_dies_simple
1473 (struct dwarf2_per_cu_data
*this_cu
,
1474 die_reader_func_ftype
*die_reader_func
, void *data
);
1476 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1478 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1480 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1482 static struct dwo_unit
*lookup_dwo_comp_unit
1483 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1485 static struct dwo_unit
*lookup_dwo_type_unit
1486 (struct signatured_type
*, char *, const char *);
1488 static void free_dwo_file_cleanup (void *);
1490 static void munmap_section_buffer (struct dwarf2_section_info
*);
1492 static void process_cu_includes (void);
1496 /* Convert VALUE between big- and little-endian. */
1498 byte_swap (offset_type value
)
1502 result
= (value
& 0xff) << 24;
1503 result
|= (value
& 0xff00) << 8;
1504 result
|= (value
& 0xff0000) >> 8;
1505 result
|= (value
& 0xff000000) >> 24;
1509 #define MAYBE_SWAP(V) byte_swap (V)
1512 #define MAYBE_SWAP(V) (V)
1513 #endif /* WORDS_BIGENDIAN */
1515 /* The suffix for an index file. */
1516 #define INDEX_SUFFIX ".gdb-index"
1518 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1519 struct dwarf2_cu
*cu
);
1521 /* Try to locate the sections we need for DWARF 2 debugging
1522 information and return true if we have enough to do something.
1523 NAMES points to the dwarf2 section names, or is NULL if the standard
1524 ELF names are used. */
1527 dwarf2_has_info (struct objfile
*objfile
,
1528 const struct dwarf2_debug_sections
*names
)
1530 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1531 if (!dwarf2_per_objfile
)
1533 /* Initialize per-objfile state. */
1534 struct dwarf2_per_objfile
*data
1535 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1537 memset (data
, 0, sizeof (*data
));
1538 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1539 dwarf2_per_objfile
= data
;
1541 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1543 dwarf2_per_objfile
->objfile
= objfile
;
1545 return (dwarf2_per_objfile
->info
.asection
!= NULL
1546 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1549 /* When loading sections, we look either for uncompressed section or for
1550 compressed section names. */
1553 section_is_p (const char *section_name
,
1554 const struct dwarf2_section_names
*names
)
1556 if (names
->normal
!= NULL
1557 && strcmp (section_name
, names
->normal
) == 0)
1559 if (names
->compressed
!= NULL
1560 && strcmp (section_name
, names
->compressed
) == 0)
1565 /* This function is mapped across the sections and remembers the
1566 offset and size of each of the debugging sections we are interested
1570 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1572 const struct dwarf2_debug_sections
*names
;
1575 names
= &dwarf2_elf_names
;
1577 names
= (const struct dwarf2_debug_sections
*) vnames
;
1579 if (section_is_p (sectp
->name
, &names
->info
))
1581 dwarf2_per_objfile
->info
.asection
= sectp
;
1582 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1584 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1586 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1587 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1589 else if (section_is_p (sectp
->name
, &names
->line
))
1591 dwarf2_per_objfile
->line
.asection
= sectp
;
1592 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1594 else if (section_is_p (sectp
->name
, &names
->loc
))
1596 dwarf2_per_objfile
->loc
.asection
= sectp
;
1597 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1599 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1601 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1602 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1604 else if (section_is_p (sectp
->name
, &names
->macro
))
1606 dwarf2_per_objfile
->macro
.asection
= sectp
;
1607 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1609 else if (section_is_p (sectp
->name
, &names
->str
))
1611 dwarf2_per_objfile
->str
.asection
= sectp
;
1612 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1614 else if (section_is_p (sectp
->name
, &names
->addr
))
1616 dwarf2_per_objfile
->addr
.asection
= sectp
;
1617 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1619 else if (section_is_p (sectp
->name
, &names
->frame
))
1621 dwarf2_per_objfile
->frame
.asection
= sectp
;
1622 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1624 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1626 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1628 if (aflag
& SEC_HAS_CONTENTS
)
1630 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1631 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1634 else if (section_is_p (sectp
->name
, &names
->ranges
))
1636 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1637 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1639 else if (section_is_p (sectp
->name
, &names
->types
))
1641 struct dwarf2_section_info type_section
;
1643 memset (&type_section
, 0, sizeof (type_section
));
1644 type_section
.asection
= sectp
;
1645 type_section
.size
= bfd_get_section_size (sectp
);
1647 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1650 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1652 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1653 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1656 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1657 && bfd_section_vma (abfd
, sectp
) == 0)
1658 dwarf2_per_objfile
->has_section_at_zero
= 1;
1661 /* Decompress a section that was compressed using zlib. Store the
1662 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1665 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1666 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1668 bfd
*abfd
= sectp
->owner
;
1670 error (_("Support for zlib-compressed DWARF data (from '%s') "
1671 "is disabled in this copy of GDB"),
1672 bfd_get_filename (abfd
));
1674 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1675 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1676 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1677 bfd_size_type uncompressed_size
;
1678 gdb_byte
*uncompressed_buffer
;
1681 int header_size
= 12;
1683 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1684 || bfd_bread (compressed_buffer
,
1685 compressed_size
, abfd
) != compressed_size
)
1686 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1687 bfd_get_filename (abfd
));
1689 /* Read the zlib header. In this case, it should be "ZLIB" followed
1690 by the uncompressed section size, 8 bytes in big-endian order. */
1691 if (compressed_size
< header_size
1692 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1693 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1694 bfd_get_filename (abfd
));
1695 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1696 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1697 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1698 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1699 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1700 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1701 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1702 uncompressed_size
+= compressed_buffer
[11];
1704 /* It is possible the section consists of several compressed
1705 buffers concatenated together, so we uncompress in a loop. */
1709 strm
.avail_in
= compressed_size
- header_size
;
1710 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1711 strm
.avail_out
= uncompressed_size
;
1712 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1714 rc
= inflateInit (&strm
);
1715 while (strm
.avail_in
> 0)
1718 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1719 bfd_get_filename (abfd
), rc
);
1720 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1721 + (uncompressed_size
- strm
.avail_out
));
1722 rc
= inflate (&strm
, Z_FINISH
);
1723 if (rc
!= Z_STREAM_END
)
1724 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1725 bfd_get_filename (abfd
), rc
);
1726 rc
= inflateReset (&strm
);
1728 rc
= inflateEnd (&strm
);
1730 || strm
.avail_out
!= 0)
1731 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1732 bfd_get_filename (abfd
), rc
);
1734 do_cleanups (cleanup
);
1735 *outbuf
= uncompressed_buffer
;
1736 *outsize
= uncompressed_size
;
1740 /* A helper function that decides whether a section is empty,
1744 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1746 return info
->asection
== NULL
|| info
->size
== 0;
1749 /* Read the contents of the section INFO.
1750 OBJFILE is the main object file, but not necessarily the file where
1751 the section comes from. E.g., for DWO files INFO->asection->owner
1752 is the bfd of the DWO file.
1753 If the section is compressed, uncompress it before returning. */
1756 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1758 asection
*sectp
= info
->asection
;
1760 gdb_byte
*buf
, *retbuf
;
1761 unsigned char header
[4];
1765 info
->buffer
= NULL
;
1766 info
->map_addr
= NULL
;
1769 if (dwarf2_section_empty_p (info
))
1772 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1773 abfd
= sectp
->owner
;
1775 /* Check if the file has a 4-byte header indicating compression. */
1776 if (info
->size
> sizeof (header
)
1777 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1778 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1780 /* Upon decompression, update the buffer and its size. */
1781 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1783 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1791 pagesize
= getpagesize ();
1793 /* Only try to mmap sections which are large enough: we don't want to
1794 waste space due to fragmentation. Also, only try mmap for sections
1795 without relocations. */
1797 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1799 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1800 MAP_PRIVATE
, sectp
->filepos
,
1801 &info
->map_addr
, &info
->map_len
);
1803 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1805 #if HAVE_POSIX_MADVISE
1806 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1813 /* If we get here, we are a normal, not-compressed section. */
1815 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1817 /* When debugging .o files, we may need to apply relocations; see
1818 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1819 We never compress sections in .o files, so we only need to
1820 try this when the section is not compressed. */
1821 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1824 info
->buffer
= retbuf
;
1828 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1829 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1830 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1831 bfd_get_filename (abfd
));
1834 /* A helper function that returns the size of a section in a safe way.
1835 If you are positive that the section has been read before using the
1836 size, then it is safe to refer to the dwarf2_section_info object's
1837 "size" field directly. In other cases, you must call this
1838 function, because for compressed sections the size field is not set
1839 correctly until the section has been read. */
1841 static bfd_size_type
1842 dwarf2_section_size (struct objfile
*objfile
,
1843 struct dwarf2_section_info
*info
)
1846 dwarf2_read_section (objfile
, info
);
1850 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1854 dwarf2_get_section_info (struct objfile
*objfile
,
1855 enum dwarf2_section_enum sect
,
1856 asection
**sectp
, gdb_byte
**bufp
,
1857 bfd_size_type
*sizep
)
1859 struct dwarf2_per_objfile
*data
1860 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1861 struct dwarf2_section_info
*info
;
1863 /* We may see an objfile without any DWARF, in which case we just
1874 case DWARF2_DEBUG_FRAME
:
1875 info
= &data
->frame
;
1877 case DWARF2_EH_FRAME
:
1878 info
= &data
->eh_frame
;
1881 gdb_assert_not_reached ("unexpected section");
1884 dwarf2_read_section (objfile
, info
);
1886 *sectp
= info
->asection
;
1887 *bufp
= info
->buffer
;
1888 *sizep
= info
->size
;
1892 /* DWARF quick_symbols_functions support. */
1894 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1895 unique line tables, so we maintain a separate table of all .debug_line
1896 derived entries to support the sharing.
1897 All the quick functions need is the list of file names. We discard the
1898 line_header when we're done and don't need to record it here. */
1899 struct quick_file_names
1901 /* The offset in .debug_line of the line table. We hash on this. */
1902 unsigned int offset
;
1904 /* The number of entries in file_names, real_names. */
1905 unsigned int num_file_names
;
1907 /* The file names from the line table, after being run through
1909 const char **file_names
;
1911 /* The file names from the line table after being run through
1912 gdb_realpath. These are computed lazily. */
1913 const char **real_names
;
1916 /* When using the index (and thus not using psymtabs), each CU has an
1917 object of this type. This is used to hold information needed by
1918 the various "quick" methods. */
1919 struct dwarf2_per_cu_quick_data
1921 /* The file table. This can be NULL if there was no file table
1922 or it's currently not read in.
1923 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1924 struct quick_file_names
*file_names
;
1926 /* The corresponding symbol table. This is NULL if symbols for this
1927 CU have not yet been read. */
1928 struct symtab
*symtab
;
1930 /* A temporary mark bit used when iterating over all CUs in
1931 expand_symtabs_matching. */
1932 unsigned int mark
: 1;
1934 /* True if we've tried to read the file table and found there isn't one.
1935 There will be no point in trying to read it again next time. */
1936 unsigned int no_file_data
: 1;
1939 /* Hash function for a quick_file_names. */
1942 hash_file_name_entry (const void *e
)
1944 const struct quick_file_names
*file_data
= e
;
1946 return file_data
->offset
;
1949 /* Equality function for a quick_file_names. */
1952 eq_file_name_entry (const void *a
, const void *b
)
1954 const struct quick_file_names
*ea
= a
;
1955 const struct quick_file_names
*eb
= b
;
1957 return ea
->offset
== eb
->offset
;
1960 /* Delete function for a quick_file_names. */
1963 delete_file_name_entry (void *e
)
1965 struct quick_file_names
*file_data
= e
;
1968 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1970 xfree ((void*) file_data
->file_names
[i
]);
1971 if (file_data
->real_names
)
1972 xfree ((void*) file_data
->real_names
[i
]);
1975 /* The space for the struct itself lives on objfile_obstack,
1976 so we don't free it here. */
1979 /* Create a quick_file_names hash table. */
1982 create_quick_file_names_table (unsigned int nr_initial_entries
)
1984 return htab_create_alloc (nr_initial_entries
,
1985 hash_file_name_entry
, eq_file_name_entry
,
1986 delete_file_name_entry
, xcalloc
, xfree
);
1989 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
1990 have to be created afterwards. You should call age_cached_comp_units after
1991 processing PER_CU->CU. dw2_setup must have been already called. */
1994 load_cu (struct dwarf2_per_cu_data
*per_cu
)
1996 if (per_cu
->is_debug_types
)
1997 load_full_type_unit (per_cu
);
1999 load_full_comp_unit (per_cu
, language_minimal
);
2001 gdb_assert (per_cu
->cu
!= NULL
);
2003 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2006 /* Read in the symbols for PER_CU. */
2009 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2011 struct cleanup
*back_to
;
2013 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2015 if (dwarf2_per_objfile
->using_index
2016 ? per_cu
->v
.quick
->symtab
== NULL
2017 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2019 queue_comp_unit (per_cu
, language_minimal
);
2025 /* Age the cache, releasing compilation units that have not
2026 been used recently. */
2027 age_cached_comp_units ();
2029 do_cleanups (back_to
);
2032 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2033 the objfile from which this CU came. Returns the resulting symbol
2036 static struct symtab
*
2037 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2039 gdb_assert (dwarf2_per_objfile
->using_index
);
2040 if (!per_cu
->v
.quick
->symtab
)
2042 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2043 increment_reading_symtab ();
2044 dw2_do_instantiate_symtab (per_cu
);
2045 process_cu_includes ();
2046 do_cleanups (back_to
);
2048 return per_cu
->v
.quick
->symtab
;
2051 /* Return the CU given its index. */
2053 static struct dwarf2_per_cu_data
*
2054 dw2_get_cu (int index
)
2056 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2058 index
-= dwarf2_per_objfile
->n_comp_units
;
2059 return dwarf2_per_objfile
->all_type_units
[index
];
2061 return dwarf2_per_objfile
->all_comp_units
[index
];
2064 /* A helper function that knows how to read a 64-bit value in a way
2065 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2069 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2071 if (sizeof (ULONGEST
) < 8)
2075 /* Ignore the upper 4 bytes if they are all zero. */
2076 for (i
= 0; i
< 4; ++i
)
2077 if (bytes
[i
+ 4] != 0)
2080 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2083 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2087 /* Read the CU list from the mapped index, and use it to create all
2088 the CU objects for this objfile. Return 0 if something went wrong,
2089 1 if everything went ok. */
2092 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2093 offset_type cu_list_elements
)
2097 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2098 dwarf2_per_objfile
->all_comp_units
2099 = obstack_alloc (&objfile
->objfile_obstack
,
2100 dwarf2_per_objfile
->n_comp_units
2101 * sizeof (struct dwarf2_per_cu_data
*));
2103 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2105 struct dwarf2_per_cu_data
*the_cu
;
2106 ULONGEST offset
, length
;
2108 if (!extract_cu_value (cu_list
, &offset
)
2109 || !extract_cu_value (cu_list
+ 8, &length
))
2113 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2114 struct dwarf2_per_cu_data
);
2115 the_cu
->offset
.sect_off
= offset
;
2116 the_cu
->length
= length
;
2117 the_cu
->objfile
= objfile
;
2118 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2119 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2120 struct dwarf2_per_cu_quick_data
);
2121 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2127 /* Create the signatured type hash table from the index. */
2130 create_signatured_type_table_from_index (struct objfile
*objfile
,
2131 struct dwarf2_section_info
*section
,
2132 const gdb_byte
*bytes
,
2133 offset_type elements
)
2136 htab_t sig_types_hash
;
2138 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2139 dwarf2_per_objfile
->all_type_units
2140 = obstack_alloc (&objfile
->objfile_obstack
,
2141 dwarf2_per_objfile
->n_type_units
2142 * sizeof (struct dwarf2_per_cu_data
*));
2144 sig_types_hash
= allocate_signatured_type_table (objfile
);
2146 for (i
= 0; i
< elements
; i
+= 3)
2148 struct signatured_type
*sig_type
;
2149 ULONGEST offset
, type_offset_in_tu
, signature
;
2152 if (!extract_cu_value (bytes
, &offset
)
2153 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2155 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2158 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2159 struct signatured_type
);
2160 sig_type
->signature
= signature
;
2161 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2162 sig_type
->per_cu
.is_debug_types
= 1;
2163 sig_type
->per_cu
.info_or_types_section
= section
;
2164 sig_type
->per_cu
.offset
.sect_off
= offset
;
2165 sig_type
->per_cu
.objfile
= objfile
;
2166 sig_type
->per_cu
.v
.quick
2167 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2168 struct dwarf2_per_cu_quick_data
);
2170 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2173 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2176 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2181 /* Read the address map data from the mapped index, and use it to
2182 populate the objfile's psymtabs_addrmap. */
2185 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2187 const gdb_byte
*iter
, *end
;
2188 struct obstack temp_obstack
;
2189 struct addrmap
*mutable_map
;
2190 struct cleanup
*cleanup
;
2193 obstack_init (&temp_obstack
);
2194 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2195 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2197 iter
= index
->address_table
;
2198 end
= iter
+ index
->address_table_size
;
2200 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2204 ULONGEST hi
, lo
, cu_index
;
2205 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2207 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2209 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2212 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2213 dw2_get_cu (cu_index
));
2216 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2217 &objfile
->objfile_obstack
);
2218 do_cleanups (cleanup
);
2221 /* The hash function for strings in the mapped index. This is the same as
2222 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2223 implementation. This is necessary because the hash function is tied to the
2224 format of the mapped index file. The hash values do not have to match with
2227 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2230 mapped_index_string_hash (int index_version
, const void *p
)
2232 const unsigned char *str
= (const unsigned char *) p
;
2236 while ((c
= *str
++) != 0)
2238 if (index_version
>= 5)
2240 r
= r
* 67 + c
- 113;
2246 /* Find a slot in the mapped index INDEX for the object named NAME.
2247 If NAME is found, set *VEC_OUT to point to the CU vector in the
2248 constant pool and return 1. If NAME cannot be found, return 0. */
2251 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2252 offset_type
**vec_out
)
2254 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2256 offset_type slot
, step
;
2257 int (*cmp
) (const char *, const char *);
2259 if (current_language
->la_language
== language_cplus
2260 || current_language
->la_language
== language_java
2261 || current_language
->la_language
== language_fortran
)
2263 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2265 const char *paren
= strchr (name
, '(');
2271 dup
= xmalloc (paren
- name
+ 1);
2272 memcpy (dup
, name
, paren
- name
);
2273 dup
[paren
- name
] = 0;
2275 make_cleanup (xfree
, dup
);
2280 /* Index version 4 did not support case insensitive searches. But the
2281 indices for case insensitive languages are built in lowercase, therefore
2282 simulate our NAME being searched is also lowercased. */
2283 hash
= mapped_index_string_hash ((index
->version
== 4
2284 && case_sensitivity
== case_sensitive_off
2285 ? 5 : index
->version
),
2288 slot
= hash
& (index
->symbol_table_slots
- 1);
2289 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2290 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2294 /* Convert a slot number to an offset into the table. */
2295 offset_type i
= 2 * slot
;
2297 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2299 do_cleanups (back_to
);
2303 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2304 if (!cmp (name
, str
))
2306 *vec_out
= (offset_type
*) (index
->constant_pool
2307 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2308 do_cleanups (back_to
);
2312 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2316 /* Read the index file. If everything went ok, initialize the "quick"
2317 elements of all the CUs and return 1. Otherwise, return 0. */
2320 dwarf2_read_index (struct objfile
*objfile
)
2323 struct mapped_index
*map
;
2324 offset_type
*metadata
;
2325 const gdb_byte
*cu_list
;
2326 const gdb_byte
*types_list
= NULL
;
2327 offset_type version
, cu_list_elements
;
2328 offset_type types_list_elements
= 0;
2331 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2334 /* Older elfutils strip versions could keep the section in the main
2335 executable while splitting it for the separate debug info file. */
2336 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2337 & SEC_HAS_CONTENTS
) == 0)
2340 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2342 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2343 /* Version check. */
2344 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2345 /* Versions earlier than 3 emitted every copy of a psymbol. This
2346 causes the index to behave very poorly for certain requests. Version 3
2347 contained incomplete addrmap. So, it seems better to just ignore such
2351 static int warning_printed
= 0;
2352 if (!warning_printed
)
2354 warning (_("Skipping obsolete .gdb_index section in %s."),
2356 warning_printed
= 1;
2360 /* Index version 4 uses a different hash function than index version
2363 Versions earlier than 6 did not emit psymbols for inlined
2364 functions. Using these files will cause GDB not to be able to
2365 set breakpoints on inlined functions by name, so we ignore these
2366 indices unless the --use-deprecated-index-sections command line
2367 option was supplied. */
2368 if (version
< 6 && !use_deprecated_index_sections
)
2370 static int warning_printed
= 0;
2371 if (!warning_printed
)
2373 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2374 "--use-deprecated-index-sections to use them anyway"),
2376 warning_printed
= 1;
2380 /* Indexes with higher version than the one supported by GDB may be no
2381 longer backward compatible. */
2385 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2386 map
->version
= version
;
2387 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2389 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2392 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2393 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2397 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2398 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2399 - MAYBE_SWAP (metadata
[i
]))
2403 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2404 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2405 - MAYBE_SWAP (metadata
[i
]));
2408 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2409 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2410 - MAYBE_SWAP (metadata
[i
]))
2411 / (2 * sizeof (offset_type
)));
2414 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2416 /* Don't use the index if it's empty. */
2417 if (map
->symbol_table_slots
== 0)
2420 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2423 if (types_list_elements
)
2425 struct dwarf2_section_info
*section
;
2427 /* We can only handle a single .debug_types when we have an
2429 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2432 section
= VEC_index (dwarf2_section_info_def
,
2433 dwarf2_per_objfile
->types
, 0);
2435 if (!create_signatured_type_table_from_index (objfile
, section
,
2437 types_list_elements
))
2441 create_addrmap_from_index (objfile
, map
);
2443 dwarf2_per_objfile
->index_table
= map
;
2444 dwarf2_per_objfile
->using_index
= 1;
2445 dwarf2_per_objfile
->quick_file_names_table
=
2446 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2451 /* A helper for the "quick" functions which sets the global
2452 dwarf2_per_objfile according to OBJFILE. */
2455 dw2_setup (struct objfile
*objfile
)
2457 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2458 gdb_assert (dwarf2_per_objfile
);
2461 /* die_reader_func for dw2_get_file_names. */
2464 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2466 struct die_info
*comp_unit_die
,
2470 struct dwarf2_cu
*cu
= reader
->cu
;
2471 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2472 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2473 struct line_header
*lh
;
2474 struct attribute
*attr
;
2476 char *name
, *comp_dir
;
2478 struct quick_file_names
*qfn
;
2479 unsigned int line_offset
;
2481 /* Our callers never want to match partial units -- instead they
2482 will match the enclosing full CU. */
2483 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2485 this_cu
->v
.quick
->no_file_data
= 1;
2493 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2496 struct quick_file_names find_entry
;
2498 line_offset
= DW_UNSND (attr
);
2500 /* We may have already read in this line header (TU line header sharing).
2501 If we have we're done. */
2502 find_entry
.offset
= line_offset
;
2503 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2504 &find_entry
, INSERT
);
2507 this_cu
->v
.quick
->file_names
= *slot
;
2511 lh
= dwarf_decode_line_header (line_offset
, cu
);
2515 this_cu
->v
.quick
->no_file_data
= 1;
2519 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2520 qfn
->offset
= line_offset
;
2521 gdb_assert (slot
!= NULL
);
2524 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2526 qfn
->num_file_names
= lh
->num_file_names
;
2527 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2528 lh
->num_file_names
* sizeof (char *));
2529 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2530 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2531 qfn
->real_names
= NULL
;
2533 free_line_header (lh
);
2535 this_cu
->v
.quick
->file_names
= qfn
;
2538 /* A helper for the "quick" functions which attempts to read the line
2539 table for THIS_CU. */
2541 static struct quick_file_names
*
2542 dw2_get_file_names (struct objfile
*objfile
,
2543 struct dwarf2_per_cu_data
*this_cu
)
2545 if (this_cu
->v
.quick
->file_names
!= NULL
)
2546 return this_cu
->v
.quick
->file_names
;
2547 /* If we know there is no line data, no point in looking again. */
2548 if (this_cu
->v
.quick
->no_file_data
)
2551 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2552 in the stub for CUs, there's is no need to lookup the DWO file.
2553 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2555 if (this_cu
->is_debug_types
)
2556 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2558 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2560 if (this_cu
->v
.quick
->no_file_data
)
2562 return this_cu
->v
.quick
->file_names
;
2565 /* A helper for the "quick" functions which computes and caches the
2566 real path for a given file name from the line table. */
2569 dw2_get_real_path (struct objfile
*objfile
,
2570 struct quick_file_names
*qfn
, int index
)
2572 if (qfn
->real_names
== NULL
)
2573 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2574 qfn
->num_file_names
, sizeof (char *));
2576 if (qfn
->real_names
[index
] == NULL
)
2577 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2579 return qfn
->real_names
[index
];
2582 static struct symtab
*
2583 dw2_find_last_source_symtab (struct objfile
*objfile
)
2587 dw2_setup (objfile
);
2588 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2589 return dw2_instantiate_symtab (dw2_get_cu (index
));
2592 /* Traversal function for dw2_forget_cached_source_info. */
2595 dw2_free_cached_file_names (void **slot
, void *info
)
2597 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2599 if (file_data
->real_names
)
2603 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2605 xfree ((void*) file_data
->real_names
[i
]);
2606 file_data
->real_names
[i
] = NULL
;
2614 dw2_forget_cached_source_info (struct objfile
*objfile
)
2616 dw2_setup (objfile
);
2618 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2619 dw2_free_cached_file_names
, NULL
);
2622 /* Helper function for dw2_map_symtabs_matching_filename that expands
2623 the symtabs and calls the iterator. */
2626 dw2_map_expand_apply (struct objfile
*objfile
,
2627 struct dwarf2_per_cu_data
*per_cu
,
2629 const char *full_path
, const char *real_path
,
2630 int (*callback
) (struct symtab
*, void *),
2633 struct symtab
*last_made
= objfile
->symtabs
;
2635 /* Don't visit already-expanded CUs. */
2636 if (per_cu
->v
.quick
->symtab
)
2639 /* This may expand more than one symtab, and we want to iterate over
2641 dw2_instantiate_symtab (per_cu
);
2643 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2644 objfile
->symtabs
, last_made
);
2647 /* Implementation of the map_symtabs_matching_filename method. */
2650 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2651 const char *full_path
, const char *real_path
,
2652 int (*callback
) (struct symtab
*, void *),
2656 const char *name_basename
= lbasename (name
);
2657 int name_len
= strlen (name
);
2658 int is_abs
= IS_ABSOLUTE_PATH (name
);
2660 dw2_setup (objfile
);
2662 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2663 + dwarf2_per_objfile
->n_type_units
); ++i
)
2666 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2667 struct quick_file_names
*file_data
;
2669 /* We only need to look at symtabs not already expanded. */
2670 if (per_cu
->v
.quick
->symtab
)
2673 file_data
= dw2_get_file_names (objfile
, per_cu
);
2674 if (file_data
== NULL
)
2677 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2679 const char *this_name
= file_data
->file_names
[j
];
2681 if (FILENAME_CMP (name
, this_name
) == 0
2682 || (!is_abs
&& compare_filenames_for_search (this_name
,
2685 if (dw2_map_expand_apply (objfile
, per_cu
,
2686 name
, full_path
, real_path
,
2691 /* Before we invoke realpath, which can get expensive when many
2692 files are involved, do a quick comparison of the basenames. */
2693 if (! basenames_may_differ
2694 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2697 if (full_path
!= NULL
)
2699 const char *this_real_name
= dw2_get_real_path (objfile
,
2702 if (this_real_name
!= NULL
2703 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2705 && compare_filenames_for_search (this_real_name
,
2708 if (dw2_map_expand_apply (objfile
, per_cu
,
2709 name
, full_path
, real_path
,
2715 if (real_path
!= NULL
)
2717 const char *this_real_name
= dw2_get_real_path (objfile
,
2720 if (this_real_name
!= NULL
2721 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2723 && compare_filenames_for_search (this_real_name
,
2726 if (dw2_map_expand_apply (objfile
, per_cu
,
2727 name
, full_path
, real_path
,
2738 static struct symtab
*
2739 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2740 const char *name
, domain_enum domain
)
2742 /* We do all the work in the pre_expand_symtabs_matching hook
2747 /* A helper function that expands all symtabs that hold an object
2748 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2749 symbols in block BLOCK_KIND. */
2752 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2753 int want_specific_block
,
2754 enum block_enum block_kind
,
2755 const char *name
, domain_enum domain
)
2757 struct mapped_index
*index
;
2759 dw2_setup (objfile
);
2761 index
= dwarf2_per_objfile
->index_table
;
2763 /* index_table is NULL if OBJF_READNOW. */
2768 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2770 offset_type i
, len
= MAYBE_SWAP (*vec
);
2771 for (i
= 0; i
< len
; ++i
)
2773 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2774 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2775 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2776 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2777 /* This value is only valid for index versions >= 7. */
2778 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2779 gdb_index_symbol_kind symbol_kind
=
2780 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2782 if (want_specific_block
2783 && index
->version
>= 7
2784 && want_static
!= is_static
)
2787 /* Only check the symbol's kind if it has one.
2788 Indices prior to version 7 don't record it. */
2789 if (index
->version
>= 7)
2794 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2795 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2796 /* Some types are also in VAR_DOMAIN. */
2797 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2801 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2805 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
2813 dw2_instantiate_symtab (per_cu
);
2820 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2821 enum block_enum block_kind
, const char *name
,
2824 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
2828 dw2_print_stats (struct objfile
*objfile
)
2832 dw2_setup (objfile
);
2834 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2835 + dwarf2_per_objfile
->n_type_units
); ++i
)
2837 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2839 if (!per_cu
->v
.quick
->symtab
)
2842 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2846 dw2_dump (struct objfile
*objfile
)
2848 /* Nothing worth printing. */
2852 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2853 struct section_offsets
*delta
)
2855 /* There's nothing to relocate here. */
2859 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2860 const char *func_name
)
2862 /* Note: It doesn't matter what we pass for block_kind here. */
2863 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
2868 dw2_expand_all_symtabs (struct objfile
*objfile
)
2872 dw2_setup (objfile
);
2874 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2875 + dwarf2_per_objfile
->n_type_units
); ++i
)
2877 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2879 dw2_instantiate_symtab (per_cu
);
2884 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2885 const char *filename
)
2889 dw2_setup (objfile
);
2891 /* We don't need to consider type units here.
2892 This is only called for examining code, e.g. expand_line_sal.
2893 There can be an order of magnitude (or more) more type units
2894 than comp units, and we avoid them if we can. */
2896 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2899 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2900 struct quick_file_names
*file_data
;
2902 /* We only need to look at symtabs not already expanded. */
2903 if (per_cu
->v
.quick
->symtab
)
2906 file_data
= dw2_get_file_names (objfile
, per_cu
);
2907 if (file_data
== NULL
)
2910 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2912 const char *this_name
= file_data
->file_names
[j
];
2913 if (FILENAME_CMP (this_name
, filename
) == 0)
2915 dw2_instantiate_symtab (per_cu
);
2922 /* A helper function for dw2_find_symbol_file that finds the primary
2923 file name for a given CU. This is a die_reader_func. */
2926 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
2928 struct die_info
*comp_unit_die
,
2932 const char **result_ptr
= data
;
2933 struct dwarf2_cu
*cu
= reader
->cu
;
2934 struct attribute
*attr
;
2936 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
2940 *result_ptr
= DW_STRING (attr
);
2944 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2946 struct dwarf2_per_cu_data
*per_cu
;
2948 struct quick_file_names
*file_data
;
2949 const char *filename
;
2951 dw2_setup (objfile
);
2953 /* index_table is NULL if OBJF_READNOW. */
2954 if (!dwarf2_per_objfile
->index_table
)
2958 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
2960 struct blockvector
*bv
= BLOCKVECTOR (s
);
2961 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2962 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2965 return sym
->symtab
->filename
;
2970 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2974 /* Note that this just looks at the very first one named NAME -- but
2975 actually we are looking for a function. find_main_filename
2976 should be rewritten so that it doesn't require a custom hook. It
2977 could just use the ordinary symbol tables. */
2978 /* vec[0] is the length, which must always be >0. */
2979 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
2981 if (per_cu
->v
.quick
->symtab
!= NULL
)
2982 return per_cu
->v
.quick
->symtab
->filename
;
2984 init_cutu_and_read_dies (per_cu
, 0, 0, dw2_get_primary_filename_reader
,
2991 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2992 struct objfile
*objfile
, int global
,
2993 int (*callback
) (struct block
*,
2994 struct symbol
*, void *),
2995 void *data
, symbol_compare_ftype
*match
,
2996 symbol_compare_ftype
*ordered_compare
)
2998 /* Currently unimplemented; used for Ada. The function can be called if the
2999 current language is Ada for a non-Ada objfile using GNU index. As Ada
3000 does not look for non-Ada symbols this function should just return. */
3004 dw2_expand_symtabs_matching
3005 (struct objfile
*objfile
,
3006 int (*file_matcher
) (const char *, void *),
3007 int (*name_matcher
) (const char *, void *),
3008 enum search_domain kind
,
3013 struct mapped_index
*index
;
3015 dw2_setup (objfile
);
3017 /* index_table is NULL if OBJF_READNOW. */
3018 if (!dwarf2_per_objfile
->index_table
)
3020 index
= dwarf2_per_objfile
->index_table
;
3022 if (file_matcher
!= NULL
)
3024 struct cleanup
*cleanup
;
3025 htab_t visited_found
, visited_not_found
;
3027 visited_found
= htab_create_alloc (10,
3028 htab_hash_pointer
, htab_eq_pointer
,
3029 NULL
, xcalloc
, xfree
);
3030 cleanup
= make_cleanup_htab_delete (visited_found
);
3031 visited_not_found
= htab_create_alloc (10,
3032 htab_hash_pointer
, htab_eq_pointer
,
3033 NULL
, xcalloc
, xfree
);
3034 make_cleanup_htab_delete (visited_not_found
);
3036 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3037 + dwarf2_per_objfile
->n_type_units
); ++i
)
3040 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3041 struct quick_file_names
*file_data
;
3044 per_cu
->v
.quick
->mark
= 0;
3046 /* We only need to look at symtabs not already expanded. */
3047 if (per_cu
->v
.quick
->symtab
)
3050 file_data
= dw2_get_file_names (objfile
, per_cu
);
3051 if (file_data
== NULL
)
3054 if (htab_find (visited_not_found
, file_data
) != NULL
)
3056 else if (htab_find (visited_found
, file_data
) != NULL
)
3058 per_cu
->v
.quick
->mark
= 1;
3062 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3064 if (file_matcher (file_data
->file_names
[j
], data
))
3066 per_cu
->v
.quick
->mark
= 1;
3071 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3073 : visited_not_found
,
3078 do_cleanups (cleanup
);
3081 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3083 offset_type idx
= 2 * iter
;
3085 offset_type
*vec
, vec_len
, vec_idx
;
3087 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3090 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3092 if (! (*name_matcher
) (name
, data
))
3095 /* The name was matched, now expand corresponding CUs that were
3097 vec
= (offset_type
*) (index
->constant_pool
3098 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3099 vec_len
= MAYBE_SWAP (vec
[0]);
3100 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3102 struct dwarf2_per_cu_data
*per_cu
;
3103 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3104 gdb_index_symbol_kind symbol_kind
=
3105 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3106 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3108 /* Don't crash on bad data. */
3109 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3110 + dwarf2_per_objfile
->n_comp_units
))
3113 /* Only check the symbol's kind if it has one.
3114 Indices prior to version 7 don't record it. */
3115 if (index
->version
>= 7)
3119 case VARIABLES_DOMAIN
:
3120 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3123 case FUNCTIONS_DOMAIN
:
3124 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3128 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3136 per_cu
= dw2_get_cu (cu_index
);
3137 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3138 dw2_instantiate_symtab (per_cu
);
3143 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3146 static struct symtab
*
3147 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3151 if (BLOCKVECTOR (symtab
) != NULL
3152 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3155 if (symtab
->includes
== NULL
)
3158 for (i
= 0; symtab
->includes
[i
]; ++i
)
3160 struct symtab
*s
= symtab
->includes
[i
];
3162 s
= recursively_find_pc_sect_symtab (s
, pc
);
3170 static struct symtab
*
3171 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3172 struct minimal_symbol
*msymbol
,
3174 struct obj_section
*section
,
3177 struct dwarf2_per_cu_data
*data
;
3178 struct symtab
*result
;
3180 dw2_setup (objfile
);
3182 if (!objfile
->psymtabs_addrmap
)
3185 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3189 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3190 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3191 paddress (get_objfile_arch (objfile
), pc
));
3193 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3194 gdb_assert (result
!= NULL
);
3199 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3200 void *data
, int need_fullname
)
3203 struct cleanup
*cleanup
;
3204 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3205 NULL
, xcalloc
, xfree
);
3207 cleanup
= make_cleanup_htab_delete (visited
);
3208 dw2_setup (objfile
);
3210 /* We can ignore file names coming from already-expanded CUs. */
3211 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3212 + dwarf2_per_objfile
->n_type_units
); ++i
)
3214 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3216 if (per_cu
->v
.quick
->symtab
)
3218 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3221 *slot
= per_cu
->v
.quick
->file_names
;
3225 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3226 + dwarf2_per_objfile
->n_type_units
); ++i
)
3229 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3230 struct quick_file_names
*file_data
;
3233 /* We only need to look at symtabs not already expanded. */
3234 if (per_cu
->v
.quick
->symtab
)
3237 file_data
= dw2_get_file_names (objfile
, per_cu
);
3238 if (file_data
== NULL
)
3241 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3244 /* Already visited. */
3249 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3251 const char *this_real_name
;
3254 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3256 this_real_name
= NULL
;
3257 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3261 do_cleanups (cleanup
);
3265 dw2_has_symbols (struct objfile
*objfile
)
3270 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3273 dw2_find_last_source_symtab
,
3274 dw2_forget_cached_source_info
,
3275 dw2_map_symtabs_matching_filename
,
3277 dw2_pre_expand_symtabs_matching
,
3281 dw2_expand_symtabs_for_function
,
3282 dw2_expand_all_symtabs
,
3283 dw2_expand_symtabs_with_filename
,
3284 dw2_find_symbol_file
,
3285 dw2_map_matching_symbols
,
3286 dw2_expand_symtabs_matching
,
3287 dw2_find_pc_sect_symtab
,
3288 dw2_map_symbol_filenames
3291 /* Initialize for reading DWARF for this objfile. Return 0 if this
3292 file will use psymtabs, or 1 if using the GNU index. */
3295 dwarf2_initialize_objfile (struct objfile
*objfile
)
3297 /* If we're about to read full symbols, don't bother with the
3298 indices. In this case we also don't care if some other debug
3299 format is making psymtabs, because they are all about to be
3301 if ((objfile
->flags
& OBJF_READNOW
))
3305 dwarf2_per_objfile
->using_index
= 1;
3306 create_all_comp_units (objfile
);
3307 create_all_type_units (objfile
);
3308 dwarf2_per_objfile
->quick_file_names_table
=
3309 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3311 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3312 + dwarf2_per_objfile
->n_type_units
); ++i
)
3314 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3316 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3317 struct dwarf2_per_cu_quick_data
);
3320 /* Return 1 so that gdb sees the "quick" functions. However,
3321 these functions will be no-ops because we will have expanded
3326 if (dwarf2_read_index (objfile
))
3334 /* Build a partial symbol table. */
3337 dwarf2_build_psymtabs (struct objfile
*objfile
)
3339 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3341 init_psymbol_list (objfile
, 1024);
3344 dwarf2_build_psymtabs_hard (objfile
);
3347 /* Return TRUE if OFFSET is within CU_HEADER. */
3350 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3352 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3353 sect_offset top
= { (cu_header
->offset
.sect_off
+ cu_header
->length
3354 + cu_header
->initial_length_size
) };
3356 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3359 /* Read in the comp unit header information from the debug_info at info_ptr.
3360 NOTE: This leaves members offset, first_die_offset to be filled in
3364 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3365 gdb_byte
*info_ptr
, bfd
*abfd
)
3368 unsigned int bytes_read
;
3370 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3371 cu_header
->initial_length_size
= bytes_read
;
3372 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3373 info_ptr
+= bytes_read
;
3374 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3376 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3378 info_ptr
+= bytes_read
;
3379 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3381 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3382 if (signed_addr
< 0)
3383 internal_error (__FILE__
, __LINE__
,
3384 _("read_comp_unit_head: dwarf from non elf file"));
3385 cu_header
->signed_addr_p
= signed_addr
;
3390 /* Subroutine of read_and_check_comp_unit_head and
3391 read_and_check_type_unit_head to simplify them.
3392 Perform various error checking on the header. */
3395 error_check_comp_unit_head (struct comp_unit_head
*header
,
3396 struct dwarf2_section_info
*section
,
3397 struct dwarf2_section_info
*abbrev_section
)
3399 bfd
*abfd
= section
->asection
->owner
;
3400 const char *filename
= bfd_get_filename (abfd
);
3402 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3403 error (_("Dwarf Error: wrong version in compilation unit header "
3404 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3407 if (header
->abbrev_offset
.sect_off
3408 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3409 &dwarf2_per_objfile
->abbrev
))
3410 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3411 "(offset 0x%lx + 6) [in module %s]"),
3412 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3415 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3416 avoid potential 32-bit overflow. */
3417 if (((unsigned long) header
->offset
.sect_off
3418 + header
->length
+ header
->initial_length_size
)
3420 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3421 "(offset 0x%lx + 0) [in module %s]"),
3422 (long) header
->length
, (long) header
->offset
.sect_off
,
3426 /* Read in a CU/TU header and perform some basic error checking.
3427 The contents of the header are stored in HEADER.
3428 The result is a pointer to the start of the first DIE. */
3431 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3432 struct dwarf2_section_info
*section
,
3433 struct dwarf2_section_info
*abbrev_section
,
3435 int is_debug_types_section
)
3437 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3438 bfd
*abfd
= section
->asection
->owner
;
3440 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3442 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3444 /* If we're reading a type unit, skip over the signature and
3445 type_offset fields. */
3446 if (is_debug_types_section
)
3447 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3449 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3451 error_check_comp_unit_head (header
, section
, abbrev_section
);
3456 /* Read in the types comp unit header information from .debug_types entry at
3457 types_ptr. The result is a pointer to one past the end of the header. */
3460 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3461 struct dwarf2_section_info
*section
,
3462 struct dwarf2_section_info
*abbrev_section
,
3464 ULONGEST
*signature
,
3465 cu_offset
*type_offset_in_tu
)
3467 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3468 bfd
*abfd
= section
->asection
->owner
;
3470 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3472 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3474 /* If we're reading a type unit, skip over the signature and
3475 type_offset fields. */
3476 if (signature
!= NULL
)
3477 *signature
= read_8_bytes (abfd
, info_ptr
);
3479 if (type_offset_in_tu
!= NULL
)
3480 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3481 header
->offset_size
);
3482 info_ptr
+= header
->offset_size
;
3484 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3486 error_check_comp_unit_head (header
, section
, abbrev_section
);
3491 /* Allocate a new partial symtab for file named NAME and mark this new
3492 partial symtab as being an include of PST. */
3495 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3496 struct objfile
*objfile
)
3498 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3500 subpst
->section_offsets
= pst
->section_offsets
;
3501 subpst
->textlow
= 0;
3502 subpst
->texthigh
= 0;
3504 subpst
->dependencies
= (struct partial_symtab
**)
3505 obstack_alloc (&objfile
->objfile_obstack
,
3506 sizeof (struct partial_symtab
*));
3507 subpst
->dependencies
[0] = pst
;
3508 subpst
->number_of_dependencies
= 1;
3510 subpst
->globals_offset
= 0;
3511 subpst
->n_global_syms
= 0;
3512 subpst
->statics_offset
= 0;
3513 subpst
->n_static_syms
= 0;
3514 subpst
->symtab
= NULL
;
3515 subpst
->read_symtab
= pst
->read_symtab
;
3518 /* No private part is necessary for include psymtabs. This property
3519 can be used to differentiate between such include psymtabs and
3520 the regular ones. */
3521 subpst
->read_symtab_private
= NULL
;
3524 /* Read the Line Number Program data and extract the list of files
3525 included by the source file represented by PST. Build an include
3526 partial symtab for each of these included files. */
3529 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3530 struct die_info
*die
,
3531 struct partial_symtab
*pst
)
3533 struct line_header
*lh
= NULL
;
3534 struct attribute
*attr
;
3536 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3538 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3540 return; /* No linetable, so no includes. */
3542 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3543 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3545 free_line_header (lh
);
3549 hash_signatured_type (const void *item
)
3551 const struct signatured_type
*sig_type
= item
;
3553 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3554 return sig_type
->signature
;
3558 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3560 const struct signatured_type
*lhs
= item_lhs
;
3561 const struct signatured_type
*rhs
= item_rhs
;
3563 return lhs
->signature
== rhs
->signature
;
3566 /* Allocate a hash table for signatured types. */
3569 allocate_signatured_type_table (struct objfile
*objfile
)
3571 return htab_create_alloc_ex (41,
3572 hash_signatured_type
,
3575 &objfile
->objfile_obstack
,
3576 hashtab_obstack_allocate
,
3577 dummy_obstack_deallocate
);
3580 /* A helper function to add a signatured type CU to a table. */
3583 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3585 struct signatured_type
*sigt
= *slot
;
3586 struct dwarf2_per_cu_data
***datap
= datum
;
3588 **datap
= &sigt
->per_cu
;
3594 /* Create the hash table of all entries in the .debug_types section.
3595 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3596 The result is a pointer to the hash table or NULL if there are
3600 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3601 VEC (dwarf2_section_info_def
) *types
)
3603 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3604 htab_t types_htab
= NULL
;
3606 struct dwarf2_section_info
*section
;
3607 struct dwarf2_section_info
*abbrev_section
;
3609 if (VEC_empty (dwarf2_section_info_def
, types
))
3612 abbrev_section
= (dwo_file
!= NULL
3613 ? &dwo_file
->sections
.abbrev
3614 : &dwarf2_per_objfile
->abbrev
);
3617 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3621 gdb_byte
*info_ptr
, *end_ptr
;
3623 dwarf2_read_section (objfile
, section
);
3624 info_ptr
= section
->buffer
;
3626 if (info_ptr
== NULL
)
3629 /* We can't set abfd until now because the section may be empty or
3630 not present, in which case section->asection will be NULL. */
3631 abfd
= section
->asection
->owner
;
3633 if (types_htab
== NULL
)
3636 types_htab
= allocate_dwo_unit_table (objfile
);
3638 types_htab
= allocate_signatured_type_table (objfile
);
3641 if (dwarf2_die_debug
)
3642 fprintf_unfiltered (gdb_stdlog
, "Reading signatured types for %s:\n",
3643 bfd_get_filename (abfd
));
3645 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3646 because we don't need to read any dies: the signature is in the
3649 end_ptr
= info_ptr
+ section
->size
;
3650 while (info_ptr
< end_ptr
)
3653 cu_offset type_offset_in_tu
;
3655 struct signatured_type
*sig_type
;
3656 struct dwo_unit
*dwo_tu
;
3658 gdb_byte
*ptr
= info_ptr
;
3659 struct comp_unit_head header
;
3660 unsigned int length
;
3662 offset
.sect_off
= ptr
- section
->buffer
;
3664 /* We need to read the type's signature in order to build the hash
3665 table, but we don't need anything else just yet. */
3667 ptr
= read_and_check_type_unit_head (&header
, section
,
3668 abbrev_section
, ptr
,
3669 &signature
, &type_offset_in_tu
);
3671 length
= header
.initial_length_size
+ header
.length
;
3673 /* Skip dummy type units. */
3674 if (ptr
>= info_ptr
+ length
3675 || peek_abbrev_code (abfd
, ptr
) == 0)
3677 info_ptr
+= header
.initial_length_size
+ header
.length
;
3684 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3686 dwo_tu
->dwo_file
= dwo_file
;
3687 dwo_tu
->signature
= signature
;
3688 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3689 dwo_tu
->info_or_types_section
= section
;
3690 dwo_tu
->offset
= offset
;
3691 dwo_tu
->length
= length
;
3695 /* N.B.: type_offset is not usable if this type uses a DWO file.
3696 The real type_offset is in the DWO file. */
3698 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3699 struct signatured_type
);
3700 sig_type
->signature
= signature
;
3701 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3702 sig_type
->per_cu
.objfile
= objfile
;
3703 sig_type
->per_cu
.is_debug_types
= 1;
3704 sig_type
->per_cu
.info_or_types_section
= section
;
3705 sig_type
->per_cu
.offset
= offset
;
3706 sig_type
->per_cu
.length
= length
;
3709 slot
= htab_find_slot (types_htab
,
3710 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3712 gdb_assert (slot
!= NULL
);
3715 sect_offset dup_offset
;
3719 const struct dwo_unit
*dup_tu
= *slot
;
3721 dup_offset
= dup_tu
->offset
;
3725 const struct signatured_type
*dup_tu
= *slot
;
3727 dup_offset
= dup_tu
->per_cu
.offset
;
3730 complaint (&symfile_complaints
,
3731 _("debug type entry at offset 0x%x is duplicate to the "
3732 "entry at offset 0x%x, signature 0x%s"),
3733 offset
.sect_off
, dup_offset
.sect_off
,
3734 phex (signature
, sizeof (signature
)));
3736 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3738 if (dwarf2_die_debug
)
3739 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3741 phex (signature
, sizeof (signature
)));
3750 /* Create the hash table of all entries in the .debug_types section,
3751 and initialize all_type_units.
3752 The result is zero if there is an error (e.g. missing .debug_types section),
3753 otherwise non-zero. */
3756 create_all_type_units (struct objfile
*objfile
)
3759 struct dwarf2_per_cu_data
**iter
;
3761 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3762 if (types_htab
== NULL
)
3764 dwarf2_per_objfile
->signatured_types
= NULL
;
3768 dwarf2_per_objfile
->signatured_types
= types_htab
;
3770 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3771 dwarf2_per_objfile
->all_type_units
3772 = obstack_alloc (&objfile
->objfile_obstack
,
3773 dwarf2_per_objfile
->n_type_units
3774 * sizeof (struct dwarf2_per_cu_data
*));
3775 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3776 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3777 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3778 == dwarf2_per_objfile
->n_type_units
);
3783 /* Lookup a signature based type for DW_FORM_ref_sig8.
3784 Returns NULL if signature SIG is not present in the table. */
3786 static struct signatured_type
*
3787 lookup_signatured_type (ULONGEST sig
)
3789 struct signatured_type find_entry
, *entry
;
3791 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3793 complaint (&symfile_complaints
,
3794 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3798 find_entry
.signature
= sig
;
3799 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3803 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3806 init_cu_die_reader (struct die_reader_specs
*reader
,
3807 struct dwarf2_cu
*cu
,
3808 struct dwarf2_section_info
*section
,
3809 struct dwo_file
*dwo_file
)
3811 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3812 reader
->abfd
= section
->asection
->owner
;
3814 reader
->dwo_file
= dwo_file
;
3815 reader
->die_section
= section
;
3816 reader
->buffer
= section
->buffer
;
3817 reader
->buffer_end
= section
->buffer
+ section
->size
;
3820 /* Find the base address of the compilation unit for range lists and
3821 location lists. It will normally be specified by DW_AT_low_pc.
3822 In DWARF-3 draft 4, the base address could be overridden by
3823 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3824 compilation units with discontinuous ranges. */
3827 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3829 struct attribute
*attr
;
3832 cu
->base_address
= 0;
3834 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3837 cu
->base_address
= DW_ADDR (attr
);
3842 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3845 cu
->base_address
= DW_ADDR (attr
);
3851 /* Initialize a CU (or TU) and read its DIEs.
3852 If the CU defers to a DWO file, read the DWO file as well.
3854 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3855 Otherwise, a new CU is allocated with xmalloc.
3857 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3858 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3860 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3861 linker) then DIE_READER_FUNC will not get called. */
3864 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3865 int use_existing_cu
, int keep
,
3866 die_reader_func_ftype
*die_reader_func
,
3869 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3870 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3871 bfd
*abfd
= section
->asection
->owner
;
3872 struct dwarf2_cu
*cu
;
3873 gdb_byte
*begin_info_ptr
, *info_ptr
;
3874 struct die_reader_specs reader
;
3875 struct die_info
*comp_unit_die
;
3877 struct attribute
*attr
;
3878 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3879 struct signatured_type
*sig_type
= NULL
;
3880 struct dwarf2_section_info
*abbrev_section
;
3882 if (use_existing_cu
)
3885 cleanups
= make_cleanup (null_cleanup
, NULL
);
3887 /* This is cheap if the section is already read in. */
3888 dwarf2_read_section (objfile
, section
);
3890 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3891 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
3893 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3896 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3900 /* If !use_existing_cu, this_cu->cu must be NULL. */
3901 gdb_assert (this_cu
->cu
== NULL
);
3903 cu
= xmalloc (sizeof (*cu
));
3904 init_one_comp_unit (cu
, this_cu
);
3906 /* If an error occurs while loading, release our storage. */
3907 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3909 if (this_cu
->is_debug_types
)
3913 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
3914 abbrev_section
, info_ptr
,
3917 /* There's no way to get from PER_CU to its containing
3918 struct signatured_type.
3919 But we have the signature so we can use that. */
3920 sig_type
= lookup_signatured_type (signature
);
3921 /* We've already scanned all the signatured types,
3922 this must succeed. */
3923 gdb_assert (sig_type
!= NULL
);
3924 gdb_assert (&sig_type
->per_cu
== this_cu
);
3925 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3927 /* LENGTH has not been set yet for type units. */
3928 this_cu
->length
= cu
->header
.length
+ cu
->header
.initial_length_size
;
3930 /* Establish the type offset that can be used to lookup the type. */
3931 sig_type
->type_offset_in_section
.sect_off
=
3932 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3936 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
3940 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3941 gdb_assert (this_cu
->length
3942 == cu
->header
.length
+ cu
->header
.initial_length_size
);
3946 /* Skip dummy compilation units. */
3947 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3948 || peek_abbrev_code (abfd
, info_ptr
) == 0)
3950 do_cleanups (cleanups
);
3954 /* Read the abbrevs for this compilation unit into a table. */
3955 if (cu
->dwarf2_abbrevs
== NULL
)
3957 dwarf2_read_abbrevs (cu
, abbrev_section
);
3958 make_cleanup (dwarf2_free_abbrev_table
, cu
);
3961 /* Read the top level CU/TU die. */
3962 init_cu_die_reader (&reader
, cu
, section
, NULL
);
3963 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
3965 /* If we have a DWO stub, process it and then read in the DWO file.
3966 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
3967 a DWO CU, that this test will fail. */
3968 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
3971 char *dwo_name
= DW_STRING (attr
);
3972 const char *comp_dir
;
3973 struct dwo_unit
*dwo_unit
;
3974 ULONGEST signature
; /* Or dwo_id. */
3975 struct attribute
*stmt_list
, *low_pc
, *high_pc
, *ranges
;
3976 int i
,num_extra_attrs
;
3977 struct dwarf2_section_info
*dwo_abbrev_section
;
3980 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
3981 " has children (offset 0x%x) [in module %s]"),
3982 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
3984 /* These attributes aren't processed until later:
3985 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
3986 However, the attribute is found in the stub which we won't have later.
3987 In order to not impose this complication on the rest of the code,
3988 we read them here and copy them to the DWO CU/TU die. */
3989 stmt_list
= low_pc
= high_pc
= ranges
= NULL
;
3991 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
3993 if (! this_cu
->is_debug_types
)
3994 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3995 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
3996 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
3997 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
3999 /* There should be a DW_AT_addr_base attribute here (if needed).
4000 We need the value before we can process DW_FORM_GNU_addr_index. */
4002 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4004 cu
->addr_base
= DW_UNSND (attr
);
4006 /* There should be a DW_AT_ranges_base attribute here (if needed).
4007 We need the value before we can process DW_AT_ranges. */
4008 cu
->ranges_base
= 0;
4009 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4011 cu
->ranges_base
= DW_UNSND (attr
);
4013 if (this_cu
->is_debug_types
)
4015 gdb_assert (sig_type
!= NULL
);
4016 signature
= sig_type
->signature
;
4020 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4022 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4024 signature
= DW_UNSND (attr
);
4027 /* We may need the comp_dir in order to find the DWO file. */
4029 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4031 comp_dir
= DW_STRING (attr
);
4033 if (this_cu
->is_debug_types
)
4034 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
4036 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
4039 if (dwo_unit
== NULL
)
4041 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4042 " with ID %s [in module %s]"),
4043 this_cu
->offset
.sect_off
,
4044 phex (signature
, sizeof (signature
)),
4048 /* Set up for reading the DWO CU/TU. */
4049 cu
->dwo_unit
= dwo_unit
;
4050 section
= dwo_unit
->info_or_types_section
;
4051 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4052 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4053 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4055 if (this_cu
->is_debug_types
)
4059 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4063 gdb_assert (sig_type
->signature
== signature
);
4064 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4065 gdb_assert (dwo_unit
->length
4066 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4068 /* Establish the type offset that can be used to lookup the type.
4069 For DWO files, we don't know it until now. */
4070 sig_type
->type_offset_in_section
.sect_off
=
4071 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4075 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4078 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4079 gdb_assert (dwo_unit
->length
4080 == cu
->header
.length
+ cu
->header
.initial_length_size
);
4083 /* Discard the original CU's abbrev table, and read the DWO's. */
4084 dwarf2_free_abbrev_table (cu
);
4085 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4087 /* Read in the die, but leave space to copy over the attributes
4088 from the stub. This has the benefit of simplifying the rest of
4089 the code - all the real work is done here. */
4090 num_extra_attrs
= ((stmt_list
!= NULL
)
4093 + (ranges
!= NULL
));
4094 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4095 &has_children
, num_extra_attrs
);
4097 /* Copy over the attributes from the stub to the DWO die. */
4098 i
= comp_unit_die
->num_attrs
;
4099 if (stmt_list
!= NULL
)
4100 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4102 comp_unit_die
->attrs
[i
++] = *low_pc
;
4103 if (high_pc
!= NULL
)
4104 comp_unit_die
->attrs
[i
++] = *high_pc
;
4106 comp_unit_die
->attrs
[i
++] = *ranges
;
4107 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4109 /* Skip dummy compilation units. */
4110 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4111 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4113 do_cleanups (cleanups
);
4118 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4120 if (free_cu_cleanup
!= NULL
)
4124 /* We've successfully allocated this compilation unit. Let our
4125 caller clean it up when finished with it. */
4126 discard_cleanups (free_cu_cleanup
);
4128 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4129 So we have to manually free the abbrev table. */
4130 dwarf2_free_abbrev_table (cu
);
4132 /* Link this CU into read_in_chain. */
4133 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4134 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4137 do_cleanups (free_cu_cleanup
);
4140 do_cleanups (cleanups
);
4143 /* Read CU/TU THIS_CU in section SECTION,
4144 but do not follow DW_AT_GNU_dwo_name if present.
4145 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4146 have already done the lookup to find the DWO file).
4148 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4149 THIS_CU->is_debug_types, but nothing else.
4151 We fill in THIS_CU->length.
4153 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4154 linker) then DIE_READER_FUNC will not get called.
4156 THIS_CU->cu is always freed when done.
4157 This is done in order to not leave THIS_CU->cu in a state where we have
4158 to care whether it refers to the "main" CU or the DWO CU. */
4161 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4162 struct dwarf2_section_info
*abbrev_section
,
4163 struct dwo_file
*dwo_file
,
4164 die_reader_func_ftype
*die_reader_func
,
4167 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4168 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4169 bfd
*abfd
= section
->asection
->owner
;
4170 struct dwarf2_cu cu
;
4171 gdb_byte
*begin_info_ptr
, *info_ptr
;
4172 struct die_reader_specs reader
;
4173 struct cleanup
*cleanups
;
4174 struct die_info
*comp_unit_die
;
4177 gdb_assert (this_cu
->cu
== NULL
);
4179 /* This is cheap if the section is already read in. */
4180 dwarf2_read_section (objfile
, section
);
4182 init_one_comp_unit (&cu
, this_cu
);
4184 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4186 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4187 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4188 abbrev_section
, info_ptr
,
4189 this_cu
->is_debug_types
);
4191 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
4193 /* Skip dummy compilation units. */
4194 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4195 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4197 do_cleanups (cleanups
);
4201 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4202 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4204 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4205 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4207 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4209 do_cleanups (cleanups
);
4212 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4213 does not lookup the specified DWO file.
4214 This cannot be used to read DWO files.
4216 THIS_CU->cu is always freed when done.
4217 This is done in order to not leave THIS_CU->cu in a state where we have
4218 to care whether it refers to the "main" CU or the DWO CU.
4219 We can revisit this if the data shows there's a performance issue. */
4222 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4223 die_reader_func_ftype
*die_reader_func
,
4226 init_cutu_and_read_dies_no_follow (this_cu
,
4227 &dwarf2_per_objfile
->abbrev
,
4229 die_reader_func
, data
);
4232 /* die_reader_func for process_psymtab_comp_unit. */
4235 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4237 struct die_info
*comp_unit_die
,
4241 struct dwarf2_cu
*cu
= reader
->cu
;
4242 struct objfile
*objfile
= cu
->objfile
;
4243 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4244 struct attribute
*attr
;
4246 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4247 struct partial_symtab
*pst
;
4249 const char *filename
;
4250 int *want_partial_unit_ptr
= data
;
4252 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4253 && (want_partial_unit_ptr
== NULL
4254 || !*want_partial_unit_ptr
))
4257 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4259 cu
->list_in_scope
= &file_symbols
;
4261 /* Allocate a new partial symbol table structure. */
4262 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4263 if (attr
== NULL
|| !DW_STRING (attr
))
4266 filename
= DW_STRING (attr
);
4267 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4269 /* TEXTLOW and TEXTHIGH are set below. */
4271 objfile
->global_psymbols
.next
,
4272 objfile
->static_psymbols
.next
);
4273 pst
->psymtabs_addrmap_supported
= 1;
4275 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4277 pst
->dirname
= DW_STRING (attr
);
4279 pst
->read_symtab_private
= per_cu
;
4281 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4283 /* Store the function that reads in the rest of the symbol table. */
4284 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4286 per_cu
->v
.psymtab
= pst
;
4288 dwarf2_find_base_address (comp_unit_die
, cu
);
4290 /* Possibly set the default values of LOWPC and HIGHPC from
4292 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4293 &best_highpc
, cu
, pst
);
4294 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4295 /* Store the contiguous range if it is not empty; it can be empty for
4296 CUs with no code. */
4297 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4298 best_lowpc
+ baseaddr
,
4299 best_highpc
+ baseaddr
- 1, pst
);
4301 /* Check if comp unit has_children.
4302 If so, read the rest of the partial symbols from this comp unit.
4303 If not, there's no more debug_info for this comp unit. */
4306 struct partial_die_info
*first_die
;
4307 CORE_ADDR lowpc
, highpc
;
4309 lowpc
= ((CORE_ADDR
) -1);
4310 highpc
= ((CORE_ADDR
) 0);
4312 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4314 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4317 /* If we didn't find a lowpc, set it to highpc to avoid
4318 complaints from `maint check'. */
4319 if (lowpc
== ((CORE_ADDR
) -1))
4322 /* If the compilation unit didn't have an explicit address range,
4323 then use the information extracted from its child dies. */
4327 best_highpc
= highpc
;
4330 pst
->textlow
= best_lowpc
+ baseaddr
;
4331 pst
->texthigh
= best_highpc
+ baseaddr
;
4333 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4334 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4335 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4336 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4337 sort_pst_symbols (pst
);
4339 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4342 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4343 struct dwarf2_per_cu_data
*iter
;
4345 /* Fill in 'dependencies' here; we fill in 'users' in a
4347 pst
->number_of_dependencies
= len
;
4348 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4349 len
* sizeof (struct symtab
*));
4351 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4354 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4356 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4359 if (per_cu
->is_debug_types
)
4361 /* It's not clear we want to do anything with stmt lists here.
4362 Waiting to see what gcc ultimately does. */
4366 /* Get the list of files included in the current compilation unit,
4367 and build a psymtab for each of them. */
4368 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4372 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4373 Process compilation unit THIS_CU for a psymtab. */
4376 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4377 int want_partial_unit
)
4379 /* If this compilation unit was already read in, free the
4380 cached copy in order to read it in again. This is
4381 necessary because we skipped some symbols when we first
4382 read in the compilation unit (see load_partial_dies).
4383 This problem could be avoided, but the benefit is unclear. */
4384 if (this_cu
->cu
!= NULL
)
4385 free_one_cached_comp_unit (this_cu
);
4387 gdb_assert (! this_cu
->is_debug_types
);
4388 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4389 &want_partial_unit
);
4391 /* Age out any secondary CUs. */
4392 age_cached_comp_units ();
4395 /* Traversal function for htab_traverse_noresize.
4396 Process one .debug_types comp-unit. */
4399 process_psymtab_type_unit (void **slot
, void *info
)
4401 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4402 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4404 gdb_assert (per_cu
->is_debug_types
);
4405 gdb_assert (info
== NULL
);
4407 /* If this compilation unit was already read in, free the
4408 cached copy in order to read it in again. This is
4409 necessary because we skipped some symbols when we first
4410 read in the compilation unit (see load_partial_dies).
4411 This problem could be avoided, but the benefit is unclear. */
4412 if (per_cu
->cu
!= NULL
)
4413 free_one_cached_comp_unit (per_cu
);
4415 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4418 /* Age out any secondary CUs. */
4419 age_cached_comp_units ();
4424 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4425 Build partial symbol tables for the .debug_types comp-units. */
4428 build_type_psymtabs (struct objfile
*objfile
)
4430 if (! create_all_type_units (objfile
))
4433 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4434 process_psymtab_type_unit
, NULL
);
4437 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4440 psymtabs_addrmap_cleanup (void *o
)
4442 struct objfile
*objfile
= o
;
4444 objfile
->psymtabs_addrmap
= NULL
;
4447 /* Compute the 'user' field for each psymtab in OBJFILE. */
4450 set_partial_user (struct objfile
*objfile
)
4454 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4456 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4457 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4460 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4462 /* Set the 'user' field only if it is not already set. */
4463 if (pst
->dependencies
[j
]->user
== NULL
)
4464 pst
->dependencies
[j
]->user
= pst
;
4469 /* Build the partial symbol table by doing a quick pass through the
4470 .debug_info and .debug_abbrev sections. */
4473 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4475 struct cleanup
*back_to
, *addrmap_cleanup
;
4476 struct obstack temp_obstack
;
4479 if (dwarf2_read_debug
)
4481 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
4485 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4487 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4489 /* Any cached compilation units will be linked by the per-objfile
4490 read_in_chain. Make sure to free them when we're done. */
4491 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4493 build_type_psymtabs (objfile
);
4495 create_all_comp_units (objfile
);
4497 /* Create a temporary address map on a temporary obstack. We later
4498 copy this to the final obstack. */
4499 obstack_init (&temp_obstack
);
4500 make_cleanup_obstack_free (&temp_obstack
);
4501 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4502 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4504 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4506 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4508 process_psymtab_comp_unit (per_cu
, 0);
4511 set_partial_user (objfile
);
4513 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4514 &objfile
->objfile_obstack
);
4515 discard_cleanups (addrmap_cleanup
);
4517 do_cleanups (back_to
);
4519 if (dwarf2_read_debug
)
4520 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
4524 /* die_reader_func for load_partial_comp_unit. */
4527 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4529 struct die_info
*comp_unit_die
,
4533 struct dwarf2_cu
*cu
= reader
->cu
;
4535 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4537 /* Check if comp unit has_children.
4538 If so, read the rest of the partial symbols from this comp unit.
4539 If not, there's no more debug_info for this comp unit. */
4541 load_partial_dies (reader
, info_ptr
, 0);
4544 /* Load the partial DIEs for a secondary CU into memory.
4545 This is also used when rereading a primary CU with load_all_dies. */
4548 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4550 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4553 /* Create a list of all compilation units in OBJFILE.
4554 This is only done for -readnow and building partial symtabs. */
4557 create_all_comp_units (struct objfile
*objfile
)
4561 struct dwarf2_per_cu_data
**all_comp_units
;
4564 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4565 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4569 all_comp_units
= xmalloc (n_allocated
4570 * sizeof (struct dwarf2_per_cu_data
*));
4572 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4573 + dwarf2_per_objfile
->info
.size
)
4575 unsigned int length
, initial_length_size
;
4576 struct dwarf2_per_cu_data
*this_cu
;
4579 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4581 /* Read just enough information to find out where the next
4582 compilation unit is. */
4583 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4584 &initial_length_size
);
4586 /* Save the compilation unit for later lookup. */
4587 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4588 sizeof (struct dwarf2_per_cu_data
));
4589 memset (this_cu
, 0, sizeof (*this_cu
));
4590 this_cu
->offset
= offset
;
4591 this_cu
->length
= length
+ initial_length_size
;
4592 this_cu
->objfile
= objfile
;
4593 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4595 if (n_comp_units
== n_allocated
)
4598 all_comp_units
= xrealloc (all_comp_units
,
4600 * sizeof (struct dwarf2_per_cu_data
*));
4602 all_comp_units
[n_comp_units
++] = this_cu
;
4604 info_ptr
= info_ptr
+ this_cu
->length
;
4607 dwarf2_per_objfile
->all_comp_units
4608 = obstack_alloc (&objfile
->objfile_obstack
,
4609 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4610 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4611 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4612 xfree (all_comp_units
);
4613 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4616 /* Process all loaded DIEs for compilation unit CU, starting at
4617 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4618 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4619 DW_AT_ranges). If NEED_PC is set, then this function will set
4620 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4621 and record the covered ranges in the addrmap. */
4624 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4625 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4627 struct partial_die_info
*pdi
;
4629 /* Now, march along the PDI's, descending into ones which have
4630 interesting children but skipping the children of the other ones,
4631 until we reach the end of the compilation unit. */
4637 fixup_partial_die (pdi
, cu
);
4639 /* Anonymous namespaces or modules have no name but have interesting
4640 children, so we need to look at them. Ditto for anonymous
4643 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4644 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4645 || pdi
->tag
== DW_TAG_imported_unit
)
4649 case DW_TAG_subprogram
:
4650 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4652 case DW_TAG_constant
:
4653 case DW_TAG_variable
:
4654 case DW_TAG_typedef
:
4655 case DW_TAG_union_type
:
4656 if (!pdi
->is_declaration
)
4658 add_partial_symbol (pdi
, cu
);
4661 case DW_TAG_class_type
:
4662 case DW_TAG_interface_type
:
4663 case DW_TAG_structure_type
:
4664 if (!pdi
->is_declaration
)
4666 add_partial_symbol (pdi
, cu
);
4669 case DW_TAG_enumeration_type
:
4670 if (!pdi
->is_declaration
)
4671 add_partial_enumeration (pdi
, cu
);
4673 case DW_TAG_base_type
:
4674 case DW_TAG_subrange_type
:
4675 /* File scope base type definitions are added to the partial
4677 add_partial_symbol (pdi
, cu
);
4679 case DW_TAG_namespace
:
4680 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4683 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4685 case DW_TAG_imported_unit
:
4687 struct dwarf2_per_cu_data
*per_cu
;
4689 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4692 /* Go read the partial unit, if needed. */
4693 if (per_cu
->v
.psymtab
== NULL
)
4694 process_psymtab_comp_unit (per_cu
, 1);
4696 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4705 /* If the die has a sibling, skip to the sibling. */
4707 pdi
= pdi
->die_sibling
;
4711 /* Functions used to compute the fully scoped name of a partial DIE.
4713 Normally, this is simple. For C++, the parent DIE's fully scoped
4714 name is concatenated with "::" and the partial DIE's name. For
4715 Java, the same thing occurs except that "." is used instead of "::".
4716 Enumerators are an exception; they use the scope of their parent
4717 enumeration type, i.e. the name of the enumeration type is not
4718 prepended to the enumerator.
4720 There are two complexities. One is DW_AT_specification; in this
4721 case "parent" means the parent of the target of the specification,
4722 instead of the direct parent of the DIE. The other is compilers
4723 which do not emit DW_TAG_namespace; in this case we try to guess
4724 the fully qualified name of structure types from their members'
4725 linkage names. This must be done using the DIE's children rather
4726 than the children of any DW_AT_specification target. We only need
4727 to do this for structures at the top level, i.e. if the target of
4728 any DW_AT_specification (if any; otherwise the DIE itself) does not
4731 /* Compute the scope prefix associated with PDI's parent, in
4732 compilation unit CU. The result will be allocated on CU's
4733 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4734 field. NULL is returned if no prefix is necessary. */
4736 partial_die_parent_scope (struct partial_die_info
*pdi
,
4737 struct dwarf2_cu
*cu
)
4739 char *grandparent_scope
;
4740 struct partial_die_info
*parent
, *real_pdi
;
4742 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4743 then this means the parent of the specification DIE. */
4746 while (real_pdi
->has_specification
)
4747 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4749 parent
= real_pdi
->die_parent
;
4753 if (parent
->scope_set
)
4754 return parent
->scope
;
4756 fixup_partial_die (parent
, cu
);
4758 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4760 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4761 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4762 Work around this problem here. */
4763 if (cu
->language
== language_cplus
4764 && parent
->tag
== DW_TAG_namespace
4765 && strcmp (parent
->name
, "::") == 0
4766 && grandparent_scope
== NULL
)
4768 parent
->scope
= NULL
;
4769 parent
->scope_set
= 1;
4773 if (pdi
->tag
== DW_TAG_enumerator
)
4774 /* Enumerators should not get the name of the enumeration as a prefix. */
4775 parent
->scope
= grandparent_scope
;
4776 else if (parent
->tag
== DW_TAG_namespace
4777 || parent
->tag
== DW_TAG_module
4778 || parent
->tag
== DW_TAG_structure_type
4779 || parent
->tag
== DW_TAG_class_type
4780 || parent
->tag
== DW_TAG_interface_type
4781 || parent
->tag
== DW_TAG_union_type
4782 || parent
->tag
== DW_TAG_enumeration_type
)
4784 if (grandparent_scope
== NULL
)
4785 parent
->scope
= parent
->name
;
4787 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4789 parent
->name
, 0, cu
);
4793 /* FIXME drow/2004-04-01: What should we be doing with
4794 function-local names? For partial symbols, we should probably be
4796 complaint (&symfile_complaints
,
4797 _("unhandled containing DIE tag %d for DIE at %d"),
4798 parent
->tag
, pdi
->offset
.sect_off
);
4799 parent
->scope
= grandparent_scope
;
4802 parent
->scope_set
= 1;
4803 return parent
->scope
;
4806 /* Return the fully scoped name associated with PDI, from compilation unit
4807 CU. The result will be allocated with malloc. */
4810 partial_die_full_name (struct partial_die_info
*pdi
,
4811 struct dwarf2_cu
*cu
)
4815 /* If this is a template instantiation, we can not work out the
4816 template arguments from partial DIEs. So, unfortunately, we have
4817 to go through the full DIEs. At least any work we do building
4818 types here will be reused if full symbols are loaded later. */
4819 if (pdi
->has_template_arguments
)
4821 fixup_partial_die (pdi
, cu
);
4823 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4825 struct die_info
*die
;
4826 struct attribute attr
;
4827 struct dwarf2_cu
*ref_cu
= cu
;
4829 /* DW_FORM_ref_addr is using section offset. */
4831 attr
.form
= DW_FORM_ref_addr
;
4832 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4833 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4835 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4839 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4840 if (parent_scope
== NULL
)
4843 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4847 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4849 struct objfile
*objfile
= cu
->objfile
;
4851 char *actual_name
= NULL
;
4853 int built_actual_name
= 0;
4855 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4857 actual_name
= partial_die_full_name (pdi
, cu
);
4859 built_actual_name
= 1;
4861 if (actual_name
== NULL
)
4862 actual_name
= pdi
->name
;
4866 case DW_TAG_subprogram
:
4867 if (pdi
->is_external
|| cu
->language
== language_ada
)
4869 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4870 of the global scope. But in Ada, we want to be able to access
4871 nested procedures globally. So all Ada subprograms are stored
4872 in the global scope. */
4873 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4874 mst_text, objfile); */
4875 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4877 VAR_DOMAIN
, LOC_BLOCK
,
4878 &objfile
->global_psymbols
,
4879 0, pdi
->lowpc
+ baseaddr
,
4880 cu
->language
, objfile
);
4884 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4885 mst_file_text, objfile); */
4886 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4888 VAR_DOMAIN
, LOC_BLOCK
,
4889 &objfile
->static_psymbols
,
4890 0, pdi
->lowpc
+ baseaddr
,
4891 cu
->language
, objfile
);
4894 case DW_TAG_constant
:
4896 struct psymbol_allocation_list
*list
;
4898 if (pdi
->is_external
)
4899 list
= &objfile
->global_psymbols
;
4901 list
= &objfile
->static_psymbols
;
4902 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4903 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4904 list
, 0, 0, cu
->language
, objfile
);
4907 case DW_TAG_variable
:
4909 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4913 && !dwarf2_per_objfile
->has_section_at_zero
)
4915 /* A global or static variable may also have been stripped
4916 out by the linker if unused, in which case its address
4917 will be nullified; do not add such variables into partial
4918 symbol table then. */
4920 else if (pdi
->is_external
)
4923 Don't enter into the minimal symbol tables as there is
4924 a minimal symbol table entry from the ELF symbols already.
4925 Enter into partial symbol table if it has a location
4926 descriptor or a type.
4927 If the location descriptor is missing, new_symbol will create
4928 a LOC_UNRESOLVED symbol, the address of the variable will then
4929 be determined from the minimal symbol table whenever the variable
4931 The address for the partial symbol table entry is not
4932 used by GDB, but it comes in handy for debugging partial symbol
4935 if (pdi
->d
.locdesc
|| pdi
->has_type
)
4936 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4938 VAR_DOMAIN
, LOC_STATIC
,
4939 &objfile
->global_psymbols
,
4941 cu
->language
, objfile
);
4945 /* Static Variable. Skip symbols without location descriptors. */
4946 if (pdi
->d
.locdesc
== NULL
)
4948 if (built_actual_name
)
4949 xfree (actual_name
);
4952 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
4953 mst_file_data, objfile); */
4954 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4956 VAR_DOMAIN
, LOC_STATIC
,
4957 &objfile
->static_psymbols
,
4959 cu
->language
, objfile
);
4962 case DW_TAG_typedef
:
4963 case DW_TAG_base_type
:
4964 case DW_TAG_subrange_type
:
4965 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4967 VAR_DOMAIN
, LOC_TYPEDEF
,
4968 &objfile
->static_psymbols
,
4969 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4971 case DW_TAG_namespace
:
4972 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4974 VAR_DOMAIN
, LOC_TYPEDEF
,
4975 &objfile
->global_psymbols
,
4976 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4978 case DW_TAG_class_type
:
4979 case DW_TAG_interface_type
:
4980 case DW_TAG_structure_type
:
4981 case DW_TAG_union_type
:
4982 case DW_TAG_enumeration_type
:
4983 /* Skip external references. The DWARF standard says in the section
4984 about "Structure, Union, and Class Type Entries": "An incomplete
4985 structure, union or class type is represented by a structure,
4986 union or class entry that does not have a byte size attribute
4987 and that has a DW_AT_declaration attribute." */
4988 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
4990 if (built_actual_name
)
4991 xfree (actual_name
);
4995 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
4996 static vs. global. */
4997 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4999 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5000 (cu
->language
== language_cplus
5001 || cu
->language
== language_java
)
5002 ? &objfile
->global_psymbols
5003 : &objfile
->static_psymbols
,
5004 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5007 case DW_TAG_enumerator
:
5008 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5010 VAR_DOMAIN
, LOC_CONST
,
5011 (cu
->language
== language_cplus
5012 || cu
->language
== language_java
)
5013 ? &objfile
->global_psymbols
5014 : &objfile
->static_psymbols
,
5015 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5021 if (built_actual_name
)
5022 xfree (actual_name
);
5025 /* Read a partial die corresponding to a namespace; also, add a symbol
5026 corresponding to that namespace to the symbol table. NAMESPACE is
5027 the name of the enclosing namespace. */
5030 add_partial_namespace (struct partial_die_info
*pdi
,
5031 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5032 int need_pc
, struct dwarf2_cu
*cu
)
5034 /* Add a symbol for the namespace. */
5036 add_partial_symbol (pdi
, cu
);
5038 /* Now scan partial symbols in that namespace. */
5040 if (pdi
->has_children
)
5041 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5044 /* Read a partial die corresponding to a Fortran module. */
5047 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5048 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5050 /* Now scan partial symbols in that module. */
5052 if (pdi
->has_children
)
5053 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5056 /* Read a partial die corresponding to a subprogram and create a partial
5057 symbol for that subprogram. When the CU language allows it, this
5058 routine also defines a partial symbol for each nested subprogram
5059 that this subprogram contains.
5061 DIE my also be a lexical block, in which case we simply search
5062 recursively for suprograms defined inside that lexical block.
5063 Again, this is only performed when the CU language allows this
5064 type of definitions. */
5067 add_partial_subprogram (struct partial_die_info
*pdi
,
5068 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5069 int need_pc
, struct dwarf2_cu
*cu
)
5071 if (pdi
->tag
== DW_TAG_subprogram
)
5073 if (pdi
->has_pc_info
)
5075 if (pdi
->lowpc
< *lowpc
)
5076 *lowpc
= pdi
->lowpc
;
5077 if (pdi
->highpc
> *highpc
)
5078 *highpc
= pdi
->highpc
;
5082 struct objfile
*objfile
= cu
->objfile
;
5084 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5085 SECT_OFF_TEXT (objfile
));
5086 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5087 pdi
->lowpc
+ baseaddr
,
5088 pdi
->highpc
- 1 + baseaddr
,
5089 cu
->per_cu
->v
.psymtab
);
5093 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5095 if (!pdi
->is_declaration
)
5096 /* Ignore subprogram DIEs that do not have a name, they are
5097 illegal. Do not emit a complaint at this point, we will
5098 do so when we convert this psymtab into a symtab. */
5100 add_partial_symbol (pdi
, cu
);
5104 if (! pdi
->has_children
)
5107 if (cu
->language
== language_ada
)
5109 pdi
= pdi
->die_child
;
5112 fixup_partial_die (pdi
, cu
);
5113 if (pdi
->tag
== DW_TAG_subprogram
5114 || pdi
->tag
== DW_TAG_lexical_block
)
5115 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5116 pdi
= pdi
->die_sibling
;
5121 /* Read a partial die corresponding to an enumeration type. */
5124 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5125 struct dwarf2_cu
*cu
)
5127 struct partial_die_info
*pdi
;
5129 if (enum_pdi
->name
!= NULL
)
5130 add_partial_symbol (enum_pdi
, cu
);
5132 pdi
= enum_pdi
->die_child
;
5135 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5136 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5138 add_partial_symbol (pdi
, cu
);
5139 pdi
= pdi
->die_sibling
;
5143 /* Return the initial uleb128 in the die at INFO_PTR. */
5146 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5148 unsigned int bytes_read
;
5150 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5153 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5154 Return the corresponding abbrev, or NULL if the number is zero (indicating
5155 an empty DIE). In either case *BYTES_READ will be set to the length of
5156 the initial number. */
5158 static struct abbrev_info
*
5159 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5160 struct dwarf2_cu
*cu
)
5162 bfd
*abfd
= cu
->objfile
->obfd
;
5163 unsigned int abbrev_number
;
5164 struct abbrev_info
*abbrev
;
5166 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5168 if (abbrev_number
== 0)
5171 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5174 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5175 abbrev_number
, bfd_get_filename (abfd
));
5181 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5182 Returns a pointer to the end of a series of DIEs, terminated by an empty
5183 DIE. Any children of the skipped DIEs will also be skipped. */
5186 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5188 struct dwarf2_cu
*cu
= reader
->cu
;
5189 struct abbrev_info
*abbrev
;
5190 unsigned int bytes_read
;
5194 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5196 return info_ptr
+ bytes_read
;
5198 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5202 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5203 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5204 abbrev corresponding to that skipped uleb128 should be passed in
5205 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5209 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5210 struct abbrev_info
*abbrev
)
5212 unsigned int bytes_read
;
5213 struct attribute attr
;
5214 bfd
*abfd
= reader
->abfd
;
5215 struct dwarf2_cu
*cu
= reader
->cu
;
5216 gdb_byte
*buffer
= reader
->buffer
;
5217 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5218 gdb_byte
*start_info_ptr
= info_ptr
;
5219 unsigned int form
, i
;
5221 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5223 /* The only abbrev we care about is DW_AT_sibling. */
5224 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5226 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5227 if (attr
.form
== DW_FORM_ref_addr
)
5228 complaint (&symfile_complaints
,
5229 _("ignoring absolute DW_AT_sibling"));
5231 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5234 /* If it isn't DW_AT_sibling, skip this attribute. */
5235 form
= abbrev
->attrs
[i
].form
;
5239 case DW_FORM_ref_addr
:
5240 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5241 and later it is offset sized. */
5242 if (cu
->header
.version
== 2)
5243 info_ptr
+= cu
->header
.addr_size
;
5245 info_ptr
+= cu
->header
.offset_size
;
5248 info_ptr
+= cu
->header
.addr_size
;
5255 case DW_FORM_flag_present
:
5267 case DW_FORM_ref_sig8
:
5270 case DW_FORM_string
:
5271 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5272 info_ptr
+= bytes_read
;
5274 case DW_FORM_sec_offset
:
5276 info_ptr
+= cu
->header
.offset_size
;
5278 case DW_FORM_exprloc
:
5280 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5281 info_ptr
+= bytes_read
;
5283 case DW_FORM_block1
:
5284 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5286 case DW_FORM_block2
:
5287 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5289 case DW_FORM_block4
:
5290 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5294 case DW_FORM_ref_udata
:
5295 case DW_FORM_GNU_addr_index
:
5296 case DW_FORM_GNU_str_index
:
5297 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5299 case DW_FORM_indirect
:
5300 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5301 info_ptr
+= bytes_read
;
5302 /* We need to continue parsing from here, so just go back to
5304 goto skip_attribute
;
5307 error (_("Dwarf Error: Cannot handle %s "
5308 "in DWARF reader [in module %s]"),
5309 dwarf_form_name (form
),
5310 bfd_get_filename (abfd
));
5314 if (abbrev
->has_children
)
5315 return skip_children (reader
, info_ptr
);
5320 /* Locate ORIG_PDI's sibling.
5321 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5324 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5325 struct partial_die_info
*orig_pdi
,
5328 /* Do we know the sibling already? */
5330 if (orig_pdi
->sibling
)
5331 return orig_pdi
->sibling
;
5333 /* Are there any children to deal with? */
5335 if (!orig_pdi
->has_children
)
5338 /* Skip the children the long way. */
5340 return skip_children (reader
, info_ptr
);
5343 /* Expand this partial symbol table into a full symbol table. */
5346 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5352 warning (_("bug: psymtab for %s is already read in."),
5359 printf_filtered (_("Reading in symbols for %s..."),
5361 gdb_flush (gdb_stdout
);
5364 /* Restore our global data. */
5365 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5366 dwarf2_objfile_data_key
);
5368 /* If this psymtab is constructed from a debug-only objfile, the
5369 has_section_at_zero flag will not necessarily be correct. We
5370 can get the correct value for this flag by looking at the data
5371 associated with the (presumably stripped) associated objfile. */
5372 if (pst
->objfile
->separate_debug_objfile_backlink
)
5374 struct dwarf2_per_objfile
*dpo_backlink
5375 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5376 dwarf2_objfile_data_key
);
5378 dwarf2_per_objfile
->has_section_at_zero
5379 = dpo_backlink
->has_section_at_zero
;
5382 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5384 psymtab_to_symtab_1 (pst
);
5386 /* Finish up the debug error message. */
5388 printf_filtered (_("done.\n"));
5392 process_cu_includes ();
5395 /* Reading in full CUs. */
5397 /* Add PER_CU to the queue. */
5400 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5401 enum language pretend_language
)
5403 struct dwarf2_queue_item
*item
;
5406 item
= xmalloc (sizeof (*item
));
5407 item
->per_cu
= per_cu
;
5408 item
->pretend_language
= pretend_language
;
5411 if (dwarf2_queue
== NULL
)
5412 dwarf2_queue
= item
;
5414 dwarf2_queue_tail
->next
= item
;
5416 dwarf2_queue_tail
= item
;
5419 /* Process the queue. */
5422 process_queue (void)
5424 struct dwarf2_queue_item
*item
, *next_item
;
5426 if (dwarf2_read_debug
)
5428 fprintf_unfiltered (gdb_stdlog
,
5429 "Expanding one or more symtabs of objfile %s ...\n",
5430 dwarf2_per_objfile
->objfile
->name
);
5433 /* The queue starts out with one item, but following a DIE reference
5434 may load a new CU, adding it to the end of the queue. */
5435 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5437 if (dwarf2_per_objfile
->using_index
5438 ? !item
->per_cu
->v
.quick
->symtab
5439 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5440 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5442 item
->per_cu
->queued
= 0;
5443 next_item
= item
->next
;
5447 dwarf2_queue_tail
= NULL
;
5449 if (dwarf2_read_debug
)
5451 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
5452 dwarf2_per_objfile
->objfile
->name
);
5456 /* Free all allocated queue entries. This function only releases anything if
5457 an error was thrown; if the queue was processed then it would have been
5458 freed as we went along. */
5461 dwarf2_release_queue (void *dummy
)
5463 struct dwarf2_queue_item
*item
, *last
;
5465 item
= dwarf2_queue
;
5468 /* Anything still marked queued is likely to be in an
5469 inconsistent state, so discard it. */
5470 if (item
->per_cu
->queued
)
5472 if (item
->per_cu
->cu
!= NULL
)
5473 free_one_cached_comp_unit (item
->per_cu
);
5474 item
->per_cu
->queued
= 0;
5482 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5485 /* Read in full symbols for PST, and anything it depends on. */
5488 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5490 struct dwarf2_per_cu_data
*per_cu
;
5496 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5497 if (!pst
->dependencies
[i
]->readin
5498 && pst
->dependencies
[i
]->user
== NULL
)
5500 /* Inform about additional files that need to be read in. */
5503 /* FIXME: i18n: Need to make this a single string. */
5504 fputs_filtered (" ", gdb_stdout
);
5506 fputs_filtered ("and ", gdb_stdout
);
5508 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5509 wrap_here (""); /* Flush output. */
5510 gdb_flush (gdb_stdout
);
5512 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5515 per_cu
= pst
->read_symtab_private
;
5519 /* It's an include file, no symbols to read for it.
5520 Everything is in the parent symtab. */
5525 dw2_do_instantiate_symtab (per_cu
);
5528 /* Trivial hash function for die_info: the hash value of a DIE
5529 is its offset in .debug_info for this objfile. */
5532 die_hash (const void *item
)
5534 const struct die_info
*die
= item
;
5536 return die
->offset
.sect_off
;
5539 /* Trivial comparison function for die_info structures: two DIEs
5540 are equal if they have the same offset. */
5543 die_eq (const void *item_lhs
, const void *item_rhs
)
5545 const struct die_info
*die_lhs
= item_lhs
;
5546 const struct die_info
*die_rhs
= item_rhs
;
5548 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5551 /* die_reader_func for load_full_comp_unit.
5552 This is identical to read_signatured_type_reader,
5553 but is kept separate for now. */
5556 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5558 struct die_info
*comp_unit_die
,
5562 struct dwarf2_cu
*cu
= reader
->cu
;
5563 enum language
*language_ptr
= data
;
5565 gdb_assert (cu
->die_hash
== NULL
);
5567 htab_create_alloc_ex (cu
->header
.length
/ 12,
5571 &cu
->comp_unit_obstack
,
5572 hashtab_obstack_allocate
,
5573 dummy_obstack_deallocate
);
5576 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5577 &info_ptr
, comp_unit_die
);
5578 cu
->dies
= comp_unit_die
;
5579 /* comp_unit_die is not stored in die_hash, no need. */
5581 /* We try not to read any attributes in this function, because not
5582 all CUs needed for references have been loaded yet, and symbol
5583 table processing isn't initialized. But we have to set the CU language,
5584 or we won't be able to build types correctly.
5585 Similarly, if we do not read the producer, we can not apply
5586 producer-specific interpretation. */
5587 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5590 /* Load the DIEs associated with PER_CU into memory. */
5593 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5594 enum language pretend_language
)
5596 gdb_assert (! this_cu
->is_debug_types
);
5598 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5602 /* Add a DIE to the delayed physname list. */
5605 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5606 const char *name
, struct die_info
*die
,
5607 struct dwarf2_cu
*cu
)
5609 struct delayed_method_info mi
;
5611 mi
.fnfield_index
= fnfield_index
;
5615 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5618 /* A cleanup for freeing the delayed method list. */
5621 free_delayed_list (void *ptr
)
5623 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5624 if (cu
->method_list
!= NULL
)
5626 VEC_free (delayed_method_info
, cu
->method_list
);
5627 cu
->method_list
= NULL
;
5631 /* Compute the physnames of any methods on the CU's method list.
5633 The computation of method physnames is delayed in order to avoid the
5634 (bad) condition that one of the method's formal parameters is of an as yet
5638 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5641 struct delayed_method_info
*mi
;
5642 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5644 const char *physname
;
5645 struct fn_fieldlist
*fn_flp
5646 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5647 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5648 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5652 /* Go objects should be embedded in a DW_TAG_module DIE,
5653 and it's not clear if/how imported objects will appear.
5654 To keep Go support simple until that's worked out,
5655 go back through what we've read and create something usable.
5656 We could do this while processing each DIE, and feels kinda cleaner,
5657 but that way is more invasive.
5658 This is to, for example, allow the user to type "p var" or "b main"
5659 without having to specify the package name, and allow lookups
5660 of module.object to work in contexts that use the expression
5664 fixup_go_packaging (struct dwarf2_cu
*cu
)
5666 char *package_name
= NULL
;
5667 struct pending
*list
;
5670 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5672 for (i
= 0; i
< list
->nsyms
; ++i
)
5674 struct symbol
*sym
= list
->symbol
[i
];
5676 if (SYMBOL_LANGUAGE (sym
) == language_go
5677 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5679 char *this_package_name
= go_symbol_package_name (sym
);
5681 if (this_package_name
== NULL
)
5683 if (package_name
== NULL
)
5684 package_name
= this_package_name
;
5687 if (strcmp (package_name
, this_package_name
) != 0)
5688 complaint (&symfile_complaints
,
5689 _("Symtab %s has objects from two different Go packages: %s and %s"),
5690 (sym
->symtab
&& sym
->symtab
->filename
5691 ? sym
->symtab
->filename
5692 : cu
->objfile
->name
),
5693 this_package_name
, package_name
);
5694 xfree (this_package_name
);
5700 if (package_name
!= NULL
)
5702 struct objfile
*objfile
= cu
->objfile
;
5703 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5704 package_name
, objfile
);
5707 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5709 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5710 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5711 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5712 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5713 e.g., "main" finds the "main" module and not C's main(). */
5714 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5715 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5716 SYMBOL_TYPE (sym
) = type
;
5718 add_symbol_to_list (sym
, &global_symbols
);
5720 xfree (package_name
);
5724 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5726 /* Return the symtab for PER_CU. This works properly regardless of
5727 whether we're using the index or psymtabs. */
5729 static struct symtab
*
5730 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5732 return (dwarf2_per_objfile
->using_index
5733 ? per_cu
->v
.quick
->symtab
5734 : per_cu
->v
.psymtab
->symtab
);
5737 /* A helper function for computing the list of all symbol tables
5738 included by PER_CU. */
5741 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5742 htab_t all_children
,
5743 struct dwarf2_per_cu_data
*per_cu
)
5747 struct dwarf2_per_cu_data
*iter
;
5749 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5752 /* This inclusion and its children have been processed. */
5757 /* Only add a CU if it has a symbol table. */
5758 if (get_symtab (per_cu
) != NULL
)
5759 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5762 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5764 recursively_compute_inclusions (result
, all_children
, iter
);
5767 /* Compute the symtab 'includes' fields for the symtab related to
5771 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5773 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5776 struct dwarf2_per_cu_data
*iter
;
5777 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5778 htab_t all_children
;
5779 struct symtab
*symtab
= get_symtab (per_cu
);
5781 /* If we don't have a symtab, we can just skip this case. */
5785 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5786 NULL
, xcalloc
, xfree
);
5789 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5792 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5794 /* Now we have a transitive closure of all the included CUs, so
5795 we can convert it to a list of symtabs. */
5796 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5798 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5799 (len
+ 1) * sizeof (struct symtab
*));
5801 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5803 symtab
->includes
[ix
] = get_symtab (iter
);
5804 symtab
->includes
[len
] = NULL
;
5806 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5807 htab_delete (all_children
);
5811 /* Compute the 'includes' field for the symtabs of all the CUs we just
5815 process_cu_includes (void)
5818 struct dwarf2_per_cu_data
*iter
;
5821 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5824 compute_symtab_includes (iter
);
5826 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5829 /* Generate full symbol information for PER_CU, whose DIEs have
5830 already been loaded into memory. */
5833 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5834 enum language pretend_language
)
5836 struct dwarf2_cu
*cu
= per_cu
->cu
;
5837 struct objfile
*objfile
= per_cu
->objfile
;
5838 CORE_ADDR lowpc
, highpc
;
5839 struct symtab
*symtab
;
5840 struct cleanup
*back_to
, *delayed_list_cleanup
;
5843 if (dwarf2_read_debug
)
5845 fprintf_unfiltered (gdb_stdlog
,
5846 "Expanding symtab of %s at offset 0x%x\n",
5847 per_cu
->is_debug_types
? "TU" : "CU",
5848 per_cu
->offset
.sect_off
);
5851 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5854 back_to
= make_cleanup (really_free_pendings
, NULL
);
5855 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5857 cu
->list_in_scope
= &file_symbols
;
5859 cu
->language
= pretend_language
;
5860 cu
->language_defn
= language_def (cu
->language
);
5862 /* Do line number decoding in read_file_scope () */
5863 process_die (cu
->dies
, cu
);
5865 /* For now fudge the Go package. */
5866 if (cu
->language
== language_go
)
5867 fixup_go_packaging (cu
);
5869 /* Now that we have processed all the DIEs in the CU, all the types
5870 should be complete, and it should now be safe to compute all of the
5872 compute_delayed_physnames (cu
);
5873 do_cleanups (delayed_list_cleanup
);
5875 /* Some compilers don't define a DW_AT_high_pc attribute for the
5876 compilation unit. If the DW_AT_high_pc is missing, synthesize
5877 it, by scanning the DIE's below the compilation unit. */
5878 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
5880 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
5884 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
5886 /* Set symtab language to language from DW_AT_language. If the
5887 compilation is from a C file generated by language preprocessors, do
5888 not set the language if it was already deduced by start_subfile. */
5889 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
5890 symtab
->language
= cu
->language
;
5892 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
5893 produce DW_AT_location with location lists but it can be possibly
5894 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
5895 there were bugs in prologue debug info, fixed later in GCC-4.5
5896 by "unwind info for epilogues" patch (which is not directly related).
5898 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
5899 needed, it would be wrong due to missing DW_AT_producer there.
5901 Still one can confuse GDB by using non-standard GCC compilation
5902 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
5904 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
5905 symtab
->locations_valid
= 1;
5907 if (gcc_4_minor
>= 5)
5908 symtab
->epilogue_unwind_valid
= 1;
5910 symtab
->call_site_htab
= cu
->call_site_htab
;
5913 if (dwarf2_per_objfile
->using_index
)
5914 per_cu
->v
.quick
->symtab
= symtab
;
5917 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5918 pst
->symtab
= symtab
;
5922 /* Push it for inclusion processing later. */
5923 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
5925 do_cleanups (back_to
);
5927 if (dwarf2_read_debug
)
5929 fprintf_unfiltered (gdb_stdlog
,
5930 "Done expanding symtab of %s at offset 0x%x\n",
5931 per_cu
->is_debug_types
? "TU" : "CU",
5932 per_cu
->offset
.sect_off
);
5936 /* Process an imported unit DIE. */
5939 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5941 struct attribute
*attr
;
5943 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5946 struct dwarf2_per_cu_data
*per_cu
;
5947 struct symtab
*imported_symtab
;
5950 offset
= dwarf2_get_ref_die_offset (attr
);
5951 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5953 /* Queue the unit, if needed. */
5954 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
5955 load_full_comp_unit (per_cu
, cu
->language
);
5957 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
5962 /* Process a die and its children. */
5965 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
5969 case DW_TAG_padding
:
5971 case DW_TAG_compile_unit
:
5972 case DW_TAG_partial_unit
:
5973 read_file_scope (die
, cu
);
5975 case DW_TAG_type_unit
:
5976 read_type_unit_scope (die
, cu
);
5978 case DW_TAG_subprogram
:
5979 case DW_TAG_inlined_subroutine
:
5980 read_func_scope (die
, cu
);
5982 case DW_TAG_lexical_block
:
5983 case DW_TAG_try_block
:
5984 case DW_TAG_catch_block
:
5985 read_lexical_block_scope (die
, cu
);
5987 case DW_TAG_GNU_call_site
:
5988 read_call_site_scope (die
, cu
);
5990 case DW_TAG_class_type
:
5991 case DW_TAG_interface_type
:
5992 case DW_TAG_structure_type
:
5993 case DW_TAG_union_type
:
5994 process_structure_scope (die
, cu
);
5996 case DW_TAG_enumeration_type
:
5997 process_enumeration_scope (die
, cu
);
6000 /* These dies have a type, but processing them does not create
6001 a symbol or recurse to process the children. Therefore we can
6002 read them on-demand through read_type_die. */
6003 case DW_TAG_subroutine_type
:
6004 case DW_TAG_set_type
:
6005 case DW_TAG_array_type
:
6006 case DW_TAG_pointer_type
:
6007 case DW_TAG_ptr_to_member_type
:
6008 case DW_TAG_reference_type
:
6009 case DW_TAG_string_type
:
6012 case DW_TAG_base_type
:
6013 case DW_TAG_subrange_type
:
6014 case DW_TAG_typedef
:
6015 /* Add a typedef symbol for the type definition, if it has a
6017 new_symbol (die
, read_type_die (die
, cu
), cu
);
6019 case DW_TAG_common_block
:
6020 read_common_block (die
, cu
);
6022 case DW_TAG_common_inclusion
:
6024 case DW_TAG_namespace
:
6025 processing_has_namespace_info
= 1;
6026 read_namespace (die
, cu
);
6029 processing_has_namespace_info
= 1;
6030 read_module (die
, cu
);
6032 case DW_TAG_imported_declaration
:
6033 case DW_TAG_imported_module
:
6034 processing_has_namespace_info
= 1;
6035 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6036 || cu
->language
!= language_fortran
))
6037 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6038 dwarf_tag_name (die
->tag
));
6039 read_import_statement (die
, cu
);
6042 case DW_TAG_imported_unit
:
6043 process_imported_unit_die (die
, cu
);
6047 new_symbol (die
, NULL
, cu
);
6052 /* A helper function for dwarf2_compute_name which determines whether DIE
6053 needs to have the name of the scope prepended to the name listed in the
6057 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6059 struct attribute
*attr
;
6063 case DW_TAG_namespace
:
6064 case DW_TAG_typedef
:
6065 case DW_TAG_class_type
:
6066 case DW_TAG_interface_type
:
6067 case DW_TAG_structure_type
:
6068 case DW_TAG_union_type
:
6069 case DW_TAG_enumeration_type
:
6070 case DW_TAG_enumerator
:
6071 case DW_TAG_subprogram
:
6075 case DW_TAG_variable
:
6076 case DW_TAG_constant
:
6077 /* We only need to prefix "globally" visible variables. These include
6078 any variable marked with DW_AT_external or any variable that
6079 lives in a namespace. [Variables in anonymous namespaces
6080 require prefixing, but they are not DW_AT_external.] */
6082 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6084 struct dwarf2_cu
*spec_cu
= cu
;
6086 return die_needs_namespace (die_specification (die
, &spec_cu
),
6090 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6091 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6092 && die
->parent
->tag
!= DW_TAG_module
)
6094 /* A variable in a lexical block of some kind does not need a
6095 namespace, even though in C++ such variables may be external
6096 and have a mangled name. */
6097 if (die
->parent
->tag
== DW_TAG_lexical_block
6098 || die
->parent
->tag
== DW_TAG_try_block
6099 || die
->parent
->tag
== DW_TAG_catch_block
6100 || die
->parent
->tag
== DW_TAG_subprogram
)
6109 /* Retrieve the last character from a mem_file. */
6112 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6114 char *last_char_p
= (char *) object
;
6117 *last_char_p
= buffer
[length
- 1];
6120 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6121 compute the physname for the object, which include a method's:
6122 - formal parameters (C++/Java),
6123 - receiver type (Go),
6124 - return type (Java).
6126 The term "physname" is a bit confusing.
6127 For C++, for example, it is the demangled name.
6128 For Go, for example, it's the mangled name.
6130 For Ada, return the DIE's linkage name rather than the fully qualified
6131 name. PHYSNAME is ignored..
6133 The result is allocated on the objfile_obstack and canonicalized. */
6136 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6139 struct objfile
*objfile
= cu
->objfile
;
6142 name
= dwarf2_name (die
, cu
);
6144 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6145 compute it by typename_concat inside GDB. */
6146 if (cu
->language
== language_ada
6147 || (cu
->language
== language_fortran
&& physname
))
6149 /* For Ada unit, we prefer the linkage name over the name, as
6150 the former contains the exported name, which the user expects
6151 to be able to reference. Ideally, we want the user to be able
6152 to reference this entity using either natural or linkage name,
6153 but we haven't started looking at this enhancement yet. */
6154 struct attribute
*attr
;
6156 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6158 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6159 if (attr
&& DW_STRING (attr
))
6160 return DW_STRING (attr
);
6163 /* These are the only languages we know how to qualify names in. */
6165 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6166 || cu
->language
== language_fortran
))
6168 if (die_needs_namespace (die
, cu
))
6172 struct ui_file
*buf
;
6174 prefix
= determine_prefix (die
, cu
);
6175 buf
= mem_fileopen ();
6176 if (*prefix
!= '\0')
6178 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
6181 fputs_unfiltered (prefixed_name
, buf
);
6182 xfree (prefixed_name
);
6185 fputs_unfiltered (name
, buf
);
6187 /* Template parameters may be specified in the DIE's DW_AT_name, or
6188 as children with DW_TAG_template_type_param or
6189 DW_TAG_value_type_param. If the latter, add them to the name
6190 here. If the name already has template parameters, then
6191 skip this step; some versions of GCC emit both, and
6192 it is more efficient to use the pre-computed name.
6194 Something to keep in mind about this process: it is very
6195 unlikely, or in some cases downright impossible, to produce
6196 something that will match the mangled name of a function.
6197 If the definition of the function has the same debug info,
6198 we should be able to match up with it anyway. But fallbacks
6199 using the minimal symbol, for instance to find a method
6200 implemented in a stripped copy of libstdc++, will not work.
6201 If we do not have debug info for the definition, we will have to
6202 match them up some other way.
6204 When we do name matching there is a related problem with function
6205 templates; two instantiated function templates are allowed to
6206 differ only by their return types, which we do not add here. */
6208 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6210 struct attribute
*attr
;
6211 struct die_info
*child
;
6214 die
->building_fullname
= 1;
6216 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6221 struct dwarf2_locexpr_baton
*baton
;
6224 if (child
->tag
!= DW_TAG_template_type_param
6225 && child
->tag
!= DW_TAG_template_value_param
)
6230 fputs_unfiltered ("<", buf
);
6234 fputs_unfiltered (", ", buf
);
6236 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6239 complaint (&symfile_complaints
,
6240 _("template parameter missing DW_AT_type"));
6241 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6244 type
= die_type (child
, cu
);
6246 if (child
->tag
== DW_TAG_template_type_param
)
6248 c_print_type (type
, "", buf
, -1, 0);
6252 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6255 complaint (&symfile_complaints
,
6256 _("template parameter missing "
6257 "DW_AT_const_value"));
6258 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6262 dwarf2_const_value_attr (attr
, type
, name
,
6263 &cu
->comp_unit_obstack
, cu
,
6264 &value
, &bytes
, &baton
);
6266 if (TYPE_NOSIGN (type
))
6267 /* GDB prints characters as NUMBER 'CHAR'. If that's
6268 changed, this can use value_print instead. */
6269 c_printchar (value
, type
, buf
);
6272 struct value_print_options opts
;
6275 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6279 else if (bytes
!= NULL
)
6281 v
= allocate_value (type
);
6282 memcpy (value_contents_writeable (v
), bytes
,
6283 TYPE_LENGTH (type
));
6286 v
= value_from_longest (type
, value
);
6288 /* Specify decimal so that we do not depend on
6290 get_formatted_print_options (&opts
, 'd');
6292 value_print (v
, buf
, &opts
);
6298 die
->building_fullname
= 0;
6302 /* Close the argument list, with a space if necessary
6303 (nested templates). */
6304 char last_char
= '\0';
6305 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6306 if (last_char
== '>')
6307 fputs_unfiltered (" >", buf
);
6309 fputs_unfiltered (">", buf
);
6313 /* For Java and C++ methods, append formal parameter type
6314 information, if PHYSNAME. */
6316 if (physname
&& die
->tag
== DW_TAG_subprogram
6317 && (cu
->language
== language_cplus
6318 || cu
->language
== language_java
))
6320 struct type
*type
= read_type_die (die
, cu
);
6322 c_type_print_args (type
, buf
, 1, cu
->language
);
6324 if (cu
->language
== language_java
)
6326 /* For java, we must append the return type to method
6328 if (die
->tag
== DW_TAG_subprogram
)
6329 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6332 else if (cu
->language
== language_cplus
)
6334 /* Assume that an artificial first parameter is
6335 "this", but do not crash if it is not. RealView
6336 marks unnamed (and thus unused) parameters as
6337 artificial; there is no way to differentiate
6339 if (TYPE_NFIELDS (type
) > 0
6340 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6341 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6342 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6344 fputs_unfiltered (" const", buf
);
6348 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6350 ui_file_delete (buf
);
6352 if (cu
->language
== language_cplus
)
6355 = dwarf2_canonicalize_name (name
, cu
,
6356 &objfile
->objfile_obstack
);
6367 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6368 If scope qualifiers are appropriate they will be added. The result
6369 will be allocated on the objfile_obstack, or NULL if the DIE does
6370 not have a name. NAME may either be from a previous call to
6371 dwarf2_name or NULL.
6373 The output string will be canonicalized (if C++/Java). */
6376 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6378 return dwarf2_compute_name (name
, die
, cu
, 0);
6381 /* Construct a physname for the given DIE in CU. NAME may either be
6382 from a previous call to dwarf2_name or NULL. The result will be
6383 allocated on the objfile_objstack or NULL if the DIE does not have a
6386 The output string will be canonicalized (if C++/Java). */
6389 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6391 struct objfile
*objfile
= cu
->objfile
;
6392 struct attribute
*attr
;
6393 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6394 struct cleanup
*back_to
;
6397 /* In this case dwarf2_compute_name is just a shortcut not building anything
6399 if (!die_needs_namespace (die
, cu
))
6400 return dwarf2_compute_name (name
, die
, cu
, 1);
6402 back_to
= make_cleanup (null_cleanup
, NULL
);
6404 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6406 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6408 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6410 if (attr
&& DW_STRING (attr
))
6414 mangled
= DW_STRING (attr
);
6416 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6417 type. It is easier for GDB users to search for such functions as
6418 `name(params)' than `long name(params)'. In such case the minimal
6419 symbol names do not match the full symbol names but for template
6420 functions there is never a need to look up their definition from their
6421 declaration so the only disadvantage remains the minimal symbol
6422 variant `long name(params)' does not have the proper inferior type.
6425 if (cu
->language
== language_go
)
6427 /* This is a lie, but we already lie to the caller new_symbol_full.
6428 new_symbol_full assumes we return the mangled name.
6429 This just undoes that lie until things are cleaned up. */
6434 demangled
= cplus_demangle (mangled
,
6435 (DMGL_PARAMS
| DMGL_ANSI
6436 | (cu
->language
== language_java
6437 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6442 make_cleanup (xfree
, demangled
);
6452 if (canon
== NULL
|| check_physname
)
6454 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6456 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6458 /* It may not mean a bug in GDB. The compiler could also
6459 compute DW_AT_linkage_name incorrectly. But in such case
6460 GDB would need to be bug-to-bug compatible. */
6462 complaint (&symfile_complaints
,
6463 _("Computed physname <%s> does not match demangled <%s> "
6464 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6465 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6467 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6468 is available here - over computed PHYSNAME. It is safer
6469 against both buggy GDB and buggy compilers. */
6483 retval
= obsavestring (retval
, strlen (retval
),
6484 &objfile
->objfile_obstack
);
6486 do_cleanups (back_to
);
6490 /* Read the import statement specified by the given die and record it. */
6493 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6495 struct objfile
*objfile
= cu
->objfile
;
6496 struct attribute
*import_attr
;
6497 struct die_info
*imported_die
, *child_die
;
6498 struct dwarf2_cu
*imported_cu
;
6499 const char *imported_name
;
6500 const char *imported_name_prefix
;
6501 const char *canonical_name
;
6502 const char *import_alias
;
6503 const char *imported_declaration
= NULL
;
6504 const char *import_prefix
;
6505 VEC (const_char_ptr
) *excludes
= NULL
;
6506 struct cleanup
*cleanups
;
6510 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6511 if (import_attr
== NULL
)
6513 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6514 dwarf_tag_name (die
->tag
));
6519 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6520 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6521 if (imported_name
== NULL
)
6523 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6525 The import in the following code:
6539 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6540 <52> DW_AT_decl_file : 1
6541 <53> DW_AT_decl_line : 6
6542 <54> DW_AT_import : <0x75>
6543 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6545 <5b> DW_AT_decl_file : 1
6546 <5c> DW_AT_decl_line : 2
6547 <5d> DW_AT_type : <0x6e>
6549 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6550 <76> DW_AT_byte_size : 4
6551 <77> DW_AT_encoding : 5 (signed)
6553 imports the wrong die ( 0x75 instead of 0x58 ).
6554 This case will be ignored until the gcc bug is fixed. */
6558 /* Figure out the local name after import. */
6559 import_alias
= dwarf2_name (die
, cu
);
6561 /* Figure out where the statement is being imported to. */
6562 import_prefix
= determine_prefix (die
, cu
);
6564 /* Figure out what the scope of the imported die is and prepend it
6565 to the name of the imported die. */
6566 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6568 if (imported_die
->tag
!= DW_TAG_namespace
6569 && imported_die
->tag
!= DW_TAG_module
)
6571 imported_declaration
= imported_name
;
6572 canonical_name
= imported_name_prefix
;
6574 else if (strlen (imported_name_prefix
) > 0)
6576 temp
= alloca (strlen (imported_name_prefix
)
6577 + 2 + strlen (imported_name
) + 1);
6578 strcpy (temp
, imported_name_prefix
);
6579 strcat (temp
, "::");
6580 strcat (temp
, imported_name
);
6581 canonical_name
= temp
;
6584 canonical_name
= imported_name
;
6586 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6588 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6589 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6590 child_die
= sibling_die (child_die
))
6592 /* DWARF-4: A Fortran use statement with a “rename list” may be
6593 represented by an imported module entry with an import attribute
6594 referring to the module and owned entries corresponding to those
6595 entities that are renamed as part of being imported. */
6597 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6599 complaint (&symfile_complaints
,
6600 _("child DW_TAG_imported_declaration expected "
6601 "- DIE at 0x%x [in module %s]"),
6602 child_die
->offset
.sect_off
, objfile
->name
);
6606 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6607 if (import_attr
== NULL
)
6609 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6610 dwarf_tag_name (child_die
->tag
));
6615 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6617 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6618 if (imported_name
== NULL
)
6620 complaint (&symfile_complaints
,
6621 _("child DW_TAG_imported_declaration has unknown "
6622 "imported name - DIE at 0x%x [in module %s]"),
6623 child_die
->offset
.sect_off
, objfile
->name
);
6627 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6629 process_die (child_die
, cu
);
6632 cp_add_using_directive (import_prefix
,
6635 imported_declaration
,
6637 &objfile
->objfile_obstack
);
6639 do_cleanups (cleanups
);
6642 /* Cleanup function for read_file_scope. */
6645 free_cu_line_header (void *arg
)
6647 struct dwarf2_cu
*cu
= arg
;
6649 free_line_header (cu
->line_header
);
6650 cu
->line_header
= NULL
;
6654 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6655 char **name
, char **comp_dir
)
6657 struct attribute
*attr
;
6662 /* Find the filename. Do not use dwarf2_name here, since the filename
6663 is not a source language identifier. */
6664 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6667 *name
= DW_STRING (attr
);
6670 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6672 *comp_dir
= DW_STRING (attr
);
6673 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6675 *comp_dir
= ldirname (*name
);
6676 if (*comp_dir
!= NULL
)
6677 make_cleanup (xfree
, *comp_dir
);
6679 if (*comp_dir
!= NULL
)
6681 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6682 directory, get rid of it. */
6683 char *cp
= strchr (*comp_dir
, ':');
6685 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6690 *name
= "<unknown>";
6693 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6694 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6695 COMP_DIR is the compilation directory.
6696 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6699 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6700 const char *comp_dir
, int want_line_info
)
6702 struct attribute
*attr
;
6704 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6707 unsigned int line_offset
= DW_UNSND (attr
);
6708 struct line_header
*line_header
6709 = dwarf_decode_line_header (line_offset
, cu
);
6713 cu
->line_header
= line_header
;
6714 make_cleanup (free_cu_line_header
, cu
);
6715 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6720 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6723 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6725 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6726 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6727 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6728 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6729 struct attribute
*attr
;
6731 char *comp_dir
= NULL
;
6732 struct die_info
*child_die
;
6733 bfd
*abfd
= objfile
->obfd
;
6736 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6738 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6740 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6741 from finish_block. */
6742 if (lowpc
== ((CORE_ADDR
) -1))
6747 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6749 prepare_one_comp_unit (cu
, die
, cu
->language
);
6751 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6752 standardised yet. As a workaround for the language detection we fall
6753 back to the DW_AT_producer string. */
6754 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6755 cu
->language
= language_opencl
;
6757 /* Similar hack for Go. */
6758 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6759 set_cu_language (DW_LANG_Go
, cu
);
6761 /* We assume that we're processing GCC output. */
6762 processing_gcc_compilation
= 2;
6764 processing_has_namespace_info
= 0;
6766 start_symtab (name
, comp_dir
, lowpc
);
6767 record_debugformat ("DWARF 2");
6768 record_producer (cu
->producer
);
6770 /* Decode line number information if present. We do this before
6771 processing child DIEs, so that the line header table is available
6772 for DW_AT_decl_file. */
6773 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6775 /* Process all dies in compilation unit. */
6776 if (die
->child
!= NULL
)
6778 child_die
= die
->child
;
6779 while (child_die
&& child_die
->tag
)
6781 process_die (child_die
, cu
);
6782 child_die
= sibling_die (child_die
);
6786 /* Decode macro information, if present. Dwarf 2 macro information
6787 refers to information in the line number info statement program
6788 header, so we can only read it if we've read the header
6790 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6791 if (attr
&& cu
->line_header
)
6793 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6794 complaint (&symfile_complaints
,
6795 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6797 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
6801 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6802 if (attr
&& cu
->line_header
)
6804 unsigned int macro_offset
= DW_UNSND (attr
);
6806 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
6810 do_cleanups (back_to
);
6813 /* Process DW_TAG_type_unit.
6814 For TUs we want to skip the first top level sibling if it's not the
6815 actual type being defined by this TU. In this case the first top
6816 level sibling is there to provide context only. */
6819 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6821 struct objfile
*objfile
= cu
->objfile
;
6822 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6824 struct attribute
*attr
;
6826 char *comp_dir
= NULL
;
6827 struct die_info
*child_die
;
6828 bfd
*abfd
= objfile
->obfd
;
6830 /* start_symtab needs a low pc, but we don't really have one.
6831 Do what read_file_scope would do in the absence of such info. */
6832 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6834 /* Find the filename. Do not use dwarf2_name here, since the filename
6835 is not a source language identifier. */
6836 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6838 name
= DW_STRING (attr
);
6840 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6842 comp_dir
= DW_STRING (attr
);
6843 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6845 comp_dir
= ldirname (name
);
6846 if (comp_dir
!= NULL
)
6847 make_cleanup (xfree
, comp_dir
);
6853 prepare_one_comp_unit (cu
, die
, language_minimal
);
6855 /* We assume that we're processing GCC output. */
6856 processing_gcc_compilation
= 2;
6858 processing_has_namespace_info
= 0;
6860 start_symtab (name
, comp_dir
, lowpc
);
6861 record_debugformat ("DWARF 2");
6862 record_producer (cu
->producer
);
6864 /* Decode line number information if present. We do this before
6865 processing child DIEs, so that the line header table is available
6866 for DW_AT_decl_file.
6867 We don't need the pc/line-number mapping for type units. */
6868 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6870 /* Process the dies in the type unit. */
6871 if (die
->child
== NULL
)
6873 dump_die_for_error (die
);
6874 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6875 bfd_get_filename (abfd
));
6878 child_die
= die
->child
;
6880 while (child_die
&& child_die
->tag
)
6882 process_die (child_die
, cu
);
6884 child_die
= sibling_die (child_die
);
6887 do_cleanups (back_to
);
6893 hash_dwo_file (const void *item
)
6895 const struct dwo_file
*dwo_file
= item
;
6897 return htab_hash_string (dwo_file
->dwo_name
);
6901 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
6903 const struct dwo_file
*lhs
= item_lhs
;
6904 const struct dwo_file
*rhs
= item_rhs
;
6906 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
6909 /* Allocate a hash table for DWO files. */
6912 allocate_dwo_file_hash_table (void)
6914 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6916 return htab_create_alloc_ex (41,
6920 &objfile
->objfile_obstack
,
6921 hashtab_obstack_allocate
,
6922 dummy_obstack_deallocate
);
6926 hash_dwo_unit (const void *item
)
6928 const struct dwo_unit
*dwo_unit
= item
;
6930 /* This drops the top 32 bits of the id, but is ok for a hash. */
6931 return dwo_unit
->signature
;
6935 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
6937 const struct dwo_unit
*lhs
= item_lhs
;
6938 const struct dwo_unit
*rhs
= item_rhs
;
6940 /* The signature is assumed to be unique within the DWO file.
6941 So while object file CU dwo_id's always have the value zero,
6942 that's OK, assuming each object file DWO file has only one CU,
6943 and that's the rule for now. */
6944 return lhs
->signature
== rhs
->signature
;
6947 /* Allocate a hash table for DWO CUs,TUs.
6948 There is one of these tables for each of CUs,TUs for each DWO file. */
6951 allocate_dwo_unit_table (struct objfile
*objfile
)
6953 /* Start out with a pretty small number.
6954 Generally DWO files contain only one CU and maybe some TUs. */
6955 return htab_create_alloc_ex (3,
6959 &objfile
->objfile_obstack
,
6960 hashtab_obstack_allocate
,
6961 dummy_obstack_deallocate
);
6964 /* This function is mapped across the sections and remembers the offset and
6965 size of each of the DWO debugging sections we are interested in. */
6968 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
6970 struct dwo_file
*dwo_file
= dwo_file_ptr
;
6971 const struct dwo_section_names
*names
= &dwo_section_names
;
6973 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
6975 dwo_file
->sections
.abbrev
.asection
= sectp
;
6976 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
6978 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
6980 dwo_file
->sections
.info
.asection
= sectp
;
6981 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
6983 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
6985 dwo_file
->sections
.line
.asection
= sectp
;
6986 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
6988 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
6990 dwo_file
->sections
.loc
.asection
= sectp
;
6991 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
6993 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
6995 dwo_file
->sections
.macinfo
.asection
= sectp
;
6996 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
6998 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7000 dwo_file
->sections
.macro
.asection
= sectp
;
7001 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7003 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7005 dwo_file
->sections
.str
.asection
= sectp
;
7006 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7008 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7010 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7011 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7013 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7015 struct dwarf2_section_info type_section
;
7017 memset (&type_section
, 0, sizeof (type_section
));
7018 type_section
.asection
= sectp
;
7019 type_section
.size
= bfd_get_section_size (sectp
);
7020 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7025 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7027 struct create_dwo_info_table_data
7029 struct dwo_file
*dwo_file
;
7033 /* die_reader_func for create_debug_info_hash_table. */
7036 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7038 struct die_info
*comp_unit_die
,
7042 struct dwarf2_cu
*cu
= reader
->cu
;
7043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7044 sect_offset offset
= cu
->per_cu
->offset
;
7045 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7046 struct create_dwo_info_table_data
*data
= datap
;
7047 struct dwo_file
*dwo_file
= data
->dwo_file
;
7048 htab_t cu_htab
= data
->cu_htab
;
7050 struct attribute
*attr
;
7051 struct dwo_unit
*dwo_unit
;
7053 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7056 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
7057 " its dwo_id [in module %s]"),
7058 offset
.sect_off
, dwo_file
->dwo_name
);
7062 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
7063 dwo_unit
->dwo_file
= dwo_file
;
7064 dwo_unit
->signature
= DW_UNSND (attr
);
7065 dwo_unit
->info_or_types_section
= section
;
7066 dwo_unit
->offset
= offset
;
7067 dwo_unit
->length
= cu
->per_cu
->length
;
7069 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7070 gdb_assert (slot
!= NULL
);
7073 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7075 complaint (&symfile_complaints
,
7076 _("debug entry at offset 0x%x is duplicate to the entry at"
7077 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7078 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7079 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7080 dwo_file
->dwo_name
);
7085 if (dwarf2_die_debug
)
7086 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7088 phex (dwo_unit
->signature
,
7089 sizeof (dwo_unit
->signature
)));
7092 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7095 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7097 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7098 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7101 gdb_byte
*info_ptr
, *end_ptr
;
7102 struct create_dwo_info_table_data create_dwo_info_table_data
;
7104 dwarf2_read_section (objfile
, section
);
7105 info_ptr
= section
->buffer
;
7107 if (info_ptr
== NULL
)
7110 /* We can't set abfd until now because the section may be empty or
7111 not present, in which case section->asection will be NULL. */
7112 abfd
= section
->asection
->owner
;
7114 if (dwarf2_die_debug
)
7115 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
7116 bfd_get_filename (abfd
));
7118 cu_htab
= allocate_dwo_unit_table (objfile
);
7120 create_dwo_info_table_data
.dwo_file
= dwo_file
;
7121 create_dwo_info_table_data
.cu_htab
= cu_htab
;
7123 end_ptr
= info_ptr
+ section
->size
;
7124 while (info_ptr
< end_ptr
)
7126 struct dwarf2_per_cu_data per_cu
;
7128 memset (&per_cu
, 0, sizeof (per_cu
));
7129 per_cu
.objfile
= objfile
;
7130 per_cu
.is_debug_types
= 0;
7131 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
7132 per_cu
.info_or_types_section
= section
;
7134 init_cutu_and_read_dies_no_follow (&per_cu
,
7135 &dwo_file
->sections
.abbrev
,
7137 create_debug_info_hash_table_reader
,
7138 &create_dwo_info_table_data
);
7140 info_ptr
+= per_cu
.length
;
7146 /* Subroutine of open_dwo_file to simplify it.
7147 Open the file specified by FILE_NAME and hand it off to BFD for
7148 preliminary analysis. Return a newly initialized bfd *, which
7149 includes a canonicalized copy of FILE_NAME.
7150 In case of trouble, return NULL.
7151 NOTE: This function is derived from symfile_bfd_open. */
7154 try_open_dwo_file (const char *file_name
)
7158 char *absolute_name
;
7160 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
7161 O_RDONLY
| O_BINARY
, &absolute_name
);
7165 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
7168 xfree (absolute_name
);
7171 bfd_set_cacheable (sym_bfd
, 1);
7173 if (!bfd_check_format (sym_bfd
, bfd_object
))
7175 bfd_close (sym_bfd
); /* This also closes desc. */
7176 xfree (absolute_name
);
7180 /* bfd_usrdata exists for applications and libbfd must not touch it. */
7181 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
7186 /* Try to open DWO file DWO_NAME.
7187 COMP_DIR is the DW_AT_comp_dir attribute.
7188 The result is the bfd handle of the file.
7189 If there is a problem finding or opening the file, return NULL.
7190 Upon success, the canonicalized path of the file is stored in the bfd,
7191 same as symfile_bfd_open. */
7194 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
7198 if (IS_ABSOLUTE_PATH (dwo_name
))
7199 return try_open_dwo_file (dwo_name
);
7201 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
7203 if (comp_dir
!= NULL
)
7205 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
7207 /* NOTE: If comp_dir is a relative path, this will also try the
7208 search path, which seems useful. */
7209 abfd
= try_open_dwo_file (path_to_try
);
7210 xfree (path_to_try
);
7215 /* That didn't work, try debug-file-directory, which, despite its name,
7216 is a list of paths. */
7218 if (*debug_file_directory
== '\0')
7221 return try_open_dwo_file (dwo_name
);
7224 /* Initialize the use of the DWO file specified by DWO_NAME. */
7226 static struct dwo_file
*
7227 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7230 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7233 struct cleanup
*cleanups
;
7235 if (dwarf2_die_debug
)
7236 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7238 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7241 dwo_file
->dwo_name
= dwo_name
;
7242 dwo_file
->dwo_bfd
= abfd
;
7244 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7246 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7248 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7250 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7251 dwo_file
->sections
.types
);
7253 discard_cleanups (cleanups
);
7258 /* Lookup DWO file DWO_NAME. */
7260 static struct dwo_file
*
7261 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7263 struct dwo_file
*dwo_file
;
7264 struct dwo_file find_entry
;
7267 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7268 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7270 /* Have we already seen this DWO file? */
7271 find_entry
.dwo_name
= dwo_name
;
7272 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7274 /* If not, read it in and build a table of the DWOs it contains. */
7276 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7278 /* NOTE: This will be NULL if unable to open the file. */
7284 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7285 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7286 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7287 nomenclature as TUs).
7288 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7289 (dwo_id mismatch or couldn't find the DWO file). */
7291 static struct dwo_unit
*
7292 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7293 char *dwo_name
, const char *comp_dir
,
7296 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7297 struct dwo_file
*dwo_file
;
7299 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7300 if (dwo_file
== NULL
)
7303 /* Look up the DWO using its signature(dwo_id). */
7305 if (dwo_file
->cus
!= NULL
)
7307 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7309 find_dwo_cu
.signature
= signature
;
7310 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7316 /* We didn't find it. This must mean a dwo_id mismatch. */
7318 complaint (&symfile_complaints
,
7319 _("Could not find DWO CU referenced by CU at offset 0x%x"
7321 this_cu
->offset
.sect_off
, objfile
->name
);
7325 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7326 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7327 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7328 (dwo_id mismatch or couldn't find the DWO file). */
7330 static struct dwo_unit
*
7331 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7332 char *dwo_name
, const char *comp_dir
)
7334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7335 struct dwo_file
*dwo_file
;
7337 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7338 if (dwo_file
== NULL
)
7341 /* Look up the DWO using its signature(dwo_id). */
7343 if (dwo_file
->tus
!= NULL
)
7345 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7347 find_dwo_tu
.signature
= this_tu
->signature
;
7348 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7354 /* We didn't find it. This must mean a dwo_id mismatch. */
7356 complaint (&symfile_complaints
,
7357 _("Could not find DWO TU referenced by TU at offset 0x%x"
7359 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7363 /* Free all resources associated with DWO_FILE.
7364 Close the DWO file and munmap the sections.
7365 All memory should be on the objfile obstack. */
7368 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7371 struct dwarf2_section_info
*section
;
7373 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7374 bfd_close (dwo_file
->dwo_bfd
);
7376 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7377 munmap_section_buffer (&dwo_file
->sections
.info
);
7378 munmap_section_buffer (&dwo_file
->sections
.line
);
7379 munmap_section_buffer (&dwo_file
->sections
.loc
);
7380 munmap_section_buffer (&dwo_file
->sections
.str
);
7381 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7384 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7387 munmap_section_buffer (section
);
7389 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7392 /* Wrapper for free_dwo_file for use in cleanups. */
7395 free_dwo_file_cleanup (void *arg
)
7397 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7398 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7400 free_dwo_file (dwo_file
, objfile
);
7403 /* Traversal function for free_dwo_files. */
7406 free_dwo_file_from_slot (void **slot
, void *info
)
7408 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7409 struct objfile
*objfile
= (struct objfile
*) info
;
7411 free_dwo_file (dwo_file
, objfile
);
7416 /* Free all resources associated with DWO_FILES. */
7419 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7421 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7424 /* Read in various DIEs. */
7426 /* qsort helper for inherit_abstract_dies. */
7429 unsigned_int_compar (const void *ap
, const void *bp
)
7431 unsigned int a
= *(unsigned int *) ap
;
7432 unsigned int b
= *(unsigned int *) bp
;
7434 return (a
> b
) - (b
> a
);
7437 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7438 Inherit only the children of the DW_AT_abstract_origin DIE not being
7439 already referenced by DW_AT_abstract_origin from the children of the
7443 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7445 struct die_info
*child_die
;
7446 unsigned die_children_count
;
7447 /* CU offsets which were referenced by children of the current DIE. */
7448 sect_offset
*offsets
;
7449 sect_offset
*offsets_end
, *offsetp
;
7450 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7451 struct die_info
*origin_die
;
7452 /* Iterator of the ORIGIN_DIE children. */
7453 struct die_info
*origin_child_die
;
7454 struct cleanup
*cleanups
;
7455 struct attribute
*attr
;
7456 struct dwarf2_cu
*origin_cu
;
7457 struct pending
**origin_previous_list_in_scope
;
7459 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7463 /* Note that following die references may follow to a die in a
7467 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7469 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7471 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7472 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7474 if (die
->tag
!= origin_die
->tag
7475 && !(die
->tag
== DW_TAG_inlined_subroutine
7476 && origin_die
->tag
== DW_TAG_subprogram
))
7477 complaint (&symfile_complaints
,
7478 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7479 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7481 child_die
= die
->child
;
7482 die_children_count
= 0;
7483 while (child_die
&& child_die
->tag
)
7485 child_die
= sibling_die (child_die
);
7486 die_children_count
++;
7488 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7489 cleanups
= make_cleanup (xfree
, offsets
);
7491 offsets_end
= offsets
;
7492 child_die
= die
->child
;
7493 while (child_die
&& child_die
->tag
)
7495 /* For each CHILD_DIE, find the corresponding child of
7496 ORIGIN_DIE. If there is more than one layer of
7497 DW_AT_abstract_origin, follow them all; there shouldn't be,
7498 but GCC versions at least through 4.4 generate this (GCC PR
7500 struct die_info
*child_origin_die
= child_die
;
7501 struct dwarf2_cu
*child_origin_cu
= cu
;
7505 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7509 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7513 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7514 counterpart may exist. */
7515 if (child_origin_die
!= child_die
)
7517 if (child_die
->tag
!= child_origin_die
->tag
7518 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7519 && child_origin_die
->tag
== DW_TAG_subprogram
))
7520 complaint (&symfile_complaints
,
7521 _("Child DIE 0x%x and its abstract origin 0x%x have "
7522 "different tags"), child_die
->offset
.sect_off
,
7523 child_origin_die
->offset
.sect_off
);
7524 if (child_origin_die
->parent
!= origin_die
)
7525 complaint (&symfile_complaints
,
7526 _("Child DIE 0x%x and its abstract origin 0x%x have "
7527 "different parents"), child_die
->offset
.sect_off
,
7528 child_origin_die
->offset
.sect_off
);
7530 *offsets_end
++ = child_origin_die
->offset
;
7532 child_die
= sibling_die (child_die
);
7534 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7535 unsigned_int_compar
);
7536 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7537 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7538 complaint (&symfile_complaints
,
7539 _("Multiple children of DIE 0x%x refer "
7540 "to DIE 0x%x as their abstract origin"),
7541 die
->offset
.sect_off
, offsetp
->sect_off
);
7544 origin_child_die
= origin_die
->child
;
7545 while (origin_child_die
&& origin_child_die
->tag
)
7547 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7548 while (offsetp
< offsets_end
7549 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7551 if (offsetp
>= offsets_end
7552 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7554 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7555 process_die (origin_child_die
, origin_cu
);
7557 origin_child_die
= sibling_die (origin_child_die
);
7559 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7561 do_cleanups (cleanups
);
7565 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7567 struct objfile
*objfile
= cu
->objfile
;
7568 struct context_stack
*new;
7571 struct die_info
*child_die
;
7572 struct attribute
*attr
, *call_line
, *call_file
;
7575 struct block
*block
;
7576 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7577 VEC (symbolp
) *template_args
= NULL
;
7578 struct template_symbol
*templ_func
= NULL
;
7582 /* If we do not have call site information, we can't show the
7583 caller of this inlined function. That's too confusing, so
7584 only use the scope for local variables. */
7585 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7586 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7587 if (call_line
== NULL
|| call_file
== NULL
)
7589 read_lexical_block_scope (die
, cu
);
7594 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7596 name
= dwarf2_name (die
, cu
);
7598 /* Ignore functions with missing or empty names. These are actually
7599 illegal according to the DWARF standard. */
7602 complaint (&symfile_complaints
,
7603 _("missing name for subprogram DIE at %d"),
7604 die
->offset
.sect_off
);
7608 /* Ignore functions with missing or invalid low and high pc attributes. */
7609 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7611 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7612 if (!attr
|| !DW_UNSND (attr
))
7613 complaint (&symfile_complaints
,
7614 _("cannot get low and high bounds "
7615 "for subprogram DIE at %d"),
7616 die
->offset
.sect_off
);
7623 /* If we have any template arguments, then we must allocate a
7624 different sort of symbol. */
7625 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7627 if (child_die
->tag
== DW_TAG_template_type_param
7628 || child_die
->tag
== DW_TAG_template_value_param
)
7630 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7631 struct template_symbol
);
7632 templ_func
->base
.is_cplus_template_function
= 1;
7637 new = push_context (0, lowpc
);
7638 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7639 (struct symbol
*) templ_func
);
7641 /* If there is a location expression for DW_AT_frame_base, record
7643 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7645 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7646 expression is being recorded directly in the function's symbol
7647 and not in a separate frame-base object. I guess this hack is
7648 to avoid adding some sort of frame-base adjunct/annex to the
7649 function's symbol :-(. The problem with doing this is that it
7650 results in a function symbol with a location expression that
7651 has nothing to do with the location of the function, ouch! The
7652 relationship should be: a function's symbol has-a frame base; a
7653 frame-base has-a location expression. */
7654 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7656 cu
->list_in_scope
= &local_symbols
;
7658 if (die
->child
!= NULL
)
7660 child_die
= die
->child
;
7661 while (child_die
&& child_die
->tag
)
7663 if (child_die
->tag
== DW_TAG_template_type_param
7664 || child_die
->tag
== DW_TAG_template_value_param
)
7666 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7669 VEC_safe_push (symbolp
, template_args
, arg
);
7672 process_die (child_die
, cu
);
7673 child_die
= sibling_die (child_die
);
7677 inherit_abstract_dies (die
, cu
);
7679 /* If we have a DW_AT_specification, we might need to import using
7680 directives from the context of the specification DIE. See the
7681 comment in determine_prefix. */
7682 if (cu
->language
== language_cplus
7683 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7685 struct dwarf2_cu
*spec_cu
= cu
;
7686 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7690 child_die
= spec_die
->child
;
7691 while (child_die
&& child_die
->tag
)
7693 if (child_die
->tag
== DW_TAG_imported_module
)
7694 process_die (child_die
, spec_cu
);
7695 child_die
= sibling_die (child_die
);
7698 /* In some cases, GCC generates specification DIEs that
7699 themselves contain DW_AT_specification attributes. */
7700 spec_die
= die_specification (spec_die
, &spec_cu
);
7704 new = pop_context ();
7705 /* Make a block for the local symbols within. */
7706 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7707 lowpc
, highpc
, objfile
);
7709 /* For C++, set the block's scope. */
7710 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7711 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7712 determine_prefix (die
, cu
),
7713 processing_has_namespace_info
);
7715 /* If we have address ranges, record them. */
7716 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7718 /* Attach template arguments to function. */
7719 if (! VEC_empty (symbolp
, template_args
))
7721 gdb_assert (templ_func
!= NULL
);
7723 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7724 templ_func
->template_arguments
7725 = obstack_alloc (&objfile
->objfile_obstack
,
7726 (templ_func
->n_template_arguments
7727 * sizeof (struct symbol
*)));
7728 memcpy (templ_func
->template_arguments
,
7729 VEC_address (symbolp
, template_args
),
7730 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7731 VEC_free (symbolp
, template_args
);
7734 /* In C++, we can have functions nested inside functions (e.g., when
7735 a function declares a class that has methods). This means that
7736 when we finish processing a function scope, we may need to go
7737 back to building a containing block's symbol lists. */
7738 local_symbols
= new->locals
;
7739 param_symbols
= new->params
;
7740 using_directives
= new->using_directives
;
7742 /* If we've finished processing a top-level function, subsequent
7743 symbols go in the file symbol list. */
7744 if (outermost_context_p ())
7745 cu
->list_in_scope
= &file_symbols
;
7748 /* Process all the DIES contained within a lexical block scope. Start
7749 a new scope, process the dies, and then close the scope. */
7752 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7754 struct objfile
*objfile
= cu
->objfile
;
7755 struct context_stack
*new;
7756 CORE_ADDR lowpc
, highpc
;
7757 struct die_info
*child_die
;
7760 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7762 /* Ignore blocks with missing or invalid low and high pc attributes. */
7763 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7764 as multiple lexical blocks? Handling children in a sane way would
7765 be nasty. Might be easier to properly extend generic blocks to
7767 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7772 push_context (0, lowpc
);
7773 if (die
->child
!= NULL
)
7775 child_die
= die
->child
;
7776 while (child_die
&& child_die
->tag
)
7778 process_die (child_die
, cu
);
7779 child_die
= sibling_die (child_die
);
7782 new = pop_context ();
7784 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7787 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7790 /* Note that recording ranges after traversing children, as we
7791 do here, means that recording a parent's ranges entails
7792 walking across all its children's ranges as they appear in
7793 the address map, which is quadratic behavior.
7795 It would be nicer to record the parent's ranges before
7796 traversing its children, simply overriding whatever you find
7797 there. But since we don't even decide whether to create a
7798 block until after we've traversed its children, that's hard
7800 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7802 local_symbols
= new->locals
;
7803 using_directives
= new->using_directives
;
7806 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7809 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7811 struct objfile
*objfile
= cu
->objfile
;
7812 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7813 CORE_ADDR pc
, baseaddr
;
7814 struct attribute
*attr
;
7815 struct call_site
*call_site
, call_site_local
;
7818 struct die_info
*child_die
;
7820 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7822 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7825 complaint (&symfile_complaints
,
7826 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7827 "DIE 0x%x [in module %s]"),
7828 die
->offset
.sect_off
, objfile
->name
);
7831 pc
= DW_ADDR (attr
) + baseaddr
;
7833 if (cu
->call_site_htab
== NULL
)
7834 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7835 NULL
, &objfile
->objfile_obstack
,
7836 hashtab_obstack_allocate
, NULL
);
7837 call_site_local
.pc
= pc
;
7838 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7841 complaint (&symfile_complaints
,
7842 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7843 "DIE 0x%x [in module %s]"),
7844 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7848 /* Count parameters at the caller. */
7851 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7852 child_die
= sibling_die (child_die
))
7854 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7856 complaint (&symfile_complaints
,
7857 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7858 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7859 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7866 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7867 (sizeof (*call_site
)
7868 + (sizeof (*call_site
->parameter
)
7871 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7874 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7876 struct die_info
*func_die
;
7878 /* Skip also over DW_TAG_inlined_subroutine. */
7879 for (func_die
= die
->parent
;
7880 func_die
&& func_die
->tag
!= DW_TAG_subprogram
7881 && func_die
->tag
!= DW_TAG_subroutine_type
;
7882 func_die
= func_die
->parent
);
7884 /* DW_AT_GNU_all_call_sites is a superset
7885 of DW_AT_GNU_all_tail_call_sites. */
7887 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
7888 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
7890 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
7891 not complete. But keep CALL_SITE for look ups via call_site_htab,
7892 both the initial caller containing the real return address PC and
7893 the final callee containing the current PC of a chain of tail
7894 calls do not need to have the tail call list complete. But any
7895 function candidate for a virtual tail call frame searched via
7896 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
7897 determined unambiguously. */
7901 struct type
*func_type
= NULL
;
7904 func_type
= get_die_type (func_die
, cu
);
7905 if (func_type
!= NULL
)
7907 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
7909 /* Enlist this call site to the function. */
7910 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
7911 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
7914 complaint (&symfile_complaints
,
7915 _("Cannot find function owning DW_TAG_GNU_call_site "
7916 "DIE 0x%x [in module %s]"),
7917 die
->offset
.sect_off
, objfile
->name
);
7921 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
7923 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7924 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
7925 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
7926 /* Keep NULL DWARF_BLOCK. */;
7927 else if (attr_form_is_block (attr
))
7929 struct dwarf2_locexpr_baton
*dlbaton
;
7931 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
7932 dlbaton
->data
= DW_BLOCK (attr
)->data
;
7933 dlbaton
->size
= DW_BLOCK (attr
)->size
;
7934 dlbaton
->per_cu
= cu
->per_cu
;
7936 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
7938 else if (is_ref_attr (attr
))
7940 struct dwarf2_cu
*target_cu
= cu
;
7941 struct die_info
*target_die
;
7943 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
7944 gdb_assert (target_cu
->objfile
== objfile
);
7945 if (die_is_declaration (target_die
, target_cu
))
7947 const char *target_physname
;
7949 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
7950 if (target_physname
== NULL
)
7951 complaint (&symfile_complaints
,
7952 _("DW_AT_GNU_call_site_target target DIE has invalid "
7953 "physname, for referencing DIE 0x%x [in module %s]"),
7954 die
->offset
.sect_off
, objfile
->name
);
7956 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
7962 /* DW_AT_entry_pc should be preferred. */
7963 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
7964 complaint (&symfile_complaints
,
7965 _("DW_AT_GNU_call_site_target target DIE has invalid "
7966 "low pc, for referencing DIE 0x%x [in module %s]"),
7967 die
->offset
.sect_off
, objfile
->name
);
7969 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
7973 complaint (&symfile_complaints
,
7974 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
7975 "block nor reference, for DIE 0x%x [in module %s]"),
7976 die
->offset
.sect_off
, objfile
->name
);
7978 call_site
->per_cu
= cu
->per_cu
;
7980 for (child_die
= die
->child
;
7981 child_die
&& child_die
->tag
;
7982 child_die
= sibling_die (child_die
))
7984 struct call_site_parameter
*parameter
;
7985 struct attribute
*loc
, *origin
;
7987 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7989 /* Already printed the complaint above. */
7993 gdb_assert (call_site
->parameter_count
< nparams
);
7994 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
7996 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
7997 specifies DW_TAG_formal_parameter. Value of the data assumed for the
7998 register is contained in DW_AT_GNU_call_site_value. */
8000 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8001 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8002 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8006 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8007 offset
= dwarf2_get_ref_die_offset (origin
);
8008 gdb_assert (offset
.sect_off
>= cu
->header
.offset
.sect_off
);
8009 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8010 - cu
->header
.offset
.sect_off
);
8012 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8014 complaint (&symfile_complaints
,
8015 _("No DW_FORM_block* DW_AT_location for "
8016 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8017 child_die
->offset
.sect_off
, objfile
->name
);
8022 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8023 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8024 if (parameter
->u
.dwarf_reg
!= -1)
8025 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8026 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8027 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8028 ¶meter
->u
.fb_offset
))
8029 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8032 complaint (&symfile_complaints
,
8033 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8034 "for DW_FORM_block* DW_AT_location is supported for "
8035 "DW_TAG_GNU_call_site child DIE 0x%x "
8037 child_die
->offset
.sect_off
, objfile
->name
);
8042 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
8043 if (!attr_form_is_block (attr
))
8045 complaint (&symfile_complaints
,
8046 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
8047 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8048 child_die
->offset
.sect_off
, objfile
->name
);
8051 parameter
->value
= DW_BLOCK (attr
)->data
;
8052 parameter
->value_size
= DW_BLOCK (attr
)->size
;
8054 /* Parameters are not pre-cleared by memset above. */
8055 parameter
->data_value
= NULL
;
8056 parameter
->data_value_size
= 0;
8057 call_site
->parameter_count
++;
8059 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
8062 if (!attr_form_is_block (attr
))
8063 complaint (&symfile_complaints
,
8064 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
8065 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8066 child_die
->offset
.sect_off
, objfile
->name
);
8069 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8070 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8076 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8077 Return 1 if the attributes are present and valid, otherwise, return 0.
8078 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8081 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8082 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8083 struct partial_symtab
*ranges_pst
)
8085 struct objfile
*objfile
= cu
->objfile
;
8086 struct comp_unit_head
*cu_header
= &cu
->header
;
8087 bfd
*obfd
= objfile
->obfd
;
8088 unsigned int addr_size
= cu_header
->addr_size
;
8089 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8090 /* Base address selection entry. */
8101 found_base
= cu
->base_known
;
8102 base
= cu
->base_address
;
8104 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
8105 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8107 complaint (&symfile_complaints
,
8108 _("Offset %d out of bounds for DW_AT_ranges attribute"),
8112 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8114 /* Read in the largest possible address. */
8115 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
8116 if ((marker
& mask
) == mask
)
8118 /* If we found the largest possible address, then
8119 read the base address. */
8120 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8121 buffer
+= 2 * addr_size
;
8122 offset
+= 2 * addr_size
;
8128 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8132 CORE_ADDR range_beginning
, range_end
;
8134 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
8135 buffer
+= addr_size
;
8136 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
8137 buffer
+= addr_size
;
8138 offset
+= 2 * addr_size
;
8140 /* An end of list marker is a pair of zero addresses. */
8141 if (range_beginning
== 0 && range_end
== 0)
8142 /* Found the end of list entry. */
8145 /* Each base address selection entry is a pair of 2 values.
8146 The first is the largest possible address, the second is
8147 the base address. Check for a base address here. */
8148 if ((range_beginning
& mask
) == mask
)
8150 /* If we found the largest possible address, then
8151 read the base address. */
8152 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8159 /* We have no valid base address for the ranges
8161 complaint (&symfile_complaints
,
8162 _("Invalid .debug_ranges data (no base address)"));
8166 if (range_beginning
> range_end
)
8168 /* Inverted range entries are invalid. */
8169 complaint (&symfile_complaints
,
8170 _("Invalid .debug_ranges data (inverted range)"));
8174 /* Empty range entries have no effect. */
8175 if (range_beginning
== range_end
)
8178 range_beginning
+= base
;
8181 if (ranges_pst
!= NULL
)
8182 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8183 range_beginning
+ baseaddr
,
8184 range_end
- 1 + baseaddr
,
8187 /* FIXME: This is recording everything as a low-high
8188 segment of consecutive addresses. We should have a
8189 data structure for discontiguous block ranges
8193 low
= range_beginning
;
8199 if (range_beginning
< low
)
8200 low
= range_beginning
;
8201 if (range_end
> high
)
8207 /* If the first entry is an end-of-list marker, the range
8208 describes an empty scope, i.e. no instructions. */
8214 *high_return
= high
;
8218 /* Get low and high pc attributes from a die. Return 1 if the attributes
8219 are present and valid, otherwise, return 0. Return -1 if the range is
8220 discontinuous, i.e. derived from DW_AT_ranges information. */
8223 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
8224 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
8225 struct partial_symtab
*pst
)
8227 struct attribute
*attr
;
8228 struct attribute
*attr_high
;
8233 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8236 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8239 low
= DW_ADDR (attr
);
8240 if (attr_high
->form
== DW_FORM_addr
8241 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8242 high
= DW_ADDR (attr_high
);
8244 high
= low
+ DW_UNSND (attr_high
);
8247 /* Found high w/o low attribute. */
8250 /* Found consecutive range of addresses. */
8255 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8258 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
8260 /* Value of the DW_AT_ranges attribute is the offset in the
8261 .debug_ranges section. */
8262 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
8264 /* Found discontinuous range of addresses. */
8269 /* read_partial_die has also the strict LOW < HIGH requirement. */
8273 /* When using the GNU linker, .gnu.linkonce. sections are used to
8274 eliminate duplicate copies of functions and vtables and such.
8275 The linker will arbitrarily choose one and discard the others.
8276 The AT_*_pc values for such functions refer to local labels in
8277 these sections. If the section from that file was discarded, the
8278 labels are not in the output, so the relocs get a value of 0.
8279 If this is a discarded function, mark the pc bounds as invalid,
8280 so that GDB will ignore it. */
8281 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8290 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8291 its low and high PC addresses. Do nothing if these addresses could not
8292 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8293 and HIGHPC to the high address if greater than HIGHPC. */
8296 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8297 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8298 struct dwarf2_cu
*cu
)
8300 CORE_ADDR low
, high
;
8301 struct die_info
*child
= die
->child
;
8303 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8305 *lowpc
= min (*lowpc
, low
);
8306 *highpc
= max (*highpc
, high
);
8309 /* If the language does not allow nested subprograms (either inside
8310 subprograms or lexical blocks), we're done. */
8311 if (cu
->language
!= language_ada
)
8314 /* Check all the children of the given DIE. If it contains nested
8315 subprograms, then check their pc bounds. Likewise, we need to
8316 check lexical blocks as well, as they may also contain subprogram
8318 while (child
&& child
->tag
)
8320 if (child
->tag
== DW_TAG_subprogram
8321 || child
->tag
== DW_TAG_lexical_block
)
8322 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8323 child
= sibling_die (child
);
8327 /* Get the low and high pc's represented by the scope DIE, and store
8328 them in *LOWPC and *HIGHPC. If the correct values can't be
8329 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8332 get_scope_pc_bounds (struct die_info
*die
,
8333 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8334 struct dwarf2_cu
*cu
)
8336 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8337 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8338 CORE_ADDR current_low
, current_high
;
8340 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8342 best_low
= current_low
;
8343 best_high
= current_high
;
8347 struct die_info
*child
= die
->child
;
8349 while (child
&& child
->tag
)
8351 switch (child
->tag
) {
8352 case DW_TAG_subprogram
:
8353 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8355 case DW_TAG_namespace
:
8357 /* FIXME: carlton/2004-01-16: Should we do this for
8358 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8359 that current GCC's always emit the DIEs corresponding
8360 to definitions of methods of classes as children of a
8361 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8362 the DIEs giving the declarations, which could be
8363 anywhere). But I don't see any reason why the
8364 standards says that they have to be there. */
8365 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8367 if (current_low
!= ((CORE_ADDR
) -1))
8369 best_low
= min (best_low
, current_low
);
8370 best_high
= max (best_high
, current_high
);
8378 child
= sibling_die (child
);
8383 *highpc
= best_high
;
8386 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8390 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8391 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8393 struct objfile
*objfile
= cu
->objfile
;
8394 struct attribute
*attr
;
8395 struct attribute
*attr_high
;
8397 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8400 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8403 CORE_ADDR low
= DW_ADDR (attr
);
8405 if (attr_high
->form
== DW_FORM_addr
8406 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8407 high
= DW_ADDR (attr_high
);
8409 high
= low
+ DW_UNSND (attr_high
);
8411 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8415 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8418 bfd
*obfd
= objfile
->obfd
;
8420 /* The value of the DW_AT_ranges attribute is the offset of the
8421 address range list in the .debug_ranges section. */
8422 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
8423 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8425 /* For some target architectures, but not others, the
8426 read_address function sign-extends the addresses it returns.
8427 To recognize base address selection entries, we need a
8429 unsigned int addr_size
= cu
->header
.addr_size
;
8430 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8432 /* The base address, to which the next pair is relative. Note
8433 that this 'base' is a DWARF concept: most entries in a range
8434 list are relative, to reduce the number of relocs against the
8435 debugging information. This is separate from this function's
8436 'baseaddr' argument, which GDB uses to relocate debugging
8437 information from a shared library based on the address at
8438 which the library was loaded. */
8439 CORE_ADDR base
= cu
->base_address
;
8440 int base_known
= cu
->base_known
;
8442 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8443 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8445 complaint (&symfile_complaints
,
8446 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8453 unsigned int bytes_read
;
8454 CORE_ADDR start
, end
;
8456 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8457 buffer
+= bytes_read
;
8458 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8459 buffer
+= bytes_read
;
8461 /* Did we find the end of the range list? */
8462 if (start
== 0 && end
== 0)
8465 /* Did we find a base address selection entry? */
8466 else if ((start
& base_select_mask
) == base_select_mask
)
8472 /* We found an ordinary address range. */
8477 complaint (&symfile_complaints
,
8478 _("Invalid .debug_ranges data "
8479 "(no base address)"));
8485 /* Inverted range entries are invalid. */
8486 complaint (&symfile_complaints
,
8487 _("Invalid .debug_ranges data "
8488 "(inverted range)"));
8492 /* Empty range entries have no effect. */
8496 record_block_range (block
,
8497 baseaddr
+ base
+ start
,
8498 baseaddr
+ base
+ end
- 1);
8504 /* Check whether the producer field indicates either of GCC < 4.6, or the
8505 Intel C/C++ compiler, and cache the result in CU. */
8508 check_producer (struct dwarf2_cu
*cu
)
8511 int major
, minor
, release
;
8513 if (cu
->producer
== NULL
)
8515 /* For unknown compilers expect their behavior is DWARF version
8518 GCC started to support .debug_types sections by -gdwarf-4 since
8519 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8520 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8521 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8522 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8524 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
8526 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8528 cs
= &cu
->producer
[strlen ("GNU ")];
8529 while (*cs
&& !isdigit (*cs
))
8531 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8533 /* Not recognized as GCC. */
8536 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
8538 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
8539 cu
->producer_is_icc
= 1;
8542 /* For other non-GCC compilers, expect their behavior is DWARF version
8546 cu
->checked_producer
= 1;
8549 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8550 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8551 during 4.6.0 experimental. */
8554 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8556 if (!cu
->checked_producer
)
8557 check_producer (cu
);
8559 return cu
->producer_is_gxx_lt_4_6
;
8562 /* Return the default accessibility type if it is not overriden by
8563 DW_AT_accessibility. */
8565 static enum dwarf_access_attribute
8566 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8568 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8570 /* The default DWARF 2 accessibility for members is public, the default
8571 accessibility for inheritance is private. */
8573 if (die
->tag
!= DW_TAG_inheritance
)
8574 return DW_ACCESS_public
;
8576 return DW_ACCESS_private
;
8580 /* DWARF 3+ defines the default accessibility a different way. The same
8581 rules apply now for DW_TAG_inheritance as for the members and it only
8582 depends on the container kind. */
8584 if (die
->parent
->tag
== DW_TAG_class_type
)
8585 return DW_ACCESS_private
;
8587 return DW_ACCESS_public
;
8591 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8592 offset. If the attribute was not found return 0, otherwise return
8593 1. If it was found but could not properly be handled, set *OFFSET
8597 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8600 struct attribute
*attr
;
8602 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8607 /* Note that we do not check for a section offset first here.
8608 This is because DW_AT_data_member_location is new in DWARF 4,
8609 so if we see it, we can assume that a constant form is really
8610 a constant and not a section offset. */
8611 if (attr_form_is_constant (attr
))
8612 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8613 else if (attr_form_is_section_offset (attr
))
8614 dwarf2_complex_location_expr_complaint ();
8615 else if (attr_form_is_block (attr
))
8616 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8618 dwarf2_complex_location_expr_complaint ();
8626 /* Add an aggregate field to the field list. */
8629 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8630 struct dwarf2_cu
*cu
)
8632 struct objfile
*objfile
= cu
->objfile
;
8633 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8634 struct nextfield
*new_field
;
8635 struct attribute
*attr
;
8637 char *fieldname
= "";
8639 /* Allocate a new field list entry and link it in. */
8640 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8641 make_cleanup (xfree
, new_field
);
8642 memset (new_field
, 0, sizeof (struct nextfield
));
8644 if (die
->tag
== DW_TAG_inheritance
)
8646 new_field
->next
= fip
->baseclasses
;
8647 fip
->baseclasses
= new_field
;
8651 new_field
->next
= fip
->fields
;
8652 fip
->fields
= new_field
;
8656 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8658 new_field
->accessibility
= DW_UNSND (attr
);
8660 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8661 if (new_field
->accessibility
!= DW_ACCESS_public
)
8662 fip
->non_public_fields
= 1;
8664 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8666 new_field
->virtuality
= DW_UNSND (attr
);
8668 new_field
->virtuality
= DW_VIRTUALITY_none
;
8670 fp
= &new_field
->field
;
8672 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8676 /* Data member other than a C++ static data member. */
8678 /* Get type of field. */
8679 fp
->type
= die_type (die
, cu
);
8681 SET_FIELD_BITPOS (*fp
, 0);
8683 /* Get bit size of field (zero if none). */
8684 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8687 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8691 FIELD_BITSIZE (*fp
) = 0;
8694 /* Get bit offset of field. */
8695 if (handle_data_member_location (die
, cu
, &offset
))
8696 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8697 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8700 if (gdbarch_bits_big_endian (gdbarch
))
8702 /* For big endian bits, the DW_AT_bit_offset gives the
8703 additional bit offset from the MSB of the containing
8704 anonymous object to the MSB of the field. We don't
8705 have to do anything special since we don't need to
8706 know the size of the anonymous object. */
8707 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8711 /* For little endian bits, compute the bit offset to the
8712 MSB of the anonymous object, subtract off the number of
8713 bits from the MSB of the field to the MSB of the
8714 object, and then subtract off the number of bits of
8715 the field itself. The result is the bit offset of
8716 the LSB of the field. */
8718 int bit_offset
= DW_UNSND (attr
);
8720 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8723 /* The size of the anonymous object containing
8724 the bit field is explicit, so use the
8725 indicated size (in bytes). */
8726 anonymous_size
= DW_UNSND (attr
);
8730 /* The size of the anonymous object containing
8731 the bit field must be inferred from the type
8732 attribute of the data member containing the
8734 anonymous_size
= TYPE_LENGTH (fp
->type
);
8736 SET_FIELD_BITPOS (*fp
,
8738 + anonymous_size
* bits_per_byte
8739 - bit_offset
- FIELD_BITSIZE (*fp
)));
8743 /* Get name of field. */
8744 fieldname
= dwarf2_name (die
, cu
);
8745 if (fieldname
== NULL
)
8748 /* The name is already allocated along with this objfile, so we don't
8749 need to duplicate it for the type. */
8750 fp
->name
= fieldname
;
8752 /* Change accessibility for artificial fields (e.g. virtual table
8753 pointer or virtual base class pointer) to private. */
8754 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8756 FIELD_ARTIFICIAL (*fp
) = 1;
8757 new_field
->accessibility
= DW_ACCESS_private
;
8758 fip
->non_public_fields
= 1;
8761 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8763 /* C++ static member. */
8765 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8766 is a declaration, but all versions of G++ as of this writing
8767 (so through at least 3.2.1) incorrectly generate
8768 DW_TAG_variable tags. */
8770 const char *physname
;
8772 /* Get name of field. */
8773 fieldname
= dwarf2_name (die
, cu
);
8774 if (fieldname
== NULL
)
8777 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8779 /* Only create a symbol if this is an external value.
8780 new_symbol checks this and puts the value in the global symbol
8781 table, which we want. If it is not external, new_symbol
8782 will try to put the value in cu->list_in_scope which is wrong. */
8783 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8785 /* A static const member, not much different than an enum as far as
8786 we're concerned, except that we can support more types. */
8787 new_symbol (die
, NULL
, cu
);
8790 /* Get physical name. */
8791 physname
= dwarf2_physname (fieldname
, die
, cu
);
8793 /* The name is already allocated along with this objfile, so we don't
8794 need to duplicate it for the type. */
8795 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8796 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8797 FIELD_NAME (*fp
) = fieldname
;
8799 else if (die
->tag
== DW_TAG_inheritance
)
8803 /* C++ base class field. */
8804 if (handle_data_member_location (die
, cu
, &offset
))
8805 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8806 FIELD_BITSIZE (*fp
) = 0;
8807 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8808 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8809 fip
->nbaseclasses
++;
8813 /* Add a typedef defined in the scope of the FIP's class. */
8816 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8817 struct dwarf2_cu
*cu
)
8819 struct objfile
*objfile
= cu
->objfile
;
8820 struct typedef_field_list
*new_field
;
8821 struct attribute
*attr
;
8822 struct typedef_field
*fp
;
8823 char *fieldname
= "";
8825 /* Allocate a new field list entry and link it in. */
8826 new_field
= xzalloc (sizeof (*new_field
));
8827 make_cleanup (xfree
, new_field
);
8829 gdb_assert (die
->tag
== DW_TAG_typedef
);
8831 fp
= &new_field
->field
;
8833 /* Get name of field. */
8834 fp
->name
= dwarf2_name (die
, cu
);
8835 if (fp
->name
== NULL
)
8838 fp
->type
= read_type_die (die
, cu
);
8840 new_field
->next
= fip
->typedef_field_list
;
8841 fip
->typedef_field_list
= new_field
;
8842 fip
->typedef_field_list_count
++;
8845 /* Create the vector of fields, and attach it to the type. */
8848 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8849 struct dwarf2_cu
*cu
)
8851 int nfields
= fip
->nfields
;
8853 /* Record the field count, allocate space for the array of fields,
8854 and create blank accessibility bitfields if necessary. */
8855 TYPE_NFIELDS (type
) = nfields
;
8856 TYPE_FIELDS (type
) = (struct field
*)
8857 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8858 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8860 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8862 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8864 TYPE_FIELD_PRIVATE_BITS (type
) =
8865 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8866 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8868 TYPE_FIELD_PROTECTED_BITS (type
) =
8869 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8870 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8872 TYPE_FIELD_IGNORE_BITS (type
) =
8873 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8874 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8877 /* If the type has baseclasses, allocate and clear a bit vector for
8878 TYPE_FIELD_VIRTUAL_BITS. */
8879 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
8881 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
8882 unsigned char *pointer
;
8884 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8885 pointer
= TYPE_ALLOC (type
, num_bytes
);
8886 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
8887 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
8888 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
8891 /* Copy the saved-up fields into the field vector. Start from the head of
8892 the list, adding to the tail of the field array, so that they end up in
8893 the same order in the array in which they were added to the list. */
8894 while (nfields
-- > 0)
8896 struct nextfield
*fieldp
;
8900 fieldp
= fip
->fields
;
8901 fip
->fields
= fieldp
->next
;
8905 fieldp
= fip
->baseclasses
;
8906 fip
->baseclasses
= fieldp
->next
;
8909 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
8910 switch (fieldp
->accessibility
)
8912 case DW_ACCESS_private
:
8913 if (cu
->language
!= language_ada
)
8914 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
8917 case DW_ACCESS_protected
:
8918 if (cu
->language
!= language_ada
)
8919 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
8922 case DW_ACCESS_public
:
8926 /* Unknown accessibility. Complain and treat it as public. */
8928 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
8929 fieldp
->accessibility
);
8933 if (nfields
< fip
->nbaseclasses
)
8935 switch (fieldp
->virtuality
)
8937 case DW_VIRTUALITY_virtual
:
8938 case DW_VIRTUALITY_pure_virtual
:
8939 if (cu
->language
== language_ada
)
8940 error (_("unexpected virtuality in component of Ada type"));
8941 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
8948 /* Add a member function to the proper fieldlist. */
8951 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
8952 struct type
*type
, struct dwarf2_cu
*cu
)
8954 struct objfile
*objfile
= cu
->objfile
;
8955 struct attribute
*attr
;
8956 struct fnfieldlist
*flp
;
8958 struct fn_field
*fnp
;
8960 struct nextfnfield
*new_fnfield
;
8961 struct type
*this_type
;
8962 enum dwarf_access_attribute accessibility
;
8964 if (cu
->language
== language_ada
)
8965 error (_("unexpected member function in Ada type"));
8967 /* Get name of member function. */
8968 fieldname
= dwarf2_name (die
, cu
);
8969 if (fieldname
== NULL
)
8972 /* Look up member function name in fieldlist. */
8973 for (i
= 0; i
< fip
->nfnfields
; i
++)
8975 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
8979 /* Create new list element if necessary. */
8980 if (i
< fip
->nfnfields
)
8981 flp
= &fip
->fnfieldlists
[i
];
8984 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
8986 fip
->fnfieldlists
= (struct fnfieldlist
*)
8987 xrealloc (fip
->fnfieldlists
,
8988 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
8989 * sizeof (struct fnfieldlist
));
8990 if (fip
->nfnfields
== 0)
8991 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
8993 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
8994 flp
->name
= fieldname
;
8997 i
= fip
->nfnfields
++;
9000 /* Create a new member function field and chain it to the field list
9002 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9003 make_cleanup (xfree
, new_fnfield
);
9004 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9005 new_fnfield
->next
= flp
->head
;
9006 flp
->head
= new_fnfield
;
9009 /* Fill in the member function field info. */
9010 fnp
= &new_fnfield
->fnfield
;
9012 /* Delay processing of the physname until later. */
9013 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9015 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9020 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9021 fnp
->physname
= physname
? physname
: "";
9024 fnp
->type
= alloc_type (objfile
);
9025 this_type
= read_type_die (die
, cu
);
9026 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9028 int nparams
= TYPE_NFIELDS (this_type
);
9030 /* TYPE is the domain of this method, and THIS_TYPE is the type
9031 of the method itself (TYPE_CODE_METHOD). */
9032 smash_to_method_type (fnp
->type
, type
,
9033 TYPE_TARGET_TYPE (this_type
),
9034 TYPE_FIELDS (this_type
),
9035 TYPE_NFIELDS (this_type
),
9036 TYPE_VARARGS (this_type
));
9038 /* Handle static member functions.
9039 Dwarf2 has no clean way to discern C++ static and non-static
9040 member functions. G++ helps GDB by marking the first
9041 parameter for non-static member functions (which is the this
9042 pointer) as artificial. We obtain this information from
9043 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
9044 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
9045 fnp
->voffset
= VOFFSET_STATIC
;
9048 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
9049 dwarf2_full_name (fieldname
, die
, cu
));
9051 /* Get fcontext from DW_AT_containing_type if present. */
9052 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9053 fnp
->fcontext
= die_containing_type (die
, cu
);
9055 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
9056 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
9058 /* Get accessibility. */
9059 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9061 accessibility
= DW_UNSND (attr
);
9063 accessibility
= dwarf2_default_access_attribute (die
, cu
);
9064 switch (accessibility
)
9066 case DW_ACCESS_private
:
9067 fnp
->is_private
= 1;
9069 case DW_ACCESS_protected
:
9070 fnp
->is_protected
= 1;
9074 /* Check for artificial methods. */
9075 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9076 if (attr
&& DW_UNSND (attr
) != 0)
9077 fnp
->is_artificial
= 1;
9079 /* Get index in virtual function table if it is a virtual member
9080 function. For older versions of GCC, this is an offset in the
9081 appropriate virtual table, as specified by DW_AT_containing_type.
9082 For everyone else, it is an expression to be evaluated relative
9083 to the object address. */
9085 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9088 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9090 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9092 /* Old-style GCC. */
9093 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9095 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9096 || (DW_BLOCK (attr
)->size
> 1
9097 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9098 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9100 struct dwarf_block blk
;
9103 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9105 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
9106 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
9107 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9108 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
9109 dwarf2_complex_location_expr_complaint ();
9111 fnp
->voffset
/= cu
->header
.addr_size
;
9115 dwarf2_complex_location_expr_complaint ();
9118 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
9120 else if (attr_form_is_section_offset (attr
))
9122 dwarf2_complex_location_expr_complaint ();
9126 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
9132 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9133 if (attr
&& DW_UNSND (attr
))
9135 /* GCC does this, as of 2008-08-25; PR debug/37237. */
9136 complaint (&symfile_complaints
,
9137 _("Member function \"%s\" (offset %d) is virtual "
9138 "but the vtable offset is not specified"),
9139 fieldname
, die
->offset
.sect_off
);
9140 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9141 TYPE_CPLUS_DYNAMIC (type
) = 1;
9146 /* Create the vector of member function fields, and attach it to the type. */
9149 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
9150 struct dwarf2_cu
*cu
)
9152 struct fnfieldlist
*flp
;
9155 if (cu
->language
== language_ada
)
9156 error (_("unexpected member functions in Ada type"));
9158 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9159 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
9160 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
9162 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
9164 struct nextfnfield
*nfp
= flp
->head
;
9165 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
9168 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
9169 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
9170 fn_flp
->fn_fields
= (struct fn_field
*)
9171 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
9172 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
9173 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
9176 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
9179 /* Returns non-zero if NAME is the name of a vtable member in CU's
9180 language, zero otherwise. */
9182 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
9184 static const char vptr
[] = "_vptr";
9185 static const char vtable
[] = "vtable";
9187 /* Look for the C++ and Java forms of the vtable. */
9188 if ((cu
->language
== language_java
9189 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
9190 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
9191 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
9197 /* GCC outputs unnamed structures that are really pointers to member
9198 functions, with the ABI-specified layout. If TYPE describes
9199 such a structure, smash it into a member function type.
9201 GCC shouldn't do this; it should just output pointer to member DIEs.
9202 This is GCC PR debug/28767. */
9205 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
9207 struct type
*pfn_type
, *domain_type
, *new_type
;
9209 /* Check for a structure with no name and two children. */
9210 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
9213 /* Check for __pfn and __delta members. */
9214 if (TYPE_FIELD_NAME (type
, 0) == NULL
9215 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
9216 || TYPE_FIELD_NAME (type
, 1) == NULL
9217 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
9220 /* Find the type of the method. */
9221 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
9222 if (pfn_type
== NULL
9223 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
9224 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
9227 /* Look for the "this" argument. */
9228 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
9229 if (TYPE_NFIELDS (pfn_type
) == 0
9230 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
9231 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
9234 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9235 new_type
= alloc_type (objfile
);
9236 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9237 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9238 TYPE_VARARGS (pfn_type
));
9239 smash_to_methodptr_type (type
, new_type
);
9242 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
9246 producer_is_icc (struct dwarf2_cu
*cu
)
9248 if (!cu
->checked_producer
)
9249 check_producer (cu
);
9251 return cu
->producer_is_icc
;
9254 /* Called when we find the DIE that starts a structure or union scope
9255 (definition) to create a type for the structure or union. Fill in
9256 the type's name and general properties; the members will not be
9257 processed until process_structure_type.
9259 NOTE: we need to call these functions regardless of whether or not the
9260 DIE has a DW_AT_name attribute, since it might be an anonymous
9261 structure or union. This gets the type entered into our set of
9264 However, if the structure is incomplete (an opaque struct/union)
9265 then suppress creating a symbol table entry for it since gdb only
9266 wants to find the one with the complete definition. Note that if
9267 it is complete, we just call new_symbol, which does it's own
9268 checking about whether the struct/union is anonymous or not (and
9269 suppresses creating a symbol table entry itself). */
9271 static struct type
*
9272 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9274 struct objfile
*objfile
= cu
->objfile
;
9276 struct attribute
*attr
;
9279 /* If the definition of this type lives in .debug_types, read that type.
9280 Don't follow DW_AT_specification though, that will take us back up
9281 the chain and we want to go down. */
9282 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9285 struct dwarf2_cu
*type_cu
= cu
;
9286 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9288 /* We could just recurse on read_structure_type, but we need to call
9289 get_die_type to ensure only one type for this DIE is created.
9290 This is important, for example, because for c++ classes we need
9291 TYPE_NAME set which is only done by new_symbol. Blech. */
9292 type
= read_type_die (type_die
, type_cu
);
9294 /* TYPE_CU may not be the same as CU.
9295 Ensure TYPE is recorded in CU's type_hash table. */
9296 return set_die_type (die
, type
, cu
);
9299 type
= alloc_type (objfile
);
9300 INIT_CPLUS_SPECIFIC (type
);
9302 name
= dwarf2_name (die
, cu
);
9305 if (cu
->language
== language_cplus
9306 || cu
->language
== language_java
)
9308 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9310 /* dwarf2_full_name might have already finished building the DIE's
9311 type. If so, there is no need to continue. */
9312 if (get_die_type (die
, cu
) != NULL
)
9313 return get_die_type (die
, cu
);
9315 TYPE_TAG_NAME (type
) = full_name
;
9316 if (die
->tag
== DW_TAG_structure_type
9317 || die
->tag
== DW_TAG_class_type
)
9318 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9322 /* The name is already allocated along with this objfile, so
9323 we don't need to duplicate it for the type. */
9324 TYPE_TAG_NAME (type
) = (char *) name
;
9325 if (die
->tag
== DW_TAG_class_type
)
9326 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9330 if (die
->tag
== DW_TAG_structure_type
)
9332 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9334 else if (die
->tag
== DW_TAG_union_type
)
9336 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9340 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9343 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9344 TYPE_DECLARED_CLASS (type
) = 1;
9346 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9349 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9353 TYPE_LENGTH (type
) = 0;
9356 if (producer_is_icc (cu
))
9358 /* ICC does not output the required DW_AT_declaration
9359 on incomplete types, but gives them a size of zero. */
9362 TYPE_STUB_SUPPORTED (type
) = 1;
9364 if (die_is_declaration (die
, cu
))
9365 TYPE_STUB (type
) = 1;
9366 else if (attr
== NULL
&& die
->child
== NULL
9367 && producer_is_realview (cu
->producer
))
9368 /* RealView does not output the required DW_AT_declaration
9369 on incomplete types. */
9370 TYPE_STUB (type
) = 1;
9372 /* We need to add the type field to the die immediately so we don't
9373 infinitely recurse when dealing with pointers to the structure
9374 type within the structure itself. */
9375 set_die_type (die
, type
, cu
);
9377 /* set_die_type should be already done. */
9378 set_descriptive_type (type
, die
, cu
);
9383 /* Finish creating a structure or union type, including filling in
9384 its members and creating a symbol for it. */
9387 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9389 struct objfile
*objfile
= cu
->objfile
;
9390 struct die_info
*child_die
= die
->child
;
9393 type
= get_die_type (die
, cu
);
9395 type
= read_structure_type (die
, cu
);
9397 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9399 struct field_info fi
;
9400 struct die_info
*child_die
;
9401 VEC (symbolp
) *template_args
= NULL
;
9402 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9404 memset (&fi
, 0, sizeof (struct field_info
));
9406 child_die
= die
->child
;
9408 while (child_die
&& child_die
->tag
)
9410 if (child_die
->tag
== DW_TAG_member
9411 || child_die
->tag
== DW_TAG_variable
)
9413 /* NOTE: carlton/2002-11-05: A C++ static data member
9414 should be a DW_TAG_member that is a declaration, but
9415 all versions of G++ as of this writing (so through at
9416 least 3.2.1) incorrectly generate DW_TAG_variable
9417 tags for them instead. */
9418 dwarf2_add_field (&fi
, child_die
, cu
);
9420 else if (child_die
->tag
== DW_TAG_subprogram
)
9422 /* C++ member function. */
9423 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9425 else if (child_die
->tag
== DW_TAG_inheritance
)
9427 /* C++ base class field. */
9428 dwarf2_add_field (&fi
, child_die
, cu
);
9430 else if (child_die
->tag
== DW_TAG_typedef
)
9431 dwarf2_add_typedef (&fi
, child_die
, cu
);
9432 else if (child_die
->tag
== DW_TAG_template_type_param
9433 || child_die
->tag
== DW_TAG_template_value_param
)
9435 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9438 VEC_safe_push (symbolp
, template_args
, arg
);
9441 child_die
= sibling_die (child_die
);
9444 /* Attach template arguments to type. */
9445 if (! VEC_empty (symbolp
, template_args
))
9447 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9448 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9449 = VEC_length (symbolp
, template_args
);
9450 TYPE_TEMPLATE_ARGUMENTS (type
)
9451 = obstack_alloc (&objfile
->objfile_obstack
,
9452 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9453 * sizeof (struct symbol
*)));
9454 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9455 VEC_address (symbolp
, template_args
),
9456 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9457 * sizeof (struct symbol
*)));
9458 VEC_free (symbolp
, template_args
);
9461 /* Attach fields and member functions to the type. */
9463 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9466 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9468 /* Get the type which refers to the base class (possibly this
9469 class itself) which contains the vtable pointer for the current
9470 class from the DW_AT_containing_type attribute. This use of
9471 DW_AT_containing_type is a GNU extension. */
9473 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9475 struct type
*t
= die_containing_type (die
, cu
);
9477 TYPE_VPTR_BASETYPE (type
) = t
;
9482 /* Our own class provides vtbl ptr. */
9483 for (i
= TYPE_NFIELDS (t
) - 1;
9484 i
>= TYPE_N_BASECLASSES (t
);
9487 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9489 if (is_vtable_name (fieldname
, cu
))
9491 TYPE_VPTR_FIELDNO (type
) = i
;
9496 /* Complain if virtual function table field not found. */
9497 if (i
< TYPE_N_BASECLASSES (t
))
9498 complaint (&symfile_complaints
,
9499 _("virtual function table pointer "
9500 "not found when defining class '%s'"),
9501 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9506 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9509 else if (cu
->producer
9510 && strncmp (cu
->producer
,
9511 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9513 /* The IBM XLC compiler does not provide direct indication
9514 of the containing type, but the vtable pointer is
9515 always named __vfp. */
9519 for (i
= TYPE_NFIELDS (type
) - 1;
9520 i
>= TYPE_N_BASECLASSES (type
);
9523 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9525 TYPE_VPTR_FIELDNO (type
) = i
;
9526 TYPE_VPTR_BASETYPE (type
) = type
;
9533 /* Copy fi.typedef_field_list linked list elements content into the
9534 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9535 if (fi
.typedef_field_list
)
9537 int i
= fi
.typedef_field_list_count
;
9539 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9540 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9541 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9542 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9544 /* Reverse the list order to keep the debug info elements order. */
9547 struct typedef_field
*dest
, *src
;
9549 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9550 src
= &fi
.typedef_field_list
->field
;
9551 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9556 do_cleanups (back_to
);
9558 if (HAVE_CPLUS_STRUCT (type
))
9559 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9562 quirk_gcc_member_function_pointer (type
, objfile
);
9564 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9565 snapshots) has been known to create a die giving a declaration
9566 for a class that has, as a child, a die giving a definition for a
9567 nested class. So we have to process our children even if the
9568 current die is a declaration. Normally, of course, a declaration
9569 won't have any children at all. */
9571 while (child_die
!= NULL
&& child_die
->tag
)
9573 if (child_die
->tag
== DW_TAG_member
9574 || child_die
->tag
== DW_TAG_variable
9575 || child_die
->tag
== DW_TAG_inheritance
9576 || child_die
->tag
== DW_TAG_template_value_param
9577 || child_die
->tag
== DW_TAG_template_type_param
)
9582 process_die (child_die
, cu
);
9584 child_die
= sibling_die (child_die
);
9587 /* Do not consider external references. According to the DWARF standard,
9588 these DIEs are identified by the fact that they have no byte_size
9589 attribute, and a declaration attribute. */
9590 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9591 || !die_is_declaration (die
, cu
))
9592 new_symbol (die
, type
, cu
);
9595 /* Given a DW_AT_enumeration_type die, set its type. We do not
9596 complete the type's fields yet, or create any symbols. */
9598 static struct type
*
9599 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9601 struct objfile
*objfile
= cu
->objfile
;
9603 struct attribute
*attr
;
9606 /* If the definition of this type lives in .debug_types, read that type.
9607 Don't follow DW_AT_specification though, that will take us back up
9608 the chain and we want to go down. */
9609 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9612 struct dwarf2_cu
*type_cu
= cu
;
9613 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9615 type
= read_type_die (type_die
, type_cu
);
9617 /* TYPE_CU may not be the same as CU.
9618 Ensure TYPE is recorded in CU's type_hash table. */
9619 return set_die_type (die
, type
, cu
);
9622 type
= alloc_type (objfile
);
9624 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9625 name
= dwarf2_full_name (NULL
, die
, cu
);
9627 TYPE_TAG_NAME (type
) = (char *) name
;
9629 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9632 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9636 TYPE_LENGTH (type
) = 0;
9639 /* The enumeration DIE can be incomplete. In Ada, any type can be
9640 declared as private in the package spec, and then defined only
9641 inside the package body. Such types are known as Taft Amendment
9642 Types. When another package uses such a type, an incomplete DIE
9643 may be generated by the compiler. */
9644 if (die_is_declaration (die
, cu
))
9645 TYPE_STUB (type
) = 1;
9647 return set_die_type (die
, type
, cu
);
9650 /* Given a pointer to a die which begins an enumeration, process all
9651 the dies that define the members of the enumeration, and create the
9652 symbol for the enumeration type.
9654 NOTE: We reverse the order of the element list. */
9657 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9659 struct type
*this_type
;
9661 this_type
= get_die_type (die
, cu
);
9662 if (this_type
== NULL
)
9663 this_type
= read_enumeration_type (die
, cu
);
9665 if (die
->child
!= NULL
)
9667 struct die_info
*child_die
;
9669 struct field
*fields
= NULL
;
9671 int unsigned_enum
= 1;
9676 child_die
= die
->child
;
9677 while (child_die
&& child_die
->tag
)
9679 if (child_die
->tag
!= DW_TAG_enumerator
)
9681 process_die (child_die
, cu
);
9685 name
= dwarf2_name (child_die
, cu
);
9688 sym
= new_symbol (child_die
, this_type
, cu
);
9689 if (SYMBOL_VALUE (sym
) < 0)
9694 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9697 mask
|= SYMBOL_VALUE (sym
);
9699 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9701 fields
= (struct field
*)
9703 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9704 * sizeof (struct field
));
9707 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9708 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9709 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9710 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9716 child_die
= sibling_die (child_die
);
9721 TYPE_NFIELDS (this_type
) = num_fields
;
9722 TYPE_FIELDS (this_type
) = (struct field
*)
9723 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9724 memcpy (TYPE_FIELDS (this_type
), fields
,
9725 sizeof (struct field
) * num_fields
);
9729 TYPE_UNSIGNED (this_type
) = 1;
9731 TYPE_FLAG_ENUM (this_type
) = 1;
9734 /* If we are reading an enum from a .debug_types unit, and the enum
9735 is a declaration, and the enum is not the signatured type in the
9736 unit, then we do not want to add a symbol for it. Adding a
9737 symbol would in some cases obscure the true definition of the
9738 enum, giving users an incomplete type when the definition is
9739 actually available. Note that we do not want to do this for all
9740 enums which are just declarations, because C++0x allows forward
9741 enum declarations. */
9742 if (cu
->per_cu
->is_debug_types
9743 && die_is_declaration (die
, cu
))
9745 struct signatured_type
*sig_type
;
9748 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9749 cu
->per_cu
->info_or_types_section
,
9750 cu
->per_cu
->offset
);
9751 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9752 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9756 new_symbol (die
, this_type
, cu
);
9759 /* Extract all information from a DW_TAG_array_type DIE and put it in
9760 the DIE's type field. For now, this only handles one dimensional
9763 static struct type
*
9764 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9766 struct objfile
*objfile
= cu
->objfile
;
9767 struct die_info
*child_die
;
9769 struct type
*element_type
, *range_type
, *index_type
;
9770 struct type
**range_types
= NULL
;
9771 struct attribute
*attr
;
9773 struct cleanup
*back_to
;
9776 element_type
= die_type (die
, cu
);
9778 /* The die_type call above may have already set the type for this DIE. */
9779 type
= get_die_type (die
, cu
);
9783 /* Irix 6.2 native cc creates array types without children for
9784 arrays with unspecified length. */
9785 if (die
->child
== NULL
)
9787 index_type
= objfile_type (objfile
)->builtin_int
;
9788 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9789 type
= create_array_type (NULL
, element_type
, range_type
);
9790 return set_die_type (die
, type
, cu
);
9793 back_to
= make_cleanup (null_cleanup
, NULL
);
9794 child_die
= die
->child
;
9795 while (child_die
&& child_die
->tag
)
9797 if (child_die
->tag
== DW_TAG_subrange_type
)
9799 struct type
*child_type
= read_type_die (child_die
, cu
);
9801 if (child_type
!= NULL
)
9803 /* The range type was succesfully read. Save it for the
9804 array type creation. */
9805 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9807 range_types
= (struct type
**)
9808 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9809 * sizeof (struct type
*));
9811 make_cleanup (free_current_contents
, &range_types
);
9813 range_types
[ndim
++] = child_type
;
9816 child_die
= sibling_die (child_die
);
9819 /* Dwarf2 dimensions are output from left to right, create the
9820 necessary array types in backwards order. */
9822 type
= element_type
;
9824 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9829 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9834 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9837 /* Understand Dwarf2 support for vector types (like they occur on
9838 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9839 array type. This is not part of the Dwarf2/3 standard yet, but a
9840 custom vendor extension. The main difference between a regular
9841 array and the vector variant is that vectors are passed by value
9843 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9845 make_vector_type (type
);
9847 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9848 implementation may choose to implement triple vectors using this
9850 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9853 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9854 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9856 complaint (&symfile_complaints
,
9857 _("DW_AT_byte_size for array type smaller "
9858 "than the total size of elements"));
9861 name
= dwarf2_name (die
, cu
);
9863 TYPE_NAME (type
) = name
;
9865 /* Install the type in the die. */
9866 set_die_type (die
, type
, cu
);
9868 /* set_die_type should be already done. */
9869 set_descriptive_type (type
, die
, cu
);
9871 do_cleanups (back_to
);
9876 static enum dwarf_array_dim_ordering
9877 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
9879 struct attribute
*attr
;
9881 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
9883 if (attr
) return DW_SND (attr
);
9885 /* GNU F77 is a special case, as at 08/2004 array type info is the
9886 opposite order to the dwarf2 specification, but data is still
9887 laid out as per normal fortran.
9889 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
9890 version checking. */
9892 if (cu
->language
== language_fortran
9893 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
9895 return DW_ORD_row_major
;
9898 switch (cu
->language_defn
->la_array_ordering
)
9900 case array_column_major
:
9901 return DW_ORD_col_major
;
9902 case array_row_major
:
9904 return DW_ORD_row_major
;
9908 /* Extract all information from a DW_TAG_set_type DIE and put it in
9909 the DIE's type field. */
9911 static struct type
*
9912 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9914 struct type
*domain_type
, *set_type
;
9915 struct attribute
*attr
;
9917 domain_type
= die_type (die
, cu
);
9919 /* The die_type call above may have already set the type for this DIE. */
9920 set_type
= get_die_type (die
, cu
);
9924 set_type
= create_set_type (NULL
, domain_type
);
9926 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9928 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
9930 return set_die_type (die
, set_type
, cu
);
9933 /* First cut: install each common block member as a global variable. */
9936 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
9938 struct die_info
*child_die
;
9939 struct attribute
*attr
;
9941 CORE_ADDR base
= (CORE_ADDR
) 0;
9943 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9946 /* Support the .debug_loc offsets. */
9947 if (attr_form_is_block (attr
))
9949 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
9951 else if (attr_form_is_section_offset (attr
))
9953 dwarf2_complex_location_expr_complaint ();
9957 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9958 "common block member");
9961 if (die
->child
!= NULL
)
9963 child_die
= die
->child
;
9964 while (child_die
&& child_die
->tag
)
9968 sym
= new_symbol (child_die
, NULL
, cu
);
9970 && handle_data_member_location (child_die
, cu
, &offset
))
9972 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
9973 add_symbol_to_list (sym
, &global_symbols
);
9975 child_die
= sibling_die (child_die
);
9980 /* Create a type for a C++ namespace. */
9982 static struct type
*
9983 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9985 struct objfile
*objfile
= cu
->objfile
;
9986 const char *previous_prefix
, *name
;
9990 /* For extensions, reuse the type of the original namespace. */
9991 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
9993 struct die_info
*ext_die
;
9994 struct dwarf2_cu
*ext_cu
= cu
;
9996 ext_die
= dwarf2_extension (die
, &ext_cu
);
9997 type
= read_type_die (ext_die
, ext_cu
);
9999 /* EXT_CU may not be the same as CU.
10000 Ensure TYPE is recorded in CU's type_hash table. */
10001 return set_die_type (die
, type
, cu
);
10004 name
= namespace_name (die
, &is_anonymous
, cu
);
10006 /* Now build the name of the current namespace. */
10008 previous_prefix
= determine_prefix (die
, cu
);
10009 if (previous_prefix
[0] != '\0')
10010 name
= typename_concat (&objfile
->objfile_obstack
,
10011 previous_prefix
, name
, 0, cu
);
10013 /* Create the type. */
10014 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10016 TYPE_NAME (type
) = (char *) name
;
10017 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10019 return set_die_type (die
, type
, cu
);
10022 /* Read a C++ namespace. */
10025 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10027 struct objfile
*objfile
= cu
->objfile
;
10030 /* Add a symbol associated to this if we haven't seen the namespace
10031 before. Also, add a using directive if it's an anonymous
10034 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10038 type
= read_type_die (die
, cu
);
10039 new_symbol (die
, type
, cu
);
10041 namespace_name (die
, &is_anonymous
, cu
);
10044 const char *previous_prefix
= determine_prefix (die
, cu
);
10046 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
10047 NULL
, NULL
, &objfile
->objfile_obstack
);
10051 if (die
->child
!= NULL
)
10053 struct die_info
*child_die
= die
->child
;
10055 while (child_die
&& child_die
->tag
)
10057 process_die (child_die
, cu
);
10058 child_die
= sibling_die (child_die
);
10063 /* Read a Fortran module as type. This DIE can be only a declaration used for
10064 imported module. Still we need that type as local Fortran "use ... only"
10065 declaration imports depend on the created type in determine_prefix. */
10067 static struct type
*
10068 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10070 struct objfile
*objfile
= cu
->objfile
;
10074 module_name
= dwarf2_name (die
, cu
);
10076 complaint (&symfile_complaints
,
10077 _("DW_TAG_module has no name, offset 0x%x"),
10078 die
->offset
.sect_off
);
10079 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10081 /* determine_prefix uses TYPE_TAG_NAME. */
10082 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10084 return set_die_type (die
, type
, cu
);
10087 /* Read a Fortran module. */
10090 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10092 struct die_info
*child_die
= die
->child
;
10094 while (child_die
&& child_die
->tag
)
10096 process_die (child_die
, cu
);
10097 child_die
= sibling_die (child_die
);
10101 /* Return the name of the namespace represented by DIE. Set
10102 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
10105 static const char *
10106 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
10108 struct die_info
*current_die
;
10109 const char *name
= NULL
;
10111 /* Loop through the extensions until we find a name. */
10113 for (current_die
= die
;
10114 current_die
!= NULL
;
10115 current_die
= dwarf2_extension (die
, &cu
))
10117 name
= dwarf2_name (current_die
, cu
);
10122 /* Is it an anonymous namespace? */
10124 *is_anonymous
= (name
== NULL
);
10126 name
= CP_ANONYMOUS_NAMESPACE_STR
;
10131 /* Extract all information from a DW_TAG_pointer_type DIE and add to
10132 the user defined type vector. */
10134 static struct type
*
10135 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10137 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
10138 struct comp_unit_head
*cu_header
= &cu
->header
;
10140 struct attribute
*attr_byte_size
;
10141 struct attribute
*attr_address_class
;
10142 int byte_size
, addr_class
;
10143 struct type
*target_type
;
10145 target_type
= die_type (die
, cu
);
10147 /* The die_type call above may have already set the type for this DIE. */
10148 type
= get_die_type (die
, cu
);
10152 type
= lookup_pointer_type (target_type
);
10154 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10155 if (attr_byte_size
)
10156 byte_size
= DW_UNSND (attr_byte_size
);
10158 byte_size
= cu_header
->addr_size
;
10160 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
10161 if (attr_address_class
)
10162 addr_class
= DW_UNSND (attr_address_class
);
10164 addr_class
= DW_ADDR_none
;
10166 /* If the pointer size or address class is different than the
10167 default, create a type variant marked as such and set the
10168 length accordingly. */
10169 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
10171 if (gdbarch_address_class_type_flags_p (gdbarch
))
10175 type_flags
= gdbarch_address_class_type_flags
10176 (gdbarch
, byte_size
, addr_class
);
10177 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
10179 type
= make_type_with_address_space (type
, type_flags
);
10181 else if (TYPE_LENGTH (type
) != byte_size
)
10183 complaint (&symfile_complaints
,
10184 _("invalid pointer size %d"), byte_size
);
10188 /* Should we also complain about unhandled address classes? */
10192 TYPE_LENGTH (type
) = byte_size
;
10193 return set_die_type (die
, type
, cu
);
10196 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
10197 the user defined type vector. */
10199 static struct type
*
10200 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10203 struct type
*to_type
;
10204 struct type
*domain
;
10206 to_type
= die_type (die
, cu
);
10207 domain
= die_containing_type (die
, cu
);
10209 /* The calls above may have already set the type for this DIE. */
10210 type
= get_die_type (die
, cu
);
10214 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
10215 type
= lookup_methodptr_type (to_type
);
10217 type
= lookup_memberptr_type (to_type
, domain
);
10219 return set_die_type (die
, type
, cu
);
10222 /* Extract all information from a DW_TAG_reference_type DIE and add to
10223 the user defined type vector. */
10225 static struct type
*
10226 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10228 struct comp_unit_head
*cu_header
= &cu
->header
;
10229 struct type
*type
, *target_type
;
10230 struct attribute
*attr
;
10232 target_type
= die_type (die
, cu
);
10234 /* The die_type call above may have already set the type for this DIE. */
10235 type
= get_die_type (die
, cu
);
10239 type
= lookup_reference_type (target_type
);
10240 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10243 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10247 TYPE_LENGTH (type
) = cu_header
->addr_size
;
10249 return set_die_type (die
, type
, cu
);
10252 static struct type
*
10253 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10255 struct type
*base_type
, *cv_type
;
10257 base_type
= die_type (die
, cu
);
10259 /* The die_type call above may have already set the type for this DIE. */
10260 cv_type
= get_die_type (die
, cu
);
10264 /* In case the const qualifier is applied to an array type, the element type
10265 is so qualified, not the array type (section 6.7.3 of C99). */
10266 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10268 struct type
*el_type
, *inner_array
;
10270 base_type
= copy_type (base_type
);
10271 inner_array
= base_type
;
10273 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10275 TYPE_TARGET_TYPE (inner_array
) =
10276 copy_type (TYPE_TARGET_TYPE (inner_array
));
10277 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10280 el_type
= TYPE_TARGET_TYPE (inner_array
);
10281 TYPE_TARGET_TYPE (inner_array
) =
10282 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10284 return set_die_type (die
, base_type
, cu
);
10287 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10288 return set_die_type (die
, cv_type
, cu
);
10291 static struct type
*
10292 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10294 struct type
*base_type
, *cv_type
;
10296 base_type
= die_type (die
, cu
);
10298 /* The die_type call above may have already set the type for this DIE. */
10299 cv_type
= get_die_type (die
, cu
);
10303 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10304 return set_die_type (die
, cv_type
, cu
);
10307 /* Extract all information from a DW_TAG_string_type DIE and add to
10308 the user defined type vector. It isn't really a user defined type,
10309 but it behaves like one, with other DIE's using an AT_user_def_type
10310 attribute to reference it. */
10312 static struct type
*
10313 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10315 struct objfile
*objfile
= cu
->objfile
;
10316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10317 struct type
*type
, *range_type
, *index_type
, *char_type
;
10318 struct attribute
*attr
;
10319 unsigned int length
;
10321 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10324 length
= DW_UNSND (attr
);
10328 /* Check for the DW_AT_byte_size attribute. */
10329 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10332 length
= DW_UNSND (attr
);
10340 index_type
= objfile_type (objfile
)->builtin_int
;
10341 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10342 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10343 type
= create_string_type (NULL
, char_type
, range_type
);
10345 return set_die_type (die
, type
, cu
);
10348 /* Handle DIES due to C code like:
10352 int (*funcp)(int a, long l);
10356 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10358 static struct type
*
10359 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10361 struct objfile
*objfile
= cu
->objfile
;
10362 struct type
*type
; /* Type that this function returns. */
10363 struct type
*ftype
; /* Function that returns above type. */
10364 struct attribute
*attr
;
10366 type
= die_type (die
, cu
);
10368 /* The die_type call above may have already set the type for this DIE. */
10369 ftype
= get_die_type (die
, cu
);
10373 ftype
= lookup_function_type (type
);
10375 /* All functions in C++, Pascal and Java have prototypes. */
10376 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10377 if ((attr
&& (DW_UNSND (attr
) != 0))
10378 || cu
->language
== language_cplus
10379 || cu
->language
== language_java
10380 || cu
->language
== language_pascal
)
10381 TYPE_PROTOTYPED (ftype
) = 1;
10382 else if (producer_is_realview (cu
->producer
))
10383 /* RealView does not emit DW_AT_prototyped. We can not
10384 distinguish prototyped and unprototyped functions; default to
10385 prototyped, since that is more common in modern code (and
10386 RealView warns about unprototyped functions). */
10387 TYPE_PROTOTYPED (ftype
) = 1;
10389 /* Store the calling convention in the type if it's available in
10390 the subroutine die. Otherwise set the calling convention to
10391 the default value DW_CC_normal. */
10392 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10394 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10395 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10396 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10398 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10400 /* We need to add the subroutine type to the die immediately so
10401 we don't infinitely recurse when dealing with parameters
10402 declared as the same subroutine type. */
10403 set_die_type (die
, ftype
, cu
);
10405 if (die
->child
!= NULL
)
10407 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10408 struct die_info
*child_die
;
10409 int nparams
, iparams
;
10411 /* Count the number of parameters.
10412 FIXME: GDB currently ignores vararg functions, but knows about
10413 vararg member functions. */
10415 child_die
= die
->child
;
10416 while (child_die
&& child_die
->tag
)
10418 if (child_die
->tag
== DW_TAG_formal_parameter
)
10420 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10421 TYPE_VARARGS (ftype
) = 1;
10422 child_die
= sibling_die (child_die
);
10425 /* Allocate storage for parameters and fill them in. */
10426 TYPE_NFIELDS (ftype
) = nparams
;
10427 TYPE_FIELDS (ftype
) = (struct field
*)
10428 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10430 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10431 even if we error out during the parameters reading below. */
10432 for (iparams
= 0; iparams
< nparams
; iparams
++)
10433 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10436 child_die
= die
->child
;
10437 while (child_die
&& child_die
->tag
)
10439 if (child_die
->tag
== DW_TAG_formal_parameter
)
10441 struct type
*arg_type
;
10443 /* DWARF version 2 has no clean way to discern C++
10444 static and non-static member functions. G++ helps
10445 GDB by marking the first parameter for non-static
10446 member functions (which is the this pointer) as
10447 artificial. We pass this information to
10448 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10450 DWARF version 3 added DW_AT_object_pointer, which GCC
10451 4.5 does not yet generate. */
10452 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10454 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10457 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10459 /* GCC/43521: In java, the formal parameter
10460 "this" is sometimes not marked with DW_AT_artificial. */
10461 if (cu
->language
== language_java
)
10463 const char *name
= dwarf2_name (child_die
, cu
);
10465 if (name
&& !strcmp (name
, "this"))
10466 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10469 arg_type
= die_type (child_die
, cu
);
10471 /* RealView does not mark THIS as const, which the testsuite
10472 expects. GCC marks THIS as const in method definitions,
10473 but not in the class specifications (GCC PR 43053). */
10474 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10475 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10478 struct dwarf2_cu
*arg_cu
= cu
;
10479 const char *name
= dwarf2_name (child_die
, cu
);
10481 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10484 /* If the compiler emits this, use it. */
10485 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10488 else if (name
&& strcmp (name
, "this") == 0)
10489 /* Function definitions will have the argument names. */
10491 else if (name
== NULL
&& iparams
== 0)
10492 /* Declarations may not have the names, so like
10493 elsewhere in GDB, assume an artificial first
10494 argument is "this". */
10498 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10502 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10505 child_die
= sibling_die (child_die
);
10512 static struct type
*
10513 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10515 struct objfile
*objfile
= cu
->objfile
;
10516 const char *name
= NULL
;
10517 struct type
*this_type
, *target_type
;
10519 name
= dwarf2_full_name (NULL
, die
, cu
);
10520 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10521 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10522 TYPE_NAME (this_type
) = (char *) name
;
10523 set_die_type (die
, this_type
, cu
);
10524 target_type
= die_type (die
, cu
);
10525 if (target_type
!= this_type
)
10526 TYPE_TARGET_TYPE (this_type
) = target_type
;
10529 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10530 spec and cause infinite loops in GDB. */
10531 complaint (&symfile_complaints
,
10532 _("Self-referential DW_TAG_typedef "
10533 "- DIE at 0x%x [in module %s]"),
10534 die
->offset
.sect_off
, objfile
->name
);
10535 TYPE_TARGET_TYPE (this_type
) = NULL
;
10540 /* Find a representation of a given base type and install
10541 it in the TYPE field of the die. */
10543 static struct type
*
10544 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10546 struct objfile
*objfile
= cu
->objfile
;
10548 struct attribute
*attr
;
10549 int encoding
= 0, size
= 0;
10551 enum type_code code
= TYPE_CODE_INT
;
10552 int type_flags
= 0;
10553 struct type
*target_type
= NULL
;
10555 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10558 encoding
= DW_UNSND (attr
);
10560 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10563 size
= DW_UNSND (attr
);
10565 name
= dwarf2_name (die
, cu
);
10568 complaint (&symfile_complaints
,
10569 _("DW_AT_name missing from DW_TAG_base_type"));
10574 case DW_ATE_address
:
10575 /* Turn DW_ATE_address into a void * pointer. */
10576 code
= TYPE_CODE_PTR
;
10577 type_flags
|= TYPE_FLAG_UNSIGNED
;
10578 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10580 case DW_ATE_boolean
:
10581 code
= TYPE_CODE_BOOL
;
10582 type_flags
|= TYPE_FLAG_UNSIGNED
;
10584 case DW_ATE_complex_float
:
10585 code
= TYPE_CODE_COMPLEX
;
10586 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10588 case DW_ATE_decimal_float
:
10589 code
= TYPE_CODE_DECFLOAT
;
10592 code
= TYPE_CODE_FLT
;
10594 case DW_ATE_signed
:
10596 case DW_ATE_unsigned
:
10597 type_flags
|= TYPE_FLAG_UNSIGNED
;
10598 if (cu
->language
== language_fortran
10600 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10601 code
= TYPE_CODE_CHAR
;
10603 case DW_ATE_signed_char
:
10604 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10605 || cu
->language
== language_pascal
10606 || cu
->language
== language_fortran
)
10607 code
= TYPE_CODE_CHAR
;
10609 case DW_ATE_unsigned_char
:
10610 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10611 || cu
->language
== language_pascal
10612 || cu
->language
== language_fortran
)
10613 code
= TYPE_CODE_CHAR
;
10614 type_flags
|= TYPE_FLAG_UNSIGNED
;
10617 /* We just treat this as an integer and then recognize the
10618 type by name elsewhere. */
10622 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10623 dwarf_type_encoding_name (encoding
));
10627 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10628 TYPE_NAME (type
) = name
;
10629 TYPE_TARGET_TYPE (type
) = target_type
;
10631 if (name
&& strcmp (name
, "char") == 0)
10632 TYPE_NOSIGN (type
) = 1;
10634 return set_die_type (die
, type
, cu
);
10637 /* Read the given DW_AT_subrange DIE. */
10639 static struct type
*
10640 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10642 struct type
*base_type
;
10643 struct type
*range_type
;
10644 struct attribute
*attr
;
10646 int low_default_is_valid
;
10648 LONGEST negative_mask
;
10650 base_type
= die_type (die
, cu
);
10651 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10652 check_typedef (base_type
);
10654 /* The die_type call above may have already set the type for this DIE. */
10655 range_type
= get_die_type (die
, cu
);
10659 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10660 omitting DW_AT_lower_bound. */
10661 switch (cu
->language
)
10664 case language_cplus
:
10666 low_default_is_valid
= 1;
10668 case language_fortran
:
10670 low_default_is_valid
= 1;
10673 case language_java
:
10674 case language_objc
:
10676 low_default_is_valid
= (cu
->header
.version
>= 4);
10680 case language_pascal
:
10682 low_default_is_valid
= (cu
->header
.version
>= 4);
10686 low_default_is_valid
= 0;
10690 /* FIXME: For variable sized arrays either of these could be
10691 a variable rather than a constant value. We'll allow it,
10692 but we don't know how to handle it. */
10693 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10695 low
= dwarf2_get_attr_constant_value (attr
, low
);
10696 else if (!low_default_is_valid
)
10697 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10698 "- DIE at 0x%x [in module %s]"),
10699 die
->offset
.sect_off
, cu
->objfile
->name
);
10701 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10704 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10706 /* GCC encodes arrays with unspecified or dynamic length
10707 with a DW_FORM_block1 attribute or a reference attribute.
10708 FIXME: GDB does not yet know how to handle dynamic
10709 arrays properly, treat them as arrays with unspecified
10712 FIXME: jimb/2003-09-22: GDB does not really know
10713 how to handle arrays of unspecified length
10714 either; we just represent them as zero-length
10715 arrays. Choose an appropriate upper bound given
10716 the lower bound we've computed above. */
10720 high
= dwarf2_get_attr_constant_value (attr
, 1);
10724 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10727 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10728 high
= low
+ count
- 1;
10732 /* Unspecified array length. */
10737 /* Dwarf-2 specifications explicitly allows to create subrange types
10738 without specifying a base type.
10739 In that case, the base type must be set to the type of
10740 the lower bound, upper bound or count, in that order, if any of these
10741 three attributes references an object that has a type.
10742 If no base type is found, the Dwarf-2 specifications say that
10743 a signed integer type of size equal to the size of an address should
10745 For the following C code: `extern char gdb_int [];'
10746 GCC produces an empty range DIE.
10747 FIXME: muller/2010-05-28: Possible references to object for low bound,
10748 high bound or count are not yet handled by this code. */
10749 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10751 struct objfile
*objfile
= cu
->objfile
;
10752 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10753 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10754 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10756 /* Test "int", "long int", and "long long int" objfile types,
10757 and select the first one having a size above or equal to the
10758 architecture address size. */
10759 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10760 base_type
= int_type
;
10763 int_type
= objfile_type (objfile
)->builtin_long
;
10764 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10765 base_type
= int_type
;
10768 int_type
= objfile_type (objfile
)->builtin_long_long
;
10769 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10770 base_type
= int_type
;
10776 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10777 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10778 low
|= negative_mask
;
10779 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10780 high
|= negative_mask
;
10782 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10784 /* Mark arrays with dynamic length at least as an array of unspecified
10785 length. GDB could check the boundary but before it gets implemented at
10786 least allow accessing the array elements. */
10787 if (attr
&& attr_form_is_block (attr
))
10788 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10790 /* Ada expects an empty array on no boundary attributes. */
10791 if (attr
== NULL
&& cu
->language
!= language_ada
)
10792 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10794 name
= dwarf2_name (die
, cu
);
10796 TYPE_NAME (range_type
) = name
;
10798 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10800 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10802 set_die_type (die
, range_type
, cu
);
10804 /* set_die_type should be already done. */
10805 set_descriptive_type (range_type
, die
, cu
);
10810 static struct type
*
10811 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10815 /* For now, we only support the C meaning of an unspecified type: void. */
10817 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10818 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10820 return set_die_type (die
, type
, cu
);
10823 /* Read a single die and all its descendents. Set the die's sibling
10824 field to NULL; set other fields in the die correctly, and set all
10825 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10826 location of the info_ptr after reading all of those dies. PARENT
10827 is the parent of the die in question. */
10829 static struct die_info
*
10830 read_die_and_children (const struct die_reader_specs
*reader
,
10831 gdb_byte
*info_ptr
,
10832 gdb_byte
**new_info_ptr
,
10833 struct die_info
*parent
)
10835 struct die_info
*die
;
10839 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10842 *new_info_ptr
= cur_ptr
;
10845 store_in_ref_table (die
, reader
->cu
);
10848 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10852 *new_info_ptr
= cur_ptr
;
10855 die
->sibling
= NULL
;
10856 die
->parent
= parent
;
10860 /* Read a die, all of its descendents, and all of its siblings; set
10861 all of the fields of all of the dies correctly. Arguments are as
10862 in read_die_and_children. */
10864 static struct die_info
*
10865 read_die_and_siblings (const struct die_reader_specs
*reader
,
10866 gdb_byte
*info_ptr
,
10867 gdb_byte
**new_info_ptr
,
10868 struct die_info
*parent
)
10870 struct die_info
*first_die
, *last_sibling
;
10873 cur_ptr
= info_ptr
;
10874 first_die
= last_sibling
= NULL
;
10878 struct die_info
*die
10879 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
10883 *new_info_ptr
= cur_ptr
;
10890 last_sibling
->sibling
= die
;
10892 last_sibling
= die
;
10896 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
10898 The caller is responsible for filling in the extra attributes
10899 and updating (*DIEP)->num_attrs.
10900 Set DIEP to point to a newly allocated die with its information,
10901 except for its child, sibling, and parent fields.
10902 Set HAS_CHILDREN to tell whether the die has children or not. */
10905 read_full_die_1 (const struct die_reader_specs
*reader
,
10906 struct die_info
**diep
, gdb_byte
*info_ptr
,
10907 int *has_children
, int num_extra_attrs
)
10909 unsigned int abbrev_number
, bytes_read
, i
;
10910 sect_offset offset
;
10911 struct abbrev_info
*abbrev
;
10912 struct die_info
*die
;
10913 struct dwarf2_cu
*cu
= reader
->cu
;
10914 bfd
*abfd
= reader
->abfd
;
10916 offset
.sect_off
= info_ptr
- reader
->buffer
;
10917 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
10918 info_ptr
+= bytes_read
;
10919 if (!abbrev_number
)
10926 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
10928 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
10930 bfd_get_filename (abfd
));
10932 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
10933 die
->offset
= offset
;
10934 die
->tag
= abbrev
->tag
;
10935 die
->abbrev
= abbrev_number
;
10937 /* Make the result usable.
10938 The caller needs to update num_attrs after adding the extra
10940 die
->num_attrs
= abbrev
->num_attrs
;
10942 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
10943 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
10947 *has_children
= abbrev
->has_children
;
10951 /* Read a die and all its attributes.
10952 Set DIEP to point to a newly allocated die with its information,
10953 except for its child, sibling, and parent fields.
10954 Set HAS_CHILDREN to tell whether the die has children or not. */
10957 read_full_die (const struct die_reader_specs
*reader
,
10958 struct die_info
**diep
, gdb_byte
*info_ptr
,
10961 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
10964 /* In DWARF version 2, the description of the debugging information is
10965 stored in a separate .debug_abbrev section. Before we read any
10966 dies from a section we read in all abbreviations and install them
10967 in a hash table. This function also sets flags in CU describing
10968 the data found in the abbrev table. */
10971 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
10972 struct dwarf2_section_info
*abbrev_section
)
10975 bfd
*abfd
= abbrev_section
->asection
->owner
;
10976 struct comp_unit_head
*cu_header
= &cu
->header
;
10977 gdb_byte
*abbrev_ptr
;
10978 struct abbrev_info
*cur_abbrev
;
10979 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
10980 unsigned int abbrev_form
, hash_number
;
10981 struct attr_abbrev
*cur_attrs
;
10982 unsigned int allocated_attrs
;
10984 /* Initialize dwarf2 abbrevs. */
10985 obstack_init (&cu
->abbrev_obstack
);
10986 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
10988 * sizeof (struct abbrev_info
*)));
10989 memset (cu
->dwarf2_abbrevs
, 0,
10990 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
10992 dwarf2_read_section (cu
->objfile
, abbrev_section
);
10993 abbrev_ptr
= abbrev_section
->buffer
+ cu_header
->abbrev_offset
.sect_off
;
10994 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
10995 abbrev_ptr
+= bytes_read
;
10997 allocated_attrs
= ATTR_ALLOC_CHUNK
;
10998 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
11000 /* Loop until we reach an abbrev number of 0. */
11001 while (abbrev_number
)
11003 cur_abbrev
= dwarf_alloc_abbrev (cu
);
11005 /* read in abbrev header */
11006 cur_abbrev
->number
= abbrev_number
;
11007 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11008 abbrev_ptr
+= bytes_read
;
11009 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
11012 /* now read in declarations */
11013 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11014 abbrev_ptr
+= bytes_read
;
11015 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11016 abbrev_ptr
+= bytes_read
;
11017 while (abbrev_name
)
11019 if (cur_abbrev
->num_attrs
== allocated_attrs
)
11021 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
11023 = xrealloc (cur_attrs
, (allocated_attrs
11024 * sizeof (struct attr_abbrev
)));
11027 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
11028 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
11029 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11030 abbrev_ptr
+= bytes_read
;
11031 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11032 abbrev_ptr
+= bytes_read
;
11035 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
11036 (cur_abbrev
->num_attrs
11037 * sizeof (struct attr_abbrev
)));
11038 memcpy (cur_abbrev
->attrs
, cur_attrs
,
11039 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
11041 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11042 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
11043 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
11045 /* Get next abbreviation.
11046 Under Irix6 the abbreviations for a compilation unit are not
11047 always properly terminated with an abbrev number of 0.
11048 Exit loop if we encounter an abbreviation which we have
11049 already read (which means we are about to read the abbreviations
11050 for the next compile unit) or if the end of the abbreviation
11051 table is reached. */
11052 if ((unsigned int) (abbrev_ptr
- abbrev_section
->buffer
)
11053 >= abbrev_section
->size
)
11055 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11056 abbrev_ptr
+= bytes_read
;
11057 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
11064 /* Release the memory used by the abbrev table for a compilation unit. */
11067 dwarf2_free_abbrev_table (void *ptr_to_cu
)
11069 struct dwarf2_cu
*cu
= ptr_to_cu
;
11071 obstack_free (&cu
->abbrev_obstack
, NULL
);
11072 cu
->dwarf2_abbrevs
= NULL
;
11075 /* Lookup an abbrev_info structure in the abbrev hash table. */
11077 static struct abbrev_info
*
11078 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
11080 unsigned int hash_number
;
11081 struct abbrev_info
*abbrev
;
11083 hash_number
= number
% ABBREV_HASH_SIZE
;
11084 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
11088 if (abbrev
->number
== number
)
11091 abbrev
= abbrev
->next
;
11096 /* Returns nonzero if TAG represents a type that we might generate a partial
11100 is_type_tag_for_partial (int tag
)
11105 /* Some types that would be reasonable to generate partial symbols for,
11106 that we don't at present. */
11107 case DW_TAG_array_type
:
11108 case DW_TAG_file_type
:
11109 case DW_TAG_ptr_to_member_type
:
11110 case DW_TAG_set_type
:
11111 case DW_TAG_string_type
:
11112 case DW_TAG_subroutine_type
:
11114 case DW_TAG_base_type
:
11115 case DW_TAG_class_type
:
11116 case DW_TAG_interface_type
:
11117 case DW_TAG_enumeration_type
:
11118 case DW_TAG_structure_type
:
11119 case DW_TAG_subrange_type
:
11120 case DW_TAG_typedef
:
11121 case DW_TAG_union_type
:
11128 /* Load all DIEs that are interesting for partial symbols into memory. */
11130 static struct partial_die_info
*
11131 load_partial_dies (const struct die_reader_specs
*reader
,
11132 gdb_byte
*info_ptr
, int building_psymtab
)
11134 struct dwarf2_cu
*cu
= reader
->cu
;
11135 struct objfile
*objfile
= cu
->objfile
;
11136 struct partial_die_info
*part_die
;
11137 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
11138 struct abbrev_info
*abbrev
;
11139 unsigned int bytes_read
;
11140 unsigned int load_all
= 0;
11141 int nesting_level
= 1;
11146 gdb_assert (cu
->per_cu
!= NULL
);
11147 if (cu
->per_cu
->load_all_dies
)
11151 = htab_create_alloc_ex (cu
->header
.length
/ 12,
11155 &cu
->comp_unit_obstack
,
11156 hashtab_obstack_allocate
,
11157 dummy_obstack_deallocate
);
11159 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11160 sizeof (struct partial_die_info
));
11164 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
11166 /* A NULL abbrev means the end of a series of children. */
11167 if (abbrev
== NULL
)
11169 if (--nesting_level
== 0)
11171 /* PART_DIE was probably the last thing allocated on the
11172 comp_unit_obstack, so we could call obstack_free
11173 here. We don't do that because the waste is small,
11174 and will be cleaned up when we're done with this
11175 compilation unit. This way, we're also more robust
11176 against other users of the comp_unit_obstack. */
11179 info_ptr
+= bytes_read
;
11180 last_die
= parent_die
;
11181 parent_die
= parent_die
->die_parent
;
11185 /* Check for template arguments. We never save these; if
11186 they're seen, we just mark the parent, and go on our way. */
11187 if (parent_die
!= NULL
11188 && cu
->language
== language_cplus
11189 && (abbrev
->tag
== DW_TAG_template_type_param
11190 || abbrev
->tag
== DW_TAG_template_value_param
))
11192 parent_die
->has_template_arguments
= 1;
11196 /* We don't need a partial DIE for the template argument. */
11197 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11202 /* We only recurse into c++ subprograms looking for template arguments.
11203 Skip their other children. */
11205 && cu
->language
== language_cplus
11206 && parent_die
!= NULL
11207 && parent_die
->tag
== DW_TAG_subprogram
)
11209 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11213 /* Check whether this DIE is interesting enough to save. Normally
11214 we would not be interested in members here, but there may be
11215 later variables referencing them via DW_AT_specification (for
11216 static members). */
11218 && !is_type_tag_for_partial (abbrev
->tag
)
11219 && abbrev
->tag
!= DW_TAG_constant
11220 && abbrev
->tag
!= DW_TAG_enumerator
11221 && abbrev
->tag
!= DW_TAG_subprogram
11222 && abbrev
->tag
!= DW_TAG_lexical_block
11223 && abbrev
->tag
!= DW_TAG_variable
11224 && abbrev
->tag
!= DW_TAG_namespace
11225 && abbrev
->tag
!= DW_TAG_module
11226 && abbrev
->tag
!= DW_TAG_member
11227 && abbrev
->tag
!= DW_TAG_imported_unit
)
11229 /* Otherwise we skip to the next sibling, if any. */
11230 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11234 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
11237 /* This two-pass algorithm for processing partial symbols has a
11238 high cost in cache pressure. Thus, handle some simple cases
11239 here which cover the majority of C partial symbols. DIEs
11240 which neither have specification tags in them, nor could have
11241 specification tags elsewhere pointing at them, can simply be
11242 processed and discarded.
11244 This segment is also optional; scan_partial_symbols and
11245 add_partial_symbol will handle these DIEs if we chain
11246 them in normally. When compilers which do not emit large
11247 quantities of duplicate debug information are more common,
11248 this code can probably be removed. */
11250 /* Any complete simple types at the top level (pretty much all
11251 of them, for a language without namespaces), can be processed
11253 if (parent_die
== NULL
11254 && part_die
->has_specification
== 0
11255 && part_die
->is_declaration
== 0
11256 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11257 || part_die
->tag
== DW_TAG_base_type
11258 || part_die
->tag
== DW_TAG_subrange_type
))
11260 if (building_psymtab
&& part_die
->name
!= NULL
)
11261 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11262 VAR_DOMAIN
, LOC_TYPEDEF
,
11263 &objfile
->static_psymbols
,
11264 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11265 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11269 /* The exception for DW_TAG_typedef with has_children above is
11270 a workaround of GCC PR debug/47510. In the case of this complaint
11271 type_name_no_tag_or_error will error on such types later.
11273 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11274 it could not find the child DIEs referenced later, this is checked
11275 above. In correct DWARF DW_TAG_typedef should have no children. */
11277 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11278 complaint (&symfile_complaints
,
11279 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11280 "- DIE at 0x%x [in module %s]"),
11281 part_die
->offset
.sect_off
, objfile
->name
);
11283 /* If we're at the second level, and we're an enumerator, and
11284 our parent has no specification (meaning possibly lives in a
11285 namespace elsewhere), then we can add the partial symbol now
11286 instead of queueing it. */
11287 if (part_die
->tag
== DW_TAG_enumerator
11288 && parent_die
!= NULL
11289 && parent_die
->die_parent
== NULL
11290 && parent_die
->tag
== DW_TAG_enumeration_type
11291 && parent_die
->has_specification
== 0)
11293 if (part_die
->name
== NULL
)
11294 complaint (&symfile_complaints
,
11295 _("malformed enumerator DIE ignored"));
11296 else if (building_psymtab
)
11297 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11298 VAR_DOMAIN
, LOC_CONST
,
11299 (cu
->language
== language_cplus
11300 || cu
->language
== language_java
)
11301 ? &objfile
->global_psymbols
11302 : &objfile
->static_psymbols
,
11303 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11305 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11309 /* We'll save this DIE so link it in. */
11310 part_die
->die_parent
= parent_die
;
11311 part_die
->die_sibling
= NULL
;
11312 part_die
->die_child
= NULL
;
11314 if (last_die
&& last_die
== parent_die
)
11315 last_die
->die_child
= part_die
;
11317 last_die
->die_sibling
= part_die
;
11319 last_die
= part_die
;
11321 if (first_die
== NULL
)
11322 first_die
= part_die
;
11324 /* Maybe add the DIE to the hash table. Not all DIEs that we
11325 find interesting need to be in the hash table, because we
11326 also have the parent/sibling/child chains; only those that we
11327 might refer to by offset later during partial symbol reading.
11329 For now this means things that might have be the target of a
11330 DW_AT_specification, DW_AT_abstract_origin, or
11331 DW_AT_extension. DW_AT_extension will refer only to
11332 namespaces; DW_AT_abstract_origin refers to functions (and
11333 many things under the function DIE, but we do not recurse
11334 into function DIEs during partial symbol reading) and
11335 possibly variables as well; DW_AT_specification refers to
11336 declarations. Declarations ought to have the DW_AT_declaration
11337 flag. It happens that GCC forgets to put it in sometimes, but
11338 only for functions, not for types.
11340 Adding more things than necessary to the hash table is harmless
11341 except for the performance cost. Adding too few will result in
11342 wasted time in find_partial_die, when we reread the compilation
11343 unit with load_all_dies set. */
11346 || abbrev
->tag
== DW_TAG_constant
11347 || abbrev
->tag
== DW_TAG_subprogram
11348 || abbrev
->tag
== DW_TAG_variable
11349 || abbrev
->tag
== DW_TAG_namespace
11350 || part_die
->is_declaration
)
11354 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11355 part_die
->offset
.sect_off
, INSERT
);
11359 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11360 sizeof (struct partial_die_info
));
11362 /* For some DIEs we want to follow their children (if any). For C
11363 we have no reason to follow the children of structures; for other
11364 languages we have to, so that we can get at method physnames
11365 to infer fully qualified class names, for DW_AT_specification,
11366 and for C++ template arguments. For C++, we also look one level
11367 inside functions to find template arguments (if the name of the
11368 function does not already contain the template arguments).
11370 For Ada, we need to scan the children of subprograms and lexical
11371 blocks as well because Ada allows the definition of nested
11372 entities that could be interesting for the debugger, such as
11373 nested subprograms for instance. */
11374 if (last_die
->has_children
11376 || last_die
->tag
== DW_TAG_namespace
11377 || last_die
->tag
== DW_TAG_module
11378 || last_die
->tag
== DW_TAG_enumeration_type
11379 || (cu
->language
== language_cplus
11380 && last_die
->tag
== DW_TAG_subprogram
11381 && (last_die
->name
== NULL
11382 || strchr (last_die
->name
, '<') == NULL
))
11383 || (cu
->language
!= language_c
11384 && (last_die
->tag
== DW_TAG_class_type
11385 || last_die
->tag
== DW_TAG_interface_type
11386 || last_die
->tag
== DW_TAG_structure_type
11387 || last_die
->tag
== DW_TAG_union_type
))
11388 || (cu
->language
== language_ada
11389 && (last_die
->tag
== DW_TAG_subprogram
11390 || last_die
->tag
== DW_TAG_lexical_block
))))
11393 parent_die
= last_die
;
11397 /* Otherwise we skip to the next sibling, if any. */
11398 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11400 /* Back to the top, do it again. */
11404 /* Read a minimal amount of information into the minimal die structure. */
11407 read_partial_die (const struct die_reader_specs
*reader
,
11408 struct partial_die_info
*part_die
,
11409 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11410 gdb_byte
*info_ptr
)
11412 struct dwarf2_cu
*cu
= reader
->cu
;
11413 struct objfile
*objfile
= cu
->objfile
;
11414 gdb_byte
*buffer
= reader
->buffer
;
11416 struct attribute attr
;
11417 int has_low_pc_attr
= 0;
11418 int has_high_pc_attr
= 0;
11419 int high_pc_relative
= 0;
11421 memset (part_die
, 0, sizeof (struct partial_die_info
));
11423 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11425 info_ptr
+= abbrev_len
;
11427 if (abbrev
== NULL
)
11430 part_die
->tag
= abbrev
->tag
;
11431 part_die
->has_children
= abbrev
->has_children
;
11433 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11435 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11437 /* Store the data if it is of an attribute we want to keep in a
11438 partial symbol table. */
11442 switch (part_die
->tag
)
11444 case DW_TAG_compile_unit
:
11445 case DW_TAG_partial_unit
:
11446 case DW_TAG_type_unit
:
11447 /* Compilation units have a DW_AT_name that is a filename, not
11448 a source language identifier. */
11449 case DW_TAG_enumeration_type
:
11450 case DW_TAG_enumerator
:
11451 /* These tags always have simple identifiers already; no need
11452 to canonicalize them. */
11453 part_die
->name
= DW_STRING (&attr
);
11457 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11458 &objfile
->objfile_obstack
);
11462 case DW_AT_linkage_name
:
11463 case DW_AT_MIPS_linkage_name
:
11464 /* Note that both forms of linkage name might appear. We
11465 assume they will be the same, and we only store the last
11467 if (cu
->language
== language_ada
)
11468 part_die
->name
= DW_STRING (&attr
);
11469 part_die
->linkage_name
= DW_STRING (&attr
);
11472 has_low_pc_attr
= 1;
11473 part_die
->lowpc
= DW_ADDR (&attr
);
11475 case DW_AT_high_pc
:
11476 has_high_pc_attr
= 1;
11477 if (attr
.form
== DW_FORM_addr
11478 || attr
.form
== DW_FORM_GNU_addr_index
)
11479 part_die
->highpc
= DW_ADDR (&attr
);
11482 high_pc_relative
= 1;
11483 part_die
->highpc
= DW_UNSND (&attr
);
11486 case DW_AT_location
:
11487 /* Support the .debug_loc offsets. */
11488 if (attr_form_is_block (&attr
))
11490 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11492 else if (attr_form_is_section_offset (&attr
))
11494 dwarf2_complex_location_expr_complaint ();
11498 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11499 "partial symbol information");
11502 case DW_AT_external
:
11503 part_die
->is_external
= DW_UNSND (&attr
);
11505 case DW_AT_declaration
:
11506 part_die
->is_declaration
= DW_UNSND (&attr
);
11509 part_die
->has_type
= 1;
11511 case DW_AT_abstract_origin
:
11512 case DW_AT_specification
:
11513 case DW_AT_extension
:
11514 part_die
->has_specification
= 1;
11515 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11517 case DW_AT_sibling
:
11518 /* Ignore absolute siblings, they might point outside of
11519 the current compile unit. */
11520 if (attr
.form
== DW_FORM_ref_addr
)
11521 complaint (&symfile_complaints
,
11522 _("ignoring absolute DW_AT_sibling"));
11524 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11526 case DW_AT_byte_size
:
11527 part_die
->has_byte_size
= 1;
11529 case DW_AT_calling_convention
:
11530 /* DWARF doesn't provide a way to identify a program's source-level
11531 entry point. DW_AT_calling_convention attributes are only meant
11532 to describe functions' calling conventions.
11534 However, because it's a necessary piece of information in
11535 Fortran, and because DW_CC_program is the only piece of debugging
11536 information whose definition refers to a 'main program' at all,
11537 several compilers have begun marking Fortran main programs with
11538 DW_CC_program --- even when those functions use the standard
11539 calling conventions.
11541 So until DWARF specifies a way to provide this information and
11542 compilers pick up the new representation, we'll support this
11544 if (DW_UNSND (&attr
) == DW_CC_program
11545 && cu
->language
== language_fortran
)
11547 set_main_name (part_die
->name
);
11549 /* As this DIE has a static linkage the name would be difficult
11550 to look up later. */
11551 language_of_main
= language_fortran
;
11555 if (DW_UNSND (&attr
) == DW_INL_inlined
11556 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11557 part_die
->may_be_inlined
= 1;
11561 if (part_die
->tag
== DW_TAG_imported_unit
)
11562 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11570 if (high_pc_relative
)
11571 part_die
->highpc
+= part_die
->lowpc
;
11573 if (has_low_pc_attr
&& has_high_pc_attr
)
11575 /* When using the GNU linker, .gnu.linkonce. sections are used to
11576 eliminate duplicate copies of functions and vtables and such.
11577 The linker will arbitrarily choose one and discard the others.
11578 The AT_*_pc values for such functions refer to local labels in
11579 these sections. If the section from that file was discarded, the
11580 labels are not in the output, so the relocs get a value of 0.
11581 If this is a discarded function, mark the pc bounds as invalid,
11582 so that GDB will ignore it. */
11583 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11585 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11587 complaint (&symfile_complaints
,
11588 _("DW_AT_low_pc %s is zero "
11589 "for DIE at 0x%x [in module %s]"),
11590 paddress (gdbarch
, part_die
->lowpc
),
11591 part_die
->offset
.sect_off
, objfile
->name
);
11593 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11594 else if (part_die
->lowpc
>= part_die
->highpc
)
11596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11598 complaint (&symfile_complaints
,
11599 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11600 "for DIE at 0x%x [in module %s]"),
11601 paddress (gdbarch
, part_die
->lowpc
),
11602 paddress (gdbarch
, part_die
->highpc
),
11603 part_die
->offset
.sect_off
, objfile
->name
);
11606 part_die
->has_pc_info
= 1;
11612 /* Find a cached partial DIE at OFFSET in CU. */
11614 static struct partial_die_info
*
11615 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11617 struct partial_die_info
*lookup_die
= NULL
;
11618 struct partial_die_info part_die
;
11620 part_die
.offset
= offset
;
11621 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11627 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11628 except in the case of .debug_types DIEs which do not reference
11629 outside their CU (they do however referencing other types via
11630 DW_FORM_ref_sig8). */
11632 static struct partial_die_info
*
11633 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11635 struct objfile
*objfile
= cu
->objfile
;
11636 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11637 struct partial_die_info
*pd
= NULL
;
11639 if (offset_in_cu_p (&cu
->header
, offset
))
11641 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11644 /* We missed recording what we needed.
11645 Load all dies and try again. */
11646 per_cu
= cu
->per_cu
;
11650 /* TUs don't reference other CUs/TUs (except via type signatures). */
11651 if (cu
->per_cu
->is_debug_types
)
11653 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11654 " external reference to offset 0x%lx [in module %s].\n"),
11655 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11656 bfd_get_filename (objfile
->obfd
));
11658 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11660 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11661 load_partial_comp_unit (per_cu
);
11663 per_cu
->cu
->last_used
= 0;
11664 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11667 /* If we didn't find it, and not all dies have been loaded,
11668 load them all and try again. */
11670 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11672 per_cu
->load_all_dies
= 1;
11674 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11675 THIS_CU->cu may already be in use. So we can't just free it and
11676 replace its DIEs with the ones we read in. Instead, we leave those
11677 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11678 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11680 load_partial_comp_unit (per_cu
);
11682 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11686 internal_error (__FILE__
, __LINE__
,
11687 _("could not find partial DIE 0x%x "
11688 "in cache [from module %s]\n"),
11689 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11693 /* See if we can figure out if the class lives in a namespace. We do
11694 this by looking for a member function; its demangled name will
11695 contain namespace info, if there is any. */
11698 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11699 struct dwarf2_cu
*cu
)
11701 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11702 what template types look like, because the demangler
11703 frequently doesn't give the same name as the debug info. We
11704 could fix this by only using the demangled name to get the
11705 prefix (but see comment in read_structure_type). */
11707 struct partial_die_info
*real_pdi
;
11708 struct partial_die_info
*child_pdi
;
11710 /* If this DIE (this DIE's specification, if any) has a parent, then
11711 we should not do this. We'll prepend the parent's fully qualified
11712 name when we create the partial symbol. */
11714 real_pdi
= struct_pdi
;
11715 while (real_pdi
->has_specification
)
11716 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11718 if (real_pdi
->die_parent
!= NULL
)
11721 for (child_pdi
= struct_pdi
->die_child
;
11723 child_pdi
= child_pdi
->die_sibling
)
11725 if (child_pdi
->tag
== DW_TAG_subprogram
11726 && child_pdi
->linkage_name
!= NULL
)
11728 char *actual_class_name
11729 = language_class_name_from_physname (cu
->language_defn
,
11730 child_pdi
->linkage_name
);
11731 if (actual_class_name
!= NULL
)
11734 = obsavestring (actual_class_name
,
11735 strlen (actual_class_name
),
11736 &cu
->objfile
->objfile_obstack
);
11737 xfree (actual_class_name
);
11744 /* Adjust PART_DIE before generating a symbol for it. This function
11745 may set the is_external flag or change the DIE's name. */
11748 fixup_partial_die (struct partial_die_info
*part_die
,
11749 struct dwarf2_cu
*cu
)
11751 /* Once we've fixed up a die, there's no point in doing so again.
11752 This also avoids a memory leak if we were to call
11753 guess_partial_die_structure_name multiple times. */
11754 if (part_die
->fixup_called
)
11757 /* If we found a reference attribute and the DIE has no name, try
11758 to find a name in the referred to DIE. */
11760 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11762 struct partial_die_info
*spec_die
;
11764 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11766 fixup_partial_die (spec_die
, cu
);
11768 if (spec_die
->name
)
11770 part_die
->name
= spec_die
->name
;
11772 /* Copy DW_AT_external attribute if it is set. */
11773 if (spec_die
->is_external
)
11774 part_die
->is_external
= spec_die
->is_external
;
11778 /* Set default names for some unnamed DIEs. */
11780 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11781 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11783 /* If there is no parent die to provide a namespace, and there are
11784 children, see if we can determine the namespace from their linkage
11786 if (cu
->language
== language_cplus
11787 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11788 && part_die
->die_parent
== NULL
11789 && part_die
->has_children
11790 && (part_die
->tag
== DW_TAG_class_type
11791 || part_die
->tag
== DW_TAG_structure_type
11792 || part_die
->tag
== DW_TAG_union_type
))
11793 guess_partial_die_structure_name (part_die
, cu
);
11795 /* GCC might emit a nameless struct or union that has a linkage
11796 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11797 if (part_die
->name
== NULL
11798 && (part_die
->tag
== DW_TAG_class_type
11799 || part_die
->tag
== DW_TAG_interface_type
11800 || part_die
->tag
== DW_TAG_structure_type
11801 || part_die
->tag
== DW_TAG_union_type
)
11802 && part_die
->linkage_name
!= NULL
)
11806 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11811 /* Strip any leading namespaces/classes, keep only the base name.
11812 DW_AT_name for named DIEs does not contain the prefixes. */
11813 base
= strrchr (demangled
, ':');
11814 if (base
&& base
> demangled
&& base
[-1] == ':')
11819 part_die
->name
= obsavestring (base
, strlen (base
),
11820 &cu
->objfile
->objfile_obstack
);
11825 part_die
->fixup_called
= 1;
11828 /* Read an attribute value described by an attribute form. */
11831 read_attribute_value (const struct die_reader_specs
*reader
,
11832 struct attribute
*attr
, unsigned form
,
11833 gdb_byte
*info_ptr
)
11835 struct dwarf2_cu
*cu
= reader
->cu
;
11836 bfd
*abfd
= reader
->abfd
;
11837 struct comp_unit_head
*cu_header
= &cu
->header
;
11838 unsigned int bytes_read
;
11839 struct dwarf_block
*blk
;
11844 case DW_FORM_ref_addr
:
11845 if (cu
->header
.version
== 2)
11846 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11848 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
11849 &cu
->header
, &bytes_read
);
11850 info_ptr
+= bytes_read
;
11853 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
11854 info_ptr
+= bytes_read
;
11856 case DW_FORM_block2
:
11857 blk
= dwarf_alloc_block (cu
);
11858 blk
->size
= read_2_bytes (abfd
, info_ptr
);
11860 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11861 info_ptr
+= blk
->size
;
11862 DW_BLOCK (attr
) = blk
;
11864 case DW_FORM_block4
:
11865 blk
= dwarf_alloc_block (cu
);
11866 blk
->size
= read_4_bytes (abfd
, info_ptr
);
11868 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11869 info_ptr
+= blk
->size
;
11870 DW_BLOCK (attr
) = blk
;
11872 case DW_FORM_data2
:
11873 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
11876 case DW_FORM_data4
:
11877 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
11880 case DW_FORM_data8
:
11881 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
11884 case DW_FORM_sec_offset
:
11885 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
11886 info_ptr
+= bytes_read
;
11888 case DW_FORM_string
:
11889 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
11890 DW_STRING_IS_CANONICAL (attr
) = 0;
11891 info_ptr
+= bytes_read
;
11894 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
11896 DW_STRING_IS_CANONICAL (attr
) = 0;
11897 info_ptr
+= bytes_read
;
11899 case DW_FORM_exprloc
:
11900 case DW_FORM_block
:
11901 blk
= dwarf_alloc_block (cu
);
11902 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11903 info_ptr
+= bytes_read
;
11904 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11905 info_ptr
+= blk
->size
;
11906 DW_BLOCK (attr
) = blk
;
11908 case DW_FORM_block1
:
11909 blk
= dwarf_alloc_block (cu
);
11910 blk
->size
= read_1_byte (abfd
, info_ptr
);
11912 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
11913 info_ptr
+= blk
->size
;
11914 DW_BLOCK (attr
) = blk
;
11916 case DW_FORM_data1
:
11917 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11921 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
11924 case DW_FORM_flag_present
:
11925 DW_UNSND (attr
) = 1;
11927 case DW_FORM_sdata
:
11928 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
11929 info_ptr
+= bytes_read
;
11931 case DW_FORM_udata
:
11932 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11933 info_ptr
+= bytes_read
;
11936 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11937 + read_1_byte (abfd
, info_ptr
));
11941 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11942 + read_2_bytes (abfd
, info_ptr
));
11946 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11947 + read_4_bytes (abfd
, info_ptr
));
11951 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11952 + read_8_bytes (abfd
, info_ptr
));
11955 case DW_FORM_ref_sig8
:
11956 /* Convert the signature to something we can record in DW_UNSND
11958 NOTE: This is NULL if the type wasn't found. */
11959 DW_SIGNATURED_TYPE (attr
) =
11960 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
11963 case DW_FORM_ref_udata
:
11964 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
11965 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
11966 info_ptr
+= bytes_read
;
11968 case DW_FORM_indirect
:
11969 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11970 info_ptr
+= bytes_read
;
11971 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
11973 case DW_FORM_GNU_addr_index
:
11974 if (reader
->dwo_file
== NULL
)
11976 /* For now flag a hard error.
11977 Later we can turn this into a complaint. */
11978 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11979 dwarf_form_name (form
),
11980 bfd_get_filename (abfd
));
11982 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
11983 info_ptr
+= bytes_read
;
11985 case DW_FORM_GNU_str_index
:
11986 if (reader
->dwo_file
== NULL
)
11988 /* For now flag a hard error.
11989 Later we can turn this into a complaint if warranted. */
11990 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
11991 dwarf_form_name (form
),
11992 bfd_get_filename (abfd
));
11995 ULONGEST str_index
=
11996 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11998 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
11999 DW_STRING_IS_CANONICAL (attr
) = 0;
12000 info_ptr
+= bytes_read
;
12004 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
12005 dwarf_form_name (form
),
12006 bfd_get_filename (abfd
));
12009 /* We have seen instances where the compiler tried to emit a byte
12010 size attribute of -1 which ended up being encoded as an unsigned
12011 0xffffffff. Although 0xffffffff is technically a valid size value,
12012 an object of this size seems pretty unlikely so we can relatively
12013 safely treat these cases as if the size attribute was invalid and
12014 treat them as zero by default. */
12015 if (attr
->name
== DW_AT_byte_size
12016 && form
== DW_FORM_data4
12017 && DW_UNSND (attr
) >= 0xffffffff)
12020 (&symfile_complaints
,
12021 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12022 hex_string (DW_UNSND (attr
)));
12023 DW_UNSND (attr
) = 0;
12029 /* Read an attribute described by an abbreviated attribute. */
12032 read_attribute (const struct die_reader_specs
*reader
,
12033 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12034 gdb_byte
*info_ptr
)
12036 attr
->name
= abbrev
->name
;
12037 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
12040 /* Read dwarf information from a buffer. */
12042 static unsigned int
12043 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
12045 return bfd_get_8 (abfd
, buf
);
12049 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
12051 return bfd_get_signed_8 (abfd
, buf
);
12054 static unsigned int
12055 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
12057 return bfd_get_16 (abfd
, buf
);
12061 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12063 return bfd_get_signed_16 (abfd
, buf
);
12066 static unsigned int
12067 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
12069 return bfd_get_32 (abfd
, buf
);
12073 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12075 return bfd_get_signed_32 (abfd
, buf
);
12079 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12081 return bfd_get_64 (abfd
, buf
);
12085 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12086 unsigned int *bytes_read
)
12088 struct comp_unit_head
*cu_header
= &cu
->header
;
12089 CORE_ADDR retval
= 0;
12091 if (cu_header
->signed_addr_p
)
12093 switch (cu_header
->addr_size
)
12096 retval
= bfd_get_signed_16 (abfd
, buf
);
12099 retval
= bfd_get_signed_32 (abfd
, buf
);
12102 retval
= bfd_get_signed_64 (abfd
, buf
);
12105 internal_error (__FILE__
, __LINE__
,
12106 _("read_address: bad switch, signed [in module %s]"),
12107 bfd_get_filename (abfd
));
12112 switch (cu_header
->addr_size
)
12115 retval
= bfd_get_16 (abfd
, buf
);
12118 retval
= bfd_get_32 (abfd
, buf
);
12121 retval
= bfd_get_64 (abfd
, buf
);
12124 internal_error (__FILE__
, __LINE__
,
12125 _("read_address: bad switch, "
12126 "unsigned [in module %s]"),
12127 bfd_get_filename (abfd
));
12131 *bytes_read
= cu_header
->addr_size
;
12135 /* Read the initial length from a section. The (draft) DWARF 3
12136 specification allows the initial length to take up either 4 bytes
12137 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
12138 bytes describe the length and all offsets will be 8 bytes in length
12141 An older, non-standard 64-bit format is also handled by this
12142 function. The older format in question stores the initial length
12143 as an 8-byte quantity without an escape value. Lengths greater
12144 than 2^32 aren't very common which means that the initial 4 bytes
12145 is almost always zero. Since a length value of zero doesn't make
12146 sense for the 32-bit format, this initial zero can be considered to
12147 be an escape value which indicates the presence of the older 64-bit
12148 format. As written, the code can't detect (old format) lengths
12149 greater than 4GB. If it becomes necessary to handle lengths
12150 somewhat larger than 4GB, we could allow other small values (such
12151 as the non-sensical values of 1, 2, and 3) to also be used as
12152 escape values indicating the presence of the old format.
12154 The value returned via bytes_read should be used to increment the
12155 relevant pointer after calling read_initial_length().
12157 [ Note: read_initial_length() and read_offset() are based on the
12158 document entitled "DWARF Debugging Information Format", revision
12159 3, draft 8, dated November 19, 2001. This document was obtained
12162 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
12164 This document is only a draft and is subject to change. (So beware.)
12166 Details regarding the older, non-standard 64-bit format were
12167 determined empirically by examining 64-bit ELF files produced by
12168 the SGI toolchain on an IRIX 6.5 machine.
12170 - Kevin, July 16, 2002
12174 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
12176 LONGEST length
= bfd_get_32 (abfd
, buf
);
12178 if (length
== 0xffffffff)
12180 length
= bfd_get_64 (abfd
, buf
+ 4);
12183 else if (length
== 0)
12185 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
12186 length
= bfd_get_64 (abfd
, buf
);
12197 /* Cover function for read_initial_length.
12198 Returns the length of the object at BUF, and stores the size of the
12199 initial length in *BYTES_READ and stores the size that offsets will be in
12201 If the initial length size is not equivalent to that specified in
12202 CU_HEADER then issue a complaint.
12203 This is useful when reading non-comp-unit headers. */
12206 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
12207 const struct comp_unit_head
*cu_header
,
12208 unsigned int *bytes_read
,
12209 unsigned int *offset_size
)
12211 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
12213 gdb_assert (cu_header
->initial_length_size
== 4
12214 || cu_header
->initial_length_size
== 8
12215 || cu_header
->initial_length_size
== 12);
12217 if (cu_header
->initial_length_size
!= *bytes_read
)
12218 complaint (&symfile_complaints
,
12219 _("intermixed 32-bit and 64-bit DWARF sections"));
12221 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
12225 /* Read an offset from the data stream. The size of the offset is
12226 given by cu_header->offset_size. */
12229 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
12230 unsigned int *bytes_read
)
12232 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
12234 *bytes_read
= cu_header
->offset_size
;
12238 /* Read an offset from the data stream. */
12241 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
12243 LONGEST retval
= 0;
12245 switch (offset_size
)
12248 retval
= bfd_get_32 (abfd
, buf
);
12251 retval
= bfd_get_64 (abfd
, buf
);
12254 internal_error (__FILE__
, __LINE__
,
12255 _("read_offset_1: bad switch [in module %s]"),
12256 bfd_get_filename (abfd
));
12263 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12265 /* If the size of a host char is 8 bits, we can return a pointer
12266 to the buffer, otherwise we have to copy the data to a buffer
12267 allocated on the temporary obstack. */
12268 gdb_assert (HOST_CHAR_BIT
== 8);
12273 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12275 /* If the size of a host char is 8 bits, we can return a pointer
12276 to the string, otherwise we have to copy the string to a buffer
12277 allocated on the temporary obstack. */
12278 gdb_assert (HOST_CHAR_BIT
== 8);
12281 *bytes_read_ptr
= 1;
12284 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12285 return (char *) buf
;
12289 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12291 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12292 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12293 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12294 bfd_get_filename (abfd
));
12295 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12296 error (_("DW_FORM_strp pointing outside of "
12297 ".debug_str section [in module %s]"),
12298 bfd_get_filename (abfd
));
12299 gdb_assert (HOST_CHAR_BIT
== 8);
12300 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12302 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12306 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12307 const struct comp_unit_head
*cu_header
,
12308 unsigned int *bytes_read_ptr
)
12310 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12312 return read_indirect_string_at_offset (abfd
, str_offset
);
12316 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12319 unsigned int num_read
;
12321 unsigned char byte
;
12329 byte
= bfd_get_8 (abfd
, buf
);
12332 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12333 if ((byte
& 128) == 0)
12339 *bytes_read_ptr
= num_read
;
12344 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12347 int i
, shift
, num_read
;
12348 unsigned char byte
;
12356 byte
= bfd_get_8 (abfd
, buf
);
12359 result
|= ((LONGEST
) (byte
& 127) << shift
);
12361 if ((byte
& 128) == 0)
12366 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12367 result
|= -(((LONGEST
) 1) << shift
);
12368 *bytes_read_ptr
= num_read
;
12372 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12373 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12374 ADDR_SIZE is the size of addresses from the CU header. */
12377 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12379 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12380 bfd
*abfd
= objfile
->obfd
;
12381 const gdb_byte
*info_ptr
;
12383 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12384 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12385 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12387 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12388 error (_("DW_FORM_addr_index pointing outside of "
12389 ".debug_addr section [in module %s]"),
12391 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12392 + addr_base
+ addr_index
* addr_size
);
12393 if (addr_size
== 4)
12394 return bfd_get_32 (abfd
, info_ptr
);
12396 return bfd_get_64 (abfd
, info_ptr
);
12399 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12402 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12404 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12407 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12410 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12411 unsigned int *bytes_read
)
12413 bfd
*abfd
= cu
->objfile
->obfd
;
12414 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12416 return read_addr_index (cu
, addr_index
);
12419 /* Data structure to pass results from dwarf2_read_addr_index_reader
12420 back to dwarf2_read_addr_index. */
12422 struct dwarf2_read_addr_index_data
12424 ULONGEST addr_base
;
12428 /* die_reader_func for dwarf2_read_addr_index. */
12431 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12432 gdb_byte
*info_ptr
,
12433 struct die_info
*comp_unit_die
,
12437 struct dwarf2_cu
*cu
= reader
->cu
;
12438 struct dwarf2_read_addr_index_data
*aidata
=
12439 (struct dwarf2_read_addr_index_data
*) data
;
12441 aidata
->addr_base
= cu
->addr_base
;
12442 aidata
->addr_size
= cu
->header
.addr_size
;
12445 /* Given an index in .debug_addr, fetch the value.
12446 NOTE: This can be called during dwarf expression evaluation,
12447 long after the debug information has been read, and thus per_cu->cu
12448 may no longer exist. */
12451 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12452 unsigned int addr_index
)
12454 struct objfile
*objfile
= per_cu
->objfile
;
12455 struct dwarf2_cu
*cu
= per_cu
->cu
;
12456 ULONGEST addr_base
;
12459 /* This is intended to be called from outside this file. */
12460 dw2_setup (objfile
);
12462 /* We need addr_base and addr_size.
12463 If we don't have PER_CU->cu, we have to get it.
12464 Nasty, but the alternative is storing the needed info in PER_CU,
12465 which at this point doesn't seem justified: it's not clear how frequently
12466 it would get used and it would increase the size of every PER_CU.
12467 Entry points like dwarf2_per_cu_addr_size do a similar thing
12468 so we're not in uncharted territory here.
12469 Alas we need to be a bit more complicated as addr_base is contained
12472 We don't need to read the entire CU(/TU).
12473 We just need the header and top level die.
12474 IWBN to use the aging mechanism to let us lazily later discard the CU.
12475 See however init_cutu_and_read_dies_simple. */
12479 addr_base
= cu
->addr_base
;
12480 addr_size
= cu
->header
.addr_size
;
12484 struct dwarf2_read_addr_index_data aidata
;
12486 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12488 addr_base
= aidata
.addr_base
;
12489 addr_size
= aidata
.addr_size
;
12492 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12495 /* Given a DW_AT_str_index, fetch the string. */
12498 read_str_index (const struct die_reader_specs
*reader
,
12499 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12501 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12502 const char *dwo_name
= objfile
->name
;
12503 bfd
*abfd
= objfile
->obfd
;
12504 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12505 gdb_byte
*info_ptr
;
12506 ULONGEST str_offset
;
12508 dwarf2_read_section (objfile
, §ions
->str
);
12509 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12510 if (sections
->str
.buffer
== NULL
)
12511 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12512 " in CU at offset 0x%lx [in module %s]"),
12513 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12514 if (sections
->str_offsets
.buffer
== NULL
)
12515 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12516 " in CU at offset 0x%lx [in module %s]"),
12517 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12518 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12519 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12520 " section in CU at offset 0x%lx [in module %s]"),
12521 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12522 info_ptr
= (sections
->str_offsets
.buffer
12523 + str_index
* cu
->header
.offset_size
);
12524 if (cu
->header
.offset_size
== 4)
12525 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12527 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12528 if (str_offset
>= sections
->str
.size
)
12529 error (_("Offset from DW_FORM_str_index pointing outside of"
12530 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12531 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12532 return (char *) (sections
->str
.buffer
+ str_offset
);
12535 /* Return the length of an LEB128 number in BUF. */
12538 leb128_size (const gdb_byte
*buf
)
12540 const gdb_byte
*begin
= buf
;
12546 if ((byte
& 128) == 0)
12547 return buf
- begin
;
12552 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12559 cu
->language
= language_c
;
12561 case DW_LANG_C_plus_plus
:
12562 cu
->language
= language_cplus
;
12565 cu
->language
= language_d
;
12567 case DW_LANG_Fortran77
:
12568 case DW_LANG_Fortran90
:
12569 case DW_LANG_Fortran95
:
12570 cu
->language
= language_fortran
;
12573 cu
->language
= language_go
;
12575 case DW_LANG_Mips_Assembler
:
12576 cu
->language
= language_asm
;
12579 cu
->language
= language_java
;
12581 case DW_LANG_Ada83
:
12582 case DW_LANG_Ada95
:
12583 cu
->language
= language_ada
;
12585 case DW_LANG_Modula2
:
12586 cu
->language
= language_m2
;
12588 case DW_LANG_Pascal83
:
12589 cu
->language
= language_pascal
;
12592 cu
->language
= language_objc
;
12594 case DW_LANG_Cobol74
:
12595 case DW_LANG_Cobol85
:
12597 cu
->language
= language_minimal
;
12600 cu
->language_defn
= language_def (cu
->language
);
12603 /* Return the named attribute or NULL if not there. */
12605 static struct attribute
*
12606 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12611 struct attribute
*spec
= NULL
;
12613 for (i
= 0; i
< die
->num_attrs
; ++i
)
12615 if (die
->attrs
[i
].name
== name
)
12616 return &die
->attrs
[i
];
12617 if (die
->attrs
[i
].name
== DW_AT_specification
12618 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12619 spec
= &die
->attrs
[i
];
12625 die
= follow_die_ref (die
, spec
, &cu
);
12631 /* Return the named attribute or NULL if not there,
12632 but do not follow DW_AT_specification, etc.
12633 This is for use in contexts where we're reading .debug_types dies.
12634 Following DW_AT_specification, DW_AT_abstract_origin will take us
12635 back up the chain, and we want to go down. */
12637 static struct attribute
*
12638 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12639 struct dwarf2_cu
*cu
)
12643 for (i
= 0; i
< die
->num_attrs
; ++i
)
12644 if (die
->attrs
[i
].name
== name
)
12645 return &die
->attrs
[i
];
12650 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12651 and holds a non-zero value. This function should only be used for
12652 DW_FORM_flag or DW_FORM_flag_present attributes. */
12655 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12657 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12659 return (attr
&& DW_UNSND (attr
));
12663 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12665 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12666 which value is non-zero. However, we have to be careful with
12667 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12668 (via dwarf2_flag_true_p) follows this attribute. So we may
12669 end up accidently finding a declaration attribute that belongs
12670 to a different DIE referenced by the specification attribute,
12671 even though the given DIE does not have a declaration attribute. */
12672 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12673 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12676 /* Return the die giving the specification for DIE, if there is
12677 one. *SPEC_CU is the CU containing DIE on input, and the CU
12678 containing the return value on output. If there is no
12679 specification, but there is an abstract origin, that is
12682 static struct die_info
*
12683 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12685 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12688 if (spec_attr
== NULL
)
12689 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12691 if (spec_attr
== NULL
)
12694 return follow_die_ref (die
, spec_attr
, spec_cu
);
12697 /* Free the line_header structure *LH, and any arrays and strings it
12699 NOTE: This is also used as a "cleanup" function. */
12702 free_line_header (struct line_header
*lh
)
12704 if (lh
->standard_opcode_lengths
)
12705 xfree (lh
->standard_opcode_lengths
);
12707 /* Remember that all the lh->file_names[i].name pointers are
12708 pointers into debug_line_buffer, and don't need to be freed. */
12709 if (lh
->file_names
)
12710 xfree (lh
->file_names
);
12712 /* Similarly for the include directory names. */
12713 if (lh
->include_dirs
)
12714 xfree (lh
->include_dirs
);
12719 /* Add an entry to LH's include directory table. */
12722 add_include_dir (struct line_header
*lh
, char *include_dir
)
12724 /* Grow the array if necessary. */
12725 if (lh
->include_dirs_size
== 0)
12727 lh
->include_dirs_size
= 1; /* for testing */
12728 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12729 * sizeof (*lh
->include_dirs
));
12731 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12733 lh
->include_dirs_size
*= 2;
12734 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12735 (lh
->include_dirs_size
12736 * sizeof (*lh
->include_dirs
)));
12739 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12742 /* Add an entry to LH's file name table. */
12745 add_file_name (struct line_header
*lh
,
12747 unsigned int dir_index
,
12748 unsigned int mod_time
,
12749 unsigned int length
)
12751 struct file_entry
*fe
;
12753 /* Grow the array if necessary. */
12754 if (lh
->file_names_size
== 0)
12756 lh
->file_names_size
= 1; /* for testing */
12757 lh
->file_names
= xmalloc (lh
->file_names_size
12758 * sizeof (*lh
->file_names
));
12760 else if (lh
->num_file_names
>= lh
->file_names_size
)
12762 lh
->file_names_size
*= 2;
12763 lh
->file_names
= xrealloc (lh
->file_names
,
12764 (lh
->file_names_size
12765 * sizeof (*lh
->file_names
)));
12768 fe
= &lh
->file_names
[lh
->num_file_names
++];
12770 fe
->dir_index
= dir_index
;
12771 fe
->mod_time
= mod_time
;
12772 fe
->length
= length
;
12773 fe
->included_p
= 0;
12777 /* Read the statement program header starting at OFFSET in
12778 .debug_line, or .debug_line.dwo. Return a pointer
12779 to a struct line_header, allocated using xmalloc.
12781 NOTE: the strings in the include directory and file name tables of
12782 the returned object point into the dwarf line section buffer,
12783 and must not be freed. */
12785 static struct line_header
*
12786 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12788 struct cleanup
*back_to
;
12789 struct line_header
*lh
;
12790 gdb_byte
*line_ptr
;
12791 unsigned int bytes_read
, offset_size
;
12793 char *cur_dir
, *cur_file
;
12794 struct dwarf2_section_info
*section
;
12797 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12799 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12800 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12802 section
= &dwarf2_per_objfile
->line
;
12804 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12805 if (section
->buffer
== NULL
)
12807 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12808 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12810 complaint (&symfile_complaints
, _("missing .debug_line section"));
12814 /* We can't do this until we know the section is non-empty.
12815 Only then do we know we have such a section. */
12816 abfd
= section
->asection
->owner
;
12818 /* Make sure that at least there's room for the total_length field.
12819 That could be 12 bytes long, but we're just going to fudge that. */
12820 if (offset
+ 4 >= section
->size
)
12822 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12826 lh
= xmalloc (sizeof (*lh
));
12827 memset (lh
, 0, sizeof (*lh
));
12828 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
12831 line_ptr
= section
->buffer
+ offset
;
12833 /* Read in the header. */
12835 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
12836 &bytes_read
, &offset_size
);
12837 line_ptr
+= bytes_read
;
12838 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
12840 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12843 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
12844 lh
->version
= read_2_bytes (abfd
, line_ptr
);
12846 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
12847 line_ptr
+= offset_size
;
12848 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
12850 if (lh
->version
>= 4)
12852 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
12856 lh
->maximum_ops_per_instruction
= 1;
12858 if (lh
->maximum_ops_per_instruction
== 0)
12860 lh
->maximum_ops_per_instruction
= 1;
12861 complaint (&symfile_complaints
,
12862 _("invalid maximum_ops_per_instruction "
12863 "in `.debug_line' section"));
12866 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
12868 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
12870 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
12872 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
12874 lh
->standard_opcode_lengths
12875 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
12877 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
12878 for (i
= 1; i
< lh
->opcode_base
; ++i
)
12880 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
12884 /* Read directory table. */
12885 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12887 line_ptr
+= bytes_read
;
12888 add_include_dir (lh
, cur_dir
);
12890 line_ptr
+= bytes_read
;
12892 /* Read file name table. */
12893 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
12895 unsigned int dir_index
, mod_time
, length
;
12897 line_ptr
+= bytes_read
;
12898 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12899 line_ptr
+= bytes_read
;
12900 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12901 line_ptr
+= bytes_read
;
12902 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
12903 line_ptr
+= bytes_read
;
12905 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
12907 line_ptr
+= bytes_read
;
12908 lh
->statement_program_start
= line_ptr
;
12910 if (line_ptr
> (section
->buffer
+ section
->size
))
12911 complaint (&symfile_complaints
,
12912 _("line number info header doesn't "
12913 "fit in `.debug_line' section"));
12915 discard_cleanups (back_to
);
12919 /* Subroutine of dwarf_decode_lines to simplify it.
12920 Return the file name of the psymtab for included file FILE_INDEX
12921 in line header LH of PST.
12922 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
12923 If space for the result is malloc'd, it will be freed by a cleanup.
12924 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
12927 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
12928 const struct partial_symtab
*pst
,
12929 const char *comp_dir
)
12931 const struct file_entry fe
= lh
->file_names
[file_index
];
12932 char *include_name
= fe
.name
;
12933 char *include_name_to_compare
= include_name
;
12934 char *dir_name
= NULL
;
12935 const char *pst_filename
;
12936 char *copied_name
= NULL
;
12940 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
12942 if (!IS_ABSOLUTE_PATH (include_name
)
12943 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
12945 /* Avoid creating a duplicate psymtab for PST.
12946 We do this by comparing INCLUDE_NAME and PST_FILENAME.
12947 Before we do the comparison, however, we need to account
12948 for DIR_NAME and COMP_DIR.
12949 First prepend dir_name (if non-NULL). If we still don't
12950 have an absolute path prepend comp_dir (if non-NULL).
12951 However, the directory we record in the include-file's
12952 psymtab does not contain COMP_DIR (to match the
12953 corresponding symtab(s)).
12958 bash$ gcc -g ./hello.c
12959 include_name = "hello.c"
12961 DW_AT_comp_dir = comp_dir = "/tmp"
12962 DW_AT_name = "./hello.c" */
12964 if (dir_name
!= NULL
)
12966 include_name
= concat (dir_name
, SLASH_STRING
,
12967 include_name
, (char *)NULL
);
12968 include_name_to_compare
= include_name
;
12969 make_cleanup (xfree
, include_name
);
12971 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
12973 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
12974 include_name
, (char *)NULL
);
12978 pst_filename
= pst
->filename
;
12979 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
12981 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
12982 pst_filename
, (char *)NULL
);
12983 pst_filename
= copied_name
;
12986 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
12988 if (include_name_to_compare
!= include_name
)
12989 xfree (include_name_to_compare
);
12990 if (copied_name
!= NULL
)
12991 xfree (copied_name
);
12995 return include_name
;
12998 /* Ignore this record_line request. */
13001 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13006 /* Subroutine of dwarf_decode_lines to simplify it.
13007 Process the line number information in LH. */
13010 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13011 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13013 gdb_byte
*line_ptr
, *extended_end
;
13014 gdb_byte
*line_end
;
13015 unsigned int bytes_read
, extended_len
;
13016 unsigned char op_code
, extended_op
, adj_opcode
;
13017 CORE_ADDR baseaddr
;
13018 struct objfile
*objfile
= cu
->objfile
;
13019 bfd
*abfd
= objfile
->obfd
;
13020 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13021 const int decode_for_pst_p
= (pst
!= NULL
);
13022 struct subfile
*last_subfile
= NULL
;
13023 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13026 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13028 line_ptr
= lh
->statement_program_start
;
13029 line_end
= lh
->statement_program_end
;
13031 /* Read the statement sequences until there's nothing left. */
13032 while (line_ptr
< line_end
)
13034 /* state machine registers */
13035 CORE_ADDR address
= 0;
13036 unsigned int file
= 1;
13037 unsigned int line
= 1;
13038 unsigned int column
= 0;
13039 int is_stmt
= lh
->default_is_stmt
;
13040 int basic_block
= 0;
13041 int end_sequence
= 0;
13043 unsigned char op_index
= 0;
13045 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
13047 /* Start a subfile for the current file of the state machine. */
13048 /* lh->include_dirs and lh->file_names are 0-based, but the
13049 directory and file name numbers in the statement program
13051 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13055 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13057 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13060 /* Decode the table. */
13061 while (!end_sequence
)
13063 op_code
= read_1_byte (abfd
, line_ptr
);
13065 if (line_ptr
> line_end
)
13067 dwarf2_debug_line_missing_end_sequence_complaint ();
13071 if (op_code
>= lh
->opcode_base
)
13073 /* Special operand. */
13074 adj_opcode
= op_code
- lh
->opcode_base
;
13075 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13076 / lh
->maximum_ops_per_instruction
)
13077 * lh
->minimum_instruction_length
);
13078 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13079 % lh
->maximum_ops_per_instruction
);
13080 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13081 if (lh
->num_file_names
< file
|| file
== 0)
13082 dwarf2_debug_line_missing_file_complaint ();
13083 /* For now we ignore lines not starting on an
13084 instruction boundary. */
13085 else if (op_index
== 0)
13087 lh
->file_names
[file
- 1].included_p
= 1;
13088 if (!decode_for_pst_p
&& is_stmt
)
13090 if (last_subfile
!= current_subfile
)
13092 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13094 (*p_record_line
) (last_subfile
, 0, addr
);
13095 last_subfile
= current_subfile
;
13097 /* Append row to matrix using current values. */
13098 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13099 (*p_record_line
) (current_subfile
, line
, addr
);
13104 else switch (op_code
)
13106 case DW_LNS_extended_op
:
13107 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13109 line_ptr
+= bytes_read
;
13110 extended_end
= line_ptr
+ extended_len
;
13111 extended_op
= read_1_byte (abfd
, line_ptr
);
13113 switch (extended_op
)
13115 case DW_LNE_end_sequence
:
13116 p_record_line
= record_line
;
13119 case DW_LNE_set_address
:
13120 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
13122 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13124 /* This line table is for a function which has been
13125 GCd by the linker. Ignore it. PR gdb/12528 */
13128 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
13130 complaint (&symfile_complaints
,
13131 _(".debug_line address at offset 0x%lx is 0 "
13133 line_offset
, objfile
->name
);
13134 p_record_line
= noop_record_line
;
13138 line_ptr
+= bytes_read
;
13139 address
+= baseaddr
;
13141 case DW_LNE_define_file
:
13144 unsigned int dir_index
, mod_time
, length
;
13146 cur_file
= read_direct_string (abfd
, line_ptr
,
13148 line_ptr
+= bytes_read
;
13150 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13151 line_ptr
+= bytes_read
;
13153 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13154 line_ptr
+= bytes_read
;
13156 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13157 line_ptr
+= bytes_read
;
13158 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13161 case DW_LNE_set_discriminator
:
13162 /* The discriminator is not interesting to the debugger;
13164 line_ptr
= extended_end
;
13167 complaint (&symfile_complaints
,
13168 _("mangled .debug_line section"));
13171 /* Make sure that we parsed the extended op correctly. If e.g.
13172 we expected a different address size than the producer used,
13173 we may have read the wrong number of bytes. */
13174 if (line_ptr
!= extended_end
)
13176 complaint (&symfile_complaints
,
13177 _("mangled .debug_line section"));
13182 if (lh
->num_file_names
< file
|| file
== 0)
13183 dwarf2_debug_line_missing_file_complaint ();
13186 lh
->file_names
[file
- 1].included_p
= 1;
13187 if (!decode_for_pst_p
&& is_stmt
)
13189 if (last_subfile
!= current_subfile
)
13191 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13193 (*p_record_line
) (last_subfile
, 0, addr
);
13194 last_subfile
= current_subfile
;
13196 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13197 (*p_record_line
) (current_subfile
, line
, addr
);
13202 case DW_LNS_advance_pc
:
13205 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13207 address
+= (((op_index
+ adjust
)
13208 / lh
->maximum_ops_per_instruction
)
13209 * lh
->minimum_instruction_length
);
13210 op_index
= ((op_index
+ adjust
)
13211 % lh
->maximum_ops_per_instruction
);
13212 line_ptr
+= bytes_read
;
13215 case DW_LNS_advance_line
:
13216 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
13217 line_ptr
+= bytes_read
;
13219 case DW_LNS_set_file
:
13221 /* The arrays lh->include_dirs and lh->file_names are
13222 0-based, but the directory and file name numbers in
13223 the statement program are 1-based. */
13224 struct file_entry
*fe
;
13227 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13228 line_ptr
+= bytes_read
;
13229 if (lh
->num_file_names
< file
|| file
== 0)
13230 dwarf2_debug_line_missing_file_complaint ();
13233 fe
= &lh
->file_names
[file
- 1];
13235 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13236 if (!decode_for_pst_p
)
13238 last_subfile
= current_subfile
;
13239 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13244 case DW_LNS_set_column
:
13245 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13246 line_ptr
+= bytes_read
;
13248 case DW_LNS_negate_stmt
:
13249 is_stmt
= (!is_stmt
);
13251 case DW_LNS_set_basic_block
:
13254 /* Add to the address register of the state machine the
13255 address increment value corresponding to special opcode
13256 255. I.e., this value is scaled by the minimum
13257 instruction length since special opcode 255 would have
13258 scaled the increment. */
13259 case DW_LNS_const_add_pc
:
13261 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13263 address
+= (((op_index
+ adjust
)
13264 / lh
->maximum_ops_per_instruction
)
13265 * lh
->minimum_instruction_length
);
13266 op_index
= ((op_index
+ adjust
)
13267 % lh
->maximum_ops_per_instruction
);
13270 case DW_LNS_fixed_advance_pc
:
13271 address
+= read_2_bytes (abfd
, line_ptr
);
13277 /* Unknown standard opcode, ignore it. */
13280 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13282 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13283 line_ptr
+= bytes_read
;
13288 if (lh
->num_file_names
< file
|| file
== 0)
13289 dwarf2_debug_line_missing_file_complaint ();
13292 lh
->file_names
[file
- 1].included_p
= 1;
13293 if (!decode_for_pst_p
)
13295 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13296 (*p_record_line
) (current_subfile
, 0, addr
);
13302 /* Decode the Line Number Program (LNP) for the given line_header
13303 structure and CU. The actual information extracted and the type
13304 of structures created from the LNP depends on the value of PST.
13306 1. If PST is NULL, then this procedure uses the data from the program
13307 to create all necessary symbol tables, and their linetables.
13309 2. If PST is not NULL, this procedure reads the program to determine
13310 the list of files included by the unit represented by PST, and
13311 builds all the associated partial symbol tables.
13313 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13314 It is used for relative paths in the line table.
13315 NOTE: When processing partial symtabs (pst != NULL),
13316 comp_dir == pst->dirname.
13318 NOTE: It is important that psymtabs have the same file name (via strcmp)
13319 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13320 symtab we don't use it in the name of the psymtabs we create.
13321 E.g. expand_line_sal requires this when finding psymtabs to expand.
13322 A good testcase for this is mb-inline.exp. */
13325 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13326 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13327 int want_line_info
)
13329 struct objfile
*objfile
= cu
->objfile
;
13330 const int decode_for_pst_p
= (pst
!= NULL
);
13331 struct subfile
*first_subfile
= current_subfile
;
13333 if (want_line_info
)
13334 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13336 if (decode_for_pst_p
)
13340 /* Now that we're done scanning the Line Header Program, we can
13341 create the psymtab of each included file. */
13342 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13343 if (lh
->file_names
[file_index
].included_p
== 1)
13345 char *include_name
=
13346 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13347 if (include_name
!= NULL
)
13348 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13353 /* Make sure a symtab is created for every file, even files
13354 which contain only variables (i.e. no code with associated
13358 for (i
= 0; i
< lh
->num_file_names
; i
++)
13361 struct file_entry
*fe
;
13363 fe
= &lh
->file_names
[i
];
13365 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13366 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13368 /* Skip the main file; we don't need it, and it must be
13369 allocated last, so that it will show up before the
13370 non-primary symtabs in the objfile's symtab list. */
13371 if (current_subfile
== first_subfile
)
13374 if (current_subfile
->symtab
== NULL
)
13375 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13377 fe
->symtab
= current_subfile
->symtab
;
13382 /* Start a subfile for DWARF. FILENAME is the name of the file and
13383 DIRNAME the name of the source directory which contains FILENAME
13384 or NULL if not known. COMP_DIR is the compilation directory for the
13385 linetable's compilation unit or NULL if not known.
13386 This routine tries to keep line numbers from identical absolute and
13387 relative file names in a common subfile.
13389 Using the `list' example from the GDB testsuite, which resides in
13390 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13391 of /srcdir/list0.c yields the following debugging information for list0.c:
13393 DW_AT_name: /srcdir/list0.c
13394 DW_AT_comp_dir: /compdir
13395 files.files[0].name: list0.h
13396 files.files[0].dir: /srcdir
13397 files.files[1].name: list0.c
13398 files.files[1].dir: /srcdir
13400 The line number information for list0.c has to end up in a single
13401 subfile, so that `break /srcdir/list0.c:1' works as expected.
13402 start_subfile will ensure that this happens provided that we pass the
13403 concatenation of files.files[1].dir and files.files[1].name as the
13407 dwarf2_start_subfile (char *filename
, const char *dirname
,
13408 const char *comp_dir
)
13412 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13413 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13414 second argument to start_subfile. To be consistent, we do the
13415 same here. In order not to lose the line information directory,
13416 we concatenate it to the filename when it makes sense.
13417 Note that the Dwarf3 standard says (speaking of filenames in line
13418 information): ``The directory index is ignored for file names
13419 that represent full path names''. Thus ignoring dirname in the
13420 `else' branch below isn't an issue. */
13422 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13423 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13425 fullname
= filename
;
13427 start_subfile (fullname
, comp_dir
);
13429 if (fullname
!= filename
)
13434 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13435 struct dwarf2_cu
*cu
)
13437 struct objfile
*objfile
= cu
->objfile
;
13438 struct comp_unit_head
*cu_header
= &cu
->header
;
13440 /* NOTE drow/2003-01-30: There used to be a comment and some special
13441 code here to turn a symbol with DW_AT_external and a
13442 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13443 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13444 with some versions of binutils) where shared libraries could have
13445 relocations against symbols in their debug information - the
13446 minimal symbol would have the right address, but the debug info
13447 would not. It's no longer necessary, because we will explicitly
13448 apply relocations when we read in the debug information now. */
13450 /* A DW_AT_location attribute with no contents indicates that a
13451 variable has been optimized away. */
13452 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13454 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13458 /* Handle one degenerate form of location expression specially, to
13459 preserve GDB's previous behavior when section offsets are
13460 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13461 then mark this symbol as LOC_STATIC. */
13463 if (attr_form_is_block (attr
)
13464 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13465 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13466 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13467 && (DW_BLOCK (attr
)->size
13468 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13470 unsigned int dummy
;
13472 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13473 SYMBOL_VALUE_ADDRESS (sym
) =
13474 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13476 SYMBOL_VALUE_ADDRESS (sym
) =
13477 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13478 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13479 fixup_symbol_section (sym
, objfile
);
13480 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13481 SYMBOL_SECTION (sym
));
13485 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13486 expression evaluator, and use LOC_COMPUTED only when necessary
13487 (i.e. when the value of a register or memory location is
13488 referenced, or a thread-local block, etc.). Then again, it might
13489 not be worthwhile. I'm assuming that it isn't unless performance
13490 or memory numbers show me otherwise. */
13492 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13493 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13495 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13496 cu
->has_loclist
= 1;
13499 /* Given a pointer to a DWARF information entry, figure out if we need
13500 to make a symbol table entry for it, and if so, create a new entry
13501 and return a pointer to it.
13502 If TYPE is NULL, determine symbol type from the die, otherwise
13503 used the passed type.
13504 If SPACE is not NULL, use it to hold the new symbol. If it is
13505 NULL, allocate a new symbol on the objfile's obstack. */
13507 static struct symbol
*
13508 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13509 struct symbol
*space
)
13511 struct objfile
*objfile
= cu
->objfile
;
13512 struct symbol
*sym
= NULL
;
13514 struct attribute
*attr
= NULL
;
13515 struct attribute
*attr2
= NULL
;
13516 CORE_ADDR baseaddr
;
13517 struct pending
**list_to_add
= NULL
;
13519 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13521 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13523 name
= dwarf2_name (die
, cu
);
13526 const char *linkagename
;
13527 int suppress_add
= 0;
13532 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13533 OBJSTAT (objfile
, n_syms
++);
13535 /* Cache this symbol's name and the name's demangled form (if any). */
13536 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13537 linkagename
= dwarf2_physname (name
, die
, cu
);
13538 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13540 /* Fortran does not have mangling standard and the mangling does differ
13541 between gfortran, iFort etc. */
13542 if (cu
->language
== language_fortran
13543 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13544 symbol_set_demangled_name (&(sym
->ginfo
),
13545 (char *) dwarf2_full_name (name
, die
, cu
),
13548 /* Default assumptions.
13549 Use the passed type or decode it from the die. */
13550 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13551 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13553 SYMBOL_TYPE (sym
) = type
;
13555 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13556 attr
= dwarf2_attr (die
,
13557 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13561 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13564 attr
= dwarf2_attr (die
,
13565 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13569 int file_index
= DW_UNSND (attr
);
13571 if (cu
->line_header
== NULL
13572 || file_index
> cu
->line_header
->num_file_names
)
13573 complaint (&symfile_complaints
,
13574 _("file index out of range"));
13575 else if (file_index
> 0)
13577 struct file_entry
*fe
;
13579 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13580 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13587 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13590 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13592 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13593 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13594 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13595 add_symbol_to_list (sym
, cu
->list_in_scope
);
13597 case DW_TAG_subprogram
:
13598 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13600 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13601 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13602 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13603 || cu
->language
== language_ada
)
13605 /* Subprograms marked external are stored as a global symbol.
13606 Ada subprograms, whether marked external or not, are always
13607 stored as a global symbol, because we want to be able to
13608 access them globally. For instance, we want to be able
13609 to break on a nested subprogram without having to
13610 specify the context. */
13611 list_to_add
= &global_symbols
;
13615 list_to_add
= cu
->list_in_scope
;
13618 case DW_TAG_inlined_subroutine
:
13619 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13621 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13622 SYMBOL_INLINED (sym
) = 1;
13623 list_to_add
= cu
->list_in_scope
;
13625 case DW_TAG_template_value_param
:
13627 /* Fall through. */
13628 case DW_TAG_constant
:
13629 case DW_TAG_variable
:
13630 case DW_TAG_member
:
13631 /* Compilation with minimal debug info may result in
13632 variables with missing type entries. Change the
13633 misleading `void' type to something sensible. */
13634 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13636 = objfile_type (objfile
)->nodebug_data_symbol
;
13638 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13639 /* In the case of DW_TAG_member, we should only be called for
13640 static const members. */
13641 if (die
->tag
== DW_TAG_member
)
13643 /* dwarf2_add_field uses die_is_declaration,
13644 so we do the same. */
13645 gdb_assert (die_is_declaration (die
, cu
));
13650 dwarf2_const_value (attr
, sym
, cu
);
13651 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13654 if (attr2
&& (DW_UNSND (attr2
) != 0))
13655 list_to_add
= &global_symbols
;
13657 list_to_add
= cu
->list_in_scope
;
13661 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13664 var_decode_location (attr
, sym
, cu
);
13665 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13666 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13667 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13668 && !dwarf2_per_objfile
->has_section_at_zero
)
13670 /* When a static variable is eliminated by the linker,
13671 the corresponding debug information is not stripped
13672 out, but the variable address is set to null;
13673 do not add such variables into symbol table. */
13675 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13677 /* Workaround gfortran PR debug/40040 - it uses
13678 DW_AT_location for variables in -fPIC libraries which may
13679 get overriden by other libraries/executable and get
13680 a different address. Resolve it by the minimal symbol
13681 which may come from inferior's executable using copy
13682 relocation. Make this workaround only for gfortran as for
13683 other compilers GDB cannot guess the minimal symbol
13684 Fortran mangling kind. */
13685 if (cu
->language
== language_fortran
&& die
->parent
13686 && die
->parent
->tag
== DW_TAG_module
13688 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13689 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13691 /* A variable with DW_AT_external is never static,
13692 but it may be block-scoped. */
13693 list_to_add
= (cu
->list_in_scope
== &file_symbols
13694 ? &global_symbols
: cu
->list_in_scope
);
13697 list_to_add
= cu
->list_in_scope
;
13701 /* We do not know the address of this symbol.
13702 If it is an external symbol and we have type information
13703 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13704 The address of the variable will then be determined from
13705 the minimal symbol table whenever the variable is
13707 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13708 if (attr2
&& (DW_UNSND (attr2
) != 0)
13709 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13711 /* A variable with DW_AT_external is never static, but it
13712 may be block-scoped. */
13713 list_to_add
= (cu
->list_in_scope
== &file_symbols
13714 ? &global_symbols
: cu
->list_in_scope
);
13716 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13718 else if (!die_is_declaration (die
, cu
))
13720 /* Use the default LOC_OPTIMIZED_OUT class. */
13721 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13723 list_to_add
= cu
->list_in_scope
;
13727 case DW_TAG_formal_parameter
:
13728 /* If we are inside a function, mark this as an argument. If
13729 not, we might be looking at an argument to an inlined function
13730 when we do not have enough information to show inlined frames;
13731 pretend it's a local variable in that case so that the user can
13733 if (context_stack_depth
> 0
13734 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13735 SYMBOL_IS_ARGUMENT (sym
) = 1;
13736 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13739 var_decode_location (attr
, sym
, cu
);
13741 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13744 dwarf2_const_value (attr
, sym
, cu
);
13747 list_to_add
= cu
->list_in_scope
;
13749 case DW_TAG_unspecified_parameters
:
13750 /* From varargs functions; gdb doesn't seem to have any
13751 interest in this information, so just ignore it for now.
13754 case DW_TAG_template_type_param
:
13756 /* Fall through. */
13757 case DW_TAG_class_type
:
13758 case DW_TAG_interface_type
:
13759 case DW_TAG_structure_type
:
13760 case DW_TAG_union_type
:
13761 case DW_TAG_set_type
:
13762 case DW_TAG_enumeration_type
:
13763 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13764 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13767 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13768 really ever be static objects: otherwise, if you try
13769 to, say, break of a class's method and you're in a file
13770 which doesn't mention that class, it won't work unless
13771 the check for all static symbols in lookup_symbol_aux
13772 saves you. See the OtherFileClass tests in
13773 gdb.c++/namespace.exp. */
13777 list_to_add
= (cu
->list_in_scope
== &file_symbols
13778 && (cu
->language
== language_cplus
13779 || cu
->language
== language_java
)
13780 ? &global_symbols
: cu
->list_in_scope
);
13782 /* The semantics of C++ state that "struct foo {
13783 ... }" also defines a typedef for "foo". A Java
13784 class declaration also defines a typedef for the
13786 if (cu
->language
== language_cplus
13787 || cu
->language
== language_java
13788 || cu
->language
== language_ada
)
13790 /* The symbol's name is already allocated along
13791 with this objfile, so we don't need to
13792 duplicate it for the type. */
13793 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13794 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13799 case DW_TAG_typedef
:
13800 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13801 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13802 list_to_add
= cu
->list_in_scope
;
13804 case DW_TAG_base_type
:
13805 case DW_TAG_subrange_type
:
13806 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13807 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13808 list_to_add
= cu
->list_in_scope
;
13810 case DW_TAG_enumerator
:
13811 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13814 dwarf2_const_value (attr
, sym
, cu
);
13817 /* NOTE: carlton/2003-11-10: See comment above in the
13818 DW_TAG_class_type, etc. block. */
13820 list_to_add
= (cu
->list_in_scope
== &file_symbols
13821 && (cu
->language
== language_cplus
13822 || cu
->language
== language_java
)
13823 ? &global_symbols
: cu
->list_in_scope
);
13826 case DW_TAG_namespace
:
13827 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13828 list_to_add
= &global_symbols
;
13831 /* Not a tag we recognize. Hopefully we aren't processing
13832 trash data, but since we must specifically ignore things
13833 we don't recognize, there is nothing else we should do at
13835 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
13836 dwarf_tag_name (die
->tag
));
13842 sym
->hash_next
= objfile
->template_symbols
;
13843 objfile
->template_symbols
= sym
;
13844 list_to_add
= NULL
;
13847 if (list_to_add
!= NULL
)
13848 add_symbol_to_list (sym
, list_to_add
);
13850 /* For the benefit of old versions of GCC, check for anonymous
13851 namespaces based on the demangled name. */
13852 if (!processing_has_namespace_info
13853 && cu
->language
== language_cplus
)
13854 cp_scan_for_anonymous_namespaces (sym
, objfile
);
13859 /* A wrapper for new_symbol_full that always allocates a new symbol. */
13861 static struct symbol
*
13862 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13864 return new_symbol_full (die
, type
, cu
, NULL
);
13867 /* Given an attr with a DW_FORM_dataN value in host byte order,
13868 zero-extend it as appropriate for the symbol's type. The DWARF
13869 standard (v4) is not entirely clear about the meaning of using
13870 DW_FORM_dataN for a constant with a signed type, where the type is
13871 wider than the data. The conclusion of a discussion on the DWARF
13872 list was that this is unspecified. We choose to always zero-extend
13873 because that is the interpretation long in use by GCC. */
13876 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
13877 const char *name
, struct obstack
*obstack
,
13878 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
13880 struct objfile
*objfile
= cu
->objfile
;
13881 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
13882 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
13883 LONGEST l
= DW_UNSND (attr
);
13885 if (bits
< sizeof (*value
) * 8)
13887 l
&= ((LONGEST
) 1 << bits
) - 1;
13890 else if (bits
== sizeof (*value
) * 8)
13894 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
13895 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
13902 /* Read a constant value from an attribute. Either set *VALUE, or if
13903 the value does not fit in *VALUE, set *BYTES - either already
13904 allocated on the objfile obstack, or newly allocated on OBSTACK,
13905 or, set *BATON, if we translated the constant to a location
13909 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
13910 const char *name
, struct obstack
*obstack
,
13911 struct dwarf2_cu
*cu
,
13912 LONGEST
*value
, gdb_byte
**bytes
,
13913 struct dwarf2_locexpr_baton
**baton
)
13915 struct objfile
*objfile
= cu
->objfile
;
13916 struct comp_unit_head
*cu_header
= &cu
->header
;
13917 struct dwarf_block
*blk
;
13918 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
13919 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
13925 switch (attr
->form
)
13928 case DW_FORM_GNU_addr_index
:
13932 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
13933 dwarf2_const_value_length_mismatch_complaint (name
,
13934 cu_header
->addr_size
,
13935 TYPE_LENGTH (type
));
13936 /* Symbols of this form are reasonably rare, so we just
13937 piggyback on the existing location code rather than writing
13938 a new implementation of symbol_computed_ops. */
13939 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
13940 sizeof (struct dwarf2_locexpr_baton
));
13941 (*baton
)->per_cu
= cu
->per_cu
;
13942 gdb_assert ((*baton
)->per_cu
);
13944 (*baton
)->size
= 2 + cu_header
->addr_size
;
13945 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
13946 (*baton
)->data
= data
;
13948 data
[0] = DW_OP_addr
;
13949 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
13950 byte_order
, DW_ADDR (attr
));
13951 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
13954 case DW_FORM_string
:
13956 case DW_FORM_GNU_str_index
:
13957 /* DW_STRING is already allocated on the objfile obstack, point
13959 *bytes
= (gdb_byte
*) DW_STRING (attr
);
13961 case DW_FORM_block1
:
13962 case DW_FORM_block2
:
13963 case DW_FORM_block4
:
13964 case DW_FORM_block
:
13965 case DW_FORM_exprloc
:
13966 blk
= DW_BLOCK (attr
);
13967 if (TYPE_LENGTH (type
) != blk
->size
)
13968 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
13969 TYPE_LENGTH (type
));
13970 *bytes
= blk
->data
;
13973 /* The DW_AT_const_value attributes are supposed to carry the
13974 symbol's value "represented as it would be on the target
13975 architecture." By the time we get here, it's already been
13976 converted to host endianness, so we just need to sign- or
13977 zero-extend it as appropriate. */
13978 case DW_FORM_data1
:
13979 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13980 obstack
, cu
, value
, 8);
13982 case DW_FORM_data2
:
13983 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13984 obstack
, cu
, value
, 16);
13986 case DW_FORM_data4
:
13987 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13988 obstack
, cu
, value
, 32);
13990 case DW_FORM_data8
:
13991 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
13992 obstack
, cu
, value
, 64);
13995 case DW_FORM_sdata
:
13996 *value
= DW_SND (attr
);
13999 case DW_FORM_udata
:
14000 *value
= DW_UNSND (attr
);
14004 complaint (&symfile_complaints
,
14005 _("unsupported const value attribute form: '%s'"),
14006 dwarf_form_name (attr
->form
));
14013 /* Copy constant value from an attribute to a symbol. */
14016 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14017 struct dwarf2_cu
*cu
)
14019 struct objfile
*objfile
= cu
->objfile
;
14020 struct comp_unit_head
*cu_header
= &cu
->header
;
14023 struct dwarf2_locexpr_baton
*baton
;
14025 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
14026 SYMBOL_PRINT_NAME (sym
),
14027 &objfile
->objfile_obstack
, cu
,
14028 &value
, &bytes
, &baton
);
14032 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14033 SYMBOL_LOCATION_BATON (sym
) = baton
;
14034 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14036 else if (bytes
!= NULL
)
14038 SYMBOL_VALUE_BYTES (sym
) = bytes
;
14039 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
14043 SYMBOL_VALUE (sym
) = value
;
14044 SYMBOL_CLASS (sym
) = LOC_CONST
;
14048 /* Return the type of the die in question using its DW_AT_type attribute. */
14050 static struct type
*
14051 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14053 struct attribute
*type_attr
;
14055 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14058 /* A missing DW_AT_type represents a void type. */
14059 return objfile_type (cu
->objfile
)->builtin_void
;
14062 return lookup_die_type (die
, type_attr
, cu
);
14065 /* True iff CU's producer generates GNAT Ada auxiliary information
14066 that allows to find parallel types through that information instead
14067 of having to do expensive parallel lookups by type name. */
14070 need_gnat_info (struct dwarf2_cu
*cu
)
14072 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14073 of GNAT produces this auxiliary information, without any indication
14074 that it is produced. Part of enhancing the FSF version of GNAT
14075 to produce that information will be to put in place an indicator
14076 that we can use in order to determine whether the descriptive type
14077 info is available or not. One suggestion that has been made is
14078 to use a new attribute, attached to the CU die. For now, assume
14079 that the descriptive type info is not available. */
14083 /* Return the auxiliary type of the die in question using its
14084 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14085 attribute is not present. */
14087 static struct type
*
14088 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14090 struct attribute
*type_attr
;
14092 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
14096 return lookup_die_type (die
, type_attr
, cu
);
14099 /* If DIE has a descriptive_type attribute, then set the TYPE's
14100 descriptive type accordingly. */
14103 set_descriptive_type (struct type
*type
, struct die_info
*die
,
14104 struct dwarf2_cu
*cu
)
14106 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
14108 if (descriptive_type
)
14110 ALLOCATE_GNAT_AUX_TYPE (type
);
14111 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
14115 /* Return the containing type of the die in question using its
14116 DW_AT_containing_type attribute. */
14118 static struct type
*
14119 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14121 struct attribute
*type_attr
;
14123 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
14125 error (_("Dwarf Error: Problem turning containing type into gdb type "
14126 "[in module %s]"), cu
->objfile
->name
);
14128 return lookup_die_type (die
, type_attr
, cu
);
14131 /* Look up the type of DIE in CU using its type attribute ATTR.
14132 If there is no type substitute an error marker. */
14134 static struct type
*
14135 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
14136 struct dwarf2_cu
*cu
)
14138 struct objfile
*objfile
= cu
->objfile
;
14139 struct type
*this_type
;
14141 /* First see if we have it cached. */
14143 if (is_ref_attr (attr
))
14145 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14147 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
14149 else if (attr
->form
== DW_FORM_ref_sig8
)
14151 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14153 /* sig_type will be NULL if the signatured type is missing from
14155 if (sig_type
== NULL
)
14156 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14157 "at 0x%x [in module %s]"),
14158 die
->offset
.sect_off
, objfile
->name
);
14160 gdb_assert (sig_type
->per_cu
.is_debug_types
);
14161 /* If we haven't filled in type_offset_in_section yet, then we
14162 haven't read the type in yet. */
14164 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
14167 get_die_type_at_offset (sig_type
->type_offset_in_section
,
14168 &sig_type
->per_cu
);
14173 dump_die_for_error (die
);
14174 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
14175 dwarf_attr_name (attr
->name
), objfile
->name
);
14178 /* If not cached we need to read it in. */
14180 if (this_type
== NULL
)
14182 struct die_info
*type_die
;
14183 struct dwarf2_cu
*type_cu
= cu
;
14185 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
14186 /* If we found the type now, it's probably because the type came
14187 from an inter-CU reference and the type's CU got expanded before
14189 this_type
= get_die_type (type_die
, type_cu
);
14190 if (this_type
== NULL
)
14191 this_type
= read_type_die_1 (type_die
, type_cu
);
14194 /* If we still don't have a type use an error marker. */
14196 if (this_type
== NULL
)
14198 char *message
, *saved
;
14200 /* read_type_die already issued a complaint. */
14201 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
14203 cu
->header
.offset
.sect_off
,
14204 die
->offset
.sect_off
);
14205 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
14206 message
, strlen (message
));
14209 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
14215 /* Return the type in DIE, CU.
14216 Returns NULL for invalid types.
14218 This first does a lookup in the appropriate type_hash table,
14219 and only reads the die in if necessary.
14221 NOTE: This can be called when reading in partial or full symbols. */
14223 static struct type
*
14224 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
14226 struct type
*this_type
;
14228 this_type
= get_die_type (die
, cu
);
14232 return read_type_die_1 (die
, cu
);
14235 /* Read the type in DIE, CU.
14236 Returns NULL for invalid types. */
14238 static struct type
*
14239 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14241 struct type
*this_type
= NULL
;
14245 case DW_TAG_class_type
:
14246 case DW_TAG_interface_type
:
14247 case DW_TAG_structure_type
:
14248 case DW_TAG_union_type
:
14249 this_type
= read_structure_type (die
, cu
);
14251 case DW_TAG_enumeration_type
:
14252 this_type
= read_enumeration_type (die
, cu
);
14254 case DW_TAG_subprogram
:
14255 case DW_TAG_subroutine_type
:
14256 case DW_TAG_inlined_subroutine
:
14257 this_type
= read_subroutine_type (die
, cu
);
14259 case DW_TAG_array_type
:
14260 this_type
= read_array_type (die
, cu
);
14262 case DW_TAG_set_type
:
14263 this_type
= read_set_type (die
, cu
);
14265 case DW_TAG_pointer_type
:
14266 this_type
= read_tag_pointer_type (die
, cu
);
14268 case DW_TAG_ptr_to_member_type
:
14269 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14271 case DW_TAG_reference_type
:
14272 this_type
= read_tag_reference_type (die
, cu
);
14274 case DW_TAG_const_type
:
14275 this_type
= read_tag_const_type (die
, cu
);
14277 case DW_TAG_volatile_type
:
14278 this_type
= read_tag_volatile_type (die
, cu
);
14280 case DW_TAG_string_type
:
14281 this_type
= read_tag_string_type (die
, cu
);
14283 case DW_TAG_typedef
:
14284 this_type
= read_typedef (die
, cu
);
14286 case DW_TAG_subrange_type
:
14287 this_type
= read_subrange_type (die
, cu
);
14289 case DW_TAG_base_type
:
14290 this_type
= read_base_type (die
, cu
);
14292 case DW_TAG_unspecified_type
:
14293 this_type
= read_unspecified_type (die
, cu
);
14295 case DW_TAG_namespace
:
14296 this_type
= read_namespace_type (die
, cu
);
14298 case DW_TAG_module
:
14299 this_type
= read_module_type (die
, cu
);
14302 complaint (&symfile_complaints
,
14303 _("unexpected tag in read_type_die: '%s'"),
14304 dwarf_tag_name (die
->tag
));
14311 /* See if we can figure out if the class lives in a namespace. We do
14312 this by looking for a member function; its demangled name will
14313 contain namespace info, if there is any.
14314 Return the computed name or NULL.
14315 Space for the result is allocated on the objfile's obstack.
14316 This is the full-die version of guess_partial_die_structure_name.
14317 In this case we know DIE has no useful parent. */
14320 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14322 struct die_info
*spec_die
;
14323 struct dwarf2_cu
*spec_cu
;
14324 struct die_info
*child
;
14327 spec_die
= die_specification (die
, &spec_cu
);
14328 if (spec_die
!= NULL
)
14334 for (child
= die
->child
;
14336 child
= child
->sibling
)
14338 if (child
->tag
== DW_TAG_subprogram
)
14340 struct attribute
*attr
;
14342 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14344 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14348 = language_class_name_from_physname (cu
->language_defn
,
14352 if (actual_name
!= NULL
)
14354 char *die_name
= dwarf2_name (die
, cu
);
14356 if (die_name
!= NULL
14357 && strcmp (die_name
, actual_name
) != 0)
14359 /* Strip off the class name from the full name.
14360 We want the prefix. */
14361 int die_name_len
= strlen (die_name
);
14362 int actual_name_len
= strlen (actual_name
);
14364 /* Test for '::' as a sanity check. */
14365 if (actual_name_len
> die_name_len
+ 2
14366 && actual_name
[actual_name_len
14367 - die_name_len
- 1] == ':')
14369 obsavestring (actual_name
,
14370 actual_name_len
- die_name_len
- 2,
14371 &cu
->objfile
->objfile_obstack
);
14374 xfree (actual_name
);
14383 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14384 prefix part in such case. See
14385 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14388 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14390 struct attribute
*attr
;
14393 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14394 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14397 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14398 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14401 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14403 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14404 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14407 /* dwarf2_name had to be already called. */
14408 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14410 /* Strip the base name, keep any leading namespaces/classes. */
14411 base
= strrchr (DW_STRING (attr
), ':');
14412 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14415 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14416 &cu
->objfile
->objfile_obstack
);
14419 /* Return the name of the namespace/class that DIE is defined within,
14420 or "" if we can't tell. The caller should not xfree the result.
14422 For example, if we're within the method foo() in the following
14432 then determine_prefix on foo's die will return "N::C". */
14434 static const char *
14435 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14437 struct die_info
*parent
, *spec_die
;
14438 struct dwarf2_cu
*spec_cu
;
14439 struct type
*parent_type
;
14442 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14443 && cu
->language
!= language_fortran
)
14446 retval
= anonymous_struct_prefix (die
, cu
);
14450 /* We have to be careful in the presence of DW_AT_specification.
14451 For example, with GCC 3.4, given the code
14455 // Definition of N::foo.
14459 then we'll have a tree of DIEs like this:
14461 1: DW_TAG_compile_unit
14462 2: DW_TAG_namespace // N
14463 3: DW_TAG_subprogram // declaration of N::foo
14464 4: DW_TAG_subprogram // definition of N::foo
14465 DW_AT_specification // refers to die #3
14467 Thus, when processing die #4, we have to pretend that we're in
14468 the context of its DW_AT_specification, namely the contex of die
14471 spec_die
= die_specification (die
, &spec_cu
);
14472 if (spec_die
== NULL
)
14473 parent
= die
->parent
;
14476 parent
= spec_die
->parent
;
14480 if (parent
== NULL
)
14482 else if (parent
->building_fullname
)
14485 const char *parent_name
;
14487 /* It has been seen on RealView 2.2 built binaries,
14488 DW_TAG_template_type_param types actually _defined_ as
14489 children of the parent class:
14492 template class <class Enum> Class{};
14493 Class<enum E> class_e;
14495 1: DW_TAG_class_type (Class)
14496 2: DW_TAG_enumeration_type (E)
14497 3: DW_TAG_enumerator (enum1:0)
14498 3: DW_TAG_enumerator (enum2:1)
14500 2: DW_TAG_template_type_param
14501 DW_AT_type DW_FORM_ref_udata (E)
14503 Besides being broken debug info, it can put GDB into an
14504 infinite loop. Consider:
14506 When we're building the full name for Class<E>, we'll start
14507 at Class, and go look over its template type parameters,
14508 finding E. We'll then try to build the full name of E, and
14509 reach here. We're now trying to build the full name of E,
14510 and look over the parent DIE for containing scope. In the
14511 broken case, if we followed the parent DIE of E, we'd again
14512 find Class, and once again go look at its template type
14513 arguments, etc., etc. Simply don't consider such parent die
14514 as source-level parent of this die (it can't be, the language
14515 doesn't allow it), and break the loop here. */
14516 name
= dwarf2_name (die
, cu
);
14517 parent_name
= dwarf2_name (parent
, cu
);
14518 complaint (&symfile_complaints
,
14519 _("template param type '%s' defined within parent '%s'"),
14520 name
? name
: "<unknown>",
14521 parent_name
? parent_name
: "<unknown>");
14525 switch (parent
->tag
)
14527 case DW_TAG_namespace
:
14528 parent_type
= read_type_die (parent
, cu
);
14529 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14530 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14531 Work around this problem here. */
14532 if (cu
->language
== language_cplus
14533 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14535 /* We give a name to even anonymous namespaces. */
14536 return TYPE_TAG_NAME (parent_type
);
14537 case DW_TAG_class_type
:
14538 case DW_TAG_interface_type
:
14539 case DW_TAG_structure_type
:
14540 case DW_TAG_union_type
:
14541 case DW_TAG_module
:
14542 parent_type
= read_type_die (parent
, cu
);
14543 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14544 return TYPE_TAG_NAME (parent_type
);
14546 /* An anonymous structure is only allowed non-static data
14547 members; no typedefs, no member functions, et cetera.
14548 So it does not need a prefix. */
14550 case DW_TAG_compile_unit
:
14551 case DW_TAG_partial_unit
:
14552 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14553 if (cu
->language
== language_cplus
14554 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14555 && die
->child
!= NULL
14556 && (die
->tag
== DW_TAG_class_type
14557 || die
->tag
== DW_TAG_structure_type
14558 || die
->tag
== DW_TAG_union_type
))
14560 char *name
= guess_full_die_structure_name (die
, cu
);
14566 return determine_prefix (parent
, cu
);
14570 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14571 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14572 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14573 an obconcat, otherwise allocate storage for the result. The CU argument is
14574 used to determine the language and hence, the appropriate separator. */
14576 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14579 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14580 int physname
, struct dwarf2_cu
*cu
)
14582 const char *lead
= "";
14585 if (suffix
== NULL
|| suffix
[0] == '\0'
14586 || prefix
== NULL
|| prefix
[0] == '\0')
14588 else if (cu
->language
== language_java
)
14590 else if (cu
->language
== language_fortran
&& physname
)
14592 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14593 DW_AT_MIPS_linkage_name is preferred and used instead. */
14601 if (prefix
== NULL
)
14603 if (suffix
== NULL
)
14609 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14611 strcpy (retval
, lead
);
14612 strcat (retval
, prefix
);
14613 strcat (retval
, sep
);
14614 strcat (retval
, suffix
);
14619 /* We have an obstack. */
14620 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14624 /* Return sibling of die, NULL if no sibling. */
14626 static struct die_info
*
14627 sibling_die (struct die_info
*die
)
14629 return die
->sibling
;
14632 /* Get name of a die, return NULL if not found. */
14635 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14636 struct obstack
*obstack
)
14638 if (name
&& cu
->language
== language_cplus
)
14640 char *canon_name
= cp_canonicalize_string (name
);
14642 if (canon_name
!= NULL
)
14644 if (strcmp (canon_name
, name
) != 0)
14645 name
= obsavestring (canon_name
, strlen (canon_name
),
14647 xfree (canon_name
);
14654 /* Get name of a die, return NULL if not found. */
14657 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14659 struct attribute
*attr
;
14661 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14662 if ((!attr
|| !DW_STRING (attr
))
14663 && die
->tag
!= DW_TAG_class_type
14664 && die
->tag
!= DW_TAG_interface_type
14665 && die
->tag
!= DW_TAG_structure_type
14666 && die
->tag
!= DW_TAG_union_type
)
14671 case DW_TAG_compile_unit
:
14672 case DW_TAG_partial_unit
:
14673 /* Compilation units have a DW_AT_name that is a filename, not
14674 a source language identifier. */
14675 case DW_TAG_enumeration_type
:
14676 case DW_TAG_enumerator
:
14677 /* These tags always have simple identifiers already; no need
14678 to canonicalize them. */
14679 return DW_STRING (attr
);
14681 case DW_TAG_subprogram
:
14682 /* Java constructors will all be named "<init>", so return
14683 the class name when we see this special case. */
14684 if (cu
->language
== language_java
14685 && DW_STRING (attr
) != NULL
14686 && strcmp (DW_STRING (attr
), "<init>") == 0)
14688 struct dwarf2_cu
*spec_cu
= cu
;
14689 struct die_info
*spec_die
;
14691 /* GCJ will output '<init>' for Java constructor names.
14692 For this special case, return the name of the parent class. */
14694 /* GCJ may output suprogram DIEs with AT_specification set.
14695 If so, use the name of the specified DIE. */
14696 spec_die
= die_specification (die
, &spec_cu
);
14697 if (spec_die
!= NULL
)
14698 return dwarf2_name (spec_die
, spec_cu
);
14703 if (die
->tag
== DW_TAG_class_type
)
14704 return dwarf2_name (die
, cu
);
14706 while (die
->tag
!= DW_TAG_compile_unit
14707 && die
->tag
!= DW_TAG_partial_unit
);
14711 case DW_TAG_class_type
:
14712 case DW_TAG_interface_type
:
14713 case DW_TAG_structure_type
:
14714 case DW_TAG_union_type
:
14715 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14716 structures or unions. These were of the form "._%d" in GCC 4.1,
14717 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14718 and GCC 4.4. We work around this problem by ignoring these. */
14719 if (attr
&& DW_STRING (attr
)
14720 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14721 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14724 /* GCC might emit a nameless typedef that has a linkage name. See
14725 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14726 if (!attr
|| DW_STRING (attr
) == NULL
)
14728 char *demangled
= NULL
;
14730 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14732 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14734 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14737 /* Avoid demangling DW_STRING (attr) the second time on a second
14738 call for the same DIE. */
14739 if (!DW_STRING_IS_CANONICAL (attr
))
14740 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14746 /* FIXME: we already did this for the partial symbol... */
14747 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14748 &cu
->objfile
->objfile_obstack
);
14749 DW_STRING_IS_CANONICAL (attr
) = 1;
14752 /* Strip any leading namespaces/classes, keep only the base name.
14753 DW_AT_name for named DIEs does not contain the prefixes. */
14754 base
= strrchr (DW_STRING (attr
), ':');
14755 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14758 return DW_STRING (attr
);
14767 if (!DW_STRING_IS_CANONICAL (attr
))
14770 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14771 &cu
->objfile
->objfile_obstack
);
14772 DW_STRING_IS_CANONICAL (attr
) = 1;
14774 return DW_STRING (attr
);
14777 /* Return the die that this die in an extension of, or NULL if there
14778 is none. *EXT_CU is the CU containing DIE on input, and the CU
14779 containing the return value on output. */
14781 static struct die_info
*
14782 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14784 struct attribute
*attr
;
14786 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14790 return follow_die_ref (die
, attr
, ext_cu
);
14793 /* Convert a DIE tag into its string name. */
14795 static const char *
14796 dwarf_tag_name (unsigned tag
)
14798 const char *name
= get_DW_TAG_name (tag
);
14801 return "DW_TAG_<unknown>";
14806 /* Convert a DWARF attribute code into its string name. */
14808 static const char *
14809 dwarf_attr_name (unsigned attr
)
14813 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14814 if (attr
== DW_AT_MIPS_fde
)
14815 return "DW_AT_MIPS_fde";
14817 if (attr
== DW_AT_HP_block_index
)
14818 return "DW_AT_HP_block_index";
14821 name
= get_DW_AT_name (attr
);
14824 return "DW_AT_<unknown>";
14829 /* Convert a DWARF value form code into its string name. */
14831 static const char *
14832 dwarf_form_name (unsigned form
)
14834 const char *name
= get_DW_FORM_name (form
);
14837 return "DW_FORM_<unknown>";
14843 dwarf_bool_name (unsigned mybool
)
14851 /* Convert a DWARF type code into its string name. */
14853 static const char *
14854 dwarf_type_encoding_name (unsigned enc
)
14856 const char *name
= get_DW_ATE_name (enc
);
14859 return "DW_ATE_<unknown>";
14865 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
14869 print_spaces (indent
, f
);
14870 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
14871 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
14873 if (die
->parent
!= NULL
)
14875 print_spaces (indent
, f
);
14876 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
14877 die
->parent
->offset
.sect_off
);
14880 print_spaces (indent
, f
);
14881 fprintf_unfiltered (f
, " has children: %s\n",
14882 dwarf_bool_name (die
->child
!= NULL
));
14884 print_spaces (indent
, f
);
14885 fprintf_unfiltered (f
, " attributes:\n");
14887 for (i
= 0; i
< die
->num_attrs
; ++i
)
14889 print_spaces (indent
, f
);
14890 fprintf_unfiltered (f
, " %s (%s) ",
14891 dwarf_attr_name (die
->attrs
[i
].name
),
14892 dwarf_form_name (die
->attrs
[i
].form
));
14894 switch (die
->attrs
[i
].form
)
14897 case DW_FORM_GNU_addr_index
:
14898 fprintf_unfiltered (f
, "address: ");
14899 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
14901 case DW_FORM_block2
:
14902 case DW_FORM_block4
:
14903 case DW_FORM_block
:
14904 case DW_FORM_block1
:
14905 fprintf_unfiltered (f
, "block: size %d",
14906 DW_BLOCK (&die
->attrs
[i
])->size
);
14908 case DW_FORM_exprloc
:
14909 fprintf_unfiltered (f
, "expression: size %u",
14910 DW_BLOCK (&die
->attrs
[i
])->size
);
14912 case DW_FORM_ref_addr
:
14913 fprintf_unfiltered (f
, "ref address: ");
14914 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
14920 case DW_FORM_ref_udata
:
14921 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
14922 (long) (DW_UNSND (&die
->attrs
[i
])));
14924 case DW_FORM_data1
:
14925 case DW_FORM_data2
:
14926 case DW_FORM_data4
:
14927 case DW_FORM_data8
:
14928 case DW_FORM_udata
:
14929 case DW_FORM_sdata
:
14930 fprintf_unfiltered (f
, "constant: %s",
14931 pulongest (DW_UNSND (&die
->attrs
[i
])));
14933 case DW_FORM_sec_offset
:
14934 fprintf_unfiltered (f
, "section offset: %s",
14935 pulongest (DW_UNSND (&die
->attrs
[i
])));
14937 case DW_FORM_ref_sig8
:
14938 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
14939 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
14940 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
14942 fprintf_unfiltered (f
, "signatured type, offset: unknown");
14944 case DW_FORM_string
:
14946 case DW_FORM_GNU_str_index
:
14947 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
14948 DW_STRING (&die
->attrs
[i
])
14949 ? DW_STRING (&die
->attrs
[i
]) : "",
14950 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
14953 if (DW_UNSND (&die
->attrs
[i
]))
14954 fprintf_unfiltered (f
, "flag: TRUE");
14956 fprintf_unfiltered (f
, "flag: FALSE");
14958 case DW_FORM_flag_present
:
14959 fprintf_unfiltered (f
, "flag: TRUE");
14961 case DW_FORM_indirect
:
14962 /* The reader will have reduced the indirect form to
14963 the "base form" so this form should not occur. */
14964 fprintf_unfiltered (f
,
14965 "unexpected attribute form: DW_FORM_indirect");
14968 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
14969 die
->attrs
[i
].form
);
14972 fprintf_unfiltered (f
, "\n");
14977 dump_die_for_error (struct die_info
*die
)
14979 dump_die_shallow (gdb_stderr
, 0, die
);
14983 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
14985 int indent
= level
* 4;
14987 gdb_assert (die
!= NULL
);
14989 if (level
>= max_level
)
14992 dump_die_shallow (f
, indent
, die
);
14994 if (die
->child
!= NULL
)
14996 print_spaces (indent
, f
);
14997 fprintf_unfiltered (f
, " Children:");
14998 if (level
+ 1 < max_level
)
15000 fprintf_unfiltered (f
, "\n");
15001 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15005 fprintf_unfiltered (f
,
15006 " [not printed, max nesting level reached]\n");
15010 if (die
->sibling
!= NULL
&& level
> 0)
15012 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15016 /* This is called from the pdie macro in gdbinit.in.
15017 It's not static so gcc will keep a copy callable from gdb. */
15020 dump_die (struct die_info
*die
, int max_level
)
15022 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15026 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15030 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15036 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15037 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15040 is_ref_attr (struct attribute
*attr
)
15042 switch (attr
->form
)
15044 case DW_FORM_ref_addr
:
15049 case DW_FORM_ref_udata
:
15056 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15060 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15062 sect_offset retval
= { DW_UNSND (attr
) };
15064 if (is_ref_attr (attr
))
15067 retval
.sect_off
= 0;
15068 complaint (&symfile_complaints
,
15069 _("unsupported die ref attribute form: '%s'"),
15070 dwarf_form_name (attr
->form
));
15074 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15075 * the value held by the attribute is not constant. */
15078 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15080 if (attr
->form
== DW_FORM_sdata
)
15081 return DW_SND (attr
);
15082 else if (attr
->form
== DW_FORM_udata
15083 || attr
->form
== DW_FORM_data1
15084 || attr
->form
== DW_FORM_data2
15085 || attr
->form
== DW_FORM_data4
15086 || attr
->form
== DW_FORM_data8
)
15087 return DW_UNSND (attr
);
15090 complaint (&symfile_complaints
,
15091 _("Attribute value is not a constant (%s)"),
15092 dwarf_form_name (attr
->form
));
15093 return default_value
;
15097 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
15098 unit and add it to our queue.
15099 The result is non-zero if PER_CU was queued, otherwise the result is zero
15100 meaning either PER_CU is already queued or it is already loaded. */
15103 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
15104 struct dwarf2_per_cu_data
*per_cu
,
15105 enum language pretend_language
)
15107 /* We may arrive here during partial symbol reading, if we need full
15108 DIEs to process an unusual case (e.g. template arguments). Do
15109 not queue PER_CU, just tell our caller to load its DIEs. */
15110 if (dwarf2_per_objfile
->reading_partial_symbols
)
15112 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
15117 /* Mark the dependence relation so that we don't flush PER_CU
15119 dwarf2_add_dependence (this_cu
, per_cu
);
15121 /* If it's already on the queue, we have nothing to do. */
15122 if (per_cu
->queued
)
15125 /* If the compilation unit is already loaded, just mark it as
15127 if (per_cu
->cu
!= NULL
)
15129 per_cu
->cu
->last_used
= 0;
15133 /* Add it to the queue. */
15134 queue_comp_unit (per_cu
, pretend_language
);
15139 /* Follow reference or signature attribute ATTR of SRC_DIE.
15140 On entry *REF_CU is the CU of SRC_DIE.
15141 On exit *REF_CU is the CU of the result. */
15143 static struct die_info
*
15144 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15145 struct dwarf2_cu
**ref_cu
)
15147 struct die_info
*die
;
15149 if (is_ref_attr (attr
))
15150 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15151 else if (attr
->form
== DW_FORM_ref_sig8
)
15152 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15155 dump_die_for_error (src_die
);
15156 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15157 (*ref_cu
)->objfile
->name
);
15163 /* Follow reference OFFSET.
15164 On entry *REF_CU is the CU of the source die referencing OFFSET.
15165 On exit *REF_CU is the CU of the result.
15166 Returns NULL if OFFSET is invalid. */
15168 static struct die_info
*
15169 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15171 struct die_info temp_die
;
15172 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15174 gdb_assert (cu
->per_cu
!= NULL
);
15178 if (cu
->per_cu
->is_debug_types
)
15180 /* .debug_types CUs cannot reference anything outside their CU.
15181 If they need to, they have to reference a signatured type via
15182 DW_FORM_ref_sig8. */
15183 if (! offset_in_cu_p (&cu
->header
, offset
))
15186 else if (! offset_in_cu_p (&cu
->header
, offset
))
15188 struct dwarf2_per_cu_data
*per_cu
;
15190 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15192 /* If necessary, add it to the queue and load its DIEs. */
15193 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
15194 load_full_comp_unit (per_cu
, cu
->language
);
15196 target_cu
= per_cu
->cu
;
15198 else if (cu
->dies
== NULL
)
15200 /* We're loading full DIEs during partial symbol reading. */
15201 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15202 load_full_comp_unit (cu
->per_cu
, language_minimal
);
15205 *ref_cu
= target_cu
;
15206 temp_die
.offset
= offset
;
15207 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15210 /* Follow reference attribute ATTR of SRC_DIE.
15211 On entry *REF_CU is the CU of SRC_DIE.
15212 On exit *REF_CU is the CU of the result. */
15214 static struct die_info
*
15215 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15216 struct dwarf2_cu
**ref_cu
)
15218 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15219 struct dwarf2_cu
*cu
= *ref_cu
;
15220 struct die_info
*die
;
15222 die
= follow_die_offset (offset
, ref_cu
);
15224 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15225 "at 0x%x [in module %s]"),
15226 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15231 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15232 Returned value is intended for DW_OP_call*. Returned
15233 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15235 struct dwarf2_locexpr_baton
15236 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15237 struct dwarf2_per_cu_data
*per_cu
,
15238 CORE_ADDR (*get_frame_pc
) (void *baton
),
15241 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15242 struct dwarf2_cu
*cu
;
15243 struct die_info
*die
;
15244 struct attribute
*attr
;
15245 struct dwarf2_locexpr_baton retval
;
15247 dw2_setup (per_cu
->objfile
);
15249 if (per_cu
->cu
== NULL
)
15253 die
= follow_die_offset (offset
, &cu
);
15255 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15256 offset
.sect_off
, per_cu
->objfile
->name
);
15258 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15261 /* DWARF: "If there is no such attribute, then there is no effect.".
15262 DATA is ignored if SIZE is 0. */
15264 retval
.data
= NULL
;
15267 else if (attr_form_is_section_offset (attr
))
15269 struct dwarf2_loclist_baton loclist_baton
;
15270 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15273 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15275 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15277 retval
.size
= size
;
15281 if (!attr_form_is_block (attr
))
15282 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15283 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15284 offset
.sect_off
, per_cu
->objfile
->name
);
15286 retval
.data
= DW_BLOCK (attr
)->data
;
15287 retval
.size
= DW_BLOCK (attr
)->size
;
15289 retval
.per_cu
= cu
->per_cu
;
15291 age_cached_comp_units ();
15296 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15300 dwarf2_get_die_type (cu_offset die_offset
,
15301 struct dwarf2_per_cu_data
*per_cu
)
15303 sect_offset die_offset_sect
;
15305 dw2_setup (per_cu
->objfile
);
15307 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15308 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15311 /* Follow the signature attribute ATTR in SRC_DIE.
15312 On entry *REF_CU is the CU of SRC_DIE.
15313 On exit *REF_CU is the CU of the result. */
15315 static struct die_info
*
15316 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15317 struct dwarf2_cu
**ref_cu
)
15319 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15320 struct die_info temp_die
;
15321 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15322 struct dwarf2_cu
*sig_cu
;
15323 struct die_info
*die
;
15325 /* sig_type will be NULL if the signatured type is missing from
15327 if (sig_type
== NULL
)
15328 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15329 "at 0x%x [in module %s]"),
15330 src_die
->offset
.sect_off
, objfile
->name
);
15332 /* If necessary, add it to the queue and load its DIEs. */
15334 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15335 read_signatured_type (sig_type
);
15337 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15339 sig_cu
= sig_type
->per_cu
.cu
;
15340 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15341 temp_die
.offset
= sig_type
->type_offset_in_section
;
15342 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15343 temp_die
.offset
.sect_off
);
15350 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15351 "from DIE at 0x%x [in module %s]"),
15352 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15355 /* Given an offset of a signatured type, return its signatured_type. */
15357 static struct signatured_type
*
15358 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15359 struct dwarf2_section_info
*section
,
15360 sect_offset offset
)
15362 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15363 unsigned int length
, initial_length_size
;
15364 unsigned int sig_offset
;
15365 struct signatured_type find_entry
, *sig_type
;
15367 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15368 sig_offset
= (initial_length_size
15370 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15371 + 1 /*address_size*/);
15372 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15373 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15375 /* This is only used to lookup previously recorded types.
15376 If we didn't find it, it's our bug. */
15377 gdb_assert (sig_type
!= NULL
);
15378 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15383 /* Load the DIEs associated with type unit PER_CU into memory. */
15386 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15388 struct objfile
*objfile
= per_cu
->objfile
;
15389 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15390 sect_offset offset
= per_cu
->offset
;
15391 struct signatured_type
*sig_type
;
15393 dwarf2_read_section (objfile
, sect
);
15395 /* We have the section offset, but we need the signature to do the
15396 hash table lookup. */
15397 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15398 the signature to assert we found the right one.
15399 Ok, but it's a lot of work. We should simplify things so any needed
15400 assert doesn't require all this clumsiness. */
15401 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15403 gdb_assert (&sig_type
->per_cu
== per_cu
);
15404 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15406 read_signatured_type (sig_type
);
15408 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15411 /* die_reader_func for read_signatured_type.
15412 This is identical to load_full_comp_unit_reader,
15413 but is kept separate for now. */
15416 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15417 gdb_byte
*info_ptr
,
15418 struct die_info
*comp_unit_die
,
15422 struct dwarf2_cu
*cu
= reader
->cu
;
15424 gdb_assert (cu
->die_hash
== NULL
);
15426 htab_create_alloc_ex (cu
->header
.length
/ 12,
15430 &cu
->comp_unit_obstack
,
15431 hashtab_obstack_allocate
,
15432 dummy_obstack_deallocate
);
15435 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15436 &info_ptr
, comp_unit_die
);
15437 cu
->dies
= comp_unit_die
;
15438 /* comp_unit_die is not stored in die_hash, no need. */
15440 /* We try not to read any attributes in this function, because not
15441 all CUs needed for references have been loaded yet, and symbol
15442 table processing isn't initialized. But we have to set the CU language,
15443 or we won't be able to build types correctly.
15444 Similarly, if we do not read the producer, we can not apply
15445 producer-specific interpretation. */
15446 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15449 /* Read in a signatured type and build its CU and DIEs.
15450 If the type is a stub for the real type in a DWO file,
15451 read in the real type from the DWO file as well. */
15454 read_signatured_type (struct signatured_type
*sig_type
)
15456 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15458 gdb_assert (per_cu
->is_debug_types
);
15459 gdb_assert (per_cu
->cu
== NULL
);
15461 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15464 /* Decode simple location descriptions.
15465 Given a pointer to a dwarf block that defines a location, compute
15466 the location and return the value.
15468 NOTE drow/2003-11-18: This function is called in two situations
15469 now: for the address of static or global variables (partial symbols
15470 only) and for offsets into structures which are expected to be
15471 (more or less) constant. The partial symbol case should go away,
15472 and only the constant case should remain. That will let this
15473 function complain more accurately. A few special modes are allowed
15474 without complaint for global variables (for instance, global
15475 register values and thread-local values).
15477 A location description containing no operations indicates that the
15478 object is optimized out. The return value is 0 for that case.
15479 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15480 callers will only want a very basic result and this can become a
15483 Note that stack[0] is unused except as a default error return. */
15486 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15488 struct objfile
*objfile
= cu
->objfile
;
15490 int size
= blk
->size
;
15491 gdb_byte
*data
= blk
->data
;
15492 CORE_ADDR stack
[64];
15494 unsigned int bytes_read
, unsnd
;
15500 stack
[++stacki
] = 0;
15539 stack
[++stacki
] = op
- DW_OP_lit0
;
15574 stack
[++stacki
] = op
- DW_OP_reg0
;
15576 dwarf2_complex_location_expr_complaint ();
15580 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15582 stack
[++stacki
] = unsnd
;
15584 dwarf2_complex_location_expr_complaint ();
15588 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15593 case DW_OP_const1u
:
15594 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15598 case DW_OP_const1s
:
15599 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15603 case DW_OP_const2u
:
15604 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15608 case DW_OP_const2s
:
15609 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15613 case DW_OP_const4u
:
15614 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15618 case DW_OP_const4s
:
15619 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15623 case DW_OP_const8u
:
15624 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15629 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15635 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15640 stack
[stacki
+ 1] = stack
[stacki
];
15645 stack
[stacki
- 1] += stack
[stacki
];
15649 case DW_OP_plus_uconst
:
15650 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15656 stack
[stacki
- 1] -= stack
[stacki
];
15661 /* If we're not the last op, then we definitely can't encode
15662 this using GDB's address_class enum. This is valid for partial
15663 global symbols, although the variable's address will be bogus
15666 dwarf2_complex_location_expr_complaint ();
15669 case DW_OP_GNU_push_tls_address
:
15670 /* The top of the stack has the offset from the beginning
15671 of the thread control block at which the variable is located. */
15672 /* Nothing should follow this operator, so the top of stack would
15674 /* This is valid for partial global symbols, but the variable's
15675 address will be bogus in the psymtab. Make it always at least
15676 non-zero to not look as a variable garbage collected by linker
15677 which have DW_OP_addr 0. */
15679 dwarf2_complex_location_expr_complaint ();
15683 case DW_OP_GNU_uninit
:
15686 case DW_OP_GNU_addr_index
:
15687 case DW_OP_GNU_const_index
:
15688 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15695 const char *name
= get_DW_OP_name (op
);
15698 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15701 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15705 return (stack
[stacki
]);
15708 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15709 outside of the allocated space. Also enforce minimum>0. */
15710 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15712 complaint (&symfile_complaints
,
15713 _("location description stack overflow"));
15719 complaint (&symfile_complaints
,
15720 _("location description stack underflow"));
15724 return (stack
[stacki
]);
15727 /* memory allocation interface */
15729 static struct dwarf_block
*
15730 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15732 struct dwarf_block
*blk
;
15734 blk
= (struct dwarf_block
*)
15735 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15739 static struct abbrev_info
*
15740 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
15742 struct abbrev_info
*abbrev
;
15744 abbrev
= (struct abbrev_info
*)
15745 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
15746 memset (abbrev
, 0, sizeof (struct abbrev_info
));
15750 static struct die_info
*
15751 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15753 struct die_info
*die
;
15754 size_t size
= sizeof (struct die_info
);
15757 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15759 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15760 memset (die
, 0, sizeof (struct die_info
));
15765 /* Macro support. */
15767 /* Return the full name of file number I in *LH's file name table.
15768 Use COMP_DIR as the name of the current directory of the
15769 compilation. The result is allocated using xmalloc; the caller is
15770 responsible for freeing it. */
15772 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15774 /* Is the file number a valid index into the line header's file name
15775 table? Remember that file numbers start with one, not zero. */
15776 if (1 <= file
&& file
<= lh
->num_file_names
)
15778 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15780 if (IS_ABSOLUTE_PATH (fe
->name
))
15781 return xstrdup (fe
->name
);
15789 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15795 dir_len
= strlen (dir
);
15796 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15797 strcpy (full_name
, dir
);
15798 full_name
[dir_len
] = '/';
15799 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15803 return xstrdup (fe
->name
);
15808 /* The compiler produced a bogus file number. We can at least
15809 record the macro definitions made in the file, even if we
15810 won't be able to find the file by name. */
15811 char fake_name
[80];
15813 sprintf (fake_name
, "<bad macro file number %d>", file
);
15815 complaint (&symfile_complaints
,
15816 _("bad file number in macro information (%d)"),
15819 return xstrdup (fake_name
);
15824 static struct macro_source_file
*
15825 macro_start_file (int file
, int line
,
15826 struct macro_source_file
*current_file
,
15827 const char *comp_dir
,
15828 struct line_header
*lh
, struct objfile
*objfile
)
15830 /* The full name of this source file. */
15831 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15833 /* We don't create a macro table for this compilation unit
15834 at all until we actually get a filename. */
15835 if (! pending_macros
)
15836 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15837 objfile
->macro_cache
);
15839 if (! current_file
)
15841 /* If we have no current file, then this must be the start_file
15842 directive for the compilation unit's main source file. */
15843 current_file
= macro_set_main (pending_macros
, full_name
);
15844 macro_define_special (pending_macros
);
15847 current_file
= macro_include (current_file
, line
, full_name
);
15851 return current_file
;
15855 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15856 followed by a null byte. */
15858 copy_string (const char *buf
, int len
)
15860 char *s
= xmalloc (len
+ 1);
15862 memcpy (s
, buf
, len
);
15868 static const char *
15869 consume_improper_spaces (const char *p
, const char *body
)
15873 complaint (&symfile_complaints
,
15874 _("macro definition contains spaces "
15875 "in formal argument list:\n`%s'"),
15887 parse_macro_definition (struct macro_source_file
*file
, int line
,
15892 /* The body string takes one of two forms. For object-like macro
15893 definitions, it should be:
15895 <macro name> " " <definition>
15897 For function-like macro definitions, it should be:
15899 <macro name> "() " <definition>
15901 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
15903 Spaces may appear only where explicitly indicated, and in the
15906 The Dwarf 2 spec says that an object-like macro's name is always
15907 followed by a space, but versions of GCC around March 2002 omit
15908 the space when the macro's definition is the empty string.
15910 The Dwarf 2 spec says that there should be no spaces between the
15911 formal arguments in a function-like macro's formal argument list,
15912 but versions of GCC around March 2002 include spaces after the
15916 /* Find the extent of the macro name. The macro name is terminated
15917 by either a space or null character (for an object-like macro) or
15918 an opening paren (for a function-like macro). */
15919 for (p
= body
; *p
; p
++)
15920 if (*p
== ' ' || *p
== '(')
15923 if (*p
== ' ' || *p
== '\0')
15925 /* It's an object-like macro. */
15926 int name_len
= p
- body
;
15927 char *name
= copy_string (body
, name_len
);
15928 const char *replacement
;
15931 replacement
= body
+ name_len
+ 1;
15934 dwarf2_macro_malformed_definition_complaint (body
);
15935 replacement
= body
+ name_len
;
15938 macro_define_object (file
, line
, name
, replacement
);
15942 else if (*p
== '(')
15944 /* It's a function-like macro. */
15945 char *name
= copy_string (body
, p
- body
);
15948 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
15952 p
= consume_improper_spaces (p
, body
);
15954 /* Parse the formal argument list. */
15955 while (*p
&& *p
!= ')')
15957 /* Find the extent of the current argument name. */
15958 const char *arg_start
= p
;
15960 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
15963 if (! *p
|| p
== arg_start
)
15964 dwarf2_macro_malformed_definition_complaint (body
);
15967 /* Make sure argv has room for the new argument. */
15968 if (argc
>= argv_size
)
15971 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
15974 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
15977 p
= consume_improper_spaces (p
, body
);
15979 /* Consume the comma, if present. */
15984 p
= consume_improper_spaces (p
, body
);
15993 /* Perfectly formed definition, no complaints. */
15994 macro_define_function (file
, line
, name
,
15995 argc
, (const char **) argv
,
15997 else if (*p
== '\0')
15999 /* Complain, but do define it. */
16000 dwarf2_macro_malformed_definition_complaint (body
);
16001 macro_define_function (file
, line
, name
,
16002 argc
, (const char **) argv
,
16006 /* Just complain. */
16007 dwarf2_macro_malformed_definition_complaint (body
);
16010 /* Just complain. */
16011 dwarf2_macro_malformed_definition_complaint (body
);
16017 for (i
= 0; i
< argc
; i
++)
16023 dwarf2_macro_malformed_definition_complaint (body
);
16026 /* Skip some bytes from BYTES according to the form given in FORM.
16027 Returns the new pointer. */
16030 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16031 enum dwarf_form form
,
16032 unsigned int offset_size
,
16033 struct dwarf2_section_info
*section
)
16035 unsigned int bytes_read
;
16039 case DW_FORM_data1
:
16044 case DW_FORM_data2
:
16048 case DW_FORM_data4
:
16052 case DW_FORM_data8
:
16056 case DW_FORM_string
:
16057 read_direct_string (abfd
, bytes
, &bytes_read
);
16058 bytes
+= bytes_read
;
16061 case DW_FORM_sec_offset
:
16063 bytes
+= offset_size
;
16066 case DW_FORM_block
:
16067 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16068 bytes
+= bytes_read
;
16071 case DW_FORM_block1
:
16072 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16074 case DW_FORM_block2
:
16075 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16077 case DW_FORM_block4
:
16078 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16081 case DW_FORM_sdata
:
16082 case DW_FORM_udata
:
16083 case DW_FORM_GNU_addr_index
:
16084 case DW_FORM_GNU_str_index
:
16085 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16088 dwarf2_section_buffer_overflow_complaint (section
);
16096 complaint (&symfile_complaints
,
16097 _("invalid form 0x%x in `%s'"),
16099 section
->asection
->name
);
16107 /* A helper for dwarf_decode_macros that handles skipping an unknown
16108 opcode. Returns an updated pointer to the macro data buffer; or,
16109 on error, issues a complaint and returns NULL. */
16112 skip_unknown_opcode (unsigned int opcode
,
16113 gdb_byte
**opcode_definitions
,
16114 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16116 unsigned int offset_size
,
16117 struct dwarf2_section_info
*section
)
16119 unsigned int bytes_read
, i
;
16123 if (opcode_definitions
[opcode
] == NULL
)
16125 complaint (&symfile_complaints
,
16126 _("unrecognized DW_MACFINO opcode 0x%x"),
16131 defn
= opcode_definitions
[opcode
];
16132 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16133 defn
+= bytes_read
;
16135 for (i
= 0; i
< arg
; ++i
)
16137 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16139 if (mac_ptr
== NULL
)
16141 /* skip_form_bytes already issued the complaint. */
16149 /* A helper function which parses the header of a macro section.
16150 If the macro section is the extended (for now called "GNU") type,
16151 then this updates *OFFSET_SIZE. Returns a pointer to just after
16152 the header, or issues a complaint and returns NULL on error. */
16155 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16158 unsigned int *offset_size
,
16159 int section_is_gnu
)
16161 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16163 if (section_is_gnu
)
16165 unsigned int version
, flags
;
16167 version
= read_2_bytes (abfd
, mac_ptr
);
16170 complaint (&symfile_complaints
,
16171 _("unrecognized version `%d' in .debug_macro section"),
16177 flags
= read_1_byte (abfd
, mac_ptr
);
16179 *offset_size
= (flags
& 1) ? 8 : 4;
16181 if ((flags
& 2) != 0)
16182 /* We don't need the line table offset. */
16183 mac_ptr
+= *offset_size
;
16185 /* Vendor opcode descriptions. */
16186 if ((flags
& 4) != 0)
16188 unsigned int i
, count
;
16190 count
= read_1_byte (abfd
, mac_ptr
);
16192 for (i
= 0; i
< count
; ++i
)
16194 unsigned int opcode
, bytes_read
;
16197 opcode
= read_1_byte (abfd
, mac_ptr
);
16199 opcode_definitions
[opcode
] = mac_ptr
;
16200 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16201 mac_ptr
+= bytes_read
;
16210 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16211 including DW_MACRO_GNU_transparent_include. */
16214 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16215 struct macro_source_file
*current_file
,
16216 struct line_header
*lh
, char *comp_dir
,
16217 struct dwarf2_section_info
*section
,
16218 int section_is_gnu
,
16219 unsigned int offset_size
,
16220 struct objfile
*objfile
,
16221 htab_t include_hash
)
16223 enum dwarf_macro_record_type macinfo_type
;
16224 int at_commandline
;
16225 gdb_byte
*opcode_definitions
[256];
16227 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16228 &offset_size
, section_is_gnu
);
16229 if (mac_ptr
== NULL
)
16231 /* We already issued a complaint. */
16235 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16236 GDB is still reading the definitions from command line. First
16237 DW_MACINFO_start_file will need to be ignored as it was already executed
16238 to create CURRENT_FILE for the main source holding also the command line
16239 definitions. On first met DW_MACINFO_start_file this flag is reset to
16240 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16242 at_commandline
= 1;
16246 /* Do we at least have room for a macinfo type byte? */
16247 if (mac_ptr
>= mac_end
)
16249 dwarf2_section_buffer_overflow_complaint (section
);
16253 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16256 /* Note that we rely on the fact that the corresponding GNU and
16257 DWARF constants are the same. */
16258 switch (macinfo_type
)
16260 /* A zero macinfo type indicates the end of the macro
16265 case DW_MACRO_GNU_define
:
16266 case DW_MACRO_GNU_undef
:
16267 case DW_MACRO_GNU_define_indirect
:
16268 case DW_MACRO_GNU_undef_indirect
:
16270 unsigned int bytes_read
;
16275 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16276 mac_ptr
+= bytes_read
;
16278 if (macinfo_type
== DW_MACRO_GNU_define
16279 || macinfo_type
== DW_MACRO_GNU_undef
)
16281 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16282 mac_ptr
+= bytes_read
;
16286 LONGEST str_offset
;
16288 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16289 mac_ptr
+= offset_size
;
16291 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16294 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16295 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16296 if (! current_file
)
16298 /* DWARF violation as no main source is present. */
16299 complaint (&symfile_complaints
,
16300 _("debug info with no main source gives macro %s "
16302 is_define
? _("definition") : _("undefinition"),
16306 if ((line
== 0 && !at_commandline
)
16307 || (line
!= 0 && at_commandline
))
16308 complaint (&symfile_complaints
,
16309 _("debug info gives %s macro %s with %s line %d: %s"),
16310 at_commandline
? _("command-line") : _("in-file"),
16311 is_define
? _("definition") : _("undefinition"),
16312 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16315 parse_macro_definition (current_file
, line
, body
);
16318 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16319 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16320 macro_undef (current_file
, line
, body
);
16325 case DW_MACRO_GNU_start_file
:
16327 unsigned int bytes_read
;
16330 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16331 mac_ptr
+= bytes_read
;
16332 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16333 mac_ptr
+= bytes_read
;
16335 if ((line
== 0 && !at_commandline
)
16336 || (line
!= 0 && at_commandline
))
16337 complaint (&symfile_complaints
,
16338 _("debug info gives source %d included "
16339 "from %s at %s line %d"),
16340 file
, at_commandline
? _("command-line") : _("file"),
16341 line
== 0 ? _("zero") : _("non-zero"), line
);
16343 if (at_commandline
)
16345 /* This DW_MACRO_GNU_start_file was executed in the
16347 at_commandline
= 0;
16350 current_file
= macro_start_file (file
, line
,
16351 current_file
, comp_dir
,
16356 case DW_MACRO_GNU_end_file
:
16357 if (! current_file
)
16358 complaint (&symfile_complaints
,
16359 _("macro debug info has an unmatched "
16360 "`close_file' directive"));
16363 current_file
= current_file
->included_by
;
16364 if (! current_file
)
16366 enum dwarf_macro_record_type next_type
;
16368 /* GCC circa March 2002 doesn't produce the zero
16369 type byte marking the end of the compilation
16370 unit. Complain if it's not there, but exit no
16373 /* Do we at least have room for a macinfo type byte? */
16374 if (mac_ptr
>= mac_end
)
16376 dwarf2_section_buffer_overflow_complaint (section
);
16380 /* We don't increment mac_ptr here, so this is just
16382 next_type
= read_1_byte (abfd
, mac_ptr
);
16383 if (next_type
!= 0)
16384 complaint (&symfile_complaints
,
16385 _("no terminating 0-type entry for "
16386 "macros in `.debug_macinfo' section"));
16393 case DW_MACRO_GNU_transparent_include
:
16398 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16399 mac_ptr
+= offset_size
;
16401 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16404 /* This has actually happened; see
16405 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16406 complaint (&symfile_complaints
,
16407 _("recursive DW_MACRO_GNU_transparent_include in "
16408 ".debug_macro section"));
16414 dwarf_decode_macro_bytes (abfd
,
16415 section
->buffer
+ offset
,
16416 mac_end
, current_file
,
16418 section
, section_is_gnu
,
16419 offset_size
, objfile
, include_hash
);
16421 htab_remove_elt (include_hash
, mac_ptr
);
16426 case DW_MACINFO_vendor_ext
:
16427 if (!section_is_gnu
)
16429 unsigned int bytes_read
;
16432 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16433 mac_ptr
+= bytes_read
;
16434 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16435 mac_ptr
+= bytes_read
;
16437 /* We don't recognize any vendor extensions. */
16443 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16444 mac_ptr
, mac_end
, abfd
, offset_size
,
16446 if (mac_ptr
== NULL
)
16450 } while (macinfo_type
!= 0);
16454 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
16455 char *comp_dir
, int section_is_gnu
)
16457 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16458 struct line_header
*lh
= cu
->line_header
;
16460 gdb_byte
*mac_ptr
, *mac_end
;
16461 struct macro_source_file
*current_file
= 0;
16462 enum dwarf_macro_record_type macinfo_type
;
16463 unsigned int offset_size
= cu
->header
.offset_size
;
16464 gdb_byte
*opcode_definitions
[256];
16465 struct cleanup
*cleanup
;
16466 htab_t include_hash
;
16468 struct dwarf2_section_info
*section
;
16469 const char *section_name
;
16471 if (cu
->dwo_unit
!= NULL
)
16473 if (section_is_gnu
)
16475 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
16476 section_name
= ".debug_macro.dwo";
16480 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
16481 section_name
= ".debug_macinfo.dwo";
16486 if (section_is_gnu
)
16488 section
= &dwarf2_per_objfile
->macro
;
16489 section_name
= ".debug_macro";
16493 section
= &dwarf2_per_objfile
->macinfo
;
16494 section_name
= ".debug_macinfo";
16498 dwarf2_read_section (objfile
, section
);
16499 if (section
->buffer
== NULL
)
16501 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16504 abfd
= section
->asection
->owner
;
16506 /* First pass: Find the name of the base filename.
16507 This filename is needed in order to process all macros whose definition
16508 (or undefinition) comes from the command line. These macros are defined
16509 before the first DW_MACINFO_start_file entry, and yet still need to be
16510 associated to the base file.
16512 To determine the base file name, we scan the macro definitions until we
16513 reach the first DW_MACINFO_start_file entry. We then initialize
16514 CURRENT_FILE accordingly so that any macro definition found before the
16515 first DW_MACINFO_start_file can still be associated to the base file. */
16517 mac_ptr
= section
->buffer
+ offset
;
16518 mac_end
= section
->buffer
+ section
->size
;
16520 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16521 &offset_size
, section_is_gnu
);
16522 if (mac_ptr
== NULL
)
16524 /* We already issued a complaint. */
16530 /* Do we at least have room for a macinfo type byte? */
16531 if (mac_ptr
>= mac_end
)
16533 /* Complaint is printed during the second pass as GDB will probably
16534 stop the first pass earlier upon finding
16535 DW_MACINFO_start_file. */
16539 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16542 /* Note that we rely on the fact that the corresponding GNU and
16543 DWARF constants are the same. */
16544 switch (macinfo_type
)
16546 /* A zero macinfo type indicates the end of the macro
16551 case DW_MACRO_GNU_define
:
16552 case DW_MACRO_GNU_undef
:
16553 /* Only skip the data by MAC_PTR. */
16555 unsigned int bytes_read
;
16557 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16558 mac_ptr
+= bytes_read
;
16559 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16560 mac_ptr
+= bytes_read
;
16564 case DW_MACRO_GNU_start_file
:
16566 unsigned int bytes_read
;
16569 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16570 mac_ptr
+= bytes_read
;
16571 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16572 mac_ptr
+= bytes_read
;
16574 current_file
= macro_start_file (file
, line
, current_file
,
16575 comp_dir
, lh
, objfile
);
16579 case DW_MACRO_GNU_end_file
:
16580 /* No data to skip by MAC_PTR. */
16583 case DW_MACRO_GNU_define_indirect
:
16584 case DW_MACRO_GNU_undef_indirect
:
16586 unsigned int bytes_read
;
16588 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16589 mac_ptr
+= bytes_read
;
16590 mac_ptr
+= offset_size
;
16594 case DW_MACRO_GNU_transparent_include
:
16595 /* Note that, according to the spec, a transparent include
16596 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16597 skip this opcode. */
16598 mac_ptr
+= offset_size
;
16601 case DW_MACINFO_vendor_ext
:
16602 /* Only skip the data by MAC_PTR. */
16603 if (!section_is_gnu
)
16605 unsigned int bytes_read
;
16607 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16608 mac_ptr
+= bytes_read
;
16609 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16610 mac_ptr
+= bytes_read
;
16615 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16616 mac_ptr
, mac_end
, abfd
, offset_size
,
16618 if (mac_ptr
== NULL
)
16622 } while (macinfo_type
!= 0 && current_file
== NULL
);
16624 /* Second pass: Process all entries.
16626 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16627 command-line macro definitions/undefinitions. This flag is unset when we
16628 reach the first DW_MACINFO_start_file entry. */
16630 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16631 NULL
, xcalloc
, xfree
);
16632 cleanup
= make_cleanup_htab_delete (include_hash
);
16633 mac_ptr
= section
->buffer
+ offset
;
16634 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16636 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16637 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16638 offset_size
, objfile
, include_hash
);
16639 do_cleanups (cleanup
);
16642 /* Check if the attribute's form is a DW_FORM_block*
16643 if so return true else false. */
16646 attr_form_is_block (struct attribute
*attr
)
16648 return (attr
== NULL
? 0 :
16649 attr
->form
== DW_FORM_block1
16650 || attr
->form
== DW_FORM_block2
16651 || attr
->form
== DW_FORM_block4
16652 || attr
->form
== DW_FORM_block
16653 || attr
->form
== DW_FORM_exprloc
);
16656 /* Return non-zero if ATTR's value is a section offset --- classes
16657 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16658 You may use DW_UNSND (attr) to retrieve such offsets.
16660 Section 7.5.4, "Attribute Encodings", explains that no attribute
16661 may have a value that belongs to more than one of these classes; it
16662 would be ambiguous if we did, because we use the same forms for all
16666 attr_form_is_section_offset (struct attribute
*attr
)
16668 return (attr
->form
== DW_FORM_data4
16669 || attr
->form
== DW_FORM_data8
16670 || attr
->form
== DW_FORM_sec_offset
);
16673 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16674 zero otherwise. When this function returns true, you can apply
16675 dwarf2_get_attr_constant_value to it.
16677 However, note that for some attributes you must check
16678 attr_form_is_section_offset before using this test. DW_FORM_data4
16679 and DW_FORM_data8 are members of both the constant class, and of
16680 the classes that contain offsets into other debug sections
16681 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16682 that, if an attribute's can be either a constant or one of the
16683 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16684 taken as section offsets, not constants. */
16687 attr_form_is_constant (struct attribute
*attr
)
16689 switch (attr
->form
)
16691 case DW_FORM_sdata
:
16692 case DW_FORM_udata
:
16693 case DW_FORM_data1
:
16694 case DW_FORM_data2
:
16695 case DW_FORM_data4
:
16696 case DW_FORM_data8
:
16703 /* Return the .debug_loc section to use for CU.
16704 For DWO files use .debug_loc.dwo. */
16706 static struct dwarf2_section_info
*
16707 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16710 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16711 return &dwarf2_per_objfile
->loc
;
16714 /* A helper function that fills in a dwarf2_loclist_baton. */
16717 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16718 struct dwarf2_loclist_baton
*baton
,
16719 struct attribute
*attr
)
16721 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16723 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16725 baton
->per_cu
= cu
->per_cu
;
16726 gdb_assert (baton
->per_cu
);
16727 /* We don't know how long the location list is, but make sure we
16728 don't run off the edge of the section. */
16729 baton
->size
= section
->size
- DW_UNSND (attr
);
16730 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16731 baton
->base_address
= cu
->base_address
;
16732 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16736 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16737 struct dwarf2_cu
*cu
)
16739 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16740 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16742 if (attr_form_is_section_offset (attr
)
16743 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16744 the section. If so, fall through to the complaint in the
16746 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16748 struct dwarf2_loclist_baton
*baton
;
16750 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16751 sizeof (struct dwarf2_loclist_baton
));
16753 fill_in_loclist_baton (cu
, baton
, attr
);
16755 if (cu
->base_known
== 0)
16756 complaint (&symfile_complaints
,
16757 _("Location list used without "
16758 "specifying the CU base address."));
16760 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16761 SYMBOL_LOCATION_BATON (sym
) = baton
;
16765 struct dwarf2_locexpr_baton
*baton
;
16767 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16768 sizeof (struct dwarf2_locexpr_baton
));
16769 baton
->per_cu
= cu
->per_cu
;
16770 gdb_assert (baton
->per_cu
);
16772 if (attr_form_is_block (attr
))
16774 /* Note that we're just copying the block's data pointer
16775 here, not the actual data. We're still pointing into the
16776 info_buffer for SYM's objfile; right now we never release
16777 that buffer, but when we do clean up properly this may
16779 baton
->size
= DW_BLOCK (attr
)->size
;
16780 baton
->data
= DW_BLOCK (attr
)->data
;
16784 dwarf2_invalid_attrib_class_complaint ("location description",
16785 SYMBOL_NATURAL_NAME (sym
));
16789 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16790 SYMBOL_LOCATION_BATON (sym
) = baton
;
16794 /* Return the OBJFILE associated with the compilation unit CU. If CU
16795 came from a separate debuginfo file, then the master objfile is
16799 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16801 struct objfile
*objfile
= per_cu
->objfile
;
16803 /* Return the master objfile, so that we can report and look up the
16804 correct file containing this variable. */
16805 if (objfile
->separate_debug_objfile_backlink
)
16806 objfile
= objfile
->separate_debug_objfile_backlink
;
16811 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16812 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16813 CU_HEADERP first. */
16815 static const struct comp_unit_head
*
16816 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16817 struct dwarf2_per_cu_data
*per_cu
)
16819 gdb_byte
*info_ptr
;
16822 return &per_cu
->cu
->header
;
16824 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
16826 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16827 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
16832 /* Return the address size given in the compilation unit header for CU. */
16835 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16837 struct comp_unit_head cu_header_local
;
16838 const struct comp_unit_head
*cu_headerp
;
16840 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16842 return cu_headerp
->addr_size
;
16845 /* Return the offset size given in the compilation unit header for CU. */
16848 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16850 struct comp_unit_head cu_header_local
;
16851 const struct comp_unit_head
*cu_headerp
;
16853 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16855 return cu_headerp
->offset_size
;
16858 /* See its dwarf2loc.h declaration. */
16861 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16863 struct comp_unit_head cu_header_local
;
16864 const struct comp_unit_head
*cu_headerp
;
16866 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16868 if (cu_headerp
->version
== 2)
16869 return cu_headerp
->addr_size
;
16871 return cu_headerp
->offset_size
;
16874 /* Return the text offset of the CU. The returned offset comes from
16875 this CU's objfile. If this objfile came from a separate debuginfo
16876 file, then the offset may be different from the corresponding
16877 offset in the parent objfile. */
16880 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
16882 struct objfile
*objfile
= per_cu
->objfile
;
16884 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
16887 /* Locate the .debug_info compilation unit from CU's objfile which contains
16888 the DIE at OFFSET. Raises an error on failure. */
16890 static struct dwarf2_per_cu_data
*
16891 dwarf2_find_containing_comp_unit (sect_offset offset
,
16892 struct objfile
*objfile
)
16894 struct dwarf2_per_cu_data
*this_cu
;
16898 high
= dwarf2_per_objfile
->n_comp_units
- 1;
16901 int mid
= low
+ (high
- low
) / 2;
16903 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
16904 >= offset
.sect_off
)
16909 gdb_assert (low
== high
);
16910 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
16914 error (_("Dwarf Error: could not find partial DIE containing "
16915 "offset 0x%lx [in module %s]"),
16916 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
16918 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
16919 <= offset
.sect_off
);
16920 return dwarf2_per_objfile
->all_comp_units
[low
-1];
16924 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
16925 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
16926 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
16927 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
16928 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
16933 /* Initialize dwarf2_cu CU, owned by PER_CU. */
16936 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
16938 memset (cu
, 0, sizeof (*cu
));
16940 cu
->per_cu
= per_cu
;
16941 cu
->objfile
= per_cu
->objfile
;
16942 obstack_init (&cu
->comp_unit_obstack
);
16945 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
16948 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
16949 enum language pretend_language
)
16951 struct attribute
*attr
;
16953 /* Set the language we're debugging. */
16954 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
16956 set_cu_language (DW_UNSND (attr
), cu
);
16959 cu
->language
= pretend_language
;
16960 cu
->language_defn
= language_def (cu
->language
);
16963 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
16965 cu
->producer
= DW_STRING (attr
);
16968 /* Release one cached compilation unit, CU. We unlink it from the tree
16969 of compilation units, but we don't remove it from the read_in_chain;
16970 the caller is responsible for that.
16971 NOTE: DATA is a void * because this function is also used as a
16972 cleanup routine. */
16975 free_heap_comp_unit (void *data
)
16977 struct dwarf2_cu
*cu
= data
;
16979 gdb_assert (cu
->per_cu
!= NULL
);
16980 cu
->per_cu
->cu
= NULL
;
16983 obstack_free (&cu
->comp_unit_obstack
, NULL
);
16988 /* This cleanup function is passed the address of a dwarf2_cu on the stack
16989 when we're finished with it. We can't free the pointer itself, but be
16990 sure to unlink it from the cache. Also release any associated storage. */
16993 free_stack_comp_unit (void *data
)
16995 struct dwarf2_cu
*cu
= data
;
16997 gdb_assert (cu
->per_cu
!= NULL
);
16998 cu
->per_cu
->cu
= NULL
;
17001 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17002 cu
->partial_dies
= NULL
;
17005 /* Free all cached compilation units. */
17008 free_cached_comp_units (void *data
)
17010 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17012 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17013 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17014 while (per_cu
!= NULL
)
17016 struct dwarf2_per_cu_data
*next_cu
;
17018 next_cu
= per_cu
->cu
->read_in_chain
;
17020 free_heap_comp_unit (per_cu
->cu
);
17021 *last_chain
= next_cu
;
17027 /* Increase the age counter on each cached compilation unit, and free
17028 any that are too old. */
17031 age_cached_comp_units (void)
17033 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17035 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17036 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17037 while (per_cu
!= NULL
)
17039 per_cu
->cu
->last_used
++;
17040 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17041 dwarf2_mark (per_cu
->cu
);
17042 per_cu
= per_cu
->cu
->read_in_chain
;
17045 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17046 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17047 while (per_cu
!= NULL
)
17049 struct dwarf2_per_cu_data
*next_cu
;
17051 next_cu
= per_cu
->cu
->read_in_chain
;
17053 if (!per_cu
->cu
->mark
)
17055 free_heap_comp_unit (per_cu
->cu
);
17056 *last_chain
= next_cu
;
17059 last_chain
= &per_cu
->cu
->read_in_chain
;
17065 /* Remove a single compilation unit from the cache. */
17068 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17070 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17072 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17073 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17074 while (per_cu
!= NULL
)
17076 struct dwarf2_per_cu_data
*next_cu
;
17078 next_cu
= per_cu
->cu
->read_in_chain
;
17080 if (per_cu
== target_per_cu
)
17082 free_heap_comp_unit (per_cu
->cu
);
17084 *last_chain
= next_cu
;
17088 last_chain
= &per_cu
->cu
->read_in_chain
;
17094 /* Release all extra memory associated with OBJFILE. */
17097 dwarf2_free_objfile (struct objfile
*objfile
)
17099 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17101 if (dwarf2_per_objfile
== NULL
)
17104 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17105 free_cached_comp_units (NULL
);
17107 if (dwarf2_per_objfile
->quick_file_names_table
)
17108 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17110 /* Everything else should be on the objfile obstack. */
17113 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17114 We store these in a hash table separate from the DIEs, and preserve them
17115 when the DIEs are flushed out of cache.
17117 The CU "per_cu" pointer is needed because offset alone is not enough to
17118 uniquely identify the type. A file may have multiple .debug_types sections,
17119 or the type may come from a DWO file. We have to use something in
17120 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17121 routine, get_die_type_at_offset, from outside this file, and thus won't
17122 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17125 struct dwarf2_per_cu_offset_and_type
17127 const struct dwarf2_per_cu_data
*per_cu
;
17128 sect_offset offset
;
17132 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17135 per_cu_offset_and_type_hash (const void *item
)
17137 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17139 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17142 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17145 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17147 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17148 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17150 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17151 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17154 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17155 table if necessary. For convenience, return TYPE.
17157 The DIEs reading must have careful ordering to:
17158 * Not cause infite loops trying to read in DIEs as a prerequisite for
17159 reading current DIE.
17160 * Not trying to dereference contents of still incompletely read in types
17161 while reading in other DIEs.
17162 * Enable referencing still incompletely read in types just by a pointer to
17163 the type without accessing its fields.
17165 Therefore caller should follow these rules:
17166 * Try to fetch any prerequisite types we may need to build this DIE type
17167 before building the type and calling set_die_type.
17168 * After building type call set_die_type for current DIE as soon as
17169 possible before fetching more types to complete the current type.
17170 * Make the type as complete as possible before fetching more types. */
17172 static struct type
*
17173 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17175 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17176 struct objfile
*objfile
= cu
->objfile
;
17178 /* For Ada types, make sure that the gnat-specific data is always
17179 initialized (if not already set). There are a few types where
17180 we should not be doing so, because the type-specific area is
17181 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17182 where the type-specific area is used to store the floatformat).
17183 But this is not a problem, because the gnat-specific information
17184 is actually not needed for these types. */
17185 if (need_gnat_info (cu
)
17186 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17187 && TYPE_CODE (type
) != TYPE_CODE_FLT
17188 && !HAVE_GNAT_AUX_INFO (type
))
17189 INIT_GNAT_SPECIFIC (type
);
17191 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17193 dwarf2_per_objfile
->die_type_hash
=
17194 htab_create_alloc_ex (127,
17195 per_cu_offset_and_type_hash
,
17196 per_cu_offset_and_type_eq
,
17198 &objfile
->objfile_obstack
,
17199 hashtab_obstack_allocate
,
17200 dummy_obstack_deallocate
);
17203 ofs
.per_cu
= cu
->per_cu
;
17204 ofs
.offset
= die
->offset
;
17206 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17207 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17209 complaint (&symfile_complaints
,
17210 _("A problem internal to GDB: DIE 0x%x has type already set"),
17211 die
->offset
.sect_off
);
17212 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17217 /* Look up the type for the die at OFFSET in the appropriate type_hash
17218 table, or return NULL if the die does not have a saved type. */
17220 static struct type
*
17221 get_die_type_at_offset (sect_offset offset
,
17222 struct dwarf2_per_cu_data
*per_cu
)
17224 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17226 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17229 ofs
.per_cu
= per_cu
;
17230 ofs
.offset
= offset
;
17231 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17238 /* Look up the type for DIE in the appropriate type_hash table,
17239 or return NULL if DIE does not have a saved type. */
17241 static struct type
*
17242 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17244 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17247 /* Add a dependence relationship from CU to REF_PER_CU. */
17250 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17251 struct dwarf2_per_cu_data
*ref_per_cu
)
17255 if (cu
->dependencies
== NULL
)
17257 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17258 NULL
, &cu
->comp_unit_obstack
,
17259 hashtab_obstack_allocate
,
17260 dummy_obstack_deallocate
);
17262 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17264 *slot
= ref_per_cu
;
17267 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17268 Set the mark field in every compilation unit in the
17269 cache that we must keep because we are keeping CU. */
17272 dwarf2_mark_helper (void **slot
, void *data
)
17274 struct dwarf2_per_cu_data
*per_cu
;
17276 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17278 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17279 reading of the chain. As such dependencies remain valid it is not much
17280 useful to track and undo them during QUIT cleanups. */
17281 if (per_cu
->cu
== NULL
)
17284 if (per_cu
->cu
->mark
)
17286 per_cu
->cu
->mark
= 1;
17288 if (per_cu
->cu
->dependencies
!= NULL
)
17289 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17294 /* Set the mark field in CU and in every other compilation unit in the
17295 cache that we must keep because we are keeping CU. */
17298 dwarf2_mark (struct dwarf2_cu
*cu
)
17303 if (cu
->dependencies
!= NULL
)
17304 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17308 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17312 per_cu
->cu
->mark
= 0;
17313 per_cu
= per_cu
->cu
->read_in_chain
;
17317 /* Trivial hash function for partial_die_info: the hash value of a DIE
17318 is its offset in .debug_info for this objfile. */
17321 partial_die_hash (const void *item
)
17323 const struct partial_die_info
*part_die
= item
;
17325 return part_die
->offset
.sect_off
;
17328 /* Trivial comparison function for partial_die_info structures: two DIEs
17329 are equal if they have the same offset. */
17332 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17334 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17335 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17337 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17340 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17341 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17344 set_dwarf2_cmd (char *args
, int from_tty
)
17346 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17350 show_dwarf2_cmd (char *args
, int from_tty
)
17352 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17355 /* If section described by INFO was mmapped, munmap it now. */
17358 munmap_section_buffer (struct dwarf2_section_info
*info
)
17360 if (info
->map_addr
!= NULL
)
17365 res
= munmap (info
->map_addr
, info
->map_len
);
17366 gdb_assert (res
== 0);
17368 /* Without HAVE_MMAP, we should never be here to begin with. */
17369 gdb_assert_not_reached ("no mmap support");
17374 /* munmap debug sections for OBJFILE, if necessary. */
17377 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17379 struct dwarf2_per_objfile
*data
= d
;
17381 struct dwarf2_section_info
*section
;
17383 /* This is sorted according to the order they're defined in to make it easier
17384 to keep in sync. */
17385 munmap_section_buffer (&data
->info
);
17386 munmap_section_buffer (&data
->abbrev
);
17387 munmap_section_buffer (&data
->line
);
17388 munmap_section_buffer (&data
->loc
);
17389 munmap_section_buffer (&data
->macinfo
);
17390 munmap_section_buffer (&data
->macro
);
17391 munmap_section_buffer (&data
->str
);
17392 munmap_section_buffer (&data
->ranges
);
17393 munmap_section_buffer (&data
->addr
);
17394 munmap_section_buffer (&data
->frame
);
17395 munmap_section_buffer (&data
->eh_frame
);
17396 munmap_section_buffer (&data
->gdb_index
);
17399 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17401 munmap_section_buffer (section
);
17403 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17404 VEC_free (dwarf2_per_cu_ptr
,
17405 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17407 VEC_free (dwarf2_section_info_def
, data
->types
);
17409 if (data
->dwo_files
)
17410 free_dwo_files (data
->dwo_files
, objfile
);
17414 /* The "save gdb-index" command. */
17416 /* The contents of the hash table we create when building the string
17418 struct strtab_entry
17420 offset_type offset
;
17424 /* Hash function for a strtab_entry.
17426 Function is used only during write_hash_table so no index format backward
17427 compatibility is needed. */
17430 hash_strtab_entry (const void *e
)
17432 const struct strtab_entry
*entry
= e
;
17433 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17436 /* Equality function for a strtab_entry. */
17439 eq_strtab_entry (const void *a
, const void *b
)
17441 const struct strtab_entry
*ea
= a
;
17442 const struct strtab_entry
*eb
= b
;
17443 return !strcmp (ea
->str
, eb
->str
);
17446 /* Create a strtab_entry hash table. */
17449 create_strtab (void)
17451 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17452 xfree
, xcalloc
, xfree
);
17455 /* Add a string to the constant pool. Return the string's offset in
17459 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17462 struct strtab_entry entry
;
17463 struct strtab_entry
*result
;
17466 slot
= htab_find_slot (table
, &entry
, INSERT
);
17471 result
= XNEW (struct strtab_entry
);
17472 result
->offset
= obstack_object_size (cpool
);
17474 obstack_grow_str0 (cpool
, str
);
17477 return result
->offset
;
17480 /* An entry in the symbol table. */
17481 struct symtab_index_entry
17483 /* The name of the symbol. */
17485 /* The offset of the name in the constant pool. */
17486 offset_type index_offset
;
17487 /* A sorted vector of the indices of all the CUs that hold an object
17489 VEC (offset_type
) *cu_indices
;
17492 /* The symbol table. This is a power-of-2-sized hash table. */
17493 struct mapped_symtab
17495 offset_type n_elements
;
17497 struct symtab_index_entry
**data
;
17500 /* Hash function for a symtab_index_entry. */
17503 hash_symtab_entry (const void *e
)
17505 const struct symtab_index_entry
*entry
= e
;
17506 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17507 sizeof (offset_type
) * VEC_length (offset_type
,
17508 entry
->cu_indices
),
17512 /* Equality function for a symtab_index_entry. */
17515 eq_symtab_entry (const void *a
, const void *b
)
17517 const struct symtab_index_entry
*ea
= a
;
17518 const struct symtab_index_entry
*eb
= b
;
17519 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17520 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17522 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17523 VEC_address (offset_type
, eb
->cu_indices
),
17524 sizeof (offset_type
) * len
);
17527 /* Destroy a symtab_index_entry. */
17530 delete_symtab_entry (void *p
)
17532 struct symtab_index_entry
*entry
= p
;
17533 VEC_free (offset_type
, entry
->cu_indices
);
17537 /* Create a hash table holding symtab_index_entry objects. */
17540 create_symbol_hash_table (void)
17542 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17543 delete_symtab_entry
, xcalloc
, xfree
);
17546 /* Create a new mapped symtab object. */
17548 static struct mapped_symtab
*
17549 create_mapped_symtab (void)
17551 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17552 symtab
->n_elements
= 0;
17553 symtab
->size
= 1024;
17554 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17558 /* Destroy a mapped_symtab. */
17561 cleanup_mapped_symtab (void *p
)
17563 struct mapped_symtab
*symtab
= p
;
17564 /* The contents of the array are freed when the other hash table is
17566 xfree (symtab
->data
);
17570 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17573 Function is used only during write_hash_table so no index format backward
17574 compatibility is needed. */
17576 static struct symtab_index_entry
**
17577 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17579 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17581 index
= hash
& (symtab
->size
- 1);
17582 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17586 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17587 return &symtab
->data
[index
];
17588 index
= (index
+ step
) & (symtab
->size
- 1);
17592 /* Expand SYMTAB's hash table. */
17595 hash_expand (struct mapped_symtab
*symtab
)
17597 offset_type old_size
= symtab
->size
;
17599 struct symtab_index_entry
**old_entries
= symtab
->data
;
17602 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17604 for (i
= 0; i
< old_size
; ++i
)
17606 if (old_entries
[i
])
17608 struct symtab_index_entry
**slot
= find_slot (symtab
,
17609 old_entries
[i
]->name
);
17610 *slot
= old_entries
[i
];
17614 xfree (old_entries
);
17617 /* Add an entry to SYMTAB. NAME is the name of the symbol.
17618 CU_INDEX is the index of the CU in which the symbol appears.
17619 IS_STATIC is one if the symbol is static, otherwise zero (global). */
17622 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17623 int is_static
, gdb_index_symbol_kind kind
,
17624 offset_type cu_index
)
17626 struct symtab_index_entry
**slot
;
17627 offset_type cu_index_and_attrs
;
17629 ++symtab
->n_elements
;
17630 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17631 hash_expand (symtab
);
17633 slot
= find_slot (symtab
, name
);
17636 *slot
= XNEW (struct symtab_index_entry
);
17637 (*slot
)->name
= name
;
17638 /* index_offset is set later. */
17639 (*slot
)->cu_indices
= NULL
;
17642 cu_index_and_attrs
= 0;
17643 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
17644 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
17645 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
17647 /* We don't want to record an index value twice as we want to avoid the
17649 We process all global symbols and then all static symbols
17650 (which would allow us to avoid the duplication by only having to check
17651 the last entry pushed), but a symbol could have multiple kinds in one CU.
17652 To keep things simple we don't worry about the duplication here and
17653 sort and uniqufy the list after we've processed all symbols. */
17654 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
17657 /* qsort helper routine for uniquify_cu_indices. */
17660 offset_type_compare (const void *ap
, const void *bp
)
17662 offset_type a
= *(offset_type
*) ap
;
17663 offset_type b
= *(offset_type
*) bp
;
17665 return (a
> b
) - (b
> a
);
17668 /* Sort and remove duplicates of all symbols' cu_indices lists. */
17671 uniquify_cu_indices (struct mapped_symtab
*symtab
)
17675 for (i
= 0; i
< symtab
->size
; ++i
)
17677 struct symtab_index_entry
*entry
= symtab
->data
[i
];
17680 && entry
->cu_indices
!= NULL
)
17682 unsigned int next_to_insert
, next_to_check
;
17683 offset_type last_value
;
17685 qsort (VEC_address (offset_type
, entry
->cu_indices
),
17686 VEC_length (offset_type
, entry
->cu_indices
),
17687 sizeof (offset_type
), offset_type_compare
);
17689 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
17690 next_to_insert
= 1;
17691 for (next_to_check
= 1;
17692 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
17695 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
17698 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
17700 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
17705 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
17710 /* Add a vector of indices to the constant pool. */
17713 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17714 struct symtab_index_entry
*entry
)
17718 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17721 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17722 offset_type val
= MAYBE_SWAP (len
);
17727 entry
->index_offset
= obstack_object_size (cpool
);
17729 obstack_grow (cpool
, &val
, sizeof (val
));
17731 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17734 val
= MAYBE_SWAP (iter
);
17735 obstack_grow (cpool
, &val
, sizeof (val
));
17740 struct symtab_index_entry
*old_entry
= *slot
;
17741 entry
->index_offset
= old_entry
->index_offset
;
17744 return entry
->index_offset
;
17747 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17748 constant pool entries going into the obstack CPOOL. */
17751 write_hash_table (struct mapped_symtab
*symtab
,
17752 struct obstack
*output
, struct obstack
*cpool
)
17755 htab_t symbol_hash_table
;
17758 symbol_hash_table
= create_symbol_hash_table ();
17759 str_table
= create_strtab ();
17761 /* We add all the index vectors to the constant pool first, to
17762 ensure alignment is ok. */
17763 for (i
= 0; i
< symtab
->size
; ++i
)
17765 if (symtab
->data
[i
])
17766 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17769 /* Now write out the hash table. */
17770 for (i
= 0; i
< symtab
->size
; ++i
)
17772 offset_type str_off
, vec_off
;
17774 if (symtab
->data
[i
])
17776 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17777 vec_off
= symtab
->data
[i
]->index_offset
;
17781 /* While 0 is a valid constant pool index, it is not valid
17782 to have 0 for both offsets. */
17787 str_off
= MAYBE_SWAP (str_off
);
17788 vec_off
= MAYBE_SWAP (vec_off
);
17790 obstack_grow (output
, &str_off
, sizeof (str_off
));
17791 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17794 htab_delete (str_table
);
17795 htab_delete (symbol_hash_table
);
17798 /* Struct to map psymtab to CU index in the index file. */
17799 struct psymtab_cu_index_map
17801 struct partial_symtab
*psymtab
;
17802 unsigned int cu_index
;
17806 hash_psymtab_cu_index (const void *item
)
17808 const struct psymtab_cu_index_map
*map
= item
;
17810 return htab_hash_pointer (map
->psymtab
);
17814 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17816 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17817 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17819 return lhs
->psymtab
== rhs
->psymtab
;
17822 /* Helper struct for building the address table. */
17823 struct addrmap_index_data
17825 struct objfile
*objfile
;
17826 struct obstack
*addr_obstack
;
17827 htab_t cu_index_htab
;
17829 /* Non-zero if the previous_* fields are valid.
17830 We can't write an entry until we see the next entry (since it is only then
17831 that we know the end of the entry). */
17832 int previous_valid
;
17833 /* Index of the CU in the table of all CUs in the index file. */
17834 unsigned int previous_cu_index
;
17835 /* Start address of the CU. */
17836 CORE_ADDR previous_cu_start
;
17839 /* Write an address entry to OBSTACK. */
17842 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17843 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17845 offset_type cu_index_to_write
;
17847 CORE_ADDR baseaddr
;
17849 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17851 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17852 obstack_grow (obstack
, addr
, 8);
17853 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17854 obstack_grow (obstack
, addr
, 8);
17855 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17856 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17859 /* Worker function for traversing an addrmap to build the address table. */
17862 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17864 struct addrmap_index_data
*data
= datap
;
17865 struct partial_symtab
*pst
= obj
;
17867 if (data
->previous_valid
)
17868 add_address_entry (data
->objfile
, data
->addr_obstack
,
17869 data
->previous_cu_start
, start_addr
,
17870 data
->previous_cu_index
);
17872 data
->previous_cu_start
= start_addr
;
17875 struct psymtab_cu_index_map find_map
, *map
;
17876 find_map
.psymtab
= pst
;
17877 map
= htab_find (data
->cu_index_htab
, &find_map
);
17878 gdb_assert (map
!= NULL
);
17879 data
->previous_cu_index
= map
->cu_index
;
17880 data
->previous_valid
= 1;
17883 data
->previous_valid
= 0;
17888 /* Write OBJFILE's address map to OBSTACK.
17889 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
17890 in the index file. */
17893 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
17894 htab_t cu_index_htab
)
17896 struct addrmap_index_data addrmap_index_data
;
17898 /* When writing the address table, we have to cope with the fact that
17899 the addrmap iterator only provides the start of a region; we have to
17900 wait until the next invocation to get the start of the next region. */
17902 addrmap_index_data
.objfile
= objfile
;
17903 addrmap_index_data
.addr_obstack
= obstack
;
17904 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
17905 addrmap_index_data
.previous_valid
= 0;
17907 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
17908 &addrmap_index_data
);
17910 /* It's highly unlikely the last entry (end address = 0xff...ff)
17911 is valid, but we should still handle it.
17912 The end address is recorded as the start of the next region, but that
17913 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
17915 if (addrmap_index_data
.previous_valid
)
17916 add_address_entry (objfile
, obstack
,
17917 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
17918 addrmap_index_data
.previous_cu_index
);
17921 /* Return the symbol kind of PSYM. */
17923 static gdb_index_symbol_kind
17924 symbol_kind (struct partial_symbol
*psym
)
17926 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
17927 enum address_class aclass
= PSYMBOL_CLASS (psym
);
17935 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
17937 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17939 case LOC_CONST_BYTES
:
17940 case LOC_OPTIMIZED_OUT
:
17942 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
17944 /* Note: It's currently impossible to recognize psyms as enum values
17945 short of reading the type info. For now punt. */
17946 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
17948 /* There are other LOC_FOO values that one might want to classify
17949 as variables, but dwarf2read.c doesn't currently use them. */
17950 return GDB_INDEX_SYMBOL_KIND_OTHER
;
17952 case STRUCT_DOMAIN
:
17953 return GDB_INDEX_SYMBOL_KIND_TYPE
;
17955 return GDB_INDEX_SYMBOL_KIND_OTHER
;
17959 /* Add a list of partial symbols to SYMTAB. */
17962 write_psymbols (struct mapped_symtab
*symtab
,
17964 struct partial_symbol
**psymp
,
17966 offset_type cu_index
,
17969 for (; count
-- > 0; ++psymp
)
17971 struct partial_symbol
*psym
= *psymp
;
17974 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
17975 error (_("Ada is not currently supported by the index"));
17977 /* Only add a given psymbol once. */
17978 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
17981 gdb_index_symbol_kind kind
= symbol_kind (psym
);
17984 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
17985 is_static
, kind
, cu_index
);
17990 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
17991 exception if there is an error. */
17994 write_obstack (FILE *file
, struct obstack
*obstack
)
17996 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
17998 != obstack_object_size (obstack
))
17999 error (_("couldn't data write to file"));
18002 /* Unlink a file if the argument is not NULL. */
18005 unlink_if_set (void *p
)
18007 char **filename
= p
;
18009 unlink (*filename
);
18012 /* A helper struct used when iterating over debug_types. */
18013 struct signatured_type_index_data
18015 struct objfile
*objfile
;
18016 struct mapped_symtab
*symtab
;
18017 struct obstack
*types_list
;
18022 /* A helper function that writes a single signatured_type to an
18026 write_one_signatured_type (void **slot
, void *d
)
18028 struct signatured_type_index_data
*info
= d
;
18029 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18030 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18031 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18034 write_psymbols (info
->symtab
,
18036 info
->objfile
->global_psymbols
.list
18037 + psymtab
->globals_offset
,
18038 psymtab
->n_global_syms
, info
->cu_index
,
18040 write_psymbols (info
->symtab
,
18042 info
->objfile
->static_psymbols
.list
18043 + psymtab
->statics_offset
,
18044 psymtab
->n_static_syms
, info
->cu_index
,
18047 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18048 entry
->per_cu
.offset
.sect_off
);
18049 obstack_grow (info
->types_list
, val
, 8);
18050 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18051 entry
->type_offset_in_tu
.cu_off
);
18052 obstack_grow (info
->types_list
, val
, 8);
18053 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18054 obstack_grow (info
->types_list
, val
, 8);
18061 /* Recurse into all "included" dependencies and write their symbols as
18062 if they appeared in this psymtab. */
18065 recursively_write_psymbols (struct objfile
*objfile
,
18066 struct partial_symtab
*psymtab
,
18067 struct mapped_symtab
*symtab
,
18069 offset_type cu_index
)
18073 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18074 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18075 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18076 symtab
, psyms_seen
, cu_index
);
18078 write_psymbols (symtab
,
18080 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18081 psymtab
->n_global_syms
, cu_index
,
18083 write_psymbols (symtab
,
18085 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18086 psymtab
->n_static_syms
, cu_index
,
18090 /* Create an index file for OBJFILE in the directory DIR. */
18093 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18095 struct cleanup
*cleanup
;
18096 char *filename
, *cleanup_filename
;
18097 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18098 struct obstack cu_list
, types_cu_list
;
18101 struct mapped_symtab
*symtab
;
18102 offset_type val
, size_of_contents
, total_len
;
18105 htab_t cu_index_htab
;
18106 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18108 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18111 if (dwarf2_per_objfile
->using_index
)
18112 error (_("Cannot use an index to create the index"));
18114 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18115 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18117 if (stat (objfile
->name
, &st
) < 0)
18118 perror_with_name (objfile
->name
);
18120 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18121 INDEX_SUFFIX
, (char *) NULL
);
18122 cleanup
= make_cleanup (xfree
, filename
);
18124 out_file
= fopen (filename
, "wb");
18126 error (_("Can't open `%s' for writing"), filename
);
18128 cleanup_filename
= filename
;
18129 make_cleanup (unlink_if_set
, &cleanup_filename
);
18131 symtab
= create_mapped_symtab ();
18132 make_cleanup (cleanup_mapped_symtab
, symtab
);
18134 obstack_init (&addr_obstack
);
18135 make_cleanup_obstack_free (&addr_obstack
);
18137 obstack_init (&cu_list
);
18138 make_cleanup_obstack_free (&cu_list
);
18140 obstack_init (&types_cu_list
);
18141 make_cleanup_obstack_free (&types_cu_list
);
18143 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18144 NULL
, xcalloc
, xfree
);
18145 make_cleanup_htab_delete (psyms_seen
);
18147 /* While we're scanning CU's create a table that maps a psymtab pointer
18148 (which is what addrmap records) to its index (which is what is recorded
18149 in the index file). This will later be needed to write the address
18151 cu_index_htab
= htab_create_alloc (100,
18152 hash_psymtab_cu_index
,
18153 eq_psymtab_cu_index
,
18154 NULL
, xcalloc
, xfree
);
18155 make_cleanup_htab_delete (cu_index_htab
);
18156 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18157 xmalloc (sizeof (struct psymtab_cu_index_map
)
18158 * dwarf2_per_objfile
->n_comp_units
);
18159 make_cleanup (xfree
, psymtab_cu_index_map
);
18161 /* The CU list is already sorted, so we don't need to do additional
18162 work here. Also, the debug_types entries do not appear in
18163 all_comp_units, but only in their own hash table. */
18164 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18166 struct dwarf2_per_cu_data
*per_cu
18167 = dwarf2_per_objfile
->all_comp_units
[i
];
18168 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18170 struct psymtab_cu_index_map
*map
;
18173 if (psymtab
->user
== NULL
)
18174 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18176 map
= &psymtab_cu_index_map
[i
];
18177 map
->psymtab
= psymtab
;
18179 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18180 gdb_assert (slot
!= NULL
);
18181 gdb_assert (*slot
== NULL
);
18184 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18185 per_cu
->offset
.sect_off
);
18186 obstack_grow (&cu_list
, val
, 8);
18187 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18188 obstack_grow (&cu_list
, val
, 8);
18191 /* Dump the address map. */
18192 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18194 /* Write out the .debug_type entries, if any. */
18195 if (dwarf2_per_objfile
->signatured_types
)
18197 struct signatured_type_index_data sig_data
;
18199 sig_data
.objfile
= objfile
;
18200 sig_data
.symtab
= symtab
;
18201 sig_data
.types_list
= &types_cu_list
;
18202 sig_data
.psyms_seen
= psyms_seen
;
18203 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18204 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18205 write_one_signatured_type
, &sig_data
);
18208 /* Now that we've processed all symbols we can shrink their cu_indices
18210 uniquify_cu_indices (symtab
);
18212 obstack_init (&constant_pool
);
18213 make_cleanup_obstack_free (&constant_pool
);
18214 obstack_init (&symtab_obstack
);
18215 make_cleanup_obstack_free (&symtab_obstack
);
18216 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18218 obstack_init (&contents
);
18219 make_cleanup_obstack_free (&contents
);
18220 size_of_contents
= 6 * sizeof (offset_type
);
18221 total_len
= size_of_contents
;
18223 /* The version number. */
18224 val
= MAYBE_SWAP (7);
18225 obstack_grow (&contents
, &val
, sizeof (val
));
18227 /* The offset of the CU list from the start of the file. */
18228 val
= MAYBE_SWAP (total_len
);
18229 obstack_grow (&contents
, &val
, sizeof (val
));
18230 total_len
+= obstack_object_size (&cu_list
);
18232 /* The offset of the types CU list from the start of the file. */
18233 val
= MAYBE_SWAP (total_len
);
18234 obstack_grow (&contents
, &val
, sizeof (val
));
18235 total_len
+= obstack_object_size (&types_cu_list
);
18237 /* The offset of the address table from the start of the file. */
18238 val
= MAYBE_SWAP (total_len
);
18239 obstack_grow (&contents
, &val
, sizeof (val
));
18240 total_len
+= obstack_object_size (&addr_obstack
);
18242 /* The offset of the symbol table from the start of the file. */
18243 val
= MAYBE_SWAP (total_len
);
18244 obstack_grow (&contents
, &val
, sizeof (val
));
18245 total_len
+= obstack_object_size (&symtab_obstack
);
18247 /* The offset of the constant pool from the start of the file. */
18248 val
= MAYBE_SWAP (total_len
);
18249 obstack_grow (&contents
, &val
, sizeof (val
));
18250 total_len
+= obstack_object_size (&constant_pool
);
18252 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18254 write_obstack (out_file
, &contents
);
18255 write_obstack (out_file
, &cu_list
);
18256 write_obstack (out_file
, &types_cu_list
);
18257 write_obstack (out_file
, &addr_obstack
);
18258 write_obstack (out_file
, &symtab_obstack
);
18259 write_obstack (out_file
, &constant_pool
);
18263 /* We want to keep the file, so we set cleanup_filename to NULL
18264 here. See unlink_if_set. */
18265 cleanup_filename
= NULL
;
18267 do_cleanups (cleanup
);
18270 /* Implementation of the `save gdb-index' command.
18272 Note that the file format used by this command is documented in the
18273 GDB manual. Any changes here must be documented there. */
18276 save_gdb_index_command (char *arg
, int from_tty
)
18278 struct objfile
*objfile
;
18281 error (_("usage: save gdb-index DIRECTORY"));
18283 ALL_OBJFILES (objfile
)
18287 /* If the objfile does not correspond to an actual file, skip it. */
18288 if (stat (objfile
->name
, &st
) < 0)
18291 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18292 if (dwarf2_per_objfile
)
18294 volatile struct gdb_exception except
;
18296 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18298 write_psymtabs_to_index (objfile
, arg
);
18300 if (except
.reason
< 0)
18301 exception_fprintf (gdb_stderr
, except
,
18302 _("Error while writing index for `%s': "),
18310 int dwarf2_always_disassemble
;
18313 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18314 struct cmd_list_element
*c
, const char *value
)
18316 fprintf_filtered (file
,
18317 _("Whether to always disassemble "
18318 "DWARF expressions is %s.\n"),
18323 show_check_physname (struct ui_file
*file
, int from_tty
,
18324 struct cmd_list_element
*c
, const char *value
)
18326 fprintf_filtered (file
,
18327 _("Whether to check \"physname\" is %s.\n"),
18331 void _initialize_dwarf2_read (void);
18334 _initialize_dwarf2_read (void)
18336 struct cmd_list_element
*c
;
18338 dwarf2_objfile_data_key
18339 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18341 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18342 Set DWARF 2 specific variables.\n\
18343 Configure DWARF 2 variables such as the cache size"),
18344 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18345 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18347 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18348 Show DWARF 2 specific variables\n\
18349 Show DWARF 2 variables such as the cache size"),
18350 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18351 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18353 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18354 &dwarf2_max_cache_age
, _("\
18355 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18356 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18357 A higher limit means that cached compilation units will be stored\n\
18358 in memory longer, and more total memory will be used. Zero disables\n\
18359 caching, which can slow down startup."),
18361 show_dwarf2_max_cache_age
,
18362 &set_dwarf2_cmdlist
,
18363 &show_dwarf2_cmdlist
);
18365 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18366 &dwarf2_always_disassemble
, _("\
18367 Set whether `info address' always disassembles DWARF expressions."), _("\
18368 Show whether `info address' always disassembles DWARF expressions."), _("\
18369 When enabled, DWARF expressions are always printed in an assembly-like\n\
18370 syntax. When disabled, expressions will be printed in a more\n\
18371 conversational style, when possible."),
18373 show_dwarf2_always_disassemble
,
18374 &set_dwarf2_cmdlist
,
18375 &show_dwarf2_cmdlist
);
18377 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
18378 Set debugging of the dwarf2 reader."), _("\
18379 Show debugging of the dwarf2 reader."), _("\
18380 When enabled, debugging messages are printed during dwarf2 reading\n\
18381 and symtab expansion."),
18384 &setdebuglist
, &showdebuglist
);
18386 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18387 Set debugging of the dwarf2 DIE reader."), _("\
18388 Show debugging of the dwarf2 DIE reader."), _("\
18389 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18390 The value is the maximum depth to print."),
18393 &setdebuglist
, &showdebuglist
);
18395 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18396 Set cross-checking of \"physname\" code against demangler."), _("\
18397 Show cross-checking of \"physname\" code against demangler."), _("\
18398 When enabled, GDB's internal \"physname\" code is checked against\n\
18400 NULL
, show_check_physname
,
18401 &setdebuglist
, &showdebuglist
);
18403 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18405 Save a gdb-index file.\n\
18406 Usage: save gdb-index DIRECTORY"),
18408 set_cmd_completer (c
, filename_completer
);