1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
39 #include "gdb-demangle.h"
40 #include "expression.h"
41 #include "filenames.h" /* for DOSish file names */
44 #include "complaints.h"
46 #include "dwarf2expr.h"
47 #include "dwarf2loc.h"
48 #include "cp-support.h"
54 #include "typeprint.h"
57 #include "exceptions.h"
59 #include "completer.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
69 #include "gdb_string.h"
70 #include "gdb_assert.h"
71 #include <sys/types.h>
78 #define MAP_FAILED ((void *) -1)
82 typedef struct symbol
*symbolp
;
85 /* When non-zero, print basic high level tracing messages.
86 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
87 static int dwarf2_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static int dwarf2_die_debug
= 0;
92 /* When non-zero, cross-check physname against demangler. */
93 static int check_physname
= 0;
95 /* When non-zero, do not reject deprecated .gdb_index sections. */
96 int use_deprecated_index_sections
= 0;
100 /* When set, the file that we're processing is known to have debugging
101 info for C++ namespaces. GCC 3.3.x did not produce this information,
102 but later versions do. */
104 static int processing_has_namespace_info
;
106 static const struct objfile_data
*dwarf2_objfile_data_key
;
108 struct dwarf2_section_info
113 /* Not NULL if the section was actually mmapped. */
115 /* Page aligned size of mmapped area. */
116 bfd_size_type map_len
;
117 /* True if we have tried to read this section. */
121 typedef struct dwarf2_section_info dwarf2_section_info_def
;
122 DEF_VEC_O (dwarf2_section_info_def
);
124 /* All offsets in the index are of this type. It must be
125 architecture-independent. */
126 typedef uint32_t offset_type
;
128 DEF_VEC_I (offset_type
);
130 /* Ensure only legit values are used. */
131 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
133 gdb_assert ((unsigned int) (value) <= 1); \
134 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
137 /* Ensure only legit values are used. */
138 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
140 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
141 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
142 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
145 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
146 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
148 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
149 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
152 /* A description of the mapped index. The file format is described in
153 a comment by the code that writes the index. */
156 /* Index data format version. */
159 /* The total length of the buffer. */
162 /* A pointer to the address table data. */
163 const gdb_byte
*address_table
;
165 /* Size of the address table data in bytes. */
166 offset_type address_table_size
;
168 /* The symbol table, implemented as a hash table. */
169 const offset_type
*symbol_table
;
171 /* Size in slots, each slot is 2 offset_types. */
172 offset_type symbol_table_slots
;
174 /* A pointer to the constant pool. */
175 const char *constant_pool
;
178 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
179 DEF_VEC_P (dwarf2_per_cu_ptr
);
181 /* Collection of data recorded per objfile.
182 This hangs off of dwarf2_objfile_data_key. */
184 struct dwarf2_per_objfile
186 struct dwarf2_section_info info
;
187 struct dwarf2_section_info abbrev
;
188 struct dwarf2_section_info line
;
189 struct dwarf2_section_info loc
;
190 struct dwarf2_section_info macinfo
;
191 struct dwarf2_section_info macro
;
192 struct dwarf2_section_info str
;
193 struct dwarf2_section_info ranges
;
194 struct dwarf2_section_info addr
;
195 struct dwarf2_section_info frame
;
196 struct dwarf2_section_info eh_frame
;
197 struct dwarf2_section_info gdb_index
;
199 VEC (dwarf2_section_info_def
) *types
;
202 struct objfile
*objfile
;
204 /* Table of all the compilation units. This is used to locate
205 the target compilation unit of a particular reference. */
206 struct dwarf2_per_cu_data
**all_comp_units
;
208 /* The number of compilation units in ALL_COMP_UNITS. */
211 /* The number of .debug_types-related CUs. */
214 /* The .debug_types-related CUs (TUs). */
215 struct dwarf2_per_cu_data
**all_type_units
;
217 /* A chain of compilation units that are currently read in, so that
218 they can be freed later. */
219 struct dwarf2_per_cu_data
*read_in_chain
;
221 /* A table mapping .debug_types signatures to its signatured_type entry.
222 This is NULL if the .debug_types section hasn't been read in yet. */
223 htab_t signatured_types
;
225 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
226 This is NULL if the table hasn't been allocated yet. */
229 /* A flag indicating wether this objfile has a section loaded at a
231 int has_section_at_zero
;
233 /* True if we are using the mapped index,
234 or we are faking it for OBJF_READNOW's sake. */
235 unsigned char using_index
;
237 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
238 struct mapped_index
*index_table
;
240 /* When using index_table, this keeps track of all quick_file_names entries.
241 TUs can share line table entries with CUs or other TUs, and there can be
242 a lot more TUs than unique line tables, so we maintain a separate table
243 of all line table entries to support the sharing. */
244 htab_t quick_file_names_table
;
246 /* Set during partial symbol reading, to prevent queueing of full
248 int reading_partial_symbols
;
250 /* Table mapping type DIEs to their struct type *.
251 This is NULL if not allocated yet.
252 The mapping is done via (CU/TU signature + DIE offset) -> type. */
253 htab_t die_type_hash
;
255 /* The CUs we recently read. */
256 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
259 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
261 /* Default names of the debugging sections. */
263 /* Note that if the debugging section has been compressed, it might
264 have a name like .zdebug_info. */
266 static const struct dwarf2_debug_sections dwarf2_elf_names
=
268 { ".debug_info", ".zdebug_info" },
269 { ".debug_abbrev", ".zdebug_abbrev" },
270 { ".debug_line", ".zdebug_line" },
271 { ".debug_loc", ".zdebug_loc" },
272 { ".debug_macinfo", ".zdebug_macinfo" },
273 { ".debug_macro", ".zdebug_macro" },
274 { ".debug_str", ".zdebug_str" },
275 { ".debug_ranges", ".zdebug_ranges" },
276 { ".debug_types", ".zdebug_types" },
277 { ".debug_addr", ".zdebug_addr" },
278 { ".debug_frame", ".zdebug_frame" },
279 { ".eh_frame", NULL
},
280 { ".gdb_index", ".zgdb_index" },
284 /* List of DWO sections. */
286 static const struct dwo_section_names
288 struct dwarf2_section_names abbrev_dwo
;
289 struct dwarf2_section_names info_dwo
;
290 struct dwarf2_section_names line_dwo
;
291 struct dwarf2_section_names loc_dwo
;
292 struct dwarf2_section_names macinfo_dwo
;
293 struct dwarf2_section_names macro_dwo
;
294 struct dwarf2_section_names str_dwo
;
295 struct dwarf2_section_names str_offsets_dwo
;
296 struct dwarf2_section_names types_dwo
;
300 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
301 { ".debug_info.dwo", ".zdebug_info.dwo" },
302 { ".debug_line.dwo", ".zdebug_line.dwo" },
303 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
304 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
305 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
306 { ".debug_str.dwo", ".zdebug_str.dwo" },
307 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
308 { ".debug_types.dwo", ".zdebug_types.dwo" },
311 /* local data types */
313 /* The data in a compilation unit header, after target2host
314 translation, looks like this. */
315 struct comp_unit_head
319 unsigned char addr_size
;
320 unsigned char signed_addr_p
;
321 sect_offset abbrev_offset
;
323 /* Size of file offsets; either 4 or 8. */
324 unsigned int offset_size
;
326 /* Size of the length field; either 4 or 12. */
327 unsigned int initial_length_size
;
329 /* Offset to the first byte of this compilation unit header in the
330 .debug_info section, for resolving relative reference dies. */
333 /* Offset to first die in this cu from the start of the cu.
334 This will be the first byte following the compilation unit header. */
335 cu_offset first_die_offset
;
338 /* Type used for delaying computation of method physnames.
339 See comments for compute_delayed_physnames. */
340 struct delayed_method_info
342 /* The type to which the method is attached, i.e., its parent class. */
345 /* The index of the method in the type's function fieldlists. */
348 /* The index of the method in the fieldlist. */
351 /* The name of the DIE. */
354 /* The DIE associated with this method. */
355 struct die_info
*die
;
358 typedef struct delayed_method_info delayed_method_info
;
359 DEF_VEC_O (delayed_method_info
);
361 /* Internal state when decoding a particular compilation unit. */
364 /* The objfile containing this compilation unit. */
365 struct objfile
*objfile
;
367 /* The header of the compilation unit. */
368 struct comp_unit_head header
;
370 /* Base address of this compilation unit. */
371 CORE_ADDR base_address
;
373 /* Non-zero if base_address has been set. */
376 /* The language we are debugging. */
377 enum language language
;
378 const struct language_defn
*language_defn
;
380 const char *producer
;
382 /* The generic symbol table building routines have separate lists for
383 file scope symbols and all all other scopes (local scopes). So
384 we need to select the right one to pass to add_symbol_to_list().
385 We do it by keeping a pointer to the correct list in list_in_scope.
387 FIXME: The original dwarf code just treated the file scope as the
388 first local scope, and all other local scopes as nested local
389 scopes, and worked fine. Check to see if we really need to
390 distinguish these in buildsym.c. */
391 struct pending
**list_in_scope
;
393 /* The abbrev table for this CU.
394 Normally this points to the abbrev table in the objfile.
395 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
396 struct abbrev_table
*abbrev_table
;
398 /* Hash table holding all the loaded partial DIEs
399 with partial_die->offset.SECT_OFF as hash. */
402 /* Storage for things with the same lifetime as this read-in compilation
403 unit, including partial DIEs. */
404 struct obstack comp_unit_obstack
;
406 /* When multiple dwarf2_cu structures are living in memory, this field
407 chains them all together, so that they can be released efficiently.
408 We will probably also want a generation counter so that most-recently-used
409 compilation units are cached... */
410 struct dwarf2_per_cu_data
*read_in_chain
;
412 /* Backchain to our per_cu entry if the tree has been built. */
413 struct dwarf2_per_cu_data
*per_cu
;
415 /* How many compilation units ago was this CU last referenced? */
418 /* A hash table of DIE cu_offset for following references with
419 die_info->offset.sect_off as hash. */
422 /* Full DIEs if read in. */
423 struct die_info
*dies
;
425 /* A set of pointers to dwarf2_per_cu_data objects for compilation
426 units referenced by this one. Only set during full symbol processing;
427 partial symbol tables do not have dependencies. */
430 /* Header data from the line table, during full symbol processing. */
431 struct line_header
*line_header
;
433 /* A list of methods which need to have physnames computed
434 after all type information has been read. */
435 VEC (delayed_method_info
) *method_list
;
437 /* To be copied to symtab->call_site_htab. */
438 htab_t call_site_htab
;
440 /* Non-NULL if this CU came from a DWO file.
441 There is an invariant here that is important to remember:
442 Except for attributes copied from the top level DIE in the "main"
443 (or "stub") file in preparation for reading the DWO file
444 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
445 Either there isn't a DWO file (in which case this is NULL and the point
446 is moot), or there is and either we're not going to read it (in which
447 case this is NULL) or there is and we are reading it (in which case this
449 struct dwo_unit
*dwo_unit
;
451 /* The DW_AT_addr_base attribute if present, zero otherwise
452 (zero is a valid value though).
453 Note this value comes from the stub CU/TU's DIE. */
456 /* The DW_AT_ranges_base attribute if present, zero otherwise
457 (zero is a valid value though).
458 Note this value comes from the stub CU/TU's DIE.
459 Also note that the value is zero in the non-DWO case so this value can
460 be used without needing to know whether DWO files are in use or not. */
461 ULONGEST ranges_base
;
463 /* Mark used when releasing cached dies. */
464 unsigned int mark
: 1;
466 /* This CU references .debug_loc. See the symtab->locations_valid field.
467 This test is imperfect as there may exist optimized debug code not using
468 any location list and still facing inlining issues if handled as
469 unoptimized code. For a future better test see GCC PR other/32998. */
470 unsigned int has_loclist
: 1;
472 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
473 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
474 are valid. This information is cached because profiling CU expansion
475 showed excessive time spent in producer_is_gxx_lt_4_6. */
476 unsigned int checked_producer
: 1;
477 unsigned int producer_is_gxx_lt_4_6
: 1;
478 unsigned int producer_is_icc
: 1;
481 /* Persistent data held for a compilation unit, even when not
482 processing it. We put a pointer to this structure in the
483 read_symtab_private field of the psymtab. */
485 struct dwarf2_per_cu_data
487 /* The start offset and length of this compilation unit. 2**29-1
488 bytes should suffice to store the length of any compilation unit
489 - if it doesn't, GDB will fall over anyway.
490 NOTE: Unlike comp_unit_head.length, this length includes
492 If the DIE refers to a DWO file, this is always of the original die,
495 unsigned int length
: 29;
497 /* Flag indicating this compilation unit will be read in before
498 any of the current compilation units are processed. */
499 unsigned int queued
: 1;
501 /* This flag will be set when reading partial DIEs if we need to load
502 absolutely all DIEs for this compilation unit, instead of just the ones
503 we think are interesting. It gets set if we look for a DIE in the
504 hash table and don't find it. */
505 unsigned int load_all_dies
: 1;
507 /* Non-zero if this CU is from .debug_types. */
508 unsigned int is_debug_types
: 1;
510 /* The section this CU/TU lives in.
511 If the DIE refers to a DWO file, this is always the original die,
513 struct dwarf2_section_info
*info_or_types_section
;
515 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
516 of the CU cache it gets reset to NULL again. */
517 struct dwarf2_cu
*cu
;
519 /* The corresponding objfile.
520 Normally we can get the objfile from dwarf2_per_objfile.
521 However we can enter this file with just a "per_cu" handle. */
522 struct objfile
*objfile
;
524 /* When using partial symbol tables, the 'psymtab' field is active.
525 Otherwise the 'quick' field is active. */
528 /* The partial symbol table associated with this compilation unit,
529 or NULL for unread partial units. */
530 struct partial_symtab
*psymtab
;
532 /* Data needed by the "quick" functions. */
533 struct dwarf2_per_cu_quick_data
*quick
;
536 /* The CUs we import using DW_TAG_imported_unit. This is filled in
537 while reading psymtabs, used to compute the psymtab dependencies,
538 and then cleared. Then it is filled in again while reading full
539 symbols, and only deleted when the objfile is destroyed. */
540 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
543 /* Entry in the signatured_types hash table. */
545 struct signatured_type
547 /* The "per_cu" object of this type.
548 N.B.: This is the first member so that it's easy to convert pointers
550 struct dwarf2_per_cu_data per_cu
;
552 /* The type's signature. */
555 /* Offset in the TU of the type's DIE, as read from the TU header.
556 If the definition lives in a DWO file, this value is unusable. */
557 cu_offset type_offset_in_tu
;
559 /* Offset in the section of the type's DIE.
560 If the definition lives in a DWO file, this is the offset in the
561 .debug_types.dwo section.
562 The value is zero until the actual value is known.
563 Zero is otherwise not a valid section offset. */
564 sect_offset type_offset_in_section
;
567 /* These sections are what may appear in a "dwo" file. */
571 struct dwarf2_section_info abbrev
;
572 struct dwarf2_section_info info
;
573 struct dwarf2_section_info line
;
574 struct dwarf2_section_info loc
;
575 struct dwarf2_section_info macinfo
;
576 struct dwarf2_section_info macro
;
577 struct dwarf2_section_info str
;
578 struct dwarf2_section_info str_offsets
;
579 VEC (dwarf2_section_info_def
) *types
;
582 /* Common bits of DWO CUs/TUs. */
586 /* Backlink to the containing struct dwo_file. */
587 struct dwo_file
*dwo_file
;
589 /* The "id" that distinguishes this CU/TU.
590 .debug_info calls this "dwo_id", .debug_types calls this "signature".
591 Since signatures came first, we stick with it for consistency. */
594 /* The section this CU/TU lives in, in the DWO file. */
595 struct dwarf2_section_info
*info_or_types_section
;
597 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
601 /* For types, offset in the type's DIE of the type defined by this TU. */
602 cu_offset type_offset_in_tu
;
605 /* Data for one DWO file. */
609 /* The DW_AT_GNU_dwo_name attribute.
610 We don't manage space for this, it's an attribute. */
611 const char *dwo_name
;
613 /* The bfd, when the file is open. Otherwise this is NULL. */
616 /* Section info for this file. */
617 struct dwo_sections sections
;
619 /* Table of CUs in the file.
620 Each element is a struct dwo_unit. */
623 /* Table of TUs in the file.
624 Each element is a struct dwo_unit. */
628 /* Struct used to pass misc. parameters to read_die_and_children, et
629 al. which are used for both .debug_info and .debug_types dies.
630 All parameters here are unchanging for the life of the call. This
631 struct exists to abstract away the constant parameters of die reading. */
633 struct die_reader_specs
635 /* die_section->asection->owner. */
638 /* The CU of the DIE we are parsing. */
639 struct dwarf2_cu
*cu
;
641 /* Non-NULL if reading a DWO file. */
642 struct dwo_file
*dwo_file
;
644 /* The section the die comes from.
645 This is either .debug_info or .debug_types, or the .dwo variants. */
646 struct dwarf2_section_info
*die_section
;
648 /* die_section->buffer. */
651 /* The end of the buffer. */
652 const gdb_byte
*buffer_end
;
655 /* Type of function passed to init_cutu_and_read_dies, et.al. */
656 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
658 struct die_info
*comp_unit_die
,
662 /* The line number information for a compilation unit (found in the
663 .debug_line section) begins with a "statement program header",
664 which contains the following information. */
667 unsigned int total_length
;
668 unsigned short version
;
669 unsigned int header_length
;
670 unsigned char minimum_instruction_length
;
671 unsigned char maximum_ops_per_instruction
;
672 unsigned char default_is_stmt
;
674 unsigned char line_range
;
675 unsigned char opcode_base
;
677 /* standard_opcode_lengths[i] is the number of operands for the
678 standard opcode whose value is i. This means that
679 standard_opcode_lengths[0] is unused, and the last meaningful
680 element is standard_opcode_lengths[opcode_base - 1]. */
681 unsigned char *standard_opcode_lengths
;
683 /* The include_directories table. NOTE! These strings are not
684 allocated with xmalloc; instead, they are pointers into
685 debug_line_buffer. If you try to free them, `free' will get
687 unsigned int num_include_dirs
, include_dirs_size
;
690 /* The file_names table. NOTE! These strings are not allocated
691 with xmalloc; instead, they are pointers into debug_line_buffer.
692 Don't try to free them directly. */
693 unsigned int num_file_names
, file_names_size
;
697 unsigned int dir_index
;
698 unsigned int mod_time
;
700 int included_p
; /* Non-zero if referenced by the Line Number Program. */
701 struct symtab
*symtab
; /* The associated symbol table, if any. */
704 /* The start and end of the statement program following this
705 header. These point into dwarf2_per_objfile->line_buffer. */
706 gdb_byte
*statement_program_start
, *statement_program_end
;
709 /* When we construct a partial symbol table entry we only
710 need this much information. */
711 struct partial_die_info
713 /* Offset of this DIE. */
716 /* DWARF-2 tag for this DIE. */
717 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
719 /* Assorted flags describing the data found in this DIE. */
720 unsigned int has_children
: 1;
721 unsigned int is_external
: 1;
722 unsigned int is_declaration
: 1;
723 unsigned int has_type
: 1;
724 unsigned int has_specification
: 1;
725 unsigned int has_pc_info
: 1;
726 unsigned int may_be_inlined
: 1;
728 /* Flag set if the SCOPE field of this structure has been
730 unsigned int scope_set
: 1;
732 /* Flag set if the DIE has a byte_size attribute. */
733 unsigned int has_byte_size
: 1;
735 /* Flag set if any of the DIE's children are template arguments. */
736 unsigned int has_template_arguments
: 1;
738 /* Flag set if fixup_partial_die has been called on this die. */
739 unsigned int fixup_called
: 1;
741 /* The name of this DIE. Normally the value of DW_AT_name, but
742 sometimes a default name for unnamed DIEs. */
745 /* The linkage name, if present. */
746 const char *linkage_name
;
748 /* The scope to prepend to our children. This is generally
749 allocated on the comp_unit_obstack, so will disappear
750 when this compilation unit leaves the cache. */
753 /* Some data associated with the partial DIE. The tag determines
754 which field is live. */
757 /* The location description associated with this DIE, if any. */
758 struct dwarf_block
*locdesc
;
759 /* The offset of an import, for DW_TAG_imported_unit. */
763 /* If HAS_PC_INFO, the PC range associated with this DIE. */
767 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
768 DW_AT_sibling, if any. */
769 /* NOTE: This member isn't strictly necessary, read_partial_die could
770 return DW_AT_sibling values to its caller load_partial_dies. */
773 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
774 DW_AT_specification (or DW_AT_abstract_origin or
776 sect_offset spec_offset
;
778 /* Pointers to this DIE's parent, first child, and next sibling,
780 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
783 /* This data structure holds the information of an abbrev. */
786 unsigned int number
; /* number identifying abbrev */
787 enum dwarf_tag tag
; /* dwarf tag */
788 unsigned short has_children
; /* boolean */
789 unsigned short num_attrs
; /* number of attributes */
790 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
791 struct abbrev_info
*next
; /* next in chain */
796 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
797 ENUM_BITFIELD(dwarf_form
) form
: 16;
800 /* Size of abbrev_table.abbrev_hash_table. */
801 #define ABBREV_HASH_SIZE 121
803 /* Top level data structure to contain an abbreviation table. */
807 /* Where the abbrev table came from. */
808 struct dwarf2_section_info
*section
;
811 /* Storage for the abbrev table. */
812 struct obstack abbrev_obstack
;
814 /* Hash table of abbrevs.
815 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
816 It could be statically allocated, but the previous code didn't so we
818 struct abbrev_info
**abbrevs
;
821 /* Attributes have a name and a value. */
824 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
825 ENUM_BITFIELD(dwarf_form
) form
: 15;
827 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
828 field should be in u.str (existing only for DW_STRING) but it is kept
829 here for better struct attribute alignment. */
830 unsigned int string_is_canonical
: 1;
835 struct dwarf_block
*blk
;
839 struct signatured_type
*signatured_type
;
844 /* This data structure holds a complete die structure. */
847 /* DWARF-2 tag for this DIE. */
848 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
850 /* Number of attributes */
851 unsigned char num_attrs
;
853 /* True if we're presently building the full type name for the
854 type derived from this DIE. */
855 unsigned char building_fullname
: 1;
860 /* Offset in .debug_info or .debug_types section. */
863 /* The dies in a compilation unit form an n-ary tree. PARENT
864 points to this die's parent; CHILD points to the first child of
865 this node; and all the children of a given node are chained
866 together via their SIBLING fields. */
867 struct die_info
*child
; /* Its first child, if any. */
868 struct die_info
*sibling
; /* Its next sibling, if any. */
869 struct die_info
*parent
; /* Its parent, if any. */
871 /* An array of attributes, with NUM_ATTRS elements. There may be
872 zero, but it's not common and zero-sized arrays are not
873 sufficiently portable C. */
874 struct attribute attrs
[1];
877 /* Get at parts of an attribute structure. */
879 #define DW_STRING(attr) ((attr)->u.str)
880 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
881 #define DW_UNSND(attr) ((attr)->u.unsnd)
882 #define DW_BLOCK(attr) ((attr)->u.blk)
883 #define DW_SND(attr) ((attr)->u.snd)
884 #define DW_ADDR(attr) ((attr)->u.addr)
885 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
887 /* Blocks are a bunch of untyped bytes. */
892 /* Valid only if SIZE is not zero. */
896 #ifndef ATTR_ALLOC_CHUNK
897 #define ATTR_ALLOC_CHUNK 4
900 /* Allocate fields for structs, unions and enums in this size. */
901 #ifndef DW_FIELD_ALLOC_CHUNK
902 #define DW_FIELD_ALLOC_CHUNK 4
905 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
906 but this would require a corresponding change in unpack_field_as_long
908 static int bits_per_byte
= 8;
910 /* The routines that read and process dies for a C struct or C++ class
911 pass lists of data member fields and lists of member function fields
912 in an instance of a field_info structure, as defined below. */
915 /* List of data member and baseclasses fields. */
918 struct nextfield
*next
;
923 *fields
, *baseclasses
;
925 /* Number of fields (including baseclasses). */
928 /* Number of baseclasses. */
931 /* Set if the accesibility of one of the fields is not public. */
932 int non_public_fields
;
934 /* Member function fields array, entries are allocated in the order they
935 are encountered in the object file. */
938 struct nextfnfield
*next
;
939 struct fn_field fnfield
;
943 /* Member function fieldlist array, contains name of possibly overloaded
944 member function, number of overloaded member functions and a pointer
945 to the head of the member function field chain. */
950 struct nextfnfield
*head
;
954 /* Number of entries in the fnfieldlists array. */
957 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
958 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
959 struct typedef_field_list
961 struct typedef_field field
;
962 struct typedef_field_list
*next
;
965 unsigned typedef_field_list_count
;
968 /* One item on the queue of compilation units to read in full symbols
970 struct dwarf2_queue_item
972 struct dwarf2_per_cu_data
*per_cu
;
973 enum language pretend_language
;
974 struct dwarf2_queue_item
*next
;
977 /* The current queue. */
978 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
980 /* Loaded secondary compilation units are kept in memory until they
981 have not been referenced for the processing of this many
982 compilation units. Set this to zero to disable caching. Cache
983 sizes of up to at least twenty will improve startup time for
984 typical inter-CU-reference binaries, at an obvious memory cost. */
985 static int dwarf2_max_cache_age
= 5;
987 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
988 struct cmd_list_element
*c
, const char *value
)
990 fprintf_filtered (file
, _("The upper bound on the age of cached "
991 "dwarf2 compilation units is %s.\n"),
996 /* Various complaints about symbol reading that don't abort the process. */
999 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1001 complaint (&symfile_complaints
,
1002 _("statement list doesn't fit in .debug_line section"));
1006 dwarf2_debug_line_missing_file_complaint (void)
1008 complaint (&symfile_complaints
,
1009 _(".debug_line section has line data without a file"));
1013 dwarf2_debug_line_missing_end_sequence_complaint (void)
1015 complaint (&symfile_complaints
,
1016 _(".debug_line section has line "
1017 "program sequence without an end"));
1021 dwarf2_complex_location_expr_complaint (void)
1023 complaint (&symfile_complaints
, _("location expression too complex"));
1027 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1030 complaint (&symfile_complaints
,
1031 _("const value length mismatch for '%s', got %d, expected %d"),
1036 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1038 complaint (&symfile_complaints
,
1039 _("debug info runs off end of %s section"
1041 section
->asection
->name
,
1042 bfd_get_filename (section
->asection
->owner
));
1046 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1048 complaint (&symfile_complaints
,
1049 _("macro debug info contains a "
1050 "malformed macro definition:\n`%s'"),
1055 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1057 complaint (&symfile_complaints
,
1058 _("invalid attribute class or form for '%s' in '%s'"),
1062 /* local function prototypes */
1064 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1066 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1069 static void dwarf2_find_base_address (struct die_info
*die
,
1070 struct dwarf2_cu
*cu
);
1072 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1074 static void scan_partial_symbols (struct partial_die_info
*,
1075 CORE_ADDR
*, CORE_ADDR
*,
1076 int, struct dwarf2_cu
*);
1078 static void add_partial_symbol (struct partial_die_info
*,
1079 struct dwarf2_cu
*);
1081 static void add_partial_namespace (struct partial_die_info
*pdi
,
1082 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1083 int need_pc
, struct dwarf2_cu
*cu
);
1085 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1086 CORE_ADDR
*highpc
, int need_pc
,
1087 struct dwarf2_cu
*cu
);
1089 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1090 struct dwarf2_cu
*cu
);
1092 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1093 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1094 int need_pc
, struct dwarf2_cu
*cu
);
1096 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1098 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1100 static struct abbrev_info
*abbrev_table_lookup_abbrev
1101 (const struct abbrev_table
*, unsigned int);
1103 static struct abbrev_table
*abbrev_table_read_table
1104 (struct dwarf2_section_info
*, sect_offset
);
1106 static void abbrev_table_free (struct abbrev_table
*);
1108 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1109 struct dwarf2_section_info
*);
1111 static void dwarf2_free_abbrev_table (void *);
1113 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1115 static struct partial_die_info
*load_partial_dies
1116 (const struct die_reader_specs
*, gdb_byte
*, int);
1118 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1119 struct partial_die_info
*,
1120 struct abbrev_info
*,
1124 static struct partial_die_info
*find_partial_die (sect_offset
,
1125 struct dwarf2_cu
*);
1127 static void fixup_partial_die (struct partial_die_info
*,
1128 struct dwarf2_cu
*);
1130 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1131 struct attribute
*, struct attr_abbrev
*,
1134 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1136 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1138 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1140 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1142 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1144 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1147 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1149 static LONGEST read_checked_initial_length_and_offset
1150 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1151 unsigned int *, unsigned int *);
1153 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1156 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1158 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1160 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1162 static char *read_indirect_string (bfd
*, gdb_byte
*,
1163 const struct comp_unit_head
*,
1166 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1168 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1170 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1173 static char *read_str_index (const struct die_reader_specs
*reader
,
1174 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1176 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1178 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1179 struct dwarf2_cu
*);
1181 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1183 struct dwarf2_cu
*);
1185 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1186 struct dwarf2_cu
*cu
);
1188 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1190 static struct die_info
*die_specification (struct die_info
*die
,
1191 struct dwarf2_cu
**);
1193 static void free_line_header (struct line_header
*lh
);
1195 static void add_file_name (struct line_header
*, char *, unsigned int,
1196 unsigned int, unsigned int);
1198 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1199 struct dwarf2_cu
*cu
);
1201 static void dwarf_decode_lines (struct line_header
*, const char *,
1202 struct dwarf2_cu
*, struct partial_symtab
*,
1205 static void dwarf2_start_subfile (char *, const char *, const char *);
1207 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1208 struct dwarf2_cu
*);
1210 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1211 struct dwarf2_cu
*, struct symbol
*);
1213 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1214 struct dwarf2_cu
*);
1216 static void dwarf2_const_value_attr (struct attribute
*attr
,
1219 struct obstack
*obstack
,
1220 struct dwarf2_cu
*cu
, LONGEST
*value
,
1222 struct dwarf2_locexpr_baton
**baton
);
1224 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1226 static int need_gnat_info (struct dwarf2_cu
*);
1228 static struct type
*die_descriptive_type (struct die_info
*,
1229 struct dwarf2_cu
*);
1231 static void set_descriptive_type (struct type
*, struct die_info
*,
1232 struct dwarf2_cu
*);
1234 static struct type
*die_containing_type (struct die_info
*,
1235 struct dwarf2_cu
*);
1237 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1238 struct dwarf2_cu
*);
1240 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1242 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1244 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1246 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1247 const char *suffix
, int physname
,
1248 struct dwarf2_cu
*cu
);
1250 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1252 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1254 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1256 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1258 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1260 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1261 struct dwarf2_cu
*, struct partial_symtab
*);
1263 static int dwarf2_get_pc_bounds (struct die_info
*,
1264 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1265 struct partial_symtab
*);
1267 static void get_scope_pc_bounds (struct die_info
*,
1268 CORE_ADDR
*, CORE_ADDR
*,
1269 struct dwarf2_cu
*);
1271 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1272 CORE_ADDR
, struct dwarf2_cu
*);
1274 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1275 struct dwarf2_cu
*);
1277 static void dwarf2_attach_fields_to_type (struct field_info
*,
1278 struct type
*, struct dwarf2_cu
*);
1280 static void dwarf2_add_member_fn (struct field_info
*,
1281 struct die_info
*, struct type
*,
1282 struct dwarf2_cu
*);
1284 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1286 struct dwarf2_cu
*);
1288 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1290 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1292 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1294 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1296 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1298 static struct type
*read_module_type (struct die_info
*die
,
1299 struct dwarf2_cu
*cu
);
1301 static const char *namespace_name (struct die_info
*die
,
1302 int *is_anonymous
, struct dwarf2_cu
*);
1304 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1306 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1308 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1309 struct dwarf2_cu
*);
1311 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1313 gdb_byte
**new_info_ptr
,
1314 struct die_info
*parent
);
1316 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1318 gdb_byte
**new_info_ptr
,
1319 struct die_info
*parent
);
1321 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1322 struct die_info
**, gdb_byte
*, int *, int);
1324 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1325 struct die_info
**, gdb_byte
*, int *);
1327 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1329 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1332 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1334 static const char *dwarf2_full_name (char *name
,
1335 struct die_info
*die
,
1336 struct dwarf2_cu
*cu
);
1338 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1339 struct dwarf2_cu
**);
1341 static const char *dwarf_tag_name (unsigned int);
1343 static const char *dwarf_attr_name (unsigned int);
1345 static const char *dwarf_form_name (unsigned int);
1347 static char *dwarf_bool_name (unsigned int);
1349 static const char *dwarf_type_encoding_name (unsigned int);
1351 static struct die_info
*sibling_die (struct die_info
*);
1353 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1355 static void dump_die_for_error (struct die_info
*);
1357 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1360 /*static*/ void dump_die (struct die_info
*, int max_level
);
1362 static void store_in_ref_table (struct die_info
*,
1363 struct dwarf2_cu
*);
1365 static int is_ref_attr (struct attribute
*);
1367 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1369 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1371 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1373 struct dwarf2_cu
**);
1375 static struct die_info
*follow_die_ref (struct die_info
*,
1377 struct dwarf2_cu
**);
1379 static struct die_info
*follow_die_sig (struct die_info
*,
1381 struct dwarf2_cu
**);
1383 static struct signatured_type
*lookup_signatured_type_at_offset
1384 (struct objfile
*objfile
,
1385 struct dwarf2_section_info
*section
, sect_offset offset
);
1387 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1389 static void read_signatured_type (struct signatured_type
*);
1391 /* memory allocation interface */
1393 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1395 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1397 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1400 static int attr_form_is_block (struct attribute
*);
1402 static int attr_form_is_section_offset (struct attribute
*);
1404 static int attr_form_is_constant (struct attribute
*);
1406 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1407 struct dwarf2_loclist_baton
*baton
,
1408 struct attribute
*attr
);
1410 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1412 struct dwarf2_cu
*cu
);
1414 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1416 struct abbrev_info
*abbrev
);
1418 static void free_stack_comp_unit (void *);
1420 static hashval_t
partial_die_hash (const void *item
);
1422 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1424 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1425 (sect_offset offset
, struct objfile
*objfile
);
1427 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1428 struct dwarf2_per_cu_data
*per_cu
);
1430 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1431 struct die_info
*comp_unit_die
,
1432 enum language pretend_language
);
1434 static void free_heap_comp_unit (void *);
1436 static void free_cached_comp_units (void *);
1438 static void age_cached_comp_units (void);
1440 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1442 static struct type
*set_die_type (struct die_info
*, struct type
*,
1443 struct dwarf2_cu
*);
1445 static void create_all_comp_units (struct objfile
*);
1447 static int create_all_type_units (struct objfile
*);
1449 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1452 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1455 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1456 struct dwarf2_per_cu_data
*);
1458 static void dwarf2_mark (struct dwarf2_cu
*);
1460 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1462 static struct type
*get_die_type_at_offset (sect_offset
,
1463 struct dwarf2_per_cu_data
*per_cu
);
1465 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1467 static void dwarf2_release_queue (void *dummy
);
1469 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1470 enum language pretend_language
);
1472 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1473 struct dwarf2_per_cu_data
*per_cu
,
1474 enum language pretend_language
);
1476 static void process_queue (void);
1478 static void find_file_and_directory (struct die_info
*die
,
1479 struct dwarf2_cu
*cu
,
1480 char **name
, char **comp_dir
);
1482 static char *file_full_name (int file
, struct line_header
*lh
,
1483 const char *comp_dir
);
1485 static void init_cutu_and_read_dies
1486 (struct dwarf2_per_cu_data
*this_cu
, int use_existing_cu
, int keep
,
1487 die_reader_func_ftype
*die_reader_func
, void *data
);
1489 static void init_cutu_and_read_dies_simple
1490 (struct dwarf2_per_cu_data
*this_cu
,
1491 die_reader_func_ftype
*die_reader_func
, void *data
);
1493 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1495 static void process_psymtab_comp_unit (struct dwarf2_per_cu_data
*, int);
1497 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1499 static struct dwo_unit
*lookup_dwo_comp_unit
1500 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1502 static struct dwo_unit
*lookup_dwo_type_unit
1503 (struct signatured_type
*, char *, const char *);
1505 static void free_dwo_file_cleanup (void *);
1507 static void munmap_section_buffer (struct dwarf2_section_info
*);
1509 static void process_cu_includes (void);
1513 /* Convert VALUE between big- and little-endian. */
1515 byte_swap (offset_type value
)
1519 result
= (value
& 0xff) << 24;
1520 result
|= (value
& 0xff00) << 8;
1521 result
|= (value
& 0xff0000) >> 8;
1522 result
|= (value
& 0xff000000) >> 24;
1526 #define MAYBE_SWAP(V) byte_swap (V)
1529 #define MAYBE_SWAP(V) (V)
1530 #endif /* WORDS_BIGENDIAN */
1532 /* The suffix for an index file. */
1533 #define INDEX_SUFFIX ".gdb-index"
1535 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1536 struct dwarf2_cu
*cu
);
1538 /* Try to locate the sections we need for DWARF 2 debugging
1539 information and return true if we have enough to do something.
1540 NAMES points to the dwarf2 section names, or is NULL if the standard
1541 ELF names are used. */
1544 dwarf2_has_info (struct objfile
*objfile
,
1545 const struct dwarf2_debug_sections
*names
)
1547 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1548 if (!dwarf2_per_objfile
)
1550 /* Initialize per-objfile state. */
1551 struct dwarf2_per_objfile
*data
1552 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1554 memset (data
, 0, sizeof (*data
));
1555 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1556 dwarf2_per_objfile
= data
;
1558 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1560 dwarf2_per_objfile
->objfile
= objfile
;
1562 return (dwarf2_per_objfile
->info
.asection
!= NULL
1563 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1566 /* When loading sections, we look either for uncompressed section or for
1567 compressed section names. */
1570 section_is_p (const char *section_name
,
1571 const struct dwarf2_section_names
*names
)
1573 if (names
->normal
!= NULL
1574 && strcmp (section_name
, names
->normal
) == 0)
1576 if (names
->compressed
!= NULL
1577 && strcmp (section_name
, names
->compressed
) == 0)
1582 /* This function is mapped across the sections and remembers the
1583 offset and size of each of the debugging sections we are interested
1587 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1589 const struct dwarf2_debug_sections
*names
;
1592 names
= &dwarf2_elf_names
;
1594 names
= (const struct dwarf2_debug_sections
*) vnames
;
1596 if (section_is_p (sectp
->name
, &names
->info
))
1598 dwarf2_per_objfile
->info
.asection
= sectp
;
1599 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1601 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1603 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1604 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1606 else if (section_is_p (sectp
->name
, &names
->line
))
1608 dwarf2_per_objfile
->line
.asection
= sectp
;
1609 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1611 else if (section_is_p (sectp
->name
, &names
->loc
))
1613 dwarf2_per_objfile
->loc
.asection
= sectp
;
1614 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1616 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1618 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1619 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1621 else if (section_is_p (sectp
->name
, &names
->macro
))
1623 dwarf2_per_objfile
->macro
.asection
= sectp
;
1624 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1626 else if (section_is_p (sectp
->name
, &names
->str
))
1628 dwarf2_per_objfile
->str
.asection
= sectp
;
1629 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1631 else if (section_is_p (sectp
->name
, &names
->addr
))
1633 dwarf2_per_objfile
->addr
.asection
= sectp
;
1634 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1636 else if (section_is_p (sectp
->name
, &names
->frame
))
1638 dwarf2_per_objfile
->frame
.asection
= sectp
;
1639 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1641 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1643 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1645 if (aflag
& SEC_HAS_CONTENTS
)
1647 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1648 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1651 else if (section_is_p (sectp
->name
, &names
->ranges
))
1653 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1654 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1656 else if (section_is_p (sectp
->name
, &names
->types
))
1658 struct dwarf2_section_info type_section
;
1660 memset (&type_section
, 0, sizeof (type_section
));
1661 type_section
.asection
= sectp
;
1662 type_section
.size
= bfd_get_section_size (sectp
);
1664 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1667 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1669 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1670 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1673 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1674 && bfd_section_vma (abfd
, sectp
) == 0)
1675 dwarf2_per_objfile
->has_section_at_zero
= 1;
1678 /* Decompress a section that was compressed using zlib. Store the
1679 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1682 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1683 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1685 bfd
*abfd
= sectp
->owner
;
1687 error (_("Support for zlib-compressed DWARF data (from '%s') "
1688 "is disabled in this copy of GDB"),
1689 bfd_get_filename (abfd
));
1691 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1692 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1693 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1694 bfd_size_type uncompressed_size
;
1695 gdb_byte
*uncompressed_buffer
;
1698 int header_size
= 12;
1700 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1701 || bfd_bread (compressed_buffer
,
1702 compressed_size
, abfd
) != compressed_size
)
1703 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1704 bfd_get_filename (abfd
));
1706 /* Read the zlib header. In this case, it should be "ZLIB" followed
1707 by the uncompressed section size, 8 bytes in big-endian order. */
1708 if (compressed_size
< header_size
1709 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1710 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1711 bfd_get_filename (abfd
));
1712 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1713 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1714 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1715 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1716 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1717 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1718 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1719 uncompressed_size
+= compressed_buffer
[11];
1721 /* It is possible the section consists of several compressed
1722 buffers concatenated together, so we uncompress in a loop. */
1726 strm
.avail_in
= compressed_size
- header_size
;
1727 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1728 strm
.avail_out
= uncompressed_size
;
1729 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1731 rc
= inflateInit (&strm
);
1732 while (strm
.avail_in
> 0)
1735 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1736 bfd_get_filename (abfd
), rc
);
1737 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1738 + (uncompressed_size
- strm
.avail_out
));
1739 rc
= inflate (&strm
, Z_FINISH
);
1740 if (rc
!= Z_STREAM_END
)
1741 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1742 bfd_get_filename (abfd
), rc
);
1743 rc
= inflateReset (&strm
);
1745 rc
= inflateEnd (&strm
);
1747 || strm
.avail_out
!= 0)
1748 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1749 bfd_get_filename (abfd
), rc
);
1751 do_cleanups (cleanup
);
1752 *outbuf
= uncompressed_buffer
;
1753 *outsize
= uncompressed_size
;
1757 /* A helper function that decides whether a section is empty,
1761 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1763 return info
->asection
== NULL
|| info
->size
== 0;
1766 /* Read the contents of the section INFO.
1767 OBJFILE is the main object file, but not necessarily the file where
1768 the section comes from. E.g., for DWO files INFO->asection->owner
1769 is the bfd of the DWO file.
1770 If the section is compressed, uncompress it before returning. */
1773 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1775 asection
*sectp
= info
->asection
;
1777 gdb_byte
*buf
, *retbuf
;
1778 unsigned char header
[4];
1782 info
->buffer
= NULL
;
1783 info
->map_addr
= NULL
;
1786 if (dwarf2_section_empty_p (info
))
1789 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1790 abfd
= sectp
->owner
;
1792 /* Check if the file has a 4-byte header indicating compression. */
1793 if (info
->size
> sizeof (header
)
1794 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1795 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1797 /* Upon decompression, update the buffer and its size. */
1798 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1800 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1808 pagesize
= getpagesize ();
1810 /* Only try to mmap sections which are large enough: we don't want to
1811 waste space due to fragmentation. Also, only try mmap for sections
1812 without relocations. */
1814 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1816 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1817 MAP_PRIVATE
, sectp
->filepos
,
1818 &info
->map_addr
, &info
->map_len
);
1820 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1822 #if HAVE_POSIX_MADVISE
1823 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1830 /* If we get here, we are a normal, not-compressed section. */
1832 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1834 /* When debugging .o files, we may need to apply relocations; see
1835 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1836 We never compress sections in .o files, so we only need to
1837 try this when the section is not compressed. */
1838 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1841 info
->buffer
= retbuf
;
1845 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1846 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1847 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1848 bfd_get_filename (abfd
));
1851 /* A helper function that returns the size of a section in a safe way.
1852 If you are positive that the section has been read before using the
1853 size, then it is safe to refer to the dwarf2_section_info object's
1854 "size" field directly. In other cases, you must call this
1855 function, because for compressed sections the size field is not set
1856 correctly until the section has been read. */
1858 static bfd_size_type
1859 dwarf2_section_size (struct objfile
*objfile
,
1860 struct dwarf2_section_info
*info
)
1863 dwarf2_read_section (objfile
, info
);
1867 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1871 dwarf2_get_section_info (struct objfile
*objfile
,
1872 enum dwarf2_section_enum sect
,
1873 asection
**sectp
, gdb_byte
**bufp
,
1874 bfd_size_type
*sizep
)
1876 struct dwarf2_per_objfile
*data
1877 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1878 struct dwarf2_section_info
*info
;
1880 /* We may see an objfile without any DWARF, in which case we just
1891 case DWARF2_DEBUG_FRAME
:
1892 info
= &data
->frame
;
1894 case DWARF2_EH_FRAME
:
1895 info
= &data
->eh_frame
;
1898 gdb_assert_not_reached ("unexpected section");
1901 dwarf2_read_section (objfile
, info
);
1903 *sectp
= info
->asection
;
1904 *bufp
= info
->buffer
;
1905 *sizep
= info
->size
;
1909 /* DWARF quick_symbols_functions support. */
1911 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1912 unique line tables, so we maintain a separate table of all .debug_line
1913 derived entries to support the sharing.
1914 All the quick functions need is the list of file names. We discard the
1915 line_header when we're done and don't need to record it here. */
1916 struct quick_file_names
1918 /* The offset in .debug_line of the line table. We hash on this. */
1919 unsigned int offset
;
1921 /* The number of entries in file_names, real_names. */
1922 unsigned int num_file_names
;
1924 /* The file names from the line table, after being run through
1926 const char **file_names
;
1928 /* The file names from the line table after being run through
1929 gdb_realpath. These are computed lazily. */
1930 const char **real_names
;
1933 /* When using the index (and thus not using psymtabs), each CU has an
1934 object of this type. This is used to hold information needed by
1935 the various "quick" methods. */
1936 struct dwarf2_per_cu_quick_data
1938 /* The file table. This can be NULL if there was no file table
1939 or it's currently not read in.
1940 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1941 struct quick_file_names
*file_names
;
1943 /* The corresponding symbol table. This is NULL if symbols for this
1944 CU have not yet been read. */
1945 struct symtab
*symtab
;
1947 /* A temporary mark bit used when iterating over all CUs in
1948 expand_symtabs_matching. */
1949 unsigned int mark
: 1;
1951 /* True if we've tried to read the file table and found there isn't one.
1952 There will be no point in trying to read it again next time. */
1953 unsigned int no_file_data
: 1;
1956 /* Hash function for a quick_file_names. */
1959 hash_file_name_entry (const void *e
)
1961 const struct quick_file_names
*file_data
= e
;
1963 return file_data
->offset
;
1966 /* Equality function for a quick_file_names. */
1969 eq_file_name_entry (const void *a
, const void *b
)
1971 const struct quick_file_names
*ea
= a
;
1972 const struct quick_file_names
*eb
= b
;
1974 return ea
->offset
== eb
->offset
;
1977 /* Delete function for a quick_file_names. */
1980 delete_file_name_entry (void *e
)
1982 struct quick_file_names
*file_data
= e
;
1985 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1987 xfree ((void*) file_data
->file_names
[i
]);
1988 if (file_data
->real_names
)
1989 xfree ((void*) file_data
->real_names
[i
]);
1992 /* The space for the struct itself lives on objfile_obstack,
1993 so we don't free it here. */
1996 /* Create a quick_file_names hash table. */
1999 create_quick_file_names_table (unsigned int nr_initial_entries
)
2001 return htab_create_alloc (nr_initial_entries
,
2002 hash_file_name_entry
, eq_file_name_entry
,
2003 delete_file_name_entry
, xcalloc
, xfree
);
2006 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2007 have to be created afterwards. You should call age_cached_comp_units after
2008 processing PER_CU->CU. dw2_setup must have been already called. */
2011 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2013 if (per_cu
->is_debug_types
)
2014 load_full_type_unit (per_cu
);
2016 load_full_comp_unit (per_cu
, language_minimal
);
2018 gdb_assert (per_cu
->cu
!= NULL
);
2020 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2023 /* Read in the symbols for PER_CU. */
2026 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2028 struct cleanup
*back_to
;
2030 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2032 if (dwarf2_per_objfile
->using_index
2033 ? per_cu
->v
.quick
->symtab
== NULL
2034 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2036 queue_comp_unit (per_cu
, language_minimal
);
2042 /* Age the cache, releasing compilation units that have not
2043 been used recently. */
2044 age_cached_comp_units ();
2046 do_cleanups (back_to
);
2049 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2050 the objfile from which this CU came. Returns the resulting symbol
2053 static struct symtab
*
2054 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2056 gdb_assert (dwarf2_per_objfile
->using_index
);
2057 if (!per_cu
->v
.quick
->symtab
)
2059 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2060 increment_reading_symtab ();
2061 dw2_do_instantiate_symtab (per_cu
);
2062 process_cu_includes ();
2063 do_cleanups (back_to
);
2065 return per_cu
->v
.quick
->symtab
;
2068 /* Return the CU given its index. */
2070 static struct dwarf2_per_cu_data
*
2071 dw2_get_cu (int index
)
2073 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2075 index
-= dwarf2_per_objfile
->n_comp_units
;
2076 return dwarf2_per_objfile
->all_type_units
[index
];
2078 return dwarf2_per_objfile
->all_comp_units
[index
];
2081 /* A helper function that knows how to read a 64-bit value in a way
2082 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2086 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2088 if (sizeof (ULONGEST
) < 8)
2092 /* Ignore the upper 4 bytes if they are all zero. */
2093 for (i
= 0; i
< 4; ++i
)
2094 if (bytes
[i
+ 4] != 0)
2097 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2100 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2104 /* Read the CU list from the mapped index, and use it to create all
2105 the CU objects for this objfile. Return 0 if something went wrong,
2106 1 if everything went ok. */
2109 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2110 offset_type cu_list_elements
)
2114 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2115 dwarf2_per_objfile
->all_comp_units
2116 = obstack_alloc (&objfile
->objfile_obstack
,
2117 dwarf2_per_objfile
->n_comp_units
2118 * sizeof (struct dwarf2_per_cu_data
*));
2120 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2122 struct dwarf2_per_cu_data
*the_cu
;
2123 ULONGEST offset
, length
;
2125 if (!extract_cu_value (cu_list
, &offset
)
2126 || !extract_cu_value (cu_list
+ 8, &length
))
2130 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2131 struct dwarf2_per_cu_data
);
2132 the_cu
->offset
.sect_off
= offset
;
2133 the_cu
->length
= length
;
2134 the_cu
->objfile
= objfile
;
2135 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2136 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2137 struct dwarf2_per_cu_quick_data
);
2138 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2144 /* Create the signatured type hash table from the index. */
2147 create_signatured_type_table_from_index (struct objfile
*objfile
,
2148 struct dwarf2_section_info
*section
,
2149 const gdb_byte
*bytes
,
2150 offset_type elements
)
2153 htab_t sig_types_hash
;
2155 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2156 dwarf2_per_objfile
->all_type_units
2157 = obstack_alloc (&objfile
->objfile_obstack
,
2158 dwarf2_per_objfile
->n_type_units
2159 * sizeof (struct dwarf2_per_cu_data
*));
2161 sig_types_hash
= allocate_signatured_type_table (objfile
);
2163 for (i
= 0; i
< elements
; i
+= 3)
2165 struct signatured_type
*sig_type
;
2166 ULONGEST offset
, type_offset_in_tu
, signature
;
2169 if (!extract_cu_value (bytes
, &offset
)
2170 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2172 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2175 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2176 struct signatured_type
);
2177 sig_type
->signature
= signature
;
2178 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2179 sig_type
->per_cu
.is_debug_types
= 1;
2180 sig_type
->per_cu
.info_or_types_section
= section
;
2181 sig_type
->per_cu
.offset
.sect_off
= offset
;
2182 sig_type
->per_cu
.objfile
= objfile
;
2183 sig_type
->per_cu
.v
.quick
2184 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2185 struct dwarf2_per_cu_quick_data
);
2187 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2190 dwarf2_per_objfile
->all_type_units
[i
/ 3] = &sig_type
->per_cu
;
2193 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2198 /* Read the address map data from the mapped index, and use it to
2199 populate the objfile's psymtabs_addrmap. */
2202 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2204 const gdb_byte
*iter
, *end
;
2205 struct obstack temp_obstack
;
2206 struct addrmap
*mutable_map
;
2207 struct cleanup
*cleanup
;
2210 obstack_init (&temp_obstack
);
2211 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2212 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2214 iter
= index
->address_table
;
2215 end
= iter
+ index
->address_table_size
;
2217 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2221 ULONGEST hi
, lo
, cu_index
;
2222 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2224 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2226 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2229 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2230 dw2_get_cu (cu_index
));
2233 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2234 &objfile
->objfile_obstack
);
2235 do_cleanups (cleanup
);
2238 /* The hash function for strings in the mapped index. This is the same as
2239 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2240 implementation. This is necessary because the hash function is tied to the
2241 format of the mapped index file. The hash values do not have to match with
2244 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2247 mapped_index_string_hash (int index_version
, const void *p
)
2249 const unsigned char *str
= (const unsigned char *) p
;
2253 while ((c
= *str
++) != 0)
2255 if (index_version
>= 5)
2257 r
= r
* 67 + c
- 113;
2263 /* Find a slot in the mapped index INDEX for the object named NAME.
2264 If NAME is found, set *VEC_OUT to point to the CU vector in the
2265 constant pool and return 1. If NAME cannot be found, return 0. */
2268 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2269 offset_type
**vec_out
)
2271 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2273 offset_type slot
, step
;
2274 int (*cmp
) (const char *, const char *);
2276 if (current_language
->la_language
== language_cplus
2277 || current_language
->la_language
== language_java
2278 || current_language
->la_language
== language_fortran
)
2280 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2282 const char *paren
= strchr (name
, '(');
2288 dup
= xmalloc (paren
- name
+ 1);
2289 memcpy (dup
, name
, paren
- name
);
2290 dup
[paren
- name
] = 0;
2292 make_cleanup (xfree
, dup
);
2297 /* Index version 4 did not support case insensitive searches. But the
2298 indices for case insensitive languages are built in lowercase, therefore
2299 simulate our NAME being searched is also lowercased. */
2300 hash
= mapped_index_string_hash ((index
->version
== 4
2301 && case_sensitivity
== case_sensitive_off
2302 ? 5 : index
->version
),
2305 slot
= hash
& (index
->symbol_table_slots
- 1);
2306 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2307 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2311 /* Convert a slot number to an offset into the table. */
2312 offset_type i
= 2 * slot
;
2314 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2316 do_cleanups (back_to
);
2320 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2321 if (!cmp (name
, str
))
2323 *vec_out
= (offset_type
*) (index
->constant_pool
2324 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2325 do_cleanups (back_to
);
2329 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2333 /* Read the index file. If everything went ok, initialize the "quick"
2334 elements of all the CUs and return 1. Otherwise, return 0. */
2337 dwarf2_read_index (struct objfile
*objfile
)
2340 struct mapped_index
*map
;
2341 offset_type
*metadata
;
2342 const gdb_byte
*cu_list
;
2343 const gdb_byte
*types_list
= NULL
;
2344 offset_type version
, cu_list_elements
;
2345 offset_type types_list_elements
= 0;
2348 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2351 /* Older elfutils strip versions could keep the section in the main
2352 executable while splitting it for the separate debug info file. */
2353 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2354 & SEC_HAS_CONTENTS
) == 0)
2357 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2359 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2360 /* Version check. */
2361 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2362 /* Versions earlier than 3 emitted every copy of a psymbol. This
2363 causes the index to behave very poorly for certain requests. Version 3
2364 contained incomplete addrmap. So, it seems better to just ignore such
2368 static int warning_printed
= 0;
2369 if (!warning_printed
)
2371 warning (_("Skipping obsolete .gdb_index section in %s."),
2373 warning_printed
= 1;
2377 /* Index version 4 uses a different hash function than index version
2380 Versions earlier than 6 did not emit psymbols for inlined
2381 functions. Using these files will cause GDB not to be able to
2382 set breakpoints on inlined functions by name, so we ignore these
2383 indices unless the --use-deprecated-index-sections command line
2384 option was supplied. */
2385 if (version
< 6 && !use_deprecated_index_sections
)
2387 static int warning_printed
= 0;
2388 if (!warning_printed
)
2390 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2391 "--use-deprecated-index-sections to use them anyway"),
2393 warning_printed
= 1;
2397 /* Indexes with higher version than the one supported by GDB may be no
2398 longer backward compatible. */
2402 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2403 map
->version
= version
;
2404 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2406 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2409 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2410 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2414 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2415 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2416 - MAYBE_SWAP (metadata
[i
]))
2420 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2421 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2422 - MAYBE_SWAP (metadata
[i
]));
2425 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2426 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2427 - MAYBE_SWAP (metadata
[i
]))
2428 / (2 * sizeof (offset_type
)));
2431 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2433 /* Don't use the index if it's empty. */
2434 if (map
->symbol_table_slots
== 0)
2437 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2440 if (types_list_elements
)
2442 struct dwarf2_section_info
*section
;
2444 /* We can only handle a single .debug_types when we have an
2446 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2449 section
= VEC_index (dwarf2_section_info_def
,
2450 dwarf2_per_objfile
->types
, 0);
2452 if (!create_signatured_type_table_from_index (objfile
, section
,
2454 types_list_elements
))
2458 create_addrmap_from_index (objfile
, map
);
2460 dwarf2_per_objfile
->index_table
= map
;
2461 dwarf2_per_objfile
->using_index
= 1;
2462 dwarf2_per_objfile
->quick_file_names_table
=
2463 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2468 /* A helper for the "quick" functions which sets the global
2469 dwarf2_per_objfile according to OBJFILE. */
2472 dw2_setup (struct objfile
*objfile
)
2474 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2475 gdb_assert (dwarf2_per_objfile
);
2478 /* die_reader_func for dw2_get_file_names. */
2481 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2483 struct die_info
*comp_unit_die
,
2487 struct dwarf2_cu
*cu
= reader
->cu
;
2488 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2489 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2490 struct line_header
*lh
;
2491 struct attribute
*attr
;
2493 char *name
, *comp_dir
;
2495 struct quick_file_names
*qfn
;
2496 unsigned int line_offset
;
2498 /* Our callers never want to match partial units -- instead they
2499 will match the enclosing full CU. */
2500 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2502 this_cu
->v
.quick
->no_file_data
= 1;
2510 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2513 struct quick_file_names find_entry
;
2515 line_offset
= DW_UNSND (attr
);
2517 /* We may have already read in this line header (TU line header sharing).
2518 If we have we're done. */
2519 find_entry
.offset
= line_offset
;
2520 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2521 &find_entry
, INSERT
);
2524 this_cu
->v
.quick
->file_names
= *slot
;
2528 lh
= dwarf_decode_line_header (line_offset
, cu
);
2532 this_cu
->v
.quick
->no_file_data
= 1;
2536 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2537 qfn
->offset
= line_offset
;
2538 gdb_assert (slot
!= NULL
);
2541 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2543 qfn
->num_file_names
= lh
->num_file_names
;
2544 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2545 lh
->num_file_names
* sizeof (char *));
2546 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2547 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2548 qfn
->real_names
= NULL
;
2550 free_line_header (lh
);
2552 this_cu
->v
.quick
->file_names
= qfn
;
2555 /* A helper for the "quick" functions which attempts to read the line
2556 table for THIS_CU. */
2558 static struct quick_file_names
*
2559 dw2_get_file_names (struct objfile
*objfile
,
2560 struct dwarf2_per_cu_data
*this_cu
)
2562 if (this_cu
->v
.quick
->file_names
!= NULL
)
2563 return this_cu
->v
.quick
->file_names
;
2564 /* If we know there is no line data, no point in looking again. */
2565 if (this_cu
->v
.quick
->no_file_data
)
2568 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2569 in the stub for CUs, there's is no need to lookup the DWO file.
2570 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2572 if (this_cu
->is_debug_types
)
2573 init_cutu_and_read_dies (this_cu
, 0, 0, dw2_get_file_names_reader
, NULL
);
2575 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2577 if (this_cu
->v
.quick
->no_file_data
)
2579 return this_cu
->v
.quick
->file_names
;
2582 /* A helper for the "quick" functions which computes and caches the
2583 real path for a given file name from the line table. */
2586 dw2_get_real_path (struct objfile
*objfile
,
2587 struct quick_file_names
*qfn
, int index
)
2589 if (qfn
->real_names
== NULL
)
2590 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2591 qfn
->num_file_names
, sizeof (char *));
2593 if (qfn
->real_names
[index
] == NULL
)
2594 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2596 return qfn
->real_names
[index
];
2599 static struct symtab
*
2600 dw2_find_last_source_symtab (struct objfile
*objfile
)
2604 dw2_setup (objfile
);
2605 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2606 return dw2_instantiate_symtab (dw2_get_cu (index
));
2609 /* Traversal function for dw2_forget_cached_source_info. */
2612 dw2_free_cached_file_names (void **slot
, void *info
)
2614 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2616 if (file_data
->real_names
)
2620 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2622 xfree ((void*) file_data
->real_names
[i
]);
2623 file_data
->real_names
[i
] = NULL
;
2631 dw2_forget_cached_source_info (struct objfile
*objfile
)
2633 dw2_setup (objfile
);
2635 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2636 dw2_free_cached_file_names
, NULL
);
2639 /* Helper function for dw2_map_symtabs_matching_filename that expands
2640 the symtabs and calls the iterator. */
2643 dw2_map_expand_apply (struct objfile
*objfile
,
2644 struct dwarf2_per_cu_data
*per_cu
,
2646 const char *full_path
, const char *real_path
,
2647 int (*callback
) (struct symtab
*, void *),
2650 struct symtab
*last_made
= objfile
->symtabs
;
2652 /* Don't visit already-expanded CUs. */
2653 if (per_cu
->v
.quick
->symtab
)
2656 /* This may expand more than one symtab, and we want to iterate over
2658 dw2_instantiate_symtab (per_cu
);
2660 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2661 objfile
->symtabs
, last_made
);
2664 /* Implementation of the map_symtabs_matching_filename method. */
2667 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2668 const char *full_path
, const char *real_path
,
2669 int (*callback
) (struct symtab
*, void *),
2673 const char *name_basename
= lbasename (name
);
2674 int name_len
= strlen (name
);
2675 int is_abs
= IS_ABSOLUTE_PATH (name
);
2677 dw2_setup (objfile
);
2679 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2680 + dwarf2_per_objfile
->n_type_units
); ++i
)
2683 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2684 struct quick_file_names
*file_data
;
2686 /* We only need to look at symtabs not already expanded. */
2687 if (per_cu
->v
.quick
->symtab
)
2690 file_data
= dw2_get_file_names (objfile
, per_cu
);
2691 if (file_data
== NULL
)
2694 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2696 const char *this_name
= file_data
->file_names
[j
];
2698 if (FILENAME_CMP (name
, this_name
) == 0
2699 || (!is_abs
&& compare_filenames_for_search (this_name
,
2702 if (dw2_map_expand_apply (objfile
, per_cu
,
2703 name
, full_path
, real_path
,
2708 /* Before we invoke realpath, which can get expensive when many
2709 files are involved, do a quick comparison of the basenames. */
2710 if (! basenames_may_differ
2711 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2714 if (full_path
!= NULL
)
2716 const char *this_real_name
= dw2_get_real_path (objfile
,
2719 if (this_real_name
!= NULL
2720 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2722 && compare_filenames_for_search (this_real_name
,
2725 if (dw2_map_expand_apply (objfile
, per_cu
,
2726 name
, full_path
, real_path
,
2732 if (real_path
!= NULL
)
2734 const char *this_real_name
= dw2_get_real_path (objfile
,
2737 if (this_real_name
!= NULL
2738 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2740 && compare_filenames_for_search (this_real_name
,
2743 if (dw2_map_expand_apply (objfile
, per_cu
,
2744 name
, full_path
, real_path
,
2755 static struct symtab
*
2756 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2757 const char *name
, domain_enum domain
)
2759 /* We do all the work in the pre_expand_symtabs_matching hook
2764 /* A helper function that expands all symtabs that hold an object
2765 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
2766 symbols in block BLOCK_KIND. */
2769 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
2770 int want_specific_block
,
2771 enum block_enum block_kind
,
2772 const char *name
, domain_enum domain
)
2774 struct mapped_index
*index
;
2776 dw2_setup (objfile
);
2778 index
= dwarf2_per_objfile
->index_table
;
2780 /* index_table is NULL if OBJF_READNOW. */
2785 if (find_slot_in_mapped_hash (index
, name
, &vec
))
2787 offset_type i
, len
= MAYBE_SWAP (*vec
);
2788 for (i
= 0; i
< len
; ++i
)
2790 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
2791 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
2792 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2793 int want_static
= block_kind
!= GLOBAL_BLOCK
;
2794 /* This value is only valid for index versions >= 7. */
2795 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
2796 gdb_index_symbol_kind symbol_kind
=
2797 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
2799 if (want_specific_block
2800 && index
->version
>= 7
2801 && want_static
!= is_static
)
2804 /* Only check the symbol's kind if it has one.
2805 Indices prior to version 7 don't record it. */
2806 if (index
->version
>= 7)
2811 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
2812 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
2813 /* Some types are also in VAR_DOMAIN. */
2814 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2818 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
2822 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
2830 dw2_instantiate_symtab (per_cu
);
2837 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2838 enum block_enum block_kind
, const char *name
,
2841 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
2845 dw2_print_stats (struct objfile
*objfile
)
2849 dw2_setup (objfile
);
2851 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2852 + dwarf2_per_objfile
->n_type_units
); ++i
)
2854 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2856 if (!per_cu
->v
.quick
->symtab
)
2859 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2863 dw2_dump (struct objfile
*objfile
)
2865 /* Nothing worth printing. */
2869 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2870 struct section_offsets
*delta
)
2872 /* There's nothing to relocate here. */
2876 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2877 const char *func_name
)
2879 /* Note: It doesn't matter what we pass for block_kind here. */
2880 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
2885 dw2_expand_all_symtabs (struct objfile
*objfile
)
2889 dw2_setup (objfile
);
2891 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2892 + dwarf2_per_objfile
->n_type_units
); ++i
)
2894 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2896 dw2_instantiate_symtab (per_cu
);
2901 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2902 const char *filename
)
2906 dw2_setup (objfile
);
2908 /* We don't need to consider type units here.
2909 This is only called for examining code, e.g. expand_line_sal.
2910 There can be an order of magnitude (or more) more type units
2911 than comp units, and we avoid them if we can. */
2913 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2916 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2917 struct quick_file_names
*file_data
;
2919 /* We only need to look at symtabs not already expanded. */
2920 if (per_cu
->v
.quick
->symtab
)
2923 file_data
= dw2_get_file_names (objfile
, per_cu
);
2924 if (file_data
== NULL
)
2927 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2929 const char *this_name
= file_data
->file_names
[j
];
2930 if (FILENAME_CMP (this_name
, filename
) == 0)
2932 dw2_instantiate_symtab (per_cu
);
2939 /* A helper function for dw2_find_symbol_file that finds the primary
2940 file name for a given CU. This is a die_reader_func. */
2943 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
2945 struct die_info
*comp_unit_die
,
2949 const char **result_ptr
= data
;
2950 struct dwarf2_cu
*cu
= reader
->cu
;
2951 struct attribute
*attr
;
2953 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
2957 *result_ptr
= DW_STRING (attr
);
2961 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2963 struct dwarf2_per_cu_data
*per_cu
;
2965 struct quick_file_names
*file_data
;
2966 const char *filename
;
2968 dw2_setup (objfile
);
2970 /* index_table is NULL if OBJF_READNOW. */
2971 if (!dwarf2_per_objfile
->index_table
)
2975 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
2977 struct blockvector
*bv
= BLOCKVECTOR (s
);
2978 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2979 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
2982 return sym
->symtab
->filename
;
2987 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2991 /* Note that this just looks at the very first one named NAME -- but
2992 actually we are looking for a function. find_main_filename
2993 should be rewritten so that it doesn't require a custom hook. It
2994 could just use the ordinary symbol tables. */
2995 /* vec[0] is the length, which must always be >0. */
2996 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
2998 if (per_cu
->v
.quick
->symtab
!= NULL
)
2999 return per_cu
->v
.quick
->symtab
->filename
;
3001 init_cutu_and_read_dies (per_cu
, 0, 0, dw2_get_primary_filename_reader
,
3008 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3009 struct objfile
*objfile
, int global
,
3010 int (*callback
) (struct block
*,
3011 struct symbol
*, void *),
3012 void *data
, symbol_compare_ftype
*match
,
3013 symbol_compare_ftype
*ordered_compare
)
3015 /* Currently unimplemented; used for Ada. The function can be called if the
3016 current language is Ada for a non-Ada objfile using GNU index. As Ada
3017 does not look for non-Ada symbols this function should just return. */
3021 dw2_expand_symtabs_matching
3022 (struct objfile
*objfile
,
3023 int (*file_matcher
) (const char *, void *),
3024 int (*name_matcher
) (const char *, void *),
3025 enum search_domain kind
,
3030 struct mapped_index
*index
;
3032 dw2_setup (objfile
);
3034 /* index_table is NULL if OBJF_READNOW. */
3035 if (!dwarf2_per_objfile
->index_table
)
3037 index
= dwarf2_per_objfile
->index_table
;
3039 if (file_matcher
!= NULL
)
3041 struct cleanup
*cleanup
;
3042 htab_t visited_found
, visited_not_found
;
3044 visited_found
= htab_create_alloc (10,
3045 htab_hash_pointer
, htab_eq_pointer
,
3046 NULL
, xcalloc
, xfree
);
3047 cleanup
= make_cleanup_htab_delete (visited_found
);
3048 visited_not_found
= htab_create_alloc (10,
3049 htab_hash_pointer
, htab_eq_pointer
,
3050 NULL
, xcalloc
, xfree
);
3051 make_cleanup_htab_delete (visited_not_found
);
3053 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3054 + dwarf2_per_objfile
->n_type_units
); ++i
)
3057 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3058 struct quick_file_names
*file_data
;
3061 per_cu
->v
.quick
->mark
= 0;
3063 /* We only need to look at symtabs not already expanded. */
3064 if (per_cu
->v
.quick
->symtab
)
3067 file_data
= dw2_get_file_names (objfile
, per_cu
);
3068 if (file_data
== NULL
)
3071 if (htab_find (visited_not_found
, file_data
) != NULL
)
3073 else if (htab_find (visited_found
, file_data
) != NULL
)
3075 per_cu
->v
.quick
->mark
= 1;
3079 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3081 if (file_matcher (file_data
->file_names
[j
], data
))
3083 per_cu
->v
.quick
->mark
= 1;
3088 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3090 : visited_not_found
,
3095 do_cleanups (cleanup
);
3098 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3100 offset_type idx
= 2 * iter
;
3102 offset_type
*vec
, vec_len
, vec_idx
;
3104 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3107 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3109 if (! (*name_matcher
) (name
, data
))
3112 /* The name was matched, now expand corresponding CUs that were
3114 vec
= (offset_type
*) (index
->constant_pool
3115 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3116 vec_len
= MAYBE_SWAP (vec
[0]);
3117 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3119 struct dwarf2_per_cu_data
*per_cu
;
3120 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3121 gdb_index_symbol_kind symbol_kind
=
3122 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3123 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3125 /* Don't crash on bad data. */
3126 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3127 + dwarf2_per_objfile
->n_comp_units
))
3130 /* Only check the symbol's kind if it has one.
3131 Indices prior to version 7 don't record it. */
3132 if (index
->version
>= 7)
3136 case VARIABLES_DOMAIN
:
3137 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3140 case FUNCTIONS_DOMAIN
:
3141 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3145 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3153 per_cu
= dw2_get_cu (cu_index
);
3154 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3155 dw2_instantiate_symtab (per_cu
);
3160 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3163 static struct symtab
*
3164 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3168 if (BLOCKVECTOR (symtab
) != NULL
3169 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3172 if (symtab
->includes
== NULL
)
3175 for (i
= 0; symtab
->includes
[i
]; ++i
)
3177 struct symtab
*s
= symtab
->includes
[i
];
3179 s
= recursively_find_pc_sect_symtab (s
, pc
);
3187 static struct symtab
*
3188 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3189 struct minimal_symbol
*msymbol
,
3191 struct obj_section
*section
,
3194 struct dwarf2_per_cu_data
*data
;
3195 struct symtab
*result
;
3197 dw2_setup (objfile
);
3199 if (!objfile
->psymtabs_addrmap
)
3202 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3206 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3207 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3208 paddress (get_objfile_arch (objfile
), pc
));
3210 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3211 gdb_assert (result
!= NULL
);
3216 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3217 void *data
, int need_fullname
)
3220 struct cleanup
*cleanup
;
3221 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3222 NULL
, xcalloc
, xfree
);
3224 cleanup
= make_cleanup_htab_delete (visited
);
3225 dw2_setup (objfile
);
3227 /* We can ignore file names coming from already-expanded CUs. */
3228 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3229 + dwarf2_per_objfile
->n_type_units
); ++i
)
3231 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3233 if (per_cu
->v
.quick
->symtab
)
3235 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3238 *slot
= per_cu
->v
.quick
->file_names
;
3242 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3243 + dwarf2_per_objfile
->n_type_units
); ++i
)
3246 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3247 struct quick_file_names
*file_data
;
3250 /* We only need to look at symtabs not already expanded. */
3251 if (per_cu
->v
.quick
->symtab
)
3254 file_data
= dw2_get_file_names (objfile
, per_cu
);
3255 if (file_data
== NULL
)
3258 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3261 /* Already visited. */
3266 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3268 const char *this_real_name
;
3271 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3273 this_real_name
= NULL
;
3274 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3278 do_cleanups (cleanup
);
3282 dw2_has_symbols (struct objfile
*objfile
)
3287 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3290 dw2_find_last_source_symtab
,
3291 dw2_forget_cached_source_info
,
3292 dw2_map_symtabs_matching_filename
,
3294 dw2_pre_expand_symtabs_matching
,
3298 dw2_expand_symtabs_for_function
,
3299 dw2_expand_all_symtabs
,
3300 dw2_expand_symtabs_with_filename
,
3301 dw2_find_symbol_file
,
3302 dw2_map_matching_symbols
,
3303 dw2_expand_symtabs_matching
,
3304 dw2_find_pc_sect_symtab
,
3305 dw2_map_symbol_filenames
3308 /* Initialize for reading DWARF for this objfile. Return 0 if this
3309 file will use psymtabs, or 1 if using the GNU index. */
3312 dwarf2_initialize_objfile (struct objfile
*objfile
)
3314 /* If we're about to read full symbols, don't bother with the
3315 indices. In this case we also don't care if some other debug
3316 format is making psymtabs, because they are all about to be
3318 if ((objfile
->flags
& OBJF_READNOW
))
3322 dwarf2_per_objfile
->using_index
= 1;
3323 create_all_comp_units (objfile
);
3324 create_all_type_units (objfile
);
3325 dwarf2_per_objfile
->quick_file_names_table
=
3326 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3328 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3329 + dwarf2_per_objfile
->n_type_units
); ++i
)
3331 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3333 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3334 struct dwarf2_per_cu_quick_data
);
3337 /* Return 1 so that gdb sees the "quick" functions. However,
3338 these functions will be no-ops because we will have expanded
3343 if (dwarf2_read_index (objfile
))
3351 /* Build a partial symbol table. */
3354 dwarf2_build_psymtabs (struct objfile
*objfile
)
3356 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3358 init_psymbol_list (objfile
, 1024);
3361 dwarf2_build_psymtabs_hard (objfile
);
3364 /* Return the total length of the CU described by HEADER. */
3367 get_cu_length (const struct comp_unit_head
*header
)
3369 return header
->initial_length_size
+ header
->length
;
3372 /* Return TRUE if OFFSET is within CU_HEADER. */
3375 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3377 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3378 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3380 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3383 /* Find the base address of the compilation unit for range lists and
3384 location lists. It will normally be specified by DW_AT_low_pc.
3385 In DWARF-3 draft 4, the base address could be overridden by
3386 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3387 compilation units with discontinuous ranges. */
3390 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3392 struct attribute
*attr
;
3395 cu
->base_address
= 0;
3397 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3400 cu
->base_address
= DW_ADDR (attr
);
3405 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3408 cu
->base_address
= DW_ADDR (attr
);
3414 /* Read in the comp unit header information from the debug_info at info_ptr.
3415 NOTE: This leaves members offset, first_die_offset to be filled in
3419 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3420 gdb_byte
*info_ptr
, bfd
*abfd
)
3423 unsigned int bytes_read
;
3425 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3426 cu_header
->initial_length_size
= bytes_read
;
3427 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3428 info_ptr
+= bytes_read
;
3429 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3431 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3433 info_ptr
+= bytes_read
;
3434 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3436 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3437 if (signed_addr
< 0)
3438 internal_error (__FILE__
, __LINE__
,
3439 _("read_comp_unit_head: dwarf from non elf file"));
3440 cu_header
->signed_addr_p
= signed_addr
;
3445 /* Subroutine of read_and_check_comp_unit_head and
3446 read_and_check_type_unit_head to simplify them.
3447 Perform various error checking on the header. */
3450 error_check_comp_unit_head (struct comp_unit_head
*header
,
3451 struct dwarf2_section_info
*section
,
3452 struct dwarf2_section_info
*abbrev_section
)
3454 bfd
*abfd
= section
->asection
->owner
;
3455 const char *filename
= bfd_get_filename (abfd
);
3457 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3458 error (_("Dwarf Error: wrong version in compilation unit header "
3459 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3462 if (header
->abbrev_offset
.sect_off
3463 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3464 &dwarf2_per_objfile
->abbrev
))
3465 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3466 "(offset 0x%lx + 6) [in module %s]"),
3467 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3470 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3471 avoid potential 32-bit overflow. */
3472 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3474 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3475 "(offset 0x%lx + 0) [in module %s]"),
3476 (long) header
->length
, (long) header
->offset
.sect_off
,
3480 /* Read in a CU/TU header and perform some basic error checking.
3481 The contents of the header are stored in HEADER.
3482 The result is a pointer to the start of the first DIE. */
3485 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3486 struct dwarf2_section_info
*section
,
3487 struct dwarf2_section_info
*abbrev_section
,
3489 int is_debug_types_section
)
3491 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3492 bfd
*abfd
= section
->asection
->owner
;
3494 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3496 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3498 /* If we're reading a type unit, skip over the signature and
3499 type_offset fields. */
3500 if (is_debug_types_section
)
3501 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3503 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3505 error_check_comp_unit_head (header
, section
, abbrev_section
);
3510 /* Read in the types comp unit header information from .debug_types entry at
3511 types_ptr. The result is a pointer to one past the end of the header. */
3514 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3515 struct dwarf2_section_info
*section
,
3516 struct dwarf2_section_info
*abbrev_section
,
3518 ULONGEST
*signature
,
3519 cu_offset
*type_offset_in_tu
)
3521 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3522 bfd
*abfd
= section
->asection
->owner
;
3524 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3526 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3528 /* If we're reading a type unit, skip over the signature and
3529 type_offset fields. */
3530 if (signature
!= NULL
)
3531 *signature
= read_8_bytes (abfd
, info_ptr
);
3533 if (type_offset_in_tu
!= NULL
)
3534 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3535 header
->offset_size
);
3536 info_ptr
+= header
->offset_size
;
3538 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3540 error_check_comp_unit_head (header
, section
, abbrev_section
);
3545 /* Allocate a new partial symtab for file named NAME and mark this new
3546 partial symtab as being an include of PST. */
3549 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3550 struct objfile
*objfile
)
3552 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3554 subpst
->section_offsets
= pst
->section_offsets
;
3555 subpst
->textlow
= 0;
3556 subpst
->texthigh
= 0;
3558 subpst
->dependencies
= (struct partial_symtab
**)
3559 obstack_alloc (&objfile
->objfile_obstack
,
3560 sizeof (struct partial_symtab
*));
3561 subpst
->dependencies
[0] = pst
;
3562 subpst
->number_of_dependencies
= 1;
3564 subpst
->globals_offset
= 0;
3565 subpst
->n_global_syms
= 0;
3566 subpst
->statics_offset
= 0;
3567 subpst
->n_static_syms
= 0;
3568 subpst
->symtab
= NULL
;
3569 subpst
->read_symtab
= pst
->read_symtab
;
3572 /* No private part is necessary for include psymtabs. This property
3573 can be used to differentiate between such include psymtabs and
3574 the regular ones. */
3575 subpst
->read_symtab_private
= NULL
;
3578 /* Read the Line Number Program data and extract the list of files
3579 included by the source file represented by PST. Build an include
3580 partial symtab for each of these included files. */
3583 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3584 struct die_info
*die
,
3585 struct partial_symtab
*pst
)
3587 struct line_header
*lh
= NULL
;
3588 struct attribute
*attr
;
3590 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3592 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3594 return; /* No linetable, so no includes. */
3596 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3597 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3599 free_line_header (lh
);
3603 hash_signatured_type (const void *item
)
3605 const struct signatured_type
*sig_type
= item
;
3607 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3608 return sig_type
->signature
;
3612 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3614 const struct signatured_type
*lhs
= item_lhs
;
3615 const struct signatured_type
*rhs
= item_rhs
;
3617 return lhs
->signature
== rhs
->signature
;
3620 /* Allocate a hash table for signatured types. */
3623 allocate_signatured_type_table (struct objfile
*objfile
)
3625 return htab_create_alloc_ex (41,
3626 hash_signatured_type
,
3629 &objfile
->objfile_obstack
,
3630 hashtab_obstack_allocate
,
3631 dummy_obstack_deallocate
);
3634 /* A helper function to add a signatured type CU to a table. */
3637 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3639 struct signatured_type
*sigt
= *slot
;
3640 struct dwarf2_per_cu_data
***datap
= datum
;
3642 **datap
= &sigt
->per_cu
;
3648 /* Create the hash table of all entries in the .debug_types section.
3649 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3650 The result is a pointer to the hash table or NULL if there are
3654 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3655 VEC (dwarf2_section_info_def
) *types
)
3657 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3658 htab_t types_htab
= NULL
;
3660 struct dwarf2_section_info
*section
;
3661 struct dwarf2_section_info
*abbrev_section
;
3663 if (VEC_empty (dwarf2_section_info_def
, types
))
3666 abbrev_section
= (dwo_file
!= NULL
3667 ? &dwo_file
->sections
.abbrev
3668 : &dwarf2_per_objfile
->abbrev
);
3670 if (dwarf2_read_debug
)
3671 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
3672 dwo_file
? ".dwo" : "",
3673 bfd_get_filename (abbrev_section
->asection
->owner
));
3676 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3680 gdb_byte
*info_ptr
, *end_ptr
;
3682 dwarf2_read_section (objfile
, section
);
3683 info_ptr
= section
->buffer
;
3685 if (info_ptr
== NULL
)
3688 /* We can't set abfd until now because the section may be empty or
3689 not present, in which case section->asection will be NULL. */
3690 abfd
= section
->asection
->owner
;
3692 if (types_htab
== NULL
)
3695 types_htab
= allocate_dwo_unit_table (objfile
);
3697 types_htab
= allocate_signatured_type_table (objfile
);
3700 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3701 because we don't need to read any dies: the signature is in the
3704 end_ptr
= info_ptr
+ section
->size
;
3705 while (info_ptr
< end_ptr
)
3708 cu_offset type_offset_in_tu
;
3710 struct signatured_type
*sig_type
;
3711 struct dwo_unit
*dwo_tu
;
3713 gdb_byte
*ptr
= info_ptr
;
3714 struct comp_unit_head header
;
3715 unsigned int length
;
3717 offset
.sect_off
= ptr
- section
->buffer
;
3719 /* We need to read the type's signature in order to build the hash
3720 table, but we don't need anything else just yet. */
3722 ptr
= read_and_check_type_unit_head (&header
, section
,
3723 abbrev_section
, ptr
,
3724 &signature
, &type_offset_in_tu
);
3726 length
= get_cu_length (&header
);
3728 /* Skip dummy type units. */
3729 if (ptr
>= info_ptr
+ length
3730 || peek_abbrev_code (abfd
, ptr
) == 0)
3739 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3741 dwo_tu
->dwo_file
= dwo_file
;
3742 dwo_tu
->signature
= signature
;
3743 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
3744 dwo_tu
->info_or_types_section
= section
;
3745 dwo_tu
->offset
= offset
;
3746 dwo_tu
->length
= length
;
3750 /* N.B.: type_offset is not usable if this type uses a DWO file.
3751 The real type_offset is in the DWO file. */
3753 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3754 struct signatured_type
);
3755 sig_type
->signature
= signature
;
3756 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3757 sig_type
->per_cu
.objfile
= objfile
;
3758 sig_type
->per_cu
.is_debug_types
= 1;
3759 sig_type
->per_cu
.info_or_types_section
= section
;
3760 sig_type
->per_cu
.offset
= offset
;
3761 sig_type
->per_cu
.length
= length
;
3764 slot
= htab_find_slot (types_htab
,
3765 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
3767 gdb_assert (slot
!= NULL
);
3770 sect_offset dup_offset
;
3774 const struct dwo_unit
*dup_tu
= *slot
;
3776 dup_offset
= dup_tu
->offset
;
3780 const struct signatured_type
*dup_tu
= *slot
;
3782 dup_offset
= dup_tu
->per_cu
.offset
;
3785 complaint (&symfile_complaints
,
3786 _("debug type entry at offset 0x%x is duplicate to the "
3787 "entry at offset 0x%x, signature 0x%s"),
3788 offset
.sect_off
, dup_offset
.sect_off
,
3789 phex (signature
, sizeof (signature
)));
3791 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
3793 if (dwarf2_read_debug
)
3794 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3796 phex (signature
, sizeof (signature
)));
3805 /* Create the hash table of all entries in the .debug_types section,
3806 and initialize all_type_units.
3807 The result is zero if there is an error (e.g. missing .debug_types section),
3808 otherwise non-zero. */
3811 create_all_type_units (struct objfile
*objfile
)
3814 struct dwarf2_per_cu_data
**iter
;
3816 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
3817 if (types_htab
== NULL
)
3819 dwarf2_per_objfile
->signatured_types
= NULL
;
3823 dwarf2_per_objfile
->signatured_types
= types_htab
;
3825 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
3826 dwarf2_per_objfile
->all_type_units
3827 = obstack_alloc (&objfile
->objfile_obstack
,
3828 dwarf2_per_objfile
->n_type_units
3829 * sizeof (struct dwarf2_per_cu_data
*));
3830 iter
= &dwarf2_per_objfile
->all_type_units
[0];
3831 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
3832 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
3833 == dwarf2_per_objfile
->n_type_units
);
3838 /* Lookup a signature based type for DW_FORM_ref_sig8.
3839 Returns NULL if signature SIG is not present in the table. */
3841 static struct signatured_type
*
3842 lookup_signatured_type (ULONGEST sig
)
3844 struct signatured_type find_entry
, *entry
;
3846 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3848 complaint (&symfile_complaints
,
3849 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3853 find_entry
.signature
= sig
;
3854 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3858 /* Low level DIE reading support. */
3860 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3863 init_cu_die_reader (struct die_reader_specs
*reader
,
3864 struct dwarf2_cu
*cu
,
3865 struct dwarf2_section_info
*section
,
3866 struct dwo_file
*dwo_file
)
3868 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
3869 reader
->abfd
= section
->asection
->owner
;
3871 reader
->dwo_file
= dwo_file
;
3872 reader
->die_section
= section
;
3873 reader
->buffer
= section
->buffer
;
3874 reader
->buffer_end
= section
->buffer
+ section
->size
;
3877 /* Initialize a CU (or TU) and read its DIEs.
3878 If the CU defers to a DWO file, read the DWO file as well.
3880 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
3881 Otherwise, a new CU is allocated with xmalloc.
3883 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
3884 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
3886 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
3887 linker) then DIE_READER_FUNC will not get called. */
3890 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
3891 int use_existing_cu
, int keep
,
3892 die_reader_func_ftype
*die_reader_func
,
3895 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3896 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
3897 bfd
*abfd
= section
->asection
->owner
;
3898 struct dwarf2_cu
*cu
;
3899 gdb_byte
*begin_info_ptr
, *info_ptr
;
3900 struct die_reader_specs reader
;
3901 struct die_info
*comp_unit_die
;
3903 struct attribute
*attr
;
3904 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
3905 struct signatured_type
*sig_type
= NULL
;
3906 struct dwarf2_section_info
*abbrev_section
;
3907 /* Non-zero if CU currently points to a DWO file and we need to
3908 reread it. When this happens we need to reread the skeleton die
3909 before we can reread the DWO file. */
3910 int rereading_dwo_cu
= 0;
3912 if (dwarf2_die_debug
)
3913 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
3914 this_cu
->is_debug_types
? "type" : "comp",
3915 this_cu
->offset
.sect_off
);
3917 if (use_existing_cu
)
3920 cleanups
= make_cleanup (null_cleanup
, NULL
);
3922 /* This is cheap if the section is already read in. */
3923 dwarf2_read_section (objfile
, section
);
3925 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
3926 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
3928 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
3932 /* If this CU is from a DWO file we need to start over, we need to
3933 refetch the attributes from the skeleton CU.
3934 This could be optimized by retrieving those attributes from when we
3935 were here the first time: the previous comp_unit_die was stored in
3936 comp_unit_obstack. But there's no data yet that we need this
3938 if (cu
->dwo_unit
!= NULL
)
3939 rereading_dwo_cu
= 1;
3943 /* If !use_existing_cu, this_cu->cu must be NULL. */
3944 gdb_assert (this_cu
->cu
== NULL
);
3946 cu
= xmalloc (sizeof (*cu
));
3947 init_one_comp_unit (cu
, this_cu
);
3949 /* If an error occurs while loading, release our storage. */
3950 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
3953 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
3955 /* We already have the header, there's no need to read it in again. */
3956 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
3960 if (this_cu
->is_debug_types
)
3963 cu_offset type_offset_in_tu
;
3965 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
3966 abbrev_section
, info_ptr
,
3968 &type_offset_in_tu
);
3970 /* Since per_cu is the first member of struct signatured_type,
3971 we can go from a pointer to one to a pointer to the other. */
3972 sig_type
= (struct signatured_type
*) this_cu
;
3973 gdb_assert (sig_type
->signature
== signature
);
3974 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
3975 == type_offset_in_tu
.cu_off
);
3976 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3978 /* LENGTH has not been set yet for type units if we're
3979 using .gdb_index. */
3980 this_cu
->length
= get_cu_length (&cu
->header
);
3982 /* Establish the type offset that can be used to lookup the type. */
3983 sig_type
->type_offset_in_section
.sect_off
=
3984 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
3988 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
3992 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
3993 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
3997 /* Skip dummy compilation units. */
3998 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
3999 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4001 do_cleanups (cleanups
);
4005 /* If we don't have them yet, read the abbrevs for this compilation unit.
4006 And if we need to read them now, make sure they're freed when we're
4007 done. Note that it's important that if the CU had an abbrev table
4008 on entry we don't free it when we're done: Somewhere up the call stack
4009 it may be in use. */
4010 if (cu
->abbrev_table
== NULL
)
4012 dwarf2_read_abbrevs (cu
, abbrev_section
);
4013 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4015 else if (rereading_dwo_cu
)
4017 dwarf2_free_abbrev_table (cu
);
4018 dwarf2_read_abbrevs (cu
, abbrev_section
);
4021 /* Read the top level CU/TU die. */
4022 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4023 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4025 /* If we have a DWO stub, process it and then read in the DWO file.
4026 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4027 a DWO CU, that this test will fail. */
4028 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4031 char *dwo_name
= DW_STRING (attr
);
4032 const char *comp_dir_string
;
4033 struct dwo_unit
*dwo_unit
;
4034 ULONGEST signature
; /* Or dwo_id. */
4035 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4036 int i
,num_extra_attrs
;
4037 struct dwarf2_section_info
*dwo_abbrev_section
;
4040 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4041 " has children (offset 0x%x) [in module %s]"),
4042 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4044 /* These attributes aren't processed until later:
4045 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4046 However, the attribute is found in the stub which we won't have later.
4047 In order to not impose this complication on the rest of the code,
4048 we read them here and copy them to the DWO CU/TU die. */
4050 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4053 if (! this_cu
->is_debug_types
)
4054 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4055 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4056 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4057 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4058 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4060 /* There should be a DW_AT_addr_base attribute here (if needed).
4061 We need the value before we can process DW_FORM_GNU_addr_index. */
4063 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4065 cu
->addr_base
= DW_UNSND (attr
);
4067 /* There should be a DW_AT_ranges_base attribute here (if needed).
4068 We need the value before we can process DW_AT_ranges. */
4069 cu
->ranges_base
= 0;
4070 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4072 cu
->ranges_base
= DW_UNSND (attr
);
4074 if (this_cu
->is_debug_types
)
4076 gdb_assert (sig_type
!= NULL
);
4077 signature
= sig_type
->signature
;
4081 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4083 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4085 signature
= DW_UNSND (attr
);
4088 /* We may need the comp_dir in order to find the DWO file. */
4089 comp_dir_string
= NULL
;
4091 comp_dir_string
= DW_STRING (comp_dir
);
4093 if (this_cu
->is_debug_types
)
4094 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4096 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4099 if (dwo_unit
== NULL
)
4101 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4102 " with ID %s [in module %s]"),
4103 this_cu
->offset
.sect_off
,
4104 phex (signature
, sizeof (signature
)),
4108 /* Set up for reading the DWO CU/TU. */
4109 cu
->dwo_unit
= dwo_unit
;
4110 section
= dwo_unit
->info_or_types_section
;
4111 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4112 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4113 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4115 if (this_cu
->is_debug_types
)
4119 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4123 gdb_assert (sig_type
->signature
== signature
);
4124 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4125 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4127 /* Establish the type offset that can be used to lookup the type.
4128 For DWO files, we don't know it until now. */
4129 sig_type
->type_offset_in_section
.sect_off
=
4130 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4134 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4137 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4138 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4141 /* Discard the original CU's abbrev table, and read the DWO's. */
4142 dwarf2_free_abbrev_table (cu
);
4143 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4145 /* Read in the die, but leave space to copy over the attributes
4146 from the stub. This has the benefit of simplifying the rest of
4147 the code - all the real work is done here. */
4148 num_extra_attrs
= ((stmt_list
!= NULL
)
4152 + (comp_dir
!= NULL
));
4153 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4154 &has_children
, num_extra_attrs
);
4156 /* Copy over the attributes from the stub to the DWO die. */
4157 i
= comp_unit_die
->num_attrs
;
4158 if (stmt_list
!= NULL
)
4159 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4161 comp_unit_die
->attrs
[i
++] = *low_pc
;
4162 if (high_pc
!= NULL
)
4163 comp_unit_die
->attrs
[i
++] = *high_pc
;
4165 comp_unit_die
->attrs
[i
++] = *ranges
;
4166 if (comp_dir
!= NULL
)
4167 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4168 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4170 /* Skip dummy compilation units. */
4171 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4172 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4174 do_cleanups (cleanups
);
4179 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4181 if (free_cu_cleanup
!= NULL
)
4185 /* We've successfully allocated this compilation unit. Let our
4186 caller clean it up when finished with it. */
4187 discard_cleanups (free_cu_cleanup
);
4189 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4190 So we have to manually free the abbrev table. */
4191 dwarf2_free_abbrev_table (cu
);
4193 /* Link this CU into read_in_chain. */
4194 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4195 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4198 do_cleanups (free_cu_cleanup
);
4201 do_cleanups (cleanups
);
4204 /* Read CU/TU THIS_CU in section SECTION,
4205 but do not follow DW_AT_GNU_dwo_name if present.
4206 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4207 have already done the lookup to find the DWO file).
4209 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4210 THIS_CU->is_debug_types, but nothing else.
4212 We fill in THIS_CU->length.
4214 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4215 linker) then DIE_READER_FUNC will not get called.
4217 THIS_CU->cu is always freed when done.
4218 This is done in order to not leave THIS_CU->cu in a state where we have
4219 to care whether it refers to the "main" CU or the DWO CU. */
4222 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4223 struct dwarf2_section_info
*abbrev_section
,
4224 struct dwo_file
*dwo_file
,
4225 die_reader_func_ftype
*die_reader_func
,
4228 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4229 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4230 bfd
*abfd
= section
->asection
->owner
;
4231 struct dwarf2_cu cu
;
4232 gdb_byte
*begin_info_ptr
, *info_ptr
;
4233 struct die_reader_specs reader
;
4234 struct cleanup
*cleanups
;
4235 struct die_info
*comp_unit_die
;
4238 if (dwarf2_die_debug
)
4239 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4240 this_cu
->is_debug_types
? "type" : "comp",
4241 this_cu
->offset
.sect_off
);
4243 gdb_assert (this_cu
->cu
== NULL
);
4245 /* This is cheap if the section is already read in. */
4246 dwarf2_read_section (objfile
, section
);
4248 init_one_comp_unit (&cu
, this_cu
);
4250 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4252 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4253 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4254 abbrev_section
, info_ptr
,
4255 this_cu
->is_debug_types
);
4257 this_cu
->length
= get_cu_length (&cu
.header
);
4259 /* Skip dummy compilation units. */
4260 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4261 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4263 do_cleanups (cleanups
);
4267 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4268 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4270 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4271 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4273 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4275 do_cleanups (cleanups
);
4278 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4279 does not lookup the specified DWO file.
4280 This cannot be used to read DWO files.
4282 THIS_CU->cu is always freed when done.
4283 This is done in order to not leave THIS_CU->cu in a state where we have
4284 to care whether it refers to the "main" CU or the DWO CU.
4285 We can revisit this if the data shows there's a performance issue. */
4288 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4289 die_reader_func_ftype
*die_reader_func
,
4292 init_cutu_and_read_dies_no_follow (this_cu
,
4293 &dwarf2_per_objfile
->abbrev
,
4295 die_reader_func
, data
);
4298 /* die_reader_func for process_psymtab_comp_unit. */
4301 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4303 struct die_info
*comp_unit_die
,
4307 struct dwarf2_cu
*cu
= reader
->cu
;
4308 struct objfile
*objfile
= cu
->objfile
;
4309 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4310 struct attribute
*attr
;
4312 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4313 struct partial_symtab
*pst
;
4315 const char *filename
;
4316 int *want_partial_unit_ptr
= data
;
4318 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4319 && (want_partial_unit_ptr
== NULL
4320 || !*want_partial_unit_ptr
))
4323 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4325 cu
->list_in_scope
= &file_symbols
;
4327 /* Allocate a new partial symbol table structure. */
4328 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4329 if (attr
== NULL
|| !DW_STRING (attr
))
4332 filename
= DW_STRING (attr
);
4333 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4335 /* TEXTLOW and TEXTHIGH are set below. */
4337 objfile
->global_psymbols
.next
,
4338 objfile
->static_psymbols
.next
);
4339 pst
->psymtabs_addrmap_supported
= 1;
4341 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4343 pst
->dirname
= DW_STRING (attr
);
4345 pst
->read_symtab_private
= per_cu
;
4347 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4349 /* Store the function that reads in the rest of the symbol table. */
4350 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4352 per_cu
->v
.psymtab
= pst
;
4354 dwarf2_find_base_address (comp_unit_die
, cu
);
4356 /* Possibly set the default values of LOWPC and HIGHPC from
4358 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4359 &best_highpc
, cu
, pst
);
4360 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4361 /* Store the contiguous range if it is not empty; it can be empty for
4362 CUs with no code. */
4363 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4364 best_lowpc
+ baseaddr
,
4365 best_highpc
+ baseaddr
- 1, pst
);
4367 /* Check if comp unit has_children.
4368 If so, read the rest of the partial symbols from this comp unit.
4369 If not, there's no more debug_info for this comp unit. */
4372 struct partial_die_info
*first_die
;
4373 CORE_ADDR lowpc
, highpc
;
4375 lowpc
= ((CORE_ADDR
) -1);
4376 highpc
= ((CORE_ADDR
) 0);
4378 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4380 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4383 /* If we didn't find a lowpc, set it to highpc to avoid
4384 complaints from `maint check'. */
4385 if (lowpc
== ((CORE_ADDR
) -1))
4388 /* If the compilation unit didn't have an explicit address range,
4389 then use the information extracted from its child dies. */
4393 best_highpc
= highpc
;
4396 pst
->textlow
= best_lowpc
+ baseaddr
;
4397 pst
->texthigh
= best_highpc
+ baseaddr
;
4399 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4400 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4401 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4402 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4403 sort_pst_symbols (pst
);
4405 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4408 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4409 struct dwarf2_per_cu_data
*iter
;
4411 /* Fill in 'dependencies' here; we fill in 'users' in a
4413 pst
->number_of_dependencies
= len
;
4414 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4415 len
* sizeof (struct symtab
*));
4417 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4420 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4422 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4425 if (per_cu
->is_debug_types
)
4427 /* It's not clear we want to do anything with stmt lists here.
4428 Waiting to see what gcc ultimately does. */
4432 /* Get the list of files included in the current compilation unit,
4433 and build a psymtab for each of them. */
4434 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4437 if (dwarf2_read_debug
)
4439 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4441 fprintf_unfiltered (gdb_stdlog
,
4442 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4443 ", %d global, %d static syms\n",
4444 per_cu
->is_debug_types
? "type" : "comp",
4445 per_cu
->offset
.sect_off
,
4446 paddress (gdbarch
, pst
->textlow
),
4447 paddress (gdbarch
, pst
->texthigh
),
4448 pst
->n_global_syms
, pst
->n_static_syms
);
4452 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4453 Process compilation unit THIS_CU for a psymtab. */
4456 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4457 int want_partial_unit
)
4459 /* If this compilation unit was already read in, free the
4460 cached copy in order to read it in again. This is
4461 necessary because we skipped some symbols when we first
4462 read in the compilation unit (see load_partial_dies).
4463 This problem could be avoided, but the benefit is unclear. */
4464 if (this_cu
->cu
!= NULL
)
4465 free_one_cached_comp_unit (this_cu
);
4467 gdb_assert (! this_cu
->is_debug_types
);
4468 init_cutu_and_read_dies (this_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4469 &want_partial_unit
);
4471 /* Age out any secondary CUs. */
4472 age_cached_comp_units ();
4475 /* Traversal function for htab_traverse_noresize.
4476 Process one .debug_types comp-unit. */
4479 process_psymtab_type_unit (void **slot
, void *info
)
4481 struct signatured_type
*sig_type
= (struct signatured_type
*) *slot
;
4482 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
4484 gdb_assert (per_cu
->is_debug_types
);
4485 gdb_assert (info
== NULL
);
4487 /* If this compilation unit was already read in, free the
4488 cached copy in order to read it in again. This is
4489 necessary because we skipped some symbols when we first
4490 read in the compilation unit (see load_partial_dies).
4491 This problem could be avoided, but the benefit is unclear. */
4492 if (per_cu
->cu
!= NULL
)
4493 free_one_cached_comp_unit (per_cu
);
4495 init_cutu_and_read_dies (per_cu
, 0, 0, process_psymtab_comp_unit_reader
,
4498 /* Age out any secondary CUs. */
4499 age_cached_comp_units ();
4504 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4505 Build partial symbol tables for the .debug_types comp-units. */
4508 build_type_psymtabs (struct objfile
*objfile
)
4510 if (! create_all_type_units (objfile
))
4513 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
4514 process_psymtab_type_unit
, NULL
);
4517 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
4520 psymtabs_addrmap_cleanup (void *o
)
4522 struct objfile
*objfile
= o
;
4524 objfile
->psymtabs_addrmap
= NULL
;
4527 /* Compute the 'user' field for each psymtab in OBJFILE. */
4530 set_partial_user (struct objfile
*objfile
)
4534 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4536 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4537 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4540 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
4542 /* Set the 'user' field only if it is not already set. */
4543 if (pst
->dependencies
[j
]->user
== NULL
)
4544 pst
->dependencies
[j
]->user
= pst
;
4549 /* Build the partial symbol table by doing a quick pass through the
4550 .debug_info and .debug_abbrev sections. */
4553 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
4555 struct cleanup
*back_to
, *addrmap_cleanup
;
4556 struct obstack temp_obstack
;
4559 if (dwarf2_read_debug
)
4561 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
4565 dwarf2_per_objfile
->reading_partial_symbols
= 1;
4567 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4569 /* Any cached compilation units will be linked by the per-objfile
4570 read_in_chain. Make sure to free them when we're done. */
4571 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
4573 build_type_psymtabs (objfile
);
4575 create_all_comp_units (objfile
);
4577 /* Create a temporary address map on a temporary obstack. We later
4578 copy this to the final obstack. */
4579 obstack_init (&temp_obstack
);
4580 make_cleanup_obstack_free (&temp_obstack
);
4581 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
4582 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
4584 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4586 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
4588 process_psymtab_comp_unit (per_cu
, 0);
4591 set_partial_user (objfile
);
4593 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
4594 &objfile
->objfile_obstack
);
4595 discard_cleanups (addrmap_cleanup
);
4597 do_cleanups (back_to
);
4599 if (dwarf2_read_debug
)
4600 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
4604 /* die_reader_func for load_partial_comp_unit. */
4607 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
4609 struct die_info
*comp_unit_die
,
4613 struct dwarf2_cu
*cu
= reader
->cu
;
4615 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4617 /* Check if comp unit has_children.
4618 If so, read the rest of the partial symbols from this comp unit.
4619 If not, there's no more debug_info for this comp unit. */
4621 load_partial_dies (reader
, info_ptr
, 0);
4624 /* Load the partial DIEs for a secondary CU into memory.
4625 This is also used when rereading a primary CU with load_all_dies. */
4628 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
4630 init_cutu_and_read_dies (this_cu
, 1, 1, load_partial_comp_unit_reader
, NULL
);
4633 /* Create a list of all compilation units in OBJFILE.
4634 This is only done for -readnow and building partial symtabs. */
4637 create_all_comp_units (struct objfile
*objfile
)
4641 struct dwarf2_per_cu_data
**all_comp_units
;
4644 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4645 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
4649 all_comp_units
= xmalloc (n_allocated
4650 * sizeof (struct dwarf2_per_cu_data
*));
4652 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
4653 + dwarf2_per_objfile
->info
.size
)
4655 unsigned int length
, initial_length_size
;
4656 struct dwarf2_per_cu_data
*this_cu
;
4659 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
4661 /* Read just enough information to find out where the next
4662 compilation unit is. */
4663 length
= read_initial_length (objfile
->obfd
, info_ptr
,
4664 &initial_length_size
);
4666 /* Save the compilation unit for later lookup. */
4667 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
4668 sizeof (struct dwarf2_per_cu_data
));
4669 memset (this_cu
, 0, sizeof (*this_cu
));
4670 this_cu
->offset
= offset
;
4671 this_cu
->length
= length
+ initial_length_size
;
4672 this_cu
->objfile
= objfile
;
4673 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
4675 if (n_comp_units
== n_allocated
)
4678 all_comp_units
= xrealloc (all_comp_units
,
4680 * sizeof (struct dwarf2_per_cu_data
*));
4682 all_comp_units
[n_comp_units
++] = this_cu
;
4684 info_ptr
= info_ptr
+ this_cu
->length
;
4687 dwarf2_per_objfile
->all_comp_units
4688 = obstack_alloc (&objfile
->objfile_obstack
,
4689 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4690 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
4691 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
4692 xfree (all_comp_units
);
4693 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
4696 /* Process all loaded DIEs for compilation unit CU, starting at
4697 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
4698 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
4699 DW_AT_ranges). If NEED_PC is set, then this function will set
4700 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
4701 and record the covered ranges in the addrmap. */
4704 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
4705 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4707 struct partial_die_info
*pdi
;
4709 /* Now, march along the PDI's, descending into ones which have
4710 interesting children but skipping the children of the other ones,
4711 until we reach the end of the compilation unit. */
4717 fixup_partial_die (pdi
, cu
);
4719 /* Anonymous namespaces or modules have no name but have interesting
4720 children, so we need to look at them. Ditto for anonymous
4723 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
4724 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
4725 || pdi
->tag
== DW_TAG_imported_unit
)
4729 case DW_TAG_subprogram
:
4730 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4732 case DW_TAG_constant
:
4733 case DW_TAG_variable
:
4734 case DW_TAG_typedef
:
4735 case DW_TAG_union_type
:
4736 if (!pdi
->is_declaration
)
4738 add_partial_symbol (pdi
, cu
);
4741 case DW_TAG_class_type
:
4742 case DW_TAG_interface_type
:
4743 case DW_TAG_structure_type
:
4744 if (!pdi
->is_declaration
)
4746 add_partial_symbol (pdi
, cu
);
4749 case DW_TAG_enumeration_type
:
4750 if (!pdi
->is_declaration
)
4751 add_partial_enumeration (pdi
, cu
);
4753 case DW_TAG_base_type
:
4754 case DW_TAG_subrange_type
:
4755 /* File scope base type definitions are added to the partial
4757 add_partial_symbol (pdi
, cu
);
4759 case DW_TAG_namespace
:
4760 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
4763 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
4765 case DW_TAG_imported_unit
:
4767 struct dwarf2_per_cu_data
*per_cu
;
4769 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
4772 /* Go read the partial unit, if needed. */
4773 if (per_cu
->v
.psymtab
== NULL
)
4774 process_psymtab_comp_unit (per_cu
, 1);
4776 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4785 /* If the die has a sibling, skip to the sibling. */
4787 pdi
= pdi
->die_sibling
;
4791 /* Functions used to compute the fully scoped name of a partial DIE.
4793 Normally, this is simple. For C++, the parent DIE's fully scoped
4794 name is concatenated with "::" and the partial DIE's name. For
4795 Java, the same thing occurs except that "." is used instead of "::".
4796 Enumerators are an exception; they use the scope of their parent
4797 enumeration type, i.e. the name of the enumeration type is not
4798 prepended to the enumerator.
4800 There are two complexities. One is DW_AT_specification; in this
4801 case "parent" means the parent of the target of the specification,
4802 instead of the direct parent of the DIE. The other is compilers
4803 which do not emit DW_TAG_namespace; in this case we try to guess
4804 the fully qualified name of structure types from their members'
4805 linkage names. This must be done using the DIE's children rather
4806 than the children of any DW_AT_specification target. We only need
4807 to do this for structures at the top level, i.e. if the target of
4808 any DW_AT_specification (if any; otherwise the DIE itself) does not
4811 /* Compute the scope prefix associated with PDI's parent, in
4812 compilation unit CU. The result will be allocated on CU's
4813 comp_unit_obstack, or a copy of the already allocated PDI->NAME
4814 field. NULL is returned if no prefix is necessary. */
4816 partial_die_parent_scope (struct partial_die_info
*pdi
,
4817 struct dwarf2_cu
*cu
)
4819 char *grandparent_scope
;
4820 struct partial_die_info
*parent
, *real_pdi
;
4822 /* We need to look at our parent DIE; if we have a DW_AT_specification,
4823 then this means the parent of the specification DIE. */
4826 while (real_pdi
->has_specification
)
4827 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
4829 parent
= real_pdi
->die_parent
;
4833 if (parent
->scope_set
)
4834 return parent
->scope
;
4836 fixup_partial_die (parent
, cu
);
4838 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
4840 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
4841 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
4842 Work around this problem here. */
4843 if (cu
->language
== language_cplus
4844 && parent
->tag
== DW_TAG_namespace
4845 && strcmp (parent
->name
, "::") == 0
4846 && grandparent_scope
== NULL
)
4848 parent
->scope
= NULL
;
4849 parent
->scope_set
= 1;
4853 if (pdi
->tag
== DW_TAG_enumerator
)
4854 /* Enumerators should not get the name of the enumeration as a prefix. */
4855 parent
->scope
= grandparent_scope
;
4856 else if (parent
->tag
== DW_TAG_namespace
4857 || parent
->tag
== DW_TAG_module
4858 || parent
->tag
== DW_TAG_structure_type
4859 || parent
->tag
== DW_TAG_class_type
4860 || parent
->tag
== DW_TAG_interface_type
4861 || parent
->tag
== DW_TAG_union_type
4862 || parent
->tag
== DW_TAG_enumeration_type
)
4864 if (grandparent_scope
== NULL
)
4865 parent
->scope
= parent
->name
;
4867 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
4869 parent
->name
, 0, cu
);
4873 /* FIXME drow/2004-04-01: What should we be doing with
4874 function-local names? For partial symbols, we should probably be
4876 complaint (&symfile_complaints
,
4877 _("unhandled containing DIE tag %d for DIE at %d"),
4878 parent
->tag
, pdi
->offset
.sect_off
);
4879 parent
->scope
= grandparent_scope
;
4882 parent
->scope_set
= 1;
4883 return parent
->scope
;
4886 /* Return the fully scoped name associated with PDI, from compilation unit
4887 CU. The result will be allocated with malloc. */
4890 partial_die_full_name (struct partial_die_info
*pdi
,
4891 struct dwarf2_cu
*cu
)
4895 /* If this is a template instantiation, we can not work out the
4896 template arguments from partial DIEs. So, unfortunately, we have
4897 to go through the full DIEs. At least any work we do building
4898 types here will be reused if full symbols are loaded later. */
4899 if (pdi
->has_template_arguments
)
4901 fixup_partial_die (pdi
, cu
);
4903 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
4905 struct die_info
*die
;
4906 struct attribute attr
;
4907 struct dwarf2_cu
*ref_cu
= cu
;
4909 /* DW_FORM_ref_addr is using section offset. */
4911 attr
.form
= DW_FORM_ref_addr
;
4912 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
4913 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
4915 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
4919 parent_scope
= partial_die_parent_scope (pdi
, cu
);
4920 if (parent_scope
== NULL
)
4923 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
4927 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
4929 struct objfile
*objfile
= cu
->objfile
;
4931 char *actual_name
= NULL
;
4933 int built_actual_name
= 0;
4935 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4937 actual_name
= partial_die_full_name (pdi
, cu
);
4939 built_actual_name
= 1;
4941 if (actual_name
== NULL
)
4942 actual_name
= pdi
->name
;
4946 case DW_TAG_subprogram
:
4947 if (pdi
->is_external
|| cu
->language
== language_ada
)
4949 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
4950 of the global scope. But in Ada, we want to be able to access
4951 nested procedures globally. So all Ada subprograms are stored
4952 in the global scope. */
4953 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4954 mst_text, objfile); */
4955 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4957 VAR_DOMAIN
, LOC_BLOCK
,
4958 &objfile
->global_psymbols
,
4959 0, pdi
->lowpc
+ baseaddr
,
4960 cu
->language
, objfile
);
4964 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
4965 mst_file_text, objfile); */
4966 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4968 VAR_DOMAIN
, LOC_BLOCK
,
4969 &objfile
->static_psymbols
,
4970 0, pdi
->lowpc
+ baseaddr
,
4971 cu
->language
, objfile
);
4974 case DW_TAG_constant
:
4976 struct psymbol_allocation_list
*list
;
4978 if (pdi
->is_external
)
4979 list
= &objfile
->global_psymbols
;
4981 list
= &objfile
->static_psymbols
;
4982 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4983 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
4984 list
, 0, 0, cu
->language
, objfile
);
4987 case DW_TAG_variable
:
4989 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
4993 && !dwarf2_per_objfile
->has_section_at_zero
)
4995 /* A global or static variable may also have been stripped
4996 out by the linker if unused, in which case its address
4997 will be nullified; do not add such variables into partial
4998 symbol table then. */
5000 else if (pdi
->is_external
)
5003 Don't enter into the minimal symbol tables as there is
5004 a minimal symbol table entry from the ELF symbols already.
5005 Enter into partial symbol table if it has a location
5006 descriptor or a type.
5007 If the location descriptor is missing, new_symbol will create
5008 a LOC_UNRESOLVED symbol, the address of the variable will then
5009 be determined from the minimal symbol table whenever the variable
5011 The address for the partial symbol table entry is not
5012 used by GDB, but it comes in handy for debugging partial symbol
5015 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5016 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5018 VAR_DOMAIN
, LOC_STATIC
,
5019 &objfile
->global_psymbols
,
5021 cu
->language
, objfile
);
5025 /* Static Variable. Skip symbols without location descriptors. */
5026 if (pdi
->d
.locdesc
== NULL
)
5028 if (built_actual_name
)
5029 xfree (actual_name
);
5032 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5033 mst_file_data, objfile); */
5034 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5036 VAR_DOMAIN
, LOC_STATIC
,
5037 &objfile
->static_psymbols
,
5039 cu
->language
, objfile
);
5042 case DW_TAG_typedef
:
5043 case DW_TAG_base_type
:
5044 case DW_TAG_subrange_type
:
5045 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5047 VAR_DOMAIN
, LOC_TYPEDEF
,
5048 &objfile
->static_psymbols
,
5049 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5051 case DW_TAG_namespace
:
5052 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5054 VAR_DOMAIN
, LOC_TYPEDEF
,
5055 &objfile
->global_psymbols
,
5056 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5058 case DW_TAG_class_type
:
5059 case DW_TAG_interface_type
:
5060 case DW_TAG_structure_type
:
5061 case DW_TAG_union_type
:
5062 case DW_TAG_enumeration_type
:
5063 /* Skip external references. The DWARF standard says in the section
5064 about "Structure, Union, and Class Type Entries": "An incomplete
5065 structure, union or class type is represented by a structure,
5066 union or class entry that does not have a byte size attribute
5067 and that has a DW_AT_declaration attribute." */
5068 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5070 if (built_actual_name
)
5071 xfree (actual_name
);
5075 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5076 static vs. global. */
5077 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5079 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5080 (cu
->language
== language_cplus
5081 || cu
->language
== language_java
)
5082 ? &objfile
->global_psymbols
5083 : &objfile
->static_psymbols
,
5084 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5087 case DW_TAG_enumerator
:
5088 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5090 VAR_DOMAIN
, LOC_CONST
,
5091 (cu
->language
== language_cplus
5092 || cu
->language
== language_java
)
5093 ? &objfile
->global_psymbols
5094 : &objfile
->static_psymbols
,
5095 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5101 if (built_actual_name
)
5102 xfree (actual_name
);
5105 /* Read a partial die corresponding to a namespace; also, add a symbol
5106 corresponding to that namespace to the symbol table. NAMESPACE is
5107 the name of the enclosing namespace. */
5110 add_partial_namespace (struct partial_die_info
*pdi
,
5111 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5112 int need_pc
, struct dwarf2_cu
*cu
)
5114 /* Add a symbol for the namespace. */
5116 add_partial_symbol (pdi
, cu
);
5118 /* Now scan partial symbols in that namespace. */
5120 if (pdi
->has_children
)
5121 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5124 /* Read a partial die corresponding to a Fortran module. */
5127 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5128 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5130 /* Now scan partial symbols in that module. */
5132 if (pdi
->has_children
)
5133 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5136 /* Read a partial die corresponding to a subprogram and create a partial
5137 symbol for that subprogram. When the CU language allows it, this
5138 routine also defines a partial symbol for each nested subprogram
5139 that this subprogram contains.
5141 DIE my also be a lexical block, in which case we simply search
5142 recursively for suprograms defined inside that lexical block.
5143 Again, this is only performed when the CU language allows this
5144 type of definitions. */
5147 add_partial_subprogram (struct partial_die_info
*pdi
,
5148 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5149 int need_pc
, struct dwarf2_cu
*cu
)
5151 if (pdi
->tag
== DW_TAG_subprogram
)
5153 if (pdi
->has_pc_info
)
5155 if (pdi
->lowpc
< *lowpc
)
5156 *lowpc
= pdi
->lowpc
;
5157 if (pdi
->highpc
> *highpc
)
5158 *highpc
= pdi
->highpc
;
5162 struct objfile
*objfile
= cu
->objfile
;
5164 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5165 SECT_OFF_TEXT (objfile
));
5166 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5167 pdi
->lowpc
+ baseaddr
,
5168 pdi
->highpc
- 1 + baseaddr
,
5169 cu
->per_cu
->v
.psymtab
);
5173 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5175 if (!pdi
->is_declaration
)
5176 /* Ignore subprogram DIEs that do not have a name, they are
5177 illegal. Do not emit a complaint at this point, we will
5178 do so when we convert this psymtab into a symtab. */
5180 add_partial_symbol (pdi
, cu
);
5184 if (! pdi
->has_children
)
5187 if (cu
->language
== language_ada
)
5189 pdi
= pdi
->die_child
;
5192 fixup_partial_die (pdi
, cu
);
5193 if (pdi
->tag
== DW_TAG_subprogram
5194 || pdi
->tag
== DW_TAG_lexical_block
)
5195 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5196 pdi
= pdi
->die_sibling
;
5201 /* Read a partial die corresponding to an enumeration type. */
5204 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5205 struct dwarf2_cu
*cu
)
5207 struct partial_die_info
*pdi
;
5209 if (enum_pdi
->name
!= NULL
)
5210 add_partial_symbol (enum_pdi
, cu
);
5212 pdi
= enum_pdi
->die_child
;
5215 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5216 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5218 add_partial_symbol (pdi
, cu
);
5219 pdi
= pdi
->die_sibling
;
5223 /* Return the initial uleb128 in the die at INFO_PTR. */
5226 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5228 unsigned int bytes_read
;
5230 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5233 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5234 Return the corresponding abbrev, or NULL if the number is zero (indicating
5235 an empty DIE). In either case *BYTES_READ will be set to the length of
5236 the initial number. */
5238 static struct abbrev_info
*
5239 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5240 struct dwarf2_cu
*cu
)
5242 bfd
*abfd
= cu
->objfile
->obfd
;
5243 unsigned int abbrev_number
;
5244 struct abbrev_info
*abbrev
;
5246 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5248 if (abbrev_number
== 0)
5251 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
5254 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5255 abbrev_number
, bfd_get_filename (abfd
));
5261 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5262 Returns a pointer to the end of a series of DIEs, terminated by an empty
5263 DIE. Any children of the skipped DIEs will also be skipped. */
5266 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5268 struct dwarf2_cu
*cu
= reader
->cu
;
5269 struct abbrev_info
*abbrev
;
5270 unsigned int bytes_read
;
5274 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5276 return info_ptr
+ bytes_read
;
5278 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5282 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5283 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5284 abbrev corresponding to that skipped uleb128 should be passed in
5285 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5289 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5290 struct abbrev_info
*abbrev
)
5292 unsigned int bytes_read
;
5293 struct attribute attr
;
5294 bfd
*abfd
= reader
->abfd
;
5295 struct dwarf2_cu
*cu
= reader
->cu
;
5296 gdb_byte
*buffer
= reader
->buffer
;
5297 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5298 gdb_byte
*start_info_ptr
= info_ptr
;
5299 unsigned int form
, i
;
5301 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5303 /* The only abbrev we care about is DW_AT_sibling. */
5304 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5306 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5307 if (attr
.form
== DW_FORM_ref_addr
)
5308 complaint (&symfile_complaints
,
5309 _("ignoring absolute DW_AT_sibling"));
5311 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5314 /* If it isn't DW_AT_sibling, skip this attribute. */
5315 form
= abbrev
->attrs
[i
].form
;
5319 case DW_FORM_ref_addr
:
5320 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5321 and later it is offset sized. */
5322 if (cu
->header
.version
== 2)
5323 info_ptr
+= cu
->header
.addr_size
;
5325 info_ptr
+= cu
->header
.offset_size
;
5328 info_ptr
+= cu
->header
.addr_size
;
5335 case DW_FORM_flag_present
:
5347 case DW_FORM_ref_sig8
:
5350 case DW_FORM_string
:
5351 read_direct_string (abfd
, info_ptr
, &bytes_read
);
5352 info_ptr
+= bytes_read
;
5354 case DW_FORM_sec_offset
:
5356 info_ptr
+= cu
->header
.offset_size
;
5358 case DW_FORM_exprloc
:
5360 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5361 info_ptr
+= bytes_read
;
5363 case DW_FORM_block1
:
5364 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
5366 case DW_FORM_block2
:
5367 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
5369 case DW_FORM_block4
:
5370 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
5374 case DW_FORM_ref_udata
:
5375 case DW_FORM_GNU_addr_index
:
5376 case DW_FORM_GNU_str_index
:
5377 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
5379 case DW_FORM_indirect
:
5380 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5381 info_ptr
+= bytes_read
;
5382 /* We need to continue parsing from here, so just go back to
5384 goto skip_attribute
;
5387 error (_("Dwarf Error: Cannot handle %s "
5388 "in DWARF reader [in module %s]"),
5389 dwarf_form_name (form
),
5390 bfd_get_filename (abfd
));
5394 if (abbrev
->has_children
)
5395 return skip_children (reader
, info_ptr
);
5400 /* Locate ORIG_PDI's sibling.
5401 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
5404 locate_pdi_sibling (const struct die_reader_specs
*reader
,
5405 struct partial_die_info
*orig_pdi
,
5408 /* Do we know the sibling already? */
5410 if (orig_pdi
->sibling
)
5411 return orig_pdi
->sibling
;
5413 /* Are there any children to deal with? */
5415 if (!orig_pdi
->has_children
)
5418 /* Skip the children the long way. */
5420 return skip_children (reader
, info_ptr
);
5423 /* Expand this partial symbol table into a full symbol table. */
5426 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
5432 warning (_("bug: psymtab for %s is already read in."),
5439 printf_filtered (_("Reading in symbols for %s..."),
5441 gdb_flush (gdb_stdout
);
5444 /* Restore our global data. */
5445 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
5446 dwarf2_objfile_data_key
);
5448 /* If this psymtab is constructed from a debug-only objfile, the
5449 has_section_at_zero flag will not necessarily be correct. We
5450 can get the correct value for this flag by looking at the data
5451 associated with the (presumably stripped) associated objfile. */
5452 if (pst
->objfile
->separate_debug_objfile_backlink
)
5454 struct dwarf2_per_objfile
*dpo_backlink
5455 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
5456 dwarf2_objfile_data_key
);
5458 dwarf2_per_objfile
->has_section_at_zero
5459 = dpo_backlink
->has_section_at_zero
;
5462 dwarf2_per_objfile
->reading_partial_symbols
= 0;
5464 psymtab_to_symtab_1 (pst
);
5466 /* Finish up the debug error message. */
5468 printf_filtered (_("done.\n"));
5472 process_cu_includes ();
5475 /* Reading in full CUs. */
5477 /* Add PER_CU to the queue. */
5480 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5481 enum language pretend_language
)
5483 struct dwarf2_queue_item
*item
;
5486 item
= xmalloc (sizeof (*item
));
5487 item
->per_cu
= per_cu
;
5488 item
->pretend_language
= pretend_language
;
5491 if (dwarf2_queue
== NULL
)
5492 dwarf2_queue
= item
;
5494 dwarf2_queue_tail
->next
= item
;
5496 dwarf2_queue_tail
= item
;
5499 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
5500 unit and add it to our queue.
5501 The result is non-zero if PER_CU was queued, otherwise the result is zero
5502 meaning either PER_CU is already queued or it is already loaded. */
5505 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
5506 struct dwarf2_per_cu_data
*per_cu
,
5507 enum language pretend_language
)
5509 /* We may arrive here during partial symbol reading, if we need full
5510 DIEs to process an unusual case (e.g. template arguments). Do
5511 not queue PER_CU, just tell our caller to load its DIEs. */
5512 if (dwarf2_per_objfile
->reading_partial_symbols
)
5514 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
5519 /* Mark the dependence relation so that we don't flush PER_CU
5521 dwarf2_add_dependence (this_cu
, per_cu
);
5523 /* If it's already on the queue, we have nothing to do. */
5527 /* If the compilation unit is already loaded, just mark it as
5529 if (per_cu
->cu
!= NULL
)
5531 per_cu
->cu
->last_used
= 0;
5535 /* Add it to the queue. */
5536 queue_comp_unit (per_cu
, pretend_language
);
5541 /* Process the queue. */
5544 process_queue (void)
5546 struct dwarf2_queue_item
*item
, *next_item
;
5548 if (dwarf2_read_debug
)
5550 fprintf_unfiltered (gdb_stdlog
,
5551 "Expanding one or more symtabs of objfile %s ...\n",
5552 dwarf2_per_objfile
->objfile
->name
);
5555 /* The queue starts out with one item, but following a DIE reference
5556 may load a new CU, adding it to the end of the queue. */
5557 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
5559 if (dwarf2_per_objfile
->using_index
5560 ? !item
->per_cu
->v
.quick
->symtab
5561 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
5562 process_full_comp_unit (item
->per_cu
, item
->pretend_language
);
5564 item
->per_cu
->queued
= 0;
5565 next_item
= item
->next
;
5569 dwarf2_queue_tail
= NULL
;
5571 if (dwarf2_read_debug
)
5573 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
5574 dwarf2_per_objfile
->objfile
->name
);
5578 /* Free all allocated queue entries. This function only releases anything if
5579 an error was thrown; if the queue was processed then it would have been
5580 freed as we went along. */
5583 dwarf2_release_queue (void *dummy
)
5585 struct dwarf2_queue_item
*item
, *last
;
5587 item
= dwarf2_queue
;
5590 /* Anything still marked queued is likely to be in an
5591 inconsistent state, so discard it. */
5592 if (item
->per_cu
->queued
)
5594 if (item
->per_cu
->cu
!= NULL
)
5595 free_one_cached_comp_unit (item
->per_cu
);
5596 item
->per_cu
->queued
= 0;
5604 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
5607 /* Read in full symbols for PST, and anything it depends on. */
5610 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
5612 struct dwarf2_per_cu_data
*per_cu
;
5618 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
5619 if (!pst
->dependencies
[i
]->readin
5620 && pst
->dependencies
[i
]->user
== NULL
)
5622 /* Inform about additional files that need to be read in. */
5625 /* FIXME: i18n: Need to make this a single string. */
5626 fputs_filtered (" ", gdb_stdout
);
5628 fputs_filtered ("and ", gdb_stdout
);
5630 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
5631 wrap_here (""); /* Flush output. */
5632 gdb_flush (gdb_stdout
);
5634 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
5637 per_cu
= pst
->read_symtab_private
;
5641 /* It's an include file, no symbols to read for it.
5642 Everything is in the parent symtab. */
5647 dw2_do_instantiate_symtab (per_cu
);
5650 /* Trivial hash function for die_info: the hash value of a DIE
5651 is its offset in .debug_info for this objfile. */
5654 die_hash (const void *item
)
5656 const struct die_info
*die
= item
;
5658 return die
->offset
.sect_off
;
5661 /* Trivial comparison function for die_info structures: two DIEs
5662 are equal if they have the same offset. */
5665 die_eq (const void *item_lhs
, const void *item_rhs
)
5667 const struct die_info
*die_lhs
= item_lhs
;
5668 const struct die_info
*die_rhs
= item_rhs
;
5670 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
5673 /* die_reader_func for load_full_comp_unit.
5674 This is identical to read_signatured_type_reader,
5675 but is kept separate for now. */
5678 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
5680 struct die_info
*comp_unit_die
,
5684 struct dwarf2_cu
*cu
= reader
->cu
;
5685 enum language
*language_ptr
= data
;
5687 gdb_assert (cu
->die_hash
== NULL
);
5689 htab_create_alloc_ex (cu
->header
.length
/ 12,
5693 &cu
->comp_unit_obstack
,
5694 hashtab_obstack_allocate
,
5695 dummy_obstack_deallocate
);
5698 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
5699 &info_ptr
, comp_unit_die
);
5700 cu
->dies
= comp_unit_die
;
5701 /* comp_unit_die is not stored in die_hash, no need. */
5703 /* We try not to read any attributes in this function, because not
5704 all CUs needed for references have been loaded yet, and symbol
5705 table processing isn't initialized. But we have to set the CU language,
5706 or we won't be able to build types correctly.
5707 Similarly, if we do not read the producer, we can not apply
5708 producer-specific interpretation. */
5709 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
5712 /* Load the DIEs associated with PER_CU into memory. */
5715 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5716 enum language pretend_language
)
5718 gdb_assert (! this_cu
->is_debug_types
);
5720 init_cutu_and_read_dies (this_cu
, 1, 1, load_full_comp_unit_reader
,
5724 /* Add a DIE to the delayed physname list. */
5727 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
5728 const char *name
, struct die_info
*die
,
5729 struct dwarf2_cu
*cu
)
5731 struct delayed_method_info mi
;
5733 mi
.fnfield_index
= fnfield_index
;
5737 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
5740 /* A cleanup for freeing the delayed method list. */
5743 free_delayed_list (void *ptr
)
5745 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
5746 if (cu
->method_list
!= NULL
)
5748 VEC_free (delayed_method_info
, cu
->method_list
);
5749 cu
->method_list
= NULL
;
5753 /* Compute the physnames of any methods on the CU's method list.
5755 The computation of method physnames is delayed in order to avoid the
5756 (bad) condition that one of the method's formal parameters is of an as yet
5760 compute_delayed_physnames (struct dwarf2_cu
*cu
)
5763 struct delayed_method_info
*mi
;
5764 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
5766 const char *physname
;
5767 struct fn_fieldlist
*fn_flp
5768 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
5769 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
5770 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
5774 /* Go objects should be embedded in a DW_TAG_module DIE,
5775 and it's not clear if/how imported objects will appear.
5776 To keep Go support simple until that's worked out,
5777 go back through what we've read and create something usable.
5778 We could do this while processing each DIE, and feels kinda cleaner,
5779 but that way is more invasive.
5780 This is to, for example, allow the user to type "p var" or "b main"
5781 without having to specify the package name, and allow lookups
5782 of module.object to work in contexts that use the expression
5786 fixup_go_packaging (struct dwarf2_cu
*cu
)
5788 char *package_name
= NULL
;
5789 struct pending
*list
;
5792 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
5794 for (i
= 0; i
< list
->nsyms
; ++i
)
5796 struct symbol
*sym
= list
->symbol
[i
];
5798 if (SYMBOL_LANGUAGE (sym
) == language_go
5799 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
5801 char *this_package_name
= go_symbol_package_name (sym
);
5803 if (this_package_name
== NULL
)
5805 if (package_name
== NULL
)
5806 package_name
= this_package_name
;
5809 if (strcmp (package_name
, this_package_name
) != 0)
5810 complaint (&symfile_complaints
,
5811 _("Symtab %s has objects from two different Go packages: %s and %s"),
5812 (sym
->symtab
&& sym
->symtab
->filename
5813 ? sym
->symtab
->filename
5814 : cu
->objfile
->name
),
5815 this_package_name
, package_name
);
5816 xfree (this_package_name
);
5822 if (package_name
!= NULL
)
5824 struct objfile
*objfile
= cu
->objfile
;
5825 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
5826 package_name
, objfile
);
5829 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5831 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
5832 SYMBOL_SET_LANGUAGE (sym
, language_go
);
5833 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
5834 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
5835 e.g., "main" finds the "main" module and not C's main(). */
5836 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
5837 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5838 SYMBOL_TYPE (sym
) = type
;
5840 add_symbol_to_list (sym
, &global_symbols
);
5842 xfree (package_name
);
5846 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
5848 /* Return the symtab for PER_CU. This works properly regardless of
5849 whether we're using the index or psymtabs. */
5851 static struct symtab
*
5852 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
5854 return (dwarf2_per_objfile
->using_index
5855 ? per_cu
->v
.quick
->symtab
5856 : per_cu
->v
.psymtab
->symtab
);
5859 /* A helper function for computing the list of all symbol tables
5860 included by PER_CU. */
5863 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
5864 htab_t all_children
,
5865 struct dwarf2_per_cu_data
*per_cu
)
5869 struct dwarf2_per_cu_data
*iter
;
5871 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
5874 /* This inclusion and its children have been processed. */
5879 /* Only add a CU if it has a symbol table. */
5880 if (get_symtab (per_cu
) != NULL
)
5881 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
5884 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
5886 recursively_compute_inclusions (result
, all_children
, iter
);
5889 /* Compute the symtab 'includes' fields for the symtab related to
5893 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
5895 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
5898 struct dwarf2_per_cu_data
*iter
;
5899 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
5900 htab_t all_children
;
5901 struct symtab
*symtab
= get_symtab (per_cu
);
5903 /* If we don't have a symtab, we can just skip this case. */
5907 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
5908 NULL
, xcalloc
, xfree
);
5911 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
5914 recursively_compute_inclusions (&result_children
, all_children
, iter
);
5916 /* Now we have a transitive closure of all the included CUs, so
5917 we can convert it to a list of symtabs. */
5918 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
5920 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
5921 (len
+ 1) * sizeof (struct symtab
*));
5923 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
5925 symtab
->includes
[ix
] = get_symtab (iter
);
5926 symtab
->includes
[len
] = NULL
;
5928 VEC_free (dwarf2_per_cu_ptr
, result_children
);
5929 htab_delete (all_children
);
5933 /* Compute the 'includes' field for the symtabs of all the CUs we just
5937 process_cu_includes (void)
5940 struct dwarf2_per_cu_data
*iter
;
5943 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
5946 compute_symtab_includes (iter
);
5948 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
5951 /* Generate full symbol information for PER_CU, whose DIEs have
5952 already been loaded into memory. */
5955 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
5956 enum language pretend_language
)
5958 struct dwarf2_cu
*cu
= per_cu
->cu
;
5959 struct objfile
*objfile
= per_cu
->objfile
;
5960 CORE_ADDR lowpc
, highpc
;
5961 struct symtab
*symtab
;
5962 struct cleanup
*back_to
, *delayed_list_cleanup
;
5965 if (dwarf2_read_debug
)
5967 fprintf_unfiltered (gdb_stdlog
,
5968 "Expanding symtab of %s at offset 0x%x\n",
5969 per_cu
->is_debug_types
? "TU" : "CU",
5970 per_cu
->offset
.sect_off
);
5973 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5976 back_to
= make_cleanup (really_free_pendings
, NULL
);
5977 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
5979 cu
->list_in_scope
= &file_symbols
;
5981 cu
->language
= pretend_language
;
5982 cu
->language_defn
= language_def (cu
->language
);
5984 /* Do line number decoding in read_file_scope () */
5985 process_die (cu
->dies
, cu
);
5987 /* For now fudge the Go package. */
5988 if (cu
->language
== language_go
)
5989 fixup_go_packaging (cu
);
5991 /* Now that we have processed all the DIEs in the CU, all the types
5992 should be complete, and it should now be safe to compute all of the
5994 compute_delayed_physnames (cu
);
5995 do_cleanups (delayed_list_cleanup
);
5997 /* Some compilers don't define a DW_AT_high_pc attribute for the
5998 compilation unit. If the DW_AT_high_pc is missing, synthesize
5999 it, by scanning the DIE's below the compilation unit. */
6000 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6002 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
6006 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6008 /* Set symtab language to language from DW_AT_language. If the
6009 compilation is from a C file generated by language preprocessors, do
6010 not set the language if it was already deduced by start_subfile. */
6011 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6012 symtab
->language
= cu
->language
;
6014 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6015 produce DW_AT_location with location lists but it can be possibly
6016 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6017 there were bugs in prologue debug info, fixed later in GCC-4.5
6018 by "unwind info for epilogues" patch (which is not directly related).
6020 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6021 needed, it would be wrong due to missing DW_AT_producer there.
6023 Still one can confuse GDB by using non-standard GCC compilation
6024 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6026 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6027 symtab
->locations_valid
= 1;
6029 if (gcc_4_minor
>= 5)
6030 symtab
->epilogue_unwind_valid
= 1;
6032 symtab
->call_site_htab
= cu
->call_site_htab
;
6035 if (dwarf2_per_objfile
->using_index
)
6036 per_cu
->v
.quick
->symtab
= symtab
;
6039 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6040 pst
->symtab
= symtab
;
6044 /* Push it for inclusion processing later. */
6045 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6047 do_cleanups (back_to
);
6049 if (dwarf2_read_debug
)
6051 fprintf_unfiltered (gdb_stdlog
,
6052 "Done expanding symtab of %s at offset 0x%x\n",
6053 per_cu
->is_debug_types
? "TU" : "CU",
6054 per_cu
->offset
.sect_off
);
6058 /* Process an imported unit DIE. */
6061 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6063 struct attribute
*attr
;
6065 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6068 struct dwarf2_per_cu_data
*per_cu
;
6069 struct symtab
*imported_symtab
;
6072 offset
= dwarf2_get_ref_die_offset (attr
);
6073 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6075 /* Queue the unit, if needed. */
6076 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
6077 load_full_comp_unit (per_cu
, cu
->language
);
6079 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
6084 /* Process a die and its children. */
6087 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6091 case DW_TAG_padding
:
6093 case DW_TAG_compile_unit
:
6094 case DW_TAG_partial_unit
:
6095 read_file_scope (die
, cu
);
6097 case DW_TAG_type_unit
:
6098 read_type_unit_scope (die
, cu
);
6100 case DW_TAG_subprogram
:
6101 case DW_TAG_inlined_subroutine
:
6102 read_func_scope (die
, cu
);
6104 case DW_TAG_lexical_block
:
6105 case DW_TAG_try_block
:
6106 case DW_TAG_catch_block
:
6107 read_lexical_block_scope (die
, cu
);
6109 case DW_TAG_GNU_call_site
:
6110 read_call_site_scope (die
, cu
);
6112 case DW_TAG_class_type
:
6113 case DW_TAG_interface_type
:
6114 case DW_TAG_structure_type
:
6115 case DW_TAG_union_type
:
6116 process_structure_scope (die
, cu
);
6118 case DW_TAG_enumeration_type
:
6119 process_enumeration_scope (die
, cu
);
6122 /* These dies have a type, but processing them does not create
6123 a symbol or recurse to process the children. Therefore we can
6124 read them on-demand through read_type_die. */
6125 case DW_TAG_subroutine_type
:
6126 case DW_TAG_set_type
:
6127 case DW_TAG_array_type
:
6128 case DW_TAG_pointer_type
:
6129 case DW_TAG_ptr_to_member_type
:
6130 case DW_TAG_reference_type
:
6131 case DW_TAG_string_type
:
6134 case DW_TAG_base_type
:
6135 case DW_TAG_subrange_type
:
6136 case DW_TAG_typedef
:
6137 /* Add a typedef symbol for the type definition, if it has a
6139 new_symbol (die
, read_type_die (die
, cu
), cu
);
6141 case DW_TAG_common_block
:
6142 read_common_block (die
, cu
);
6144 case DW_TAG_common_inclusion
:
6146 case DW_TAG_namespace
:
6147 processing_has_namespace_info
= 1;
6148 read_namespace (die
, cu
);
6151 processing_has_namespace_info
= 1;
6152 read_module (die
, cu
);
6154 case DW_TAG_imported_declaration
:
6155 case DW_TAG_imported_module
:
6156 processing_has_namespace_info
= 1;
6157 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6158 || cu
->language
!= language_fortran
))
6159 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6160 dwarf_tag_name (die
->tag
));
6161 read_import_statement (die
, cu
);
6164 case DW_TAG_imported_unit
:
6165 process_imported_unit_die (die
, cu
);
6169 new_symbol (die
, NULL
, cu
);
6174 /* A helper function for dwarf2_compute_name which determines whether DIE
6175 needs to have the name of the scope prepended to the name listed in the
6179 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6181 struct attribute
*attr
;
6185 case DW_TAG_namespace
:
6186 case DW_TAG_typedef
:
6187 case DW_TAG_class_type
:
6188 case DW_TAG_interface_type
:
6189 case DW_TAG_structure_type
:
6190 case DW_TAG_union_type
:
6191 case DW_TAG_enumeration_type
:
6192 case DW_TAG_enumerator
:
6193 case DW_TAG_subprogram
:
6197 case DW_TAG_variable
:
6198 case DW_TAG_constant
:
6199 /* We only need to prefix "globally" visible variables. These include
6200 any variable marked with DW_AT_external or any variable that
6201 lives in a namespace. [Variables in anonymous namespaces
6202 require prefixing, but they are not DW_AT_external.] */
6204 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6206 struct dwarf2_cu
*spec_cu
= cu
;
6208 return die_needs_namespace (die_specification (die
, &spec_cu
),
6212 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6213 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6214 && die
->parent
->tag
!= DW_TAG_module
)
6216 /* A variable in a lexical block of some kind does not need a
6217 namespace, even though in C++ such variables may be external
6218 and have a mangled name. */
6219 if (die
->parent
->tag
== DW_TAG_lexical_block
6220 || die
->parent
->tag
== DW_TAG_try_block
6221 || die
->parent
->tag
== DW_TAG_catch_block
6222 || die
->parent
->tag
== DW_TAG_subprogram
)
6231 /* Retrieve the last character from a mem_file. */
6234 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
6236 char *last_char_p
= (char *) object
;
6239 *last_char_p
= buffer
[length
- 1];
6242 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
6243 compute the physname for the object, which include a method's:
6244 - formal parameters (C++/Java),
6245 - receiver type (Go),
6246 - return type (Java).
6248 The term "physname" is a bit confusing.
6249 For C++, for example, it is the demangled name.
6250 For Go, for example, it's the mangled name.
6252 For Ada, return the DIE's linkage name rather than the fully qualified
6253 name. PHYSNAME is ignored..
6255 The result is allocated on the objfile_obstack and canonicalized. */
6258 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
6261 struct objfile
*objfile
= cu
->objfile
;
6264 name
= dwarf2_name (die
, cu
);
6266 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
6267 compute it by typename_concat inside GDB. */
6268 if (cu
->language
== language_ada
6269 || (cu
->language
== language_fortran
&& physname
))
6271 /* For Ada unit, we prefer the linkage name over the name, as
6272 the former contains the exported name, which the user expects
6273 to be able to reference. Ideally, we want the user to be able
6274 to reference this entity using either natural or linkage name,
6275 but we haven't started looking at this enhancement yet. */
6276 struct attribute
*attr
;
6278 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6280 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6281 if (attr
&& DW_STRING (attr
))
6282 return DW_STRING (attr
);
6285 /* These are the only languages we know how to qualify names in. */
6287 && (cu
->language
== language_cplus
|| cu
->language
== language_java
6288 || cu
->language
== language_fortran
))
6290 if (die_needs_namespace (die
, cu
))
6294 struct ui_file
*buf
;
6296 prefix
= determine_prefix (die
, cu
);
6297 buf
= mem_fileopen ();
6298 if (*prefix
!= '\0')
6300 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
6303 fputs_unfiltered (prefixed_name
, buf
);
6304 xfree (prefixed_name
);
6307 fputs_unfiltered (name
, buf
);
6309 /* Template parameters may be specified in the DIE's DW_AT_name, or
6310 as children with DW_TAG_template_type_param or
6311 DW_TAG_value_type_param. If the latter, add them to the name
6312 here. If the name already has template parameters, then
6313 skip this step; some versions of GCC emit both, and
6314 it is more efficient to use the pre-computed name.
6316 Something to keep in mind about this process: it is very
6317 unlikely, or in some cases downright impossible, to produce
6318 something that will match the mangled name of a function.
6319 If the definition of the function has the same debug info,
6320 we should be able to match up with it anyway. But fallbacks
6321 using the minimal symbol, for instance to find a method
6322 implemented in a stripped copy of libstdc++, will not work.
6323 If we do not have debug info for the definition, we will have to
6324 match them up some other way.
6326 When we do name matching there is a related problem with function
6327 templates; two instantiated function templates are allowed to
6328 differ only by their return types, which we do not add here. */
6330 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
6332 struct attribute
*attr
;
6333 struct die_info
*child
;
6336 die
->building_fullname
= 1;
6338 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
6343 struct dwarf2_locexpr_baton
*baton
;
6346 if (child
->tag
!= DW_TAG_template_type_param
6347 && child
->tag
!= DW_TAG_template_value_param
)
6352 fputs_unfiltered ("<", buf
);
6356 fputs_unfiltered (", ", buf
);
6358 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
6361 complaint (&symfile_complaints
,
6362 _("template parameter missing DW_AT_type"));
6363 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
6366 type
= die_type (child
, cu
);
6368 if (child
->tag
== DW_TAG_template_type_param
)
6370 c_print_type (type
, "", buf
, -1, 0);
6374 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
6377 complaint (&symfile_complaints
,
6378 _("template parameter missing "
6379 "DW_AT_const_value"));
6380 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
6384 dwarf2_const_value_attr (attr
, type
, name
,
6385 &cu
->comp_unit_obstack
, cu
,
6386 &value
, &bytes
, &baton
);
6388 if (TYPE_NOSIGN (type
))
6389 /* GDB prints characters as NUMBER 'CHAR'. If that's
6390 changed, this can use value_print instead. */
6391 c_printchar (value
, type
, buf
);
6394 struct value_print_options opts
;
6397 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
6401 else if (bytes
!= NULL
)
6403 v
= allocate_value (type
);
6404 memcpy (value_contents_writeable (v
), bytes
,
6405 TYPE_LENGTH (type
));
6408 v
= value_from_longest (type
, value
);
6410 /* Specify decimal so that we do not depend on
6412 get_formatted_print_options (&opts
, 'd');
6414 value_print (v
, buf
, &opts
);
6420 die
->building_fullname
= 0;
6424 /* Close the argument list, with a space if necessary
6425 (nested templates). */
6426 char last_char
= '\0';
6427 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
6428 if (last_char
== '>')
6429 fputs_unfiltered (" >", buf
);
6431 fputs_unfiltered (">", buf
);
6435 /* For Java and C++ methods, append formal parameter type
6436 information, if PHYSNAME. */
6438 if (physname
&& die
->tag
== DW_TAG_subprogram
6439 && (cu
->language
== language_cplus
6440 || cu
->language
== language_java
))
6442 struct type
*type
= read_type_die (die
, cu
);
6444 c_type_print_args (type
, buf
, 1, cu
->language
);
6446 if (cu
->language
== language_java
)
6448 /* For java, we must append the return type to method
6450 if (die
->tag
== DW_TAG_subprogram
)
6451 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
6454 else if (cu
->language
== language_cplus
)
6456 /* Assume that an artificial first parameter is
6457 "this", but do not crash if it is not. RealView
6458 marks unnamed (and thus unused) parameters as
6459 artificial; there is no way to differentiate
6461 if (TYPE_NFIELDS (type
) > 0
6462 && TYPE_FIELD_ARTIFICIAL (type
, 0)
6463 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
6464 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
6466 fputs_unfiltered (" const", buf
);
6470 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
6472 ui_file_delete (buf
);
6474 if (cu
->language
== language_cplus
)
6477 = dwarf2_canonicalize_name (name
, cu
,
6478 &objfile
->objfile_obstack
);
6489 /* Return the fully qualified name of DIE, based on its DW_AT_name.
6490 If scope qualifiers are appropriate they will be added. The result
6491 will be allocated on the objfile_obstack, or NULL if the DIE does
6492 not have a name. NAME may either be from a previous call to
6493 dwarf2_name or NULL.
6495 The output string will be canonicalized (if C++/Java). */
6498 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6500 return dwarf2_compute_name (name
, die
, cu
, 0);
6503 /* Construct a physname for the given DIE in CU. NAME may either be
6504 from a previous call to dwarf2_name or NULL. The result will be
6505 allocated on the objfile_objstack or NULL if the DIE does not have a
6508 The output string will be canonicalized (if C++/Java). */
6511 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
6513 struct objfile
*objfile
= cu
->objfile
;
6514 struct attribute
*attr
;
6515 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
6516 struct cleanup
*back_to
;
6519 /* In this case dwarf2_compute_name is just a shortcut not building anything
6521 if (!die_needs_namespace (die
, cu
))
6522 return dwarf2_compute_name (name
, die
, cu
, 1);
6524 back_to
= make_cleanup (null_cleanup
, NULL
);
6526 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
6528 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
6530 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
6532 if (attr
&& DW_STRING (attr
))
6536 mangled
= DW_STRING (attr
);
6538 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
6539 type. It is easier for GDB users to search for such functions as
6540 `name(params)' than `long name(params)'. In such case the minimal
6541 symbol names do not match the full symbol names but for template
6542 functions there is never a need to look up their definition from their
6543 declaration so the only disadvantage remains the minimal symbol
6544 variant `long name(params)' does not have the proper inferior type.
6547 if (cu
->language
== language_go
)
6549 /* This is a lie, but we already lie to the caller new_symbol_full.
6550 new_symbol_full assumes we return the mangled name.
6551 This just undoes that lie until things are cleaned up. */
6556 demangled
= cplus_demangle (mangled
,
6557 (DMGL_PARAMS
| DMGL_ANSI
6558 | (cu
->language
== language_java
6559 ? DMGL_JAVA
| DMGL_RET_POSTFIX
6564 make_cleanup (xfree
, demangled
);
6574 if (canon
== NULL
|| check_physname
)
6576 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
6578 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
6580 /* It may not mean a bug in GDB. The compiler could also
6581 compute DW_AT_linkage_name incorrectly. But in such case
6582 GDB would need to be bug-to-bug compatible. */
6584 complaint (&symfile_complaints
,
6585 _("Computed physname <%s> does not match demangled <%s> "
6586 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
6587 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
6589 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
6590 is available here - over computed PHYSNAME. It is safer
6591 against both buggy GDB and buggy compilers. */
6605 retval
= obsavestring (retval
, strlen (retval
),
6606 &objfile
->objfile_obstack
);
6608 do_cleanups (back_to
);
6612 /* Read the import statement specified by the given die and record it. */
6615 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
6617 struct objfile
*objfile
= cu
->objfile
;
6618 struct attribute
*import_attr
;
6619 struct die_info
*imported_die
, *child_die
;
6620 struct dwarf2_cu
*imported_cu
;
6621 const char *imported_name
;
6622 const char *imported_name_prefix
;
6623 const char *canonical_name
;
6624 const char *import_alias
;
6625 const char *imported_declaration
= NULL
;
6626 const char *import_prefix
;
6627 VEC (const_char_ptr
) *excludes
= NULL
;
6628 struct cleanup
*cleanups
;
6632 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6633 if (import_attr
== NULL
)
6635 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6636 dwarf_tag_name (die
->tag
));
6641 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
6642 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6643 if (imported_name
== NULL
)
6645 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
6647 The import in the following code:
6661 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
6662 <52> DW_AT_decl_file : 1
6663 <53> DW_AT_decl_line : 6
6664 <54> DW_AT_import : <0x75>
6665 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
6667 <5b> DW_AT_decl_file : 1
6668 <5c> DW_AT_decl_line : 2
6669 <5d> DW_AT_type : <0x6e>
6671 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
6672 <76> DW_AT_byte_size : 4
6673 <77> DW_AT_encoding : 5 (signed)
6675 imports the wrong die ( 0x75 instead of 0x58 ).
6676 This case will be ignored until the gcc bug is fixed. */
6680 /* Figure out the local name after import. */
6681 import_alias
= dwarf2_name (die
, cu
);
6683 /* Figure out where the statement is being imported to. */
6684 import_prefix
= determine_prefix (die
, cu
);
6686 /* Figure out what the scope of the imported die is and prepend it
6687 to the name of the imported die. */
6688 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
6690 if (imported_die
->tag
!= DW_TAG_namespace
6691 && imported_die
->tag
!= DW_TAG_module
)
6693 imported_declaration
= imported_name
;
6694 canonical_name
= imported_name_prefix
;
6696 else if (strlen (imported_name_prefix
) > 0)
6698 temp
= alloca (strlen (imported_name_prefix
)
6699 + 2 + strlen (imported_name
) + 1);
6700 strcpy (temp
, imported_name_prefix
);
6701 strcat (temp
, "::");
6702 strcat (temp
, imported_name
);
6703 canonical_name
= temp
;
6706 canonical_name
= imported_name
;
6708 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
6710 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
6711 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
6712 child_die
= sibling_die (child_die
))
6714 /* DWARF-4: A Fortran use statement with a “rename list” may be
6715 represented by an imported module entry with an import attribute
6716 referring to the module and owned entries corresponding to those
6717 entities that are renamed as part of being imported. */
6719 if (child_die
->tag
!= DW_TAG_imported_declaration
)
6721 complaint (&symfile_complaints
,
6722 _("child DW_TAG_imported_declaration expected "
6723 "- DIE at 0x%x [in module %s]"),
6724 child_die
->offset
.sect_off
, objfile
->name
);
6728 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
6729 if (import_attr
== NULL
)
6731 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
6732 dwarf_tag_name (child_die
->tag
));
6737 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
6739 imported_name
= dwarf2_name (imported_die
, imported_cu
);
6740 if (imported_name
== NULL
)
6742 complaint (&symfile_complaints
,
6743 _("child DW_TAG_imported_declaration has unknown "
6744 "imported name - DIE at 0x%x [in module %s]"),
6745 child_die
->offset
.sect_off
, objfile
->name
);
6749 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
6751 process_die (child_die
, cu
);
6754 cp_add_using_directive (import_prefix
,
6757 imported_declaration
,
6759 &objfile
->objfile_obstack
);
6761 do_cleanups (cleanups
);
6764 /* Cleanup function for read_file_scope. */
6767 free_cu_line_header (void *arg
)
6769 struct dwarf2_cu
*cu
= arg
;
6771 free_line_header (cu
->line_header
);
6772 cu
->line_header
= NULL
;
6776 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
6777 char **name
, char **comp_dir
)
6779 struct attribute
*attr
;
6784 /* Find the filename. Do not use dwarf2_name here, since the filename
6785 is not a source language identifier. */
6786 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6789 *name
= DW_STRING (attr
);
6792 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6794 *comp_dir
= DW_STRING (attr
);
6795 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
6797 *comp_dir
= ldirname (*name
);
6798 if (*comp_dir
!= NULL
)
6799 make_cleanup (xfree
, *comp_dir
);
6801 if (*comp_dir
!= NULL
)
6803 /* Irix 6.2 native cc prepends <machine>.: to the compilation
6804 directory, get rid of it. */
6805 char *cp
= strchr (*comp_dir
, ':');
6807 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
6812 *name
= "<unknown>";
6815 /* Handle DW_AT_stmt_list for a compilation unit or type unit.
6816 DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU.
6817 COMP_DIR is the compilation directory.
6818 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
6821 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
6822 const char *comp_dir
, int want_line_info
)
6824 struct attribute
*attr
;
6826 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6829 unsigned int line_offset
= DW_UNSND (attr
);
6830 struct line_header
*line_header
6831 = dwarf_decode_line_header (line_offset
, cu
);
6835 cu
->line_header
= line_header
;
6836 make_cleanup (free_cu_line_header
, cu
);
6837 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, want_line_info
);
6842 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
6845 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6848 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6849 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
6850 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
6851 struct attribute
*attr
;
6853 char *comp_dir
= NULL
;
6854 struct die_info
*child_die
;
6855 bfd
*abfd
= objfile
->obfd
;
6858 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6860 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
6862 /* If we didn't find a lowpc, set it to highpc to avoid complaints
6863 from finish_block. */
6864 if (lowpc
== ((CORE_ADDR
) -1))
6869 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
6871 prepare_one_comp_unit (cu
, die
, cu
->language
);
6873 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
6874 standardised yet. As a workaround for the language detection we fall
6875 back to the DW_AT_producer string. */
6876 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
6877 cu
->language
= language_opencl
;
6879 /* Similar hack for Go. */
6880 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
6881 set_cu_language (DW_LANG_Go
, cu
);
6883 /* We assume that we're processing GCC output. */
6884 processing_gcc_compilation
= 2;
6886 processing_has_namespace_info
= 0;
6888 start_symtab (name
, comp_dir
, lowpc
);
6889 record_debugformat ("DWARF 2");
6890 record_producer (cu
->producer
);
6892 /* Decode line number information if present. We do this before
6893 processing child DIEs, so that the line header table is available
6894 for DW_AT_decl_file. */
6895 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 1);
6897 /* Process all dies in compilation unit. */
6898 if (die
->child
!= NULL
)
6900 child_die
= die
->child
;
6901 while (child_die
&& child_die
->tag
)
6903 process_die (child_die
, cu
);
6904 child_die
= sibling_die (child_die
);
6908 /* Decode macro information, if present. Dwarf 2 macro information
6909 refers to information in the line number info statement program
6910 header, so we can only read it if we've read the header
6912 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
6913 if (attr
&& cu
->line_header
)
6915 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
6916 complaint (&symfile_complaints
,
6917 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
6919 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
6923 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
6924 if (attr
&& cu
->line_header
)
6926 unsigned int macro_offset
= DW_UNSND (attr
);
6928 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
6932 do_cleanups (back_to
);
6935 /* Process DW_TAG_type_unit.
6936 For TUs we want to skip the first top level sibling if it's not the
6937 actual type being defined by this TU. In this case the first top
6938 level sibling is there to provide context only. */
6941 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6943 struct objfile
*objfile
= cu
->objfile
;
6944 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6946 struct attribute
*attr
;
6948 char *comp_dir
= NULL
;
6949 struct die_info
*child_die
;
6950 bfd
*abfd
= objfile
->obfd
;
6952 /* start_symtab needs a low pc, but we don't really have one.
6953 Do what read_file_scope would do in the absence of such info. */
6954 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6956 /* Find the filename. Do not use dwarf2_name here, since the filename
6957 is not a source language identifier. */
6958 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
6960 name
= DW_STRING (attr
);
6962 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
6964 comp_dir
= DW_STRING (attr
);
6965 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
6967 comp_dir
= ldirname (name
);
6968 if (comp_dir
!= NULL
)
6969 make_cleanup (xfree
, comp_dir
);
6975 prepare_one_comp_unit (cu
, die
, language_minimal
);
6977 /* We assume that we're processing GCC output. */
6978 processing_gcc_compilation
= 2;
6980 processing_has_namespace_info
= 0;
6982 start_symtab (name
, comp_dir
, lowpc
);
6983 record_debugformat ("DWARF 2");
6984 record_producer (cu
->producer
);
6986 /* Decode line number information if present. We do this before
6987 processing child DIEs, so that the line header table is available
6988 for DW_AT_decl_file.
6989 We don't need the pc/line-number mapping for type units. */
6990 handle_DW_AT_stmt_list (die
, cu
, comp_dir
, 0);
6992 /* Process the dies in the type unit. */
6993 if (die
->child
== NULL
)
6995 dump_die_for_error (die
);
6996 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
6997 bfd_get_filename (abfd
));
7000 child_die
= die
->child
;
7002 while (child_die
&& child_die
->tag
)
7004 process_die (child_die
, cu
);
7006 child_die
= sibling_die (child_die
);
7009 do_cleanups (back_to
);
7015 hash_dwo_file (const void *item
)
7017 const struct dwo_file
*dwo_file
= item
;
7019 return htab_hash_string (dwo_file
->dwo_name
);
7023 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7025 const struct dwo_file
*lhs
= item_lhs
;
7026 const struct dwo_file
*rhs
= item_rhs
;
7028 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
7031 /* Allocate a hash table for DWO files. */
7034 allocate_dwo_file_hash_table (void)
7036 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7038 return htab_create_alloc_ex (41,
7042 &objfile
->objfile_obstack
,
7043 hashtab_obstack_allocate
,
7044 dummy_obstack_deallocate
);
7048 hash_dwo_unit (const void *item
)
7050 const struct dwo_unit
*dwo_unit
= item
;
7052 /* This drops the top 32 bits of the id, but is ok for a hash. */
7053 return dwo_unit
->signature
;
7057 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7059 const struct dwo_unit
*lhs
= item_lhs
;
7060 const struct dwo_unit
*rhs
= item_rhs
;
7062 /* The signature is assumed to be unique within the DWO file.
7063 So while object file CU dwo_id's always have the value zero,
7064 that's OK, assuming each object file DWO file has only one CU,
7065 and that's the rule for now. */
7066 return lhs
->signature
== rhs
->signature
;
7069 /* Allocate a hash table for DWO CUs,TUs.
7070 There is one of these tables for each of CUs,TUs for each DWO file. */
7073 allocate_dwo_unit_table (struct objfile
*objfile
)
7075 /* Start out with a pretty small number.
7076 Generally DWO files contain only one CU and maybe some TUs. */
7077 return htab_create_alloc_ex (3,
7081 &objfile
->objfile_obstack
,
7082 hashtab_obstack_allocate
,
7083 dummy_obstack_deallocate
);
7086 /* This function is mapped across the sections and remembers the offset and
7087 size of each of the DWO debugging sections we are interested in. */
7090 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
7092 struct dwo_file
*dwo_file
= dwo_file_ptr
;
7093 const struct dwo_section_names
*names
= &dwo_section_names
;
7095 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
7097 dwo_file
->sections
.abbrev
.asection
= sectp
;
7098 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
7100 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
7102 dwo_file
->sections
.info
.asection
= sectp
;
7103 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
7105 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
7107 dwo_file
->sections
.line
.asection
= sectp
;
7108 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
7110 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
7112 dwo_file
->sections
.loc
.asection
= sectp
;
7113 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
7115 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
7117 dwo_file
->sections
.macinfo
.asection
= sectp
;
7118 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
7120 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7122 dwo_file
->sections
.macro
.asection
= sectp
;
7123 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7125 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7127 dwo_file
->sections
.str
.asection
= sectp
;
7128 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7130 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7132 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7133 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7135 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7137 struct dwarf2_section_info type_section
;
7139 memset (&type_section
, 0, sizeof (type_section
));
7140 type_section
.asection
= sectp
;
7141 type_section
.size
= bfd_get_section_size (sectp
);
7142 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7147 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7149 struct create_dwo_info_table_data
7151 struct dwo_file
*dwo_file
;
7155 /* die_reader_func for create_debug_info_hash_table. */
7158 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7160 struct die_info
*comp_unit_die
,
7164 struct dwarf2_cu
*cu
= reader
->cu
;
7165 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7166 sect_offset offset
= cu
->per_cu
->offset
;
7167 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7168 struct create_dwo_info_table_data
*data
= datap
;
7169 struct dwo_file
*dwo_file
= data
->dwo_file
;
7170 htab_t cu_htab
= data
->cu_htab
;
7172 struct attribute
*attr
;
7173 struct dwo_unit
*dwo_unit
;
7175 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7178 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
7179 " its dwo_id [in module %s]"),
7180 offset
.sect_off
, dwo_file
->dwo_name
);
7184 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
7185 dwo_unit
->dwo_file
= dwo_file
;
7186 dwo_unit
->signature
= DW_UNSND (attr
);
7187 dwo_unit
->info_or_types_section
= section
;
7188 dwo_unit
->offset
= offset
;
7189 dwo_unit
->length
= cu
->per_cu
->length
;
7191 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
7192 gdb_assert (slot
!= NULL
);
7195 const struct dwo_unit
*dup_dwo_unit
= *slot
;
7197 complaint (&symfile_complaints
,
7198 _("debug entry at offset 0x%x is duplicate to the entry at"
7199 " offset 0x%x, dwo_id 0x%s [in module %s]"),
7200 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
7201 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
7202 dwo_file
->dwo_name
);
7207 if (dwarf2_read_debug
)
7208 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
7210 phex (dwo_unit
->signature
,
7211 sizeof (dwo_unit
->signature
)));
7214 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
7217 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
7219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7220 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
7223 gdb_byte
*info_ptr
, *end_ptr
;
7224 struct create_dwo_info_table_data create_dwo_info_table_data
;
7226 dwarf2_read_section (objfile
, section
);
7227 info_ptr
= section
->buffer
;
7229 if (info_ptr
== NULL
)
7232 /* We can't set abfd until now because the section may be empty or
7233 not present, in which case section->asection will be NULL. */
7234 abfd
= section
->asection
->owner
;
7236 if (dwarf2_read_debug
)
7237 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
7238 bfd_get_filename (abfd
));
7240 cu_htab
= allocate_dwo_unit_table (objfile
);
7242 create_dwo_info_table_data
.dwo_file
= dwo_file
;
7243 create_dwo_info_table_data
.cu_htab
= cu_htab
;
7245 end_ptr
= info_ptr
+ section
->size
;
7246 while (info_ptr
< end_ptr
)
7248 struct dwarf2_per_cu_data per_cu
;
7250 memset (&per_cu
, 0, sizeof (per_cu
));
7251 per_cu
.objfile
= objfile
;
7252 per_cu
.is_debug_types
= 0;
7253 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
7254 per_cu
.info_or_types_section
= section
;
7256 init_cutu_and_read_dies_no_follow (&per_cu
,
7257 &dwo_file
->sections
.abbrev
,
7259 create_debug_info_hash_table_reader
,
7260 &create_dwo_info_table_data
);
7262 info_ptr
+= per_cu
.length
;
7268 /* Subroutine of open_dwo_file to simplify it.
7269 Open the file specified by FILE_NAME and hand it off to BFD for
7270 preliminary analysis. Return a newly initialized bfd *, which
7271 includes a canonicalized copy of FILE_NAME.
7272 In case of trouble, return NULL.
7273 NOTE: This function is derived from symfile_bfd_open. */
7276 try_open_dwo_file (const char *file_name
)
7280 char *absolute_name
;
7282 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
7283 O_RDONLY
| O_BINARY
, &absolute_name
);
7287 sym_bfd
= bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
);
7290 xfree (absolute_name
);
7293 bfd_set_cacheable (sym_bfd
, 1);
7295 if (!bfd_check_format (sym_bfd
, bfd_object
))
7297 bfd_close (sym_bfd
); /* This also closes desc. */
7298 xfree (absolute_name
);
7302 /* bfd_usrdata exists for applications and libbfd must not touch it. */
7303 gdb_assert (bfd_usrdata (sym_bfd
) == NULL
);
7308 /* Try to open DWO file DWO_NAME.
7309 COMP_DIR is the DW_AT_comp_dir attribute.
7310 The result is the bfd handle of the file.
7311 If there is a problem finding or opening the file, return NULL.
7312 Upon success, the canonicalized path of the file is stored in the bfd,
7313 same as symfile_bfd_open. */
7316 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
7320 if (IS_ABSOLUTE_PATH (dwo_name
))
7321 return try_open_dwo_file (dwo_name
);
7323 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
7325 if (comp_dir
!= NULL
)
7327 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
7329 /* NOTE: If comp_dir is a relative path, this will also try the
7330 search path, which seems useful. */
7331 abfd
= try_open_dwo_file (path_to_try
);
7332 xfree (path_to_try
);
7337 /* That didn't work, try debug-file-directory, which, despite its name,
7338 is a list of paths. */
7340 if (*debug_file_directory
== '\0')
7343 return try_open_dwo_file (dwo_name
);
7346 /* Initialize the use of the DWO file specified by DWO_NAME. */
7348 static struct dwo_file
*
7349 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
7351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7352 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7355 struct cleanup
*cleanups
;
7357 if (dwarf2_read_debug
)
7358 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
7360 abfd
= open_dwo_file (dwo_name
, comp_dir
);
7363 dwo_file
->dwo_name
= dwo_name
;
7364 dwo_file
->dwo_bfd
= abfd
;
7366 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
7368 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
7370 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
7372 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
7373 dwo_file
->sections
.types
);
7375 discard_cleanups (cleanups
);
7380 /* Lookup DWO file DWO_NAME. */
7382 static struct dwo_file
*
7383 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
7385 struct dwo_file
*dwo_file
;
7386 struct dwo_file find_entry
;
7389 if (dwarf2_per_objfile
->dwo_files
== NULL
)
7390 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
7392 /* Have we already seen this DWO file? */
7393 find_entry
.dwo_name
= dwo_name
;
7394 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
7396 /* If not, read it in and build a table of the DWOs it contains. */
7398 *slot
= init_dwo_file (dwo_name
, comp_dir
);
7400 /* NOTE: This will be NULL if unable to open the file. */
7406 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
7407 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7408 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
7409 nomenclature as TUs).
7410 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7411 (dwo_id mismatch or couldn't find the DWO file). */
7413 static struct dwo_unit
*
7414 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7415 char *dwo_name
, const char *comp_dir
,
7418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7419 struct dwo_file
*dwo_file
;
7421 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7422 if (dwo_file
== NULL
)
7425 /* Look up the DWO using its signature(dwo_id). */
7427 if (dwo_file
->cus
!= NULL
)
7429 struct dwo_unit find_dwo_cu
, *dwo_cu
;
7431 find_dwo_cu
.signature
= signature
;
7432 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
7438 /* We didn't find it. This must mean a dwo_id mismatch. */
7440 complaint (&symfile_complaints
,
7441 _("Could not find DWO CU referenced by CU at offset 0x%x"
7443 this_cu
->offset
.sect_off
, objfile
->name
);
7447 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
7448 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
7449 The result is a pointer to the dwo_unit object or NULL if we didn't find it
7450 (dwo_id mismatch or couldn't find the DWO file). */
7452 static struct dwo_unit
*
7453 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
7454 char *dwo_name
, const char *comp_dir
)
7456 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7457 struct dwo_file
*dwo_file
;
7459 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
7460 if (dwo_file
== NULL
)
7463 /* Look up the DWO using its signature(dwo_id). */
7465 if (dwo_file
->tus
!= NULL
)
7467 struct dwo_unit find_dwo_tu
, *dwo_tu
;
7469 find_dwo_tu
.signature
= this_tu
->signature
;
7470 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
7476 /* We didn't find it. This must mean a dwo_id mismatch. */
7478 complaint (&symfile_complaints
,
7479 _("Could not find DWO TU referenced by TU at offset 0x%x"
7481 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
7485 /* Free all resources associated with DWO_FILE.
7486 Close the DWO file and munmap the sections.
7487 All memory should be on the objfile obstack. */
7490 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
7493 struct dwarf2_section_info
*section
;
7495 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
7496 bfd_close (dwo_file
->dwo_bfd
);
7498 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
7499 munmap_section_buffer (&dwo_file
->sections
.info
);
7500 munmap_section_buffer (&dwo_file
->sections
.line
);
7501 munmap_section_buffer (&dwo_file
->sections
.loc
);
7502 munmap_section_buffer (&dwo_file
->sections
.str
);
7503 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
7506 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7509 munmap_section_buffer (section
);
7511 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
7514 /* Wrapper for free_dwo_file for use in cleanups. */
7517 free_dwo_file_cleanup (void *arg
)
7519 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
7520 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7522 free_dwo_file (dwo_file
, objfile
);
7525 /* Traversal function for free_dwo_files. */
7528 free_dwo_file_from_slot (void **slot
, void *info
)
7530 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7531 struct objfile
*objfile
= (struct objfile
*) info
;
7533 free_dwo_file (dwo_file
, objfile
);
7538 /* Free all resources associated with DWO_FILES. */
7541 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
7543 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
7546 /* Read in various DIEs. */
7548 /* qsort helper for inherit_abstract_dies. */
7551 unsigned_int_compar (const void *ap
, const void *bp
)
7553 unsigned int a
= *(unsigned int *) ap
;
7554 unsigned int b
= *(unsigned int *) bp
;
7556 return (a
> b
) - (b
> a
);
7559 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
7560 Inherit only the children of the DW_AT_abstract_origin DIE not being
7561 already referenced by DW_AT_abstract_origin from the children of the
7565 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
7567 struct die_info
*child_die
;
7568 unsigned die_children_count
;
7569 /* CU offsets which were referenced by children of the current DIE. */
7570 sect_offset
*offsets
;
7571 sect_offset
*offsets_end
, *offsetp
;
7572 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
7573 struct die_info
*origin_die
;
7574 /* Iterator of the ORIGIN_DIE children. */
7575 struct die_info
*origin_child_die
;
7576 struct cleanup
*cleanups
;
7577 struct attribute
*attr
;
7578 struct dwarf2_cu
*origin_cu
;
7579 struct pending
**origin_previous_list_in_scope
;
7581 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
7585 /* Note that following die references may follow to a die in a
7589 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
7591 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
7593 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
7594 origin_cu
->list_in_scope
= cu
->list_in_scope
;
7596 if (die
->tag
!= origin_die
->tag
7597 && !(die
->tag
== DW_TAG_inlined_subroutine
7598 && origin_die
->tag
== DW_TAG_subprogram
))
7599 complaint (&symfile_complaints
,
7600 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
7601 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
7603 child_die
= die
->child
;
7604 die_children_count
= 0;
7605 while (child_die
&& child_die
->tag
)
7607 child_die
= sibling_die (child_die
);
7608 die_children_count
++;
7610 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
7611 cleanups
= make_cleanup (xfree
, offsets
);
7613 offsets_end
= offsets
;
7614 child_die
= die
->child
;
7615 while (child_die
&& child_die
->tag
)
7617 /* For each CHILD_DIE, find the corresponding child of
7618 ORIGIN_DIE. If there is more than one layer of
7619 DW_AT_abstract_origin, follow them all; there shouldn't be,
7620 but GCC versions at least through 4.4 generate this (GCC PR
7622 struct die_info
*child_origin_die
= child_die
;
7623 struct dwarf2_cu
*child_origin_cu
= cu
;
7627 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
7631 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
7635 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
7636 counterpart may exist. */
7637 if (child_origin_die
!= child_die
)
7639 if (child_die
->tag
!= child_origin_die
->tag
7640 && !(child_die
->tag
== DW_TAG_inlined_subroutine
7641 && child_origin_die
->tag
== DW_TAG_subprogram
))
7642 complaint (&symfile_complaints
,
7643 _("Child DIE 0x%x and its abstract origin 0x%x have "
7644 "different tags"), child_die
->offset
.sect_off
,
7645 child_origin_die
->offset
.sect_off
);
7646 if (child_origin_die
->parent
!= origin_die
)
7647 complaint (&symfile_complaints
,
7648 _("Child DIE 0x%x and its abstract origin 0x%x have "
7649 "different parents"), child_die
->offset
.sect_off
,
7650 child_origin_die
->offset
.sect_off
);
7652 *offsets_end
++ = child_origin_die
->offset
;
7654 child_die
= sibling_die (child_die
);
7656 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
7657 unsigned_int_compar
);
7658 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
7659 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
7660 complaint (&symfile_complaints
,
7661 _("Multiple children of DIE 0x%x refer "
7662 "to DIE 0x%x as their abstract origin"),
7663 die
->offset
.sect_off
, offsetp
->sect_off
);
7666 origin_child_die
= origin_die
->child
;
7667 while (origin_child_die
&& origin_child_die
->tag
)
7669 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
7670 while (offsetp
< offsets_end
7671 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
7673 if (offsetp
>= offsets_end
7674 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
7676 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
7677 process_die (origin_child_die
, origin_cu
);
7679 origin_child_die
= sibling_die (origin_child_die
);
7681 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
7683 do_cleanups (cleanups
);
7687 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7689 struct objfile
*objfile
= cu
->objfile
;
7690 struct context_stack
*new;
7693 struct die_info
*child_die
;
7694 struct attribute
*attr
, *call_line
, *call_file
;
7697 struct block
*block
;
7698 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7699 VEC (symbolp
) *template_args
= NULL
;
7700 struct template_symbol
*templ_func
= NULL
;
7704 /* If we do not have call site information, we can't show the
7705 caller of this inlined function. That's too confusing, so
7706 only use the scope for local variables. */
7707 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
7708 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
7709 if (call_line
== NULL
|| call_file
== NULL
)
7711 read_lexical_block_scope (die
, cu
);
7716 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7718 name
= dwarf2_name (die
, cu
);
7720 /* Ignore functions with missing or empty names. These are actually
7721 illegal according to the DWARF standard. */
7724 complaint (&symfile_complaints
,
7725 _("missing name for subprogram DIE at %d"),
7726 die
->offset
.sect_off
);
7730 /* Ignore functions with missing or invalid low and high pc attributes. */
7731 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7733 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7734 if (!attr
|| !DW_UNSND (attr
))
7735 complaint (&symfile_complaints
,
7736 _("cannot get low and high bounds "
7737 "for subprogram DIE at %d"),
7738 die
->offset
.sect_off
);
7745 /* If we have any template arguments, then we must allocate a
7746 different sort of symbol. */
7747 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
7749 if (child_die
->tag
== DW_TAG_template_type_param
7750 || child_die
->tag
== DW_TAG_template_value_param
)
7752 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7753 struct template_symbol
);
7754 templ_func
->base
.is_cplus_template_function
= 1;
7759 new = push_context (0, lowpc
);
7760 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
7761 (struct symbol
*) templ_func
);
7763 /* If there is a location expression for DW_AT_frame_base, record
7765 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
7767 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
7768 expression is being recorded directly in the function's symbol
7769 and not in a separate frame-base object. I guess this hack is
7770 to avoid adding some sort of frame-base adjunct/annex to the
7771 function's symbol :-(. The problem with doing this is that it
7772 results in a function symbol with a location expression that
7773 has nothing to do with the location of the function, ouch! The
7774 relationship should be: a function's symbol has-a frame base; a
7775 frame-base has-a location expression. */
7776 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
7778 cu
->list_in_scope
= &local_symbols
;
7780 if (die
->child
!= NULL
)
7782 child_die
= die
->child
;
7783 while (child_die
&& child_die
->tag
)
7785 if (child_die
->tag
== DW_TAG_template_type_param
7786 || child_die
->tag
== DW_TAG_template_value_param
)
7788 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7791 VEC_safe_push (symbolp
, template_args
, arg
);
7794 process_die (child_die
, cu
);
7795 child_die
= sibling_die (child_die
);
7799 inherit_abstract_dies (die
, cu
);
7801 /* If we have a DW_AT_specification, we might need to import using
7802 directives from the context of the specification DIE. See the
7803 comment in determine_prefix. */
7804 if (cu
->language
== language_cplus
7805 && dwarf2_attr (die
, DW_AT_specification
, cu
))
7807 struct dwarf2_cu
*spec_cu
= cu
;
7808 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
7812 child_die
= spec_die
->child
;
7813 while (child_die
&& child_die
->tag
)
7815 if (child_die
->tag
== DW_TAG_imported_module
)
7816 process_die (child_die
, spec_cu
);
7817 child_die
= sibling_die (child_die
);
7820 /* In some cases, GCC generates specification DIEs that
7821 themselves contain DW_AT_specification attributes. */
7822 spec_die
= die_specification (spec_die
, &spec_cu
);
7826 new = pop_context ();
7827 /* Make a block for the local symbols within. */
7828 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
7829 lowpc
, highpc
, objfile
);
7831 /* For C++, set the block's scope. */
7832 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
7833 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
7834 determine_prefix (die
, cu
),
7835 processing_has_namespace_info
);
7837 /* If we have address ranges, record them. */
7838 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7840 /* Attach template arguments to function. */
7841 if (! VEC_empty (symbolp
, template_args
))
7843 gdb_assert (templ_func
!= NULL
);
7845 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
7846 templ_func
->template_arguments
7847 = obstack_alloc (&objfile
->objfile_obstack
,
7848 (templ_func
->n_template_arguments
7849 * sizeof (struct symbol
*)));
7850 memcpy (templ_func
->template_arguments
,
7851 VEC_address (symbolp
, template_args
),
7852 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
7853 VEC_free (symbolp
, template_args
);
7856 /* In C++, we can have functions nested inside functions (e.g., when
7857 a function declares a class that has methods). This means that
7858 when we finish processing a function scope, we may need to go
7859 back to building a containing block's symbol lists. */
7860 local_symbols
= new->locals
;
7861 param_symbols
= new->params
;
7862 using_directives
= new->using_directives
;
7864 /* If we've finished processing a top-level function, subsequent
7865 symbols go in the file symbol list. */
7866 if (outermost_context_p ())
7867 cu
->list_in_scope
= &file_symbols
;
7870 /* Process all the DIES contained within a lexical block scope. Start
7871 a new scope, process the dies, and then close the scope. */
7874 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7876 struct objfile
*objfile
= cu
->objfile
;
7877 struct context_stack
*new;
7878 CORE_ADDR lowpc
, highpc
;
7879 struct die_info
*child_die
;
7882 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7884 /* Ignore blocks with missing or invalid low and high pc attributes. */
7885 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
7886 as multiple lexical blocks? Handling children in a sane way would
7887 be nasty. Might be easier to properly extend generic blocks to
7889 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
7894 push_context (0, lowpc
);
7895 if (die
->child
!= NULL
)
7897 child_die
= die
->child
;
7898 while (child_die
&& child_die
->tag
)
7900 process_die (child_die
, cu
);
7901 child_die
= sibling_die (child_die
);
7904 new = pop_context ();
7906 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
7909 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
7912 /* Note that recording ranges after traversing children, as we
7913 do here, means that recording a parent's ranges entails
7914 walking across all its children's ranges as they appear in
7915 the address map, which is quadratic behavior.
7917 It would be nicer to record the parent's ranges before
7918 traversing its children, simply overriding whatever you find
7919 there. But since we don't even decide whether to create a
7920 block until after we've traversed its children, that's hard
7922 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
7924 local_symbols
= new->locals
;
7925 using_directives
= new->using_directives
;
7928 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
7931 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7933 struct objfile
*objfile
= cu
->objfile
;
7934 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7935 CORE_ADDR pc
, baseaddr
;
7936 struct attribute
*attr
;
7937 struct call_site
*call_site
, call_site_local
;
7940 struct die_info
*child_die
;
7942 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7944 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7947 complaint (&symfile_complaints
,
7948 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
7949 "DIE 0x%x [in module %s]"),
7950 die
->offset
.sect_off
, objfile
->name
);
7953 pc
= DW_ADDR (attr
) + baseaddr
;
7955 if (cu
->call_site_htab
== NULL
)
7956 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
7957 NULL
, &objfile
->objfile_obstack
,
7958 hashtab_obstack_allocate
, NULL
);
7959 call_site_local
.pc
= pc
;
7960 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
7963 complaint (&symfile_complaints
,
7964 _("Duplicate PC %s for DW_TAG_GNU_call_site "
7965 "DIE 0x%x [in module %s]"),
7966 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
7970 /* Count parameters at the caller. */
7973 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7974 child_die
= sibling_die (child_die
))
7976 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
7978 complaint (&symfile_complaints
,
7979 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
7980 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
7981 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
7988 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
7989 (sizeof (*call_site
)
7990 + (sizeof (*call_site
->parameter
)
7993 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
7996 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
7998 struct die_info
*func_die
;
8000 /* Skip also over DW_TAG_inlined_subroutine. */
8001 for (func_die
= die
->parent
;
8002 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8003 && func_die
->tag
!= DW_TAG_subroutine_type
;
8004 func_die
= func_die
->parent
);
8006 /* DW_AT_GNU_all_call_sites is a superset
8007 of DW_AT_GNU_all_tail_call_sites. */
8009 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8010 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8012 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8013 not complete. But keep CALL_SITE for look ups via call_site_htab,
8014 both the initial caller containing the real return address PC and
8015 the final callee containing the current PC of a chain of tail
8016 calls do not need to have the tail call list complete. But any
8017 function candidate for a virtual tail call frame searched via
8018 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8019 determined unambiguously. */
8023 struct type
*func_type
= NULL
;
8026 func_type
= get_die_type (func_die
, cu
);
8027 if (func_type
!= NULL
)
8029 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
8031 /* Enlist this call site to the function. */
8032 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
8033 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
8036 complaint (&symfile_complaints
,
8037 _("Cannot find function owning DW_TAG_GNU_call_site "
8038 "DIE 0x%x [in module %s]"),
8039 die
->offset
.sect_off
, objfile
->name
);
8043 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
8045 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8046 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
8047 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
8048 /* Keep NULL DWARF_BLOCK. */;
8049 else if (attr_form_is_block (attr
))
8051 struct dwarf2_locexpr_baton
*dlbaton
;
8053 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
8054 dlbaton
->data
= DW_BLOCK (attr
)->data
;
8055 dlbaton
->size
= DW_BLOCK (attr
)->size
;
8056 dlbaton
->per_cu
= cu
->per_cu
;
8058 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
8060 else if (is_ref_attr (attr
))
8062 struct dwarf2_cu
*target_cu
= cu
;
8063 struct die_info
*target_die
;
8065 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
8066 gdb_assert (target_cu
->objfile
== objfile
);
8067 if (die_is_declaration (target_die
, target_cu
))
8069 const char *target_physname
;
8071 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
8072 if (target_physname
== NULL
)
8073 complaint (&symfile_complaints
,
8074 _("DW_AT_GNU_call_site_target target DIE has invalid "
8075 "physname, for referencing DIE 0x%x [in module %s]"),
8076 die
->offset
.sect_off
, objfile
->name
);
8078 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
8084 /* DW_AT_entry_pc should be preferred. */
8085 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
8086 complaint (&symfile_complaints
,
8087 _("DW_AT_GNU_call_site_target target DIE has invalid "
8088 "low pc, for referencing DIE 0x%x [in module %s]"),
8089 die
->offset
.sect_off
, objfile
->name
);
8091 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
8095 complaint (&symfile_complaints
,
8096 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
8097 "block nor reference, for DIE 0x%x [in module %s]"),
8098 die
->offset
.sect_off
, objfile
->name
);
8100 call_site
->per_cu
= cu
->per_cu
;
8102 for (child_die
= die
->child
;
8103 child_die
&& child_die
->tag
;
8104 child_die
= sibling_die (child_die
))
8106 struct call_site_parameter
*parameter
;
8107 struct attribute
*loc
, *origin
;
8109 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8111 /* Already printed the complaint above. */
8115 gdb_assert (call_site
->parameter_count
< nparams
);
8116 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8118 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8119 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8120 register is contained in DW_AT_GNU_call_site_value. */
8122 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8123 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8124 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8128 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8129 offset
= dwarf2_get_ref_die_offset (origin
);
8130 gdb_assert (offset
.sect_off
>= cu
->header
.offset
.sect_off
);
8131 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8132 - cu
->header
.offset
.sect_off
);
8134 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8136 complaint (&symfile_complaints
,
8137 _("No DW_FORM_block* DW_AT_location for "
8138 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8139 child_die
->offset
.sect_off
, objfile
->name
);
8144 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8145 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8146 if (parameter
->u
.dwarf_reg
!= -1)
8147 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8148 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8149 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8150 ¶meter
->u
.fb_offset
))
8151 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8154 complaint (&symfile_complaints
,
8155 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8156 "for DW_FORM_block* DW_AT_location is supported for "
8157 "DW_TAG_GNU_call_site child DIE 0x%x "
8159 child_die
->offset
.sect_off
, objfile
->name
);
8164 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
8165 if (!attr_form_is_block (attr
))
8167 complaint (&symfile_complaints
,
8168 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
8169 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8170 child_die
->offset
.sect_off
, objfile
->name
);
8173 parameter
->value
= DW_BLOCK (attr
)->data
;
8174 parameter
->value_size
= DW_BLOCK (attr
)->size
;
8176 /* Parameters are not pre-cleared by memset above. */
8177 parameter
->data_value
= NULL
;
8178 parameter
->data_value_size
= 0;
8179 call_site
->parameter_count
++;
8181 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
8184 if (!attr_form_is_block (attr
))
8185 complaint (&symfile_complaints
,
8186 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
8187 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8188 child_die
->offset
.sect_off
, objfile
->name
);
8191 parameter
->data_value
= DW_BLOCK (attr
)->data
;
8192 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
8198 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
8199 Return 1 if the attributes are present and valid, otherwise, return 0.
8200 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
8203 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
8204 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
8205 struct partial_symtab
*ranges_pst
)
8207 struct objfile
*objfile
= cu
->objfile
;
8208 struct comp_unit_head
*cu_header
= &cu
->header
;
8209 bfd
*obfd
= objfile
->obfd
;
8210 unsigned int addr_size
= cu_header
->addr_size
;
8211 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8212 /* Base address selection entry. */
8223 found_base
= cu
->base_known
;
8224 base
= cu
->base_address
;
8226 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
8227 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8229 complaint (&symfile_complaints
,
8230 _("Offset %d out of bounds for DW_AT_ranges attribute"),
8234 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8236 /* Read in the largest possible address. */
8237 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
8238 if ((marker
& mask
) == mask
)
8240 /* If we found the largest possible address, then
8241 read the base address. */
8242 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8243 buffer
+= 2 * addr_size
;
8244 offset
+= 2 * addr_size
;
8250 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8254 CORE_ADDR range_beginning
, range_end
;
8256 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
8257 buffer
+= addr_size
;
8258 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
8259 buffer
+= addr_size
;
8260 offset
+= 2 * addr_size
;
8262 /* An end of list marker is a pair of zero addresses. */
8263 if (range_beginning
== 0 && range_end
== 0)
8264 /* Found the end of list entry. */
8267 /* Each base address selection entry is a pair of 2 values.
8268 The first is the largest possible address, the second is
8269 the base address. Check for a base address here. */
8270 if ((range_beginning
& mask
) == mask
)
8272 /* If we found the largest possible address, then
8273 read the base address. */
8274 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
8281 /* We have no valid base address for the ranges
8283 complaint (&symfile_complaints
,
8284 _("Invalid .debug_ranges data (no base address)"));
8288 if (range_beginning
> range_end
)
8290 /* Inverted range entries are invalid. */
8291 complaint (&symfile_complaints
,
8292 _("Invalid .debug_ranges data (inverted range)"));
8296 /* Empty range entries have no effect. */
8297 if (range_beginning
== range_end
)
8300 range_beginning
+= base
;
8303 if (ranges_pst
!= NULL
)
8304 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8305 range_beginning
+ baseaddr
,
8306 range_end
- 1 + baseaddr
,
8309 /* FIXME: This is recording everything as a low-high
8310 segment of consecutive addresses. We should have a
8311 data structure for discontiguous block ranges
8315 low
= range_beginning
;
8321 if (range_beginning
< low
)
8322 low
= range_beginning
;
8323 if (range_end
> high
)
8329 /* If the first entry is an end-of-list marker, the range
8330 describes an empty scope, i.e. no instructions. */
8336 *high_return
= high
;
8340 /* Get low and high pc attributes from a die. Return 1 if the attributes
8341 are present and valid, otherwise, return 0. Return -1 if the range is
8342 discontinuous, i.e. derived from DW_AT_ranges information. */
8345 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
8346 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
8347 struct partial_symtab
*pst
)
8349 struct attribute
*attr
;
8350 struct attribute
*attr_high
;
8355 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8358 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8361 low
= DW_ADDR (attr
);
8362 if (attr_high
->form
== DW_FORM_addr
8363 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8364 high
= DW_ADDR (attr_high
);
8366 high
= low
+ DW_UNSND (attr_high
);
8369 /* Found high w/o low attribute. */
8372 /* Found consecutive range of addresses. */
8377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8380 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
8382 /* Value of the DW_AT_ranges attribute is the offset in the
8383 .debug_ranges section. */
8384 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
8386 /* Found discontinuous range of addresses. */
8391 /* read_partial_die has also the strict LOW < HIGH requirement. */
8395 /* When using the GNU linker, .gnu.linkonce. sections are used to
8396 eliminate duplicate copies of functions and vtables and such.
8397 The linker will arbitrarily choose one and discard the others.
8398 The AT_*_pc values for such functions refer to local labels in
8399 these sections. If the section from that file was discarded, the
8400 labels are not in the output, so the relocs get a value of 0.
8401 If this is a discarded function, mark the pc bounds as invalid,
8402 so that GDB will ignore it. */
8403 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
8412 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
8413 its low and high PC addresses. Do nothing if these addresses could not
8414 be determined. Otherwise, set LOWPC to the low address if it is smaller,
8415 and HIGHPC to the high address if greater than HIGHPC. */
8418 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
8419 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8420 struct dwarf2_cu
*cu
)
8422 CORE_ADDR low
, high
;
8423 struct die_info
*child
= die
->child
;
8425 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
8427 *lowpc
= min (*lowpc
, low
);
8428 *highpc
= max (*highpc
, high
);
8431 /* If the language does not allow nested subprograms (either inside
8432 subprograms or lexical blocks), we're done. */
8433 if (cu
->language
!= language_ada
)
8436 /* Check all the children of the given DIE. If it contains nested
8437 subprograms, then check their pc bounds. Likewise, we need to
8438 check lexical blocks as well, as they may also contain subprogram
8440 while (child
&& child
->tag
)
8442 if (child
->tag
== DW_TAG_subprogram
8443 || child
->tag
== DW_TAG_lexical_block
)
8444 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
8445 child
= sibling_die (child
);
8449 /* Get the low and high pc's represented by the scope DIE, and store
8450 them in *LOWPC and *HIGHPC. If the correct values can't be
8451 determined, set *LOWPC to -1 and *HIGHPC to 0. */
8454 get_scope_pc_bounds (struct die_info
*die
,
8455 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8456 struct dwarf2_cu
*cu
)
8458 CORE_ADDR best_low
= (CORE_ADDR
) -1;
8459 CORE_ADDR best_high
= (CORE_ADDR
) 0;
8460 CORE_ADDR current_low
, current_high
;
8462 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
8464 best_low
= current_low
;
8465 best_high
= current_high
;
8469 struct die_info
*child
= die
->child
;
8471 while (child
&& child
->tag
)
8473 switch (child
->tag
) {
8474 case DW_TAG_subprogram
:
8475 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
8477 case DW_TAG_namespace
:
8479 /* FIXME: carlton/2004-01-16: Should we do this for
8480 DW_TAG_class_type/DW_TAG_structure_type, too? I think
8481 that current GCC's always emit the DIEs corresponding
8482 to definitions of methods of classes as children of a
8483 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
8484 the DIEs giving the declarations, which could be
8485 anywhere). But I don't see any reason why the
8486 standards says that they have to be there. */
8487 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
8489 if (current_low
!= ((CORE_ADDR
) -1))
8491 best_low
= min (best_low
, current_low
);
8492 best_high
= max (best_high
, current_high
);
8500 child
= sibling_die (child
);
8505 *highpc
= best_high
;
8508 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
8512 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
8513 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
8515 struct objfile
*objfile
= cu
->objfile
;
8516 struct attribute
*attr
;
8517 struct attribute
*attr_high
;
8519 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
8522 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8525 CORE_ADDR low
= DW_ADDR (attr
);
8527 if (attr_high
->form
== DW_FORM_addr
8528 || attr_high
->form
== DW_FORM_GNU_addr_index
)
8529 high
= DW_ADDR (attr_high
);
8531 high
= low
+ DW_UNSND (attr_high
);
8533 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
8537 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
8540 bfd
*obfd
= objfile
->obfd
;
8542 /* The value of the DW_AT_ranges attribute is the offset of the
8543 address range list in the .debug_ranges section. */
8544 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
8545 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
8547 /* For some target architectures, but not others, the
8548 read_address function sign-extends the addresses it returns.
8549 To recognize base address selection entries, we need a
8551 unsigned int addr_size
= cu
->header
.addr_size
;
8552 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
8554 /* The base address, to which the next pair is relative. Note
8555 that this 'base' is a DWARF concept: most entries in a range
8556 list are relative, to reduce the number of relocs against the
8557 debugging information. This is separate from this function's
8558 'baseaddr' argument, which GDB uses to relocate debugging
8559 information from a shared library based on the address at
8560 which the library was loaded. */
8561 CORE_ADDR base
= cu
->base_address
;
8562 int base_known
= cu
->base_known
;
8564 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
8565 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
8567 complaint (&symfile_complaints
,
8568 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
8575 unsigned int bytes_read
;
8576 CORE_ADDR start
, end
;
8578 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8579 buffer
+= bytes_read
;
8580 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
8581 buffer
+= bytes_read
;
8583 /* Did we find the end of the range list? */
8584 if (start
== 0 && end
== 0)
8587 /* Did we find a base address selection entry? */
8588 else if ((start
& base_select_mask
) == base_select_mask
)
8594 /* We found an ordinary address range. */
8599 complaint (&symfile_complaints
,
8600 _("Invalid .debug_ranges data "
8601 "(no base address)"));
8607 /* Inverted range entries are invalid. */
8608 complaint (&symfile_complaints
,
8609 _("Invalid .debug_ranges data "
8610 "(inverted range)"));
8614 /* Empty range entries have no effect. */
8618 record_block_range (block
,
8619 baseaddr
+ base
+ start
,
8620 baseaddr
+ base
+ end
- 1);
8626 /* Check whether the producer field indicates either of GCC < 4.6, or the
8627 Intel C/C++ compiler, and cache the result in CU. */
8630 check_producer (struct dwarf2_cu
*cu
)
8633 int major
, minor
, release
;
8635 if (cu
->producer
== NULL
)
8637 /* For unknown compilers expect their behavior is DWARF version
8640 GCC started to support .debug_types sections by -gdwarf-4 since
8641 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
8642 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
8643 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
8644 interpreted incorrectly by GDB now - GCC PR debug/48229. */
8646 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
8648 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
8650 cs
= &cu
->producer
[strlen ("GNU ")];
8651 while (*cs
&& !isdigit (*cs
))
8653 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
8655 /* Not recognized as GCC. */
8658 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
8660 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
8661 cu
->producer_is_icc
= 1;
8664 /* For other non-GCC compilers, expect their behavior is DWARF version
8668 cu
->checked_producer
= 1;
8671 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
8672 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
8673 during 4.6.0 experimental. */
8676 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
8678 if (!cu
->checked_producer
)
8679 check_producer (cu
);
8681 return cu
->producer_is_gxx_lt_4_6
;
8684 /* Return the default accessibility type if it is not overriden by
8685 DW_AT_accessibility. */
8687 static enum dwarf_access_attribute
8688 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
8690 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
8692 /* The default DWARF 2 accessibility for members is public, the default
8693 accessibility for inheritance is private. */
8695 if (die
->tag
!= DW_TAG_inheritance
)
8696 return DW_ACCESS_public
;
8698 return DW_ACCESS_private
;
8702 /* DWARF 3+ defines the default accessibility a different way. The same
8703 rules apply now for DW_TAG_inheritance as for the members and it only
8704 depends on the container kind. */
8706 if (die
->parent
->tag
== DW_TAG_class_type
)
8707 return DW_ACCESS_private
;
8709 return DW_ACCESS_public
;
8713 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
8714 offset. If the attribute was not found return 0, otherwise return
8715 1. If it was found but could not properly be handled, set *OFFSET
8719 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
8722 struct attribute
*attr
;
8724 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
8729 /* Note that we do not check for a section offset first here.
8730 This is because DW_AT_data_member_location is new in DWARF 4,
8731 so if we see it, we can assume that a constant form is really
8732 a constant and not a section offset. */
8733 if (attr_form_is_constant (attr
))
8734 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
8735 else if (attr_form_is_section_offset (attr
))
8736 dwarf2_complex_location_expr_complaint ();
8737 else if (attr_form_is_block (attr
))
8738 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
8740 dwarf2_complex_location_expr_complaint ();
8748 /* Add an aggregate field to the field list. */
8751 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
8752 struct dwarf2_cu
*cu
)
8754 struct objfile
*objfile
= cu
->objfile
;
8755 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8756 struct nextfield
*new_field
;
8757 struct attribute
*attr
;
8759 char *fieldname
= "";
8761 /* Allocate a new field list entry and link it in. */
8762 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
8763 make_cleanup (xfree
, new_field
);
8764 memset (new_field
, 0, sizeof (struct nextfield
));
8766 if (die
->tag
== DW_TAG_inheritance
)
8768 new_field
->next
= fip
->baseclasses
;
8769 fip
->baseclasses
= new_field
;
8773 new_field
->next
= fip
->fields
;
8774 fip
->fields
= new_field
;
8778 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
8780 new_field
->accessibility
= DW_UNSND (attr
);
8782 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
8783 if (new_field
->accessibility
!= DW_ACCESS_public
)
8784 fip
->non_public_fields
= 1;
8786 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
8788 new_field
->virtuality
= DW_UNSND (attr
);
8790 new_field
->virtuality
= DW_VIRTUALITY_none
;
8792 fp
= &new_field
->field
;
8794 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
8798 /* Data member other than a C++ static data member. */
8800 /* Get type of field. */
8801 fp
->type
= die_type (die
, cu
);
8803 SET_FIELD_BITPOS (*fp
, 0);
8805 /* Get bit size of field (zero if none). */
8806 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
8809 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
8813 FIELD_BITSIZE (*fp
) = 0;
8816 /* Get bit offset of field. */
8817 if (handle_data_member_location (die
, cu
, &offset
))
8818 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8819 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
8822 if (gdbarch_bits_big_endian (gdbarch
))
8824 /* For big endian bits, the DW_AT_bit_offset gives the
8825 additional bit offset from the MSB of the containing
8826 anonymous object to the MSB of the field. We don't
8827 have to do anything special since we don't need to
8828 know the size of the anonymous object. */
8829 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
8833 /* For little endian bits, compute the bit offset to the
8834 MSB of the anonymous object, subtract off the number of
8835 bits from the MSB of the field to the MSB of the
8836 object, and then subtract off the number of bits of
8837 the field itself. The result is the bit offset of
8838 the LSB of the field. */
8840 int bit_offset
= DW_UNSND (attr
);
8842 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8845 /* The size of the anonymous object containing
8846 the bit field is explicit, so use the
8847 indicated size (in bytes). */
8848 anonymous_size
= DW_UNSND (attr
);
8852 /* The size of the anonymous object containing
8853 the bit field must be inferred from the type
8854 attribute of the data member containing the
8856 anonymous_size
= TYPE_LENGTH (fp
->type
);
8858 SET_FIELD_BITPOS (*fp
,
8860 + anonymous_size
* bits_per_byte
8861 - bit_offset
- FIELD_BITSIZE (*fp
)));
8865 /* Get name of field. */
8866 fieldname
= dwarf2_name (die
, cu
);
8867 if (fieldname
== NULL
)
8870 /* The name is already allocated along with this objfile, so we don't
8871 need to duplicate it for the type. */
8872 fp
->name
= fieldname
;
8874 /* Change accessibility for artificial fields (e.g. virtual table
8875 pointer or virtual base class pointer) to private. */
8876 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
8878 FIELD_ARTIFICIAL (*fp
) = 1;
8879 new_field
->accessibility
= DW_ACCESS_private
;
8880 fip
->non_public_fields
= 1;
8883 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
8885 /* C++ static member. */
8887 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
8888 is a declaration, but all versions of G++ as of this writing
8889 (so through at least 3.2.1) incorrectly generate
8890 DW_TAG_variable tags. */
8892 const char *physname
;
8894 /* Get name of field. */
8895 fieldname
= dwarf2_name (die
, cu
);
8896 if (fieldname
== NULL
)
8899 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8901 /* Only create a symbol if this is an external value.
8902 new_symbol checks this and puts the value in the global symbol
8903 table, which we want. If it is not external, new_symbol
8904 will try to put the value in cu->list_in_scope which is wrong. */
8905 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
8907 /* A static const member, not much different than an enum as far as
8908 we're concerned, except that we can support more types. */
8909 new_symbol (die
, NULL
, cu
);
8912 /* Get physical name. */
8913 physname
= dwarf2_physname (fieldname
, die
, cu
);
8915 /* The name is already allocated along with this objfile, so we don't
8916 need to duplicate it for the type. */
8917 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
8918 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8919 FIELD_NAME (*fp
) = fieldname
;
8921 else if (die
->tag
== DW_TAG_inheritance
)
8925 /* C++ base class field. */
8926 if (handle_data_member_location (die
, cu
, &offset
))
8927 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
8928 FIELD_BITSIZE (*fp
) = 0;
8929 FIELD_TYPE (*fp
) = die_type (die
, cu
);
8930 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
8931 fip
->nbaseclasses
++;
8935 /* Add a typedef defined in the scope of the FIP's class. */
8938 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
8939 struct dwarf2_cu
*cu
)
8941 struct objfile
*objfile
= cu
->objfile
;
8942 struct typedef_field_list
*new_field
;
8943 struct attribute
*attr
;
8944 struct typedef_field
*fp
;
8945 char *fieldname
= "";
8947 /* Allocate a new field list entry and link it in. */
8948 new_field
= xzalloc (sizeof (*new_field
));
8949 make_cleanup (xfree
, new_field
);
8951 gdb_assert (die
->tag
== DW_TAG_typedef
);
8953 fp
= &new_field
->field
;
8955 /* Get name of field. */
8956 fp
->name
= dwarf2_name (die
, cu
);
8957 if (fp
->name
== NULL
)
8960 fp
->type
= read_type_die (die
, cu
);
8962 new_field
->next
= fip
->typedef_field_list
;
8963 fip
->typedef_field_list
= new_field
;
8964 fip
->typedef_field_list_count
++;
8967 /* Create the vector of fields, and attach it to the type. */
8970 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
8971 struct dwarf2_cu
*cu
)
8973 int nfields
= fip
->nfields
;
8975 /* Record the field count, allocate space for the array of fields,
8976 and create blank accessibility bitfields if necessary. */
8977 TYPE_NFIELDS (type
) = nfields
;
8978 TYPE_FIELDS (type
) = (struct field
*)
8979 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
8980 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
8982 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
8984 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
8986 TYPE_FIELD_PRIVATE_BITS (type
) =
8987 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8988 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
8990 TYPE_FIELD_PROTECTED_BITS (type
) =
8991 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8992 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
8994 TYPE_FIELD_IGNORE_BITS (type
) =
8995 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
8996 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
8999 /* If the type has baseclasses, allocate and clear a bit vector for
9000 TYPE_FIELD_VIRTUAL_BITS. */
9001 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9003 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9004 unsigned char *pointer
;
9006 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9007 pointer
= TYPE_ALLOC (type
, num_bytes
);
9008 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9009 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9010 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9013 /* Copy the saved-up fields into the field vector. Start from the head of
9014 the list, adding to the tail of the field array, so that they end up in
9015 the same order in the array in which they were added to the list. */
9016 while (nfields
-- > 0)
9018 struct nextfield
*fieldp
;
9022 fieldp
= fip
->fields
;
9023 fip
->fields
= fieldp
->next
;
9027 fieldp
= fip
->baseclasses
;
9028 fip
->baseclasses
= fieldp
->next
;
9031 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
9032 switch (fieldp
->accessibility
)
9034 case DW_ACCESS_private
:
9035 if (cu
->language
!= language_ada
)
9036 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
9039 case DW_ACCESS_protected
:
9040 if (cu
->language
!= language_ada
)
9041 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
9044 case DW_ACCESS_public
:
9048 /* Unknown accessibility. Complain and treat it as public. */
9050 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
9051 fieldp
->accessibility
);
9055 if (nfields
< fip
->nbaseclasses
)
9057 switch (fieldp
->virtuality
)
9059 case DW_VIRTUALITY_virtual
:
9060 case DW_VIRTUALITY_pure_virtual
:
9061 if (cu
->language
== language_ada
)
9062 error (_("unexpected virtuality in component of Ada type"));
9063 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
9070 /* Add a member function to the proper fieldlist. */
9073 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
9074 struct type
*type
, struct dwarf2_cu
*cu
)
9076 struct objfile
*objfile
= cu
->objfile
;
9077 struct attribute
*attr
;
9078 struct fnfieldlist
*flp
;
9080 struct fn_field
*fnp
;
9082 struct nextfnfield
*new_fnfield
;
9083 struct type
*this_type
;
9084 enum dwarf_access_attribute accessibility
;
9086 if (cu
->language
== language_ada
)
9087 error (_("unexpected member function in Ada type"));
9089 /* Get name of member function. */
9090 fieldname
= dwarf2_name (die
, cu
);
9091 if (fieldname
== NULL
)
9094 /* Look up member function name in fieldlist. */
9095 for (i
= 0; i
< fip
->nfnfields
; i
++)
9097 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
9101 /* Create new list element if necessary. */
9102 if (i
< fip
->nfnfields
)
9103 flp
= &fip
->fnfieldlists
[i
];
9106 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9108 fip
->fnfieldlists
= (struct fnfieldlist
*)
9109 xrealloc (fip
->fnfieldlists
,
9110 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9111 * sizeof (struct fnfieldlist
));
9112 if (fip
->nfnfields
== 0)
9113 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9115 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9116 flp
->name
= fieldname
;
9119 i
= fip
->nfnfields
++;
9122 /* Create a new member function field and chain it to the field list
9124 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9125 make_cleanup (xfree
, new_fnfield
);
9126 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9127 new_fnfield
->next
= flp
->head
;
9128 flp
->head
= new_fnfield
;
9131 /* Fill in the member function field info. */
9132 fnp
= &new_fnfield
->fnfield
;
9134 /* Delay processing of the physname until later. */
9135 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9137 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9142 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9143 fnp
->physname
= physname
? physname
: "";
9146 fnp
->type
= alloc_type (objfile
);
9147 this_type
= read_type_die (die
, cu
);
9148 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9150 int nparams
= TYPE_NFIELDS (this_type
);
9152 /* TYPE is the domain of this method, and THIS_TYPE is the type
9153 of the method itself (TYPE_CODE_METHOD). */
9154 smash_to_method_type (fnp
->type
, type
,
9155 TYPE_TARGET_TYPE (this_type
),
9156 TYPE_FIELDS (this_type
),
9157 TYPE_NFIELDS (this_type
),
9158 TYPE_VARARGS (this_type
));
9160 /* Handle static member functions.
9161 Dwarf2 has no clean way to discern C++ static and non-static
9162 member functions. G++ helps GDB by marking the first
9163 parameter for non-static member functions (which is the this
9164 pointer) as artificial. We obtain this information from
9165 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
9166 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
9167 fnp
->voffset
= VOFFSET_STATIC
;
9170 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
9171 dwarf2_full_name (fieldname
, die
, cu
));
9173 /* Get fcontext from DW_AT_containing_type if present. */
9174 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9175 fnp
->fcontext
= die_containing_type (die
, cu
);
9177 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
9178 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
9180 /* Get accessibility. */
9181 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9183 accessibility
= DW_UNSND (attr
);
9185 accessibility
= dwarf2_default_access_attribute (die
, cu
);
9186 switch (accessibility
)
9188 case DW_ACCESS_private
:
9189 fnp
->is_private
= 1;
9191 case DW_ACCESS_protected
:
9192 fnp
->is_protected
= 1;
9196 /* Check for artificial methods. */
9197 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
9198 if (attr
&& DW_UNSND (attr
) != 0)
9199 fnp
->is_artificial
= 1;
9201 /* Get index in virtual function table if it is a virtual member
9202 function. For older versions of GCC, this is an offset in the
9203 appropriate virtual table, as specified by DW_AT_containing_type.
9204 For everyone else, it is an expression to be evaluated relative
9205 to the object address. */
9207 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
9210 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
9212 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
9214 /* Old-style GCC. */
9215 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
9217 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9218 || (DW_BLOCK (attr
)->size
> 1
9219 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
9220 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
9222 struct dwarf_block blk
;
9225 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
9227 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
9228 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
9229 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9230 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
9231 dwarf2_complex_location_expr_complaint ();
9233 fnp
->voffset
/= cu
->header
.addr_size
;
9237 dwarf2_complex_location_expr_complaint ();
9240 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
9242 else if (attr_form_is_section_offset (attr
))
9244 dwarf2_complex_location_expr_complaint ();
9248 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
9254 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9255 if (attr
&& DW_UNSND (attr
))
9257 /* GCC does this, as of 2008-08-25; PR debug/37237. */
9258 complaint (&symfile_complaints
,
9259 _("Member function \"%s\" (offset %d) is virtual "
9260 "but the vtable offset is not specified"),
9261 fieldname
, die
->offset
.sect_off
);
9262 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9263 TYPE_CPLUS_DYNAMIC (type
) = 1;
9268 /* Create the vector of member function fields, and attach it to the type. */
9271 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
9272 struct dwarf2_cu
*cu
)
9274 struct fnfieldlist
*flp
;
9277 if (cu
->language
== language_ada
)
9278 error (_("unexpected member functions in Ada type"));
9280 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9281 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
9282 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
9284 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
9286 struct nextfnfield
*nfp
= flp
->head
;
9287 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
9290 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
9291 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
9292 fn_flp
->fn_fields
= (struct fn_field
*)
9293 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
9294 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
9295 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
9298 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
9301 /* Returns non-zero if NAME is the name of a vtable member in CU's
9302 language, zero otherwise. */
9304 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
9306 static const char vptr
[] = "_vptr";
9307 static const char vtable
[] = "vtable";
9309 /* Look for the C++ and Java forms of the vtable. */
9310 if ((cu
->language
== language_java
9311 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
9312 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
9313 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
9319 /* GCC outputs unnamed structures that are really pointers to member
9320 functions, with the ABI-specified layout. If TYPE describes
9321 such a structure, smash it into a member function type.
9323 GCC shouldn't do this; it should just output pointer to member DIEs.
9324 This is GCC PR debug/28767. */
9327 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
9329 struct type
*pfn_type
, *domain_type
, *new_type
;
9331 /* Check for a structure with no name and two children. */
9332 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
9335 /* Check for __pfn and __delta members. */
9336 if (TYPE_FIELD_NAME (type
, 0) == NULL
9337 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
9338 || TYPE_FIELD_NAME (type
, 1) == NULL
9339 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
9342 /* Find the type of the method. */
9343 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
9344 if (pfn_type
== NULL
9345 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
9346 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
9349 /* Look for the "this" argument. */
9350 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
9351 if (TYPE_NFIELDS (pfn_type
) == 0
9352 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
9353 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
9356 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
9357 new_type
= alloc_type (objfile
);
9358 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
9359 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
9360 TYPE_VARARGS (pfn_type
));
9361 smash_to_methodptr_type (type
, new_type
);
9364 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
9368 producer_is_icc (struct dwarf2_cu
*cu
)
9370 if (!cu
->checked_producer
)
9371 check_producer (cu
);
9373 return cu
->producer_is_icc
;
9376 /* Called when we find the DIE that starts a structure or union scope
9377 (definition) to create a type for the structure or union. Fill in
9378 the type's name and general properties; the members will not be
9379 processed until process_structure_type.
9381 NOTE: we need to call these functions regardless of whether or not the
9382 DIE has a DW_AT_name attribute, since it might be an anonymous
9383 structure or union. This gets the type entered into our set of
9386 However, if the structure is incomplete (an opaque struct/union)
9387 then suppress creating a symbol table entry for it since gdb only
9388 wants to find the one with the complete definition. Note that if
9389 it is complete, we just call new_symbol, which does it's own
9390 checking about whether the struct/union is anonymous or not (and
9391 suppresses creating a symbol table entry itself). */
9393 static struct type
*
9394 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9396 struct objfile
*objfile
= cu
->objfile
;
9398 struct attribute
*attr
;
9401 /* If the definition of this type lives in .debug_types, read that type.
9402 Don't follow DW_AT_specification though, that will take us back up
9403 the chain and we want to go down. */
9404 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9407 struct dwarf2_cu
*type_cu
= cu
;
9408 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9410 /* We could just recurse on read_structure_type, but we need to call
9411 get_die_type to ensure only one type for this DIE is created.
9412 This is important, for example, because for c++ classes we need
9413 TYPE_NAME set which is only done by new_symbol. Blech. */
9414 type
= read_type_die (type_die
, type_cu
);
9416 /* TYPE_CU may not be the same as CU.
9417 Ensure TYPE is recorded in CU's type_hash table. */
9418 return set_die_type (die
, type
, cu
);
9421 type
= alloc_type (objfile
);
9422 INIT_CPLUS_SPECIFIC (type
);
9424 name
= dwarf2_name (die
, cu
);
9427 if (cu
->language
== language_cplus
9428 || cu
->language
== language_java
)
9430 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
9432 /* dwarf2_full_name might have already finished building the DIE's
9433 type. If so, there is no need to continue. */
9434 if (get_die_type (die
, cu
) != NULL
)
9435 return get_die_type (die
, cu
);
9437 TYPE_TAG_NAME (type
) = full_name
;
9438 if (die
->tag
== DW_TAG_structure_type
9439 || die
->tag
== DW_TAG_class_type
)
9440 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9444 /* The name is already allocated along with this objfile, so
9445 we don't need to duplicate it for the type. */
9446 TYPE_TAG_NAME (type
) = (char *) name
;
9447 if (die
->tag
== DW_TAG_class_type
)
9448 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
9452 if (die
->tag
== DW_TAG_structure_type
)
9454 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9456 else if (die
->tag
== DW_TAG_union_type
)
9458 TYPE_CODE (type
) = TYPE_CODE_UNION
;
9462 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
9465 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
9466 TYPE_DECLARED_CLASS (type
) = 1;
9468 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9471 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9475 TYPE_LENGTH (type
) = 0;
9478 if (producer_is_icc (cu
))
9480 /* ICC does not output the required DW_AT_declaration
9481 on incomplete types, but gives them a size of zero. */
9484 TYPE_STUB_SUPPORTED (type
) = 1;
9486 if (die_is_declaration (die
, cu
))
9487 TYPE_STUB (type
) = 1;
9488 else if (attr
== NULL
&& die
->child
== NULL
9489 && producer_is_realview (cu
->producer
))
9490 /* RealView does not output the required DW_AT_declaration
9491 on incomplete types. */
9492 TYPE_STUB (type
) = 1;
9494 /* We need to add the type field to the die immediately so we don't
9495 infinitely recurse when dealing with pointers to the structure
9496 type within the structure itself. */
9497 set_die_type (die
, type
, cu
);
9499 /* set_die_type should be already done. */
9500 set_descriptive_type (type
, die
, cu
);
9505 /* Finish creating a structure or union type, including filling in
9506 its members and creating a symbol for it. */
9509 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9511 struct objfile
*objfile
= cu
->objfile
;
9512 struct die_info
*child_die
= die
->child
;
9515 type
= get_die_type (die
, cu
);
9517 type
= read_structure_type (die
, cu
);
9519 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
9521 struct field_info fi
;
9522 struct die_info
*child_die
;
9523 VEC (symbolp
) *template_args
= NULL
;
9524 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
9526 memset (&fi
, 0, sizeof (struct field_info
));
9528 child_die
= die
->child
;
9530 while (child_die
&& child_die
->tag
)
9532 if (child_die
->tag
== DW_TAG_member
9533 || child_die
->tag
== DW_TAG_variable
)
9535 /* NOTE: carlton/2002-11-05: A C++ static data member
9536 should be a DW_TAG_member that is a declaration, but
9537 all versions of G++ as of this writing (so through at
9538 least 3.2.1) incorrectly generate DW_TAG_variable
9539 tags for them instead. */
9540 dwarf2_add_field (&fi
, child_die
, cu
);
9542 else if (child_die
->tag
== DW_TAG_subprogram
)
9544 /* C++ member function. */
9545 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
9547 else if (child_die
->tag
== DW_TAG_inheritance
)
9549 /* C++ base class field. */
9550 dwarf2_add_field (&fi
, child_die
, cu
);
9552 else if (child_die
->tag
== DW_TAG_typedef
)
9553 dwarf2_add_typedef (&fi
, child_die
, cu
);
9554 else if (child_die
->tag
== DW_TAG_template_type_param
9555 || child_die
->tag
== DW_TAG_template_value_param
)
9557 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9560 VEC_safe_push (symbolp
, template_args
, arg
);
9563 child_die
= sibling_die (child_die
);
9566 /* Attach template arguments to type. */
9567 if (! VEC_empty (symbolp
, template_args
))
9569 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9570 TYPE_N_TEMPLATE_ARGUMENTS (type
)
9571 = VEC_length (symbolp
, template_args
);
9572 TYPE_TEMPLATE_ARGUMENTS (type
)
9573 = obstack_alloc (&objfile
->objfile_obstack
,
9574 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9575 * sizeof (struct symbol
*)));
9576 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
9577 VEC_address (symbolp
, template_args
),
9578 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
9579 * sizeof (struct symbol
*)));
9580 VEC_free (symbolp
, template_args
);
9583 /* Attach fields and member functions to the type. */
9585 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
9588 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
9590 /* Get the type which refers to the base class (possibly this
9591 class itself) which contains the vtable pointer for the current
9592 class from the DW_AT_containing_type attribute. This use of
9593 DW_AT_containing_type is a GNU extension. */
9595 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
9597 struct type
*t
= die_containing_type (die
, cu
);
9599 TYPE_VPTR_BASETYPE (type
) = t
;
9604 /* Our own class provides vtbl ptr. */
9605 for (i
= TYPE_NFIELDS (t
) - 1;
9606 i
>= TYPE_N_BASECLASSES (t
);
9609 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
9611 if (is_vtable_name (fieldname
, cu
))
9613 TYPE_VPTR_FIELDNO (type
) = i
;
9618 /* Complain if virtual function table field not found. */
9619 if (i
< TYPE_N_BASECLASSES (t
))
9620 complaint (&symfile_complaints
,
9621 _("virtual function table pointer "
9622 "not found when defining class '%s'"),
9623 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
9628 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
9631 else if (cu
->producer
9632 && strncmp (cu
->producer
,
9633 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
9635 /* The IBM XLC compiler does not provide direct indication
9636 of the containing type, but the vtable pointer is
9637 always named __vfp. */
9641 for (i
= TYPE_NFIELDS (type
) - 1;
9642 i
>= TYPE_N_BASECLASSES (type
);
9645 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
9647 TYPE_VPTR_FIELDNO (type
) = i
;
9648 TYPE_VPTR_BASETYPE (type
) = type
;
9655 /* Copy fi.typedef_field_list linked list elements content into the
9656 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
9657 if (fi
.typedef_field_list
)
9659 int i
= fi
.typedef_field_list_count
;
9661 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9662 TYPE_TYPEDEF_FIELD_ARRAY (type
)
9663 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
9664 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
9666 /* Reverse the list order to keep the debug info elements order. */
9669 struct typedef_field
*dest
, *src
;
9671 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
9672 src
= &fi
.typedef_field_list
->field
;
9673 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
9678 do_cleanups (back_to
);
9680 if (HAVE_CPLUS_STRUCT (type
))
9681 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
9684 quirk_gcc_member_function_pointer (type
, objfile
);
9686 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
9687 snapshots) has been known to create a die giving a declaration
9688 for a class that has, as a child, a die giving a definition for a
9689 nested class. So we have to process our children even if the
9690 current die is a declaration. Normally, of course, a declaration
9691 won't have any children at all. */
9693 while (child_die
!= NULL
&& child_die
->tag
)
9695 if (child_die
->tag
== DW_TAG_member
9696 || child_die
->tag
== DW_TAG_variable
9697 || child_die
->tag
== DW_TAG_inheritance
9698 || child_die
->tag
== DW_TAG_template_value_param
9699 || child_die
->tag
== DW_TAG_template_type_param
)
9704 process_die (child_die
, cu
);
9706 child_die
= sibling_die (child_die
);
9709 /* Do not consider external references. According to the DWARF standard,
9710 these DIEs are identified by the fact that they have no byte_size
9711 attribute, and a declaration attribute. */
9712 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
9713 || !die_is_declaration (die
, cu
))
9714 new_symbol (die
, type
, cu
);
9717 /* Given a DW_AT_enumeration_type die, set its type. We do not
9718 complete the type's fields yet, or create any symbols. */
9720 static struct type
*
9721 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9723 struct objfile
*objfile
= cu
->objfile
;
9725 struct attribute
*attr
;
9728 /* If the definition of this type lives in .debug_types, read that type.
9729 Don't follow DW_AT_specification though, that will take us back up
9730 the chain and we want to go down. */
9731 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
9734 struct dwarf2_cu
*type_cu
= cu
;
9735 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
9737 type
= read_type_die (type_die
, type_cu
);
9739 /* TYPE_CU may not be the same as CU.
9740 Ensure TYPE is recorded in CU's type_hash table. */
9741 return set_die_type (die
, type
, cu
);
9744 type
= alloc_type (objfile
);
9746 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
9747 name
= dwarf2_full_name (NULL
, die
, cu
);
9749 TYPE_TAG_NAME (type
) = (char *) name
;
9751 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9754 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9758 TYPE_LENGTH (type
) = 0;
9761 /* The enumeration DIE can be incomplete. In Ada, any type can be
9762 declared as private in the package spec, and then defined only
9763 inside the package body. Such types are known as Taft Amendment
9764 Types. When another package uses such a type, an incomplete DIE
9765 may be generated by the compiler. */
9766 if (die_is_declaration (die
, cu
))
9767 TYPE_STUB (type
) = 1;
9769 return set_die_type (die
, type
, cu
);
9772 /* Given a pointer to a die which begins an enumeration, process all
9773 the dies that define the members of the enumeration, and create the
9774 symbol for the enumeration type.
9776 NOTE: We reverse the order of the element list. */
9779 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9781 struct type
*this_type
;
9783 this_type
= get_die_type (die
, cu
);
9784 if (this_type
== NULL
)
9785 this_type
= read_enumeration_type (die
, cu
);
9787 if (die
->child
!= NULL
)
9789 struct die_info
*child_die
;
9791 struct field
*fields
= NULL
;
9793 int unsigned_enum
= 1;
9798 child_die
= die
->child
;
9799 while (child_die
&& child_die
->tag
)
9801 if (child_die
->tag
!= DW_TAG_enumerator
)
9803 process_die (child_die
, cu
);
9807 name
= dwarf2_name (child_die
, cu
);
9810 sym
= new_symbol (child_die
, this_type
, cu
);
9811 if (SYMBOL_VALUE (sym
) < 0)
9816 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
9819 mask
|= SYMBOL_VALUE (sym
);
9821 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9823 fields
= (struct field
*)
9825 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
9826 * sizeof (struct field
));
9829 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
9830 FIELD_TYPE (fields
[num_fields
]) = NULL
;
9831 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
9832 FIELD_BITSIZE (fields
[num_fields
]) = 0;
9838 child_die
= sibling_die (child_die
);
9843 TYPE_NFIELDS (this_type
) = num_fields
;
9844 TYPE_FIELDS (this_type
) = (struct field
*)
9845 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
9846 memcpy (TYPE_FIELDS (this_type
), fields
,
9847 sizeof (struct field
) * num_fields
);
9851 TYPE_UNSIGNED (this_type
) = 1;
9853 TYPE_FLAG_ENUM (this_type
) = 1;
9856 /* If we are reading an enum from a .debug_types unit, and the enum
9857 is a declaration, and the enum is not the signatured type in the
9858 unit, then we do not want to add a symbol for it. Adding a
9859 symbol would in some cases obscure the true definition of the
9860 enum, giving users an incomplete type when the definition is
9861 actually available. Note that we do not want to do this for all
9862 enums which are just declarations, because C++0x allows forward
9863 enum declarations. */
9864 if (cu
->per_cu
->is_debug_types
9865 && die_is_declaration (die
, cu
))
9867 struct signatured_type
*sig_type
;
9870 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
9871 cu
->per_cu
->info_or_types_section
,
9872 cu
->per_cu
->offset
);
9873 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
9874 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
9878 new_symbol (die
, this_type
, cu
);
9881 /* Extract all information from a DW_TAG_array_type DIE and put it in
9882 the DIE's type field. For now, this only handles one dimensional
9885 static struct type
*
9886 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9888 struct objfile
*objfile
= cu
->objfile
;
9889 struct die_info
*child_die
;
9891 struct type
*element_type
, *range_type
, *index_type
;
9892 struct type
**range_types
= NULL
;
9893 struct attribute
*attr
;
9895 struct cleanup
*back_to
;
9898 element_type
= die_type (die
, cu
);
9900 /* The die_type call above may have already set the type for this DIE. */
9901 type
= get_die_type (die
, cu
);
9905 /* Irix 6.2 native cc creates array types without children for
9906 arrays with unspecified length. */
9907 if (die
->child
== NULL
)
9909 index_type
= objfile_type (objfile
)->builtin_int
;
9910 range_type
= create_range_type (NULL
, index_type
, 0, -1);
9911 type
= create_array_type (NULL
, element_type
, range_type
);
9912 return set_die_type (die
, type
, cu
);
9915 back_to
= make_cleanup (null_cleanup
, NULL
);
9916 child_die
= die
->child
;
9917 while (child_die
&& child_die
->tag
)
9919 if (child_die
->tag
== DW_TAG_subrange_type
)
9921 struct type
*child_type
= read_type_die (child_die
, cu
);
9923 if (child_type
!= NULL
)
9925 /* The range type was succesfully read. Save it for the
9926 array type creation. */
9927 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
9929 range_types
= (struct type
**)
9930 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
9931 * sizeof (struct type
*));
9933 make_cleanup (free_current_contents
, &range_types
);
9935 range_types
[ndim
++] = child_type
;
9938 child_die
= sibling_die (child_die
);
9941 /* Dwarf2 dimensions are output from left to right, create the
9942 necessary array types in backwards order. */
9944 type
= element_type
;
9946 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
9951 type
= create_array_type (NULL
, type
, range_types
[i
++]);
9956 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
9959 /* Understand Dwarf2 support for vector types (like they occur on
9960 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
9961 array type. This is not part of the Dwarf2/3 standard yet, but a
9962 custom vendor extension. The main difference between a regular
9963 array and the vector variant is that vectors are passed by value
9965 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
9967 make_vector_type (type
);
9969 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
9970 implementation may choose to implement triple vectors using this
9972 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9975 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
9976 TYPE_LENGTH (type
) = DW_UNSND (attr
);
9978 complaint (&symfile_complaints
,
9979 _("DW_AT_byte_size for array type smaller "
9980 "than the total size of elements"));
9983 name
= dwarf2_name (die
, cu
);
9985 TYPE_NAME (type
) = name
;
9987 /* Install the type in the die. */
9988 set_die_type (die
, type
, cu
);
9990 /* set_die_type should be already done. */
9991 set_descriptive_type (type
, die
, cu
);
9993 do_cleanups (back_to
);
9998 static enum dwarf_array_dim_ordering
9999 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10001 struct attribute
*attr
;
10003 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10005 if (attr
) return DW_SND (attr
);
10007 /* GNU F77 is a special case, as at 08/2004 array type info is the
10008 opposite order to the dwarf2 specification, but data is still
10009 laid out as per normal fortran.
10011 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10012 version checking. */
10014 if (cu
->language
== language_fortran
10015 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
10017 return DW_ORD_row_major
;
10020 switch (cu
->language_defn
->la_array_ordering
)
10022 case array_column_major
:
10023 return DW_ORD_col_major
;
10024 case array_row_major
:
10026 return DW_ORD_row_major
;
10030 /* Extract all information from a DW_TAG_set_type DIE and put it in
10031 the DIE's type field. */
10033 static struct type
*
10034 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10036 struct type
*domain_type
, *set_type
;
10037 struct attribute
*attr
;
10039 domain_type
= die_type (die
, cu
);
10041 /* The die_type call above may have already set the type for this DIE. */
10042 set_type
= get_die_type (die
, cu
);
10046 set_type
= create_set_type (NULL
, domain_type
);
10048 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10050 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
10052 return set_die_type (die
, set_type
, cu
);
10055 /* First cut: install each common block member as a global variable. */
10058 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
10060 struct die_info
*child_die
;
10061 struct attribute
*attr
;
10062 struct symbol
*sym
;
10063 CORE_ADDR base
= (CORE_ADDR
) 0;
10065 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10068 /* Support the .debug_loc offsets. */
10069 if (attr_form_is_block (attr
))
10071 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
10073 else if (attr_form_is_section_offset (attr
))
10075 dwarf2_complex_location_expr_complaint ();
10079 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10080 "common block member");
10083 if (die
->child
!= NULL
)
10085 child_die
= die
->child
;
10086 while (child_die
&& child_die
->tag
)
10090 sym
= new_symbol (child_die
, NULL
, cu
);
10092 && handle_data_member_location (child_die
, cu
, &offset
))
10094 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
10095 add_symbol_to_list (sym
, &global_symbols
);
10097 child_die
= sibling_die (child_die
);
10102 /* Create a type for a C++ namespace. */
10104 static struct type
*
10105 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10107 struct objfile
*objfile
= cu
->objfile
;
10108 const char *previous_prefix
, *name
;
10112 /* For extensions, reuse the type of the original namespace. */
10113 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10115 struct die_info
*ext_die
;
10116 struct dwarf2_cu
*ext_cu
= cu
;
10118 ext_die
= dwarf2_extension (die
, &ext_cu
);
10119 type
= read_type_die (ext_die
, ext_cu
);
10121 /* EXT_CU may not be the same as CU.
10122 Ensure TYPE is recorded in CU's type_hash table. */
10123 return set_die_type (die
, type
, cu
);
10126 name
= namespace_name (die
, &is_anonymous
, cu
);
10128 /* Now build the name of the current namespace. */
10130 previous_prefix
= determine_prefix (die
, cu
);
10131 if (previous_prefix
[0] != '\0')
10132 name
= typename_concat (&objfile
->objfile_obstack
,
10133 previous_prefix
, name
, 0, cu
);
10135 /* Create the type. */
10136 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10138 TYPE_NAME (type
) = (char *) name
;
10139 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10141 return set_die_type (die
, type
, cu
);
10144 /* Read a C++ namespace. */
10147 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10149 struct objfile
*objfile
= cu
->objfile
;
10152 /* Add a symbol associated to this if we haven't seen the namespace
10153 before. Also, add a using directive if it's an anonymous
10156 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10160 type
= read_type_die (die
, cu
);
10161 new_symbol (die
, type
, cu
);
10163 namespace_name (die
, &is_anonymous
, cu
);
10166 const char *previous_prefix
= determine_prefix (die
, cu
);
10168 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
10169 NULL
, NULL
, &objfile
->objfile_obstack
);
10173 if (die
->child
!= NULL
)
10175 struct die_info
*child_die
= die
->child
;
10177 while (child_die
&& child_die
->tag
)
10179 process_die (child_die
, cu
);
10180 child_die
= sibling_die (child_die
);
10185 /* Read a Fortran module as type. This DIE can be only a declaration used for
10186 imported module. Still we need that type as local Fortran "use ... only"
10187 declaration imports depend on the created type in determine_prefix. */
10189 static struct type
*
10190 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10192 struct objfile
*objfile
= cu
->objfile
;
10196 module_name
= dwarf2_name (die
, cu
);
10198 complaint (&symfile_complaints
,
10199 _("DW_TAG_module has no name, offset 0x%x"),
10200 die
->offset
.sect_off
);
10201 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
10203 /* determine_prefix uses TYPE_TAG_NAME. */
10204 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10206 return set_die_type (die
, type
, cu
);
10209 /* Read a Fortran module. */
10212 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
10214 struct die_info
*child_die
= die
->child
;
10216 while (child_die
&& child_die
->tag
)
10218 process_die (child_die
, cu
);
10219 child_die
= sibling_die (child_die
);
10223 /* Return the name of the namespace represented by DIE. Set
10224 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
10227 static const char *
10228 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
10230 struct die_info
*current_die
;
10231 const char *name
= NULL
;
10233 /* Loop through the extensions until we find a name. */
10235 for (current_die
= die
;
10236 current_die
!= NULL
;
10237 current_die
= dwarf2_extension (die
, &cu
))
10239 name
= dwarf2_name (current_die
, cu
);
10244 /* Is it an anonymous namespace? */
10246 *is_anonymous
= (name
== NULL
);
10248 name
= CP_ANONYMOUS_NAMESPACE_STR
;
10253 /* Extract all information from a DW_TAG_pointer_type DIE and add to
10254 the user defined type vector. */
10256 static struct type
*
10257 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10259 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
10260 struct comp_unit_head
*cu_header
= &cu
->header
;
10262 struct attribute
*attr_byte_size
;
10263 struct attribute
*attr_address_class
;
10264 int byte_size
, addr_class
;
10265 struct type
*target_type
;
10267 target_type
= die_type (die
, cu
);
10269 /* The die_type call above may have already set the type for this DIE. */
10270 type
= get_die_type (die
, cu
);
10274 type
= lookup_pointer_type (target_type
);
10276 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10277 if (attr_byte_size
)
10278 byte_size
= DW_UNSND (attr_byte_size
);
10280 byte_size
= cu_header
->addr_size
;
10282 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
10283 if (attr_address_class
)
10284 addr_class
= DW_UNSND (attr_address_class
);
10286 addr_class
= DW_ADDR_none
;
10288 /* If the pointer size or address class is different than the
10289 default, create a type variant marked as such and set the
10290 length accordingly. */
10291 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
10293 if (gdbarch_address_class_type_flags_p (gdbarch
))
10297 type_flags
= gdbarch_address_class_type_flags
10298 (gdbarch
, byte_size
, addr_class
);
10299 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
10301 type
= make_type_with_address_space (type
, type_flags
);
10303 else if (TYPE_LENGTH (type
) != byte_size
)
10305 complaint (&symfile_complaints
,
10306 _("invalid pointer size %d"), byte_size
);
10310 /* Should we also complain about unhandled address classes? */
10314 TYPE_LENGTH (type
) = byte_size
;
10315 return set_die_type (die
, type
, cu
);
10318 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
10319 the user defined type vector. */
10321 static struct type
*
10322 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10325 struct type
*to_type
;
10326 struct type
*domain
;
10328 to_type
= die_type (die
, cu
);
10329 domain
= die_containing_type (die
, cu
);
10331 /* The calls above may have already set the type for this DIE. */
10332 type
= get_die_type (die
, cu
);
10336 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
10337 type
= lookup_methodptr_type (to_type
);
10339 type
= lookup_memberptr_type (to_type
, domain
);
10341 return set_die_type (die
, type
, cu
);
10344 /* Extract all information from a DW_TAG_reference_type DIE and add to
10345 the user defined type vector. */
10347 static struct type
*
10348 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10350 struct comp_unit_head
*cu_header
= &cu
->header
;
10351 struct type
*type
, *target_type
;
10352 struct attribute
*attr
;
10354 target_type
= die_type (die
, cu
);
10356 /* The die_type call above may have already set the type for this DIE. */
10357 type
= get_die_type (die
, cu
);
10361 type
= lookup_reference_type (target_type
);
10362 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10365 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10369 TYPE_LENGTH (type
) = cu_header
->addr_size
;
10371 return set_die_type (die
, type
, cu
);
10374 static struct type
*
10375 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10377 struct type
*base_type
, *cv_type
;
10379 base_type
= die_type (die
, cu
);
10381 /* The die_type call above may have already set the type for this DIE. */
10382 cv_type
= get_die_type (die
, cu
);
10386 /* In case the const qualifier is applied to an array type, the element type
10387 is so qualified, not the array type (section 6.7.3 of C99). */
10388 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
10390 struct type
*el_type
, *inner_array
;
10392 base_type
= copy_type (base_type
);
10393 inner_array
= base_type
;
10395 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
10397 TYPE_TARGET_TYPE (inner_array
) =
10398 copy_type (TYPE_TARGET_TYPE (inner_array
));
10399 inner_array
= TYPE_TARGET_TYPE (inner_array
);
10402 el_type
= TYPE_TARGET_TYPE (inner_array
);
10403 TYPE_TARGET_TYPE (inner_array
) =
10404 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
10406 return set_die_type (die
, base_type
, cu
);
10409 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
10410 return set_die_type (die
, cv_type
, cu
);
10413 static struct type
*
10414 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10416 struct type
*base_type
, *cv_type
;
10418 base_type
= die_type (die
, cu
);
10420 /* The die_type call above may have already set the type for this DIE. */
10421 cv_type
= get_die_type (die
, cu
);
10425 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
10426 return set_die_type (die
, cv_type
, cu
);
10429 /* Extract all information from a DW_TAG_string_type DIE and add to
10430 the user defined type vector. It isn't really a user defined type,
10431 but it behaves like one, with other DIE's using an AT_user_def_type
10432 attribute to reference it. */
10434 static struct type
*
10435 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10437 struct objfile
*objfile
= cu
->objfile
;
10438 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10439 struct type
*type
, *range_type
, *index_type
, *char_type
;
10440 struct attribute
*attr
;
10441 unsigned int length
;
10443 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
10446 length
= DW_UNSND (attr
);
10450 /* Check for the DW_AT_byte_size attribute. */
10451 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10454 length
= DW_UNSND (attr
);
10462 index_type
= objfile_type (objfile
)->builtin_int
;
10463 range_type
= create_range_type (NULL
, index_type
, 1, length
);
10464 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
10465 type
= create_string_type (NULL
, char_type
, range_type
);
10467 return set_die_type (die
, type
, cu
);
10470 /* Handle DIES due to C code like:
10474 int (*funcp)(int a, long l);
10478 ('funcp' generates a DW_TAG_subroutine_type DIE). */
10480 static struct type
*
10481 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10483 struct objfile
*objfile
= cu
->objfile
;
10484 struct type
*type
; /* Type that this function returns. */
10485 struct type
*ftype
; /* Function that returns above type. */
10486 struct attribute
*attr
;
10488 type
= die_type (die
, cu
);
10490 /* The die_type call above may have already set the type for this DIE. */
10491 ftype
= get_die_type (die
, cu
);
10495 ftype
= lookup_function_type (type
);
10497 /* All functions in C++, Pascal and Java have prototypes. */
10498 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
10499 if ((attr
&& (DW_UNSND (attr
) != 0))
10500 || cu
->language
== language_cplus
10501 || cu
->language
== language_java
10502 || cu
->language
== language_pascal
)
10503 TYPE_PROTOTYPED (ftype
) = 1;
10504 else if (producer_is_realview (cu
->producer
))
10505 /* RealView does not emit DW_AT_prototyped. We can not
10506 distinguish prototyped and unprototyped functions; default to
10507 prototyped, since that is more common in modern code (and
10508 RealView warns about unprototyped functions). */
10509 TYPE_PROTOTYPED (ftype
) = 1;
10511 /* Store the calling convention in the type if it's available in
10512 the subroutine die. Otherwise set the calling convention to
10513 the default value DW_CC_normal. */
10514 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
10516 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
10517 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
10518 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
10520 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
10522 /* We need to add the subroutine type to the die immediately so
10523 we don't infinitely recurse when dealing with parameters
10524 declared as the same subroutine type. */
10525 set_die_type (die
, ftype
, cu
);
10527 if (die
->child
!= NULL
)
10529 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
10530 struct die_info
*child_die
;
10531 int nparams
, iparams
;
10533 /* Count the number of parameters.
10534 FIXME: GDB currently ignores vararg functions, but knows about
10535 vararg member functions. */
10537 child_die
= die
->child
;
10538 while (child_die
&& child_die
->tag
)
10540 if (child_die
->tag
== DW_TAG_formal_parameter
)
10542 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
10543 TYPE_VARARGS (ftype
) = 1;
10544 child_die
= sibling_die (child_die
);
10547 /* Allocate storage for parameters and fill them in. */
10548 TYPE_NFIELDS (ftype
) = nparams
;
10549 TYPE_FIELDS (ftype
) = (struct field
*)
10550 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
10552 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
10553 even if we error out during the parameters reading below. */
10554 for (iparams
= 0; iparams
< nparams
; iparams
++)
10555 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
10558 child_die
= die
->child
;
10559 while (child_die
&& child_die
->tag
)
10561 if (child_die
->tag
== DW_TAG_formal_parameter
)
10563 struct type
*arg_type
;
10565 /* DWARF version 2 has no clean way to discern C++
10566 static and non-static member functions. G++ helps
10567 GDB by marking the first parameter for non-static
10568 member functions (which is the this pointer) as
10569 artificial. We pass this information to
10570 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
10572 DWARF version 3 added DW_AT_object_pointer, which GCC
10573 4.5 does not yet generate. */
10574 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
10576 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
10579 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
10581 /* GCC/43521: In java, the formal parameter
10582 "this" is sometimes not marked with DW_AT_artificial. */
10583 if (cu
->language
== language_java
)
10585 const char *name
= dwarf2_name (child_die
, cu
);
10587 if (name
&& !strcmp (name
, "this"))
10588 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
10591 arg_type
= die_type (child_die
, cu
);
10593 /* RealView does not mark THIS as const, which the testsuite
10594 expects. GCC marks THIS as const in method definitions,
10595 but not in the class specifications (GCC PR 43053). */
10596 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
10597 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
10600 struct dwarf2_cu
*arg_cu
= cu
;
10601 const char *name
= dwarf2_name (child_die
, cu
);
10603 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
10606 /* If the compiler emits this, use it. */
10607 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
10610 else if (name
&& strcmp (name
, "this") == 0)
10611 /* Function definitions will have the argument names. */
10613 else if (name
== NULL
&& iparams
== 0)
10614 /* Declarations may not have the names, so like
10615 elsewhere in GDB, assume an artificial first
10616 argument is "this". */
10620 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
10624 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
10627 child_die
= sibling_die (child_die
);
10634 static struct type
*
10635 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
10637 struct objfile
*objfile
= cu
->objfile
;
10638 const char *name
= NULL
;
10639 struct type
*this_type
, *target_type
;
10641 name
= dwarf2_full_name (NULL
, die
, cu
);
10642 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
10643 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
10644 TYPE_NAME (this_type
) = (char *) name
;
10645 set_die_type (die
, this_type
, cu
);
10646 target_type
= die_type (die
, cu
);
10647 if (target_type
!= this_type
)
10648 TYPE_TARGET_TYPE (this_type
) = target_type
;
10651 /* Self-referential typedefs are, it seems, not allowed by the DWARF
10652 spec and cause infinite loops in GDB. */
10653 complaint (&symfile_complaints
,
10654 _("Self-referential DW_TAG_typedef "
10655 "- DIE at 0x%x [in module %s]"),
10656 die
->offset
.sect_off
, objfile
->name
);
10657 TYPE_TARGET_TYPE (this_type
) = NULL
;
10662 /* Find a representation of a given base type and install
10663 it in the TYPE field of the die. */
10665 static struct type
*
10666 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10668 struct objfile
*objfile
= cu
->objfile
;
10670 struct attribute
*attr
;
10671 int encoding
= 0, size
= 0;
10673 enum type_code code
= TYPE_CODE_INT
;
10674 int type_flags
= 0;
10675 struct type
*target_type
= NULL
;
10677 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
10680 encoding
= DW_UNSND (attr
);
10682 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10685 size
= DW_UNSND (attr
);
10687 name
= dwarf2_name (die
, cu
);
10690 complaint (&symfile_complaints
,
10691 _("DW_AT_name missing from DW_TAG_base_type"));
10696 case DW_ATE_address
:
10697 /* Turn DW_ATE_address into a void * pointer. */
10698 code
= TYPE_CODE_PTR
;
10699 type_flags
|= TYPE_FLAG_UNSIGNED
;
10700 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
10702 case DW_ATE_boolean
:
10703 code
= TYPE_CODE_BOOL
;
10704 type_flags
|= TYPE_FLAG_UNSIGNED
;
10706 case DW_ATE_complex_float
:
10707 code
= TYPE_CODE_COMPLEX
;
10708 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
10710 case DW_ATE_decimal_float
:
10711 code
= TYPE_CODE_DECFLOAT
;
10714 code
= TYPE_CODE_FLT
;
10716 case DW_ATE_signed
:
10718 case DW_ATE_unsigned
:
10719 type_flags
|= TYPE_FLAG_UNSIGNED
;
10720 if (cu
->language
== language_fortran
10722 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
10723 code
= TYPE_CODE_CHAR
;
10725 case DW_ATE_signed_char
:
10726 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10727 || cu
->language
== language_pascal
10728 || cu
->language
== language_fortran
)
10729 code
= TYPE_CODE_CHAR
;
10731 case DW_ATE_unsigned_char
:
10732 if (cu
->language
== language_ada
|| cu
->language
== language_m2
10733 || cu
->language
== language_pascal
10734 || cu
->language
== language_fortran
)
10735 code
= TYPE_CODE_CHAR
;
10736 type_flags
|= TYPE_FLAG_UNSIGNED
;
10739 /* We just treat this as an integer and then recognize the
10740 type by name elsewhere. */
10744 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
10745 dwarf_type_encoding_name (encoding
));
10749 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
10750 TYPE_NAME (type
) = name
;
10751 TYPE_TARGET_TYPE (type
) = target_type
;
10753 if (name
&& strcmp (name
, "char") == 0)
10754 TYPE_NOSIGN (type
) = 1;
10756 return set_die_type (die
, type
, cu
);
10759 /* Read the given DW_AT_subrange DIE. */
10761 static struct type
*
10762 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10764 struct type
*base_type
;
10765 struct type
*range_type
;
10766 struct attribute
*attr
;
10768 int low_default_is_valid
;
10770 LONGEST negative_mask
;
10772 base_type
= die_type (die
, cu
);
10773 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
10774 check_typedef (base_type
);
10776 /* The die_type call above may have already set the type for this DIE. */
10777 range_type
= get_die_type (die
, cu
);
10781 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
10782 omitting DW_AT_lower_bound. */
10783 switch (cu
->language
)
10786 case language_cplus
:
10788 low_default_is_valid
= 1;
10790 case language_fortran
:
10792 low_default_is_valid
= 1;
10795 case language_java
:
10796 case language_objc
:
10798 low_default_is_valid
= (cu
->header
.version
>= 4);
10802 case language_pascal
:
10804 low_default_is_valid
= (cu
->header
.version
>= 4);
10808 low_default_is_valid
= 0;
10812 /* FIXME: For variable sized arrays either of these could be
10813 a variable rather than a constant value. We'll allow it,
10814 but we don't know how to handle it. */
10815 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
10817 low
= dwarf2_get_attr_constant_value (attr
, low
);
10818 else if (!low_default_is_valid
)
10819 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
10820 "- DIE at 0x%x [in module %s]"),
10821 die
->offset
.sect_off
, cu
->objfile
->name
);
10823 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
10826 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
10828 /* GCC encodes arrays with unspecified or dynamic length
10829 with a DW_FORM_block1 attribute or a reference attribute.
10830 FIXME: GDB does not yet know how to handle dynamic
10831 arrays properly, treat them as arrays with unspecified
10834 FIXME: jimb/2003-09-22: GDB does not really know
10835 how to handle arrays of unspecified length
10836 either; we just represent them as zero-length
10837 arrays. Choose an appropriate upper bound given
10838 the lower bound we've computed above. */
10842 high
= dwarf2_get_attr_constant_value (attr
, 1);
10846 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
10849 int count
= dwarf2_get_attr_constant_value (attr
, 1);
10850 high
= low
+ count
- 1;
10854 /* Unspecified array length. */
10859 /* Dwarf-2 specifications explicitly allows to create subrange types
10860 without specifying a base type.
10861 In that case, the base type must be set to the type of
10862 the lower bound, upper bound or count, in that order, if any of these
10863 three attributes references an object that has a type.
10864 If no base type is found, the Dwarf-2 specifications say that
10865 a signed integer type of size equal to the size of an address should
10867 For the following C code: `extern char gdb_int [];'
10868 GCC produces an empty range DIE.
10869 FIXME: muller/2010-05-28: Possible references to object for low bound,
10870 high bound or count are not yet handled by this code. */
10871 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
10873 struct objfile
*objfile
= cu
->objfile
;
10874 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10875 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
10876 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
10878 /* Test "int", "long int", and "long long int" objfile types,
10879 and select the first one having a size above or equal to the
10880 architecture address size. */
10881 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10882 base_type
= int_type
;
10885 int_type
= objfile_type (objfile
)->builtin_long
;
10886 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10887 base_type
= int_type
;
10890 int_type
= objfile_type (objfile
)->builtin_long_long
;
10891 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
10892 base_type
= int_type
;
10898 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
10899 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
10900 low
|= negative_mask
;
10901 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
10902 high
|= negative_mask
;
10904 range_type
= create_range_type (NULL
, base_type
, low
, high
);
10906 /* Mark arrays with dynamic length at least as an array of unspecified
10907 length. GDB could check the boundary but before it gets implemented at
10908 least allow accessing the array elements. */
10909 if (attr
&& attr_form_is_block (attr
))
10910 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10912 /* Ada expects an empty array on no boundary attributes. */
10913 if (attr
== NULL
&& cu
->language
!= language_ada
)
10914 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
10916 name
= dwarf2_name (die
, cu
);
10918 TYPE_NAME (range_type
) = name
;
10920 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10922 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
10924 set_die_type (die
, range_type
, cu
);
10926 /* set_die_type should be already done. */
10927 set_descriptive_type (range_type
, die
, cu
);
10932 static struct type
*
10933 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10937 /* For now, we only support the C meaning of an unspecified type: void. */
10939 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
10940 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
10942 return set_die_type (die
, type
, cu
);
10945 /* Read a single die and all its descendents. Set the die's sibling
10946 field to NULL; set other fields in the die correctly, and set all
10947 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
10948 location of the info_ptr after reading all of those dies. PARENT
10949 is the parent of the die in question. */
10951 static struct die_info
*
10952 read_die_and_children (const struct die_reader_specs
*reader
,
10953 gdb_byte
*info_ptr
,
10954 gdb_byte
**new_info_ptr
,
10955 struct die_info
*parent
)
10957 struct die_info
*die
;
10961 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
10964 *new_info_ptr
= cur_ptr
;
10967 store_in_ref_table (die
, reader
->cu
);
10970 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
10974 *new_info_ptr
= cur_ptr
;
10977 die
->sibling
= NULL
;
10978 die
->parent
= parent
;
10982 /* Read a die, all of its descendents, and all of its siblings; set
10983 all of the fields of all of the dies correctly. Arguments are as
10984 in read_die_and_children. */
10986 static struct die_info
*
10987 read_die_and_siblings (const struct die_reader_specs
*reader
,
10988 gdb_byte
*info_ptr
,
10989 gdb_byte
**new_info_ptr
,
10990 struct die_info
*parent
)
10992 struct die_info
*first_die
, *last_sibling
;
10995 cur_ptr
= info_ptr
;
10996 first_die
= last_sibling
= NULL
;
11000 struct die_info
*die
11001 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11005 *new_info_ptr
= cur_ptr
;
11012 last_sibling
->sibling
= die
;
11014 last_sibling
= die
;
11018 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
11020 The caller is responsible for filling in the extra attributes
11021 and updating (*DIEP)->num_attrs.
11022 Set DIEP to point to a newly allocated die with its information,
11023 except for its child, sibling, and parent fields.
11024 Set HAS_CHILDREN to tell whether the die has children or not. */
11027 read_full_die_1 (const struct die_reader_specs
*reader
,
11028 struct die_info
**diep
, gdb_byte
*info_ptr
,
11029 int *has_children
, int num_extra_attrs
)
11031 unsigned int abbrev_number
, bytes_read
, i
;
11032 sect_offset offset
;
11033 struct abbrev_info
*abbrev
;
11034 struct die_info
*die
;
11035 struct dwarf2_cu
*cu
= reader
->cu
;
11036 bfd
*abfd
= reader
->abfd
;
11038 offset
.sect_off
= info_ptr
- reader
->buffer
;
11039 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11040 info_ptr
+= bytes_read
;
11041 if (!abbrev_number
)
11048 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
11050 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
11052 bfd_get_filename (abfd
));
11054 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
11055 die
->offset
= offset
;
11056 die
->tag
= abbrev
->tag
;
11057 die
->abbrev
= abbrev_number
;
11059 /* Make the result usable.
11060 The caller needs to update num_attrs after adding the extra
11062 die
->num_attrs
= abbrev
->num_attrs
;
11064 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11065 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
11069 *has_children
= abbrev
->has_children
;
11073 /* Read a die and all its attributes.
11074 Set DIEP to point to a newly allocated die with its information,
11075 except for its child, sibling, and parent fields.
11076 Set HAS_CHILDREN to tell whether the die has children or not. */
11079 read_full_die (const struct die_reader_specs
*reader
,
11080 struct die_info
**diep
, gdb_byte
*info_ptr
,
11083 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
11086 /* Abbreviation tables.
11088 In DWARF version 2, the description of the debugging information is
11089 stored in a separate .debug_abbrev section. Before we read any
11090 dies from a section we read in all abbreviations and install them
11091 in a hash table. */
11093 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
11095 static struct abbrev_info
*
11096 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
11098 struct abbrev_info
*abbrev
;
11100 abbrev
= (struct abbrev_info
*)
11101 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
11102 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11106 /* Add an abbreviation to the table. */
11109 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11110 unsigned int abbrev_number
,
11111 struct abbrev_info
*abbrev
)
11113 unsigned int hash_number
;
11115 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11116 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11117 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11120 /* Look up an abbrev in the table.
11121 Returns NULL if the abbrev is not found. */
11123 static struct abbrev_info
*
11124 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11125 unsigned int abbrev_number
)
11127 unsigned int hash_number
;
11128 struct abbrev_info
*abbrev
;
11130 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11131 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11135 if (abbrev
->number
== abbrev_number
)
11137 abbrev
= abbrev
->next
;
11142 /* Read in an abbrev table. */
11144 static struct abbrev_table
*
11145 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11146 sect_offset offset
)
11148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11149 bfd
*abfd
= section
->asection
->owner
;
11150 struct abbrev_table
*abbrev_table
;
11151 gdb_byte
*abbrev_ptr
;
11152 struct abbrev_info
*cur_abbrev
;
11153 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11154 unsigned int abbrev_form
;
11155 struct attr_abbrev
*cur_attrs
;
11156 unsigned int allocated_attrs
;
11158 abbrev_table
= XMALLOC (struct abbrev_table
);
11159 obstack_init (&abbrev_table
->abbrev_obstack
);
11160 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11162 * sizeof (struct abbrev_info
*)));
11163 memset (abbrev_table
->abbrevs
, 0,
11164 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
11166 dwarf2_read_section (objfile
, section
);
11167 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
11168 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11169 abbrev_ptr
+= bytes_read
;
11171 allocated_attrs
= ATTR_ALLOC_CHUNK
;
11172 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
11174 /* Loop until we reach an abbrev number of 0. */
11175 while (abbrev_number
)
11177 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
11179 /* read in abbrev header */
11180 cur_abbrev
->number
= abbrev_number
;
11181 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11182 abbrev_ptr
+= bytes_read
;
11183 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
11186 /* now read in declarations */
11187 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11188 abbrev_ptr
+= bytes_read
;
11189 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11190 abbrev_ptr
+= bytes_read
;
11191 while (abbrev_name
)
11193 if (cur_abbrev
->num_attrs
== allocated_attrs
)
11195 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
11197 = xrealloc (cur_attrs
, (allocated_attrs
11198 * sizeof (struct attr_abbrev
)));
11201 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
11202 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
11203 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11204 abbrev_ptr
+= bytes_read
;
11205 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11206 abbrev_ptr
+= bytes_read
;
11209 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
11210 (cur_abbrev
->num_attrs
11211 * sizeof (struct attr_abbrev
)));
11212 memcpy (cur_abbrev
->attrs
, cur_attrs
,
11213 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
11215 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
11217 /* Get next abbreviation.
11218 Under Irix6 the abbreviations for a compilation unit are not
11219 always properly terminated with an abbrev number of 0.
11220 Exit loop if we encounter an abbreviation which we have
11221 already read (which means we are about to read the abbreviations
11222 for the next compile unit) or if the end of the abbreviation
11223 table is reached. */
11224 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
11226 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
11227 abbrev_ptr
+= bytes_read
;
11228 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
11233 return abbrev_table
;
11236 /* Free the resources held by ABBREV_TABLE. */
11239 abbrev_table_free (struct abbrev_table
*abbrev_table
)
11241 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
11242 xfree (abbrev_table
);
11245 /* Read the abbrev table for CU from ABBREV_SECTION. */
11248 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
11249 struct dwarf2_section_info
*abbrev_section
)
11252 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
11255 /* Release the memory used by the abbrev table for a compilation unit. */
11258 dwarf2_free_abbrev_table (void *ptr_to_cu
)
11260 struct dwarf2_cu
*cu
= ptr_to_cu
;
11262 abbrev_table_free (cu
->abbrev_table
);
11263 /* Set this to NULL so that we SEGV if we try to read it later,
11264 and also because free_comp_unit verifies this is NULL. */
11265 cu
->abbrev_table
= NULL
;
11268 /* Returns nonzero if TAG represents a type that we might generate a partial
11272 is_type_tag_for_partial (int tag
)
11277 /* Some types that would be reasonable to generate partial symbols for,
11278 that we don't at present. */
11279 case DW_TAG_array_type
:
11280 case DW_TAG_file_type
:
11281 case DW_TAG_ptr_to_member_type
:
11282 case DW_TAG_set_type
:
11283 case DW_TAG_string_type
:
11284 case DW_TAG_subroutine_type
:
11286 case DW_TAG_base_type
:
11287 case DW_TAG_class_type
:
11288 case DW_TAG_interface_type
:
11289 case DW_TAG_enumeration_type
:
11290 case DW_TAG_structure_type
:
11291 case DW_TAG_subrange_type
:
11292 case DW_TAG_typedef
:
11293 case DW_TAG_union_type
:
11300 /* Load all DIEs that are interesting for partial symbols into memory. */
11302 static struct partial_die_info
*
11303 load_partial_dies (const struct die_reader_specs
*reader
,
11304 gdb_byte
*info_ptr
, int building_psymtab
)
11306 struct dwarf2_cu
*cu
= reader
->cu
;
11307 struct objfile
*objfile
= cu
->objfile
;
11308 struct partial_die_info
*part_die
;
11309 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
11310 struct abbrev_info
*abbrev
;
11311 unsigned int bytes_read
;
11312 unsigned int load_all
= 0;
11313 int nesting_level
= 1;
11318 gdb_assert (cu
->per_cu
!= NULL
);
11319 if (cu
->per_cu
->load_all_dies
)
11323 = htab_create_alloc_ex (cu
->header
.length
/ 12,
11327 &cu
->comp_unit_obstack
,
11328 hashtab_obstack_allocate
,
11329 dummy_obstack_deallocate
);
11331 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11332 sizeof (struct partial_die_info
));
11336 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
11338 /* A NULL abbrev means the end of a series of children. */
11339 if (abbrev
== NULL
)
11341 if (--nesting_level
== 0)
11343 /* PART_DIE was probably the last thing allocated on the
11344 comp_unit_obstack, so we could call obstack_free
11345 here. We don't do that because the waste is small,
11346 and will be cleaned up when we're done with this
11347 compilation unit. This way, we're also more robust
11348 against other users of the comp_unit_obstack. */
11351 info_ptr
+= bytes_read
;
11352 last_die
= parent_die
;
11353 parent_die
= parent_die
->die_parent
;
11357 /* Check for template arguments. We never save these; if
11358 they're seen, we just mark the parent, and go on our way. */
11359 if (parent_die
!= NULL
11360 && cu
->language
== language_cplus
11361 && (abbrev
->tag
== DW_TAG_template_type_param
11362 || abbrev
->tag
== DW_TAG_template_value_param
))
11364 parent_die
->has_template_arguments
= 1;
11368 /* We don't need a partial DIE for the template argument. */
11369 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11374 /* We only recurse into c++ subprograms looking for template arguments.
11375 Skip their other children. */
11377 && cu
->language
== language_cplus
11378 && parent_die
!= NULL
11379 && parent_die
->tag
== DW_TAG_subprogram
)
11381 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11385 /* Check whether this DIE is interesting enough to save. Normally
11386 we would not be interested in members here, but there may be
11387 later variables referencing them via DW_AT_specification (for
11388 static members). */
11390 && !is_type_tag_for_partial (abbrev
->tag
)
11391 && abbrev
->tag
!= DW_TAG_constant
11392 && abbrev
->tag
!= DW_TAG_enumerator
11393 && abbrev
->tag
!= DW_TAG_subprogram
11394 && abbrev
->tag
!= DW_TAG_lexical_block
11395 && abbrev
->tag
!= DW_TAG_variable
11396 && abbrev
->tag
!= DW_TAG_namespace
11397 && abbrev
->tag
!= DW_TAG_module
11398 && abbrev
->tag
!= DW_TAG_member
11399 && abbrev
->tag
!= DW_TAG_imported_unit
)
11401 /* Otherwise we skip to the next sibling, if any. */
11402 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
11406 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
11409 /* This two-pass algorithm for processing partial symbols has a
11410 high cost in cache pressure. Thus, handle some simple cases
11411 here which cover the majority of C partial symbols. DIEs
11412 which neither have specification tags in them, nor could have
11413 specification tags elsewhere pointing at them, can simply be
11414 processed and discarded.
11416 This segment is also optional; scan_partial_symbols and
11417 add_partial_symbol will handle these DIEs if we chain
11418 them in normally. When compilers which do not emit large
11419 quantities of duplicate debug information are more common,
11420 this code can probably be removed. */
11422 /* Any complete simple types at the top level (pretty much all
11423 of them, for a language without namespaces), can be processed
11425 if (parent_die
== NULL
11426 && part_die
->has_specification
== 0
11427 && part_die
->is_declaration
== 0
11428 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
11429 || part_die
->tag
== DW_TAG_base_type
11430 || part_die
->tag
== DW_TAG_subrange_type
))
11432 if (building_psymtab
&& part_die
->name
!= NULL
)
11433 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11434 VAR_DOMAIN
, LOC_TYPEDEF
,
11435 &objfile
->static_psymbols
,
11436 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11437 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11441 /* The exception for DW_TAG_typedef with has_children above is
11442 a workaround of GCC PR debug/47510. In the case of this complaint
11443 type_name_no_tag_or_error will error on such types later.
11445 GDB skipped children of DW_TAG_typedef by the shortcut above and then
11446 it could not find the child DIEs referenced later, this is checked
11447 above. In correct DWARF DW_TAG_typedef should have no children. */
11449 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
11450 complaint (&symfile_complaints
,
11451 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
11452 "- DIE at 0x%x [in module %s]"),
11453 part_die
->offset
.sect_off
, objfile
->name
);
11455 /* If we're at the second level, and we're an enumerator, and
11456 our parent has no specification (meaning possibly lives in a
11457 namespace elsewhere), then we can add the partial symbol now
11458 instead of queueing it. */
11459 if (part_die
->tag
== DW_TAG_enumerator
11460 && parent_die
!= NULL
11461 && parent_die
->die_parent
== NULL
11462 && parent_die
->tag
== DW_TAG_enumeration_type
11463 && parent_die
->has_specification
== 0)
11465 if (part_die
->name
== NULL
)
11466 complaint (&symfile_complaints
,
11467 _("malformed enumerator DIE ignored"));
11468 else if (building_psymtab
)
11469 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
11470 VAR_DOMAIN
, LOC_CONST
,
11471 (cu
->language
== language_cplus
11472 || cu
->language
== language_java
)
11473 ? &objfile
->global_psymbols
11474 : &objfile
->static_psymbols
,
11475 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
11477 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
11481 /* We'll save this DIE so link it in. */
11482 part_die
->die_parent
= parent_die
;
11483 part_die
->die_sibling
= NULL
;
11484 part_die
->die_child
= NULL
;
11486 if (last_die
&& last_die
== parent_die
)
11487 last_die
->die_child
= part_die
;
11489 last_die
->die_sibling
= part_die
;
11491 last_die
= part_die
;
11493 if (first_die
== NULL
)
11494 first_die
= part_die
;
11496 /* Maybe add the DIE to the hash table. Not all DIEs that we
11497 find interesting need to be in the hash table, because we
11498 also have the parent/sibling/child chains; only those that we
11499 might refer to by offset later during partial symbol reading.
11501 For now this means things that might have be the target of a
11502 DW_AT_specification, DW_AT_abstract_origin, or
11503 DW_AT_extension. DW_AT_extension will refer only to
11504 namespaces; DW_AT_abstract_origin refers to functions (and
11505 many things under the function DIE, but we do not recurse
11506 into function DIEs during partial symbol reading) and
11507 possibly variables as well; DW_AT_specification refers to
11508 declarations. Declarations ought to have the DW_AT_declaration
11509 flag. It happens that GCC forgets to put it in sometimes, but
11510 only for functions, not for types.
11512 Adding more things than necessary to the hash table is harmless
11513 except for the performance cost. Adding too few will result in
11514 wasted time in find_partial_die, when we reread the compilation
11515 unit with load_all_dies set. */
11518 || abbrev
->tag
== DW_TAG_constant
11519 || abbrev
->tag
== DW_TAG_subprogram
11520 || abbrev
->tag
== DW_TAG_variable
11521 || abbrev
->tag
== DW_TAG_namespace
11522 || part_die
->is_declaration
)
11526 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
11527 part_die
->offset
.sect_off
, INSERT
);
11531 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
11532 sizeof (struct partial_die_info
));
11534 /* For some DIEs we want to follow their children (if any). For C
11535 we have no reason to follow the children of structures; for other
11536 languages we have to, so that we can get at method physnames
11537 to infer fully qualified class names, for DW_AT_specification,
11538 and for C++ template arguments. For C++, we also look one level
11539 inside functions to find template arguments (if the name of the
11540 function does not already contain the template arguments).
11542 For Ada, we need to scan the children of subprograms and lexical
11543 blocks as well because Ada allows the definition of nested
11544 entities that could be interesting for the debugger, such as
11545 nested subprograms for instance. */
11546 if (last_die
->has_children
11548 || last_die
->tag
== DW_TAG_namespace
11549 || last_die
->tag
== DW_TAG_module
11550 || last_die
->tag
== DW_TAG_enumeration_type
11551 || (cu
->language
== language_cplus
11552 && last_die
->tag
== DW_TAG_subprogram
11553 && (last_die
->name
== NULL
11554 || strchr (last_die
->name
, '<') == NULL
))
11555 || (cu
->language
!= language_c
11556 && (last_die
->tag
== DW_TAG_class_type
11557 || last_die
->tag
== DW_TAG_interface_type
11558 || last_die
->tag
== DW_TAG_structure_type
11559 || last_die
->tag
== DW_TAG_union_type
))
11560 || (cu
->language
== language_ada
11561 && (last_die
->tag
== DW_TAG_subprogram
11562 || last_die
->tag
== DW_TAG_lexical_block
))))
11565 parent_die
= last_die
;
11569 /* Otherwise we skip to the next sibling, if any. */
11570 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
11572 /* Back to the top, do it again. */
11576 /* Read a minimal amount of information into the minimal die structure. */
11579 read_partial_die (const struct die_reader_specs
*reader
,
11580 struct partial_die_info
*part_die
,
11581 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
11582 gdb_byte
*info_ptr
)
11584 struct dwarf2_cu
*cu
= reader
->cu
;
11585 struct objfile
*objfile
= cu
->objfile
;
11586 gdb_byte
*buffer
= reader
->buffer
;
11588 struct attribute attr
;
11589 int has_low_pc_attr
= 0;
11590 int has_high_pc_attr
= 0;
11591 int high_pc_relative
= 0;
11593 memset (part_die
, 0, sizeof (struct partial_die_info
));
11595 part_die
->offset
.sect_off
= info_ptr
- buffer
;
11597 info_ptr
+= abbrev_len
;
11599 if (abbrev
== NULL
)
11602 part_die
->tag
= abbrev
->tag
;
11603 part_die
->has_children
= abbrev
->has_children
;
11605 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11607 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
11609 /* Store the data if it is of an attribute we want to keep in a
11610 partial symbol table. */
11614 switch (part_die
->tag
)
11616 case DW_TAG_compile_unit
:
11617 case DW_TAG_partial_unit
:
11618 case DW_TAG_type_unit
:
11619 /* Compilation units have a DW_AT_name that is a filename, not
11620 a source language identifier. */
11621 case DW_TAG_enumeration_type
:
11622 case DW_TAG_enumerator
:
11623 /* These tags always have simple identifiers already; no need
11624 to canonicalize them. */
11625 part_die
->name
= DW_STRING (&attr
);
11629 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
11630 &objfile
->objfile_obstack
);
11634 case DW_AT_linkage_name
:
11635 case DW_AT_MIPS_linkage_name
:
11636 /* Note that both forms of linkage name might appear. We
11637 assume they will be the same, and we only store the last
11639 if (cu
->language
== language_ada
)
11640 part_die
->name
= DW_STRING (&attr
);
11641 part_die
->linkage_name
= DW_STRING (&attr
);
11644 has_low_pc_attr
= 1;
11645 part_die
->lowpc
= DW_ADDR (&attr
);
11647 case DW_AT_high_pc
:
11648 has_high_pc_attr
= 1;
11649 if (attr
.form
== DW_FORM_addr
11650 || attr
.form
== DW_FORM_GNU_addr_index
)
11651 part_die
->highpc
= DW_ADDR (&attr
);
11654 high_pc_relative
= 1;
11655 part_die
->highpc
= DW_UNSND (&attr
);
11658 case DW_AT_location
:
11659 /* Support the .debug_loc offsets. */
11660 if (attr_form_is_block (&attr
))
11662 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
11664 else if (attr_form_is_section_offset (&attr
))
11666 dwarf2_complex_location_expr_complaint ();
11670 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11671 "partial symbol information");
11674 case DW_AT_external
:
11675 part_die
->is_external
= DW_UNSND (&attr
);
11677 case DW_AT_declaration
:
11678 part_die
->is_declaration
= DW_UNSND (&attr
);
11681 part_die
->has_type
= 1;
11683 case DW_AT_abstract_origin
:
11684 case DW_AT_specification
:
11685 case DW_AT_extension
:
11686 part_die
->has_specification
= 1;
11687 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
11689 case DW_AT_sibling
:
11690 /* Ignore absolute siblings, they might point outside of
11691 the current compile unit. */
11692 if (attr
.form
== DW_FORM_ref_addr
)
11693 complaint (&symfile_complaints
,
11694 _("ignoring absolute DW_AT_sibling"));
11696 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
11698 case DW_AT_byte_size
:
11699 part_die
->has_byte_size
= 1;
11701 case DW_AT_calling_convention
:
11702 /* DWARF doesn't provide a way to identify a program's source-level
11703 entry point. DW_AT_calling_convention attributes are only meant
11704 to describe functions' calling conventions.
11706 However, because it's a necessary piece of information in
11707 Fortran, and because DW_CC_program is the only piece of debugging
11708 information whose definition refers to a 'main program' at all,
11709 several compilers have begun marking Fortran main programs with
11710 DW_CC_program --- even when those functions use the standard
11711 calling conventions.
11713 So until DWARF specifies a way to provide this information and
11714 compilers pick up the new representation, we'll support this
11716 if (DW_UNSND (&attr
) == DW_CC_program
11717 && cu
->language
== language_fortran
)
11719 set_main_name (part_die
->name
);
11721 /* As this DIE has a static linkage the name would be difficult
11722 to look up later. */
11723 language_of_main
= language_fortran
;
11727 if (DW_UNSND (&attr
) == DW_INL_inlined
11728 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
11729 part_die
->may_be_inlined
= 1;
11733 if (part_die
->tag
== DW_TAG_imported_unit
)
11734 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
11742 if (high_pc_relative
)
11743 part_die
->highpc
+= part_die
->lowpc
;
11745 if (has_low_pc_attr
&& has_high_pc_attr
)
11747 /* When using the GNU linker, .gnu.linkonce. sections are used to
11748 eliminate duplicate copies of functions and vtables and such.
11749 The linker will arbitrarily choose one and discard the others.
11750 The AT_*_pc values for such functions refer to local labels in
11751 these sections. If the section from that file was discarded, the
11752 labels are not in the output, so the relocs get a value of 0.
11753 If this is a discarded function, mark the pc bounds as invalid,
11754 so that GDB will ignore it. */
11755 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
11757 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11759 complaint (&symfile_complaints
,
11760 _("DW_AT_low_pc %s is zero "
11761 "for DIE at 0x%x [in module %s]"),
11762 paddress (gdbarch
, part_die
->lowpc
),
11763 part_die
->offset
.sect_off
, objfile
->name
);
11765 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
11766 else if (part_die
->lowpc
>= part_die
->highpc
)
11768 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11770 complaint (&symfile_complaints
,
11771 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
11772 "for DIE at 0x%x [in module %s]"),
11773 paddress (gdbarch
, part_die
->lowpc
),
11774 paddress (gdbarch
, part_die
->highpc
),
11775 part_die
->offset
.sect_off
, objfile
->name
);
11778 part_die
->has_pc_info
= 1;
11784 /* Find a cached partial DIE at OFFSET in CU. */
11786 static struct partial_die_info
*
11787 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
11789 struct partial_die_info
*lookup_die
= NULL
;
11790 struct partial_die_info part_die
;
11792 part_die
.offset
= offset
;
11793 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
11799 /* Find a partial DIE at OFFSET, which may or may not be in CU,
11800 except in the case of .debug_types DIEs which do not reference
11801 outside their CU (they do however referencing other types via
11802 DW_FORM_ref_sig8). */
11804 static struct partial_die_info
*
11805 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
11807 struct objfile
*objfile
= cu
->objfile
;
11808 struct dwarf2_per_cu_data
*per_cu
= NULL
;
11809 struct partial_die_info
*pd
= NULL
;
11811 if (offset_in_cu_p (&cu
->header
, offset
))
11813 pd
= find_partial_die_in_comp_unit (offset
, cu
);
11816 /* We missed recording what we needed.
11817 Load all dies and try again. */
11818 per_cu
= cu
->per_cu
;
11822 /* TUs don't reference other CUs/TUs (except via type signatures). */
11823 if (cu
->per_cu
->is_debug_types
)
11825 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
11826 " external reference to offset 0x%lx [in module %s].\n"),
11827 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
11828 bfd_get_filename (objfile
->obfd
));
11830 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11832 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
11833 load_partial_comp_unit (per_cu
);
11835 per_cu
->cu
->last_used
= 0;
11836 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11839 /* If we didn't find it, and not all dies have been loaded,
11840 load them all and try again. */
11842 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
11844 per_cu
->load_all_dies
= 1;
11846 /* This is nasty. When we reread the DIEs, somewhere up the call chain
11847 THIS_CU->cu may already be in use. So we can't just free it and
11848 replace its DIEs with the ones we read in. Instead, we leave those
11849 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
11850 and clobber THIS_CU->cu->partial_dies with the hash table for the new
11852 load_partial_comp_unit (per_cu
);
11854 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
11858 internal_error (__FILE__
, __LINE__
,
11859 _("could not find partial DIE 0x%x "
11860 "in cache [from module %s]\n"),
11861 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
11865 /* See if we can figure out if the class lives in a namespace. We do
11866 this by looking for a member function; its demangled name will
11867 contain namespace info, if there is any. */
11870 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
11871 struct dwarf2_cu
*cu
)
11873 /* NOTE: carlton/2003-10-07: Getting the info this way changes
11874 what template types look like, because the demangler
11875 frequently doesn't give the same name as the debug info. We
11876 could fix this by only using the demangled name to get the
11877 prefix (but see comment in read_structure_type). */
11879 struct partial_die_info
*real_pdi
;
11880 struct partial_die_info
*child_pdi
;
11882 /* If this DIE (this DIE's specification, if any) has a parent, then
11883 we should not do this. We'll prepend the parent's fully qualified
11884 name when we create the partial symbol. */
11886 real_pdi
= struct_pdi
;
11887 while (real_pdi
->has_specification
)
11888 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
11890 if (real_pdi
->die_parent
!= NULL
)
11893 for (child_pdi
= struct_pdi
->die_child
;
11895 child_pdi
= child_pdi
->die_sibling
)
11897 if (child_pdi
->tag
== DW_TAG_subprogram
11898 && child_pdi
->linkage_name
!= NULL
)
11900 char *actual_class_name
11901 = language_class_name_from_physname (cu
->language_defn
,
11902 child_pdi
->linkage_name
);
11903 if (actual_class_name
!= NULL
)
11906 = obsavestring (actual_class_name
,
11907 strlen (actual_class_name
),
11908 &cu
->objfile
->objfile_obstack
);
11909 xfree (actual_class_name
);
11916 /* Adjust PART_DIE before generating a symbol for it. This function
11917 may set the is_external flag or change the DIE's name. */
11920 fixup_partial_die (struct partial_die_info
*part_die
,
11921 struct dwarf2_cu
*cu
)
11923 /* Once we've fixed up a die, there's no point in doing so again.
11924 This also avoids a memory leak if we were to call
11925 guess_partial_die_structure_name multiple times. */
11926 if (part_die
->fixup_called
)
11929 /* If we found a reference attribute and the DIE has no name, try
11930 to find a name in the referred to DIE. */
11932 if (part_die
->name
== NULL
&& part_die
->has_specification
)
11934 struct partial_die_info
*spec_die
;
11936 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
11938 fixup_partial_die (spec_die
, cu
);
11940 if (spec_die
->name
)
11942 part_die
->name
= spec_die
->name
;
11944 /* Copy DW_AT_external attribute if it is set. */
11945 if (spec_die
->is_external
)
11946 part_die
->is_external
= spec_die
->is_external
;
11950 /* Set default names for some unnamed DIEs. */
11952 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
11953 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
11955 /* If there is no parent die to provide a namespace, and there are
11956 children, see if we can determine the namespace from their linkage
11958 if (cu
->language
== language_cplus
11959 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
11960 && part_die
->die_parent
== NULL
11961 && part_die
->has_children
11962 && (part_die
->tag
== DW_TAG_class_type
11963 || part_die
->tag
== DW_TAG_structure_type
11964 || part_die
->tag
== DW_TAG_union_type
))
11965 guess_partial_die_structure_name (part_die
, cu
);
11967 /* GCC might emit a nameless struct or union that has a linkage
11968 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
11969 if (part_die
->name
== NULL
11970 && (part_die
->tag
== DW_TAG_class_type
11971 || part_die
->tag
== DW_TAG_interface_type
11972 || part_die
->tag
== DW_TAG_structure_type
11973 || part_die
->tag
== DW_TAG_union_type
)
11974 && part_die
->linkage_name
!= NULL
)
11978 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
11983 /* Strip any leading namespaces/classes, keep only the base name.
11984 DW_AT_name for named DIEs does not contain the prefixes. */
11985 base
= strrchr (demangled
, ':');
11986 if (base
&& base
> demangled
&& base
[-1] == ':')
11991 part_die
->name
= obsavestring (base
, strlen (base
),
11992 &cu
->objfile
->objfile_obstack
);
11997 part_die
->fixup_called
= 1;
12000 /* Read an attribute value described by an attribute form. */
12003 read_attribute_value (const struct die_reader_specs
*reader
,
12004 struct attribute
*attr
, unsigned form
,
12005 gdb_byte
*info_ptr
)
12007 struct dwarf2_cu
*cu
= reader
->cu
;
12008 bfd
*abfd
= reader
->abfd
;
12009 struct comp_unit_head
*cu_header
= &cu
->header
;
12010 unsigned int bytes_read
;
12011 struct dwarf_block
*blk
;
12016 case DW_FORM_ref_addr
:
12017 if (cu
->header
.version
== 2)
12018 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12020 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
12021 &cu
->header
, &bytes_read
);
12022 info_ptr
+= bytes_read
;
12025 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12026 info_ptr
+= bytes_read
;
12028 case DW_FORM_block2
:
12029 blk
= dwarf_alloc_block (cu
);
12030 blk
->size
= read_2_bytes (abfd
, info_ptr
);
12032 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12033 info_ptr
+= blk
->size
;
12034 DW_BLOCK (attr
) = blk
;
12036 case DW_FORM_block4
:
12037 blk
= dwarf_alloc_block (cu
);
12038 blk
->size
= read_4_bytes (abfd
, info_ptr
);
12040 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12041 info_ptr
+= blk
->size
;
12042 DW_BLOCK (attr
) = blk
;
12044 case DW_FORM_data2
:
12045 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
12048 case DW_FORM_data4
:
12049 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
12052 case DW_FORM_data8
:
12053 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
12056 case DW_FORM_sec_offset
:
12057 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
12058 info_ptr
+= bytes_read
;
12060 case DW_FORM_string
:
12061 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
12062 DW_STRING_IS_CANONICAL (attr
) = 0;
12063 info_ptr
+= bytes_read
;
12066 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
12068 DW_STRING_IS_CANONICAL (attr
) = 0;
12069 info_ptr
+= bytes_read
;
12071 case DW_FORM_exprloc
:
12072 case DW_FORM_block
:
12073 blk
= dwarf_alloc_block (cu
);
12074 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12075 info_ptr
+= bytes_read
;
12076 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12077 info_ptr
+= blk
->size
;
12078 DW_BLOCK (attr
) = blk
;
12080 case DW_FORM_block1
:
12081 blk
= dwarf_alloc_block (cu
);
12082 blk
->size
= read_1_byte (abfd
, info_ptr
);
12084 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12085 info_ptr
+= blk
->size
;
12086 DW_BLOCK (attr
) = blk
;
12088 case DW_FORM_data1
:
12089 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12093 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12096 case DW_FORM_flag_present
:
12097 DW_UNSND (attr
) = 1;
12099 case DW_FORM_sdata
:
12100 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
12101 info_ptr
+= bytes_read
;
12103 case DW_FORM_udata
:
12104 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12105 info_ptr
+= bytes_read
;
12108 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12109 + read_1_byte (abfd
, info_ptr
));
12113 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12114 + read_2_bytes (abfd
, info_ptr
));
12118 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12119 + read_4_bytes (abfd
, info_ptr
));
12123 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12124 + read_8_bytes (abfd
, info_ptr
));
12127 case DW_FORM_ref_sig8
:
12128 /* Convert the signature to something we can record in DW_UNSND
12130 NOTE: This is NULL if the type wasn't found. */
12131 DW_SIGNATURED_TYPE (attr
) =
12132 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12135 case DW_FORM_ref_udata
:
12136 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12137 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12138 info_ptr
+= bytes_read
;
12140 case DW_FORM_indirect
:
12141 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12142 info_ptr
+= bytes_read
;
12143 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
12145 case DW_FORM_GNU_addr_index
:
12146 if (reader
->dwo_file
== NULL
)
12148 /* For now flag a hard error.
12149 Later we can turn this into a complaint. */
12150 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12151 dwarf_form_name (form
),
12152 bfd_get_filename (abfd
));
12154 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
12155 info_ptr
+= bytes_read
;
12157 case DW_FORM_GNU_str_index
:
12158 if (reader
->dwo_file
== NULL
)
12160 /* For now flag a hard error.
12161 Later we can turn this into a complaint if warranted. */
12162 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
12163 dwarf_form_name (form
),
12164 bfd_get_filename (abfd
));
12167 ULONGEST str_index
=
12168 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12170 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
12171 DW_STRING_IS_CANONICAL (attr
) = 0;
12172 info_ptr
+= bytes_read
;
12176 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
12177 dwarf_form_name (form
),
12178 bfd_get_filename (abfd
));
12181 /* We have seen instances where the compiler tried to emit a byte
12182 size attribute of -1 which ended up being encoded as an unsigned
12183 0xffffffff. Although 0xffffffff is technically a valid size value,
12184 an object of this size seems pretty unlikely so we can relatively
12185 safely treat these cases as if the size attribute was invalid and
12186 treat them as zero by default. */
12187 if (attr
->name
== DW_AT_byte_size
12188 && form
== DW_FORM_data4
12189 && DW_UNSND (attr
) >= 0xffffffff)
12192 (&symfile_complaints
,
12193 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
12194 hex_string (DW_UNSND (attr
)));
12195 DW_UNSND (attr
) = 0;
12201 /* Read an attribute described by an abbreviated attribute. */
12204 read_attribute (const struct die_reader_specs
*reader
,
12205 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
12206 gdb_byte
*info_ptr
)
12208 attr
->name
= abbrev
->name
;
12209 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
12212 /* Read dwarf information from a buffer. */
12214 static unsigned int
12215 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
12217 return bfd_get_8 (abfd
, buf
);
12221 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
12223 return bfd_get_signed_8 (abfd
, buf
);
12226 static unsigned int
12227 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
12229 return bfd_get_16 (abfd
, buf
);
12233 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12235 return bfd_get_signed_16 (abfd
, buf
);
12238 static unsigned int
12239 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
12241 return bfd_get_32 (abfd
, buf
);
12245 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
12247 return bfd_get_signed_32 (abfd
, buf
);
12251 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
12253 return bfd_get_64 (abfd
, buf
);
12257 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
12258 unsigned int *bytes_read
)
12260 struct comp_unit_head
*cu_header
= &cu
->header
;
12261 CORE_ADDR retval
= 0;
12263 if (cu_header
->signed_addr_p
)
12265 switch (cu_header
->addr_size
)
12268 retval
= bfd_get_signed_16 (abfd
, buf
);
12271 retval
= bfd_get_signed_32 (abfd
, buf
);
12274 retval
= bfd_get_signed_64 (abfd
, buf
);
12277 internal_error (__FILE__
, __LINE__
,
12278 _("read_address: bad switch, signed [in module %s]"),
12279 bfd_get_filename (abfd
));
12284 switch (cu_header
->addr_size
)
12287 retval
= bfd_get_16 (abfd
, buf
);
12290 retval
= bfd_get_32 (abfd
, buf
);
12293 retval
= bfd_get_64 (abfd
, buf
);
12296 internal_error (__FILE__
, __LINE__
,
12297 _("read_address: bad switch, "
12298 "unsigned [in module %s]"),
12299 bfd_get_filename (abfd
));
12303 *bytes_read
= cu_header
->addr_size
;
12307 /* Read the initial length from a section. The (draft) DWARF 3
12308 specification allows the initial length to take up either 4 bytes
12309 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
12310 bytes describe the length and all offsets will be 8 bytes in length
12313 An older, non-standard 64-bit format is also handled by this
12314 function. The older format in question stores the initial length
12315 as an 8-byte quantity without an escape value. Lengths greater
12316 than 2^32 aren't very common which means that the initial 4 bytes
12317 is almost always zero. Since a length value of zero doesn't make
12318 sense for the 32-bit format, this initial zero can be considered to
12319 be an escape value which indicates the presence of the older 64-bit
12320 format. As written, the code can't detect (old format) lengths
12321 greater than 4GB. If it becomes necessary to handle lengths
12322 somewhat larger than 4GB, we could allow other small values (such
12323 as the non-sensical values of 1, 2, and 3) to also be used as
12324 escape values indicating the presence of the old format.
12326 The value returned via bytes_read should be used to increment the
12327 relevant pointer after calling read_initial_length().
12329 [ Note: read_initial_length() and read_offset() are based on the
12330 document entitled "DWARF Debugging Information Format", revision
12331 3, draft 8, dated November 19, 2001. This document was obtained
12334 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
12336 This document is only a draft and is subject to change. (So beware.)
12338 Details regarding the older, non-standard 64-bit format were
12339 determined empirically by examining 64-bit ELF files produced by
12340 the SGI toolchain on an IRIX 6.5 machine.
12342 - Kevin, July 16, 2002
12346 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
12348 LONGEST length
= bfd_get_32 (abfd
, buf
);
12350 if (length
== 0xffffffff)
12352 length
= bfd_get_64 (abfd
, buf
+ 4);
12355 else if (length
== 0)
12357 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
12358 length
= bfd_get_64 (abfd
, buf
);
12369 /* Cover function for read_initial_length.
12370 Returns the length of the object at BUF, and stores the size of the
12371 initial length in *BYTES_READ and stores the size that offsets will be in
12373 If the initial length size is not equivalent to that specified in
12374 CU_HEADER then issue a complaint.
12375 This is useful when reading non-comp-unit headers. */
12378 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
12379 const struct comp_unit_head
*cu_header
,
12380 unsigned int *bytes_read
,
12381 unsigned int *offset_size
)
12383 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
12385 gdb_assert (cu_header
->initial_length_size
== 4
12386 || cu_header
->initial_length_size
== 8
12387 || cu_header
->initial_length_size
== 12);
12389 if (cu_header
->initial_length_size
!= *bytes_read
)
12390 complaint (&symfile_complaints
,
12391 _("intermixed 32-bit and 64-bit DWARF sections"));
12393 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
12397 /* Read an offset from the data stream. The size of the offset is
12398 given by cu_header->offset_size. */
12401 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
12402 unsigned int *bytes_read
)
12404 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
12406 *bytes_read
= cu_header
->offset_size
;
12410 /* Read an offset from the data stream. */
12413 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
12415 LONGEST retval
= 0;
12417 switch (offset_size
)
12420 retval
= bfd_get_32 (abfd
, buf
);
12423 retval
= bfd_get_64 (abfd
, buf
);
12426 internal_error (__FILE__
, __LINE__
,
12427 _("read_offset_1: bad switch [in module %s]"),
12428 bfd_get_filename (abfd
));
12435 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
12437 /* If the size of a host char is 8 bits, we can return a pointer
12438 to the buffer, otherwise we have to copy the data to a buffer
12439 allocated on the temporary obstack. */
12440 gdb_assert (HOST_CHAR_BIT
== 8);
12445 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12447 /* If the size of a host char is 8 bits, we can return a pointer
12448 to the string, otherwise we have to copy the string to a buffer
12449 allocated on the temporary obstack. */
12450 gdb_assert (HOST_CHAR_BIT
== 8);
12453 *bytes_read_ptr
= 1;
12456 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
12457 return (char *) buf
;
12461 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
12463 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
12464 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
12465 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
12466 bfd_get_filename (abfd
));
12467 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
12468 error (_("DW_FORM_strp pointing outside of "
12469 ".debug_str section [in module %s]"),
12470 bfd_get_filename (abfd
));
12471 gdb_assert (HOST_CHAR_BIT
== 8);
12472 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
12474 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
12478 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
12479 const struct comp_unit_head
*cu_header
,
12480 unsigned int *bytes_read_ptr
)
12482 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
12484 return read_indirect_string_at_offset (abfd
, str_offset
);
12488 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12491 unsigned int num_read
;
12493 unsigned char byte
;
12501 byte
= bfd_get_8 (abfd
, buf
);
12504 result
|= ((ULONGEST
) (byte
& 127) << shift
);
12505 if ((byte
& 128) == 0)
12511 *bytes_read_ptr
= num_read
;
12516 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
12519 int i
, shift
, num_read
;
12520 unsigned char byte
;
12528 byte
= bfd_get_8 (abfd
, buf
);
12531 result
|= ((LONGEST
) (byte
& 127) << shift
);
12533 if ((byte
& 128) == 0)
12538 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
12539 result
|= -(((LONGEST
) 1) << shift
);
12540 *bytes_read_ptr
= num_read
;
12544 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
12545 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
12546 ADDR_SIZE is the size of addresses from the CU header. */
12549 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
12551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12552 bfd
*abfd
= objfile
->obfd
;
12553 const gdb_byte
*info_ptr
;
12555 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
12556 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
12557 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
12559 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
12560 error (_("DW_FORM_addr_index pointing outside of "
12561 ".debug_addr section [in module %s]"),
12563 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
12564 + addr_base
+ addr_index
* addr_size
);
12565 if (addr_size
== 4)
12566 return bfd_get_32 (abfd
, info_ptr
);
12568 return bfd_get_64 (abfd
, info_ptr
);
12571 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
12574 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
12576 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
12579 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
12582 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
12583 unsigned int *bytes_read
)
12585 bfd
*abfd
= cu
->objfile
->obfd
;
12586 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
12588 return read_addr_index (cu
, addr_index
);
12591 /* Data structure to pass results from dwarf2_read_addr_index_reader
12592 back to dwarf2_read_addr_index. */
12594 struct dwarf2_read_addr_index_data
12596 ULONGEST addr_base
;
12600 /* die_reader_func for dwarf2_read_addr_index. */
12603 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
12604 gdb_byte
*info_ptr
,
12605 struct die_info
*comp_unit_die
,
12609 struct dwarf2_cu
*cu
= reader
->cu
;
12610 struct dwarf2_read_addr_index_data
*aidata
=
12611 (struct dwarf2_read_addr_index_data
*) data
;
12613 aidata
->addr_base
= cu
->addr_base
;
12614 aidata
->addr_size
= cu
->header
.addr_size
;
12617 /* Given an index in .debug_addr, fetch the value.
12618 NOTE: This can be called during dwarf expression evaluation,
12619 long after the debug information has been read, and thus per_cu->cu
12620 may no longer exist. */
12623 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
12624 unsigned int addr_index
)
12626 struct objfile
*objfile
= per_cu
->objfile
;
12627 struct dwarf2_cu
*cu
= per_cu
->cu
;
12628 ULONGEST addr_base
;
12631 /* This is intended to be called from outside this file. */
12632 dw2_setup (objfile
);
12634 /* We need addr_base and addr_size.
12635 If we don't have PER_CU->cu, we have to get it.
12636 Nasty, but the alternative is storing the needed info in PER_CU,
12637 which at this point doesn't seem justified: it's not clear how frequently
12638 it would get used and it would increase the size of every PER_CU.
12639 Entry points like dwarf2_per_cu_addr_size do a similar thing
12640 so we're not in uncharted territory here.
12641 Alas we need to be a bit more complicated as addr_base is contained
12644 We don't need to read the entire CU(/TU).
12645 We just need the header and top level die.
12646 IWBN to use the aging mechanism to let us lazily later discard the CU.
12647 See however init_cutu_and_read_dies_simple. */
12651 addr_base
= cu
->addr_base
;
12652 addr_size
= cu
->header
.addr_size
;
12656 struct dwarf2_read_addr_index_data aidata
;
12658 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
12660 addr_base
= aidata
.addr_base
;
12661 addr_size
= aidata
.addr_size
;
12664 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
12667 /* Given a DW_AT_str_index, fetch the string. */
12670 read_str_index (const struct die_reader_specs
*reader
,
12671 struct dwarf2_cu
*cu
, ULONGEST str_index
)
12673 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12674 const char *dwo_name
= objfile
->name
;
12675 bfd
*abfd
= objfile
->obfd
;
12676 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
12677 gdb_byte
*info_ptr
;
12678 ULONGEST str_offset
;
12680 dwarf2_read_section (objfile
, §ions
->str
);
12681 dwarf2_read_section (objfile
, §ions
->str_offsets
);
12682 if (sections
->str
.buffer
== NULL
)
12683 error (_("DW_FORM_str_index used without .debug_str.dwo section"
12684 " in CU at offset 0x%lx [in module %s]"),
12685 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12686 if (sections
->str_offsets
.buffer
== NULL
)
12687 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
12688 " in CU at offset 0x%lx [in module %s]"),
12689 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12690 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
12691 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
12692 " section in CU at offset 0x%lx [in module %s]"),
12693 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12694 info_ptr
= (sections
->str_offsets
.buffer
12695 + str_index
* cu
->header
.offset_size
);
12696 if (cu
->header
.offset_size
== 4)
12697 str_offset
= bfd_get_32 (abfd
, info_ptr
);
12699 str_offset
= bfd_get_64 (abfd
, info_ptr
);
12700 if (str_offset
>= sections
->str
.size
)
12701 error (_("Offset from DW_FORM_str_index pointing outside of"
12702 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
12703 (long) cu
->header
.offset
.sect_off
, dwo_name
);
12704 return (char *) (sections
->str
.buffer
+ str_offset
);
12707 /* Return the length of an LEB128 number in BUF. */
12710 leb128_size (const gdb_byte
*buf
)
12712 const gdb_byte
*begin
= buf
;
12718 if ((byte
& 128) == 0)
12719 return buf
- begin
;
12724 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
12731 cu
->language
= language_c
;
12733 case DW_LANG_C_plus_plus
:
12734 cu
->language
= language_cplus
;
12737 cu
->language
= language_d
;
12739 case DW_LANG_Fortran77
:
12740 case DW_LANG_Fortran90
:
12741 case DW_LANG_Fortran95
:
12742 cu
->language
= language_fortran
;
12745 cu
->language
= language_go
;
12747 case DW_LANG_Mips_Assembler
:
12748 cu
->language
= language_asm
;
12751 cu
->language
= language_java
;
12753 case DW_LANG_Ada83
:
12754 case DW_LANG_Ada95
:
12755 cu
->language
= language_ada
;
12757 case DW_LANG_Modula2
:
12758 cu
->language
= language_m2
;
12760 case DW_LANG_Pascal83
:
12761 cu
->language
= language_pascal
;
12764 cu
->language
= language_objc
;
12766 case DW_LANG_Cobol74
:
12767 case DW_LANG_Cobol85
:
12769 cu
->language
= language_minimal
;
12772 cu
->language_defn
= language_def (cu
->language
);
12775 /* Return the named attribute or NULL if not there. */
12777 static struct attribute
*
12778 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
12783 struct attribute
*spec
= NULL
;
12785 for (i
= 0; i
< die
->num_attrs
; ++i
)
12787 if (die
->attrs
[i
].name
== name
)
12788 return &die
->attrs
[i
];
12789 if (die
->attrs
[i
].name
== DW_AT_specification
12790 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
12791 spec
= &die
->attrs
[i
];
12797 die
= follow_die_ref (die
, spec
, &cu
);
12803 /* Return the named attribute or NULL if not there,
12804 but do not follow DW_AT_specification, etc.
12805 This is for use in contexts where we're reading .debug_types dies.
12806 Following DW_AT_specification, DW_AT_abstract_origin will take us
12807 back up the chain, and we want to go down. */
12809 static struct attribute
*
12810 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
12811 struct dwarf2_cu
*cu
)
12815 for (i
= 0; i
< die
->num_attrs
; ++i
)
12816 if (die
->attrs
[i
].name
== name
)
12817 return &die
->attrs
[i
];
12822 /* Return non-zero iff the attribute NAME is defined for the given DIE,
12823 and holds a non-zero value. This function should only be used for
12824 DW_FORM_flag or DW_FORM_flag_present attributes. */
12827 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
12829 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
12831 return (attr
&& DW_UNSND (attr
));
12835 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
12837 /* A DIE is a declaration if it has a DW_AT_declaration attribute
12838 which value is non-zero. However, we have to be careful with
12839 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
12840 (via dwarf2_flag_true_p) follows this attribute. So we may
12841 end up accidently finding a declaration attribute that belongs
12842 to a different DIE referenced by the specification attribute,
12843 even though the given DIE does not have a declaration attribute. */
12844 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
12845 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
12848 /* Return the die giving the specification for DIE, if there is
12849 one. *SPEC_CU is the CU containing DIE on input, and the CU
12850 containing the return value on output. If there is no
12851 specification, but there is an abstract origin, that is
12854 static struct die_info
*
12855 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
12857 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
12860 if (spec_attr
== NULL
)
12861 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
12863 if (spec_attr
== NULL
)
12866 return follow_die_ref (die
, spec_attr
, spec_cu
);
12869 /* Free the line_header structure *LH, and any arrays and strings it
12871 NOTE: This is also used as a "cleanup" function. */
12874 free_line_header (struct line_header
*lh
)
12876 if (lh
->standard_opcode_lengths
)
12877 xfree (lh
->standard_opcode_lengths
);
12879 /* Remember that all the lh->file_names[i].name pointers are
12880 pointers into debug_line_buffer, and don't need to be freed. */
12881 if (lh
->file_names
)
12882 xfree (lh
->file_names
);
12884 /* Similarly for the include directory names. */
12885 if (lh
->include_dirs
)
12886 xfree (lh
->include_dirs
);
12891 /* Add an entry to LH's include directory table. */
12894 add_include_dir (struct line_header
*lh
, char *include_dir
)
12896 /* Grow the array if necessary. */
12897 if (lh
->include_dirs_size
== 0)
12899 lh
->include_dirs_size
= 1; /* for testing */
12900 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
12901 * sizeof (*lh
->include_dirs
));
12903 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
12905 lh
->include_dirs_size
*= 2;
12906 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
12907 (lh
->include_dirs_size
12908 * sizeof (*lh
->include_dirs
)));
12911 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
12914 /* Add an entry to LH's file name table. */
12917 add_file_name (struct line_header
*lh
,
12919 unsigned int dir_index
,
12920 unsigned int mod_time
,
12921 unsigned int length
)
12923 struct file_entry
*fe
;
12925 /* Grow the array if necessary. */
12926 if (lh
->file_names_size
== 0)
12928 lh
->file_names_size
= 1; /* for testing */
12929 lh
->file_names
= xmalloc (lh
->file_names_size
12930 * sizeof (*lh
->file_names
));
12932 else if (lh
->num_file_names
>= lh
->file_names_size
)
12934 lh
->file_names_size
*= 2;
12935 lh
->file_names
= xrealloc (lh
->file_names
,
12936 (lh
->file_names_size
12937 * sizeof (*lh
->file_names
)));
12940 fe
= &lh
->file_names
[lh
->num_file_names
++];
12942 fe
->dir_index
= dir_index
;
12943 fe
->mod_time
= mod_time
;
12944 fe
->length
= length
;
12945 fe
->included_p
= 0;
12949 /* Read the statement program header starting at OFFSET in
12950 .debug_line, or .debug_line.dwo. Return a pointer
12951 to a struct line_header, allocated using xmalloc.
12953 NOTE: the strings in the include directory and file name tables of
12954 the returned object point into the dwarf line section buffer,
12955 and must not be freed. */
12957 static struct line_header
*
12958 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
12960 struct cleanup
*back_to
;
12961 struct line_header
*lh
;
12962 gdb_byte
*line_ptr
;
12963 unsigned int bytes_read
, offset_size
;
12965 char *cur_dir
, *cur_file
;
12966 struct dwarf2_section_info
*section
;
12969 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
12971 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12972 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
12974 section
= &dwarf2_per_objfile
->line
;
12976 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
12977 if (section
->buffer
== NULL
)
12979 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
12980 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
12982 complaint (&symfile_complaints
, _("missing .debug_line section"));
12986 /* We can't do this until we know the section is non-empty.
12987 Only then do we know we have such a section. */
12988 abfd
= section
->asection
->owner
;
12990 /* Make sure that at least there's room for the total_length field.
12991 That could be 12 bytes long, but we're just going to fudge that. */
12992 if (offset
+ 4 >= section
->size
)
12994 dwarf2_statement_list_fits_in_line_number_section_complaint ();
12998 lh
= xmalloc (sizeof (*lh
));
12999 memset (lh
, 0, sizeof (*lh
));
13000 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
13003 line_ptr
= section
->buffer
+ offset
;
13005 /* Read in the header. */
13007 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
13008 &bytes_read
, &offset_size
);
13009 line_ptr
+= bytes_read
;
13010 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
13012 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13015 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
13016 lh
->version
= read_2_bytes (abfd
, line_ptr
);
13018 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
13019 line_ptr
+= offset_size
;
13020 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
13022 if (lh
->version
>= 4)
13024 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
13028 lh
->maximum_ops_per_instruction
= 1;
13030 if (lh
->maximum_ops_per_instruction
== 0)
13032 lh
->maximum_ops_per_instruction
= 1;
13033 complaint (&symfile_complaints
,
13034 _("invalid maximum_ops_per_instruction "
13035 "in `.debug_line' section"));
13038 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
13040 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
13042 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
13044 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
13046 lh
->standard_opcode_lengths
13047 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
13049 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
13050 for (i
= 1; i
< lh
->opcode_base
; ++i
)
13052 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
13056 /* Read directory table. */
13057 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13059 line_ptr
+= bytes_read
;
13060 add_include_dir (lh
, cur_dir
);
13062 line_ptr
+= bytes_read
;
13064 /* Read file name table. */
13065 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13067 unsigned int dir_index
, mod_time
, length
;
13069 line_ptr
+= bytes_read
;
13070 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13071 line_ptr
+= bytes_read
;
13072 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13073 line_ptr
+= bytes_read
;
13074 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13075 line_ptr
+= bytes_read
;
13077 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13079 line_ptr
+= bytes_read
;
13080 lh
->statement_program_start
= line_ptr
;
13082 if (line_ptr
> (section
->buffer
+ section
->size
))
13083 complaint (&symfile_complaints
,
13084 _("line number info header doesn't "
13085 "fit in `.debug_line' section"));
13087 discard_cleanups (back_to
);
13091 /* Subroutine of dwarf_decode_lines to simplify it.
13092 Return the file name of the psymtab for included file FILE_INDEX
13093 in line header LH of PST.
13094 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13095 If space for the result is malloc'd, it will be freed by a cleanup.
13096 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
13099 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
13100 const struct partial_symtab
*pst
,
13101 const char *comp_dir
)
13103 const struct file_entry fe
= lh
->file_names
[file_index
];
13104 char *include_name
= fe
.name
;
13105 char *include_name_to_compare
= include_name
;
13106 char *dir_name
= NULL
;
13107 const char *pst_filename
;
13108 char *copied_name
= NULL
;
13112 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13114 if (!IS_ABSOLUTE_PATH (include_name
)
13115 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13117 /* Avoid creating a duplicate psymtab for PST.
13118 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13119 Before we do the comparison, however, we need to account
13120 for DIR_NAME and COMP_DIR.
13121 First prepend dir_name (if non-NULL). If we still don't
13122 have an absolute path prepend comp_dir (if non-NULL).
13123 However, the directory we record in the include-file's
13124 psymtab does not contain COMP_DIR (to match the
13125 corresponding symtab(s)).
13130 bash$ gcc -g ./hello.c
13131 include_name = "hello.c"
13133 DW_AT_comp_dir = comp_dir = "/tmp"
13134 DW_AT_name = "./hello.c" */
13136 if (dir_name
!= NULL
)
13138 include_name
= concat (dir_name
, SLASH_STRING
,
13139 include_name
, (char *)NULL
);
13140 include_name_to_compare
= include_name
;
13141 make_cleanup (xfree
, include_name
);
13143 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
13145 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
13146 include_name
, (char *)NULL
);
13150 pst_filename
= pst
->filename
;
13151 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
13153 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
13154 pst_filename
, (char *)NULL
);
13155 pst_filename
= copied_name
;
13158 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
13160 if (include_name_to_compare
!= include_name
)
13161 xfree (include_name_to_compare
);
13162 if (copied_name
!= NULL
)
13163 xfree (copied_name
);
13167 return include_name
;
13170 /* Ignore this record_line request. */
13173 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13178 /* Subroutine of dwarf_decode_lines to simplify it.
13179 Process the line number information in LH. */
13182 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
13183 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
13185 gdb_byte
*line_ptr
, *extended_end
;
13186 gdb_byte
*line_end
;
13187 unsigned int bytes_read
, extended_len
;
13188 unsigned char op_code
, extended_op
, adj_opcode
;
13189 CORE_ADDR baseaddr
;
13190 struct objfile
*objfile
= cu
->objfile
;
13191 bfd
*abfd
= objfile
->obfd
;
13192 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13193 const int decode_for_pst_p
= (pst
!= NULL
);
13194 struct subfile
*last_subfile
= NULL
;
13195 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
13198 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13200 line_ptr
= lh
->statement_program_start
;
13201 line_end
= lh
->statement_program_end
;
13203 /* Read the statement sequences until there's nothing left. */
13204 while (line_ptr
< line_end
)
13206 /* state machine registers */
13207 CORE_ADDR address
= 0;
13208 unsigned int file
= 1;
13209 unsigned int line
= 1;
13210 unsigned int column
= 0;
13211 int is_stmt
= lh
->default_is_stmt
;
13212 int basic_block
= 0;
13213 int end_sequence
= 0;
13215 unsigned char op_index
= 0;
13217 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
13219 /* Start a subfile for the current file of the state machine. */
13220 /* lh->include_dirs and lh->file_names are 0-based, but the
13221 directory and file name numbers in the statement program
13223 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13227 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13229 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13232 /* Decode the table. */
13233 while (!end_sequence
)
13235 op_code
= read_1_byte (abfd
, line_ptr
);
13237 if (line_ptr
> line_end
)
13239 dwarf2_debug_line_missing_end_sequence_complaint ();
13243 if (op_code
>= lh
->opcode_base
)
13245 /* Special operand. */
13246 adj_opcode
= op_code
- lh
->opcode_base
;
13247 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
13248 / lh
->maximum_ops_per_instruction
)
13249 * lh
->minimum_instruction_length
);
13250 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
13251 % lh
->maximum_ops_per_instruction
);
13252 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
13253 if (lh
->num_file_names
< file
|| file
== 0)
13254 dwarf2_debug_line_missing_file_complaint ();
13255 /* For now we ignore lines not starting on an
13256 instruction boundary. */
13257 else if (op_index
== 0)
13259 lh
->file_names
[file
- 1].included_p
= 1;
13260 if (!decode_for_pst_p
&& is_stmt
)
13262 if (last_subfile
!= current_subfile
)
13264 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13266 (*p_record_line
) (last_subfile
, 0, addr
);
13267 last_subfile
= current_subfile
;
13269 /* Append row to matrix using current values. */
13270 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13271 (*p_record_line
) (current_subfile
, line
, addr
);
13276 else switch (op_code
)
13278 case DW_LNS_extended_op
:
13279 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
13281 line_ptr
+= bytes_read
;
13282 extended_end
= line_ptr
+ extended_len
;
13283 extended_op
= read_1_byte (abfd
, line_ptr
);
13285 switch (extended_op
)
13287 case DW_LNE_end_sequence
:
13288 p_record_line
= record_line
;
13291 case DW_LNE_set_address
:
13292 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
13294 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13296 /* This line table is for a function which has been
13297 GCd by the linker. Ignore it. PR gdb/12528 */
13300 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
13302 complaint (&symfile_complaints
,
13303 _(".debug_line address at offset 0x%lx is 0 "
13305 line_offset
, objfile
->name
);
13306 p_record_line
= noop_record_line
;
13310 line_ptr
+= bytes_read
;
13311 address
+= baseaddr
;
13313 case DW_LNE_define_file
:
13316 unsigned int dir_index
, mod_time
, length
;
13318 cur_file
= read_direct_string (abfd
, line_ptr
,
13320 line_ptr
+= bytes_read
;
13322 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13323 line_ptr
+= bytes_read
;
13325 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13326 line_ptr
+= bytes_read
;
13328 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13329 line_ptr
+= bytes_read
;
13330 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13333 case DW_LNE_set_discriminator
:
13334 /* The discriminator is not interesting to the debugger;
13336 line_ptr
= extended_end
;
13339 complaint (&symfile_complaints
,
13340 _("mangled .debug_line section"));
13343 /* Make sure that we parsed the extended op correctly. If e.g.
13344 we expected a different address size than the producer used,
13345 we may have read the wrong number of bytes. */
13346 if (line_ptr
!= extended_end
)
13348 complaint (&symfile_complaints
,
13349 _("mangled .debug_line section"));
13354 if (lh
->num_file_names
< file
|| file
== 0)
13355 dwarf2_debug_line_missing_file_complaint ();
13358 lh
->file_names
[file
- 1].included_p
= 1;
13359 if (!decode_for_pst_p
&& is_stmt
)
13361 if (last_subfile
!= current_subfile
)
13363 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13365 (*p_record_line
) (last_subfile
, 0, addr
);
13366 last_subfile
= current_subfile
;
13368 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13369 (*p_record_line
) (current_subfile
, line
, addr
);
13374 case DW_LNS_advance_pc
:
13377 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13379 address
+= (((op_index
+ adjust
)
13380 / lh
->maximum_ops_per_instruction
)
13381 * lh
->minimum_instruction_length
);
13382 op_index
= ((op_index
+ adjust
)
13383 % lh
->maximum_ops_per_instruction
);
13384 line_ptr
+= bytes_read
;
13387 case DW_LNS_advance_line
:
13388 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
13389 line_ptr
+= bytes_read
;
13391 case DW_LNS_set_file
:
13393 /* The arrays lh->include_dirs and lh->file_names are
13394 0-based, but the directory and file name numbers in
13395 the statement program are 1-based. */
13396 struct file_entry
*fe
;
13399 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13400 line_ptr
+= bytes_read
;
13401 if (lh
->num_file_names
< file
|| file
== 0)
13402 dwarf2_debug_line_missing_file_complaint ();
13405 fe
= &lh
->file_names
[file
- 1];
13407 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13408 if (!decode_for_pst_p
)
13410 last_subfile
= current_subfile
;
13411 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13416 case DW_LNS_set_column
:
13417 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13418 line_ptr
+= bytes_read
;
13420 case DW_LNS_negate_stmt
:
13421 is_stmt
= (!is_stmt
);
13423 case DW_LNS_set_basic_block
:
13426 /* Add to the address register of the state machine the
13427 address increment value corresponding to special opcode
13428 255. I.e., this value is scaled by the minimum
13429 instruction length since special opcode 255 would have
13430 scaled the increment. */
13431 case DW_LNS_const_add_pc
:
13433 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
13435 address
+= (((op_index
+ adjust
)
13436 / lh
->maximum_ops_per_instruction
)
13437 * lh
->minimum_instruction_length
);
13438 op_index
= ((op_index
+ adjust
)
13439 % lh
->maximum_ops_per_instruction
);
13442 case DW_LNS_fixed_advance_pc
:
13443 address
+= read_2_bytes (abfd
, line_ptr
);
13449 /* Unknown standard opcode, ignore it. */
13452 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
13454 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13455 line_ptr
+= bytes_read
;
13460 if (lh
->num_file_names
< file
|| file
== 0)
13461 dwarf2_debug_line_missing_file_complaint ();
13464 lh
->file_names
[file
- 1].included_p
= 1;
13465 if (!decode_for_pst_p
)
13467 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
13468 (*p_record_line
) (current_subfile
, 0, addr
);
13474 /* Decode the Line Number Program (LNP) for the given line_header
13475 structure and CU. The actual information extracted and the type
13476 of structures created from the LNP depends on the value of PST.
13478 1. If PST is NULL, then this procedure uses the data from the program
13479 to create all necessary symbol tables, and their linetables.
13481 2. If PST is not NULL, this procedure reads the program to determine
13482 the list of files included by the unit represented by PST, and
13483 builds all the associated partial symbol tables.
13485 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13486 It is used for relative paths in the line table.
13487 NOTE: When processing partial symtabs (pst != NULL),
13488 comp_dir == pst->dirname.
13490 NOTE: It is important that psymtabs have the same file name (via strcmp)
13491 as the corresponding symtab. Since COMP_DIR is not used in the name of the
13492 symtab we don't use it in the name of the psymtabs we create.
13493 E.g. expand_line_sal requires this when finding psymtabs to expand.
13494 A good testcase for this is mb-inline.exp. */
13497 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
13498 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
13499 int want_line_info
)
13501 struct objfile
*objfile
= cu
->objfile
;
13502 const int decode_for_pst_p
= (pst
!= NULL
);
13503 struct subfile
*first_subfile
= current_subfile
;
13505 if (want_line_info
)
13506 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
13508 if (decode_for_pst_p
)
13512 /* Now that we're done scanning the Line Header Program, we can
13513 create the psymtab of each included file. */
13514 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
13515 if (lh
->file_names
[file_index
].included_p
== 1)
13517 char *include_name
=
13518 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
13519 if (include_name
!= NULL
)
13520 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
13525 /* Make sure a symtab is created for every file, even files
13526 which contain only variables (i.e. no code with associated
13530 for (i
= 0; i
< lh
->num_file_names
; i
++)
13533 struct file_entry
*fe
;
13535 fe
= &lh
->file_names
[i
];
13537 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13538 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
13540 /* Skip the main file; we don't need it, and it must be
13541 allocated last, so that it will show up before the
13542 non-primary symtabs in the objfile's symtab list. */
13543 if (current_subfile
== first_subfile
)
13546 if (current_subfile
->symtab
== NULL
)
13547 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
13549 fe
->symtab
= current_subfile
->symtab
;
13554 /* Start a subfile for DWARF. FILENAME is the name of the file and
13555 DIRNAME the name of the source directory which contains FILENAME
13556 or NULL if not known. COMP_DIR is the compilation directory for the
13557 linetable's compilation unit or NULL if not known.
13558 This routine tries to keep line numbers from identical absolute and
13559 relative file names in a common subfile.
13561 Using the `list' example from the GDB testsuite, which resides in
13562 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
13563 of /srcdir/list0.c yields the following debugging information for list0.c:
13565 DW_AT_name: /srcdir/list0.c
13566 DW_AT_comp_dir: /compdir
13567 files.files[0].name: list0.h
13568 files.files[0].dir: /srcdir
13569 files.files[1].name: list0.c
13570 files.files[1].dir: /srcdir
13572 The line number information for list0.c has to end up in a single
13573 subfile, so that `break /srcdir/list0.c:1' works as expected.
13574 start_subfile will ensure that this happens provided that we pass the
13575 concatenation of files.files[1].dir and files.files[1].name as the
13579 dwarf2_start_subfile (char *filename
, const char *dirname
,
13580 const char *comp_dir
)
13584 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
13585 `start_symtab' will always pass the contents of DW_AT_comp_dir as
13586 second argument to start_subfile. To be consistent, we do the
13587 same here. In order not to lose the line information directory,
13588 we concatenate it to the filename when it makes sense.
13589 Note that the Dwarf3 standard says (speaking of filenames in line
13590 information): ``The directory index is ignored for file names
13591 that represent full path names''. Thus ignoring dirname in the
13592 `else' branch below isn't an issue. */
13594 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
13595 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
13597 fullname
= filename
;
13599 start_subfile (fullname
, comp_dir
);
13601 if (fullname
!= filename
)
13606 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
13607 struct dwarf2_cu
*cu
)
13609 struct objfile
*objfile
= cu
->objfile
;
13610 struct comp_unit_head
*cu_header
= &cu
->header
;
13612 /* NOTE drow/2003-01-30: There used to be a comment and some special
13613 code here to turn a symbol with DW_AT_external and a
13614 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
13615 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
13616 with some versions of binutils) where shared libraries could have
13617 relocations against symbols in their debug information - the
13618 minimal symbol would have the right address, but the debug info
13619 would not. It's no longer necessary, because we will explicitly
13620 apply relocations when we read in the debug information now. */
13622 /* A DW_AT_location attribute with no contents indicates that a
13623 variable has been optimized away. */
13624 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
13626 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13630 /* Handle one degenerate form of location expression specially, to
13631 preserve GDB's previous behavior when section offsets are
13632 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
13633 then mark this symbol as LOC_STATIC. */
13635 if (attr_form_is_block (attr
)
13636 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
13637 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
13638 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
13639 && (DW_BLOCK (attr
)->size
13640 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
13642 unsigned int dummy
;
13644 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
13645 SYMBOL_VALUE_ADDRESS (sym
) =
13646 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
13648 SYMBOL_VALUE_ADDRESS (sym
) =
13649 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
13650 SYMBOL_CLASS (sym
) = LOC_STATIC
;
13651 fixup_symbol_section (sym
, objfile
);
13652 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
13653 SYMBOL_SECTION (sym
));
13657 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
13658 expression evaluator, and use LOC_COMPUTED only when necessary
13659 (i.e. when the value of a register or memory location is
13660 referenced, or a thread-local block, etc.). Then again, it might
13661 not be worthwhile. I'm assuming that it isn't unless performance
13662 or memory numbers show me otherwise. */
13664 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
13665 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
13667 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
13668 cu
->has_loclist
= 1;
13671 /* Given a pointer to a DWARF information entry, figure out if we need
13672 to make a symbol table entry for it, and if so, create a new entry
13673 and return a pointer to it.
13674 If TYPE is NULL, determine symbol type from the die, otherwise
13675 used the passed type.
13676 If SPACE is not NULL, use it to hold the new symbol. If it is
13677 NULL, allocate a new symbol on the objfile's obstack. */
13679 static struct symbol
*
13680 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
13681 struct symbol
*space
)
13683 struct objfile
*objfile
= cu
->objfile
;
13684 struct symbol
*sym
= NULL
;
13686 struct attribute
*attr
= NULL
;
13687 struct attribute
*attr2
= NULL
;
13688 CORE_ADDR baseaddr
;
13689 struct pending
**list_to_add
= NULL
;
13691 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13693 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13695 name
= dwarf2_name (die
, cu
);
13698 const char *linkagename
;
13699 int suppress_add
= 0;
13704 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
13705 OBJSTAT (objfile
, n_syms
++);
13707 /* Cache this symbol's name and the name's demangled form (if any). */
13708 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
13709 linkagename
= dwarf2_physname (name
, die
, cu
);
13710 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
13712 /* Fortran does not have mangling standard and the mangling does differ
13713 between gfortran, iFort etc. */
13714 if (cu
->language
== language_fortran
13715 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
13716 symbol_set_demangled_name (&(sym
->ginfo
),
13717 (char *) dwarf2_full_name (name
, die
, cu
),
13720 /* Default assumptions.
13721 Use the passed type or decode it from the die. */
13722 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13723 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
13725 SYMBOL_TYPE (sym
) = type
;
13727 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
13728 attr
= dwarf2_attr (die
,
13729 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
13733 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
13736 attr
= dwarf2_attr (die
,
13737 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
13741 int file_index
= DW_UNSND (attr
);
13743 if (cu
->line_header
== NULL
13744 || file_index
> cu
->line_header
->num_file_names
)
13745 complaint (&symfile_complaints
,
13746 _("file index out of range"));
13747 else if (file_index
> 0)
13749 struct file_entry
*fe
;
13751 fe
= &cu
->line_header
->file_names
[file_index
- 1];
13752 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
13759 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13762 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
13764 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
13765 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
13766 SYMBOL_CLASS (sym
) = LOC_LABEL
;
13767 add_symbol_to_list (sym
, cu
->list_in_scope
);
13769 case DW_TAG_subprogram
:
13770 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13772 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13773 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13774 if ((attr2
&& (DW_UNSND (attr2
) != 0))
13775 || cu
->language
== language_ada
)
13777 /* Subprograms marked external are stored as a global symbol.
13778 Ada subprograms, whether marked external or not, are always
13779 stored as a global symbol, because we want to be able to
13780 access them globally. For instance, we want to be able
13781 to break on a nested subprogram without having to
13782 specify the context. */
13783 list_to_add
= &global_symbols
;
13787 list_to_add
= cu
->list_in_scope
;
13790 case DW_TAG_inlined_subroutine
:
13791 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
13793 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
13794 SYMBOL_INLINED (sym
) = 1;
13795 list_to_add
= cu
->list_in_scope
;
13797 case DW_TAG_template_value_param
:
13799 /* Fall through. */
13800 case DW_TAG_constant
:
13801 case DW_TAG_variable
:
13802 case DW_TAG_member
:
13803 /* Compilation with minimal debug info may result in
13804 variables with missing type entries. Change the
13805 misleading `void' type to something sensible. */
13806 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
13808 = objfile_type (objfile
)->nodebug_data_symbol
;
13810 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13811 /* In the case of DW_TAG_member, we should only be called for
13812 static const members. */
13813 if (die
->tag
== DW_TAG_member
)
13815 /* dwarf2_add_field uses die_is_declaration,
13816 so we do the same. */
13817 gdb_assert (die_is_declaration (die
, cu
));
13822 dwarf2_const_value (attr
, sym
, cu
);
13823 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13826 if (attr2
&& (DW_UNSND (attr2
) != 0))
13827 list_to_add
= &global_symbols
;
13829 list_to_add
= cu
->list_in_scope
;
13833 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13836 var_decode_location (attr
, sym
, cu
);
13837 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13838 if (SYMBOL_CLASS (sym
) == LOC_STATIC
13839 && SYMBOL_VALUE_ADDRESS (sym
) == 0
13840 && !dwarf2_per_objfile
->has_section_at_zero
)
13842 /* When a static variable is eliminated by the linker,
13843 the corresponding debug information is not stripped
13844 out, but the variable address is set to null;
13845 do not add such variables into symbol table. */
13847 else if (attr2
&& (DW_UNSND (attr2
) != 0))
13849 /* Workaround gfortran PR debug/40040 - it uses
13850 DW_AT_location for variables in -fPIC libraries which may
13851 get overriden by other libraries/executable and get
13852 a different address. Resolve it by the minimal symbol
13853 which may come from inferior's executable using copy
13854 relocation. Make this workaround only for gfortran as for
13855 other compilers GDB cannot guess the minimal symbol
13856 Fortran mangling kind. */
13857 if (cu
->language
== language_fortran
&& die
->parent
13858 && die
->parent
->tag
== DW_TAG_module
13860 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
13861 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13863 /* A variable with DW_AT_external is never static,
13864 but it may be block-scoped. */
13865 list_to_add
= (cu
->list_in_scope
== &file_symbols
13866 ? &global_symbols
: cu
->list_in_scope
);
13869 list_to_add
= cu
->list_in_scope
;
13873 /* We do not know the address of this symbol.
13874 If it is an external symbol and we have type information
13875 for it, enter the symbol as a LOC_UNRESOLVED symbol.
13876 The address of the variable will then be determined from
13877 the minimal symbol table whenever the variable is
13879 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
13880 if (attr2
&& (DW_UNSND (attr2
) != 0)
13881 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
13883 /* A variable with DW_AT_external is never static, but it
13884 may be block-scoped. */
13885 list_to_add
= (cu
->list_in_scope
== &file_symbols
13886 ? &global_symbols
: cu
->list_in_scope
);
13888 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
13890 else if (!die_is_declaration (die
, cu
))
13892 /* Use the default LOC_OPTIMIZED_OUT class. */
13893 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
13895 list_to_add
= cu
->list_in_scope
;
13899 case DW_TAG_formal_parameter
:
13900 /* If we are inside a function, mark this as an argument. If
13901 not, we might be looking at an argument to an inlined function
13902 when we do not have enough information to show inlined frames;
13903 pretend it's a local variable in that case so that the user can
13905 if (context_stack_depth
> 0
13906 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
13907 SYMBOL_IS_ARGUMENT (sym
) = 1;
13908 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13911 var_decode_location (attr
, sym
, cu
);
13913 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13916 dwarf2_const_value (attr
, sym
, cu
);
13919 list_to_add
= cu
->list_in_scope
;
13921 case DW_TAG_unspecified_parameters
:
13922 /* From varargs functions; gdb doesn't seem to have any
13923 interest in this information, so just ignore it for now.
13926 case DW_TAG_template_type_param
:
13928 /* Fall through. */
13929 case DW_TAG_class_type
:
13930 case DW_TAG_interface_type
:
13931 case DW_TAG_structure_type
:
13932 case DW_TAG_union_type
:
13933 case DW_TAG_set_type
:
13934 case DW_TAG_enumeration_type
:
13935 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13936 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
13939 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
13940 really ever be static objects: otherwise, if you try
13941 to, say, break of a class's method and you're in a file
13942 which doesn't mention that class, it won't work unless
13943 the check for all static symbols in lookup_symbol_aux
13944 saves you. See the OtherFileClass tests in
13945 gdb.c++/namespace.exp. */
13949 list_to_add
= (cu
->list_in_scope
== &file_symbols
13950 && (cu
->language
== language_cplus
13951 || cu
->language
== language_java
)
13952 ? &global_symbols
: cu
->list_in_scope
);
13954 /* The semantics of C++ state that "struct foo {
13955 ... }" also defines a typedef for "foo". A Java
13956 class declaration also defines a typedef for the
13958 if (cu
->language
== language_cplus
13959 || cu
->language
== language_java
13960 || cu
->language
== language_ada
)
13962 /* The symbol's name is already allocated along
13963 with this objfile, so we don't need to
13964 duplicate it for the type. */
13965 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
13966 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
13971 case DW_TAG_typedef
:
13972 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13973 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13974 list_to_add
= cu
->list_in_scope
;
13976 case DW_TAG_base_type
:
13977 case DW_TAG_subrange_type
:
13978 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
13979 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
13980 list_to_add
= cu
->list_in_scope
;
13982 case DW_TAG_enumerator
:
13983 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
13986 dwarf2_const_value (attr
, sym
, cu
);
13989 /* NOTE: carlton/2003-11-10: See comment above in the
13990 DW_TAG_class_type, etc. block. */
13992 list_to_add
= (cu
->list_in_scope
== &file_symbols
13993 && (cu
->language
== language_cplus
13994 || cu
->language
== language_java
)
13995 ? &global_symbols
: cu
->list_in_scope
);
13998 case DW_TAG_namespace
:
13999 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14000 list_to_add
= &global_symbols
;
14003 /* Not a tag we recognize. Hopefully we aren't processing
14004 trash data, but since we must specifically ignore things
14005 we don't recognize, there is nothing else we should do at
14007 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
14008 dwarf_tag_name (die
->tag
));
14014 sym
->hash_next
= objfile
->template_symbols
;
14015 objfile
->template_symbols
= sym
;
14016 list_to_add
= NULL
;
14019 if (list_to_add
!= NULL
)
14020 add_symbol_to_list (sym
, list_to_add
);
14022 /* For the benefit of old versions of GCC, check for anonymous
14023 namespaces based on the demangled name. */
14024 if (!processing_has_namespace_info
14025 && cu
->language
== language_cplus
)
14026 cp_scan_for_anonymous_namespaces (sym
, objfile
);
14031 /* A wrapper for new_symbol_full that always allocates a new symbol. */
14033 static struct symbol
*
14034 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14036 return new_symbol_full (die
, type
, cu
, NULL
);
14039 /* Given an attr with a DW_FORM_dataN value in host byte order,
14040 zero-extend it as appropriate for the symbol's type. The DWARF
14041 standard (v4) is not entirely clear about the meaning of using
14042 DW_FORM_dataN for a constant with a signed type, where the type is
14043 wider than the data. The conclusion of a discussion on the DWARF
14044 list was that this is unspecified. We choose to always zero-extend
14045 because that is the interpretation long in use by GCC. */
14048 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
14049 const char *name
, struct obstack
*obstack
,
14050 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
14052 struct objfile
*objfile
= cu
->objfile
;
14053 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
14054 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
14055 LONGEST l
= DW_UNSND (attr
);
14057 if (bits
< sizeof (*value
) * 8)
14059 l
&= ((LONGEST
) 1 << bits
) - 1;
14062 else if (bits
== sizeof (*value
) * 8)
14066 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
14067 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
14074 /* Read a constant value from an attribute. Either set *VALUE, or if
14075 the value does not fit in *VALUE, set *BYTES - either already
14076 allocated on the objfile obstack, or newly allocated on OBSTACK,
14077 or, set *BATON, if we translated the constant to a location
14081 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
14082 const char *name
, struct obstack
*obstack
,
14083 struct dwarf2_cu
*cu
,
14084 LONGEST
*value
, gdb_byte
**bytes
,
14085 struct dwarf2_locexpr_baton
**baton
)
14087 struct objfile
*objfile
= cu
->objfile
;
14088 struct comp_unit_head
*cu_header
= &cu
->header
;
14089 struct dwarf_block
*blk
;
14090 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
14091 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
14097 switch (attr
->form
)
14100 case DW_FORM_GNU_addr_index
:
14104 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14105 dwarf2_const_value_length_mismatch_complaint (name
,
14106 cu_header
->addr_size
,
14107 TYPE_LENGTH (type
));
14108 /* Symbols of this form are reasonably rare, so we just
14109 piggyback on the existing location code rather than writing
14110 a new implementation of symbol_computed_ops. */
14111 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14112 sizeof (struct dwarf2_locexpr_baton
));
14113 (*baton
)->per_cu
= cu
->per_cu
;
14114 gdb_assert ((*baton
)->per_cu
);
14116 (*baton
)->size
= 2 + cu_header
->addr_size
;
14117 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14118 (*baton
)->data
= data
;
14120 data
[0] = DW_OP_addr
;
14121 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14122 byte_order
, DW_ADDR (attr
));
14123 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14126 case DW_FORM_string
:
14128 case DW_FORM_GNU_str_index
:
14129 /* DW_STRING is already allocated on the objfile obstack, point
14131 *bytes
= (gdb_byte
*) DW_STRING (attr
);
14133 case DW_FORM_block1
:
14134 case DW_FORM_block2
:
14135 case DW_FORM_block4
:
14136 case DW_FORM_block
:
14137 case DW_FORM_exprloc
:
14138 blk
= DW_BLOCK (attr
);
14139 if (TYPE_LENGTH (type
) != blk
->size
)
14140 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
14141 TYPE_LENGTH (type
));
14142 *bytes
= blk
->data
;
14145 /* The DW_AT_const_value attributes are supposed to carry the
14146 symbol's value "represented as it would be on the target
14147 architecture." By the time we get here, it's already been
14148 converted to host endianness, so we just need to sign- or
14149 zero-extend it as appropriate. */
14150 case DW_FORM_data1
:
14151 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14152 obstack
, cu
, value
, 8);
14154 case DW_FORM_data2
:
14155 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14156 obstack
, cu
, value
, 16);
14158 case DW_FORM_data4
:
14159 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14160 obstack
, cu
, value
, 32);
14162 case DW_FORM_data8
:
14163 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
14164 obstack
, cu
, value
, 64);
14167 case DW_FORM_sdata
:
14168 *value
= DW_SND (attr
);
14171 case DW_FORM_udata
:
14172 *value
= DW_UNSND (attr
);
14176 complaint (&symfile_complaints
,
14177 _("unsupported const value attribute form: '%s'"),
14178 dwarf_form_name (attr
->form
));
14185 /* Copy constant value from an attribute to a symbol. */
14188 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
14189 struct dwarf2_cu
*cu
)
14191 struct objfile
*objfile
= cu
->objfile
;
14192 struct comp_unit_head
*cu_header
= &cu
->header
;
14195 struct dwarf2_locexpr_baton
*baton
;
14197 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
14198 SYMBOL_PRINT_NAME (sym
),
14199 &objfile
->objfile_obstack
, cu
,
14200 &value
, &bytes
, &baton
);
14204 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14205 SYMBOL_LOCATION_BATON (sym
) = baton
;
14206 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14208 else if (bytes
!= NULL
)
14210 SYMBOL_VALUE_BYTES (sym
) = bytes
;
14211 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
14215 SYMBOL_VALUE (sym
) = value
;
14216 SYMBOL_CLASS (sym
) = LOC_CONST
;
14220 /* Return the type of the die in question using its DW_AT_type attribute. */
14222 static struct type
*
14223 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14225 struct attribute
*type_attr
;
14227 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14230 /* A missing DW_AT_type represents a void type. */
14231 return objfile_type (cu
->objfile
)->builtin_void
;
14234 return lookup_die_type (die
, type_attr
, cu
);
14237 /* True iff CU's producer generates GNAT Ada auxiliary information
14238 that allows to find parallel types through that information instead
14239 of having to do expensive parallel lookups by type name. */
14242 need_gnat_info (struct dwarf2_cu
*cu
)
14244 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
14245 of GNAT produces this auxiliary information, without any indication
14246 that it is produced. Part of enhancing the FSF version of GNAT
14247 to produce that information will be to put in place an indicator
14248 that we can use in order to determine whether the descriptive type
14249 info is available or not. One suggestion that has been made is
14250 to use a new attribute, attached to the CU die. For now, assume
14251 that the descriptive type info is not available. */
14255 /* Return the auxiliary type of the die in question using its
14256 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
14257 attribute is not present. */
14259 static struct type
*
14260 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14262 struct attribute
*type_attr
;
14264 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
14268 return lookup_die_type (die
, type_attr
, cu
);
14271 /* If DIE has a descriptive_type attribute, then set the TYPE's
14272 descriptive type accordingly. */
14275 set_descriptive_type (struct type
*type
, struct die_info
*die
,
14276 struct dwarf2_cu
*cu
)
14278 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
14280 if (descriptive_type
)
14282 ALLOCATE_GNAT_AUX_TYPE (type
);
14283 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
14287 /* Return the containing type of the die in question using its
14288 DW_AT_containing_type attribute. */
14290 static struct type
*
14291 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14293 struct attribute
*type_attr
;
14295 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
14297 error (_("Dwarf Error: Problem turning containing type into gdb type "
14298 "[in module %s]"), cu
->objfile
->name
);
14300 return lookup_die_type (die
, type_attr
, cu
);
14303 /* Look up the type of DIE in CU using its type attribute ATTR.
14304 If there is no type substitute an error marker. */
14306 static struct type
*
14307 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
14308 struct dwarf2_cu
*cu
)
14310 struct objfile
*objfile
= cu
->objfile
;
14311 struct type
*this_type
;
14313 /* First see if we have it cached. */
14315 if (is_ref_attr (attr
))
14317 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
14319 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
14321 else if (attr
->form
== DW_FORM_ref_sig8
)
14323 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
14325 /* sig_type will be NULL if the signatured type is missing from
14327 if (sig_type
== NULL
)
14328 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
14329 "at 0x%x [in module %s]"),
14330 die
->offset
.sect_off
, objfile
->name
);
14332 gdb_assert (sig_type
->per_cu
.is_debug_types
);
14333 /* If we haven't filled in type_offset_in_section yet, then we
14334 haven't read the type in yet. */
14336 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
14339 get_die_type_at_offset (sig_type
->type_offset_in_section
,
14340 &sig_type
->per_cu
);
14345 dump_die_for_error (die
);
14346 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
14347 dwarf_attr_name (attr
->name
), objfile
->name
);
14350 /* If not cached we need to read it in. */
14352 if (this_type
== NULL
)
14354 struct die_info
*type_die
;
14355 struct dwarf2_cu
*type_cu
= cu
;
14357 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
14358 /* If we found the type now, it's probably because the type came
14359 from an inter-CU reference and the type's CU got expanded before
14361 this_type
= get_die_type (type_die
, type_cu
);
14362 if (this_type
== NULL
)
14363 this_type
= read_type_die_1 (type_die
, type_cu
);
14366 /* If we still don't have a type use an error marker. */
14368 if (this_type
== NULL
)
14370 char *message
, *saved
;
14372 /* read_type_die already issued a complaint. */
14373 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
14375 cu
->header
.offset
.sect_off
,
14376 die
->offset
.sect_off
);
14377 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
14378 message
, strlen (message
));
14381 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
14387 /* Return the type in DIE, CU.
14388 Returns NULL for invalid types.
14390 This first does a lookup in the appropriate type_hash table,
14391 and only reads the die in if necessary.
14393 NOTE: This can be called when reading in partial or full symbols. */
14395 static struct type
*
14396 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
14398 struct type
*this_type
;
14400 this_type
= get_die_type (die
, cu
);
14404 return read_type_die_1 (die
, cu
);
14407 /* Read the type in DIE, CU.
14408 Returns NULL for invalid types. */
14410 static struct type
*
14411 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
14413 struct type
*this_type
= NULL
;
14417 case DW_TAG_class_type
:
14418 case DW_TAG_interface_type
:
14419 case DW_TAG_structure_type
:
14420 case DW_TAG_union_type
:
14421 this_type
= read_structure_type (die
, cu
);
14423 case DW_TAG_enumeration_type
:
14424 this_type
= read_enumeration_type (die
, cu
);
14426 case DW_TAG_subprogram
:
14427 case DW_TAG_subroutine_type
:
14428 case DW_TAG_inlined_subroutine
:
14429 this_type
= read_subroutine_type (die
, cu
);
14431 case DW_TAG_array_type
:
14432 this_type
= read_array_type (die
, cu
);
14434 case DW_TAG_set_type
:
14435 this_type
= read_set_type (die
, cu
);
14437 case DW_TAG_pointer_type
:
14438 this_type
= read_tag_pointer_type (die
, cu
);
14440 case DW_TAG_ptr_to_member_type
:
14441 this_type
= read_tag_ptr_to_member_type (die
, cu
);
14443 case DW_TAG_reference_type
:
14444 this_type
= read_tag_reference_type (die
, cu
);
14446 case DW_TAG_const_type
:
14447 this_type
= read_tag_const_type (die
, cu
);
14449 case DW_TAG_volatile_type
:
14450 this_type
= read_tag_volatile_type (die
, cu
);
14452 case DW_TAG_string_type
:
14453 this_type
= read_tag_string_type (die
, cu
);
14455 case DW_TAG_typedef
:
14456 this_type
= read_typedef (die
, cu
);
14458 case DW_TAG_subrange_type
:
14459 this_type
= read_subrange_type (die
, cu
);
14461 case DW_TAG_base_type
:
14462 this_type
= read_base_type (die
, cu
);
14464 case DW_TAG_unspecified_type
:
14465 this_type
= read_unspecified_type (die
, cu
);
14467 case DW_TAG_namespace
:
14468 this_type
= read_namespace_type (die
, cu
);
14470 case DW_TAG_module
:
14471 this_type
= read_module_type (die
, cu
);
14474 complaint (&symfile_complaints
,
14475 _("unexpected tag in read_type_die: '%s'"),
14476 dwarf_tag_name (die
->tag
));
14483 /* See if we can figure out if the class lives in a namespace. We do
14484 this by looking for a member function; its demangled name will
14485 contain namespace info, if there is any.
14486 Return the computed name or NULL.
14487 Space for the result is allocated on the objfile's obstack.
14488 This is the full-die version of guess_partial_die_structure_name.
14489 In this case we know DIE has no useful parent. */
14492 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14494 struct die_info
*spec_die
;
14495 struct dwarf2_cu
*spec_cu
;
14496 struct die_info
*child
;
14499 spec_die
= die_specification (die
, &spec_cu
);
14500 if (spec_die
!= NULL
)
14506 for (child
= die
->child
;
14508 child
= child
->sibling
)
14510 if (child
->tag
== DW_TAG_subprogram
)
14512 struct attribute
*attr
;
14514 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
14516 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
14520 = language_class_name_from_physname (cu
->language_defn
,
14524 if (actual_name
!= NULL
)
14526 char *die_name
= dwarf2_name (die
, cu
);
14528 if (die_name
!= NULL
14529 && strcmp (die_name
, actual_name
) != 0)
14531 /* Strip off the class name from the full name.
14532 We want the prefix. */
14533 int die_name_len
= strlen (die_name
);
14534 int actual_name_len
= strlen (actual_name
);
14536 /* Test for '::' as a sanity check. */
14537 if (actual_name_len
> die_name_len
+ 2
14538 && actual_name
[actual_name_len
14539 - die_name_len
- 1] == ':')
14541 obsavestring (actual_name
,
14542 actual_name_len
- die_name_len
- 2,
14543 &cu
->objfile
->objfile_obstack
);
14546 xfree (actual_name
);
14555 /* GCC might emit a nameless typedef that has a linkage name. Determine the
14556 prefix part in such case. See
14557 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14560 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14562 struct attribute
*attr
;
14565 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
14566 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
14569 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14570 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
14573 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14575 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14576 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14579 /* dwarf2_name had to be already called. */
14580 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
14582 /* Strip the base name, keep any leading namespaces/classes. */
14583 base
= strrchr (DW_STRING (attr
), ':');
14584 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
14587 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
14588 &cu
->objfile
->objfile_obstack
);
14591 /* Return the name of the namespace/class that DIE is defined within,
14592 or "" if we can't tell. The caller should not xfree the result.
14594 For example, if we're within the method foo() in the following
14604 then determine_prefix on foo's die will return "N::C". */
14606 static const char *
14607 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
14609 struct die_info
*parent
, *spec_die
;
14610 struct dwarf2_cu
*spec_cu
;
14611 struct type
*parent_type
;
14614 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
14615 && cu
->language
!= language_fortran
)
14618 retval
= anonymous_struct_prefix (die
, cu
);
14622 /* We have to be careful in the presence of DW_AT_specification.
14623 For example, with GCC 3.4, given the code
14627 // Definition of N::foo.
14631 then we'll have a tree of DIEs like this:
14633 1: DW_TAG_compile_unit
14634 2: DW_TAG_namespace // N
14635 3: DW_TAG_subprogram // declaration of N::foo
14636 4: DW_TAG_subprogram // definition of N::foo
14637 DW_AT_specification // refers to die #3
14639 Thus, when processing die #4, we have to pretend that we're in
14640 the context of its DW_AT_specification, namely the contex of die
14643 spec_die
= die_specification (die
, &spec_cu
);
14644 if (spec_die
== NULL
)
14645 parent
= die
->parent
;
14648 parent
= spec_die
->parent
;
14652 if (parent
== NULL
)
14654 else if (parent
->building_fullname
)
14657 const char *parent_name
;
14659 /* It has been seen on RealView 2.2 built binaries,
14660 DW_TAG_template_type_param types actually _defined_ as
14661 children of the parent class:
14664 template class <class Enum> Class{};
14665 Class<enum E> class_e;
14667 1: DW_TAG_class_type (Class)
14668 2: DW_TAG_enumeration_type (E)
14669 3: DW_TAG_enumerator (enum1:0)
14670 3: DW_TAG_enumerator (enum2:1)
14672 2: DW_TAG_template_type_param
14673 DW_AT_type DW_FORM_ref_udata (E)
14675 Besides being broken debug info, it can put GDB into an
14676 infinite loop. Consider:
14678 When we're building the full name for Class<E>, we'll start
14679 at Class, and go look over its template type parameters,
14680 finding E. We'll then try to build the full name of E, and
14681 reach here. We're now trying to build the full name of E,
14682 and look over the parent DIE for containing scope. In the
14683 broken case, if we followed the parent DIE of E, we'd again
14684 find Class, and once again go look at its template type
14685 arguments, etc., etc. Simply don't consider such parent die
14686 as source-level parent of this die (it can't be, the language
14687 doesn't allow it), and break the loop here. */
14688 name
= dwarf2_name (die
, cu
);
14689 parent_name
= dwarf2_name (parent
, cu
);
14690 complaint (&symfile_complaints
,
14691 _("template param type '%s' defined within parent '%s'"),
14692 name
? name
: "<unknown>",
14693 parent_name
? parent_name
: "<unknown>");
14697 switch (parent
->tag
)
14699 case DW_TAG_namespace
:
14700 parent_type
= read_type_die (parent
, cu
);
14701 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
14702 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
14703 Work around this problem here. */
14704 if (cu
->language
== language_cplus
14705 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
14707 /* We give a name to even anonymous namespaces. */
14708 return TYPE_TAG_NAME (parent_type
);
14709 case DW_TAG_class_type
:
14710 case DW_TAG_interface_type
:
14711 case DW_TAG_structure_type
:
14712 case DW_TAG_union_type
:
14713 case DW_TAG_module
:
14714 parent_type
= read_type_die (parent
, cu
);
14715 if (TYPE_TAG_NAME (parent_type
) != NULL
)
14716 return TYPE_TAG_NAME (parent_type
);
14718 /* An anonymous structure is only allowed non-static data
14719 members; no typedefs, no member functions, et cetera.
14720 So it does not need a prefix. */
14722 case DW_TAG_compile_unit
:
14723 case DW_TAG_partial_unit
:
14724 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
14725 if (cu
->language
== language_cplus
14726 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
14727 && die
->child
!= NULL
14728 && (die
->tag
== DW_TAG_class_type
14729 || die
->tag
== DW_TAG_structure_type
14730 || die
->tag
== DW_TAG_union_type
))
14732 char *name
= guess_full_die_structure_name (die
, cu
);
14738 return determine_prefix (parent
, cu
);
14742 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
14743 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
14744 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
14745 an obconcat, otherwise allocate storage for the result. The CU argument is
14746 used to determine the language and hence, the appropriate separator. */
14748 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
14751 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
14752 int physname
, struct dwarf2_cu
*cu
)
14754 const char *lead
= "";
14757 if (suffix
== NULL
|| suffix
[0] == '\0'
14758 || prefix
== NULL
|| prefix
[0] == '\0')
14760 else if (cu
->language
== language_java
)
14762 else if (cu
->language
== language_fortran
&& physname
)
14764 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
14765 DW_AT_MIPS_linkage_name is preferred and used instead. */
14773 if (prefix
== NULL
)
14775 if (suffix
== NULL
)
14781 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
14783 strcpy (retval
, lead
);
14784 strcat (retval
, prefix
);
14785 strcat (retval
, sep
);
14786 strcat (retval
, suffix
);
14791 /* We have an obstack. */
14792 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
14796 /* Return sibling of die, NULL if no sibling. */
14798 static struct die_info
*
14799 sibling_die (struct die_info
*die
)
14801 return die
->sibling
;
14804 /* Get name of a die, return NULL if not found. */
14807 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
14808 struct obstack
*obstack
)
14810 if (name
&& cu
->language
== language_cplus
)
14812 char *canon_name
= cp_canonicalize_string (name
);
14814 if (canon_name
!= NULL
)
14816 if (strcmp (canon_name
, name
) != 0)
14817 name
= obsavestring (canon_name
, strlen (canon_name
),
14819 xfree (canon_name
);
14826 /* Get name of a die, return NULL if not found. */
14829 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
14831 struct attribute
*attr
;
14833 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
14834 if ((!attr
|| !DW_STRING (attr
))
14835 && die
->tag
!= DW_TAG_class_type
14836 && die
->tag
!= DW_TAG_interface_type
14837 && die
->tag
!= DW_TAG_structure_type
14838 && die
->tag
!= DW_TAG_union_type
)
14843 case DW_TAG_compile_unit
:
14844 case DW_TAG_partial_unit
:
14845 /* Compilation units have a DW_AT_name that is a filename, not
14846 a source language identifier. */
14847 case DW_TAG_enumeration_type
:
14848 case DW_TAG_enumerator
:
14849 /* These tags always have simple identifiers already; no need
14850 to canonicalize them. */
14851 return DW_STRING (attr
);
14853 case DW_TAG_subprogram
:
14854 /* Java constructors will all be named "<init>", so return
14855 the class name when we see this special case. */
14856 if (cu
->language
== language_java
14857 && DW_STRING (attr
) != NULL
14858 && strcmp (DW_STRING (attr
), "<init>") == 0)
14860 struct dwarf2_cu
*spec_cu
= cu
;
14861 struct die_info
*spec_die
;
14863 /* GCJ will output '<init>' for Java constructor names.
14864 For this special case, return the name of the parent class. */
14866 /* GCJ may output suprogram DIEs with AT_specification set.
14867 If so, use the name of the specified DIE. */
14868 spec_die
= die_specification (die
, &spec_cu
);
14869 if (spec_die
!= NULL
)
14870 return dwarf2_name (spec_die
, spec_cu
);
14875 if (die
->tag
== DW_TAG_class_type
)
14876 return dwarf2_name (die
, cu
);
14878 while (die
->tag
!= DW_TAG_compile_unit
14879 && die
->tag
!= DW_TAG_partial_unit
);
14883 case DW_TAG_class_type
:
14884 case DW_TAG_interface_type
:
14885 case DW_TAG_structure_type
:
14886 case DW_TAG_union_type
:
14887 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
14888 structures or unions. These were of the form "._%d" in GCC 4.1,
14889 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
14890 and GCC 4.4. We work around this problem by ignoring these. */
14891 if (attr
&& DW_STRING (attr
)
14892 && (strncmp (DW_STRING (attr
), "._", 2) == 0
14893 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
14896 /* GCC might emit a nameless typedef that has a linkage name. See
14897 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14898 if (!attr
|| DW_STRING (attr
) == NULL
)
14900 char *demangled
= NULL
;
14902 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
14904 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
14906 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
14909 /* Avoid demangling DW_STRING (attr) the second time on a second
14910 call for the same DIE. */
14911 if (!DW_STRING_IS_CANONICAL (attr
))
14912 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
14918 /* FIXME: we already did this for the partial symbol... */
14919 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
14920 &cu
->objfile
->objfile_obstack
);
14921 DW_STRING_IS_CANONICAL (attr
) = 1;
14924 /* Strip any leading namespaces/classes, keep only the base name.
14925 DW_AT_name for named DIEs does not contain the prefixes. */
14926 base
= strrchr (DW_STRING (attr
), ':');
14927 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
14930 return DW_STRING (attr
);
14939 if (!DW_STRING_IS_CANONICAL (attr
))
14942 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
14943 &cu
->objfile
->objfile_obstack
);
14944 DW_STRING_IS_CANONICAL (attr
) = 1;
14946 return DW_STRING (attr
);
14949 /* Return the die that this die in an extension of, or NULL if there
14950 is none. *EXT_CU is the CU containing DIE on input, and the CU
14951 containing the return value on output. */
14953 static struct die_info
*
14954 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
14956 struct attribute
*attr
;
14958 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
14962 return follow_die_ref (die
, attr
, ext_cu
);
14965 /* Convert a DIE tag into its string name. */
14967 static const char *
14968 dwarf_tag_name (unsigned tag
)
14970 const char *name
= get_DW_TAG_name (tag
);
14973 return "DW_TAG_<unknown>";
14978 /* Convert a DWARF attribute code into its string name. */
14980 static const char *
14981 dwarf_attr_name (unsigned attr
)
14985 #ifdef MIPS /* collides with DW_AT_HP_block_index */
14986 if (attr
== DW_AT_MIPS_fde
)
14987 return "DW_AT_MIPS_fde";
14989 if (attr
== DW_AT_HP_block_index
)
14990 return "DW_AT_HP_block_index";
14993 name
= get_DW_AT_name (attr
);
14996 return "DW_AT_<unknown>";
15001 /* Convert a DWARF value form code into its string name. */
15003 static const char *
15004 dwarf_form_name (unsigned form
)
15006 const char *name
= get_DW_FORM_name (form
);
15009 return "DW_FORM_<unknown>";
15015 dwarf_bool_name (unsigned mybool
)
15023 /* Convert a DWARF type code into its string name. */
15025 static const char *
15026 dwarf_type_encoding_name (unsigned enc
)
15028 const char *name
= get_DW_ATE_name (enc
);
15031 return "DW_ATE_<unknown>";
15037 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15041 print_spaces (indent
, f
);
15042 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15043 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15045 if (die
->parent
!= NULL
)
15047 print_spaces (indent
, f
);
15048 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15049 die
->parent
->offset
.sect_off
);
15052 print_spaces (indent
, f
);
15053 fprintf_unfiltered (f
, " has children: %s\n",
15054 dwarf_bool_name (die
->child
!= NULL
));
15056 print_spaces (indent
, f
);
15057 fprintf_unfiltered (f
, " attributes:\n");
15059 for (i
= 0; i
< die
->num_attrs
; ++i
)
15061 print_spaces (indent
, f
);
15062 fprintf_unfiltered (f
, " %s (%s) ",
15063 dwarf_attr_name (die
->attrs
[i
].name
),
15064 dwarf_form_name (die
->attrs
[i
].form
));
15066 switch (die
->attrs
[i
].form
)
15069 case DW_FORM_GNU_addr_index
:
15070 fprintf_unfiltered (f
, "address: ");
15071 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15073 case DW_FORM_block2
:
15074 case DW_FORM_block4
:
15075 case DW_FORM_block
:
15076 case DW_FORM_block1
:
15077 fprintf_unfiltered (f
, "block: size %d",
15078 DW_BLOCK (&die
->attrs
[i
])->size
);
15080 case DW_FORM_exprloc
:
15081 fprintf_unfiltered (f
, "expression: size %u",
15082 DW_BLOCK (&die
->attrs
[i
])->size
);
15084 case DW_FORM_ref_addr
:
15085 fprintf_unfiltered (f
, "ref address: ");
15086 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15092 case DW_FORM_ref_udata
:
15093 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15094 (long) (DW_UNSND (&die
->attrs
[i
])));
15096 case DW_FORM_data1
:
15097 case DW_FORM_data2
:
15098 case DW_FORM_data4
:
15099 case DW_FORM_data8
:
15100 case DW_FORM_udata
:
15101 case DW_FORM_sdata
:
15102 fprintf_unfiltered (f
, "constant: %s",
15103 pulongest (DW_UNSND (&die
->attrs
[i
])));
15105 case DW_FORM_sec_offset
:
15106 fprintf_unfiltered (f
, "section offset: %s",
15107 pulongest (DW_UNSND (&die
->attrs
[i
])));
15109 case DW_FORM_ref_sig8
:
15110 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15111 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15112 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15114 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15116 case DW_FORM_string
:
15118 case DW_FORM_GNU_str_index
:
15119 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15120 DW_STRING (&die
->attrs
[i
])
15121 ? DW_STRING (&die
->attrs
[i
]) : "",
15122 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15125 if (DW_UNSND (&die
->attrs
[i
]))
15126 fprintf_unfiltered (f
, "flag: TRUE");
15128 fprintf_unfiltered (f
, "flag: FALSE");
15130 case DW_FORM_flag_present
:
15131 fprintf_unfiltered (f
, "flag: TRUE");
15133 case DW_FORM_indirect
:
15134 /* The reader will have reduced the indirect form to
15135 the "base form" so this form should not occur. */
15136 fprintf_unfiltered (f
,
15137 "unexpected attribute form: DW_FORM_indirect");
15140 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
15141 die
->attrs
[i
].form
);
15144 fprintf_unfiltered (f
, "\n");
15149 dump_die_for_error (struct die_info
*die
)
15151 dump_die_shallow (gdb_stderr
, 0, die
);
15155 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
15157 int indent
= level
* 4;
15159 gdb_assert (die
!= NULL
);
15161 if (level
>= max_level
)
15164 dump_die_shallow (f
, indent
, die
);
15166 if (die
->child
!= NULL
)
15168 print_spaces (indent
, f
);
15169 fprintf_unfiltered (f
, " Children:");
15170 if (level
+ 1 < max_level
)
15172 fprintf_unfiltered (f
, "\n");
15173 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
15177 fprintf_unfiltered (f
,
15178 " [not printed, max nesting level reached]\n");
15182 if (die
->sibling
!= NULL
&& level
> 0)
15184 dump_die_1 (f
, level
, max_level
, die
->sibling
);
15188 /* This is called from the pdie macro in gdbinit.in.
15189 It's not static so gcc will keep a copy callable from gdb. */
15192 dump_die (struct die_info
*die
, int max_level
)
15194 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
15198 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
15202 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
15208 /* DW_ADDR is always stored already as sect_offset; despite for the forms
15209 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
15212 is_ref_attr (struct attribute
*attr
)
15214 switch (attr
->form
)
15216 case DW_FORM_ref_addr
:
15221 case DW_FORM_ref_udata
:
15228 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
15232 dwarf2_get_ref_die_offset (struct attribute
*attr
)
15234 sect_offset retval
= { DW_UNSND (attr
) };
15236 if (is_ref_attr (attr
))
15239 retval
.sect_off
= 0;
15240 complaint (&symfile_complaints
,
15241 _("unsupported die ref attribute form: '%s'"),
15242 dwarf_form_name (attr
->form
));
15246 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
15247 * the value held by the attribute is not constant. */
15250 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
15252 if (attr
->form
== DW_FORM_sdata
)
15253 return DW_SND (attr
);
15254 else if (attr
->form
== DW_FORM_udata
15255 || attr
->form
== DW_FORM_data1
15256 || attr
->form
== DW_FORM_data2
15257 || attr
->form
== DW_FORM_data4
15258 || attr
->form
== DW_FORM_data8
)
15259 return DW_UNSND (attr
);
15262 complaint (&symfile_complaints
,
15263 _("Attribute value is not a constant (%s)"),
15264 dwarf_form_name (attr
->form
));
15265 return default_value
;
15269 /* Follow reference or signature attribute ATTR of SRC_DIE.
15270 On entry *REF_CU is the CU of SRC_DIE.
15271 On exit *REF_CU is the CU of the result. */
15273 static struct die_info
*
15274 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
15275 struct dwarf2_cu
**ref_cu
)
15277 struct die_info
*die
;
15279 if (is_ref_attr (attr
))
15280 die
= follow_die_ref (src_die
, attr
, ref_cu
);
15281 else if (attr
->form
== DW_FORM_ref_sig8
)
15282 die
= follow_die_sig (src_die
, attr
, ref_cu
);
15285 dump_die_for_error (src_die
);
15286 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
15287 (*ref_cu
)->objfile
->name
);
15293 /* Follow reference OFFSET.
15294 On entry *REF_CU is the CU of the source die referencing OFFSET.
15295 On exit *REF_CU is the CU of the result.
15296 Returns NULL if OFFSET is invalid. */
15298 static struct die_info
*
15299 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
15301 struct die_info temp_die
;
15302 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
15304 gdb_assert (cu
->per_cu
!= NULL
);
15308 if (cu
->per_cu
->is_debug_types
)
15310 /* .debug_types CUs cannot reference anything outside their CU.
15311 If they need to, they have to reference a signatured type via
15312 DW_FORM_ref_sig8. */
15313 if (! offset_in_cu_p (&cu
->header
, offset
))
15316 else if (! offset_in_cu_p (&cu
->header
, offset
))
15318 struct dwarf2_per_cu_data
*per_cu
;
15320 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
15322 /* If necessary, add it to the queue and load its DIEs. */
15323 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
15324 load_full_comp_unit (per_cu
, cu
->language
);
15326 target_cu
= per_cu
->cu
;
15328 else if (cu
->dies
== NULL
)
15330 /* We're loading full DIEs during partial symbol reading. */
15331 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
15332 load_full_comp_unit (cu
->per_cu
, language_minimal
);
15335 *ref_cu
= target_cu
;
15336 temp_die
.offset
= offset
;
15337 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
15340 /* Follow reference attribute ATTR of SRC_DIE.
15341 On entry *REF_CU is the CU of SRC_DIE.
15342 On exit *REF_CU is the CU of the result. */
15344 static struct die_info
*
15345 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
15346 struct dwarf2_cu
**ref_cu
)
15348 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15349 struct dwarf2_cu
*cu
= *ref_cu
;
15350 struct die_info
*die
;
15352 die
= follow_die_offset (offset
, ref_cu
);
15354 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
15355 "at 0x%x [in module %s]"),
15356 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
15361 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
15362 Returned value is intended for DW_OP_call*. Returned
15363 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
15365 struct dwarf2_locexpr_baton
15366 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
15367 struct dwarf2_per_cu_data
*per_cu
,
15368 CORE_ADDR (*get_frame_pc
) (void *baton
),
15371 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
15372 struct dwarf2_cu
*cu
;
15373 struct die_info
*die
;
15374 struct attribute
*attr
;
15375 struct dwarf2_locexpr_baton retval
;
15377 dw2_setup (per_cu
->objfile
);
15379 if (per_cu
->cu
== NULL
)
15383 die
= follow_die_offset (offset
, &cu
);
15385 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
15386 offset
.sect_off
, per_cu
->objfile
->name
);
15388 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15391 /* DWARF: "If there is no such attribute, then there is no effect.".
15392 DATA is ignored if SIZE is 0. */
15394 retval
.data
= NULL
;
15397 else if (attr_form_is_section_offset (attr
))
15399 struct dwarf2_loclist_baton loclist_baton
;
15400 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
15403 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
15405 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
15407 retval
.size
= size
;
15411 if (!attr_form_is_block (attr
))
15412 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
15413 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
15414 offset
.sect_off
, per_cu
->objfile
->name
);
15416 retval
.data
= DW_BLOCK (attr
)->data
;
15417 retval
.size
= DW_BLOCK (attr
)->size
;
15419 retval
.per_cu
= cu
->per_cu
;
15421 age_cached_comp_units ();
15426 /* Return the type of the DIE at DIE_OFFSET in the CU named by
15430 dwarf2_get_die_type (cu_offset die_offset
,
15431 struct dwarf2_per_cu_data
*per_cu
)
15433 sect_offset die_offset_sect
;
15435 dw2_setup (per_cu
->objfile
);
15437 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
15438 return get_die_type_at_offset (die_offset_sect
, per_cu
);
15441 /* Follow the signature attribute ATTR in SRC_DIE.
15442 On entry *REF_CU is the CU of SRC_DIE.
15443 On exit *REF_CU is the CU of the result. */
15445 static struct die_info
*
15446 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
15447 struct dwarf2_cu
**ref_cu
)
15449 struct objfile
*objfile
= (*ref_cu
)->objfile
;
15450 struct die_info temp_die
;
15451 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15452 struct dwarf2_cu
*sig_cu
;
15453 struct die_info
*die
;
15455 /* sig_type will be NULL if the signatured type is missing from
15457 if (sig_type
== NULL
)
15458 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15459 "at 0x%x [in module %s]"),
15460 src_die
->offset
.sect_off
, objfile
->name
);
15462 /* If necessary, add it to the queue and load its DIEs. */
15464 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
15465 read_signatured_type (sig_type
);
15467 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15469 sig_cu
= sig_type
->per_cu
.cu
;
15470 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
15471 temp_die
.offset
= sig_type
->type_offset_in_section
;
15472 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
15473 temp_die
.offset
.sect_off
);
15480 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
15481 "from DIE at 0x%x [in module %s]"),
15482 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
15485 /* Given an offset of a signatured type, return its signatured_type. */
15487 static struct signatured_type
*
15488 lookup_signatured_type_at_offset (struct objfile
*objfile
,
15489 struct dwarf2_section_info
*section
,
15490 sect_offset offset
)
15492 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
15493 unsigned int length
, initial_length_size
;
15494 unsigned int sig_offset
;
15495 struct signatured_type find_entry
, *sig_type
;
15497 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
15498 sig_offset
= (initial_length_size
15500 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
15501 + 1 /*address_size*/);
15502 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
15503 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
15505 /* This is only used to lookup previously recorded types.
15506 If we didn't find it, it's our bug. */
15507 gdb_assert (sig_type
!= NULL
);
15508 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
15513 /* Load the DIEs associated with type unit PER_CU into memory. */
15516 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
15518 struct objfile
*objfile
= per_cu
->objfile
;
15519 struct dwarf2_section_info
*sect
= per_cu
->info_or_types_section
;
15520 sect_offset offset
= per_cu
->offset
;
15521 struct signatured_type
*sig_type
;
15523 dwarf2_read_section (objfile
, sect
);
15525 /* We have the section offset, but we need the signature to do the
15526 hash table lookup. */
15527 /* FIXME: This is sorta unnecessary, read_signatured_type only uses
15528 the signature to assert we found the right one.
15529 Ok, but it's a lot of work. We should simplify things so any needed
15530 assert doesn't require all this clumsiness. */
15531 sig_type
= lookup_signatured_type_at_offset (objfile
, sect
, offset
);
15533 gdb_assert (&sig_type
->per_cu
== per_cu
);
15534 gdb_assert (sig_type
->per_cu
.cu
== NULL
);
15536 read_signatured_type (sig_type
);
15538 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
15541 /* die_reader_func for read_signatured_type.
15542 This is identical to load_full_comp_unit_reader,
15543 but is kept separate for now. */
15546 read_signatured_type_reader (const struct die_reader_specs
*reader
,
15547 gdb_byte
*info_ptr
,
15548 struct die_info
*comp_unit_die
,
15552 struct dwarf2_cu
*cu
= reader
->cu
;
15554 gdb_assert (cu
->die_hash
== NULL
);
15556 htab_create_alloc_ex (cu
->header
.length
/ 12,
15560 &cu
->comp_unit_obstack
,
15561 hashtab_obstack_allocate
,
15562 dummy_obstack_deallocate
);
15565 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
15566 &info_ptr
, comp_unit_die
);
15567 cu
->dies
= comp_unit_die
;
15568 /* comp_unit_die is not stored in die_hash, no need. */
15570 /* We try not to read any attributes in this function, because not
15571 all CUs needed for references have been loaded yet, and symbol
15572 table processing isn't initialized. But we have to set the CU language,
15573 or we won't be able to build types correctly.
15574 Similarly, if we do not read the producer, we can not apply
15575 producer-specific interpretation. */
15576 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
15579 /* Read in a signatured type and build its CU and DIEs.
15580 If the type is a stub for the real type in a DWO file,
15581 read in the real type from the DWO file as well. */
15584 read_signatured_type (struct signatured_type
*sig_type
)
15586 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
15588 gdb_assert (per_cu
->is_debug_types
);
15589 gdb_assert (per_cu
->cu
== NULL
);
15591 init_cutu_and_read_dies (per_cu
, 0, 1, read_signatured_type_reader
, NULL
);
15594 /* Decode simple location descriptions.
15595 Given a pointer to a dwarf block that defines a location, compute
15596 the location and return the value.
15598 NOTE drow/2003-11-18: This function is called in two situations
15599 now: for the address of static or global variables (partial symbols
15600 only) and for offsets into structures which are expected to be
15601 (more or less) constant. The partial symbol case should go away,
15602 and only the constant case should remain. That will let this
15603 function complain more accurately. A few special modes are allowed
15604 without complaint for global variables (for instance, global
15605 register values and thread-local values).
15607 A location description containing no operations indicates that the
15608 object is optimized out. The return value is 0 for that case.
15609 FIXME drow/2003-11-16: No callers check for this case any more; soon all
15610 callers will only want a very basic result and this can become a
15613 Note that stack[0] is unused except as a default error return. */
15616 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
15618 struct objfile
*objfile
= cu
->objfile
;
15620 int size
= blk
->size
;
15621 gdb_byte
*data
= blk
->data
;
15622 CORE_ADDR stack
[64];
15624 unsigned int bytes_read
, unsnd
;
15630 stack
[++stacki
] = 0;
15669 stack
[++stacki
] = op
- DW_OP_lit0
;
15704 stack
[++stacki
] = op
- DW_OP_reg0
;
15706 dwarf2_complex_location_expr_complaint ();
15710 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
15712 stack
[++stacki
] = unsnd
;
15714 dwarf2_complex_location_expr_complaint ();
15718 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
15723 case DW_OP_const1u
:
15724 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
15728 case DW_OP_const1s
:
15729 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
15733 case DW_OP_const2u
:
15734 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
15738 case DW_OP_const2s
:
15739 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
15743 case DW_OP_const4u
:
15744 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
15748 case DW_OP_const4s
:
15749 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
15753 case DW_OP_const8u
:
15754 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
15759 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
15765 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
15770 stack
[stacki
+ 1] = stack
[stacki
];
15775 stack
[stacki
- 1] += stack
[stacki
];
15779 case DW_OP_plus_uconst
:
15780 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
15786 stack
[stacki
- 1] -= stack
[stacki
];
15791 /* If we're not the last op, then we definitely can't encode
15792 this using GDB's address_class enum. This is valid for partial
15793 global symbols, although the variable's address will be bogus
15796 dwarf2_complex_location_expr_complaint ();
15799 case DW_OP_GNU_push_tls_address
:
15800 /* The top of the stack has the offset from the beginning
15801 of the thread control block at which the variable is located. */
15802 /* Nothing should follow this operator, so the top of stack would
15804 /* This is valid for partial global symbols, but the variable's
15805 address will be bogus in the psymtab. Make it always at least
15806 non-zero to not look as a variable garbage collected by linker
15807 which have DW_OP_addr 0. */
15809 dwarf2_complex_location_expr_complaint ();
15813 case DW_OP_GNU_uninit
:
15816 case DW_OP_GNU_addr_index
:
15817 case DW_OP_GNU_const_index
:
15818 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
15825 const char *name
= get_DW_OP_name (op
);
15828 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
15831 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
15835 return (stack
[stacki
]);
15838 /* Enforce maximum stack depth of SIZE-1 to avoid writing
15839 outside of the allocated space. Also enforce minimum>0. */
15840 if (stacki
>= ARRAY_SIZE (stack
) - 1)
15842 complaint (&symfile_complaints
,
15843 _("location description stack overflow"));
15849 complaint (&symfile_complaints
,
15850 _("location description stack underflow"));
15854 return (stack
[stacki
]);
15857 /* memory allocation interface */
15859 static struct dwarf_block
*
15860 dwarf_alloc_block (struct dwarf2_cu
*cu
)
15862 struct dwarf_block
*blk
;
15864 blk
= (struct dwarf_block
*)
15865 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
15869 static struct die_info
*
15870 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
15872 struct die_info
*die
;
15873 size_t size
= sizeof (struct die_info
);
15876 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
15878 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
15879 memset (die
, 0, sizeof (struct die_info
));
15884 /* Macro support. */
15886 /* Return the full name of file number I in *LH's file name table.
15887 Use COMP_DIR as the name of the current directory of the
15888 compilation. The result is allocated using xmalloc; the caller is
15889 responsible for freeing it. */
15891 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
15893 /* Is the file number a valid index into the line header's file name
15894 table? Remember that file numbers start with one, not zero. */
15895 if (1 <= file
&& file
<= lh
->num_file_names
)
15897 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15899 if (IS_ABSOLUTE_PATH (fe
->name
))
15900 return xstrdup (fe
->name
);
15908 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15914 dir_len
= strlen (dir
);
15915 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
15916 strcpy (full_name
, dir
);
15917 full_name
[dir_len
] = '/';
15918 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
15922 return xstrdup (fe
->name
);
15927 /* The compiler produced a bogus file number. We can at least
15928 record the macro definitions made in the file, even if we
15929 won't be able to find the file by name. */
15930 char fake_name
[80];
15932 sprintf (fake_name
, "<bad macro file number %d>", file
);
15934 complaint (&symfile_complaints
,
15935 _("bad file number in macro information (%d)"),
15938 return xstrdup (fake_name
);
15943 static struct macro_source_file
*
15944 macro_start_file (int file
, int line
,
15945 struct macro_source_file
*current_file
,
15946 const char *comp_dir
,
15947 struct line_header
*lh
, struct objfile
*objfile
)
15949 /* The full name of this source file. */
15950 char *full_name
= file_full_name (file
, lh
, comp_dir
);
15952 /* We don't create a macro table for this compilation unit
15953 at all until we actually get a filename. */
15954 if (! pending_macros
)
15955 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
15956 objfile
->macro_cache
);
15958 if (! current_file
)
15960 /* If we have no current file, then this must be the start_file
15961 directive for the compilation unit's main source file. */
15962 current_file
= macro_set_main (pending_macros
, full_name
);
15963 macro_define_special (pending_macros
);
15966 current_file
= macro_include (current_file
, line
, full_name
);
15970 return current_file
;
15974 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
15975 followed by a null byte. */
15977 copy_string (const char *buf
, int len
)
15979 char *s
= xmalloc (len
+ 1);
15981 memcpy (s
, buf
, len
);
15987 static const char *
15988 consume_improper_spaces (const char *p
, const char *body
)
15992 complaint (&symfile_complaints
,
15993 _("macro definition contains spaces "
15994 "in formal argument list:\n`%s'"),
16006 parse_macro_definition (struct macro_source_file
*file
, int line
,
16011 /* The body string takes one of two forms. For object-like macro
16012 definitions, it should be:
16014 <macro name> " " <definition>
16016 For function-like macro definitions, it should be:
16018 <macro name> "() " <definition>
16020 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16022 Spaces may appear only where explicitly indicated, and in the
16025 The Dwarf 2 spec says that an object-like macro's name is always
16026 followed by a space, but versions of GCC around March 2002 omit
16027 the space when the macro's definition is the empty string.
16029 The Dwarf 2 spec says that there should be no spaces between the
16030 formal arguments in a function-like macro's formal argument list,
16031 but versions of GCC around March 2002 include spaces after the
16035 /* Find the extent of the macro name. The macro name is terminated
16036 by either a space or null character (for an object-like macro) or
16037 an opening paren (for a function-like macro). */
16038 for (p
= body
; *p
; p
++)
16039 if (*p
== ' ' || *p
== '(')
16042 if (*p
== ' ' || *p
== '\0')
16044 /* It's an object-like macro. */
16045 int name_len
= p
- body
;
16046 char *name
= copy_string (body
, name_len
);
16047 const char *replacement
;
16050 replacement
= body
+ name_len
+ 1;
16053 dwarf2_macro_malformed_definition_complaint (body
);
16054 replacement
= body
+ name_len
;
16057 macro_define_object (file
, line
, name
, replacement
);
16061 else if (*p
== '(')
16063 /* It's a function-like macro. */
16064 char *name
= copy_string (body
, p
- body
);
16067 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16071 p
= consume_improper_spaces (p
, body
);
16073 /* Parse the formal argument list. */
16074 while (*p
&& *p
!= ')')
16076 /* Find the extent of the current argument name. */
16077 const char *arg_start
= p
;
16079 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16082 if (! *p
|| p
== arg_start
)
16083 dwarf2_macro_malformed_definition_complaint (body
);
16086 /* Make sure argv has room for the new argument. */
16087 if (argc
>= argv_size
)
16090 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16093 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16096 p
= consume_improper_spaces (p
, body
);
16098 /* Consume the comma, if present. */
16103 p
= consume_improper_spaces (p
, body
);
16112 /* Perfectly formed definition, no complaints. */
16113 macro_define_function (file
, line
, name
,
16114 argc
, (const char **) argv
,
16116 else if (*p
== '\0')
16118 /* Complain, but do define it. */
16119 dwarf2_macro_malformed_definition_complaint (body
);
16120 macro_define_function (file
, line
, name
,
16121 argc
, (const char **) argv
,
16125 /* Just complain. */
16126 dwarf2_macro_malformed_definition_complaint (body
);
16129 /* Just complain. */
16130 dwarf2_macro_malformed_definition_complaint (body
);
16136 for (i
= 0; i
< argc
; i
++)
16142 dwarf2_macro_malformed_definition_complaint (body
);
16145 /* Skip some bytes from BYTES according to the form given in FORM.
16146 Returns the new pointer. */
16149 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
16150 enum dwarf_form form
,
16151 unsigned int offset_size
,
16152 struct dwarf2_section_info
*section
)
16154 unsigned int bytes_read
;
16158 case DW_FORM_data1
:
16163 case DW_FORM_data2
:
16167 case DW_FORM_data4
:
16171 case DW_FORM_data8
:
16175 case DW_FORM_string
:
16176 read_direct_string (abfd
, bytes
, &bytes_read
);
16177 bytes
+= bytes_read
;
16180 case DW_FORM_sec_offset
:
16182 bytes
+= offset_size
;
16185 case DW_FORM_block
:
16186 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
16187 bytes
+= bytes_read
;
16190 case DW_FORM_block1
:
16191 bytes
+= 1 + read_1_byte (abfd
, bytes
);
16193 case DW_FORM_block2
:
16194 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
16196 case DW_FORM_block4
:
16197 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
16200 case DW_FORM_sdata
:
16201 case DW_FORM_udata
:
16202 case DW_FORM_GNU_addr_index
:
16203 case DW_FORM_GNU_str_index
:
16204 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
16207 dwarf2_section_buffer_overflow_complaint (section
);
16215 complaint (&symfile_complaints
,
16216 _("invalid form 0x%x in `%s'"),
16218 section
->asection
->name
);
16226 /* A helper for dwarf_decode_macros that handles skipping an unknown
16227 opcode. Returns an updated pointer to the macro data buffer; or,
16228 on error, issues a complaint and returns NULL. */
16231 skip_unknown_opcode (unsigned int opcode
,
16232 gdb_byte
**opcode_definitions
,
16233 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16235 unsigned int offset_size
,
16236 struct dwarf2_section_info
*section
)
16238 unsigned int bytes_read
, i
;
16242 if (opcode_definitions
[opcode
] == NULL
)
16244 complaint (&symfile_complaints
,
16245 _("unrecognized DW_MACFINO opcode 0x%x"),
16250 defn
= opcode_definitions
[opcode
];
16251 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
16252 defn
+= bytes_read
;
16254 for (i
= 0; i
< arg
; ++i
)
16256 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
16258 if (mac_ptr
== NULL
)
16260 /* skip_form_bytes already issued the complaint. */
16268 /* A helper function which parses the header of a macro section.
16269 If the macro section is the extended (for now called "GNU") type,
16270 then this updates *OFFSET_SIZE. Returns a pointer to just after
16271 the header, or issues a complaint and returns NULL on error. */
16274 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
16277 unsigned int *offset_size
,
16278 int section_is_gnu
)
16280 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
16282 if (section_is_gnu
)
16284 unsigned int version
, flags
;
16286 version
= read_2_bytes (abfd
, mac_ptr
);
16289 complaint (&symfile_complaints
,
16290 _("unrecognized version `%d' in .debug_macro section"),
16296 flags
= read_1_byte (abfd
, mac_ptr
);
16298 *offset_size
= (flags
& 1) ? 8 : 4;
16300 if ((flags
& 2) != 0)
16301 /* We don't need the line table offset. */
16302 mac_ptr
+= *offset_size
;
16304 /* Vendor opcode descriptions. */
16305 if ((flags
& 4) != 0)
16307 unsigned int i
, count
;
16309 count
= read_1_byte (abfd
, mac_ptr
);
16311 for (i
= 0; i
< count
; ++i
)
16313 unsigned int opcode
, bytes_read
;
16316 opcode
= read_1_byte (abfd
, mac_ptr
);
16318 opcode_definitions
[opcode
] = mac_ptr
;
16319 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16320 mac_ptr
+= bytes_read
;
16329 /* A helper for dwarf_decode_macros that handles the GNU extensions,
16330 including DW_MACRO_GNU_transparent_include. */
16333 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
16334 struct macro_source_file
*current_file
,
16335 struct line_header
*lh
, char *comp_dir
,
16336 struct dwarf2_section_info
*section
,
16337 int section_is_gnu
,
16338 unsigned int offset_size
,
16339 struct objfile
*objfile
,
16340 htab_t include_hash
)
16342 enum dwarf_macro_record_type macinfo_type
;
16343 int at_commandline
;
16344 gdb_byte
*opcode_definitions
[256];
16346 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16347 &offset_size
, section_is_gnu
);
16348 if (mac_ptr
== NULL
)
16350 /* We already issued a complaint. */
16354 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
16355 GDB is still reading the definitions from command line. First
16356 DW_MACINFO_start_file will need to be ignored as it was already executed
16357 to create CURRENT_FILE for the main source holding also the command line
16358 definitions. On first met DW_MACINFO_start_file this flag is reset to
16359 normally execute all the remaining DW_MACINFO_start_file macinfos. */
16361 at_commandline
= 1;
16365 /* Do we at least have room for a macinfo type byte? */
16366 if (mac_ptr
>= mac_end
)
16368 dwarf2_section_buffer_overflow_complaint (section
);
16372 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16375 /* Note that we rely on the fact that the corresponding GNU and
16376 DWARF constants are the same. */
16377 switch (macinfo_type
)
16379 /* A zero macinfo type indicates the end of the macro
16384 case DW_MACRO_GNU_define
:
16385 case DW_MACRO_GNU_undef
:
16386 case DW_MACRO_GNU_define_indirect
:
16387 case DW_MACRO_GNU_undef_indirect
:
16389 unsigned int bytes_read
;
16394 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16395 mac_ptr
+= bytes_read
;
16397 if (macinfo_type
== DW_MACRO_GNU_define
16398 || macinfo_type
== DW_MACRO_GNU_undef
)
16400 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16401 mac_ptr
+= bytes_read
;
16405 LONGEST str_offset
;
16407 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16408 mac_ptr
+= offset_size
;
16410 body
= read_indirect_string_at_offset (abfd
, str_offset
);
16413 is_define
= (macinfo_type
== DW_MACRO_GNU_define
16414 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
16415 if (! current_file
)
16417 /* DWARF violation as no main source is present. */
16418 complaint (&symfile_complaints
,
16419 _("debug info with no main source gives macro %s "
16421 is_define
? _("definition") : _("undefinition"),
16425 if ((line
== 0 && !at_commandline
)
16426 || (line
!= 0 && at_commandline
))
16427 complaint (&symfile_complaints
,
16428 _("debug info gives %s macro %s with %s line %d: %s"),
16429 at_commandline
? _("command-line") : _("in-file"),
16430 is_define
? _("definition") : _("undefinition"),
16431 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
16434 parse_macro_definition (current_file
, line
, body
);
16437 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
16438 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
16439 macro_undef (current_file
, line
, body
);
16444 case DW_MACRO_GNU_start_file
:
16446 unsigned int bytes_read
;
16449 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16450 mac_ptr
+= bytes_read
;
16451 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16452 mac_ptr
+= bytes_read
;
16454 if ((line
== 0 && !at_commandline
)
16455 || (line
!= 0 && at_commandline
))
16456 complaint (&symfile_complaints
,
16457 _("debug info gives source %d included "
16458 "from %s at %s line %d"),
16459 file
, at_commandline
? _("command-line") : _("file"),
16460 line
== 0 ? _("zero") : _("non-zero"), line
);
16462 if (at_commandline
)
16464 /* This DW_MACRO_GNU_start_file was executed in the
16466 at_commandline
= 0;
16469 current_file
= macro_start_file (file
, line
,
16470 current_file
, comp_dir
,
16475 case DW_MACRO_GNU_end_file
:
16476 if (! current_file
)
16477 complaint (&symfile_complaints
,
16478 _("macro debug info has an unmatched "
16479 "`close_file' directive"));
16482 current_file
= current_file
->included_by
;
16483 if (! current_file
)
16485 enum dwarf_macro_record_type next_type
;
16487 /* GCC circa March 2002 doesn't produce the zero
16488 type byte marking the end of the compilation
16489 unit. Complain if it's not there, but exit no
16492 /* Do we at least have room for a macinfo type byte? */
16493 if (mac_ptr
>= mac_end
)
16495 dwarf2_section_buffer_overflow_complaint (section
);
16499 /* We don't increment mac_ptr here, so this is just
16501 next_type
= read_1_byte (abfd
, mac_ptr
);
16502 if (next_type
!= 0)
16503 complaint (&symfile_complaints
,
16504 _("no terminating 0-type entry for "
16505 "macros in `.debug_macinfo' section"));
16512 case DW_MACRO_GNU_transparent_include
:
16517 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
16518 mac_ptr
+= offset_size
;
16520 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16523 /* This has actually happened; see
16524 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
16525 complaint (&symfile_complaints
,
16526 _("recursive DW_MACRO_GNU_transparent_include in "
16527 ".debug_macro section"));
16533 dwarf_decode_macro_bytes (abfd
,
16534 section
->buffer
+ offset
,
16535 mac_end
, current_file
,
16537 section
, section_is_gnu
,
16538 offset_size
, objfile
, include_hash
);
16540 htab_remove_elt (include_hash
, mac_ptr
);
16545 case DW_MACINFO_vendor_ext
:
16546 if (!section_is_gnu
)
16548 unsigned int bytes_read
;
16551 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16552 mac_ptr
+= bytes_read
;
16553 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16554 mac_ptr
+= bytes_read
;
16556 /* We don't recognize any vendor extensions. */
16562 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16563 mac_ptr
, mac_end
, abfd
, offset_size
,
16565 if (mac_ptr
== NULL
)
16569 } while (macinfo_type
!= 0);
16573 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
16574 char *comp_dir
, int section_is_gnu
)
16576 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16577 struct line_header
*lh
= cu
->line_header
;
16579 gdb_byte
*mac_ptr
, *mac_end
;
16580 struct macro_source_file
*current_file
= 0;
16581 enum dwarf_macro_record_type macinfo_type
;
16582 unsigned int offset_size
= cu
->header
.offset_size
;
16583 gdb_byte
*opcode_definitions
[256];
16584 struct cleanup
*cleanup
;
16585 htab_t include_hash
;
16587 struct dwarf2_section_info
*section
;
16588 const char *section_name
;
16590 if (cu
->dwo_unit
!= NULL
)
16592 if (section_is_gnu
)
16594 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
16595 section_name
= ".debug_macro.dwo";
16599 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
16600 section_name
= ".debug_macinfo.dwo";
16605 if (section_is_gnu
)
16607 section
= &dwarf2_per_objfile
->macro
;
16608 section_name
= ".debug_macro";
16612 section
= &dwarf2_per_objfile
->macinfo
;
16613 section_name
= ".debug_macinfo";
16617 dwarf2_read_section (objfile
, section
);
16618 if (section
->buffer
== NULL
)
16620 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
16623 abfd
= section
->asection
->owner
;
16625 /* First pass: Find the name of the base filename.
16626 This filename is needed in order to process all macros whose definition
16627 (or undefinition) comes from the command line. These macros are defined
16628 before the first DW_MACINFO_start_file entry, and yet still need to be
16629 associated to the base file.
16631 To determine the base file name, we scan the macro definitions until we
16632 reach the first DW_MACINFO_start_file entry. We then initialize
16633 CURRENT_FILE accordingly so that any macro definition found before the
16634 first DW_MACINFO_start_file can still be associated to the base file. */
16636 mac_ptr
= section
->buffer
+ offset
;
16637 mac_end
= section
->buffer
+ section
->size
;
16639 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
16640 &offset_size
, section_is_gnu
);
16641 if (mac_ptr
== NULL
)
16643 /* We already issued a complaint. */
16649 /* Do we at least have room for a macinfo type byte? */
16650 if (mac_ptr
>= mac_end
)
16652 /* Complaint is printed during the second pass as GDB will probably
16653 stop the first pass earlier upon finding
16654 DW_MACINFO_start_file. */
16658 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
16661 /* Note that we rely on the fact that the corresponding GNU and
16662 DWARF constants are the same. */
16663 switch (macinfo_type
)
16665 /* A zero macinfo type indicates the end of the macro
16670 case DW_MACRO_GNU_define
:
16671 case DW_MACRO_GNU_undef
:
16672 /* Only skip the data by MAC_PTR. */
16674 unsigned int bytes_read
;
16676 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16677 mac_ptr
+= bytes_read
;
16678 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16679 mac_ptr
+= bytes_read
;
16683 case DW_MACRO_GNU_start_file
:
16685 unsigned int bytes_read
;
16688 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16689 mac_ptr
+= bytes_read
;
16690 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16691 mac_ptr
+= bytes_read
;
16693 current_file
= macro_start_file (file
, line
, current_file
,
16694 comp_dir
, lh
, objfile
);
16698 case DW_MACRO_GNU_end_file
:
16699 /* No data to skip by MAC_PTR. */
16702 case DW_MACRO_GNU_define_indirect
:
16703 case DW_MACRO_GNU_undef_indirect
:
16705 unsigned int bytes_read
;
16707 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16708 mac_ptr
+= bytes_read
;
16709 mac_ptr
+= offset_size
;
16713 case DW_MACRO_GNU_transparent_include
:
16714 /* Note that, according to the spec, a transparent include
16715 chain cannot call DW_MACRO_GNU_start_file. So, we can just
16716 skip this opcode. */
16717 mac_ptr
+= offset_size
;
16720 case DW_MACINFO_vendor_ext
:
16721 /* Only skip the data by MAC_PTR. */
16722 if (!section_is_gnu
)
16724 unsigned int bytes_read
;
16726 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
16727 mac_ptr
+= bytes_read
;
16728 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
16729 mac_ptr
+= bytes_read
;
16734 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
16735 mac_ptr
, mac_end
, abfd
, offset_size
,
16737 if (mac_ptr
== NULL
)
16741 } while (macinfo_type
!= 0 && current_file
== NULL
);
16743 /* Second pass: Process all entries.
16745 Use the AT_COMMAND_LINE flag to determine whether we are still processing
16746 command-line macro definitions/undefinitions. This flag is unset when we
16747 reach the first DW_MACINFO_start_file entry. */
16749 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
16750 NULL
, xcalloc
, xfree
);
16751 cleanup
= make_cleanup_htab_delete (include_hash
);
16752 mac_ptr
= section
->buffer
+ offset
;
16753 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
16755 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
16756 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
16757 offset_size
, objfile
, include_hash
);
16758 do_cleanups (cleanup
);
16761 /* Check if the attribute's form is a DW_FORM_block*
16762 if so return true else false. */
16765 attr_form_is_block (struct attribute
*attr
)
16767 return (attr
== NULL
? 0 :
16768 attr
->form
== DW_FORM_block1
16769 || attr
->form
== DW_FORM_block2
16770 || attr
->form
== DW_FORM_block4
16771 || attr
->form
== DW_FORM_block
16772 || attr
->form
== DW_FORM_exprloc
);
16775 /* Return non-zero if ATTR's value is a section offset --- classes
16776 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
16777 You may use DW_UNSND (attr) to retrieve such offsets.
16779 Section 7.5.4, "Attribute Encodings", explains that no attribute
16780 may have a value that belongs to more than one of these classes; it
16781 would be ambiguous if we did, because we use the same forms for all
16785 attr_form_is_section_offset (struct attribute
*attr
)
16787 return (attr
->form
== DW_FORM_data4
16788 || attr
->form
== DW_FORM_data8
16789 || attr
->form
== DW_FORM_sec_offset
);
16792 /* Return non-zero if ATTR's value falls in the 'constant' class, or
16793 zero otherwise. When this function returns true, you can apply
16794 dwarf2_get_attr_constant_value to it.
16796 However, note that for some attributes you must check
16797 attr_form_is_section_offset before using this test. DW_FORM_data4
16798 and DW_FORM_data8 are members of both the constant class, and of
16799 the classes that contain offsets into other debug sections
16800 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
16801 that, if an attribute's can be either a constant or one of the
16802 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
16803 taken as section offsets, not constants. */
16806 attr_form_is_constant (struct attribute
*attr
)
16808 switch (attr
->form
)
16810 case DW_FORM_sdata
:
16811 case DW_FORM_udata
:
16812 case DW_FORM_data1
:
16813 case DW_FORM_data2
:
16814 case DW_FORM_data4
:
16815 case DW_FORM_data8
:
16822 /* Return the .debug_loc section to use for CU.
16823 For DWO files use .debug_loc.dwo. */
16825 static struct dwarf2_section_info
*
16826 cu_debug_loc_section (struct dwarf2_cu
*cu
)
16829 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
16830 return &dwarf2_per_objfile
->loc
;
16833 /* A helper function that fills in a dwarf2_loclist_baton. */
16836 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
16837 struct dwarf2_loclist_baton
*baton
,
16838 struct attribute
*attr
)
16840 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16842 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
16844 baton
->per_cu
= cu
->per_cu
;
16845 gdb_assert (baton
->per_cu
);
16846 /* We don't know how long the location list is, but make sure we
16847 don't run off the edge of the section. */
16848 baton
->size
= section
->size
- DW_UNSND (attr
);
16849 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
16850 baton
->base_address
= cu
->base_address
;
16851 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
16855 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
16856 struct dwarf2_cu
*cu
)
16858 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16859 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
16861 if (attr_form_is_section_offset (attr
)
16862 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
16863 the section. If so, fall through to the complaint in the
16865 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
16867 struct dwarf2_loclist_baton
*baton
;
16869 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16870 sizeof (struct dwarf2_loclist_baton
));
16872 fill_in_loclist_baton (cu
, baton
, attr
);
16874 if (cu
->base_known
== 0)
16875 complaint (&symfile_complaints
,
16876 _("Location list used without "
16877 "specifying the CU base address."));
16879 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
16880 SYMBOL_LOCATION_BATON (sym
) = baton
;
16884 struct dwarf2_locexpr_baton
*baton
;
16886 baton
= obstack_alloc (&objfile
->objfile_obstack
,
16887 sizeof (struct dwarf2_locexpr_baton
));
16888 baton
->per_cu
= cu
->per_cu
;
16889 gdb_assert (baton
->per_cu
);
16891 if (attr_form_is_block (attr
))
16893 /* Note that we're just copying the block's data pointer
16894 here, not the actual data. We're still pointing into the
16895 info_buffer for SYM's objfile; right now we never release
16896 that buffer, but when we do clean up properly this may
16898 baton
->size
= DW_BLOCK (attr
)->size
;
16899 baton
->data
= DW_BLOCK (attr
)->data
;
16903 dwarf2_invalid_attrib_class_complaint ("location description",
16904 SYMBOL_NATURAL_NAME (sym
));
16908 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16909 SYMBOL_LOCATION_BATON (sym
) = baton
;
16913 /* Return the OBJFILE associated with the compilation unit CU. If CU
16914 came from a separate debuginfo file, then the master objfile is
16918 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
16920 struct objfile
*objfile
= per_cu
->objfile
;
16922 /* Return the master objfile, so that we can report and look up the
16923 correct file containing this variable. */
16924 if (objfile
->separate_debug_objfile_backlink
)
16925 objfile
= objfile
->separate_debug_objfile_backlink
;
16930 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
16931 (CU_HEADERP is unused in such case) or prepare a temporary copy at
16932 CU_HEADERP first. */
16934 static const struct comp_unit_head
*
16935 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
16936 struct dwarf2_per_cu_data
*per_cu
)
16938 gdb_byte
*info_ptr
;
16941 return &per_cu
->cu
->header
;
16943 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
16945 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
16946 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
16951 /* Return the address size given in the compilation unit header for CU. */
16954 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16956 struct comp_unit_head cu_header_local
;
16957 const struct comp_unit_head
*cu_headerp
;
16959 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16961 return cu_headerp
->addr_size
;
16964 /* Return the offset size given in the compilation unit header for CU. */
16967 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
16969 struct comp_unit_head cu_header_local
;
16970 const struct comp_unit_head
*cu_headerp
;
16972 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16974 return cu_headerp
->offset_size
;
16977 /* See its dwarf2loc.h declaration. */
16980 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
16982 struct comp_unit_head cu_header_local
;
16983 const struct comp_unit_head
*cu_headerp
;
16985 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
16987 if (cu_headerp
->version
== 2)
16988 return cu_headerp
->addr_size
;
16990 return cu_headerp
->offset_size
;
16993 /* Return the text offset of the CU. The returned offset comes from
16994 this CU's objfile. If this objfile came from a separate debuginfo
16995 file, then the offset may be different from the corresponding
16996 offset in the parent objfile. */
16999 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17001 struct objfile
*objfile
= per_cu
->objfile
;
17003 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17006 /* Locate the .debug_info compilation unit from CU's objfile which contains
17007 the DIE at OFFSET. Raises an error on failure. */
17009 static struct dwarf2_per_cu_data
*
17010 dwarf2_find_containing_comp_unit (sect_offset offset
,
17011 struct objfile
*objfile
)
17013 struct dwarf2_per_cu_data
*this_cu
;
17017 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17020 int mid
= low
+ (high
- low
) / 2;
17022 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17023 >= offset
.sect_off
)
17028 gdb_assert (low
== high
);
17029 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17033 error (_("Dwarf Error: could not find partial DIE containing "
17034 "offset 0x%lx [in module %s]"),
17035 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17037 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17038 <= offset
.sect_off
);
17039 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17043 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17044 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17045 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17046 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17047 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17052 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17055 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17057 memset (cu
, 0, sizeof (*cu
));
17059 cu
->per_cu
= per_cu
;
17060 cu
->objfile
= per_cu
->objfile
;
17061 obstack_init (&cu
->comp_unit_obstack
);
17064 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17067 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17068 enum language pretend_language
)
17070 struct attribute
*attr
;
17072 /* Set the language we're debugging. */
17073 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17075 set_cu_language (DW_UNSND (attr
), cu
);
17078 cu
->language
= pretend_language
;
17079 cu
->language_defn
= language_def (cu
->language
);
17082 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17084 cu
->producer
= DW_STRING (attr
);
17087 /* Release one cached compilation unit, CU. We unlink it from the tree
17088 of compilation units, but we don't remove it from the read_in_chain;
17089 the caller is responsible for that.
17090 NOTE: DATA is a void * because this function is also used as a
17091 cleanup routine. */
17094 free_heap_comp_unit (void *data
)
17096 struct dwarf2_cu
*cu
= data
;
17098 gdb_assert (cu
->per_cu
!= NULL
);
17099 cu
->per_cu
->cu
= NULL
;
17102 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17107 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17108 when we're finished with it. We can't free the pointer itself, but be
17109 sure to unlink it from the cache. Also release any associated storage. */
17112 free_stack_comp_unit (void *data
)
17114 struct dwarf2_cu
*cu
= data
;
17116 gdb_assert (cu
->per_cu
!= NULL
);
17117 cu
->per_cu
->cu
= NULL
;
17120 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17121 cu
->partial_dies
= NULL
;
17124 /* Free all cached compilation units. */
17127 free_cached_comp_units (void *data
)
17129 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17131 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17132 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17133 while (per_cu
!= NULL
)
17135 struct dwarf2_per_cu_data
*next_cu
;
17137 next_cu
= per_cu
->cu
->read_in_chain
;
17139 free_heap_comp_unit (per_cu
->cu
);
17140 *last_chain
= next_cu
;
17146 /* Increase the age counter on each cached compilation unit, and free
17147 any that are too old. */
17150 age_cached_comp_units (void)
17152 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17154 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
17155 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17156 while (per_cu
!= NULL
)
17158 per_cu
->cu
->last_used
++;
17159 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
17160 dwarf2_mark (per_cu
->cu
);
17161 per_cu
= per_cu
->cu
->read_in_chain
;
17164 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17165 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17166 while (per_cu
!= NULL
)
17168 struct dwarf2_per_cu_data
*next_cu
;
17170 next_cu
= per_cu
->cu
->read_in_chain
;
17172 if (!per_cu
->cu
->mark
)
17174 free_heap_comp_unit (per_cu
->cu
);
17175 *last_chain
= next_cu
;
17178 last_chain
= &per_cu
->cu
->read_in_chain
;
17184 /* Remove a single compilation unit from the cache. */
17187 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
17189 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17191 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17192 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17193 while (per_cu
!= NULL
)
17195 struct dwarf2_per_cu_data
*next_cu
;
17197 next_cu
= per_cu
->cu
->read_in_chain
;
17199 if (per_cu
== target_per_cu
)
17201 free_heap_comp_unit (per_cu
->cu
);
17203 *last_chain
= next_cu
;
17207 last_chain
= &per_cu
->cu
->read_in_chain
;
17213 /* Release all extra memory associated with OBJFILE. */
17216 dwarf2_free_objfile (struct objfile
*objfile
)
17218 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
17220 if (dwarf2_per_objfile
== NULL
)
17223 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
17224 free_cached_comp_units (NULL
);
17226 if (dwarf2_per_objfile
->quick_file_names_table
)
17227 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
17229 /* Everything else should be on the objfile obstack. */
17232 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
17233 We store these in a hash table separate from the DIEs, and preserve them
17234 when the DIEs are flushed out of cache.
17236 The CU "per_cu" pointer is needed because offset alone is not enough to
17237 uniquely identify the type. A file may have multiple .debug_types sections,
17238 or the type may come from a DWO file. We have to use something in
17239 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
17240 routine, get_die_type_at_offset, from outside this file, and thus won't
17241 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
17244 struct dwarf2_per_cu_offset_and_type
17246 const struct dwarf2_per_cu_data
*per_cu
;
17247 sect_offset offset
;
17251 /* Hash function for a dwarf2_per_cu_offset_and_type. */
17254 per_cu_offset_and_type_hash (const void *item
)
17256 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
17258 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
17261 /* Equality function for a dwarf2_per_cu_offset_and_type. */
17264 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
17266 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
17267 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
17269 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
17270 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
17273 /* Set the type associated with DIE to TYPE. Save it in CU's hash
17274 table if necessary. For convenience, return TYPE.
17276 The DIEs reading must have careful ordering to:
17277 * Not cause infite loops trying to read in DIEs as a prerequisite for
17278 reading current DIE.
17279 * Not trying to dereference contents of still incompletely read in types
17280 while reading in other DIEs.
17281 * Enable referencing still incompletely read in types just by a pointer to
17282 the type without accessing its fields.
17284 Therefore caller should follow these rules:
17285 * Try to fetch any prerequisite types we may need to build this DIE type
17286 before building the type and calling set_die_type.
17287 * After building type call set_die_type for current DIE as soon as
17288 possible before fetching more types to complete the current type.
17289 * Make the type as complete as possible before fetching more types. */
17291 static struct type
*
17292 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
17294 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
17295 struct objfile
*objfile
= cu
->objfile
;
17297 /* For Ada types, make sure that the gnat-specific data is always
17298 initialized (if not already set). There are a few types where
17299 we should not be doing so, because the type-specific area is
17300 already used to hold some other piece of info (eg: TYPE_CODE_FLT
17301 where the type-specific area is used to store the floatformat).
17302 But this is not a problem, because the gnat-specific information
17303 is actually not needed for these types. */
17304 if (need_gnat_info (cu
)
17305 && TYPE_CODE (type
) != TYPE_CODE_FUNC
17306 && TYPE_CODE (type
) != TYPE_CODE_FLT
17307 && !HAVE_GNAT_AUX_INFO (type
))
17308 INIT_GNAT_SPECIFIC (type
);
17310 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17312 dwarf2_per_objfile
->die_type_hash
=
17313 htab_create_alloc_ex (127,
17314 per_cu_offset_and_type_hash
,
17315 per_cu_offset_and_type_eq
,
17317 &objfile
->objfile_obstack
,
17318 hashtab_obstack_allocate
,
17319 dummy_obstack_deallocate
);
17322 ofs
.per_cu
= cu
->per_cu
;
17323 ofs
.offset
= die
->offset
;
17325 slot
= (struct dwarf2_per_cu_offset_and_type
**)
17326 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
17328 complaint (&symfile_complaints
,
17329 _("A problem internal to GDB: DIE 0x%x has type already set"),
17330 die
->offset
.sect_off
);
17331 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
17336 /* Look up the type for the die at OFFSET in the appropriate type_hash
17337 table, or return NULL if the die does not have a saved type. */
17339 static struct type
*
17340 get_die_type_at_offset (sect_offset offset
,
17341 struct dwarf2_per_cu_data
*per_cu
)
17343 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
17345 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
17348 ofs
.per_cu
= per_cu
;
17349 ofs
.offset
= offset
;
17350 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
17357 /* Look up the type for DIE in the appropriate type_hash table,
17358 or return NULL if DIE does not have a saved type. */
17360 static struct type
*
17361 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17363 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
17366 /* Add a dependence relationship from CU to REF_PER_CU. */
17369 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
17370 struct dwarf2_per_cu_data
*ref_per_cu
)
17374 if (cu
->dependencies
== NULL
)
17376 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
17377 NULL
, &cu
->comp_unit_obstack
,
17378 hashtab_obstack_allocate
,
17379 dummy_obstack_deallocate
);
17381 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
17383 *slot
= ref_per_cu
;
17386 /* Subroutine of dwarf2_mark to pass to htab_traverse.
17387 Set the mark field in every compilation unit in the
17388 cache that we must keep because we are keeping CU. */
17391 dwarf2_mark_helper (void **slot
, void *data
)
17393 struct dwarf2_per_cu_data
*per_cu
;
17395 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
17397 /* cu->dependencies references may not yet have been ever read if QUIT aborts
17398 reading of the chain. As such dependencies remain valid it is not much
17399 useful to track and undo them during QUIT cleanups. */
17400 if (per_cu
->cu
== NULL
)
17403 if (per_cu
->cu
->mark
)
17405 per_cu
->cu
->mark
= 1;
17407 if (per_cu
->cu
->dependencies
!= NULL
)
17408 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17413 /* Set the mark field in CU and in every other compilation unit in the
17414 cache that we must keep because we are keeping CU. */
17417 dwarf2_mark (struct dwarf2_cu
*cu
)
17422 if (cu
->dependencies
!= NULL
)
17423 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
17427 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
17431 per_cu
->cu
->mark
= 0;
17432 per_cu
= per_cu
->cu
->read_in_chain
;
17436 /* Trivial hash function for partial_die_info: the hash value of a DIE
17437 is its offset in .debug_info for this objfile. */
17440 partial_die_hash (const void *item
)
17442 const struct partial_die_info
*part_die
= item
;
17444 return part_die
->offset
.sect_off
;
17447 /* Trivial comparison function for partial_die_info structures: two DIEs
17448 are equal if they have the same offset. */
17451 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
17453 const struct partial_die_info
*part_die_lhs
= item_lhs
;
17454 const struct partial_die_info
*part_die_rhs
= item_rhs
;
17456 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
17459 static struct cmd_list_element
*set_dwarf2_cmdlist
;
17460 static struct cmd_list_element
*show_dwarf2_cmdlist
;
17463 set_dwarf2_cmd (char *args
, int from_tty
)
17465 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
17469 show_dwarf2_cmd (char *args
, int from_tty
)
17471 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
17474 /* If section described by INFO was mmapped, munmap it now. */
17477 munmap_section_buffer (struct dwarf2_section_info
*info
)
17479 if (info
->map_addr
!= NULL
)
17484 res
= munmap (info
->map_addr
, info
->map_len
);
17485 gdb_assert (res
== 0);
17487 /* Without HAVE_MMAP, we should never be here to begin with. */
17488 gdb_assert_not_reached ("no mmap support");
17493 /* munmap debug sections for OBJFILE, if necessary. */
17496 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
17498 struct dwarf2_per_objfile
*data
= d
;
17500 struct dwarf2_section_info
*section
;
17502 /* This is sorted according to the order they're defined in to make it easier
17503 to keep in sync. */
17504 munmap_section_buffer (&data
->info
);
17505 munmap_section_buffer (&data
->abbrev
);
17506 munmap_section_buffer (&data
->line
);
17507 munmap_section_buffer (&data
->loc
);
17508 munmap_section_buffer (&data
->macinfo
);
17509 munmap_section_buffer (&data
->macro
);
17510 munmap_section_buffer (&data
->str
);
17511 munmap_section_buffer (&data
->ranges
);
17512 munmap_section_buffer (&data
->addr
);
17513 munmap_section_buffer (&data
->frame
);
17514 munmap_section_buffer (&data
->eh_frame
);
17515 munmap_section_buffer (&data
->gdb_index
);
17518 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
17520 munmap_section_buffer (section
);
17522 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
17523 VEC_free (dwarf2_per_cu_ptr
,
17524 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
17526 VEC_free (dwarf2_section_info_def
, data
->types
);
17528 if (data
->dwo_files
)
17529 free_dwo_files (data
->dwo_files
, objfile
);
17533 /* The "save gdb-index" command. */
17535 /* The contents of the hash table we create when building the string
17537 struct strtab_entry
17539 offset_type offset
;
17543 /* Hash function for a strtab_entry.
17545 Function is used only during write_hash_table so no index format backward
17546 compatibility is needed. */
17549 hash_strtab_entry (const void *e
)
17551 const struct strtab_entry
*entry
= e
;
17552 return mapped_index_string_hash (INT_MAX
, entry
->str
);
17555 /* Equality function for a strtab_entry. */
17558 eq_strtab_entry (const void *a
, const void *b
)
17560 const struct strtab_entry
*ea
= a
;
17561 const struct strtab_entry
*eb
= b
;
17562 return !strcmp (ea
->str
, eb
->str
);
17565 /* Create a strtab_entry hash table. */
17568 create_strtab (void)
17570 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
17571 xfree
, xcalloc
, xfree
);
17574 /* Add a string to the constant pool. Return the string's offset in
17578 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
17581 struct strtab_entry entry
;
17582 struct strtab_entry
*result
;
17585 slot
= htab_find_slot (table
, &entry
, INSERT
);
17590 result
= XNEW (struct strtab_entry
);
17591 result
->offset
= obstack_object_size (cpool
);
17593 obstack_grow_str0 (cpool
, str
);
17596 return result
->offset
;
17599 /* An entry in the symbol table. */
17600 struct symtab_index_entry
17602 /* The name of the symbol. */
17604 /* The offset of the name in the constant pool. */
17605 offset_type index_offset
;
17606 /* A sorted vector of the indices of all the CUs that hold an object
17608 VEC (offset_type
) *cu_indices
;
17611 /* The symbol table. This is a power-of-2-sized hash table. */
17612 struct mapped_symtab
17614 offset_type n_elements
;
17616 struct symtab_index_entry
**data
;
17619 /* Hash function for a symtab_index_entry. */
17622 hash_symtab_entry (const void *e
)
17624 const struct symtab_index_entry
*entry
= e
;
17625 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
17626 sizeof (offset_type
) * VEC_length (offset_type
,
17627 entry
->cu_indices
),
17631 /* Equality function for a symtab_index_entry. */
17634 eq_symtab_entry (const void *a
, const void *b
)
17636 const struct symtab_index_entry
*ea
= a
;
17637 const struct symtab_index_entry
*eb
= b
;
17638 int len
= VEC_length (offset_type
, ea
->cu_indices
);
17639 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
17641 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
17642 VEC_address (offset_type
, eb
->cu_indices
),
17643 sizeof (offset_type
) * len
);
17646 /* Destroy a symtab_index_entry. */
17649 delete_symtab_entry (void *p
)
17651 struct symtab_index_entry
*entry
= p
;
17652 VEC_free (offset_type
, entry
->cu_indices
);
17656 /* Create a hash table holding symtab_index_entry objects. */
17659 create_symbol_hash_table (void)
17661 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
17662 delete_symtab_entry
, xcalloc
, xfree
);
17665 /* Create a new mapped symtab object. */
17667 static struct mapped_symtab
*
17668 create_mapped_symtab (void)
17670 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
17671 symtab
->n_elements
= 0;
17672 symtab
->size
= 1024;
17673 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17677 /* Destroy a mapped_symtab. */
17680 cleanup_mapped_symtab (void *p
)
17682 struct mapped_symtab
*symtab
= p
;
17683 /* The contents of the array are freed when the other hash table is
17685 xfree (symtab
->data
);
17689 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
17692 Function is used only during write_hash_table so no index format backward
17693 compatibility is needed. */
17695 static struct symtab_index_entry
**
17696 find_slot (struct mapped_symtab
*symtab
, const char *name
)
17698 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
17700 index
= hash
& (symtab
->size
- 1);
17701 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
17705 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
17706 return &symtab
->data
[index
];
17707 index
= (index
+ step
) & (symtab
->size
- 1);
17711 /* Expand SYMTAB's hash table. */
17714 hash_expand (struct mapped_symtab
*symtab
)
17716 offset_type old_size
= symtab
->size
;
17718 struct symtab_index_entry
**old_entries
= symtab
->data
;
17721 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
17723 for (i
= 0; i
< old_size
; ++i
)
17725 if (old_entries
[i
])
17727 struct symtab_index_entry
**slot
= find_slot (symtab
,
17728 old_entries
[i
]->name
);
17729 *slot
= old_entries
[i
];
17733 xfree (old_entries
);
17736 /* Add an entry to SYMTAB. NAME is the name of the symbol.
17737 CU_INDEX is the index of the CU in which the symbol appears.
17738 IS_STATIC is one if the symbol is static, otherwise zero (global). */
17741 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
17742 int is_static
, gdb_index_symbol_kind kind
,
17743 offset_type cu_index
)
17745 struct symtab_index_entry
**slot
;
17746 offset_type cu_index_and_attrs
;
17748 ++symtab
->n_elements
;
17749 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
17750 hash_expand (symtab
);
17752 slot
= find_slot (symtab
, name
);
17755 *slot
= XNEW (struct symtab_index_entry
);
17756 (*slot
)->name
= name
;
17757 /* index_offset is set later. */
17758 (*slot
)->cu_indices
= NULL
;
17761 cu_index_and_attrs
= 0;
17762 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
17763 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
17764 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
17766 /* We don't want to record an index value twice as we want to avoid the
17768 We process all global symbols and then all static symbols
17769 (which would allow us to avoid the duplication by only having to check
17770 the last entry pushed), but a symbol could have multiple kinds in one CU.
17771 To keep things simple we don't worry about the duplication here and
17772 sort and uniqufy the list after we've processed all symbols. */
17773 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
17776 /* qsort helper routine for uniquify_cu_indices. */
17779 offset_type_compare (const void *ap
, const void *bp
)
17781 offset_type a
= *(offset_type
*) ap
;
17782 offset_type b
= *(offset_type
*) bp
;
17784 return (a
> b
) - (b
> a
);
17787 /* Sort and remove duplicates of all symbols' cu_indices lists. */
17790 uniquify_cu_indices (struct mapped_symtab
*symtab
)
17794 for (i
= 0; i
< symtab
->size
; ++i
)
17796 struct symtab_index_entry
*entry
= symtab
->data
[i
];
17799 && entry
->cu_indices
!= NULL
)
17801 unsigned int next_to_insert
, next_to_check
;
17802 offset_type last_value
;
17804 qsort (VEC_address (offset_type
, entry
->cu_indices
),
17805 VEC_length (offset_type
, entry
->cu_indices
),
17806 sizeof (offset_type
), offset_type_compare
);
17808 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
17809 next_to_insert
= 1;
17810 for (next_to_check
= 1;
17811 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
17814 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
17817 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
17819 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
17824 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
17829 /* Add a vector of indices to the constant pool. */
17832 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
17833 struct symtab_index_entry
*entry
)
17837 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
17840 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
17841 offset_type val
= MAYBE_SWAP (len
);
17846 entry
->index_offset
= obstack_object_size (cpool
);
17848 obstack_grow (cpool
, &val
, sizeof (val
));
17850 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
17853 val
= MAYBE_SWAP (iter
);
17854 obstack_grow (cpool
, &val
, sizeof (val
));
17859 struct symtab_index_entry
*old_entry
= *slot
;
17860 entry
->index_offset
= old_entry
->index_offset
;
17863 return entry
->index_offset
;
17866 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
17867 constant pool entries going into the obstack CPOOL. */
17870 write_hash_table (struct mapped_symtab
*symtab
,
17871 struct obstack
*output
, struct obstack
*cpool
)
17874 htab_t symbol_hash_table
;
17877 symbol_hash_table
= create_symbol_hash_table ();
17878 str_table
= create_strtab ();
17880 /* We add all the index vectors to the constant pool first, to
17881 ensure alignment is ok. */
17882 for (i
= 0; i
< symtab
->size
; ++i
)
17884 if (symtab
->data
[i
])
17885 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
17888 /* Now write out the hash table. */
17889 for (i
= 0; i
< symtab
->size
; ++i
)
17891 offset_type str_off
, vec_off
;
17893 if (symtab
->data
[i
])
17895 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
17896 vec_off
= symtab
->data
[i
]->index_offset
;
17900 /* While 0 is a valid constant pool index, it is not valid
17901 to have 0 for both offsets. */
17906 str_off
= MAYBE_SWAP (str_off
);
17907 vec_off
= MAYBE_SWAP (vec_off
);
17909 obstack_grow (output
, &str_off
, sizeof (str_off
));
17910 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
17913 htab_delete (str_table
);
17914 htab_delete (symbol_hash_table
);
17917 /* Struct to map psymtab to CU index in the index file. */
17918 struct psymtab_cu_index_map
17920 struct partial_symtab
*psymtab
;
17921 unsigned int cu_index
;
17925 hash_psymtab_cu_index (const void *item
)
17927 const struct psymtab_cu_index_map
*map
= item
;
17929 return htab_hash_pointer (map
->psymtab
);
17933 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
17935 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
17936 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
17938 return lhs
->psymtab
== rhs
->psymtab
;
17941 /* Helper struct for building the address table. */
17942 struct addrmap_index_data
17944 struct objfile
*objfile
;
17945 struct obstack
*addr_obstack
;
17946 htab_t cu_index_htab
;
17948 /* Non-zero if the previous_* fields are valid.
17949 We can't write an entry until we see the next entry (since it is only then
17950 that we know the end of the entry). */
17951 int previous_valid
;
17952 /* Index of the CU in the table of all CUs in the index file. */
17953 unsigned int previous_cu_index
;
17954 /* Start address of the CU. */
17955 CORE_ADDR previous_cu_start
;
17958 /* Write an address entry to OBSTACK. */
17961 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
17962 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
17964 offset_type cu_index_to_write
;
17966 CORE_ADDR baseaddr
;
17968 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17970 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
17971 obstack_grow (obstack
, addr
, 8);
17972 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
17973 obstack_grow (obstack
, addr
, 8);
17974 cu_index_to_write
= MAYBE_SWAP (cu_index
);
17975 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
17978 /* Worker function for traversing an addrmap to build the address table. */
17981 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
17983 struct addrmap_index_data
*data
= datap
;
17984 struct partial_symtab
*pst
= obj
;
17986 if (data
->previous_valid
)
17987 add_address_entry (data
->objfile
, data
->addr_obstack
,
17988 data
->previous_cu_start
, start_addr
,
17989 data
->previous_cu_index
);
17991 data
->previous_cu_start
= start_addr
;
17994 struct psymtab_cu_index_map find_map
, *map
;
17995 find_map
.psymtab
= pst
;
17996 map
= htab_find (data
->cu_index_htab
, &find_map
);
17997 gdb_assert (map
!= NULL
);
17998 data
->previous_cu_index
= map
->cu_index
;
17999 data
->previous_valid
= 1;
18002 data
->previous_valid
= 0;
18007 /* Write OBJFILE's address map to OBSTACK.
18008 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18009 in the index file. */
18012 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18013 htab_t cu_index_htab
)
18015 struct addrmap_index_data addrmap_index_data
;
18017 /* When writing the address table, we have to cope with the fact that
18018 the addrmap iterator only provides the start of a region; we have to
18019 wait until the next invocation to get the start of the next region. */
18021 addrmap_index_data
.objfile
= objfile
;
18022 addrmap_index_data
.addr_obstack
= obstack
;
18023 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18024 addrmap_index_data
.previous_valid
= 0;
18026 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18027 &addrmap_index_data
);
18029 /* It's highly unlikely the last entry (end address = 0xff...ff)
18030 is valid, but we should still handle it.
18031 The end address is recorded as the start of the next region, but that
18032 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18034 if (addrmap_index_data
.previous_valid
)
18035 add_address_entry (objfile
, obstack
,
18036 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18037 addrmap_index_data
.previous_cu_index
);
18040 /* Return the symbol kind of PSYM. */
18042 static gdb_index_symbol_kind
18043 symbol_kind (struct partial_symbol
*psym
)
18045 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
18046 enum address_class aclass
= PSYMBOL_CLASS (psym
);
18054 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
18056 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18058 case LOC_CONST_BYTES
:
18059 case LOC_OPTIMIZED_OUT
:
18061 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18063 /* Note: It's currently impossible to recognize psyms as enum values
18064 short of reading the type info. For now punt. */
18065 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18067 /* There are other LOC_FOO values that one might want to classify
18068 as variables, but dwarf2read.c doesn't currently use them. */
18069 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18071 case STRUCT_DOMAIN
:
18072 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18074 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18078 /* Add a list of partial symbols to SYMTAB. */
18081 write_psymbols (struct mapped_symtab
*symtab
,
18083 struct partial_symbol
**psymp
,
18085 offset_type cu_index
,
18088 for (; count
-- > 0; ++psymp
)
18090 struct partial_symbol
*psym
= *psymp
;
18093 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18094 error (_("Ada is not currently supported by the index"));
18096 /* Only add a given psymbol once. */
18097 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18100 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18103 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18104 is_static
, kind
, cu_index
);
18109 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18110 exception if there is an error. */
18113 write_obstack (FILE *file
, struct obstack
*obstack
)
18115 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18117 != obstack_object_size (obstack
))
18118 error (_("couldn't data write to file"));
18121 /* Unlink a file if the argument is not NULL. */
18124 unlink_if_set (void *p
)
18126 char **filename
= p
;
18128 unlink (*filename
);
18131 /* A helper struct used when iterating over debug_types. */
18132 struct signatured_type_index_data
18134 struct objfile
*objfile
;
18135 struct mapped_symtab
*symtab
;
18136 struct obstack
*types_list
;
18141 /* A helper function that writes a single signatured_type to an
18145 write_one_signatured_type (void **slot
, void *d
)
18147 struct signatured_type_index_data
*info
= d
;
18148 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
18149 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
18150 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18153 write_psymbols (info
->symtab
,
18155 info
->objfile
->global_psymbols
.list
18156 + psymtab
->globals_offset
,
18157 psymtab
->n_global_syms
, info
->cu_index
,
18159 write_psymbols (info
->symtab
,
18161 info
->objfile
->static_psymbols
.list
18162 + psymtab
->statics_offset
,
18163 psymtab
->n_static_syms
, info
->cu_index
,
18166 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18167 entry
->per_cu
.offset
.sect_off
);
18168 obstack_grow (info
->types_list
, val
, 8);
18169 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18170 entry
->type_offset_in_tu
.cu_off
);
18171 obstack_grow (info
->types_list
, val
, 8);
18172 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
18173 obstack_grow (info
->types_list
, val
, 8);
18180 /* Recurse into all "included" dependencies and write their symbols as
18181 if they appeared in this psymtab. */
18184 recursively_write_psymbols (struct objfile
*objfile
,
18185 struct partial_symtab
*psymtab
,
18186 struct mapped_symtab
*symtab
,
18188 offset_type cu_index
)
18192 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
18193 if (psymtab
->dependencies
[i
]->user
!= NULL
)
18194 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
18195 symtab
, psyms_seen
, cu_index
);
18197 write_psymbols (symtab
,
18199 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
18200 psymtab
->n_global_syms
, cu_index
,
18202 write_psymbols (symtab
,
18204 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
18205 psymtab
->n_static_syms
, cu_index
,
18209 /* Create an index file for OBJFILE in the directory DIR. */
18212 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
18214 struct cleanup
*cleanup
;
18215 char *filename
, *cleanup_filename
;
18216 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
18217 struct obstack cu_list
, types_cu_list
;
18220 struct mapped_symtab
*symtab
;
18221 offset_type val
, size_of_contents
, total_len
;
18224 htab_t cu_index_htab
;
18225 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
18227 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
18230 if (dwarf2_per_objfile
->using_index
)
18231 error (_("Cannot use an index to create the index"));
18233 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
18234 error (_("Cannot make an index when the file has multiple .debug_types sections"));
18236 if (stat (objfile
->name
, &st
) < 0)
18237 perror_with_name (objfile
->name
);
18239 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
18240 INDEX_SUFFIX
, (char *) NULL
);
18241 cleanup
= make_cleanup (xfree
, filename
);
18243 out_file
= fopen (filename
, "wb");
18245 error (_("Can't open `%s' for writing"), filename
);
18247 cleanup_filename
= filename
;
18248 make_cleanup (unlink_if_set
, &cleanup_filename
);
18250 symtab
= create_mapped_symtab ();
18251 make_cleanup (cleanup_mapped_symtab
, symtab
);
18253 obstack_init (&addr_obstack
);
18254 make_cleanup_obstack_free (&addr_obstack
);
18256 obstack_init (&cu_list
);
18257 make_cleanup_obstack_free (&cu_list
);
18259 obstack_init (&types_cu_list
);
18260 make_cleanup_obstack_free (&types_cu_list
);
18262 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
18263 NULL
, xcalloc
, xfree
);
18264 make_cleanup_htab_delete (psyms_seen
);
18266 /* While we're scanning CU's create a table that maps a psymtab pointer
18267 (which is what addrmap records) to its index (which is what is recorded
18268 in the index file). This will later be needed to write the address
18270 cu_index_htab
= htab_create_alloc (100,
18271 hash_psymtab_cu_index
,
18272 eq_psymtab_cu_index
,
18273 NULL
, xcalloc
, xfree
);
18274 make_cleanup_htab_delete (cu_index_htab
);
18275 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
18276 xmalloc (sizeof (struct psymtab_cu_index_map
)
18277 * dwarf2_per_objfile
->n_comp_units
);
18278 make_cleanup (xfree
, psymtab_cu_index_map
);
18280 /* The CU list is already sorted, so we don't need to do additional
18281 work here. Also, the debug_types entries do not appear in
18282 all_comp_units, but only in their own hash table. */
18283 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
18285 struct dwarf2_per_cu_data
*per_cu
18286 = dwarf2_per_objfile
->all_comp_units
[i
];
18287 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
18289 struct psymtab_cu_index_map
*map
;
18292 if (psymtab
->user
== NULL
)
18293 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
18295 map
= &psymtab_cu_index_map
[i
];
18296 map
->psymtab
= psymtab
;
18298 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
18299 gdb_assert (slot
!= NULL
);
18300 gdb_assert (*slot
== NULL
);
18303 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
18304 per_cu
->offset
.sect_off
);
18305 obstack_grow (&cu_list
, val
, 8);
18306 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
18307 obstack_grow (&cu_list
, val
, 8);
18310 /* Dump the address map. */
18311 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
18313 /* Write out the .debug_type entries, if any. */
18314 if (dwarf2_per_objfile
->signatured_types
)
18316 struct signatured_type_index_data sig_data
;
18318 sig_data
.objfile
= objfile
;
18319 sig_data
.symtab
= symtab
;
18320 sig_data
.types_list
= &types_cu_list
;
18321 sig_data
.psyms_seen
= psyms_seen
;
18322 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
18323 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
18324 write_one_signatured_type
, &sig_data
);
18327 /* Now that we've processed all symbols we can shrink their cu_indices
18329 uniquify_cu_indices (symtab
);
18331 obstack_init (&constant_pool
);
18332 make_cleanup_obstack_free (&constant_pool
);
18333 obstack_init (&symtab_obstack
);
18334 make_cleanup_obstack_free (&symtab_obstack
);
18335 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
18337 obstack_init (&contents
);
18338 make_cleanup_obstack_free (&contents
);
18339 size_of_contents
= 6 * sizeof (offset_type
);
18340 total_len
= size_of_contents
;
18342 /* The version number. */
18343 val
= MAYBE_SWAP (7);
18344 obstack_grow (&contents
, &val
, sizeof (val
));
18346 /* The offset of the CU list from the start of the file. */
18347 val
= MAYBE_SWAP (total_len
);
18348 obstack_grow (&contents
, &val
, sizeof (val
));
18349 total_len
+= obstack_object_size (&cu_list
);
18351 /* The offset of the types CU list from the start of the file. */
18352 val
= MAYBE_SWAP (total_len
);
18353 obstack_grow (&contents
, &val
, sizeof (val
));
18354 total_len
+= obstack_object_size (&types_cu_list
);
18356 /* The offset of the address table from the start of the file. */
18357 val
= MAYBE_SWAP (total_len
);
18358 obstack_grow (&contents
, &val
, sizeof (val
));
18359 total_len
+= obstack_object_size (&addr_obstack
);
18361 /* The offset of the symbol table from the start of the file. */
18362 val
= MAYBE_SWAP (total_len
);
18363 obstack_grow (&contents
, &val
, sizeof (val
));
18364 total_len
+= obstack_object_size (&symtab_obstack
);
18366 /* The offset of the constant pool from the start of the file. */
18367 val
= MAYBE_SWAP (total_len
);
18368 obstack_grow (&contents
, &val
, sizeof (val
));
18369 total_len
+= obstack_object_size (&constant_pool
);
18371 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
18373 write_obstack (out_file
, &contents
);
18374 write_obstack (out_file
, &cu_list
);
18375 write_obstack (out_file
, &types_cu_list
);
18376 write_obstack (out_file
, &addr_obstack
);
18377 write_obstack (out_file
, &symtab_obstack
);
18378 write_obstack (out_file
, &constant_pool
);
18382 /* We want to keep the file, so we set cleanup_filename to NULL
18383 here. See unlink_if_set. */
18384 cleanup_filename
= NULL
;
18386 do_cleanups (cleanup
);
18389 /* Implementation of the `save gdb-index' command.
18391 Note that the file format used by this command is documented in the
18392 GDB manual. Any changes here must be documented there. */
18395 save_gdb_index_command (char *arg
, int from_tty
)
18397 struct objfile
*objfile
;
18400 error (_("usage: save gdb-index DIRECTORY"));
18402 ALL_OBJFILES (objfile
)
18406 /* If the objfile does not correspond to an actual file, skip it. */
18407 if (stat (objfile
->name
, &st
) < 0)
18410 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18411 if (dwarf2_per_objfile
)
18413 volatile struct gdb_exception except
;
18415 TRY_CATCH (except
, RETURN_MASK_ERROR
)
18417 write_psymtabs_to_index (objfile
, arg
);
18419 if (except
.reason
< 0)
18420 exception_fprintf (gdb_stderr
, except
,
18421 _("Error while writing index for `%s': "),
18429 int dwarf2_always_disassemble
;
18432 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
18433 struct cmd_list_element
*c
, const char *value
)
18435 fprintf_filtered (file
,
18436 _("Whether to always disassemble "
18437 "DWARF expressions is %s.\n"),
18442 show_check_physname (struct ui_file
*file
, int from_tty
,
18443 struct cmd_list_element
*c
, const char *value
)
18445 fprintf_filtered (file
,
18446 _("Whether to check \"physname\" is %s.\n"),
18450 void _initialize_dwarf2_read (void);
18453 _initialize_dwarf2_read (void)
18455 struct cmd_list_element
*c
;
18457 dwarf2_objfile_data_key
18458 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
18460 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
18461 Set DWARF 2 specific variables.\n\
18462 Configure DWARF 2 variables such as the cache size"),
18463 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
18464 0/*allow-unknown*/, &maintenance_set_cmdlist
);
18466 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
18467 Show DWARF 2 specific variables\n\
18468 Show DWARF 2 variables such as the cache size"),
18469 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
18470 0/*allow-unknown*/, &maintenance_show_cmdlist
);
18472 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
18473 &dwarf2_max_cache_age
, _("\
18474 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
18475 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
18476 A higher limit means that cached compilation units will be stored\n\
18477 in memory longer, and more total memory will be used. Zero disables\n\
18478 caching, which can slow down startup."),
18480 show_dwarf2_max_cache_age
,
18481 &set_dwarf2_cmdlist
,
18482 &show_dwarf2_cmdlist
);
18484 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
18485 &dwarf2_always_disassemble
, _("\
18486 Set whether `info address' always disassembles DWARF expressions."), _("\
18487 Show whether `info address' always disassembles DWARF expressions."), _("\
18488 When enabled, DWARF expressions are always printed in an assembly-like\n\
18489 syntax. When disabled, expressions will be printed in a more\n\
18490 conversational style, when possible."),
18492 show_dwarf2_always_disassemble
,
18493 &set_dwarf2_cmdlist
,
18494 &show_dwarf2_cmdlist
);
18496 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
18497 Set debugging of the dwarf2 reader."), _("\
18498 Show debugging of the dwarf2 reader."), _("\
18499 When enabled, debugging messages are printed during dwarf2 reading\n\
18500 and symtab expansion."),
18503 &setdebuglist
, &showdebuglist
);
18505 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
18506 Set debugging of the dwarf2 DIE reader."), _("\
18507 Show debugging of the dwarf2 DIE reader."), _("\
18508 When enabled (non-zero), DIEs are dumped after they are read in.\n\
18509 The value is the maximum depth to print."),
18512 &setdebuglist
, &showdebuglist
);
18514 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
18515 Set cross-checking of \"physname\" code against demangler."), _("\
18516 Show cross-checking of \"physname\" code against demangler."), _("\
18517 When enabled, GDB's internal \"physname\" code is checked against\n\
18519 NULL
, show_check_physname
,
18520 &setdebuglist
, &showdebuglist
);
18522 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
18524 Save a gdb-index file.\n\
18525 Usage: save gdb-index DIRECTORY"),
18527 set_cmd_completer (c
, filename_completer
);