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 bfd_set_cacheable (sym_bfd
, 1);
8126 if (!bfd_check_format (sym_bfd
, bfd_object
))
8128 xfree (absolute_name
);
8129 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8136 /* Try to open DWO file DWO_NAME.
8137 COMP_DIR is the DW_AT_comp_dir attribute.
8138 The result is the bfd handle of the file.
8139 If there is a problem finding or opening the file, return NULL.
8140 Upon success, the canonicalized path of the file is stored in the bfd,
8141 same as symfile_bfd_open. */
8144 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8148 if (IS_ABSOLUTE_PATH (dwo_name
))
8149 return try_open_dwo_file (dwo_name
);
8151 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8153 if (comp_dir
!= NULL
)
8155 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8157 /* NOTE: If comp_dir is a relative path, this will also try the
8158 search path, which seems useful. */
8159 abfd
= try_open_dwo_file (path_to_try
);
8160 xfree (path_to_try
);
8165 /* That didn't work, try debug-file-directory, which, despite its name,
8166 is a list of paths. */
8168 if (*debug_file_directory
== '\0')
8171 return try_open_dwo_file (dwo_name
);
8174 /* Initialize the use of the DWO file specified by DWO_NAME. */
8176 static struct dwo_file
*
8177 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8179 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8180 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8183 struct cleanup
*cleanups
;
8185 if (dwarf2_read_debug
)
8186 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8188 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8191 dwo_file
->dwo_name
= dwo_name
;
8192 dwo_file
->dwo_bfd
= abfd
;
8194 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8196 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8198 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8200 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8201 dwo_file
->sections
.types
);
8203 discard_cleanups (cleanups
);
8208 /* Lookup DWO file DWO_NAME. */
8210 static struct dwo_file
*
8211 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8213 struct dwo_file
*dwo_file
;
8214 struct dwo_file find_entry
;
8217 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8218 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8220 /* Have we already seen this DWO file? */
8221 find_entry
.dwo_name
= dwo_name
;
8222 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8224 /* If not, read it in and build a table of the DWOs it contains. */
8226 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8228 /* NOTE: This will be NULL if unable to open the file. */
8234 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8235 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8236 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8237 nomenclature as TUs).
8238 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8239 (dwo_id mismatch or couldn't find the DWO file). */
8241 static struct dwo_unit
*
8242 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8243 char *dwo_name
, const char *comp_dir
,
8246 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8247 struct dwo_file
*dwo_file
;
8249 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8250 if (dwo_file
== NULL
)
8253 /* Look up the DWO using its signature(dwo_id). */
8255 if (dwo_file
->cus
!= NULL
)
8257 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8259 find_dwo_cu
.signature
= signature
;
8260 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8266 /* We didn't find it. This must mean a dwo_id mismatch. */
8268 complaint (&symfile_complaints
,
8269 _("Could not find DWO CU referenced by CU at offset 0x%x"
8271 this_cu
->offset
.sect_off
, objfile
->name
);
8275 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8276 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8277 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8278 (dwo_id mismatch or couldn't find the DWO file). */
8280 static struct dwo_unit
*
8281 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8282 char *dwo_name
, const char *comp_dir
)
8284 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8285 struct dwo_file
*dwo_file
;
8287 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8288 if (dwo_file
== NULL
)
8291 /* Look up the DWO using its signature(dwo_id). */
8293 if (dwo_file
->tus
!= NULL
)
8295 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8297 find_dwo_tu
.signature
= this_tu
->signature
;
8298 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8304 /* We didn't find it. This must mean a dwo_id mismatch. */
8306 complaint (&symfile_complaints
,
8307 _("Could not find DWO TU referenced by TU at offset 0x%x"
8309 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8313 /* Free all resources associated with DWO_FILE.
8314 Close the DWO file and munmap the sections.
8315 All memory should be on the objfile obstack. */
8318 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8321 struct dwarf2_section_info
*section
;
8323 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8324 gdb_bfd_unref (dwo_file
->dwo_bfd
);
8326 munmap_section_buffer (&dwo_file
->sections
.abbrev
);
8327 munmap_section_buffer (&dwo_file
->sections
.info
);
8328 munmap_section_buffer (&dwo_file
->sections
.line
);
8329 munmap_section_buffer (&dwo_file
->sections
.loc
);
8330 munmap_section_buffer (&dwo_file
->sections
.str
);
8331 munmap_section_buffer (&dwo_file
->sections
.str_offsets
);
8334 VEC_iterate (dwarf2_section_info_def
, dwo_file
->sections
.types
,
8337 munmap_section_buffer (section
);
8339 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8342 /* Wrapper for free_dwo_file for use in cleanups. */
8345 free_dwo_file_cleanup (void *arg
)
8347 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8348 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8350 free_dwo_file (dwo_file
, objfile
);
8353 /* Traversal function for free_dwo_files. */
8356 free_dwo_file_from_slot (void **slot
, void *info
)
8358 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8359 struct objfile
*objfile
= (struct objfile
*) info
;
8361 free_dwo_file (dwo_file
, objfile
);
8366 /* Free all resources associated with DWO_FILES. */
8369 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8371 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8374 /* Read in various DIEs. */
8376 /* qsort helper for inherit_abstract_dies. */
8379 unsigned_int_compar (const void *ap
, const void *bp
)
8381 unsigned int a
= *(unsigned int *) ap
;
8382 unsigned int b
= *(unsigned int *) bp
;
8384 return (a
> b
) - (b
> a
);
8387 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8388 Inherit only the children of the DW_AT_abstract_origin DIE not being
8389 already referenced by DW_AT_abstract_origin from the children of the
8393 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8395 struct die_info
*child_die
;
8396 unsigned die_children_count
;
8397 /* CU offsets which were referenced by children of the current DIE. */
8398 sect_offset
*offsets
;
8399 sect_offset
*offsets_end
, *offsetp
;
8400 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8401 struct die_info
*origin_die
;
8402 /* Iterator of the ORIGIN_DIE children. */
8403 struct die_info
*origin_child_die
;
8404 struct cleanup
*cleanups
;
8405 struct attribute
*attr
;
8406 struct dwarf2_cu
*origin_cu
;
8407 struct pending
**origin_previous_list_in_scope
;
8409 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8413 /* Note that following die references may follow to a die in a
8417 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8419 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8421 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8422 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8424 if (die
->tag
!= origin_die
->tag
8425 && !(die
->tag
== DW_TAG_inlined_subroutine
8426 && origin_die
->tag
== DW_TAG_subprogram
))
8427 complaint (&symfile_complaints
,
8428 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8429 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8431 child_die
= die
->child
;
8432 die_children_count
= 0;
8433 while (child_die
&& child_die
->tag
)
8435 child_die
= sibling_die (child_die
);
8436 die_children_count
++;
8438 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8439 cleanups
= make_cleanup (xfree
, offsets
);
8441 offsets_end
= offsets
;
8442 child_die
= die
->child
;
8443 while (child_die
&& child_die
->tag
)
8445 /* For each CHILD_DIE, find the corresponding child of
8446 ORIGIN_DIE. If there is more than one layer of
8447 DW_AT_abstract_origin, follow them all; there shouldn't be,
8448 but GCC versions at least through 4.4 generate this (GCC PR
8450 struct die_info
*child_origin_die
= child_die
;
8451 struct dwarf2_cu
*child_origin_cu
= cu
;
8455 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8459 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8463 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8464 counterpart may exist. */
8465 if (child_origin_die
!= child_die
)
8467 if (child_die
->tag
!= child_origin_die
->tag
8468 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8469 && child_origin_die
->tag
== DW_TAG_subprogram
))
8470 complaint (&symfile_complaints
,
8471 _("Child DIE 0x%x and its abstract origin 0x%x have "
8472 "different tags"), child_die
->offset
.sect_off
,
8473 child_origin_die
->offset
.sect_off
);
8474 if (child_origin_die
->parent
!= origin_die
)
8475 complaint (&symfile_complaints
,
8476 _("Child DIE 0x%x and its abstract origin 0x%x have "
8477 "different parents"), child_die
->offset
.sect_off
,
8478 child_origin_die
->offset
.sect_off
);
8480 *offsets_end
++ = child_origin_die
->offset
;
8482 child_die
= sibling_die (child_die
);
8484 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8485 unsigned_int_compar
);
8486 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8487 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8488 complaint (&symfile_complaints
,
8489 _("Multiple children of DIE 0x%x refer "
8490 "to DIE 0x%x as their abstract origin"),
8491 die
->offset
.sect_off
, offsetp
->sect_off
);
8494 origin_child_die
= origin_die
->child
;
8495 while (origin_child_die
&& origin_child_die
->tag
)
8497 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8498 while (offsetp
< offsets_end
8499 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8501 if (offsetp
>= offsets_end
8502 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8504 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8505 process_die (origin_child_die
, origin_cu
);
8507 origin_child_die
= sibling_die (origin_child_die
);
8509 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8511 do_cleanups (cleanups
);
8515 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8517 struct objfile
*objfile
= cu
->objfile
;
8518 struct context_stack
*new;
8521 struct die_info
*child_die
;
8522 struct attribute
*attr
, *call_line
, *call_file
;
8525 struct block
*block
;
8526 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8527 VEC (symbolp
) *template_args
= NULL
;
8528 struct template_symbol
*templ_func
= NULL
;
8532 /* If we do not have call site information, we can't show the
8533 caller of this inlined function. That's too confusing, so
8534 only use the scope for local variables. */
8535 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8536 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8537 if (call_line
== NULL
|| call_file
== NULL
)
8539 read_lexical_block_scope (die
, cu
);
8544 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8546 name
= dwarf2_name (die
, cu
);
8548 /* Ignore functions with missing or empty names. These are actually
8549 illegal according to the DWARF standard. */
8552 complaint (&symfile_complaints
,
8553 _("missing name for subprogram DIE at %d"),
8554 die
->offset
.sect_off
);
8558 /* Ignore functions with missing or invalid low and high pc attributes. */
8559 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8561 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8562 if (!attr
|| !DW_UNSND (attr
))
8563 complaint (&symfile_complaints
,
8564 _("cannot get low and high bounds "
8565 "for subprogram DIE at %d"),
8566 die
->offset
.sect_off
);
8573 /* If we have any template arguments, then we must allocate a
8574 different sort of symbol. */
8575 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8577 if (child_die
->tag
== DW_TAG_template_type_param
8578 || child_die
->tag
== DW_TAG_template_value_param
)
8580 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8581 struct template_symbol
);
8582 templ_func
->base
.is_cplus_template_function
= 1;
8587 new = push_context (0, lowpc
);
8588 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8589 (struct symbol
*) templ_func
);
8591 /* If there is a location expression for DW_AT_frame_base, record
8593 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8595 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8596 expression is being recorded directly in the function's symbol
8597 and not in a separate frame-base object. I guess this hack is
8598 to avoid adding some sort of frame-base adjunct/annex to the
8599 function's symbol :-(. The problem with doing this is that it
8600 results in a function symbol with a location expression that
8601 has nothing to do with the location of the function, ouch! The
8602 relationship should be: a function's symbol has-a frame base; a
8603 frame-base has-a location expression. */
8604 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8606 cu
->list_in_scope
= &local_symbols
;
8608 if (die
->child
!= NULL
)
8610 child_die
= die
->child
;
8611 while (child_die
&& child_die
->tag
)
8613 if (child_die
->tag
== DW_TAG_template_type_param
8614 || child_die
->tag
== DW_TAG_template_value_param
)
8616 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8619 VEC_safe_push (symbolp
, template_args
, arg
);
8622 process_die (child_die
, cu
);
8623 child_die
= sibling_die (child_die
);
8627 inherit_abstract_dies (die
, cu
);
8629 /* If we have a DW_AT_specification, we might need to import using
8630 directives from the context of the specification DIE. See the
8631 comment in determine_prefix. */
8632 if (cu
->language
== language_cplus
8633 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8635 struct dwarf2_cu
*spec_cu
= cu
;
8636 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8640 child_die
= spec_die
->child
;
8641 while (child_die
&& child_die
->tag
)
8643 if (child_die
->tag
== DW_TAG_imported_module
)
8644 process_die (child_die
, spec_cu
);
8645 child_die
= sibling_die (child_die
);
8648 /* In some cases, GCC generates specification DIEs that
8649 themselves contain DW_AT_specification attributes. */
8650 spec_die
= die_specification (spec_die
, &spec_cu
);
8654 new = pop_context ();
8655 /* Make a block for the local symbols within. */
8656 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8657 lowpc
, highpc
, objfile
);
8659 /* For C++, set the block's scope. */
8660 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8661 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8662 determine_prefix (die
, cu
),
8663 processing_has_namespace_info
);
8665 /* If we have address ranges, record them. */
8666 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8668 /* Attach template arguments to function. */
8669 if (! VEC_empty (symbolp
, template_args
))
8671 gdb_assert (templ_func
!= NULL
);
8673 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8674 templ_func
->template_arguments
8675 = obstack_alloc (&objfile
->objfile_obstack
,
8676 (templ_func
->n_template_arguments
8677 * sizeof (struct symbol
*)));
8678 memcpy (templ_func
->template_arguments
,
8679 VEC_address (symbolp
, template_args
),
8680 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8681 VEC_free (symbolp
, template_args
);
8684 /* In C++, we can have functions nested inside functions (e.g., when
8685 a function declares a class that has methods). This means that
8686 when we finish processing a function scope, we may need to go
8687 back to building a containing block's symbol lists. */
8688 local_symbols
= new->locals
;
8689 param_symbols
= new->params
;
8690 using_directives
= new->using_directives
;
8692 /* If we've finished processing a top-level function, subsequent
8693 symbols go in the file symbol list. */
8694 if (outermost_context_p ())
8695 cu
->list_in_scope
= &file_symbols
;
8698 /* Process all the DIES contained within a lexical block scope. Start
8699 a new scope, process the dies, and then close the scope. */
8702 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8704 struct objfile
*objfile
= cu
->objfile
;
8705 struct context_stack
*new;
8706 CORE_ADDR lowpc
, highpc
;
8707 struct die_info
*child_die
;
8710 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8712 /* Ignore blocks with missing or invalid low and high pc attributes. */
8713 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8714 as multiple lexical blocks? Handling children in a sane way would
8715 be nasty. Might be easier to properly extend generic blocks to
8717 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8722 push_context (0, lowpc
);
8723 if (die
->child
!= NULL
)
8725 child_die
= die
->child
;
8726 while (child_die
&& child_die
->tag
)
8728 process_die (child_die
, cu
);
8729 child_die
= sibling_die (child_die
);
8732 new = pop_context ();
8734 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8737 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8740 /* Note that recording ranges after traversing children, as we
8741 do here, means that recording a parent's ranges entails
8742 walking across all its children's ranges as they appear in
8743 the address map, which is quadratic behavior.
8745 It would be nicer to record the parent's ranges before
8746 traversing its children, simply overriding whatever you find
8747 there. But since we don't even decide whether to create a
8748 block until after we've traversed its children, that's hard
8750 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8752 local_symbols
= new->locals
;
8753 using_directives
= new->using_directives
;
8756 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8759 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8761 struct objfile
*objfile
= cu
->objfile
;
8762 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8763 CORE_ADDR pc
, baseaddr
;
8764 struct attribute
*attr
;
8765 struct call_site
*call_site
, call_site_local
;
8768 struct die_info
*child_die
;
8770 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8772 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8775 complaint (&symfile_complaints
,
8776 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8777 "DIE 0x%x [in module %s]"),
8778 die
->offset
.sect_off
, objfile
->name
);
8781 pc
= DW_ADDR (attr
) + baseaddr
;
8783 if (cu
->call_site_htab
== NULL
)
8784 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8785 NULL
, &objfile
->objfile_obstack
,
8786 hashtab_obstack_allocate
, NULL
);
8787 call_site_local
.pc
= pc
;
8788 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8791 complaint (&symfile_complaints
,
8792 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8793 "DIE 0x%x [in module %s]"),
8794 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8798 /* Count parameters at the caller. */
8801 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8802 child_die
= sibling_die (child_die
))
8804 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8806 complaint (&symfile_complaints
,
8807 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8808 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8809 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8816 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8817 (sizeof (*call_site
)
8818 + (sizeof (*call_site
->parameter
)
8821 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8824 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8826 struct die_info
*func_die
;
8828 /* Skip also over DW_TAG_inlined_subroutine. */
8829 for (func_die
= die
->parent
;
8830 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8831 && func_die
->tag
!= DW_TAG_subroutine_type
;
8832 func_die
= func_die
->parent
);
8834 /* DW_AT_GNU_all_call_sites is a superset
8835 of DW_AT_GNU_all_tail_call_sites. */
8837 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8838 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8840 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8841 not complete. But keep CALL_SITE for look ups via call_site_htab,
8842 both the initial caller containing the real return address PC and
8843 the final callee containing the current PC of a chain of tail
8844 calls do not need to have the tail call list complete. But any
8845 function candidate for a virtual tail call frame searched via
8846 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8847 determined unambiguously. */
8851 struct type
*func_type
= NULL
;
8854 func_type
= get_die_type (func_die
, cu
);
8855 if (func_type
!= NULL
)
8857 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
8859 /* Enlist this call site to the function. */
8860 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
8861 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
8864 complaint (&symfile_complaints
,
8865 _("Cannot find function owning DW_TAG_GNU_call_site "
8866 "DIE 0x%x [in module %s]"),
8867 die
->offset
.sect_off
, objfile
->name
);
8871 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
8873 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8874 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
8875 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
8876 /* Keep NULL DWARF_BLOCK. */;
8877 else if (attr_form_is_block (attr
))
8879 struct dwarf2_locexpr_baton
*dlbaton
;
8881 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
8882 dlbaton
->data
= DW_BLOCK (attr
)->data
;
8883 dlbaton
->size
= DW_BLOCK (attr
)->size
;
8884 dlbaton
->per_cu
= cu
->per_cu
;
8886 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
8888 else if (is_ref_attr (attr
))
8890 struct dwarf2_cu
*target_cu
= cu
;
8891 struct die_info
*target_die
;
8893 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
8894 gdb_assert (target_cu
->objfile
== objfile
);
8895 if (die_is_declaration (target_die
, target_cu
))
8897 const char *target_physname
;
8899 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
8900 if (target_physname
== NULL
)
8901 complaint (&symfile_complaints
,
8902 _("DW_AT_GNU_call_site_target target DIE has invalid "
8903 "physname, for referencing DIE 0x%x [in module %s]"),
8904 die
->offset
.sect_off
, objfile
->name
);
8906 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
8912 /* DW_AT_entry_pc should be preferred. */
8913 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
8914 complaint (&symfile_complaints
,
8915 _("DW_AT_GNU_call_site_target target DIE has invalid "
8916 "low pc, for referencing DIE 0x%x [in module %s]"),
8917 die
->offset
.sect_off
, objfile
->name
);
8919 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
8923 complaint (&symfile_complaints
,
8924 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
8925 "block nor reference, for DIE 0x%x [in module %s]"),
8926 die
->offset
.sect_off
, objfile
->name
);
8928 call_site
->per_cu
= cu
->per_cu
;
8930 for (child_die
= die
->child
;
8931 child_die
&& child_die
->tag
;
8932 child_die
= sibling_die (child_die
))
8934 struct call_site_parameter
*parameter
;
8935 struct attribute
*loc
, *origin
;
8937 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8939 /* Already printed the complaint above. */
8943 gdb_assert (call_site
->parameter_count
< nparams
);
8944 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
8946 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
8947 specifies DW_TAG_formal_parameter. Value of the data assumed for the
8948 register is contained in DW_AT_GNU_call_site_value. */
8950 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
8951 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
8952 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
8956 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
8957 offset
= dwarf2_get_ref_die_offset (origin
);
8958 if (!offset_in_cu_p (&cu
->header
, offset
))
8960 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
8961 binding can be done only inside one CU. Such referenced DIE
8962 therefore cannot be even moved to DW_TAG_partial_unit. */
8963 complaint (&symfile_complaints
,
8964 _("DW_AT_abstract_origin offset is not in CU for "
8965 "DW_TAG_GNU_call_site child DIE 0x%x "
8967 child_die
->offset
.sect_off
, objfile
->name
);
8970 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
8971 - cu
->header
.offset
.sect_off
);
8973 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
8975 complaint (&symfile_complaints
,
8976 _("No DW_FORM_block* DW_AT_location for "
8977 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8978 child_die
->offset
.sect_off
, objfile
->name
);
8983 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
8984 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
8985 if (parameter
->u
.dwarf_reg
!= -1)
8986 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
8987 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
8988 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
8989 ¶meter
->u
.fb_offset
))
8990 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
8993 complaint (&symfile_complaints
,
8994 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
8995 "for DW_FORM_block* DW_AT_location is supported for "
8996 "DW_TAG_GNU_call_site child DIE 0x%x "
8998 child_die
->offset
.sect_off
, objfile
->name
);
9003 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9004 if (!attr_form_is_block (attr
))
9006 complaint (&symfile_complaints
,
9007 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9008 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9009 child_die
->offset
.sect_off
, objfile
->name
);
9012 parameter
->value
= DW_BLOCK (attr
)->data
;
9013 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9015 /* Parameters are not pre-cleared by memset above. */
9016 parameter
->data_value
= NULL
;
9017 parameter
->data_value_size
= 0;
9018 call_site
->parameter_count
++;
9020 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9023 if (!attr_form_is_block (attr
))
9024 complaint (&symfile_complaints
,
9025 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9026 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9027 child_die
->offset
.sect_off
, objfile
->name
);
9030 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9031 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9037 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9038 Return 1 if the attributes are present and valid, otherwise, return 0.
9039 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9042 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9043 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9044 struct partial_symtab
*ranges_pst
)
9046 struct objfile
*objfile
= cu
->objfile
;
9047 struct comp_unit_head
*cu_header
= &cu
->header
;
9048 bfd
*obfd
= objfile
->obfd
;
9049 unsigned int addr_size
= cu_header
->addr_size
;
9050 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9051 /* Base address selection entry. */
9062 found_base
= cu
->base_known
;
9063 base
= cu
->base_address
;
9065 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9066 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9068 complaint (&symfile_complaints
,
9069 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9073 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9075 /* Read in the largest possible address. */
9076 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9077 if ((marker
& mask
) == mask
)
9079 /* If we found the largest possible address, then
9080 read the base address. */
9081 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9082 buffer
+= 2 * addr_size
;
9083 offset
+= 2 * addr_size
;
9089 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9093 CORE_ADDR range_beginning
, range_end
;
9095 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9096 buffer
+= addr_size
;
9097 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9098 buffer
+= addr_size
;
9099 offset
+= 2 * addr_size
;
9101 /* An end of list marker is a pair of zero addresses. */
9102 if (range_beginning
== 0 && range_end
== 0)
9103 /* Found the end of list entry. */
9106 /* Each base address selection entry is a pair of 2 values.
9107 The first is the largest possible address, the second is
9108 the base address. Check for a base address here. */
9109 if ((range_beginning
& mask
) == mask
)
9111 /* If we found the largest possible address, then
9112 read the base address. */
9113 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9120 /* We have no valid base address for the ranges
9122 complaint (&symfile_complaints
,
9123 _("Invalid .debug_ranges data (no base address)"));
9127 if (range_beginning
> range_end
)
9129 /* Inverted range entries are invalid. */
9130 complaint (&symfile_complaints
,
9131 _("Invalid .debug_ranges data (inverted range)"));
9135 /* Empty range entries have no effect. */
9136 if (range_beginning
== range_end
)
9139 range_beginning
+= base
;
9142 if (ranges_pst
!= NULL
)
9143 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9144 range_beginning
+ baseaddr
,
9145 range_end
- 1 + baseaddr
,
9148 /* FIXME: This is recording everything as a low-high
9149 segment of consecutive addresses. We should have a
9150 data structure for discontiguous block ranges
9154 low
= range_beginning
;
9160 if (range_beginning
< low
)
9161 low
= range_beginning
;
9162 if (range_end
> high
)
9168 /* If the first entry is an end-of-list marker, the range
9169 describes an empty scope, i.e. no instructions. */
9175 *high_return
= high
;
9179 /* Get low and high pc attributes from a die. Return 1 if the attributes
9180 are present and valid, otherwise, return 0. Return -1 if the range is
9181 discontinuous, i.e. derived from DW_AT_ranges information. */
9184 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9185 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9186 struct partial_symtab
*pst
)
9188 struct attribute
*attr
;
9189 struct attribute
*attr_high
;
9194 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9197 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9200 low
= DW_ADDR (attr
);
9201 if (attr_high
->form
== DW_FORM_addr
9202 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9203 high
= DW_ADDR (attr_high
);
9205 high
= low
+ DW_UNSND (attr_high
);
9208 /* Found high w/o low attribute. */
9211 /* Found consecutive range of addresses. */
9216 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9219 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9221 /* Value of the DW_AT_ranges attribute is the offset in the
9222 .debug_ranges section. */
9223 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9225 /* Found discontinuous range of addresses. */
9230 /* read_partial_die has also the strict LOW < HIGH requirement. */
9234 /* When using the GNU linker, .gnu.linkonce. sections are used to
9235 eliminate duplicate copies of functions and vtables and such.
9236 The linker will arbitrarily choose one and discard the others.
9237 The AT_*_pc values for such functions refer to local labels in
9238 these sections. If the section from that file was discarded, the
9239 labels are not in the output, so the relocs get a value of 0.
9240 If this is a discarded function, mark the pc bounds as invalid,
9241 so that GDB will ignore it. */
9242 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9251 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9252 its low and high PC addresses. Do nothing if these addresses could not
9253 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9254 and HIGHPC to the high address if greater than HIGHPC. */
9257 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9258 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9259 struct dwarf2_cu
*cu
)
9261 CORE_ADDR low
, high
;
9262 struct die_info
*child
= die
->child
;
9264 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9266 *lowpc
= min (*lowpc
, low
);
9267 *highpc
= max (*highpc
, high
);
9270 /* If the language does not allow nested subprograms (either inside
9271 subprograms or lexical blocks), we're done. */
9272 if (cu
->language
!= language_ada
)
9275 /* Check all the children of the given DIE. If it contains nested
9276 subprograms, then check their pc bounds. Likewise, we need to
9277 check lexical blocks as well, as they may also contain subprogram
9279 while (child
&& child
->tag
)
9281 if (child
->tag
== DW_TAG_subprogram
9282 || child
->tag
== DW_TAG_lexical_block
)
9283 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9284 child
= sibling_die (child
);
9288 /* Get the low and high pc's represented by the scope DIE, and store
9289 them in *LOWPC and *HIGHPC. If the correct values can't be
9290 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9293 get_scope_pc_bounds (struct die_info
*die
,
9294 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9295 struct dwarf2_cu
*cu
)
9297 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9298 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9299 CORE_ADDR current_low
, current_high
;
9301 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9303 best_low
= current_low
;
9304 best_high
= current_high
;
9308 struct die_info
*child
= die
->child
;
9310 while (child
&& child
->tag
)
9312 switch (child
->tag
) {
9313 case DW_TAG_subprogram
:
9314 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9316 case DW_TAG_namespace
:
9318 /* FIXME: carlton/2004-01-16: Should we do this for
9319 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9320 that current GCC's always emit the DIEs corresponding
9321 to definitions of methods of classes as children of a
9322 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9323 the DIEs giving the declarations, which could be
9324 anywhere). But I don't see any reason why the
9325 standards says that they have to be there. */
9326 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9328 if (current_low
!= ((CORE_ADDR
) -1))
9330 best_low
= min (best_low
, current_low
);
9331 best_high
= max (best_high
, current_high
);
9339 child
= sibling_die (child
);
9344 *highpc
= best_high
;
9347 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9351 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9352 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9354 struct objfile
*objfile
= cu
->objfile
;
9355 struct attribute
*attr
;
9356 struct attribute
*attr_high
;
9358 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9361 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9364 CORE_ADDR low
= DW_ADDR (attr
);
9366 if (attr_high
->form
== DW_FORM_addr
9367 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9368 high
= DW_ADDR (attr_high
);
9370 high
= low
+ DW_UNSND (attr_high
);
9372 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9376 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9379 bfd
*obfd
= objfile
->obfd
;
9381 /* The value of the DW_AT_ranges attribute is the offset of the
9382 address range list in the .debug_ranges section. */
9383 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9384 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9386 /* For some target architectures, but not others, the
9387 read_address function sign-extends the addresses it returns.
9388 To recognize base address selection entries, we need a
9390 unsigned int addr_size
= cu
->header
.addr_size
;
9391 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9393 /* The base address, to which the next pair is relative. Note
9394 that this 'base' is a DWARF concept: most entries in a range
9395 list are relative, to reduce the number of relocs against the
9396 debugging information. This is separate from this function's
9397 'baseaddr' argument, which GDB uses to relocate debugging
9398 information from a shared library based on the address at
9399 which the library was loaded. */
9400 CORE_ADDR base
= cu
->base_address
;
9401 int base_known
= cu
->base_known
;
9403 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9404 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9406 complaint (&symfile_complaints
,
9407 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9414 unsigned int bytes_read
;
9415 CORE_ADDR start
, end
;
9417 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9418 buffer
+= bytes_read
;
9419 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9420 buffer
+= bytes_read
;
9422 /* Did we find the end of the range list? */
9423 if (start
== 0 && end
== 0)
9426 /* Did we find a base address selection entry? */
9427 else if ((start
& base_select_mask
) == base_select_mask
)
9433 /* We found an ordinary address range. */
9438 complaint (&symfile_complaints
,
9439 _("Invalid .debug_ranges data "
9440 "(no base address)"));
9446 /* Inverted range entries are invalid. */
9447 complaint (&symfile_complaints
,
9448 _("Invalid .debug_ranges data "
9449 "(inverted range)"));
9453 /* Empty range entries have no effect. */
9457 record_block_range (block
,
9458 baseaddr
+ base
+ start
,
9459 baseaddr
+ base
+ end
- 1);
9465 /* Check whether the producer field indicates either of GCC < 4.6, or the
9466 Intel C/C++ compiler, and cache the result in CU. */
9469 check_producer (struct dwarf2_cu
*cu
)
9472 int major
, minor
, release
;
9474 if (cu
->producer
== NULL
)
9476 /* For unknown compilers expect their behavior is DWARF version
9479 GCC started to support .debug_types sections by -gdwarf-4 since
9480 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9481 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9482 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9483 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9485 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9487 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9489 cs
= &cu
->producer
[strlen ("GNU ")];
9490 while (*cs
&& !isdigit (*cs
))
9492 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9494 /* Not recognized as GCC. */
9497 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9499 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9500 cu
->producer_is_icc
= 1;
9503 /* For other non-GCC compilers, expect their behavior is DWARF version
9507 cu
->checked_producer
= 1;
9510 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9511 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9512 during 4.6.0 experimental. */
9515 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9517 if (!cu
->checked_producer
)
9518 check_producer (cu
);
9520 return cu
->producer_is_gxx_lt_4_6
;
9523 /* Return the default accessibility type if it is not overriden by
9524 DW_AT_accessibility. */
9526 static enum dwarf_access_attribute
9527 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9529 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9531 /* The default DWARF 2 accessibility for members is public, the default
9532 accessibility for inheritance is private. */
9534 if (die
->tag
!= DW_TAG_inheritance
)
9535 return DW_ACCESS_public
;
9537 return DW_ACCESS_private
;
9541 /* DWARF 3+ defines the default accessibility a different way. The same
9542 rules apply now for DW_TAG_inheritance as for the members and it only
9543 depends on the container kind. */
9545 if (die
->parent
->tag
== DW_TAG_class_type
)
9546 return DW_ACCESS_private
;
9548 return DW_ACCESS_public
;
9552 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9553 offset. If the attribute was not found return 0, otherwise return
9554 1. If it was found but could not properly be handled, set *OFFSET
9558 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9561 struct attribute
*attr
;
9563 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9568 /* Note that we do not check for a section offset first here.
9569 This is because DW_AT_data_member_location is new in DWARF 4,
9570 so if we see it, we can assume that a constant form is really
9571 a constant and not a section offset. */
9572 if (attr_form_is_constant (attr
))
9573 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9574 else if (attr_form_is_section_offset (attr
))
9575 dwarf2_complex_location_expr_complaint ();
9576 else if (attr_form_is_block (attr
))
9577 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9579 dwarf2_complex_location_expr_complaint ();
9587 /* Add an aggregate field to the field list. */
9590 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9591 struct dwarf2_cu
*cu
)
9593 struct objfile
*objfile
= cu
->objfile
;
9594 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9595 struct nextfield
*new_field
;
9596 struct attribute
*attr
;
9598 char *fieldname
= "";
9600 /* Allocate a new field list entry and link it in. */
9601 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9602 make_cleanup (xfree
, new_field
);
9603 memset (new_field
, 0, sizeof (struct nextfield
));
9605 if (die
->tag
== DW_TAG_inheritance
)
9607 new_field
->next
= fip
->baseclasses
;
9608 fip
->baseclasses
= new_field
;
9612 new_field
->next
= fip
->fields
;
9613 fip
->fields
= new_field
;
9617 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9619 new_field
->accessibility
= DW_UNSND (attr
);
9621 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9622 if (new_field
->accessibility
!= DW_ACCESS_public
)
9623 fip
->non_public_fields
= 1;
9625 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9627 new_field
->virtuality
= DW_UNSND (attr
);
9629 new_field
->virtuality
= DW_VIRTUALITY_none
;
9631 fp
= &new_field
->field
;
9633 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9637 /* Data member other than a C++ static data member. */
9639 /* Get type of field. */
9640 fp
->type
= die_type (die
, cu
);
9642 SET_FIELD_BITPOS (*fp
, 0);
9644 /* Get bit size of field (zero if none). */
9645 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9648 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9652 FIELD_BITSIZE (*fp
) = 0;
9655 /* Get bit offset of field. */
9656 if (handle_data_member_location (die
, cu
, &offset
))
9657 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9658 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9661 if (gdbarch_bits_big_endian (gdbarch
))
9663 /* For big endian bits, the DW_AT_bit_offset gives the
9664 additional bit offset from the MSB of the containing
9665 anonymous object to the MSB of the field. We don't
9666 have to do anything special since we don't need to
9667 know the size of the anonymous object. */
9668 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9672 /* For little endian bits, compute the bit offset to the
9673 MSB of the anonymous object, subtract off the number of
9674 bits from the MSB of the field to the MSB of the
9675 object, and then subtract off the number of bits of
9676 the field itself. The result is the bit offset of
9677 the LSB of the field. */
9679 int bit_offset
= DW_UNSND (attr
);
9681 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9684 /* The size of the anonymous object containing
9685 the bit field is explicit, so use the
9686 indicated size (in bytes). */
9687 anonymous_size
= DW_UNSND (attr
);
9691 /* The size of the anonymous object containing
9692 the bit field must be inferred from the type
9693 attribute of the data member containing the
9695 anonymous_size
= TYPE_LENGTH (fp
->type
);
9697 SET_FIELD_BITPOS (*fp
,
9699 + anonymous_size
* bits_per_byte
9700 - bit_offset
- FIELD_BITSIZE (*fp
)));
9704 /* Get name of field. */
9705 fieldname
= dwarf2_name (die
, cu
);
9706 if (fieldname
== NULL
)
9709 /* The name is already allocated along with this objfile, so we don't
9710 need to duplicate it for the type. */
9711 fp
->name
= fieldname
;
9713 /* Change accessibility for artificial fields (e.g. virtual table
9714 pointer or virtual base class pointer) to private. */
9715 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9717 FIELD_ARTIFICIAL (*fp
) = 1;
9718 new_field
->accessibility
= DW_ACCESS_private
;
9719 fip
->non_public_fields
= 1;
9722 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9724 /* C++ static member. */
9726 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9727 is a declaration, but all versions of G++ as of this writing
9728 (so through at least 3.2.1) incorrectly generate
9729 DW_TAG_variable tags. */
9731 const char *physname
;
9733 /* Get name of field. */
9734 fieldname
= dwarf2_name (die
, cu
);
9735 if (fieldname
== NULL
)
9738 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9740 /* Only create a symbol if this is an external value.
9741 new_symbol checks this and puts the value in the global symbol
9742 table, which we want. If it is not external, new_symbol
9743 will try to put the value in cu->list_in_scope which is wrong. */
9744 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9746 /* A static const member, not much different than an enum as far as
9747 we're concerned, except that we can support more types. */
9748 new_symbol (die
, NULL
, cu
);
9751 /* Get physical name. */
9752 physname
= dwarf2_physname (fieldname
, die
, cu
);
9754 /* The name is already allocated along with this objfile, so we don't
9755 need to duplicate it for the type. */
9756 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9757 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9758 FIELD_NAME (*fp
) = fieldname
;
9760 else if (die
->tag
== DW_TAG_inheritance
)
9764 /* C++ base class field. */
9765 if (handle_data_member_location (die
, cu
, &offset
))
9766 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9767 FIELD_BITSIZE (*fp
) = 0;
9768 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9769 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9770 fip
->nbaseclasses
++;
9774 /* Add a typedef defined in the scope of the FIP's class. */
9777 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9778 struct dwarf2_cu
*cu
)
9780 struct objfile
*objfile
= cu
->objfile
;
9781 struct typedef_field_list
*new_field
;
9782 struct attribute
*attr
;
9783 struct typedef_field
*fp
;
9784 char *fieldname
= "";
9786 /* Allocate a new field list entry and link it in. */
9787 new_field
= xzalloc (sizeof (*new_field
));
9788 make_cleanup (xfree
, new_field
);
9790 gdb_assert (die
->tag
== DW_TAG_typedef
);
9792 fp
= &new_field
->field
;
9794 /* Get name of field. */
9795 fp
->name
= dwarf2_name (die
, cu
);
9796 if (fp
->name
== NULL
)
9799 fp
->type
= read_type_die (die
, cu
);
9801 new_field
->next
= fip
->typedef_field_list
;
9802 fip
->typedef_field_list
= new_field
;
9803 fip
->typedef_field_list_count
++;
9806 /* Create the vector of fields, and attach it to the type. */
9809 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9810 struct dwarf2_cu
*cu
)
9812 int nfields
= fip
->nfields
;
9814 /* Record the field count, allocate space for the array of fields,
9815 and create blank accessibility bitfields if necessary. */
9816 TYPE_NFIELDS (type
) = nfields
;
9817 TYPE_FIELDS (type
) = (struct field
*)
9818 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9819 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9821 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9823 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9825 TYPE_FIELD_PRIVATE_BITS (type
) =
9826 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9827 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9829 TYPE_FIELD_PROTECTED_BITS (type
) =
9830 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9831 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
9833 TYPE_FIELD_IGNORE_BITS (type
) =
9834 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9835 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
9838 /* If the type has baseclasses, allocate and clear a bit vector for
9839 TYPE_FIELD_VIRTUAL_BITS. */
9840 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9842 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9843 unsigned char *pointer
;
9845 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9846 pointer
= TYPE_ALLOC (type
, num_bytes
);
9847 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9848 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9849 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9852 /* Copy the saved-up fields into the field vector. Start from the head of
9853 the list, adding to the tail of the field array, so that they end up in
9854 the same order in the array in which they were added to the list. */
9855 while (nfields
-- > 0)
9857 struct nextfield
*fieldp
;
9861 fieldp
= fip
->fields
;
9862 fip
->fields
= fieldp
->next
;
9866 fieldp
= fip
->baseclasses
;
9867 fip
->baseclasses
= fieldp
->next
;
9870 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
9871 switch (fieldp
->accessibility
)
9873 case DW_ACCESS_private
:
9874 if (cu
->language
!= language_ada
)
9875 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
9878 case DW_ACCESS_protected
:
9879 if (cu
->language
!= language_ada
)
9880 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
9883 case DW_ACCESS_public
:
9887 /* Unknown accessibility. Complain and treat it as public. */
9889 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
9890 fieldp
->accessibility
);
9894 if (nfields
< fip
->nbaseclasses
)
9896 switch (fieldp
->virtuality
)
9898 case DW_VIRTUALITY_virtual
:
9899 case DW_VIRTUALITY_pure_virtual
:
9900 if (cu
->language
== language_ada
)
9901 error (_("unexpected virtuality in component of Ada type"));
9902 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
9909 /* Add a member function to the proper fieldlist. */
9912 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
9913 struct type
*type
, struct dwarf2_cu
*cu
)
9915 struct objfile
*objfile
= cu
->objfile
;
9916 struct attribute
*attr
;
9917 struct fnfieldlist
*flp
;
9919 struct fn_field
*fnp
;
9921 struct nextfnfield
*new_fnfield
;
9922 struct type
*this_type
;
9923 enum dwarf_access_attribute accessibility
;
9925 if (cu
->language
== language_ada
)
9926 error (_("unexpected member function in Ada type"));
9928 /* Get name of member function. */
9929 fieldname
= dwarf2_name (die
, cu
);
9930 if (fieldname
== NULL
)
9933 /* Look up member function name in fieldlist. */
9934 for (i
= 0; i
< fip
->nfnfields
; i
++)
9936 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
9940 /* Create new list element if necessary. */
9941 if (i
< fip
->nfnfields
)
9942 flp
= &fip
->fnfieldlists
[i
];
9945 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
9947 fip
->fnfieldlists
= (struct fnfieldlist
*)
9948 xrealloc (fip
->fnfieldlists
,
9949 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
9950 * sizeof (struct fnfieldlist
));
9951 if (fip
->nfnfields
== 0)
9952 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
9954 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
9955 flp
->name
= fieldname
;
9958 i
= fip
->nfnfields
++;
9961 /* Create a new member function field and chain it to the field list
9963 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
9964 make_cleanup (xfree
, new_fnfield
);
9965 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
9966 new_fnfield
->next
= flp
->head
;
9967 flp
->head
= new_fnfield
;
9970 /* Fill in the member function field info. */
9971 fnp
= &new_fnfield
->fnfield
;
9973 /* Delay processing of the physname until later. */
9974 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
9976 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
9981 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
9982 fnp
->physname
= physname
? physname
: "";
9985 fnp
->type
= alloc_type (objfile
);
9986 this_type
= read_type_die (die
, cu
);
9987 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
9989 int nparams
= TYPE_NFIELDS (this_type
);
9991 /* TYPE is the domain of this method, and THIS_TYPE is the type
9992 of the method itself (TYPE_CODE_METHOD). */
9993 smash_to_method_type (fnp
->type
, type
,
9994 TYPE_TARGET_TYPE (this_type
),
9995 TYPE_FIELDS (this_type
),
9996 TYPE_NFIELDS (this_type
),
9997 TYPE_VARARGS (this_type
));
9999 /* Handle static member functions.
10000 Dwarf2 has no clean way to discern C++ static and non-static
10001 member functions. G++ helps GDB by marking the first
10002 parameter for non-static member functions (which is the this
10003 pointer) as artificial. We obtain this information from
10004 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10005 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10006 fnp
->voffset
= VOFFSET_STATIC
;
10009 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10010 dwarf2_full_name (fieldname
, die
, cu
));
10012 /* Get fcontext from DW_AT_containing_type if present. */
10013 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10014 fnp
->fcontext
= die_containing_type (die
, cu
);
10016 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10017 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10019 /* Get accessibility. */
10020 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10022 accessibility
= DW_UNSND (attr
);
10024 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10025 switch (accessibility
)
10027 case DW_ACCESS_private
:
10028 fnp
->is_private
= 1;
10030 case DW_ACCESS_protected
:
10031 fnp
->is_protected
= 1;
10035 /* Check for artificial methods. */
10036 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10037 if (attr
&& DW_UNSND (attr
) != 0)
10038 fnp
->is_artificial
= 1;
10040 /* Get index in virtual function table if it is a virtual member
10041 function. For older versions of GCC, this is an offset in the
10042 appropriate virtual table, as specified by DW_AT_containing_type.
10043 For everyone else, it is an expression to be evaluated relative
10044 to the object address. */
10046 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10049 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10051 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10053 /* Old-style GCC. */
10054 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10056 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10057 || (DW_BLOCK (attr
)->size
> 1
10058 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10059 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10061 struct dwarf_block blk
;
10064 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10066 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10067 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10068 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10069 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10070 dwarf2_complex_location_expr_complaint ();
10072 fnp
->voffset
/= cu
->header
.addr_size
;
10076 dwarf2_complex_location_expr_complaint ();
10078 if (!fnp
->fcontext
)
10079 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10081 else if (attr_form_is_section_offset (attr
))
10083 dwarf2_complex_location_expr_complaint ();
10087 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10093 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10094 if (attr
&& DW_UNSND (attr
))
10096 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10097 complaint (&symfile_complaints
,
10098 _("Member function \"%s\" (offset %d) is virtual "
10099 "but the vtable offset is not specified"),
10100 fieldname
, die
->offset
.sect_off
);
10101 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10102 TYPE_CPLUS_DYNAMIC (type
) = 1;
10107 /* Create the vector of member function fields, and attach it to the type. */
10110 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10111 struct dwarf2_cu
*cu
)
10113 struct fnfieldlist
*flp
;
10116 if (cu
->language
== language_ada
)
10117 error (_("unexpected member functions in Ada type"));
10119 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10120 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10121 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10123 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10125 struct nextfnfield
*nfp
= flp
->head
;
10126 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10129 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10130 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10131 fn_flp
->fn_fields
= (struct fn_field
*)
10132 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10133 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10134 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10137 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10140 /* Returns non-zero if NAME is the name of a vtable member in CU's
10141 language, zero otherwise. */
10143 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10145 static const char vptr
[] = "_vptr";
10146 static const char vtable
[] = "vtable";
10148 /* Look for the C++ and Java forms of the vtable. */
10149 if ((cu
->language
== language_java
10150 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10151 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10152 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10158 /* GCC outputs unnamed structures that are really pointers to member
10159 functions, with the ABI-specified layout. If TYPE describes
10160 such a structure, smash it into a member function type.
10162 GCC shouldn't do this; it should just output pointer to member DIEs.
10163 This is GCC PR debug/28767. */
10166 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10168 struct type
*pfn_type
, *domain_type
, *new_type
;
10170 /* Check for a structure with no name and two children. */
10171 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10174 /* Check for __pfn and __delta members. */
10175 if (TYPE_FIELD_NAME (type
, 0) == NULL
10176 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10177 || TYPE_FIELD_NAME (type
, 1) == NULL
10178 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10181 /* Find the type of the method. */
10182 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10183 if (pfn_type
== NULL
10184 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10185 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10188 /* Look for the "this" argument. */
10189 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10190 if (TYPE_NFIELDS (pfn_type
) == 0
10191 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10192 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10195 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10196 new_type
= alloc_type (objfile
);
10197 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10198 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10199 TYPE_VARARGS (pfn_type
));
10200 smash_to_methodptr_type (type
, new_type
);
10203 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10207 producer_is_icc (struct dwarf2_cu
*cu
)
10209 if (!cu
->checked_producer
)
10210 check_producer (cu
);
10212 return cu
->producer_is_icc
;
10215 /* Called when we find the DIE that starts a structure or union scope
10216 (definition) to create a type for the structure or union. Fill in
10217 the type's name and general properties; the members will not be
10218 processed until process_structure_type.
10220 NOTE: we need to call these functions regardless of whether or not the
10221 DIE has a DW_AT_name attribute, since it might be an anonymous
10222 structure or union. This gets the type entered into our set of
10223 user defined types.
10225 However, if the structure is incomplete (an opaque struct/union)
10226 then suppress creating a symbol table entry for it since gdb only
10227 wants to find the one with the complete definition. Note that if
10228 it is complete, we just call new_symbol, which does it's own
10229 checking about whether the struct/union is anonymous or not (and
10230 suppresses creating a symbol table entry itself). */
10232 static struct type
*
10233 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10235 struct objfile
*objfile
= cu
->objfile
;
10237 struct attribute
*attr
;
10240 /* If the definition of this type lives in .debug_types, read that type.
10241 Don't follow DW_AT_specification though, that will take us back up
10242 the chain and we want to go down. */
10243 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10246 struct dwarf2_cu
*type_cu
= cu
;
10247 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10249 /* We could just recurse on read_structure_type, but we need to call
10250 get_die_type to ensure only one type for this DIE is created.
10251 This is important, for example, because for c++ classes we need
10252 TYPE_NAME set which is only done by new_symbol. Blech. */
10253 type
= read_type_die (type_die
, type_cu
);
10255 /* TYPE_CU may not be the same as CU.
10256 Ensure TYPE is recorded in CU's type_hash table. */
10257 return set_die_type (die
, type
, cu
);
10260 type
= alloc_type (objfile
);
10261 INIT_CPLUS_SPECIFIC (type
);
10263 name
= dwarf2_name (die
, cu
);
10266 if (cu
->language
== language_cplus
10267 || cu
->language
== language_java
)
10269 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10271 /* dwarf2_full_name might have already finished building the DIE's
10272 type. If so, there is no need to continue. */
10273 if (get_die_type (die
, cu
) != NULL
)
10274 return get_die_type (die
, cu
);
10276 TYPE_TAG_NAME (type
) = full_name
;
10277 if (die
->tag
== DW_TAG_structure_type
10278 || die
->tag
== DW_TAG_class_type
)
10279 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10283 /* The name is already allocated along with this objfile, so
10284 we don't need to duplicate it for the type. */
10285 TYPE_TAG_NAME (type
) = (char *) name
;
10286 if (die
->tag
== DW_TAG_class_type
)
10287 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10291 if (die
->tag
== DW_TAG_structure_type
)
10293 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10295 else if (die
->tag
== DW_TAG_union_type
)
10297 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10301 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10304 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10305 TYPE_DECLARED_CLASS (type
) = 1;
10307 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10310 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10314 TYPE_LENGTH (type
) = 0;
10317 if (producer_is_icc (cu
))
10319 /* ICC does not output the required DW_AT_declaration
10320 on incomplete types, but gives them a size of zero. */
10323 TYPE_STUB_SUPPORTED (type
) = 1;
10325 if (die_is_declaration (die
, cu
))
10326 TYPE_STUB (type
) = 1;
10327 else if (attr
== NULL
&& die
->child
== NULL
10328 && producer_is_realview (cu
->producer
))
10329 /* RealView does not output the required DW_AT_declaration
10330 on incomplete types. */
10331 TYPE_STUB (type
) = 1;
10333 /* We need to add the type field to the die immediately so we don't
10334 infinitely recurse when dealing with pointers to the structure
10335 type within the structure itself. */
10336 set_die_type (die
, type
, cu
);
10338 /* set_die_type should be already done. */
10339 set_descriptive_type (type
, die
, cu
);
10344 /* Finish creating a structure or union type, including filling in
10345 its members and creating a symbol for it. */
10348 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10350 struct objfile
*objfile
= cu
->objfile
;
10351 struct die_info
*child_die
= die
->child
;
10354 type
= get_die_type (die
, cu
);
10356 type
= read_structure_type (die
, cu
);
10358 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10360 struct field_info fi
;
10361 struct die_info
*child_die
;
10362 VEC (symbolp
) *template_args
= NULL
;
10363 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10365 memset (&fi
, 0, sizeof (struct field_info
));
10367 child_die
= die
->child
;
10369 while (child_die
&& child_die
->tag
)
10371 if (child_die
->tag
== DW_TAG_member
10372 || child_die
->tag
== DW_TAG_variable
)
10374 /* NOTE: carlton/2002-11-05: A C++ static data member
10375 should be a DW_TAG_member that is a declaration, but
10376 all versions of G++ as of this writing (so through at
10377 least 3.2.1) incorrectly generate DW_TAG_variable
10378 tags for them instead. */
10379 dwarf2_add_field (&fi
, child_die
, cu
);
10381 else if (child_die
->tag
== DW_TAG_subprogram
)
10383 /* C++ member function. */
10384 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10386 else if (child_die
->tag
== DW_TAG_inheritance
)
10388 /* C++ base class field. */
10389 dwarf2_add_field (&fi
, child_die
, cu
);
10391 else if (child_die
->tag
== DW_TAG_typedef
)
10392 dwarf2_add_typedef (&fi
, child_die
, cu
);
10393 else if (child_die
->tag
== DW_TAG_template_type_param
10394 || child_die
->tag
== DW_TAG_template_value_param
)
10396 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10399 VEC_safe_push (symbolp
, template_args
, arg
);
10402 child_die
= sibling_die (child_die
);
10405 /* Attach template arguments to type. */
10406 if (! VEC_empty (symbolp
, template_args
))
10408 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10409 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10410 = VEC_length (symbolp
, template_args
);
10411 TYPE_TEMPLATE_ARGUMENTS (type
)
10412 = obstack_alloc (&objfile
->objfile_obstack
,
10413 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10414 * sizeof (struct symbol
*)));
10415 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10416 VEC_address (symbolp
, template_args
),
10417 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10418 * sizeof (struct symbol
*)));
10419 VEC_free (symbolp
, template_args
);
10422 /* Attach fields and member functions to the type. */
10424 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10427 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10429 /* Get the type which refers to the base class (possibly this
10430 class itself) which contains the vtable pointer for the current
10431 class from the DW_AT_containing_type attribute. This use of
10432 DW_AT_containing_type is a GNU extension. */
10434 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10436 struct type
*t
= die_containing_type (die
, cu
);
10438 TYPE_VPTR_BASETYPE (type
) = t
;
10443 /* Our own class provides vtbl ptr. */
10444 for (i
= TYPE_NFIELDS (t
) - 1;
10445 i
>= TYPE_N_BASECLASSES (t
);
10448 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10450 if (is_vtable_name (fieldname
, cu
))
10452 TYPE_VPTR_FIELDNO (type
) = i
;
10457 /* Complain if virtual function table field not found. */
10458 if (i
< TYPE_N_BASECLASSES (t
))
10459 complaint (&symfile_complaints
,
10460 _("virtual function table pointer "
10461 "not found when defining class '%s'"),
10462 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10467 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10470 else if (cu
->producer
10471 && strncmp (cu
->producer
,
10472 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10474 /* The IBM XLC compiler does not provide direct indication
10475 of the containing type, but the vtable pointer is
10476 always named __vfp. */
10480 for (i
= TYPE_NFIELDS (type
) - 1;
10481 i
>= TYPE_N_BASECLASSES (type
);
10484 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10486 TYPE_VPTR_FIELDNO (type
) = i
;
10487 TYPE_VPTR_BASETYPE (type
) = type
;
10494 /* Copy fi.typedef_field_list linked list elements content into the
10495 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10496 if (fi
.typedef_field_list
)
10498 int i
= fi
.typedef_field_list_count
;
10500 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10501 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10502 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10503 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10505 /* Reverse the list order to keep the debug info elements order. */
10508 struct typedef_field
*dest
, *src
;
10510 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10511 src
= &fi
.typedef_field_list
->field
;
10512 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10517 do_cleanups (back_to
);
10519 if (HAVE_CPLUS_STRUCT (type
))
10520 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10523 quirk_gcc_member_function_pointer (type
, objfile
);
10525 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10526 snapshots) has been known to create a die giving a declaration
10527 for a class that has, as a child, a die giving a definition for a
10528 nested class. So we have to process our children even if the
10529 current die is a declaration. Normally, of course, a declaration
10530 won't have any children at all. */
10532 while (child_die
!= NULL
&& child_die
->tag
)
10534 if (child_die
->tag
== DW_TAG_member
10535 || child_die
->tag
== DW_TAG_variable
10536 || child_die
->tag
== DW_TAG_inheritance
10537 || child_die
->tag
== DW_TAG_template_value_param
10538 || child_die
->tag
== DW_TAG_template_type_param
)
10543 process_die (child_die
, cu
);
10545 child_die
= sibling_die (child_die
);
10548 /* Do not consider external references. According to the DWARF standard,
10549 these DIEs are identified by the fact that they have no byte_size
10550 attribute, and a declaration attribute. */
10551 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10552 || !die_is_declaration (die
, cu
))
10553 new_symbol (die
, type
, cu
);
10556 /* Given a DW_AT_enumeration_type die, set its type. We do not
10557 complete the type's fields yet, or create any symbols. */
10559 static struct type
*
10560 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10562 struct objfile
*objfile
= cu
->objfile
;
10564 struct attribute
*attr
;
10567 /* If the definition of this type lives in .debug_types, read that type.
10568 Don't follow DW_AT_specification though, that will take us back up
10569 the chain and we want to go down. */
10570 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10573 struct dwarf2_cu
*type_cu
= cu
;
10574 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10576 type
= read_type_die (type_die
, type_cu
);
10578 /* TYPE_CU may not be the same as CU.
10579 Ensure TYPE is recorded in CU's type_hash table. */
10580 return set_die_type (die
, type
, cu
);
10583 type
= alloc_type (objfile
);
10585 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10586 name
= dwarf2_full_name (NULL
, die
, cu
);
10588 TYPE_TAG_NAME (type
) = (char *) name
;
10590 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10593 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10597 TYPE_LENGTH (type
) = 0;
10600 /* The enumeration DIE can be incomplete. In Ada, any type can be
10601 declared as private in the package spec, and then defined only
10602 inside the package body. Such types are known as Taft Amendment
10603 Types. When another package uses such a type, an incomplete DIE
10604 may be generated by the compiler. */
10605 if (die_is_declaration (die
, cu
))
10606 TYPE_STUB (type
) = 1;
10608 return set_die_type (die
, type
, cu
);
10611 /* Given a pointer to a die which begins an enumeration, process all
10612 the dies that define the members of the enumeration, and create the
10613 symbol for the enumeration type.
10615 NOTE: We reverse the order of the element list. */
10618 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10620 struct type
*this_type
;
10622 this_type
= get_die_type (die
, cu
);
10623 if (this_type
== NULL
)
10624 this_type
= read_enumeration_type (die
, cu
);
10626 if (die
->child
!= NULL
)
10628 struct die_info
*child_die
;
10629 struct symbol
*sym
;
10630 struct field
*fields
= NULL
;
10631 int num_fields
= 0;
10632 int unsigned_enum
= 1;
10637 child_die
= die
->child
;
10638 while (child_die
&& child_die
->tag
)
10640 if (child_die
->tag
!= DW_TAG_enumerator
)
10642 process_die (child_die
, cu
);
10646 name
= dwarf2_name (child_die
, cu
);
10649 sym
= new_symbol (child_die
, this_type
, cu
);
10650 if (SYMBOL_VALUE (sym
) < 0)
10655 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10658 mask
|= SYMBOL_VALUE (sym
);
10660 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10662 fields
= (struct field
*)
10664 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10665 * sizeof (struct field
));
10668 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10669 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10670 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10671 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10677 child_die
= sibling_die (child_die
);
10682 TYPE_NFIELDS (this_type
) = num_fields
;
10683 TYPE_FIELDS (this_type
) = (struct field
*)
10684 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10685 memcpy (TYPE_FIELDS (this_type
), fields
,
10686 sizeof (struct field
) * num_fields
);
10690 TYPE_UNSIGNED (this_type
) = 1;
10692 TYPE_FLAG_ENUM (this_type
) = 1;
10695 /* If we are reading an enum from a .debug_types unit, and the enum
10696 is a declaration, and the enum is not the signatured type in the
10697 unit, then we do not want to add a symbol for it. Adding a
10698 symbol would in some cases obscure the true definition of the
10699 enum, giving users an incomplete type when the definition is
10700 actually available. Note that we do not want to do this for all
10701 enums which are just declarations, because C++0x allows forward
10702 enum declarations. */
10703 if (cu
->per_cu
->is_debug_types
10704 && die_is_declaration (die
, cu
))
10706 struct signatured_type
*sig_type
;
10709 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10710 cu
->per_cu
->info_or_types_section
,
10711 cu
->per_cu
->offset
);
10712 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10713 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10717 new_symbol (die
, this_type
, cu
);
10720 /* Extract all information from a DW_TAG_array_type DIE and put it in
10721 the DIE's type field. For now, this only handles one dimensional
10724 static struct type
*
10725 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10727 struct objfile
*objfile
= cu
->objfile
;
10728 struct die_info
*child_die
;
10730 struct type
*element_type
, *range_type
, *index_type
;
10731 struct type
**range_types
= NULL
;
10732 struct attribute
*attr
;
10734 struct cleanup
*back_to
;
10737 element_type
= die_type (die
, cu
);
10739 /* The die_type call above may have already set the type for this DIE. */
10740 type
= get_die_type (die
, cu
);
10744 /* Irix 6.2 native cc creates array types without children for
10745 arrays with unspecified length. */
10746 if (die
->child
== NULL
)
10748 index_type
= objfile_type (objfile
)->builtin_int
;
10749 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10750 type
= create_array_type (NULL
, element_type
, range_type
);
10751 return set_die_type (die
, type
, cu
);
10754 back_to
= make_cleanup (null_cleanup
, NULL
);
10755 child_die
= die
->child
;
10756 while (child_die
&& child_die
->tag
)
10758 if (child_die
->tag
== DW_TAG_subrange_type
)
10760 struct type
*child_type
= read_type_die (child_die
, cu
);
10762 if (child_type
!= NULL
)
10764 /* The range type was succesfully read. Save it for the
10765 array type creation. */
10766 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10768 range_types
= (struct type
**)
10769 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10770 * sizeof (struct type
*));
10772 make_cleanup (free_current_contents
, &range_types
);
10774 range_types
[ndim
++] = child_type
;
10777 child_die
= sibling_die (child_die
);
10780 /* Dwarf2 dimensions are output from left to right, create the
10781 necessary array types in backwards order. */
10783 type
= element_type
;
10785 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10790 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10795 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10798 /* Understand Dwarf2 support for vector types (like they occur on
10799 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10800 array type. This is not part of the Dwarf2/3 standard yet, but a
10801 custom vendor extension. The main difference between a regular
10802 array and the vector variant is that vectors are passed by value
10804 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10806 make_vector_type (type
);
10808 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10809 implementation may choose to implement triple vectors using this
10811 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10814 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10815 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10817 complaint (&symfile_complaints
,
10818 _("DW_AT_byte_size for array type smaller "
10819 "than the total size of elements"));
10822 name
= dwarf2_name (die
, cu
);
10824 TYPE_NAME (type
) = name
;
10826 /* Install the type in the die. */
10827 set_die_type (die
, type
, cu
);
10829 /* set_die_type should be already done. */
10830 set_descriptive_type (type
, die
, cu
);
10832 do_cleanups (back_to
);
10837 static enum dwarf_array_dim_ordering
10838 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10840 struct attribute
*attr
;
10842 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10844 if (attr
) return DW_SND (attr
);
10846 /* GNU F77 is a special case, as at 08/2004 array type info is the
10847 opposite order to the dwarf2 specification, but data is still
10848 laid out as per normal fortran.
10850 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10851 version checking. */
10853 if (cu
->language
== language_fortran
10854 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
10856 return DW_ORD_row_major
;
10859 switch (cu
->language_defn
->la_array_ordering
)
10861 case array_column_major
:
10862 return DW_ORD_col_major
;
10863 case array_row_major
:
10865 return DW_ORD_row_major
;
10869 /* Extract all information from a DW_TAG_set_type DIE and put it in
10870 the DIE's type field. */
10872 static struct type
*
10873 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10875 struct type
*domain_type
, *set_type
;
10876 struct attribute
*attr
;
10878 domain_type
= die_type (die
, cu
);
10880 /* The die_type call above may have already set the type for this DIE. */
10881 set_type
= get_die_type (die
, cu
);
10885 set_type
= create_set_type (NULL
, domain_type
);
10887 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10889 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
10891 return set_die_type (die
, set_type
, cu
);
10894 /* First cut: install each common block member as a global variable. */
10897 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
10899 struct die_info
*child_die
;
10900 struct attribute
*attr
;
10901 struct symbol
*sym
;
10902 CORE_ADDR base
= (CORE_ADDR
) 0;
10904 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10907 /* Support the .debug_loc offsets. */
10908 if (attr_form_is_block (attr
))
10910 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
10912 else if (attr_form_is_section_offset (attr
))
10914 dwarf2_complex_location_expr_complaint ();
10918 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
10919 "common block member");
10922 if (die
->child
!= NULL
)
10924 child_die
= die
->child
;
10925 while (child_die
&& child_die
->tag
)
10929 sym
= new_symbol (child_die
, NULL
, cu
);
10931 && handle_data_member_location (child_die
, cu
, &offset
))
10933 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
10934 add_symbol_to_list (sym
, &global_symbols
);
10936 child_die
= sibling_die (child_die
);
10941 /* Create a type for a C++ namespace. */
10943 static struct type
*
10944 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10946 struct objfile
*objfile
= cu
->objfile
;
10947 const char *previous_prefix
, *name
;
10951 /* For extensions, reuse the type of the original namespace. */
10952 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
10954 struct die_info
*ext_die
;
10955 struct dwarf2_cu
*ext_cu
= cu
;
10957 ext_die
= dwarf2_extension (die
, &ext_cu
);
10958 type
= read_type_die (ext_die
, ext_cu
);
10960 /* EXT_CU may not be the same as CU.
10961 Ensure TYPE is recorded in CU's type_hash table. */
10962 return set_die_type (die
, type
, cu
);
10965 name
= namespace_name (die
, &is_anonymous
, cu
);
10967 /* Now build the name of the current namespace. */
10969 previous_prefix
= determine_prefix (die
, cu
);
10970 if (previous_prefix
[0] != '\0')
10971 name
= typename_concat (&objfile
->objfile_obstack
,
10972 previous_prefix
, name
, 0, cu
);
10974 /* Create the type. */
10975 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
10977 TYPE_NAME (type
) = (char *) name
;
10978 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10980 return set_die_type (die
, type
, cu
);
10983 /* Read a C++ namespace. */
10986 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10988 struct objfile
*objfile
= cu
->objfile
;
10991 /* Add a symbol associated to this if we haven't seen the namespace
10992 before. Also, add a using directive if it's an anonymous
10995 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
10999 type
= read_type_die (die
, cu
);
11000 new_symbol (die
, type
, cu
);
11002 namespace_name (die
, &is_anonymous
, cu
);
11005 const char *previous_prefix
= determine_prefix (die
, cu
);
11007 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11008 NULL
, NULL
, &objfile
->objfile_obstack
);
11012 if (die
->child
!= NULL
)
11014 struct die_info
*child_die
= die
->child
;
11016 while (child_die
&& child_die
->tag
)
11018 process_die (child_die
, cu
);
11019 child_die
= sibling_die (child_die
);
11024 /* Read a Fortran module as type. This DIE can be only a declaration used for
11025 imported module. Still we need that type as local Fortran "use ... only"
11026 declaration imports depend on the created type in determine_prefix. */
11028 static struct type
*
11029 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11031 struct objfile
*objfile
= cu
->objfile
;
11035 module_name
= dwarf2_name (die
, cu
);
11037 complaint (&symfile_complaints
,
11038 _("DW_TAG_module has no name, offset 0x%x"),
11039 die
->offset
.sect_off
);
11040 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
11042 /* determine_prefix uses TYPE_TAG_NAME. */
11043 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11045 return set_die_type (die
, type
, cu
);
11048 /* Read a Fortran module. */
11051 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
11053 struct die_info
*child_die
= die
->child
;
11055 while (child_die
&& child_die
->tag
)
11057 process_die (child_die
, cu
);
11058 child_die
= sibling_die (child_die
);
11062 /* Return the name of the namespace represented by DIE. Set
11063 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
11066 static const char *
11067 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
11069 struct die_info
*current_die
;
11070 const char *name
= NULL
;
11072 /* Loop through the extensions until we find a name. */
11074 for (current_die
= die
;
11075 current_die
!= NULL
;
11076 current_die
= dwarf2_extension (die
, &cu
))
11078 name
= dwarf2_name (current_die
, cu
);
11083 /* Is it an anonymous namespace? */
11085 *is_anonymous
= (name
== NULL
);
11087 name
= CP_ANONYMOUS_NAMESPACE_STR
;
11092 /* Extract all information from a DW_TAG_pointer_type DIE and add to
11093 the user defined type vector. */
11095 static struct type
*
11096 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11098 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
11099 struct comp_unit_head
*cu_header
= &cu
->header
;
11101 struct attribute
*attr_byte_size
;
11102 struct attribute
*attr_address_class
;
11103 int byte_size
, addr_class
;
11104 struct type
*target_type
;
11106 target_type
= die_type (die
, cu
);
11108 /* The die_type call above may have already set the type for this DIE. */
11109 type
= get_die_type (die
, cu
);
11113 type
= lookup_pointer_type (target_type
);
11115 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11116 if (attr_byte_size
)
11117 byte_size
= DW_UNSND (attr_byte_size
);
11119 byte_size
= cu_header
->addr_size
;
11121 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
11122 if (attr_address_class
)
11123 addr_class
= DW_UNSND (attr_address_class
);
11125 addr_class
= DW_ADDR_none
;
11127 /* If the pointer size or address class is different than the
11128 default, create a type variant marked as such and set the
11129 length accordingly. */
11130 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
11132 if (gdbarch_address_class_type_flags_p (gdbarch
))
11136 type_flags
= gdbarch_address_class_type_flags
11137 (gdbarch
, byte_size
, addr_class
);
11138 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11140 type
= make_type_with_address_space (type
, type_flags
);
11142 else if (TYPE_LENGTH (type
) != byte_size
)
11144 complaint (&symfile_complaints
,
11145 _("invalid pointer size %d"), byte_size
);
11149 /* Should we also complain about unhandled address classes? */
11153 TYPE_LENGTH (type
) = byte_size
;
11154 return set_die_type (die
, type
, cu
);
11157 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11158 the user defined type vector. */
11160 static struct type
*
11161 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11164 struct type
*to_type
;
11165 struct type
*domain
;
11167 to_type
= die_type (die
, cu
);
11168 domain
= die_containing_type (die
, cu
);
11170 /* The calls above may have already set the type for this DIE. */
11171 type
= get_die_type (die
, cu
);
11175 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11176 type
= lookup_methodptr_type (to_type
);
11178 type
= lookup_memberptr_type (to_type
, domain
);
11180 return set_die_type (die
, type
, cu
);
11183 /* Extract all information from a DW_TAG_reference_type DIE and add to
11184 the user defined type vector. */
11186 static struct type
*
11187 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11189 struct comp_unit_head
*cu_header
= &cu
->header
;
11190 struct type
*type
, *target_type
;
11191 struct attribute
*attr
;
11193 target_type
= die_type (die
, cu
);
11195 /* The die_type call above may have already set the type for this DIE. */
11196 type
= get_die_type (die
, cu
);
11200 type
= lookup_reference_type (target_type
);
11201 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11204 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11208 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11210 return set_die_type (die
, type
, cu
);
11213 static struct type
*
11214 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11216 struct type
*base_type
, *cv_type
;
11218 base_type
= die_type (die
, cu
);
11220 /* The die_type call above may have already set the type for this DIE. */
11221 cv_type
= get_die_type (die
, cu
);
11225 /* In case the const qualifier is applied to an array type, the element type
11226 is so qualified, not the array type (section 6.7.3 of C99). */
11227 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11229 struct type
*el_type
, *inner_array
;
11231 base_type
= copy_type (base_type
);
11232 inner_array
= base_type
;
11234 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11236 TYPE_TARGET_TYPE (inner_array
) =
11237 copy_type (TYPE_TARGET_TYPE (inner_array
));
11238 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11241 el_type
= TYPE_TARGET_TYPE (inner_array
);
11242 TYPE_TARGET_TYPE (inner_array
) =
11243 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11245 return set_die_type (die
, base_type
, cu
);
11248 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11249 return set_die_type (die
, cv_type
, cu
);
11252 static struct type
*
11253 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11255 struct type
*base_type
, *cv_type
;
11257 base_type
= die_type (die
, cu
);
11259 /* The die_type call above may have already set the type for this DIE. */
11260 cv_type
= get_die_type (die
, cu
);
11264 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11265 return set_die_type (die
, cv_type
, cu
);
11268 /* Extract all information from a DW_TAG_string_type DIE and add to
11269 the user defined type vector. It isn't really a user defined type,
11270 but it behaves like one, with other DIE's using an AT_user_def_type
11271 attribute to reference it. */
11273 static struct type
*
11274 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11276 struct objfile
*objfile
= cu
->objfile
;
11277 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11278 struct type
*type
, *range_type
, *index_type
, *char_type
;
11279 struct attribute
*attr
;
11280 unsigned int length
;
11282 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11285 length
= DW_UNSND (attr
);
11289 /* Check for the DW_AT_byte_size attribute. */
11290 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11293 length
= DW_UNSND (attr
);
11301 index_type
= objfile_type (objfile
)->builtin_int
;
11302 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11303 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11304 type
= create_string_type (NULL
, char_type
, range_type
);
11306 return set_die_type (die
, type
, cu
);
11309 /* Handle DIES due to C code like:
11313 int (*funcp)(int a, long l);
11317 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11319 static struct type
*
11320 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11322 struct objfile
*objfile
= cu
->objfile
;
11323 struct type
*type
; /* Type that this function returns. */
11324 struct type
*ftype
; /* Function that returns above type. */
11325 struct attribute
*attr
;
11327 type
= die_type (die
, cu
);
11329 /* The die_type call above may have already set the type for this DIE. */
11330 ftype
= get_die_type (die
, cu
);
11334 ftype
= lookup_function_type (type
);
11336 /* All functions in C++, Pascal and Java have prototypes. */
11337 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11338 if ((attr
&& (DW_UNSND (attr
) != 0))
11339 || cu
->language
== language_cplus
11340 || cu
->language
== language_java
11341 || cu
->language
== language_pascal
)
11342 TYPE_PROTOTYPED (ftype
) = 1;
11343 else if (producer_is_realview (cu
->producer
))
11344 /* RealView does not emit DW_AT_prototyped. We can not
11345 distinguish prototyped and unprototyped functions; default to
11346 prototyped, since that is more common in modern code (and
11347 RealView warns about unprototyped functions). */
11348 TYPE_PROTOTYPED (ftype
) = 1;
11350 /* Store the calling convention in the type if it's available in
11351 the subroutine die. Otherwise set the calling convention to
11352 the default value DW_CC_normal. */
11353 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11355 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11356 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11357 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11359 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11361 /* We need to add the subroutine type to the die immediately so
11362 we don't infinitely recurse when dealing with parameters
11363 declared as the same subroutine type. */
11364 set_die_type (die
, ftype
, cu
);
11366 if (die
->child
!= NULL
)
11368 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11369 struct die_info
*child_die
;
11370 int nparams
, iparams
;
11372 /* Count the number of parameters.
11373 FIXME: GDB currently ignores vararg functions, but knows about
11374 vararg member functions. */
11376 child_die
= die
->child
;
11377 while (child_die
&& child_die
->tag
)
11379 if (child_die
->tag
== DW_TAG_formal_parameter
)
11381 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11382 TYPE_VARARGS (ftype
) = 1;
11383 child_die
= sibling_die (child_die
);
11386 /* Allocate storage for parameters and fill them in. */
11387 TYPE_NFIELDS (ftype
) = nparams
;
11388 TYPE_FIELDS (ftype
) = (struct field
*)
11389 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11391 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11392 even if we error out during the parameters reading below. */
11393 for (iparams
= 0; iparams
< nparams
; iparams
++)
11394 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11397 child_die
= die
->child
;
11398 while (child_die
&& child_die
->tag
)
11400 if (child_die
->tag
== DW_TAG_formal_parameter
)
11402 struct type
*arg_type
;
11404 /* DWARF version 2 has no clean way to discern C++
11405 static and non-static member functions. G++ helps
11406 GDB by marking the first parameter for non-static
11407 member functions (which is the this pointer) as
11408 artificial. We pass this information to
11409 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11411 DWARF version 3 added DW_AT_object_pointer, which GCC
11412 4.5 does not yet generate. */
11413 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11415 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11418 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11420 /* GCC/43521: In java, the formal parameter
11421 "this" is sometimes not marked with DW_AT_artificial. */
11422 if (cu
->language
== language_java
)
11424 const char *name
= dwarf2_name (child_die
, cu
);
11426 if (name
&& !strcmp (name
, "this"))
11427 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11430 arg_type
= die_type (child_die
, cu
);
11432 /* RealView does not mark THIS as const, which the testsuite
11433 expects. GCC marks THIS as const in method definitions,
11434 but not in the class specifications (GCC PR 43053). */
11435 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11436 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11439 struct dwarf2_cu
*arg_cu
= cu
;
11440 const char *name
= dwarf2_name (child_die
, cu
);
11442 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11445 /* If the compiler emits this, use it. */
11446 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11449 else if (name
&& strcmp (name
, "this") == 0)
11450 /* Function definitions will have the argument names. */
11452 else if (name
== NULL
&& iparams
== 0)
11453 /* Declarations may not have the names, so like
11454 elsewhere in GDB, assume an artificial first
11455 argument is "this". */
11459 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11463 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11466 child_die
= sibling_die (child_die
);
11473 static struct type
*
11474 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11476 struct objfile
*objfile
= cu
->objfile
;
11477 const char *name
= NULL
;
11478 struct type
*this_type
, *target_type
;
11480 name
= dwarf2_full_name (NULL
, die
, cu
);
11481 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11482 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11483 TYPE_NAME (this_type
) = (char *) name
;
11484 set_die_type (die
, this_type
, cu
);
11485 target_type
= die_type (die
, cu
);
11486 if (target_type
!= this_type
)
11487 TYPE_TARGET_TYPE (this_type
) = target_type
;
11490 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11491 spec and cause infinite loops in GDB. */
11492 complaint (&symfile_complaints
,
11493 _("Self-referential DW_TAG_typedef "
11494 "- DIE at 0x%x [in module %s]"),
11495 die
->offset
.sect_off
, objfile
->name
);
11496 TYPE_TARGET_TYPE (this_type
) = NULL
;
11501 /* Find a representation of a given base type and install
11502 it in the TYPE field of the die. */
11504 static struct type
*
11505 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11507 struct objfile
*objfile
= cu
->objfile
;
11509 struct attribute
*attr
;
11510 int encoding
= 0, size
= 0;
11512 enum type_code code
= TYPE_CODE_INT
;
11513 int type_flags
= 0;
11514 struct type
*target_type
= NULL
;
11516 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11519 encoding
= DW_UNSND (attr
);
11521 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11524 size
= DW_UNSND (attr
);
11526 name
= dwarf2_name (die
, cu
);
11529 complaint (&symfile_complaints
,
11530 _("DW_AT_name missing from DW_TAG_base_type"));
11535 case DW_ATE_address
:
11536 /* Turn DW_ATE_address into a void * pointer. */
11537 code
= TYPE_CODE_PTR
;
11538 type_flags
|= TYPE_FLAG_UNSIGNED
;
11539 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11541 case DW_ATE_boolean
:
11542 code
= TYPE_CODE_BOOL
;
11543 type_flags
|= TYPE_FLAG_UNSIGNED
;
11545 case DW_ATE_complex_float
:
11546 code
= TYPE_CODE_COMPLEX
;
11547 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11549 case DW_ATE_decimal_float
:
11550 code
= TYPE_CODE_DECFLOAT
;
11553 code
= TYPE_CODE_FLT
;
11555 case DW_ATE_signed
:
11557 case DW_ATE_unsigned
:
11558 type_flags
|= TYPE_FLAG_UNSIGNED
;
11559 if (cu
->language
== language_fortran
11561 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11562 code
= TYPE_CODE_CHAR
;
11564 case DW_ATE_signed_char
:
11565 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11566 || cu
->language
== language_pascal
11567 || cu
->language
== language_fortran
)
11568 code
= TYPE_CODE_CHAR
;
11570 case DW_ATE_unsigned_char
:
11571 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11572 || cu
->language
== language_pascal
11573 || cu
->language
== language_fortran
)
11574 code
= TYPE_CODE_CHAR
;
11575 type_flags
|= TYPE_FLAG_UNSIGNED
;
11578 /* We just treat this as an integer and then recognize the
11579 type by name elsewhere. */
11583 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11584 dwarf_type_encoding_name (encoding
));
11588 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11589 TYPE_NAME (type
) = name
;
11590 TYPE_TARGET_TYPE (type
) = target_type
;
11592 if (name
&& strcmp (name
, "char") == 0)
11593 TYPE_NOSIGN (type
) = 1;
11595 return set_die_type (die
, type
, cu
);
11598 /* Read the given DW_AT_subrange DIE. */
11600 static struct type
*
11601 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11603 struct type
*base_type
;
11604 struct type
*range_type
;
11605 struct attribute
*attr
;
11607 int low_default_is_valid
;
11609 LONGEST negative_mask
;
11611 base_type
= die_type (die
, cu
);
11612 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11613 check_typedef (base_type
);
11615 /* The die_type call above may have already set the type for this DIE. */
11616 range_type
= get_die_type (die
, cu
);
11620 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11621 omitting DW_AT_lower_bound. */
11622 switch (cu
->language
)
11625 case language_cplus
:
11627 low_default_is_valid
= 1;
11629 case language_fortran
:
11631 low_default_is_valid
= 1;
11634 case language_java
:
11635 case language_objc
:
11637 low_default_is_valid
= (cu
->header
.version
>= 4);
11641 case language_pascal
:
11643 low_default_is_valid
= (cu
->header
.version
>= 4);
11647 low_default_is_valid
= 0;
11651 /* FIXME: For variable sized arrays either of these could be
11652 a variable rather than a constant value. We'll allow it,
11653 but we don't know how to handle it. */
11654 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11656 low
= dwarf2_get_attr_constant_value (attr
, low
);
11657 else if (!low_default_is_valid
)
11658 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11659 "- DIE at 0x%x [in module %s]"),
11660 die
->offset
.sect_off
, cu
->objfile
->name
);
11662 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11665 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11667 /* GCC encodes arrays with unspecified or dynamic length
11668 with a DW_FORM_block1 attribute or a reference attribute.
11669 FIXME: GDB does not yet know how to handle dynamic
11670 arrays properly, treat them as arrays with unspecified
11673 FIXME: jimb/2003-09-22: GDB does not really know
11674 how to handle arrays of unspecified length
11675 either; we just represent them as zero-length
11676 arrays. Choose an appropriate upper bound given
11677 the lower bound we've computed above. */
11681 high
= dwarf2_get_attr_constant_value (attr
, 1);
11685 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11688 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11689 high
= low
+ count
- 1;
11693 /* Unspecified array length. */
11698 /* Dwarf-2 specifications explicitly allows to create subrange types
11699 without specifying a base type.
11700 In that case, the base type must be set to the type of
11701 the lower bound, upper bound or count, in that order, if any of these
11702 three attributes references an object that has a type.
11703 If no base type is found, the Dwarf-2 specifications say that
11704 a signed integer type of size equal to the size of an address should
11706 For the following C code: `extern char gdb_int [];'
11707 GCC produces an empty range DIE.
11708 FIXME: muller/2010-05-28: Possible references to object for low bound,
11709 high bound or count are not yet handled by this code. */
11710 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11712 struct objfile
*objfile
= cu
->objfile
;
11713 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11714 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11715 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11717 /* Test "int", "long int", and "long long int" objfile types,
11718 and select the first one having a size above or equal to the
11719 architecture address size. */
11720 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11721 base_type
= int_type
;
11724 int_type
= objfile_type (objfile
)->builtin_long
;
11725 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11726 base_type
= int_type
;
11729 int_type
= objfile_type (objfile
)->builtin_long_long
;
11730 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11731 base_type
= int_type
;
11737 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11738 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11739 low
|= negative_mask
;
11740 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11741 high
|= negative_mask
;
11743 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11745 /* Mark arrays with dynamic length at least as an array of unspecified
11746 length. GDB could check the boundary but before it gets implemented at
11747 least allow accessing the array elements. */
11748 if (attr
&& attr_form_is_block (attr
))
11749 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11751 /* Ada expects an empty array on no boundary attributes. */
11752 if (attr
== NULL
&& cu
->language
!= language_ada
)
11753 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11755 name
= dwarf2_name (die
, cu
);
11757 TYPE_NAME (range_type
) = name
;
11759 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11761 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11763 set_die_type (die
, range_type
, cu
);
11765 /* set_die_type should be already done. */
11766 set_descriptive_type (range_type
, die
, cu
);
11771 static struct type
*
11772 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11776 /* For now, we only support the C meaning of an unspecified type: void. */
11778 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11779 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11781 return set_die_type (die
, type
, cu
);
11784 /* Read a single die and all its descendents. Set the die's sibling
11785 field to NULL; set other fields in the die correctly, and set all
11786 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11787 location of the info_ptr after reading all of those dies. PARENT
11788 is the parent of the die in question. */
11790 static struct die_info
*
11791 read_die_and_children (const struct die_reader_specs
*reader
,
11792 gdb_byte
*info_ptr
,
11793 gdb_byte
**new_info_ptr
,
11794 struct die_info
*parent
)
11796 struct die_info
*die
;
11800 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11803 *new_info_ptr
= cur_ptr
;
11806 store_in_ref_table (die
, reader
->cu
);
11809 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11813 *new_info_ptr
= cur_ptr
;
11816 die
->sibling
= NULL
;
11817 die
->parent
= parent
;
11821 /* Read a die, all of its descendents, and all of its siblings; set
11822 all of the fields of all of the dies correctly. Arguments are as
11823 in read_die_and_children. */
11825 static struct die_info
*
11826 read_die_and_siblings (const struct die_reader_specs
*reader
,
11827 gdb_byte
*info_ptr
,
11828 gdb_byte
**new_info_ptr
,
11829 struct die_info
*parent
)
11831 struct die_info
*first_die
, *last_sibling
;
11834 cur_ptr
= info_ptr
;
11835 first_die
= last_sibling
= NULL
;
11839 struct die_info
*die
11840 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11844 *new_info_ptr
= cur_ptr
;
11851 last_sibling
->sibling
= die
;
11853 last_sibling
= die
;
11857 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
11859 The caller is responsible for filling in the extra attributes
11860 and updating (*DIEP)->num_attrs.
11861 Set DIEP to point to a newly allocated die with its information,
11862 except for its child, sibling, and parent fields.
11863 Set HAS_CHILDREN to tell whether the die has children or not. */
11866 read_full_die_1 (const struct die_reader_specs
*reader
,
11867 struct die_info
**diep
, gdb_byte
*info_ptr
,
11868 int *has_children
, int num_extra_attrs
)
11870 unsigned int abbrev_number
, bytes_read
, i
;
11871 sect_offset offset
;
11872 struct abbrev_info
*abbrev
;
11873 struct die_info
*die
;
11874 struct dwarf2_cu
*cu
= reader
->cu
;
11875 bfd
*abfd
= reader
->abfd
;
11877 offset
.sect_off
= info_ptr
- reader
->buffer
;
11878 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
11879 info_ptr
+= bytes_read
;
11880 if (!abbrev_number
)
11887 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
11889 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
11891 bfd_get_filename (abfd
));
11893 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
11894 die
->offset
= offset
;
11895 die
->tag
= abbrev
->tag
;
11896 die
->abbrev
= abbrev_number
;
11898 /* Make the result usable.
11899 The caller needs to update num_attrs after adding the extra
11901 die
->num_attrs
= abbrev
->num_attrs
;
11903 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
11904 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
11908 *has_children
= abbrev
->has_children
;
11912 /* Read a die and all its attributes.
11913 Set DIEP to point to a newly allocated die with its information,
11914 except for its child, sibling, and parent fields.
11915 Set HAS_CHILDREN to tell whether the die has children or not. */
11918 read_full_die (const struct die_reader_specs
*reader
,
11919 struct die_info
**diep
, gdb_byte
*info_ptr
,
11922 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
11925 /* Abbreviation tables.
11927 In DWARF version 2, the description of the debugging information is
11928 stored in a separate .debug_abbrev section. Before we read any
11929 dies from a section we read in all abbreviations and install them
11930 in a hash table. */
11932 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
11934 static struct abbrev_info
*
11935 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
11937 struct abbrev_info
*abbrev
;
11939 abbrev
= (struct abbrev_info
*)
11940 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
11941 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11945 /* Add an abbreviation to the table. */
11948 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
11949 unsigned int abbrev_number
,
11950 struct abbrev_info
*abbrev
)
11952 unsigned int hash_number
;
11954 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11955 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
11956 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
11959 /* Look up an abbrev in the table.
11960 Returns NULL if the abbrev is not found. */
11962 static struct abbrev_info
*
11963 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
11964 unsigned int abbrev_number
)
11966 unsigned int hash_number
;
11967 struct abbrev_info
*abbrev
;
11969 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
11970 abbrev
= abbrev_table
->abbrevs
[hash_number
];
11974 if (abbrev
->number
== abbrev_number
)
11976 abbrev
= abbrev
->next
;
11981 /* Read in an abbrev table. */
11983 static struct abbrev_table
*
11984 abbrev_table_read_table (struct dwarf2_section_info
*section
,
11985 sect_offset offset
)
11987 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11988 bfd
*abfd
= section
->asection
->owner
;
11989 struct abbrev_table
*abbrev_table
;
11990 gdb_byte
*abbrev_ptr
;
11991 struct abbrev_info
*cur_abbrev
;
11992 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
11993 unsigned int abbrev_form
;
11994 struct attr_abbrev
*cur_attrs
;
11995 unsigned int allocated_attrs
;
11997 abbrev_table
= XMALLOC (struct abbrev_table
);
11998 abbrev_table
->offset
= offset
;
11999 obstack_init (&abbrev_table
->abbrev_obstack
);
12000 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12002 * sizeof (struct abbrev_info
*)));
12003 memset (abbrev_table
->abbrevs
, 0,
12004 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12006 dwarf2_read_section (objfile
, section
);
12007 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12008 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12009 abbrev_ptr
+= bytes_read
;
12011 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12012 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12014 /* Loop until we reach an abbrev number of 0. */
12015 while (abbrev_number
)
12017 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
12019 /* read in abbrev header */
12020 cur_abbrev
->number
= abbrev_number
;
12021 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12022 abbrev_ptr
+= bytes_read
;
12023 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
12026 /* now read in declarations */
12027 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12028 abbrev_ptr
+= bytes_read
;
12029 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12030 abbrev_ptr
+= bytes_read
;
12031 while (abbrev_name
)
12033 if (cur_abbrev
->num_attrs
== allocated_attrs
)
12035 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
12037 = xrealloc (cur_attrs
, (allocated_attrs
12038 * sizeof (struct attr_abbrev
)));
12041 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
12042 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
12043 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12044 abbrev_ptr
+= bytes_read
;
12045 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12046 abbrev_ptr
+= bytes_read
;
12049 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12050 (cur_abbrev
->num_attrs
12051 * sizeof (struct attr_abbrev
)));
12052 memcpy (cur_abbrev
->attrs
, cur_attrs
,
12053 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
12055 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
12057 /* Get next abbreviation.
12058 Under Irix6 the abbreviations for a compilation unit are not
12059 always properly terminated with an abbrev number of 0.
12060 Exit loop if we encounter an abbreviation which we have
12061 already read (which means we are about to read the abbreviations
12062 for the next compile unit) or if the end of the abbreviation
12063 table is reached. */
12064 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
12066 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12067 abbrev_ptr
+= bytes_read
;
12068 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
12073 return abbrev_table
;
12076 /* Free the resources held by ABBREV_TABLE. */
12079 abbrev_table_free (struct abbrev_table
*abbrev_table
)
12081 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
12082 xfree (abbrev_table
);
12085 /* Same as abbrev_table_free but as a cleanup.
12086 We pass in a pointer to the pointer to the table so that we can
12087 set the pointer to NULL when we're done. It also simplifies
12088 build_type_unit_groups. */
12091 abbrev_table_free_cleanup (void *table_ptr
)
12093 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
12095 if (*abbrev_table_ptr
!= NULL
)
12096 abbrev_table_free (*abbrev_table_ptr
);
12097 *abbrev_table_ptr
= NULL
;
12100 /* Read the abbrev table for CU from ABBREV_SECTION. */
12103 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
12104 struct dwarf2_section_info
*abbrev_section
)
12107 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
12110 /* Release the memory used by the abbrev table for a compilation unit. */
12113 dwarf2_free_abbrev_table (void *ptr_to_cu
)
12115 struct dwarf2_cu
*cu
= ptr_to_cu
;
12117 abbrev_table_free (cu
->abbrev_table
);
12118 /* Set this to NULL so that we SEGV if we try to read it later,
12119 and also because free_comp_unit verifies this is NULL. */
12120 cu
->abbrev_table
= NULL
;
12123 /* Returns nonzero if TAG represents a type that we might generate a partial
12127 is_type_tag_for_partial (int tag
)
12132 /* Some types that would be reasonable to generate partial symbols for,
12133 that we don't at present. */
12134 case DW_TAG_array_type
:
12135 case DW_TAG_file_type
:
12136 case DW_TAG_ptr_to_member_type
:
12137 case DW_TAG_set_type
:
12138 case DW_TAG_string_type
:
12139 case DW_TAG_subroutine_type
:
12141 case DW_TAG_base_type
:
12142 case DW_TAG_class_type
:
12143 case DW_TAG_interface_type
:
12144 case DW_TAG_enumeration_type
:
12145 case DW_TAG_structure_type
:
12146 case DW_TAG_subrange_type
:
12147 case DW_TAG_typedef
:
12148 case DW_TAG_union_type
:
12155 /* Load all DIEs that are interesting for partial symbols into memory. */
12157 static struct partial_die_info
*
12158 load_partial_dies (const struct die_reader_specs
*reader
,
12159 gdb_byte
*info_ptr
, int building_psymtab
)
12161 struct dwarf2_cu
*cu
= reader
->cu
;
12162 struct objfile
*objfile
= cu
->objfile
;
12163 struct partial_die_info
*part_die
;
12164 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12165 struct abbrev_info
*abbrev
;
12166 unsigned int bytes_read
;
12167 unsigned int load_all
= 0;
12168 int nesting_level
= 1;
12173 gdb_assert (cu
->per_cu
!= NULL
);
12174 if (cu
->per_cu
->load_all_dies
)
12178 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12182 &cu
->comp_unit_obstack
,
12183 hashtab_obstack_allocate
,
12184 dummy_obstack_deallocate
);
12186 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12187 sizeof (struct partial_die_info
));
12191 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12193 /* A NULL abbrev means the end of a series of children. */
12194 if (abbrev
== NULL
)
12196 if (--nesting_level
== 0)
12198 /* PART_DIE was probably the last thing allocated on the
12199 comp_unit_obstack, so we could call obstack_free
12200 here. We don't do that because the waste is small,
12201 and will be cleaned up when we're done with this
12202 compilation unit. This way, we're also more robust
12203 against other users of the comp_unit_obstack. */
12206 info_ptr
+= bytes_read
;
12207 last_die
= parent_die
;
12208 parent_die
= parent_die
->die_parent
;
12212 /* Check for template arguments. We never save these; if
12213 they're seen, we just mark the parent, and go on our way. */
12214 if (parent_die
!= NULL
12215 && cu
->language
== language_cplus
12216 && (abbrev
->tag
== DW_TAG_template_type_param
12217 || abbrev
->tag
== DW_TAG_template_value_param
))
12219 parent_die
->has_template_arguments
= 1;
12223 /* We don't need a partial DIE for the template argument. */
12224 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12229 /* We only recurse into c++ subprograms looking for template arguments.
12230 Skip their other children. */
12232 && cu
->language
== language_cplus
12233 && parent_die
!= NULL
12234 && parent_die
->tag
== DW_TAG_subprogram
)
12236 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12240 /* Check whether this DIE is interesting enough to save. Normally
12241 we would not be interested in members here, but there may be
12242 later variables referencing them via DW_AT_specification (for
12243 static members). */
12245 && !is_type_tag_for_partial (abbrev
->tag
)
12246 && abbrev
->tag
!= DW_TAG_constant
12247 && abbrev
->tag
!= DW_TAG_enumerator
12248 && abbrev
->tag
!= DW_TAG_subprogram
12249 && abbrev
->tag
!= DW_TAG_lexical_block
12250 && abbrev
->tag
!= DW_TAG_variable
12251 && abbrev
->tag
!= DW_TAG_namespace
12252 && abbrev
->tag
!= DW_TAG_module
12253 && abbrev
->tag
!= DW_TAG_member
12254 && abbrev
->tag
!= DW_TAG_imported_unit
)
12256 /* Otherwise we skip to the next sibling, if any. */
12257 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12261 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12264 /* This two-pass algorithm for processing partial symbols has a
12265 high cost in cache pressure. Thus, handle some simple cases
12266 here which cover the majority of C partial symbols. DIEs
12267 which neither have specification tags in them, nor could have
12268 specification tags elsewhere pointing at them, can simply be
12269 processed and discarded.
12271 This segment is also optional; scan_partial_symbols and
12272 add_partial_symbol will handle these DIEs if we chain
12273 them in normally. When compilers which do not emit large
12274 quantities of duplicate debug information are more common,
12275 this code can probably be removed. */
12277 /* Any complete simple types at the top level (pretty much all
12278 of them, for a language without namespaces), can be processed
12280 if (parent_die
== NULL
12281 && part_die
->has_specification
== 0
12282 && part_die
->is_declaration
== 0
12283 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12284 || part_die
->tag
== DW_TAG_base_type
12285 || part_die
->tag
== DW_TAG_subrange_type
))
12287 if (building_psymtab
&& part_die
->name
!= NULL
)
12288 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12289 VAR_DOMAIN
, LOC_TYPEDEF
,
12290 &objfile
->static_psymbols
,
12291 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12292 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12296 /* The exception for DW_TAG_typedef with has_children above is
12297 a workaround of GCC PR debug/47510. In the case of this complaint
12298 type_name_no_tag_or_error will error on such types later.
12300 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12301 it could not find the child DIEs referenced later, this is checked
12302 above. In correct DWARF DW_TAG_typedef should have no children. */
12304 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12305 complaint (&symfile_complaints
,
12306 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12307 "- DIE at 0x%x [in module %s]"),
12308 part_die
->offset
.sect_off
, objfile
->name
);
12310 /* If we're at the second level, and we're an enumerator, and
12311 our parent has no specification (meaning possibly lives in a
12312 namespace elsewhere), then we can add the partial symbol now
12313 instead of queueing it. */
12314 if (part_die
->tag
== DW_TAG_enumerator
12315 && parent_die
!= NULL
12316 && parent_die
->die_parent
== NULL
12317 && parent_die
->tag
== DW_TAG_enumeration_type
12318 && parent_die
->has_specification
== 0)
12320 if (part_die
->name
== NULL
)
12321 complaint (&symfile_complaints
,
12322 _("malformed enumerator DIE ignored"));
12323 else if (building_psymtab
)
12324 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12325 VAR_DOMAIN
, LOC_CONST
,
12326 (cu
->language
== language_cplus
12327 || cu
->language
== language_java
)
12328 ? &objfile
->global_psymbols
12329 : &objfile
->static_psymbols
,
12330 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12332 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12336 /* We'll save this DIE so link it in. */
12337 part_die
->die_parent
= parent_die
;
12338 part_die
->die_sibling
= NULL
;
12339 part_die
->die_child
= NULL
;
12341 if (last_die
&& last_die
== parent_die
)
12342 last_die
->die_child
= part_die
;
12344 last_die
->die_sibling
= part_die
;
12346 last_die
= part_die
;
12348 if (first_die
== NULL
)
12349 first_die
= part_die
;
12351 /* Maybe add the DIE to the hash table. Not all DIEs that we
12352 find interesting need to be in the hash table, because we
12353 also have the parent/sibling/child chains; only those that we
12354 might refer to by offset later during partial symbol reading.
12356 For now this means things that might have be the target of a
12357 DW_AT_specification, DW_AT_abstract_origin, or
12358 DW_AT_extension. DW_AT_extension will refer only to
12359 namespaces; DW_AT_abstract_origin refers to functions (and
12360 many things under the function DIE, but we do not recurse
12361 into function DIEs during partial symbol reading) and
12362 possibly variables as well; DW_AT_specification refers to
12363 declarations. Declarations ought to have the DW_AT_declaration
12364 flag. It happens that GCC forgets to put it in sometimes, but
12365 only for functions, not for types.
12367 Adding more things than necessary to the hash table is harmless
12368 except for the performance cost. Adding too few will result in
12369 wasted time in find_partial_die, when we reread the compilation
12370 unit with load_all_dies set. */
12373 || abbrev
->tag
== DW_TAG_constant
12374 || abbrev
->tag
== DW_TAG_subprogram
12375 || abbrev
->tag
== DW_TAG_variable
12376 || abbrev
->tag
== DW_TAG_namespace
12377 || part_die
->is_declaration
)
12381 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12382 part_die
->offset
.sect_off
, INSERT
);
12386 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12387 sizeof (struct partial_die_info
));
12389 /* For some DIEs we want to follow their children (if any). For C
12390 we have no reason to follow the children of structures; for other
12391 languages we have to, so that we can get at method physnames
12392 to infer fully qualified class names, for DW_AT_specification,
12393 and for C++ template arguments. For C++, we also look one level
12394 inside functions to find template arguments (if the name of the
12395 function does not already contain the template arguments).
12397 For Ada, we need to scan the children of subprograms and lexical
12398 blocks as well because Ada allows the definition of nested
12399 entities that could be interesting for the debugger, such as
12400 nested subprograms for instance. */
12401 if (last_die
->has_children
12403 || last_die
->tag
== DW_TAG_namespace
12404 || last_die
->tag
== DW_TAG_module
12405 || last_die
->tag
== DW_TAG_enumeration_type
12406 || (cu
->language
== language_cplus
12407 && last_die
->tag
== DW_TAG_subprogram
12408 && (last_die
->name
== NULL
12409 || strchr (last_die
->name
, '<') == NULL
))
12410 || (cu
->language
!= language_c
12411 && (last_die
->tag
== DW_TAG_class_type
12412 || last_die
->tag
== DW_TAG_interface_type
12413 || last_die
->tag
== DW_TAG_structure_type
12414 || last_die
->tag
== DW_TAG_union_type
))
12415 || (cu
->language
== language_ada
12416 && (last_die
->tag
== DW_TAG_subprogram
12417 || last_die
->tag
== DW_TAG_lexical_block
))))
12420 parent_die
= last_die
;
12424 /* Otherwise we skip to the next sibling, if any. */
12425 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12427 /* Back to the top, do it again. */
12431 /* Read a minimal amount of information into the minimal die structure. */
12434 read_partial_die (const struct die_reader_specs
*reader
,
12435 struct partial_die_info
*part_die
,
12436 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12437 gdb_byte
*info_ptr
)
12439 struct dwarf2_cu
*cu
= reader
->cu
;
12440 struct objfile
*objfile
= cu
->objfile
;
12441 gdb_byte
*buffer
= reader
->buffer
;
12443 struct attribute attr
;
12444 int has_low_pc_attr
= 0;
12445 int has_high_pc_attr
= 0;
12446 int high_pc_relative
= 0;
12448 memset (part_die
, 0, sizeof (struct partial_die_info
));
12450 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12452 info_ptr
+= abbrev_len
;
12454 if (abbrev
== NULL
)
12457 part_die
->tag
= abbrev
->tag
;
12458 part_die
->has_children
= abbrev
->has_children
;
12460 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12462 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12464 /* Store the data if it is of an attribute we want to keep in a
12465 partial symbol table. */
12469 switch (part_die
->tag
)
12471 case DW_TAG_compile_unit
:
12472 case DW_TAG_partial_unit
:
12473 case DW_TAG_type_unit
:
12474 /* Compilation units have a DW_AT_name that is a filename, not
12475 a source language identifier. */
12476 case DW_TAG_enumeration_type
:
12477 case DW_TAG_enumerator
:
12478 /* These tags always have simple identifiers already; no need
12479 to canonicalize them. */
12480 part_die
->name
= DW_STRING (&attr
);
12484 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12485 &objfile
->objfile_obstack
);
12489 case DW_AT_linkage_name
:
12490 case DW_AT_MIPS_linkage_name
:
12491 /* Note that both forms of linkage name might appear. We
12492 assume they will be the same, and we only store the last
12494 if (cu
->language
== language_ada
)
12495 part_die
->name
= DW_STRING (&attr
);
12496 part_die
->linkage_name
= DW_STRING (&attr
);
12499 has_low_pc_attr
= 1;
12500 part_die
->lowpc
= DW_ADDR (&attr
);
12502 case DW_AT_high_pc
:
12503 has_high_pc_attr
= 1;
12504 if (attr
.form
== DW_FORM_addr
12505 || attr
.form
== DW_FORM_GNU_addr_index
)
12506 part_die
->highpc
= DW_ADDR (&attr
);
12509 high_pc_relative
= 1;
12510 part_die
->highpc
= DW_UNSND (&attr
);
12513 case DW_AT_location
:
12514 /* Support the .debug_loc offsets. */
12515 if (attr_form_is_block (&attr
))
12517 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12519 else if (attr_form_is_section_offset (&attr
))
12521 dwarf2_complex_location_expr_complaint ();
12525 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12526 "partial symbol information");
12529 case DW_AT_external
:
12530 part_die
->is_external
= DW_UNSND (&attr
);
12532 case DW_AT_declaration
:
12533 part_die
->is_declaration
= DW_UNSND (&attr
);
12536 part_die
->has_type
= 1;
12538 case DW_AT_abstract_origin
:
12539 case DW_AT_specification
:
12540 case DW_AT_extension
:
12541 part_die
->has_specification
= 1;
12542 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12544 case DW_AT_sibling
:
12545 /* Ignore absolute siblings, they might point outside of
12546 the current compile unit. */
12547 if (attr
.form
== DW_FORM_ref_addr
)
12548 complaint (&symfile_complaints
,
12549 _("ignoring absolute DW_AT_sibling"));
12551 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12553 case DW_AT_byte_size
:
12554 part_die
->has_byte_size
= 1;
12556 case DW_AT_calling_convention
:
12557 /* DWARF doesn't provide a way to identify a program's source-level
12558 entry point. DW_AT_calling_convention attributes are only meant
12559 to describe functions' calling conventions.
12561 However, because it's a necessary piece of information in
12562 Fortran, and because DW_CC_program is the only piece of debugging
12563 information whose definition refers to a 'main program' at all,
12564 several compilers have begun marking Fortran main programs with
12565 DW_CC_program --- even when those functions use the standard
12566 calling conventions.
12568 So until DWARF specifies a way to provide this information and
12569 compilers pick up the new representation, we'll support this
12571 if (DW_UNSND (&attr
) == DW_CC_program
12572 && cu
->language
== language_fortran
)
12574 set_main_name (part_die
->name
);
12576 /* As this DIE has a static linkage the name would be difficult
12577 to look up later. */
12578 language_of_main
= language_fortran
;
12582 if (DW_UNSND (&attr
) == DW_INL_inlined
12583 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12584 part_die
->may_be_inlined
= 1;
12588 if (part_die
->tag
== DW_TAG_imported_unit
)
12589 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12597 if (high_pc_relative
)
12598 part_die
->highpc
+= part_die
->lowpc
;
12600 if (has_low_pc_attr
&& has_high_pc_attr
)
12602 /* When using the GNU linker, .gnu.linkonce. sections are used to
12603 eliminate duplicate copies of functions and vtables and such.
12604 The linker will arbitrarily choose one and discard the others.
12605 The AT_*_pc values for such functions refer to local labels in
12606 these sections. If the section from that file was discarded, the
12607 labels are not in the output, so the relocs get a value of 0.
12608 If this is a discarded function, mark the pc bounds as invalid,
12609 so that GDB will ignore it. */
12610 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12612 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12614 complaint (&symfile_complaints
,
12615 _("DW_AT_low_pc %s is zero "
12616 "for DIE at 0x%x [in module %s]"),
12617 paddress (gdbarch
, part_die
->lowpc
),
12618 part_die
->offset
.sect_off
, objfile
->name
);
12620 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12621 else if (part_die
->lowpc
>= part_die
->highpc
)
12623 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12625 complaint (&symfile_complaints
,
12626 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12627 "for DIE at 0x%x [in module %s]"),
12628 paddress (gdbarch
, part_die
->lowpc
),
12629 paddress (gdbarch
, part_die
->highpc
),
12630 part_die
->offset
.sect_off
, objfile
->name
);
12633 part_die
->has_pc_info
= 1;
12639 /* Find a cached partial DIE at OFFSET in CU. */
12641 static struct partial_die_info
*
12642 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12644 struct partial_die_info
*lookup_die
= NULL
;
12645 struct partial_die_info part_die
;
12647 part_die
.offset
= offset
;
12648 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12654 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12655 except in the case of .debug_types DIEs which do not reference
12656 outside their CU (they do however referencing other types via
12657 DW_FORM_ref_sig8). */
12659 static struct partial_die_info
*
12660 find_partial_die (sect_offset offset
, struct dwarf2_cu
*cu
)
12662 struct objfile
*objfile
= cu
->objfile
;
12663 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12664 struct partial_die_info
*pd
= NULL
;
12666 if (offset_in_cu_p (&cu
->header
, offset
))
12668 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12671 /* We missed recording what we needed.
12672 Load all dies and try again. */
12673 per_cu
= cu
->per_cu
;
12677 /* TUs don't reference other CUs/TUs (except via type signatures). */
12678 if (cu
->per_cu
->is_debug_types
)
12680 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12681 " external reference to offset 0x%lx [in module %s].\n"),
12682 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12683 bfd_get_filename (objfile
->obfd
));
12685 per_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
12687 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12688 load_partial_comp_unit (per_cu
);
12690 per_cu
->cu
->last_used
= 0;
12691 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12694 /* If we didn't find it, and not all dies have been loaded,
12695 load them all and try again. */
12697 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12699 per_cu
->load_all_dies
= 1;
12701 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12702 THIS_CU->cu may already be in use. So we can't just free it and
12703 replace its DIEs with the ones we read in. Instead, we leave those
12704 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12705 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12707 load_partial_comp_unit (per_cu
);
12709 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12713 internal_error (__FILE__
, __LINE__
,
12714 _("could not find partial DIE 0x%x "
12715 "in cache [from module %s]\n"),
12716 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12720 /* See if we can figure out if the class lives in a namespace. We do
12721 this by looking for a member function; its demangled name will
12722 contain namespace info, if there is any. */
12725 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12726 struct dwarf2_cu
*cu
)
12728 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12729 what template types look like, because the demangler
12730 frequently doesn't give the same name as the debug info. We
12731 could fix this by only using the demangled name to get the
12732 prefix (but see comment in read_structure_type). */
12734 struct partial_die_info
*real_pdi
;
12735 struct partial_die_info
*child_pdi
;
12737 /* If this DIE (this DIE's specification, if any) has a parent, then
12738 we should not do this. We'll prepend the parent's fully qualified
12739 name when we create the partial symbol. */
12741 real_pdi
= struct_pdi
;
12742 while (real_pdi
->has_specification
)
12743 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
12745 if (real_pdi
->die_parent
!= NULL
)
12748 for (child_pdi
= struct_pdi
->die_child
;
12750 child_pdi
= child_pdi
->die_sibling
)
12752 if (child_pdi
->tag
== DW_TAG_subprogram
12753 && child_pdi
->linkage_name
!= NULL
)
12755 char *actual_class_name
12756 = language_class_name_from_physname (cu
->language_defn
,
12757 child_pdi
->linkage_name
);
12758 if (actual_class_name
!= NULL
)
12761 = obsavestring (actual_class_name
,
12762 strlen (actual_class_name
),
12763 &cu
->objfile
->objfile_obstack
);
12764 xfree (actual_class_name
);
12771 /* Adjust PART_DIE before generating a symbol for it. This function
12772 may set the is_external flag or change the DIE's name. */
12775 fixup_partial_die (struct partial_die_info
*part_die
,
12776 struct dwarf2_cu
*cu
)
12778 /* Once we've fixed up a die, there's no point in doing so again.
12779 This also avoids a memory leak if we were to call
12780 guess_partial_die_structure_name multiple times. */
12781 if (part_die
->fixup_called
)
12784 /* If we found a reference attribute and the DIE has no name, try
12785 to find a name in the referred to DIE. */
12787 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12789 struct partial_die_info
*spec_die
;
12791 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
12793 fixup_partial_die (spec_die
, cu
);
12795 if (spec_die
->name
)
12797 part_die
->name
= spec_die
->name
;
12799 /* Copy DW_AT_external attribute if it is set. */
12800 if (spec_die
->is_external
)
12801 part_die
->is_external
= spec_die
->is_external
;
12805 /* Set default names for some unnamed DIEs. */
12807 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12808 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12810 /* If there is no parent die to provide a namespace, and there are
12811 children, see if we can determine the namespace from their linkage
12813 if (cu
->language
== language_cplus
12814 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12815 && part_die
->die_parent
== NULL
12816 && part_die
->has_children
12817 && (part_die
->tag
== DW_TAG_class_type
12818 || part_die
->tag
== DW_TAG_structure_type
12819 || part_die
->tag
== DW_TAG_union_type
))
12820 guess_partial_die_structure_name (part_die
, cu
);
12822 /* GCC might emit a nameless struct or union that has a linkage
12823 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12824 if (part_die
->name
== NULL
12825 && (part_die
->tag
== DW_TAG_class_type
12826 || part_die
->tag
== DW_TAG_interface_type
12827 || part_die
->tag
== DW_TAG_structure_type
12828 || part_die
->tag
== DW_TAG_union_type
)
12829 && part_die
->linkage_name
!= NULL
)
12833 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
12838 /* Strip any leading namespaces/classes, keep only the base name.
12839 DW_AT_name for named DIEs does not contain the prefixes. */
12840 base
= strrchr (demangled
, ':');
12841 if (base
&& base
> demangled
&& base
[-1] == ':')
12846 part_die
->name
= obsavestring (base
, strlen (base
),
12847 &cu
->objfile
->objfile_obstack
);
12852 part_die
->fixup_called
= 1;
12855 /* Read an attribute value described by an attribute form. */
12858 read_attribute_value (const struct die_reader_specs
*reader
,
12859 struct attribute
*attr
, unsigned form
,
12860 gdb_byte
*info_ptr
)
12862 struct dwarf2_cu
*cu
= reader
->cu
;
12863 bfd
*abfd
= reader
->abfd
;
12864 struct comp_unit_head
*cu_header
= &cu
->header
;
12865 unsigned int bytes_read
;
12866 struct dwarf_block
*blk
;
12871 case DW_FORM_ref_addr
:
12872 if (cu
->header
.version
== 2)
12873 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12875 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
12876 &cu
->header
, &bytes_read
);
12877 info_ptr
+= bytes_read
;
12880 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
12881 info_ptr
+= bytes_read
;
12883 case DW_FORM_block2
:
12884 blk
= dwarf_alloc_block (cu
);
12885 blk
->size
= read_2_bytes (abfd
, info_ptr
);
12887 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12888 info_ptr
+= blk
->size
;
12889 DW_BLOCK (attr
) = blk
;
12891 case DW_FORM_block4
:
12892 blk
= dwarf_alloc_block (cu
);
12893 blk
->size
= read_4_bytes (abfd
, info_ptr
);
12895 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12896 info_ptr
+= blk
->size
;
12897 DW_BLOCK (attr
) = blk
;
12899 case DW_FORM_data2
:
12900 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
12903 case DW_FORM_data4
:
12904 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
12907 case DW_FORM_data8
:
12908 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
12911 case DW_FORM_sec_offset
:
12912 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
12913 info_ptr
+= bytes_read
;
12915 case DW_FORM_string
:
12916 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
12917 DW_STRING_IS_CANONICAL (attr
) = 0;
12918 info_ptr
+= bytes_read
;
12921 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
12923 DW_STRING_IS_CANONICAL (attr
) = 0;
12924 info_ptr
+= bytes_read
;
12926 case DW_FORM_exprloc
:
12927 case DW_FORM_block
:
12928 blk
= dwarf_alloc_block (cu
);
12929 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12930 info_ptr
+= bytes_read
;
12931 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12932 info_ptr
+= blk
->size
;
12933 DW_BLOCK (attr
) = blk
;
12935 case DW_FORM_block1
:
12936 blk
= dwarf_alloc_block (cu
);
12937 blk
->size
= read_1_byte (abfd
, info_ptr
);
12939 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
12940 info_ptr
+= blk
->size
;
12941 DW_BLOCK (attr
) = blk
;
12943 case DW_FORM_data1
:
12944 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12948 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
12951 case DW_FORM_flag_present
:
12952 DW_UNSND (attr
) = 1;
12954 case DW_FORM_sdata
:
12955 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
12956 info_ptr
+= bytes_read
;
12958 case DW_FORM_udata
:
12959 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12960 info_ptr
+= bytes_read
;
12963 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12964 + read_1_byte (abfd
, info_ptr
));
12968 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12969 + read_2_bytes (abfd
, info_ptr
));
12973 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12974 + read_4_bytes (abfd
, info_ptr
));
12978 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12979 + read_8_bytes (abfd
, info_ptr
));
12982 case DW_FORM_ref_sig8
:
12983 /* Convert the signature to something we can record in DW_UNSND
12985 NOTE: This is NULL if the type wasn't found. */
12986 DW_SIGNATURED_TYPE (attr
) =
12987 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
12990 case DW_FORM_ref_udata
:
12991 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
12992 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
12993 info_ptr
+= bytes_read
;
12995 case DW_FORM_indirect
:
12996 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12997 info_ptr
+= bytes_read
;
12998 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
13000 case DW_FORM_GNU_addr_index
:
13001 if (reader
->dwo_file
== NULL
)
13003 /* For now flag a hard error.
13004 Later we can turn this into a complaint. */
13005 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13006 dwarf_form_name (form
),
13007 bfd_get_filename (abfd
));
13009 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
13010 info_ptr
+= bytes_read
;
13012 case DW_FORM_GNU_str_index
:
13013 if (reader
->dwo_file
== NULL
)
13015 /* For now flag a hard error.
13016 Later we can turn this into a complaint if warranted. */
13017 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13018 dwarf_form_name (form
),
13019 bfd_get_filename (abfd
));
13022 ULONGEST str_index
=
13023 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13025 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
13026 DW_STRING_IS_CANONICAL (attr
) = 0;
13027 info_ptr
+= bytes_read
;
13031 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
13032 dwarf_form_name (form
),
13033 bfd_get_filename (abfd
));
13036 /* We have seen instances where the compiler tried to emit a byte
13037 size attribute of -1 which ended up being encoded as an unsigned
13038 0xffffffff. Although 0xffffffff is technically a valid size value,
13039 an object of this size seems pretty unlikely so we can relatively
13040 safely treat these cases as if the size attribute was invalid and
13041 treat them as zero by default. */
13042 if (attr
->name
== DW_AT_byte_size
13043 && form
== DW_FORM_data4
13044 && DW_UNSND (attr
) >= 0xffffffff)
13047 (&symfile_complaints
,
13048 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
13049 hex_string (DW_UNSND (attr
)));
13050 DW_UNSND (attr
) = 0;
13056 /* Read an attribute described by an abbreviated attribute. */
13059 read_attribute (const struct die_reader_specs
*reader
,
13060 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
13061 gdb_byte
*info_ptr
)
13063 attr
->name
= abbrev
->name
;
13064 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
13067 /* Read dwarf information from a buffer. */
13069 static unsigned int
13070 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
13072 return bfd_get_8 (abfd
, buf
);
13076 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
13078 return bfd_get_signed_8 (abfd
, buf
);
13081 static unsigned int
13082 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
13084 return bfd_get_16 (abfd
, buf
);
13088 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13090 return bfd_get_signed_16 (abfd
, buf
);
13093 static unsigned int
13094 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
13096 return bfd_get_32 (abfd
, buf
);
13100 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13102 return bfd_get_signed_32 (abfd
, buf
);
13106 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
13108 return bfd_get_64 (abfd
, buf
);
13112 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
13113 unsigned int *bytes_read
)
13115 struct comp_unit_head
*cu_header
= &cu
->header
;
13116 CORE_ADDR retval
= 0;
13118 if (cu_header
->signed_addr_p
)
13120 switch (cu_header
->addr_size
)
13123 retval
= bfd_get_signed_16 (abfd
, buf
);
13126 retval
= bfd_get_signed_32 (abfd
, buf
);
13129 retval
= bfd_get_signed_64 (abfd
, buf
);
13132 internal_error (__FILE__
, __LINE__
,
13133 _("read_address: bad switch, signed [in module %s]"),
13134 bfd_get_filename (abfd
));
13139 switch (cu_header
->addr_size
)
13142 retval
= bfd_get_16 (abfd
, buf
);
13145 retval
= bfd_get_32 (abfd
, buf
);
13148 retval
= bfd_get_64 (abfd
, buf
);
13151 internal_error (__FILE__
, __LINE__
,
13152 _("read_address: bad switch, "
13153 "unsigned [in module %s]"),
13154 bfd_get_filename (abfd
));
13158 *bytes_read
= cu_header
->addr_size
;
13162 /* Read the initial length from a section. The (draft) DWARF 3
13163 specification allows the initial length to take up either 4 bytes
13164 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13165 bytes describe the length and all offsets will be 8 bytes in length
13168 An older, non-standard 64-bit format is also handled by this
13169 function. The older format in question stores the initial length
13170 as an 8-byte quantity without an escape value. Lengths greater
13171 than 2^32 aren't very common which means that the initial 4 bytes
13172 is almost always zero. Since a length value of zero doesn't make
13173 sense for the 32-bit format, this initial zero can be considered to
13174 be an escape value which indicates the presence of the older 64-bit
13175 format. As written, the code can't detect (old format) lengths
13176 greater than 4GB. If it becomes necessary to handle lengths
13177 somewhat larger than 4GB, we could allow other small values (such
13178 as the non-sensical values of 1, 2, and 3) to also be used as
13179 escape values indicating the presence of the old format.
13181 The value returned via bytes_read should be used to increment the
13182 relevant pointer after calling read_initial_length().
13184 [ Note: read_initial_length() and read_offset() are based on the
13185 document entitled "DWARF Debugging Information Format", revision
13186 3, draft 8, dated November 19, 2001. This document was obtained
13189 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13191 This document is only a draft and is subject to change. (So beware.)
13193 Details regarding the older, non-standard 64-bit format were
13194 determined empirically by examining 64-bit ELF files produced by
13195 the SGI toolchain on an IRIX 6.5 machine.
13197 - Kevin, July 16, 2002
13201 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13203 LONGEST length
= bfd_get_32 (abfd
, buf
);
13205 if (length
== 0xffffffff)
13207 length
= bfd_get_64 (abfd
, buf
+ 4);
13210 else if (length
== 0)
13212 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13213 length
= bfd_get_64 (abfd
, buf
);
13224 /* Cover function for read_initial_length.
13225 Returns the length of the object at BUF, and stores the size of the
13226 initial length in *BYTES_READ and stores the size that offsets will be in
13228 If the initial length size is not equivalent to that specified in
13229 CU_HEADER then issue a complaint.
13230 This is useful when reading non-comp-unit headers. */
13233 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13234 const struct comp_unit_head
*cu_header
,
13235 unsigned int *bytes_read
,
13236 unsigned int *offset_size
)
13238 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13240 gdb_assert (cu_header
->initial_length_size
== 4
13241 || cu_header
->initial_length_size
== 8
13242 || cu_header
->initial_length_size
== 12);
13244 if (cu_header
->initial_length_size
!= *bytes_read
)
13245 complaint (&symfile_complaints
,
13246 _("intermixed 32-bit and 64-bit DWARF sections"));
13248 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13252 /* Read an offset from the data stream. The size of the offset is
13253 given by cu_header->offset_size. */
13256 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13257 unsigned int *bytes_read
)
13259 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13261 *bytes_read
= cu_header
->offset_size
;
13265 /* Read an offset from the data stream. */
13268 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13270 LONGEST retval
= 0;
13272 switch (offset_size
)
13275 retval
= bfd_get_32 (abfd
, buf
);
13278 retval
= bfd_get_64 (abfd
, buf
);
13281 internal_error (__FILE__
, __LINE__
,
13282 _("read_offset_1: bad switch [in module %s]"),
13283 bfd_get_filename (abfd
));
13290 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13292 /* If the size of a host char is 8 bits, we can return a pointer
13293 to the buffer, otherwise we have to copy the data to a buffer
13294 allocated on the temporary obstack. */
13295 gdb_assert (HOST_CHAR_BIT
== 8);
13300 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13302 /* If the size of a host char is 8 bits, we can return a pointer
13303 to the string, otherwise we have to copy the string to a buffer
13304 allocated on the temporary obstack. */
13305 gdb_assert (HOST_CHAR_BIT
== 8);
13308 *bytes_read_ptr
= 1;
13311 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13312 return (char *) buf
;
13316 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13318 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13319 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13320 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13321 bfd_get_filename (abfd
));
13322 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13323 error (_("DW_FORM_strp pointing outside of "
13324 ".debug_str section [in module %s]"),
13325 bfd_get_filename (abfd
));
13326 gdb_assert (HOST_CHAR_BIT
== 8);
13327 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13329 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13333 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13334 const struct comp_unit_head
*cu_header
,
13335 unsigned int *bytes_read_ptr
)
13337 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13339 return read_indirect_string_at_offset (abfd
, str_offset
);
13343 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13346 unsigned int num_read
;
13348 unsigned char byte
;
13356 byte
= bfd_get_8 (abfd
, buf
);
13359 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13360 if ((byte
& 128) == 0)
13366 *bytes_read_ptr
= num_read
;
13371 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13374 int i
, shift
, num_read
;
13375 unsigned char byte
;
13383 byte
= bfd_get_8 (abfd
, buf
);
13386 result
|= ((LONGEST
) (byte
& 127) << shift
);
13388 if ((byte
& 128) == 0)
13393 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13394 result
|= -(((LONGEST
) 1) << shift
);
13395 *bytes_read_ptr
= num_read
;
13399 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13400 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13401 ADDR_SIZE is the size of addresses from the CU header. */
13404 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13406 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13407 bfd
*abfd
= objfile
->obfd
;
13408 const gdb_byte
*info_ptr
;
13410 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13411 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13412 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13414 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13415 error (_("DW_FORM_addr_index pointing outside of "
13416 ".debug_addr section [in module %s]"),
13418 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13419 + addr_base
+ addr_index
* addr_size
);
13420 if (addr_size
== 4)
13421 return bfd_get_32 (abfd
, info_ptr
);
13423 return bfd_get_64 (abfd
, info_ptr
);
13426 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13429 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13431 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13434 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13437 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13438 unsigned int *bytes_read
)
13440 bfd
*abfd
= cu
->objfile
->obfd
;
13441 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13443 return read_addr_index (cu
, addr_index
);
13446 /* Data structure to pass results from dwarf2_read_addr_index_reader
13447 back to dwarf2_read_addr_index. */
13449 struct dwarf2_read_addr_index_data
13451 ULONGEST addr_base
;
13455 /* die_reader_func for dwarf2_read_addr_index. */
13458 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13459 gdb_byte
*info_ptr
,
13460 struct die_info
*comp_unit_die
,
13464 struct dwarf2_cu
*cu
= reader
->cu
;
13465 struct dwarf2_read_addr_index_data
*aidata
=
13466 (struct dwarf2_read_addr_index_data
*) data
;
13468 aidata
->addr_base
= cu
->addr_base
;
13469 aidata
->addr_size
= cu
->header
.addr_size
;
13472 /* Given an index in .debug_addr, fetch the value.
13473 NOTE: This can be called during dwarf expression evaluation,
13474 long after the debug information has been read, and thus per_cu->cu
13475 may no longer exist. */
13478 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13479 unsigned int addr_index
)
13481 struct objfile
*objfile
= per_cu
->objfile
;
13482 struct dwarf2_cu
*cu
= per_cu
->cu
;
13483 ULONGEST addr_base
;
13486 /* This is intended to be called from outside this file. */
13487 dw2_setup (objfile
);
13489 /* We need addr_base and addr_size.
13490 If we don't have PER_CU->cu, we have to get it.
13491 Nasty, but the alternative is storing the needed info in PER_CU,
13492 which at this point doesn't seem justified: it's not clear how frequently
13493 it would get used and it would increase the size of every PER_CU.
13494 Entry points like dwarf2_per_cu_addr_size do a similar thing
13495 so we're not in uncharted territory here.
13496 Alas we need to be a bit more complicated as addr_base is contained
13499 We don't need to read the entire CU(/TU).
13500 We just need the header and top level die.
13501 IWBN to use the aging mechanism to let us lazily later discard the CU.
13502 See however init_cutu_and_read_dies_simple. */
13506 addr_base
= cu
->addr_base
;
13507 addr_size
= cu
->header
.addr_size
;
13511 struct dwarf2_read_addr_index_data aidata
;
13513 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13515 addr_base
= aidata
.addr_base
;
13516 addr_size
= aidata
.addr_size
;
13519 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13522 /* Given a DW_AT_str_index, fetch the string. */
13525 read_str_index (const struct die_reader_specs
*reader
,
13526 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13528 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13529 const char *dwo_name
= objfile
->name
;
13530 bfd
*abfd
= objfile
->obfd
;
13531 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13532 gdb_byte
*info_ptr
;
13533 ULONGEST str_offset
;
13535 dwarf2_read_section (objfile
, §ions
->str
);
13536 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13537 if (sections
->str
.buffer
== NULL
)
13538 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13539 " in CU at offset 0x%lx [in module %s]"),
13540 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13541 if (sections
->str_offsets
.buffer
== NULL
)
13542 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13543 " in CU at offset 0x%lx [in module %s]"),
13544 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13545 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13546 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13547 " section in CU at offset 0x%lx [in module %s]"),
13548 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13549 info_ptr
= (sections
->str_offsets
.buffer
13550 + str_index
* cu
->header
.offset_size
);
13551 if (cu
->header
.offset_size
== 4)
13552 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13554 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13555 if (str_offset
>= sections
->str
.size
)
13556 error (_("Offset from DW_FORM_str_index pointing outside of"
13557 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13558 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13559 return (char *) (sections
->str
.buffer
+ str_offset
);
13562 /* Return the length of an LEB128 number in BUF. */
13565 leb128_size (const gdb_byte
*buf
)
13567 const gdb_byte
*begin
= buf
;
13573 if ((byte
& 128) == 0)
13574 return buf
- begin
;
13579 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13586 cu
->language
= language_c
;
13588 case DW_LANG_C_plus_plus
:
13589 cu
->language
= language_cplus
;
13592 cu
->language
= language_d
;
13594 case DW_LANG_Fortran77
:
13595 case DW_LANG_Fortran90
:
13596 case DW_LANG_Fortran95
:
13597 cu
->language
= language_fortran
;
13600 cu
->language
= language_go
;
13602 case DW_LANG_Mips_Assembler
:
13603 cu
->language
= language_asm
;
13606 cu
->language
= language_java
;
13608 case DW_LANG_Ada83
:
13609 case DW_LANG_Ada95
:
13610 cu
->language
= language_ada
;
13612 case DW_LANG_Modula2
:
13613 cu
->language
= language_m2
;
13615 case DW_LANG_Pascal83
:
13616 cu
->language
= language_pascal
;
13619 cu
->language
= language_objc
;
13621 case DW_LANG_Cobol74
:
13622 case DW_LANG_Cobol85
:
13624 cu
->language
= language_minimal
;
13627 cu
->language_defn
= language_def (cu
->language
);
13630 /* Return the named attribute or NULL if not there. */
13632 static struct attribute
*
13633 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13638 struct attribute
*spec
= NULL
;
13640 for (i
= 0; i
< die
->num_attrs
; ++i
)
13642 if (die
->attrs
[i
].name
== name
)
13643 return &die
->attrs
[i
];
13644 if (die
->attrs
[i
].name
== DW_AT_specification
13645 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13646 spec
= &die
->attrs
[i
];
13652 die
= follow_die_ref (die
, spec
, &cu
);
13658 /* Return the named attribute or NULL if not there,
13659 but do not follow DW_AT_specification, etc.
13660 This is for use in contexts where we're reading .debug_types dies.
13661 Following DW_AT_specification, DW_AT_abstract_origin will take us
13662 back up the chain, and we want to go down. */
13664 static struct attribute
*
13665 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13669 for (i
= 0; i
< die
->num_attrs
; ++i
)
13670 if (die
->attrs
[i
].name
== name
)
13671 return &die
->attrs
[i
];
13676 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13677 and holds a non-zero value. This function should only be used for
13678 DW_FORM_flag or DW_FORM_flag_present attributes. */
13681 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13683 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13685 return (attr
&& DW_UNSND (attr
));
13689 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13691 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13692 which value is non-zero. However, we have to be careful with
13693 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13694 (via dwarf2_flag_true_p) follows this attribute. So we may
13695 end up accidently finding a declaration attribute that belongs
13696 to a different DIE referenced by the specification attribute,
13697 even though the given DIE does not have a declaration attribute. */
13698 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13699 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13702 /* Return the die giving the specification for DIE, if there is
13703 one. *SPEC_CU is the CU containing DIE on input, and the CU
13704 containing the return value on output. If there is no
13705 specification, but there is an abstract origin, that is
13708 static struct die_info
*
13709 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13711 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13714 if (spec_attr
== NULL
)
13715 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13717 if (spec_attr
== NULL
)
13720 return follow_die_ref (die
, spec_attr
, spec_cu
);
13723 /* Free the line_header structure *LH, and any arrays and strings it
13725 NOTE: This is also used as a "cleanup" function. */
13728 free_line_header (struct line_header
*lh
)
13730 if (lh
->standard_opcode_lengths
)
13731 xfree (lh
->standard_opcode_lengths
);
13733 /* Remember that all the lh->file_names[i].name pointers are
13734 pointers into debug_line_buffer, and don't need to be freed. */
13735 if (lh
->file_names
)
13736 xfree (lh
->file_names
);
13738 /* Similarly for the include directory names. */
13739 if (lh
->include_dirs
)
13740 xfree (lh
->include_dirs
);
13745 /* Add an entry to LH's include directory table. */
13748 add_include_dir (struct line_header
*lh
, char *include_dir
)
13750 /* Grow the array if necessary. */
13751 if (lh
->include_dirs_size
== 0)
13753 lh
->include_dirs_size
= 1; /* for testing */
13754 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13755 * sizeof (*lh
->include_dirs
));
13757 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13759 lh
->include_dirs_size
*= 2;
13760 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13761 (lh
->include_dirs_size
13762 * sizeof (*lh
->include_dirs
)));
13765 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13768 /* Add an entry to LH's file name table. */
13771 add_file_name (struct line_header
*lh
,
13773 unsigned int dir_index
,
13774 unsigned int mod_time
,
13775 unsigned int length
)
13777 struct file_entry
*fe
;
13779 /* Grow the array if necessary. */
13780 if (lh
->file_names_size
== 0)
13782 lh
->file_names_size
= 1; /* for testing */
13783 lh
->file_names
= xmalloc (lh
->file_names_size
13784 * sizeof (*lh
->file_names
));
13786 else if (lh
->num_file_names
>= lh
->file_names_size
)
13788 lh
->file_names_size
*= 2;
13789 lh
->file_names
= xrealloc (lh
->file_names
,
13790 (lh
->file_names_size
13791 * sizeof (*lh
->file_names
)));
13794 fe
= &lh
->file_names
[lh
->num_file_names
++];
13796 fe
->dir_index
= dir_index
;
13797 fe
->mod_time
= mod_time
;
13798 fe
->length
= length
;
13799 fe
->included_p
= 0;
13803 /* Read the statement program header starting at OFFSET in
13804 .debug_line, or .debug_line.dwo. Return a pointer
13805 to a struct line_header, allocated using xmalloc.
13807 NOTE: the strings in the include directory and file name tables of
13808 the returned object point into the dwarf line section buffer,
13809 and must not be freed. */
13811 static struct line_header
*
13812 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
13814 struct cleanup
*back_to
;
13815 struct line_header
*lh
;
13816 gdb_byte
*line_ptr
;
13817 unsigned int bytes_read
, offset_size
;
13819 char *cur_dir
, *cur_file
;
13820 struct dwarf2_section_info
*section
;
13823 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
13825 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13826 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
13828 section
= &dwarf2_per_objfile
->line
;
13830 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
13831 if (section
->buffer
== NULL
)
13833 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
13834 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
13836 complaint (&symfile_complaints
, _("missing .debug_line section"));
13840 /* We can't do this until we know the section is non-empty.
13841 Only then do we know we have such a section. */
13842 abfd
= section
->asection
->owner
;
13844 /* Make sure that at least there's room for the total_length field.
13845 That could be 12 bytes long, but we're just going to fudge that. */
13846 if (offset
+ 4 >= section
->size
)
13848 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13852 lh
= xmalloc (sizeof (*lh
));
13853 memset (lh
, 0, sizeof (*lh
));
13854 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
13857 line_ptr
= section
->buffer
+ offset
;
13859 /* Read in the header. */
13861 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
13862 &bytes_read
, &offset_size
);
13863 line_ptr
+= bytes_read
;
13864 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
13866 dwarf2_statement_list_fits_in_line_number_section_complaint ();
13869 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
13870 lh
->version
= read_2_bytes (abfd
, line_ptr
);
13872 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
13873 line_ptr
+= offset_size
;
13874 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
13876 if (lh
->version
>= 4)
13878 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
13882 lh
->maximum_ops_per_instruction
= 1;
13884 if (lh
->maximum_ops_per_instruction
== 0)
13886 lh
->maximum_ops_per_instruction
= 1;
13887 complaint (&symfile_complaints
,
13888 _("invalid maximum_ops_per_instruction "
13889 "in `.debug_line' section"));
13892 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
13894 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
13896 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
13898 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
13900 lh
->standard_opcode_lengths
13901 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
13903 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
13904 for (i
= 1; i
< lh
->opcode_base
; ++i
)
13906 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
13910 /* Read directory table. */
13911 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13913 line_ptr
+= bytes_read
;
13914 add_include_dir (lh
, cur_dir
);
13916 line_ptr
+= bytes_read
;
13918 /* Read file name table. */
13919 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
13921 unsigned int dir_index
, mod_time
, length
;
13923 line_ptr
+= bytes_read
;
13924 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13925 line_ptr
+= bytes_read
;
13926 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13927 line_ptr
+= bytes_read
;
13928 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
13929 line_ptr
+= bytes_read
;
13931 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
13933 line_ptr
+= bytes_read
;
13934 lh
->statement_program_start
= line_ptr
;
13936 if (line_ptr
> (section
->buffer
+ section
->size
))
13937 complaint (&symfile_complaints
,
13938 _("line number info header doesn't "
13939 "fit in `.debug_line' section"));
13941 discard_cleanups (back_to
);
13945 /* Subroutine of dwarf_decode_lines to simplify it.
13946 Return the file name of the psymtab for included file FILE_INDEX
13947 in line header LH of PST.
13948 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
13949 If space for the result is malloc'd, it will be freed by a cleanup.
13950 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
13953 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
13954 const struct partial_symtab
*pst
,
13955 const char *comp_dir
)
13957 const struct file_entry fe
= lh
->file_names
[file_index
];
13958 char *include_name
= fe
.name
;
13959 char *include_name_to_compare
= include_name
;
13960 char *dir_name
= NULL
;
13961 const char *pst_filename
;
13962 char *copied_name
= NULL
;
13966 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
13968 if (!IS_ABSOLUTE_PATH (include_name
)
13969 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
13971 /* Avoid creating a duplicate psymtab for PST.
13972 We do this by comparing INCLUDE_NAME and PST_FILENAME.
13973 Before we do the comparison, however, we need to account
13974 for DIR_NAME and COMP_DIR.
13975 First prepend dir_name (if non-NULL). If we still don't
13976 have an absolute path prepend comp_dir (if non-NULL).
13977 However, the directory we record in the include-file's
13978 psymtab does not contain COMP_DIR (to match the
13979 corresponding symtab(s)).
13984 bash$ gcc -g ./hello.c
13985 include_name = "hello.c"
13987 DW_AT_comp_dir = comp_dir = "/tmp"
13988 DW_AT_name = "./hello.c" */
13990 if (dir_name
!= NULL
)
13992 include_name
= concat (dir_name
, SLASH_STRING
,
13993 include_name
, (char *)NULL
);
13994 include_name_to_compare
= include_name
;
13995 make_cleanup (xfree
, include_name
);
13997 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
13999 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
14000 include_name
, (char *)NULL
);
14004 pst_filename
= pst
->filename
;
14005 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
14007 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
14008 pst_filename
, (char *)NULL
);
14009 pst_filename
= copied_name
;
14012 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
14014 if (include_name_to_compare
!= include_name
)
14015 xfree (include_name_to_compare
);
14016 if (copied_name
!= NULL
)
14017 xfree (copied_name
);
14021 return include_name
;
14024 /* Ignore this record_line request. */
14027 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14032 /* Subroutine of dwarf_decode_lines to simplify it.
14033 Process the line number information in LH. */
14036 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
14037 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
14039 gdb_byte
*line_ptr
, *extended_end
;
14040 gdb_byte
*line_end
;
14041 unsigned int bytes_read
, extended_len
;
14042 unsigned char op_code
, extended_op
, adj_opcode
;
14043 CORE_ADDR baseaddr
;
14044 struct objfile
*objfile
= cu
->objfile
;
14045 bfd
*abfd
= objfile
->obfd
;
14046 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14047 const int decode_for_pst_p
= (pst
!= NULL
);
14048 struct subfile
*last_subfile
= NULL
;
14049 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14052 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14054 line_ptr
= lh
->statement_program_start
;
14055 line_end
= lh
->statement_program_end
;
14057 /* Read the statement sequences until there's nothing left. */
14058 while (line_ptr
< line_end
)
14060 /* state machine registers */
14061 CORE_ADDR address
= 0;
14062 unsigned int file
= 1;
14063 unsigned int line
= 1;
14064 unsigned int column
= 0;
14065 int is_stmt
= lh
->default_is_stmt
;
14066 int basic_block
= 0;
14067 int end_sequence
= 0;
14069 unsigned char op_index
= 0;
14071 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
14073 /* Start a subfile for the current file of the state machine. */
14074 /* lh->include_dirs and lh->file_names are 0-based, but the
14075 directory and file name numbers in the statement program
14077 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14081 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14083 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14086 /* Decode the table. */
14087 while (!end_sequence
)
14089 op_code
= read_1_byte (abfd
, line_ptr
);
14091 if (line_ptr
> line_end
)
14093 dwarf2_debug_line_missing_end_sequence_complaint ();
14097 if (op_code
>= lh
->opcode_base
)
14099 /* Special operand. */
14100 adj_opcode
= op_code
- lh
->opcode_base
;
14101 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
14102 / lh
->maximum_ops_per_instruction
)
14103 * lh
->minimum_instruction_length
);
14104 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
14105 % lh
->maximum_ops_per_instruction
);
14106 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
14107 if (lh
->num_file_names
< file
|| file
== 0)
14108 dwarf2_debug_line_missing_file_complaint ();
14109 /* For now we ignore lines not starting on an
14110 instruction boundary. */
14111 else if (op_index
== 0)
14113 lh
->file_names
[file
- 1].included_p
= 1;
14114 if (!decode_for_pst_p
&& is_stmt
)
14116 if (last_subfile
!= current_subfile
)
14118 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14120 (*p_record_line
) (last_subfile
, 0, addr
);
14121 last_subfile
= current_subfile
;
14123 /* Append row to matrix using current values. */
14124 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14125 (*p_record_line
) (current_subfile
, line
, addr
);
14130 else switch (op_code
)
14132 case DW_LNS_extended_op
:
14133 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
14135 line_ptr
+= bytes_read
;
14136 extended_end
= line_ptr
+ extended_len
;
14137 extended_op
= read_1_byte (abfd
, line_ptr
);
14139 switch (extended_op
)
14141 case DW_LNE_end_sequence
:
14142 p_record_line
= record_line
;
14145 case DW_LNE_set_address
:
14146 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14148 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14150 /* This line table is for a function which has been
14151 GCd by the linker. Ignore it. PR gdb/12528 */
14154 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
14156 complaint (&symfile_complaints
,
14157 _(".debug_line address at offset 0x%lx is 0 "
14159 line_offset
, objfile
->name
);
14160 p_record_line
= noop_record_line
;
14164 line_ptr
+= bytes_read
;
14165 address
+= baseaddr
;
14167 case DW_LNE_define_file
:
14170 unsigned int dir_index
, mod_time
, length
;
14172 cur_file
= read_direct_string (abfd
, line_ptr
,
14174 line_ptr
+= bytes_read
;
14176 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14177 line_ptr
+= bytes_read
;
14179 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14180 line_ptr
+= bytes_read
;
14182 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14183 line_ptr
+= bytes_read
;
14184 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14187 case DW_LNE_set_discriminator
:
14188 /* The discriminator is not interesting to the debugger;
14190 line_ptr
= extended_end
;
14193 complaint (&symfile_complaints
,
14194 _("mangled .debug_line section"));
14197 /* Make sure that we parsed the extended op correctly. If e.g.
14198 we expected a different address size than the producer used,
14199 we may have read the wrong number of bytes. */
14200 if (line_ptr
!= extended_end
)
14202 complaint (&symfile_complaints
,
14203 _("mangled .debug_line section"));
14208 if (lh
->num_file_names
< file
|| file
== 0)
14209 dwarf2_debug_line_missing_file_complaint ();
14212 lh
->file_names
[file
- 1].included_p
= 1;
14213 if (!decode_for_pst_p
&& is_stmt
)
14215 if (last_subfile
!= current_subfile
)
14217 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14219 (*p_record_line
) (last_subfile
, 0, addr
);
14220 last_subfile
= current_subfile
;
14222 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14223 (*p_record_line
) (current_subfile
, line
, addr
);
14228 case DW_LNS_advance_pc
:
14231 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14233 address
+= (((op_index
+ adjust
)
14234 / lh
->maximum_ops_per_instruction
)
14235 * lh
->minimum_instruction_length
);
14236 op_index
= ((op_index
+ adjust
)
14237 % lh
->maximum_ops_per_instruction
);
14238 line_ptr
+= bytes_read
;
14241 case DW_LNS_advance_line
:
14242 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14243 line_ptr
+= bytes_read
;
14245 case DW_LNS_set_file
:
14247 /* The arrays lh->include_dirs and lh->file_names are
14248 0-based, but the directory and file name numbers in
14249 the statement program are 1-based. */
14250 struct file_entry
*fe
;
14253 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14254 line_ptr
+= bytes_read
;
14255 if (lh
->num_file_names
< file
|| file
== 0)
14256 dwarf2_debug_line_missing_file_complaint ();
14259 fe
= &lh
->file_names
[file
- 1];
14261 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14262 if (!decode_for_pst_p
)
14264 last_subfile
= current_subfile
;
14265 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14270 case DW_LNS_set_column
:
14271 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14272 line_ptr
+= bytes_read
;
14274 case DW_LNS_negate_stmt
:
14275 is_stmt
= (!is_stmt
);
14277 case DW_LNS_set_basic_block
:
14280 /* Add to the address register of the state machine the
14281 address increment value corresponding to special opcode
14282 255. I.e., this value is scaled by the minimum
14283 instruction length since special opcode 255 would have
14284 scaled the increment. */
14285 case DW_LNS_const_add_pc
:
14287 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14289 address
+= (((op_index
+ adjust
)
14290 / lh
->maximum_ops_per_instruction
)
14291 * lh
->minimum_instruction_length
);
14292 op_index
= ((op_index
+ adjust
)
14293 % lh
->maximum_ops_per_instruction
);
14296 case DW_LNS_fixed_advance_pc
:
14297 address
+= read_2_bytes (abfd
, line_ptr
);
14303 /* Unknown standard opcode, ignore it. */
14306 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14308 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14309 line_ptr
+= bytes_read
;
14314 if (lh
->num_file_names
< file
|| file
== 0)
14315 dwarf2_debug_line_missing_file_complaint ();
14318 lh
->file_names
[file
- 1].included_p
= 1;
14319 if (!decode_for_pst_p
)
14321 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14322 (*p_record_line
) (current_subfile
, 0, addr
);
14328 /* Decode the Line Number Program (LNP) for the given line_header
14329 structure and CU. The actual information extracted and the type
14330 of structures created from the LNP depends on the value of PST.
14332 1. If PST is NULL, then this procedure uses the data from the program
14333 to create all necessary symbol tables, and their linetables.
14335 2. If PST is not NULL, this procedure reads the program to determine
14336 the list of files included by the unit represented by PST, and
14337 builds all the associated partial symbol tables.
14339 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14340 It is used for relative paths in the line table.
14341 NOTE: When processing partial symtabs (pst != NULL),
14342 comp_dir == pst->dirname.
14344 NOTE: It is important that psymtabs have the same file name (via strcmp)
14345 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14346 symtab we don't use it in the name of the psymtabs we create.
14347 E.g. expand_line_sal requires this when finding psymtabs to expand.
14348 A good testcase for this is mb-inline.exp. */
14351 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14352 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14353 int want_line_info
)
14355 struct objfile
*objfile
= cu
->objfile
;
14356 const int decode_for_pst_p
= (pst
!= NULL
);
14357 struct subfile
*first_subfile
= current_subfile
;
14359 if (want_line_info
)
14360 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14362 if (decode_for_pst_p
)
14366 /* Now that we're done scanning the Line Header Program, we can
14367 create the psymtab of each included file. */
14368 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14369 if (lh
->file_names
[file_index
].included_p
== 1)
14371 char *include_name
=
14372 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14373 if (include_name
!= NULL
)
14374 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14379 /* Make sure a symtab is created for every file, even files
14380 which contain only variables (i.e. no code with associated
14384 for (i
= 0; i
< lh
->num_file_names
; i
++)
14387 struct file_entry
*fe
;
14389 fe
= &lh
->file_names
[i
];
14391 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14392 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14394 /* Skip the main file; we don't need it, and it must be
14395 allocated last, so that it will show up before the
14396 non-primary symtabs in the objfile's symtab list. */
14397 if (current_subfile
== first_subfile
)
14400 if (current_subfile
->symtab
== NULL
)
14401 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14403 fe
->symtab
= current_subfile
->symtab
;
14408 /* Start a subfile for DWARF. FILENAME is the name of the file and
14409 DIRNAME the name of the source directory which contains FILENAME
14410 or NULL if not known. COMP_DIR is the compilation directory for the
14411 linetable's compilation unit or NULL if not known.
14412 This routine tries to keep line numbers from identical absolute and
14413 relative file names in a common subfile.
14415 Using the `list' example from the GDB testsuite, which resides in
14416 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14417 of /srcdir/list0.c yields the following debugging information for list0.c:
14419 DW_AT_name: /srcdir/list0.c
14420 DW_AT_comp_dir: /compdir
14421 files.files[0].name: list0.h
14422 files.files[0].dir: /srcdir
14423 files.files[1].name: list0.c
14424 files.files[1].dir: /srcdir
14426 The line number information for list0.c has to end up in a single
14427 subfile, so that `break /srcdir/list0.c:1' works as expected.
14428 start_subfile will ensure that this happens provided that we pass the
14429 concatenation of files.files[1].dir and files.files[1].name as the
14433 dwarf2_start_subfile (char *filename
, const char *dirname
,
14434 const char *comp_dir
)
14438 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14439 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14440 second argument to start_subfile. To be consistent, we do the
14441 same here. In order not to lose the line information directory,
14442 we concatenate it to the filename when it makes sense.
14443 Note that the Dwarf3 standard says (speaking of filenames in line
14444 information): ``The directory index is ignored for file names
14445 that represent full path names''. Thus ignoring dirname in the
14446 `else' branch below isn't an issue. */
14448 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14449 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14451 fullname
= filename
;
14453 start_subfile (fullname
, comp_dir
);
14455 if (fullname
!= filename
)
14459 /* Start a symtab for DWARF.
14460 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14463 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14464 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14466 start_symtab (name
, comp_dir
, low_pc
);
14467 record_debugformat ("DWARF 2");
14468 record_producer (cu
->producer
);
14470 /* We assume that we're processing GCC output. */
14471 processing_gcc_compilation
= 2;
14473 processing_has_namespace_info
= 0;
14477 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14478 struct dwarf2_cu
*cu
)
14480 struct objfile
*objfile
= cu
->objfile
;
14481 struct comp_unit_head
*cu_header
= &cu
->header
;
14483 /* NOTE drow/2003-01-30: There used to be a comment and some special
14484 code here to turn a symbol with DW_AT_external and a
14485 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14486 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14487 with some versions of binutils) where shared libraries could have
14488 relocations against symbols in their debug information - the
14489 minimal symbol would have the right address, but the debug info
14490 would not. It's no longer necessary, because we will explicitly
14491 apply relocations when we read in the debug information now. */
14493 /* A DW_AT_location attribute with no contents indicates that a
14494 variable has been optimized away. */
14495 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14497 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14501 /* Handle one degenerate form of location expression specially, to
14502 preserve GDB's previous behavior when section offsets are
14503 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14504 then mark this symbol as LOC_STATIC. */
14506 if (attr_form_is_block (attr
)
14507 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14508 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14509 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14510 && (DW_BLOCK (attr
)->size
14511 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14513 unsigned int dummy
;
14515 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14516 SYMBOL_VALUE_ADDRESS (sym
) =
14517 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14519 SYMBOL_VALUE_ADDRESS (sym
) =
14520 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14521 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14522 fixup_symbol_section (sym
, objfile
);
14523 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14524 SYMBOL_SECTION (sym
));
14528 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14529 expression evaluator, and use LOC_COMPUTED only when necessary
14530 (i.e. when the value of a register or memory location is
14531 referenced, or a thread-local block, etc.). Then again, it might
14532 not be worthwhile. I'm assuming that it isn't unless performance
14533 or memory numbers show me otherwise. */
14535 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14536 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14538 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14539 cu
->has_loclist
= 1;
14542 /* Given a pointer to a DWARF information entry, figure out if we need
14543 to make a symbol table entry for it, and if so, create a new entry
14544 and return a pointer to it.
14545 If TYPE is NULL, determine symbol type from the die, otherwise
14546 used the passed type.
14547 If SPACE is not NULL, use it to hold the new symbol. If it is
14548 NULL, allocate a new symbol on the objfile's obstack. */
14550 static struct symbol
*
14551 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14552 struct symbol
*space
)
14554 struct objfile
*objfile
= cu
->objfile
;
14555 struct symbol
*sym
= NULL
;
14557 struct attribute
*attr
= NULL
;
14558 struct attribute
*attr2
= NULL
;
14559 CORE_ADDR baseaddr
;
14560 struct pending
**list_to_add
= NULL
;
14562 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14564 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14566 name
= dwarf2_name (die
, cu
);
14569 const char *linkagename
;
14570 int suppress_add
= 0;
14575 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14576 OBJSTAT (objfile
, n_syms
++);
14578 /* Cache this symbol's name and the name's demangled form (if any). */
14579 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14580 linkagename
= dwarf2_physname (name
, die
, cu
);
14581 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14583 /* Fortran does not have mangling standard and the mangling does differ
14584 between gfortran, iFort etc. */
14585 if (cu
->language
== language_fortran
14586 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14587 symbol_set_demangled_name (&(sym
->ginfo
),
14588 (char *) dwarf2_full_name (name
, die
, cu
),
14591 /* Default assumptions.
14592 Use the passed type or decode it from the die. */
14593 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14594 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14596 SYMBOL_TYPE (sym
) = type
;
14598 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14599 attr
= dwarf2_attr (die
,
14600 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14604 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14607 attr
= dwarf2_attr (die
,
14608 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14612 int file_index
= DW_UNSND (attr
);
14614 if (cu
->line_header
== NULL
14615 || file_index
> cu
->line_header
->num_file_names
)
14616 complaint (&symfile_complaints
,
14617 _("file index out of range"));
14618 else if (file_index
> 0)
14620 struct file_entry
*fe
;
14622 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14623 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14630 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14633 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14635 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14636 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14637 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14638 add_symbol_to_list (sym
, cu
->list_in_scope
);
14640 case DW_TAG_subprogram
:
14641 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14643 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14644 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14645 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14646 || cu
->language
== language_ada
)
14648 /* Subprograms marked external are stored as a global symbol.
14649 Ada subprograms, whether marked external or not, are always
14650 stored as a global symbol, because we want to be able to
14651 access them globally. For instance, we want to be able
14652 to break on a nested subprogram without having to
14653 specify the context. */
14654 list_to_add
= &global_symbols
;
14658 list_to_add
= cu
->list_in_scope
;
14661 case DW_TAG_inlined_subroutine
:
14662 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14664 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14665 SYMBOL_INLINED (sym
) = 1;
14666 list_to_add
= cu
->list_in_scope
;
14668 case DW_TAG_template_value_param
:
14670 /* Fall through. */
14671 case DW_TAG_constant
:
14672 case DW_TAG_variable
:
14673 case DW_TAG_member
:
14674 /* Compilation with minimal debug info may result in
14675 variables with missing type entries. Change the
14676 misleading `void' type to something sensible. */
14677 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14679 = objfile_type (objfile
)->nodebug_data_symbol
;
14681 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14682 /* In the case of DW_TAG_member, we should only be called for
14683 static const members. */
14684 if (die
->tag
== DW_TAG_member
)
14686 /* dwarf2_add_field uses die_is_declaration,
14687 so we do the same. */
14688 gdb_assert (die_is_declaration (die
, cu
));
14693 dwarf2_const_value (attr
, sym
, cu
);
14694 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14697 if (attr2
&& (DW_UNSND (attr2
) != 0))
14698 list_to_add
= &global_symbols
;
14700 list_to_add
= cu
->list_in_scope
;
14704 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14707 var_decode_location (attr
, sym
, cu
);
14708 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14709 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14710 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14711 && !dwarf2_per_objfile
->has_section_at_zero
)
14713 /* When a static variable is eliminated by the linker,
14714 the corresponding debug information is not stripped
14715 out, but the variable address is set to null;
14716 do not add such variables into symbol table. */
14718 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14720 /* Workaround gfortran PR debug/40040 - it uses
14721 DW_AT_location for variables in -fPIC libraries which may
14722 get overriden by other libraries/executable and get
14723 a different address. Resolve it by the minimal symbol
14724 which may come from inferior's executable using copy
14725 relocation. Make this workaround only for gfortran as for
14726 other compilers GDB cannot guess the minimal symbol
14727 Fortran mangling kind. */
14728 if (cu
->language
== language_fortran
&& die
->parent
14729 && die
->parent
->tag
== DW_TAG_module
14731 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14732 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14734 /* A variable with DW_AT_external is never static,
14735 but it may be block-scoped. */
14736 list_to_add
= (cu
->list_in_scope
== &file_symbols
14737 ? &global_symbols
: cu
->list_in_scope
);
14740 list_to_add
= cu
->list_in_scope
;
14744 /* We do not know the address of this symbol.
14745 If it is an external symbol and we have type information
14746 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14747 The address of the variable will then be determined from
14748 the minimal symbol table whenever the variable is
14750 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14751 if (attr2
&& (DW_UNSND (attr2
) != 0)
14752 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14754 /* A variable with DW_AT_external is never static, but it
14755 may be block-scoped. */
14756 list_to_add
= (cu
->list_in_scope
== &file_symbols
14757 ? &global_symbols
: cu
->list_in_scope
);
14759 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14761 else if (!die_is_declaration (die
, cu
))
14763 /* Use the default LOC_OPTIMIZED_OUT class. */
14764 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
14766 list_to_add
= cu
->list_in_scope
;
14770 case DW_TAG_formal_parameter
:
14771 /* If we are inside a function, mark this as an argument. If
14772 not, we might be looking at an argument to an inlined function
14773 when we do not have enough information to show inlined frames;
14774 pretend it's a local variable in that case so that the user can
14776 if (context_stack_depth
> 0
14777 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
14778 SYMBOL_IS_ARGUMENT (sym
) = 1;
14779 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14782 var_decode_location (attr
, sym
, cu
);
14784 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14787 dwarf2_const_value (attr
, sym
, cu
);
14790 list_to_add
= cu
->list_in_scope
;
14792 case DW_TAG_unspecified_parameters
:
14793 /* From varargs functions; gdb doesn't seem to have any
14794 interest in this information, so just ignore it for now.
14797 case DW_TAG_template_type_param
:
14799 /* Fall through. */
14800 case DW_TAG_class_type
:
14801 case DW_TAG_interface_type
:
14802 case DW_TAG_structure_type
:
14803 case DW_TAG_union_type
:
14804 case DW_TAG_set_type
:
14805 case DW_TAG_enumeration_type
:
14806 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14807 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
14810 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
14811 really ever be static objects: otherwise, if you try
14812 to, say, break of a class's method and you're in a file
14813 which doesn't mention that class, it won't work unless
14814 the check for all static symbols in lookup_symbol_aux
14815 saves you. See the OtherFileClass tests in
14816 gdb.c++/namespace.exp. */
14820 list_to_add
= (cu
->list_in_scope
== &file_symbols
14821 && (cu
->language
== language_cplus
14822 || cu
->language
== language_java
)
14823 ? &global_symbols
: cu
->list_in_scope
);
14825 /* The semantics of C++ state that "struct foo {
14826 ... }" also defines a typedef for "foo". A Java
14827 class declaration also defines a typedef for the
14829 if (cu
->language
== language_cplus
14830 || cu
->language
== language_java
14831 || cu
->language
== language_ada
)
14833 /* The symbol's name is already allocated along
14834 with this objfile, so we don't need to
14835 duplicate it for the type. */
14836 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
14837 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
14842 case DW_TAG_typedef
:
14843 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14844 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14845 list_to_add
= cu
->list_in_scope
;
14847 case DW_TAG_base_type
:
14848 case DW_TAG_subrange_type
:
14849 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14850 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14851 list_to_add
= cu
->list_in_scope
;
14853 case DW_TAG_enumerator
:
14854 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14857 dwarf2_const_value (attr
, sym
, cu
);
14860 /* NOTE: carlton/2003-11-10: See comment above in the
14861 DW_TAG_class_type, etc. block. */
14863 list_to_add
= (cu
->list_in_scope
== &file_symbols
14864 && (cu
->language
== language_cplus
14865 || cu
->language
== language_java
)
14866 ? &global_symbols
: cu
->list_in_scope
);
14869 case DW_TAG_namespace
:
14870 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
14871 list_to_add
= &global_symbols
;
14874 /* Not a tag we recognize. Hopefully we aren't processing
14875 trash data, but since we must specifically ignore things
14876 we don't recognize, there is nothing else we should do at
14878 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
14879 dwarf_tag_name (die
->tag
));
14885 sym
->hash_next
= objfile
->template_symbols
;
14886 objfile
->template_symbols
= sym
;
14887 list_to_add
= NULL
;
14890 if (list_to_add
!= NULL
)
14891 add_symbol_to_list (sym
, list_to_add
);
14893 /* For the benefit of old versions of GCC, check for anonymous
14894 namespaces based on the demangled name. */
14895 if (!processing_has_namespace_info
14896 && cu
->language
== language_cplus
)
14897 cp_scan_for_anonymous_namespaces (sym
, objfile
);
14902 /* A wrapper for new_symbol_full that always allocates a new symbol. */
14904 static struct symbol
*
14905 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14907 return new_symbol_full (die
, type
, cu
, NULL
);
14910 /* Given an attr with a DW_FORM_dataN value in host byte order,
14911 zero-extend it as appropriate for the symbol's type. The DWARF
14912 standard (v4) is not entirely clear about the meaning of using
14913 DW_FORM_dataN for a constant with a signed type, where the type is
14914 wider than the data. The conclusion of a discussion on the DWARF
14915 list was that this is unspecified. We choose to always zero-extend
14916 because that is the interpretation long in use by GCC. */
14919 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
14920 const char *name
, struct obstack
*obstack
,
14921 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
14923 struct objfile
*objfile
= cu
->objfile
;
14924 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
14925 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
14926 LONGEST l
= DW_UNSND (attr
);
14928 if (bits
< sizeof (*value
) * 8)
14930 l
&= ((LONGEST
) 1 << bits
) - 1;
14933 else if (bits
== sizeof (*value
) * 8)
14937 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
14938 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
14945 /* Read a constant value from an attribute. Either set *VALUE, or if
14946 the value does not fit in *VALUE, set *BYTES - either already
14947 allocated on the objfile obstack, or newly allocated on OBSTACK,
14948 or, set *BATON, if we translated the constant to a location
14952 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
14953 const char *name
, struct obstack
*obstack
,
14954 struct dwarf2_cu
*cu
,
14955 LONGEST
*value
, gdb_byte
**bytes
,
14956 struct dwarf2_locexpr_baton
**baton
)
14958 struct objfile
*objfile
= cu
->objfile
;
14959 struct comp_unit_head
*cu_header
= &cu
->header
;
14960 struct dwarf_block
*blk
;
14961 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
14962 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
14968 switch (attr
->form
)
14971 case DW_FORM_GNU_addr_index
:
14975 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
14976 dwarf2_const_value_length_mismatch_complaint (name
,
14977 cu_header
->addr_size
,
14978 TYPE_LENGTH (type
));
14979 /* Symbols of this form are reasonably rare, so we just
14980 piggyback on the existing location code rather than writing
14981 a new implementation of symbol_computed_ops. */
14982 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
14983 sizeof (struct dwarf2_locexpr_baton
));
14984 (*baton
)->per_cu
= cu
->per_cu
;
14985 gdb_assert ((*baton
)->per_cu
);
14987 (*baton
)->size
= 2 + cu_header
->addr_size
;
14988 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
14989 (*baton
)->data
= data
;
14991 data
[0] = DW_OP_addr
;
14992 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
14993 byte_order
, DW_ADDR (attr
));
14994 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
14997 case DW_FORM_string
:
14999 case DW_FORM_GNU_str_index
:
15000 /* DW_STRING is already allocated on the objfile obstack, point
15002 *bytes
= (gdb_byte
*) DW_STRING (attr
);
15004 case DW_FORM_block1
:
15005 case DW_FORM_block2
:
15006 case DW_FORM_block4
:
15007 case DW_FORM_block
:
15008 case DW_FORM_exprloc
:
15009 blk
= DW_BLOCK (attr
);
15010 if (TYPE_LENGTH (type
) != blk
->size
)
15011 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
15012 TYPE_LENGTH (type
));
15013 *bytes
= blk
->data
;
15016 /* The DW_AT_const_value attributes are supposed to carry the
15017 symbol's value "represented as it would be on the target
15018 architecture." By the time we get here, it's already been
15019 converted to host endianness, so we just need to sign- or
15020 zero-extend it as appropriate. */
15021 case DW_FORM_data1
:
15022 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15023 obstack
, cu
, value
, 8);
15025 case DW_FORM_data2
:
15026 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15027 obstack
, cu
, value
, 16);
15029 case DW_FORM_data4
:
15030 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15031 obstack
, cu
, value
, 32);
15033 case DW_FORM_data8
:
15034 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15035 obstack
, cu
, value
, 64);
15038 case DW_FORM_sdata
:
15039 *value
= DW_SND (attr
);
15042 case DW_FORM_udata
:
15043 *value
= DW_UNSND (attr
);
15047 complaint (&symfile_complaints
,
15048 _("unsupported const value attribute form: '%s'"),
15049 dwarf_form_name (attr
->form
));
15056 /* Copy constant value from an attribute to a symbol. */
15059 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
15060 struct dwarf2_cu
*cu
)
15062 struct objfile
*objfile
= cu
->objfile
;
15063 struct comp_unit_head
*cu_header
= &cu
->header
;
15066 struct dwarf2_locexpr_baton
*baton
;
15068 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
15069 SYMBOL_PRINT_NAME (sym
),
15070 &objfile
->objfile_obstack
, cu
,
15071 &value
, &bytes
, &baton
);
15075 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15076 SYMBOL_LOCATION_BATON (sym
) = baton
;
15077 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15079 else if (bytes
!= NULL
)
15081 SYMBOL_VALUE_BYTES (sym
) = bytes
;
15082 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
15086 SYMBOL_VALUE (sym
) = value
;
15087 SYMBOL_CLASS (sym
) = LOC_CONST
;
15091 /* Return the type of the die in question using its DW_AT_type attribute. */
15093 static struct type
*
15094 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15096 struct attribute
*type_attr
;
15098 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15101 /* A missing DW_AT_type represents a void type. */
15102 return objfile_type (cu
->objfile
)->builtin_void
;
15105 return lookup_die_type (die
, type_attr
, cu
);
15108 /* True iff CU's producer generates GNAT Ada auxiliary information
15109 that allows to find parallel types through that information instead
15110 of having to do expensive parallel lookups by type name. */
15113 need_gnat_info (struct dwarf2_cu
*cu
)
15115 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
15116 of GNAT produces this auxiliary information, without any indication
15117 that it is produced. Part of enhancing the FSF version of GNAT
15118 to produce that information will be to put in place an indicator
15119 that we can use in order to determine whether the descriptive type
15120 info is available or not. One suggestion that has been made is
15121 to use a new attribute, attached to the CU die. For now, assume
15122 that the descriptive type info is not available. */
15126 /* Return the auxiliary type of the die in question using its
15127 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
15128 attribute is not present. */
15130 static struct type
*
15131 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15133 struct attribute
*type_attr
;
15135 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15139 return lookup_die_type (die
, type_attr
, cu
);
15142 /* If DIE has a descriptive_type attribute, then set the TYPE's
15143 descriptive type accordingly. */
15146 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15147 struct dwarf2_cu
*cu
)
15149 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15151 if (descriptive_type
)
15153 ALLOCATE_GNAT_AUX_TYPE (type
);
15154 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15158 /* Return the containing type of the die in question using its
15159 DW_AT_containing_type attribute. */
15161 static struct type
*
15162 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15164 struct attribute
*type_attr
;
15166 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15168 error (_("Dwarf Error: Problem turning containing type into gdb type "
15169 "[in module %s]"), cu
->objfile
->name
);
15171 return lookup_die_type (die
, type_attr
, cu
);
15174 /* Look up the type of DIE in CU using its type attribute ATTR.
15175 If there is no type substitute an error marker. */
15177 static struct type
*
15178 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15179 struct dwarf2_cu
*cu
)
15181 struct objfile
*objfile
= cu
->objfile
;
15182 struct type
*this_type
;
15184 /* First see if we have it cached. */
15186 if (is_ref_attr (attr
))
15188 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15190 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15192 else if (attr
->form
== DW_FORM_ref_sig8
)
15194 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15196 /* sig_type will be NULL if the signatured type is missing from
15198 if (sig_type
== NULL
)
15199 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15200 "at 0x%x [in module %s]"),
15201 die
->offset
.sect_off
, objfile
->name
);
15203 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15204 /* If we haven't filled in type_offset_in_section yet, then we
15205 haven't read the type in yet. */
15207 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15210 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15211 &sig_type
->per_cu
);
15216 dump_die_for_error (die
);
15217 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15218 dwarf_attr_name (attr
->name
), objfile
->name
);
15221 /* If not cached we need to read it in. */
15223 if (this_type
== NULL
)
15225 struct die_info
*type_die
;
15226 struct dwarf2_cu
*type_cu
= cu
;
15228 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15229 /* If we found the type now, it's probably because the type came
15230 from an inter-CU reference and the type's CU got expanded before
15232 this_type
= get_die_type (type_die
, type_cu
);
15233 if (this_type
== NULL
)
15234 this_type
= read_type_die_1 (type_die
, type_cu
);
15237 /* If we still don't have a type use an error marker. */
15239 if (this_type
== NULL
)
15241 char *message
, *saved
;
15243 /* read_type_die already issued a complaint. */
15244 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15246 cu
->header
.offset
.sect_off
,
15247 die
->offset
.sect_off
);
15248 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15249 message
, strlen (message
));
15252 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15258 /* Return the type in DIE, CU.
15259 Returns NULL for invalid types.
15261 This first does a lookup in the appropriate type_hash table,
15262 and only reads the die in if necessary.
15264 NOTE: This can be called when reading in partial or full symbols. */
15266 static struct type
*
15267 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15269 struct type
*this_type
;
15271 this_type
= get_die_type (die
, cu
);
15275 return read_type_die_1 (die
, cu
);
15278 /* Read the type in DIE, CU.
15279 Returns NULL for invalid types. */
15281 static struct type
*
15282 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15284 struct type
*this_type
= NULL
;
15288 case DW_TAG_class_type
:
15289 case DW_TAG_interface_type
:
15290 case DW_TAG_structure_type
:
15291 case DW_TAG_union_type
:
15292 this_type
= read_structure_type (die
, cu
);
15294 case DW_TAG_enumeration_type
:
15295 this_type
= read_enumeration_type (die
, cu
);
15297 case DW_TAG_subprogram
:
15298 case DW_TAG_subroutine_type
:
15299 case DW_TAG_inlined_subroutine
:
15300 this_type
= read_subroutine_type (die
, cu
);
15302 case DW_TAG_array_type
:
15303 this_type
= read_array_type (die
, cu
);
15305 case DW_TAG_set_type
:
15306 this_type
= read_set_type (die
, cu
);
15308 case DW_TAG_pointer_type
:
15309 this_type
= read_tag_pointer_type (die
, cu
);
15311 case DW_TAG_ptr_to_member_type
:
15312 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15314 case DW_TAG_reference_type
:
15315 this_type
= read_tag_reference_type (die
, cu
);
15317 case DW_TAG_const_type
:
15318 this_type
= read_tag_const_type (die
, cu
);
15320 case DW_TAG_volatile_type
:
15321 this_type
= read_tag_volatile_type (die
, cu
);
15323 case DW_TAG_string_type
:
15324 this_type
= read_tag_string_type (die
, cu
);
15326 case DW_TAG_typedef
:
15327 this_type
= read_typedef (die
, cu
);
15329 case DW_TAG_subrange_type
:
15330 this_type
= read_subrange_type (die
, cu
);
15332 case DW_TAG_base_type
:
15333 this_type
= read_base_type (die
, cu
);
15335 case DW_TAG_unspecified_type
:
15336 this_type
= read_unspecified_type (die
, cu
);
15338 case DW_TAG_namespace
:
15339 this_type
= read_namespace_type (die
, cu
);
15341 case DW_TAG_module
:
15342 this_type
= read_module_type (die
, cu
);
15345 complaint (&symfile_complaints
,
15346 _("unexpected tag in read_type_die: '%s'"),
15347 dwarf_tag_name (die
->tag
));
15354 /* See if we can figure out if the class lives in a namespace. We do
15355 this by looking for a member function; its demangled name will
15356 contain namespace info, if there is any.
15357 Return the computed name or NULL.
15358 Space for the result is allocated on the objfile's obstack.
15359 This is the full-die version of guess_partial_die_structure_name.
15360 In this case we know DIE has no useful parent. */
15363 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15365 struct die_info
*spec_die
;
15366 struct dwarf2_cu
*spec_cu
;
15367 struct die_info
*child
;
15370 spec_die
= die_specification (die
, &spec_cu
);
15371 if (spec_die
!= NULL
)
15377 for (child
= die
->child
;
15379 child
= child
->sibling
)
15381 if (child
->tag
== DW_TAG_subprogram
)
15383 struct attribute
*attr
;
15385 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15387 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15391 = language_class_name_from_physname (cu
->language_defn
,
15395 if (actual_name
!= NULL
)
15397 char *die_name
= dwarf2_name (die
, cu
);
15399 if (die_name
!= NULL
15400 && strcmp (die_name
, actual_name
) != 0)
15402 /* Strip off the class name from the full name.
15403 We want the prefix. */
15404 int die_name_len
= strlen (die_name
);
15405 int actual_name_len
= strlen (actual_name
);
15407 /* Test for '::' as a sanity check. */
15408 if (actual_name_len
> die_name_len
+ 2
15409 && actual_name
[actual_name_len
15410 - die_name_len
- 1] == ':')
15412 obsavestring (actual_name
,
15413 actual_name_len
- die_name_len
- 2,
15414 &cu
->objfile
->objfile_obstack
);
15417 xfree (actual_name
);
15426 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15427 prefix part in such case. See
15428 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15431 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15433 struct attribute
*attr
;
15436 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15437 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15440 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15441 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15444 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15446 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15447 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15450 /* dwarf2_name had to be already called. */
15451 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15453 /* Strip the base name, keep any leading namespaces/classes. */
15454 base
= strrchr (DW_STRING (attr
), ':');
15455 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15458 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15459 &cu
->objfile
->objfile_obstack
);
15462 /* Return the name of the namespace/class that DIE is defined within,
15463 or "" if we can't tell. The caller should not xfree the result.
15465 For example, if we're within the method foo() in the following
15475 then determine_prefix on foo's die will return "N::C". */
15477 static const char *
15478 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15480 struct die_info
*parent
, *spec_die
;
15481 struct dwarf2_cu
*spec_cu
;
15482 struct type
*parent_type
;
15485 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15486 && cu
->language
!= language_fortran
)
15489 retval
= anonymous_struct_prefix (die
, cu
);
15493 /* We have to be careful in the presence of DW_AT_specification.
15494 For example, with GCC 3.4, given the code
15498 // Definition of N::foo.
15502 then we'll have a tree of DIEs like this:
15504 1: DW_TAG_compile_unit
15505 2: DW_TAG_namespace // N
15506 3: DW_TAG_subprogram // declaration of N::foo
15507 4: DW_TAG_subprogram // definition of N::foo
15508 DW_AT_specification // refers to die #3
15510 Thus, when processing die #4, we have to pretend that we're in
15511 the context of its DW_AT_specification, namely the contex of die
15514 spec_die
= die_specification (die
, &spec_cu
);
15515 if (spec_die
== NULL
)
15516 parent
= die
->parent
;
15519 parent
= spec_die
->parent
;
15523 if (parent
== NULL
)
15525 else if (parent
->building_fullname
)
15528 const char *parent_name
;
15530 /* It has been seen on RealView 2.2 built binaries,
15531 DW_TAG_template_type_param types actually _defined_ as
15532 children of the parent class:
15535 template class <class Enum> Class{};
15536 Class<enum E> class_e;
15538 1: DW_TAG_class_type (Class)
15539 2: DW_TAG_enumeration_type (E)
15540 3: DW_TAG_enumerator (enum1:0)
15541 3: DW_TAG_enumerator (enum2:1)
15543 2: DW_TAG_template_type_param
15544 DW_AT_type DW_FORM_ref_udata (E)
15546 Besides being broken debug info, it can put GDB into an
15547 infinite loop. Consider:
15549 When we're building the full name for Class<E>, we'll start
15550 at Class, and go look over its template type parameters,
15551 finding E. We'll then try to build the full name of E, and
15552 reach here. We're now trying to build the full name of E,
15553 and look over the parent DIE for containing scope. In the
15554 broken case, if we followed the parent DIE of E, we'd again
15555 find Class, and once again go look at its template type
15556 arguments, etc., etc. Simply don't consider such parent die
15557 as source-level parent of this die (it can't be, the language
15558 doesn't allow it), and break the loop here. */
15559 name
= dwarf2_name (die
, cu
);
15560 parent_name
= dwarf2_name (parent
, cu
);
15561 complaint (&symfile_complaints
,
15562 _("template param type '%s' defined within parent '%s'"),
15563 name
? name
: "<unknown>",
15564 parent_name
? parent_name
: "<unknown>");
15568 switch (parent
->tag
)
15570 case DW_TAG_namespace
:
15571 parent_type
= read_type_die (parent
, cu
);
15572 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15573 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15574 Work around this problem here. */
15575 if (cu
->language
== language_cplus
15576 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15578 /* We give a name to even anonymous namespaces. */
15579 return TYPE_TAG_NAME (parent_type
);
15580 case DW_TAG_class_type
:
15581 case DW_TAG_interface_type
:
15582 case DW_TAG_structure_type
:
15583 case DW_TAG_union_type
:
15584 case DW_TAG_module
:
15585 parent_type
= read_type_die (parent
, cu
);
15586 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15587 return TYPE_TAG_NAME (parent_type
);
15589 /* An anonymous structure is only allowed non-static data
15590 members; no typedefs, no member functions, et cetera.
15591 So it does not need a prefix. */
15593 case DW_TAG_compile_unit
:
15594 case DW_TAG_partial_unit
:
15595 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15596 if (cu
->language
== language_cplus
15597 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15598 && die
->child
!= NULL
15599 && (die
->tag
== DW_TAG_class_type
15600 || die
->tag
== DW_TAG_structure_type
15601 || die
->tag
== DW_TAG_union_type
))
15603 char *name
= guess_full_die_structure_name (die
, cu
);
15609 return determine_prefix (parent
, cu
);
15613 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15614 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15615 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15616 an obconcat, otherwise allocate storage for the result. The CU argument is
15617 used to determine the language and hence, the appropriate separator. */
15619 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15622 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15623 int physname
, struct dwarf2_cu
*cu
)
15625 const char *lead
= "";
15628 if (suffix
== NULL
|| suffix
[0] == '\0'
15629 || prefix
== NULL
|| prefix
[0] == '\0')
15631 else if (cu
->language
== language_java
)
15633 else if (cu
->language
== language_fortran
&& physname
)
15635 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15636 DW_AT_MIPS_linkage_name is preferred and used instead. */
15644 if (prefix
== NULL
)
15646 if (suffix
== NULL
)
15652 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15654 strcpy (retval
, lead
);
15655 strcat (retval
, prefix
);
15656 strcat (retval
, sep
);
15657 strcat (retval
, suffix
);
15662 /* We have an obstack. */
15663 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15667 /* Return sibling of die, NULL if no sibling. */
15669 static struct die_info
*
15670 sibling_die (struct die_info
*die
)
15672 return die
->sibling
;
15675 /* Get name of a die, return NULL if not found. */
15678 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15679 struct obstack
*obstack
)
15681 if (name
&& cu
->language
== language_cplus
)
15683 char *canon_name
= cp_canonicalize_string (name
);
15685 if (canon_name
!= NULL
)
15687 if (strcmp (canon_name
, name
) != 0)
15688 name
= obsavestring (canon_name
, strlen (canon_name
),
15690 xfree (canon_name
);
15697 /* Get name of a die, return NULL if not found. */
15700 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15702 struct attribute
*attr
;
15704 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15705 if ((!attr
|| !DW_STRING (attr
))
15706 && die
->tag
!= DW_TAG_class_type
15707 && die
->tag
!= DW_TAG_interface_type
15708 && die
->tag
!= DW_TAG_structure_type
15709 && die
->tag
!= DW_TAG_union_type
)
15714 case DW_TAG_compile_unit
:
15715 case DW_TAG_partial_unit
:
15716 /* Compilation units have a DW_AT_name that is a filename, not
15717 a source language identifier. */
15718 case DW_TAG_enumeration_type
:
15719 case DW_TAG_enumerator
:
15720 /* These tags always have simple identifiers already; no need
15721 to canonicalize them. */
15722 return DW_STRING (attr
);
15724 case DW_TAG_subprogram
:
15725 /* Java constructors will all be named "<init>", so return
15726 the class name when we see this special case. */
15727 if (cu
->language
== language_java
15728 && DW_STRING (attr
) != NULL
15729 && strcmp (DW_STRING (attr
), "<init>") == 0)
15731 struct dwarf2_cu
*spec_cu
= cu
;
15732 struct die_info
*spec_die
;
15734 /* GCJ will output '<init>' for Java constructor names.
15735 For this special case, return the name of the parent class. */
15737 /* GCJ may output suprogram DIEs with AT_specification set.
15738 If so, use the name of the specified DIE. */
15739 spec_die
= die_specification (die
, &spec_cu
);
15740 if (spec_die
!= NULL
)
15741 return dwarf2_name (spec_die
, spec_cu
);
15746 if (die
->tag
== DW_TAG_class_type
)
15747 return dwarf2_name (die
, cu
);
15749 while (die
->tag
!= DW_TAG_compile_unit
15750 && die
->tag
!= DW_TAG_partial_unit
);
15754 case DW_TAG_class_type
:
15755 case DW_TAG_interface_type
:
15756 case DW_TAG_structure_type
:
15757 case DW_TAG_union_type
:
15758 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
15759 structures or unions. These were of the form "._%d" in GCC 4.1,
15760 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
15761 and GCC 4.4. We work around this problem by ignoring these. */
15762 if (attr
&& DW_STRING (attr
)
15763 && (strncmp (DW_STRING (attr
), "._", 2) == 0
15764 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
15767 /* GCC might emit a nameless typedef that has a linkage name. See
15768 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15769 if (!attr
|| DW_STRING (attr
) == NULL
)
15771 char *demangled
= NULL
;
15773 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15775 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15777 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15780 /* Avoid demangling DW_STRING (attr) the second time on a second
15781 call for the same DIE. */
15782 if (!DW_STRING_IS_CANONICAL (attr
))
15783 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
15789 /* FIXME: we already did this for the partial symbol... */
15790 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
15791 &cu
->objfile
->objfile_obstack
);
15792 DW_STRING_IS_CANONICAL (attr
) = 1;
15795 /* Strip any leading namespaces/classes, keep only the base name.
15796 DW_AT_name for named DIEs does not contain the prefixes. */
15797 base
= strrchr (DW_STRING (attr
), ':');
15798 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
15801 return DW_STRING (attr
);
15810 if (!DW_STRING_IS_CANONICAL (attr
))
15813 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
15814 &cu
->objfile
->objfile_obstack
);
15815 DW_STRING_IS_CANONICAL (attr
) = 1;
15817 return DW_STRING (attr
);
15820 /* Return the die that this die in an extension of, or NULL if there
15821 is none. *EXT_CU is the CU containing DIE on input, and the CU
15822 containing the return value on output. */
15824 static struct die_info
*
15825 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
15827 struct attribute
*attr
;
15829 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
15833 return follow_die_ref (die
, attr
, ext_cu
);
15836 /* Convert a DIE tag into its string name. */
15838 static const char *
15839 dwarf_tag_name (unsigned tag
)
15841 const char *name
= get_DW_TAG_name (tag
);
15844 return "DW_TAG_<unknown>";
15849 /* Convert a DWARF attribute code into its string name. */
15851 static const char *
15852 dwarf_attr_name (unsigned attr
)
15856 #ifdef MIPS /* collides with DW_AT_HP_block_index */
15857 if (attr
== DW_AT_MIPS_fde
)
15858 return "DW_AT_MIPS_fde";
15860 if (attr
== DW_AT_HP_block_index
)
15861 return "DW_AT_HP_block_index";
15864 name
= get_DW_AT_name (attr
);
15867 return "DW_AT_<unknown>";
15872 /* Convert a DWARF value form code into its string name. */
15874 static const char *
15875 dwarf_form_name (unsigned form
)
15877 const char *name
= get_DW_FORM_name (form
);
15880 return "DW_FORM_<unknown>";
15886 dwarf_bool_name (unsigned mybool
)
15894 /* Convert a DWARF type code into its string name. */
15896 static const char *
15897 dwarf_type_encoding_name (unsigned enc
)
15899 const char *name
= get_DW_ATE_name (enc
);
15902 return "DW_ATE_<unknown>";
15908 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
15912 print_spaces (indent
, f
);
15913 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
15914 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
15916 if (die
->parent
!= NULL
)
15918 print_spaces (indent
, f
);
15919 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
15920 die
->parent
->offset
.sect_off
);
15923 print_spaces (indent
, f
);
15924 fprintf_unfiltered (f
, " has children: %s\n",
15925 dwarf_bool_name (die
->child
!= NULL
));
15927 print_spaces (indent
, f
);
15928 fprintf_unfiltered (f
, " attributes:\n");
15930 for (i
= 0; i
< die
->num_attrs
; ++i
)
15932 print_spaces (indent
, f
);
15933 fprintf_unfiltered (f
, " %s (%s) ",
15934 dwarf_attr_name (die
->attrs
[i
].name
),
15935 dwarf_form_name (die
->attrs
[i
].form
));
15937 switch (die
->attrs
[i
].form
)
15940 case DW_FORM_GNU_addr_index
:
15941 fprintf_unfiltered (f
, "address: ");
15942 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
15944 case DW_FORM_block2
:
15945 case DW_FORM_block4
:
15946 case DW_FORM_block
:
15947 case DW_FORM_block1
:
15948 fprintf_unfiltered (f
, "block: size %d",
15949 DW_BLOCK (&die
->attrs
[i
])->size
);
15951 case DW_FORM_exprloc
:
15952 fprintf_unfiltered (f
, "expression: size %u",
15953 DW_BLOCK (&die
->attrs
[i
])->size
);
15955 case DW_FORM_ref_addr
:
15956 fprintf_unfiltered (f
, "ref address: ");
15957 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
15963 case DW_FORM_ref_udata
:
15964 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
15965 (long) (DW_UNSND (&die
->attrs
[i
])));
15967 case DW_FORM_data1
:
15968 case DW_FORM_data2
:
15969 case DW_FORM_data4
:
15970 case DW_FORM_data8
:
15971 case DW_FORM_udata
:
15972 case DW_FORM_sdata
:
15973 fprintf_unfiltered (f
, "constant: %s",
15974 pulongest (DW_UNSND (&die
->attrs
[i
])));
15976 case DW_FORM_sec_offset
:
15977 fprintf_unfiltered (f
, "section offset: %s",
15978 pulongest (DW_UNSND (&die
->attrs
[i
])));
15980 case DW_FORM_ref_sig8
:
15981 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
15982 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
15983 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
15985 fprintf_unfiltered (f
, "signatured type, offset: unknown");
15987 case DW_FORM_string
:
15989 case DW_FORM_GNU_str_index
:
15990 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
15991 DW_STRING (&die
->attrs
[i
])
15992 ? DW_STRING (&die
->attrs
[i
]) : "",
15993 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
15996 if (DW_UNSND (&die
->attrs
[i
]))
15997 fprintf_unfiltered (f
, "flag: TRUE");
15999 fprintf_unfiltered (f
, "flag: FALSE");
16001 case DW_FORM_flag_present
:
16002 fprintf_unfiltered (f
, "flag: TRUE");
16004 case DW_FORM_indirect
:
16005 /* The reader will have reduced the indirect form to
16006 the "base form" so this form should not occur. */
16007 fprintf_unfiltered (f
,
16008 "unexpected attribute form: DW_FORM_indirect");
16011 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
16012 die
->attrs
[i
].form
);
16015 fprintf_unfiltered (f
, "\n");
16020 dump_die_for_error (struct die_info
*die
)
16022 dump_die_shallow (gdb_stderr
, 0, die
);
16026 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
16028 int indent
= level
* 4;
16030 gdb_assert (die
!= NULL
);
16032 if (level
>= max_level
)
16035 dump_die_shallow (f
, indent
, die
);
16037 if (die
->child
!= NULL
)
16039 print_spaces (indent
, f
);
16040 fprintf_unfiltered (f
, " Children:");
16041 if (level
+ 1 < max_level
)
16043 fprintf_unfiltered (f
, "\n");
16044 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
16048 fprintf_unfiltered (f
,
16049 " [not printed, max nesting level reached]\n");
16053 if (die
->sibling
!= NULL
&& level
> 0)
16055 dump_die_1 (f
, level
, max_level
, die
->sibling
);
16059 /* This is called from the pdie macro in gdbinit.in.
16060 It's not static so gcc will keep a copy callable from gdb. */
16063 dump_die (struct die_info
*die
, int max_level
)
16065 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
16069 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
16073 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
16079 /* DW_ADDR is always stored already as sect_offset; despite for the forms
16080 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
16083 is_ref_attr (struct attribute
*attr
)
16085 switch (attr
->form
)
16087 case DW_FORM_ref_addr
:
16092 case DW_FORM_ref_udata
:
16099 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
16103 dwarf2_get_ref_die_offset (struct attribute
*attr
)
16105 sect_offset retval
= { DW_UNSND (attr
) };
16107 if (is_ref_attr (attr
))
16110 retval
.sect_off
= 0;
16111 complaint (&symfile_complaints
,
16112 _("unsupported die ref attribute form: '%s'"),
16113 dwarf_form_name (attr
->form
));
16117 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
16118 * the value held by the attribute is not constant. */
16121 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
16123 if (attr
->form
== DW_FORM_sdata
)
16124 return DW_SND (attr
);
16125 else if (attr
->form
== DW_FORM_udata
16126 || attr
->form
== DW_FORM_data1
16127 || attr
->form
== DW_FORM_data2
16128 || attr
->form
== DW_FORM_data4
16129 || attr
->form
== DW_FORM_data8
)
16130 return DW_UNSND (attr
);
16133 complaint (&symfile_complaints
,
16134 _("Attribute value is not a constant (%s)"),
16135 dwarf_form_name (attr
->form
));
16136 return default_value
;
16140 /* Follow reference or signature attribute ATTR of SRC_DIE.
16141 On entry *REF_CU is the CU of SRC_DIE.
16142 On exit *REF_CU is the CU of the result. */
16144 static struct die_info
*
16145 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16146 struct dwarf2_cu
**ref_cu
)
16148 struct die_info
*die
;
16150 if (is_ref_attr (attr
))
16151 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16152 else if (attr
->form
== DW_FORM_ref_sig8
)
16153 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16156 dump_die_for_error (src_die
);
16157 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16158 (*ref_cu
)->objfile
->name
);
16164 /* Follow reference OFFSET.
16165 On entry *REF_CU is the CU of the source die referencing OFFSET.
16166 On exit *REF_CU is the CU of the result.
16167 Returns NULL if OFFSET is invalid. */
16169 static struct die_info
*
16170 follow_die_offset (sect_offset offset
, struct dwarf2_cu
**ref_cu
)
16172 struct die_info temp_die
;
16173 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16175 gdb_assert (cu
->per_cu
!= NULL
);
16179 if (cu
->per_cu
->is_debug_types
)
16181 /* .debug_types CUs cannot reference anything outside their CU.
16182 If they need to, they have to reference a signatured type via
16183 DW_FORM_ref_sig8. */
16184 if (! offset_in_cu_p (&cu
->header
, offset
))
16187 else if (! offset_in_cu_p (&cu
->header
, offset
))
16189 struct dwarf2_per_cu_data
*per_cu
;
16191 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
16193 /* If necessary, add it to the queue and load its DIEs. */
16194 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16195 load_full_comp_unit (per_cu
, cu
->language
);
16197 target_cu
= per_cu
->cu
;
16199 else if (cu
->dies
== NULL
)
16201 /* We're loading full DIEs during partial symbol reading. */
16202 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16203 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16206 *ref_cu
= target_cu
;
16207 temp_die
.offset
= offset
;
16208 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16211 /* Follow reference attribute ATTR of SRC_DIE.
16212 On entry *REF_CU is the CU of SRC_DIE.
16213 On exit *REF_CU is the CU of the result. */
16215 static struct die_info
*
16216 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16217 struct dwarf2_cu
**ref_cu
)
16219 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16220 struct dwarf2_cu
*cu
= *ref_cu
;
16221 struct die_info
*die
;
16223 die
= follow_die_offset (offset
, ref_cu
);
16225 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16226 "at 0x%x [in module %s]"),
16227 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16232 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16233 Returned value is intended for DW_OP_call*. Returned
16234 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16236 struct dwarf2_locexpr_baton
16237 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16238 struct dwarf2_per_cu_data
*per_cu
,
16239 CORE_ADDR (*get_frame_pc
) (void *baton
),
16242 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16243 struct dwarf2_cu
*cu
;
16244 struct die_info
*die
;
16245 struct attribute
*attr
;
16246 struct dwarf2_locexpr_baton retval
;
16248 dw2_setup (per_cu
->objfile
);
16250 if (per_cu
->cu
== NULL
)
16254 die
= follow_die_offset (offset
, &cu
);
16256 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16257 offset
.sect_off
, per_cu
->objfile
->name
);
16259 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16262 /* DWARF: "If there is no such attribute, then there is no effect.".
16263 DATA is ignored if SIZE is 0. */
16265 retval
.data
= NULL
;
16268 else if (attr_form_is_section_offset (attr
))
16270 struct dwarf2_loclist_baton loclist_baton
;
16271 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16274 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16276 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16278 retval
.size
= size
;
16282 if (!attr_form_is_block (attr
))
16283 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16284 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16285 offset
.sect_off
, per_cu
->objfile
->name
);
16287 retval
.data
= DW_BLOCK (attr
)->data
;
16288 retval
.size
= DW_BLOCK (attr
)->size
;
16290 retval
.per_cu
= cu
->per_cu
;
16292 age_cached_comp_units ();
16297 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16301 dwarf2_get_die_type (cu_offset die_offset
,
16302 struct dwarf2_per_cu_data
*per_cu
)
16304 sect_offset die_offset_sect
;
16306 dw2_setup (per_cu
->objfile
);
16308 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16309 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16312 /* Follow the signature attribute ATTR in SRC_DIE.
16313 On entry *REF_CU is the CU of SRC_DIE.
16314 On exit *REF_CU is the CU of the result. */
16316 static struct die_info
*
16317 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16318 struct dwarf2_cu
**ref_cu
)
16320 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16321 struct die_info temp_die
;
16322 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16323 struct dwarf2_cu
*sig_cu
;
16324 struct die_info
*die
;
16326 /* sig_type will be NULL if the signatured type is missing from
16328 if (sig_type
== NULL
)
16329 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16330 "at 0x%x [in module %s]"),
16331 src_die
->offset
.sect_off
, objfile
->name
);
16333 /* If necessary, add it to the queue and load its DIEs. */
16335 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16336 read_signatured_type (sig_type
);
16338 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16340 sig_cu
= sig_type
->per_cu
.cu
;
16341 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16342 temp_die
.offset
= sig_type
->type_offset_in_section
;
16343 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16344 temp_die
.offset
.sect_off
);
16351 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16352 "from DIE at 0x%x [in module %s]"),
16353 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16356 /* Given an offset of a signatured type, return its signatured_type. */
16358 static struct signatured_type
*
16359 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16360 struct dwarf2_section_info
*section
,
16361 sect_offset offset
)
16363 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16364 unsigned int length
, initial_length_size
;
16365 unsigned int sig_offset
;
16366 struct signatured_type find_entry
, *sig_type
;
16368 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16369 sig_offset
= (initial_length_size
16371 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16372 + 1 /*address_size*/);
16373 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16374 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16376 /* This is only used to lookup previously recorded types.
16377 If we didn't find it, it's our bug. */
16378 gdb_assert (sig_type
!= NULL
);
16379 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16384 /* Load the DIEs associated with type unit PER_CU into memory. */
16387 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16389 struct signatured_type
*sig_type
;
16391 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16392 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16394 /* We have the per_cu, but we need the signatured_type.
16395 Fortunately this is an easy translation. */
16396 gdb_assert (per_cu
->is_debug_types
);
16397 sig_type
= (struct signatured_type
*) per_cu
;
16399 gdb_assert (per_cu
->cu
== NULL
);
16401 read_signatured_type (sig_type
);
16403 gdb_assert (per_cu
->cu
!= NULL
);
16406 /* die_reader_func for read_signatured_type.
16407 This is identical to load_full_comp_unit_reader,
16408 but is kept separate for now. */
16411 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16412 gdb_byte
*info_ptr
,
16413 struct die_info
*comp_unit_die
,
16417 struct dwarf2_cu
*cu
= reader
->cu
;
16419 gdb_assert (cu
->die_hash
== NULL
);
16421 htab_create_alloc_ex (cu
->header
.length
/ 12,
16425 &cu
->comp_unit_obstack
,
16426 hashtab_obstack_allocate
,
16427 dummy_obstack_deallocate
);
16430 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16431 &info_ptr
, comp_unit_die
);
16432 cu
->dies
= comp_unit_die
;
16433 /* comp_unit_die is not stored in die_hash, no need. */
16435 /* We try not to read any attributes in this function, because not
16436 all CUs needed for references have been loaded yet, and symbol
16437 table processing isn't initialized. But we have to set the CU language,
16438 or we won't be able to build types correctly.
16439 Similarly, if we do not read the producer, we can not apply
16440 producer-specific interpretation. */
16441 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16444 /* Read in a signatured type and build its CU and DIEs.
16445 If the type is a stub for the real type in a DWO file,
16446 read in the real type from the DWO file as well. */
16449 read_signatured_type (struct signatured_type
*sig_type
)
16451 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16453 gdb_assert (per_cu
->is_debug_types
);
16454 gdb_assert (per_cu
->cu
== NULL
);
16456 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16457 read_signatured_type_reader
, NULL
);
16460 /* Decode simple location descriptions.
16461 Given a pointer to a dwarf block that defines a location, compute
16462 the location and return the value.
16464 NOTE drow/2003-11-18: This function is called in two situations
16465 now: for the address of static or global variables (partial symbols
16466 only) and for offsets into structures which are expected to be
16467 (more or less) constant. The partial symbol case should go away,
16468 and only the constant case should remain. That will let this
16469 function complain more accurately. A few special modes are allowed
16470 without complaint for global variables (for instance, global
16471 register values and thread-local values).
16473 A location description containing no operations indicates that the
16474 object is optimized out. The return value is 0 for that case.
16475 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16476 callers will only want a very basic result and this can become a
16479 Note that stack[0] is unused except as a default error return. */
16482 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16484 struct objfile
*objfile
= cu
->objfile
;
16486 int size
= blk
->size
;
16487 gdb_byte
*data
= blk
->data
;
16488 CORE_ADDR stack
[64];
16490 unsigned int bytes_read
, unsnd
;
16496 stack
[++stacki
] = 0;
16535 stack
[++stacki
] = op
- DW_OP_lit0
;
16570 stack
[++stacki
] = op
- DW_OP_reg0
;
16572 dwarf2_complex_location_expr_complaint ();
16576 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16578 stack
[++stacki
] = unsnd
;
16580 dwarf2_complex_location_expr_complaint ();
16584 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16589 case DW_OP_const1u
:
16590 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16594 case DW_OP_const1s
:
16595 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16599 case DW_OP_const2u
:
16600 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16604 case DW_OP_const2s
:
16605 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16609 case DW_OP_const4u
:
16610 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16614 case DW_OP_const4s
:
16615 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16619 case DW_OP_const8u
:
16620 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16625 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16631 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16636 stack
[stacki
+ 1] = stack
[stacki
];
16641 stack
[stacki
- 1] += stack
[stacki
];
16645 case DW_OP_plus_uconst
:
16646 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16652 stack
[stacki
- 1] -= stack
[stacki
];
16657 /* If we're not the last op, then we definitely can't encode
16658 this using GDB's address_class enum. This is valid for partial
16659 global symbols, although the variable's address will be bogus
16662 dwarf2_complex_location_expr_complaint ();
16665 case DW_OP_GNU_push_tls_address
:
16666 /* The top of the stack has the offset from the beginning
16667 of the thread control block at which the variable is located. */
16668 /* Nothing should follow this operator, so the top of stack would
16670 /* This is valid for partial global symbols, but the variable's
16671 address will be bogus in the psymtab. Make it always at least
16672 non-zero to not look as a variable garbage collected by linker
16673 which have DW_OP_addr 0. */
16675 dwarf2_complex_location_expr_complaint ();
16679 case DW_OP_GNU_uninit
:
16682 case DW_OP_GNU_addr_index
:
16683 case DW_OP_GNU_const_index
:
16684 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16691 const char *name
= get_DW_OP_name (op
);
16694 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16697 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16701 return (stack
[stacki
]);
16704 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16705 outside of the allocated space. Also enforce minimum>0. */
16706 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16708 complaint (&symfile_complaints
,
16709 _("location description stack overflow"));
16715 complaint (&symfile_complaints
,
16716 _("location description stack underflow"));
16720 return (stack
[stacki
]);
16723 /* memory allocation interface */
16725 static struct dwarf_block
*
16726 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16728 struct dwarf_block
*blk
;
16730 blk
= (struct dwarf_block
*)
16731 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16735 static struct die_info
*
16736 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16738 struct die_info
*die
;
16739 size_t size
= sizeof (struct die_info
);
16742 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16744 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16745 memset (die
, 0, sizeof (struct die_info
));
16750 /* Macro support. */
16752 /* Return the full name of file number I in *LH's file name table.
16753 Use COMP_DIR as the name of the current directory of the
16754 compilation. The result is allocated using xmalloc; the caller is
16755 responsible for freeing it. */
16757 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
16759 /* Is the file number a valid index into the line header's file name
16760 table? Remember that file numbers start with one, not zero. */
16761 if (1 <= file
&& file
<= lh
->num_file_names
)
16763 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
16765 if (IS_ABSOLUTE_PATH (fe
->name
))
16766 return xstrdup (fe
->name
);
16774 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
16780 dir_len
= strlen (dir
);
16781 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
16782 strcpy (full_name
, dir
);
16783 full_name
[dir_len
] = '/';
16784 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
16788 return xstrdup (fe
->name
);
16793 /* The compiler produced a bogus file number. We can at least
16794 record the macro definitions made in the file, even if we
16795 won't be able to find the file by name. */
16796 char fake_name
[80];
16798 sprintf (fake_name
, "<bad macro file number %d>", file
);
16800 complaint (&symfile_complaints
,
16801 _("bad file number in macro information (%d)"),
16804 return xstrdup (fake_name
);
16809 static struct macro_source_file
*
16810 macro_start_file (int file
, int line
,
16811 struct macro_source_file
*current_file
,
16812 const char *comp_dir
,
16813 struct line_header
*lh
, struct objfile
*objfile
)
16815 /* The full name of this source file. */
16816 char *full_name
= file_full_name (file
, lh
, comp_dir
);
16818 /* We don't create a macro table for this compilation unit
16819 at all until we actually get a filename. */
16820 if (! pending_macros
)
16821 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
16822 objfile
->macro_cache
);
16824 if (! current_file
)
16826 /* If we have no current file, then this must be the start_file
16827 directive for the compilation unit's main source file. */
16828 current_file
= macro_set_main (pending_macros
, full_name
);
16829 macro_define_special (pending_macros
);
16832 current_file
= macro_include (current_file
, line
, full_name
);
16836 return current_file
;
16840 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
16841 followed by a null byte. */
16843 copy_string (const char *buf
, int len
)
16845 char *s
= xmalloc (len
+ 1);
16847 memcpy (s
, buf
, len
);
16853 static const char *
16854 consume_improper_spaces (const char *p
, const char *body
)
16858 complaint (&symfile_complaints
,
16859 _("macro definition contains spaces "
16860 "in formal argument list:\n`%s'"),
16872 parse_macro_definition (struct macro_source_file
*file
, int line
,
16877 /* The body string takes one of two forms. For object-like macro
16878 definitions, it should be:
16880 <macro name> " " <definition>
16882 For function-like macro definitions, it should be:
16884 <macro name> "() " <definition>
16886 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
16888 Spaces may appear only where explicitly indicated, and in the
16891 The Dwarf 2 spec says that an object-like macro's name is always
16892 followed by a space, but versions of GCC around March 2002 omit
16893 the space when the macro's definition is the empty string.
16895 The Dwarf 2 spec says that there should be no spaces between the
16896 formal arguments in a function-like macro's formal argument list,
16897 but versions of GCC around March 2002 include spaces after the
16901 /* Find the extent of the macro name. The macro name is terminated
16902 by either a space or null character (for an object-like macro) or
16903 an opening paren (for a function-like macro). */
16904 for (p
= body
; *p
; p
++)
16905 if (*p
== ' ' || *p
== '(')
16908 if (*p
== ' ' || *p
== '\0')
16910 /* It's an object-like macro. */
16911 int name_len
= p
- body
;
16912 char *name
= copy_string (body
, name_len
);
16913 const char *replacement
;
16916 replacement
= body
+ name_len
+ 1;
16919 dwarf2_macro_malformed_definition_complaint (body
);
16920 replacement
= body
+ name_len
;
16923 macro_define_object (file
, line
, name
, replacement
);
16927 else if (*p
== '(')
16929 /* It's a function-like macro. */
16930 char *name
= copy_string (body
, p
- body
);
16933 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
16937 p
= consume_improper_spaces (p
, body
);
16939 /* Parse the formal argument list. */
16940 while (*p
&& *p
!= ')')
16942 /* Find the extent of the current argument name. */
16943 const char *arg_start
= p
;
16945 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
16948 if (! *p
|| p
== arg_start
)
16949 dwarf2_macro_malformed_definition_complaint (body
);
16952 /* Make sure argv has room for the new argument. */
16953 if (argc
>= argv_size
)
16956 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
16959 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
16962 p
= consume_improper_spaces (p
, body
);
16964 /* Consume the comma, if present. */
16969 p
= consume_improper_spaces (p
, body
);
16978 /* Perfectly formed definition, no complaints. */
16979 macro_define_function (file
, line
, name
,
16980 argc
, (const char **) argv
,
16982 else if (*p
== '\0')
16984 /* Complain, but do define it. */
16985 dwarf2_macro_malformed_definition_complaint (body
);
16986 macro_define_function (file
, line
, name
,
16987 argc
, (const char **) argv
,
16991 /* Just complain. */
16992 dwarf2_macro_malformed_definition_complaint (body
);
16995 /* Just complain. */
16996 dwarf2_macro_malformed_definition_complaint (body
);
17002 for (i
= 0; i
< argc
; i
++)
17008 dwarf2_macro_malformed_definition_complaint (body
);
17011 /* Skip some bytes from BYTES according to the form given in FORM.
17012 Returns the new pointer. */
17015 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
17016 enum dwarf_form form
,
17017 unsigned int offset_size
,
17018 struct dwarf2_section_info
*section
)
17020 unsigned int bytes_read
;
17024 case DW_FORM_data1
:
17029 case DW_FORM_data2
:
17033 case DW_FORM_data4
:
17037 case DW_FORM_data8
:
17041 case DW_FORM_string
:
17042 read_direct_string (abfd
, bytes
, &bytes_read
);
17043 bytes
+= bytes_read
;
17046 case DW_FORM_sec_offset
:
17048 bytes
+= offset_size
;
17051 case DW_FORM_block
:
17052 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
17053 bytes
+= bytes_read
;
17056 case DW_FORM_block1
:
17057 bytes
+= 1 + read_1_byte (abfd
, bytes
);
17059 case DW_FORM_block2
:
17060 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
17062 case DW_FORM_block4
:
17063 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
17066 case DW_FORM_sdata
:
17067 case DW_FORM_udata
:
17068 case DW_FORM_GNU_addr_index
:
17069 case DW_FORM_GNU_str_index
:
17070 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
17073 dwarf2_section_buffer_overflow_complaint (section
);
17081 complaint (&symfile_complaints
,
17082 _("invalid form 0x%x in `%s'"),
17084 section
->asection
->name
);
17092 /* A helper for dwarf_decode_macros that handles skipping an unknown
17093 opcode. Returns an updated pointer to the macro data buffer; or,
17094 on error, issues a complaint and returns NULL. */
17097 skip_unknown_opcode (unsigned int opcode
,
17098 gdb_byte
**opcode_definitions
,
17099 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17101 unsigned int offset_size
,
17102 struct dwarf2_section_info
*section
)
17104 unsigned int bytes_read
, i
;
17108 if (opcode_definitions
[opcode
] == NULL
)
17110 complaint (&symfile_complaints
,
17111 _("unrecognized DW_MACFINO opcode 0x%x"),
17116 defn
= opcode_definitions
[opcode
];
17117 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
17118 defn
+= bytes_read
;
17120 for (i
= 0; i
< arg
; ++i
)
17122 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
17124 if (mac_ptr
== NULL
)
17126 /* skip_form_bytes already issued the complaint. */
17134 /* A helper function which parses the header of a macro section.
17135 If the macro section is the extended (for now called "GNU") type,
17136 then this updates *OFFSET_SIZE. Returns a pointer to just after
17137 the header, or issues a complaint and returns NULL on error. */
17140 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17143 unsigned int *offset_size
,
17144 int section_is_gnu
)
17146 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17148 if (section_is_gnu
)
17150 unsigned int version
, flags
;
17152 version
= read_2_bytes (abfd
, mac_ptr
);
17155 complaint (&symfile_complaints
,
17156 _("unrecognized version `%d' in .debug_macro section"),
17162 flags
= read_1_byte (abfd
, mac_ptr
);
17164 *offset_size
= (flags
& 1) ? 8 : 4;
17166 if ((flags
& 2) != 0)
17167 /* We don't need the line table offset. */
17168 mac_ptr
+= *offset_size
;
17170 /* Vendor opcode descriptions. */
17171 if ((flags
& 4) != 0)
17173 unsigned int i
, count
;
17175 count
= read_1_byte (abfd
, mac_ptr
);
17177 for (i
= 0; i
< count
; ++i
)
17179 unsigned int opcode
, bytes_read
;
17182 opcode
= read_1_byte (abfd
, mac_ptr
);
17184 opcode_definitions
[opcode
] = mac_ptr
;
17185 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17186 mac_ptr
+= bytes_read
;
17195 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17196 including DW_MACRO_GNU_transparent_include. */
17199 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17200 struct macro_source_file
*current_file
,
17201 struct line_header
*lh
, char *comp_dir
,
17202 struct dwarf2_section_info
*section
,
17203 int section_is_gnu
,
17204 unsigned int offset_size
,
17205 struct objfile
*objfile
,
17206 htab_t include_hash
)
17208 enum dwarf_macro_record_type macinfo_type
;
17209 int at_commandline
;
17210 gdb_byte
*opcode_definitions
[256];
17212 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17213 &offset_size
, section_is_gnu
);
17214 if (mac_ptr
== NULL
)
17216 /* We already issued a complaint. */
17220 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17221 GDB is still reading the definitions from command line. First
17222 DW_MACINFO_start_file will need to be ignored as it was already executed
17223 to create CURRENT_FILE for the main source holding also the command line
17224 definitions. On first met DW_MACINFO_start_file this flag is reset to
17225 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17227 at_commandline
= 1;
17231 /* Do we at least have room for a macinfo type byte? */
17232 if (mac_ptr
>= mac_end
)
17234 dwarf2_section_buffer_overflow_complaint (section
);
17238 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17241 /* Note that we rely on the fact that the corresponding GNU and
17242 DWARF constants are the same. */
17243 switch (macinfo_type
)
17245 /* A zero macinfo type indicates the end of the macro
17250 case DW_MACRO_GNU_define
:
17251 case DW_MACRO_GNU_undef
:
17252 case DW_MACRO_GNU_define_indirect
:
17253 case DW_MACRO_GNU_undef_indirect
:
17255 unsigned int bytes_read
;
17260 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17261 mac_ptr
+= bytes_read
;
17263 if (macinfo_type
== DW_MACRO_GNU_define
17264 || macinfo_type
== DW_MACRO_GNU_undef
)
17266 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17267 mac_ptr
+= bytes_read
;
17271 LONGEST str_offset
;
17273 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17274 mac_ptr
+= offset_size
;
17276 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17279 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17280 || macinfo_type
== DW_MACRO_GNU_define_indirect
);
17281 if (! current_file
)
17283 /* DWARF violation as no main source is present. */
17284 complaint (&symfile_complaints
,
17285 _("debug info with no main source gives macro %s "
17287 is_define
? _("definition") : _("undefinition"),
17291 if ((line
== 0 && !at_commandline
)
17292 || (line
!= 0 && at_commandline
))
17293 complaint (&symfile_complaints
,
17294 _("debug info gives %s macro %s with %s line %d: %s"),
17295 at_commandline
? _("command-line") : _("in-file"),
17296 is_define
? _("definition") : _("undefinition"),
17297 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17300 parse_macro_definition (current_file
, line
, body
);
17303 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17304 || macinfo_type
== DW_MACRO_GNU_undef_indirect
);
17305 macro_undef (current_file
, line
, body
);
17310 case DW_MACRO_GNU_start_file
:
17312 unsigned int bytes_read
;
17315 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17316 mac_ptr
+= bytes_read
;
17317 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17318 mac_ptr
+= bytes_read
;
17320 if ((line
== 0 && !at_commandline
)
17321 || (line
!= 0 && at_commandline
))
17322 complaint (&symfile_complaints
,
17323 _("debug info gives source %d included "
17324 "from %s at %s line %d"),
17325 file
, at_commandline
? _("command-line") : _("file"),
17326 line
== 0 ? _("zero") : _("non-zero"), line
);
17328 if (at_commandline
)
17330 /* This DW_MACRO_GNU_start_file was executed in the
17332 at_commandline
= 0;
17335 current_file
= macro_start_file (file
, line
,
17336 current_file
, comp_dir
,
17341 case DW_MACRO_GNU_end_file
:
17342 if (! current_file
)
17343 complaint (&symfile_complaints
,
17344 _("macro debug info has an unmatched "
17345 "`close_file' directive"));
17348 current_file
= current_file
->included_by
;
17349 if (! current_file
)
17351 enum dwarf_macro_record_type next_type
;
17353 /* GCC circa March 2002 doesn't produce the zero
17354 type byte marking the end of the compilation
17355 unit. Complain if it's not there, but exit no
17358 /* Do we at least have room for a macinfo type byte? */
17359 if (mac_ptr
>= mac_end
)
17361 dwarf2_section_buffer_overflow_complaint (section
);
17365 /* We don't increment mac_ptr here, so this is just
17367 next_type
= read_1_byte (abfd
, mac_ptr
);
17368 if (next_type
!= 0)
17369 complaint (&symfile_complaints
,
17370 _("no terminating 0-type entry for "
17371 "macros in `.debug_macinfo' section"));
17378 case DW_MACRO_GNU_transparent_include
:
17383 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17384 mac_ptr
+= offset_size
;
17386 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17389 /* This has actually happened; see
17390 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17391 complaint (&symfile_complaints
,
17392 _("recursive DW_MACRO_GNU_transparent_include in "
17393 ".debug_macro section"));
17399 dwarf_decode_macro_bytes (abfd
,
17400 section
->buffer
+ offset
,
17401 mac_end
, current_file
,
17403 section
, section_is_gnu
,
17404 offset_size
, objfile
, include_hash
);
17406 htab_remove_elt (include_hash
, mac_ptr
);
17411 case DW_MACINFO_vendor_ext
:
17412 if (!section_is_gnu
)
17414 unsigned int bytes_read
;
17417 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17418 mac_ptr
+= bytes_read
;
17419 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17420 mac_ptr
+= bytes_read
;
17422 /* We don't recognize any vendor extensions. */
17428 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17429 mac_ptr
, mac_end
, abfd
, offset_size
,
17431 if (mac_ptr
== NULL
)
17435 } while (macinfo_type
!= 0);
17439 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17440 char *comp_dir
, int section_is_gnu
)
17442 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17443 struct line_header
*lh
= cu
->line_header
;
17445 gdb_byte
*mac_ptr
, *mac_end
;
17446 struct macro_source_file
*current_file
= 0;
17447 enum dwarf_macro_record_type macinfo_type
;
17448 unsigned int offset_size
= cu
->header
.offset_size
;
17449 gdb_byte
*opcode_definitions
[256];
17450 struct cleanup
*cleanup
;
17451 htab_t include_hash
;
17453 struct dwarf2_section_info
*section
;
17454 const char *section_name
;
17456 if (cu
->dwo_unit
!= NULL
)
17458 if (section_is_gnu
)
17460 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17461 section_name
= ".debug_macro.dwo";
17465 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17466 section_name
= ".debug_macinfo.dwo";
17471 if (section_is_gnu
)
17473 section
= &dwarf2_per_objfile
->macro
;
17474 section_name
= ".debug_macro";
17478 section
= &dwarf2_per_objfile
->macinfo
;
17479 section_name
= ".debug_macinfo";
17483 dwarf2_read_section (objfile
, section
);
17484 if (section
->buffer
== NULL
)
17486 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17489 abfd
= section
->asection
->owner
;
17491 /* First pass: Find the name of the base filename.
17492 This filename is needed in order to process all macros whose definition
17493 (or undefinition) comes from the command line. These macros are defined
17494 before the first DW_MACINFO_start_file entry, and yet still need to be
17495 associated to the base file.
17497 To determine the base file name, we scan the macro definitions until we
17498 reach the first DW_MACINFO_start_file entry. We then initialize
17499 CURRENT_FILE accordingly so that any macro definition found before the
17500 first DW_MACINFO_start_file can still be associated to the base file. */
17502 mac_ptr
= section
->buffer
+ offset
;
17503 mac_end
= section
->buffer
+ section
->size
;
17505 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17506 &offset_size
, section_is_gnu
);
17507 if (mac_ptr
== NULL
)
17509 /* We already issued a complaint. */
17515 /* Do we at least have room for a macinfo type byte? */
17516 if (mac_ptr
>= mac_end
)
17518 /* Complaint is printed during the second pass as GDB will probably
17519 stop the first pass earlier upon finding
17520 DW_MACINFO_start_file. */
17524 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17527 /* Note that we rely on the fact that the corresponding GNU and
17528 DWARF constants are the same. */
17529 switch (macinfo_type
)
17531 /* A zero macinfo type indicates the end of the macro
17536 case DW_MACRO_GNU_define
:
17537 case DW_MACRO_GNU_undef
:
17538 /* Only skip the data by MAC_PTR. */
17540 unsigned int bytes_read
;
17542 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17543 mac_ptr
+= bytes_read
;
17544 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17545 mac_ptr
+= bytes_read
;
17549 case DW_MACRO_GNU_start_file
:
17551 unsigned int bytes_read
;
17554 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17555 mac_ptr
+= bytes_read
;
17556 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17557 mac_ptr
+= bytes_read
;
17559 current_file
= macro_start_file (file
, line
, current_file
,
17560 comp_dir
, lh
, objfile
);
17564 case DW_MACRO_GNU_end_file
:
17565 /* No data to skip by MAC_PTR. */
17568 case DW_MACRO_GNU_define_indirect
:
17569 case DW_MACRO_GNU_undef_indirect
:
17571 unsigned int bytes_read
;
17573 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17574 mac_ptr
+= bytes_read
;
17575 mac_ptr
+= offset_size
;
17579 case DW_MACRO_GNU_transparent_include
:
17580 /* Note that, according to the spec, a transparent include
17581 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17582 skip this opcode. */
17583 mac_ptr
+= offset_size
;
17586 case DW_MACINFO_vendor_ext
:
17587 /* Only skip the data by MAC_PTR. */
17588 if (!section_is_gnu
)
17590 unsigned int bytes_read
;
17592 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17593 mac_ptr
+= bytes_read
;
17594 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17595 mac_ptr
+= bytes_read
;
17600 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17601 mac_ptr
, mac_end
, abfd
, offset_size
,
17603 if (mac_ptr
== NULL
)
17607 } while (macinfo_type
!= 0 && current_file
== NULL
);
17609 /* Second pass: Process all entries.
17611 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17612 command-line macro definitions/undefinitions. This flag is unset when we
17613 reach the first DW_MACINFO_start_file entry. */
17615 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17616 NULL
, xcalloc
, xfree
);
17617 cleanup
= make_cleanup_htab_delete (include_hash
);
17618 mac_ptr
= section
->buffer
+ offset
;
17619 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17621 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17622 current_file
, lh
, comp_dir
, section
, section_is_gnu
,
17623 offset_size
, objfile
, include_hash
);
17624 do_cleanups (cleanup
);
17627 /* Check if the attribute's form is a DW_FORM_block*
17628 if so return true else false. */
17631 attr_form_is_block (struct attribute
*attr
)
17633 return (attr
== NULL
? 0 :
17634 attr
->form
== DW_FORM_block1
17635 || attr
->form
== DW_FORM_block2
17636 || attr
->form
== DW_FORM_block4
17637 || attr
->form
== DW_FORM_block
17638 || attr
->form
== DW_FORM_exprloc
);
17641 /* Return non-zero if ATTR's value is a section offset --- classes
17642 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17643 You may use DW_UNSND (attr) to retrieve such offsets.
17645 Section 7.5.4, "Attribute Encodings", explains that no attribute
17646 may have a value that belongs to more than one of these classes; it
17647 would be ambiguous if we did, because we use the same forms for all
17651 attr_form_is_section_offset (struct attribute
*attr
)
17653 return (attr
->form
== DW_FORM_data4
17654 || attr
->form
== DW_FORM_data8
17655 || attr
->form
== DW_FORM_sec_offset
);
17658 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17659 zero otherwise. When this function returns true, you can apply
17660 dwarf2_get_attr_constant_value to it.
17662 However, note that for some attributes you must check
17663 attr_form_is_section_offset before using this test. DW_FORM_data4
17664 and DW_FORM_data8 are members of both the constant class, and of
17665 the classes that contain offsets into other debug sections
17666 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17667 that, if an attribute's can be either a constant or one of the
17668 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17669 taken as section offsets, not constants. */
17672 attr_form_is_constant (struct attribute
*attr
)
17674 switch (attr
->form
)
17676 case DW_FORM_sdata
:
17677 case DW_FORM_udata
:
17678 case DW_FORM_data1
:
17679 case DW_FORM_data2
:
17680 case DW_FORM_data4
:
17681 case DW_FORM_data8
:
17688 /* Return the .debug_loc section to use for CU.
17689 For DWO files use .debug_loc.dwo. */
17691 static struct dwarf2_section_info
*
17692 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17695 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17696 return &dwarf2_per_objfile
->loc
;
17699 /* A helper function that fills in a dwarf2_loclist_baton. */
17702 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17703 struct dwarf2_loclist_baton
*baton
,
17704 struct attribute
*attr
)
17706 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17708 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17710 baton
->per_cu
= cu
->per_cu
;
17711 gdb_assert (baton
->per_cu
);
17712 /* We don't know how long the location list is, but make sure we
17713 don't run off the edge of the section. */
17714 baton
->size
= section
->size
- DW_UNSND (attr
);
17715 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17716 baton
->base_address
= cu
->base_address
;
17717 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
17721 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17722 struct dwarf2_cu
*cu
)
17724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17725 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17727 if (attr_form_is_section_offset (attr
)
17728 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
17729 the section. If so, fall through to the complaint in the
17731 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
17733 struct dwarf2_loclist_baton
*baton
;
17735 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17736 sizeof (struct dwarf2_loclist_baton
));
17738 fill_in_loclist_baton (cu
, baton
, attr
);
17740 if (cu
->base_known
== 0)
17741 complaint (&symfile_complaints
,
17742 _("Location list used without "
17743 "specifying the CU base address."));
17745 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
17746 SYMBOL_LOCATION_BATON (sym
) = baton
;
17750 struct dwarf2_locexpr_baton
*baton
;
17752 baton
= obstack_alloc (&objfile
->objfile_obstack
,
17753 sizeof (struct dwarf2_locexpr_baton
));
17754 baton
->per_cu
= cu
->per_cu
;
17755 gdb_assert (baton
->per_cu
);
17757 if (attr_form_is_block (attr
))
17759 /* Note that we're just copying the block's data pointer
17760 here, not the actual data. We're still pointing into the
17761 info_buffer for SYM's objfile; right now we never release
17762 that buffer, but when we do clean up properly this may
17764 baton
->size
= DW_BLOCK (attr
)->size
;
17765 baton
->data
= DW_BLOCK (attr
)->data
;
17769 dwarf2_invalid_attrib_class_complaint ("location description",
17770 SYMBOL_NATURAL_NAME (sym
));
17774 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
17775 SYMBOL_LOCATION_BATON (sym
) = baton
;
17779 /* Return the OBJFILE associated with the compilation unit CU. If CU
17780 came from a separate debuginfo file, then the master objfile is
17784 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
17786 struct objfile
*objfile
= per_cu
->objfile
;
17788 /* Return the master objfile, so that we can report and look up the
17789 correct file containing this variable. */
17790 if (objfile
->separate_debug_objfile_backlink
)
17791 objfile
= objfile
->separate_debug_objfile_backlink
;
17796 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
17797 (CU_HEADERP is unused in such case) or prepare a temporary copy at
17798 CU_HEADERP first. */
17800 static const struct comp_unit_head
*
17801 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
17802 struct dwarf2_per_cu_data
*per_cu
)
17804 gdb_byte
*info_ptr
;
17807 return &per_cu
->cu
->header
;
17809 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
17811 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
17812 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
17817 /* Return the address size given in the compilation unit header for CU. */
17820 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17822 struct comp_unit_head cu_header_local
;
17823 const struct comp_unit_head
*cu_headerp
;
17825 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17827 return cu_headerp
->addr_size
;
17830 /* Return the offset size given in the compilation unit header for CU. */
17833 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
17835 struct comp_unit_head cu_header_local
;
17836 const struct comp_unit_head
*cu_headerp
;
17838 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17840 return cu_headerp
->offset_size
;
17843 /* See its dwarf2loc.h declaration. */
17846 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
17848 struct comp_unit_head cu_header_local
;
17849 const struct comp_unit_head
*cu_headerp
;
17851 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
17853 if (cu_headerp
->version
== 2)
17854 return cu_headerp
->addr_size
;
17856 return cu_headerp
->offset_size
;
17859 /* Return the text offset of the CU. The returned offset comes from
17860 this CU's objfile. If this objfile came from a separate debuginfo
17861 file, then the offset may be different from the corresponding
17862 offset in the parent objfile. */
17865 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
17867 struct objfile
*objfile
= per_cu
->objfile
;
17869 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
17872 /* Locate the .debug_info compilation unit from CU's objfile which contains
17873 the DIE at OFFSET. Raises an error on failure. */
17875 static struct dwarf2_per_cu_data
*
17876 dwarf2_find_containing_comp_unit (sect_offset offset
,
17877 struct objfile
*objfile
)
17879 struct dwarf2_per_cu_data
*this_cu
;
17883 high
= dwarf2_per_objfile
->n_comp_units
- 1;
17886 int mid
= low
+ (high
- low
) / 2;
17888 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
.sect_off
17889 >= offset
.sect_off
)
17894 gdb_assert (low
== high
);
17895 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
.sect_off
17899 error (_("Dwarf Error: could not find partial DIE containing "
17900 "offset 0x%lx [in module %s]"),
17901 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
17903 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
17904 <= offset
.sect_off
);
17905 return dwarf2_per_objfile
->all_comp_units
[low
-1];
17909 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
17910 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
17911 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
17912 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
17913 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
17918 /* Initialize dwarf2_cu CU, owned by PER_CU. */
17921 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
17923 memset (cu
, 0, sizeof (*cu
));
17925 cu
->per_cu
= per_cu
;
17926 cu
->objfile
= per_cu
->objfile
;
17927 obstack_init (&cu
->comp_unit_obstack
);
17930 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
17933 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
17934 enum language pretend_language
)
17936 struct attribute
*attr
;
17938 /* Set the language we're debugging. */
17939 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
17941 set_cu_language (DW_UNSND (attr
), cu
);
17944 cu
->language
= pretend_language
;
17945 cu
->language_defn
= language_def (cu
->language
);
17948 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
17950 cu
->producer
= DW_STRING (attr
);
17953 /* Release one cached compilation unit, CU. We unlink it from the tree
17954 of compilation units, but we don't remove it from the read_in_chain;
17955 the caller is responsible for that.
17956 NOTE: DATA is a void * because this function is also used as a
17957 cleanup routine. */
17960 free_heap_comp_unit (void *data
)
17962 struct dwarf2_cu
*cu
= data
;
17964 gdb_assert (cu
->per_cu
!= NULL
);
17965 cu
->per_cu
->cu
= NULL
;
17968 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17973 /* This cleanup function is passed the address of a dwarf2_cu on the stack
17974 when we're finished with it. We can't free the pointer itself, but be
17975 sure to unlink it from the cache. Also release any associated storage. */
17978 free_stack_comp_unit (void *data
)
17980 struct dwarf2_cu
*cu
= data
;
17982 gdb_assert (cu
->per_cu
!= NULL
);
17983 cu
->per_cu
->cu
= NULL
;
17986 obstack_free (&cu
->comp_unit_obstack
, NULL
);
17987 cu
->partial_dies
= NULL
;
17990 /* Free all cached compilation units. */
17993 free_cached_comp_units (void *data
)
17995 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
17997 per_cu
= dwarf2_per_objfile
->read_in_chain
;
17998 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
17999 while (per_cu
!= NULL
)
18001 struct dwarf2_per_cu_data
*next_cu
;
18003 next_cu
= per_cu
->cu
->read_in_chain
;
18005 free_heap_comp_unit (per_cu
->cu
);
18006 *last_chain
= next_cu
;
18012 /* Increase the age counter on each cached compilation unit, and free
18013 any that are too old. */
18016 age_cached_comp_units (void)
18018 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18020 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
18021 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18022 while (per_cu
!= NULL
)
18024 per_cu
->cu
->last_used
++;
18025 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
18026 dwarf2_mark (per_cu
->cu
);
18027 per_cu
= per_cu
->cu
->read_in_chain
;
18030 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18031 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18032 while (per_cu
!= NULL
)
18034 struct dwarf2_per_cu_data
*next_cu
;
18036 next_cu
= per_cu
->cu
->read_in_chain
;
18038 if (!per_cu
->cu
->mark
)
18040 free_heap_comp_unit (per_cu
->cu
);
18041 *last_chain
= next_cu
;
18044 last_chain
= &per_cu
->cu
->read_in_chain
;
18050 /* Remove a single compilation unit from the cache. */
18053 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
18055 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18057 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18058 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18059 while (per_cu
!= NULL
)
18061 struct dwarf2_per_cu_data
*next_cu
;
18063 next_cu
= per_cu
->cu
->read_in_chain
;
18065 if (per_cu
== target_per_cu
)
18067 free_heap_comp_unit (per_cu
->cu
);
18069 *last_chain
= next_cu
;
18073 last_chain
= &per_cu
->cu
->read_in_chain
;
18079 /* Release all extra memory associated with OBJFILE. */
18082 dwarf2_free_objfile (struct objfile
*objfile
)
18084 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18086 if (dwarf2_per_objfile
== NULL
)
18089 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
18090 free_cached_comp_units (NULL
);
18092 if (dwarf2_per_objfile
->quick_file_names_table
)
18093 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
18095 /* Everything else should be on the objfile obstack. */
18098 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
18099 We store these in a hash table separate from the DIEs, and preserve them
18100 when the DIEs are flushed out of cache.
18102 The CU "per_cu" pointer is needed because offset alone is not enough to
18103 uniquely identify the type. A file may have multiple .debug_types sections,
18104 or the type may come from a DWO file. We have to use something in
18105 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
18106 routine, get_die_type_at_offset, from outside this file, and thus won't
18107 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
18110 struct dwarf2_per_cu_offset_and_type
18112 const struct dwarf2_per_cu_data
*per_cu
;
18113 sect_offset offset
;
18117 /* Hash function for a dwarf2_per_cu_offset_and_type. */
18120 per_cu_offset_and_type_hash (const void *item
)
18122 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
18124 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
18127 /* Equality function for a dwarf2_per_cu_offset_and_type. */
18130 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
18132 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
18133 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
18135 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
18136 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18139 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18140 table if necessary. For convenience, return TYPE.
18142 The DIEs reading must have careful ordering to:
18143 * Not cause infite loops trying to read in DIEs as a prerequisite for
18144 reading current DIE.
18145 * Not trying to dereference contents of still incompletely read in types
18146 while reading in other DIEs.
18147 * Enable referencing still incompletely read in types just by a pointer to
18148 the type without accessing its fields.
18150 Therefore caller should follow these rules:
18151 * Try to fetch any prerequisite types we may need to build this DIE type
18152 before building the type and calling set_die_type.
18153 * After building type call set_die_type for current DIE as soon as
18154 possible before fetching more types to complete the current type.
18155 * Make the type as complete as possible before fetching more types. */
18157 static struct type
*
18158 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18160 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18161 struct objfile
*objfile
= cu
->objfile
;
18163 /* For Ada types, make sure that the gnat-specific data is always
18164 initialized (if not already set). There are a few types where
18165 we should not be doing so, because the type-specific area is
18166 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18167 where the type-specific area is used to store the floatformat).
18168 But this is not a problem, because the gnat-specific information
18169 is actually not needed for these types. */
18170 if (need_gnat_info (cu
)
18171 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18172 && TYPE_CODE (type
) != TYPE_CODE_FLT
18173 && !HAVE_GNAT_AUX_INFO (type
))
18174 INIT_GNAT_SPECIFIC (type
);
18176 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18178 dwarf2_per_objfile
->die_type_hash
=
18179 htab_create_alloc_ex (127,
18180 per_cu_offset_and_type_hash
,
18181 per_cu_offset_and_type_eq
,
18183 &objfile
->objfile_obstack
,
18184 hashtab_obstack_allocate
,
18185 dummy_obstack_deallocate
);
18188 ofs
.per_cu
= cu
->per_cu
;
18189 ofs
.offset
= die
->offset
;
18191 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18192 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18194 complaint (&symfile_complaints
,
18195 _("A problem internal to GDB: DIE 0x%x has type already set"),
18196 die
->offset
.sect_off
);
18197 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18202 /* Look up the type for the die at OFFSET in the appropriate type_hash
18203 table, or return NULL if the die does not have a saved type. */
18205 static struct type
*
18206 get_die_type_at_offset (sect_offset offset
,
18207 struct dwarf2_per_cu_data
*per_cu
)
18209 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18211 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18214 ofs
.per_cu
= per_cu
;
18215 ofs
.offset
= offset
;
18216 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18223 /* Look up the type for DIE in the appropriate type_hash table,
18224 or return NULL if DIE does not have a saved type. */
18226 static struct type
*
18227 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18229 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18232 /* Add a dependence relationship from CU to REF_PER_CU. */
18235 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18236 struct dwarf2_per_cu_data
*ref_per_cu
)
18240 if (cu
->dependencies
== NULL
)
18242 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18243 NULL
, &cu
->comp_unit_obstack
,
18244 hashtab_obstack_allocate
,
18245 dummy_obstack_deallocate
);
18247 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18249 *slot
= ref_per_cu
;
18252 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18253 Set the mark field in every compilation unit in the
18254 cache that we must keep because we are keeping CU. */
18257 dwarf2_mark_helper (void **slot
, void *data
)
18259 struct dwarf2_per_cu_data
*per_cu
;
18261 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18263 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18264 reading of the chain. As such dependencies remain valid it is not much
18265 useful to track and undo them during QUIT cleanups. */
18266 if (per_cu
->cu
== NULL
)
18269 if (per_cu
->cu
->mark
)
18271 per_cu
->cu
->mark
= 1;
18273 if (per_cu
->cu
->dependencies
!= NULL
)
18274 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18279 /* Set the mark field in CU and in every other compilation unit in the
18280 cache that we must keep because we are keeping CU. */
18283 dwarf2_mark (struct dwarf2_cu
*cu
)
18288 if (cu
->dependencies
!= NULL
)
18289 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18293 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18297 per_cu
->cu
->mark
= 0;
18298 per_cu
= per_cu
->cu
->read_in_chain
;
18302 /* Trivial hash function for partial_die_info: the hash value of a DIE
18303 is its offset in .debug_info for this objfile. */
18306 partial_die_hash (const void *item
)
18308 const struct partial_die_info
*part_die
= item
;
18310 return part_die
->offset
.sect_off
;
18313 /* Trivial comparison function for partial_die_info structures: two DIEs
18314 are equal if they have the same offset. */
18317 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18319 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18320 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18322 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18325 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18326 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18329 set_dwarf2_cmd (char *args
, int from_tty
)
18331 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18335 show_dwarf2_cmd (char *args
, int from_tty
)
18337 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18340 /* If section described by INFO was mmapped, munmap it now. */
18343 munmap_section_buffer (struct dwarf2_section_info
*info
)
18345 if (info
->map_addr
!= NULL
)
18350 res
= munmap (info
->map_addr
, info
->map_len
);
18351 gdb_assert (res
== 0);
18353 /* Without HAVE_MMAP, we should never be here to begin with. */
18354 gdb_assert_not_reached ("no mmap support");
18359 /* munmap debug sections for OBJFILE, if necessary. */
18362 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18364 struct dwarf2_per_objfile
*data
= d
;
18366 struct dwarf2_section_info
*section
;
18368 /* This is sorted according to the order they're defined in to make it easier
18369 to keep in sync. */
18370 munmap_section_buffer (&data
->info
);
18371 munmap_section_buffer (&data
->abbrev
);
18372 munmap_section_buffer (&data
->line
);
18373 munmap_section_buffer (&data
->loc
);
18374 munmap_section_buffer (&data
->macinfo
);
18375 munmap_section_buffer (&data
->macro
);
18376 munmap_section_buffer (&data
->str
);
18377 munmap_section_buffer (&data
->ranges
);
18378 munmap_section_buffer (&data
->addr
);
18379 munmap_section_buffer (&data
->frame
);
18380 munmap_section_buffer (&data
->eh_frame
);
18381 munmap_section_buffer (&data
->gdb_index
);
18384 VEC_iterate (dwarf2_section_info_def
, data
->types
, ix
, section
);
18386 munmap_section_buffer (section
);
18388 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18389 VEC_free (dwarf2_per_cu_ptr
,
18390 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18392 VEC_free (dwarf2_section_info_def
, data
->types
);
18394 if (data
->dwo_files
)
18395 free_dwo_files (data
->dwo_files
, objfile
);
18399 /* The "save gdb-index" command. */
18401 /* The contents of the hash table we create when building the string
18403 struct strtab_entry
18405 offset_type offset
;
18409 /* Hash function for a strtab_entry.
18411 Function is used only during write_hash_table so no index format backward
18412 compatibility is needed. */
18415 hash_strtab_entry (const void *e
)
18417 const struct strtab_entry
*entry
= e
;
18418 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18421 /* Equality function for a strtab_entry. */
18424 eq_strtab_entry (const void *a
, const void *b
)
18426 const struct strtab_entry
*ea
= a
;
18427 const struct strtab_entry
*eb
= b
;
18428 return !strcmp (ea
->str
, eb
->str
);
18431 /* Create a strtab_entry hash table. */
18434 create_strtab (void)
18436 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18437 xfree
, xcalloc
, xfree
);
18440 /* Add a string to the constant pool. Return the string's offset in
18444 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18447 struct strtab_entry entry
;
18448 struct strtab_entry
*result
;
18451 slot
= htab_find_slot (table
, &entry
, INSERT
);
18456 result
= XNEW (struct strtab_entry
);
18457 result
->offset
= obstack_object_size (cpool
);
18459 obstack_grow_str0 (cpool
, str
);
18462 return result
->offset
;
18465 /* An entry in the symbol table. */
18466 struct symtab_index_entry
18468 /* The name of the symbol. */
18470 /* The offset of the name in the constant pool. */
18471 offset_type index_offset
;
18472 /* A sorted vector of the indices of all the CUs that hold an object
18474 VEC (offset_type
) *cu_indices
;
18477 /* The symbol table. This is a power-of-2-sized hash table. */
18478 struct mapped_symtab
18480 offset_type n_elements
;
18482 struct symtab_index_entry
**data
;
18485 /* Hash function for a symtab_index_entry. */
18488 hash_symtab_entry (const void *e
)
18490 const struct symtab_index_entry
*entry
= e
;
18491 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18492 sizeof (offset_type
) * VEC_length (offset_type
,
18493 entry
->cu_indices
),
18497 /* Equality function for a symtab_index_entry. */
18500 eq_symtab_entry (const void *a
, const void *b
)
18502 const struct symtab_index_entry
*ea
= a
;
18503 const struct symtab_index_entry
*eb
= b
;
18504 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18505 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18507 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18508 VEC_address (offset_type
, eb
->cu_indices
),
18509 sizeof (offset_type
) * len
);
18512 /* Destroy a symtab_index_entry. */
18515 delete_symtab_entry (void *p
)
18517 struct symtab_index_entry
*entry
= p
;
18518 VEC_free (offset_type
, entry
->cu_indices
);
18522 /* Create a hash table holding symtab_index_entry objects. */
18525 create_symbol_hash_table (void)
18527 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18528 delete_symtab_entry
, xcalloc
, xfree
);
18531 /* Create a new mapped symtab object. */
18533 static struct mapped_symtab
*
18534 create_mapped_symtab (void)
18536 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18537 symtab
->n_elements
= 0;
18538 symtab
->size
= 1024;
18539 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18543 /* Destroy a mapped_symtab. */
18546 cleanup_mapped_symtab (void *p
)
18548 struct mapped_symtab
*symtab
= p
;
18549 /* The contents of the array are freed when the other hash table is
18551 xfree (symtab
->data
);
18555 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18558 Function is used only during write_hash_table so no index format backward
18559 compatibility is needed. */
18561 static struct symtab_index_entry
**
18562 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18564 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18566 index
= hash
& (symtab
->size
- 1);
18567 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18571 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18572 return &symtab
->data
[index
];
18573 index
= (index
+ step
) & (symtab
->size
- 1);
18577 /* Expand SYMTAB's hash table. */
18580 hash_expand (struct mapped_symtab
*symtab
)
18582 offset_type old_size
= symtab
->size
;
18584 struct symtab_index_entry
**old_entries
= symtab
->data
;
18587 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18589 for (i
= 0; i
< old_size
; ++i
)
18591 if (old_entries
[i
])
18593 struct symtab_index_entry
**slot
= find_slot (symtab
,
18594 old_entries
[i
]->name
);
18595 *slot
= old_entries
[i
];
18599 xfree (old_entries
);
18602 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18603 CU_INDEX is the index of the CU in which the symbol appears.
18604 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18607 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18608 int is_static
, gdb_index_symbol_kind kind
,
18609 offset_type cu_index
)
18611 struct symtab_index_entry
**slot
;
18612 offset_type cu_index_and_attrs
;
18614 ++symtab
->n_elements
;
18615 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18616 hash_expand (symtab
);
18618 slot
= find_slot (symtab
, name
);
18621 *slot
= XNEW (struct symtab_index_entry
);
18622 (*slot
)->name
= name
;
18623 /* index_offset is set later. */
18624 (*slot
)->cu_indices
= NULL
;
18627 cu_index_and_attrs
= 0;
18628 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18629 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18630 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18632 /* We don't want to record an index value twice as we want to avoid the
18634 We process all global symbols and then all static symbols
18635 (which would allow us to avoid the duplication by only having to check
18636 the last entry pushed), but a symbol could have multiple kinds in one CU.
18637 To keep things simple we don't worry about the duplication here and
18638 sort and uniqufy the list after we've processed all symbols. */
18639 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18642 /* qsort helper routine for uniquify_cu_indices. */
18645 offset_type_compare (const void *ap
, const void *bp
)
18647 offset_type a
= *(offset_type
*) ap
;
18648 offset_type b
= *(offset_type
*) bp
;
18650 return (a
> b
) - (b
> a
);
18653 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18656 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18660 for (i
= 0; i
< symtab
->size
; ++i
)
18662 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18665 && entry
->cu_indices
!= NULL
)
18667 unsigned int next_to_insert
, next_to_check
;
18668 offset_type last_value
;
18670 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18671 VEC_length (offset_type
, entry
->cu_indices
),
18672 sizeof (offset_type
), offset_type_compare
);
18674 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18675 next_to_insert
= 1;
18676 for (next_to_check
= 1;
18677 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18680 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18683 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18685 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18690 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18695 /* Add a vector of indices to the constant pool. */
18698 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18699 struct symtab_index_entry
*entry
)
18703 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18706 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18707 offset_type val
= MAYBE_SWAP (len
);
18712 entry
->index_offset
= obstack_object_size (cpool
);
18714 obstack_grow (cpool
, &val
, sizeof (val
));
18716 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18719 val
= MAYBE_SWAP (iter
);
18720 obstack_grow (cpool
, &val
, sizeof (val
));
18725 struct symtab_index_entry
*old_entry
= *slot
;
18726 entry
->index_offset
= old_entry
->index_offset
;
18729 return entry
->index_offset
;
18732 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18733 constant pool entries going into the obstack CPOOL. */
18736 write_hash_table (struct mapped_symtab
*symtab
,
18737 struct obstack
*output
, struct obstack
*cpool
)
18740 htab_t symbol_hash_table
;
18743 symbol_hash_table
= create_symbol_hash_table ();
18744 str_table
= create_strtab ();
18746 /* We add all the index vectors to the constant pool first, to
18747 ensure alignment is ok. */
18748 for (i
= 0; i
< symtab
->size
; ++i
)
18750 if (symtab
->data
[i
])
18751 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18754 /* Now write out the hash table. */
18755 for (i
= 0; i
< symtab
->size
; ++i
)
18757 offset_type str_off
, vec_off
;
18759 if (symtab
->data
[i
])
18761 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
18762 vec_off
= symtab
->data
[i
]->index_offset
;
18766 /* While 0 is a valid constant pool index, it is not valid
18767 to have 0 for both offsets. */
18772 str_off
= MAYBE_SWAP (str_off
);
18773 vec_off
= MAYBE_SWAP (vec_off
);
18775 obstack_grow (output
, &str_off
, sizeof (str_off
));
18776 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
18779 htab_delete (str_table
);
18780 htab_delete (symbol_hash_table
);
18783 /* Struct to map psymtab to CU index in the index file. */
18784 struct psymtab_cu_index_map
18786 struct partial_symtab
*psymtab
;
18787 unsigned int cu_index
;
18791 hash_psymtab_cu_index (const void *item
)
18793 const struct psymtab_cu_index_map
*map
= item
;
18795 return htab_hash_pointer (map
->psymtab
);
18799 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
18801 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
18802 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
18804 return lhs
->psymtab
== rhs
->psymtab
;
18807 /* Helper struct for building the address table. */
18808 struct addrmap_index_data
18810 struct objfile
*objfile
;
18811 struct obstack
*addr_obstack
;
18812 htab_t cu_index_htab
;
18814 /* Non-zero if the previous_* fields are valid.
18815 We can't write an entry until we see the next entry (since it is only then
18816 that we know the end of the entry). */
18817 int previous_valid
;
18818 /* Index of the CU in the table of all CUs in the index file. */
18819 unsigned int previous_cu_index
;
18820 /* Start address of the CU. */
18821 CORE_ADDR previous_cu_start
;
18824 /* Write an address entry to OBSTACK. */
18827 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
18828 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
18830 offset_type cu_index_to_write
;
18832 CORE_ADDR baseaddr
;
18834 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18836 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
18837 obstack_grow (obstack
, addr
, 8);
18838 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
18839 obstack_grow (obstack
, addr
, 8);
18840 cu_index_to_write
= MAYBE_SWAP (cu_index
);
18841 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
18844 /* Worker function for traversing an addrmap to build the address table. */
18847 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
18849 struct addrmap_index_data
*data
= datap
;
18850 struct partial_symtab
*pst
= obj
;
18852 if (data
->previous_valid
)
18853 add_address_entry (data
->objfile
, data
->addr_obstack
,
18854 data
->previous_cu_start
, start_addr
,
18855 data
->previous_cu_index
);
18857 data
->previous_cu_start
= start_addr
;
18860 struct psymtab_cu_index_map find_map
, *map
;
18861 find_map
.psymtab
= pst
;
18862 map
= htab_find (data
->cu_index_htab
, &find_map
);
18863 gdb_assert (map
!= NULL
);
18864 data
->previous_cu_index
= map
->cu_index
;
18865 data
->previous_valid
= 1;
18868 data
->previous_valid
= 0;
18873 /* Write OBJFILE's address map to OBSTACK.
18874 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
18875 in the index file. */
18878 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
18879 htab_t cu_index_htab
)
18881 struct addrmap_index_data addrmap_index_data
;
18883 /* When writing the address table, we have to cope with the fact that
18884 the addrmap iterator only provides the start of a region; we have to
18885 wait until the next invocation to get the start of the next region. */
18887 addrmap_index_data
.objfile
= objfile
;
18888 addrmap_index_data
.addr_obstack
= obstack
;
18889 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
18890 addrmap_index_data
.previous_valid
= 0;
18892 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
18893 &addrmap_index_data
);
18895 /* It's highly unlikely the last entry (end address = 0xff...ff)
18896 is valid, but we should still handle it.
18897 The end address is recorded as the start of the next region, but that
18898 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
18900 if (addrmap_index_data
.previous_valid
)
18901 add_address_entry (objfile
, obstack
,
18902 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
18903 addrmap_index_data
.previous_cu_index
);
18906 /* Return the symbol kind of PSYM. */
18908 static gdb_index_symbol_kind
18909 symbol_kind (struct partial_symbol
*psym
)
18911 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
18912 enum address_class aclass
= PSYMBOL_CLASS (psym
);
18920 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
18922 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18924 case LOC_CONST_BYTES
:
18925 case LOC_OPTIMIZED_OUT
:
18927 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18929 /* Note: It's currently impossible to recognize psyms as enum values
18930 short of reading the type info. For now punt. */
18931 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
18933 /* There are other LOC_FOO values that one might want to classify
18934 as variables, but dwarf2read.c doesn't currently use them. */
18935 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18937 case STRUCT_DOMAIN
:
18938 return GDB_INDEX_SYMBOL_KIND_TYPE
;
18940 return GDB_INDEX_SYMBOL_KIND_OTHER
;
18944 /* Add a list of partial symbols to SYMTAB. */
18947 write_psymbols (struct mapped_symtab
*symtab
,
18949 struct partial_symbol
**psymp
,
18951 offset_type cu_index
,
18954 for (; count
-- > 0; ++psymp
)
18956 struct partial_symbol
*psym
= *psymp
;
18959 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
18960 error (_("Ada is not currently supported by the index"));
18962 /* Only add a given psymbol once. */
18963 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
18966 gdb_index_symbol_kind kind
= symbol_kind (psym
);
18969 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
18970 is_static
, kind
, cu_index
);
18975 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
18976 exception if there is an error. */
18979 write_obstack (FILE *file
, struct obstack
*obstack
)
18981 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
18983 != obstack_object_size (obstack
))
18984 error (_("couldn't data write to file"));
18987 /* Unlink a file if the argument is not NULL. */
18990 unlink_if_set (void *p
)
18992 char **filename
= p
;
18994 unlink (*filename
);
18997 /* A helper struct used when iterating over debug_types. */
18998 struct signatured_type_index_data
19000 struct objfile
*objfile
;
19001 struct mapped_symtab
*symtab
;
19002 struct obstack
*types_list
;
19007 /* A helper function that writes a single signatured_type to an
19011 write_one_signatured_type (void **slot
, void *d
)
19013 struct signatured_type_index_data
*info
= d
;
19014 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
19015 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
19016 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19019 write_psymbols (info
->symtab
,
19021 info
->objfile
->global_psymbols
.list
19022 + psymtab
->globals_offset
,
19023 psymtab
->n_global_syms
, info
->cu_index
,
19025 write_psymbols (info
->symtab
,
19027 info
->objfile
->static_psymbols
.list
19028 + psymtab
->statics_offset
,
19029 psymtab
->n_static_syms
, info
->cu_index
,
19032 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19033 entry
->per_cu
.offset
.sect_off
);
19034 obstack_grow (info
->types_list
, val
, 8);
19035 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19036 entry
->type_offset_in_tu
.cu_off
);
19037 obstack_grow (info
->types_list
, val
, 8);
19038 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
19039 obstack_grow (info
->types_list
, val
, 8);
19046 /* Recurse into all "included" dependencies and write their symbols as
19047 if they appeared in this psymtab. */
19050 recursively_write_psymbols (struct objfile
*objfile
,
19051 struct partial_symtab
*psymtab
,
19052 struct mapped_symtab
*symtab
,
19054 offset_type cu_index
)
19058 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
19059 if (psymtab
->dependencies
[i
]->user
!= NULL
)
19060 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
19061 symtab
, psyms_seen
, cu_index
);
19063 write_psymbols (symtab
,
19065 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
19066 psymtab
->n_global_syms
, cu_index
,
19068 write_psymbols (symtab
,
19070 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
19071 psymtab
->n_static_syms
, cu_index
,
19075 /* Create an index file for OBJFILE in the directory DIR. */
19078 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
19080 struct cleanup
*cleanup
;
19081 char *filename
, *cleanup_filename
;
19082 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
19083 struct obstack cu_list
, types_cu_list
;
19086 struct mapped_symtab
*symtab
;
19087 offset_type val
, size_of_contents
, total_len
;
19090 htab_t cu_index_htab
;
19091 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
19093 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
19096 if (dwarf2_per_objfile
->using_index
)
19097 error (_("Cannot use an index to create the index"));
19099 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
19100 error (_("Cannot make an index when the file has multiple .debug_types sections"));
19102 if (stat (objfile
->name
, &st
) < 0)
19103 perror_with_name (objfile
->name
);
19105 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
19106 INDEX_SUFFIX
, (char *) NULL
);
19107 cleanup
= make_cleanup (xfree
, filename
);
19109 out_file
= fopen (filename
, "wb");
19111 error (_("Can't open `%s' for writing"), filename
);
19113 cleanup_filename
= filename
;
19114 make_cleanup (unlink_if_set
, &cleanup_filename
);
19116 symtab
= create_mapped_symtab ();
19117 make_cleanup (cleanup_mapped_symtab
, symtab
);
19119 obstack_init (&addr_obstack
);
19120 make_cleanup_obstack_free (&addr_obstack
);
19122 obstack_init (&cu_list
);
19123 make_cleanup_obstack_free (&cu_list
);
19125 obstack_init (&types_cu_list
);
19126 make_cleanup_obstack_free (&types_cu_list
);
19128 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
19129 NULL
, xcalloc
, xfree
);
19130 make_cleanup_htab_delete (psyms_seen
);
19132 /* While we're scanning CU's create a table that maps a psymtab pointer
19133 (which is what addrmap records) to its index (which is what is recorded
19134 in the index file). This will later be needed to write the address
19136 cu_index_htab
= htab_create_alloc (100,
19137 hash_psymtab_cu_index
,
19138 eq_psymtab_cu_index
,
19139 NULL
, xcalloc
, xfree
);
19140 make_cleanup_htab_delete (cu_index_htab
);
19141 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
19142 xmalloc (sizeof (struct psymtab_cu_index_map
)
19143 * dwarf2_per_objfile
->n_comp_units
);
19144 make_cleanup (xfree
, psymtab_cu_index_map
);
19146 /* The CU list is already sorted, so we don't need to do additional
19147 work here. Also, the debug_types entries do not appear in
19148 all_comp_units, but only in their own hash table. */
19149 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
19151 struct dwarf2_per_cu_data
*per_cu
19152 = dwarf2_per_objfile
->all_comp_units
[i
];
19153 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19155 struct psymtab_cu_index_map
*map
;
19158 if (psymtab
->user
== NULL
)
19159 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
19161 map
= &psymtab_cu_index_map
[i
];
19162 map
->psymtab
= psymtab
;
19164 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
19165 gdb_assert (slot
!= NULL
);
19166 gdb_assert (*slot
== NULL
);
19169 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19170 per_cu
->offset
.sect_off
);
19171 obstack_grow (&cu_list
, val
, 8);
19172 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
19173 obstack_grow (&cu_list
, val
, 8);
19176 /* Dump the address map. */
19177 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19179 /* Write out the .debug_type entries, if any. */
19180 if (dwarf2_per_objfile
->signatured_types
)
19182 struct signatured_type_index_data sig_data
;
19184 sig_data
.objfile
= objfile
;
19185 sig_data
.symtab
= symtab
;
19186 sig_data
.types_list
= &types_cu_list
;
19187 sig_data
.psyms_seen
= psyms_seen
;
19188 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19189 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19190 write_one_signatured_type
, &sig_data
);
19193 /* Now that we've processed all symbols we can shrink their cu_indices
19195 uniquify_cu_indices (symtab
);
19197 obstack_init (&constant_pool
);
19198 make_cleanup_obstack_free (&constant_pool
);
19199 obstack_init (&symtab_obstack
);
19200 make_cleanup_obstack_free (&symtab_obstack
);
19201 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19203 obstack_init (&contents
);
19204 make_cleanup_obstack_free (&contents
);
19205 size_of_contents
= 6 * sizeof (offset_type
);
19206 total_len
= size_of_contents
;
19208 /* The version number. */
19209 val
= MAYBE_SWAP (7);
19210 obstack_grow (&contents
, &val
, sizeof (val
));
19212 /* The offset of the CU list from the start of the file. */
19213 val
= MAYBE_SWAP (total_len
);
19214 obstack_grow (&contents
, &val
, sizeof (val
));
19215 total_len
+= obstack_object_size (&cu_list
);
19217 /* The offset of the types CU list from the start of the file. */
19218 val
= MAYBE_SWAP (total_len
);
19219 obstack_grow (&contents
, &val
, sizeof (val
));
19220 total_len
+= obstack_object_size (&types_cu_list
);
19222 /* The offset of the address table from the start of the file. */
19223 val
= MAYBE_SWAP (total_len
);
19224 obstack_grow (&contents
, &val
, sizeof (val
));
19225 total_len
+= obstack_object_size (&addr_obstack
);
19227 /* The offset of the symbol table from the start of the file. */
19228 val
= MAYBE_SWAP (total_len
);
19229 obstack_grow (&contents
, &val
, sizeof (val
));
19230 total_len
+= obstack_object_size (&symtab_obstack
);
19232 /* The offset of the constant pool from the start of the file. */
19233 val
= MAYBE_SWAP (total_len
);
19234 obstack_grow (&contents
, &val
, sizeof (val
));
19235 total_len
+= obstack_object_size (&constant_pool
);
19237 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19239 write_obstack (out_file
, &contents
);
19240 write_obstack (out_file
, &cu_list
);
19241 write_obstack (out_file
, &types_cu_list
);
19242 write_obstack (out_file
, &addr_obstack
);
19243 write_obstack (out_file
, &symtab_obstack
);
19244 write_obstack (out_file
, &constant_pool
);
19248 /* We want to keep the file, so we set cleanup_filename to NULL
19249 here. See unlink_if_set. */
19250 cleanup_filename
= NULL
;
19252 do_cleanups (cleanup
);
19255 /* Implementation of the `save gdb-index' command.
19257 Note that the file format used by this command is documented in the
19258 GDB manual. Any changes here must be documented there. */
19261 save_gdb_index_command (char *arg
, int from_tty
)
19263 struct objfile
*objfile
;
19266 error (_("usage: save gdb-index DIRECTORY"));
19268 ALL_OBJFILES (objfile
)
19272 /* If the objfile does not correspond to an actual file, skip it. */
19273 if (stat (objfile
->name
, &st
) < 0)
19276 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19277 if (dwarf2_per_objfile
)
19279 volatile struct gdb_exception except
;
19281 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19283 write_psymtabs_to_index (objfile
, arg
);
19285 if (except
.reason
< 0)
19286 exception_fprintf (gdb_stderr
, except
,
19287 _("Error while writing index for `%s': "),
19295 int dwarf2_always_disassemble
;
19298 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19299 struct cmd_list_element
*c
, const char *value
)
19301 fprintf_filtered (file
,
19302 _("Whether to always disassemble "
19303 "DWARF expressions is %s.\n"),
19308 show_check_physname (struct ui_file
*file
, int from_tty
,
19309 struct cmd_list_element
*c
, const char *value
)
19311 fprintf_filtered (file
,
19312 _("Whether to check \"physname\" is %s.\n"),
19316 void _initialize_dwarf2_read (void);
19319 _initialize_dwarf2_read (void)
19321 struct cmd_list_element
*c
;
19323 dwarf2_objfile_data_key
19324 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19326 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19327 Set DWARF 2 specific variables.\n\
19328 Configure DWARF 2 variables such as the cache size"),
19329 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19330 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19332 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19333 Show DWARF 2 specific variables\n\
19334 Show DWARF 2 variables such as the cache size"),
19335 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19336 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19338 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19339 &dwarf2_max_cache_age
, _("\
19340 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19341 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19342 A higher limit means that cached compilation units will be stored\n\
19343 in memory longer, and more total memory will be used. Zero disables\n\
19344 caching, which can slow down startup."),
19346 show_dwarf2_max_cache_age
,
19347 &set_dwarf2_cmdlist
,
19348 &show_dwarf2_cmdlist
);
19350 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19351 &dwarf2_always_disassemble
, _("\
19352 Set whether `info address' always disassembles DWARF expressions."), _("\
19353 Show whether `info address' always disassembles DWARF expressions."), _("\
19354 When enabled, DWARF expressions are always printed in an assembly-like\n\
19355 syntax. When disabled, expressions will be printed in a more\n\
19356 conversational style, when possible."),
19358 show_dwarf2_always_disassemble
,
19359 &set_dwarf2_cmdlist
,
19360 &show_dwarf2_cmdlist
);
19362 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19363 Set debugging of the dwarf2 reader."), _("\
19364 Show debugging of the dwarf2 reader."), _("\
19365 When enabled, debugging messages are printed during dwarf2 reading\n\
19366 and symtab expansion."),
19369 &setdebuglist
, &showdebuglist
);
19371 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19372 Set debugging of the dwarf2 DIE reader."), _("\
19373 Show debugging of the dwarf2 DIE reader."), _("\
19374 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19375 The value is the maximum depth to print."),
19378 &setdebuglist
, &showdebuglist
);
19380 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19381 Set cross-checking of \"physname\" code against demangler."), _("\
19382 Show cross-checking of \"physname\" code against demangler."), _("\
19383 When enabled, GDB's internal \"physname\" code is checked against\n\
19385 NULL
, show_check_physname
,
19386 &setdebuglist
, &showdebuglist
);
19388 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19390 Save a gdb-index file.\n\
19391 Usage: save gdb-index DIRECTORY"),
19393 set_cmd_completer (c
, filename_completer
);