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"
70 #include "gdb_string.h"
71 #include "gdb_assert.h"
72 #include <sys/types.h>
79 #define MAP_FAILED ((void *) -1)
83 typedef struct symbol
*symbolp
;
86 /* When non-zero, print basic high level tracing messages.
87 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
88 static int dwarf2_read_debug
= 0;
90 /* When non-zero, dump DIEs after they are read in. */
91 static int dwarf2_die_debug
= 0;
93 /* When non-zero, cross-check physname against demangler. */
94 static int check_physname
= 0;
96 /* When non-zero, do not reject deprecated .gdb_index sections. */
97 int use_deprecated_index_sections
= 0;
101 /* When set, the file that we're processing is known to have debugging
102 info for C++ namespaces. GCC 3.3.x did not produce this information,
103 but later versions do. */
105 static int processing_has_namespace_info
;
107 static const struct objfile_data
*dwarf2_objfile_data_key
;
109 struct dwarf2_section_info
114 /* Not NULL if the section was actually mmapped. */
116 /* Page aligned size of mmapped area. */
117 bfd_size_type map_len
;
118 /* True if we have tried to read this section. */
122 typedef struct dwarf2_section_info dwarf2_section_info_def
;
123 DEF_VEC_O (dwarf2_section_info_def
);
125 /* All offsets in the index are of this type. It must be
126 architecture-independent. */
127 typedef uint32_t offset_type
;
129 DEF_VEC_I (offset_type
);
131 /* Ensure only legit values are used. */
132 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
134 gdb_assert ((unsigned int) (value) <= 1); \
135 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
138 /* Ensure only legit values are used. */
139 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
141 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
142 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
143 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
146 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
147 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
149 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
150 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
153 /* A description of the mapped index. The file format is described in
154 a comment by the code that writes the index. */
157 /* Index data format version. */
160 /* The total length of the buffer. */
163 /* A pointer to the address table data. */
164 const gdb_byte
*address_table
;
166 /* Size of the address table data in bytes. */
167 offset_type address_table_size
;
169 /* The symbol table, implemented as a hash table. */
170 const offset_type
*symbol_table
;
172 /* Size in slots, each slot is 2 offset_types. */
173 offset_type symbol_table_slots
;
175 /* A pointer to the constant pool. */
176 const char *constant_pool
;
179 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
180 DEF_VEC_P (dwarf2_per_cu_ptr
);
182 /* Collection of data recorded per objfile.
183 This hangs off of dwarf2_objfile_data_key. */
185 struct dwarf2_per_objfile
187 struct dwarf2_section_info info
;
188 struct dwarf2_section_info abbrev
;
189 struct dwarf2_section_info line
;
190 struct dwarf2_section_info loc
;
191 struct dwarf2_section_info macinfo
;
192 struct dwarf2_section_info macro
;
193 struct dwarf2_section_info str
;
194 struct dwarf2_section_info ranges
;
195 struct dwarf2_section_info addr
;
196 struct dwarf2_section_info frame
;
197 struct dwarf2_section_info eh_frame
;
198 struct dwarf2_section_info gdb_index
;
200 VEC (dwarf2_section_info_def
) *types
;
203 struct objfile
*objfile
;
205 /* Table of all the compilation units. This is used to locate
206 the target compilation unit of a particular reference. */
207 struct dwarf2_per_cu_data
**all_comp_units
;
209 /* The number of compilation units in ALL_COMP_UNITS. */
212 /* The number of .debug_types-related CUs. */
215 /* The .debug_types-related CUs (TUs). */
216 struct signatured_type
**all_type_units
;
218 /* The number of entries in all_type_unit_groups. */
219 int n_type_unit_groups
;
221 /* Table of type unit groups.
222 This exists to make it easy to iterate over all CUs and TU groups. */
223 struct type_unit_group
**all_type_unit_groups
;
225 /* Table of struct type_unit_group objects.
226 The hash key is the DW_AT_stmt_list value. */
227 htab_t type_unit_groups
;
229 /* A table mapping .debug_types signatures to its signatured_type entry.
230 This is NULL if the .debug_types section hasn't been read in yet. */
231 htab_t signatured_types
;
233 /* Type unit statistics, to see how well the scaling improvements
237 int nr_uniq_abbrev_tables
;
239 int nr_symtab_sharers
;
240 int nr_stmt_less_type_units
;
243 /* A chain of compilation units that are currently read in, so that
244 they can be freed later. */
245 struct dwarf2_per_cu_data
*read_in_chain
;
247 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
248 This is NULL if the table hasn't been allocated yet. */
251 /* A flag indicating wether this objfile has a section loaded at a
253 int has_section_at_zero
;
255 /* True if we are using the mapped index,
256 or we are faking it for OBJF_READNOW's sake. */
257 unsigned char using_index
;
259 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
260 struct mapped_index
*index_table
;
262 /* When using index_table, this keeps track of all quick_file_names entries.
263 TUs can share line table entries with CUs or other TUs, and there can be
264 a lot more TUs than unique line tables, so we maintain a separate table
265 of all line table entries to support the sharing. */
266 htab_t quick_file_names_table
;
268 /* Set during partial symbol reading, to prevent queueing of full
270 int reading_partial_symbols
;
272 /* Table mapping type DIEs to their struct type *.
273 This is NULL if not allocated yet.
274 The mapping is done via (CU/TU signature + DIE offset) -> type. */
275 htab_t die_type_hash
;
277 /* The CUs we recently read. */
278 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
281 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_macinfo", ".zdebug_macinfo" },
295 { ".debug_macro", ".zdebug_macro" },
296 { ".debug_str", ".zdebug_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_types", ".zdebug_types" },
299 { ".debug_addr", ".zdebug_addr" },
300 { ".debug_frame", ".zdebug_frame" },
301 { ".eh_frame", NULL
},
302 { ".gdb_index", ".zgdb_index" },
306 /* List of DWO sections. */
308 static const struct dwo_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
322 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
323 { ".debug_info.dwo", ".zdebug_info.dwo" },
324 { ".debug_line.dwo", ".zdebug_line.dwo" },
325 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
326 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
327 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
328 { ".debug_str.dwo", ".zdebug_str.dwo" },
329 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
330 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 /* local data types */
335 /* The data in a compilation unit header, after target2host
336 translation, looks like this. */
337 struct comp_unit_head
341 unsigned char addr_size
;
342 unsigned char signed_addr_p
;
343 sect_offset abbrev_offset
;
345 /* Size of file offsets; either 4 or 8. */
346 unsigned int offset_size
;
348 /* Size of the length field; either 4 or 12. */
349 unsigned int initial_length_size
;
351 /* Offset to the first byte of this compilation unit header in the
352 .debug_info section, for resolving relative reference dies. */
355 /* Offset to first die in this cu from the start of the cu.
356 This will be the first byte following the compilation unit header. */
357 cu_offset first_die_offset
;
360 /* Type used for delaying computation of method physnames.
361 See comments for compute_delayed_physnames. */
362 struct delayed_method_info
364 /* The type to which the method is attached, i.e., its parent class. */
367 /* The index of the method in the type's function fieldlists. */
370 /* The index of the method in the fieldlist. */
373 /* The name of the DIE. */
376 /* The DIE associated with this method. */
377 struct die_info
*die
;
380 typedef struct delayed_method_info delayed_method_info
;
381 DEF_VEC_O (delayed_method_info
);
383 /* Internal state when decoding a particular compilation unit. */
386 /* The objfile containing this compilation unit. */
387 struct objfile
*objfile
;
389 /* The header of the compilation unit. */
390 struct comp_unit_head header
;
392 /* Base address of this compilation unit. */
393 CORE_ADDR base_address
;
395 /* Non-zero if base_address has been set. */
398 /* The language we are debugging. */
399 enum language language
;
400 const struct language_defn
*language_defn
;
402 const char *producer
;
404 /* The generic symbol table building routines have separate lists for
405 file scope symbols and all all other scopes (local scopes). So
406 we need to select the right one to pass to add_symbol_to_list().
407 We do it by keeping a pointer to the correct list in list_in_scope.
409 FIXME: The original dwarf code just treated the file scope as the
410 first local scope, and all other local scopes as nested local
411 scopes, and worked fine. Check to see if we really need to
412 distinguish these in buildsym.c. */
413 struct pending
**list_in_scope
;
415 /* The abbrev table for this CU.
416 Normally this points to the abbrev table in the objfile.
417 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
418 struct abbrev_table
*abbrev_table
;
420 /* Hash table holding all the loaded partial DIEs
421 with partial_die->offset.SECT_OFF as hash. */
424 /* Storage for things with the same lifetime as this read-in compilation
425 unit, including partial DIEs. */
426 struct obstack comp_unit_obstack
;
428 /* When multiple dwarf2_cu structures are living in memory, this field
429 chains them all together, so that they can be released efficiently.
430 We will probably also want a generation counter so that most-recently-used
431 compilation units are cached... */
432 struct dwarf2_per_cu_data
*read_in_chain
;
434 /* Backchain to our per_cu entry if the tree has been built. */
435 struct dwarf2_per_cu_data
*per_cu
;
437 /* How many compilation units ago was this CU last referenced? */
440 /* A hash table of DIE cu_offset for following references with
441 die_info->offset.sect_off as hash. */
444 /* Full DIEs if read in. */
445 struct die_info
*dies
;
447 /* A set of pointers to dwarf2_per_cu_data objects for compilation
448 units referenced by this one. Only set during full symbol processing;
449 partial symbol tables do not have dependencies. */
452 /* Header data from the line table, during full symbol processing. */
453 struct line_header
*line_header
;
455 /* A list of methods which need to have physnames computed
456 after all type information has been read. */
457 VEC (delayed_method_info
) *method_list
;
459 /* To be copied to symtab->call_site_htab. */
460 htab_t call_site_htab
;
462 /* Non-NULL if this CU came from a DWO file.
463 There is an invariant here that is important to remember:
464 Except for attributes copied from the top level DIE in the "main"
465 (or "stub") file in preparation for reading the DWO file
466 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
467 Either there isn't a DWO file (in which case this is NULL and the point
468 is moot), or there is and either we're not going to read it (in which
469 case this is NULL) or there is and we are reading it (in which case this
471 struct dwo_unit
*dwo_unit
;
473 /* The DW_AT_addr_base attribute if present, zero otherwise
474 (zero is a valid value though).
475 Note this value comes from the stub CU/TU's DIE. */
478 /* The DW_AT_ranges_base attribute if present, zero otherwise
479 (zero is a valid value though).
480 Note this value comes from the stub CU/TU's DIE.
481 Also note that the value is zero in the non-DWO case so this value can
482 be used without needing to know whether DWO files are in use or not. */
483 ULONGEST ranges_base
;
485 /* Mark used when releasing cached dies. */
486 unsigned int mark
: 1;
488 /* This CU references .debug_loc. See the symtab->locations_valid field.
489 This test is imperfect as there may exist optimized debug code not using
490 any location list and still facing inlining issues if handled as
491 unoptimized code. For a future better test see GCC PR other/32998. */
492 unsigned int has_loclist
: 1;
494 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
495 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
496 are valid. This information is cached because profiling CU expansion
497 showed excessive time spent in producer_is_gxx_lt_4_6. */
498 unsigned int checked_producer
: 1;
499 unsigned int producer_is_gxx_lt_4_6
: 1;
500 unsigned int producer_is_icc
: 1;
503 /* Persistent data held for a compilation unit, even when not
504 processing it. We put a pointer to this structure in the
505 read_symtab_private field of the psymtab. */
507 struct dwarf2_per_cu_data
509 /* The start offset and length of this compilation unit. 2**29-1
510 bytes should suffice to store the length of any compilation unit
511 - if it doesn't, GDB will fall over anyway.
512 NOTE: Unlike comp_unit_head.length, this length includes
514 If the DIE refers to a DWO file, this is always of the original die,
517 unsigned int length
: 29;
519 /* Flag indicating this compilation unit will be read in before
520 any of the current compilation units are processed. */
521 unsigned int queued
: 1;
523 /* This flag will be set when reading partial DIEs if we need to load
524 absolutely all DIEs for this compilation unit, instead of just the ones
525 we think are interesting. It gets set if we look for a DIE in the
526 hash table and don't find it. */
527 unsigned int load_all_dies
: 1;
529 /* Non-zero if this CU is from .debug_types. */
530 unsigned int is_debug_types
: 1;
532 /* The section this CU/TU lives in.
533 If the DIE refers to a DWO file, this is always the original die,
535 struct dwarf2_section_info
*info_or_types_section
;
537 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
538 of the CU cache it gets reset to NULL again. */
539 struct dwarf2_cu
*cu
;
541 /* The corresponding objfile.
542 Normally we can get the objfile from dwarf2_per_objfile.
543 However we can enter this file with just a "per_cu" handle. */
544 struct objfile
*objfile
;
546 /* When using partial symbol tables, the 'psymtab' field is active.
547 Otherwise the 'quick' field is active. */
550 /* The partial symbol table associated with this compilation unit,
551 or NULL for unread partial units. */
552 struct partial_symtab
*psymtab
;
554 /* Data needed by the "quick" functions. */
555 struct dwarf2_per_cu_quick_data
*quick
;
560 /* The CUs we import using DW_TAG_imported_unit. This is filled in
561 while reading psymtabs, used to compute the psymtab dependencies,
562 and then cleared. Then it is filled in again while reading full
563 symbols, and only deleted when the objfile is destroyed. */
564 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
566 /* Type units are grouped by their DW_AT_stmt_list entry so that they
567 can share them. If this is a TU, this points to the containing
569 struct type_unit_group
*type_unit_group
;
573 /* Entry in the signatured_types hash table. */
575 struct signatured_type
577 /* The "per_cu" object of this type.
578 N.B.: This is the first member so that it's easy to convert pointers
580 struct dwarf2_per_cu_data per_cu
;
582 /* The type's signature. */
585 /* Offset in the TU of the type's DIE, as read from the TU header.
586 If the definition lives in a DWO file, this value is unusable. */
587 cu_offset type_offset_in_tu
;
589 /* Offset in the section of the type's DIE.
590 If the definition lives in a DWO file, this is the offset in the
591 .debug_types.dwo section.
592 The value is zero until the actual value is known.
593 Zero is otherwise not a valid section offset. */
594 sect_offset type_offset_in_section
;
597 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
598 This includes type_unit_group and quick_file_names. */
600 struct stmt_list_hash
602 /* The DWO unit this table is from or NULL if there is none. */
603 struct dwo_unit
*dwo_unit
;
605 /* Offset in .debug_line or .debug_line.dwo. */
606 sect_offset line_offset
;
609 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
610 an object of this type. */
612 struct type_unit_group
614 /* dwarf2read.c's main "handle" on the symtab.
615 To simplify things we create an artificial CU that "includes" all the
616 type units using this stmt_list so that the rest of the code still has
617 a "per_cu" handle on the symtab.
618 This PER_CU is recognized by having no section. */
619 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
620 struct dwarf2_per_cu_data per_cu
;
624 /* The TUs that share this DW_AT_stmt_list entry.
625 This is added to while parsing type units to build partial symtabs,
626 and is deleted afterwards and not used again. */
627 VEC (dwarf2_per_cu_ptr
) *tus
;
629 /* When reading the line table in "quick" functions, we need a real TU.
630 Any will do, we know they all share the same DW_AT_stmt_list entry.
631 For simplicity's sake, we pick the first one. */
632 struct dwarf2_per_cu_data
*first_tu
;
635 /* The primary symtab.
636 Type units in a group needn't all be defined in the same source file,
637 so we create an essentially anonymous symtab as the primary symtab. */
638 struct symtab
*primary_symtab
;
640 /* The data used to construct the hash key. */
641 struct stmt_list_hash hash
;
643 /* The number of symtabs from the line header.
644 The value here must match line_header.num_file_names. */
645 unsigned int num_symtabs
;
647 /* The symbol tables for this TU (obtained from the files listed in
649 WARNING: The order of entries here must match the order of entries
650 in the line header. After the first TU using this type_unit_group, the
651 line header for the subsequent TUs is recreated from this. This is done
652 because we need to use the same symtabs for each TU using the same
653 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
654 there's no guarantee the line header doesn't have duplicate entries. */
655 struct symtab
**symtabs
;
658 /* These sections are what may appear in a "dwo" file. */
662 struct dwarf2_section_info abbrev
;
663 struct dwarf2_section_info info
;
664 struct dwarf2_section_info line
;
665 struct dwarf2_section_info loc
;
666 struct dwarf2_section_info macinfo
;
667 struct dwarf2_section_info macro
;
668 struct dwarf2_section_info str
;
669 struct dwarf2_section_info str_offsets
;
670 VEC (dwarf2_section_info_def
) *types
;
673 /* Common bits of DWO CUs/TUs. */
677 /* Backlink to the containing struct dwo_file. */
678 struct dwo_file
*dwo_file
;
680 /* The "id" that distinguishes this CU/TU.
681 .debug_info calls this "dwo_id", .debug_types calls this "signature".
682 Since signatures came first, we stick with it for consistency. */
685 /* The section this CU/TU lives in, in the DWO file. */
686 struct dwarf2_section_info
*info_or_types_section
;
688 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
692 /* For types, offset in the type's DIE of the type defined by this TU. */
693 cu_offset type_offset_in_tu
;
696 /* Data for one DWO file. */
700 /* The DW_AT_GNU_dwo_name attribute.
701 We don't manage space for this, it's an attribute. */
702 const char *dwo_name
;
704 /* The bfd, when the file is open. Otherwise this is NULL. */
707 /* Section info for this file. */
708 struct dwo_sections sections
;
710 /* Table of CUs in the file.
711 Each element is a struct dwo_unit. */
714 /* Table of TUs in the file.
715 Each element is a struct dwo_unit. */
719 /* Struct used to pass misc. parameters to read_die_and_children, et
720 al. which are used for both .debug_info and .debug_types dies.
721 All parameters here are unchanging for the life of the call. This
722 struct exists to abstract away the constant parameters of die reading. */
724 struct die_reader_specs
726 /* die_section->asection->owner. */
729 /* The CU of the DIE we are parsing. */
730 struct dwarf2_cu
*cu
;
732 /* Non-NULL if reading a DWO file. */
733 struct dwo_file
*dwo_file
;
735 /* The section the die comes from.
736 This is either .debug_info or .debug_types, or the .dwo variants. */
737 struct dwarf2_section_info
*die_section
;
739 /* die_section->buffer. */
742 /* The end of the buffer. */
743 const gdb_byte
*buffer_end
;
746 /* Type of function passed to init_cutu_and_read_dies, et.al. */
747 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
749 struct die_info
*comp_unit_die
,
753 /* The line number information for a compilation unit (found in the
754 .debug_line section) begins with a "statement program header",
755 which contains the following information. */
758 unsigned int total_length
;
759 unsigned short version
;
760 unsigned int header_length
;
761 unsigned char minimum_instruction_length
;
762 unsigned char maximum_ops_per_instruction
;
763 unsigned char default_is_stmt
;
765 unsigned char line_range
;
766 unsigned char opcode_base
;
768 /* standard_opcode_lengths[i] is the number of operands for the
769 standard opcode whose value is i. This means that
770 standard_opcode_lengths[0] is unused, and the last meaningful
771 element is standard_opcode_lengths[opcode_base - 1]. */
772 unsigned char *standard_opcode_lengths
;
774 /* The include_directories table. NOTE! These strings are not
775 allocated with xmalloc; instead, they are pointers into
776 debug_line_buffer. If you try to free them, `free' will get
778 unsigned int num_include_dirs
, include_dirs_size
;
781 /* The file_names table. NOTE! These strings are not allocated
782 with xmalloc; instead, they are pointers into debug_line_buffer.
783 Don't try to free them directly. */
784 unsigned int num_file_names
, file_names_size
;
788 unsigned int dir_index
;
789 unsigned int mod_time
;
791 int included_p
; /* Non-zero if referenced by the Line Number Program. */
792 struct symtab
*symtab
; /* The associated symbol table, if any. */
795 /* The start and end of the statement program following this
796 header. These point into dwarf2_per_objfile->line_buffer. */
797 gdb_byte
*statement_program_start
, *statement_program_end
;
800 /* When we construct a partial symbol table entry we only
801 need this much information. */
802 struct partial_die_info
804 /* Offset of this DIE. */
807 /* DWARF-2 tag for this DIE. */
808 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
810 /* Assorted flags describing the data found in this DIE. */
811 unsigned int has_children
: 1;
812 unsigned int is_external
: 1;
813 unsigned int is_declaration
: 1;
814 unsigned int has_type
: 1;
815 unsigned int has_specification
: 1;
816 unsigned int has_pc_info
: 1;
817 unsigned int may_be_inlined
: 1;
819 /* Flag set if the SCOPE field of this structure has been
821 unsigned int scope_set
: 1;
823 /* Flag set if the DIE has a byte_size attribute. */
824 unsigned int has_byte_size
: 1;
826 /* Flag set if any of the DIE's children are template arguments. */
827 unsigned int has_template_arguments
: 1;
829 /* Flag set if fixup_partial_die has been called on this die. */
830 unsigned int fixup_called
: 1;
832 /* The name of this DIE. Normally the value of DW_AT_name, but
833 sometimes a default name for unnamed DIEs. */
836 /* The linkage name, if present. */
837 const char *linkage_name
;
839 /* The scope to prepend to our children. This is generally
840 allocated on the comp_unit_obstack, so will disappear
841 when this compilation unit leaves the cache. */
844 /* Some data associated with the partial DIE. The tag determines
845 which field is live. */
848 /* The location description associated with this DIE, if any. */
849 struct dwarf_block
*locdesc
;
850 /* The offset of an import, for DW_TAG_imported_unit. */
854 /* If HAS_PC_INFO, the PC range associated with this DIE. */
858 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
859 DW_AT_sibling, if any. */
860 /* NOTE: This member isn't strictly necessary, read_partial_die could
861 return DW_AT_sibling values to its caller load_partial_dies. */
864 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
865 DW_AT_specification (or DW_AT_abstract_origin or
867 sect_offset spec_offset
;
869 /* Pointers to this DIE's parent, first child, and next sibling,
871 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
874 /* This data structure holds the information of an abbrev. */
877 unsigned int number
; /* number identifying abbrev */
878 enum dwarf_tag tag
; /* dwarf tag */
879 unsigned short has_children
; /* boolean */
880 unsigned short num_attrs
; /* number of attributes */
881 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
882 struct abbrev_info
*next
; /* next in chain */
887 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
888 ENUM_BITFIELD(dwarf_form
) form
: 16;
891 /* Size of abbrev_table.abbrev_hash_table. */
892 #define ABBREV_HASH_SIZE 121
894 /* Top level data structure to contain an abbreviation table. */
898 /* Where the abbrev table came from.
899 This is used as a sanity check when the table is used. */
902 /* Storage for the abbrev table. */
903 struct obstack abbrev_obstack
;
905 /* Hash table of abbrevs.
906 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
907 It could be statically allocated, but the previous code didn't so we
909 struct abbrev_info
**abbrevs
;
912 /* Attributes have a name and a value. */
915 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
916 ENUM_BITFIELD(dwarf_form
) form
: 15;
918 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
919 field should be in u.str (existing only for DW_STRING) but it is kept
920 here for better struct attribute alignment. */
921 unsigned int string_is_canonical
: 1;
926 struct dwarf_block
*blk
;
930 struct signatured_type
*signatured_type
;
935 /* This data structure holds a complete die structure. */
938 /* DWARF-2 tag for this DIE. */
939 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
941 /* Number of attributes */
942 unsigned char num_attrs
;
944 /* True if we're presently building the full type name for the
945 type derived from this DIE. */
946 unsigned char building_fullname
: 1;
951 /* Offset in .debug_info or .debug_types section. */
954 /* The dies in a compilation unit form an n-ary tree. PARENT
955 points to this die's parent; CHILD points to the first child of
956 this node; and all the children of a given node are chained
957 together via their SIBLING fields. */
958 struct die_info
*child
; /* Its first child, if any. */
959 struct die_info
*sibling
; /* Its next sibling, if any. */
960 struct die_info
*parent
; /* Its parent, if any. */
962 /* An array of attributes, with NUM_ATTRS elements. There may be
963 zero, but it's not common and zero-sized arrays are not
964 sufficiently portable C. */
965 struct attribute attrs
[1];
968 /* Get at parts of an attribute structure. */
970 #define DW_STRING(attr) ((attr)->u.str)
971 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
972 #define DW_UNSND(attr) ((attr)->u.unsnd)
973 #define DW_BLOCK(attr) ((attr)->u.blk)
974 #define DW_SND(attr) ((attr)->u.snd)
975 #define DW_ADDR(attr) ((attr)->u.addr)
976 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
978 /* Blocks are a bunch of untyped bytes. */
983 /* Valid only if SIZE is not zero. */
987 #ifndef ATTR_ALLOC_CHUNK
988 #define ATTR_ALLOC_CHUNK 4
991 /* Allocate fields for structs, unions and enums in this size. */
992 #ifndef DW_FIELD_ALLOC_CHUNK
993 #define DW_FIELD_ALLOC_CHUNK 4
996 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
997 but this would require a corresponding change in unpack_field_as_long
999 static int bits_per_byte
= 8;
1001 /* The routines that read and process dies for a C struct or C++ class
1002 pass lists of data member fields and lists of member function fields
1003 in an instance of a field_info structure, as defined below. */
1006 /* List of data member and baseclasses fields. */
1009 struct nextfield
*next
;
1014 *fields
, *baseclasses
;
1016 /* Number of fields (including baseclasses). */
1019 /* Number of baseclasses. */
1022 /* Set if the accesibility of one of the fields is not public. */
1023 int non_public_fields
;
1025 /* Member function fields array, entries are allocated in the order they
1026 are encountered in the object file. */
1029 struct nextfnfield
*next
;
1030 struct fn_field fnfield
;
1034 /* Member function fieldlist array, contains name of possibly overloaded
1035 member function, number of overloaded member functions and a pointer
1036 to the head of the member function field chain. */
1041 struct nextfnfield
*head
;
1045 /* Number of entries in the fnfieldlists array. */
1048 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1049 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1050 struct typedef_field_list
1052 struct typedef_field field
;
1053 struct typedef_field_list
*next
;
1055 *typedef_field_list
;
1056 unsigned typedef_field_list_count
;
1059 /* One item on the queue of compilation units to read in full symbols
1061 struct dwarf2_queue_item
1063 struct dwarf2_per_cu_data
*per_cu
;
1064 enum language pretend_language
;
1065 struct dwarf2_queue_item
*next
;
1068 /* The current queue. */
1069 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1071 /* Loaded secondary compilation units are kept in memory until they
1072 have not been referenced for the processing of this many
1073 compilation units. Set this to zero to disable caching. Cache
1074 sizes of up to at least twenty will improve startup time for
1075 typical inter-CU-reference binaries, at an obvious memory cost. */
1076 static int dwarf2_max_cache_age
= 5;
1078 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1079 struct cmd_list_element
*c
, const char *value
)
1081 fprintf_filtered (file
, _("The upper bound on the age of cached "
1082 "dwarf2 compilation units is %s.\n"),
1087 /* Various complaints about symbol reading that don't abort the process. */
1090 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1092 complaint (&symfile_complaints
,
1093 _("statement list doesn't fit in .debug_line section"));
1097 dwarf2_debug_line_missing_file_complaint (void)
1099 complaint (&symfile_complaints
,
1100 _(".debug_line section has line data without a file"));
1104 dwarf2_debug_line_missing_end_sequence_complaint (void)
1106 complaint (&symfile_complaints
,
1107 _(".debug_line section has line "
1108 "program sequence without an end"));
1112 dwarf2_complex_location_expr_complaint (void)
1114 complaint (&symfile_complaints
, _("location expression too complex"));
1118 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1121 complaint (&symfile_complaints
,
1122 _("const value length mismatch for '%s', got %d, expected %d"),
1127 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1129 complaint (&symfile_complaints
,
1130 _("debug info runs off end of %s section"
1132 section
->asection
->name
,
1133 bfd_get_filename (section
->asection
->owner
));
1137 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1139 complaint (&symfile_complaints
,
1140 _("macro debug info contains a "
1141 "malformed macro definition:\n`%s'"),
1146 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1148 complaint (&symfile_complaints
,
1149 _("invalid attribute class or form for '%s' in '%s'"),
1153 /* local function prototypes */
1155 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1157 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1160 static void dwarf2_find_base_address (struct die_info
*die
,
1161 struct dwarf2_cu
*cu
);
1163 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1165 static void scan_partial_symbols (struct partial_die_info
*,
1166 CORE_ADDR
*, CORE_ADDR
*,
1167 int, struct dwarf2_cu
*);
1169 static void add_partial_symbol (struct partial_die_info
*,
1170 struct dwarf2_cu
*);
1172 static void add_partial_namespace (struct partial_die_info
*pdi
,
1173 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1174 int need_pc
, struct dwarf2_cu
*cu
);
1176 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1177 CORE_ADDR
*highpc
, int need_pc
,
1178 struct dwarf2_cu
*cu
);
1180 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1181 struct dwarf2_cu
*cu
);
1183 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1184 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1185 int need_pc
, struct dwarf2_cu
*cu
);
1187 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1189 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1191 static struct abbrev_info
*abbrev_table_lookup_abbrev
1192 (const struct abbrev_table
*, unsigned int);
1194 static struct abbrev_table
*abbrev_table_read_table
1195 (struct dwarf2_section_info
*, sect_offset
);
1197 static void abbrev_table_free (struct abbrev_table
*);
1199 static void abbrev_table_free_cleanup (void *);
1201 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1202 struct dwarf2_section_info
*);
1204 static void dwarf2_free_abbrev_table (void *);
1206 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1208 static struct partial_die_info
*load_partial_dies
1209 (const struct die_reader_specs
*, gdb_byte
*, int);
1211 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1212 struct partial_die_info
*,
1213 struct abbrev_info
*,
1217 static struct partial_die_info
*find_partial_die (sect_offset
,
1218 struct dwarf2_cu
*);
1220 static void fixup_partial_die (struct partial_die_info
*,
1221 struct dwarf2_cu
*);
1223 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1224 struct attribute
*, struct attr_abbrev
*,
1227 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1229 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1231 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1233 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1235 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1237 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1240 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1242 static LONGEST read_checked_initial_length_and_offset
1243 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1244 unsigned int *, unsigned int *);
1246 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1249 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1251 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1254 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1256 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1258 static char *read_indirect_string (bfd
*, gdb_byte
*,
1259 const struct comp_unit_head
*,
1262 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1264 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1266 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1269 static char *read_str_index (const struct die_reader_specs
*reader
,
1270 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1272 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1274 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1275 struct dwarf2_cu
*);
1277 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1280 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1281 struct dwarf2_cu
*cu
);
1283 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1285 static struct die_info
*die_specification (struct die_info
*die
,
1286 struct dwarf2_cu
**);
1288 static void free_line_header (struct line_header
*lh
);
1290 static void add_file_name (struct line_header
*, char *, unsigned int,
1291 unsigned int, unsigned int);
1293 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1294 struct dwarf2_cu
*cu
);
1296 static void dwarf_decode_lines (struct line_header
*, const char *,
1297 struct dwarf2_cu
*, struct partial_symtab
*,
1300 static void dwarf2_start_subfile (char *, const char *, const char *);
1302 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1303 char *, char *, CORE_ADDR
);
1305 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1306 struct dwarf2_cu
*);
1308 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1309 struct dwarf2_cu
*, struct symbol
*);
1311 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1312 struct dwarf2_cu
*);
1314 static void dwarf2_const_value_attr (struct attribute
*attr
,
1317 struct obstack
*obstack
,
1318 struct dwarf2_cu
*cu
, LONGEST
*value
,
1320 struct dwarf2_locexpr_baton
**baton
);
1322 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1324 static int need_gnat_info (struct dwarf2_cu
*);
1326 static struct type
*die_descriptive_type (struct die_info
*,
1327 struct dwarf2_cu
*);
1329 static void set_descriptive_type (struct type
*, struct die_info
*,
1330 struct dwarf2_cu
*);
1332 static struct type
*die_containing_type (struct die_info
*,
1333 struct dwarf2_cu
*);
1335 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1336 struct dwarf2_cu
*);
1338 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1340 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1342 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1344 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1345 const char *suffix
, int physname
,
1346 struct dwarf2_cu
*cu
);
1348 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1350 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1352 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1354 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1356 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1358 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1359 struct dwarf2_cu
*, struct partial_symtab
*);
1361 static int dwarf2_get_pc_bounds (struct die_info
*,
1362 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1363 struct partial_symtab
*);
1365 static void get_scope_pc_bounds (struct die_info
*,
1366 CORE_ADDR
*, CORE_ADDR
*,
1367 struct dwarf2_cu
*);
1369 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1370 CORE_ADDR
, struct dwarf2_cu
*);
1372 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1373 struct dwarf2_cu
*);
1375 static void dwarf2_attach_fields_to_type (struct field_info
*,
1376 struct type
*, struct dwarf2_cu
*);
1378 static void dwarf2_add_member_fn (struct field_info
*,
1379 struct die_info
*, struct type
*,
1380 struct dwarf2_cu
*);
1382 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1384 struct dwarf2_cu
*);
1386 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1388 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1390 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1392 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1394 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1396 static struct type
*read_module_type (struct die_info
*die
,
1397 struct dwarf2_cu
*cu
);
1399 static const char *namespace_name (struct die_info
*die
,
1400 int *is_anonymous
, struct dwarf2_cu
*);
1402 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1404 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1406 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1407 struct dwarf2_cu
*);
1409 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1411 gdb_byte
**new_info_ptr
,
1412 struct die_info
*parent
);
1414 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1416 gdb_byte
**new_info_ptr
,
1417 struct die_info
*parent
);
1419 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1420 struct die_info
**, gdb_byte
*, int *, int);
1422 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1423 struct die_info
**, gdb_byte
*, int *);
1425 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1427 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1430 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1432 static const char *dwarf2_full_name (char *name
,
1433 struct die_info
*die
,
1434 struct dwarf2_cu
*cu
);
1436 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1437 struct dwarf2_cu
**);
1439 static const char *dwarf_tag_name (unsigned int);
1441 static const char *dwarf_attr_name (unsigned int);
1443 static const char *dwarf_form_name (unsigned int);
1445 static char *dwarf_bool_name (unsigned int);
1447 static const char *dwarf_type_encoding_name (unsigned int);
1449 static struct die_info
*sibling_die (struct die_info
*);
1451 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1453 static void dump_die_for_error (struct die_info
*);
1455 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1458 /*static*/ void dump_die (struct die_info
*, int max_level
);
1460 static void store_in_ref_table (struct die_info
*,
1461 struct dwarf2_cu
*);
1463 static int is_ref_attr (struct attribute
*);
1465 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1467 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1469 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1471 struct dwarf2_cu
**);
1473 static struct die_info
*follow_die_ref (struct die_info
*,
1475 struct dwarf2_cu
**);
1477 static struct die_info
*follow_die_sig (struct die_info
*,
1479 struct dwarf2_cu
**);
1481 static struct signatured_type
*lookup_signatured_type_at_offset
1482 (struct objfile
*objfile
,
1483 struct dwarf2_section_info
*section
, sect_offset offset
);
1485 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1487 static void read_signatured_type (struct signatured_type
*);
1489 static struct type_unit_group
*get_type_unit_group
1490 (struct dwarf2_cu
*, struct attribute
*);
1492 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1494 /* memory allocation interface */
1496 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1498 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1500 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1503 static int attr_form_is_block (struct attribute
*);
1505 static int attr_form_is_section_offset (struct attribute
*);
1507 static int attr_form_is_constant (struct attribute
*);
1509 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1510 struct dwarf2_loclist_baton
*baton
,
1511 struct attribute
*attr
);
1513 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1515 struct dwarf2_cu
*cu
);
1517 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1519 struct abbrev_info
*abbrev
);
1521 static void free_stack_comp_unit (void *);
1523 static hashval_t
partial_die_hash (const void *item
);
1525 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1527 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1528 (sect_offset offset
, struct objfile
*objfile
);
1530 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1531 struct dwarf2_per_cu_data
*per_cu
);
1533 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1534 struct die_info
*comp_unit_die
,
1535 enum language pretend_language
);
1537 static void free_heap_comp_unit (void *);
1539 static void free_cached_comp_units (void *);
1541 static void age_cached_comp_units (void);
1543 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1545 static struct type
*set_die_type (struct die_info
*, struct type
*,
1546 struct dwarf2_cu
*);
1548 static void create_all_comp_units (struct objfile
*);
1550 static int create_all_type_units (struct objfile
*);
1552 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1555 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1558 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1561 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1562 struct dwarf2_per_cu_data
*);
1564 static void dwarf2_mark (struct dwarf2_cu
*);
1566 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1568 static struct type
*get_die_type_at_offset (sect_offset
,
1569 struct dwarf2_per_cu_data
*per_cu
);
1571 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1573 static void dwarf2_release_queue (void *dummy
);
1575 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1576 enum language pretend_language
);
1578 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1579 struct dwarf2_per_cu_data
*per_cu
,
1580 enum language pretend_language
);
1582 static void process_queue (void);
1584 static void find_file_and_directory (struct die_info
*die
,
1585 struct dwarf2_cu
*cu
,
1586 char **name
, char **comp_dir
);
1588 static char *file_full_name (int file
, struct line_header
*lh
,
1589 const char *comp_dir
);
1591 static void init_cutu_and_read_dies
1592 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1593 int use_existing_cu
, int keep
,
1594 die_reader_func_ftype
*die_reader_func
, void *data
);
1596 static void init_cutu_and_read_dies_simple
1597 (struct dwarf2_per_cu_data
*this_cu
,
1598 die_reader_func_ftype
*die_reader_func
, void *data
);
1600 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1602 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1604 static struct dwo_unit
*lookup_dwo_comp_unit
1605 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1607 static struct dwo_unit
*lookup_dwo_type_unit
1608 (struct signatured_type
*, char *, const char *);
1610 static void free_dwo_file_cleanup (void *);
1612 static void munmap_section_buffer (struct dwarf2_section_info
*);
1614 static void process_cu_includes (void);
1618 /* Convert VALUE between big- and little-endian. */
1620 byte_swap (offset_type value
)
1624 result
= (value
& 0xff) << 24;
1625 result
|= (value
& 0xff00) << 8;
1626 result
|= (value
& 0xff0000) >> 8;
1627 result
|= (value
& 0xff000000) >> 24;
1631 #define MAYBE_SWAP(V) byte_swap (V)
1634 #define MAYBE_SWAP(V) (V)
1635 #endif /* WORDS_BIGENDIAN */
1637 /* The suffix for an index file. */
1638 #define INDEX_SUFFIX ".gdb-index"
1640 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1641 struct dwarf2_cu
*cu
);
1643 /* Try to locate the sections we need for DWARF 2 debugging
1644 information and return true if we have enough to do something.
1645 NAMES points to the dwarf2 section names, or is NULL if the standard
1646 ELF names are used. */
1649 dwarf2_has_info (struct objfile
*objfile
,
1650 const struct dwarf2_debug_sections
*names
)
1652 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1653 if (!dwarf2_per_objfile
)
1655 /* Initialize per-objfile state. */
1656 struct dwarf2_per_objfile
*data
1657 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1659 memset (data
, 0, sizeof (*data
));
1660 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1661 dwarf2_per_objfile
= data
;
1663 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1665 dwarf2_per_objfile
->objfile
= objfile
;
1667 return (dwarf2_per_objfile
->info
.asection
!= NULL
1668 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1671 /* When loading sections, we look either for uncompressed section or for
1672 compressed section names. */
1675 section_is_p (const char *section_name
,
1676 const struct dwarf2_section_names
*names
)
1678 if (names
->normal
!= NULL
1679 && strcmp (section_name
, names
->normal
) == 0)
1681 if (names
->compressed
!= NULL
1682 && strcmp (section_name
, names
->compressed
) == 0)
1687 /* This function is mapped across the sections and remembers the
1688 offset and size of each of the debugging sections we are interested
1692 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1694 const struct dwarf2_debug_sections
*names
;
1697 names
= &dwarf2_elf_names
;
1699 names
= (const struct dwarf2_debug_sections
*) vnames
;
1701 if (section_is_p (sectp
->name
, &names
->info
))
1703 dwarf2_per_objfile
->info
.asection
= sectp
;
1704 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1706 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1708 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1709 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1711 else if (section_is_p (sectp
->name
, &names
->line
))
1713 dwarf2_per_objfile
->line
.asection
= sectp
;
1714 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1716 else if (section_is_p (sectp
->name
, &names
->loc
))
1718 dwarf2_per_objfile
->loc
.asection
= sectp
;
1719 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1721 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1723 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1724 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1726 else if (section_is_p (sectp
->name
, &names
->macro
))
1728 dwarf2_per_objfile
->macro
.asection
= sectp
;
1729 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1731 else if (section_is_p (sectp
->name
, &names
->str
))
1733 dwarf2_per_objfile
->str
.asection
= sectp
;
1734 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1736 else if (section_is_p (sectp
->name
, &names
->addr
))
1738 dwarf2_per_objfile
->addr
.asection
= sectp
;
1739 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1741 else if (section_is_p (sectp
->name
, &names
->frame
))
1743 dwarf2_per_objfile
->frame
.asection
= sectp
;
1744 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1746 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1748 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1750 if (aflag
& SEC_HAS_CONTENTS
)
1752 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1753 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1756 else if (section_is_p (sectp
->name
, &names
->ranges
))
1758 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1759 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1761 else if (section_is_p (sectp
->name
, &names
->types
))
1763 struct dwarf2_section_info type_section
;
1765 memset (&type_section
, 0, sizeof (type_section
));
1766 type_section
.asection
= sectp
;
1767 type_section
.size
= bfd_get_section_size (sectp
);
1769 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1772 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1774 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1775 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1778 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1779 && bfd_section_vma (abfd
, sectp
) == 0)
1780 dwarf2_per_objfile
->has_section_at_zero
= 1;
1783 /* Decompress a section that was compressed using zlib. Store the
1784 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1787 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1788 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1790 bfd
*abfd
= sectp
->owner
;
1792 error (_("Support for zlib-compressed DWARF data (from '%s') "
1793 "is disabled in this copy of GDB"),
1794 bfd_get_filename (abfd
));
1796 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1797 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1798 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1799 bfd_size_type uncompressed_size
;
1800 gdb_byte
*uncompressed_buffer
;
1803 int header_size
= 12;
1805 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1806 || bfd_bread (compressed_buffer
,
1807 compressed_size
, abfd
) != compressed_size
)
1808 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1809 bfd_get_filename (abfd
));
1811 /* Read the zlib header. In this case, it should be "ZLIB" followed
1812 by the uncompressed section size, 8 bytes in big-endian order. */
1813 if (compressed_size
< header_size
1814 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1815 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1816 bfd_get_filename (abfd
));
1817 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1818 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1819 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1820 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1821 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1822 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1823 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1824 uncompressed_size
+= compressed_buffer
[11];
1826 /* It is possible the section consists of several compressed
1827 buffers concatenated together, so we uncompress in a loop. */
1831 strm
.avail_in
= compressed_size
- header_size
;
1832 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1833 strm
.avail_out
= uncompressed_size
;
1834 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1836 rc
= inflateInit (&strm
);
1837 while (strm
.avail_in
> 0)
1840 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1841 bfd_get_filename (abfd
), rc
);
1842 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1843 + (uncompressed_size
- strm
.avail_out
));
1844 rc
= inflate (&strm
, Z_FINISH
);
1845 if (rc
!= Z_STREAM_END
)
1846 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1847 bfd_get_filename (abfd
), rc
);
1848 rc
= inflateReset (&strm
);
1850 rc
= inflateEnd (&strm
);
1852 || strm
.avail_out
!= 0)
1853 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1854 bfd_get_filename (abfd
), rc
);
1856 do_cleanups (cleanup
);
1857 *outbuf
= uncompressed_buffer
;
1858 *outsize
= uncompressed_size
;
1862 /* A helper function that decides whether a section is empty,
1866 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1868 return info
->asection
== NULL
|| info
->size
== 0;
1871 /* Read the contents of the section INFO.
1872 OBJFILE is the main object file, but not necessarily the file where
1873 the section comes from. E.g., for DWO files INFO->asection->owner
1874 is the bfd of the DWO file.
1875 If the section is compressed, uncompress it before returning. */
1878 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1880 asection
*sectp
= info
->asection
;
1882 gdb_byte
*buf
, *retbuf
;
1883 unsigned char header
[4];
1887 info
->buffer
= NULL
;
1888 info
->map_addr
= NULL
;
1891 if (dwarf2_section_empty_p (info
))
1894 /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */
1895 abfd
= sectp
->owner
;
1897 /* Check if the file has a 4-byte header indicating compression. */
1898 if (info
->size
> sizeof (header
)
1899 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1900 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1902 /* Upon decompression, update the buffer and its size. */
1903 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1905 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1913 pagesize
= getpagesize ();
1915 /* Only try to mmap sections which are large enough: we don't want to
1916 waste space due to fragmentation. Also, only try mmap for sections
1917 without relocations. */
1919 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1921 info
->buffer
= bfd_mmap (abfd
, 0, info
->size
, PROT_READ
,
1922 MAP_PRIVATE
, sectp
->filepos
,
1923 &info
->map_addr
, &info
->map_len
);
1925 if ((caddr_t
)info
->buffer
!= MAP_FAILED
)
1927 #if HAVE_POSIX_MADVISE
1928 posix_madvise (info
->map_addr
, info
->map_len
, POSIX_MADV_WILLNEED
);
1935 /* If we get here, we are a normal, not-compressed section. */
1937 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1939 /* When debugging .o files, we may need to apply relocations; see
1940 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1941 We never compress sections in .o files, so we only need to
1942 try this when the section is not compressed. */
1943 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1946 info
->buffer
= retbuf
;
1950 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1951 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1952 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1953 bfd_get_filename (abfd
));
1956 /* A helper function that returns the size of a section in a safe way.
1957 If you are positive that the section has been read before using the
1958 size, then it is safe to refer to the dwarf2_section_info object's
1959 "size" field directly. In other cases, you must call this
1960 function, because for compressed sections the size field is not set
1961 correctly until the section has been read. */
1963 static bfd_size_type
1964 dwarf2_section_size (struct objfile
*objfile
,
1965 struct dwarf2_section_info
*info
)
1968 dwarf2_read_section (objfile
, info
);
1972 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1976 dwarf2_get_section_info (struct objfile
*objfile
,
1977 enum dwarf2_section_enum sect
,
1978 asection
**sectp
, gdb_byte
**bufp
,
1979 bfd_size_type
*sizep
)
1981 struct dwarf2_per_objfile
*data
1982 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1983 struct dwarf2_section_info
*info
;
1985 /* We may see an objfile without any DWARF, in which case we just
1996 case DWARF2_DEBUG_FRAME
:
1997 info
= &data
->frame
;
1999 case DWARF2_EH_FRAME
:
2000 info
= &data
->eh_frame
;
2003 gdb_assert_not_reached ("unexpected section");
2006 dwarf2_read_section (objfile
, info
);
2008 *sectp
= info
->asection
;
2009 *bufp
= info
->buffer
;
2010 *sizep
= info
->size
;
2014 /* DWARF quick_symbols_functions support. */
2016 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2017 unique line tables, so we maintain a separate table of all .debug_line
2018 derived entries to support the sharing.
2019 All the quick functions need is the list of file names. We discard the
2020 line_header when we're done and don't need to record it here. */
2021 struct quick_file_names
2023 /* The data used to construct the hash key. */
2024 struct stmt_list_hash hash
;
2026 /* The number of entries in file_names, real_names. */
2027 unsigned int num_file_names
;
2029 /* The file names from the line table, after being run through
2031 const char **file_names
;
2033 /* The file names from the line table after being run through
2034 gdb_realpath. These are computed lazily. */
2035 const char **real_names
;
2038 /* When using the index (and thus not using psymtabs), each CU has an
2039 object of this type. This is used to hold information needed by
2040 the various "quick" methods. */
2041 struct dwarf2_per_cu_quick_data
2043 /* The file table. This can be NULL if there was no file table
2044 or it's currently not read in.
2045 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2046 struct quick_file_names
*file_names
;
2048 /* The corresponding symbol table. This is NULL if symbols for this
2049 CU have not yet been read. */
2050 struct symtab
*symtab
;
2052 /* A temporary mark bit used when iterating over all CUs in
2053 expand_symtabs_matching. */
2054 unsigned int mark
: 1;
2056 /* True if we've tried to read the file table and found there isn't one.
2057 There will be no point in trying to read it again next time. */
2058 unsigned int no_file_data
: 1;
2061 /* Utility hash function for a stmt_list_hash. */
2064 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2068 if (stmt_list_hash
->dwo_unit
!= NULL
)
2069 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2070 v
+= stmt_list_hash
->line_offset
.sect_off
;
2074 /* Utility equality function for a stmt_list_hash. */
2077 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2078 const struct stmt_list_hash
*rhs
)
2080 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2082 if (lhs
->dwo_unit
!= NULL
2083 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2086 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2089 /* Hash function for a quick_file_names. */
2092 hash_file_name_entry (const void *e
)
2094 const struct quick_file_names
*file_data
= e
;
2096 return hash_stmt_list_entry (&file_data
->hash
);
2099 /* Equality function for a quick_file_names. */
2102 eq_file_name_entry (const void *a
, const void *b
)
2104 const struct quick_file_names
*ea
= a
;
2105 const struct quick_file_names
*eb
= b
;
2107 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2110 /* Delete function for a quick_file_names. */
2113 delete_file_name_entry (void *e
)
2115 struct quick_file_names
*file_data
= e
;
2118 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2120 xfree ((void*) file_data
->file_names
[i
]);
2121 if (file_data
->real_names
)
2122 xfree ((void*) file_data
->real_names
[i
]);
2125 /* The space for the struct itself lives on objfile_obstack,
2126 so we don't free it here. */
2129 /* Create a quick_file_names hash table. */
2132 create_quick_file_names_table (unsigned int nr_initial_entries
)
2134 return htab_create_alloc (nr_initial_entries
,
2135 hash_file_name_entry
, eq_file_name_entry
,
2136 delete_file_name_entry
, xcalloc
, xfree
);
2139 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2140 have to be created afterwards. You should call age_cached_comp_units after
2141 processing PER_CU->CU. dw2_setup must have been already called. */
2144 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2146 if (per_cu
->is_debug_types
)
2147 load_full_type_unit (per_cu
);
2149 load_full_comp_unit (per_cu
, language_minimal
);
2151 gdb_assert (per_cu
->cu
!= NULL
);
2153 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2156 /* Read in the symbols for PER_CU. */
2159 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2161 struct cleanup
*back_to
;
2163 /* Skip type_unit_groups, reading the type units they contain
2164 is handled elsewhere. */
2165 if (IS_TYPE_UNIT_GROUP (per_cu
))
2168 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2170 if (dwarf2_per_objfile
->using_index
2171 ? per_cu
->v
.quick
->symtab
== NULL
2172 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2174 queue_comp_unit (per_cu
, language_minimal
);
2180 /* Age the cache, releasing compilation units that have not
2181 been used recently. */
2182 age_cached_comp_units ();
2184 do_cleanups (back_to
);
2187 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2188 the objfile from which this CU came. Returns the resulting symbol
2191 static struct symtab
*
2192 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2194 gdb_assert (dwarf2_per_objfile
->using_index
);
2195 if (!per_cu
->v
.quick
->symtab
)
2197 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2198 increment_reading_symtab ();
2199 dw2_do_instantiate_symtab (per_cu
);
2200 process_cu_includes ();
2201 do_cleanups (back_to
);
2203 return per_cu
->v
.quick
->symtab
;
2206 /* Return the CU given its index.
2208 This is intended for loops like:
2210 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2211 + dwarf2_per_objfile->n_type_units); ++i)
2213 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2219 static struct dwarf2_per_cu_data
*
2220 dw2_get_cu (int index
)
2222 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2224 index
-= dwarf2_per_objfile
->n_comp_units
;
2225 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2226 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2229 return dwarf2_per_objfile
->all_comp_units
[index
];
2232 /* Return the primary CU given its index.
2233 The difference between this function and dw2_get_cu is in the handling
2234 of type units (TUs). Here we return the type_unit_group object.
2236 This is intended for loops like:
2238 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2239 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2241 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2247 static struct dwarf2_per_cu_data
*
2248 dw2_get_primary_cu (int index
)
2250 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2252 index
-= dwarf2_per_objfile
->n_comp_units
;
2253 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2254 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2257 return dwarf2_per_objfile
->all_comp_units
[index
];
2260 /* A helper function that knows how to read a 64-bit value in a way
2261 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2265 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2267 if (sizeof (ULONGEST
) < 8)
2271 /* Ignore the upper 4 bytes if they are all zero. */
2272 for (i
= 0; i
< 4; ++i
)
2273 if (bytes
[i
+ 4] != 0)
2276 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2279 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2283 /* Read the CU list from the mapped index, and use it to create all
2284 the CU objects for this objfile. Return 0 if something went wrong,
2285 1 if everything went ok. */
2288 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
2289 offset_type cu_list_elements
)
2293 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
2294 dwarf2_per_objfile
->all_comp_units
2295 = obstack_alloc (&objfile
->objfile_obstack
,
2296 dwarf2_per_objfile
->n_comp_units
2297 * sizeof (struct dwarf2_per_cu_data
*));
2299 for (i
= 0; i
< cu_list_elements
; i
+= 2)
2301 struct dwarf2_per_cu_data
*the_cu
;
2302 ULONGEST offset
, length
;
2304 if (!extract_cu_value (cu_list
, &offset
)
2305 || !extract_cu_value (cu_list
+ 8, &length
))
2309 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2310 struct dwarf2_per_cu_data
);
2311 the_cu
->offset
.sect_off
= offset
;
2312 the_cu
->length
= length
;
2313 the_cu
->objfile
= objfile
;
2314 the_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
2315 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2316 struct dwarf2_per_cu_quick_data
);
2317 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
2323 /* Create the signatured type hash table from the index. */
2326 create_signatured_type_table_from_index (struct objfile
*objfile
,
2327 struct dwarf2_section_info
*section
,
2328 const gdb_byte
*bytes
,
2329 offset_type elements
)
2332 htab_t sig_types_hash
;
2334 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2335 dwarf2_per_objfile
->all_type_units
2336 = obstack_alloc (&objfile
->objfile_obstack
,
2337 dwarf2_per_objfile
->n_type_units
2338 * sizeof (struct signatured_type
*));
2340 sig_types_hash
= allocate_signatured_type_table (objfile
);
2342 for (i
= 0; i
< elements
; i
+= 3)
2344 struct signatured_type
*sig_type
;
2345 ULONGEST offset
, type_offset_in_tu
, signature
;
2348 if (!extract_cu_value (bytes
, &offset
)
2349 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2351 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2354 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2355 struct signatured_type
);
2356 sig_type
->signature
= signature
;
2357 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2358 sig_type
->per_cu
.is_debug_types
= 1;
2359 sig_type
->per_cu
.info_or_types_section
= section
;
2360 sig_type
->per_cu
.offset
.sect_off
= offset
;
2361 sig_type
->per_cu
.objfile
= objfile
;
2362 sig_type
->per_cu
.v
.quick
2363 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2364 struct dwarf2_per_cu_quick_data
);
2366 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2369 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2372 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2377 /* Read the address map data from the mapped index, and use it to
2378 populate the objfile's psymtabs_addrmap. */
2381 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2383 const gdb_byte
*iter
, *end
;
2384 struct obstack temp_obstack
;
2385 struct addrmap
*mutable_map
;
2386 struct cleanup
*cleanup
;
2389 obstack_init (&temp_obstack
);
2390 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2391 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2393 iter
= index
->address_table
;
2394 end
= iter
+ index
->address_table_size
;
2396 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2400 ULONGEST hi
, lo
, cu_index
;
2401 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2403 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2405 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2408 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2409 dw2_get_cu (cu_index
));
2412 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2413 &objfile
->objfile_obstack
);
2414 do_cleanups (cleanup
);
2417 /* The hash function for strings in the mapped index. This is the same as
2418 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2419 implementation. This is necessary because the hash function is tied to the
2420 format of the mapped index file. The hash values do not have to match with
2423 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2426 mapped_index_string_hash (int index_version
, const void *p
)
2428 const unsigned char *str
= (const unsigned char *) p
;
2432 while ((c
= *str
++) != 0)
2434 if (index_version
>= 5)
2436 r
= r
* 67 + c
- 113;
2442 /* Find a slot in the mapped index INDEX for the object named NAME.
2443 If NAME is found, set *VEC_OUT to point to the CU vector in the
2444 constant pool and return 1. If NAME cannot be found, return 0. */
2447 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2448 offset_type
**vec_out
)
2450 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2452 offset_type slot
, step
;
2453 int (*cmp
) (const char *, const char *);
2455 if (current_language
->la_language
== language_cplus
2456 || current_language
->la_language
== language_java
2457 || current_language
->la_language
== language_fortran
)
2459 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2461 const char *paren
= strchr (name
, '(');
2467 dup
= xmalloc (paren
- name
+ 1);
2468 memcpy (dup
, name
, paren
- name
);
2469 dup
[paren
- name
] = 0;
2471 make_cleanup (xfree
, dup
);
2476 /* Index version 4 did not support case insensitive searches. But the
2477 indices for case insensitive languages are built in lowercase, therefore
2478 simulate our NAME being searched is also lowercased. */
2479 hash
= mapped_index_string_hash ((index
->version
== 4
2480 && case_sensitivity
== case_sensitive_off
2481 ? 5 : index
->version
),
2484 slot
= hash
& (index
->symbol_table_slots
- 1);
2485 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2486 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2490 /* Convert a slot number to an offset into the table. */
2491 offset_type i
= 2 * slot
;
2493 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2495 do_cleanups (back_to
);
2499 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2500 if (!cmp (name
, str
))
2502 *vec_out
= (offset_type
*) (index
->constant_pool
2503 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2504 do_cleanups (back_to
);
2508 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2512 /* Read the index file. If everything went ok, initialize the "quick"
2513 elements of all the CUs and return 1. Otherwise, return 0. */
2516 dwarf2_read_index (struct objfile
*objfile
)
2519 struct mapped_index
*map
;
2520 offset_type
*metadata
;
2521 const gdb_byte
*cu_list
;
2522 const gdb_byte
*types_list
= NULL
;
2523 offset_type version
, cu_list_elements
;
2524 offset_type types_list_elements
= 0;
2527 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2530 /* Older elfutils strip versions could keep the section in the main
2531 executable while splitting it for the separate debug info file. */
2532 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2533 & SEC_HAS_CONTENTS
) == 0)
2536 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2538 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2539 /* Version check. */
2540 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2541 /* Versions earlier than 3 emitted every copy of a psymbol. This
2542 causes the index to behave very poorly for certain requests. Version 3
2543 contained incomplete addrmap. So, it seems better to just ignore such
2547 static int warning_printed
= 0;
2548 if (!warning_printed
)
2550 warning (_("Skipping obsolete .gdb_index section in %s."),
2552 warning_printed
= 1;
2556 /* Index version 4 uses a different hash function than index version
2559 Versions earlier than 6 did not emit psymbols for inlined
2560 functions. Using these files will cause GDB not to be able to
2561 set breakpoints on inlined functions by name, so we ignore these
2562 indices unless the --use-deprecated-index-sections command line
2563 option was supplied. */
2564 if (version
< 6 && !use_deprecated_index_sections
)
2566 static int warning_printed
= 0;
2567 if (!warning_printed
)
2569 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2570 "--use-deprecated-index-sections to use them anyway"),
2572 warning_printed
= 1;
2576 /* Indexes with higher version than the one supported by GDB may be no
2577 longer backward compatible. */
2581 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2582 map
->version
= version
;
2583 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2585 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2588 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2589 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2593 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2594 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2595 - MAYBE_SWAP (metadata
[i
]))
2599 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2600 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2601 - MAYBE_SWAP (metadata
[i
]));
2604 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2605 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2606 - MAYBE_SWAP (metadata
[i
]))
2607 / (2 * sizeof (offset_type
)));
2610 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2612 /* Don't use the index if it's empty. */
2613 if (map
->symbol_table_slots
== 0)
2616 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2619 if (types_list_elements
)
2621 struct dwarf2_section_info
*section
;
2623 /* We can only handle a single .debug_types when we have an
2625 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2628 section
= VEC_index (dwarf2_section_info_def
,
2629 dwarf2_per_objfile
->types
, 0);
2631 if (!create_signatured_type_table_from_index (objfile
, section
,
2633 types_list_elements
))
2637 create_addrmap_from_index (objfile
, map
);
2639 dwarf2_per_objfile
->index_table
= map
;
2640 dwarf2_per_objfile
->using_index
= 1;
2641 dwarf2_per_objfile
->quick_file_names_table
=
2642 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2647 /* A helper for the "quick" functions which sets the global
2648 dwarf2_per_objfile according to OBJFILE. */
2651 dw2_setup (struct objfile
*objfile
)
2653 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2654 gdb_assert (dwarf2_per_objfile
);
2657 /* Reader function for dw2_build_type_unit_groups. */
2660 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2662 struct die_info
*type_unit_die
,
2666 struct dwarf2_cu
*cu
= reader
->cu
;
2667 struct attribute
*attr
;
2668 struct type_unit_group
*tu_group
;
2670 gdb_assert (data
== NULL
);
2675 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2676 /* Call this for its side-effect of creating the associated
2677 struct type_unit_group if it doesn't already exist. */
2678 tu_group
= get_type_unit_group (cu
, attr
);
2681 /* Build dwarf2_per_objfile->type_unit_groups.
2682 This function may be called multiple times. */
2685 dw2_build_type_unit_groups (void)
2687 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2688 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2691 /* die_reader_func for dw2_get_file_names. */
2694 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2696 struct die_info
*comp_unit_die
,
2700 struct dwarf2_cu
*cu
= reader
->cu
;
2701 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2702 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2703 struct dwarf2_per_cu_data
*lh_cu
;
2704 struct line_header
*lh
;
2705 struct attribute
*attr
;
2707 char *name
, *comp_dir
;
2709 struct quick_file_names
*qfn
;
2710 unsigned int line_offset
;
2712 /* Our callers never want to match partial units -- instead they
2713 will match the enclosing full CU. */
2714 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2716 this_cu
->v
.quick
->no_file_data
= 1;
2720 /* If we're reading the line header for TUs, store it in the "per_cu"
2722 if (this_cu
->is_debug_types
)
2724 struct type_unit_group
*tu_group
= data
;
2726 gdb_assert (tu_group
!= NULL
);
2727 lh_cu
= &tu_group
->per_cu
;
2736 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2739 struct quick_file_names find_entry
;
2741 line_offset
= DW_UNSND (attr
);
2743 /* We may have already read in this line header (TU line header sharing).
2744 If we have we're done. */
2745 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2746 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2747 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2748 &find_entry
, INSERT
);
2751 lh_cu
->v
.quick
->file_names
= *slot
;
2755 lh
= dwarf_decode_line_header (line_offset
, cu
);
2759 lh_cu
->v
.quick
->no_file_data
= 1;
2763 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2764 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2765 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2766 gdb_assert (slot
!= NULL
);
2769 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2771 qfn
->num_file_names
= lh
->num_file_names
;
2772 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2773 lh
->num_file_names
* sizeof (char *));
2774 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2775 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2776 qfn
->real_names
= NULL
;
2778 free_line_header (lh
);
2780 lh_cu
->v
.quick
->file_names
= qfn
;
2783 /* A helper for the "quick" functions which attempts to read the line
2784 table for THIS_CU. */
2786 static struct quick_file_names
*
2787 dw2_get_file_names (struct objfile
*objfile
,
2788 struct dwarf2_per_cu_data
*this_cu
)
2790 /* For TUs this should only be called on the parent group. */
2791 if (this_cu
->is_debug_types
)
2792 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2794 if (this_cu
->v
.quick
->file_names
!= NULL
)
2795 return this_cu
->v
.quick
->file_names
;
2796 /* If we know there is no line data, no point in looking again. */
2797 if (this_cu
->v
.quick
->no_file_data
)
2800 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2801 in the stub for CUs, there's is no need to lookup the DWO file.
2802 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2804 if (this_cu
->is_debug_types
)
2806 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2808 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2809 dw2_get_file_names_reader
, tu_group
);
2812 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2814 if (this_cu
->v
.quick
->no_file_data
)
2816 return this_cu
->v
.quick
->file_names
;
2819 /* A helper for the "quick" functions which computes and caches the
2820 real path for a given file name from the line table. */
2823 dw2_get_real_path (struct objfile
*objfile
,
2824 struct quick_file_names
*qfn
, int index
)
2826 if (qfn
->real_names
== NULL
)
2827 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2828 qfn
->num_file_names
, sizeof (char *));
2830 if (qfn
->real_names
[index
] == NULL
)
2831 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2833 return qfn
->real_names
[index
];
2836 static struct symtab
*
2837 dw2_find_last_source_symtab (struct objfile
*objfile
)
2841 dw2_setup (objfile
);
2842 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2843 return dw2_instantiate_symtab (dw2_get_cu (index
));
2846 /* Traversal function for dw2_forget_cached_source_info. */
2849 dw2_free_cached_file_names (void **slot
, void *info
)
2851 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2853 if (file_data
->real_names
)
2857 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2859 xfree ((void*) file_data
->real_names
[i
]);
2860 file_data
->real_names
[i
] = NULL
;
2868 dw2_forget_cached_source_info (struct objfile
*objfile
)
2870 dw2_setup (objfile
);
2872 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2873 dw2_free_cached_file_names
, NULL
);
2876 /* Helper function for dw2_map_symtabs_matching_filename that expands
2877 the symtabs and calls the iterator. */
2880 dw2_map_expand_apply (struct objfile
*objfile
,
2881 struct dwarf2_per_cu_data
*per_cu
,
2883 const char *full_path
, const char *real_path
,
2884 int (*callback
) (struct symtab
*, void *),
2887 struct symtab
*last_made
= objfile
->symtabs
;
2889 /* Don't visit already-expanded CUs. */
2890 if (per_cu
->v
.quick
->symtab
)
2893 /* This may expand more than one symtab, and we want to iterate over
2895 dw2_instantiate_symtab (per_cu
);
2897 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2898 objfile
->symtabs
, last_made
);
2901 /* Implementation of the map_symtabs_matching_filename method. */
2904 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
2905 const char *full_path
, const char *real_path
,
2906 int (*callback
) (struct symtab
*, void *),
2910 const char *name_basename
= lbasename (name
);
2911 int name_len
= strlen (name
);
2912 int is_abs
= IS_ABSOLUTE_PATH (name
);
2914 dw2_setup (objfile
);
2916 dw2_build_type_unit_groups ();
2918 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2919 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
2922 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
2923 struct quick_file_names
*file_data
;
2925 /* We only need to look at symtabs not already expanded. */
2926 if (per_cu
->v
.quick
->symtab
)
2929 file_data
= dw2_get_file_names (objfile
, per_cu
);
2930 if (file_data
== NULL
)
2933 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2935 const char *this_name
= file_data
->file_names
[j
];
2937 if (FILENAME_CMP (name
, this_name
) == 0
2938 || (!is_abs
&& compare_filenames_for_search (this_name
,
2941 if (dw2_map_expand_apply (objfile
, per_cu
,
2942 name
, full_path
, real_path
,
2947 /* Before we invoke realpath, which can get expensive when many
2948 files are involved, do a quick comparison of the basenames. */
2949 if (! basenames_may_differ
2950 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
2953 if (full_path
!= NULL
)
2955 const char *this_real_name
= dw2_get_real_path (objfile
,
2958 if (this_real_name
!= NULL
2959 && (FILENAME_CMP (full_path
, this_real_name
) == 0
2961 && compare_filenames_for_search (this_real_name
,
2964 if (dw2_map_expand_apply (objfile
, per_cu
,
2965 name
, full_path
, real_path
,
2971 if (real_path
!= NULL
)
2973 const char *this_real_name
= dw2_get_real_path (objfile
,
2976 if (this_real_name
!= NULL
2977 && (FILENAME_CMP (real_path
, this_real_name
) == 0
2979 && compare_filenames_for_search (this_real_name
,
2982 if (dw2_map_expand_apply (objfile
, per_cu
,
2983 name
, full_path
, real_path
,
2994 static struct symtab
*
2995 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2996 const char *name
, domain_enum domain
)
2998 /* We do all the work in the pre_expand_symtabs_matching hook
3003 /* A helper function that expands all symtabs that hold an object
3004 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3005 symbols in block BLOCK_KIND. */
3008 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3009 int want_specific_block
,
3010 enum block_enum block_kind
,
3011 const char *name
, domain_enum domain
)
3013 struct mapped_index
*index
;
3015 dw2_setup (objfile
);
3017 index
= dwarf2_per_objfile
->index_table
;
3019 /* index_table is NULL if OBJF_READNOW. */
3024 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3026 offset_type i
, len
= MAYBE_SWAP (*vec
);
3027 for (i
= 0; i
< len
; ++i
)
3029 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3030 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3031 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3032 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3033 /* This value is only valid for index versions >= 7. */
3034 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3035 gdb_index_symbol_kind symbol_kind
=
3036 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3038 if (want_specific_block
3039 && index
->version
>= 7
3040 && want_static
!= is_static
)
3043 /* Only check the symbol's kind if it has one.
3044 Indices prior to version 7 don't record it. */
3045 if (index
->version
>= 7)
3050 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3051 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3052 /* Some types are also in VAR_DOMAIN. */
3053 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3057 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3061 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3069 dw2_instantiate_symtab (per_cu
);
3076 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3077 enum block_enum block_kind
, const char *name
,
3080 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3084 dw2_print_stats (struct objfile
*objfile
)
3088 dw2_setup (objfile
);
3090 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3091 + dwarf2_per_objfile
->n_type_units
); ++i
)
3093 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3095 if (!per_cu
->v
.quick
->symtab
)
3098 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3102 dw2_dump (struct objfile
*objfile
)
3104 /* Nothing worth printing. */
3108 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3109 struct section_offsets
*delta
)
3111 /* There's nothing to relocate here. */
3115 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3116 const char *func_name
)
3118 /* Note: It doesn't matter what we pass for block_kind here. */
3119 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3124 dw2_expand_all_symtabs (struct objfile
*objfile
)
3128 dw2_setup (objfile
);
3130 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3131 + dwarf2_per_objfile
->n_type_units
); ++i
)
3133 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3135 dw2_instantiate_symtab (per_cu
);
3140 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3141 const char *filename
)
3145 dw2_setup (objfile
);
3147 /* We don't need to consider type units here.
3148 This is only called for examining code, e.g. expand_line_sal.
3149 There can be an order of magnitude (or more) more type units
3150 than comp units, and we avoid them if we can. */
3152 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3155 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3156 struct quick_file_names
*file_data
;
3158 /* We only need to look at symtabs not already expanded. */
3159 if (per_cu
->v
.quick
->symtab
)
3162 file_data
= dw2_get_file_names (objfile
, per_cu
);
3163 if (file_data
== NULL
)
3166 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3168 const char *this_name
= file_data
->file_names
[j
];
3169 if (FILENAME_CMP (this_name
, filename
) == 0)
3171 dw2_instantiate_symtab (per_cu
);
3178 /* A helper function for dw2_find_symbol_file that finds the primary
3179 file name for a given CU. This is a die_reader_func. */
3182 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3184 struct die_info
*comp_unit_die
,
3188 const char **result_ptr
= data
;
3189 struct dwarf2_cu
*cu
= reader
->cu
;
3190 struct attribute
*attr
;
3192 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3196 *result_ptr
= DW_STRING (attr
);
3200 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3202 struct dwarf2_per_cu_data
*per_cu
;
3204 struct quick_file_names
*file_data
;
3205 const char *filename
;
3207 dw2_setup (objfile
);
3209 /* index_table is NULL if OBJF_READNOW. */
3210 if (!dwarf2_per_objfile
->index_table
)
3214 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3216 struct blockvector
*bv
= BLOCKVECTOR (s
);
3217 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3218 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3221 return sym
->symtab
->filename
;
3226 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3230 /* Note that this just looks at the very first one named NAME -- but
3231 actually we are looking for a function. find_main_filename
3232 should be rewritten so that it doesn't require a custom hook. It
3233 could just use the ordinary symbol tables. */
3234 /* vec[0] is the length, which must always be >0. */
3235 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3237 if (per_cu
->v
.quick
->symtab
!= NULL
)
3238 return per_cu
->v
.quick
->symtab
->filename
;
3240 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3241 dw2_get_primary_filename_reader
, &filename
);
3247 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3248 struct objfile
*objfile
, int global
,
3249 int (*callback
) (struct block
*,
3250 struct symbol
*, void *),
3251 void *data
, symbol_compare_ftype
*match
,
3252 symbol_compare_ftype
*ordered_compare
)
3254 /* Currently unimplemented; used for Ada. The function can be called if the
3255 current language is Ada for a non-Ada objfile using GNU index. As Ada
3256 does not look for non-Ada symbols this function should just return. */
3260 dw2_expand_symtabs_matching
3261 (struct objfile
*objfile
,
3262 int (*file_matcher
) (const char *, void *),
3263 int (*name_matcher
) (const char *, void *),
3264 enum search_domain kind
,
3269 struct mapped_index
*index
;
3271 dw2_setup (objfile
);
3273 /* index_table is NULL if OBJF_READNOW. */
3274 if (!dwarf2_per_objfile
->index_table
)
3276 index
= dwarf2_per_objfile
->index_table
;
3278 if (file_matcher
!= NULL
)
3280 struct cleanup
*cleanup
;
3281 htab_t visited_found
, visited_not_found
;
3283 dw2_build_type_unit_groups ();
3285 visited_found
= htab_create_alloc (10,
3286 htab_hash_pointer
, htab_eq_pointer
,
3287 NULL
, xcalloc
, xfree
);
3288 cleanup
= make_cleanup_htab_delete (visited_found
);
3289 visited_not_found
= htab_create_alloc (10,
3290 htab_hash_pointer
, htab_eq_pointer
,
3291 NULL
, xcalloc
, xfree
);
3292 make_cleanup_htab_delete (visited_not_found
);
3294 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3295 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3298 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3299 struct quick_file_names
*file_data
;
3302 per_cu
->v
.quick
->mark
= 0;
3304 /* We only need to look at symtabs not already expanded. */
3305 if (per_cu
->v
.quick
->symtab
)
3308 file_data
= dw2_get_file_names (objfile
, per_cu
);
3309 if (file_data
== NULL
)
3312 if (htab_find (visited_not_found
, file_data
) != NULL
)
3314 else if (htab_find (visited_found
, file_data
) != NULL
)
3316 per_cu
->v
.quick
->mark
= 1;
3320 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3322 if (file_matcher (file_data
->file_names
[j
], data
))
3324 per_cu
->v
.quick
->mark
= 1;
3329 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3331 : visited_not_found
,
3336 do_cleanups (cleanup
);
3339 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3341 offset_type idx
= 2 * iter
;
3343 offset_type
*vec
, vec_len
, vec_idx
;
3345 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3348 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3350 if (! (*name_matcher
) (name
, data
))
3353 /* The name was matched, now expand corresponding CUs that were
3355 vec
= (offset_type
*) (index
->constant_pool
3356 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3357 vec_len
= MAYBE_SWAP (vec
[0]);
3358 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3360 struct dwarf2_per_cu_data
*per_cu
;
3361 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3362 gdb_index_symbol_kind symbol_kind
=
3363 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3364 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3366 /* Don't crash on bad data. */
3367 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3368 + dwarf2_per_objfile
->n_type_units
))
3371 /* Only check the symbol's kind if it has one.
3372 Indices prior to version 7 don't record it. */
3373 if (index
->version
>= 7)
3377 case VARIABLES_DOMAIN
:
3378 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3381 case FUNCTIONS_DOMAIN
:
3382 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3386 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3394 per_cu
= dw2_get_cu (cu_index
);
3395 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3396 dw2_instantiate_symtab (per_cu
);
3401 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3404 static struct symtab
*
3405 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3409 if (BLOCKVECTOR (symtab
) != NULL
3410 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3413 if (symtab
->includes
== NULL
)
3416 for (i
= 0; symtab
->includes
[i
]; ++i
)
3418 struct symtab
*s
= symtab
->includes
[i
];
3420 s
= recursively_find_pc_sect_symtab (s
, pc
);
3428 static struct symtab
*
3429 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3430 struct minimal_symbol
*msymbol
,
3432 struct obj_section
*section
,
3435 struct dwarf2_per_cu_data
*data
;
3436 struct symtab
*result
;
3438 dw2_setup (objfile
);
3440 if (!objfile
->psymtabs_addrmap
)
3443 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3447 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3448 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3449 paddress (get_objfile_arch (objfile
), pc
));
3451 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3452 gdb_assert (result
!= NULL
);
3457 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3458 void *data
, int need_fullname
)
3461 struct cleanup
*cleanup
;
3462 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3463 NULL
, xcalloc
, xfree
);
3465 cleanup
= make_cleanup_htab_delete (visited
);
3466 dw2_setup (objfile
);
3468 dw2_build_type_unit_groups ();
3470 /* We can ignore file names coming from already-expanded CUs. */
3471 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3472 + dwarf2_per_objfile
->n_type_units
); ++i
)
3474 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3476 if (per_cu
->v
.quick
->symtab
)
3478 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3481 *slot
= per_cu
->v
.quick
->file_names
;
3485 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3486 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3489 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3490 struct quick_file_names
*file_data
;
3493 /* We only need to look at symtabs not already expanded. */
3494 if (per_cu
->v
.quick
->symtab
)
3497 file_data
= dw2_get_file_names (objfile
, per_cu
);
3498 if (file_data
== NULL
)
3501 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3504 /* Already visited. */
3509 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3511 const char *this_real_name
;
3514 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3516 this_real_name
= NULL
;
3517 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3521 do_cleanups (cleanup
);
3525 dw2_has_symbols (struct objfile
*objfile
)
3530 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3533 dw2_find_last_source_symtab
,
3534 dw2_forget_cached_source_info
,
3535 dw2_map_symtabs_matching_filename
,
3537 dw2_pre_expand_symtabs_matching
,
3541 dw2_expand_symtabs_for_function
,
3542 dw2_expand_all_symtabs
,
3543 dw2_expand_symtabs_with_filename
,
3544 dw2_find_symbol_file
,
3545 dw2_map_matching_symbols
,
3546 dw2_expand_symtabs_matching
,
3547 dw2_find_pc_sect_symtab
,
3548 dw2_map_symbol_filenames
3551 /* Initialize for reading DWARF for this objfile. Return 0 if this
3552 file will use psymtabs, or 1 if using the GNU index. */
3555 dwarf2_initialize_objfile (struct objfile
*objfile
)
3557 /* If we're about to read full symbols, don't bother with the
3558 indices. In this case we also don't care if some other debug
3559 format is making psymtabs, because they are all about to be
3561 if ((objfile
->flags
& OBJF_READNOW
))
3565 dwarf2_per_objfile
->using_index
= 1;
3566 create_all_comp_units (objfile
);
3567 create_all_type_units (objfile
);
3568 dwarf2_per_objfile
->quick_file_names_table
=
3569 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3571 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3572 + dwarf2_per_objfile
->n_type_units
); ++i
)
3574 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3576 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3577 struct dwarf2_per_cu_quick_data
);
3580 /* Return 1 so that gdb sees the "quick" functions. However,
3581 these functions will be no-ops because we will have expanded
3586 if (dwarf2_read_index (objfile
))
3594 /* Build a partial symbol table. */
3597 dwarf2_build_psymtabs (struct objfile
*objfile
)
3599 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3601 init_psymbol_list (objfile
, 1024);
3604 dwarf2_build_psymtabs_hard (objfile
);
3607 /* Return the total length of the CU described by HEADER. */
3610 get_cu_length (const struct comp_unit_head
*header
)
3612 return header
->initial_length_size
+ header
->length
;
3615 /* Return TRUE if OFFSET is within CU_HEADER. */
3618 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3620 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3621 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3623 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3626 /* Find the base address of the compilation unit for range lists and
3627 location lists. It will normally be specified by DW_AT_low_pc.
3628 In DWARF-3 draft 4, the base address could be overridden by
3629 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3630 compilation units with discontinuous ranges. */
3633 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3635 struct attribute
*attr
;
3638 cu
->base_address
= 0;
3640 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3643 cu
->base_address
= DW_ADDR (attr
);
3648 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3651 cu
->base_address
= DW_ADDR (attr
);
3657 /* Read in the comp unit header information from the debug_info at info_ptr.
3658 NOTE: This leaves members offset, first_die_offset to be filled in
3662 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3663 gdb_byte
*info_ptr
, bfd
*abfd
)
3666 unsigned int bytes_read
;
3668 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3669 cu_header
->initial_length_size
= bytes_read
;
3670 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3671 info_ptr
+= bytes_read
;
3672 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3674 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3676 info_ptr
+= bytes_read
;
3677 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3679 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3680 if (signed_addr
< 0)
3681 internal_error (__FILE__
, __LINE__
,
3682 _("read_comp_unit_head: dwarf from non elf file"));
3683 cu_header
->signed_addr_p
= signed_addr
;
3688 /* Subroutine of read_and_check_comp_unit_head and
3689 read_and_check_type_unit_head to simplify them.
3690 Perform various error checking on the header. */
3693 error_check_comp_unit_head (struct comp_unit_head
*header
,
3694 struct dwarf2_section_info
*section
,
3695 struct dwarf2_section_info
*abbrev_section
)
3697 bfd
*abfd
= section
->asection
->owner
;
3698 const char *filename
= bfd_get_filename (abfd
);
3700 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3701 error (_("Dwarf Error: wrong version in compilation unit header "
3702 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3705 if (header
->abbrev_offset
.sect_off
3706 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
3707 &dwarf2_per_objfile
->abbrev
))
3708 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3709 "(offset 0x%lx + 6) [in module %s]"),
3710 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3713 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3714 avoid potential 32-bit overflow. */
3715 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3717 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3718 "(offset 0x%lx + 0) [in module %s]"),
3719 (long) header
->length
, (long) header
->offset
.sect_off
,
3723 /* Read in a CU/TU header and perform some basic error checking.
3724 The contents of the header are stored in HEADER.
3725 The result is a pointer to the start of the first DIE. */
3728 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3729 struct dwarf2_section_info
*section
,
3730 struct dwarf2_section_info
*abbrev_section
,
3732 int is_debug_types_section
)
3734 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3735 bfd
*abfd
= section
->asection
->owner
;
3737 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3739 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3741 /* If we're reading a type unit, skip over the signature and
3742 type_offset fields. */
3743 if (is_debug_types_section
)
3744 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3746 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3748 error_check_comp_unit_head (header
, section
, abbrev_section
);
3753 /* Read in the types comp unit header information from .debug_types entry at
3754 types_ptr. The result is a pointer to one past the end of the header. */
3757 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3758 struct dwarf2_section_info
*section
,
3759 struct dwarf2_section_info
*abbrev_section
,
3761 ULONGEST
*signature
,
3762 cu_offset
*type_offset_in_tu
)
3764 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3765 bfd
*abfd
= section
->asection
->owner
;
3767 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3769 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3771 /* If we're reading a type unit, skip over the signature and
3772 type_offset fields. */
3773 if (signature
!= NULL
)
3774 *signature
= read_8_bytes (abfd
, info_ptr
);
3776 if (type_offset_in_tu
!= NULL
)
3777 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3778 header
->offset_size
);
3779 info_ptr
+= header
->offset_size
;
3781 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3783 error_check_comp_unit_head (header
, section
, abbrev_section
);
3788 /* Fetch the abbreviation table offset from a comp or type unit header. */
3791 read_abbrev_offset (struct dwarf2_section_info
*section
,
3794 bfd
*abfd
= section
->asection
->owner
;
3796 unsigned int length
, initial_length_size
, offset_size
;
3797 sect_offset abbrev_offset
;
3799 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3800 info_ptr
= section
->buffer
+ offset
.sect_off
;
3801 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3802 offset_size
= initial_length_size
== 4 ? 4 : 8;
3803 info_ptr
+= initial_length_size
+ 2 /*version*/;
3804 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3805 return abbrev_offset
;
3808 /* Allocate a new partial symtab for file named NAME and mark this new
3809 partial symtab as being an include of PST. */
3812 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3813 struct objfile
*objfile
)
3815 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3817 subpst
->section_offsets
= pst
->section_offsets
;
3818 subpst
->textlow
= 0;
3819 subpst
->texthigh
= 0;
3821 subpst
->dependencies
= (struct partial_symtab
**)
3822 obstack_alloc (&objfile
->objfile_obstack
,
3823 sizeof (struct partial_symtab
*));
3824 subpst
->dependencies
[0] = pst
;
3825 subpst
->number_of_dependencies
= 1;
3827 subpst
->globals_offset
= 0;
3828 subpst
->n_global_syms
= 0;
3829 subpst
->statics_offset
= 0;
3830 subpst
->n_static_syms
= 0;
3831 subpst
->symtab
= NULL
;
3832 subpst
->read_symtab
= pst
->read_symtab
;
3835 /* No private part is necessary for include psymtabs. This property
3836 can be used to differentiate between such include psymtabs and
3837 the regular ones. */
3838 subpst
->read_symtab_private
= NULL
;
3841 /* Read the Line Number Program data and extract the list of files
3842 included by the source file represented by PST. Build an include
3843 partial symtab for each of these included files. */
3846 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3847 struct die_info
*die
,
3848 struct partial_symtab
*pst
)
3850 struct line_header
*lh
= NULL
;
3851 struct attribute
*attr
;
3853 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3855 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3857 return; /* No linetable, so no includes. */
3859 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3860 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3862 free_line_header (lh
);
3866 hash_signatured_type (const void *item
)
3868 const struct signatured_type
*sig_type
= item
;
3870 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3871 return sig_type
->signature
;
3875 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3877 const struct signatured_type
*lhs
= item_lhs
;
3878 const struct signatured_type
*rhs
= item_rhs
;
3880 return lhs
->signature
== rhs
->signature
;
3883 /* Allocate a hash table for signatured types. */
3886 allocate_signatured_type_table (struct objfile
*objfile
)
3888 return htab_create_alloc_ex (41,
3889 hash_signatured_type
,
3892 &objfile
->objfile_obstack
,
3893 hashtab_obstack_allocate
,
3894 dummy_obstack_deallocate
);
3897 /* A helper function to add a signatured type CU to a table. */
3900 add_signatured_type_cu_to_table (void **slot
, void *datum
)
3902 struct signatured_type
*sigt
= *slot
;
3903 struct signatured_type
***datap
= datum
;
3911 /* Create the hash table of all entries in the .debug_types section.
3912 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
3913 The result is a pointer to the hash table or NULL if there are
3917 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
3918 VEC (dwarf2_section_info_def
) *types
)
3920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3921 htab_t types_htab
= NULL
;
3923 struct dwarf2_section_info
*section
;
3924 struct dwarf2_section_info
*abbrev_section
;
3926 if (VEC_empty (dwarf2_section_info_def
, types
))
3929 abbrev_section
= (dwo_file
!= NULL
3930 ? &dwo_file
->sections
.abbrev
3931 : &dwarf2_per_objfile
->abbrev
);
3933 if (dwarf2_read_debug
)
3934 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
3935 dwo_file
? ".dwo" : "",
3936 bfd_get_filename (abbrev_section
->asection
->owner
));
3939 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
3943 gdb_byte
*info_ptr
, *end_ptr
;
3945 dwarf2_read_section (objfile
, section
);
3946 info_ptr
= section
->buffer
;
3948 if (info_ptr
== NULL
)
3951 /* We can't set abfd until now because the section may be empty or
3952 not present, in which case section->asection will be NULL. */
3953 abfd
= section
->asection
->owner
;
3955 if (types_htab
== NULL
)
3958 types_htab
= allocate_dwo_unit_table (objfile
);
3960 types_htab
= allocate_signatured_type_table (objfile
);
3963 /* We don't use init_cutu_and_read_dies_simple, or some such, here
3964 because we don't need to read any dies: the signature is in the
3967 end_ptr
= info_ptr
+ section
->size
;
3968 while (info_ptr
< end_ptr
)
3971 cu_offset type_offset_in_tu
;
3973 struct signatured_type
*sig_type
;
3974 struct dwo_unit
*dwo_tu
;
3976 gdb_byte
*ptr
= info_ptr
;
3977 struct comp_unit_head header
;
3978 unsigned int length
;
3980 offset
.sect_off
= ptr
- section
->buffer
;
3982 /* We need to read the type's signature in order to build the hash
3983 table, but we don't need anything else just yet. */
3985 ptr
= read_and_check_type_unit_head (&header
, section
,
3986 abbrev_section
, ptr
,
3987 &signature
, &type_offset_in_tu
);
3989 length
= get_cu_length (&header
);
3991 /* Skip dummy type units. */
3992 if (ptr
>= info_ptr
+ length
3993 || peek_abbrev_code (abfd
, ptr
) == 0)
4002 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4004 dwo_tu
->dwo_file
= dwo_file
;
4005 dwo_tu
->signature
= signature
;
4006 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4007 dwo_tu
->info_or_types_section
= section
;
4008 dwo_tu
->offset
= offset
;
4009 dwo_tu
->length
= length
;
4013 /* N.B.: type_offset is not usable if this type uses a DWO file.
4014 The real type_offset is in the DWO file. */
4016 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4017 struct signatured_type
);
4018 sig_type
->signature
= signature
;
4019 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4020 sig_type
->per_cu
.objfile
= objfile
;
4021 sig_type
->per_cu
.is_debug_types
= 1;
4022 sig_type
->per_cu
.info_or_types_section
= section
;
4023 sig_type
->per_cu
.offset
= offset
;
4024 sig_type
->per_cu
.length
= length
;
4027 slot
= htab_find_slot (types_htab
,
4028 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4030 gdb_assert (slot
!= NULL
);
4033 sect_offset dup_offset
;
4037 const struct dwo_unit
*dup_tu
= *slot
;
4039 dup_offset
= dup_tu
->offset
;
4043 const struct signatured_type
*dup_tu
= *slot
;
4045 dup_offset
= dup_tu
->per_cu
.offset
;
4048 complaint (&symfile_complaints
,
4049 _("debug type entry at offset 0x%x is duplicate to the "
4050 "entry at offset 0x%x, signature 0x%s"),
4051 offset
.sect_off
, dup_offset
.sect_off
,
4052 phex (signature
, sizeof (signature
)));
4054 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4056 if (dwarf2_read_debug
)
4057 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4059 phex (signature
, sizeof (signature
)));
4068 /* Create the hash table of all entries in the .debug_types section,
4069 and initialize all_type_units.
4070 The result is zero if there is an error (e.g. missing .debug_types section),
4071 otherwise non-zero. */
4074 create_all_type_units (struct objfile
*objfile
)
4077 struct signatured_type
**iter
;
4079 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4080 if (types_htab
== NULL
)
4082 dwarf2_per_objfile
->signatured_types
= NULL
;
4086 dwarf2_per_objfile
->signatured_types
= types_htab
;
4088 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4089 dwarf2_per_objfile
->all_type_units
4090 = obstack_alloc (&objfile
->objfile_obstack
,
4091 dwarf2_per_objfile
->n_type_units
4092 * sizeof (struct signatured_type
*));
4093 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4094 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4095 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4096 == dwarf2_per_objfile
->n_type_units
);
4101 /* Lookup a signature based type for DW_FORM_ref_sig8.
4102 Returns NULL if signature SIG is not present in the table. */
4104 static struct signatured_type
*
4105 lookup_signatured_type (ULONGEST sig
)
4107 struct signatured_type find_entry
, *entry
;
4109 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4111 complaint (&symfile_complaints
,
4112 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4116 find_entry
.signature
= sig
;
4117 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4121 /* Low level DIE reading support. */
4123 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4126 init_cu_die_reader (struct die_reader_specs
*reader
,
4127 struct dwarf2_cu
*cu
,
4128 struct dwarf2_section_info
*section
,
4129 struct dwo_file
*dwo_file
)
4131 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4132 reader
->abfd
= section
->asection
->owner
;
4134 reader
->dwo_file
= dwo_file
;
4135 reader
->die_section
= section
;
4136 reader
->buffer
= section
->buffer
;
4137 reader
->buffer_end
= section
->buffer
+ section
->size
;
4140 /* Initialize a CU (or TU) and read its DIEs.
4141 If the CU defers to a DWO file, read the DWO file as well.
4143 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4144 Otherwise the table specified in the comp unit header is read in and used.
4145 This is an optimization for when we already have the abbrev table.
4147 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4148 Otherwise, a new CU is allocated with xmalloc.
4150 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4151 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4153 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4154 linker) then DIE_READER_FUNC will not get called. */
4157 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4158 struct abbrev_table
*abbrev_table
,
4159 int use_existing_cu
, int keep
,
4160 die_reader_func_ftype
*die_reader_func
,
4163 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4164 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4165 bfd
*abfd
= section
->asection
->owner
;
4166 struct dwarf2_cu
*cu
;
4167 gdb_byte
*begin_info_ptr
, *info_ptr
;
4168 struct die_reader_specs reader
;
4169 struct die_info
*comp_unit_die
;
4171 struct attribute
*attr
;
4172 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4173 struct signatured_type
*sig_type
= NULL
;
4174 struct dwarf2_section_info
*abbrev_section
;
4175 /* Non-zero if CU currently points to a DWO file and we need to
4176 reread it. When this happens we need to reread the skeleton die
4177 before we can reread the DWO file. */
4178 int rereading_dwo_cu
= 0;
4180 if (dwarf2_die_debug
)
4181 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4182 this_cu
->is_debug_types
? "type" : "comp",
4183 this_cu
->offset
.sect_off
);
4185 if (use_existing_cu
)
4188 cleanups
= make_cleanup (null_cleanup
, NULL
);
4190 /* This is cheap if the section is already read in. */
4191 dwarf2_read_section (objfile
, section
);
4193 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4194 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4196 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4200 /* If this CU is from a DWO file we need to start over, we need to
4201 refetch the attributes from the skeleton CU.
4202 This could be optimized by retrieving those attributes from when we
4203 were here the first time: the previous comp_unit_die was stored in
4204 comp_unit_obstack. But there's no data yet that we need this
4206 if (cu
->dwo_unit
!= NULL
)
4207 rereading_dwo_cu
= 1;
4211 /* If !use_existing_cu, this_cu->cu must be NULL. */
4212 gdb_assert (this_cu
->cu
== NULL
);
4214 cu
= xmalloc (sizeof (*cu
));
4215 init_one_comp_unit (cu
, this_cu
);
4217 /* If an error occurs while loading, release our storage. */
4218 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4221 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4223 /* We already have the header, there's no need to read it in again. */
4224 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4228 if (this_cu
->is_debug_types
)
4231 cu_offset type_offset_in_tu
;
4233 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4234 abbrev_section
, info_ptr
,
4236 &type_offset_in_tu
);
4238 /* Since per_cu is the first member of struct signatured_type,
4239 we can go from a pointer to one to a pointer to the other. */
4240 sig_type
= (struct signatured_type
*) this_cu
;
4241 gdb_assert (sig_type
->signature
== signature
);
4242 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4243 == type_offset_in_tu
.cu_off
);
4244 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4246 /* LENGTH has not been set yet for type units if we're
4247 using .gdb_index. */
4248 this_cu
->length
= get_cu_length (&cu
->header
);
4250 /* Establish the type offset that can be used to lookup the type. */
4251 sig_type
->type_offset_in_section
.sect_off
=
4252 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4256 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4260 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4261 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4265 /* Skip dummy compilation units. */
4266 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4267 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4269 do_cleanups (cleanups
);
4273 /* If we don't have them yet, read the abbrevs for this compilation unit.
4274 And if we need to read them now, make sure they're freed when we're
4275 done. Note that it's important that if the CU had an abbrev table
4276 on entry we don't free it when we're done: Somewhere up the call stack
4277 it may be in use. */
4278 if (abbrev_table
!= NULL
)
4280 gdb_assert (cu
->abbrev_table
== NULL
);
4281 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4282 == abbrev_table
->offset
.sect_off
);
4283 cu
->abbrev_table
= abbrev_table
;
4285 else if (cu
->abbrev_table
== NULL
)
4287 dwarf2_read_abbrevs (cu
, abbrev_section
);
4288 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4290 else if (rereading_dwo_cu
)
4292 dwarf2_free_abbrev_table (cu
);
4293 dwarf2_read_abbrevs (cu
, abbrev_section
);
4296 /* Read the top level CU/TU die. */
4297 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4298 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4300 /* If we have a DWO stub, process it and then read in the DWO file.
4301 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4302 a DWO CU, that this test will fail. */
4303 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4306 char *dwo_name
= DW_STRING (attr
);
4307 const char *comp_dir_string
;
4308 struct dwo_unit
*dwo_unit
;
4309 ULONGEST signature
; /* Or dwo_id. */
4310 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4311 int i
,num_extra_attrs
;
4312 struct dwarf2_section_info
*dwo_abbrev_section
;
4315 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4316 " has children (offset 0x%x) [in module %s]"),
4317 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4319 /* These attributes aren't processed until later:
4320 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4321 However, the attribute is found in the stub which we won't have later.
4322 In order to not impose this complication on the rest of the code,
4323 we read them here and copy them to the DWO CU/TU die. */
4325 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4328 if (! this_cu
->is_debug_types
)
4329 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4330 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4331 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4332 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4333 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4335 /* There should be a DW_AT_addr_base attribute here (if needed).
4336 We need the value before we can process DW_FORM_GNU_addr_index. */
4338 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4340 cu
->addr_base
= DW_UNSND (attr
);
4342 /* There should be a DW_AT_ranges_base attribute here (if needed).
4343 We need the value before we can process DW_AT_ranges. */
4344 cu
->ranges_base
= 0;
4345 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4347 cu
->ranges_base
= DW_UNSND (attr
);
4349 if (this_cu
->is_debug_types
)
4351 gdb_assert (sig_type
!= NULL
);
4352 signature
= sig_type
->signature
;
4356 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4358 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4360 signature
= DW_UNSND (attr
);
4363 /* We may need the comp_dir in order to find the DWO file. */
4364 comp_dir_string
= NULL
;
4366 comp_dir_string
= DW_STRING (comp_dir
);
4368 if (this_cu
->is_debug_types
)
4369 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4371 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4374 if (dwo_unit
== NULL
)
4376 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4377 " with ID %s [in module %s]"),
4378 this_cu
->offset
.sect_off
,
4379 phex (signature
, sizeof (signature
)),
4383 /* Set up for reading the DWO CU/TU. */
4384 cu
->dwo_unit
= dwo_unit
;
4385 section
= dwo_unit
->info_or_types_section
;
4386 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4387 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4388 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4390 if (this_cu
->is_debug_types
)
4394 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4398 gdb_assert (sig_type
->signature
== signature
);
4399 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4400 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4402 /* Establish the type offset that can be used to lookup the type.
4403 For DWO files, we don't know it until now. */
4404 sig_type
->type_offset_in_section
.sect_off
=
4405 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4409 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4412 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4413 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4416 /* Discard the original CU's abbrev table, and read the DWO's. */
4417 if (abbrev_table
== NULL
)
4419 dwarf2_free_abbrev_table (cu
);
4420 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4424 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4425 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4428 /* Read in the die, but leave space to copy over the attributes
4429 from the stub. This has the benefit of simplifying the rest of
4430 the code - all the real work is done here. */
4431 num_extra_attrs
= ((stmt_list
!= NULL
)
4435 + (comp_dir
!= NULL
));
4436 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4437 &has_children
, num_extra_attrs
);
4439 /* Copy over the attributes from the stub to the DWO die. */
4440 i
= comp_unit_die
->num_attrs
;
4441 if (stmt_list
!= NULL
)
4442 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4444 comp_unit_die
->attrs
[i
++] = *low_pc
;
4445 if (high_pc
!= NULL
)
4446 comp_unit_die
->attrs
[i
++] = *high_pc
;
4448 comp_unit_die
->attrs
[i
++] = *ranges
;
4449 if (comp_dir
!= NULL
)
4450 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4451 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4453 /* Skip dummy compilation units. */
4454 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4455 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4457 do_cleanups (cleanups
);
4462 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4464 if (free_cu_cleanup
!= NULL
)
4468 /* We've successfully allocated this compilation unit. Let our
4469 caller clean it up when finished with it. */
4470 discard_cleanups (free_cu_cleanup
);
4472 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4473 So we have to manually free the abbrev table. */
4474 dwarf2_free_abbrev_table (cu
);
4476 /* Link this CU into read_in_chain. */
4477 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4478 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4481 do_cleanups (free_cu_cleanup
);
4484 do_cleanups (cleanups
);
4487 /* Read CU/TU THIS_CU in section SECTION,
4488 but do not follow DW_AT_GNU_dwo_name if present.
4489 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4490 have already done the lookup to find the DWO file).
4492 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4493 THIS_CU->is_debug_types, but nothing else.
4495 We fill in THIS_CU->length.
4497 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4498 linker) then DIE_READER_FUNC will not get called.
4500 THIS_CU->cu is always freed when done.
4501 This is done in order to not leave THIS_CU->cu in a state where we have
4502 to care whether it refers to the "main" CU or the DWO CU. */
4505 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4506 struct dwarf2_section_info
*abbrev_section
,
4507 struct dwo_file
*dwo_file
,
4508 die_reader_func_ftype
*die_reader_func
,
4511 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4512 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4513 bfd
*abfd
= section
->asection
->owner
;
4514 struct dwarf2_cu cu
;
4515 gdb_byte
*begin_info_ptr
, *info_ptr
;
4516 struct die_reader_specs reader
;
4517 struct cleanup
*cleanups
;
4518 struct die_info
*comp_unit_die
;
4521 if (dwarf2_die_debug
)
4522 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4523 this_cu
->is_debug_types
? "type" : "comp",
4524 this_cu
->offset
.sect_off
);
4526 gdb_assert (this_cu
->cu
== NULL
);
4528 /* This is cheap if the section is already read in. */
4529 dwarf2_read_section (objfile
, section
);
4531 init_one_comp_unit (&cu
, this_cu
);
4533 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4535 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4536 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4537 abbrev_section
, info_ptr
,
4538 this_cu
->is_debug_types
);
4540 this_cu
->length
= get_cu_length (&cu
.header
);
4542 /* Skip dummy compilation units. */
4543 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4544 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4546 do_cleanups (cleanups
);
4550 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4551 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4553 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4554 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4556 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4558 do_cleanups (cleanups
);
4561 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4562 does not lookup the specified DWO file.
4563 This cannot be used to read DWO files.
4565 THIS_CU->cu is always freed when done.
4566 This is done in order to not leave THIS_CU->cu in a state where we have
4567 to care whether it refers to the "main" CU or the DWO CU.
4568 We can revisit this if the data shows there's a performance issue. */
4571 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4572 die_reader_func_ftype
*die_reader_func
,
4575 init_cutu_and_read_dies_no_follow (this_cu
,
4576 &dwarf2_per_objfile
->abbrev
,
4578 die_reader_func
, data
);
4581 /* Create a psymtab named NAME and assign it to PER_CU.
4583 The caller must fill in the following details:
4584 dirname, textlow, texthigh. */
4586 static struct partial_symtab
*
4587 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4589 struct objfile
*objfile
= per_cu
->objfile
;
4590 struct partial_symtab
*pst
;
4592 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4594 objfile
->global_psymbols
.next
,
4595 objfile
->static_psymbols
.next
);
4597 pst
->psymtabs_addrmap_supported
= 1;
4599 /* This is the glue that links PST into GDB's symbol API. */
4600 pst
->read_symtab_private
= per_cu
;
4601 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4602 per_cu
->v
.psymtab
= pst
;
4607 /* die_reader_func for process_psymtab_comp_unit. */
4610 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4612 struct die_info
*comp_unit_die
,
4616 struct dwarf2_cu
*cu
= reader
->cu
;
4617 struct objfile
*objfile
= cu
->objfile
;
4618 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4619 struct attribute
*attr
;
4621 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4622 struct partial_symtab
*pst
;
4624 const char *filename
;
4625 int *want_partial_unit_ptr
= data
;
4627 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4628 && (want_partial_unit_ptr
== NULL
4629 || !*want_partial_unit_ptr
))
4632 gdb_assert (! per_cu
->is_debug_types
);
4634 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4636 cu
->list_in_scope
= &file_symbols
;
4638 /* Allocate a new partial symbol table structure. */
4639 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4640 if (attr
== NULL
|| !DW_STRING (attr
))
4643 filename
= DW_STRING (attr
);
4645 pst
= create_partial_symtab (per_cu
, filename
);
4647 /* This must be done before calling dwarf2_build_include_psymtabs. */
4648 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4650 pst
->dirname
= DW_STRING (attr
);
4652 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4654 dwarf2_find_base_address (comp_unit_die
, cu
);
4656 /* Possibly set the default values of LOWPC and HIGHPC from
4658 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4659 &best_highpc
, cu
, pst
);
4660 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4661 /* Store the contiguous range if it is not empty; it can be empty for
4662 CUs with no code. */
4663 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4664 best_lowpc
+ baseaddr
,
4665 best_highpc
+ baseaddr
- 1, pst
);
4667 /* Check if comp unit has_children.
4668 If so, read the rest of the partial symbols from this comp unit.
4669 If not, there's no more debug_info for this comp unit. */
4672 struct partial_die_info
*first_die
;
4673 CORE_ADDR lowpc
, highpc
;
4675 lowpc
= ((CORE_ADDR
) -1);
4676 highpc
= ((CORE_ADDR
) 0);
4678 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4680 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4683 /* If we didn't find a lowpc, set it to highpc to avoid
4684 complaints from `maint check'. */
4685 if (lowpc
== ((CORE_ADDR
) -1))
4688 /* If the compilation unit didn't have an explicit address range,
4689 then use the information extracted from its child dies. */
4693 best_highpc
= highpc
;
4696 pst
->textlow
= best_lowpc
+ baseaddr
;
4697 pst
->texthigh
= best_highpc
+ baseaddr
;
4699 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4700 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4701 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4702 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4703 sort_pst_symbols (pst
);
4705 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4708 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4709 struct dwarf2_per_cu_data
*iter
;
4711 /* Fill in 'dependencies' here; we fill in 'users' in a
4713 pst
->number_of_dependencies
= len
;
4714 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4715 len
* sizeof (struct symtab
*));
4717 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4720 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4722 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4725 /* Get the list of files included in the current compilation unit,
4726 and build a psymtab for each of them. */
4727 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4729 if (dwarf2_read_debug
)
4731 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4733 fprintf_unfiltered (gdb_stdlog
,
4734 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4735 ", %d global, %d static syms\n",
4736 per_cu
->is_debug_types
? "type" : "comp",
4737 per_cu
->offset
.sect_off
,
4738 paddress (gdbarch
, pst
->textlow
),
4739 paddress (gdbarch
, pst
->texthigh
),
4740 pst
->n_global_syms
, pst
->n_static_syms
);
4744 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4745 Process compilation unit THIS_CU for a psymtab. */
4748 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4749 int want_partial_unit
)
4751 /* If this compilation unit was already read in, free the
4752 cached copy in order to read it in again. This is
4753 necessary because we skipped some symbols when we first
4754 read in the compilation unit (see load_partial_dies).
4755 This problem could be avoided, but the benefit is unclear. */
4756 if (this_cu
->cu
!= NULL
)
4757 free_one_cached_comp_unit (this_cu
);
4759 gdb_assert (! this_cu
->is_debug_types
);
4760 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4761 process_psymtab_comp_unit_reader
,
4762 &want_partial_unit
);
4764 /* Age out any secondary CUs. */
4765 age_cached_comp_units ();
4769 hash_type_unit_group (const void *item
)
4771 const struct type_unit_group
*tu_group
= item
;
4773 return hash_stmt_list_entry (&tu_group
->hash
);
4777 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4779 const struct type_unit_group
*lhs
= item_lhs
;
4780 const struct type_unit_group
*rhs
= item_rhs
;
4782 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4785 /* Allocate a hash table for type unit groups. */
4788 allocate_type_unit_groups_table (void)
4790 return htab_create_alloc_ex (3,
4791 hash_type_unit_group
,
4794 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4795 hashtab_obstack_allocate
,
4796 dummy_obstack_deallocate
);
4799 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4800 partial symtabs. We combine several TUs per psymtab to not let the size
4801 of any one psymtab grow too big. */
4802 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4803 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4805 /* Helper routine for get_type_unit_group.
4806 Create the type_unit_group object used to hold one or more TUs. */
4808 static struct type_unit_group
*
4809 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4811 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4812 struct dwarf2_per_cu_data
*per_cu
;
4813 struct type_unit_group
*tu_group
;
4815 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4816 struct type_unit_group
);
4817 per_cu
= &tu_group
->per_cu
;
4818 per_cu
->objfile
= objfile
;
4819 per_cu
->is_debug_types
= 1;
4820 per_cu
->s
.type_unit_group
= tu_group
;
4822 if (dwarf2_per_objfile
->using_index
)
4824 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4825 struct dwarf2_per_cu_quick_data
);
4826 tu_group
->t
.first_tu
= cu
->per_cu
;
4830 unsigned int line_offset
= line_offset_struct
.sect_off
;
4831 struct partial_symtab
*pst
;
4834 /* Give the symtab a useful name for debug purposes. */
4835 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
4836 name
= xstrprintf ("<type_units_%d>",
4837 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
4839 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
4841 pst
= create_partial_symtab (per_cu
, name
);
4847 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4848 tu_group
->hash
.line_offset
= line_offset_struct
;
4853 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4854 STMT_LIST is a DW_AT_stmt_list attribute. */
4856 static struct type_unit_group
*
4857 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
4859 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4860 struct type_unit_group
*tu_group
;
4862 unsigned int line_offset
;
4863 struct type_unit_group type_unit_group_for_lookup
;
4865 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
4867 dwarf2_per_objfile
->type_unit_groups
=
4868 allocate_type_unit_groups_table ();
4871 /* Do we need to create a new group, or can we use an existing one? */
4875 line_offset
= DW_UNSND (stmt_list
);
4876 ++tu_stats
->nr_symtab_sharers
;
4880 /* Ugh, no stmt_list. Rare, but we have to handle it.
4881 We can do various things here like create one group per TU or
4882 spread them over multiple groups to split up the expansion work.
4883 To avoid worst case scenarios (too many groups or too large groups)
4884 we, umm, group them in bunches. */
4885 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
4886 | (tu_stats
->nr_stmt_less_type_units
4887 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
4888 ++tu_stats
->nr_stmt_less_type_units
;
4891 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
4892 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
4893 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
4894 &type_unit_group_for_lookup
, INSERT
);
4898 gdb_assert (tu_group
!= NULL
);
4902 sect_offset line_offset_struct
;
4904 line_offset_struct
.sect_off
= line_offset
;
4905 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
4907 ++tu_stats
->nr_symtabs
;
4913 /* Struct used to sort TUs by their abbreviation table offset. */
4915 struct tu_abbrev_offset
4917 struct signatured_type
*sig_type
;
4918 sect_offset abbrev_offset
;
4921 /* Helper routine for build_type_unit_groups, passed to qsort. */
4924 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
4926 const struct tu_abbrev_offset
* const *a
= ap
;
4927 const struct tu_abbrev_offset
* const *b
= bp
;
4928 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
4929 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
4931 return (aoff
> boff
) - (aoff
< boff
);
4934 /* A helper function to add a type_unit_group to a table. */
4937 add_type_unit_group_to_table (void **slot
, void *datum
)
4939 struct type_unit_group
*tu_group
= *slot
;
4940 struct type_unit_group
***datap
= datum
;
4948 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
4949 each one passing FUNC,DATA.
4951 The efficiency is because we sort TUs by the abbrev table they use and
4952 only read each abbrev table once. In one program there are 200K TUs
4953 sharing 8K abbrev tables.
4955 The main purpose of this function is to support building the
4956 dwarf2_per_objfile->type_unit_groups table.
4957 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
4958 can collapse the search space by grouping them by stmt_list.
4959 The savings can be significant, in the same program from above the 200K TUs
4960 share 8K stmt_list tables.
4962 FUNC is expected to call get_type_unit_group, which will create the
4963 struct type_unit_group if necessary and add it to
4964 dwarf2_per_objfile->type_unit_groups. */
4967 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
4969 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4970 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4971 struct cleanup
*cleanups
;
4972 struct abbrev_table
*abbrev_table
;
4973 sect_offset abbrev_offset
;
4974 struct tu_abbrev_offset
*sorted_by_abbrev
;
4975 struct type_unit_group
**iter
;
4978 /* It's up to the caller to not call us multiple times. */
4979 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
4981 if (dwarf2_per_objfile
->n_type_units
== 0)
4984 /* TUs typically share abbrev tables, and there can be way more TUs than
4985 abbrev tables. Sort by abbrev table to reduce the number of times we
4986 read each abbrev table in.
4987 Alternatives are to punt or to maintain a cache of abbrev tables.
4988 This is simpler and efficient enough for now.
4990 Later we group TUs by their DW_AT_stmt_list value (as this defines the
4991 symtab to use). Typically TUs with the same abbrev offset have the same
4992 stmt_list value too so in practice this should work well.
4994 The basic algorithm here is:
4996 sort TUs by abbrev table
4997 for each TU with same abbrev table:
4998 read abbrev table if first user
4999 read TU top level DIE
5000 [IWBN if DWO skeletons had DW_AT_stmt_list]
5003 if (dwarf2_read_debug
)
5004 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5006 /* Sort in a separate table to maintain the order of all_type_units
5007 for .gdb_index: TU indices directly index all_type_units. */
5008 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5009 dwarf2_per_objfile
->n_type_units
);
5010 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5012 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5014 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5015 sorted_by_abbrev
[i
].abbrev_offset
=
5016 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5017 sig_type
->per_cu
.offset
);
5019 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5020 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5021 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5023 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5024 called any number of times, so we don't reset tu_stats here. */
5026 abbrev_offset
.sect_off
= ~(unsigned) 0;
5027 abbrev_table
= NULL
;
5028 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5030 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5032 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5034 /* Switch to the next abbrev table if necessary. */
5035 if (abbrev_table
== NULL
5036 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5038 if (abbrev_table
!= NULL
)
5040 abbrev_table_free (abbrev_table
);
5041 /* Reset to NULL in case abbrev_table_read_table throws
5042 an error: abbrev_table_free_cleanup will get called. */
5043 abbrev_table
= NULL
;
5045 abbrev_offset
= tu
->abbrev_offset
;
5047 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5049 ++tu_stats
->nr_uniq_abbrev_tables
;
5052 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5056 /* Create a vector of pointers to primary type units to make it easy to
5057 iterate over them and CUs. See dw2_get_primary_cu. */
5058 dwarf2_per_objfile
->n_type_unit_groups
=
5059 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5060 dwarf2_per_objfile
->all_type_unit_groups
=
5061 obstack_alloc (&objfile
->objfile_obstack
,
5062 dwarf2_per_objfile
->n_type_unit_groups
5063 * sizeof (struct type_unit_group
*));
5064 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5065 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5066 add_type_unit_group_to_table
, &iter
);
5067 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5068 == dwarf2_per_objfile
->n_type_unit_groups
);
5070 do_cleanups (cleanups
);
5072 if (dwarf2_read_debug
)
5074 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5075 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5076 dwarf2_per_objfile
->n_type_units
);
5077 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5078 tu_stats
->nr_uniq_abbrev_tables
);
5079 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5080 tu_stats
->nr_symtabs
);
5081 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5082 tu_stats
->nr_symtab_sharers
);
5083 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5084 tu_stats
->nr_stmt_less_type_units
);
5088 /* Reader function for build_type_psymtabs. */
5091 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5093 struct die_info
*type_unit_die
,
5097 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5098 struct dwarf2_cu
*cu
= reader
->cu
;
5099 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5100 struct type_unit_group
*tu_group
;
5101 struct attribute
*attr
;
5102 struct partial_die_info
*first_die
;
5103 CORE_ADDR lowpc
, highpc
;
5104 struct partial_symtab
*pst
;
5106 gdb_assert (data
== NULL
);
5111 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5112 tu_group
= get_type_unit_group (cu
, attr
);
5114 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5116 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5117 cu
->list_in_scope
= &file_symbols
;
5118 pst
= create_partial_symtab (per_cu
, "");
5121 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5123 lowpc
= (CORE_ADDR
) -1;
5124 highpc
= (CORE_ADDR
) 0;
5125 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5127 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5128 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5129 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5130 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5131 sort_pst_symbols (pst
);
5134 /* Traversal function for build_type_psymtabs. */
5137 build_type_psymtab_dependencies (void **slot
, void *info
)
5139 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5140 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5141 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5142 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5143 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5144 struct dwarf2_per_cu_data
*iter
;
5147 gdb_assert (len
> 0);
5149 pst
->number_of_dependencies
= len
;
5150 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5151 len
* sizeof (struct psymtab
*));
5153 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5156 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5157 iter
->s
.type_unit_group
= tu_group
;
5160 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5165 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5166 Build partial symbol tables for the .debug_types comp-units. */
5169 build_type_psymtabs (struct objfile
*objfile
)
5171 if (! create_all_type_units (objfile
))
5174 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5176 /* Now that all TUs have been processed we can fill in the dependencies. */
5177 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5178 build_type_psymtab_dependencies
, NULL
);
5181 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5184 psymtabs_addrmap_cleanup (void *o
)
5186 struct objfile
*objfile
= o
;
5188 objfile
->psymtabs_addrmap
= NULL
;
5191 /* Compute the 'user' field for each psymtab in OBJFILE. */
5194 set_partial_user (struct objfile
*objfile
)
5198 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5200 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5201 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5204 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5206 /* Set the 'user' field only if it is not already set. */
5207 if (pst
->dependencies
[j
]->user
== NULL
)
5208 pst
->dependencies
[j
]->user
= pst
;
5213 /* Build the partial symbol table by doing a quick pass through the
5214 .debug_info and .debug_abbrev sections. */
5217 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5219 struct cleanup
*back_to
, *addrmap_cleanup
;
5220 struct obstack temp_obstack
;
5223 if (dwarf2_read_debug
)
5225 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5229 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5231 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5233 /* Any cached compilation units will be linked by the per-objfile
5234 read_in_chain. Make sure to free them when we're done. */
5235 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5237 build_type_psymtabs (objfile
);
5239 create_all_comp_units (objfile
);
5241 /* Create a temporary address map on a temporary obstack. We later
5242 copy this to the final obstack. */
5243 obstack_init (&temp_obstack
);
5244 make_cleanup_obstack_free (&temp_obstack
);
5245 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5246 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5248 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5250 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5252 process_psymtab_comp_unit (per_cu
, 0);
5255 set_partial_user (objfile
);
5257 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5258 &objfile
->objfile_obstack
);
5259 discard_cleanups (addrmap_cleanup
);
5261 do_cleanups (back_to
);
5263 if (dwarf2_read_debug
)
5264 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5268 /* die_reader_func for load_partial_comp_unit. */
5271 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5273 struct die_info
*comp_unit_die
,
5277 struct dwarf2_cu
*cu
= reader
->cu
;
5279 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5281 /* Check if comp unit has_children.
5282 If so, read the rest of the partial symbols from this comp unit.
5283 If not, there's no more debug_info for this comp unit. */
5285 load_partial_dies (reader
, info_ptr
, 0);
5288 /* Load the partial DIEs for a secondary CU into memory.
5289 This is also used when rereading a primary CU with load_all_dies. */
5292 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5294 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5295 load_partial_comp_unit_reader
, NULL
);
5298 /* Create a list of all compilation units in OBJFILE.
5299 This is only done for -readnow and building partial symtabs. */
5302 create_all_comp_units (struct objfile
*objfile
)
5306 struct dwarf2_per_cu_data
**all_comp_units
;
5309 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5310 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
5314 all_comp_units
= xmalloc (n_allocated
5315 * sizeof (struct dwarf2_per_cu_data
*));
5317 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
5318 + dwarf2_per_objfile
->info
.size
)
5320 unsigned int length
, initial_length_size
;
5321 struct dwarf2_per_cu_data
*this_cu
;
5324 offset
.sect_off
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
5326 /* Read just enough information to find out where the next
5327 compilation unit is. */
5328 length
= read_initial_length (objfile
->obfd
, info_ptr
,
5329 &initial_length_size
);
5331 /* Save the compilation unit for later lookup. */
5332 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5333 sizeof (struct dwarf2_per_cu_data
));
5334 memset (this_cu
, 0, sizeof (*this_cu
));
5335 this_cu
->offset
= offset
;
5336 this_cu
->length
= length
+ initial_length_size
;
5337 this_cu
->objfile
= objfile
;
5338 this_cu
->info_or_types_section
= &dwarf2_per_objfile
->info
;
5340 if (n_comp_units
== n_allocated
)
5343 all_comp_units
= xrealloc (all_comp_units
,
5345 * sizeof (struct dwarf2_per_cu_data
*));
5347 all_comp_units
[n_comp_units
++] = this_cu
;
5349 info_ptr
= info_ptr
+ this_cu
->length
;
5352 dwarf2_per_objfile
->all_comp_units
5353 = obstack_alloc (&objfile
->objfile_obstack
,
5354 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5355 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5356 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5357 xfree (all_comp_units
);
5358 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5361 /* Process all loaded DIEs for compilation unit CU, starting at
5362 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5363 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5364 DW_AT_ranges). If NEED_PC is set, then this function will set
5365 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5366 and record the covered ranges in the addrmap. */
5369 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5370 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5372 struct partial_die_info
*pdi
;
5374 /* Now, march along the PDI's, descending into ones which have
5375 interesting children but skipping the children of the other ones,
5376 until we reach the end of the compilation unit. */
5382 fixup_partial_die (pdi
, cu
);
5384 /* Anonymous namespaces or modules have no name but have interesting
5385 children, so we need to look at them. Ditto for anonymous
5388 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5389 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5390 || pdi
->tag
== DW_TAG_imported_unit
)
5394 case DW_TAG_subprogram
:
5395 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5397 case DW_TAG_constant
:
5398 case DW_TAG_variable
:
5399 case DW_TAG_typedef
:
5400 case DW_TAG_union_type
:
5401 if (!pdi
->is_declaration
)
5403 add_partial_symbol (pdi
, cu
);
5406 case DW_TAG_class_type
:
5407 case DW_TAG_interface_type
:
5408 case DW_TAG_structure_type
:
5409 if (!pdi
->is_declaration
)
5411 add_partial_symbol (pdi
, cu
);
5414 case DW_TAG_enumeration_type
:
5415 if (!pdi
->is_declaration
)
5416 add_partial_enumeration (pdi
, cu
);
5418 case DW_TAG_base_type
:
5419 case DW_TAG_subrange_type
:
5420 /* File scope base type definitions are added to the partial
5422 add_partial_symbol (pdi
, cu
);
5424 case DW_TAG_namespace
:
5425 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5428 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5430 case DW_TAG_imported_unit
:
5432 struct dwarf2_per_cu_data
*per_cu
;
5434 /* For now we don't handle imported units in type units. */
5435 if (cu
->per_cu
->is_debug_types
)
5437 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5438 " supported in type units [in module %s]"),
5442 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5445 /* Go read the partial unit, if needed. */
5446 if (per_cu
->v
.psymtab
== NULL
)
5447 process_psymtab_comp_unit (per_cu
, 1);
5449 VEC_safe_push (dwarf2_per_cu_ptr
,
5450 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5458 /* If the die has a sibling, skip to the sibling. */
5460 pdi
= pdi
->die_sibling
;
5464 /* Functions used to compute the fully scoped name of a partial DIE.
5466 Normally, this is simple. For C++, the parent DIE's fully scoped
5467 name is concatenated with "::" and the partial DIE's name. For
5468 Java, the same thing occurs except that "." is used instead of "::".
5469 Enumerators are an exception; they use the scope of their parent
5470 enumeration type, i.e. the name of the enumeration type is not
5471 prepended to the enumerator.
5473 There are two complexities. One is DW_AT_specification; in this
5474 case "parent" means the parent of the target of the specification,
5475 instead of the direct parent of the DIE. The other is compilers
5476 which do not emit DW_TAG_namespace; in this case we try to guess
5477 the fully qualified name of structure types from their members'
5478 linkage names. This must be done using the DIE's children rather
5479 than the children of any DW_AT_specification target. We only need
5480 to do this for structures at the top level, i.e. if the target of
5481 any DW_AT_specification (if any; otherwise the DIE itself) does not
5484 /* Compute the scope prefix associated with PDI's parent, in
5485 compilation unit CU. The result will be allocated on CU's
5486 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5487 field. NULL is returned if no prefix is necessary. */
5489 partial_die_parent_scope (struct partial_die_info
*pdi
,
5490 struct dwarf2_cu
*cu
)
5492 char *grandparent_scope
;
5493 struct partial_die_info
*parent
, *real_pdi
;
5495 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5496 then this means the parent of the specification DIE. */
5499 while (real_pdi
->has_specification
)
5500 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
5502 parent
= real_pdi
->die_parent
;
5506 if (parent
->scope_set
)
5507 return parent
->scope
;
5509 fixup_partial_die (parent
, cu
);
5511 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5513 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5514 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5515 Work around this problem here. */
5516 if (cu
->language
== language_cplus
5517 && parent
->tag
== DW_TAG_namespace
5518 && strcmp (parent
->name
, "::") == 0
5519 && grandparent_scope
== NULL
)
5521 parent
->scope
= NULL
;
5522 parent
->scope_set
= 1;
5526 if (pdi
->tag
== DW_TAG_enumerator
)
5527 /* Enumerators should not get the name of the enumeration as a prefix. */
5528 parent
->scope
= grandparent_scope
;
5529 else if (parent
->tag
== DW_TAG_namespace
5530 || parent
->tag
== DW_TAG_module
5531 || parent
->tag
== DW_TAG_structure_type
5532 || parent
->tag
== DW_TAG_class_type
5533 || parent
->tag
== DW_TAG_interface_type
5534 || parent
->tag
== DW_TAG_union_type
5535 || parent
->tag
== DW_TAG_enumeration_type
)
5537 if (grandparent_scope
== NULL
)
5538 parent
->scope
= parent
->name
;
5540 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5542 parent
->name
, 0, cu
);
5546 /* FIXME drow/2004-04-01: What should we be doing with
5547 function-local names? For partial symbols, we should probably be
5549 complaint (&symfile_complaints
,
5550 _("unhandled containing DIE tag %d for DIE at %d"),
5551 parent
->tag
, pdi
->offset
.sect_off
);
5552 parent
->scope
= grandparent_scope
;
5555 parent
->scope_set
= 1;
5556 return parent
->scope
;
5559 /* Return the fully scoped name associated with PDI, from compilation unit
5560 CU. The result will be allocated with malloc. */
5563 partial_die_full_name (struct partial_die_info
*pdi
,
5564 struct dwarf2_cu
*cu
)
5568 /* If this is a template instantiation, we can not work out the
5569 template arguments from partial DIEs. So, unfortunately, we have
5570 to go through the full DIEs. At least any work we do building
5571 types here will be reused if full symbols are loaded later. */
5572 if (pdi
->has_template_arguments
)
5574 fixup_partial_die (pdi
, cu
);
5576 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5578 struct die_info
*die
;
5579 struct attribute attr
;
5580 struct dwarf2_cu
*ref_cu
= cu
;
5582 /* DW_FORM_ref_addr is using section offset. */
5584 attr
.form
= DW_FORM_ref_addr
;
5585 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5586 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5588 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5592 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5593 if (parent_scope
== NULL
)
5596 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5600 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5602 struct objfile
*objfile
= cu
->objfile
;
5604 char *actual_name
= NULL
;
5606 int built_actual_name
= 0;
5608 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5610 actual_name
= partial_die_full_name (pdi
, cu
);
5612 built_actual_name
= 1;
5614 if (actual_name
== NULL
)
5615 actual_name
= pdi
->name
;
5619 case DW_TAG_subprogram
:
5620 if (pdi
->is_external
|| cu
->language
== language_ada
)
5622 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5623 of the global scope. But in Ada, we want to be able to access
5624 nested procedures globally. So all Ada subprograms are stored
5625 in the global scope. */
5626 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5627 mst_text, objfile); */
5628 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5630 VAR_DOMAIN
, LOC_BLOCK
,
5631 &objfile
->global_psymbols
,
5632 0, pdi
->lowpc
+ baseaddr
,
5633 cu
->language
, objfile
);
5637 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5638 mst_file_text, objfile); */
5639 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5641 VAR_DOMAIN
, LOC_BLOCK
,
5642 &objfile
->static_psymbols
,
5643 0, pdi
->lowpc
+ baseaddr
,
5644 cu
->language
, objfile
);
5647 case DW_TAG_constant
:
5649 struct psymbol_allocation_list
*list
;
5651 if (pdi
->is_external
)
5652 list
= &objfile
->global_psymbols
;
5654 list
= &objfile
->static_psymbols
;
5655 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5656 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5657 list
, 0, 0, cu
->language
, objfile
);
5660 case DW_TAG_variable
:
5662 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5666 && !dwarf2_per_objfile
->has_section_at_zero
)
5668 /* A global or static variable may also have been stripped
5669 out by the linker if unused, in which case its address
5670 will be nullified; do not add such variables into partial
5671 symbol table then. */
5673 else if (pdi
->is_external
)
5676 Don't enter into the minimal symbol tables as there is
5677 a minimal symbol table entry from the ELF symbols already.
5678 Enter into partial symbol table if it has a location
5679 descriptor or a type.
5680 If the location descriptor is missing, new_symbol will create
5681 a LOC_UNRESOLVED symbol, the address of the variable will then
5682 be determined from the minimal symbol table whenever the variable
5684 The address for the partial symbol table entry is not
5685 used by GDB, but it comes in handy for debugging partial symbol
5688 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5689 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5691 VAR_DOMAIN
, LOC_STATIC
,
5692 &objfile
->global_psymbols
,
5694 cu
->language
, objfile
);
5698 /* Static Variable. Skip symbols without location descriptors. */
5699 if (pdi
->d
.locdesc
== NULL
)
5701 if (built_actual_name
)
5702 xfree (actual_name
);
5705 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5706 mst_file_data, objfile); */
5707 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5709 VAR_DOMAIN
, LOC_STATIC
,
5710 &objfile
->static_psymbols
,
5712 cu
->language
, objfile
);
5715 case DW_TAG_typedef
:
5716 case DW_TAG_base_type
:
5717 case DW_TAG_subrange_type
:
5718 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5720 VAR_DOMAIN
, LOC_TYPEDEF
,
5721 &objfile
->static_psymbols
,
5722 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5724 case DW_TAG_namespace
:
5725 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5727 VAR_DOMAIN
, LOC_TYPEDEF
,
5728 &objfile
->global_psymbols
,
5729 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5731 case DW_TAG_class_type
:
5732 case DW_TAG_interface_type
:
5733 case DW_TAG_structure_type
:
5734 case DW_TAG_union_type
:
5735 case DW_TAG_enumeration_type
:
5736 /* Skip external references. The DWARF standard says in the section
5737 about "Structure, Union, and Class Type Entries": "An incomplete
5738 structure, union or class type is represented by a structure,
5739 union or class entry that does not have a byte size attribute
5740 and that has a DW_AT_declaration attribute." */
5741 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5743 if (built_actual_name
)
5744 xfree (actual_name
);
5748 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5749 static vs. global. */
5750 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5752 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5753 (cu
->language
== language_cplus
5754 || cu
->language
== language_java
)
5755 ? &objfile
->global_psymbols
5756 : &objfile
->static_psymbols
,
5757 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5760 case DW_TAG_enumerator
:
5761 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5763 VAR_DOMAIN
, LOC_CONST
,
5764 (cu
->language
== language_cplus
5765 || cu
->language
== language_java
)
5766 ? &objfile
->global_psymbols
5767 : &objfile
->static_psymbols
,
5768 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5774 if (built_actual_name
)
5775 xfree (actual_name
);
5778 /* Read a partial die corresponding to a namespace; also, add a symbol
5779 corresponding to that namespace to the symbol table. NAMESPACE is
5780 the name of the enclosing namespace. */
5783 add_partial_namespace (struct partial_die_info
*pdi
,
5784 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5785 int need_pc
, struct dwarf2_cu
*cu
)
5787 /* Add a symbol for the namespace. */
5789 add_partial_symbol (pdi
, cu
);
5791 /* Now scan partial symbols in that namespace. */
5793 if (pdi
->has_children
)
5794 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5797 /* Read a partial die corresponding to a Fortran module. */
5800 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5801 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5803 /* Now scan partial symbols in that module. */
5805 if (pdi
->has_children
)
5806 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5809 /* Read a partial die corresponding to a subprogram and create a partial
5810 symbol for that subprogram. When the CU language allows it, this
5811 routine also defines a partial symbol for each nested subprogram
5812 that this subprogram contains.
5814 DIE my also be a lexical block, in which case we simply search
5815 recursively for suprograms defined inside that lexical block.
5816 Again, this is only performed when the CU language allows this
5817 type of definitions. */
5820 add_partial_subprogram (struct partial_die_info
*pdi
,
5821 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5822 int need_pc
, struct dwarf2_cu
*cu
)
5824 if (pdi
->tag
== DW_TAG_subprogram
)
5826 if (pdi
->has_pc_info
)
5828 if (pdi
->lowpc
< *lowpc
)
5829 *lowpc
= pdi
->lowpc
;
5830 if (pdi
->highpc
> *highpc
)
5831 *highpc
= pdi
->highpc
;
5835 struct objfile
*objfile
= cu
->objfile
;
5837 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5838 SECT_OFF_TEXT (objfile
));
5839 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5840 pdi
->lowpc
+ baseaddr
,
5841 pdi
->highpc
- 1 + baseaddr
,
5842 cu
->per_cu
->v
.psymtab
);
5846 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5848 if (!pdi
->is_declaration
)
5849 /* Ignore subprogram DIEs that do not have a name, they are
5850 illegal. Do not emit a complaint at this point, we will
5851 do so when we convert this psymtab into a symtab. */
5853 add_partial_symbol (pdi
, cu
);
5857 if (! pdi
->has_children
)
5860 if (cu
->language
== language_ada
)
5862 pdi
= pdi
->die_child
;
5865 fixup_partial_die (pdi
, cu
);
5866 if (pdi
->tag
== DW_TAG_subprogram
5867 || pdi
->tag
== DW_TAG_lexical_block
)
5868 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5869 pdi
= pdi
->die_sibling
;
5874 /* Read a partial die corresponding to an enumeration type. */
5877 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
5878 struct dwarf2_cu
*cu
)
5880 struct partial_die_info
*pdi
;
5882 if (enum_pdi
->name
!= NULL
)
5883 add_partial_symbol (enum_pdi
, cu
);
5885 pdi
= enum_pdi
->die_child
;
5888 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
5889 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5891 add_partial_symbol (pdi
, cu
);
5892 pdi
= pdi
->die_sibling
;
5896 /* Return the initial uleb128 in the die at INFO_PTR. */
5899 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
5901 unsigned int bytes_read
;
5903 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5906 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
5907 Return the corresponding abbrev, or NULL if the number is zero (indicating
5908 an empty DIE). In either case *BYTES_READ will be set to the length of
5909 the initial number. */
5911 static struct abbrev_info
*
5912 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
5913 struct dwarf2_cu
*cu
)
5915 bfd
*abfd
= cu
->objfile
->obfd
;
5916 unsigned int abbrev_number
;
5917 struct abbrev_info
*abbrev
;
5919 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
5921 if (abbrev_number
== 0)
5924 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
5927 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
5928 abbrev_number
, bfd_get_filename (abfd
));
5934 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5935 Returns a pointer to the end of a series of DIEs, terminated by an empty
5936 DIE. Any children of the skipped DIEs will also be skipped. */
5939 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
5941 struct dwarf2_cu
*cu
= reader
->cu
;
5942 struct abbrev_info
*abbrev
;
5943 unsigned int bytes_read
;
5947 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5949 return info_ptr
+ bytes_read
;
5951 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
5955 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
5956 INFO_PTR should point just after the initial uleb128 of a DIE, and the
5957 abbrev corresponding to that skipped uleb128 should be passed in
5958 ABBREV. Returns a pointer to this DIE's sibling, skipping any
5962 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
5963 struct abbrev_info
*abbrev
)
5965 unsigned int bytes_read
;
5966 struct attribute attr
;
5967 bfd
*abfd
= reader
->abfd
;
5968 struct dwarf2_cu
*cu
= reader
->cu
;
5969 gdb_byte
*buffer
= reader
->buffer
;
5970 const gdb_byte
*buffer_end
= reader
->buffer_end
;
5971 gdb_byte
*start_info_ptr
= info_ptr
;
5972 unsigned int form
, i
;
5974 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
5976 /* The only abbrev we care about is DW_AT_sibling. */
5977 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
5979 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
5980 if (attr
.form
== DW_FORM_ref_addr
)
5981 complaint (&symfile_complaints
,
5982 _("ignoring absolute DW_AT_sibling"));
5984 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
5987 /* If it isn't DW_AT_sibling, skip this attribute. */
5988 form
= abbrev
->attrs
[i
].form
;
5992 case DW_FORM_ref_addr
:
5993 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
5994 and later it is offset sized. */
5995 if (cu
->header
.version
== 2)
5996 info_ptr
+= cu
->header
.addr_size
;
5998 info_ptr
+= cu
->header
.offset_size
;
6001 info_ptr
+= cu
->header
.addr_size
;
6008 case DW_FORM_flag_present
:
6020 case DW_FORM_ref_sig8
:
6023 case DW_FORM_string
:
6024 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6025 info_ptr
+= bytes_read
;
6027 case DW_FORM_sec_offset
:
6029 info_ptr
+= cu
->header
.offset_size
;
6031 case DW_FORM_exprloc
:
6033 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6034 info_ptr
+= bytes_read
;
6036 case DW_FORM_block1
:
6037 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6039 case DW_FORM_block2
:
6040 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6042 case DW_FORM_block4
:
6043 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6047 case DW_FORM_ref_udata
:
6048 case DW_FORM_GNU_addr_index
:
6049 case DW_FORM_GNU_str_index
:
6050 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6052 case DW_FORM_indirect
:
6053 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6054 info_ptr
+= bytes_read
;
6055 /* We need to continue parsing from here, so just go back to
6057 goto skip_attribute
;
6060 error (_("Dwarf Error: Cannot handle %s "
6061 "in DWARF reader [in module %s]"),
6062 dwarf_form_name (form
),
6063 bfd_get_filename (abfd
));
6067 if (abbrev
->has_children
)
6068 return skip_children (reader
, info_ptr
);
6073 /* Locate ORIG_PDI's sibling.
6074 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6077 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6078 struct partial_die_info
*orig_pdi
,
6081 /* Do we know the sibling already? */
6083 if (orig_pdi
->sibling
)
6084 return orig_pdi
->sibling
;
6086 /* Are there any children to deal with? */
6088 if (!orig_pdi
->has_children
)
6091 /* Skip the children the long way. */
6093 return skip_children (reader
, info_ptr
);
6096 /* Expand this partial symbol table into a full symbol table. */
6099 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6105 warning (_("bug: psymtab for %s is already read in."),
6112 printf_filtered (_("Reading in symbols for %s..."),
6114 gdb_flush (gdb_stdout
);
6117 /* Restore our global data. */
6118 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6119 dwarf2_objfile_data_key
);
6121 /* If this psymtab is constructed from a debug-only objfile, the
6122 has_section_at_zero flag will not necessarily be correct. We
6123 can get the correct value for this flag by looking at the data
6124 associated with the (presumably stripped) associated objfile. */
6125 if (pst
->objfile
->separate_debug_objfile_backlink
)
6127 struct dwarf2_per_objfile
*dpo_backlink
6128 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6129 dwarf2_objfile_data_key
);
6131 dwarf2_per_objfile
->has_section_at_zero
6132 = dpo_backlink
->has_section_at_zero
;
6135 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6137 psymtab_to_symtab_1 (pst
);
6139 /* Finish up the debug error message. */
6141 printf_filtered (_("done.\n"));
6145 process_cu_includes ();
6148 /* Reading in full CUs. */
6150 /* Add PER_CU to the queue. */
6153 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6154 enum language pretend_language
)
6156 struct dwarf2_queue_item
*item
;
6159 item
= xmalloc (sizeof (*item
));
6160 item
->per_cu
= per_cu
;
6161 item
->pretend_language
= pretend_language
;
6164 if (dwarf2_queue
== NULL
)
6165 dwarf2_queue
= item
;
6167 dwarf2_queue_tail
->next
= item
;
6169 dwarf2_queue_tail
= item
;
6172 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6173 unit and add it to our queue.
6174 The result is non-zero if PER_CU was queued, otherwise the result is zero
6175 meaning either PER_CU is already queued or it is already loaded. */
6178 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6179 struct dwarf2_per_cu_data
*per_cu
,
6180 enum language pretend_language
)
6182 /* We may arrive here during partial symbol reading, if we need full
6183 DIEs to process an unusual case (e.g. template arguments). Do
6184 not queue PER_CU, just tell our caller to load its DIEs. */
6185 if (dwarf2_per_objfile
->reading_partial_symbols
)
6187 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6192 /* Mark the dependence relation so that we don't flush PER_CU
6194 dwarf2_add_dependence (this_cu
, per_cu
);
6196 /* If it's already on the queue, we have nothing to do. */
6200 /* If the compilation unit is already loaded, just mark it as
6202 if (per_cu
->cu
!= NULL
)
6204 per_cu
->cu
->last_used
= 0;
6208 /* Add it to the queue. */
6209 queue_comp_unit (per_cu
, pretend_language
);
6214 /* Process the queue. */
6217 process_queue (void)
6219 struct dwarf2_queue_item
*item
, *next_item
;
6221 if (dwarf2_read_debug
)
6223 fprintf_unfiltered (gdb_stdlog
,
6224 "Expanding one or more symtabs of objfile %s ...\n",
6225 dwarf2_per_objfile
->objfile
->name
);
6228 /* The queue starts out with one item, but following a DIE reference
6229 may load a new CU, adding it to the end of the queue. */
6230 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6232 if (dwarf2_per_objfile
->using_index
6233 ? !item
->per_cu
->v
.quick
->symtab
6234 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6236 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6238 if (dwarf2_read_debug
)
6240 fprintf_unfiltered (gdb_stdlog
,
6241 "Expanding symtab of %s at offset 0x%x\n",
6242 per_cu
->is_debug_types
? "TU" : "CU",
6243 per_cu
->offset
.sect_off
);
6246 if (per_cu
->is_debug_types
)
6247 process_full_type_unit (per_cu
, item
->pretend_language
);
6249 process_full_comp_unit (per_cu
, item
->pretend_language
);
6251 if (dwarf2_read_debug
)
6253 fprintf_unfiltered (gdb_stdlog
,
6254 "Done expanding %s at offset 0x%x\n",
6255 per_cu
->is_debug_types
? "TU" : "CU",
6256 per_cu
->offset
.sect_off
);
6260 item
->per_cu
->queued
= 0;
6261 next_item
= item
->next
;
6265 dwarf2_queue_tail
= NULL
;
6267 if (dwarf2_read_debug
)
6269 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6270 dwarf2_per_objfile
->objfile
->name
);
6274 /* Free all allocated queue entries. This function only releases anything if
6275 an error was thrown; if the queue was processed then it would have been
6276 freed as we went along. */
6279 dwarf2_release_queue (void *dummy
)
6281 struct dwarf2_queue_item
*item
, *last
;
6283 item
= dwarf2_queue
;
6286 /* Anything still marked queued is likely to be in an
6287 inconsistent state, so discard it. */
6288 if (item
->per_cu
->queued
)
6290 if (item
->per_cu
->cu
!= NULL
)
6291 free_one_cached_comp_unit (item
->per_cu
);
6292 item
->per_cu
->queued
= 0;
6300 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6303 /* Read in full symbols for PST, and anything it depends on. */
6306 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6308 struct dwarf2_per_cu_data
*per_cu
;
6314 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6315 if (!pst
->dependencies
[i
]->readin
6316 && pst
->dependencies
[i
]->user
== NULL
)
6318 /* Inform about additional files that need to be read in. */
6321 /* FIXME: i18n: Need to make this a single string. */
6322 fputs_filtered (" ", gdb_stdout
);
6324 fputs_filtered ("and ", gdb_stdout
);
6326 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6327 wrap_here (""); /* Flush output. */
6328 gdb_flush (gdb_stdout
);
6330 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6333 per_cu
= pst
->read_symtab_private
;
6337 /* It's an include file, no symbols to read for it.
6338 Everything is in the parent symtab. */
6343 dw2_do_instantiate_symtab (per_cu
);
6346 /* Trivial hash function for die_info: the hash value of a DIE
6347 is its offset in .debug_info for this objfile. */
6350 die_hash (const void *item
)
6352 const struct die_info
*die
= item
;
6354 return die
->offset
.sect_off
;
6357 /* Trivial comparison function for die_info structures: two DIEs
6358 are equal if they have the same offset. */
6361 die_eq (const void *item_lhs
, const void *item_rhs
)
6363 const struct die_info
*die_lhs
= item_lhs
;
6364 const struct die_info
*die_rhs
= item_rhs
;
6366 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6369 /* die_reader_func for load_full_comp_unit.
6370 This is identical to read_signatured_type_reader,
6371 but is kept separate for now. */
6374 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6376 struct die_info
*comp_unit_die
,
6380 struct dwarf2_cu
*cu
= reader
->cu
;
6381 enum language
*language_ptr
= data
;
6383 gdb_assert (cu
->die_hash
== NULL
);
6385 htab_create_alloc_ex (cu
->header
.length
/ 12,
6389 &cu
->comp_unit_obstack
,
6390 hashtab_obstack_allocate
,
6391 dummy_obstack_deallocate
);
6394 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6395 &info_ptr
, comp_unit_die
);
6396 cu
->dies
= comp_unit_die
;
6397 /* comp_unit_die is not stored in die_hash, no need. */
6399 /* We try not to read any attributes in this function, because not
6400 all CUs needed for references have been loaded yet, and symbol
6401 table processing isn't initialized. But we have to set the CU language,
6402 or we won't be able to build types correctly.
6403 Similarly, if we do not read the producer, we can not apply
6404 producer-specific interpretation. */
6405 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6408 /* Load the DIEs associated with PER_CU into memory. */
6411 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6412 enum language pretend_language
)
6414 gdb_assert (! this_cu
->is_debug_types
);
6416 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6417 load_full_comp_unit_reader
, &pretend_language
);
6420 /* Add a DIE to the delayed physname list. */
6423 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6424 const char *name
, struct die_info
*die
,
6425 struct dwarf2_cu
*cu
)
6427 struct delayed_method_info mi
;
6429 mi
.fnfield_index
= fnfield_index
;
6433 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6436 /* A cleanup for freeing the delayed method list. */
6439 free_delayed_list (void *ptr
)
6441 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6442 if (cu
->method_list
!= NULL
)
6444 VEC_free (delayed_method_info
, cu
->method_list
);
6445 cu
->method_list
= NULL
;
6449 /* Compute the physnames of any methods on the CU's method list.
6451 The computation of method physnames is delayed in order to avoid the
6452 (bad) condition that one of the method's formal parameters is of an as yet
6456 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6459 struct delayed_method_info
*mi
;
6460 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6462 const char *physname
;
6463 struct fn_fieldlist
*fn_flp
6464 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6465 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6466 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6470 /* Go objects should be embedded in a DW_TAG_module DIE,
6471 and it's not clear if/how imported objects will appear.
6472 To keep Go support simple until that's worked out,
6473 go back through what we've read and create something usable.
6474 We could do this while processing each DIE, and feels kinda cleaner,
6475 but that way is more invasive.
6476 This is to, for example, allow the user to type "p var" or "b main"
6477 without having to specify the package name, and allow lookups
6478 of module.object to work in contexts that use the expression
6482 fixup_go_packaging (struct dwarf2_cu
*cu
)
6484 char *package_name
= NULL
;
6485 struct pending
*list
;
6488 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6490 for (i
= 0; i
< list
->nsyms
; ++i
)
6492 struct symbol
*sym
= list
->symbol
[i
];
6494 if (SYMBOL_LANGUAGE (sym
) == language_go
6495 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6497 char *this_package_name
= go_symbol_package_name (sym
);
6499 if (this_package_name
== NULL
)
6501 if (package_name
== NULL
)
6502 package_name
= this_package_name
;
6505 if (strcmp (package_name
, this_package_name
) != 0)
6506 complaint (&symfile_complaints
,
6507 _("Symtab %s has objects from two different Go packages: %s and %s"),
6508 (sym
->symtab
&& sym
->symtab
->filename
6509 ? sym
->symtab
->filename
6510 : cu
->objfile
->name
),
6511 this_package_name
, package_name
);
6512 xfree (this_package_name
);
6518 if (package_name
!= NULL
)
6520 struct objfile
*objfile
= cu
->objfile
;
6521 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6522 package_name
, objfile
);
6525 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6527 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6528 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6529 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6530 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6531 e.g., "main" finds the "main" module and not C's main(). */
6532 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6533 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6534 SYMBOL_TYPE (sym
) = type
;
6536 add_symbol_to_list (sym
, &global_symbols
);
6538 xfree (package_name
);
6542 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6544 /* Return the symtab for PER_CU. This works properly regardless of
6545 whether we're using the index or psymtabs. */
6547 static struct symtab
*
6548 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6550 return (dwarf2_per_objfile
->using_index
6551 ? per_cu
->v
.quick
->symtab
6552 : per_cu
->v
.psymtab
->symtab
);
6555 /* A helper function for computing the list of all symbol tables
6556 included by PER_CU. */
6559 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6560 htab_t all_children
,
6561 struct dwarf2_per_cu_data
*per_cu
)
6565 struct dwarf2_per_cu_data
*iter
;
6567 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6570 /* This inclusion and its children have been processed. */
6575 /* Only add a CU if it has a symbol table. */
6576 if (get_symtab (per_cu
) != NULL
)
6577 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6580 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6582 recursively_compute_inclusions (result
, all_children
, iter
);
6585 /* Compute the symtab 'includes' fields for the symtab related to
6589 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6591 gdb_assert (! per_cu
->is_debug_types
);
6593 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6596 struct dwarf2_per_cu_data
*iter
;
6597 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6598 htab_t all_children
;
6599 struct symtab
*symtab
= get_symtab (per_cu
);
6601 /* If we don't have a symtab, we can just skip this case. */
6605 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6606 NULL
, xcalloc
, xfree
);
6609 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6612 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6614 /* Now we have a transitive closure of all the included CUs, so
6615 we can convert it to a list of symtabs. */
6616 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6618 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6619 (len
+ 1) * sizeof (struct symtab
*));
6621 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6623 symtab
->includes
[ix
] = get_symtab (iter
);
6624 symtab
->includes
[len
] = NULL
;
6626 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6627 htab_delete (all_children
);
6631 /* Compute the 'includes' field for the symtabs of all the CUs we just
6635 process_cu_includes (void)
6638 struct dwarf2_per_cu_data
*iter
;
6641 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6645 if (! iter
->is_debug_types
)
6646 compute_symtab_includes (iter
);
6649 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6652 /* Generate full symbol information for PER_CU, whose DIEs have
6653 already been loaded into memory. */
6656 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6657 enum language pretend_language
)
6659 struct dwarf2_cu
*cu
= per_cu
->cu
;
6660 struct objfile
*objfile
= per_cu
->objfile
;
6661 CORE_ADDR lowpc
, highpc
;
6662 struct symtab
*symtab
;
6663 struct cleanup
*back_to
, *delayed_list_cleanup
;
6665 struct block
*static_block
;
6667 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6670 back_to
= make_cleanup (really_free_pendings
, NULL
);
6671 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6673 cu
->list_in_scope
= &file_symbols
;
6675 cu
->language
= pretend_language
;
6676 cu
->language_defn
= language_def (cu
->language
);
6678 /* Do line number decoding in read_file_scope () */
6679 process_die (cu
->dies
, cu
);
6681 /* For now fudge the Go package. */
6682 if (cu
->language
== language_go
)
6683 fixup_go_packaging (cu
);
6685 /* Now that we have processed all the DIEs in the CU, all the types
6686 should be complete, and it should now be safe to compute all of the
6688 compute_delayed_physnames (cu
);
6689 do_cleanups (delayed_list_cleanup
);
6691 /* Some compilers don't define a DW_AT_high_pc attribute for the
6692 compilation unit. If the DW_AT_high_pc is missing, synthesize
6693 it, by scanning the DIE's below the compilation unit. */
6694 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6696 static_block
= end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0);
6698 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6699 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6700 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6701 addrmap to help ensure it has an accurate map of pc values belonging to
6703 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6705 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6706 SECT_OFF_TEXT (objfile
), 0);
6710 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6712 /* Set symtab language to language from DW_AT_language. If the
6713 compilation is from a C file generated by language preprocessors, do
6714 not set the language if it was already deduced by start_subfile. */
6715 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6716 symtab
->language
= cu
->language
;
6718 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6719 produce DW_AT_location with location lists but it can be possibly
6720 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6721 there were bugs in prologue debug info, fixed later in GCC-4.5
6722 by "unwind info for epilogues" patch (which is not directly related).
6724 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6725 needed, it would be wrong due to missing DW_AT_producer there.
6727 Still one can confuse GDB by using non-standard GCC compilation
6728 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6730 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6731 symtab
->locations_valid
= 1;
6733 if (gcc_4_minor
>= 5)
6734 symtab
->epilogue_unwind_valid
= 1;
6736 symtab
->call_site_htab
= cu
->call_site_htab
;
6739 if (dwarf2_per_objfile
->using_index
)
6740 per_cu
->v
.quick
->symtab
= symtab
;
6743 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6744 pst
->symtab
= symtab
;
6748 /* Push it for inclusion processing later. */
6749 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6751 do_cleanups (back_to
);
6754 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6755 already been loaded into memory. */
6758 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6759 enum language pretend_language
)
6761 struct dwarf2_cu
*cu
= per_cu
->cu
;
6762 struct objfile
*objfile
= per_cu
->objfile
;
6763 struct symtab
*symtab
;
6764 struct cleanup
*back_to
, *delayed_list_cleanup
;
6767 back_to
= make_cleanup (really_free_pendings
, NULL
);
6768 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6770 cu
->list_in_scope
= &file_symbols
;
6772 cu
->language
= pretend_language
;
6773 cu
->language_defn
= language_def (cu
->language
);
6775 /* The symbol tables are set up in read_type_unit_scope. */
6776 process_die (cu
->dies
, cu
);
6778 /* For now fudge the Go package. */
6779 if (cu
->language
== language_go
)
6780 fixup_go_packaging (cu
);
6782 /* Now that we have processed all the DIEs in the CU, all the types
6783 should be complete, and it should now be safe to compute all of the
6785 compute_delayed_physnames (cu
);
6786 do_cleanups (delayed_list_cleanup
);
6788 /* TUs share symbol tables.
6789 If this is the first TU to use this symtab, complete the construction
6790 of it with end_expandable_symtab. Otherwise, complete the addition of
6791 this TU's symbols to the existing symtab. */
6792 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
6794 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
6795 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
6799 /* Set symtab language to language from DW_AT_language. If the
6800 compilation is from a C file generated by language preprocessors,
6801 do not set the language if it was already deduced by
6803 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6804 symtab
->language
= cu
->language
;
6809 augment_type_symtab (objfile
,
6810 per_cu
->s
.type_unit_group
->primary_symtab
);
6811 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
6814 if (dwarf2_per_objfile
->using_index
)
6815 per_cu
->v
.quick
->symtab
= symtab
;
6818 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6819 pst
->symtab
= symtab
;
6823 do_cleanups (back_to
);
6826 /* Process an imported unit DIE. */
6829 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6831 struct attribute
*attr
;
6833 /* For now we don't handle imported units in type units. */
6834 if (cu
->per_cu
->is_debug_types
)
6836 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6837 " supported in type units [in module %s]"),
6841 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6844 struct dwarf2_per_cu_data
*per_cu
;
6845 struct symtab
*imported_symtab
;
6848 offset
= dwarf2_get_ref_die_offset (attr
);
6849 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6851 /* Queue the unit, if needed. */
6852 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
6853 load_full_comp_unit (per_cu
, cu
->language
);
6855 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
6860 /* Process a die and its children. */
6863 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6867 case DW_TAG_padding
:
6869 case DW_TAG_compile_unit
:
6870 case DW_TAG_partial_unit
:
6871 read_file_scope (die
, cu
);
6873 case DW_TAG_type_unit
:
6874 read_type_unit_scope (die
, cu
);
6876 case DW_TAG_subprogram
:
6877 case DW_TAG_inlined_subroutine
:
6878 read_func_scope (die
, cu
);
6880 case DW_TAG_lexical_block
:
6881 case DW_TAG_try_block
:
6882 case DW_TAG_catch_block
:
6883 read_lexical_block_scope (die
, cu
);
6885 case DW_TAG_GNU_call_site
:
6886 read_call_site_scope (die
, cu
);
6888 case DW_TAG_class_type
:
6889 case DW_TAG_interface_type
:
6890 case DW_TAG_structure_type
:
6891 case DW_TAG_union_type
:
6892 process_structure_scope (die
, cu
);
6894 case DW_TAG_enumeration_type
:
6895 process_enumeration_scope (die
, cu
);
6898 /* These dies have a type, but processing them does not create
6899 a symbol or recurse to process the children. Therefore we can
6900 read them on-demand through read_type_die. */
6901 case DW_TAG_subroutine_type
:
6902 case DW_TAG_set_type
:
6903 case DW_TAG_array_type
:
6904 case DW_TAG_pointer_type
:
6905 case DW_TAG_ptr_to_member_type
:
6906 case DW_TAG_reference_type
:
6907 case DW_TAG_string_type
:
6910 case DW_TAG_base_type
:
6911 case DW_TAG_subrange_type
:
6912 case DW_TAG_typedef
:
6913 /* Add a typedef symbol for the type definition, if it has a
6915 new_symbol (die
, read_type_die (die
, cu
), cu
);
6917 case DW_TAG_common_block
:
6918 read_common_block (die
, cu
);
6920 case DW_TAG_common_inclusion
:
6922 case DW_TAG_namespace
:
6923 processing_has_namespace_info
= 1;
6924 read_namespace (die
, cu
);
6927 processing_has_namespace_info
= 1;
6928 read_module (die
, cu
);
6930 case DW_TAG_imported_declaration
:
6931 case DW_TAG_imported_module
:
6932 processing_has_namespace_info
= 1;
6933 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
6934 || cu
->language
!= language_fortran
))
6935 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
6936 dwarf_tag_name (die
->tag
));
6937 read_import_statement (die
, cu
);
6940 case DW_TAG_imported_unit
:
6941 process_imported_unit_die (die
, cu
);
6945 new_symbol (die
, NULL
, cu
);
6950 /* A helper function for dwarf2_compute_name which determines whether DIE
6951 needs to have the name of the scope prepended to the name listed in the
6955 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6957 struct attribute
*attr
;
6961 case DW_TAG_namespace
:
6962 case DW_TAG_typedef
:
6963 case DW_TAG_class_type
:
6964 case DW_TAG_interface_type
:
6965 case DW_TAG_structure_type
:
6966 case DW_TAG_union_type
:
6967 case DW_TAG_enumeration_type
:
6968 case DW_TAG_enumerator
:
6969 case DW_TAG_subprogram
:
6973 case DW_TAG_variable
:
6974 case DW_TAG_constant
:
6975 /* We only need to prefix "globally" visible variables. These include
6976 any variable marked with DW_AT_external or any variable that
6977 lives in a namespace. [Variables in anonymous namespaces
6978 require prefixing, but they are not DW_AT_external.] */
6980 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
6982 struct dwarf2_cu
*spec_cu
= cu
;
6984 return die_needs_namespace (die_specification (die
, &spec_cu
),
6988 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
6989 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
6990 && die
->parent
->tag
!= DW_TAG_module
)
6992 /* A variable in a lexical block of some kind does not need a
6993 namespace, even though in C++ such variables may be external
6994 and have a mangled name. */
6995 if (die
->parent
->tag
== DW_TAG_lexical_block
6996 || die
->parent
->tag
== DW_TAG_try_block
6997 || die
->parent
->tag
== DW_TAG_catch_block
6998 || die
->parent
->tag
== DW_TAG_subprogram
)
7007 /* Retrieve the last character from a mem_file. */
7010 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7012 char *last_char_p
= (char *) object
;
7015 *last_char_p
= buffer
[length
- 1];
7018 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7019 compute the physname for the object, which include a method's:
7020 - formal parameters (C++/Java),
7021 - receiver type (Go),
7022 - return type (Java).
7024 The term "physname" is a bit confusing.
7025 For C++, for example, it is the demangled name.
7026 For Go, for example, it's the mangled name.
7028 For Ada, return the DIE's linkage name rather than the fully qualified
7029 name. PHYSNAME is ignored..
7031 The result is allocated on the objfile_obstack and canonicalized. */
7034 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7037 struct objfile
*objfile
= cu
->objfile
;
7040 name
= dwarf2_name (die
, cu
);
7042 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7043 compute it by typename_concat inside GDB. */
7044 if (cu
->language
== language_ada
7045 || (cu
->language
== language_fortran
&& physname
))
7047 /* For Ada unit, we prefer the linkage name over the name, as
7048 the former contains the exported name, which the user expects
7049 to be able to reference. Ideally, we want the user to be able
7050 to reference this entity using either natural or linkage name,
7051 but we haven't started looking at this enhancement yet. */
7052 struct attribute
*attr
;
7054 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7056 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7057 if (attr
&& DW_STRING (attr
))
7058 return DW_STRING (attr
);
7061 /* These are the only languages we know how to qualify names in. */
7063 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7064 || cu
->language
== language_fortran
))
7066 if (die_needs_namespace (die
, cu
))
7070 struct ui_file
*buf
;
7072 prefix
= determine_prefix (die
, cu
);
7073 buf
= mem_fileopen ();
7074 if (*prefix
!= '\0')
7076 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7079 fputs_unfiltered (prefixed_name
, buf
);
7080 xfree (prefixed_name
);
7083 fputs_unfiltered (name
, buf
);
7085 /* Template parameters may be specified in the DIE's DW_AT_name, or
7086 as children with DW_TAG_template_type_param or
7087 DW_TAG_value_type_param. If the latter, add them to the name
7088 here. If the name already has template parameters, then
7089 skip this step; some versions of GCC emit both, and
7090 it is more efficient to use the pre-computed name.
7092 Something to keep in mind about this process: it is very
7093 unlikely, or in some cases downright impossible, to produce
7094 something that will match the mangled name of a function.
7095 If the definition of the function has the same debug info,
7096 we should be able to match up with it anyway. But fallbacks
7097 using the minimal symbol, for instance to find a method
7098 implemented in a stripped copy of libstdc++, will not work.
7099 If we do not have debug info for the definition, we will have to
7100 match them up some other way.
7102 When we do name matching there is a related problem with function
7103 templates; two instantiated function templates are allowed to
7104 differ only by their return types, which we do not add here. */
7106 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7108 struct attribute
*attr
;
7109 struct die_info
*child
;
7112 die
->building_fullname
= 1;
7114 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7119 struct dwarf2_locexpr_baton
*baton
;
7122 if (child
->tag
!= DW_TAG_template_type_param
7123 && child
->tag
!= DW_TAG_template_value_param
)
7128 fputs_unfiltered ("<", buf
);
7132 fputs_unfiltered (", ", buf
);
7134 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7137 complaint (&symfile_complaints
,
7138 _("template parameter missing DW_AT_type"));
7139 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7142 type
= die_type (child
, cu
);
7144 if (child
->tag
== DW_TAG_template_type_param
)
7146 c_print_type (type
, "", buf
, -1, 0);
7150 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7153 complaint (&symfile_complaints
,
7154 _("template parameter missing "
7155 "DW_AT_const_value"));
7156 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7160 dwarf2_const_value_attr (attr
, type
, name
,
7161 &cu
->comp_unit_obstack
, cu
,
7162 &value
, &bytes
, &baton
);
7164 if (TYPE_NOSIGN (type
))
7165 /* GDB prints characters as NUMBER 'CHAR'. If that's
7166 changed, this can use value_print instead. */
7167 c_printchar (value
, type
, buf
);
7170 struct value_print_options opts
;
7173 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7177 else if (bytes
!= NULL
)
7179 v
= allocate_value (type
);
7180 memcpy (value_contents_writeable (v
), bytes
,
7181 TYPE_LENGTH (type
));
7184 v
= value_from_longest (type
, value
);
7186 /* Specify decimal so that we do not depend on
7188 get_formatted_print_options (&opts
, 'd');
7190 value_print (v
, buf
, &opts
);
7196 die
->building_fullname
= 0;
7200 /* Close the argument list, with a space if necessary
7201 (nested templates). */
7202 char last_char
= '\0';
7203 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7204 if (last_char
== '>')
7205 fputs_unfiltered (" >", buf
);
7207 fputs_unfiltered (">", buf
);
7211 /* For Java and C++ methods, append formal parameter type
7212 information, if PHYSNAME. */
7214 if (physname
&& die
->tag
== DW_TAG_subprogram
7215 && (cu
->language
== language_cplus
7216 || cu
->language
== language_java
))
7218 struct type
*type
= read_type_die (die
, cu
);
7220 c_type_print_args (type
, buf
, 1, cu
->language
);
7222 if (cu
->language
== language_java
)
7224 /* For java, we must append the return type to method
7226 if (die
->tag
== DW_TAG_subprogram
)
7227 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7230 else if (cu
->language
== language_cplus
)
7232 /* Assume that an artificial first parameter is
7233 "this", but do not crash if it is not. RealView
7234 marks unnamed (and thus unused) parameters as
7235 artificial; there is no way to differentiate
7237 if (TYPE_NFIELDS (type
) > 0
7238 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7239 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7240 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7242 fputs_unfiltered (" const", buf
);
7246 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7248 ui_file_delete (buf
);
7250 if (cu
->language
== language_cplus
)
7253 = dwarf2_canonicalize_name (name
, cu
,
7254 &objfile
->objfile_obstack
);
7265 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7266 If scope qualifiers are appropriate they will be added. The result
7267 will be allocated on the objfile_obstack, or NULL if the DIE does
7268 not have a name. NAME may either be from a previous call to
7269 dwarf2_name or NULL.
7271 The output string will be canonicalized (if C++/Java). */
7274 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7276 return dwarf2_compute_name (name
, die
, cu
, 0);
7279 /* Construct a physname for the given DIE in CU. NAME may either be
7280 from a previous call to dwarf2_name or NULL. The result will be
7281 allocated on the objfile_objstack or NULL if the DIE does not have a
7284 The output string will be canonicalized (if C++/Java). */
7287 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7289 struct objfile
*objfile
= cu
->objfile
;
7290 struct attribute
*attr
;
7291 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7292 struct cleanup
*back_to
;
7295 /* In this case dwarf2_compute_name is just a shortcut not building anything
7297 if (!die_needs_namespace (die
, cu
))
7298 return dwarf2_compute_name (name
, die
, cu
, 1);
7300 back_to
= make_cleanup (null_cleanup
, NULL
);
7302 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7304 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7306 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7308 if (attr
&& DW_STRING (attr
))
7312 mangled
= DW_STRING (attr
);
7314 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7315 type. It is easier for GDB users to search for such functions as
7316 `name(params)' than `long name(params)'. In such case the minimal
7317 symbol names do not match the full symbol names but for template
7318 functions there is never a need to look up their definition from their
7319 declaration so the only disadvantage remains the minimal symbol
7320 variant `long name(params)' does not have the proper inferior type.
7323 if (cu
->language
== language_go
)
7325 /* This is a lie, but we already lie to the caller new_symbol_full.
7326 new_symbol_full assumes we return the mangled name.
7327 This just undoes that lie until things are cleaned up. */
7332 demangled
= cplus_demangle (mangled
,
7333 (DMGL_PARAMS
| DMGL_ANSI
7334 | (cu
->language
== language_java
7335 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7340 make_cleanup (xfree
, demangled
);
7350 if (canon
== NULL
|| check_physname
)
7352 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7354 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7356 /* It may not mean a bug in GDB. The compiler could also
7357 compute DW_AT_linkage_name incorrectly. But in such case
7358 GDB would need to be bug-to-bug compatible. */
7360 complaint (&symfile_complaints
,
7361 _("Computed physname <%s> does not match demangled <%s> "
7362 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7363 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7365 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7366 is available here - over computed PHYSNAME. It is safer
7367 against both buggy GDB and buggy compilers. */
7381 retval
= obsavestring (retval
, strlen (retval
),
7382 &objfile
->objfile_obstack
);
7384 do_cleanups (back_to
);
7388 /* Read the import statement specified by the given die and record it. */
7391 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7393 struct objfile
*objfile
= cu
->objfile
;
7394 struct attribute
*import_attr
;
7395 struct die_info
*imported_die
, *child_die
;
7396 struct dwarf2_cu
*imported_cu
;
7397 const char *imported_name
;
7398 const char *imported_name_prefix
;
7399 const char *canonical_name
;
7400 const char *import_alias
;
7401 const char *imported_declaration
= NULL
;
7402 const char *import_prefix
;
7403 VEC (const_char_ptr
) *excludes
= NULL
;
7404 struct cleanup
*cleanups
;
7408 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7409 if (import_attr
== NULL
)
7411 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7412 dwarf_tag_name (die
->tag
));
7417 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7418 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7419 if (imported_name
== NULL
)
7421 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7423 The import in the following code:
7437 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7438 <52> DW_AT_decl_file : 1
7439 <53> DW_AT_decl_line : 6
7440 <54> DW_AT_import : <0x75>
7441 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7443 <5b> DW_AT_decl_file : 1
7444 <5c> DW_AT_decl_line : 2
7445 <5d> DW_AT_type : <0x6e>
7447 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7448 <76> DW_AT_byte_size : 4
7449 <77> DW_AT_encoding : 5 (signed)
7451 imports the wrong die ( 0x75 instead of 0x58 ).
7452 This case will be ignored until the gcc bug is fixed. */
7456 /* Figure out the local name after import. */
7457 import_alias
= dwarf2_name (die
, cu
);
7459 /* Figure out where the statement is being imported to. */
7460 import_prefix
= determine_prefix (die
, cu
);
7462 /* Figure out what the scope of the imported die is and prepend it
7463 to the name of the imported die. */
7464 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7466 if (imported_die
->tag
!= DW_TAG_namespace
7467 && imported_die
->tag
!= DW_TAG_module
)
7469 imported_declaration
= imported_name
;
7470 canonical_name
= imported_name_prefix
;
7472 else if (strlen (imported_name_prefix
) > 0)
7474 temp
= alloca (strlen (imported_name_prefix
)
7475 + 2 + strlen (imported_name
) + 1);
7476 strcpy (temp
, imported_name_prefix
);
7477 strcat (temp
, "::");
7478 strcat (temp
, imported_name
);
7479 canonical_name
= temp
;
7482 canonical_name
= imported_name
;
7484 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7486 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7487 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7488 child_die
= sibling_die (child_die
))
7490 /* DWARF-4: A Fortran use statement with a “rename list” may be
7491 represented by an imported module entry with an import attribute
7492 referring to the module and owned entries corresponding to those
7493 entities that are renamed as part of being imported. */
7495 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7497 complaint (&symfile_complaints
,
7498 _("child DW_TAG_imported_declaration expected "
7499 "- DIE at 0x%x [in module %s]"),
7500 child_die
->offset
.sect_off
, objfile
->name
);
7504 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7505 if (import_attr
== NULL
)
7507 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7508 dwarf_tag_name (child_die
->tag
));
7513 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7515 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7516 if (imported_name
== NULL
)
7518 complaint (&symfile_complaints
,
7519 _("child DW_TAG_imported_declaration has unknown "
7520 "imported name - DIE at 0x%x [in module %s]"),
7521 child_die
->offset
.sect_off
, objfile
->name
);
7525 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7527 process_die (child_die
, cu
);
7530 cp_add_using_directive (import_prefix
,
7533 imported_declaration
,
7535 &objfile
->objfile_obstack
);
7537 do_cleanups (cleanups
);
7540 /* Cleanup function for handle_DW_AT_stmt_list. */
7543 free_cu_line_header (void *arg
)
7545 struct dwarf2_cu
*cu
= arg
;
7547 free_line_header (cu
->line_header
);
7548 cu
->line_header
= NULL
;
7552 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7553 char **name
, char **comp_dir
)
7555 struct attribute
*attr
;
7560 /* Find the filename. Do not use dwarf2_name here, since the filename
7561 is not a source language identifier. */
7562 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7565 *name
= DW_STRING (attr
);
7568 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7570 *comp_dir
= DW_STRING (attr
);
7571 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7573 *comp_dir
= ldirname (*name
);
7574 if (*comp_dir
!= NULL
)
7575 make_cleanup (xfree
, *comp_dir
);
7577 if (*comp_dir
!= NULL
)
7579 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7580 directory, get rid of it. */
7581 char *cp
= strchr (*comp_dir
, ':');
7583 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7588 *name
= "<unknown>";
7591 /* Handle DW_AT_stmt_list for a compilation unit.
7592 DIE is the DW_TAG_compile_unit die for CU.
7593 COMP_DIR is the compilation directory.
7594 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7597 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7598 const char *comp_dir
)
7600 struct attribute
*attr
;
7602 gdb_assert (! cu
->per_cu
->is_debug_types
);
7604 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7607 unsigned int line_offset
= DW_UNSND (attr
);
7608 struct line_header
*line_header
7609 = dwarf_decode_line_header (line_offset
, cu
);
7613 cu
->line_header
= line_header
;
7614 make_cleanup (free_cu_line_header
, cu
);
7615 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7620 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7623 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7626 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7627 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7628 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7629 struct attribute
*attr
;
7631 char *comp_dir
= NULL
;
7632 struct die_info
*child_die
;
7633 bfd
*abfd
= objfile
->obfd
;
7636 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7638 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7640 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7641 from finish_block. */
7642 if (lowpc
== ((CORE_ADDR
) -1))
7647 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7649 prepare_one_comp_unit (cu
, die
, cu
->language
);
7651 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7652 standardised yet. As a workaround for the language detection we fall
7653 back to the DW_AT_producer string. */
7654 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7655 cu
->language
= language_opencl
;
7657 /* Similar hack for Go. */
7658 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7659 set_cu_language (DW_LANG_Go
, cu
);
7661 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7663 /* Decode line number information if present. We do this before
7664 processing child DIEs, so that the line header table is available
7665 for DW_AT_decl_file. */
7666 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7668 /* Process all dies in compilation unit. */
7669 if (die
->child
!= NULL
)
7671 child_die
= die
->child
;
7672 while (child_die
&& child_die
->tag
)
7674 process_die (child_die
, cu
);
7675 child_die
= sibling_die (child_die
);
7679 /* Decode macro information, if present. Dwarf 2 macro information
7680 refers to information in the line number info statement program
7681 header, so we can only read it if we've read the header
7683 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7684 if (attr
&& cu
->line_header
)
7686 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7687 complaint (&symfile_complaints
,
7688 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7690 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7694 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7695 if (attr
&& cu
->line_header
)
7697 unsigned int macro_offset
= DW_UNSND (attr
);
7699 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7703 do_cleanups (back_to
);
7706 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7707 Create the set of symtabs used by this TU, or if this TU is sharing
7708 symtabs with another TU and the symtabs have already been created
7709 then restore those symtabs in the line header.
7710 We don't need the pc/line-number mapping for type units. */
7713 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7715 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7716 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7717 struct type_unit_group
*tu_group
;
7719 struct line_header
*lh
;
7720 struct attribute
*attr
;
7721 unsigned int i
, line_offset
;
7723 gdb_assert (per_cu
->is_debug_types
);
7725 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7727 /* If we're using .gdb_index (includes -readnow) then
7728 per_cu->s.type_unit_group may not have been set up yet. */
7729 if (per_cu
->s
.type_unit_group
== NULL
)
7730 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7731 tu_group
= per_cu
->s
.type_unit_group
;
7733 /* If we've already processed this stmt_list there's no real need to
7734 do it again, we could fake it and just recreate the part we need
7735 (file name,index -> symtab mapping). If data shows this optimization
7736 is useful we can do it then. */
7737 first_time
= tu_group
->primary_symtab
== NULL
;
7739 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7744 line_offset
= DW_UNSND (attr
);
7745 lh
= dwarf_decode_line_header (line_offset
, cu
);
7750 dwarf2_start_symtab (cu
, "", NULL
, 0);
7753 gdb_assert (tu_group
->symtabs
== NULL
);
7756 /* Note: The primary symtab will get allocated at the end. */
7760 cu
->line_header
= lh
;
7761 make_cleanup (free_cu_line_header
, cu
);
7765 dwarf2_start_symtab (cu
, "", NULL
, 0);
7767 tu_group
->num_symtabs
= lh
->num_file_names
;
7768 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
7770 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7773 struct file_entry
*fe
= &lh
->file_names
[i
];
7776 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7777 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
7779 /* Note: We don't have to watch for the main subfile here, type units
7780 don't have DW_AT_name. */
7782 if (current_subfile
->symtab
== NULL
)
7784 /* NOTE: start_subfile will recognize when it's been passed
7785 a file it has already seen. So we can't assume there's a
7786 simple mapping from lh->file_names to subfiles,
7787 lh->file_names may contain dups. */
7788 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7792 fe
->symtab
= current_subfile
->symtab
;
7793 tu_group
->symtabs
[i
] = fe
->symtab
;
7800 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7802 struct file_entry
*fe
= &lh
->file_names
[i
];
7804 fe
->symtab
= tu_group
->symtabs
[i
];
7808 /* The main symtab is allocated last. Type units don't have DW_AT_name
7809 so they don't have a "real" (so to speak) symtab anyway.
7810 There is later code that will assign the main symtab to all symbols
7811 that don't have one. We need to handle the case of a symbol with a
7812 missing symtab (DW_AT_decl_file) anyway. */
7815 /* Process DW_TAG_type_unit.
7816 For TUs we want to skip the first top level sibling if it's not the
7817 actual type being defined by this TU. In this case the first top
7818 level sibling is there to provide context only. */
7821 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7823 struct die_info
*child_die
;
7825 prepare_one_comp_unit (cu
, die
, language_minimal
);
7827 /* Initialize (or reinitialize) the machinery for building symtabs.
7828 We do this before processing child DIEs, so that the line header table
7829 is available for DW_AT_decl_file. */
7830 setup_type_unit_groups (die
, cu
);
7832 if (die
->child
!= NULL
)
7834 child_die
= die
->child
;
7835 while (child_die
&& child_die
->tag
)
7837 process_die (child_die
, cu
);
7838 child_die
= sibling_die (child_die
);
7846 hash_dwo_file (const void *item
)
7848 const struct dwo_file
*dwo_file
= item
;
7850 return htab_hash_string (dwo_file
->dwo_name
);
7854 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
7856 const struct dwo_file
*lhs
= item_lhs
;
7857 const struct dwo_file
*rhs
= item_rhs
;
7859 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
7862 /* Allocate a hash table for DWO files. */
7865 allocate_dwo_file_hash_table (void)
7867 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7869 return htab_create_alloc_ex (41,
7873 &objfile
->objfile_obstack
,
7874 hashtab_obstack_allocate
,
7875 dummy_obstack_deallocate
);
7879 hash_dwo_unit (const void *item
)
7881 const struct dwo_unit
*dwo_unit
= item
;
7883 /* This drops the top 32 bits of the id, but is ok for a hash. */
7884 return dwo_unit
->signature
;
7888 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
7890 const struct dwo_unit
*lhs
= item_lhs
;
7891 const struct dwo_unit
*rhs
= item_rhs
;
7893 /* The signature is assumed to be unique within the DWO file.
7894 So while object file CU dwo_id's always have the value zero,
7895 that's OK, assuming each object file DWO file has only one CU,
7896 and that's the rule for now. */
7897 return lhs
->signature
== rhs
->signature
;
7900 /* Allocate a hash table for DWO CUs,TUs.
7901 There is one of these tables for each of CUs,TUs for each DWO file. */
7904 allocate_dwo_unit_table (struct objfile
*objfile
)
7906 /* Start out with a pretty small number.
7907 Generally DWO files contain only one CU and maybe some TUs. */
7908 return htab_create_alloc_ex (3,
7912 &objfile
->objfile_obstack
,
7913 hashtab_obstack_allocate
,
7914 dummy_obstack_deallocate
);
7917 /* This function is mapped across the sections and remembers the offset and
7918 size of each of the DWO debugging sections we are interested in. */
7921 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
7923 struct dwo_file
*dwo_file
= dwo_file_ptr
;
7924 const struct dwo_section_names
*names
= &dwo_section_names
;
7926 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
7928 dwo_file
->sections
.abbrev
.asection
= sectp
;
7929 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
7931 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
7933 dwo_file
->sections
.info
.asection
= sectp
;
7934 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
7936 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
7938 dwo_file
->sections
.line
.asection
= sectp
;
7939 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
7941 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
7943 dwo_file
->sections
.loc
.asection
= sectp
;
7944 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
7946 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
7948 dwo_file
->sections
.macinfo
.asection
= sectp
;
7949 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
7951 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
7953 dwo_file
->sections
.macro
.asection
= sectp
;
7954 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
7956 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
7958 dwo_file
->sections
.str
.asection
= sectp
;
7959 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
7961 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
7963 dwo_file
->sections
.str_offsets
.asection
= sectp
;
7964 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
7966 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
7968 struct dwarf2_section_info type_section
;
7970 memset (&type_section
, 0, sizeof (type_section
));
7971 type_section
.asection
= sectp
;
7972 type_section
.size
= bfd_get_section_size (sectp
);
7973 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
7978 /* Structure used to pass data to create_debug_info_hash_table_reader. */
7980 struct create_dwo_info_table_data
7982 struct dwo_file
*dwo_file
;
7986 /* die_reader_func for create_debug_info_hash_table. */
7989 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
7991 struct die_info
*comp_unit_die
,
7995 struct dwarf2_cu
*cu
= reader
->cu
;
7996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7997 sect_offset offset
= cu
->per_cu
->offset
;
7998 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
7999 struct create_dwo_info_table_data
*data
= datap
;
8000 struct dwo_file
*dwo_file
= data
->dwo_file
;
8001 htab_t cu_htab
= data
->cu_htab
;
8003 struct attribute
*attr
;
8004 struct dwo_unit
*dwo_unit
;
8006 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8009 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8010 " its dwo_id [in module %s]"),
8011 offset
.sect_off
, dwo_file
->dwo_name
);
8015 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8016 dwo_unit
->dwo_file
= dwo_file
;
8017 dwo_unit
->signature
= DW_UNSND (attr
);
8018 dwo_unit
->info_or_types_section
= section
;
8019 dwo_unit
->offset
= offset
;
8020 dwo_unit
->length
= cu
->per_cu
->length
;
8022 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8023 gdb_assert (slot
!= NULL
);
8026 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8028 complaint (&symfile_complaints
,
8029 _("debug entry at offset 0x%x is duplicate to the entry at"
8030 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8031 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8032 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8033 dwo_file
->dwo_name
);
8038 if (dwarf2_read_debug
)
8039 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8041 phex (dwo_unit
->signature
,
8042 sizeof (dwo_unit
->signature
)));
8045 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
8048 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
8050 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8051 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8054 gdb_byte
*info_ptr
, *end_ptr
;
8055 struct create_dwo_info_table_data create_dwo_info_table_data
;
8057 dwarf2_read_section (objfile
, section
);
8058 info_ptr
= section
->buffer
;
8060 if (info_ptr
== NULL
)
8063 /* We can't set abfd until now because the section may be empty or
8064 not present, in which case section->asection will be NULL. */
8065 abfd
= section
->asection
->owner
;
8067 if (dwarf2_read_debug
)
8068 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8069 bfd_get_filename (abfd
));
8071 cu_htab
= allocate_dwo_unit_table (objfile
);
8073 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8074 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8076 end_ptr
= info_ptr
+ section
->size
;
8077 while (info_ptr
< end_ptr
)
8079 struct dwarf2_per_cu_data per_cu
;
8081 memset (&per_cu
, 0, sizeof (per_cu
));
8082 per_cu
.objfile
= objfile
;
8083 per_cu
.is_debug_types
= 0;
8084 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8085 per_cu
.info_or_types_section
= section
;
8087 init_cutu_and_read_dies_no_follow (&per_cu
,
8088 &dwo_file
->sections
.abbrev
,
8090 create_debug_info_hash_table_reader
,
8091 &create_dwo_info_table_data
);
8093 info_ptr
+= per_cu
.length
;
8099 /* Subroutine of open_dwo_file to simplify it.
8100 Open the file specified by FILE_NAME and hand it off to BFD for
8101 preliminary analysis. Return a newly initialized bfd *, which
8102 includes a canonicalized copy of FILE_NAME.
8103 In case of trouble, return NULL.
8104 NOTE: This function is derived from symfile_bfd_open. */
8107 try_open_dwo_file (const char *file_name
)
8111 char *absolute_name
;
8113 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
8114 O_RDONLY
| O_BINARY
, &absolute_name
);
8118 sym_bfd
= gdb_bfd_ref (bfd_fopen (absolute_name
, gnutarget
, FOPEN_RB
, desc
));
8121 xfree (absolute_name
);
8124 gdb_bfd_stash_filename (sym_bfd
);
8125 xfree (absolute_name
);
8126 bfd_set_cacheable (sym_bfd
, 1);
8128 if (!bfd_check_format (sym_bfd
, bfd_object
))
8130 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8137 /* Try to open DWO file DWO_NAME.
8138 COMP_DIR is the DW_AT_comp_dir attribute.
8139 The result is the bfd handle of the file.
8140 If there is a problem finding or opening the file, return NULL.
8141 Upon success, the canonicalized path of the file is stored in the bfd,
8142 same as symfile_bfd_open. */
8145 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8149 if (IS_ABSOLUTE_PATH (dwo_name
))
8150 return try_open_dwo_file (dwo_name
);
8152 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8154 if (comp_dir
!= NULL
)
8156 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8158 /* NOTE: If comp_dir is a relative path, this will also try the
8159 search path, which seems useful. */
8160 abfd
= try_open_dwo_file (path_to_try
);
8161 xfree (path_to_try
);
8166 /* That didn't work, try debug-file-directory, which, despite its name,
8167 is a list of paths. */
8169 if (*debug_file_directory
== '\0')
8172 return try_open_dwo_file (dwo_name
);
8175 /* Initialize the use of the DWO file specified by DWO_NAME. */
8177 static struct dwo_file
*
8178 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8180 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8181 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8184 struct cleanup
*cleanups
;
8186 if (dwarf2_read_debug
)
8187 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8189 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8192 dwo_file
->dwo_name
= dwo_name
;
8193 dwo_file
->dwo_bfd
= abfd
;
8195 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8197 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8199 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8201 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8202 dwo_file
->sections
.types
);
8204 discard_cleanups (cleanups
);
8209 /* Lookup DWO file DWO_NAME. */
8211 static struct dwo_file
*
8212 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8214 struct dwo_file
*dwo_file
;
8215 struct dwo_file find_entry
;
8218 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8219 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8221 /* Have we already seen this DWO file? */
8222 find_entry
.dwo_name
= dwo_name
;
8223 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8225 /* If not, read it in and build a table of the DWOs it contains. */
8227 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8229 /* NOTE: This will be NULL if unable to open the file. */
8235 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8236 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8237 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8238 nomenclature as TUs).
8239 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8240 (dwo_id mismatch or couldn't find the DWO file). */
8242 static struct dwo_unit
*
8243 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8244 char *dwo_name
, const char *comp_dir
,
8247 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8248 struct dwo_file
*dwo_file
;
8250 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8251 if (dwo_file
== NULL
)
8254 /* Look up the DWO using its signature(dwo_id). */
8256 if (dwo_file
->cus
!= NULL
)
8258 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8260 find_dwo_cu
.signature
= signature
;
8261 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8267 /* We didn't find it. This must mean a dwo_id mismatch. */
8269 complaint (&symfile_complaints
,
8270 _("Could not find DWO CU referenced by CU at offset 0x%x"
8272 this_cu
->offset
.sect_off
, objfile
->name
);
8276 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8277 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8278 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8279 (dwo_id mismatch or couldn't find the DWO file). */
8281 static struct dwo_unit
*
8282 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8283 char *dwo_name
, const char *comp_dir
)
8285 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8286 struct dwo_file
*dwo_file
;
8288 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8289 if (dwo_file
== NULL
)
8292 /* Look up the DWO using its signature(dwo_id). */
8294 if (dwo_file
->tus
!= NULL
)
8296 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8298 find_dwo_tu
.signature
= this_tu
->signature
;
8299 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8305 /* We didn't find it. This must mean a dwo_id mismatch. */
8307 complaint (&symfile_complaints
,
8308 _("Could not find DWO TU referenced by TU at offset 0x%x"
8310 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8314 /* Free all resources associated with DWO_FILE.
8315 Close the DWO file and munmap the sections.
8316 All memory should be on the objfile obstack. */
8319 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8322 struct dwarf2_section_info
*section
;
8324 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8325 gdb_bfd_unref (dwo_file
->dwo_bfd
);
8327 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
8328 munmap_section_buffer (&dwo_file
->sections
.info
);
8329 munmap_section_buffer (&dwo_file
->sections
.line
);
8330 munmap_section_buffer (&dwo_file
->sections
.loc
);
8331 munmap_section_buffer (&dwo_file
->sections
.str
);
8332 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
8335 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
8338 munmap_section_buffer (section
);
8340 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8343 /* Wrapper for free_dwo_file for use in cleanups. */
8346 free_dwo_file_cleanup (void *arg
)
8348 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8349 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8351 free_dwo_file (dwo_file
, objfile
);
8354 /* Traversal function for free_dwo_files. */
8357 free_dwo_file_from_slot (void **slot
, void *info
)
8359 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8360 struct objfile
*objfile
= (struct objfile
*) info
;
8362 free_dwo_file (dwo_file
, objfile
);
8367 /* Free all resources associated with DWO_FILES. */
8370 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8372 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8375 /* Read in various DIEs. */
8377 /* qsort helper for inherit_abstract_dies. */
8380 unsigned_int_compar (const void *ap
, const void *bp
)
8382 unsigned int a
= *(unsigned int *) ap
;
8383 unsigned int b
= *(unsigned int *) bp
;
8385 return (a
> b
) - (b
> a
);
8388 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8389 Inherit only the children of the DW_AT_abstract_origin DIE not being
8390 already referenced by DW_AT_abstract_origin from the children of the
8394 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8396 struct die_info
*child_die
;
8397 unsigned die_children_count
;
8398 /* CU offsets which were referenced by children of the current DIE. */
8399 sect_offset
*offsets
;
8400 sect_offset
*offsets_end
, *offsetp
;
8401 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8402 struct die_info
*origin_die
;
8403 /* Iterator of the ORIGIN_DIE children. */
8404 struct die_info
*origin_child_die
;
8405 struct cleanup
*cleanups
;
8406 struct attribute
*attr
;
8407 struct dwarf2_cu
*origin_cu
;
8408 struct pending
**origin_previous_list_in_scope
;
8410 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8414 /* Note that following die references may follow to a die in a
8418 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8420 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8422 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8423 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8425 if (die
->tag
!= origin_die
->tag
8426 && !(die
->tag
== DW_TAG_inlined_subroutine
8427 && origin_die
->tag
== DW_TAG_subprogram
))
8428 complaint (&symfile_complaints
,
8429 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8430 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8432 child_die
= die
->child
;
8433 die_children_count
= 0;
8434 while (child_die
&& child_die
->tag
)
8436 child_die
= sibling_die (child_die
);
8437 die_children_count
++;
8439 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8440 cleanups
= make_cleanup (xfree
, offsets
);
8442 offsets_end
= offsets
;
8443 child_die
= die
->child
;
8444 while (child_die
&& child_die
->tag
)
8446 /* For each CHILD_DIE, find the corresponding child of
8447 ORIGIN_DIE. If there is more than one layer of
8448 DW_AT_abstract_origin, follow them all; there shouldn't be,
8449 but GCC versions at least through 4.4 generate this (GCC PR
8451 struct die_info
*child_origin_die
= child_die
;
8452 struct dwarf2_cu
*child_origin_cu
= cu
;
8456 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8460 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8464 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8465 counterpart may exist. */
8466 if (child_origin_die
!= child_die
)
8468 if (child_die
->tag
!= child_origin_die
->tag
8469 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8470 && child_origin_die
->tag
== DW_TAG_subprogram
))
8471 complaint (&symfile_complaints
,
8472 _("Child DIE 0x%x and its abstract origin 0x%x have "
8473 "different tags"), child_die
->offset
.sect_off
,
8474 child_origin_die
->offset
.sect_off
);
8475 if (child_origin_die
->parent
!= origin_die
)
8476 complaint (&symfile_complaints
,
8477 _("Child DIE 0x%x and its abstract origin 0x%x have "
8478 "different parents"), child_die
->offset
.sect_off
,
8479 child_origin_die
->offset
.sect_off
);
8481 *offsets_end
++ = child_origin_die
->offset
;
8483 child_die
= sibling_die (child_die
);
8485 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8486 unsigned_int_compar
);
8487 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8488 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8489 complaint (&symfile_complaints
,
8490 _("Multiple children of DIE 0x%x refer "
8491 "to DIE 0x%x as their abstract origin"),
8492 die
->offset
.sect_off
, offsetp
->sect_off
);
8495 origin_child_die
= origin_die
->child
;
8496 while (origin_child_die
&& origin_child_die
->tag
)
8498 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8499 while (offsetp
< offsets_end
8500 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8502 if (offsetp
>= offsets_end
8503 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8505 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8506 process_die (origin_child_die
, origin_cu
);
8508 origin_child_die
= sibling_die (origin_child_die
);
8510 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8512 do_cleanups (cleanups
);
8516 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8518 struct objfile
*objfile
= cu
->objfile
;
8519 struct context_stack
*new;
8522 struct die_info
*child_die
;
8523 struct attribute
*attr
, *call_line
, *call_file
;
8526 struct block
*block
;
8527 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8528 VEC (symbolp
) *template_args
= NULL
;
8529 struct template_symbol
*templ_func
= NULL
;
8533 /* If we do not have call site information, we can't show the
8534 caller of this inlined function. That's too confusing, so
8535 only use the scope for local variables. */
8536 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8537 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8538 if (call_line
== NULL
|| call_file
== NULL
)
8540 read_lexical_block_scope (die
, cu
);
8545 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8547 name
= dwarf2_name (die
, cu
);
8549 /* Ignore functions with missing or empty names. These are actually
8550 illegal according to the DWARF standard. */
8553 complaint (&symfile_complaints
,
8554 _("missing name for subprogram DIE at %d"),
8555 die
->offset
.sect_off
);
8559 /* Ignore functions with missing or invalid low and high pc attributes. */
8560 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8562 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8563 if (!attr
|| !DW_UNSND (attr
))
8564 complaint (&symfile_complaints
,
8565 _("cannot get low and high bounds "
8566 "for subprogram DIE at %d"),
8567 die
->offset
.sect_off
);
8574 /* If we have any template arguments, then we must allocate a
8575 different sort of symbol. */
8576 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8578 if (child_die
->tag
== DW_TAG_template_type_param
8579 || child_die
->tag
== DW_TAG_template_value_param
)
8581 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8582 struct template_symbol
);
8583 templ_func
->base
.is_cplus_template_function
= 1;
8588 new = push_context (0, lowpc
);
8589 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8590 (struct symbol
*) templ_func
);
8592 /* If there is a location expression for DW_AT_frame_base, record
8594 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8596 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8597 expression is being recorded directly in the function's symbol
8598 and not in a separate frame-base object. I guess this hack is
8599 to avoid adding some sort of frame-base adjunct/annex to the
8600 function's symbol :-(. The problem with doing this is that it
8601 results in a function symbol with a location expression that
8602 has nothing to do with the location of the function, ouch! The
8603 relationship should be: a function's symbol has-a frame base; a
8604 frame-base has-a location expression. */
8605 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8607 cu
->list_in_scope
= &local_symbols
;
8609 if (die
->child
!= NULL
)
8611 child_die
= die
->child
;
8612 while (child_die
&& child_die
->tag
)
8614 if (child_die
->tag
== DW_TAG_template_type_param
8615 || child_die
->tag
== DW_TAG_template_value_param
)
8617 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8620 VEC_safe_push (symbolp
, template_args
, arg
);
8623 process_die (child_die
, cu
);
8624 child_die
= sibling_die (child_die
);
8628 inherit_abstract_dies (die
, cu
);
8630 /* If we have a DW_AT_specification, we might need to import using
8631 directives from the context of the specification DIE. See the
8632 comment in determine_prefix. */
8633 if (cu
->language
== language_cplus
8634 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8636 struct dwarf2_cu
*spec_cu
= cu
;
8637 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8641 child_die
= spec_die
->child
;
8642 while (child_die
&& child_die
->tag
)
8644 if (child_die
->tag
== DW_TAG_imported_module
)
8645 process_die (child_die
, spec_cu
);
8646 child_die
= sibling_die (child_die
);
8649 /* In some cases, GCC generates specification DIEs that
8650 themselves contain DW_AT_specification attributes. */
8651 spec_die
= die_specification (spec_die
, &spec_cu
);
8655 new = pop_context ();
8656 /* Make a block for the local symbols within. */
8657 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8658 lowpc
, highpc
, objfile
);
8660 /* For C++, set the block's scope. */
8661 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8662 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8663 determine_prefix (die
, cu
),
8664 processing_has_namespace_info
);
8666 /* If we have address ranges, record them. */
8667 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8669 /* Attach template arguments to function. */
8670 if (! VEC_empty (symbolp
, template_args
))
8672 gdb_assert (templ_func
!= NULL
);
8674 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8675 templ_func
->template_arguments
8676 = obstack_alloc (&objfile
->objfile_obstack
,
8677 (templ_func
->n_template_arguments
8678 * sizeof (struct symbol
*)));
8679 memcpy (templ_func
->template_arguments
,
8680 VEC_address (symbolp
, template_args
),
8681 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8682 VEC_free (symbolp
, template_args
);
8685 /* In C++, we can have functions nested inside functions (e.g., when
8686 a function declares a class that has methods). This means that
8687 when we finish processing a function scope, we may need to go
8688 back to building a containing block's symbol lists. */
8689 local_symbols
= new->locals
;
8690 param_symbols
= new->params
;
8691 using_directives
= new->using_directives
;
8693 /* If we've finished processing a top-level function, subsequent
8694 symbols go in the file symbol list. */
8695 if (outermost_context_p ())
8696 cu
->list_in_scope
= &file_symbols
;
8699 /* Process all the DIES contained within a lexical block scope. Start
8700 a new scope, process the dies, and then close the scope. */
8703 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8705 struct objfile
*objfile
= cu
->objfile
;
8706 struct context_stack
*new;
8707 CORE_ADDR lowpc
, highpc
;
8708 struct die_info
*child_die
;
8711 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8713 /* Ignore blocks with missing or invalid low and high pc attributes. */
8714 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8715 as multiple lexical blocks? Handling children in a sane way would
8716 be nasty. Might be easier to properly extend generic blocks to
8718 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8723 push_context (0, lowpc
);
8724 if (die
->child
!= NULL
)
8726 child_die
= die
->child
;
8727 while (child_die
&& child_die
->tag
)
8729 process_die (child_die
, cu
);
8730 child_die
= sibling_die (child_die
);
8733 new = pop_context ();
8735 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8738 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8741 /* Note that recording ranges after traversing children, as we
8742 do here, means that recording a parent's ranges entails
8743 walking across all its children's ranges as they appear in
8744 the address map, which is quadratic behavior.
8746 It would be nicer to record the parent's ranges before
8747 traversing its children, simply overriding whatever you find
8748 there. But since we don't even decide whether to create a
8749 block until after we've traversed its children, that's hard
8751 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8753 local_symbols
= new->locals
;
8754 using_directives
= new->using_directives
;
8757 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8760 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8762 struct objfile
*objfile
= cu
->objfile
;
8763 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8764 CORE_ADDR pc
, baseaddr
;
8765 struct attribute
*attr
;
8766 struct call_site
*call_site
, call_site_local
;
8769 struct die_info
*child_die
;
8771 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8773 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8776 complaint (&symfile_complaints
,
8777 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8778 "DIE 0x%x [in module %s]"),
8779 die
->offset
.sect_off
, objfile
->name
);
8782 pc
= DW_ADDR (attr
) + baseaddr
;
8784 if (cu
->call_site_htab
== NULL
)
8785 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8786 NULL
, &objfile
->objfile_obstack
,
8787 hashtab_obstack_allocate
, NULL
);
8788 call_site_local
.pc
= pc
;
8789 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8792 complaint (&symfile_complaints
,
8793 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8794 "DIE 0x%x [in module %s]"),
8795 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8799 /* Count parameters at the caller. */
8802 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8803 child_die
= sibling_die (child_die
))
8805 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8807 complaint (&symfile_complaints
,
8808 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8809 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8810 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8817 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8818 (sizeof (*call_site
)
8819 + (sizeof (*call_site
->parameter
)
8822 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8825 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8827 struct die_info
*func_die
;
8829 /* Skip also over DW_TAG_inlined_subroutine. */
8830 for (func_die
= die
->parent
;
8831 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8832 && func_die
->tag
!= DW_TAG_subroutine_type
;
8833 func_die
= func_die
->parent
);
8835 /* DW_AT_GNU_all_call_sites is a superset
8836 of DW_AT_GNU_all_tail_call_sites. */
8838 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8839 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8841 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8842 not complete. But keep CALL_SITE for look ups via call_site_htab,
8843 both the initial caller containing the real return address PC and
8844 the final callee containing the current PC of a chain of tail
8845 calls do not need to have the tail call list complete. But any
8846 function candidate for a virtual tail call frame searched via
8847 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8848 determined unambiguously. */
8852 struct type
*func_type
= NULL
;
8855 func_type
= get_die_type (func_die
, cu
);
8856 if (func_type
!= NULL
)
8858 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
8860 /* Enlist this call site to the function. */
8861 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
8862 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
8865 complaint (&symfile_complaints
,
8866 _("Cannot find function owning DW_TAG_GNU_call_site "
8867 "DIE 0x%x [in module %s]"),
8868 die
->offset
.sect_off
, objfile
->name
);
8872 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
8874 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8875 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
8876 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
8877 /* Keep NULL DWARF_BLOCK. */;
8878 else if (attr_form_is_block (attr
))
8880 struct dwarf2_locexpr_baton
*dlbaton
;
8882 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
8883 dlbaton
->data
= DW_BLOCK (attr
)->data
;
8884 dlbaton
->size
= DW_BLOCK (attr
)->size
;
8885 dlbaton
->per_cu
= cu
->per_cu
;
8887 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
8889 else if (is_ref_attr (attr
))
8891 struct dwarf2_cu
*target_cu
= cu
;
8892 struct die_info
*target_die
;
8894 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
8895 gdb_assert (target_cu
->objfile
== objfile
);
8896 if (die_is_declaration (target_die
, target_cu
))
8898 const char *target_physname
;
8900 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
8901 if (target_physname
== NULL
)
8902 complaint (&symfile_complaints
,
8903 _("DW_AT_GNU_call_site_target target DIE has invalid "
8904 "physname, for referencing DIE 0x%x [in module %s]"),
8905 die
->offset
.sect_off
, objfile
->name
);
8907 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
8913 /* DW_AT_entry_pc should be preferred. */
8914 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
8915 complaint (&symfile_complaints
,
8916 _("DW_AT_GNU_call_site_target target DIE has invalid "
8917 "low pc, for referencing DIE 0x%x [in module %s]"),
8918 die
->offset
.sect_off
, objfile
->name
);
8920 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
8924 complaint (&symfile_complaints
,
8925 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
8926 "block nor reference, for DIE 0x%x [in module %s]"),
8927 die
->offset
.sect_off
, objfile
->name
);
8929 call_site
->per_cu
= cu
->per_cu
;
8931 for (child_die
= die
->child
;
8932 child_die
&& child_die
->tag
;
8933 child_die
= sibling_die (child_die
))
8935 struct call_site_parameter
*parameter
;
8936 struct attribute
*loc
, *origin
;
8938 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8940 /* Already printed the complaint above. */
8944 gdb_assert (call_site
->parameter_count
< nparams
);
8945 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8947 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8948 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8949 register is contained in DW_AT_GNU_call_site_value. */
8951 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8952 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8953 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8957 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8958 offset
= dwarf2_get_ref_die_offset (origin
);
8959 if (!offset_in_cu_p (&cu
->header
, offset
))
8961 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
8962 binding can be done only inside one CU. Such referenced DIE
8963 therefore cannot be even moved to DW_TAG_partial_unit. */
8964 complaint (&symfile_complaints
,
8965 _("DW_AT_abstract_origin offset is not in CU for "
8966 "DW_TAG_GNU_call_site child DIE 0x%x "
8968 child_die
->offset
.sect_off
, objfile
->name
);
8971 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8972 - cu
->header
.offset
.sect_off
);
8974 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8976 complaint (&symfile_complaints
,
8977 _("No DW_FORM_block* DW_AT_location for "
8978 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8979 child_die
->offset
.sect_off
, objfile
->name
);
8984 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8985 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8986 if (parameter
->u
.dwarf_reg
!= -1)
8987 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8988 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8989 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8990 ¶meter
->u
.fb_offset
))
8991 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8994 complaint (&symfile_complaints
,
8995 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8996 "for DW_FORM_block* DW_AT_location is supported for "
8997 "DW_TAG_GNU_call_site child DIE 0x%x "
8999 child_die
->offset
.sect_off
, objfile
->name
);
9004 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9005 if (!attr_form_is_block (attr
))
9007 complaint (&symfile_complaints
,
9008 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9009 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9010 child_die
->offset
.sect_off
, objfile
->name
);
9013 parameter
->value
= DW_BLOCK (attr
)->data
;
9014 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9016 /* Parameters are not pre-cleared by memset above. */
9017 parameter
->data_value
= NULL
;
9018 parameter
->data_value_size
= 0;
9019 call_site
->parameter_count
++;
9021 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9024 if (!attr_form_is_block (attr
))
9025 complaint (&symfile_complaints
,
9026 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9027 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9028 child_die
->offset
.sect_off
, objfile
->name
);
9031 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9032 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9038 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9039 Return 1 if the attributes are present and valid, otherwise, return 0.
9040 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9043 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9044 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9045 struct partial_symtab
*ranges_pst
)
9047 struct objfile
*objfile
= cu
->objfile
;
9048 struct comp_unit_head
*cu_header
= &cu
->header
;
9049 bfd
*obfd
= objfile
->obfd
;
9050 unsigned int addr_size
= cu_header
->addr_size
;
9051 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9052 /* Base address selection entry. */
9063 found_base
= cu
->base_known
;
9064 base
= cu
->base_address
;
9066 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9067 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9069 complaint (&symfile_complaints
,
9070 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9074 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9076 /* Read in the largest possible address. */
9077 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9078 if ((marker
& mask
) == mask
)
9080 /* If we found the largest possible address, then
9081 read the base address. */
9082 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9083 buffer
+= 2 * addr_size
;
9084 offset
+= 2 * addr_size
;
9090 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9094 CORE_ADDR range_beginning
, range_end
;
9096 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9097 buffer
+= addr_size
;
9098 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9099 buffer
+= addr_size
;
9100 offset
+= 2 * addr_size
;
9102 /* An end of list marker is a pair of zero addresses. */
9103 if (range_beginning
== 0 && range_end
== 0)
9104 /* Found the end of list entry. */
9107 /* Each base address selection entry is a pair of 2 values.
9108 The first is the largest possible address, the second is
9109 the base address. Check for a base address here. */
9110 if ((range_beginning
& mask
) == mask
)
9112 /* If we found the largest possible address, then
9113 read the base address. */
9114 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9121 /* We have no valid base address for the ranges
9123 complaint (&symfile_complaints
,
9124 _("Invalid .debug_ranges data (no base address)"));
9128 if (range_beginning
> range_end
)
9130 /* Inverted range entries are invalid. */
9131 complaint (&symfile_complaints
,
9132 _("Invalid .debug_ranges data (inverted range)"));
9136 /* Empty range entries have no effect. */
9137 if (range_beginning
== range_end
)
9140 range_beginning
+= base
;
9143 if (ranges_pst
!= NULL
)
9144 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9145 range_beginning
+ baseaddr
,
9146 range_end
- 1 + baseaddr
,
9149 /* FIXME: This is recording everything as a low-high
9150 segment of consecutive addresses. We should have a
9151 data structure for discontiguous block ranges
9155 low
= range_beginning
;
9161 if (range_beginning
< low
)
9162 low
= range_beginning
;
9163 if (range_end
> high
)
9169 /* If the first entry is an end-of-list marker, the range
9170 describes an empty scope, i.e. no instructions. */
9176 *high_return
= high
;
9180 /* Get low and high pc attributes from a die. Return 1 if the attributes
9181 are present and valid, otherwise, return 0. Return -1 if the range is
9182 discontinuous, i.e. derived from DW_AT_ranges information. */
9185 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9186 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9187 struct partial_symtab
*pst
)
9189 struct attribute
*attr
;
9190 struct attribute
*attr_high
;
9195 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9198 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9201 low
= DW_ADDR (attr
);
9202 if (attr_high
->form
== DW_FORM_addr
9203 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9204 high
= DW_ADDR (attr_high
);
9206 high
= low
+ DW_UNSND (attr_high
);
9209 /* Found high w/o low attribute. */
9212 /* Found consecutive range of addresses. */
9217 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9220 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9222 /* Value of the DW_AT_ranges attribute is the offset in the
9223 .debug_ranges section. */
9224 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9226 /* Found discontinuous range of addresses. */
9231 /* read_partial_die has also the strict LOW < HIGH requirement. */
9235 /* When using the GNU linker, .gnu.linkonce. sections are used to
9236 eliminate duplicate copies of functions and vtables and such.
9237 The linker will arbitrarily choose one and discard the others.
9238 The AT_*_pc values for such functions refer to local labels in
9239 these sections. If the section from that file was discarded, the
9240 labels are not in the output, so the relocs get a value of 0.
9241 If this is a discarded function, mark the pc bounds as invalid,
9242 so that GDB will ignore it. */
9243 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9252 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9253 its low and high PC addresses. Do nothing if these addresses could not
9254 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9255 and HIGHPC to the high address if greater than HIGHPC. */
9258 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9259 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9260 struct dwarf2_cu
*cu
)
9262 CORE_ADDR low
, high
;
9263 struct die_info
*child
= die
->child
;
9265 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9267 *lowpc
= min (*lowpc
, low
);
9268 *highpc
= max (*highpc
, high
);
9271 /* If the language does not allow nested subprograms (either inside
9272 subprograms or lexical blocks), we're done. */
9273 if (cu
->language
!= language_ada
)
9276 /* Check all the children of the given DIE. If it contains nested
9277 subprograms, then check their pc bounds. Likewise, we need to
9278 check lexical blocks as well, as they may also contain subprogram
9280 while (child
&& child
->tag
)
9282 if (child
->tag
== DW_TAG_subprogram
9283 || child
->tag
== DW_TAG_lexical_block
)
9284 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9285 child
= sibling_die (child
);
9289 /* Get the low and high pc's represented by the scope DIE, and store
9290 them in *LOWPC and *HIGHPC. If the correct values can't be
9291 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9294 get_scope_pc_bounds (struct die_info
*die
,
9295 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9296 struct dwarf2_cu
*cu
)
9298 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9299 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9300 CORE_ADDR current_low
, current_high
;
9302 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9304 best_low
= current_low
;
9305 best_high
= current_high
;
9309 struct die_info
*child
= die
->child
;
9311 while (child
&& child
->tag
)
9313 switch (child
->tag
) {
9314 case DW_TAG_subprogram
:
9315 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9317 case DW_TAG_namespace
:
9319 /* FIXME: carlton/2004-01-16: Should we do this for
9320 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9321 that current GCC's always emit the DIEs corresponding
9322 to definitions of methods of classes as children of a
9323 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9324 the DIEs giving the declarations, which could be
9325 anywhere). But I don't see any reason why the
9326 standards says that they have to be there. */
9327 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9329 if (current_low
!= ((CORE_ADDR
) -1))
9331 best_low
= min (best_low
, current_low
);
9332 best_high
= max (best_high
, current_high
);
9340 child
= sibling_die (child
);
9345 *highpc
= best_high
;
9348 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9352 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9353 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9355 struct objfile
*objfile
= cu
->objfile
;
9356 struct attribute
*attr
;
9357 struct attribute
*attr_high
;
9359 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9362 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9365 CORE_ADDR low
= DW_ADDR (attr
);
9367 if (attr_high
->form
== DW_FORM_addr
9368 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9369 high
= DW_ADDR (attr_high
);
9371 high
= low
+ DW_UNSND (attr_high
);
9373 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9380 bfd
*obfd
= objfile
->obfd
;
9382 /* The value of the DW_AT_ranges attribute is the offset of the
9383 address range list in the .debug_ranges section. */
9384 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9385 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9387 /* For some target architectures, but not others, the
9388 read_address function sign-extends the addresses it returns.
9389 To recognize base address selection entries, we need a
9391 unsigned int addr_size
= cu
->header
.addr_size
;
9392 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9394 /* The base address, to which the next pair is relative. Note
9395 that this 'base' is a DWARF concept: most entries in a range
9396 list are relative, to reduce the number of relocs against the
9397 debugging information. This is separate from this function's
9398 'baseaddr' argument, which GDB uses to relocate debugging
9399 information from a shared library based on the address at
9400 which the library was loaded. */
9401 CORE_ADDR base
= cu
->base_address
;
9402 int base_known
= cu
->base_known
;
9404 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9405 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9407 complaint (&symfile_complaints
,
9408 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9415 unsigned int bytes_read
;
9416 CORE_ADDR start
, end
;
9418 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9419 buffer
+= bytes_read
;
9420 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9421 buffer
+= bytes_read
;
9423 /* Did we find the end of the range list? */
9424 if (start
== 0 && end
== 0)
9427 /* Did we find a base address selection entry? */
9428 else if ((start
& base_select_mask
) == base_select_mask
)
9434 /* We found an ordinary address range. */
9439 complaint (&symfile_complaints
,
9440 _("Invalid .debug_ranges data "
9441 "(no base address)"));
9447 /* Inverted range entries are invalid. */
9448 complaint (&symfile_complaints
,
9449 _("Invalid .debug_ranges data "
9450 "(inverted range)"));
9454 /* Empty range entries have no effect. */
9458 record_block_range (block
,
9459 baseaddr
+ base
+ start
,
9460 baseaddr
+ base
+ end
- 1);
9466 /* Check whether the producer field indicates either of GCC < 4.6, or the
9467 Intel C/C++ compiler, and cache the result in CU. */
9470 check_producer (struct dwarf2_cu
*cu
)
9473 int major
, minor
, release
;
9475 if (cu
->producer
== NULL
)
9477 /* For unknown compilers expect their behavior is DWARF version
9480 GCC started to support .debug_types sections by -gdwarf-4 since
9481 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9482 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9483 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9484 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9486 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9488 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9490 cs
= &cu
->producer
[strlen ("GNU ")];
9491 while (*cs
&& !isdigit (*cs
))
9493 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9495 /* Not recognized as GCC. */
9498 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9500 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9501 cu
->producer_is_icc
= 1;
9504 /* For other non-GCC compilers, expect their behavior is DWARF version
9508 cu
->checked_producer
= 1;
9511 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9512 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9513 during 4.6.0 experimental. */
9516 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9518 if (!cu
->checked_producer
)
9519 check_producer (cu
);
9521 return cu
->producer_is_gxx_lt_4_6
;
9524 /* Return the default accessibility type if it is not overriden by
9525 DW_AT_accessibility. */
9527 static enum dwarf_access_attribute
9528 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9530 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9532 /* The default DWARF 2 accessibility for members is public, the default
9533 accessibility for inheritance is private. */
9535 if (die
->tag
!= DW_TAG_inheritance
)
9536 return DW_ACCESS_public
;
9538 return DW_ACCESS_private
;
9542 /* DWARF 3+ defines the default accessibility a different way. The same
9543 rules apply now for DW_TAG_inheritance as for the members and it only
9544 depends on the container kind. */
9546 if (die
->parent
->tag
== DW_TAG_class_type
)
9547 return DW_ACCESS_private
;
9549 return DW_ACCESS_public
;
9553 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9554 offset. If the attribute was not found return 0, otherwise return
9555 1. If it was found but could not properly be handled, set *OFFSET
9559 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9562 struct attribute
*attr
;
9564 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9569 /* Note that we do not check for a section offset first here.
9570 This is because DW_AT_data_member_location is new in DWARF 4,
9571 so if we see it, we can assume that a constant form is really
9572 a constant and not a section offset. */
9573 if (attr_form_is_constant (attr
))
9574 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9575 else if (attr_form_is_section_offset (attr
))
9576 dwarf2_complex_location_expr_complaint ();
9577 else if (attr_form_is_block (attr
))
9578 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9580 dwarf2_complex_location_expr_complaint ();
9588 /* Add an aggregate field to the field list. */
9591 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9592 struct dwarf2_cu
*cu
)
9594 struct objfile
*objfile
= cu
->objfile
;
9595 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9596 struct nextfield
*new_field
;
9597 struct attribute
*attr
;
9599 char *fieldname
= "";
9601 /* Allocate a new field list entry and link it in. */
9602 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9603 make_cleanup (xfree
, new_field
);
9604 memset (new_field
, 0, sizeof (struct nextfield
));
9606 if (die
->tag
== DW_TAG_inheritance
)
9608 new_field
->next
= fip
->baseclasses
;
9609 fip
->baseclasses
= new_field
;
9613 new_field
->next
= fip
->fields
;
9614 fip
->fields
= new_field
;
9618 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9620 new_field
->accessibility
= DW_UNSND (attr
);
9622 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9623 if (new_field
->accessibility
!= DW_ACCESS_public
)
9624 fip
->non_public_fields
= 1;
9626 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9628 new_field
->virtuality
= DW_UNSND (attr
);
9630 new_field
->virtuality
= DW_VIRTUALITY_none
;
9632 fp
= &new_field
->field
;
9634 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9638 /* Data member other than a C++ static data member. */
9640 /* Get type of field. */
9641 fp
->type
= die_type (die
, cu
);
9643 SET_FIELD_BITPOS (*fp
, 0);
9645 /* Get bit size of field (zero if none). */
9646 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9649 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9653 FIELD_BITSIZE (*fp
) = 0;
9656 /* Get bit offset of field. */
9657 if (handle_data_member_location (die
, cu
, &offset
))
9658 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9659 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9662 if (gdbarch_bits_big_endian (gdbarch
))
9664 /* For big endian bits, the DW_AT_bit_offset gives the
9665 additional bit offset from the MSB of the containing
9666 anonymous object to the MSB of the field. We don't
9667 have to do anything special since we don't need to
9668 know the size of the anonymous object. */
9669 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9673 /* For little endian bits, compute the bit offset to the
9674 MSB of the anonymous object, subtract off the number of
9675 bits from the MSB of the field to the MSB of the
9676 object, and then subtract off the number of bits of
9677 the field itself. The result is the bit offset of
9678 the LSB of the field. */
9680 int bit_offset
= DW_UNSND (attr
);
9682 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9685 /* The size of the anonymous object containing
9686 the bit field is explicit, so use the
9687 indicated size (in bytes). */
9688 anonymous_size
= DW_UNSND (attr
);
9692 /* The size of the anonymous object containing
9693 the bit field must be inferred from the type
9694 attribute of the data member containing the
9696 anonymous_size
= TYPE_LENGTH (fp
->type
);
9698 SET_FIELD_BITPOS (*fp
,
9700 + anonymous_size
* bits_per_byte
9701 - bit_offset
- FIELD_BITSIZE (*fp
)));
9705 /* Get name of field. */
9706 fieldname
= dwarf2_name (die
, cu
);
9707 if (fieldname
== NULL
)
9710 /* The name is already allocated along with this objfile, so we don't
9711 need to duplicate it for the type. */
9712 fp
->name
= fieldname
;
9714 /* Change accessibility for artificial fields (e.g. virtual table
9715 pointer or virtual base class pointer) to private. */
9716 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9718 FIELD_ARTIFICIAL (*fp
) = 1;
9719 new_field
->accessibility
= DW_ACCESS_private
;
9720 fip
->non_public_fields
= 1;
9723 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9725 /* C++ static member. */
9727 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9728 is a declaration, but all versions of G++ as of this writing
9729 (so through at least 3.2.1) incorrectly generate
9730 DW_TAG_variable tags. */
9732 const char *physname
;
9734 /* Get name of field. */
9735 fieldname
= dwarf2_name (die
, cu
);
9736 if (fieldname
== NULL
)
9739 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9741 /* Only create a symbol if this is an external value.
9742 new_symbol checks this and puts the value in the global symbol
9743 table, which we want. If it is not external, new_symbol
9744 will try to put the value in cu->list_in_scope which is wrong. */
9745 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9747 /* A static const member, not much different than an enum as far as
9748 we're concerned, except that we can support more types. */
9749 new_symbol (die
, NULL
, cu
);
9752 /* Get physical name. */
9753 physname
= dwarf2_physname (fieldname
, die
, cu
);
9755 /* The name is already allocated along with this objfile, so we don't
9756 need to duplicate it for the type. */
9757 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9758 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9759 FIELD_NAME (*fp
) = fieldname
;
9761 else if (die
->tag
== DW_TAG_inheritance
)
9765 /* C++ base class field. */
9766 if (handle_data_member_location (die
, cu
, &offset
))
9767 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9768 FIELD_BITSIZE (*fp
) = 0;
9769 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9770 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9771 fip
->nbaseclasses
++;
9775 /* Add a typedef defined in the scope of the FIP's class. */
9778 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9779 struct dwarf2_cu
*cu
)
9781 struct objfile
*objfile
= cu
->objfile
;
9782 struct typedef_field_list
*new_field
;
9783 struct attribute
*attr
;
9784 struct typedef_field
*fp
;
9785 char *fieldname
= "";
9787 /* Allocate a new field list entry and link it in. */
9788 new_field
= xzalloc (sizeof (*new_field
));
9789 make_cleanup (xfree
, new_field
);
9791 gdb_assert (die
->tag
== DW_TAG_typedef
);
9793 fp
= &new_field
->field
;
9795 /* Get name of field. */
9796 fp
->name
= dwarf2_name (die
, cu
);
9797 if (fp
->name
== NULL
)
9800 fp
->type
= read_type_die (die
, cu
);
9802 new_field
->next
= fip
->typedef_field_list
;
9803 fip
->typedef_field_list
= new_field
;
9804 fip
->typedef_field_list_count
++;
9807 /* Create the vector of fields, and attach it to the type. */
9810 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9811 struct dwarf2_cu
*cu
)
9813 int nfields
= fip
->nfields
;
9815 /* Record the field count, allocate space for the array of fields,
9816 and create blank accessibility bitfields if necessary. */
9817 TYPE_NFIELDS (type
) = nfields
;
9818 TYPE_FIELDS (type
) = (struct field
*)
9819 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9820 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9822 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9824 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9826 TYPE_FIELD_PRIVATE_BITS (type
) =
9827 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9828 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9830 TYPE_FIELD_PROTECTED_BITS (type
) =
9831 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9832 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
9834 TYPE_FIELD_IGNORE_BITS (type
) =
9835 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9836 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
9839 /* If the type has baseclasses, allocate and clear a bit vector for
9840 TYPE_FIELD_VIRTUAL_BITS. */
9841 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9843 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9844 unsigned char *pointer
;
9846 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9847 pointer
= TYPE_ALLOC (type
, num_bytes
);
9848 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9849 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9850 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9853 /* Copy the saved-up fields into the field vector. Start from the head of
9854 the list, adding to the tail of the field array, so that they end up in
9855 the same order in the array in which they were added to the list. */
9856 while (nfields
-- > 0)
9858 struct nextfield
*fieldp
;
9862 fieldp
= fip
->fields
;
9863 fip
->fields
= fieldp
->next
;
9867 fieldp
= fip
->baseclasses
;
9868 fip
->baseclasses
= fieldp
->next
;
9871 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
9872 switch (fieldp
->accessibility
)
9874 case DW_ACCESS_private
:
9875 if (cu
->language
!= language_ada
)
9876 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
9879 case DW_ACCESS_protected
:
9880 if (cu
->language
!= language_ada
)
9881 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
9884 case DW_ACCESS_public
:
9888 /* Unknown accessibility. Complain and treat it as public. */
9890 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
9891 fieldp
->accessibility
);
9895 if (nfields
< fip
->nbaseclasses
)
9897 switch (fieldp
->virtuality
)
9899 case DW_VIRTUALITY_virtual
:
9900 case DW_VIRTUALITY_pure_virtual
:
9901 if (cu
->language
== language_ada
)
9902 error (_("unexpected virtuality in component of Ada type"));
9903 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
9910 /* Add a member function to the proper fieldlist. */
9913 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
9914 struct type
*type
, struct dwarf2_cu
*cu
)
9916 struct objfile
*objfile
= cu
->objfile
;
9917 struct attribute
*attr
;
9918 struct fnfieldlist
*flp
;
9920 struct fn_field
*fnp
;
9922 struct nextfnfield
*new_fnfield
;
9923 struct type
*this_type
;
9924 enum dwarf_access_attribute accessibility
;
9926 if (cu
->language
== language_ada
)
9927 error (_("unexpected member function in Ada type"));
9929 /* Get name of member function. */
9930 fieldname
= dwarf2_name (die
, cu
);
9931 if (fieldname
== NULL
)
9934 /* Look up member function name in fieldlist. */
9935 for (i
= 0; i
< fip
->nfnfields
; i
++)
9937 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
9941 /* Create new list element if necessary. */
9942 if (i
< fip
->nfnfields
)
9943 flp
= &fip
->fnfieldlists
[i
];
9946 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9948 fip
->fnfieldlists
= (struct fnfieldlist
*)
9949 xrealloc (fip
->fnfieldlists
,
9950 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9951 * sizeof (struct fnfieldlist
));
9952 if (fip
->nfnfields
== 0)
9953 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9955 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9956 flp
->name
= fieldname
;
9959 i
= fip
->nfnfields
++;
9962 /* Create a new member function field and chain it to the field list
9964 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9965 make_cleanup (xfree
, new_fnfield
);
9966 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9967 new_fnfield
->next
= flp
->head
;
9968 flp
->head
= new_fnfield
;
9971 /* Fill in the member function field info. */
9972 fnp
= &new_fnfield
->fnfield
;
9974 /* Delay processing of the physname until later. */
9975 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9977 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9982 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9983 fnp
->physname
= physname
? physname
: "";
9986 fnp
->type
= alloc_type (objfile
);
9987 this_type
= read_type_die (die
, cu
);
9988 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9990 int nparams
= TYPE_NFIELDS (this_type
);
9992 /* TYPE is the domain of this method, and THIS_TYPE is the type
9993 of the method itself (TYPE_CODE_METHOD). */
9994 smash_to_method_type (fnp
->type
, type
,
9995 TYPE_TARGET_TYPE (this_type
),
9996 TYPE_FIELDS (this_type
),
9997 TYPE_NFIELDS (this_type
),
9998 TYPE_VARARGS (this_type
));
10000 /* Handle static member functions.
10001 Dwarf2 has no clean way to discern C++ static and non-static
10002 member functions. G++ helps GDB by marking the first
10003 parameter for non-static member functions (which is the this
10004 pointer) as artificial. We obtain this information from
10005 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10006 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10007 fnp
->voffset
= VOFFSET_STATIC
;
10010 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10011 dwarf2_full_name (fieldname
, die
, cu
));
10013 /* Get fcontext from DW_AT_containing_type if present. */
10014 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10015 fnp
->fcontext
= die_containing_type (die
, cu
);
10017 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10018 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10020 /* Get accessibility. */
10021 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10023 accessibility
= DW_UNSND (attr
);
10025 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10026 switch (accessibility
)
10028 case DW_ACCESS_private
:
10029 fnp
->is_private
= 1;
10031 case DW_ACCESS_protected
:
10032 fnp
->is_protected
= 1;
10036 /* Check for artificial methods. */
10037 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10038 if (attr
&& DW_UNSND (attr
) != 0)
10039 fnp
->is_artificial
= 1;
10041 /* Get index in virtual function table if it is a virtual member
10042 function. For older versions of GCC, this is an offset in the
10043 appropriate virtual table, as specified by DW_AT_containing_type.
10044 For everyone else, it is an expression to be evaluated relative
10045 to the object address. */
10047 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10050 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10052 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10054 /* Old-style GCC. */
10055 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10057 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10058 || (DW_BLOCK (attr
)->size
> 1
10059 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10060 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10062 struct dwarf_block blk
;
10065 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10067 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10068 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10069 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10070 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10071 dwarf2_complex_location_expr_complaint ();
10073 fnp
->voffset
/= cu
->header
.addr_size
;
10077 dwarf2_complex_location_expr_complaint ();
10079 if (!fnp
->fcontext
)
10080 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10082 else if (attr_form_is_section_offset (attr
))
10084 dwarf2_complex_location_expr_complaint ();
10088 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10094 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10095 if (attr
&& DW_UNSND (attr
))
10097 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10098 complaint (&symfile_complaints
,
10099 _("Member function \"%s\" (offset %d) is virtual "
10100 "but the vtable offset is not specified"),
10101 fieldname
, die
->offset
.sect_off
);
10102 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10103 TYPE_CPLUS_DYNAMIC (type
) = 1;
10108 /* Create the vector of member function fields, and attach it to the type. */
10111 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10112 struct dwarf2_cu
*cu
)
10114 struct fnfieldlist
*flp
;
10117 if (cu
->language
== language_ada
)
10118 error (_("unexpected member functions in Ada type"));
10120 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10121 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10122 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10124 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10126 struct nextfnfield
*nfp
= flp
->head
;
10127 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10130 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10131 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10132 fn_flp
->fn_fields
= (struct fn_field
*)
10133 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10134 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10135 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10138 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10141 /* Returns non-zero if NAME is the name of a vtable member in CU's
10142 language, zero otherwise. */
10144 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10146 static const char vptr
[] = "_vptr";
10147 static const char vtable
[] = "vtable";
10149 /* Look for the C++ and Java forms of the vtable. */
10150 if ((cu
->language
== language_java
10151 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10152 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10153 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10159 /* GCC outputs unnamed structures that are really pointers to member
10160 functions, with the ABI-specified layout. If TYPE describes
10161 such a structure, smash it into a member function type.
10163 GCC shouldn't do this; it should just output pointer to member DIEs.
10164 This is GCC PR debug/28767. */
10167 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10169 struct type
*pfn_type
, *domain_type
, *new_type
;
10171 /* Check for a structure with no name and two children. */
10172 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10175 /* Check for __pfn and __delta members. */
10176 if (TYPE_FIELD_NAME (type
, 0) == NULL
10177 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10178 || TYPE_FIELD_NAME (type
, 1) == NULL
10179 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10182 /* Find the type of the method. */
10183 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10184 if (pfn_type
== NULL
10185 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10186 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10189 /* Look for the "this" argument. */
10190 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10191 if (TYPE_NFIELDS (pfn_type
) == 0
10192 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10193 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10196 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10197 new_type
= alloc_type (objfile
);
10198 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10199 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10200 TYPE_VARARGS (pfn_type
));
10201 smash_to_methodptr_type (type
, new_type
);
10204 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10208 producer_is_icc (struct dwarf2_cu
*cu
)
10210 if (!cu
->checked_producer
)
10211 check_producer (cu
);
10213 return cu
->producer_is_icc
;
10216 /* Called when we find the DIE that starts a structure or union scope
10217 (definition) to create a type for the structure or union. Fill in
10218 the type's name and general properties; the members will not be
10219 processed until process_structure_type.
10221 NOTE: we need to call these functions regardless of whether or not the
10222 DIE has a DW_AT_name attribute, since it might be an anonymous
10223 structure or union. This gets the type entered into our set of
10224 user defined types.
10226 However, if the structure is incomplete (an opaque struct/union)
10227 then suppress creating a symbol table entry for it since gdb only
10228 wants to find the one with the complete definition. Note that if
10229 it is complete, we just call new_symbol, which does it's own
10230 checking about whether the struct/union is anonymous or not (and
10231 suppresses creating a symbol table entry itself). */
10233 static struct type
*
10234 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10236 struct objfile
*objfile
= cu
->objfile
;
10238 struct attribute
*attr
;
10241 /* If the definition of this type lives in .debug_types, read that type.
10242 Don't follow DW_AT_specification though, that will take us back up
10243 the chain and we want to go down. */
10244 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10247 struct dwarf2_cu
*type_cu
= cu
;
10248 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10250 /* We could just recurse on read_structure_type, but we need to call
10251 get_die_type to ensure only one type for this DIE is created.
10252 This is important, for example, because for c++ classes we need
10253 TYPE_NAME set which is only done by new_symbol. Blech. */
10254 type
= read_type_die (type_die
, type_cu
);
10256 /* TYPE_CU may not be the same as CU.
10257 Ensure TYPE is recorded in CU's type_hash table. */
10258 return set_die_type (die
, type
, cu
);
10261 type
= alloc_type (objfile
);
10262 INIT_CPLUS_SPECIFIC (type
);
10264 name
= dwarf2_name (die
, cu
);
10267 if (cu
->language
== language_cplus
10268 || cu
->language
== language_java
)
10270 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10272 /* dwarf2_full_name might have already finished building the DIE's
10273 type. If so, there is no need to continue. */
10274 if (get_die_type (die
, cu
) != NULL
)
10275 return get_die_type (die
, cu
);
10277 TYPE_TAG_NAME (type
) = full_name
;
10278 if (die
->tag
== DW_TAG_structure_type
10279 || die
->tag
== DW_TAG_class_type
)
10280 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10284 /* The name is already allocated along with this objfile, so
10285 we don't need to duplicate it for the type. */
10286 TYPE_TAG_NAME (type
) = (char *) name
;
10287 if (die
->tag
== DW_TAG_class_type
)
10288 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10292 if (die
->tag
== DW_TAG_structure_type
)
10294 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10296 else if (die
->tag
== DW_TAG_union_type
)
10298 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10302 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10305 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10306 TYPE_DECLARED_CLASS (type
) = 1;
10308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10311 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10315 TYPE_LENGTH (type
) = 0;
10318 if (producer_is_icc (cu
))
10320 /* ICC does not output the required DW_AT_declaration
10321 on incomplete types, but gives them a size of zero. */
10324 TYPE_STUB_SUPPORTED (type
) = 1;
10326 if (die_is_declaration (die
, cu
))
10327 TYPE_STUB (type
) = 1;
10328 else if (attr
== NULL
&& die
->child
== NULL
10329 && producer_is_realview (cu
->producer
))
10330 /* RealView does not output the required DW_AT_declaration
10331 on incomplete types. */
10332 TYPE_STUB (type
) = 1;
10334 /* We need to add the type field to the die immediately so we don't
10335 infinitely recurse when dealing with pointers to the structure
10336 type within the structure itself. */
10337 set_die_type (die
, type
, cu
);
10339 /* set_die_type should be already done. */
10340 set_descriptive_type (type
, die
, cu
);
10345 /* Finish creating a structure or union type, including filling in
10346 its members and creating a symbol for it. */
10349 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10351 struct objfile
*objfile
= cu
->objfile
;
10352 struct die_info
*child_die
= die
->child
;
10355 type
= get_die_type (die
, cu
);
10357 type
= read_structure_type (die
, cu
);
10359 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10361 struct field_info fi
;
10362 struct die_info
*child_die
;
10363 VEC (symbolp
) *template_args
= NULL
;
10364 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10366 memset (&fi
, 0, sizeof (struct field_info
));
10368 child_die
= die
->child
;
10370 while (child_die
&& child_die
->tag
)
10372 if (child_die
->tag
== DW_TAG_member
10373 || child_die
->tag
== DW_TAG_variable
)
10375 /* NOTE: carlton/2002-11-05: A C++ static data member
10376 should be a DW_TAG_member that is a declaration, but
10377 all versions of G++ as of this writing (so through at
10378 least 3.2.1) incorrectly generate DW_TAG_variable
10379 tags for them instead. */
10380 dwarf2_add_field (&fi
, child_die
, cu
);
10382 else if (child_die
->tag
== DW_TAG_subprogram
)
10384 /* C++ member function. */
10385 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10387 else if (child_die
->tag
== DW_TAG_inheritance
)
10389 /* C++ base class field. */
10390 dwarf2_add_field (&fi
, child_die
, cu
);
10392 else if (child_die
->tag
== DW_TAG_typedef
)
10393 dwarf2_add_typedef (&fi
, child_die
, cu
);
10394 else if (child_die
->tag
== DW_TAG_template_type_param
10395 || child_die
->tag
== DW_TAG_template_value_param
)
10397 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10400 VEC_safe_push (symbolp
, template_args
, arg
);
10403 child_die
= sibling_die (child_die
);
10406 /* Attach template arguments to type. */
10407 if (! VEC_empty (symbolp
, template_args
))
10409 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10410 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10411 = VEC_length (symbolp
, template_args
);
10412 TYPE_TEMPLATE_ARGUMENTS (type
)
10413 = obstack_alloc (&objfile
->objfile_obstack
,
10414 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10415 * sizeof (struct symbol
*)));
10416 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10417 VEC_address (symbolp
, template_args
),
10418 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10419 * sizeof (struct symbol
*)));
10420 VEC_free (symbolp
, template_args
);
10423 /* Attach fields and member functions to the type. */
10425 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10428 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10430 /* Get the type which refers to the base class (possibly this
10431 class itself) which contains the vtable pointer for the current
10432 class from the DW_AT_containing_type attribute. This use of
10433 DW_AT_containing_type is a GNU extension. */
10435 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10437 struct type
*t
= die_containing_type (die
, cu
);
10439 TYPE_VPTR_BASETYPE (type
) = t
;
10444 /* Our own class provides vtbl ptr. */
10445 for (i
= TYPE_NFIELDS (t
) - 1;
10446 i
>= TYPE_N_BASECLASSES (t
);
10449 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10451 if (is_vtable_name (fieldname
, cu
))
10453 TYPE_VPTR_FIELDNO (type
) = i
;
10458 /* Complain if virtual function table field not found. */
10459 if (i
< TYPE_N_BASECLASSES (t
))
10460 complaint (&symfile_complaints
,
10461 _("virtual function table pointer "
10462 "not found when defining class '%s'"),
10463 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10468 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10471 else if (cu
->producer
10472 && strncmp (cu
->producer
,
10473 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10475 /* The IBM XLC compiler does not provide direct indication
10476 of the containing type, but the vtable pointer is
10477 always named __vfp. */
10481 for (i
= TYPE_NFIELDS (type
) - 1;
10482 i
>= TYPE_N_BASECLASSES (type
);
10485 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10487 TYPE_VPTR_FIELDNO (type
) = i
;
10488 TYPE_VPTR_BASETYPE (type
) = type
;
10495 /* Copy fi.typedef_field_list linked list elements content into the
10496 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10497 if (fi
.typedef_field_list
)
10499 int i
= fi
.typedef_field_list_count
;
10501 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10502 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10503 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10504 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10506 /* Reverse the list order to keep the debug info elements order. */
10509 struct typedef_field
*dest
, *src
;
10511 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10512 src
= &fi
.typedef_field_list
->field
;
10513 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10518 do_cleanups (back_to
);
10520 if (HAVE_CPLUS_STRUCT (type
))
10521 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10524 quirk_gcc_member_function_pointer (type
, objfile
);
10526 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10527 snapshots) has been known to create a die giving a declaration
10528 for a class that has, as a child, a die giving a definition for a
10529 nested class. So we have to process our children even if the
10530 current die is a declaration. Normally, of course, a declaration
10531 won't have any children at all. */
10533 while (child_die
!= NULL
&& child_die
->tag
)
10535 if (child_die
->tag
== DW_TAG_member
10536 || child_die
->tag
== DW_TAG_variable
10537 || child_die
->tag
== DW_TAG_inheritance
10538 || child_die
->tag
== DW_TAG_template_value_param
10539 || child_die
->tag
== DW_TAG_template_type_param
)
10544 process_die (child_die
, cu
);
10546 child_die
= sibling_die (child_die
);
10549 /* Do not consider external references. According to the DWARF standard,
10550 these DIEs are identified by the fact that they have no byte_size
10551 attribute, and a declaration attribute. */
10552 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10553 || !die_is_declaration (die
, cu
))
10554 new_symbol (die
, type
, cu
);
10557 /* Given a DW_AT_enumeration_type die, set its type. We do not
10558 complete the type's fields yet, or create any symbols. */
10560 static struct type
*
10561 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10563 struct objfile
*objfile
= cu
->objfile
;
10565 struct attribute
*attr
;
10568 /* If the definition of this type lives in .debug_types, read that type.
10569 Don't follow DW_AT_specification though, that will take us back up
10570 the chain and we want to go down. */
10571 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10574 struct dwarf2_cu
*type_cu
= cu
;
10575 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10577 type
= read_type_die (type_die
, type_cu
);
10579 /* TYPE_CU may not be the same as CU.
10580 Ensure TYPE is recorded in CU's type_hash table. */
10581 return set_die_type (die
, type
, cu
);
10584 type
= alloc_type (objfile
);
10586 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10587 name
= dwarf2_full_name (NULL
, die
, cu
);
10589 TYPE_TAG_NAME (type
) = (char *) name
;
10591 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10594 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10598 TYPE_LENGTH (type
) = 0;
10601 /* The enumeration DIE can be incomplete. In Ada, any type can be
10602 declared as private in the package spec, and then defined only
10603 inside the package body. Such types are known as Taft Amendment
10604 Types. When another package uses such a type, an incomplete DIE
10605 may be generated by the compiler. */
10606 if (die_is_declaration (die
, cu
))
10607 TYPE_STUB (type
) = 1;
10609 return set_die_type (die
, type
, cu
);
10612 /* Given a pointer to a die which begins an enumeration, process all
10613 the dies that define the members of the enumeration, and create the
10614 symbol for the enumeration type.
10616 NOTE: We reverse the order of the element list. */
10619 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10621 struct type
*this_type
;
10623 this_type
= get_die_type (die
, cu
);
10624 if (this_type
== NULL
)
10625 this_type
= read_enumeration_type (die
, cu
);
10627 if (die
->child
!= NULL
)
10629 struct die_info
*child_die
;
10630 struct symbol
*sym
;
10631 struct field
*fields
= NULL
;
10632 int num_fields
= 0;
10633 int unsigned_enum
= 1;
10638 child_die
= die
->child
;
10639 while (child_die
&& child_die
->tag
)
10641 if (child_die
->tag
!= DW_TAG_enumerator
)
10643 process_die (child_die
, cu
);
10647 name
= dwarf2_name (child_die
, cu
);
10650 sym
= new_symbol (child_die
, this_type
, cu
);
10651 if (SYMBOL_VALUE (sym
) < 0)
10656 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10659 mask
|= SYMBOL_VALUE (sym
);
10661 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10663 fields
= (struct field
*)
10665 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10666 * sizeof (struct field
));
10669 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10670 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10671 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10672 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10678 child_die
= sibling_die (child_die
);
10683 TYPE_NFIELDS (this_type
) = num_fields
;
10684 TYPE_FIELDS (this_type
) = (struct field
*)
10685 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10686 memcpy (TYPE_FIELDS (this_type
), fields
,
10687 sizeof (struct field
) * num_fields
);
10691 TYPE_UNSIGNED (this_type
) = 1;
10693 TYPE_FLAG_ENUM (this_type
) = 1;
10696 /* If we are reading an enum from a .debug_types unit, and the enum
10697 is a declaration, and the enum is not the signatured type in the
10698 unit, then we do not want to add a symbol for it. Adding a
10699 symbol would in some cases obscure the true definition of the
10700 enum, giving users an incomplete type when the definition is
10701 actually available. Note that we do not want to do this for all
10702 enums which are just declarations, because C++0x allows forward
10703 enum declarations. */
10704 if (cu
->per_cu
->is_debug_types
10705 && die_is_declaration (die
, cu
))
10707 struct signatured_type
*sig_type
;
10710 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10711 cu
->per_cu
->info_or_types_section
,
10712 cu
->per_cu
->offset
);
10713 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10714 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10718 new_symbol (die
, this_type
, cu
);
10721 /* Extract all information from a DW_TAG_array_type DIE and put it in
10722 the DIE's type field. For now, this only handles one dimensional
10725 static struct type
*
10726 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10728 struct objfile
*objfile
= cu
->objfile
;
10729 struct die_info
*child_die
;
10731 struct type
*element_type
, *range_type
, *index_type
;
10732 struct type
**range_types
= NULL
;
10733 struct attribute
*attr
;
10735 struct cleanup
*back_to
;
10738 element_type
= die_type (die
, cu
);
10740 /* The die_type call above may have already set the type for this DIE. */
10741 type
= get_die_type (die
, cu
);
10745 /* Irix 6.2 native cc creates array types without children for
10746 arrays with unspecified length. */
10747 if (die
->child
== NULL
)
10749 index_type
= objfile_type (objfile
)->builtin_int
;
10750 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10751 type
= create_array_type (NULL
, element_type
, range_type
);
10752 return set_die_type (die
, type
, cu
);
10755 back_to
= make_cleanup (null_cleanup
, NULL
);
10756 child_die
= die
->child
;
10757 while (child_die
&& child_die
->tag
)
10759 if (child_die
->tag
== DW_TAG_subrange_type
)
10761 struct type
*child_type
= read_type_die (child_die
, cu
);
10763 if (child_type
!= NULL
)
10765 /* The range type was succesfully read. Save it for the
10766 array type creation. */
10767 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10769 range_types
= (struct type
**)
10770 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10771 * sizeof (struct type
*));
10773 make_cleanup (free_current_contents
, &range_types
);
10775 range_types
[ndim
++] = child_type
;
10778 child_die
= sibling_die (child_die
);
10781 /* Dwarf2 dimensions are output from left to right, create the
10782 necessary array types in backwards order. */
10784 type
= element_type
;
10786 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10791 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10796 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10799 /* Understand Dwarf2 support for vector types (like they occur on
10800 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10801 array type. This is not part of the Dwarf2/3 standard yet, but a
10802 custom vendor extension. The main difference between a regular
10803 array and the vector variant is that vectors are passed by value
10805 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10807 make_vector_type (type
);
10809 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10810 implementation may choose to implement triple vectors using this
10812 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10815 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10816 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10818 complaint (&symfile_complaints
,
10819 _("DW_AT_byte_size for array type smaller "
10820 "than the total size of elements"));
10823 name
= dwarf2_name (die
, cu
);
10825 TYPE_NAME (type
) = name
;
10827 /* Install the type in the die. */
10828 set_die_type (die
, type
, cu
);
10830 /* set_die_type should be already done. */
10831 set_descriptive_type (type
, die
, cu
);
10833 do_cleanups (back_to
);
10838 static enum dwarf_array_dim_ordering
10839 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10841 struct attribute
*attr
;
10843 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10845 if (attr
) return DW_SND (attr
);
10847 /* GNU F77 is a special case, as at 08/2004 array type info is the
10848 opposite order to the dwarf2 specification, but data is still
10849 laid out as per normal fortran.
10851 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10852 version checking. */
10854 if (cu
->language
== language_fortran
10855 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
10857 return DW_ORD_row_major
;
10860 switch (cu
->language_defn
->la_array_ordering
)
10862 case array_column_major
:
10863 return DW_ORD_col_major
;
10864 case array_row_major
:
10866 return DW_ORD_row_major
;
10870 /* Extract all information from a DW_TAG_set_type DIE and put it in
10871 the DIE's type field. */
10873 static struct type
*
10874 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10876 struct type
*domain_type
, *set_type
;
10877 struct attribute
*attr
;
10879 domain_type
= die_type (die
, cu
);
10881 /* The die_type call above may have already set the type for this DIE. */
10882 set_type
= get_die_type (die
, cu
);
10886 set_type
= create_set_type (NULL
, domain_type
);
10888 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10890 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
10892 return set_die_type (die
, set_type
, cu
);
10895 /* First cut: install each common block member as a global variable. */
10898 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
10900 struct die_info
*child_die
;
10901 struct attribute
*attr
;
10902 struct symbol
*sym
;
10903 CORE_ADDR base
= (CORE_ADDR
) 0;
10905 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10908 /* Support the .debug_loc offsets. */
10909 if (attr_form_is_block (attr
))
10911 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
10913 else if (attr_form_is_section_offset (attr
))
10915 dwarf2_complex_location_expr_complaint ();
10919 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10920 "common block member");
10923 if (die
->child
!= NULL
)
10925 child_die
= die
->child
;
10926 while (child_die
&& child_die
->tag
)
10930 sym
= new_symbol (child_die
, NULL
, cu
);
10932 && handle_data_member_location (child_die
, cu
, &offset
))
10934 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
10935 add_symbol_to_list (sym
, &global_symbols
);
10937 child_die
= sibling_die (child_die
);
10942 /* Create a type for a C++ namespace. */
10944 static struct type
*
10945 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10947 struct objfile
*objfile
= cu
->objfile
;
10948 const char *previous_prefix
, *name
;
10952 /* For extensions, reuse the type of the original namespace. */
10953 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10955 struct die_info
*ext_die
;
10956 struct dwarf2_cu
*ext_cu
= cu
;
10958 ext_die
= dwarf2_extension (die
, &ext_cu
);
10959 type
= read_type_die (ext_die
, ext_cu
);
10961 /* EXT_CU may not be the same as CU.
10962 Ensure TYPE is recorded in CU's type_hash table. */
10963 return set_die_type (die
, type
, cu
);
10966 name
= namespace_name (die
, &is_anonymous
, cu
);
10968 /* Now build the name of the current namespace. */
10970 previous_prefix
= determine_prefix (die
, cu
);
10971 if (previous_prefix
[0] != '\0')
10972 name
= typename_concat (&objfile
->objfile_obstack
,
10973 previous_prefix
, name
, 0, cu
);
10975 /* Create the type. */
10976 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10978 TYPE_NAME (type
) = (char *) name
;
10979 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10981 return set_die_type (die
, type
, cu
);
10984 /* Read a C++ namespace. */
10987 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10989 struct objfile
*objfile
= cu
->objfile
;
10992 /* Add a symbol associated to this if we haven't seen the namespace
10993 before. Also, add a using directive if it's an anonymous
10996 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11000 type
= read_type_die (die
, cu
);
11001 new_symbol (die
, type
, cu
);
11003 namespace_name (die
, &is_anonymous
, cu
);
11006 const char *previous_prefix
= determine_prefix (die
, cu
);
11008 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11009 NULL
, NULL
, &objfile
->objfile_obstack
);
11013 if (die
->child
!= NULL
)
11015 struct die_info
*child_die
= die
->child
;
11017 while (child_die
&& child_die
->tag
)
11019 process_die (child_die
, cu
);
11020 child_die
= sibling_die (child_die
);
11025 /* Read a Fortran module as type. This DIE can be only a declaration used for
11026 imported module. Still we need that type as local Fortran "use ... only"
11027 declaration imports depend on the created type in determine_prefix. */
11029 static struct type
*
11030 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11032 struct objfile
*objfile
= cu
->objfile
;
11036 module_name
= dwarf2_name (die
, cu
);
11038 complaint (&symfile_complaints
,
11039 _("DW_TAG_module has no name, offset 0x%x"),
11040 die
->offset
.sect_off
);
11041 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
11043 /* determine_prefix uses TYPE_TAG_NAME. */
11044 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11046 return set_die_type (die
, type
, cu
);
11049 /* Read a Fortran module. */
11052 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
11054 struct die_info
*child_die
= die
->child
;
11056 while (child_die
&& child_die
->tag
)
11058 process_die (child_die
, cu
);
11059 child_die
= sibling_die (child_die
);
11063 /* Return the name of the namespace represented by DIE. Set
11064 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
11067 static const char *
11068 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
11070 struct die_info
*current_die
;
11071 const char *name
= NULL
;
11073 /* Loop through the extensions until we find a name. */
11075 for (current_die
= die
;
11076 current_die
!= NULL
;
11077 current_die
= dwarf2_extension (die
, &cu
))
11079 name
= dwarf2_name (current_die
, cu
);
11084 /* Is it an anonymous namespace? */
11086 *is_anonymous
= (name
== NULL
);
11088 name
= CP_ANONYMOUS_NAMESPACE_STR
;
11093 /* Extract all information from a DW_TAG_pointer_type DIE and add to
11094 the user defined type vector. */
11096 static struct type
*
11097 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11099 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
11100 struct comp_unit_head
*cu_header
= &cu
->header
;
11102 struct attribute
*attr_byte_size
;
11103 struct attribute
*attr_address_class
;
11104 int byte_size
, addr_class
;
11105 struct type
*target_type
;
11107 target_type
= die_type (die
, cu
);
11109 /* The die_type call above may have already set the type for this DIE. */
11110 type
= get_die_type (die
, cu
);
11114 type
= lookup_pointer_type (target_type
);
11116 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11117 if (attr_byte_size
)
11118 byte_size
= DW_UNSND (attr_byte_size
);
11120 byte_size
= cu_header
->addr_size
;
11122 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
11123 if (attr_address_class
)
11124 addr_class
= DW_UNSND (attr_address_class
);
11126 addr_class
= DW_ADDR_none
;
11128 /* If the pointer size or address class is different than the
11129 default, create a type variant marked as such and set the
11130 length accordingly. */
11131 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
11133 if (gdbarch_address_class_type_flags_p (gdbarch
))
11137 type_flags
= gdbarch_address_class_type_flags
11138 (gdbarch
, byte_size
, addr_class
);
11139 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11141 type
= make_type_with_address_space (type
, type_flags
);
11143 else if (TYPE_LENGTH (type
) != byte_size
)
11145 complaint (&symfile_complaints
,
11146 _("invalid pointer size %d"), byte_size
);
11150 /* Should we also complain about unhandled address classes? */
11154 TYPE_LENGTH (type
) = byte_size
;
11155 return set_die_type (die
, type
, cu
);
11158 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11159 the user defined type vector. */
11161 static struct type
*
11162 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11165 struct type
*to_type
;
11166 struct type
*domain
;
11168 to_type
= die_type (die
, cu
);
11169 domain
= die_containing_type (die
, cu
);
11171 /* The calls above may have already set the type for this DIE. */
11172 type
= get_die_type (die
, cu
);
11176 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11177 type
= lookup_methodptr_type (to_type
);
11179 type
= lookup_memberptr_type (to_type
, domain
);
11181 return set_die_type (die
, type
, cu
);
11184 /* Extract all information from a DW_TAG_reference_type DIE and add to
11185 the user defined type vector. */
11187 static struct type
*
11188 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11190 struct comp_unit_head
*cu_header
= &cu
->header
;
11191 struct type
*type
, *target_type
;
11192 struct attribute
*attr
;
11194 target_type
= die_type (die
, cu
);
11196 /* The die_type call above may have already set the type for this DIE. */
11197 type
= get_die_type (die
, cu
);
11201 type
= lookup_reference_type (target_type
);
11202 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11205 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11209 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11211 return set_die_type (die
, type
, cu
);
11214 static struct type
*
11215 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11217 struct type
*base_type
, *cv_type
;
11219 base_type
= die_type (die
, cu
);
11221 /* The die_type call above may have already set the type for this DIE. */
11222 cv_type
= get_die_type (die
, cu
);
11226 /* In case the const qualifier is applied to an array type, the element type
11227 is so qualified, not the array type (section 6.7.3 of C99). */
11228 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11230 struct type
*el_type
, *inner_array
;
11232 base_type
= copy_type (base_type
);
11233 inner_array
= base_type
;
11235 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11237 TYPE_TARGET_TYPE (inner_array
) =
11238 copy_type (TYPE_TARGET_TYPE (inner_array
));
11239 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11242 el_type
= TYPE_TARGET_TYPE (inner_array
);
11243 TYPE_TARGET_TYPE (inner_array
) =
11244 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11246 return set_die_type (die
, base_type
, cu
);
11249 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11250 return set_die_type (die
, cv_type
, cu
);
11253 static struct type
*
11254 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11256 struct type
*base_type
, *cv_type
;
11258 base_type
= die_type (die
, cu
);
11260 /* The die_type call above may have already set the type for this DIE. */
11261 cv_type
= get_die_type (die
, cu
);
11265 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11266 return set_die_type (die
, cv_type
, cu
);
11269 /* Extract all information from a DW_TAG_string_type DIE and add to
11270 the user defined type vector. It isn't really a user defined type,
11271 but it behaves like one, with other DIE's using an AT_user_def_type
11272 attribute to reference it. */
11274 static struct type
*
11275 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11277 struct objfile
*objfile
= cu
->objfile
;
11278 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11279 struct type
*type
, *range_type
, *index_type
, *char_type
;
11280 struct attribute
*attr
;
11281 unsigned int length
;
11283 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11286 length
= DW_UNSND (attr
);
11290 /* Check for the DW_AT_byte_size attribute. */
11291 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11294 length
= DW_UNSND (attr
);
11302 index_type
= objfile_type (objfile
)->builtin_int
;
11303 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11304 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11305 type
= create_string_type (NULL
, char_type
, range_type
);
11307 return set_die_type (die
, type
, cu
);
11310 /* Handle DIES due to C code like:
11314 int (*funcp)(int a, long l);
11318 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11320 static struct type
*
11321 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11323 struct objfile
*objfile
= cu
->objfile
;
11324 struct type
*type
; /* Type that this function returns. */
11325 struct type
*ftype
; /* Function that returns above type. */
11326 struct attribute
*attr
;
11328 type
= die_type (die
, cu
);
11330 /* The die_type call above may have already set the type for this DIE. */
11331 ftype
= get_die_type (die
, cu
);
11335 ftype
= lookup_function_type (type
);
11337 /* All functions in C++, Pascal and Java have prototypes. */
11338 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11339 if ((attr
&& (DW_UNSND (attr
) != 0))
11340 || cu
->language
== language_cplus
11341 || cu
->language
== language_java
11342 || cu
->language
== language_pascal
)
11343 TYPE_PROTOTYPED (ftype
) = 1;
11344 else if (producer_is_realview (cu
->producer
))
11345 /* RealView does not emit DW_AT_prototyped. We can not
11346 distinguish prototyped and unprototyped functions; default to
11347 prototyped, since that is more common in modern code (and
11348 RealView warns about unprototyped functions). */
11349 TYPE_PROTOTYPED (ftype
) = 1;
11351 /* Store the calling convention in the type if it's available in
11352 the subroutine die. Otherwise set the calling convention to
11353 the default value DW_CC_normal. */
11354 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11356 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11357 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11358 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11360 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11362 /* We need to add the subroutine type to the die immediately so
11363 we don't infinitely recurse when dealing with parameters
11364 declared as the same subroutine type. */
11365 set_die_type (die
, ftype
, cu
);
11367 if (die
->child
!= NULL
)
11369 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11370 struct die_info
*child_die
;
11371 int nparams
, iparams
;
11373 /* Count the number of parameters.
11374 FIXME: GDB currently ignores vararg functions, but knows about
11375 vararg member functions. */
11377 child_die
= die
->child
;
11378 while (child_die
&& child_die
->tag
)
11380 if (child_die
->tag
== DW_TAG_formal_parameter
)
11382 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11383 TYPE_VARARGS (ftype
) = 1;
11384 child_die
= sibling_die (child_die
);
11387 /* Allocate storage for parameters and fill them in. */
11388 TYPE_NFIELDS (ftype
) = nparams
;
11389 TYPE_FIELDS (ftype
) = (struct field
*)
11390 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11392 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11393 even if we error out during the parameters reading below. */
11394 for (iparams
= 0; iparams
< nparams
; iparams
++)
11395 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11398 child_die
= die
->child
;
11399 while (child_die
&& child_die
->tag
)
11401 if (child_die
->tag
== DW_TAG_formal_parameter
)
11403 struct type
*arg_type
;
11405 /* DWARF version 2 has no clean way to discern C++
11406 static and non-static member functions. G++ helps
11407 GDB by marking the first parameter for non-static
11408 member functions (which is the this pointer) as
11409 artificial. We pass this information to
11410 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11412 DWARF version 3 added DW_AT_object_pointer, which GCC
11413 4.5 does not yet generate. */
11414 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11416 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11419 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11421 /* GCC/43521: In java, the formal parameter
11422 "this" is sometimes not marked with DW_AT_artificial. */
11423 if (cu
->language
== language_java
)
11425 const char *name
= dwarf2_name (child_die
, cu
);
11427 if (name
&& !strcmp (name
, "this"))
11428 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11431 arg_type
= die_type (child_die
, cu
);
11433 /* RealView does not mark THIS as const, which the testsuite
11434 expects. GCC marks THIS as const in method definitions,
11435 but not in the class specifications (GCC PR 43053). */
11436 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11437 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11440 struct dwarf2_cu
*arg_cu
= cu
;
11441 const char *name
= dwarf2_name (child_die
, cu
);
11443 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11446 /* If the compiler emits this, use it. */
11447 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11450 else if (name
&& strcmp (name
, "this") == 0)
11451 /* Function definitions will have the argument names. */
11453 else if (name
== NULL
&& iparams
== 0)
11454 /* Declarations may not have the names, so like
11455 elsewhere in GDB, assume an artificial first
11456 argument is "this". */
11460 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11464 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11467 child_die
= sibling_die (child_die
);
11474 static struct type
*
11475 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11477 struct objfile
*objfile
= cu
->objfile
;
11478 const char *name
= NULL
;
11479 struct type
*this_type
, *target_type
;
11481 name
= dwarf2_full_name (NULL
, die
, cu
);
11482 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11483 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11484 TYPE_NAME (this_type
) = (char *) name
;
11485 set_die_type (die
, this_type
, cu
);
11486 target_type
= die_type (die
, cu
);
11487 if (target_type
!= this_type
)
11488 TYPE_TARGET_TYPE (this_type
) = target_type
;
11491 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11492 spec and cause infinite loops in GDB. */
11493 complaint (&symfile_complaints
,
11494 _("Self-referential DW_TAG_typedef "
11495 "- DIE at 0x%x [in module %s]"),
11496 die
->offset
.sect_off
, objfile
->name
);
11497 TYPE_TARGET_TYPE (this_type
) = NULL
;
11502 /* Find a representation of a given base type and install
11503 it in the TYPE field of the die. */
11505 static struct type
*
11506 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11508 struct objfile
*objfile
= cu
->objfile
;
11510 struct attribute
*attr
;
11511 int encoding
= 0, size
= 0;
11513 enum type_code code
= TYPE_CODE_INT
;
11514 int type_flags
= 0;
11515 struct type
*target_type
= NULL
;
11517 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11520 encoding
= DW_UNSND (attr
);
11522 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11525 size
= DW_UNSND (attr
);
11527 name
= dwarf2_name (die
, cu
);
11530 complaint (&symfile_complaints
,
11531 _("DW_AT_name missing from DW_TAG_base_type"));
11536 case DW_ATE_address
:
11537 /* Turn DW_ATE_address into a void * pointer. */
11538 code
= TYPE_CODE_PTR
;
11539 type_flags
|= TYPE_FLAG_UNSIGNED
;
11540 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11542 case DW_ATE_boolean
:
11543 code
= TYPE_CODE_BOOL
;
11544 type_flags
|= TYPE_FLAG_UNSIGNED
;
11546 case DW_ATE_complex_float
:
11547 code
= TYPE_CODE_COMPLEX
;
11548 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11550 case DW_ATE_decimal_float
:
11551 code
= TYPE_CODE_DECFLOAT
;
11554 code
= TYPE_CODE_FLT
;
11556 case DW_ATE_signed
:
11558 case DW_ATE_unsigned
:
11559 type_flags
|= TYPE_FLAG_UNSIGNED
;
11560 if (cu
->language
== language_fortran
11562 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11563 code
= TYPE_CODE_CHAR
;
11565 case DW_ATE_signed_char
:
11566 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11567 || cu
->language
== language_pascal
11568 || cu
->language
== language_fortran
)
11569 code
= TYPE_CODE_CHAR
;
11571 case DW_ATE_unsigned_char
:
11572 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11573 || cu
->language
== language_pascal
11574 || cu
->language
== language_fortran
)
11575 code
= TYPE_CODE_CHAR
;
11576 type_flags
|= TYPE_FLAG_UNSIGNED
;
11579 /* We just treat this as an integer and then recognize the
11580 type by name elsewhere. */
11584 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11585 dwarf_type_encoding_name (encoding
));
11589 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11590 TYPE_NAME (type
) = name
;
11591 TYPE_TARGET_TYPE (type
) = target_type
;
11593 if (name
&& strcmp (name
, "char") == 0)
11594 TYPE_NOSIGN (type
) = 1;
11596 return set_die_type (die
, type
, cu
);
11599 /* Read the given DW_AT_subrange DIE. */
11601 static struct type
*
11602 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11604 struct type
*base_type
;
11605 struct type
*range_type
;
11606 struct attribute
*attr
;
11608 int low_default_is_valid
;
11610 LONGEST negative_mask
;
11612 base_type
= die_type (die
, cu
);
11613 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11614 check_typedef (base_type
);
11616 /* The die_type call above may have already set the type for this DIE. */
11617 range_type
= get_die_type (die
, cu
);
11621 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11622 omitting DW_AT_lower_bound. */
11623 switch (cu
->language
)
11626 case language_cplus
:
11628 low_default_is_valid
= 1;
11630 case language_fortran
:
11632 low_default_is_valid
= 1;
11635 case language_java
:
11636 case language_objc
:
11638 low_default_is_valid
= (cu
->header
.version
>= 4);
11642 case language_pascal
:
11644 low_default_is_valid
= (cu
->header
.version
>= 4);
11648 low_default_is_valid
= 0;
11652 /* FIXME: For variable sized arrays either of these could be
11653 a variable rather than a constant value. We'll allow it,
11654 but we don't know how to handle it. */
11655 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11657 low
= dwarf2_get_attr_constant_value (attr
, low
);
11658 else if (!low_default_is_valid
)
11659 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11660 "- DIE at 0x%x [in module %s]"),
11661 die
->offset
.sect_off
, cu
->objfile
->name
);
11663 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11666 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11668 /* GCC encodes arrays with unspecified or dynamic length
11669 with a DW_FORM_block1 attribute or a reference attribute.
11670 FIXME: GDB does not yet know how to handle dynamic
11671 arrays properly, treat them as arrays with unspecified
11674 FIXME: jimb/2003-09-22: GDB does not really know
11675 how to handle arrays of unspecified length
11676 either; we just represent them as zero-length
11677 arrays. Choose an appropriate upper bound given
11678 the lower bound we've computed above. */
11682 high
= dwarf2_get_attr_constant_value (attr
, 1);
11686 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11689 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11690 high
= low
+ count
- 1;
11694 /* Unspecified array length. */
11699 /* Dwarf-2 specifications explicitly allows to create subrange types
11700 without specifying a base type.
11701 In that case, the base type must be set to the type of
11702 the lower bound, upper bound or count, in that order, if any of these
11703 three attributes references an object that has a type.
11704 If no base type is found, the Dwarf-2 specifications say that
11705 a signed integer type of size equal to the size of an address should
11707 For the following C code: `extern char gdb_int [];'
11708 GCC produces an empty range DIE.
11709 FIXME: muller/2010-05-28: Possible references to object for low bound,
11710 high bound or count are not yet handled by this code. */
11711 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11713 struct objfile
*objfile
= cu
->objfile
;
11714 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11715 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11716 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11718 /* Test "int", "long int", and "long long int" objfile types,
11719 and select the first one having a size above or equal to the
11720 architecture address size. */
11721 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11722 base_type
= int_type
;
11725 int_type
= objfile_type (objfile
)->builtin_long
;
11726 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11727 base_type
= int_type
;
11730 int_type
= objfile_type (objfile
)->builtin_long_long
;
11731 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11732 base_type
= int_type
;
11738 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11739 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11740 low
|= negative_mask
;
11741 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11742 high
|= negative_mask
;
11744 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11746 /* Mark arrays with dynamic length at least as an array of unspecified
11747 length. GDB could check the boundary but before it gets implemented at
11748 least allow accessing the array elements. */
11749 if (attr
&& attr_form_is_block (attr
))
11750 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11752 /* Ada expects an empty array on no boundary attributes. */
11753 if (attr
== NULL
&& cu
->language
!= language_ada
)
11754 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11756 name
= dwarf2_name (die
, cu
);
11758 TYPE_NAME (range_type
) = name
;
11760 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11762 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11764 set_die_type (die
, range_type
, cu
);
11766 /* set_die_type should be already done. */
11767 set_descriptive_type (range_type
, die
, cu
);
11772 static struct type
*
11773 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11777 /* For now, we only support the C meaning of an unspecified type: void. */
11779 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11780 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11782 return set_die_type (die
, type
, cu
);
11785 /* Read a single die and all its descendents. Set the die's sibling
11786 field to NULL; set other fields in the die correctly, and set all
11787 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11788 location of the info_ptr after reading all of those dies. PARENT
11789 is the parent of the die in question. */
11791 static struct die_info
*
11792 read_die_and_children (const struct die_reader_specs
*reader
,
11793 gdb_byte
*info_ptr
,
11794 gdb_byte
**new_info_ptr
,
11795 struct die_info
*parent
)
11797 struct die_info
*die
;
11801 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11804 *new_info_ptr
= cur_ptr
;
11807 store_in_ref_table (die
, reader
->cu
);
11810 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11814 *new_info_ptr
= cur_ptr
;
11817 die
->sibling
= NULL
;
11818 die
->parent
= parent
;
11822 /* Read a die, all of its descendents, and all of its siblings; set
11823 all of the fields of all of the dies correctly. Arguments are as
11824 in read_die_and_children. */
11826 static struct die_info
*
11827 read_die_and_siblings (const struct die_reader_specs
*reader
,
11828 gdb_byte
*info_ptr
,
11829 gdb_byte
**new_info_ptr
,
11830 struct die_info
*parent
)
11832 struct die_info
*first_die
, *last_sibling
;
11835 cur_ptr
= info_ptr
;
11836 first_die
= last_sibling
= NULL
;
11840 struct die_info
*die
11841 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11845 *new_info_ptr
= cur_ptr
;
11852 last_sibling
->sibling
= die
;
11854 last_sibling
= die
;
11858 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
11860 The caller is responsible for filling in the extra attributes
11861 and updating (*DIEP)->num_attrs.
11862 Set DIEP to point to a newly allocated die with its information,
11863 except for its child, sibling, and parent fields.
11864 Set HAS_CHILDREN to tell whether the die has children or not. */
11867 read_full_die_1 (const struct die_reader_specs
*reader
,
11868 struct die_info
**diep
, gdb_byte
*info_ptr
,
11869 int *has_children
, int num_extra_attrs
)
11871 unsigned int abbrev_number
, bytes_read
, i
;
11872 sect_offset offset
;
11873 struct abbrev_info
*abbrev
;
11874 struct die_info
*die
;
11875 struct dwarf2_cu
*cu
= reader
->cu
;
11876 bfd
*abfd
= reader
->abfd
;
11878 offset
.sect_off
= info_ptr
- reader
->buffer
;
11879 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11880 info_ptr
+= bytes_read
;
11881 if (!abbrev_number
)
11888 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
11890 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
11892 bfd_get_filename (abfd
));
11894 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
11895 die
->offset
= offset
;
11896 die
->tag
= abbrev
->tag
;
11897 die
->abbrev
= abbrev_number
;
11899 /* Make the result usable.
11900 The caller needs to update num_attrs after adding the extra
11902 die
->num_attrs
= abbrev
->num_attrs
;
11904 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11905 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
11909 *has_children
= abbrev
->has_children
;
11913 /* Read a die and all its attributes.
11914 Set DIEP to point to a newly allocated die with its information,
11915 except for its child, sibling, and parent fields.
11916 Set HAS_CHILDREN to tell whether the die has children or not. */
11919 read_full_die (const struct die_reader_specs
*reader
,
11920 struct die_info
**diep
, gdb_byte
*info_ptr
,
11923 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
11926 /* Abbreviation tables.
11928 In DWARF version 2, the description of the debugging information is
11929 stored in a separate .debug_abbrev section. Before we read any
11930 dies from a section we read in all abbreviations and install them
11931 in a hash table. */
11933 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
11935 static struct abbrev_info
*
11936 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
11938 struct abbrev_info
*abbrev
;
11940 abbrev
= (struct abbrev_info
*)
11941 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
11942 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11946 /* Add an abbreviation to the table. */
11949 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11950 unsigned int abbrev_number
,
11951 struct abbrev_info
*abbrev
)
11953 unsigned int hash_number
;
11955 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11956 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11957 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11960 /* Look up an abbrev in the table.
11961 Returns NULL if the abbrev is not found. */
11963 static struct abbrev_info
*
11964 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11965 unsigned int abbrev_number
)
11967 unsigned int hash_number
;
11968 struct abbrev_info
*abbrev
;
11970 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11971 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11975 if (abbrev
->number
== abbrev_number
)
11977 abbrev
= abbrev
->next
;
11982 /* Read in an abbrev table. */
11984 static struct abbrev_table
*
11985 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11986 sect_offset offset
)
11988 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11989 bfd
*abfd
= section
->asection
->owner
;
11990 struct abbrev_table
*abbrev_table
;
11991 gdb_byte
*abbrev_ptr
;
11992 struct abbrev_info
*cur_abbrev
;
11993 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11994 unsigned int abbrev_form
;
11995 struct attr_abbrev
*cur_attrs
;
11996 unsigned int allocated_attrs
;
11998 abbrev_table
= XMALLOC (struct abbrev_table
);
11999 abbrev_table
->offset
= offset
;
12000 obstack_init (&abbrev_table
->abbrev_obstack
);
12001 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12003 * sizeof (struct abbrev_info
*)));
12004 memset (abbrev_table
->abbrevs
, 0,
12005 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12007 dwarf2_read_section (objfile
, section
);
12008 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12009 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12010 abbrev_ptr
+= bytes_read
;
12012 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12013 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12015 /* Loop until we reach an abbrev number of 0. */
12016 while (abbrev_number
)
12018 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
12020 /* read in abbrev header */
12021 cur_abbrev
->number
= abbrev_number
;
12022 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12023 abbrev_ptr
+= bytes_read
;
12024 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
12027 /* now read in declarations */
12028 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12029 abbrev_ptr
+= bytes_read
;
12030 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12031 abbrev_ptr
+= bytes_read
;
12032 while (abbrev_name
)
12034 if (cur_abbrev
->num_attrs
== allocated_attrs
)
12036 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
12038 = xrealloc (cur_attrs
, (allocated_attrs
12039 * sizeof (struct attr_abbrev
)));
12042 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
12043 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
12044 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12045 abbrev_ptr
+= bytes_read
;
12046 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12047 abbrev_ptr
+= bytes_read
;
12050 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12051 (cur_abbrev
->num_attrs
12052 * sizeof (struct attr_abbrev
)));
12053 memcpy (cur_abbrev
->attrs
, cur_attrs
,
12054 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
12056 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
12058 /* Get next abbreviation.
12059 Under Irix6 the abbreviations for a compilation unit are not
12060 always properly terminated with an abbrev number of 0.
12061 Exit loop if we encounter an abbreviation which we have
12062 already read (which means we are about to read the abbreviations
12063 for the next compile unit) or if the end of the abbreviation
12064 table is reached. */
12065 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
12067 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12068 abbrev_ptr
+= bytes_read
;
12069 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
12074 return abbrev_table
;
12077 /* Free the resources held by ABBREV_TABLE. */
12080 abbrev_table_free (struct abbrev_table
*abbrev_table
)
12082 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
12083 xfree (abbrev_table
);
12086 /* Same as abbrev_table_free but as a cleanup.
12087 We pass in a pointer to the pointer to the table so that we can
12088 set the pointer to NULL when we're done. It also simplifies
12089 build_type_unit_groups. */
12092 abbrev_table_free_cleanup (void *table_ptr
)
12094 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
12096 if (*abbrev_table_ptr
!= NULL
)
12097 abbrev_table_free (*abbrev_table_ptr
);
12098 *abbrev_table_ptr
= NULL
;
12101 /* Read the abbrev table for CU from ABBREV_SECTION. */
12104 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
12105 struct dwarf2_section_info
*abbrev_section
)
12108 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
12111 /* Release the memory used by the abbrev table for a compilation unit. */
12114 dwarf2_free_abbrev_table (void *ptr_to_cu
)
12116 struct dwarf2_cu
*cu
= ptr_to_cu
;
12118 abbrev_table_free (cu
->abbrev_table
);
12119 /* Set this to NULL so that we SEGV if we try to read it later,
12120 and also because free_comp_unit verifies this is NULL. */
12121 cu
->abbrev_table
= NULL
;
12124 /* Returns nonzero if TAG represents a type that we might generate a partial
12128 is_type_tag_for_partial (int tag
)
12133 /* Some types that would be reasonable to generate partial symbols for,
12134 that we don't at present. */
12135 case DW_TAG_array_type
:
12136 case DW_TAG_file_type
:
12137 case DW_TAG_ptr_to_member_type
:
12138 case DW_TAG_set_type
:
12139 case DW_TAG_string_type
:
12140 case DW_TAG_subroutine_type
:
12142 case DW_TAG_base_type
:
12143 case DW_TAG_class_type
:
12144 case DW_TAG_interface_type
:
12145 case DW_TAG_enumeration_type
:
12146 case DW_TAG_structure_type
:
12147 case DW_TAG_subrange_type
:
12148 case DW_TAG_typedef
:
12149 case DW_TAG_union_type
:
12156 /* Load all DIEs that are interesting for partial symbols into memory. */
12158 static struct partial_die_info
*
12159 load_partial_dies (const struct die_reader_specs
*reader
,
12160 gdb_byte
*info_ptr
, int building_psymtab
)
12162 struct dwarf2_cu
*cu
= reader
->cu
;
12163 struct objfile
*objfile
= cu
->objfile
;
12164 struct partial_die_info
*part_die
;
12165 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12166 struct abbrev_info
*abbrev
;
12167 unsigned int bytes_read
;
12168 unsigned int load_all
= 0;
12169 int nesting_level
= 1;
12174 gdb_assert (cu
->per_cu
!= NULL
);
12175 if (cu
->per_cu
->load_all_dies
)
12179 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12183 &cu
->comp_unit_obstack
,
12184 hashtab_obstack_allocate
,
12185 dummy_obstack_deallocate
);
12187 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12188 sizeof (struct partial_die_info
));
12192 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12194 /* A NULL abbrev means the end of a series of children. */
12195 if (abbrev
== NULL
)
12197 if (--nesting_level
== 0)
12199 /* PART_DIE was probably the last thing allocated on the
12200 comp_unit_obstack, so we could call obstack_free
12201 here. We don't do that because the waste is small,
12202 and will be cleaned up when we're done with this
12203 compilation unit. This way, we're also more robust
12204 against other users of the comp_unit_obstack. */
12207 info_ptr
+= bytes_read
;
12208 last_die
= parent_die
;
12209 parent_die
= parent_die
->die_parent
;
12213 /* Check for template arguments. We never save these; if
12214 they're seen, we just mark the parent, and go on our way. */
12215 if (parent_die
!= NULL
12216 && cu
->language
== language_cplus
12217 && (abbrev
->tag
== DW_TAG_template_type_param
12218 || abbrev
->tag
== DW_TAG_template_value_param
))
12220 parent_die
->has_template_arguments
= 1;
12224 /* We don't need a partial DIE for the template argument. */
12225 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12230 /* We only recurse into c++ subprograms looking for template arguments.
12231 Skip their other children. */
12233 && cu
->language
== language_cplus
12234 && parent_die
!= NULL
12235 && parent_die
->tag
== DW_TAG_subprogram
)
12237 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12241 /* Check whether this DIE is interesting enough to save. Normally
12242 we would not be interested in members here, but there may be
12243 later variables referencing them via DW_AT_specification (for
12244 static members). */
12246 && !is_type_tag_for_partial (abbrev
->tag
)
12247 && abbrev
->tag
!= DW_TAG_constant
12248 && abbrev
->tag
!= DW_TAG_enumerator
12249 && abbrev
->tag
!= DW_TAG_subprogram
12250 && abbrev
->tag
!= DW_TAG_lexical_block
12251 && abbrev
->tag
!= DW_TAG_variable
12252 && abbrev
->tag
!= DW_TAG_namespace
12253 && abbrev
->tag
!= DW_TAG_module
12254 && abbrev
->tag
!= DW_TAG_member
12255 && abbrev
->tag
!= DW_TAG_imported_unit
)
12257 /* Otherwise we skip to the next sibling, if any. */
12258 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12262 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12265 /* This two-pass algorithm for processing partial symbols has a
12266 high cost in cache pressure. Thus, handle some simple cases
12267 here which cover the majority of C partial symbols. DIEs
12268 which neither have specification tags in them, nor could have
12269 specification tags elsewhere pointing at them, can simply be
12270 processed and discarded.
12272 This segment is also optional; scan_partial_symbols and
12273 add_partial_symbol will handle these DIEs if we chain
12274 them in normally. When compilers which do not emit large
12275 quantities of duplicate debug information are more common,
12276 this code can probably be removed. */
12278 /* Any complete simple types at the top level (pretty much all
12279 of them, for a language without namespaces), can be processed
12281 if (parent_die
== NULL
12282 && part_die
->has_specification
== 0
12283 && part_die
->is_declaration
== 0
12284 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12285 || part_die
->tag
== DW_TAG_base_type
12286 || part_die
->tag
== DW_TAG_subrange_type
))
12288 if (building_psymtab
&& part_die
->name
!= NULL
)
12289 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12290 VAR_DOMAIN
, LOC_TYPEDEF
,
12291 &objfile
->static_psymbols
,
12292 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12293 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12297 /* The exception for DW_TAG_typedef with has_children above is
12298 a workaround of GCC PR debug/47510. In the case of this complaint
12299 type_name_no_tag_or_error will error on such types later.
12301 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12302 it could not find the child DIEs referenced later, this is checked
12303 above. In correct DWARF DW_TAG_typedef should have no children. */
12305 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12306 complaint (&symfile_complaints
,
12307 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12308 "- DIE at 0x%x [in module %s]"),
12309 part_die
->offset
.sect_off
, objfile
->name
);
12311 /* If we're at the second level, and we're an enumerator, and
12312 our parent has no specification (meaning possibly lives in a
12313 namespace elsewhere), then we can add the partial symbol now
12314 instead of queueing it. */
12315 if (part_die
->tag
== DW_TAG_enumerator
12316 && parent_die
!= NULL
12317 && parent_die
->die_parent
== NULL
12318 && parent_die
->tag
== DW_TAG_enumeration_type
12319 && parent_die
->has_specification
== 0)
12321 if (part_die
->name
== NULL
)
12322 complaint (&symfile_complaints
,
12323 _("malformed enumerator DIE ignored"));
12324 else if (building_psymtab
)
12325 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12326 VAR_DOMAIN
, LOC_CONST
,
12327 (cu
->language
== language_cplus
12328 || cu
->language
== language_java
)
12329 ? &objfile
->global_psymbols
12330 : &objfile
->static_psymbols
,
12331 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12333 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12337 /* We'll save this DIE so link it in. */
12338 part_die
->die_parent
= parent_die
;
12339 part_die
->die_sibling
= NULL
;
12340 part_die
->die_child
= NULL
;
12342 if (last_die
&& last_die
== parent_die
)
12343 last_die
->die_child
= part_die
;
12345 last_die
->die_sibling
= part_die
;
12347 last_die
= part_die
;
12349 if (first_die
== NULL
)
12350 first_die
= part_die
;
12352 /* Maybe add the DIE to the hash table. Not all DIEs that we
12353 find interesting need to be in the hash table, because we
12354 also have the parent/sibling/child chains; only those that we
12355 might refer to by offset later during partial symbol reading.
12357 For now this means things that might have be the target of a
12358 DW_AT_specification, DW_AT_abstract_origin, or
12359 DW_AT_extension. DW_AT_extension will refer only to
12360 namespaces; DW_AT_abstract_origin refers to functions (and
12361 many things under the function DIE, but we do not recurse
12362 into function DIEs during partial symbol reading) and
12363 possibly variables as well; DW_AT_specification refers to
12364 declarations. Declarations ought to have the DW_AT_declaration
12365 flag. It happens that GCC forgets to put it in sometimes, but
12366 only for functions, not for types.
12368 Adding more things than necessary to the hash table is harmless
12369 except for the performance cost. Adding too few will result in
12370 wasted time in find_partial_die, when we reread the compilation
12371 unit with load_all_dies set. */
12374 || abbrev
->tag
== DW_TAG_constant
12375 || abbrev
->tag
== DW_TAG_subprogram
12376 || abbrev
->tag
== DW_TAG_variable
12377 || abbrev
->tag
== DW_TAG_namespace
12378 || part_die
->is_declaration
)
12382 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12383 part_die
->offset
.sect_off
, INSERT
);
12387 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12388 sizeof (struct partial_die_info
));
12390 /* For some DIEs we want to follow their children (if any). For C
12391 we have no reason to follow the children of structures; for other
12392 languages we have to, so that we can get at method physnames
12393 to infer fully qualified class names, for DW_AT_specification,
12394 and for C++ template arguments. For C++, we also look one level
12395 inside functions to find template arguments (if the name of the
12396 function does not already contain the template arguments).
12398 For Ada, we need to scan the children of subprograms and lexical
12399 blocks as well because Ada allows the definition of nested
12400 entities that could be interesting for the debugger, such as
12401 nested subprograms for instance. */
12402 if (last_die
->has_children
12404 || last_die
->tag
== DW_TAG_namespace
12405 || last_die
->tag
== DW_TAG_module
12406 || last_die
->tag
== DW_TAG_enumeration_type
12407 || (cu
->language
== language_cplus
12408 && last_die
->tag
== DW_TAG_subprogram
12409 && (last_die
->name
== NULL
12410 || strchr (last_die
->name
, '<') == NULL
))
12411 || (cu
->language
!= language_c
12412 && (last_die
->tag
== DW_TAG_class_type
12413 || last_die
->tag
== DW_TAG_interface_type
12414 || last_die
->tag
== DW_TAG_structure_type
12415 || last_die
->tag
== DW_TAG_union_type
))
12416 || (cu
->language
== language_ada
12417 && (last_die
->tag
== DW_TAG_subprogram
12418 || last_die
->tag
== DW_TAG_lexical_block
))))
12421 parent_die
= last_die
;
12425 /* Otherwise we skip to the next sibling, if any. */
12426 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12428 /* Back to the top, do it again. */
12432 /* Read a minimal amount of information into the minimal die structure. */
12435 read_partial_die (const struct die_reader_specs
*reader
,
12436 struct partial_die_info
*part_die
,
12437 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12438 gdb_byte
*info_ptr
)
12440 struct dwarf2_cu
*cu
= reader
->cu
;
12441 struct objfile
*objfile
= cu
->objfile
;
12442 gdb_byte
*buffer
= reader
->buffer
;
12444 struct attribute attr
;
12445 int has_low_pc_attr
= 0;
12446 int has_high_pc_attr
= 0;
12447 int high_pc_relative
= 0;
12449 memset (part_die
, 0, sizeof (struct partial_die_info
));
12451 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12453 info_ptr
+= abbrev_len
;
12455 if (abbrev
== NULL
)
12458 part_die
->tag
= abbrev
->tag
;
12459 part_die
->has_children
= abbrev
->has_children
;
12461 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12463 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12465 /* Store the data if it is of an attribute we want to keep in a
12466 partial symbol table. */
12470 switch (part_die
->tag
)
12472 case DW_TAG_compile_unit
:
12473 case DW_TAG_partial_unit
:
12474 case DW_TAG_type_unit
:
12475 /* Compilation units have a DW_AT_name that is a filename, not
12476 a source language identifier. */
12477 case DW_TAG_enumeration_type
:
12478 case DW_TAG_enumerator
:
12479 /* These tags always have simple identifiers already; no need
12480 to canonicalize them. */
12481 part_die
->name
= DW_STRING (&attr
);
12485 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12486 &objfile
->objfile_obstack
);
12490 case DW_AT_linkage_name
:
12491 case DW_AT_MIPS_linkage_name
:
12492 /* Note that both forms of linkage name might appear. We
12493 assume they will be the same, and we only store the last
12495 if (cu
->language
== language_ada
)
12496 part_die
->name
= DW_STRING (&attr
);
12497 part_die
->linkage_name
= DW_STRING (&attr
);
12500 has_low_pc_attr
= 1;
12501 part_die
->lowpc
= DW_ADDR (&attr
);
12503 case DW_AT_high_pc
:
12504 has_high_pc_attr
= 1;
12505 if (attr
.form
== DW_FORM_addr
12506 || attr
.form
== DW_FORM_GNU_addr_index
)
12507 part_die
->highpc
= DW_ADDR (&attr
);
12510 high_pc_relative
= 1;
12511 part_die
->highpc
= DW_UNSND (&attr
);
12514 case DW_AT_location
:
12515 /* Support the .debug_loc offsets. */
12516 if (attr_form_is_block (&attr
))
12518 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12520 else if (attr_form_is_section_offset (&attr
))
12522 dwarf2_complex_location_expr_complaint ();
12526 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12527 "partial symbol information");
12530 case DW_AT_external
:
12531 part_die
->is_external
= DW_UNSND (&attr
);
12533 case DW_AT_declaration
:
12534 part_die
->is_declaration
= DW_UNSND (&attr
);
12537 part_die
->has_type
= 1;
12539 case DW_AT_abstract_origin
:
12540 case DW_AT_specification
:
12541 case DW_AT_extension
:
12542 part_die
->has_specification
= 1;
12543 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12545 case DW_AT_sibling
:
12546 /* Ignore absolute siblings, they might point outside of
12547 the current compile unit. */
12548 if (attr
.form
== DW_FORM_ref_addr
)
12549 complaint (&symfile_complaints
,
12550 _("ignoring absolute DW_AT_sibling"));
12552 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12554 case DW_AT_byte_size
:
12555 part_die
->has_byte_size
= 1;
12557 case DW_AT_calling_convention
:
12558 /* DWARF doesn't provide a way to identify a program's source-level
12559 entry point. DW_AT_calling_convention attributes are only meant
12560 to describe functions' calling conventions.
12562 However, because it's a necessary piece of information in
12563 Fortran, and because DW_CC_program is the only piece of debugging
12564 information whose definition refers to a 'main program' at all,
12565 several compilers have begun marking Fortran main programs with
12566 DW_CC_program --- even when those functions use the standard
12567 calling conventions.
12569 So until DWARF specifies a way to provide this information and
12570 compilers pick up the new representation, we'll support this
12572 if (DW_UNSND (&attr
) == DW_CC_program
12573 && cu
->language
== language_fortran
)
12575 set_main_name (part_die
->name
);
12577 /* As this DIE has a static linkage the name would be difficult
12578 to look up later. */
12579 language_of_main
= language_fortran
;
12583 if (DW_UNSND (&attr
) == DW_INL_inlined
12584 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12585 part_die
->may_be_inlined
= 1;
12589 if (part_die
->tag
== DW_TAG_imported_unit
)
12590 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12598 if (high_pc_relative
)
12599 part_die
->highpc
+= part_die
->lowpc
;
12601 if (has_low_pc_attr
&& has_high_pc_attr
)
12603 /* When using the GNU linker, .gnu.linkonce. sections are used to
12604 eliminate duplicate copies of functions and vtables and such.
12605 The linker will arbitrarily choose one and discard the others.
12606 The AT_*_pc values for such functions refer to local labels in
12607 these sections. If the section from that file was discarded, the
12608 labels are not in the output, so the relocs get a value of 0.
12609 If this is a discarded function, mark the pc bounds as invalid,
12610 so that GDB will ignore it. */
12611 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12613 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12615 complaint (&symfile_complaints
,
12616 _("DW_AT_low_pc %s is zero "
12617 "for DIE at 0x%x [in module %s]"),
12618 paddress (gdbarch
, part_die
->lowpc
),
12619 part_die
->offset
.sect_off
, objfile
->name
);
12621 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12622 else if (part_die
->lowpc
>= part_die
->highpc
)
12624 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12626 complaint (&symfile_complaints
,
12627 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12628 "for DIE at 0x%x [in module %s]"),
12629 paddress (gdbarch
, part_die
->lowpc
),
12630 paddress (gdbarch
, part_die
->highpc
),
12631 part_die
->offset
.sect_off
, objfile
->name
);
12634 part_die
->has_pc_info
= 1;
12640 /* Find a cached partial DIE at OFFSET in CU. */
12642 static struct partial_die_info
*
12643 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12645 struct partial_die_info
*lookup_die
= NULL
;
12646 struct partial_die_info part_die
;
12648 part_die
.offset
= offset
;
12649 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12655 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12656 except in the case of .debug_types DIEs which do not reference
12657 outside their CU (they do however referencing other types via
12658 DW_FORM_ref_sig8). */
12660 static struct partial_die_info
*
12661 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
12663 struct objfile
*objfile
= cu
->objfile
;
12664 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12665 struct partial_die_info
*pd
= NULL
;
12667 if (offset_in_cu_p (&cu
->header
, offset
))
12669 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12672 /* We missed recording what we needed.
12673 Load all dies and try again. */
12674 per_cu
= cu
->per_cu
;
12678 /* TUs don't reference other CUs/TUs (except via type signatures). */
12679 if (cu
->per_cu
->is_debug_types
)
12681 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12682 " external reference to offset 0x%lx [in module %s].\n"),
12683 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12684 bfd_get_filename (objfile
->obfd
));
12686 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
12688 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12689 load_partial_comp_unit (per_cu
);
12691 per_cu
->cu
->last_used
= 0;
12692 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12695 /* If we didn't find it, and not all dies have been loaded,
12696 load them all and try again. */
12698 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12700 per_cu
->load_all_dies
= 1;
12702 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12703 THIS_CU->cu may already be in use. So we can't just free it and
12704 replace its DIEs with the ones we read in. Instead, we leave those
12705 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12706 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12708 load_partial_comp_unit (per_cu
);
12710 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12714 internal_error (__FILE__
, __LINE__
,
12715 _("could not find partial DIE 0x%x "
12716 "in cache [from module %s]\n"),
12717 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12721 /* See if we can figure out if the class lives in a namespace. We do
12722 this by looking for a member function; its demangled name will
12723 contain namespace info, if there is any. */
12726 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12727 struct dwarf2_cu
*cu
)
12729 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12730 what template types look like, because the demangler
12731 frequently doesn't give the same name as the debug info. We
12732 could fix this by only using the demangled name to get the
12733 prefix (but see comment in read_structure_type). */
12735 struct partial_die_info
*real_pdi
;
12736 struct partial_die_info
*child_pdi
;
12738 /* If this DIE (this DIE's specification, if any) has a parent, then
12739 we should not do this. We'll prepend the parent's fully qualified
12740 name when we create the partial symbol. */
12742 real_pdi
= struct_pdi
;
12743 while (real_pdi
->has_specification
)
12744 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
12746 if (real_pdi
->die_parent
!= NULL
)
12749 for (child_pdi
= struct_pdi
->die_child
;
12751 child_pdi
= child_pdi
->die_sibling
)
12753 if (child_pdi
->tag
== DW_TAG_subprogram
12754 && child_pdi
->linkage_name
!= NULL
)
12756 char *actual_class_name
12757 = language_class_name_from_physname (cu
->language_defn
,
12758 child_pdi
->linkage_name
);
12759 if (actual_class_name
!= NULL
)
12762 = obsavestring (actual_class_name
,
12763 strlen (actual_class_name
),
12764 &cu
->objfile
->objfile_obstack
);
12765 xfree (actual_class_name
);
12772 /* Adjust PART_DIE before generating a symbol for it. This function
12773 may set the is_external flag or change the DIE's name. */
12776 fixup_partial_die (struct partial_die_info
*part_die
,
12777 struct dwarf2_cu
*cu
)
12779 /* Once we've fixed up a die, there's no point in doing so again.
12780 This also avoids a memory leak if we were to call
12781 guess_partial_die_structure_name multiple times. */
12782 if (part_die
->fixup_called
)
12785 /* If we found a reference attribute and the DIE has no name, try
12786 to find a name in the referred to DIE. */
12788 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12790 struct partial_die_info
*spec_die
;
12792 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
12794 fixup_partial_die (spec_die
, cu
);
12796 if (spec_die
->name
)
12798 part_die
->name
= spec_die
->name
;
12800 /* Copy DW_AT_external attribute if it is set. */
12801 if (spec_die
->is_external
)
12802 part_die
->is_external
= spec_die
->is_external
;
12806 /* Set default names for some unnamed DIEs. */
12808 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12809 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12811 /* If there is no parent die to provide a namespace, and there are
12812 children, see if we can determine the namespace from their linkage
12814 if (cu
->language
== language_cplus
12815 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12816 && part_die
->die_parent
== NULL
12817 && part_die
->has_children
12818 && (part_die
->tag
== DW_TAG_class_type
12819 || part_die
->tag
== DW_TAG_structure_type
12820 || part_die
->tag
== DW_TAG_union_type
))
12821 guess_partial_die_structure_name (part_die
, cu
);
12823 /* GCC might emit a nameless struct or union that has a linkage
12824 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12825 if (part_die
->name
== NULL
12826 && (part_die
->tag
== DW_TAG_class_type
12827 || part_die
->tag
== DW_TAG_interface_type
12828 || part_die
->tag
== DW_TAG_structure_type
12829 || part_die
->tag
== DW_TAG_union_type
)
12830 && part_die
->linkage_name
!= NULL
)
12834 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
12839 /* Strip any leading namespaces/classes, keep only the base name.
12840 DW_AT_name for named DIEs does not contain the prefixes. */
12841 base
= strrchr (demangled
, ':');
12842 if (base
&& base
> demangled
&& base
[-1] == ':')
12847 part_die
->name
= obsavestring (base
, strlen (base
),
12848 &cu
->objfile
->objfile_obstack
);
12853 part_die
->fixup_called
= 1;
12856 /* Read an attribute value described by an attribute form. */
12859 read_attribute_value (const struct die_reader_specs
*reader
,
12860 struct attribute
*attr
, unsigned form
,
12861 gdb_byte
*info_ptr
)
12863 struct dwarf2_cu
*cu
= reader
->cu
;
12864 bfd
*abfd
= reader
->abfd
;
12865 struct comp_unit_head
*cu_header
= &cu
->header
;
12866 unsigned int bytes_read
;
12867 struct dwarf_block
*blk
;
12872 case DW_FORM_ref_addr
:
12873 if (cu
->header
.version
== 2)
12874 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12876 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
12877 &cu
->header
, &bytes_read
);
12878 info_ptr
+= bytes_read
;
12881 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12882 info_ptr
+= bytes_read
;
12884 case DW_FORM_block2
:
12885 blk
= dwarf_alloc_block (cu
);
12886 blk
->size
= read_2_bytes (abfd
, info_ptr
);
12888 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12889 info_ptr
+= blk
->size
;
12890 DW_BLOCK (attr
) = blk
;
12892 case DW_FORM_block4
:
12893 blk
= dwarf_alloc_block (cu
);
12894 blk
->size
= read_4_bytes (abfd
, info_ptr
);
12896 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12897 info_ptr
+= blk
->size
;
12898 DW_BLOCK (attr
) = blk
;
12900 case DW_FORM_data2
:
12901 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
12904 case DW_FORM_data4
:
12905 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
12908 case DW_FORM_data8
:
12909 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
12912 case DW_FORM_sec_offset
:
12913 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
12914 info_ptr
+= bytes_read
;
12916 case DW_FORM_string
:
12917 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
12918 DW_STRING_IS_CANONICAL (attr
) = 0;
12919 info_ptr
+= bytes_read
;
12922 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
12924 DW_STRING_IS_CANONICAL (attr
) = 0;
12925 info_ptr
+= bytes_read
;
12927 case DW_FORM_exprloc
:
12928 case DW_FORM_block
:
12929 blk
= dwarf_alloc_block (cu
);
12930 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12931 info_ptr
+= bytes_read
;
12932 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12933 info_ptr
+= blk
->size
;
12934 DW_BLOCK (attr
) = blk
;
12936 case DW_FORM_block1
:
12937 blk
= dwarf_alloc_block (cu
);
12938 blk
->size
= read_1_byte (abfd
, info_ptr
);
12940 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12941 info_ptr
+= blk
->size
;
12942 DW_BLOCK (attr
) = blk
;
12944 case DW_FORM_data1
:
12945 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12949 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12952 case DW_FORM_flag_present
:
12953 DW_UNSND (attr
) = 1;
12955 case DW_FORM_sdata
:
12956 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
12957 info_ptr
+= bytes_read
;
12959 case DW_FORM_udata
:
12960 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12961 info_ptr
+= bytes_read
;
12964 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12965 + read_1_byte (abfd
, info_ptr
));
12969 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12970 + read_2_bytes (abfd
, info_ptr
));
12974 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12975 + read_4_bytes (abfd
, info_ptr
));
12979 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12980 + read_8_bytes (abfd
, info_ptr
));
12983 case DW_FORM_ref_sig8
:
12984 /* Convert the signature to something we can record in DW_UNSND
12986 NOTE: This is NULL if the type wasn't found. */
12987 DW_SIGNATURED_TYPE (attr
) =
12988 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12991 case DW_FORM_ref_udata
:
12992 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12993 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12994 info_ptr
+= bytes_read
;
12996 case DW_FORM_indirect
:
12997 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12998 info_ptr
+= bytes_read
;
12999 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
13001 case DW_FORM_GNU_addr_index
:
13002 if (reader
->dwo_file
== NULL
)
13004 /* For now flag a hard error.
13005 Later we can turn this into a complaint. */
13006 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13007 dwarf_form_name (form
),
13008 bfd_get_filename (abfd
));
13010 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
13011 info_ptr
+= bytes_read
;
13013 case DW_FORM_GNU_str_index
:
13014 if (reader
->dwo_file
== NULL
)
13016 /* For now flag a hard error.
13017 Later we can turn this into a complaint if warranted. */
13018 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13019 dwarf_form_name (form
),
13020 bfd_get_filename (abfd
));
13023 ULONGEST str_index
=
13024 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13026 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
13027 DW_STRING_IS_CANONICAL (attr
) = 0;
13028 info_ptr
+= bytes_read
;
13032 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
13033 dwarf_form_name (form
),
13034 bfd_get_filename (abfd
));
13037 /* We have seen instances where the compiler tried to emit a byte
13038 size attribute of -1 which ended up being encoded as an unsigned
13039 0xffffffff. Although 0xffffffff is technically a valid size value,
13040 an object of this size seems pretty unlikely so we can relatively
13041 safely treat these cases as if the size attribute was invalid and
13042 treat them as zero by default. */
13043 if (attr
->name
== DW_AT_byte_size
13044 && form
== DW_FORM_data4
13045 && DW_UNSND (attr
) >= 0xffffffff)
13048 (&symfile_complaints
,
13049 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
13050 hex_string (DW_UNSND (attr
)));
13051 DW_UNSND (attr
) = 0;
13057 /* Read an attribute described by an abbreviated attribute. */
13060 read_attribute (const struct die_reader_specs
*reader
,
13061 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
13062 gdb_byte
*info_ptr
)
13064 attr
->name
= abbrev
->name
;
13065 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
13068 /* Read dwarf information from a buffer. */
13070 static unsigned int
13071 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
13073 return bfd_get_8 (abfd
, buf
);
13077 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
13079 return bfd_get_signed_8 (abfd
, buf
);
13082 static unsigned int
13083 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
13085 return bfd_get_16 (abfd
, buf
);
13089 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13091 return bfd_get_signed_16 (abfd
, buf
);
13094 static unsigned int
13095 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
13097 return bfd_get_32 (abfd
, buf
);
13101 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13103 return bfd_get_signed_32 (abfd
, buf
);
13107 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
13109 return bfd_get_64 (abfd
, buf
);
13113 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
13114 unsigned int *bytes_read
)
13116 struct comp_unit_head
*cu_header
= &cu
->header
;
13117 CORE_ADDR retval
= 0;
13119 if (cu_header
->signed_addr_p
)
13121 switch (cu_header
->addr_size
)
13124 retval
= bfd_get_signed_16 (abfd
, buf
);
13127 retval
= bfd_get_signed_32 (abfd
, buf
);
13130 retval
= bfd_get_signed_64 (abfd
, buf
);
13133 internal_error (__FILE__
, __LINE__
,
13134 _("read_address: bad switch, signed [in module %s]"),
13135 bfd_get_filename (abfd
));
13140 switch (cu_header
->addr_size
)
13143 retval
= bfd_get_16 (abfd
, buf
);
13146 retval
= bfd_get_32 (abfd
, buf
);
13149 retval
= bfd_get_64 (abfd
, buf
);
13152 internal_error (__FILE__
, __LINE__
,
13153 _("read_address: bad switch, "
13154 "unsigned [in module %s]"),
13155 bfd_get_filename (abfd
));
13159 *bytes_read
= cu_header
->addr_size
;
13163 /* Read the initial length from a section. The (draft) DWARF 3
13164 specification allows the initial length to take up either 4 bytes
13165 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13166 bytes describe the length and all offsets will be 8 bytes in length
13169 An older, non-standard 64-bit format is also handled by this
13170 function. The older format in question stores the initial length
13171 as an 8-byte quantity without an escape value. Lengths greater
13172 than 2^32 aren't very common which means that the initial 4 bytes
13173 is almost always zero. Since a length value of zero doesn't make
13174 sense for the 32-bit format, this initial zero can be considered to
13175 be an escape value which indicates the presence of the older 64-bit
13176 format. As written, the code can't detect (old format) lengths
13177 greater than 4GB. If it becomes necessary to handle lengths
13178 somewhat larger than 4GB, we could allow other small values (such
13179 as the non-sensical values of 1, 2, and 3) to also be used as
13180 escape values indicating the presence of the old format.
13182 The value returned via bytes_read should be used to increment the
13183 relevant pointer after calling read_initial_length().
13185 [ Note: read_initial_length() and read_offset() are based on the
13186 document entitled "DWARF Debugging Information Format", revision
13187 3, draft 8, dated November 19, 2001. This document was obtained
13190 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13192 This document is only a draft and is subject to change. (So beware.)
13194 Details regarding the older, non-standard 64-bit format were
13195 determined empirically by examining 64-bit ELF files produced by
13196 the SGI toolchain on an IRIX 6.5 machine.
13198 - Kevin, July 16, 2002
13202 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13204 LONGEST length
= bfd_get_32 (abfd
, buf
);
13206 if (length
== 0xffffffff)
13208 length
= bfd_get_64 (abfd
, buf
+ 4);
13211 else if (length
== 0)
13213 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13214 length
= bfd_get_64 (abfd
, buf
);
13225 /* Cover function for read_initial_length.
13226 Returns the length of the object at BUF, and stores the size of the
13227 initial length in *BYTES_READ and stores the size that offsets will be in
13229 If the initial length size is not equivalent to that specified in
13230 CU_HEADER then issue a complaint.
13231 This is useful when reading non-comp-unit headers. */
13234 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13235 const struct comp_unit_head
*cu_header
,
13236 unsigned int *bytes_read
,
13237 unsigned int *offset_size
)
13239 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13241 gdb_assert (cu_header
->initial_length_size
== 4
13242 || cu_header
->initial_length_size
== 8
13243 || cu_header
->initial_length_size
== 12);
13245 if (cu_header
->initial_length_size
!= *bytes_read
)
13246 complaint (&symfile_complaints
,
13247 _("intermixed 32-bit and 64-bit DWARF sections"));
13249 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13253 /* Read an offset from the data stream. The size of the offset is
13254 given by cu_header->offset_size. */
13257 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13258 unsigned int *bytes_read
)
13260 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13262 *bytes_read
= cu_header
->offset_size
;
13266 /* Read an offset from the data stream. */
13269 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13271 LONGEST retval
= 0;
13273 switch (offset_size
)
13276 retval
= bfd_get_32 (abfd
, buf
);
13279 retval
= bfd_get_64 (abfd
, buf
);
13282 internal_error (__FILE__
, __LINE__
,
13283 _("read_offset_1: bad switch [in module %s]"),
13284 bfd_get_filename (abfd
));
13291 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13293 /* If the size of a host char is 8 bits, we can return a pointer
13294 to the buffer, otherwise we have to copy the data to a buffer
13295 allocated on the temporary obstack. */
13296 gdb_assert (HOST_CHAR_BIT
== 8);
13301 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13303 /* If the size of a host char is 8 bits, we can return a pointer
13304 to the string, otherwise we have to copy the string to a buffer
13305 allocated on the temporary obstack. */
13306 gdb_assert (HOST_CHAR_BIT
== 8);
13309 *bytes_read_ptr
= 1;
13312 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13313 return (char *) buf
;
13317 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13319 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13320 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13321 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13322 bfd_get_filename (abfd
));
13323 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13324 error (_("DW_FORM_strp pointing outside of "
13325 ".debug_str section [in module %s]"),
13326 bfd_get_filename (abfd
));
13327 gdb_assert (HOST_CHAR_BIT
== 8);
13328 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13330 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13334 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13335 const struct comp_unit_head
*cu_header
,
13336 unsigned int *bytes_read_ptr
)
13338 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13340 return read_indirect_string_at_offset (abfd
, str_offset
);
13344 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13347 unsigned int num_read
;
13349 unsigned char byte
;
13357 byte
= bfd_get_8 (abfd
, buf
);
13360 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13361 if ((byte
& 128) == 0)
13367 *bytes_read_ptr
= num_read
;
13372 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13375 int i
, shift
, num_read
;
13376 unsigned char byte
;
13384 byte
= bfd_get_8 (abfd
, buf
);
13387 result
|= ((LONGEST
) (byte
& 127) << shift
);
13389 if ((byte
& 128) == 0)
13394 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13395 result
|= -(((LONGEST
) 1) << shift
);
13396 *bytes_read_ptr
= num_read
;
13400 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13401 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13402 ADDR_SIZE is the size of addresses from the CU header. */
13405 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13407 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13408 bfd
*abfd
= objfile
->obfd
;
13409 const gdb_byte
*info_ptr
;
13411 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13412 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13413 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13415 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13416 error (_("DW_FORM_addr_index pointing outside of "
13417 ".debug_addr section [in module %s]"),
13419 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13420 + addr_base
+ addr_index
* addr_size
);
13421 if (addr_size
== 4)
13422 return bfd_get_32 (abfd
, info_ptr
);
13424 return bfd_get_64 (abfd
, info_ptr
);
13427 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13430 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13432 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13435 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13438 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13439 unsigned int *bytes_read
)
13441 bfd
*abfd
= cu
->objfile
->obfd
;
13442 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13444 return read_addr_index (cu
, addr_index
);
13447 /* Data structure to pass results from dwarf2_read_addr_index_reader
13448 back to dwarf2_read_addr_index. */
13450 struct dwarf2_read_addr_index_data
13452 ULONGEST addr_base
;
13456 /* die_reader_func for dwarf2_read_addr_index. */
13459 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13460 gdb_byte
*info_ptr
,
13461 struct die_info
*comp_unit_die
,
13465 struct dwarf2_cu
*cu
= reader
->cu
;
13466 struct dwarf2_read_addr_index_data
*aidata
=
13467 (struct dwarf2_read_addr_index_data
*) data
;
13469 aidata
->addr_base
= cu
->addr_base
;
13470 aidata
->addr_size
= cu
->header
.addr_size
;
13473 /* Given an index in .debug_addr, fetch the value.
13474 NOTE: This can be called during dwarf expression evaluation,
13475 long after the debug information has been read, and thus per_cu->cu
13476 may no longer exist. */
13479 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13480 unsigned int addr_index
)
13482 struct objfile
*objfile
= per_cu
->objfile
;
13483 struct dwarf2_cu
*cu
= per_cu
->cu
;
13484 ULONGEST addr_base
;
13487 /* This is intended to be called from outside this file. */
13488 dw2_setup (objfile
);
13490 /* We need addr_base and addr_size.
13491 If we don't have PER_CU->cu, we have to get it.
13492 Nasty, but the alternative is storing the needed info in PER_CU,
13493 which at this point doesn't seem justified: it's not clear how frequently
13494 it would get used and it would increase the size of every PER_CU.
13495 Entry points like dwarf2_per_cu_addr_size do a similar thing
13496 so we're not in uncharted territory here.
13497 Alas we need to be a bit more complicated as addr_base is contained
13500 We don't need to read the entire CU(/TU).
13501 We just need the header and top level die.
13502 IWBN to use the aging mechanism to let us lazily later discard the CU.
13503 See however init_cutu_and_read_dies_simple. */
13507 addr_base
= cu
->addr_base
;
13508 addr_size
= cu
->header
.addr_size
;
13512 struct dwarf2_read_addr_index_data aidata
;
13514 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13516 addr_base
= aidata
.addr_base
;
13517 addr_size
= aidata
.addr_size
;
13520 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13523 /* Given a DW_AT_str_index, fetch the string. */
13526 read_str_index (const struct die_reader_specs
*reader
,
13527 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13529 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13530 const char *dwo_name
= objfile
->name
;
13531 bfd
*abfd
= objfile
->obfd
;
13532 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13533 gdb_byte
*info_ptr
;
13534 ULONGEST str_offset
;
13536 dwarf2_read_section (objfile
, §ions
->str
);
13537 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13538 if (sections
->str
.buffer
== NULL
)
13539 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13540 " in CU at offset 0x%lx [in module %s]"),
13541 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13542 if (sections
->str_offsets
.buffer
== NULL
)
13543 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13544 " in CU at offset 0x%lx [in module %s]"),
13545 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13546 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13547 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13548 " section in CU at offset 0x%lx [in module %s]"),
13549 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13550 info_ptr
= (sections
->str_offsets
.buffer
13551 + str_index
* cu
->header
.offset_size
);
13552 if (cu
->header
.offset_size
== 4)
13553 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13555 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13556 if (str_offset
>= sections
->str
.size
)
13557 error (_("Offset from DW_FORM_str_index pointing outside of"
13558 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13559 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13560 return (char *) (sections
->str
.buffer
+ str_offset
);
13563 /* Return the length of an LEB128 number in BUF. */
13566 leb128_size (const gdb_byte
*buf
)
13568 const gdb_byte
*begin
= buf
;
13574 if ((byte
& 128) == 0)
13575 return buf
- begin
;
13580 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13587 cu
->language
= language_c
;
13589 case DW_LANG_C_plus_plus
:
13590 cu
->language
= language_cplus
;
13593 cu
->language
= language_d
;
13595 case DW_LANG_Fortran77
:
13596 case DW_LANG_Fortran90
:
13597 case DW_LANG_Fortran95
:
13598 cu
->language
= language_fortran
;
13601 cu
->language
= language_go
;
13603 case DW_LANG_Mips_Assembler
:
13604 cu
->language
= language_asm
;
13607 cu
->language
= language_java
;
13609 case DW_LANG_Ada83
:
13610 case DW_LANG_Ada95
:
13611 cu
->language
= language_ada
;
13613 case DW_LANG_Modula2
:
13614 cu
->language
= language_m2
;
13616 case DW_LANG_Pascal83
:
13617 cu
->language
= language_pascal
;
13620 cu
->language
= language_objc
;
13622 case DW_LANG_Cobol74
:
13623 case DW_LANG_Cobol85
:
13625 cu
->language
= language_minimal
;
13628 cu
->language_defn
= language_def (cu
->language
);
13631 /* Return the named attribute or NULL if not there. */
13633 static struct attribute
*
13634 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13639 struct attribute
*spec
= NULL
;
13641 for (i
= 0; i
< die
->num_attrs
; ++i
)
13643 if (die
->attrs
[i
].name
== name
)
13644 return &die
->attrs
[i
];
13645 if (die
->attrs
[i
].name
== DW_AT_specification
13646 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13647 spec
= &die
->attrs
[i
];
13653 die
= follow_die_ref (die
, spec
, &cu
);
13659 /* Return the named attribute or NULL if not there,
13660 but do not follow DW_AT_specification, etc.
13661 This is for use in contexts where we're reading .debug_types dies.
13662 Following DW_AT_specification, DW_AT_abstract_origin will take us
13663 back up the chain, and we want to go down. */
13665 static struct attribute
*
13666 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13670 for (i
= 0; i
< die
->num_attrs
; ++i
)
13671 if (die
->attrs
[i
].name
== name
)
13672 return &die
->attrs
[i
];
13677 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13678 and holds a non-zero value. This function should only be used for
13679 DW_FORM_flag or DW_FORM_flag_present attributes. */
13682 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13684 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13686 return (attr
&& DW_UNSND (attr
));
13690 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13692 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13693 which value is non-zero. However, we have to be careful with
13694 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13695 (via dwarf2_flag_true_p) follows this attribute. So we may
13696 end up accidently finding a declaration attribute that belongs
13697 to a different DIE referenced by the specification attribute,
13698 even though the given DIE does not have a declaration attribute. */
13699 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13700 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13703 /* Return the die giving the specification for DIE, if there is
13704 one. *SPEC_CU is the CU containing DIE on input, and the CU
13705 containing the return value on output. If there is no
13706 specification, but there is an abstract origin, that is
13709 static struct die_info
*
13710 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13712 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13715 if (spec_attr
== NULL
)
13716 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13718 if (spec_attr
== NULL
)
13721 return follow_die_ref (die
, spec_attr
, spec_cu
);
13724 /* Free the line_header structure *LH, and any arrays and strings it
13726 NOTE: This is also used as a "cleanup" function. */
13729 free_line_header (struct line_header
*lh
)
13731 if (lh
->standard_opcode_lengths
)
13732 xfree (lh
->standard_opcode_lengths
);
13734 /* Remember that all the lh->file_names[i].name pointers are
13735 pointers into debug_line_buffer, and don't need to be freed. */
13736 if (lh
->file_names
)
13737 xfree (lh
->file_names
);
13739 /* Similarly for the include directory names. */
13740 if (lh
->include_dirs
)
13741 xfree (lh
->include_dirs
);
13746 /* Add an entry to LH's include directory table. */
13749 add_include_dir (struct line_header
*lh
, char *include_dir
)
13751 /* Grow the array if necessary. */
13752 if (lh
->include_dirs_size
== 0)
13754 lh
->include_dirs_size
= 1; /* for testing */
13755 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13756 * sizeof (*lh
->include_dirs
));
13758 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13760 lh
->include_dirs_size
*= 2;
13761 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13762 (lh
->include_dirs_size
13763 * sizeof (*lh
->include_dirs
)));
13766 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13769 /* Add an entry to LH's file name table. */
13772 add_file_name (struct line_header
*lh
,
13774 unsigned int dir_index
,
13775 unsigned int mod_time
,
13776 unsigned int length
)
13778 struct file_entry
*fe
;
13780 /* Grow the array if necessary. */
13781 if (lh
->file_names_size
== 0)
13783 lh
->file_names_size
= 1; /* for testing */
13784 lh
->file_names
= xmalloc (lh
->file_names_size
13785 * sizeof (*lh
->file_names
));
13787 else if (lh
->num_file_names
>= lh
->file_names_size
)
13789 lh
->file_names_size
*= 2;
13790 lh
->file_names
= xrealloc (lh
->file_names
,
13791 (lh
->file_names_size
13792 * sizeof (*lh
->file_names
)));
13795 fe
= &lh
->file_names
[lh
->num_file_names
++];
13797 fe
->dir_index
= dir_index
;
13798 fe
->mod_time
= mod_time
;
13799 fe
->length
= length
;
13800 fe
->included_p
= 0;
13804 /* Read the statement program header starting at OFFSET in
13805 .debug_line, or .debug_line.dwo. Return a pointer
13806 to a struct line_header, allocated using xmalloc.
13808 NOTE: the strings in the include directory and file name tables of
13809 the returned object point into the dwarf line section buffer,
13810 and must not be freed. */
13812 static struct line_header
*
13813 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
13815 struct cleanup
*back_to
;
13816 struct line_header
*lh
;
13817 gdb_byte
*line_ptr
;
13818 unsigned int bytes_read
, offset_size
;
13820 char *cur_dir
, *cur_file
;
13821 struct dwarf2_section_info
*section
;
13824 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
13826 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13827 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
13829 section
= &dwarf2_per_objfile
->line
;
13831 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
13832 if (section
->buffer
== NULL
)
13834 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13835 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
13837 complaint (&symfile_complaints
, _("missing .debug_line section"));
13841 /* We can't do this until we know the section is non-empty.
13842 Only then do we know we have such a section. */
13843 abfd
= section
->asection
->owner
;
13845 /* Make sure that at least there's room for the total_length field.
13846 That could be 12 bytes long, but we're just going to fudge that. */
13847 if (offset
+ 4 >= section
->size
)
13849 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13853 lh
= xmalloc (sizeof (*lh
));
13854 memset (lh
, 0, sizeof (*lh
));
13855 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
13858 line_ptr
= section
->buffer
+ offset
;
13860 /* Read in the header. */
13862 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
13863 &bytes_read
, &offset_size
);
13864 line_ptr
+= bytes_read
;
13865 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
13867 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13870 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
13871 lh
->version
= read_2_bytes (abfd
, line_ptr
);
13873 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
13874 line_ptr
+= offset_size
;
13875 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
13877 if (lh
->version
>= 4)
13879 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
13883 lh
->maximum_ops_per_instruction
= 1;
13885 if (lh
->maximum_ops_per_instruction
== 0)
13887 lh
->maximum_ops_per_instruction
= 1;
13888 complaint (&symfile_complaints
,
13889 _("invalid maximum_ops_per_instruction "
13890 "in `.debug_line' section"));
13893 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
13895 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
13897 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
13899 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
13901 lh
->standard_opcode_lengths
13902 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
13904 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
13905 for (i
= 1; i
< lh
->opcode_base
; ++i
)
13907 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
13911 /* Read directory table. */
13912 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13914 line_ptr
+= bytes_read
;
13915 add_include_dir (lh
, cur_dir
);
13917 line_ptr
+= bytes_read
;
13919 /* Read file name table. */
13920 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13922 unsigned int dir_index
, mod_time
, length
;
13924 line_ptr
+= bytes_read
;
13925 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13926 line_ptr
+= bytes_read
;
13927 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13928 line_ptr
+= bytes_read
;
13929 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13930 line_ptr
+= bytes_read
;
13932 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13934 line_ptr
+= bytes_read
;
13935 lh
->statement_program_start
= line_ptr
;
13937 if (line_ptr
> (section
->buffer
+ section
->size
))
13938 complaint (&symfile_complaints
,
13939 _("line number info header doesn't "
13940 "fit in `.debug_line' section"));
13942 discard_cleanups (back_to
);
13946 /* Subroutine of dwarf_decode_lines to simplify it.
13947 Return the file name of the psymtab for included file FILE_INDEX
13948 in line header LH of PST.
13949 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13950 If space for the result is malloc'd, it will be freed by a cleanup.
13951 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
13954 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
13955 const struct partial_symtab
*pst
,
13956 const char *comp_dir
)
13958 const struct file_entry fe
= lh
->file_names
[file_index
];
13959 char *include_name
= fe
.name
;
13960 char *include_name_to_compare
= include_name
;
13961 char *dir_name
= NULL
;
13962 const char *pst_filename
;
13963 char *copied_name
= NULL
;
13967 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13969 if (!IS_ABSOLUTE_PATH (include_name
)
13970 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13972 /* Avoid creating a duplicate psymtab for PST.
13973 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13974 Before we do the comparison, however, we need to account
13975 for DIR_NAME and COMP_DIR.
13976 First prepend dir_name (if non-NULL). If we still don't
13977 have an absolute path prepend comp_dir (if non-NULL).
13978 However, the directory we record in the include-file's
13979 psymtab does not contain COMP_DIR (to match the
13980 corresponding symtab(s)).
13985 bash$ gcc -g ./hello.c
13986 include_name = "hello.c"
13988 DW_AT_comp_dir = comp_dir = "/tmp"
13989 DW_AT_name = "./hello.c" */
13991 if (dir_name
!= NULL
)
13993 include_name
= concat (dir_name
, SLASH_STRING
,
13994 include_name
, (char *)NULL
);
13995 include_name_to_compare
= include_name
;
13996 make_cleanup (xfree
, include_name
);
13998 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
14000 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
14001 include_name
, (char *)NULL
);
14005 pst_filename
= pst
->filename
;
14006 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
14008 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
14009 pst_filename
, (char *)NULL
);
14010 pst_filename
= copied_name
;
14013 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
14015 if (include_name_to_compare
!= include_name
)
14016 xfree (include_name_to_compare
);
14017 if (copied_name
!= NULL
)
14018 xfree (copied_name
);
14022 return include_name
;
14025 /* Ignore this record_line request. */
14028 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14033 /* Subroutine of dwarf_decode_lines to simplify it.
14034 Process the line number information in LH. */
14037 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
14038 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
14040 gdb_byte
*line_ptr
, *extended_end
;
14041 gdb_byte
*line_end
;
14042 unsigned int bytes_read
, extended_len
;
14043 unsigned char op_code
, extended_op
, adj_opcode
;
14044 CORE_ADDR baseaddr
;
14045 struct objfile
*objfile
= cu
->objfile
;
14046 bfd
*abfd
= objfile
->obfd
;
14047 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14048 const int decode_for_pst_p
= (pst
!= NULL
);
14049 struct subfile
*last_subfile
= NULL
;
14050 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14053 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14055 line_ptr
= lh
->statement_program_start
;
14056 line_end
= lh
->statement_program_end
;
14058 /* Read the statement sequences until there's nothing left. */
14059 while (line_ptr
< line_end
)
14061 /* state machine registers */
14062 CORE_ADDR address
= 0;
14063 unsigned int file
= 1;
14064 unsigned int line
= 1;
14065 unsigned int column
= 0;
14066 int is_stmt
= lh
->default_is_stmt
;
14067 int basic_block
= 0;
14068 int end_sequence
= 0;
14070 unsigned char op_index
= 0;
14072 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
14074 /* Start a subfile for the current file of the state machine. */
14075 /* lh->include_dirs and lh->file_names are 0-based, but the
14076 directory and file name numbers in the statement program
14078 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14082 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14084 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14087 /* Decode the table. */
14088 while (!end_sequence
)
14090 op_code
= read_1_byte (abfd
, line_ptr
);
14092 if (line_ptr
> line_end
)
14094 dwarf2_debug_line_missing_end_sequence_complaint ();
14098 if (op_code
>= lh
->opcode_base
)
14100 /* Special operand. */
14101 adj_opcode
= op_code
- lh
->opcode_base
;
14102 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
14103 / lh
->maximum_ops_per_instruction
)
14104 * lh
->minimum_instruction_length
);
14105 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
14106 % lh
->maximum_ops_per_instruction
);
14107 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
14108 if (lh
->num_file_names
< file
|| file
== 0)
14109 dwarf2_debug_line_missing_file_complaint ();
14110 /* For now we ignore lines not starting on an
14111 instruction boundary. */
14112 else if (op_index
== 0)
14114 lh
->file_names
[file
- 1].included_p
= 1;
14115 if (!decode_for_pst_p
&& is_stmt
)
14117 if (last_subfile
!= current_subfile
)
14119 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14121 (*p_record_line
) (last_subfile
, 0, addr
);
14122 last_subfile
= current_subfile
;
14124 /* Append row to matrix using current values. */
14125 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14126 (*p_record_line
) (current_subfile
, line
, addr
);
14131 else switch (op_code
)
14133 case DW_LNS_extended_op
:
14134 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
14136 line_ptr
+= bytes_read
;
14137 extended_end
= line_ptr
+ extended_len
;
14138 extended_op
= read_1_byte (abfd
, line_ptr
);
14140 switch (extended_op
)
14142 case DW_LNE_end_sequence
:
14143 p_record_line
= record_line
;
14146 case DW_LNE_set_address
:
14147 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14149 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14151 /* This line table is for a function which has been
14152 GCd by the linker. Ignore it. PR gdb/12528 */
14155 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
14157 complaint (&symfile_complaints
,
14158 _(".debug_line address at offset 0x%lx is 0 "
14160 line_offset
, objfile
->name
);
14161 p_record_line
= noop_record_line
;
14165 line_ptr
+= bytes_read
;
14166 address
+= baseaddr
;
14168 case DW_LNE_define_file
:
14171 unsigned int dir_index
, mod_time
, length
;
14173 cur_file
= read_direct_string (abfd
, line_ptr
,
14175 line_ptr
+= bytes_read
;
14177 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14178 line_ptr
+= bytes_read
;
14180 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14181 line_ptr
+= bytes_read
;
14183 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14184 line_ptr
+= bytes_read
;
14185 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14188 case DW_LNE_set_discriminator
:
14189 /* The discriminator is not interesting to the debugger;
14191 line_ptr
= extended_end
;
14194 complaint (&symfile_complaints
,
14195 _("mangled .debug_line section"));
14198 /* Make sure that we parsed the extended op correctly. If e.g.
14199 we expected a different address size than the producer used,
14200 we may have read the wrong number of bytes. */
14201 if (line_ptr
!= extended_end
)
14203 complaint (&symfile_complaints
,
14204 _("mangled .debug_line section"));
14209 if (lh
->num_file_names
< file
|| file
== 0)
14210 dwarf2_debug_line_missing_file_complaint ();
14213 lh
->file_names
[file
- 1].included_p
= 1;
14214 if (!decode_for_pst_p
&& is_stmt
)
14216 if (last_subfile
!= current_subfile
)
14218 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14220 (*p_record_line
) (last_subfile
, 0, addr
);
14221 last_subfile
= current_subfile
;
14223 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14224 (*p_record_line
) (current_subfile
, line
, addr
);
14229 case DW_LNS_advance_pc
:
14232 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14234 address
+= (((op_index
+ adjust
)
14235 / lh
->maximum_ops_per_instruction
)
14236 * lh
->minimum_instruction_length
);
14237 op_index
= ((op_index
+ adjust
)
14238 % lh
->maximum_ops_per_instruction
);
14239 line_ptr
+= bytes_read
;
14242 case DW_LNS_advance_line
:
14243 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14244 line_ptr
+= bytes_read
;
14246 case DW_LNS_set_file
:
14248 /* The arrays lh->include_dirs and lh->file_names are
14249 0-based, but the directory and file name numbers in
14250 the statement program are 1-based. */
14251 struct file_entry
*fe
;
14254 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14255 line_ptr
+= bytes_read
;
14256 if (lh
->num_file_names
< file
|| file
== 0)
14257 dwarf2_debug_line_missing_file_complaint ();
14260 fe
= &lh
->file_names
[file
- 1];
14262 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14263 if (!decode_for_pst_p
)
14265 last_subfile
= current_subfile
;
14266 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14271 case DW_LNS_set_column
:
14272 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14273 line_ptr
+= bytes_read
;
14275 case DW_LNS_negate_stmt
:
14276 is_stmt
= (!is_stmt
);
14278 case DW_LNS_set_basic_block
:
14281 /* Add to the address register of the state machine the
14282 address increment value corresponding to special opcode
14283 255. I.e., this value is scaled by the minimum
14284 instruction length since special opcode 255 would have
14285 scaled the increment. */
14286 case DW_LNS_const_add_pc
:
14288 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14290 address
+= (((op_index
+ adjust
)
14291 / lh
->maximum_ops_per_instruction
)
14292 * lh
->minimum_instruction_length
);
14293 op_index
= ((op_index
+ adjust
)
14294 % lh
->maximum_ops_per_instruction
);
14297 case DW_LNS_fixed_advance_pc
:
14298 address
+= read_2_bytes (abfd
, line_ptr
);
14304 /* Unknown standard opcode, ignore it. */
14307 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14309 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14310 line_ptr
+= bytes_read
;
14315 if (lh
->num_file_names
< file
|| file
== 0)
14316 dwarf2_debug_line_missing_file_complaint ();
14319 lh
->file_names
[file
- 1].included_p
= 1;
14320 if (!decode_for_pst_p
)
14322 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14323 (*p_record_line
) (current_subfile
, 0, addr
);
14329 /* Decode the Line Number Program (LNP) for the given line_header
14330 structure and CU. The actual information extracted and the type
14331 of structures created from the LNP depends on the value of PST.
14333 1. If PST is NULL, then this procedure uses the data from the program
14334 to create all necessary symbol tables, and their linetables.
14336 2. If PST is not NULL, this procedure reads the program to determine
14337 the list of files included by the unit represented by PST, and
14338 builds all the associated partial symbol tables.
14340 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14341 It is used for relative paths in the line table.
14342 NOTE: When processing partial symtabs (pst != NULL),
14343 comp_dir == pst->dirname.
14345 NOTE: It is important that psymtabs have the same file name (via strcmp)
14346 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14347 symtab we don't use it in the name of the psymtabs we create.
14348 E.g. expand_line_sal requires this when finding psymtabs to expand.
14349 A good testcase for this is mb-inline.exp. */
14352 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14353 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14354 int want_line_info
)
14356 struct objfile
*objfile
= cu
->objfile
;
14357 const int decode_for_pst_p
= (pst
!= NULL
);
14358 struct subfile
*first_subfile
= current_subfile
;
14360 if (want_line_info
)
14361 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14363 if (decode_for_pst_p
)
14367 /* Now that we're done scanning the Line Header Program, we can
14368 create the psymtab of each included file. */
14369 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14370 if (lh
->file_names
[file_index
].included_p
== 1)
14372 char *include_name
=
14373 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14374 if (include_name
!= NULL
)
14375 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14380 /* Make sure a symtab is created for every file, even files
14381 which contain only variables (i.e. no code with associated
14385 for (i
= 0; i
< lh
->num_file_names
; i
++)
14388 struct file_entry
*fe
;
14390 fe
= &lh
->file_names
[i
];
14392 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14393 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14395 /* Skip the main file; we don't need it, and it must be
14396 allocated last, so that it will show up before the
14397 non-primary symtabs in the objfile's symtab list. */
14398 if (current_subfile
== first_subfile
)
14401 if (current_subfile
->symtab
== NULL
)
14402 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14404 fe
->symtab
= current_subfile
->symtab
;
14409 /* Start a subfile for DWARF. FILENAME is the name of the file and
14410 DIRNAME the name of the source directory which contains FILENAME
14411 or NULL if not known. COMP_DIR is the compilation directory for the
14412 linetable's compilation unit or NULL if not known.
14413 This routine tries to keep line numbers from identical absolute and
14414 relative file names in a common subfile.
14416 Using the `list' example from the GDB testsuite, which resides in
14417 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14418 of /srcdir/list0.c yields the following debugging information for list0.c:
14420 DW_AT_name: /srcdir/list0.c
14421 DW_AT_comp_dir: /compdir
14422 files.files[0].name: list0.h
14423 files.files[0].dir: /srcdir
14424 files.files[1].name: list0.c
14425 files.files[1].dir: /srcdir
14427 The line number information for list0.c has to end up in a single
14428 subfile, so that `break /srcdir/list0.c:1' works as expected.
14429 start_subfile will ensure that this happens provided that we pass the
14430 concatenation of files.files[1].dir and files.files[1].name as the
14434 dwarf2_start_subfile (char *filename
, const char *dirname
,
14435 const char *comp_dir
)
14439 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14440 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14441 second argument to start_subfile. To be consistent, we do the
14442 same here. In order not to lose the line information directory,
14443 we concatenate it to the filename when it makes sense.
14444 Note that the Dwarf3 standard says (speaking of filenames in line
14445 information): ``The directory index is ignored for file names
14446 that represent full path names''. Thus ignoring dirname in the
14447 `else' branch below isn't an issue. */
14449 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14450 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14452 fullname
= filename
;
14454 start_subfile (fullname
, comp_dir
);
14456 if (fullname
!= filename
)
14460 /* Start a symtab for DWARF.
14461 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14464 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14465 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14467 start_symtab (name
, comp_dir
, low_pc
);
14468 record_debugformat ("DWARF 2");
14469 record_producer (cu
->producer
);
14471 /* We assume that we're processing GCC output. */
14472 processing_gcc_compilation
= 2;
14474 processing_has_namespace_info
= 0;
14478 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14479 struct dwarf2_cu
*cu
)
14481 struct objfile
*objfile
= cu
->objfile
;
14482 struct comp_unit_head
*cu_header
= &cu
->header
;
14484 /* NOTE drow/2003-01-30: There used to be a comment and some special
14485 code here to turn a symbol with DW_AT_external and a
14486 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14487 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14488 with some versions of binutils) where shared libraries could have
14489 relocations against symbols in their debug information - the
14490 minimal symbol would have the right address, but the debug info
14491 would not. It's no longer necessary, because we will explicitly
14492 apply relocations when we read in the debug information now. */
14494 /* A DW_AT_location attribute with no contents indicates that a
14495 variable has been optimized away. */
14496 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14498 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14502 /* Handle one degenerate form of location expression specially, to
14503 preserve GDB's previous behavior when section offsets are
14504 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14505 then mark this symbol as LOC_STATIC. */
14507 if (attr_form_is_block (attr
)
14508 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14509 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14510 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14511 && (DW_BLOCK (attr
)->size
14512 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14514 unsigned int dummy
;
14516 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14517 SYMBOL_VALUE_ADDRESS (sym
) =
14518 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14520 SYMBOL_VALUE_ADDRESS (sym
) =
14521 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14522 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14523 fixup_symbol_section (sym
, objfile
);
14524 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14525 SYMBOL_SECTION (sym
));
14529 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14530 expression evaluator, and use LOC_COMPUTED only when necessary
14531 (i.e. when the value of a register or memory location is
14532 referenced, or a thread-local block, etc.). Then again, it might
14533 not be worthwhile. I'm assuming that it isn't unless performance
14534 or memory numbers show me otherwise. */
14536 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14537 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14539 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14540 cu
->has_loclist
= 1;
14543 /* Given a pointer to a DWARF information entry, figure out if we need
14544 to make a symbol table entry for it, and if so, create a new entry
14545 and return a pointer to it.
14546 If TYPE is NULL, determine symbol type from the die, otherwise
14547 used the passed type.
14548 If SPACE is not NULL, use it to hold the new symbol. If it is
14549 NULL, allocate a new symbol on the objfile's obstack. */
14551 static struct symbol
*
14552 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14553 struct symbol
*space
)
14555 struct objfile
*objfile
= cu
->objfile
;
14556 struct symbol
*sym
= NULL
;
14558 struct attribute
*attr
= NULL
;
14559 struct attribute
*attr2
= NULL
;
14560 CORE_ADDR baseaddr
;
14561 struct pending
**list_to_add
= NULL
;
14563 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14565 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14567 name
= dwarf2_name (die
, cu
);
14570 const char *linkagename
;
14571 int suppress_add
= 0;
14576 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14577 OBJSTAT (objfile
, n_syms
++);
14579 /* Cache this symbol's name and the name's demangled form (if any). */
14580 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14581 linkagename
= dwarf2_physname (name
, die
, cu
);
14582 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14584 /* Fortran does not have mangling standard and the mangling does differ
14585 between gfortran, iFort etc. */
14586 if (cu
->language
== language_fortran
14587 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14588 symbol_set_demangled_name (&(sym
->ginfo
),
14589 (char *) dwarf2_full_name (name
, die
, cu
),
14592 /* Default assumptions.
14593 Use the passed type or decode it from the die. */
14594 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14595 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14597 SYMBOL_TYPE (sym
) = type
;
14599 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14600 attr
= dwarf2_attr (die
,
14601 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14605 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14608 attr
= dwarf2_attr (die
,
14609 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14613 int file_index
= DW_UNSND (attr
);
14615 if (cu
->line_header
== NULL
14616 || file_index
> cu
->line_header
->num_file_names
)
14617 complaint (&symfile_complaints
,
14618 _("file index out of range"));
14619 else if (file_index
> 0)
14621 struct file_entry
*fe
;
14623 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14624 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14631 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14634 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14636 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14637 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14638 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14639 add_symbol_to_list (sym
, cu
->list_in_scope
);
14641 case DW_TAG_subprogram
:
14642 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14644 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14645 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14646 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14647 || cu
->language
== language_ada
)
14649 /* Subprograms marked external are stored as a global symbol.
14650 Ada subprograms, whether marked external or not, are always
14651 stored as a global symbol, because we want to be able to
14652 access them globally. For instance, we want to be able
14653 to break on a nested subprogram without having to
14654 specify the context. */
14655 list_to_add
= &global_symbols
;
14659 list_to_add
= cu
->list_in_scope
;
14662 case DW_TAG_inlined_subroutine
:
14663 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14665 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14666 SYMBOL_INLINED (sym
) = 1;
14667 list_to_add
= cu
->list_in_scope
;
14669 case DW_TAG_template_value_param
:
14671 /* Fall through. */
14672 case DW_TAG_constant
:
14673 case DW_TAG_variable
:
14674 case DW_TAG_member
:
14675 /* Compilation with minimal debug info may result in
14676 variables with missing type entries. Change the
14677 misleading `void' type to something sensible. */
14678 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14680 = objfile_type (objfile
)->nodebug_data_symbol
;
14682 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14683 /* In the case of DW_TAG_member, we should only be called for
14684 static const members. */
14685 if (die
->tag
== DW_TAG_member
)
14687 /* dwarf2_add_field uses die_is_declaration,
14688 so we do the same. */
14689 gdb_assert (die_is_declaration (die
, cu
));
14694 dwarf2_const_value (attr
, sym
, cu
);
14695 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14698 if (attr2
&& (DW_UNSND (attr2
) != 0))
14699 list_to_add
= &global_symbols
;
14701 list_to_add
= cu
->list_in_scope
;
14705 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14708 var_decode_location (attr
, sym
, cu
);
14709 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14710 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14711 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14712 && !dwarf2_per_objfile
->has_section_at_zero
)
14714 /* When a static variable is eliminated by the linker,
14715 the corresponding debug information is not stripped
14716 out, but the variable address is set to null;
14717 do not add such variables into symbol table. */
14719 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14721 /* Workaround gfortran PR debug/40040 - it uses
14722 DW_AT_location for variables in -fPIC libraries which may
14723 get overriden by other libraries/executable and get
14724 a different address. Resolve it by the minimal symbol
14725 which may come from inferior's executable using copy
14726 relocation. Make this workaround only for gfortran as for
14727 other compilers GDB cannot guess the minimal symbol
14728 Fortran mangling kind. */
14729 if (cu
->language
== language_fortran
&& die
->parent
14730 && die
->parent
->tag
== DW_TAG_module
14732 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14733 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14735 /* A variable with DW_AT_external is never static,
14736 but it may be block-scoped. */
14737 list_to_add
= (cu
->list_in_scope
== &file_symbols
14738 ? &global_symbols
: cu
->list_in_scope
);
14741 list_to_add
= cu
->list_in_scope
;
14745 /* We do not know the address of this symbol.
14746 If it is an external symbol and we have type information
14747 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14748 The address of the variable will then be determined from
14749 the minimal symbol table whenever the variable is
14751 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14752 if (attr2
&& (DW_UNSND (attr2
) != 0)
14753 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14755 /* A variable with DW_AT_external is never static, but it
14756 may be block-scoped. */
14757 list_to_add
= (cu
->list_in_scope
== &file_symbols
14758 ? &global_symbols
: cu
->list_in_scope
);
14760 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14762 else if (!die_is_declaration (die
, cu
))
14764 /* Use the default LOC_OPTIMIZED_OUT class. */
14765 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
14767 list_to_add
= cu
->list_in_scope
;
14771 case DW_TAG_formal_parameter
:
14772 /* If we are inside a function, mark this as an argument. If
14773 not, we might be looking at an argument to an inlined function
14774 when we do not have enough information to show inlined frames;
14775 pretend it's a local variable in that case so that the user can
14777 if (context_stack_depth
> 0
14778 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
14779 SYMBOL_IS_ARGUMENT (sym
) = 1;
14780 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14783 var_decode_location (attr
, sym
, cu
);
14785 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14788 dwarf2_const_value (attr
, sym
, cu
);
14791 list_to_add
= cu
->list_in_scope
;
14793 case DW_TAG_unspecified_parameters
:
14794 /* From varargs functions; gdb doesn't seem to have any
14795 interest in this information, so just ignore it for now.
14798 case DW_TAG_template_type_param
:
14800 /* Fall through. */
14801 case DW_TAG_class_type
:
14802 case DW_TAG_interface_type
:
14803 case DW_TAG_structure_type
:
14804 case DW_TAG_union_type
:
14805 case DW_TAG_set_type
:
14806 case DW_TAG_enumeration_type
:
14807 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14808 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
14811 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
14812 really ever be static objects: otherwise, if you try
14813 to, say, break of a class's method and you're in a file
14814 which doesn't mention that class, it won't work unless
14815 the check for all static symbols in lookup_symbol_aux
14816 saves you. See the OtherFileClass tests in
14817 gdb.c++/namespace.exp. */
14821 list_to_add
= (cu
->list_in_scope
== &file_symbols
14822 && (cu
->language
== language_cplus
14823 || cu
->language
== language_java
)
14824 ? &global_symbols
: cu
->list_in_scope
);
14826 /* The semantics of C++ state that "struct foo {
14827 ... }" also defines a typedef for "foo". A Java
14828 class declaration also defines a typedef for the
14830 if (cu
->language
== language_cplus
14831 || cu
->language
== language_java
14832 || cu
->language
== language_ada
)
14834 /* The symbol's name is already allocated along
14835 with this objfile, so we don't need to
14836 duplicate it for the type. */
14837 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
14838 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
14843 case DW_TAG_typedef
:
14844 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14845 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14846 list_to_add
= cu
->list_in_scope
;
14848 case DW_TAG_base_type
:
14849 case DW_TAG_subrange_type
:
14850 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14851 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14852 list_to_add
= cu
->list_in_scope
;
14854 case DW_TAG_enumerator
:
14855 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14858 dwarf2_const_value (attr
, sym
, cu
);
14861 /* NOTE: carlton/2003-11-10: See comment above in the
14862 DW_TAG_class_type, etc. block. */
14864 list_to_add
= (cu
->list_in_scope
== &file_symbols
14865 && (cu
->language
== language_cplus
14866 || cu
->language
== language_java
)
14867 ? &global_symbols
: cu
->list_in_scope
);
14870 case DW_TAG_namespace
:
14871 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14872 list_to_add
= &global_symbols
;
14875 /* Not a tag we recognize. Hopefully we aren't processing
14876 trash data, but since we must specifically ignore things
14877 we don't recognize, there is nothing else we should do at
14879 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
14880 dwarf_tag_name (die
->tag
));
14886 sym
->hash_next
= objfile
->template_symbols
;
14887 objfile
->template_symbols
= sym
;
14888 list_to_add
= NULL
;
14891 if (list_to_add
!= NULL
)
14892 add_symbol_to_list (sym
, list_to_add
);
14894 /* For the benefit of old versions of GCC, check for anonymous
14895 namespaces based on the demangled name. */
14896 if (!processing_has_namespace_info
14897 && cu
->language
== language_cplus
)
14898 cp_scan_for_anonymous_namespaces (sym
, objfile
);
14903 /* A wrapper for new_symbol_full that always allocates a new symbol. */
14905 static struct symbol
*
14906 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14908 return new_symbol_full (die
, type
, cu
, NULL
);
14911 /* Given an attr with a DW_FORM_dataN value in host byte order,
14912 zero-extend it as appropriate for the symbol's type. The DWARF
14913 standard (v4) is not entirely clear about the meaning of using
14914 DW_FORM_dataN for a constant with a signed type, where the type is
14915 wider than the data. The conclusion of a discussion on the DWARF
14916 list was that this is unspecified. We choose to always zero-extend
14917 because that is the interpretation long in use by GCC. */
14920 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
14921 const char *name
, struct obstack
*obstack
,
14922 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
14924 struct objfile
*objfile
= cu
->objfile
;
14925 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
14926 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
14927 LONGEST l
= DW_UNSND (attr
);
14929 if (bits
< sizeof (*value
) * 8)
14931 l
&= ((LONGEST
) 1 << bits
) - 1;
14934 else if (bits
== sizeof (*value
) * 8)
14938 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
14939 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
14946 /* Read a constant value from an attribute. Either set *VALUE, or if
14947 the value does not fit in *VALUE, set *BYTES - either already
14948 allocated on the objfile obstack, or newly allocated on OBSTACK,
14949 or, set *BATON, if we translated the constant to a location
14953 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
14954 const char *name
, struct obstack
*obstack
,
14955 struct dwarf2_cu
*cu
,
14956 LONGEST
*value
, gdb_byte
**bytes
,
14957 struct dwarf2_locexpr_baton
**baton
)
14959 struct objfile
*objfile
= cu
->objfile
;
14960 struct comp_unit_head
*cu_header
= &cu
->header
;
14961 struct dwarf_block
*blk
;
14962 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
14963 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
14969 switch (attr
->form
)
14972 case DW_FORM_GNU_addr_index
:
14976 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14977 dwarf2_const_value_length_mismatch_complaint (name
,
14978 cu_header
->addr_size
,
14979 TYPE_LENGTH (type
));
14980 /* Symbols of this form are reasonably rare, so we just
14981 piggyback on the existing location code rather than writing
14982 a new implementation of symbol_computed_ops. */
14983 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14984 sizeof (struct dwarf2_locexpr_baton
));
14985 (*baton
)->per_cu
= cu
->per_cu
;
14986 gdb_assert ((*baton
)->per_cu
);
14988 (*baton
)->size
= 2 + cu_header
->addr_size
;
14989 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14990 (*baton
)->data
= data
;
14992 data
[0] = DW_OP_addr
;
14993 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14994 byte_order
, DW_ADDR (attr
));
14995 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14998 case DW_FORM_string
:
15000 case DW_FORM_GNU_str_index
:
15001 /* DW_STRING is already allocated on the objfile obstack, point
15003 *bytes
= (gdb_byte
*) DW_STRING (attr
);
15005 case DW_FORM_block1
:
15006 case DW_FORM_block2
:
15007 case DW_FORM_block4
:
15008 case DW_FORM_block
:
15009 case DW_FORM_exprloc
:
15010 blk
= DW_BLOCK (attr
);
15011 if (TYPE_LENGTH (type
) != blk
->size
)
15012 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
15013 TYPE_LENGTH (type
));
15014 *bytes
= blk
->data
;
15017 /* The DW_AT_const_value attributes are supposed to carry the
15018 symbol's value "represented as it would be on the target
15019 architecture." By the time we get here, it's already been
15020 converted to host endianness, so we just need to sign- or
15021 zero-extend it as appropriate. */
15022 case DW_FORM_data1
:
15023 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15024 obstack
, cu
, value
, 8);
15026 case DW_FORM_data2
:
15027 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15028 obstack
, cu
, value
, 16);
15030 case DW_FORM_data4
:
15031 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15032 obstack
, cu
, value
, 32);
15034 case DW_FORM_data8
:
15035 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15036 obstack
, cu
, value
, 64);
15039 case DW_FORM_sdata
:
15040 *value
= DW_SND (attr
);
15043 case DW_FORM_udata
:
15044 *value
= DW_UNSND (attr
);
15048 complaint (&symfile_complaints
,
15049 _("unsupported const value attribute form: '%s'"),
15050 dwarf_form_name (attr
->form
));
15057 /* Copy constant value from an attribute to a symbol. */
15060 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
15061 struct dwarf2_cu
*cu
)
15063 struct objfile
*objfile
= cu
->objfile
;
15064 struct comp_unit_head
*cu_header
= &cu
->header
;
15067 struct dwarf2_locexpr_baton
*baton
;
15069 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
15070 SYMBOL_PRINT_NAME (sym
),
15071 &objfile
->objfile_obstack
, cu
,
15072 &value
, &bytes
, &baton
);
15076 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15077 SYMBOL_LOCATION_BATON (sym
) = baton
;
15078 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15080 else if (bytes
!= NULL
)
15082 SYMBOL_VALUE_BYTES (sym
) = bytes
;
15083 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
15087 SYMBOL_VALUE (sym
) = value
;
15088 SYMBOL_CLASS (sym
) = LOC_CONST
;
15092 /* Return the type of the die in question using its DW_AT_type attribute. */
15094 static struct type
*
15095 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15097 struct attribute
*type_attr
;
15099 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15102 /* A missing DW_AT_type represents a void type. */
15103 return objfile_type (cu
->objfile
)->builtin_void
;
15106 return lookup_die_type (die
, type_attr
, cu
);
15109 /* True iff CU's producer generates GNAT Ada auxiliary information
15110 that allows to find parallel types through that information instead
15111 of having to do expensive parallel lookups by type name. */
15114 need_gnat_info (struct dwarf2_cu
*cu
)
15116 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
15117 of GNAT produces this auxiliary information, without any indication
15118 that it is produced. Part of enhancing the FSF version of GNAT
15119 to produce that information will be to put in place an indicator
15120 that we can use in order to determine whether the descriptive type
15121 info is available or not. One suggestion that has been made is
15122 to use a new attribute, attached to the CU die. For now, assume
15123 that the descriptive type info is not available. */
15127 /* Return the auxiliary type of the die in question using its
15128 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
15129 attribute is not present. */
15131 static struct type
*
15132 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15134 struct attribute
*type_attr
;
15136 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15140 return lookup_die_type (die
, type_attr
, cu
);
15143 /* If DIE has a descriptive_type attribute, then set the TYPE's
15144 descriptive type accordingly. */
15147 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15148 struct dwarf2_cu
*cu
)
15150 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15152 if (descriptive_type
)
15154 ALLOCATE_GNAT_AUX_TYPE (type
);
15155 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15159 /* Return the containing type of the die in question using its
15160 DW_AT_containing_type attribute. */
15162 static struct type
*
15163 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15165 struct attribute
*type_attr
;
15167 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15169 error (_("Dwarf Error: Problem turning containing type into gdb type "
15170 "[in module %s]"), cu
->objfile
->name
);
15172 return lookup_die_type (die
, type_attr
, cu
);
15175 /* Look up the type of DIE in CU using its type attribute ATTR.
15176 If there is no type substitute an error marker. */
15178 static struct type
*
15179 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15180 struct dwarf2_cu
*cu
)
15182 struct objfile
*objfile
= cu
->objfile
;
15183 struct type
*this_type
;
15185 /* First see if we have it cached. */
15187 if (is_ref_attr (attr
))
15189 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15191 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15193 else if (attr
->form
== DW_FORM_ref_sig8
)
15195 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15197 /* sig_type will be NULL if the signatured type is missing from
15199 if (sig_type
== NULL
)
15200 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15201 "at 0x%x [in module %s]"),
15202 die
->offset
.sect_off
, objfile
->name
);
15204 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15205 /* If we haven't filled in type_offset_in_section yet, then we
15206 haven't read the type in yet. */
15208 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15211 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15212 &sig_type
->per_cu
);
15217 dump_die_for_error (die
);
15218 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15219 dwarf_attr_name (attr
->name
), objfile
->name
);
15222 /* If not cached we need to read it in. */
15224 if (this_type
== NULL
)
15226 struct die_info
*type_die
;
15227 struct dwarf2_cu
*type_cu
= cu
;
15229 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15230 /* If we found the type now, it's probably because the type came
15231 from an inter-CU reference and the type's CU got expanded before
15233 this_type
= get_die_type (type_die
, type_cu
);
15234 if (this_type
== NULL
)
15235 this_type
= read_type_die_1 (type_die
, type_cu
);
15238 /* If we still don't have a type use an error marker. */
15240 if (this_type
== NULL
)
15242 char *message
, *saved
;
15244 /* read_type_die already issued a complaint. */
15245 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15247 cu
->header
.offset
.sect_off
,
15248 die
->offset
.sect_off
);
15249 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15250 message
, strlen (message
));
15253 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15259 /* Return the type in DIE, CU.
15260 Returns NULL for invalid types.
15262 This first does a lookup in the appropriate type_hash table,
15263 and only reads the die in if necessary.
15265 NOTE: This can be called when reading in partial or full symbols. */
15267 static struct type
*
15268 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15270 struct type
*this_type
;
15272 this_type
= get_die_type (die
, cu
);
15276 return read_type_die_1 (die
, cu
);
15279 /* Read the type in DIE, CU.
15280 Returns NULL for invalid types. */
15282 static struct type
*
15283 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15285 struct type
*this_type
= NULL
;
15289 case DW_TAG_class_type
:
15290 case DW_TAG_interface_type
:
15291 case DW_TAG_structure_type
:
15292 case DW_TAG_union_type
:
15293 this_type
= read_structure_type (die
, cu
);
15295 case DW_TAG_enumeration_type
:
15296 this_type
= read_enumeration_type (die
, cu
);
15298 case DW_TAG_subprogram
:
15299 case DW_TAG_subroutine_type
:
15300 case DW_TAG_inlined_subroutine
:
15301 this_type
= read_subroutine_type (die
, cu
);
15303 case DW_TAG_array_type
:
15304 this_type
= read_array_type (die
, cu
);
15306 case DW_TAG_set_type
:
15307 this_type
= read_set_type (die
, cu
);
15309 case DW_TAG_pointer_type
:
15310 this_type
= read_tag_pointer_type (die
, cu
);
15312 case DW_TAG_ptr_to_member_type
:
15313 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15315 case DW_TAG_reference_type
:
15316 this_type
= read_tag_reference_type (die
, cu
);
15318 case DW_TAG_const_type
:
15319 this_type
= read_tag_const_type (die
, cu
);
15321 case DW_TAG_volatile_type
:
15322 this_type
= read_tag_volatile_type (die
, cu
);
15324 case DW_TAG_string_type
:
15325 this_type
= read_tag_string_type (die
, cu
);
15327 case DW_TAG_typedef
:
15328 this_type
= read_typedef (die
, cu
);
15330 case DW_TAG_subrange_type
:
15331 this_type
= read_subrange_type (die
, cu
);
15333 case DW_TAG_base_type
:
15334 this_type
= read_base_type (die
, cu
);
15336 case DW_TAG_unspecified_type
:
15337 this_type
= read_unspecified_type (die
, cu
);
15339 case DW_TAG_namespace
:
15340 this_type
= read_namespace_type (die
, cu
);
15342 case DW_TAG_module
:
15343 this_type
= read_module_type (die
, cu
);
15346 complaint (&symfile_complaints
,
15347 _("unexpected tag in read_type_die: '%s'"),
15348 dwarf_tag_name (die
->tag
));
15355 /* See if we can figure out if the class lives in a namespace. We do
15356 this by looking for a member function; its demangled name will
15357 contain namespace info, if there is any.
15358 Return the computed name or NULL.
15359 Space for the result is allocated on the objfile's obstack.
15360 This is the full-die version of guess_partial_die_structure_name.
15361 In this case we know DIE has no useful parent. */
15364 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15366 struct die_info
*spec_die
;
15367 struct dwarf2_cu
*spec_cu
;
15368 struct die_info
*child
;
15371 spec_die
= die_specification (die
, &spec_cu
);
15372 if (spec_die
!= NULL
)
15378 for (child
= die
->child
;
15380 child
= child
->sibling
)
15382 if (child
->tag
== DW_TAG_subprogram
)
15384 struct attribute
*attr
;
15386 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15388 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15392 = language_class_name_from_physname (cu
->language_defn
,
15396 if (actual_name
!= NULL
)
15398 char *die_name
= dwarf2_name (die
, cu
);
15400 if (die_name
!= NULL
15401 && strcmp (die_name
, actual_name
) != 0)
15403 /* Strip off the class name from the full name.
15404 We want the prefix. */
15405 int die_name_len
= strlen (die_name
);
15406 int actual_name_len
= strlen (actual_name
);
15408 /* Test for '::' as a sanity check. */
15409 if (actual_name_len
> die_name_len
+ 2
15410 && actual_name
[actual_name_len
15411 - die_name_len
- 1] == ':')
15413 obsavestring (actual_name
,
15414 actual_name_len
- die_name_len
- 2,
15415 &cu
->objfile
->objfile_obstack
);
15418 xfree (actual_name
);
15427 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15428 prefix part in such case. See
15429 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15432 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15434 struct attribute
*attr
;
15437 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15438 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15441 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15442 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15445 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15447 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15448 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15451 /* dwarf2_name had to be already called. */
15452 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15454 /* Strip the base name, keep any leading namespaces/classes. */
15455 base
= strrchr (DW_STRING (attr
), ':');
15456 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15459 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15460 &cu
->objfile
->objfile_obstack
);
15463 /* Return the name of the namespace/class that DIE is defined within,
15464 or "" if we can't tell. The caller should not xfree the result.
15466 For example, if we're within the method foo() in the following
15476 then determine_prefix on foo's die will return "N::C". */
15478 static const char *
15479 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15481 struct die_info
*parent
, *spec_die
;
15482 struct dwarf2_cu
*spec_cu
;
15483 struct type
*parent_type
;
15486 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15487 && cu
->language
!= language_fortran
)
15490 retval
= anonymous_struct_prefix (die
, cu
);
15494 /* We have to be careful in the presence of DW_AT_specification.
15495 For example, with GCC 3.4, given the code
15499 // Definition of N::foo.
15503 then we'll have a tree of DIEs like this:
15505 1: DW_TAG_compile_unit
15506 2: DW_TAG_namespace // N
15507 3: DW_TAG_subprogram // declaration of N::foo
15508 4: DW_TAG_subprogram // definition of N::foo
15509 DW_AT_specification // refers to die #3
15511 Thus, when processing die #4, we have to pretend that we're in
15512 the context of its DW_AT_specification, namely the contex of die
15515 spec_die
= die_specification (die
, &spec_cu
);
15516 if (spec_die
== NULL
)
15517 parent
= die
->parent
;
15520 parent
= spec_die
->parent
;
15524 if (parent
== NULL
)
15526 else if (parent
->building_fullname
)
15529 const char *parent_name
;
15531 /* It has been seen on RealView 2.2 built binaries,
15532 DW_TAG_template_type_param types actually _defined_ as
15533 children of the parent class:
15536 template class <class Enum> Class{};
15537 Class<enum E> class_e;
15539 1: DW_TAG_class_type (Class)
15540 2: DW_TAG_enumeration_type (E)
15541 3: DW_TAG_enumerator (enum1:0)
15542 3: DW_TAG_enumerator (enum2:1)
15544 2: DW_TAG_template_type_param
15545 DW_AT_type DW_FORM_ref_udata (E)
15547 Besides being broken debug info, it can put GDB into an
15548 infinite loop. Consider:
15550 When we're building the full name for Class<E>, we'll start
15551 at Class, and go look over its template type parameters,
15552 finding E. We'll then try to build the full name of E, and
15553 reach here. We're now trying to build the full name of E,
15554 and look over the parent DIE for containing scope. In the
15555 broken case, if we followed the parent DIE of E, we'd again
15556 find Class, and once again go look at its template type
15557 arguments, etc., etc. Simply don't consider such parent die
15558 as source-level parent of this die (it can't be, the language
15559 doesn't allow it), and break the loop here. */
15560 name
= dwarf2_name (die
, cu
);
15561 parent_name
= dwarf2_name (parent
, cu
);
15562 complaint (&symfile_complaints
,
15563 _("template param type '%s' defined within parent '%s'"),
15564 name
? name
: "<unknown>",
15565 parent_name
? parent_name
: "<unknown>");
15569 switch (parent
->tag
)
15571 case DW_TAG_namespace
:
15572 parent_type
= read_type_die (parent
, cu
);
15573 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15574 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15575 Work around this problem here. */
15576 if (cu
->language
== language_cplus
15577 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15579 /* We give a name to even anonymous namespaces. */
15580 return TYPE_TAG_NAME (parent_type
);
15581 case DW_TAG_class_type
:
15582 case DW_TAG_interface_type
:
15583 case DW_TAG_structure_type
:
15584 case DW_TAG_union_type
:
15585 case DW_TAG_module
:
15586 parent_type
= read_type_die (parent
, cu
);
15587 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15588 return TYPE_TAG_NAME (parent_type
);
15590 /* An anonymous structure is only allowed non-static data
15591 members; no typedefs, no member functions, et cetera.
15592 So it does not need a prefix. */
15594 case DW_TAG_compile_unit
:
15595 case DW_TAG_partial_unit
:
15596 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15597 if (cu
->language
== language_cplus
15598 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15599 && die
->child
!= NULL
15600 && (die
->tag
== DW_TAG_class_type
15601 || die
->tag
== DW_TAG_structure_type
15602 || die
->tag
== DW_TAG_union_type
))
15604 char *name
= guess_full_die_structure_name (die
, cu
);
15610 return determine_prefix (parent
, cu
);
15614 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15615 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15616 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15617 an obconcat, otherwise allocate storage for the result. The CU argument is
15618 used to determine the language and hence, the appropriate separator. */
15620 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15623 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15624 int physname
, struct dwarf2_cu
*cu
)
15626 const char *lead
= "";
15629 if (suffix
== NULL
|| suffix
[0] == '\0'
15630 || prefix
== NULL
|| prefix
[0] == '\0')
15632 else if (cu
->language
== language_java
)
15634 else if (cu
->language
== language_fortran
&& physname
)
15636 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15637 DW_AT_MIPS_linkage_name is preferred and used instead. */
15645 if (prefix
== NULL
)
15647 if (suffix
== NULL
)
15653 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15655 strcpy (retval
, lead
);
15656 strcat (retval
, prefix
);
15657 strcat (retval
, sep
);
15658 strcat (retval
, suffix
);
15663 /* We have an obstack. */
15664 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15668 /* Return sibling of die, NULL if no sibling. */
15670 static struct die_info
*
15671 sibling_die (struct die_info
*die
)
15673 return die
->sibling
;
15676 /* Get name of a die, return NULL if not found. */
15679 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15680 struct obstack
*obstack
)
15682 if (name
&& cu
->language
== language_cplus
)
15684 char *canon_name
= cp_canonicalize_string (name
);
15686 if (canon_name
!= NULL
)
15688 if (strcmp (canon_name
, name
) != 0)
15689 name
= obsavestring (canon_name
, strlen (canon_name
),
15691 xfree (canon_name
);
15698 /* Get name of a die, return NULL if not found. */
15701 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15703 struct attribute
*attr
;
15705 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15706 if ((!attr
|| !DW_STRING (attr
))
15707 && die
->tag
!= DW_TAG_class_type
15708 && die
->tag
!= DW_TAG_interface_type
15709 && die
->tag
!= DW_TAG_structure_type
15710 && die
->tag
!= DW_TAG_union_type
)
15715 case DW_TAG_compile_unit
:
15716 case DW_TAG_partial_unit
:
15717 /* Compilation units have a DW_AT_name that is a filename, not
15718 a source language identifier. */
15719 case DW_TAG_enumeration_type
:
15720 case DW_TAG_enumerator
:
15721 /* These tags always have simple identifiers already; no need
15722 to canonicalize them. */
15723 return DW_STRING (attr
);
15725 case DW_TAG_subprogram
:
15726 /* Java constructors will all be named "<init>", so return
15727 the class name when we see this special case. */
15728 if (cu
->language
== language_java
15729 && DW_STRING (attr
) != NULL
15730 && strcmp (DW_STRING (attr
), "<init>") == 0)
15732 struct dwarf2_cu
*spec_cu
= cu
;
15733 struct die_info
*spec_die
;
15735 /* GCJ will output '<init>' for Java constructor names.
15736 For this special case, return the name of the parent class. */
15738 /* GCJ may output suprogram DIEs with AT_specification set.
15739 If so, use the name of the specified DIE. */
15740 spec_die
= die_specification (die
, &spec_cu
);
15741 if (spec_die
!= NULL
)
15742 return dwarf2_name (spec_die
, spec_cu
);
15747 if (die
->tag
== DW_TAG_class_type
)
15748 return dwarf2_name (die
, cu
);
15750 while (die
->tag
!= DW_TAG_compile_unit
15751 && die
->tag
!= DW_TAG_partial_unit
);
15755 case DW_TAG_class_type
:
15756 case DW_TAG_interface_type
:
15757 case DW_TAG_structure_type
:
15758 case DW_TAG_union_type
:
15759 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
15760 structures or unions. These were of the form "._%d" in GCC 4.1,
15761 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
15762 and GCC 4.4. We work around this problem by ignoring these. */
15763 if (attr
&& DW_STRING (attr
)
15764 && (strncmp (DW_STRING (attr
), "._", 2) == 0
15765 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
15768 /* GCC might emit a nameless typedef that has a linkage name. See
15769 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15770 if (!attr
|| DW_STRING (attr
) == NULL
)
15772 char *demangled
= NULL
;
15774 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15776 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15778 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15781 /* Avoid demangling DW_STRING (attr) the second time on a second
15782 call for the same DIE. */
15783 if (!DW_STRING_IS_CANONICAL (attr
))
15784 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
15790 /* FIXME: we already did this for the partial symbol... */
15791 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
15792 &cu
->objfile
->objfile_obstack
);
15793 DW_STRING_IS_CANONICAL (attr
) = 1;
15796 /* Strip any leading namespaces/classes, keep only the base name.
15797 DW_AT_name for named DIEs does not contain the prefixes. */
15798 base
= strrchr (DW_STRING (attr
), ':');
15799 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
15802 return DW_STRING (attr
);
15811 if (!DW_STRING_IS_CANONICAL (attr
))
15814 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
15815 &cu
->objfile
->objfile_obstack
);
15816 DW_STRING_IS_CANONICAL (attr
) = 1;
15818 return DW_STRING (attr
);
15821 /* Return the die that this die in an extension of, or NULL if there
15822 is none. *EXT_CU is the CU containing DIE on input, and the CU
15823 containing the return value on output. */
15825 static struct die_info
*
15826 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
15828 struct attribute
*attr
;
15830 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
15834 return follow_die_ref (die
, attr
, ext_cu
);
15837 /* Convert a DIE tag into its string name. */
15839 static const char *
15840 dwarf_tag_name (unsigned tag
)
15842 const char *name
= get_DW_TAG_name (tag
);
15845 return "DW_TAG_<unknown>";
15850 /* Convert a DWARF attribute code into its string name. */
15852 static const char *
15853 dwarf_attr_name (unsigned attr
)
15857 #ifdef MIPS /* collides with DW_AT_HP_block_index */
15858 if (attr
== DW_AT_MIPS_fde
)
15859 return "DW_AT_MIPS_fde";
15861 if (attr
== DW_AT_HP_block_index
)
15862 return "DW_AT_HP_block_index";
15865 name
= get_DW_AT_name (attr
);
15868 return "DW_AT_<unknown>";
15873 /* Convert a DWARF value form code into its string name. */
15875 static const char *
15876 dwarf_form_name (unsigned form
)
15878 const char *name
= get_DW_FORM_name (form
);
15881 return "DW_FORM_<unknown>";
15887 dwarf_bool_name (unsigned mybool
)
15895 /* Convert a DWARF type code into its string name. */
15897 static const char *
15898 dwarf_type_encoding_name (unsigned enc
)
15900 const char *name
= get_DW_ATE_name (enc
);
15903 return "DW_ATE_<unknown>";
15909 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15913 print_spaces (indent
, f
);
15914 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15915 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15917 if (die
->parent
!= NULL
)
15919 print_spaces (indent
, f
);
15920 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15921 die
->parent
->offset
.sect_off
);
15924 print_spaces (indent
, f
);
15925 fprintf_unfiltered (f
, " has children: %s\n",
15926 dwarf_bool_name (die
->child
!= NULL
));
15928 print_spaces (indent
, f
);
15929 fprintf_unfiltered (f
, " attributes:\n");
15931 for (i
= 0; i
< die
->num_attrs
; ++i
)
15933 print_spaces (indent
, f
);
15934 fprintf_unfiltered (f
, " %s (%s) ",
15935 dwarf_attr_name (die
->attrs
[i
].name
),
15936 dwarf_form_name (die
->attrs
[i
].form
));
15938 switch (die
->attrs
[i
].form
)
15941 case DW_FORM_GNU_addr_index
:
15942 fprintf_unfiltered (f
, "address: ");
15943 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15945 case DW_FORM_block2
:
15946 case DW_FORM_block4
:
15947 case DW_FORM_block
:
15948 case DW_FORM_block1
:
15949 fprintf_unfiltered (f
, "block: size %d",
15950 DW_BLOCK (&die
->attrs
[i
])->size
);
15952 case DW_FORM_exprloc
:
15953 fprintf_unfiltered (f
, "expression: size %u",
15954 DW_BLOCK (&die
->attrs
[i
])->size
);
15956 case DW_FORM_ref_addr
:
15957 fprintf_unfiltered (f
, "ref address: ");
15958 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15964 case DW_FORM_ref_udata
:
15965 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15966 (long) (DW_UNSND (&die
->attrs
[i
])));
15968 case DW_FORM_data1
:
15969 case DW_FORM_data2
:
15970 case DW_FORM_data4
:
15971 case DW_FORM_data8
:
15972 case DW_FORM_udata
:
15973 case DW_FORM_sdata
:
15974 fprintf_unfiltered (f
, "constant: %s",
15975 pulongest (DW_UNSND (&die
->attrs
[i
])));
15977 case DW_FORM_sec_offset
:
15978 fprintf_unfiltered (f
, "section offset: %s",
15979 pulongest (DW_UNSND (&die
->attrs
[i
])));
15981 case DW_FORM_ref_sig8
:
15982 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15983 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15984 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15986 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15988 case DW_FORM_string
:
15990 case DW_FORM_GNU_str_index
:
15991 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15992 DW_STRING (&die
->attrs
[i
])
15993 ? DW_STRING (&die
->attrs
[i
]) : "",
15994 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15997 if (DW_UNSND (&die
->attrs
[i
]))
15998 fprintf_unfiltered (f
, "flag: TRUE");
16000 fprintf_unfiltered (f
, "flag: FALSE");
16002 case DW_FORM_flag_present
:
16003 fprintf_unfiltered (f
, "flag: TRUE");
16005 case DW_FORM_indirect
:
16006 /* The reader will have reduced the indirect form to
16007 the "base form" so this form should not occur. */
16008 fprintf_unfiltered (f
,
16009 "unexpected attribute form: DW_FORM_indirect");
16012 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
16013 die
->attrs
[i
].form
);
16016 fprintf_unfiltered (f
, "\n");
16021 dump_die_for_error (struct die_info
*die
)
16023 dump_die_shallow (gdb_stderr
, 0, die
);
16027 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
16029 int indent
= level
* 4;
16031 gdb_assert (die
!= NULL
);
16033 if (level
>= max_level
)
16036 dump_die_shallow (f
, indent
, die
);
16038 if (die
->child
!= NULL
)
16040 print_spaces (indent
, f
);
16041 fprintf_unfiltered (f
, " Children:");
16042 if (level
+ 1 < max_level
)
16044 fprintf_unfiltered (f
, "\n");
16045 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
16049 fprintf_unfiltered (f
,
16050 " [not printed, max nesting level reached]\n");
16054 if (die
->sibling
!= NULL
&& level
> 0)
16056 dump_die_1 (f
, level
, max_level
, die
->sibling
);
16060 /* This is called from the pdie macro in gdbinit.in.
16061 It's not static so gcc will keep a copy callable from gdb. */
16064 dump_die (struct die_info
*die
, int max_level
)
16066 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
16070 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
16074 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
16080 /* DW_ADDR is always stored already as sect_offset; despite for the forms
16081 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
16084 is_ref_attr (struct attribute
*attr
)
16086 switch (attr
->form
)
16088 case DW_FORM_ref_addr
:
16093 case DW_FORM_ref_udata
:
16100 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
16104 dwarf2_get_ref_die_offset (struct attribute
*attr
)
16106 sect_offset retval
= { DW_UNSND (attr
) };
16108 if (is_ref_attr (attr
))
16111 retval
.sect_off
= 0;
16112 complaint (&symfile_complaints
,
16113 _("unsupported die ref attribute form: '%s'"),
16114 dwarf_form_name (attr
->form
));
16118 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
16119 * the value held by the attribute is not constant. */
16122 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
16124 if (attr
->form
== DW_FORM_sdata
)
16125 return DW_SND (attr
);
16126 else if (attr
->form
== DW_FORM_udata
16127 || attr
->form
== DW_FORM_data1
16128 || attr
->form
== DW_FORM_data2
16129 || attr
->form
== DW_FORM_data4
16130 || attr
->form
== DW_FORM_data8
)
16131 return DW_UNSND (attr
);
16134 complaint (&symfile_complaints
,
16135 _("Attribute value is not a constant (%s)"),
16136 dwarf_form_name (attr
->form
));
16137 return default_value
;
16141 /* Follow reference or signature attribute ATTR of SRC_DIE.
16142 On entry *REF_CU is the CU of SRC_DIE.
16143 On exit *REF_CU is the CU of the result. */
16145 static struct die_info
*
16146 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16147 struct dwarf2_cu
**ref_cu
)
16149 struct die_info
*die
;
16151 if (is_ref_attr (attr
))
16152 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16153 else if (attr
->form
== DW_FORM_ref_sig8
)
16154 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16157 dump_die_for_error (src_die
);
16158 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16159 (*ref_cu
)->objfile
->name
);
16165 /* Follow reference OFFSET.
16166 On entry *REF_CU is the CU of the source die referencing OFFSET.
16167 On exit *REF_CU is the CU of the result.
16168 Returns NULL if OFFSET is invalid. */
16170 static struct die_info
*
16171 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
16173 struct die_info temp_die
;
16174 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16176 gdb_assert (cu
->per_cu
!= NULL
);
16180 if (cu
->per_cu
->is_debug_types
)
16182 /* .debug_types CUs cannot reference anything outside their CU.
16183 If they need to, they have to reference a signatured type via
16184 DW_FORM_ref_sig8. */
16185 if (! offset_in_cu_p (&cu
->header
, offset
))
16188 else if (! offset_in_cu_p (&cu
->header
, offset
))
16190 struct dwarf2_per_cu_data
*per_cu
;
16192 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
16194 /* If necessary, add it to the queue and load its DIEs. */
16195 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16196 load_full_comp_unit (per_cu
, cu
->language
);
16198 target_cu
= per_cu
->cu
;
16200 else if (cu
->dies
== NULL
)
16202 /* We're loading full DIEs during partial symbol reading. */
16203 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16204 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16207 *ref_cu
= target_cu
;
16208 temp_die
.offset
= offset
;
16209 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16212 /* Follow reference attribute ATTR of SRC_DIE.
16213 On entry *REF_CU is the CU of SRC_DIE.
16214 On exit *REF_CU is the CU of the result. */
16216 static struct die_info
*
16217 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16218 struct dwarf2_cu
**ref_cu
)
16220 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16221 struct dwarf2_cu
*cu
= *ref_cu
;
16222 struct die_info
*die
;
16224 die
= follow_die_offset (offset
, ref_cu
);
16226 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16227 "at 0x%x [in module %s]"),
16228 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16233 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16234 Returned value is intended for DW_OP_call*. Returned
16235 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16237 struct dwarf2_locexpr_baton
16238 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16239 struct dwarf2_per_cu_data
*per_cu
,
16240 CORE_ADDR (*get_frame_pc
) (void *baton
),
16243 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16244 struct dwarf2_cu
*cu
;
16245 struct die_info
*die
;
16246 struct attribute
*attr
;
16247 struct dwarf2_locexpr_baton retval
;
16249 dw2_setup (per_cu
->objfile
);
16251 if (per_cu
->cu
== NULL
)
16255 die
= follow_die_offset (offset
, &cu
);
16257 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16258 offset
.sect_off
, per_cu
->objfile
->name
);
16260 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16263 /* DWARF: "If there is no such attribute, then there is no effect.".
16264 DATA is ignored if SIZE is 0. */
16266 retval
.data
= NULL
;
16269 else if (attr_form_is_section_offset (attr
))
16271 struct dwarf2_loclist_baton loclist_baton
;
16272 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16275 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16277 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16279 retval
.size
= size
;
16283 if (!attr_form_is_block (attr
))
16284 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16285 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16286 offset
.sect_off
, per_cu
->objfile
->name
);
16288 retval
.data
= DW_BLOCK (attr
)->data
;
16289 retval
.size
= DW_BLOCK (attr
)->size
;
16291 retval
.per_cu
= cu
->per_cu
;
16293 age_cached_comp_units ();
16298 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16302 dwarf2_get_die_type (cu_offset die_offset
,
16303 struct dwarf2_per_cu_data
*per_cu
)
16305 sect_offset die_offset_sect
;
16307 dw2_setup (per_cu
->objfile
);
16309 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16310 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16313 /* Follow the signature attribute ATTR in SRC_DIE.
16314 On entry *REF_CU is the CU of SRC_DIE.
16315 On exit *REF_CU is the CU of the result. */
16317 static struct die_info
*
16318 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16319 struct dwarf2_cu
**ref_cu
)
16321 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16322 struct die_info temp_die
;
16323 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16324 struct dwarf2_cu
*sig_cu
;
16325 struct die_info
*die
;
16327 /* sig_type will be NULL if the signatured type is missing from
16329 if (sig_type
== NULL
)
16330 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16331 "at 0x%x [in module %s]"),
16332 src_die
->offset
.sect_off
, objfile
->name
);
16334 /* If necessary, add it to the queue and load its DIEs. */
16336 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16337 read_signatured_type (sig_type
);
16339 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16341 sig_cu
= sig_type
->per_cu
.cu
;
16342 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16343 temp_die
.offset
= sig_type
->type_offset_in_section
;
16344 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16345 temp_die
.offset
.sect_off
);
16352 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16353 "from DIE at 0x%x [in module %s]"),
16354 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16357 /* Given an offset of a signatured type, return its signatured_type. */
16359 static struct signatured_type
*
16360 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16361 struct dwarf2_section_info
*section
,
16362 sect_offset offset
)
16364 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16365 unsigned int length
, initial_length_size
;
16366 unsigned int sig_offset
;
16367 struct signatured_type find_entry
, *sig_type
;
16369 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16370 sig_offset
= (initial_length_size
16372 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16373 + 1 /*address_size*/);
16374 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16375 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16377 /* This is only used to lookup previously recorded types.
16378 If we didn't find it, it's our bug. */
16379 gdb_assert (sig_type
!= NULL
);
16380 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16385 /* Load the DIEs associated with type unit PER_CU into memory. */
16388 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16390 struct signatured_type
*sig_type
;
16392 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16393 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16395 /* We have the per_cu, but we need the signatured_type.
16396 Fortunately this is an easy translation. */
16397 gdb_assert (per_cu
->is_debug_types
);
16398 sig_type
= (struct signatured_type
*) per_cu
;
16400 gdb_assert (per_cu
->cu
== NULL
);
16402 read_signatured_type (sig_type
);
16404 gdb_assert (per_cu
->cu
!= NULL
);
16407 /* die_reader_func for read_signatured_type.
16408 This is identical to load_full_comp_unit_reader,
16409 but is kept separate for now. */
16412 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16413 gdb_byte
*info_ptr
,
16414 struct die_info
*comp_unit_die
,
16418 struct dwarf2_cu
*cu
= reader
->cu
;
16420 gdb_assert (cu
->die_hash
== NULL
);
16422 htab_create_alloc_ex (cu
->header
.length
/ 12,
16426 &cu
->comp_unit_obstack
,
16427 hashtab_obstack_allocate
,
16428 dummy_obstack_deallocate
);
16431 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16432 &info_ptr
, comp_unit_die
);
16433 cu
->dies
= comp_unit_die
;
16434 /* comp_unit_die is not stored in die_hash, no need. */
16436 /* We try not to read any attributes in this function, because not
16437 all CUs needed for references have been loaded yet, and symbol
16438 table processing isn't initialized. But we have to set the CU language,
16439 or we won't be able to build types correctly.
16440 Similarly, if we do not read the producer, we can not apply
16441 producer-specific interpretation. */
16442 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16445 /* Read in a signatured type and build its CU and DIEs.
16446 If the type is a stub for the real type in a DWO file,
16447 read in the real type from the DWO file as well. */
16450 read_signatured_type (struct signatured_type
*sig_type
)
16452 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16454 gdb_assert (per_cu
->is_debug_types
);
16455 gdb_assert (per_cu
->cu
== NULL
);
16457 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16458 read_signatured_type_reader
, NULL
);
16461 /* Decode simple location descriptions.
16462 Given a pointer to a dwarf block that defines a location, compute
16463 the location and return the value.
16465 NOTE drow/2003-11-18: This function is called in two situations
16466 now: for the address of static or global variables (partial symbols
16467 only) and for offsets into structures which are expected to be
16468 (more or less) constant. The partial symbol case should go away,
16469 and only the constant case should remain. That will let this
16470 function complain more accurately. A few special modes are allowed
16471 without complaint for global variables (for instance, global
16472 register values and thread-local values).
16474 A location description containing no operations indicates that the
16475 object is optimized out. The return value is 0 for that case.
16476 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16477 callers will only want a very basic result and this can become a
16480 Note that stack[0] is unused except as a default error return. */
16483 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16485 struct objfile
*objfile
= cu
->objfile
;
16487 int size
= blk
->size
;
16488 gdb_byte
*data
= blk
->data
;
16489 CORE_ADDR stack
[64];
16491 unsigned int bytes_read
, unsnd
;
16497 stack
[++stacki
] = 0;
16536 stack
[++stacki
] = op
- DW_OP_lit0
;
16571 stack
[++stacki
] = op
- DW_OP_reg0
;
16573 dwarf2_complex_location_expr_complaint ();
16577 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16579 stack
[++stacki
] = unsnd
;
16581 dwarf2_complex_location_expr_complaint ();
16585 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16590 case DW_OP_const1u
:
16591 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16595 case DW_OP_const1s
:
16596 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16600 case DW_OP_const2u
:
16601 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16605 case DW_OP_const2s
:
16606 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16610 case DW_OP_const4u
:
16611 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16615 case DW_OP_const4s
:
16616 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16620 case DW_OP_const8u
:
16621 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16626 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16632 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16637 stack
[stacki
+ 1] = stack
[stacki
];
16642 stack
[stacki
- 1] += stack
[stacki
];
16646 case DW_OP_plus_uconst
:
16647 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16653 stack
[stacki
- 1] -= stack
[stacki
];
16658 /* If we're not the last op, then we definitely can't encode
16659 this using GDB's address_class enum. This is valid for partial
16660 global symbols, although the variable's address will be bogus
16663 dwarf2_complex_location_expr_complaint ();
16666 case DW_OP_GNU_push_tls_address
:
16667 /* The top of the stack has the offset from the beginning
16668 of the thread control block at which the variable is located. */
16669 /* Nothing should follow this operator, so the top of stack would
16671 /* This is valid for partial global symbols, but the variable's
16672 address will be bogus in the psymtab. Make it always at least
16673 non-zero to not look as a variable garbage collected by linker
16674 which have DW_OP_addr 0. */
16676 dwarf2_complex_location_expr_complaint ();
16680 case DW_OP_GNU_uninit
:
16683 case DW_OP_GNU_addr_index
:
16684 case DW_OP_GNU_const_index
:
16685 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16692 const char *name
= get_DW_OP_name (op
);
16695 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16698 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16702 return (stack
[stacki
]);
16705 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16706 outside of the allocated space. Also enforce minimum>0. */
16707 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16709 complaint (&symfile_complaints
,
16710 _("location description stack overflow"));
16716 complaint (&symfile_complaints
,
16717 _("location description stack underflow"));
16721 return (stack
[stacki
]);
16724 /* memory allocation interface */
16726 static struct dwarf_block
*
16727 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16729 struct dwarf_block
*blk
;
16731 blk
= (struct dwarf_block
*)
16732 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16736 static struct die_info
*
16737 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16739 struct die_info
*die
;
16740 size_t size
= sizeof (struct die_info
);
16743 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16745 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16746 memset (die
, 0, sizeof (struct die_info
));
16751 /* Macro support. */
16753 /* Return the full name of file number I in *LH's file name table.
16754 Use COMP_DIR as the name of the current directory of the
16755 compilation. The result is allocated using xmalloc; the caller is
16756 responsible for freeing it. */
16758 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16760 /* Is the file number a valid index into the line header's file name
16761 table? Remember that file numbers start with one, not zero. */
16762 if (1 <= file
&& file
<= lh
->num_file_names
)
16764 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16766 if (IS_ABSOLUTE_PATH (fe
->name
))
16767 return xstrdup (fe
->name
);
16775 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16781 dir_len
= strlen (dir
);
16782 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16783 strcpy (full_name
, dir
);
16784 full_name
[dir_len
] = '/';
16785 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16789 return xstrdup (fe
->name
);
16794 /* The compiler produced a bogus file number. We can at least
16795 record the macro definitions made in the file, even if we
16796 won't be able to find the file by name. */
16797 char fake_name
[80];
16799 sprintf (fake_name
, "<bad macro file number %d>", file
);
16801 complaint (&symfile_complaints
,
16802 _("bad file number in macro information (%d)"),
16805 return xstrdup (fake_name
);
16810 static struct macro_source_file
*
16811 macro_start_file (int file
, int line
,
16812 struct macro_source_file
*current_file
,
16813 const char *comp_dir
,
16814 struct line_header
*lh
, struct objfile
*objfile
)
16816 /* The full name of this source file. */
16817 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16819 /* We don't create a macro table for this compilation unit
16820 at all until we actually get a filename. */
16821 if (! pending_macros
)
16822 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16823 objfile
->macro_cache
);
16825 if (! current_file
)
16827 /* If we have no current file, then this must be the start_file
16828 directive for the compilation unit's main source file. */
16829 current_file
= macro_set_main (pending_macros
, full_name
);
16830 macro_define_special (pending_macros
);
16833 current_file
= macro_include (current_file
, line
, full_name
);
16837 return current_file
;
16841 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16842 followed by a null byte. */
16844 copy_string (const char *buf
, int len
)
16846 char *s
= xmalloc (len
+ 1);
16848 memcpy (s
, buf
, len
);
16854 static const char *
16855 consume_improper_spaces (const char *p
, const char *body
)
16859 complaint (&symfile_complaints
,
16860 _("macro definition contains spaces "
16861 "in formal argument list:\n`%s'"),
16873 parse_macro_definition (struct macro_source_file
*file
, int line
,
16878 /* The body string takes one of two forms. For object-like macro
16879 definitions, it should be:
16881 <macro name> " " <definition>
16883 For function-like macro definitions, it should be:
16885 <macro name> "() " <definition>
16887 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16889 Spaces may appear only where explicitly indicated, and in the
16892 The Dwarf 2 spec says that an object-like macro's name is always
16893 followed by a space, but versions of GCC around March 2002 omit
16894 the space when the macro's definition is the empty string.
16896 The Dwarf 2 spec says that there should be no spaces between the
16897 formal arguments in a function-like macro's formal argument list,
16898 but versions of GCC around March 2002 include spaces after the
16902 /* Find the extent of the macro name. The macro name is terminated
16903 by either a space or null character (for an object-like macro) or
16904 an opening paren (for a function-like macro). */
16905 for (p
= body
; *p
; p
++)
16906 if (*p
== ' ' || *p
== '(')
16909 if (*p
== ' ' || *p
== '\0')
16911 /* It's an object-like macro. */
16912 int name_len
= p
- body
;
16913 char *name
= copy_string (body
, name_len
);
16914 const char *replacement
;
16917 replacement
= body
+ name_len
+ 1;
16920 dwarf2_macro_malformed_definition_complaint (body
);
16921 replacement
= body
+ name_len
;
16924 macro_define_object (file
, line
, name
, replacement
);
16928 else if (*p
== '(')
16930 /* It's a function-like macro. */
16931 char *name
= copy_string (body
, p
- body
);
16934 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16938 p
= consume_improper_spaces (p
, body
);
16940 /* Parse the formal argument list. */
16941 while (*p
&& *p
!= ')')
16943 /* Find the extent of the current argument name. */
16944 const char *arg_start
= p
;
16946 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16949 if (! *p
|| p
== arg_start
)
16950 dwarf2_macro_malformed_definition_complaint (body
);
16953 /* Make sure argv has room for the new argument. */
16954 if (argc
>= argv_size
)
16957 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16960 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16963 p
= consume_improper_spaces (p
, body
);
16965 /* Consume the comma, if present. */
16970 p
= consume_improper_spaces (p
, body
);
16979 /* Perfectly formed definition, no complaints. */
16980 macro_define_function (file
, line
, name
,
16981 argc
, (const char **) argv
,
16983 else if (*p
== '\0')
16985 /* Complain, but do define it. */
16986 dwarf2_macro_malformed_definition_complaint (body
);
16987 macro_define_function (file
, line
, name
,
16988 argc
, (const char **) argv
,
16992 /* Just complain. */
16993 dwarf2_macro_malformed_definition_complaint (body
);
16996 /* Just complain. */
16997 dwarf2_macro_malformed_definition_complaint (body
);
17003 for (i
= 0; i
< argc
; i
++)
17009 dwarf2_macro_malformed_definition_complaint (body
);
17012 /* Skip some bytes from BYTES according to the form given in FORM.
17013 Returns the new pointer. */
17016 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
17017 enum dwarf_form form
,
17018 unsigned int offset_size
,
17019 struct dwarf2_section_info
*section
)
17021 unsigned int bytes_read
;
17025 case DW_FORM_data1
:
17030 case DW_FORM_data2
:
17034 case DW_FORM_data4
:
17038 case DW_FORM_data8
:
17042 case DW_FORM_string
:
17043 read_direct_string (abfd
, bytes
, &bytes_read
);
17044 bytes
+= bytes_read
;
17047 case DW_FORM_sec_offset
:
17049 bytes
+= offset_size
;
17052 case DW_FORM_block
:
17053 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
17054 bytes
+= bytes_read
;
17057 case DW_FORM_block1
:
17058 bytes
+= 1 + read_1_byte (abfd
, bytes
);
17060 case DW_FORM_block2
:
17061 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
17063 case DW_FORM_block4
:
17064 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
17067 case DW_FORM_sdata
:
17068 case DW_FORM_udata
:
17069 case DW_FORM_GNU_addr_index
:
17070 case DW_FORM_GNU_str_index
:
17071 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
17074 dwarf2_section_buffer_overflow_complaint (section
);
17082 complaint (&symfile_complaints
,
17083 _("invalid form 0x%x in `%s'"),
17085 section
->asection
->name
);
17093 /* A helper for dwarf_decode_macros that handles skipping an unknown
17094 opcode. Returns an updated pointer to the macro data buffer; or,
17095 on error, issues a complaint and returns NULL. */
17098 skip_unknown_opcode (unsigned int opcode
,
17099 gdb_byte
**opcode_definitions
,
17100 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17102 unsigned int offset_size
,
17103 struct dwarf2_section_info
*section
)
17105 unsigned int bytes_read
, i
;
17109 if (opcode_definitions
[opcode
] == NULL
)
17111 complaint (&symfile_complaints
,
17112 _("unrecognized DW_MACFINO opcode 0x%x"),
17117 defn
= opcode_definitions
[opcode
];
17118 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
17119 defn
+= bytes_read
;
17121 for (i
= 0; i
< arg
; ++i
)
17123 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
17125 if (mac_ptr
== NULL
)
17127 /* skip_form_bytes already issued the complaint. */
17135 /* A helper function which parses the header of a macro section.
17136 If the macro section is the extended (for now called "GNU") type,
17137 then this updates *OFFSET_SIZE. Returns a pointer to just after
17138 the header, or issues a complaint and returns NULL on error. */
17141 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17144 unsigned int *offset_size
,
17145 int section_is_gnu
)
17147 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17149 if (section_is_gnu
)
17151 unsigned int version
, flags
;
17153 version
= read_2_bytes (abfd
, mac_ptr
);
17156 complaint (&symfile_complaints
,
17157 _("unrecognized version `%d' in .debug_macro section"),
17163 flags
= read_1_byte (abfd
, mac_ptr
);
17165 *offset_size
= (flags
& 1) ? 8 : 4;
17167 if ((flags
& 2) != 0)
17168 /* We don't need the line table offset. */
17169 mac_ptr
+= *offset_size
;
17171 /* Vendor opcode descriptions. */
17172 if ((flags
& 4) != 0)
17174 unsigned int i
, count
;
17176 count
= read_1_byte (abfd
, mac_ptr
);
17178 for (i
= 0; i
< count
; ++i
)
17180 unsigned int opcode
, bytes_read
;
17183 opcode
= read_1_byte (abfd
, mac_ptr
);
17185 opcode_definitions
[opcode
] = mac_ptr
;
17186 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17187 mac_ptr
+= bytes_read
;
17196 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17197 including DW_MACRO_GNU_transparent_include. */
17200 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17201 struct macro_source_file
*current_file
,
17202 struct line_header
*lh
, char *comp_dir
,
17203 struct dwarf2_section_info
*section
,
17204 int section_is_gnu
,
17205 unsigned int offset_size
,
17206 struct objfile
*objfile
,
17207 htab_t include_hash
)
17209 enum dwarf_macro_record_type macinfo_type
;
17210 int at_commandline
;
17211 gdb_byte
*opcode_definitions
[256];
17213 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17214 &offset_size
, section_is_gnu
);
17215 if (mac_ptr
== NULL
)
17217 /* We already issued a complaint. */
17221 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17222 GDB is still reading the definitions from command line. First
17223 DW_MACINFO_start_file will need to be ignored as it was already executed
17224 to create CURRENT_FILE for the main source holding also the command line
17225 definitions. On first met DW_MACINFO_start_file this flag is reset to
17226 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17228 at_commandline
= 1;
17232 /* Do we at least have room for a macinfo type byte? */
17233 if (mac_ptr
>= mac_end
)
17235 dwarf2_section_buffer_overflow_complaint (section
);
17239 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17242 /* Note that we rely on the fact that the corresponding GNU and
17243 DWARF constants are the same. */
17244 switch (macinfo_type
)
17246 /* A zero macinfo type indicates the end of the macro
17251 case DW_MACRO_GNU_define
:
17252 case DW_MACRO_GNU_undef
:
17253 case DW_MACRO_GNU_define_indirect
:
17254 case DW_MACRO_GNU_undef_indirect
:
17256 unsigned int bytes_read
;
17261 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17262 mac_ptr
+= bytes_read
;
17264 if (macinfo_type
== DW_MACRO_GNU_define
17265 || macinfo_type
== DW_MACRO_GNU_undef
)
17267 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17268 mac_ptr
+= bytes_read
;
17272 LONGEST str_offset
;
17274 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17275 mac_ptr
+= offset_size
;
17277 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17280 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17281 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
17282 if (! current_file
)
17284 /* DWARF violation as no main source is present. */
17285 complaint (&symfile_complaints
,
17286 _("debug info with no main source gives macro %s "
17288 is_define
? _("definition") : _("undefinition"),
17292 if ((line
== 0 && !at_commandline
)
17293 || (line
!= 0 && at_commandline
))
17294 complaint (&symfile_complaints
,
17295 _("debug info gives %s macro %s with %s line %d: %s"),
17296 at_commandline
? _("command-line") : _("in-file"),
17297 is_define
? _("definition") : _("undefinition"),
17298 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17301 parse_macro_definition (current_file
, line
, body
);
17304 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17305 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
17306 macro_undef (current_file
, line
, body
);
17311 case DW_MACRO_GNU_start_file
:
17313 unsigned int bytes_read
;
17316 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17317 mac_ptr
+= bytes_read
;
17318 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17319 mac_ptr
+= bytes_read
;
17321 if ((line
== 0 && !at_commandline
)
17322 || (line
!= 0 && at_commandline
))
17323 complaint (&symfile_complaints
,
17324 _("debug info gives source %d included "
17325 "from %s at %s line %d"),
17326 file
, at_commandline
? _("command-line") : _("file"),
17327 line
== 0 ? _("zero") : _("non-zero"), line
);
17329 if (at_commandline
)
17331 /* This DW_MACRO_GNU_start_file was executed in the
17333 at_commandline
= 0;
17336 current_file
= macro_start_file (file
, line
,
17337 current_file
, comp_dir
,
17342 case DW_MACRO_GNU_end_file
:
17343 if (! current_file
)
17344 complaint (&symfile_complaints
,
17345 _("macro debug info has an unmatched "
17346 "`close_file' directive"));
17349 current_file
= current_file
->included_by
;
17350 if (! current_file
)
17352 enum dwarf_macro_record_type next_type
;
17354 /* GCC circa March 2002 doesn't produce the zero
17355 type byte marking the end of the compilation
17356 unit. Complain if it's not there, but exit no
17359 /* Do we at least have room for a macinfo type byte? */
17360 if (mac_ptr
>= mac_end
)
17362 dwarf2_section_buffer_overflow_complaint (section
);
17366 /* We don't increment mac_ptr here, so this is just
17368 next_type
= read_1_byte (abfd
, mac_ptr
);
17369 if (next_type
!= 0)
17370 complaint (&symfile_complaints
,
17371 _("no terminating 0-type entry for "
17372 "macros in `.debug_macinfo' section"));
17379 case DW_MACRO_GNU_transparent_include
:
17384 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17385 mac_ptr
+= offset_size
;
17387 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17390 /* This has actually happened; see
17391 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17392 complaint (&symfile_complaints
,
17393 _("recursive DW_MACRO_GNU_transparent_include in "
17394 ".debug_macro section"));
17400 dwarf_decode_macro_bytes (abfd
,
17401 section
->buffer
+ offset
,
17402 mac_end
, current_file
,
17404 section
, section_is_gnu
,
17405 offset_size
, objfile
, include_hash
);
17407 htab_remove_elt (include_hash
, mac_ptr
);
17412 case DW_MACINFO_vendor_ext
:
17413 if (!section_is_gnu
)
17415 unsigned int bytes_read
;
17418 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17419 mac_ptr
+= bytes_read
;
17420 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17421 mac_ptr
+= bytes_read
;
17423 /* We don't recognize any vendor extensions. */
17429 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17430 mac_ptr
, mac_end
, abfd
, offset_size
,
17432 if (mac_ptr
== NULL
)
17436 } while (macinfo_type
!= 0);
17440 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17441 char *comp_dir
, int section_is_gnu
)
17443 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17444 struct line_header
*lh
= cu
->line_header
;
17446 gdb_byte
*mac_ptr
, *mac_end
;
17447 struct macro_source_file
*current_file
= 0;
17448 enum dwarf_macro_record_type macinfo_type
;
17449 unsigned int offset_size
= cu
->header
.offset_size
;
17450 gdb_byte
*opcode_definitions
[256];
17451 struct cleanup
*cleanup
;
17452 htab_t include_hash
;
17454 struct dwarf2_section_info
*section
;
17455 const char *section_name
;
17457 if (cu
->dwo_unit
!= NULL
)
17459 if (section_is_gnu
)
17461 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17462 section_name
= ".debug_macro.dwo";
17466 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17467 section_name
= ".debug_macinfo.dwo";
17472 if (section_is_gnu
)
17474 section
= &dwarf2_per_objfile
->macro
;
17475 section_name
= ".debug_macro";
17479 section
= &dwarf2_per_objfile
->macinfo
;
17480 section_name
= ".debug_macinfo";
17484 dwarf2_read_section (objfile
, section
);
17485 if (section
->buffer
== NULL
)
17487 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17490 abfd
= section
->asection
->owner
;
17492 /* First pass: Find the name of the base filename.
17493 This filename is needed in order to process all macros whose definition
17494 (or undefinition) comes from the command line. These macros are defined
17495 before the first DW_MACINFO_start_file entry, and yet still need to be
17496 associated to the base file.
17498 To determine the base file name, we scan the macro definitions until we
17499 reach the first DW_MACINFO_start_file entry. We then initialize
17500 CURRENT_FILE accordingly so that any macro definition found before the
17501 first DW_MACINFO_start_file can still be associated to the base file. */
17503 mac_ptr
= section
->buffer
+ offset
;
17504 mac_end
= section
->buffer
+ section
->size
;
17506 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17507 &offset_size
, section_is_gnu
);
17508 if (mac_ptr
== NULL
)
17510 /* We already issued a complaint. */
17516 /* Do we at least have room for a macinfo type byte? */
17517 if (mac_ptr
>= mac_end
)
17519 /* Complaint is printed during the second pass as GDB will probably
17520 stop the first pass earlier upon finding
17521 DW_MACINFO_start_file. */
17525 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17528 /* Note that we rely on the fact that the corresponding GNU and
17529 DWARF constants are the same. */
17530 switch (macinfo_type
)
17532 /* A zero macinfo type indicates the end of the macro
17537 case DW_MACRO_GNU_define
:
17538 case DW_MACRO_GNU_undef
:
17539 /* Only skip the data by MAC_PTR. */
17541 unsigned int bytes_read
;
17543 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17544 mac_ptr
+= bytes_read
;
17545 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17546 mac_ptr
+= bytes_read
;
17550 case DW_MACRO_GNU_start_file
:
17552 unsigned int bytes_read
;
17555 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17556 mac_ptr
+= bytes_read
;
17557 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17558 mac_ptr
+= bytes_read
;
17560 current_file
= macro_start_file (file
, line
, current_file
,
17561 comp_dir
, lh
, objfile
);
17565 case DW_MACRO_GNU_end_file
:
17566 /* No data to skip by MAC_PTR. */
17569 case DW_MACRO_GNU_define_indirect
:
17570 case DW_MACRO_GNU_undef_indirect
:
17572 unsigned int bytes_read
;
17574 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17575 mac_ptr
+= bytes_read
;
17576 mac_ptr
+= offset_size
;
17580 case DW_MACRO_GNU_transparent_include
:
17581 /* Note that, according to the spec, a transparent include
17582 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17583 skip this opcode. */
17584 mac_ptr
+= offset_size
;
17587 case DW_MACINFO_vendor_ext
:
17588 /* Only skip the data by MAC_PTR. */
17589 if (!section_is_gnu
)
17591 unsigned int bytes_read
;
17593 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17594 mac_ptr
+= bytes_read
;
17595 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17596 mac_ptr
+= bytes_read
;
17601 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17602 mac_ptr
, mac_end
, abfd
, offset_size
,
17604 if (mac_ptr
== NULL
)
17608 } while (macinfo_type
!= 0 && current_file
== NULL
);
17610 /* Second pass: Process all entries.
17612 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17613 command-line macro definitions/undefinitions. This flag is unset when we
17614 reach the first DW_MACINFO_start_file entry. */
17616 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17617 NULL
, xcalloc
, xfree
);
17618 cleanup
= make_cleanup_htab_delete (include_hash
);
17619 mac_ptr
= section
->buffer
+ offset
;
17620 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17622 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17623 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17624 offset_size
, objfile
, include_hash
);
17625 do_cleanups (cleanup
);
17628 /* Check if the attribute's form is a DW_FORM_block*
17629 if so return true else false. */
17632 attr_form_is_block (struct attribute
*attr
)
17634 return (attr
== NULL
? 0 :
17635 attr
->form
== DW_FORM_block1
17636 || attr
->form
== DW_FORM_block2
17637 || attr
->form
== DW_FORM_block4
17638 || attr
->form
== DW_FORM_block
17639 || attr
->form
== DW_FORM_exprloc
);
17642 /* Return non-zero if ATTR's value is a section offset --- classes
17643 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17644 You may use DW_UNSND (attr) to retrieve such offsets.
17646 Section 7.5.4, "Attribute Encodings", explains that no attribute
17647 may have a value that belongs to more than one of these classes; it
17648 would be ambiguous if we did, because we use the same forms for all
17652 attr_form_is_section_offset (struct attribute
*attr
)
17654 return (attr
->form
== DW_FORM_data4
17655 || attr
->form
== DW_FORM_data8
17656 || attr
->form
== DW_FORM_sec_offset
);
17659 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17660 zero otherwise. When this function returns true, you can apply
17661 dwarf2_get_attr_constant_value to it.
17663 However, note that for some attributes you must check
17664 attr_form_is_section_offset before using this test. DW_FORM_data4
17665 and DW_FORM_data8 are members of both the constant class, and of
17666 the classes that contain offsets into other debug sections
17667 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17668 that, if an attribute's can be either a constant or one of the
17669 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17670 taken as section offsets, not constants. */
17673 attr_form_is_constant (struct attribute
*attr
)
17675 switch (attr
->form
)
17677 case DW_FORM_sdata
:
17678 case DW_FORM_udata
:
17679 case DW_FORM_data1
:
17680 case DW_FORM_data2
:
17681 case DW_FORM_data4
:
17682 case DW_FORM_data8
:
17689 /* Return the .debug_loc section to use for CU.
17690 For DWO files use .debug_loc.dwo. */
17692 static struct dwarf2_section_info
*
17693 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17696 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17697 return &dwarf2_per_objfile
->loc
;
17700 /* A helper function that fills in a dwarf2_loclist_baton. */
17703 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17704 struct dwarf2_loclist_baton
*baton
,
17705 struct attribute
*attr
)
17707 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17709 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17711 baton
->per_cu
= cu
->per_cu
;
17712 gdb_assert (baton
->per_cu
);
17713 /* We don't know how long the location list is, but make sure we
17714 don't run off the edge of the section. */
17715 baton
->size
= section
->size
- DW_UNSND (attr
);
17716 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17717 baton
->base_address
= cu
->base_address
;
17718 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
17722 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17723 struct dwarf2_cu
*cu
)
17725 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17726 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17728 if (attr_form_is_section_offset (attr
)
17729 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17730 the section. If so, fall through to the complaint in the
17732 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17734 struct dwarf2_loclist_baton
*baton
;
17736 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17737 sizeof (struct dwarf2_loclist_baton
));
17739 fill_in_loclist_baton (cu
, baton
, attr
);
17741 if (cu
->base_known
== 0)
17742 complaint (&symfile_complaints
,
17743 _("Location list used without "
17744 "specifying the CU base address."));
17746 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17747 SYMBOL_LOCATION_BATON (sym
) = baton
;
17751 struct dwarf2_locexpr_baton
*baton
;
17753 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17754 sizeof (struct dwarf2_locexpr_baton
));
17755 baton
->per_cu
= cu
->per_cu
;
17756 gdb_assert (baton
->per_cu
);
17758 if (attr_form_is_block (attr
))
17760 /* Note that we're just copying the block's data pointer
17761 here, not the actual data. We're still pointing into the
17762 info_buffer for SYM's objfile; right now we never release
17763 that buffer, but when we do clean up properly this may
17765 baton
->size
= DW_BLOCK (attr
)->size
;
17766 baton
->data
= DW_BLOCK (attr
)->data
;
17770 dwarf2_invalid_attrib_class_complaint ("location description",
17771 SYMBOL_NATURAL_NAME (sym
));
17775 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17776 SYMBOL_LOCATION_BATON (sym
) = baton
;
17780 /* Return the OBJFILE associated with the compilation unit CU. If CU
17781 came from a separate debuginfo file, then the master objfile is
17785 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17787 struct objfile
*objfile
= per_cu
->objfile
;
17789 /* Return the master objfile, so that we can report and look up the
17790 correct file containing this variable. */
17791 if (objfile
->separate_debug_objfile_backlink
)
17792 objfile
= objfile
->separate_debug_objfile_backlink
;
17797 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17798 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17799 CU_HEADERP first. */
17801 static const struct comp_unit_head
*
17802 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17803 struct dwarf2_per_cu_data
*per_cu
)
17805 gdb_byte
*info_ptr
;
17808 return &per_cu
->cu
->header
;
17810 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
17812 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17813 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
17818 /* Return the address size given in the compilation unit header for CU. */
17821 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17823 struct comp_unit_head cu_header_local
;
17824 const struct comp_unit_head
*cu_headerp
;
17826 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17828 return cu_headerp
->addr_size
;
17831 /* Return the offset size given in the compilation unit header for CU. */
17834 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17836 struct comp_unit_head cu_header_local
;
17837 const struct comp_unit_head
*cu_headerp
;
17839 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17841 return cu_headerp
->offset_size
;
17844 /* See its dwarf2loc.h declaration. */
17847 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17849 struct comp_unit_head cu_header_local
;
17850 const struct comp_unit_head
*cu_headerp
;
17852 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17854 if (cu_headerp
->version
== 2)
17855 return cu_headerp
->addr_size
;
17857 return cu_headerp
->offset_size
;
17860 /* Return the text offset of the CU. The returned offset comes from
17861 this CU's objfile. If this objfile came from a separate debuginfo
17862 file, then the offset may be different from the corresponding
17863 offset in the parent objfile. */
17866 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17868 struct objfile
*objfile
= per_cu
->objfile
;
17870 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17873 /* Locate the .debug_info compilation unit from CU's objfile which contains
17874 the DIE at OFFSET. Raises an error on failure. */
17876 static struct dwarf2_per_cu_data
*
17877 dwarf2_find_containing_comp_unit (sect_offset offset
,
17878 struct objfile
*objfile
)
17880 struct dwarf2_per_cu_data
*this_cu
;
17884 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17887 int mid
= low
+ (high
- low
) / 2;
17889 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17890 >= offset
.sect_off
)
17895 gdb_assert (low
== high
);
17896 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17900 error (_("Dwarf Error: could not find partial DIE containing "
17901 "offset 0x%lx [in module %s]"),
17902 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17904 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17905 <= offset
.sect_off
);
17906 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17910 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17911 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17912 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17913 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17914 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17919 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17922 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17924 memset (cu
, 0, sizeof (*cu
));
17926 cu
->per_cu
= per_cu
;
17927 cu
->objfile
= per_cu
->objfile
;
17928 obstack_init (&cu
->comp_unit_obstack
);
17931 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17934 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17935 enum language pretend_language
)
17937 struct attribute
*attr
;
17939 /* Set the language we're debugging. */
17940 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17942 set_cu_language (DW_UNSND (attr
), cu
);
17945 cu
->language
= pretend_language
;
17946 cu
->language_defn
= language_def (cu
->language
);
17949 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17951 cu
->producer
= DW_STRING (attr
);
17954 /* Release one cached compilation unit, CU. We unlink it from the tree
17955 of compilation units, but we don't remove it from the read_in_chain;
17956 the caller is responsible for that.
17957 NOTE: DATA is a void * because this function is also used as a
17958 cleanup routine. */
17961 free_heap_comp_unit (void *data
)
17963 struct dwarf2_cu
*cu
= data
;
17965 gdb_assert (cu
->per_cu
!= NULL
);
17966 cu
->per_cu
->cu
= NULL
;
17969 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17974 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17975 when we're finished with it. We can't free the pointer itself, but be
17976 sure to unlink it from the cache. Also release any associated storage. */
17979 free_stack_comp_unit (void *data
)
17981 struct dwarf2_cu
*cu
= data
;
17983 gdb_assert (cu
->per_cu
!= NULL
);
17984 cu
->per_cu
->cu
= NULL
;
17987 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17988 cu
->partial_dies
= NULL
;
17991 /* Free all cached compilation units. */
17994 free_cached_comp_units (void *data
)
17996 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17998 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17999 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18000 while (per_cu
!= NULL
)
18002 struct dwarf2_per_cu_data
*next_cu
;
18004 next_cu
= per_cu
->cu
->read_in_chain
;
18006 free_heap_comp_unit (per_cu
->cu
);
18007 *last_chain
= next_cu
;
18013 /* Increase the age counter on each cached compilation unit, and free
18014 any that are too old. */
18017 age_cached_comp_units (void)
18019 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18021 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
18022 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18023 while (per_cu
!= NULL
)
18025 per_cu
->cu
->last_used
++;
18026 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
18027 dwarf2_mark (per_cu
->cu
);
18028 per_cu
= per_cu
->cu
->read_in_chain
;
18031 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18032 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18033 while (per_cu
!= NULL
)
18035 struct dwarf2_per_cu_data
*next_cu
;
18037 next_cu
= per_cu
->cu
->read_in_chain
;
18039 if (!per_cu
->cu
->mark
)
18041 free_heap_comp_unit (per_cu
->cu
);
18042 *last_chain
= next_cu
;
18045 last_chain
= &per_cu
->cu
->read_in_chain
;
18051 /* Remove a single compilation unit from the cache. */
18054 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
18056 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18058 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18059 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18060 while (per_cu
!= NULL
)
18062 struct dwarf2_per_cu_data
*next_cu
;
18064 next_cu
= per_cu
->cu
->read_in_chain
;
18066 if (per_cu
== target_per_cu
)
18068 free_heap_comp_unit (per_cu
->cu
);
18070 *last_chain
= next_cu
;
18074 last_chain
= &per_cu
->cu
->read_in_chain
;
18080 /* Release all extra memory associated with OBJFILE. */
18083 dwarf2_free_objfile (struct objfile
*objfile
)
18085 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18087 if (dwarf2_per_objfile
== NULL
)
18090 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
18091 free_cached_comp_units (NULL
);
18093 if (dwarf2_per_objfile
->quick_file_names_table
)
18094 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
18096 /* Everything else should be on the objfile obstack. */
18099 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
18100 We store these in a hash table separate from the DIEs, and preserve them
18101 when the DIEs are flushed out of cache.
18103 The CU "per_cu" pointer is needed because offset alone is not enough to
18104 uniquely identify the type. A file may have multiple .debug_types sections,
18105 or the type may come from a DWO file. We have to use something in
18106 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
18107 routine, get_die_type_at_offset, from outside this file, and thus won't
18108 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
18111 struct dwarf2_per_cu_offset_and_type
18113 const struct dwarf2_per_cu_data
*per_cu
;
18114 sect_offset offset
;
18118 /* Hash function for a dwarf2_per_cu_offset_and_type. */
18121 per_cu_offset_and_type_hash (const void *item
)
18123 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
18125 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
18128 /* Equality function for a dwarf2_per_cu_offset_and_type. */
18131 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
18133 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
18134 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
18136 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
18137 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18140 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18141 table if necessary. For convenience, return TYPE.
18143 The DIEs reading must have careful ordering to:
18144 * Not cause infite loops trying to read in DIEs as a prerequisite for
18145 reading current DIE.
18146 * Not trying to dereference contents of still incompletely read in types
18147 while reading in other DIEs.
18148 * Enable referencing still incompletely read in types just by a pointer to
18149 the type without accessing its fields.
18151 Therefore caller should follow these rules:
18152 * Try to fetch any prerequisite types we may need to build this DIE type
18153 before building the type and calling set_die_type.
18154 * After building type call set_die_type for current DIE as soon as
18155 possible before fetching more types to complete the current type.
18156 * Make the type as complete as possible before fetching more types. */
18158 static struct type
*
18159 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18161 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18162 struct objfile
*objfile
= cu
->objfile
;
18164 /* For Ada types, make sure that the gnat-specific data is always
18165 initialized (if not already set). There are a few types where
18166 we should not be doing so, because the type-specific area is
18167 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18168 where the type-specific area is used to store the floatformat).
18169 But this is not a problem, because the gnat-specific information
18170 is actually not needed for these types. */
18171 if (need_gnat_info (cu
)
18172 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18173 && TYPE_CODE (type
) != TYPE_CODE_FLT
18174 && !HAVE_GNAT_AUX_INFO (type
))
18175 INIT_GNAT_SPECIFIC (type
);
18177 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18179 dwarf2_per_objfile
->die_type_hash
=
18180 htab_create_alloc_ex (127,
18181 per_cu_offset_and_type_hash
,
18182 per_cu_offset_and_type_eq
,
18184 &objfile
->objfile_obstack
,
18185 hashtab_obstack_allocate
,
18186 dummy_obstack_deallocate
);
18189 ofs
.per_cu
= cu
->per_cu
;
18190 ofs
.offset
= die
->offset
;
18192 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18193 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18195 complaint (&symfile_complaints
,
18196 _("A problem internal to GDB: DIE 0x%x has type already set"),
18197 die
->offset
.sect_off
);
18198 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18203 /* Look up the type for the die at OFFSET in the appropriate type_hash
18204 table, or return NULL if the die does not have a saved type. */
18206 static struct type
*
18207 get_die_type_at_offset (sect_offset offset
,
18208 struct dwarf2_per_cu_data
*per_cu
)
18210 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18212 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18215 ofs
.per_cu
= per_cu
;
18216 ofs
.offset
= offset
;
18217 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18224 /* Look up the type for DIE in the appropriate type_hash table,
18225 or return NULL if DIE does not have a saved type. */
18227 static struct type
*
18228 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18230 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18233 /* Add a dependence relationship from CU to REF_PER_CU. */
18236 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18237 struct dwarf2_per_cu_data
*ref_per_cu
)
18241 if (cu
->dependencies
== NULL
)
18243 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18244 NULL
, &cu
->comp_unit_obstack
,
18245 hashtab_obstack_allocate
,
18246 dummy_obstack_deallocate
);
18248 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18250 *slot
= ref_per_cu
;
18253 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18254 Set the mark field in every compilation unit in the
18255 cache that we must keep because we are keeping CU. */
18258 dwarf2_mark_helper (void **slot
, void *data
)
18260 struct dwarf2_per_cu_data
*per_cu
;
18262 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18264 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18265 reading of the chain. As such dependencies remain valid it is not much
18266 useful to track and undo them during QUIT cleanups. */
18267 if (per_cu
->cu
== NULL
)
18270 if (per_cu
->cu
->mark
)
18272 per_cu
->cu
->mark
= 1;
18274 if (per_cu
->cu
->dependencies
!= NULL
)
18275 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18280 /* Set the mark field in CU and in every other compilation unit in the
18281 cache that we must keep because we are keeping CU. */
18284 dwarf2_mark (struct dwarf2_cu
*cu
)
18289 if (cu
->dependencies
!= NULL
)
18290 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18294 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18298 per_cu
->cu
->mark
= 0;
18299 per_cu
= per_cu
->cu
->read_in_chain
;
18303 /* Trivial hash function for partial_die_info: the hash value of a DIE
18304 is its offset in .debug_info for this objfile. */
18307 partial_die_hash (const void *item
)
18309 const struct partial_die_info
*part_die
= item
;
18311 return part_die
->offset
.sect_off
;
18314 /* Trivial comparison function for partial_die_info structures: two DIEs
18315 are equal if they have the same offset. */
18318 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18320 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18321 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18323 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18326 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18327 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18330 set_dwarf2_cmd (char *args
, int from_tty
)
18332 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18336 show_dwarf2_cmd (char *args
, int from_tty
)
18338 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18341 /* If section described by INFO was mmapped, munmap it now. */
18344 munmap_section_buffer (struct dwarf2_section_info
*info
)
18346 if (info
->map_addr
!= NULL
)
18351 res
= munmap (info
->map_addr
, info
->map_len
);
18352 gdb_assert (res
== 0);
18354 /* Without HAVE_MMAP, we should never be here to begin with. */
18355 gdb_assert_not_reached ("no mmap support");
18360 /* munmap debug sections for OBJFILE, if necessary. */
18363 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18365 struct dwarf2_per_objfile
*data
= d
;
18367 struct dwarf2_section_info
*section
;
18369 /* This is sorted according to the order they're defined in to make it easier
18370 to keep in sync. */
18371 munmap_section_buffer (&data
->info
);
18372 munmap_section_buffer (&data
->abbrev
);
18373 munmap_section_buffer (&data
->line
);
18374 munmap_section_buffer (&data
->loc
);
18375 munmap_section_buffer (&data
->macinfo
);
18376 munmap_section_buffer (&data
->macro
);
18377 munmap_section_buffer (&data
->str
);
18378 munmap_section_buffer (&data
->ranges
);
18379 munmap_section_buffer (&data
->addr
);
18380 munmap_section_buffer (&data
->frame
);
18381 munmap_section_buffer (&data
->eh_frame
);
18382 munmap_section_buffer (&data
->gdb_index
);
18385 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
18387 munmap_section_buffer (section
);
18389 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18390 VEC_free (dwarf2_per_cu_ptr
,
18391 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18393 VEC_free (dwarf2_section_info_def
, data
->types
);
18395 if (data
->dwo_files
)
18396 free_dwo_files (data
->dwo_files
, objfile
);
18400 /* The "save gdb-index" command. */
18402 /* The contents of the hash table we create when building the string
18404 struct strtab_entry
18406 offset_type offset
;
18410 /* Hash function for a strtab_entry.
18412 Function is used only during write_hash_table so no index format backward
18413 compatibility is needed. */
18416 hash_strtab_entry (const void *e
)
18418 const struct strtab_entry
*entry
= e
;
18419 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18422 /* Equality function for a strtab_entry. */
18425 eq_strtab_entry (const void *a
, const void *b
)
18427 const struct strtab_entry
*ea
= a
;
18428 const struct strtab_entry
*eb
= b
;
18429 return !strcmp (ea
->str
, eb
->str
);
18432 /* Create a strtab_entry hash table. */
18435 create_strtab (void)
18437 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18438 xfree
, xcalloc
, xfree
);
18441 /* Add a string to the constant pool. Return the string's offset in
18445 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18448 struct strtab_entry entry
;
18449 struct strtab_entry
*result
;
18452 slot
= htab_find_slot (table
, &entry
, INSERT
);
18457 result
= XNEW (struct strtab_entry
);
18458 result
->offset
= obstack_object_size (cpool
);
18460 obstack_grow_str0 (cpool
, str
);
18463 return result
->offset
;
18466 /* An entry in the symbol table. */
18467 struct symtab_index_entry
18469 /* The name of the symbol. */
18471 /* The offset of the name in the constant pool. */
18472 offset_type index_offset
;
18473 /* A sorted vector of the indices of all the CUs that hold an object
18475 VEC (offset_type
) *cu_indices
;
18478 /* The symbol table. This is a power-of-2-sized hash table. */
18479 struct mapped_symtab
18481 offset_type n_elements
;
18483 struct symtab_index_entry
**data
;
18486 /* Hash function for a symtab_index_entry. */
18489 hash_symtab_entry (const void *e
)
18491 const struct symtab_index_entry
*entry
= e
;
18492 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18493 sizeof (offset_type
) * VEC_length (offset_type
,
18494 entry
->cu_indices
),
18498 /* Equality function for a symtab_index_entry. */
18501 eq_symtab_entry (const void *a
, const void *b
)
18503 const struct symtab_index_entry
*ea
= a
;
18504 const struct symtab_index_entry
*eb
= b
;
18505 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18506 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18508 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18509 VEC_address (offset_type
, eb
->cu_indices
),
18510 sizeof (offset_type
) * len
);
18513 /* Destroy a symtab_index_entry. */
18516 delete_symtab_entry (void *p
)
18518 struct symtab_index_entry
*entry
= p
;
18519 VEC_free (offset_type
, entry
->cu_indices
);
18523 /* Create a hash table holding symtab_index_entry objects. */
18526 create_symbol_hash_table (void)
18528 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18529 delete_symtab_entry
, xcalloc
, xfree
);
18532 /* Create a new mapped symtab object. */
18534 static struct mapped_symtab
*
18535 create_mapped_symtab (void)
18537 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18538 symtab
->n_elements
= 0;
18539 symtab
->size
= 1024;
18540 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18544 /* Destroy a mapped_symtab. */
18547 cleanup_mapped_symtab (void *p
)
18549 struct mapped_symtab
*symtab
= p
;
18550 /* The contents of the array are freed when the other hash table is
18552 xfree (symtab
->data
);
18556 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18559 Function is used only during write_hash_table so no index format backward
18560 compatibility is needed. */
18562 static struct symtab_index_entry
**
18563 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18565 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18567 index
= hash
& (symtab
->size
- 1);
18568 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18572 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18573 return &symtab
->data
[index
];
18574 index
= (index
+ step
) & (symtab
->size
- 1);
18578 /* Expand SYMTAB's hash table. */
18581 hash_expand (struct mapped_symtab
*symtab
)
18583 offset_type old_size
= symtab
->size
;
18585 struct symtab_index_entry
**old_entries
= symtab
->data
;
18588 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18590 for (i
= 0; i
< old_size
; ++i
)
18592 if (old_entries
[i
])
18594 struct symtab_index_entry
**slot
= find_slot (symtab
,
18595 old_entries
[i
]->name
);
18596 *slot
= old_entries
[i
];
18600 xfree (old_entries
);
18603 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18604 CU_INDEX is the index of the CU in which the symbol appears.
18605 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18608 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18609 int is_static
, gdb_index_symbol_kind kind
,
18610 offset_type cu_index
)
18612 struct symtab_index_entry
**slot
;
18613 offset_type cu_index_and_attrs
;
18615 ++symtab
->n_elements
;
18616 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18617 hash_expand (symtab
);
18619 slot
= find_slot (symtab
, name
);
18622 *slot
= XNEW (struct symtab_index_entry
);
18623 (*slot
)->name
= name
;
18624 /* index_offset is set later. */
18625 (*slot
)->cu_indices
= NULL
;
18628 cu_index_and_attrs
= 0;
18629 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18630 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18631 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18633 /* We don't want to record an index value twice as we want to avoid the
18635 We process all global symbols and then all static symbols
18636 (which would allow us to avoid the duplication by only having to check
18637 the last entry pushed), but a symbol could have multiple kinds in one CU.
18638 To keep things simple we don't worry about the duplication here and
18639 sort and uniqufy the list after we've processed all symbols. */
18640 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18643 /* qsort helper routine for uniquify_cu_indices. */
18646 offset_type_compare (const void *ap
, const void *bp
)
18648 offset_type a
= *(offset_type
*) ap
;
18649 offset_type b
= *(offset_type
*) bp
;
18651 return (a
> b
) - (b
> a
);
18654 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18657 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18661 for (i
= 0; i
< symtab
->size
; ++i
)
18663 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18666 && entry
->cu_indices
!= NULL
)
18668 unsigned int next_to_insert
, next_to_check
;
18669 offset_type last_value
;
18671 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18672 VEC_length (offset_type
, entry
->cu_indices
),
18673 sizeof (offset_type
), offset_type_compare
);
18675 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18676 next_to_insert
= 1;
18677 for (next_to_check
= 1;
18678 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18681 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18684 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18686 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18691 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18696 /* Add a vector of indices to the constant pool. */
18699 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18700 struct symtab_index_entry
*entry
)
18704 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18707 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18708 offset_type val
= MAYBE_SWAP (len
);
18713 entry
->index_offset
= obstack_object_size (cpool
);
18715 obstack_grow (cpool
, &val
, sizeof (val
));
18717 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18720 val
= MAYBE_SWAP (iter
);
18721 obstack_grow (cpool
, &val
, sizeof (val
));
18726 struct symtab_index_entry
*old_entry
= *slot
;
18727 entry
->index_offset
= old_entry
->index_offset
;
18730 return entry
->index_offset
;
18733 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18734 constant pool entries going into the obstack CPOOL. */
18737 write_hash_table (struct mapped_symtab
*symtab
,
18738 struct obstack
*output
, struct obstack
*cpool
)
18741 htab_t symbol_hash_table
;
18744 symbol_hash_table
= create_symbol_hash_table ();
18745 str_table
= create_strtab ();
18747 /* We add all the index vectors to the constant pool first, to
18748 ensure alignment is ok. */
18749 for (i
= 0; i
< symtab
->size
; ++i
)
18751 if (symtab
->data
[i
])
18752 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18755 /* Now write out the hash table. */
18756 for (i
= 0; i
< symtab
->size
; ++i
)
18758 offset_type str_off
, vec_off
;
18760 if (symtab
->data
[i
])
18762 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18763 vec_off
= symtab
->data
[i
]->index_offset
;
18767 /* While 0 is a valid constant pool index, it is not valid
18768 to have 0 for both offsets. */
18773 str_off
= MAYBE_SWAP (str_off
);
18774 vec_off
= MAYBE_SWAP (vec_off
);
18776 obstack_grow (output
, &str_off
, sizeof (str_off
));
18777 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18780 htab_delete (str_table
);
18781 htab_delete (symbol_hash_table
);
18784 /* Struct to map psymtab to CU index in the index file. */
18785 struct psymtab_cu_index_map
18787 struct partial_symtab
*psymtab
;
18788 unsigned int cu_index
;
18792 hash_psymtab_cu_index (const void *item
)
18794 const struct psymtab_cu_index_map
*map
= item
;
18796 return htab_hash_pointer (map
->psymtab
);
18800 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18802 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18803 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18805 return lhs
->psymtab
== rhs
->psymtab
;
18808 /* Helper struct for building the address table. */
18809 struct addrmap_index_data
18811 struct objfile
*objfile
;
18812 struct obstack
*addr_obstack
;
18813 htab_t cu_index_htab
;
18815 /* Non-zero if the previous_* fields are valid.
18816 We can't write an entry until we see the next entry (since it is only then
18817 that we know the end of the entry). */
18818 int previous_valid
;
18819 /* Index of the CU in the table of all CUs in the index file. */
18820 unsigned int previous_cu_index
;
18821 /* Start address of the CU. */
18822 CORE_ADDR previous_cu_start
;
18825 /* Write an address entry to OBSTACK. */
18828 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18829 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18831 offset_type cu_index_to_write
;
18833 CORE_ADDR baseaddr
;
18835 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18837 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18838 obstack_grow (obstack
, addr
, 8);
18839 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18840 obstack_grow (obstack
, addr
, 8);
18841 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18842 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18845 /* Worker function for traversing an addrmap to build the address table. */
18848 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18850 struct addrmap_index_data
*data
= datap
;
18851 struct partial_symtab
*pst
= obj
;
18853 if (data
->previous_valid
)
18854 add_address_entry (data
->objfile
, data
->addr_obstack
,
18855 data
->previous_cu_start
, start_addr
,
18856 data
->previous_cu_index
);
18858 data
->previous_cu_start
= start_addr
;
18861 struct psymtab_cu_index_map find_map
, *map
;
18862 find_map
.psymtab
= pst
;
18863 map
= htab_find (data
->cu_index_htab
, &find_map
);
18864 gdb_assert (map
!= NULL
);
18865 data
->previous_cu_index
= map
->cu_index
;
18866 data
->previous_valid
= 1;
18869 data
->previous_valid
= 0;
18874 /* Write OBJFILE's address map to OBSTACK.
18875 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18876 in the index file. */
18879 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18880 htab_t cu_index_htab
)
18882 struct addrmap_index_data addrmap_index_data
;
18884 /* When writing the address table, we have to cope with the fact that
18885 the addrmap iterator only provides the start of a region; we have to
18886 wait until the next invocation to get the start of the next region. */
18888 addrmap_index_data
.objfile
= objfile
;
18889 addrmap_index_data
.addr_obstack
= obstack
;
18890 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18891 addrmap_index_data
.previous_valid
= 0;
18893 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18894 &addrmap_index_data
);
18896 /* It's highly unlikely the last entry (end address = 0xff...ff)
18897 is valid, but we should still handle it.
18898 The end address is recorded as the start of the next region, but that
18899 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18901 if (addrmap_index_data
.previous_valid
)
18902 add_address_entry (objfile
, obstack
,
18903 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18904 addrmap_index_data
.previous_cu_index
);
18907 /* Return the symbol kind of PSYM. */
18909 static gdb_index_symbol_kind
18910 symbol_kind (struct partial_symbol
*psym
)
18912 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
18913 enum address_class aclass
= PSYMBOL_CLASS (psym
);
18921 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
18923 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18925 case LOC_CONST_BYTES
:
18926 case LOC_OPTIMIZED_OUT
:
18928 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18930 /* Note: It's currently impossible to recognize psyms as enum values
18931 short of reading the type info. For now punt. */
18932 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18934 /* There are other LOC_FOO values that one might want to classify
18935 as variables, but dwarf2read.c doesn't currently use them. */
18936 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18938 case STRUCT_DOMAIN
:
18939 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18941 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18945 /* Add a list of partial symbols to SYMTAB. */
18948 write_psymbols (struct mapped_symtab
*symtab
,
18950 struct partial_symbol
**psymp
,
18952 offset_type cu_index
,
18955 for (; count
-- > 0; ++psymp
)
18957 struct partial_symbol
*psym
= *psymp
;
18960 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18961 error (_("Ada is not currently supported by the index"));
18963 /* Only add a given psymbol once. */
18964 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18967 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18970 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18971 is_static
, kind
, cu_index
);
18976 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18977 exception if there is an error. */
18980 write_obstack (FILE *file
, struct obstack
*obstack
)
18982 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18984 != obstack_object_size (obstack
))
18985 error (_("couldn't data write to file"));
18988 /* Unlink a file if the argument is not NULL. */
18991 unlink_if_set (void *p
)
18993 char **filename
= p
;
18995 unlink (*filename
);
18998 /* A helper struct used when iterating over debug_types. */
18999 struct signatured_type_index_data
19001 struct objfile
*objfile
;
19002 struct mapped_symtab
*symtab
;
19003 struct obstack
*types_list
;
19008 /* A helper function that writes a single signatured_type to an
19012 write_one_signatured_type (void **slot
, void *d
)
19014 struct signatured_type_index_data
*info
= d
;
19015 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
19016 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
19017 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19020 write_psymbols (info
->symtab
,
19022 info
->objfile
->global_psymbols
.list
19023 + psymtab
->globals_offset
,
19024 psymtab
->n_global_syms
, info
->cu_index
,
19026 write_psymbols (info
->symtab
,
19028 info
->objfile
->static_psymbols
.list
19029 + psymtab
->statics_offset
,
19030 psymtab
->n_static_syms
, info
->cu_index
,
19033 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19034 entry
->per_cu
.offset
.sect_off
);
19035 obstack_grow (info
->types_list
, val
, 8);
19036 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19037 entry
->type_offset_in_tu
.cu_off
);
19038 obstack_grow (info
->types_list
, val
, 8);
19039 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
19040 obstack_grow (info
->types_list
, val
, 8);
19047 /* Recurse into all "included" dependencies and write their symbols as
19048 if they appeared in this psymtab. */
19051 recursively_write_psymbols (struct objfile
*objfile
,
19052 struct partial_symtab
*psymtab
,
19053 struct mapped_symtab
*symtab
,
19055 offset_type cu_index
)
19059 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
19060 if (psymtab
->dependencies
[i
]->user
!= NULL
)
19061 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
19062 symtab
, psyms_seen
, cu_index
);
19064 write_psymbols (symtab
,
19066 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
19067 psymtab
->n_global_syms
, cu_index
,
19069 write_psymbols (symtab
,
19071 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
19072 psymtab
->n_static_syms
, cu_index
,
19076 /* Create an index file for OBJFILE in the directory DIR. */
19079 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
19081 struct cleanup
*cleanup
;
19082 char *filename
, *cleanup_filename
;
19083 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
19084 struct obstack cu_list
, types_cu_list
;
19087 struct mapped_symtab
*symtab
;
19088 offset_type val
, size_of_contents
, total_len
;
19091 htab_t cu_index_htab
;
19092 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
19094 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
19097 if (dwarf2_per_objfile
->using_index
)
19098 error (_("Cannot use an index to create the index"));
19100 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
19101 error (_("Cannot make an index when the file has multiple .debug_types sections"));
19103 if (stat (objfile
->name
, &st
) < 0)
19104 perror_with_name (objfile
->name
);
19106 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
19107 INDEX_SUFFIX
, (char *) NULL
);
19108 cleanup
= make_cleanup (xfree
, filename
);
19110 out_file
= fopen (filename
, "wb");
19112 error (_("Can't open `%s' for writing"), filename
);
19114 cleanup_filename
= filename
;
19115 make_cleanup (unlink_if_set
, &cleanup_filename
);
19117 symtab
= create_mapped_symtab ();
19118 make_cleanup (cleanup_mapped_symtab
, symtab
);
19120 obstack_init (&addr_obstack
);
19121 make_cleanup_obstack_free (&addr_obstack
);
19123 obstack_init (&cu_list
);
19124 make_cleanup_obstack_free (&cu_list
);
19126 obstack_init (&types_cu_list
);
19127 make_cleanup_obstack_free (&types_cu_list
);
19129 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
19130 NULL
, xcalloc
, xfree
);
19131 make_cleanup_htab_delete (psyms_seen
);
19133 /* While we're scanning CU's create a table that maps a psymtab pointer
19134 (which is what addrmap records) to its index (which is what is recorded
19135 in the index file). This will later be needed to write the address
19137 cu_index_htab
= htab_create_alloc (100,
19138 hash_psymtab_cu_index
,
19139 eq_psymtab_cu_index
,
19140 NULL
, xcalloc
, xfree
);
19141 make_cleanup_htab_delete (cu_index_htab
);
19142 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
19143 xmalloc (sizeof (struct psymtab_cu_index_map
)
19144 * dwarf2_per_objfile
->n_comp_units
);
19145 make_cleanup (xfree
, psymtab_cu_index_map
);
19147 /* The CU list is already sorted, so we don't need to do additional
19148 work here. Also, the debug_types entries do not appear in
19149 all_comp_units, but only in their own hash table. */
19150 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
19152 struct dwarf2_per_cu_data
*per_cu
19153 = dwarf2_per_objfile
->all_comp_units
[i
];
19154 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19156 struct psymtab_cu_index_map
*map
;
19159 if (psymtab
->user
== NULL
)
19160 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
19162 map
= &psymtab_cu_index_map
[i
];
19163 map
->psymtab
= psymtab
;
19165 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
19166 gdb_assert (slot
!= NULL
);
19167 gdb_assert (*slot
== NULL
);
19170 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19171 per_cu
->offset
.sect_off
);
19172 obstack_grow (&cu_list
, val
, 8);
19173 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
19174 obstack_grow (&cu_list
, val
, 8);
19177 /* Dump the address map. */
19178 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19180 /* Write out the .debug_type entries, if any. */
19181 if (dwarf2_per_objfile
->signatured_types
)
19183 struct signatured_type_index_data sig_data
;
19185 sig_data
.objfile
= objfile
;
19186 sig_data
.symtab
= symtab
;
19187 sig_data
.types_list
= &types_cu_list
;
19188 sig_data
.psyms_seen
= psyms_seen
;
19189 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19190 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19191 write_one_signatured_type
, &sig_data
);
19194 /* Now that we've processed all symbols we can shrink their cu_indices
19196 uniquify_cu_indices (symtab
);
19198 obstack_init (&constant_pool
);
19199 make_cleanup_obstack_free (&constant_pool
);
19200 obstack_init (&symtab_obstack
);
19201 make_cleanup_obstack_free (&symtab_obstack
);
19202 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19204 obstack_init (&contents
);
19205 make_cleanup_obstack_free (&contents
);
19206 size_of_contents
= 6 * sizeof (offset_type
);
19207 total_len
= size_of_contents
;
19209 /* The version number. */
19210 val
= MAYBE_SWAP (7);
19211 obstack_grow (&contents
, &val
, sizeof (val
));
19213 /* The offset of the CU list from the start of the file. */
19214 val
= MAYBE_SWAP (total_len
);
19215 obstack_grow (&contents
, &val
, sizeof (val
));
19216 total_len
+= obstack_object_size (&cu_list
);
19218 /* The offset of the types CU list from the start of the file. */
19219 val
= MAYBE_SWAP (total_len
);
19220 obstack_grow (&contents
, &val
, sizeof (val
));
19221 total_len
+= obstack_object_size (&types_cu_list
);
19223 /* The offset of the address table from the start of the file. */
19224 val
= MAYBE_SWAP (total_len
);
19225 obstack_grow (&contents
, &val
, sizeof (val
));
19226 total_len
+= obstack_object_size (&addr_obstack
);
19228 /* The offset of the symbol table from the start of the file. */
19229 val
= MAYBE_SWAP (total_len
);
19230 obstack_grow (&contents
, &val
, sizeof (val
));
19231 total_len
+= obstack_object_size (&symtab_obstack
);
19233 /* The offset of the constant pool from the start of the file. */
19234 val
= MAYBE_SWAP (total_len
);
19235 obstack_grow (&contents
, &val
, sizeof (val
));
19236 total_len
+= obstack_object_size (&constant_pool
);
19238 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19240 write_obstack (out_file
, &contents
);
19241 write_obstack (out_file
, &cu_list
);
19242 write_obstack (out_file
, &types_cu_list
);
19243 write_obstack (out_file
, &addr_obstack
);
19244 write_obstack (out_file
, &symtab_obstack
);
19245 write_obstack (out_file
, &constant_pool
);
19249 /* We want to keep the file, so we set cleanup_filename to NULL
19250 here. See unlink_if_set. */
19251 cleanup_filename
= NULL
;
19253 do_cleanups (cleanup
);
19256 /* Implementation of the `save gdb-index' command.
19258 Note that the file format used by this command is documented in the
19259 GDB manual. Any changes here must be documented there. */
19262 save_gdb_index_command (char *arg
, int from_tty
)
19264 struct objfile
*objfile
;
19267 error (_("usage: save gdb-index DIRECTORY"));
19269 ALL_OBJFILES (objfile
)
19273 /* If the objfile does not correspond to an actual file, skip it. */
19274 if (stat (objfile
->name
, &st
) < 0)
19277 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19278 if (dwarf2_per_objfile
)
19280 volatile struct gdb_exception except
;
19282 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19284 write_psymtabs_to_index (objfile
, arg
);
19286 if (except
.reason
< 0)
19287 exception_fprintf (gdb_stderr
, except
,
19288 _("Error while writing index for `%s': "),
19296 int dwarf2_always_disassemble
;
19299 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19300 struct cmd_list_element
*c
, const char *value
)
19302 fprintf_filtered (file
,
19303 _("Whether to always disassemble "
19304 "DWARF expressions is %s.\n"),
19309 show_check_physname (struct ui_file
*file
, int from_tty
,
19310 struct cmd_list_element
*c
, const char *value
)
19312 fprintf_filtered (file
,
19313 _("Whether to check \"physname\" is %s.\n"),
19317 void _initialize_dwarf2_read (void);
19320 _initialize_dwarf2_read (void)
19322 struct cmd_list_element
*c
;
19324 dwarf2_objfile_data_key
19325 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19327 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19328 Set DWARF 2 specific variables.\n\
19329 Configure DWARF 2 variables such as the cache size"),
19330 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19331 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19333 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19334 Show DWARF 2 specific variables\n\
19335 Show DWARF 2 variables such as the cache size"),
19336 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19337 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19339 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19340 &dwarf2_max_cache_age
, _("\
19341 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19342 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19343 A higher limit means that cached compilation units will be stored\n\
19344 in memory longer, and more total memory will be used. Zero disables\n\
19345 caching, which can slow down startup."),
19347 show_dwarf2_max_cache_age
,
19348 &set_dwarf2_cmdlist
,
19349 &show_dwarf2_cmdlist
);
19351 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19352 &dwarf2_always_disassemble
, _("\
19353 Set whether `info address' always disassembles DWARF expressions."), _("\
19354 Show whether `info address' always disassembles DWARF expressions."), _("\
19355 When enabled, DWARF expressions are always printed in an assembly-like\n\
19356 syntax. When disabled, expressions will be printed in a more\n\
19357 conversational style, when possible."),
19359 show_dwarf2_always_disassemble
,
19360 &set_dwarf2_cmdlist
,
19361 &show_dwarf2_cmdlist
);
19363 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19364 Set debugging of the dwarf2 reader."), _("\
19365 Show debugging of the dwarf2 reader."), _("\
19366 When enabled, debugging messages are printed during dwarf2 reading\n\
19367 and symtab expansion."),
19370 &setdebuglist
, &showdebuglist
);
19372 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19373 Set debugging of the dwarf2 DIE reader."), _("\
19374 Show debugging of the dwarf2 DIE reader."), _("\
19375 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19376 The value is the maximum depth to print."),
19379 &setdebuglist
, &showdebuglist
);
19381 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19382 Set cross-checking of \"physname\" code against demangler."), _("\
19383 Show cross-checking of \"physname\" code against demangler."), _("\
19384 When enabled, GDB's internal \"physname\" code is checked against\n\
19386 NULL
, show_check_physname
,
19387 &setdebuglist
, &showdebuglist
);
19389 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19391 Save a gdb-index file.\n\
19392 Usage: save gdb-index DIRECTORY"),
19394 set_cmd_completer (c
, filename_completer
);