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>
74 typedef struct symbol
*symbolp
;
77 /* When non-zero, print basic high level tracing messages.
78 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
79 static int dwarf2_read_debug
= 0;
81 /* When non-zero, dump DIEs after they are read in. */
82 static int dwarf2_die_debug
= 0;
84 /* When non-zero, cross-check physname against demangler. */
85 static int check_physname
= 0;
87 /* When non-zero, do not reject deprecated .gdb_index sections. */
88 int use_deprecated_index_sections
= 0;
90 /* When set, the file that we're processing is known to have debugging
91 info for C++ namespaces. GCC 3.3.x did not produce this information,
92 but later versions do. */
94 static int processing_has_namespace_info
;
96 static const struct objfile_data
*dwarf2_objfile_data_key
;
98 struct dwarf2_section_info
103 /* True if we have tried to read this section. */
107 typedef struct dwarf2_section_info dwarf2_section_info_def
;
108 DEF_VEC_O (dwarf2_section_info_def
);
110 /* All offsets in the index are of this type. It must be
111 architecture-independent. */
112 typedef uint32_t offset_type
;
114 DEF_VEC_I (offset_type
);
116 /* Ensure only legit values are used. */
117 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
119 gdb_assert ((unsigned int) (value) <= 1); \
120 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
123 /* Ensure only legit values are used. */
124 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
126 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
127 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
128 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
131 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
132 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
134 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
135 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
138 /* A description of the mapped index. The file format is described in
139 a comment by the code that writes the index. */
142 /* Index data format version. */
145 /* The total length of the buffer. */
148 /* A pointer to the address table data. */
149 const gdb_byte
*address_table
;
151 /* Size of the address table data in bytes. */
152 offset_type address_table_size
;
154 /* The symbol table, implemented as a hash table. */
155 const offset_type
*symbol_table
;
157 /* Size in slots, each slot is 2 offset_types. */
158 offset_type symbol_table_slots
;
160 /* A pointer to the constant pool. */
161 const char *constant_pool
;
164 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
165 DEF_VEC_P (dwarf2_per_cu_ptr
);
167 /* Collection of data recorded per objfile.
168 This hangs off of dwarf2_objfile_data_key. */
170 struct dwarf2_per_objfile
172 struct dwarf2_section_info info
;
173 struct dwarf2_section_info abbrev
;
174 struct dwarf2_section_info line
;
175 struct dwarf2_section_info loc
;
176 struct dwarf2_section_info macinfo
;
177 struct dwarf2_section_info macro
;
178 struct dwarf2_section_info str
;
179 struct dwarf2_section_info ranges
;
180 struct dwarf2_section_info addr
;
181 struct dwarf2_section_info frame
;
182 struct dwarf2_section_info eh_frame
;
183 struct dwarf2_section_info gdb_index
;
185 VEC (dwarf2_section_info_def
) *types
;
188 struct objfile
*objfile
;
190 /* Table of all the compilation units. This is used to locate
191 the target compilation unit of a particular reference. */
192 struct dwarf2_per_cu_data
**all_comp_units
;
194 /* The number of compilation units in ALL_COMP_UNITS. */
197 /* The number of .debug_types-related CUs. */
200 /* The .debug_types-related CUs (TUs). */
201 struct signatured_type
**all_type_units
;
203 /* The number of entries in all_type_unit_groups. */
204 int n_type_unit_groups
;
206 /* Table of type unit groups.
207 This exists to make it easy to iterate over all CUs and TU groups. */
208 struct type_unit_group
**all_type_unit_groups
;
210 /* Table of struct type_unit_group objects.
211 The hash key is the DW_AT_stmt_list value. */
212 htab_t type_unit_groups
;
214 /* A table mapping .debug_types signatures to its signatured_type entry.
215 This is NULL if the .debug_types section hasn't been read in yet. */
216 htab_t signatured_types
;
218 /* Type unit statistics, to see how well the scaling improvements
222 int nr_uniq_abbrev_tables
;
224 int nr_symtab_sharers
;
225 int nr_stmt_less_type_units
;
228 /* A chain of compilation units that are currently read in, so that
229 they can be freed later. */
230 struct dwarf2_per_cu_data
*read_in_chain
;
232 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
233 This is NULL if the table hasn't been allocated yet. */
236 /* The shared '.dwz' file, if one exists. This is used when the
237 original data was compressed using 'dwz -m'. */
238 struct dwz_file
*dwz_file
;
240 /* A flag indicating wether this objfile has a section loaded at a
242 int has_section_at_zero
;
244 /* True if we are using the mapped index,
245 or we are faking it for OBJF_READNOW's sake. */
246 unsigned char using_index
;
248 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
249 struct mapped_index
*index_table
;
251 /* When using index_table, this keeps track of all quick_file_names entries.
252 TUs can share line table entries with CUs or other TUs, and there can be
253 a lot more TUs than unique line tables, so we maintain a separate table
254 of all line table entries to support the sharing. */
255 htab_t quick_file_names_table
;
257 /* Set during partial symbol reading, to prevent queueing of full
259 int reading_partial_symbols
;
261 /* Table mapping type DIEs to their struct type *.
262 This is NULL if not allocated yet.
263 The mapping is done via (CU/TU signature + DIE offset) -> type. */
264 htab_t die_type_hash
;
266 /* The CUs we recently read. */
267 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
270 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
272 /* Default names of the debugging sections. */
274 /* Note that if the debugging section has been compressed, it might
275 have a name like .zdebug_info. */
277 static const struct dwarf2_debug_sections dwarf2_elf_names
=
279 { ".debug_info", ".zdebug_info" },
280 { ".debug_abbrev", ".zdebug_abbrev" },
281 { ".debug_line", ".zdebug_line" },
282 { ".debug_loc", ".zdebug_loc" },
283 { ".debug_macinfo", ".zdebug_macinfo" },
284 { ".debug_macro", ".zdebug_macro" },
285 { ".debug_str", ".zdebug_str" },
286 { ".debug_ranges", ".zdebug_ranges" },
287 { ".debug_types", ".zdebug_types" },
288 { ".debug_addr", ".zdebug_addr" },
289 { ".debug_frame", ".zdebug_frame" },
290 { ".eh_frame", NULL
},
291 { ".gdb_index", ".zgdb_index" },
295 /* List of DWO sections. */
297 static const struct dwo_section_names
299 struct dwarf2_section_names abbrev_dwo
;
300 struct dwarf2_section_names info_dwo
;
301 struct dwarf2_section_names line_dwo
;
302 struct dwarf2_section_names loc_dwo
;
303 struct dwarf2_section_names macinfo_dwo
;
304 struct dwarf2_section_names macro_dwo
;
305 struct dwarf2_section_names str_dwo
;
306 struct dwarf2_section_names str_offsets_dwo
;
307 struct dwarf2_section_names types_dwo
;
311 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
312 { ".debug_info.dwo", ".zdebug_info.dwo" },
313 { ".debug_line.dwo", ".zdebug_line.dwo" },
314 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
315 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
316 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
317 { ".debug_str.dwo", ".zdebug_str.dwo" },
318 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
319 { ".debug_types.dwo", ".zdebug_types.dwo" },
322 /* local data types */
324 /* The data in a compilation unit header, after target2host
325 translation, looks like this. */
326 struct comp_unit_head
330 unsigned char addr_size
;
331 unsigned char signed_addr_p
;
332 sect_offset abbrev_offset
;
334 /* Size of file offsets; either 4 or 8. */
335 unsigned int offset_size
;
337 /* Size of the length field; either 4 or 12. */
338 unsigned int initial_length_size
;
340 /* Offset to the first byte of this compilation unit header in the
341 .debug_info section, for resolving relative reference dies. */
344 /* Offset to first die in this cu from the start of the cu.
345 This will be the first byte following the compilation unit header. */
346 cu_offset first_die_offset
;
349 /* Type used for delaying computation of method physnames.
350 See comments for compute_delayed_physnames. */
351 struct delayed_method_info
353 /* The type to which the method is attached, i.e., its parent class. */
356 /* The index of the method in the type's function fieldlists. */
359 /* The index of the method in the fieldlist. */
362 /* The name of the DIE. */
365 /* The DIE associated with this method. */
366 struct die_info
*die
;
369 typedef struct delayed_method_info delayed_method_info
;
370 DEF_VEC_O (delayed_method_info
);
372 /* Internal state when decoding a particular compilation unit. */
375 /* The objfile containing this compilation unit. */
376 struct objfile
*objfile
;
378 /* The header of the compilation unit. */
379 struct comp_unit_head header
;
381 /* Base address of this compilation unit. */
382 CORE_ADDR base_address
;
384 /* Non-zero if base_address has been set. */
387 /* The language we are debugging. */
388 enum language language
;
389 const struct language_defn
*language_defn
;
391 const char *producer
;
393 /* The generic symbol table building routines have separate lists for
394 file scope symbols and all all other scopes (local scopes). So
395 we need to select the right one to pass to add_symbol_to_list().
396 We do it by keeping a pointer to the correct list in list_in_scope.
398 FIXME: The original dwarf code just treated the file scope as the
399 first local scope, and all other local scopes as nested local
400 scopes, and worked fine. Check to see if we really need to
401 distinguish these in buildsym.c. */
402 struct pending
**list_in_scope
;
404 /* The abbrev table for this CU.
405 Normally this points to the abbrev table in the objfile.
406 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
407 struct abbrev_table
*abbrev_table
;
409 /* Hash table holding all the loaded partial DIEs
410 with partial_die->offset.SECT_OFF as hash. */
413 /* Storage for things with the same lifetime as this read-in compilation
414 unit, including partial DIEs. */
415 struct obstack comp_unit_obstack
;
417 /* When multiple dwarf2_cu structures are living in memory, this field
418 chains them all together, so that they can be released efficiently.
419 We will probably also want a generation counter so that most-recently-used
420 compilation units are cached... */
421 struct dwarf2_per_cu_data
*read_in_chain
;
423 /* Backchain to our per_cu entry if the tree has been built. */
424 struct dwarf2_per_cu_data
*per_cu
;
426 /* How many compilation units ago was this CU last referenced? */
429 /* A hash table of DIE cu_offset for following references with
430 die_info->offset.sect_off as hash. */
433 /* Full DIEs if read in. */
434 struct die_info
*dies
;
436 /* A set of pointers to dwarf2_per_cu_data objects for compilation
437 units referenced by this one. Only set during full symbol processing;
438 partial symbol tables do not have dependencies. */
441 /* Header data from the line table, during full symbol processing. */
442 struct line_header
*line_header
;
444 /* A list of methods which need to have physnames computed
445 after all type information has been read. */
446 VEC (delayed_method_info
) *method_list
;
448 /* To be copied to symtab->call_site_htab. */
449 htab_t call_site_htab
;
451 /* Non-NULL if this CU came from a DWO file.
452 There is an invariant here that is important to remember:
453 Except for attributes copied from the top level DIE in the "main"
454 (or "stub") file in preparation for reading the DWO file
455 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
456 Either there isn't a DWO file (in which case this is NULL and the point
457 is moot), or there is and either we're not going to read it (in which
458 case this is NULL) or there is and we are reading it (in which case this
460 struct dwo_unit
*dwo_unit
;
462 /* The DW_AT_addr_base attribute if present, zero otherwise
463 (zero is a valid value though).
464 Note this value comes from the stub CU/TU's DIE. */
467 /* The DW_AT_ranges_base attribute if present, zero otherwise
468 (zero is a valid value though).
469 Note this value comes from the stub CU/TU's DIE.
470 Also note that the value is zero in the non-DWO case so this value can
471 be used without needing to know whether DWO files are in use or not. */
472 ULONGEST ranges_base
;
474 /* Mark used when releasing cached dies. */
475 unsigned int mark
: 1;
477 /* This CU references .debug_loc. See the symtab->locations_valid field.
478 This test is imperfect as there may exist optimized debug code not using
479 any location list and still facing inlining issues if handled as
480 unoptimized code. For a future better test see GCC PR other/32998. */
481 unsigned int has_loclist
: 1;
483 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
484 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
485 are valid. This information is cached because profiling CU expansion
486 showed excessive time spent in producer_is_gxx_lt_4_6. */
487 unsigned int checked_producer
: 1;
488 unsigned int producer_is_gxx_lt_4_6
: 1;
489 unsigned int producer_is_icc
: 1;
492 /* Persistent data held for a compilation unit, even when not
493 processing it. We put a pointer to this structure in the
494 read_symtab_private field of the psymtab. */
496 struct dwarf2_per_cu_data
498 /* The start offset and length of this compilation unit.
499 NOTE: Unlike comp_unit_head.length, this length includes
501 If the DIE refers to a DWO file, this is always of the original die,
506 /* Flag indicating this compilation unit will be read in before
507 any of the current compilation units are processed. */
508 unsigned int queued
: 1;
510 /* This flag will be set when reading partial DIEs if we need to load
511 absolutely all DIEs for this compilation unit, instead of just the ones
512 we think are interesting. It gets set if we look for a DIE in the
513 hash table and don't find it. */
514 unsigned int load_all_dies
: 1;
516 /* Non-zero if this CU is from .debug_types. */
517 unsigned int is_debug_types
: 1;
519 /* Non-zero if this CU is from the .dwz file. */
520 unsigned int is_dwz
: 1;
522 /* The section this CU/TU lives in.
523 If the DIE refers to a DWO file, this is always the original die,
525 struct dwarf2_section_info
*info_or_types_section
;
527 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
528 of the CU cache it gets reset to NULL again. */
529 struct dwarf2_cu
*cu
;
531 /* The corresponding objfile.
532 Normally we can get the objfile from dwarf2_per_objfile.
533 However we can enter this file with just a "per_cu" handle. */
534 struct objfile
*objfile
;
536 /* When using partial symbol tables, the 'psymtab' field is active.
537 Otherwise the 'quick' field is active. */
540 /* The partial symbol table associated with this compilation unit,
541 or NULL for unread partial units. */
542 struct partial_symtab
*psymtab
;
544 /* Data needed by the "quick" functions. */
545 struct dwarf2_per_cu_quick_data
*quick
;
550 /* The CUs we import using DW_TAG_imported_unit. This is filled in
551 while reading psymtabs, used to compute the psymtab dependencies,
552 and then cleared. Then it is filled in again while reading full
553 symbols, and only deleted when the objfile is destroyed. */
554 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
556 /* Type units are grouped by their DW_AT_stmt_list entry so that they
557 can share them. If this is a TU, this points to the containing
559 struct type_unit_group
*type_unit_group
;
563 /* Entry in the signatured_types hash table. */
565 struct signatured_type
567 /* The "per_cu" object of this type.
568 N.B.: This is the first member so that it's easy to convert pointers
570 struct dwarf2_per_cu_data per_cu
;
572 /* The type's signature. */
575 /* Offset in the TU of the type's DIE, as read from the TU header.
576 If the definition lives in a DWO file, this value is unusable. */
577 cu_offset type_offset_in_tu
;
579 /* Offset in the section of the type's DIE.
580 If the definition lives in a DWO file, this is the offset in the
581 .debug_types.dwo section.
582 The value is zero until the actual value is known.
583 Zero is otherwise not a valid section offset. */
584 sect_offset type_offset_in_section
;
587 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
588 This includes type_unit_group and quick_file_names. */
590 struct stmt_list_hash
592 /* The DWO unit this table is from or NULL if there is none. */
593 struct dwo_unit
*dwo_unit
;
595 /* Offset in .debug_line or .debug_line.dwo. */
596 sect_offset line_offset
;
599 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
600 an object of this type. */
602 struct type_unit_group
604 /* dwarf2read.c's main "handle" on the symtab.
605 To simplify things we create an artificial CU that "includes" all the
606 type units using this stmt_list so that the rest of the code still has
607 a "per_cu" handle on the symtab.
608 This PER_CU is recognized by having no section. */
609 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
610 struct dwarf2_per_cu_data per_cu
;
614 /* The TUs that share this DW_AT_stmt_list entry.
615 This is added to while parsing type units to build partial symtabs,
616 and is deleted afterwards and not used again. */
617 VEC (dwarf2_per_cu_ptr
) *tus
;
619 /* When reading the line table in "quick" functions, we need a real TU.
620 Any will do, we know they all share the same DW_AT_stmt_list entry.
621 For simplicity's sake, we pick the first one. */
622 struct dwarf2_per_cu_data
*first_tu
;
625 /* The primary symtab.
626 Type units in a group needn't all be defined in the same source file,
627 so we create an essentially anonymous symtab as the primary symtab. */
628 struct symtab
*primary_symtab
;
630 /* The data used to construct the hash key. */
631 struct stmt_list_hash hash
;
633 /* The number of symtabs from the line header.
634 The value here must match line_header.num_file_names. */
635 unsigned int num_symtabs
;
637 /* The symbol tables for this TU (obtained from the files listed in
639 WARNING: The order of entries here must match the order of entries
640 in the line header. After the first TU using this type_unit_group, the
641 line header for the subsequent TUs is recreated from this. This is done
642 because we need to use the same symtabs for each TU using the same
643 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
644 there's no guarantee the line header doesn't have duplicate entries. */
645 struct symtab
**symtabs
;
648 /* These sections are what may appear in a "dwo" file. */
652 struct dwarf2_section_info abbrev
;
653 struct dwarf2_section_info info
;
654 struct dwarf2_section_info line
;
655 struct dwarf2_section_info loc
;
656 struct dwarf2_section_info macinfo
;
657 struct dwarf2_section_info macro
;
658 struct dwarf2_section_info str
;
659 struct dwarf2_section_info str_offsets
;
660 VEC (dwarf2_section_info_def
) *types
;
663 /* Common bits of DWO CUs/TUs. */
667 /* Backlink to the containing struct dwo_file. */
668 struct dwo_file
*dwo_file
;
670 /* The "id" that distinguishes this CU/TU.
671 .debug_info calls this "dwo_id", .debug_types calls this "signature".
672 Since signatures came first, we stick with it for consistency. */
675 /* The section this CU/TU lives in, in the DWO file. */
676 struct dwarf2_section_info
*info_or_types_section
;
678 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
682 /* For types, offset in the type's DIE of the type defined by this TU. */
683 cu_offset type_offset_in_tu
;
686 /* Data for one DWO file. */
690 /* The DW_AT_GNU_dwo_name attribute.
691 We don't manage space for this, it's an attribute. */
692 const char *dwo_name
;
694 /* The bfd, when the file is open. Otherwise this is NULL. */
697 /* Section info for this file. */
698 struct dwo_sections sections
;
700 /* Table of CUs in the file.
701 Each element is a struct dwo_unit. */
704 /* Table of TUs in the file.
705 Each element is a struct dwo_unit. */
709 /* This represents a '.dwz' file. */
713 /* A dwz file can only contain a few sections. */
714 struct dwarf2_section_info abbrev
;
715 struct dwarf2_section_info info
;
716 struct dwarf2_section_info str
;
717 struct dwarf2_section_info line
;
718 struct dwarf2_section_info macro
;
719 struct dwarf2_section_info gdb_index
;
725 /* Struct used to pass misc. parameters to read_die_and_children, et
726 al. which are used for both .debug_info and .debug_types dies.
727 All parameters here are unchanging for the life of the call. This
728 struct exists to abstract away the constant parameters of die reading. */
730 struct die_reader_specs
732 /* die_section->asection->owner. */
735 /* The CU of the DIE we are parsing. */
736 struct dwarf2_cu
*cu
;
738 /* Non-NULL if reading a DWO file. */
739 struct dwo_file
*dwo_file
;
741 /* The section the die comes from.
742 This is either .debug_info or .debug_types, or the .dwo variants. */
743 struct dwarf2_section_info
*die_section
;
745 /* die_section->buffer. */
748 /* The end of the buffer. */
749 const gdb_byte
*buffer_end
;
752 /* Type of function passed to init_cutu_and_read_dies, et.al. */
753 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
755 struct die_info
*comp_unit_die
,
759 /* The line number information for a compilation unit (found in the
760 .debug_line section) begins with a "statement program header",
761 which contains the following information. */
764 unsigned int total_length
;
765 unsigned short version
;
766 unsigned int header_length
;
767 unsigned char minimum_instruction_length
;
768 unsigned char maximum_ops_per_instruction
;
769 unsigned char default_is_stmt
;
771 unsigned char line_range
;
772 unsigned char opcode_base
;
774 /* standard_opcode_lengths[i] is the number of operands for the
775 standard opcode whose value is i. This means that
776 standard_opcode_lengths[0] is unused, and the last meaningful
777 element is standard_opcode_lengths[opcode_base - 1]. */
778 unsigned char *standard_opcode_lengths
;
780 /* The include_directories table. NOTE! These strings are not
781 allocated with xmalloc; instead, they are pointers into
782 debug_line_buffer. If you try to free them, `free' will get
784 unsigned int num_include_dirs
, include_dirs_size
;
787 /* The file_names table. NOTE! These strings are not allocated
788 with xmalloc; instead, they are pointers into debug_line_buffer.
789 Don't try to free them directly. */
790 unsigned int num_file_names
, file_names_size
;
794 unsigned int dir_index
;
795 unsigned int mod_time
;
797 int included_p
; /* Non-zero if referenced by the Line Number Program. */
798 struct symtab
*symtab
; /* The associated symbol table, if any. */
801 /* The start and end of the statement program following this
802 header. These point into dwarf2_per_objfile->line_buffer. */
803 gdb_byte
*statement_program_start
, *statement_program_end
;
806 /* When we construct a partial symbol table entry we only
807 need this much information. */
808 struct partial_die_info
810 /* Offset of this DIE. */
813 /* DWARF-2 tag for this DIE. */
814 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
816 /* Assorted flags describing the data found in this DIE. */
817 unsigned int has_children
: 1;
818 unsigned int is_external
: 1;
819 unsigned int is_declaration
: 1;
820 unsigned int has_type
: 1;
821 unsigned int has_specification
: 1;
822 unsigned int has_pc_info
: 1;
823 unsigned int may_be_inlined
: 1;
825 /* Flag set if the SCOPE field of this structure has been
827 unsigned int scope_set
: 1;
829 /* Flag set if the DIE has a byte_size attribute. */
830 unsigned int has_byte_size
: 1;
832 /* Flag set if any of the DIE's children are template arguments. */
833 unsigned int has_template_arguments
: 1;
835 /* Flag set if fixup_partial_die has been called on this die. */
836 unsigned int fixup_called
: 1;
838 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
839 unsigned int is_dwz
: 1;
841 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
842 unsigned int spec_is_dwz
: 1;
844 /* The name of this DIE. Normally the value of DW_AT_name, but
845 sometimes a default name for unnamed DIEs. */
848 /* The linkage name, if present. */
849 const char *linkage_name
;
851 /* The scope to prepend to our children. This is generally
852 allocated on the comp_unit_obstack, so will disappear
853 when this compilation unit leaves the cache. */
856 /* Some data associated with the partial DIE. The tag determines
857 which field is live. */
860 /* The location description associated with this DIE, if any. */
861 struct dwarf_block
*locdesc
;
862 /* The offset of an import, for DW_TAG_imported_unit. */
866 /* If HAS_PC_INFO, the PC range associated with this DIE. */
870 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
871 DW_AT_sibling, if any. */
872 /* NOTE: This member isn't strictly necessary, read_partial_die could
873 return DW_AT_sibling values to its caller load_partial_dies. */
876 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
877 DW_AT_specification (or DW_AT_abstract_origin or
879 sect_offset spec_offset
;
881 /* Pointers to this DIE's parent, first child, and next sibling,
883 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
886 /* This data structure holds the information of an abbrev. */
889 unsigned int number
; /* number identifying abbrev */
890 enum dwarf_tag tag
; /* dwarf tag */
891 unsigned short has_children
; /* boolean */
892 unsigned short num_attrs
; /* number of attributes */
893 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
894 struct abbrev_info
*next
; /* next in chain */
899 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
900 ENUM_BITFIELD(dwarf_form
) form
: 16;
903 /* Size of abbrev_table.abbrev_hash_table. */
904 #define ABBREV_HASH_SIZE 121
906 /* Top level data structure to contain an abbreviation table. */
910 /* Where the abbrev table came from.
911 This is used as a sanity check when the table is used. */
914 /* Storage for the abbrev table. */
915 struct obstack abbrev_obstack
;
917 /* Hash table of abbrevs.
918 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
919 It could be statically allocated, but the previous code didn't so we
921 struct abbrev_info
**abbrevs
;
924 /* Attributes have a name and a value. */
927 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
928 ENUM_BITFIELD(dwarf_form
) form
: 15;
930 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
931 field should be in u.str (existing only for DW_STRING) but it is kept
932 here for better struct attribute alignment. */
933 unsigned int string_is_canonical
: 1;
938 struct dwarf_block
*blk
;
942 struct signatured_type
*signatured_type
;
947 /* This data structure holds a complete die structure. */
950 /* DWARF-2 tag for this DIE. */
951 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
953 /* Number of attributes */
954 unsigned char num_attrs
;
956 /* True if we're presently building the full type name for the
957 type derived from this DIE. */
958 unsigned char building_fullname
: 1;
963 /* Offset in .debug_info or .debug_types section. */
966 /* The dies in a compilation unit form an n-ary tree. PARENT
967 points to this die's parent; CHILD points to the first child of
968 this node; and all the children of a given node are chained
969 together via their SIBLING fields. */
970 struct die_info
*child
; /* Its first child, if any. */
971 struct die_info
*sibling
; /* Its next sibling, if any. */
972 struct die_info
*parent
; /* Its parent, if any. */
974 /* An array of attributes, with NUM_ATTRS elements. There may be
975 zero, but it's not common and zero-sized arrays are not
976 sufficiently portable C. */
977 struct attribute attrs
[1];
980 /* Get at parts of an attribute structure. */
982 #define DW_STRING(attr) ((attr)->u.str)
983 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
984 #define DW_UNSND(attr) ((attr)->u.unsnd)
985 #define DW_BLOCK(attr) ((attr)->u.blk)
986 #define DW_SND(attr) ((attr)->u.snd)
987 #define DW_ADDR(attr) ((attr)->u.addr)
988 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
990 /* Blocks are a bunch of untyped bytes. */
995 /* Valid only if SIZE is not zero. */
999 #ifndef ATTR_ALLOC_CHUNK
1000 #define ATTR_ALLOC_CHUNK 4
1003 /* Allocate fields for structs, unions and enums in this size. */
1004 #ifndef DW_FIELD_ALLOC_CHUNK
1005 #define DW_FIELD_ALLOC_CHUNK 4
1008 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1009 but this would require a corresponding change in unpack_field_as_long
1011 static int bits_per_byte
= 8;
1013 /* The routines that read and process dies for a C struct or C++ class
1014 pass lists of data member fields and lists of member function fields
1015 in an instance of a field_info structure, as defined below. */
1018 /* List of data member and baseclasses fields. */
1021 struct nextfield
*next
;
1026 *fields
, *baseclasses
;
1028 /* Number of fields (including baseclasses). */
1031 /* Number of baseclasses. */
1034 /* Set if the accesibility of one of the fields is not public. */
1035 int non_public_fields
;
1037 /* Member function fields array, entries are allocated in the order they
1038 are encountered in the object file. */
1041 struct nextfnfield
*next
;
1042 struct fn_field fnfield
;
1046 /* Member function fieldlist array, contains name of possibly overloaded
1047 member function, number of overloaded member functions and a pointer
1048 to the head of the member function field chain. */
1053 struct nextfnfield
*head
;
1057 /* Number of entries in the fnfieldlists array. */
1060 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1061 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1062 struct typedef_field_list
1064 struct typedef_field field
;
1065 struct typedef_field_list
*next
;
1067 *typedef_field_list
;
1068 unsigned typedef_field_list_count
;
1071 /* One item on the queue of compilation units to read in full symbols
1073 struct dwarf2_queue_item
1075 struct dwarf2_per_cu_data
*per_cu
;
1076 enum language pretend_language
;
1077 struct dwarf2_queue_item
*next
;
1080 /* The current queue. */
1081 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1083 /* Loaded secondary compilation units are kept in memory until they
1084 have not been referenced for the processing of this many
1085 compilation units. Set this to zero to disable caching. Cache
1086 sizes of up to at least twenty will improve startup time for
1087 typical inter-CU-reference binaries, at an obvious memory cost. */
1088 static int dwarf2_max_cache_age
= 5;
1090 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1091 struct cmd_list_element
*c
, const char *value
)
1093 fprintf_filtered (file
, _("The upper bound on the age of cached "
1094 "dwarf2 compilation units is %s.\n"),
1099 /* Various complaints about symbol reading that don't abort the process. */
1102 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1104 complaint (&symfile_complaints
,
1105 _("statement list doesn't fit in .debug_line section"));
1109 dwarf2_debug_line_missing_file_complaint (void)
1111 complaint (&symfile_complaints
,
1112 _(".debug_line section has line data without a file"));
1116 dwarf2_debug_line_missing_end_sequence_complaint (void)
1118 complaint (&symfile_complaints
,
1119 _(".debug_line section has line "
1120 "program sequence without an end"));
1124 dwarf2_complex_location_expr_complaint (void)
1126 complaint (&symfile_complaints
, _("location expression too complex"));
1130 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1133 complaint (&symfile_complaints
,
1134 _("const value length mismatch for '%s', got %d, expected %d"),
1139 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1141 complaint (&symfile_complaints
,
1142 _("debug info runs off end of %s section"
1144 section
->asection
->name
,
1145 bfd_get_filename (section
->asection
->owner
));
1149 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1151 complaint (&symfile_complaints
,
1152 _("macro debug info contains a "
1153 "malformed macro definition:\n`%s'"),
1158 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1160 complaint (&symfile_complaints
,
1161 _("invalid attribute class or form for '%s' in '%s'"),
1165 /* local function prototypes */
1167 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1169 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1172 static void dwarf2_find_base_address (struct die_info
*die
,
1173 struct dwarf2_cu
*cu
);
1175 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1177 static void scan_partial_symbols (struct partial_die_info
*,
1178 CORE_ADDR
*, CORE_ADDR
*,
1179 int, struct dwarf2_cu
*);
1181 static void add_partial_symbol (struct partial_die_info
*,
1182 struct dwarf2_cu
*);
1184 static void add_partial_namespace (struct partial_die_info
*pdi
,
1185 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1186 int need_pc
, struct dwarf2_cu
*cu
);
1188 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1189 CORE_ADDR
*highpc
, int need_pc
,
1190 struct dwarf2_cu
*cu
);
1192 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1193 struct dwarf2_cu
*cu
);
1195 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1196 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1197 int need_pc
, struct dwarf2_cu
*cu
);
1199 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1201 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1203 static struct abbrev_info
*abbrev_table_lookup_abbrev
1204 (const struct abbrev_table
*, unsigned int);
1206 static struct abbrev_table
*abbrev_table_read_table
1207 (struct dwarf2_section_info
*, sect_offset
);
1209 static void abbrev_table_free (struct abbrev_table
*);
1211 static void abbrev_table_free_cleanup (void *);
1213 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1214 struct dwarf2_section_info
*);
1216 static void dwarf2_free_abbrev_table (void *);
1218 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1220 static struct partial_die_info
*load_partial_dies
1221 (const struct die_reader_specs
*, gdb_byte
*, int);
1223 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1224 struct partial_die_info
*,
1225 struct abbrev_info
*,
1229 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1230 struct dwarf2_cu
*);
1232 static void fixup_partial_die (struct partial_die_info
*,
1233 struct dwarf2_cu
*);
1235 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1236 struct attribute
*, struct attr_abbrev
*,
1239 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
1241 static int read_1_signed_byte (bfd
*, gdb_byte
*);
1243 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
1245 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
1247 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
1249 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1252 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1254 static LONGEST read_checked_initial_length_and_offset
1255 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1256 unsigned int *, unsigned int *);
1258 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1261 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1263 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1266 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1268 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1270 static char *read_indirect_string (bfd
*, gdb_byte
*,
1271 const struct comp_unit_head
*,
1274 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1276 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1278 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1280 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1283 static char *read_str_index (const struct die_reader_specs
*reader
,
1284 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1286 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1288 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1289 struct dwarf2_cu
*);
1291 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1294 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1295 struct dwarf2_cu
*cu
);
1297 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1299 static struct die_info
*die_specification (struct die_info
*die
,
1300 struct dwarf2_cu
**);
1302 static void free_line_header (struct line_header
*lh
);
1304 static void add_file_name (struct line_header
*, char *, unsigned int,
1305 unsigned int, unsigned int);
1307 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1308 struct dwarf2_cu
*cu
);
1310 static void dwarf_decode_lines (struct line_header
*, const char *,
1311 struct dwarf2_cu
*, struct partial_symtab
*,
1314 static void dwarf2_start_subfile (char *, const char *, const char *);
1316 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1317 char *, char *, CORE_ADDR
);
1319 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1320 struct dwarf2_cu
*);
1322 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1323 struct dwarf2_cu
*, struct symbol
*);
1325 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1326 struct dwarf2_cu
*);
1328 static void dwarf2_const_value_attr (struct attribute
*attr
,
1331 struct obstack
*obstack
,
1332 struct dwarf2_cu
*cu
, LONGEST
*value
,
1334 struct dwarf2_locexpr_baton
**baton
);
1336 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1338 static int need_gnat_info (struct dwarf2_cu
*);
1340 static struct type
*die_descriptive_type (struct die_info
*,
1341 struct dwarf2_cu
*);
1343 static void set_descriptive_type (struct type
*, struct die_info
*,
1344 struct dwarf2_cu
*);
1346 static struct type
*die_containing_type (struct die_info
*,
1347 struct dwarf2_cu
*);
1349 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1350 struct dwarf2_cu
*);
1352 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1354 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1356 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1358 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1359 const char *suffix
, int physname
,
1360 struct dwarf2_cu
*cu
);
1362 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1364 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1366 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1368 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1370 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1372 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1373 struct dwarf2_cu
*, struct partial_symtab
*);
1375 static int dwarf2_get_pc_bounds (struct die_info
*,
1376 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1377 struct partial_symtab
*);
1379 static void get_scope_pc_bounds (struct die_info
*,
1380 CORE_ADDR
*, CORE_ADDR
*,
1381 struct dwarf2_cu
*);
1383 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1384 CORE_ADDR
, struct dwarf2_cu
*);
1386 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1387 struct dwarf2_cu
*);
1389 static void dwarf2_attach_fields_to_type (struct field_info
*,
1390 struct type
*, struct dwarf2_cu
*);
1392 static void dwarf2_add_member_fn (struct field_info
*,
1393 struct die_info
*, struct type
*,
1394 struct dwarf2_cu
*);
1396 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1398 struct dwarf2_cu
*);
1400 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1402 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1404 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1406 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1408 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1410 static struct type
*read_module_type (struct die_info
*die
,
1411 struct dwarf2_cu
*cu
);
1413 static const char *namespace_name (struct die_info
*die
,
1414 int *is_anonymous
, struct dwarf2_cu
*);
1416 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1418 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1420 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1421 struct dwarf2_cu
*);
1423 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1425 gdb_byte
**new_info_ptr
,
1426 struct die_info
*parent
);
1428 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1430 gdb_byte
**new_info_ptr
,
1431 struct die_info
*parent
);
1433 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1434 struct die_info
**, gdb_byte
*, int *, int);
1436 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1437 struct die_info
**, gdb_byte
*, int *);
1439 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1441 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1444 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1446 static const char *dwarf2_full_name (char *name
,
1447 struct die_info
*die
,
1448 struct dwarf2_cu
*cu
);
1450 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1451 struct dwarf2_cu
**);
1453 static const char *dwarf_tag_name (unsigned int);
1455 static const char *dwarf_attr_name (unsigned int);
1457 static const char *dwarf_form_name (unsigned int);
1459 static char *dwarf_bool_name (unsigned int);
1461 static const char *dwarf_type_encoding_name (unsigned int);
1463 static struct die_info
*sibling_die (struct die_info
*);
1465 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1467 static void dump_die_for_error (struct die_info
*);
1469 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1472 /*static*/ void dump_die (struct die_info
*, int max_level
);
1474 static void store_in_ref_table (struct die_info
*,
1475 struct dwarf2_cu
*);
1477 static int is_ref_attr (struct attribute
*);
1479 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1481 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1483 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1485 struct dwarf2_cu
**);
1487 static struct die_info
*follow_die_ref (struct die_info
*,
1489 struct dwarf2_cu
**);
1491 static struct die_info
*follow_die_sig (struct die_info
*,
1493 struct dwarf2_cu
**);
1495 static struct signatured_type
*lookup_signatured_type_at_offset
1496 (struct objfile
*objfile
,
1497 struct dwarf2_section_info
*section
, sect_offset offset
);
1499 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1501 static void read_signatured_type (struct signatured_type
*);
1503 static struct type_unit_group
*get_type_unit_group
1504 (struct dwarf2_cu
*, struct attribute
*);
1506 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1508 /* memory allocation interface */
1510 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1512 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1514 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1517 static int attr_form_is_block (struct attribute
*);
1519 static int attr_form_is_section_offset (struct attribute
*);
1521 static int attr_form_is_constant (struct attribute
*);
1523 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1524 struct dwarf2_loclist_baton
*baton
,
1525 struct attribute
*attr
);
1527 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1529 struct dwarf2_cu
*cu
);
1531 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1533 struct abbrev_info
*abbrev
);
1535 static void free_stack_comp_unit (void *);
1537 static hashval_t
partial_die_hash (const void *item
);
1539 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1541 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1542 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1544 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1545 struct dwarf2_per_cu_data
*per_cu
);
1547 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1548 struct die_info
*comp_unit_die
,
1549 enum language pretend_language
);
1551 static void free_heap_comp_unit (void *);
1553 static void free_cached_comp_units (void *);
1555 static void age_cached_comp_units (void);
1557 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1559 static struct type
*set_die_type (struct die_info
*, struct type
*,
1560 struct dwarf2_cu
*);
1562 static void create_all_comp_units (struct objfile
*);
1564 static int create_all_type_units (struct objfile
*);
1566 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1569 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1572 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1575 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1576 struct dwarf2_per_cu_data
*);
1578 static void dwarf2_mark (struct dwarf2_cu
*);
1580 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1582 static struct type
*get_die_type_at_offset (sect_offset
,
1583 struct dwarf2_per_cu_data
*per_cu
);
1585 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1587 static void dwarf2_release_queue (void *dummy
);
1589 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1590 enum language pretend_language
);
1592 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1593 struct dwarf2_per_cu_data
*per_cu
,
1594 enum language pretend_language
);
1596 static void process_queue (void);
1598 static void find_file_and_directory (struct die_info
*die
,
1599 struct dwarf2_cu
*cu
,
1600 char **name
, char **comp_dir
);
1602 static char *file_full_name (int file
, struct line_header
*lh
,
1603 const char *comp_dir
);
1605 static gdb_byte
*read_and_check_comp_unit_head
1606 (struct comp_unit_head
*header
,
1607 struct dwarf2_section_info
*section
,
1608 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1609 int is_debug_types_section
);
1611 static void init_cutu_and_read_dies
1612 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1613 int use_existing_cu
, int keep
,
1614 die_reader_func_ftype
*die_reader_func
, void *data
);
1616 static void init_cutu_and_read_dies_simple
1617 (struct dwarf2_per_cu_data
*this_cu
,
1618 die_reader_func_ftype
*die_reader_func
, void *data
);
1620 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1622 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1624 static struct dwo_unit
*lookup_dwo_comp_unit
1625 (struct dwarf2_per_cu_data
*, char *, const char *, ULONGEST
);
1627 static struct dwo_unit
*lookup_dwo_type_unit
1628 (struct signatured_type
*, char *, const char *);
1630 static void free_dwo_file_cleanup (void *);
1632 static void process_cu_includes (void);
1636 /* Convert VALUE between big- and little-endian. */
1638 byte_swap (offset_type value
)
1642 result
= (value
& 0xff) << 24;
1643 result
|= (value
& 0xff00) << 8;
1644 result
|= (value
& 0xff0000) >> 8;
1645 result
|= (value
& 0xff000000) >> 24;
1649 #define MAYBE_SWAP(V) byte_swap (V)
1652 #define MAYBE_SWAP(V) (V)
1653 #endif /* WORDS_BIGENDIAN */
1655 /* The suffix for an index file. */
1656 #define INDEX_SUFFIX ".gdb-index"
1658 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1659 struct dwarf2_cu
*cu
);
1661 /* Try to locate the sections we need for DWARF 2 debugging
1662 information and return true if we have enough to do something.
1663 NAMES points to the dwarf2 section names, or is NULL if the standard
1664 ELF names are used. */
1667 dwarf2_has_info (struct objfile
*objfile
,
1668 const struct dwarf2_debug_sections
*names
)
1670 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1671 if (!dwarf2_per_objfile
)
1673 /* Initialize per-objfile state. */
1674 struct dwarf2_per_objfile
*data
1675 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1677 memset (data
, 0, sizeof (*data
));
1678 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1679 dwarf2_per_objfile
= data
;
1681 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1683 dwarf2_per_objfile
->objfile
= objfile
;
1685 return (dwarf2_per_objfile
->info
.asection
!= NULL
1686 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1689 /* When loading sections, we look either for uncompressed section or for
1690 compressed section names. */
1693 section_is_p (const char *section_name
,
1694 const struct dwarf2_section_names
*names
)
1696 if (names
->normal
!= NULL
1697 && strcmp (section_name
, names
->normal
) == 0)
1699 if (names
->compressed
!= NULL
1700 && strcmp (section_name
, names
->compressed
) == 0)
1705 /* This function is mapped across the sections and remembers the
1706 offset and size of each of the debugging sections we are interested
1710 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1712 const struct dwarf2_debug_sections
*names
;
1715 names
= &dwarf2_elf_names
;
1717 names
= (const struct dwarf2_debug_sections
*) vnames
;
1719 if (section_is_p (sectp
->name
, &names
->info
))
1721 dwarf2_per_objfile
->info
.asection
= sectp
;
1722 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1724 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1726 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1727 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1729 else if (section_is_p (sectp
->name
, &names
->line
))
1731 dwarf2_per_objfile
->line
.asection
= sectp
;
1732 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1734 else if (section_is_p (sectp
->name
, &names
->loc
))
1736 dwarf2_per_objfile
->loc
.asection
= sectp
;
1737 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1739 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1741 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1742 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1744 else if (section_is_p (sectp
->name
, &names
->macro
))
1746 dwarf2_per_objfile
->macro
.asection
= sectp
;
1747 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1749 else if (section_is_p (sectp
->name
, &names
->str
))
1751 dwarf2_per_objfile
->str
.asection
= sectp
;
1752 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1754 else if (section_is_p (sectp
->name
, &names
->addr
))
1756 dwarf2_per_objfile
->addr
.asection
= sectp
;
1757 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1759 else if (section_is_p (sectp
->name
, &names
->frame
))
1761 dwarf2_per_objfile
->frame
.asection
= sectp
;
1762 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1764 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1766 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1768 if (aflag
& SEC_HAS_CONTENTS
)
1770 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1771 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1774 else if (section_is_p (sectp
->name
, &names
->ranges
))
1776 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1777 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1779 else if (section_is_p (sectp
->name
, &names
->types
))
1781 struct dwarf2_section_info type_section
;
1783 memset (&type_section
, 0, sizeof (type_section
));
1784 type_section
.asection
= sectp
;
1785 type_section
.size
= bfd_get_section_size (sectp
);
1787 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1790 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1792 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1793 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1796 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1797 && bfd_section_vma (abfd
, sectp
) == 0)
1798 dwarf2_per_objfile
->has_section_at_zero
= 1;
1801 /* A helper function that decides whether a section is empty,
1805 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1807 return info
->asection
== NULL
|| info
->size
== 0;
1810 /* Read the contents of the section INFO.
1811 OBJFILE is the main object file, but not necessarily the file where
1812 the section comes from. E.g., for DWO files INFO->asection->owner
1813 is the bfd of the DWO file.
1814 If the section is compressed, uncompress it before returning. */
1817 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1819 asection
*sectp
= info
->asection
;
1821 gdb_byte
*buf
, *retbuf
;
1822 unsigned char header
[4];
1826 info
->buffer
= NULL
;
1829 if (dwarf2_section_empty_p (info
))
1832 abfd
= sectp
->owner
;
1834 /* If the section has relocations, we must read it ourselves.
1835 Otherwise we attach it to the BFD. */
1836 if ((sectp
->flags
& SEC_RELOC
) == 0)
1838 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1840 /* We have to cast away const here for historical reasons.
1841 Fixing dwarf2read to be const-correct would be quite nice. */
1842 info
->buffer
= (gdb_byte
*) bytes
;
1846 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1849 /* When debugging .o files, we may need to apply relocations; see
1850 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1851 We never compress sections in .o files, so we only need to
1852 try this when the section is not compressed. */
1853 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1856 info
->buffer
= retbuf
;
1860 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1861 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1862 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1863 bfd_get_filename (abfd
));
1866 /* A helper function that returns the size of a section in a safe way.
1867 If you are positive that the section has been read before using the
1868 size, then it is safe to refer to the dwarf2_section_info object's
1869 "size" field directly. In other cases, you must call this
1870 function, because for compressed sections the size field is not set
1871 correctly until the section has been read. */
1873 static bfd_size_type
1874 dwarf2_section_size (struct objfile
*objfile
,
1875 struct dwarf2_section_info
*info
)
1878 dwarf2_read_section (objfile
, info
);
1882 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1886 dwarf2_get_section_info (struct objfile
*objfile
,
1887 enum dwarf2_section_enum sect
,
1888 asection
**sectp
, gdb_byte
**bufp
,
1889 bfd_size_type
*sizep
)
1891 struct dwarf2_per_objfile
*data
1892 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1893 struct dwarf2_section_info
*info
;
1895 /* We may see an objfile without any DWARF, in which case we just
1906 case DWARF2_DEBUG_FRAME
:
1907 info
= &data
->frame
;
1909 case DWARF2_EH_FRAME
:
1910 info
= &data
->eh_frame
;
1913 gdb_assert_not_reached ("unexpected section");
1916 dwarf2_read_section (objfile
, info
);
1918 *sectp
= info
->asection
;
1919 *bufp
= info
->buffer
;
1920 *sizep
= info
->size
;
1923 /* A helper function to find the sections for a .dwz file. */
1926 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
1928 struct dwz_file
*dwz_file
= arg
;
1930 /* Note that we only support the standard ELF names, because .dwz
1931 is ELF-only (at the time of writing). */
1932 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
1934 dwz_file
->abbrev
.asection
= sectp
;
1935 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
1937 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
1939 dwz_file
->info
.asection
= sectp
;
1940 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
1942 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
1944 dwz_file
->str
.asection
= sectp
;
1945 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
1947 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
1949 dwz_file
->line
.asection
= sectp
;
1950 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
1952 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
1954 dwz_file
->macro
.asection
= sectp
;
1955 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
1957 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
1959 dwz_file
->gdb_index
.asection
= sectp
;
1960 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
1964 /* Open the separate '.dwz' debug file, if needed. Error if the file
1967 static struct dwz_file
*
1968 dwarf2_get_dwz_file (void)
1970 bfd
*abfd
, *dwz_bfd
;
1973 struct cleanup
*cleanup
;
1974 const char *filename
;
1975 struct dwz_file
*result
;
1977 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
1978 return dwarf2_per_objfile
->dwz_file
;
1980 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
1981 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
1982 if (section
== NULL
)
1983 error (_("could not find '.gnu_debugaltlink' section"));
1984 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
1985 error (_("could not read '.gnu_debugaltlink' section: %s"),
1986 bfd_errmsg (bfd_get_error ()));
1987 cleanup
= make_cleanup (xfree
, data
);
1990 if (!IS_ABSOLUTE_PATH (filename
))
1992 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
1995 make_cleanup (xfree
, abs
);
1996 abs
= ldirname (abs
);
1997 make_cleanup (xfree
, abs
);
1999 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2000 make_cleanup (xfree
, rel
);
2004 /* The format is just a NUL-terminated file name, followed by the
2005 build-id. For now, though, we ignore the build-id. */
2006 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2007 if (dwz_bfd
== NULL
)
2008 error (_("could not read '%s': %s"), filename
,
2009 bfd_errmsg (bfd_get_error ()));
2011 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2013 gdb_bfd_unref (dwz_bfd
);
2014 error (_("file '%s' was not usable: %s"), filename
,
2015 bfd_errmsg (bfd_get_error ()));
2018 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2020 result
->dwz_bfd
= dwz_bfd
;
2022 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2024 do_cleanups (cleanup
);
2029 /* DWARF quick_symbols_functions support. */
2031 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2032 unique line tables, so we maintain a separate table of all .debug_line
2033 derived entries to support the sharing.
2034 All the quick functions need is the list of file names. We discard the
2035 line_header when we're done and don't need to record it here. */
2036 struct quick_file_names
2038 /* The data used to construct the hash key. */
2039 struct stmt_list_hash hash
;
2041 /* The number of entries in file_names, real_names. */
2042 unsigned int num_file_names
;
2044 /* The file names from the line table, after being run through
2046 const char **file_names
;
2048 /* The file names from the line table after being run through
2049 gdb_realpath. These are computed lazily. */
2050 const char **real_names
;
2053 /* When using the index (and thus not using psymtabs), each CU has an
2054 object of this type. This is used to hold information needed by
2055 the various "quick" methods. */
2056 struct dwarf2_per_cu_quick_data
2058 /* The file table. This can be NULL if there was no file table
2059 or it's currently not read in.
2060 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2061 struct quick_file_names
*file_names
;
2063 /* The corresponding symbol table. This is NULL if symbols for this
2064 CU have not yet been read. */
2065 struct symtab
*symtab
;
2067 /* A temporary mark bit used when iterating over all CUs in
2068 expand_symtabs_matching. */
2069 unsigned int mark
: 1;
2071 /* True if we've tried to read the file table and found there isn't one.
2072 There will be no point in trying to read it again next time. */
2073 unsigned int no_file_data
: 1;
2076 /* Utility hash function for a stmt_list_hash. */
2079 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2083 if (stmt_list_hash
->dwo_unit
!= NULL
)
2084 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2085 v
+= stmt_list_hash
->line_offset
.sect_off
;
2089 /* Utility equality function for a stmt_list_hash. */
2092 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2093 const struct stmt_list_hash
*rhs
)
2095 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2097 if (lhs
->dwo_unit
!= NULL
2098 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2101 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2104 /* Hash function for a quick_file_names. */
2107 hash_file_name_entry (const void *e
)
2109 const struct quick_file_names
*file_data
= e
;
2111 return hash_stmt_list_entry (&file_data
->hash
);
2114 /* Equality function for a quick_file_names. */
2117 eq_file_name_entry (const void *a
, const void *b
)
2119 const struct quick_file_names
*ea
= a
;
2120 const struct quick_file_names
*eb
= b
;
2122 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2125 /* Delete function for a quick_file_names. */
2128 delete_file_name_entry (void *e
)
2130 struct quick_file_names
*file_data
= e
;
2133 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2135 xfree ((void*) file_data
->file_names
[i
]);
2136 if (file_data
->real_names
)
2137 xfree ((void*) file_data
->real_names
[i
]);
2140 /* The space for the struct itself lives on objfile_obstack,
2141 so we don't free it here. */
2144 /* Create a quick_file_names hash table. */
2147 create_quick_file_names_table (unsigned int nr_initial_entries
)
2149 return htab_create_alloc (nr_initial_entries
,
2150 hash_file_name_entry
, eq_file_name_entry
,
2151 delete_file_name_entry
, xcalloc
, xfree
);
2154 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2155 have to be created afterwards. You should call age_cached_comp_units after
2156 processing PER_CU->CU. dw2_setup must have been already called. */
2159 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2161 if (per_cu
->is_debug_types
)
2162 load_full_type_unit (per_cu
);
2164 load_full_comp_unit (per_cu
, language_minimal
);
2166 gdb_assert (per_cu
->cu
!= NULL
);
2168 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2171 /* Read in the symbols for PER_CU. */
2174 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2176 struct cleanup
*back_to
;
2178 /* Skip type_unit_groups, reading the type units they contain
2179 is handled elsewhere. */
2180 if (IS_TYPE_UNIT_GROUP (per_cu
))
2183 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2185 if (dwarf2_per_objfile
->using_index
2186 ? per_cu
->v
.quick
->symtab
== NULL
2187 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2189 queue_comp_unit (per_cu
, language_minimal
);
2195 /* Age the cache, releasing compilation units that have not
2196 been used recently. */
2197 age_cached_comp_units ();
2199 do_cleanups (back_to
);
2202 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2203 the objfile from which this CU came. Returns the resulting symbol
2206 static struct symtab
*
2207 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2209 gdb_assert (dwarf2_per_objfile
->using_index
);
2210 if (!per_cu
->v
.quick
->symtab
)
2212 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2213 increment_reading_symtab ();
2214 dw2_do_instantiate_symtab (per_cu
);
2215 process_cu_includes ();
2216 do_cleanups (back_to
);
2218 return per_cu
->v
.quick
->symtab
;
2221 /* Return the CU given its index.
2223 This is intended for loops like:
2225 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2226 + dwarf2_per_objfile->n_type_units); ++i)
2228 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2234 static struct dwarf2_per_cu_data
*
2235 dw2_get_cu (int index
)
2237 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2239 index
-= dwarf2_per_objfile
->n_comp_units
;
2240 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2241 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2244 return dwarf2_per_objfile
->all_comp_units
[index
];
2247 /* Return the primary CU given its index.
2248 The difference between this function and dw2_get_cu is in the handling
2249 of type units (TUs). Here we return the type_unit_group object.
2251 This is intended for loops like:
2253 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2254 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2256 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2262 static struct dwarf2_per_cu_data
*
2263 dw2_get_primary_cu (int index
)
2265 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2267 index
-= dwarf2_per_objfile
->n_comp_units
;
2268 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2269 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2272 return dwarf2_per_objfile
->all_comp_units
[index
];
2275 /* A helper function that knows how to read a 64-bit value in a way
2276 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2280 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2282 if (sizeof (ULONGEST
) < 8)
2286 /* Ignore the upper 4 bytes if they are all zero. */
2287 for (i
= 0; i
< 4; ++i
)
2288 if (bytes
[i
+ 4] != 0)
2291 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2294 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2298 /* A helper for create_cus_from_index that handles a given list of
2302 create_cus_from_index_list (struct objfile
*objfile
,
2303 const gdb_byte
*cu_list
, offset_type n_elements
,
2304 struct dwarf2_section_info
*section
,
2310 for (i
= 0; i
< n_elements
; i
+= 2)
2312 struct dwarf2_per_cu_data
*the_cu
;
2313 ULONGEST offset
, length
;
2315 if (!extract_cu_value (cu_list
, &offset
)
2316 || !extract_cu_value (cu_list
+ 8, &length
))
2320 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2321 struct dwarf2_per_cu_data
);
2322 the_cu
->offset
.sect_off
= offset
;
2323 the_cu
->length
= length
;
2324 the_cu
->objfile
= objfile
;
2325 the_cu
->info_or_types_section
= section
;
2326 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2327 struct dwarf2_per_cu_quick_data
);
2328 the_cu
->is_dwz
= is_dwz
;
2329 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2335 /* Read the CU list from the mapped index, and use it to create all
2336 the CU objects for this objfile. Return 0 if something went wrong,
2337 1 if everything went ok. */
2340 create_cus_from_index (struct objfile
*objfile
,
2341 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2342 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2344 struct dwz_file
*dwz
;
2346 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2347 dwarf2_per_objfile
->all_comp_units
2348 = obstack_alloc (&objfile
->objfile_obstack
,
2349 dwarf2_per_objfile
->n_comp_units
2350 * sizeof (struct dwarf2_per_cu_data
*));
2352 if (!create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2353 &dwarf2_per_objfile
->info
, 0, 0))
2356 if (dwz_elements
== 0)
2359 dwz
= dwarf2_get_dwz_file ();
2360 return create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
,
2361 &dwz
->info
, 1, cu_list_elements
/ 2);
2364 /* Create the signatured type hash table from the index. */
2367 create_signatured_type_table_from_index (struct objfile
*objfile
,
2368 struct dwarf2_section_info
*section
,
2369 const gdb_byte
*bytes
,
2370 offset_type elements
)
2373 htab_t sig_types_hash
;
2375 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2376 dwarf2_per_objfile
->all_type_units
2377 = obstack_alloc (&objfile
->objfile_obstack
,
2378 dwarf2_per_objfile
->n_type_units
2379 * sizeof (struct signatured_type
*));
2381 sig_types_hash
= allocate_signatured_type_table (objfile
);
2383 for (i
= 0; i
< elements
; i
+= 3)
2385 struct signatured_type
*sig_type
;
2386 ULONGEST offset
, type_offset_in_tu
, signature
;
2389 if (!extract_cu_value (bytes
, &offset
)
2390 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2392 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2395 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2396 struct signatured_type
);
2397 sig_type
->signature
= signature
;
2398 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2399 sig_type
->per_cu
.is_debug_types
= 1;
2400 sig_type
->per_cu
.info_or_types_section
= section
;
2401 sig_type
->per_cu
.offset
.sect_off
= offset
;
2402 sig_type
->per_cu
.objfile
= objfile
;
2403 sig_type
->per_cu
.v
.quick
2404 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2405 struct dwarf2_per_cu_quick_data
);
2407 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2410 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2413 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2418 /* Read the address map data from the mapped index, and use it to
2419 populate the objfile's psymtabs_addrmap. */
2422 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2424 const gdb_byte
*iter
, *end
;
2425 struct obstack temp_obstack
;
2426 struct addrmap
*mutable_map
;
2427 struct cleanup
*cleanup
;
2430 obstack_init (&temp_obstack
);
2431 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2432 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2434 iter
= index
->address_table
;
2435 end
= iter
+ index
->address_table_size
;
2437 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2441 ULONGEST hi
, lo
, cu_index
;
2442 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2444 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2446 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2449 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2450 dw2_get_cu (cu_index
));
2453 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2454 &objfile
->objfile_obstack
);
2455 do_cleanups (cleanup
);
2458 /* The hash function for strings in the mapped index. This is the same as
2459 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2460 implementation. This is necessary because the hash function is tied to the
2461 format of the mapped index file. The hash values do not have to match with
2464 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2467 mapped_index_string_hash (int index_version
, const void *p
)
2469 const unsigned char *str
= (const unsigned char *) p
;
2473 while ((c
= *str
++) != 0)
2475 if (index_version
>= 5)
2477 r
= r
* 67 + c
- 113;
2483 /* Find a slot in the mapped index INDEX for the object named NAME.
2484 If NAME is found, set *VEC_OUT to point to the CU vector in the
2485 constant pool and return 1. If NAME cannot be found, return 0. */
2488 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2489 offset_type
**vec_out
)
2491 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2493 offset_type slot
, step
;
2494 int (*cmp
) (const char *, const char *);
2496 if (current_language
->la_language
== language_cplus
2497 || current_language
->la_language
== language_java
2498 || current_language
->la_language
== language_fortran
)
2500 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2502 const char *paren
= strchr (name
, '(');
2508 dup
= xmalloc (paren
- name
+ 1);
2509 memcpy (dup
, name
, paren
- name
);
2510 dup
[paren
- name
] = 0;
2512 make_cleanup (xfree
, dup
);
2517 /* Index version 4 did not support case insensitive searches. But the
2518 indices for case insensitive languages are built in lowercase, therefore
2519 simulate our NAME being searched is also lowercased. */
2520 hash
= mapped_index_string_hash ((index
->version
== 4
2521 && case_sensitivity
== case_sensitive_off
2522 ? 5 : index
->version
),
2525 slot
= hash
& (index
->symbol_table_slots
- 1);
2526 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2527 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2531 /* Convert a slot number to an offset into the table. */
2532 offset_type i
= 2 * slot
;
2534 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2536 do_cleanups (back_to
);
2540 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2541 if (!cmp (name
, str
))
2543 *vec_out
= (offset_type
*) (index
->constant_pool
2544 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2545 do_cleanups (back_to
);
2549 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2553 /* A helper function that reads the .gdb_index from SECTION and fills
2554 in MAP. FILENAME is the name of the file containing the section;
2555 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2556 ok to use deprecated sections.
2558 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2559 out parameters that are filled in with information about the CU and
2560 TU lists in the section.
2562 Returns 1 if all went well, 0 otherwise. */
2565 read_index_from_section (struct objfile
*objfile
,
2566 const char *filename
,
2568 struct dwarf2_section_info
*section
,
2569 struct mapped_index
*map
,
2570 const gdb_byte
**cu_list
,
2571 offset_type
*cu_list_elements
,
2572 const gdb_byte
**types_list
,
2573 offset_type
*types_list_elements
)
2576 offset_type version
;
2577 offset_type
*metadata
;
2580 if (dwarf2_section_empty_p (section
))
2583 /* Older elfutils strip versions could keep the section in the main
2584 executable while splitting it for the separate debug info file. */
2585 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2588 dwarf2_read_section (objfile
, section
);
2590 addr
= section
->buffer
;
2591 /* Version check. */
2592 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2593 /* Versions earlier than 3 emitted every copy of a psymbol. This
2594 causes the index to behave very poorly for certain requests. Version 3
2595 contained incomplete addrmap. So, it seems better to just ignore such
2599 static int warning_printed
= 0;
2600 if (!warning_printed
)
2602 warning (_("Skipping obsolete .gdb_index section in %s."),
2604 warning_printed
= 1;
2608 /* Index version 4 uses a different hash function than index version
2611 Versions earlier than 6 did not emit psymbols for inlined
2612 functions. Using these files will cause GDB not to be able to
2613 set breakpoints on inlined functions by name, so we ignore these
2614 indices unless the --use-deprecated-index-sections command line
2615 option was supplied. */
2616 if (version
< 6 && !deprecated_ok
)
2618 static int warning_printed
= 0;
2619 if (!warning_printed
)
2621 warning (_("Skipping deprecated .gdb_index section in %s, pass "
2622 "--use-deprecated-index-sections to use them anyway"),
2624 warning_printed
= 1;
2628 /* Indexes with higher version than the one supported by GDB may be no
2629 longer backward compatible. */
2633 map
->version
= version
;
2634 map
->total_size
= section
->size
;
2636 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2639 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2640 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2644 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2645 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2646 - MAYBE_SWAP (metadata
[i
]))
2650 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2651 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2652 - MAYBE_SWAP (metadata
[i
]));
2655 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2656 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2657 - MAYBE_SWAP (metadata
[i
]))
2658 / (2 * sizeof (offset_type
)));
2661 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2667 /* Read the index file. If everything went ok, initialize the "quick"
2668 elements of all the CUs and return 1. Otherwise, return 0. */
2671 dwarf2_read_index (struct objfile
*objfile
)
2673 struct mapped_index local_map
, *map
;
2674 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2675 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2677 if (!read_index_from_section (objfile
, objfile
->name
,
2678 use_deprecated_index_sections
,
2679 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2680 &cu_list
, &cu_list_elements
,
2681 &types_list
, &types_list_elements
))
2684 /* Don't use the index if it's empty. */
2685 if (local_map
.symbol_table_slots
== 0)
2688 /* If there is a .dwz file, read it so we can get its CU list as
2690 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2692 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2693 struct mapped_index dwz_map
;
2694 const gdb_byte
*dwz_types_ignore
;
2695 offset_type dwz_types_elements_ignore
;
2697 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2699 &dwz
->gdb_index
, &dwz_map
,
2700 &dwz_list
, &dwz_list_elements
,
2702 &dwz_types_elements_ignore
))
2704 warning (_("could not read '.gdb_index' section from %s; skipping"),
2705 bfd_get_filename (dwz
->dwz_bfd
));
2710 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
,
2711 dwz_list
, dwz_list_elements
))
2714 if (types_list_elements
)
2716 struct dwarf2_section_info
*section
;
2718 /* We can only handle a single .debug_types when we have an
2720 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2723 section
= VEC_index (dwarf2_section_info_def
,
2724 dwarf2_per_objfile
->types
, 0);
2726 if (!create_signatured_type_table_from_index (objfile
, section
,
2728 types_list_elements
))
2732 create_addrmap_from_index (objfile
, &local_map
);
2734 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2737 dwarf2_per_objfile
->index_table
= map
;
2738 dwarf2_per_objfile
->using_index
= 1;
2739 dwarf2_per_objfile
->quick_file_names_table
=
2740 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2745 /* A helper for the "quick" functions which sets the global
2746 dwarf2_per_objfile according to OBJFILE. */
2749 dw2_setup (struct objfile
*objfile
)
2751 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2752 gdb_assert (dwarf2_per_objfile
);
2755 /* Reader function for dw2_build_type_unit_groups. */
2758 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2760 struct die_info
*type_unit_die
,
2764 struct dwarf2_cu
*cu
= reader
->cu
;
2765 struct attribute
*attr
;
2766 struct type_unit_group
*tu_group
;
2768 gdb_assert (data
== NULL
);
2773 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2774 /* Call this for its side-effect of creating the associated
2775 struct type_unit_group if it doesn't already exist. */
2776 tu_group
= get_type_unit_group (cu
, attr
);
2779 /* Build dwarf2_per_objfile->type_unit_groups.
2780 This function may be called multiple times. */
2783 dw2_build_type_unit_groups (void)
2785 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2786 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2789 /* die_reader_func for dw2_get_file_names. */
2792 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2794 struct die_info
*comp_unit_die
,
2798 struct dwarf2_cu
*cu
= reader
->cu
;
2799 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2800 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2801 struct dwarf2_per_cu_data
*lh_cu
;
2802 struct line_header
*lh
;
2803 struct attribute
*attr
;
2805 char *name
, *comp_dir
;
2807 struct quick_file_names
*qfn
;
2808 unsigned int line_offset
;
2810 /* Our callers never want to match partial units -- instead they
2811 will match the enclosing full CU. */
2812 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2814 this_cu
->v
.quick
->no_file_data
= 1;
2818 /* If we're reading the line header for TUs, store it in the "per_cu"
2820 if (this_cu
->is_debug_types
)
2822 struct type_unit_group
*tu_group
= data
;
2824 gdb_assert (tu_group
!= NULL
);
2825 lh_cu
= &tu_group
->per_cu
;
2834 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2837 struct quick_file_names find_entry
;
2839 line_offset
= DW_UNSND (attr
);
2841 /* We may have already read in this line header (TU line header sharing).
2842 If we have we're done. */
2843 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2844 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2845 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2846 &find_entry
, INSERT
);
2849 lh_cu
->v
.quick
->file_names
= *slot
;
2853 lh
= dwarf_decode_line_header (line_offset
, cu
);
2857 lh_cu
->v
.quick
->no_file_data
= 1;
2861 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2862 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2863 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2864 gdb_assert (slot
!= NULL
);
2867 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2869 qfn
->num_file_names
= lh
->num_file_names
;
2870 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2871 lh
->num_file_names
* sizeof (char *));
2872 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2873 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2874 qfn
->real_names
= NULL
;
2876 free_line_header (lh
);
2878 lh_cu
->v
.quick
->file_names
= qfn
;
2881 /* A helper for the "quick" functions which attempts to read the line
2882 table for THIS_CU. */
2884 static struct quick_file_names
*
2885 dw2_get_file_names (struct objfile
*objfile
,
2886 struct dwarf2_per_cu_data
*this_cu
)
2888 /* For TUs this should only be called on the parent group. */
2889 if (this_cu
->is_debug_types
)
2890 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2892 if (this_cu
->v
.quick
->file_names
!= NULL
)
2893 return this_cu
->v
.quick
->file_names
;
2894 /* If we know there is no line data, no point in looking again. */
2895 if (this_cu
->v
.quick
->no_file_data
)
2898 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2899 in the stub for CUs, there's is no need to lookup the DWO file.
2900 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2902 if (this_cu
->is_debug_types
)
2904 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2906 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2907 dw2_get_file_names_reader
, tu_group
);
2910 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2912 if (this_cu
->v
.quick
->no_file_data
)
2914 return this_cu
->v
.quick
->file_names
;
2917 /* A helper for the "quick" functions which computes and caches the
2918 real path for a given file name from the line table. */
2921 dw2_get_real_path (struct objfile
*objfile
,
2922 struct quick_file_names
*qfn
, int index
)
2924 if (qfn
->real_names
== NULL
)
2925 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2926 qfn
->num_file_names
, sizeof (char *));
2928 if (qfn
->real_names
[index
] == NULL
)
2929 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2931 return qfn
->real_names
[index
];
2934 static struct symtab
*
2935 dw2_find_last_source_symtab (struct objfile
*objfile
)
2939 dw2_setup (objfile
);
2940 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2941 return dw2_instantiate_symtab (dw2_get_cu (index
));
2944 /* Traversal function for dw2_forget_cached_source_info. */
2947 dw2_free_cached_file_names (void **slot
, void *info
)
2949 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2951 if (file_data
->real_names
)
2955 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2957 xfree ((void*) file_data
->real_names
[i
]);
2958 file_data
->real_names
[i
] = NULL
;
2966 dw2_forget_cached_source_info (struct objfile
*objfile
)
2968 dw2_setup (objfile
);
2970 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2971 dw2_free_cached_file_names
, NULL
);
2974 /* Helper function for dw2_map_symtabs_matching_filename that expands
2975 the symtabs and calls the iterator. */
2978 dw2_map_expand_apply (struct objfile
*objfile
,
2979 struct dwarf2_per_cu_data
*per_cu
,
2981 const char *full_path
, const char *real_path
,
2982 int (*callback
) (struct symtab
*, void *),
2985 struct symtab
*last_made
= objfile
->symtabs
;
2987 /* Don't visit already-expanded CUs. */
2988 if (per_cu
->v
.quick
->symtab
)
2991 /* This may expand more than one symtab, and we want to iterate over
2993 dw2_instantiate_symtab (per_cu
);
2995 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
2996 objfile
->symtabs
, last_made
);
2999 /* Implementation of the map_symtabs_matching_filename method. */
3002 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3003 const char *full_path
, const char *real_path
,
3004 int (*callback
) (struct symtab
*, void *),
3008 const char *name_basename
= lbasename (name
);
3009 int name_len
= strlen (name
);
3010 int is_abs
= IS_ABSOLUTE_PATH (name
);
3012 dw2_setup (objfile
);
3014 dw2_build_type_unit_groups ();
3016 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3017 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3020 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3021 struct quick_file_names
*file_data
;
3023 /* We only need to look at symtabs not already expanded. */
3024 if (per_cu
->v
.quick
->symtab
)
3027 file_data
= dw2_get_file_names (objfile
, per_cu
);
3028 if (file_data
== NULL
)
3031 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3033 const char *this_name
= file_data
->file_names
[j
];
3035 if (FILENAME_CMP (name
, this_name
) == 0
3036 || (!is_abs
&& compare_filenames_for_search (this_name
,
3039 if (dw2_map_expand_apply (objfile
, per_cu
,
3040 name
, full_path
, real_path
,
3045 /* Before we invoke realpath, which can get expensive when many
3046 files are involved, do a quick comparison of the basenames. */
3047 if (! basenames_may_differ
3048 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3051 if (full_path
!= NULL
)
3053 const char *this_real_name
= dw2_get_real_path (objfile
,
3056 if (this_real_name
!= NULL
3057 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3059 && compare_filenames_for_search (this_real_name
,
3062 if (dw2_map_expand_apply (objfile
, per_cu
,
3063 name
, full_path
, real_path
,
3069 if (real_path
!= NULL
)
3071 const char *this_real_name
= dw2_get_real_path (objfile
,
3074 if (this_real_name
!= NULL
3075 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3077 && compare_filenames_for_search (this_real_name
,
3080 if (dw2_map_expand_apply (objfile
, per_cu
,
3081 name
, full_path
, real_path
,
3092 static struct symtab
*
3093 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3094 const char *name
, domain_enum domain
)
3096 /* We do all the work in the pre_expand_symtabs_matching hook
3101 /* A helper function that expands all symtabs that hold an object
3102 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3103 symbols in block BLOCK_KIND. */
3106 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3107 int want_specific_block
,
3108 enum block_enum block_kind
,
3109 const char *name
, domain_enum domain
)
3111 struct mapped_index
*index
;
3113 dw2_setup (objfile
);
3115 index
= dwarf2_per_objfile
->index_table
;
3117 /* index_table is NULL if OBJF_READNOW. */
3122 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3124 offset_type i
, len
= MAYBE_SWAP (*vec
);
3125 for (i
= 0; i
< len
; ++i
)
3127 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3128 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3129 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3130 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3131 /* This value is only valid for index versions >= 7. */
3132 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3133 gdb_index_symbol_kind symbol_kind
=
3134 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3136 if (want_specific_block
3137 && index
->version
>= 7
3138 && want_static
!= is_static
)
3141 /* Only check the symbol's kind if it has one.
3142 Indices prior to version 7 don't record it. */
3143 if (index
->version
>= 7)
3148 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3149 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3150 /* Some types are also in VAR_DOMAIN. */
3151 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3155 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3159 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3167 dw2_instantiate_symtab (per_cu
);
3174 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3175 enum block_enum block_kind
, const char *name
,
3178 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3182 dw2_print_stats (struct objfile
*objfile
)
3186 dw2_setup (objfile
);
3188 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3189 + dwarf2_per_objfile
->n_type_units
); ++i
)
3191 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3193 if (!per_cu
->v
.quick
->symtab
)
3196 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3200 dw2_dump (struct objfile
*objfile
)
3202 /* Nothing worth printing. */
3206 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3207 struct section_offsets
*delta
)
3209 /* There's nothing to relocate here. */
3213 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3214 const char *func_name
)
3216 /* Note: It doesn't matter what we pass for block_kind here. */
3217 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3222 dw2_expand_all_symtabs (struct objfile
*objfile
)
3226 dw2_setup (objfile
);
3228 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3229 + dwarf2_per_objfile
->n_type_units
); ++i
)
3231 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3233 dw2_instantiate_symtab (per_cu
);
3238 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3239 const char *filename
)
3243 dw2_setup (objfile
);
3245 /* We don't need to consider type units here.
3246 This is only called for examining code, e.g. expand_line_sal.
3247 There can be an order of magnitude (or more) more type units
3248 than comp units, and we avoid them if we can. */
3250 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3253 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3254 struct quick_file_names
*file_data
;
3256 /* We only need to look at symtabs not already expanded. */
3257 if (per_cu
->v
.quick
->symtab
)
3260 file_data
= dw2_get_file_names (objfile
, per_cu
);
3261 if (file_data
== NULL
)
3264 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3266 const char *this_name
= file_data
->file_names
[j
];
3267 if (FILENAME_CMP (this_name
, filename
) == 0)
3269 dw2_instantiate_symtab (per_cu
);
3276 /* A helper function for dw2_find_symbol_file that finds the primary
3277 file name for a given CU. This is a die_reader_func. */
3280 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3282 struct die_info
*comp_unit_die
,
3286 const char **result_ptr
= data
;
3287 struct dwarf2_cu
*cu
= reader
->cu
;
3288 struct attribute
*attr
;
3290 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3294 *result_ptr
= DW_STRING (attr
);
3298 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3300 struct dwarf2_per_cu_data
*per_cu
;
3302 struct quick_file_names
*file_data
;
3303 const char *filename
;
3305 dw2_setup (objfile
);
3307 /* index_table is NULL if OBJF_READNOW. */
3308 if (!dwarf2_per_objfile
->index_table
)
3312 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3314 struct blockvector
*bv
= BLOCKVECTOR (s
);
3315 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3316 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3319 return sym
->symtab
->filename
;
3324 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3328 /* Note that this just looks at the very first one named NAME -- but
3329 actually we are looking for a function. find_main_filename
3330 should be rewritten so that it doesn't require a custom hook. It
3331 could just use the ordinary symbol tables. */
3332 /* vec[0] is the length, which must always be >0. */
3333 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3335 if (per_cu
->v
.quick
->symtab
!= NULL
)
3336 return per_cu
->v
.quick
->symtab
->filename
;
3338 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3339 dw2_get_primary_filename_reader
, &filename
);
3345 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3346 struct objfile
*objfile
, int global
,
3347 int (*callback
) (struct block
*,
3348 struct symbol
*, void *),
3349 void *data
, symbol_compare_ftype
*match
,
3350 symbol_compare_ftype
*ordered_compare
)
3352 /* Currently unimplemented; used for Ada. The function can be called if the
3353 current language is Ada for a non-Ada objfile using GNU index. As Ada
3354 does not look for non-Ada symbols this function should just return. */
3358 dw2_expand_symtabs_matching
3359 (struct objfile
*objfile
,
3360 int (*file_matcher
) (const char *, void *),
3361 int (*name_matcher
) (const char *, void *),
3362 enum search_domain kind
,
3367 struct mapped_index
*index
;
3369 dw2_setup (objfile
);
3371 /* index_table is NULL if OBJF_READNOW. */
3372 if (!dwarf2_per_objfile
->index_table
)
3374 index
= dwarf2_per_objfile
->index_table
;
3376 if (file_matcher
!= NULL
)
3378 struct cleanup
*cleanup
;
3379 htab_t visited_found
, visited_not_found
;
3381 dw2_build_type_unit_groups ();
3383 visited_found
= htab_create_alloc (10,
3384 htab_hash_pointer
, htab_eq_pointer
,
3385 NULL
, xcalloc
, xfree
);
3386 cleanup
= make_cleanup_htab_delete (visited_found
);
3387 visited_not_found
= htab_create_alloc (10,
3388 htab_hash_pointer
, htab_eq_pointer
,
3389 NULL
, xcalloc
, xfree
);
3390 make_cleanup_htab_delete (visited_not_found
);
3392 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3393 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3396 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3397 struct quick_file_names
*file_data
;
3400 per_cu
->v
.quick
->mark
= 0;
3402 /* We only need to look at symtabs not already expanded. */
3403 if (per_cu
->v
.quick
->symtab
)
3406 file_data
= dw2_get_file_names (objfile
, per_cu
);
3407 if (file_data
== NULL
)
3410 if (htab_find (visited_not_found
, file_data
) != NULL
)
3412 else if (htab_find (visited_found
, file_data
) != NULL
)
3414 per_cu
->v
.quick
->mark
= 1;
3418 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3420 if (file_matcher (file_data
->file_names
[j
], data
))
3422 per_cu
->v
.quick
->mark
= 1;
3427 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3429 : visited_not_found
,
3434 do_cleanups (cleanup
);
3437 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3439 offset_type idx
= 2 * iter
;
3441 offset_type
*vec
, vec_len
, vec_idx
;
3443 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3446 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3448 if (! (*name_matcher
) (name
, data
))
3451 /* The name was matched, now expand corresponding CUs that were
3453 vec
= (offset_type
*) (index
->constant_pool
3454 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3455 vec_len
= MAYBE_SWAP (vec
[0]);
3456 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3458 struct dwarf2_per_cu_data
*per_cu
;
3459 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3460 gdb_index_symbol_kind symbol_kind
=
3461 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3462 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3464 /* Don't crash on bad data. */
3465 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3466 + dwarf2_per_objfile
->n_type_units
))
3469 /* Only check the symbol's kind if it has one.
3470 Indices prior to version 7 don't record it. */
3471 if (index
->version
>= 7)
3475 case VARIABLES_DOMAIN
:
3476 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3479 case FUNCTIONS_DOMAIN
:
3480 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3484 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3492 per_cu
= dw2_get_cu (cu_index
);
3493 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3494 dw2_instantiate_symtab (per_cu
);
3499 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3502 static struct symtab
*
3503 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3507 if (BLOCKVECTOR (symtab
) != NULL
3508 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3511 if (symtab
->includes
== NULL
)
3514 for (i
= 0; symtab
->includes
[i
]; ++i
)
3516 struct symtab
*s
= symtab
->includes
[i
];
3518 s
= recursively_find_pc_sect_symtab (s
, pc
);
3526 static struct symtab
*
3527 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3528 struct minimal_symbol
*msymbol
,
3530 struct obj_section
*section
,
3533 struct dwarf2_per_cu_data
*data
;
3534 struct symtab
*result
;
3536 dw2_setup (objfile
);
3538 if (!objfile
->psymtabs_addrmap
)
3541 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3545 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3546 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3547 paddress (get_objfile_arch (objfile
), pc
));
3549 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3550 gdb_assert (result
!= NULL
);
3555 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3556 void *data
, int need_fullname
)
3559 struct cleanup
*cleanup
;
3560 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3561 NULL
, xcalloc
, xfree
);
3563 cleanup
= make_cleanup_htab_delete (visited
);
3564 dw2_setup (objfile
);
3566 dw2_build_type_unit_groups ();
3568 /* We can ignore file names coming from already-expanded CUs. */
3569 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3570 + dwarf2_per_objfile
->n_type_units
); ++i
)
3572 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3574 if (per_cu
->v
.quick
->symtab
)
3576 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3579 *slot
= per_cu
->v
.quick
->file_names
;
3583 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3584 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3587 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3588 struct quick_file_names
*file_data
;
3591 /* We only need to look at symtabs not already expanded. */
3592 if (per_cu
->v
.quick
->symtab
)
3595 file_data
= dw2_get_file_names (objfile
, per_cu
);
3596 if (file_data
== NULL
)
3599 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3602 /* Already visited. */
3607 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3609 const char *this_real_name
;
3612 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3614 this_real_name
= NULL
;
3615 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3619 do_cleanups (cleanup
);
3623 dw2_has_symbols (struct objfile
*objfile
)
3628 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3631 dw2_find_last_source_symtab
,
3632 dw2_forget_cached_source_info
,
3633 dw2_map_symtabs_matching_filename
,
3635 dw2_pre_expand_symtabs_matching
,
3639 dw2_expand_symtabs_for_function
,
3640 dw2_expand_all_symtabs
,
3641 dw2_expand_symtabs_with_filename
,
3642 dw2_find_symbol_file
,
3643 dw2_map_matching_symbols
,
3644 dw2_expand_symtabs_matching
,
3645 dw2_find_pc_sect_symtab
,
3646 dw2_map_symbol_filenames
3649 /* Initialize for reading DWARF for this objfile. Return 0 if this
3650 file will use psymtabs, or 1 if using the GNU index. */
3653 dwarf2_initialize_objfile (struct objfile
*objfile
)
3655 /* If we're about to read full symbols, don't bother with the
3656 indices. In this case we also don't care if some other debug
3657 format is making psymtabs, because they are all about to be
3659 if ((objfile
->flags
& OBJF_READNOW
))
3663 dwarf2_per_objfile
->using_index
= 1;
3664 create_all_comp_units (objfile
);
3665 create_all_type_units (objfile
);
3666 dwarf2_per_objfile
->quick_file_names_table
=
3667 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3669 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3670 + dwarf2_per_objfile
->n_type_units
); ++i
)
3672 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3674 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3675 struct dwarf2_per_cu_quick_data
);
3678 /* Return 1 so that gdb sees the "quick" functions. However,
3679 these functions will be no-ops because we will have expanded
3684 if (dwarf2_read_index (objfile
))
3692 /* Build a partial symbol table. */
3695 dwarf2_build_psymtabs (struct objfile
*objfile
)
3697 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3699 init_psymbol_list (objfile
, 1024);
3702 dwarf2_build_psymtabs_hard (objfile
);
3705 /* Return the total length of the CU described by HEADER. */
3708 get_cu_length (const struct comp_unit_head
*header
)
3710 return header
->initial_length_size
+ header
->length
;
3713 /* Return TRUE if OFFSET is within CU_HEADER. */
3716 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3718 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3719 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3721 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3724 /* Find the base address of the compilation unit for range lists and
3725 location lists. It will normally be specified by DW_AT_low_pc.
3726 In DWARF-3 draft 4, the base address could be overridden by
3727 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3728 compilation units with discontinuous ranges. */
3731 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3733 struct attribute
*attr
;
3736 cu
->base_address
= 0;
3738 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3741 cu
->base_address
= DW_ADDR (attr
);
3746 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3749 cu
->base_address
= DW_ADDR (attr
);
3755 /* Read in the comp unit header information from the debug_info at info_ptr.
3756 NOTE: This leaves members offset, first_die_offset to be filled in
3760 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3761 gdb_byte
*info_ptr
, bfd
*abfd
)
3764 unsigned int bytes_read
;
3766 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3767 cu_header
->initial_length_size
= bytes_read
;
3768 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3769 info_ptr
+= bytes_read
;
3770 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3772 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3774 info_ptr
+= bytes_read
;
3775 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3777 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3778 if (signed_addr
< 0)
3779 internal_error (__FILE__
, __LINE__
,
3780 _("read_comp_unit_head: dwarf from non elf file"));
3781 cu_header
->signed_addr_p
= signed_addr
;
3786 /* Helper function that returns the proper abbrev section for
3789 static struct dwarf2_section_info
*
3790 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3792 struct dwarf2_section_info
*abbrev
;
3794 if (this_cu
->is_dwz
)
3795 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3797 abbrev
= &dwarf2_per_objfile
->abbrev
;
3802 /* Subroutine of read_and_check_comp_unit_head and
3803 read_and_check_type_unit_head to simplify them.
3804 Perform various error checking on the header. */
3807 error_check_comp_unit_head (struct comp_unit_head
*header
,
3808 struct dwarf2_section_info
*section
,
3809 struct dwarf2_section_info
*abbrev_section
)
3811 bfd
*abfd
= section
->asection
->owner
;
3812 const char *filename
= bfd_get_filename (abfd
);
3814 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3815 error (_("Dwarf Error: wrong version in compilation unit header "
3816 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3819 if (header
->abbrev_offset
.sect_off
3820 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3821 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3822 "(offset 0x%lx + 6) [in module %s]"),
3823 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3826 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3827 avoid potential 32-bit overflow. */
3828 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3830 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3831 "(offset 0x%lx + 0) [in module %s]"),
3832 (long) header
->length
, (long) header
->offset
.sect_off
,
3836 /* Read in a CU/TU header and perform some basic error checking.
3837 The contents of the header are stored in HEADER.
3838 The result is a pointer to the start of the first DIE. */
3841 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3842 struct dwarf2_section_info
*section
,
3843 struct dwarf2_section_info
*abbrev_section
,
3845 int is_debug_types_section
)
3847 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3848 bfd
*abfd
= section
->asection
->owner
;
3850 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3852 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3854 /* If we're reading a type unit, skip over the signature and
3855 type_offset fields. */
3856 if (is_debug_types_section
)
3857 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3859 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3861 error_check_comp_unit_head (header
, section
, abbrev_section
);
3866 /* Read in the types comp unit header information from .debug_types entry at
3867 types_ptr. The result is a pointer to one past the end of the header. */
3870 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3871 struct dwarf2_section_info
*section
,
3872 struct dwarf2_section_info
*abbrev_section
,
3874 ULONGEST
*signature
,
3875 cu_offset
*type_offset_in_tu
)
3877 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3878 bfd
*abfd
= section
->asection
->owner
;
3880 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3882 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3884 /* If we're reading a type unit, skip over the signature and
3885 type_offset fields. */
3886 if (signature
!= NULL
)
3887 *signature
= read_8_bytes (abfd
, info_ptr
);
3889 if (type_offset_in_tu
!= NULL
)
3890 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3891 header
->offset_size
);
3892 info_ptr
+= header
->offset_size
;
3894 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3896 error_check_comp_unit_head (header
, section
, abbrev_section
);
3901 /* Fetch the abbreviation table offset from a comp or type unit header. */
3904 read_abbrev_offset (struct dwarf2_section_info
*section
,
3907 bfd
*abfd
= section
->asection
->owner
;
3909 unsigned int length
, initial_length_size
, offset_size
;
3910 sect_offset abbrev_offset
;
3912 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
3913 info_ptr
= section
->buffer
+ offset
.sect_off
;
3914 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
3915 offset_size
= initial_length_size
== 4 ? 4 : 8;
3916 info_ptr
+= initial_length_size
+ 2 /*version*/;
3917 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
3918 return abbrev_offset
;
3921 /* Allocate a new partial symtab for file named NAME and mark this new
3922 partial symtab as being an include of PST. */
3925 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
3926 struct objfile
*objfile
)
3928 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
3930 subpst
->section_offsets
= pst
->section_offsets
;
3931 subpst
->textlow
= 0;
3932 subpst
->texthigh
= 0;
3934 subpst
->dependencies
= (struct partial_symtab
**)
3935 obstack_alloc (&objfile
->objfile_obstack
,
3936 sizeof (struct partial_symtab
*));
3937 subpst
->dependencies
[0] = pst
;
3938 subpst
->number_of_dependencies
= 1;
3940 subpst
->globals_offset
= 0;
3941 subpst
->n_global_syms
= 0;
3942 subpst
->statics_offset
= 0;
3943 subpst
->n_static_syms
= 0;
3944 subpst
->symtab
= NULL
;
3945 subpst
->read_symtab
= pst
->read_symtab
;
3948 /* No private part is necessary for include psymtabs. This property
3949 can be used to differentiate between such include psymtabs and
3950 the regular ones. */
3951 subpst
->read_symtab_private
= NULL
;
3954 /* Read the Line Number Program data and extract the list of files
3955 included by the source file represented by PST. Build an include
3956 partial symtab for each of these included files. */
3959 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
3960 struct die_info
*die
,
3961 struct partial_symtab
*pst
)
3963 struct line_header
*lh
= NULL
;
3964 struct attribute
*attr
;
3966 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3968 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
3970 return; /* No linetable, so no includes. */
3972 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
3973 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
3975 free_line_header (lh
);
3979 hash_signatured_type (const void *item
)
3981 const struct signatured_type
*sig_type
= item
;
3983 /* This drops the top 32 bits of the signature, but is ok for a hash. */
3984 return sig_type
->signature
;
3988 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
3990 const struct signatured_type
*lhs
= item_lhs
;
3991 const struct signatured_type
*rhs
= item_rhs
;
3993 return lhs
->signature
== rhs
->signature
;
3996 /* Allocate a hash table for signatured types. */
3999 allocate_signatured_type_table (struct objfile
*objfile
)
4001 return htab_create_alloc_ex (41,
4002 hash_signatured_type
,
4005 &objfile
->objfile_obstack
,
4006 hashtab_obstack_allocate
,
4007 dummy_obstack_deallocate
);
4010 /* A helper function to add a signatured type CU to a table. */
4013 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4015 struct signatured_type
*sigt
= *slot
;
4016 struct signatured_type
***datap
= datum
;
4024 /* Create the hash table of all entries in the .debug_types section.
4025 DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise.
4026 The result is a pointer to the hash table or NULL if there are
4030 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4031 VEC (dwarf2_section_info_def
) *types
)
4033 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4034 htab_t types_htab
= NULL
;
4036 struct dwarf2_section_info
*section
;
4037 struct dwarf2_section_info
*abbrev_section
;
4039 if (VEC_empty (dwarf2_section_info_def
, types
))
4042 abbrev_section
= (dwo_file
!= NULL
4043 ? &dwo_file
->sections
.abbrev
4044 : &dwarf2_per_objfile
->abbrev
);
4046 if (dwarf2_read_debug
)
4047 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4048 dwo_file
? ".dwo" : "",
4049 bfd_get_filename (abbrev_section
->asection
->owner
));
4052 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4056 gdb_byte
*info_ptr
, *end_ptr
;
4057 struct dwarf2_section_info
*abbrev_section
;
4059 dwarf2_read_section (objfile
, section
);
4060 info_ptr
= section
->buffer
;
4062 if (info_ptr
== NULL
)
4065 /* We can't set abfd until now because the section may be empty or
4066 not present, in which case section->asection will be NULL. */
4067 abfd
= section
->asection
->owner
;
4070 abbrev_section
= &dwo_file
->sections
.abbrev
;
4072 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4074 if (types_htab
== NULL
)
4077 types_htab
= allocate_dwo_unit_table (objfile
);
4079 types_htab
= allocate_signatured_type_table (objfile
);
4082 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4083 because we don't need to read any dies: the signature is in the
4086 end_ptr
= info_ptr
+ section
->size
;
4087 while (info_ptr
< end_ptr
)
4090 cu_offset type_offset_in_tu
;
4092 struct signatured_type
*sig_type
;
4093 struct dwo_unit
*dwo_tu
;
4095 gdb_byte
*ptr
= info_ptr
;
4096 struct comp_unit_head header
;
4097 unsigned int length
;
4099 offset
.sect_off
= ptr
- section
->buffer
;
4101 /* We need to read the type's signature in order to build the hash
4102 table, but we don't need anything else just yet. */
4104 ptr
= read_and_check_type_unit_head (&header
, section
,
4105 abbrev_section
, ptr
,
4106 &signature
, &type_offset_in_tu
);
4108 length
= get_cu_length (&header
);
4110 /* Skip dummy type units. */
4111 if (ptr
>= info_ptr
+ length
4112 || peek_abbrev_code (abfd
, ptr
) == 0)
4121 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4123 dwo_tu
->dwo_file
= dwo_file
;
4124 dwo_tu
->signature
= signature
;
4125 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4126 dwo_tu
->info_or_types_section
= section
;
4127 dwo_tu
->offset
= offset
;
4128 dwo_tu
->length
= length
;
4132 /* N.B.: type_offset is not usable if this type uses a DWO file.
4133 The real type_offset is in the DWO file. */
4135 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4136 struct signatured_type
);
4137 sig_type
->signature
= signature
;
4138 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4139 sig_type
->per_cu
.objfile
= objfile
;
4140 sig_type
->per_cu
.is_debug_types
= 1;
4141 sig_type
->per_cu
.info_or_types_section
= section
;
4142 sig_type
->per_cu
.offset
= offset
;
4143 sig_type
->per_cu
.length
= length
;
4146 slot
= htab_find_slot (types_htab
,
4147 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4149 gdb_assert (slot
!= NULL
);
4152 sect_offset dup_offset
;
4156 const struct dwo_unit
*dup_tu
= *slot
;
4158 dup_offset
= dup_tu
->offset
;
4162 const struct signatured_type
*dup_tu
= *slot
;
4164 dup_offset
= dup_tu
->per_cu
.offset
;
4167 complaint (&symfile_complaints
,
4168 _("debug type entry at offset 0x%x is duplicate to the "
4169 "entry at offset 0x%x, signature 0x%s"),
4170 offset
.sect_off
, dup_offset
.sect_off
,
4171 phex (signature
, sizeof (signature
)));
4173 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4175 if (dwarf2_read_debug
)
4176 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4178 phex (signature
, sizeof (signature
)));
4187 /* Create the hash table of all entries in the .debug_types section,
4188 and initialize all_type_units.
4189 The result is zero if there is an error (e.g. missing .debug_types section),
4190 otherwise non-zero. */
4193 create_all_type_units (struct objfile
*objfile
)
4196 struct signatured_type
**iter
;
4198 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4199 if (types_htab
== NULL
)
4201 dwarf2_per_objfile
->signatured_types
= NULL
;
4205 dwarf2_per_objfile
->signatured_types
= types_htab
;
4207 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4208 dwarf2_per_objfile
->all_type_units
4209 = obstack_alloc (&objfile
->objfile_obstack
,
4210 dwarf2_per_objfile
->n_type_units
4211 * sizeof (struct signatured_type
*));
4212 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4213 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4214 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4215 == dwarf2_per_objfile
->n_type_units
);
4220 /* Lookup a signature based type for DW_FORM_ref_sig8.
4221 Returns NULL if signature SIG is not present in the table. */
4223 static struct signatured_type
*
4224 lookup_signatured_type (ULONGEST sig
)
4226 struct signatured_type find_entry
, *entry
;
4228 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4230 complaint (&symfile_complaints
,
4231 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4235 find_entry
.signature
= sig
;
4236 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4240 /* Low level DIE reading support. */
4242 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4245 init_cu_die_reader (struct die_reader_specs
*reader
,
4246 struct dwarf2_cu
*cu
,
4247 struct dwarf2_section_info
*section
,
4248 struct dwo_file
*dwo_file
)
4250 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4251 reader
->abfd
= section
->asection
->owner
;
4253 reader
->dwo_file
= dwo_file
;
4254 reader
->die_section
= section
;
4255 reader
->buffer
= section
->buffer
;
4256 reader
->buffer_end
= section
->buffer
+ section
->size
;
4259 /* Initialize a CU (or TU) and read its DIEs.
4260 If the CU defers to a DWO file, read the DWO file as well.
4262 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4263 Otherwise the table specified in the comp unit header is read in and used.
4264 This is an optimization for when we already have the abbrev table.
4266 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4267 Otherwise, a new CU is allocated with xmalloc.
4269 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4270 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4272 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4273 linker) then DIE_READER_FUNC will not get called. */
4276 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4277 struct abbrev_table
*abbrev_table
,
4278 int use_existing_cu
, int keep
,
4279 die_reader_func_ftype
*die_reader_func
,
4282 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4283 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4284 bfd
*abfd
= section
->asection
->owner
;
4285 struct dwarf2_cu
*cu
;
4286 gdb_byte
*begin_info_ptr
, *info_ptr
;
4287 struct die_reader_specs reader
;
4288 struct die_info
*comp_unit_die
;
4290 struct attribute
*attr
;
4291 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4292 struct signatured_type
*sig_type
= NULL
;
4293 struct dwarf2_section_info
*abbrev_section
;
4294 /* Non-zero if CU currently points to a DWO file and we need to
4295 reread it. When this happens we need to reread the skeleton die
4296 before we can reread the DWO file. */
4297 int rereading_dwo_cu
= 0;
4299 if (dwarf2_die_debug
)
4300 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4301 this_cu
->is_debug_types
? "type" : "comp",
4302 this_cu
->offset
.sect_off
);
4304 if (use_existing_cu
)
4307 cleanups
= make_cleanup (null_cleanup
, NULL
);
4309 /* This is cheap if the section is already read in. */
4310 dwarf2_read_section (objfile
, section
);
4312 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4314 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4316 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4320 /* If this CU is from a DWO file we need to start over, we need to
4321 refetch the attributes from the skeleton CU.
4322 This could be optimized by retrieving those attributes from when we
4323 were here the first time: the previous comp_unit_die was stored in
4324 comp_unit_obstack. But there's no data yet that we need this
4326 if (cu
->dwo_unit
!= NULL
)
4327 rereading_dwo_cu
= 1;
4331 /* If !use_existing_cu, this_cu->cu must be NULL. */
4332 gdb_assert (this_cu
->cu
== NULL
);
4334 cu
= xmalloc (sizeof (*cu
));
4335 init_one_comp_unit (cu
, this_cu
);
4337 /* If an error occurs while loading, release our storage. */
4338 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4341 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4343 /* We already have the header, there's no need to read it in again. */
4344 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4348 if (this_cu
->is_debug_types
)
4351 cu_offset type_offset_in_tu
;
4353 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4354 abbrev_section
, info_ptr
,
4356 &type_offset_in_tu
);
4358 /* Since per_cu is the first member of struct signatured_type,
4359 we can go from a pointer to one to a pointer to the other. */
4360 sig_type
= (struct signatured_type
*) this_cu
;
4361 gdb_assert (sig_type
->signature
== signature
);
4362 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4363 == type_offset_in_tu
.cu_off
);
4364 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4366 /* LENGTH has not been set yet for type units if we're
4367 using .gdb_index. */
4368 this_cu
->length
= get_cu_length (&cu
->header
);
4370 /* Establish the type offset that can be used to lookup the type. */
4371 sig_type
->type_offset_in_section
.sect_off
=
4372 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4376 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4380 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4381 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4385 /* Skip dummy compilation units. */
4386 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4387 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4389 do_cleanups (cleanups
);
4393 /* If we don't have them yet, read the abbrevs for this compilation unit.
4394 And if we need to read them now, make sure they're freed when we're
4395 done. Note that it's important that if the CU had an abbrev table
4396 on entry we don't free it when we're done: Somewhere up the call stack
4397 it may be in use. */
4398 if (abbrev_table
!= NULL
)
4400 gdb_assert (cu
->abbrev_table
== NULL
);
4401 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4402 == abbrev_table
->offset
.sect_off
);
4403 cu
->abbrev_table
= abbrev_table
;
4405 else if (cu
->abbrev_table
== NULL
)
4407 dwarf2_read_abbrevs (cu
, abbrev_section
);
4408 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4410 else if (rereading_dwo_cu
)
4412 dwarf2_free_abbrev_table (cu
);
4413 dwarf2_read_abbrevs (cu
, abbrev_section
);
4416 /* Read the top level CU/TU die. */
4417 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4418 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4420 /* If we have a DWO stub, process it and then read in the DWO file.
4421 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4422 a DWO CU, that this test will fail. */
4423 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4426 char *dwo_name
= DW_STRING (attr
);
4427 const char *comp_dir_string
;
4428 struct dwo_unit
*dwo_unit
;
4429 ULONGEST signature
; /* Or dwo_id. */
4430 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4431 int i
,num_extra_attrs
;
4432 struct dwarf2_section_info
*dwo_abbrev_section
;
4435 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4436 " has children (offset 0x%x) [in module %s]"),
4437 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4439 /* These attributes aren't processed until later:
4440 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4441 However, the attribute is found in the stub which we won't have later.
4442 In order to not impose this complication on the rest of the code,
4443 we read them here and copy them to the DWO CU/TU die. */
4445 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4448 if (! this_cu
->is_debug_types
)
4449 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4450 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4451 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4452 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4453 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4455 /* There should be a DW_AT_addr_base attribute here (if needed).
4456 We need the value before we can process DW_FORM_GNU_addr_index. */
4458 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4460 cu
->addr_base
= DW_UNSND (attr
);
4462 /* There should be a DW_AT_ranges_base attribute here (if needed).
4463 We need the value before we can process DW_AT_ranges. */
4464 cu
->ranges_base
= 0;
4465 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4467 cu
->ranges_base
= DW_UNSND (attr
);
4469 if (this_cu
->is_debug_types
)
4471 gdb_assert (sig_type
!= NULL
);
4472 signature
= sig_type
->signature
;
4476 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4478 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4480 signature
= DW_UNSND (attr
);
4483 /* We may need the comp_dir in order to find the DWO file. */
4484 comp_dir_string
= NULL
;
4486 comp_dir_string
= DW_STRING (comp_dir
);
4488 if (this_cu
->is_debug_types
)
4489 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4491 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4494 if (dwo_unit
== NULL
)
4496 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4497 " with ID %s [in module %s]"),
4498 this_cu
->offset
.sect_off
,
4499 phex (signature
, sizeof (signature
)),
4503 /* Set up for reading the DWO CU/TU. */
4504 cu
->dwo_unit
= dwo_unit
;
4505 section
= dwo_unit
->info_or_types_section
;
4506 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4507 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4508 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4510 if (this_cu
->is_debug_types
)
4514 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4518 gdb_assert (sig_type
->signature
== signature
);
4519 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4520 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4522 /* Establish the type offset that can be used to lookup the type.
4523 For DWO files, we don't know it until now. */
4524 sig_type
->type_offset_in_section
.sect_off
=
4525 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4529 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4532 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4533 gdb_assert (dwo_unit
->length
== get_cu_length (&cu
->header
));
4536 /* Discard the original CU's abbrev table, and read the DWO's. */
4537 if (abbrev_table
== NULL
)
4539 dwarf2_free_abbrev_table (cu
);
4540 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4544 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4545 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4548 /* Read in the die, but leave space to copy over the attributes
4549 from the stub. This has the benefit of simplifying the rest of
4550 the code - all the real work is done here. */
4551 num_extra_attrs
= ((stmt_list
!= NULL
)
4555 + (comp_dir
!= NULL
));
4556 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4557 &has_children
, num_extra_attrs
);
4559 /* Copy over the attributes from the stub to the DWO die. */
4560 i
= comp_unit_die
->num_attrs
;
4561 if (stmt_list
!= NULL
)
4562 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4564 comp_unit_die
->attrs
[i
++] = *low_pc
;
4565 if (high_pc
!= NULL
)
4566 comp_unit_die
->attrs
[i
++] = *high_pc
;
4568 comp_unit_die
->attrs
[i
++] = *ranges
;
4569 if (comp_dir
!= NULL
)
4570 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4571 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4573 /* Skip dummy compilation units. */
4574 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4575 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4577 do_cleanups (cleanups
);
4582 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4584 if (free_cu_cleanup
!= NULL
)
4588 /* We've successfully allocated this compilation unit. Let our
4589 caller clean it up when finished with it. */
4590 discard_cleanups (free_cu_cleanup
);
4592 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4593 So we have to manually free the abbrev table. */
4594 dwarf2_free_abbrev_table (cu
);
4596 /* Link this CU into read_in_chain. */
4597 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4598 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4601 do_cleanups (free_cu_cleanup
);
4604 do_cleanups (cleanups
);
4607 /* Read CU/TU THIS_CU in section SECTION,
4608 but do not follow DW_AT_GNU_dwo_name if present.
4609 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to
4610 have already done the lookup to find the DWO file).
4612 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4613 THIS_CU->is_debug_types, but nothing else.
4615 We fill in THIS_CU->length.
4617 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4618 linker) then DIE_READER_FUNC will not get called.
4620 THIS_CU->cu is always freed when done.
4621 This is done in order to not leave THIS_CU->cu in a state where we have
4622 to care whether it refers to the "main" CU or the DWO CU. */
4625 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4626 struct dwarf2_section_info
*abbrev_section
,
4627 struct dwo_file
*dwo_file
,
4628 die_reader_func_ftype
*die_reader_func
,
4631 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4632 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4633 bfd
*abfd
= section
->asection
->owner
;
4634 struct dwarf2_cu cu
;
4635 gdb_byte
*begin_info_ptr
, *info_ptr
;
4636 struct die_reader_specs reader
;
4637 struct cleanup
*cleanups
;
4638 struct die_info
*comp_unit_die
;
4641 if (dwarf2_die_debug
)
4642 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4643 this_cu
->is_debug_types
? "type" : "comp",
4644 this_cu
->offset
.sect_off
);
4646 gdb_assert (this_cu
->cu
== NULL
);
4648 /* This is cheap if the section is already read in. */
4649 dwarf2_read_section (objfile
, section
);
4651 init_one_comp_unit (&cu
, this_cu
);
4653 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4655 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4656 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4657 abbrev_section
, info_ptr
,
4658 this_cu
->is_debug_types
);
4660 this_cu
->length
= get_cu_length (&cu
.header
);
4662 /* Skip dummy compilation units. */
4663 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4664 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4666 do_cleanups (cleanups
);
4670 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4671 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4673 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4674 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4676 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4678 do_cleanups (cleanups
);
4681 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4682 does not lookup the specified DWO file.
4683 This cannot be used to read DWO files.
4685 THIS_CU->cu is always freed when done.
4686 This is done in order to not leave THIS_CU->cu in a state where we have
4687 to care whether it refers to the "main" CU or the DWO CU.
4688 We can revisit this if the data shows there's a performance issue. */
4691 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4692 die_reader_func_ftype
*die_reader_func
,
4695 init_cutu_and_read_dies_no_follow (this_cu
,
4696 get_abbrev_section_for_cu (this_cu
),
4698 die_reader_func
, data
);
4701 /* Create a psymtab named NAME and assign it to PER_CU.
4703 The caller must fill in the following details:
4704 dirname, textlow, texthigh. */
4706 static struct partial_symtab
*
4707 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4709 struct objfile
*objfile
= per_cu
->objfile
;
4710 struct partial_symtab
*pst
;
4712 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4714 objfile
->global_psymbols
.next
,
4715 objfile
->static_psymbols
.next
);
4717 pst
->psymtabs_addrmap_supported
= 1;
4719 /* This is the glue that links PST into GDB's symbol API. */
4720 pst
->read_symtab_private
= per_cu
;
4721 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4722 per_cu
->v
.psymtab
= pst
;
4727 /* die_reader_func for process_psymtab_comp_unit. */
4730 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4732 struct die_info
*comp_unit_die
,
4736 struct dwarf2_cu
*cu
= reader
->cu
;
4737 struct objfile
*objfile
= cu
->objfile
;
4738 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4739 struct attribute
*attr
;
4741 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4742 struct partial_symtab
*pst
;
4744 const char *filename
;
4745 int *want_partial_unit_ptr
= data
;
4747 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4748 && (want_partial_unit_ptr
== NULL
4749 || !*want_partial_unit_ptr
))
4752 gdb_assert (! per_cu
->is_debug_types
);
4754 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4756 cu
->list_in_scope
= &file_symbols
;
4758 /* Allocate a new partial symbol table structure. */
4759 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4760 if (attr
== NULL
|| !DW_STRING (attr
))
4763 filename
= DW_STRING (attr
);
4765 pst
= create_partial_symtab (per_cu
, filename
);
4767 /* This must be done before calling dwarf2_build_include_psymtabs. */
4768 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4770 pst
->dirname
= DW_STRING (attr
);
4772 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4774 dwarf2_find_base_address (comp_unit_die
, cu
);
4776 /* Possibly set the default values of LOWPC and HIGHPC from
4778 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4779 &best_highpc
, cu
, pst
);
4780 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4781 /* Store the contiguous range if it is not empty; it can be empty for
4782 CUs with no code. */
4783 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4784 best_lowpc
+ baseaddr
,
4785 best_highpc
+ baseaddr
- 1, pst
);
4787 /* Check if comp unit has_children.
4788 If so, read the rest of the partial symbols from this comp unit.
4789 If not, there's no more debug_info for this comp unit. */
4792 struct partial_die_info
*first_die
;
4793 CORE_ADDR lowpc
, highpc
;
4795 lowpc
= ((CORE_ADDR
) -1);
4796 highpc
= ((CORE_ADDR
) 0);
4798 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4800 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4803 /* If we didn't find a lowpc, set it to highpc to avoid
4804 complaints from `maint check'. */
4805 if (lowpc
== ((CORE_ADDR
) -1))
4808 /* If the compilation unit didn't have an explicit address range,
4809 then use the information extracted from its child dies. */
4813 best_highpc
= highpc
;
4816 pst
->textlow
= best_lowpc
+ baseaddr
;
4817 pst
->texthigh
= best_highpc
+ baseaddr
;
4819 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4820 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4821 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4822 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4823 sort_pst_symbols (pst
);
4825 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4828 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4829 struct dwarf2_per_cu_data
*iter
;
4831 /* Fill in 'dependencies' here; we fill in 'users' in a
4833 pst
->number_of_dependencies
= len
;
4834 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4835 len
* sizeof (struct symtab
*));
4837 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4840 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4842 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4845 /* Get the list of files included in the current compilation unit,
4846 and build a psymtab for each of them. */
4847 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4849 if (dwarf2_read_debug
)
4851 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4853 fprintf_unfiltered (gdb_stdlog
,
4854 "Psymtab for %s unit @0x%x: 0x%s - 0x%s"
4855 ", %d global, %d static syms\n",
4856 per_cu
->is_debug_types
? "type" : "comp",
4857 per_cu
->offset
.sect_off
,
4858 paddress (gdbarch
, pst
->textlow
),
4859 paddress (gdbarch
, pst
->texthigh
),
4860 pst
->n_global_syms
, pst
->n_static_syms
);
4864 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4865 Process compilation unit THIS_CU for a psymtab. */
4868 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4869 int want_partial_unit
)
4871 /* If this compilation unit was already read in, free the
4872 cached copy in order to read it in again. This is
4873 necessary because we skipped some symbols when we first
4874 read in the compilation unit (see load_partial_dies).
4875 This problem could be avoided, but the benefit is unclear. */
4876 if (this_cu
->cu
!= NULL
)
4877 free_one_cached_comp_unit (this_cu
);
4879 gdb_assert (! this_cu
->is_debug_types
);
4880 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4881 process_psymtab_comp_unit_reader
,
4882 &want_partial_unit
);
4884 /* Age out any secondary CUs. */
4885 age_cached_comp_units ();
4889 hash_type_unit_group (const void *item
)
4891 const struct type_unit_group
*tu_group
= item
;
4893 return hash_stmt_list_entry (&tu_group
->hash
);
4897 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
4899 const struct type_unit_group
*lhs
= item_lhs
;
4900 const struct type_unit_group
*rhs
= item_rhs
;
4902 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
4905 /* Allocate a hash table for type unit groups. */
4908 allocate_type_unit_groups_table (void)
4910 return htab_create_alloc_ex (3,
4911 hash_type_unit_group
,
4914 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
4915 hashtab_obstack_allocate
,
4916 dummy_obstack_deallocate
);
4919 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4920 partial symtabs. We combine several TUs per psymtab to not let the size
4921 of any one psymtab grow too big. */
4922 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4923 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4925 /* Helper routine for get_type_unit_group.
4926 Create the type_unit_group object used to hold one or more TUs. */
4928 static struct type_unit_group
*
4929 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
4931 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4932 struct dwarf2_per_cu_data
*per_cu
;
4933 struct type_unit_group
*tu_group
;
4935 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4936 struct type_unit_group
);
4937 per_cu
= &tu_group
->per_cu
;
4938 per_cu
->objfile
= objfile
;
4939 per_cu
->is_debug_types
= 1;
4940 per_cu
->s
.type_unit_group
= tu_group
;
4942 if (dwarf2_per_objfile
->using_index
)
4944 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4945 struct dwarf2_per_cu_quick_data
);
4946 tu_group
->t
.first_tu
= cu
->per_cu
;
4950 unsigned int line_offset
= line_offset_struct
.sect_off
;
4951 struct partial_symtab
*pst
;
4954 /* Give the symtab a useful name for debug purposes. */
4955 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
4956 name
= xstrprintf ("<type_units_%d>",
4957 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
4959 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
4961 pst
= create_partial_symtab (per_cu
, name
);
4967 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
4968 tu_group
->hash
.line_offset
= line_offset_struct
;
4973 /* Look up the type_unit_group for type unit CU, and create it if necessary.
4974 STMT_LIST is a DW_AT_stmt_list attribute. */
4976 static struct type_unit_group
*
4977 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
4979 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
4980 struct type_unit_group
*tu_group
;
4982 unsigned int line_offset
;
4983 struct type_unit_group type_unit_group_for_lookup
;
4985 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
4987 dwarf2_per_objfile
->type_unit_groups
=
4988 allocate_type_unit_groups_table ();
4991 /* Do we need to create a new group, or can we use an existing one? */
4995 line_offset
= DW_UNSND (stmt_list
);
4996 ++tu_stats
->nr_symtab_sharers
;
5000 /* Ugh, no stmt_list. Rare, but we have to handle it.
5001 We can do various things here like create one group per TU or
5002 spread them over multiple groups to split up the expansion work.
5003 To avoid worst case scenarios (too many groups or too large groups)
5004 we, umm, group them in bunches. */
5005 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5006 | (tu_stats
->nr_stmt_less_type_units
5007 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5008 ++tu_stats
->nr_stmt_less_type_units
;
5011 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5012 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5013 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5014 &type_unit_group_for_lookup
, INSERT
);
5018 gdb_assert (tu_group
!= NULL
);
5022 sect_offset line_offset_struct
;
5024 line_offset_struct
.sect_off
= line_offset
;
5025 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5027 ++tu_stats
->nr_symtabs
;
5033 /* Struct used to sort TUs by their abbreviation table offset. */
5035 struct tu_abbrev_offset
5037 struct signatured_type
*sig_type
;
5038 sect_offset abbrev_offset
;
5041 /* Helper routine for build_type_unit_groups, passed to qsort. */
5044 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5046 const struct tu_abbrev_offset
* const *a
= ap
;
5047 const struct tu_abbrev_offset
* const *b
= bp
;
5048 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5049 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5051 return (aoff
> boff
) - (aoff
< boff
);
5054 /* A helper function to add a type_unit_group to a table. */
5057 add_type_unit_group_to_table (void **slot
, void *datum
)
5059 struct type_unit_group
*tu_group
= *slot
;
5060 struct type_unit_group
***datap
= datum
;
5068 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5069 each one passing FUNC,DATA.
5071 The efficiency is because we sort TUs by the abbrev table they use and
5072 only read each abbrev table once. In one program there are 200K TUs
5073 sharing 8K abbrev tables.
5075 The main purpose of this function is to support building the
5076 dwarf2_per_objfile->type_unit_groups table.
5077 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5078 can collapse the search space by grouping them by stmt_list.
5079 The savings can be significant, in the same program from above the 200K TUs
5080 share 8K stmt_list tables.
5082 FUNC is expected to call get_type_unit_group, which will create the
5083 struct type_unit_group if necessary and add it to
5084 dwarf2_per_objfile->type_unit_groups. */
5087 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5089 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5090 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5091 struct cleanup
*cleanups
;
5092 struct abbrev_table
*abbrev_table
;
5093 sect_offset abbrev_offset
;
5094 struct tu_abbrev_offset
*sorted_by_abbrev
;
5095 struct type_unit_group
**iter
;
5098 /* It's up to the caller to not call us multiple times. */
5099 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5101 if (dwarf2_per_objfile
->n_type_units
== 0)
5104 /* TUs typically share abbrev tables, and there can be way more TUs than
5105 abbrev tables. Sort by abbrev table to reduce the number of times we
5106 read each abbrev table in.
5107 Alternatives are to punt or to maintain a cache of abbrev tables.
5108 This is simpler and efficient enough for now.
5110 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5111 symtab to use). Typically TUs with the same abbrev offset have the same
5112 stmt_list value too so in practice this should work well.
5114 The basic algorithm here is:
5116 sort TUs by abbrev table
5117 for each TU with same abbrev table:
5118 read abbrev table if first user
5119 read TU top level DIE
5120 [IWBN if DWO skeletons had DW_AT_stmt_list]
5123 if (dwarf2_read_debug
)
5124 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5126 /* Sort in a separate table to maintain the order of all_type_units
5127 for .gdb_index: TU indices directly index all_type_units. */
5128 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5129 dwarf2_per_objfile
->n_type_units
);
5130 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5132 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5134 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5135 sorted_by_abbrev
[i
].abbrev_offset
=
5136 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5137 sig_type
->per_cu
.offset
);
5139 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5140 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5141 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5143 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5144 called any number of times, so we don't reset tu_stats here. */
5146 abbrev_offset
.sect_off
= ~(unsigned) 0;
5147 abbrev_table
= NULL
;
5148 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5150 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5152 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5154 /* Switch to the next abbrev table if necessary. */
5155 if (abbrev_table
== NULL
5156 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5158 if (abbrev_table
!= NULL
)
5160 abbrev_table_free (abbrev_table
);
5161 /* Reset to NULL in case abbrev_table_read_table throws
5162 an error: abbrev_table_free_cleanup will get called. */
5163 abbrev_table
= NULL
;
5165 abbrev_offset
= tu
->abbrev_offset
;
5167 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5169 ++tu_stats
->nr_uniq_abbrev_tables
;
5172 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5176 /* Create a vector of pointers to primary type units to make it easy to
5177 iterate over them and CUs. See dw2_get_primary_cu. */
5178 dwarf2_per_objfile
->n_type_unit_groups
=
5179 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5180 dwarf2_per_objfile
->all_type_unit_groups
=
5181 obstack_alloc (&objfile
->objfile_obstack
,
5182 dwarf2_per_objfile
->n_type_unit_groups
5183 * sizeof (struct type_unit_group
*));
5184 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5185 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5186 add_type_unit_group_to_table
, &iter
);
5187 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5188 == dwarf2_per_objfile
->n_type_unit_groups
);
5190 do_cleanups (cleanups
);
5192 if (dwarf2_read_debug
)
5194 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5195 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5196 dwarf2_per_objfile
->n_type_units
);
5197 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5198 tu_stats
->nr_uniq_abbrev_tables
);
5199 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5200 tu_stats
->nr_symtabs
);
5201 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5202 tu_stats
->nr_symtab_sharers
);
5203 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5204 tu_stats
->nr_stmt_less_type_units
);
5208 /* Reader function for build_type_psymtabs. */
5211 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5213 struct die_info
*type_unit_die
,
5217 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5218 struct dwarf2_cu
*cu
= reader
->cu
;
5219 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5220 struct type_unit_group
*tu_group
;
5221 struct attribute
*attr
;
5222 struct partial_die_info
*first_die
;
5223 CORE_ADDR lowpc
, highpc
;
5224 struct partial_symtab
*pst
;
5226 gdb_assert (data
== NULL
);
5231 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5232 tu_group
= get_type_unit_group (cu
, attr
);
5234 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5236 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5237 cu
->list_in_scope
= &file_symbols
;
5238 pst
= create_partial_symtab (per_cu
, "");
5241 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5243 lowpc
= (CORE_ADDR
) -1;
5244 highpc
= (CORE_ADDR
) 0;
5245 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5247 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5248 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5249 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5250 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5251 sort_pst_symbols (pst
);
5254 /* Traversal function for build_type_psymtabs. */
5257 build_type_psymtab_dependencies (void **slot
, void *info
)
5259 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5260 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5261 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5262 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5263 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5264 struct dwarf2_per_cu_data
*iter
;
5267 gdb_assert (len
> 0);
5269 pst
->number_of_dependencies
= len
;
5270 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5271 len
* sizeof (struct psymtab
*));
5273 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5276 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5277 iter
->s
.type_unit_group
= tu_group
;
5280 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5285 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5286 Build partial symbol tables for the .debug_types comp-units. */
5289 build_type_psymtabs (struct objfile
*objfile
)
5291 if (! create_all_type_units (objfile
))
5294 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5296 /* Now that all TUs have been processed we can fill in the dependencies. */
5297 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5298 build_type_psymtab_dependencies
, NULL
);
5301 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5304 psymtabs_addrmap_cleanup (void *o
)
5306 struct objfile
*objfile
= o
;
5308 objfile
->psymtabs_addrmap
= NULL
;
5311 /* Compute the 'user' field for each psymtab in OBJFILE. */
5314 set_partial_user (struct objfile
*objfile
)
5318 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5320 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5321 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5327 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5329 /* Set the 'user' field only if it is not already set. */
5330 if (pst
->dependencies
[j
]->user
== NULL
)
5331 pst
->dependencies
[j
]->user
= pst
;
5336 /* Build the partial symbol table by doing a quick pass through the
5337 .debug_info and .debug_abbrev sections. */
5340 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5342 struct cleanup
*back_to
, *addrmap_cleanup
;
5343 struct obstack temp_obstack
;
5346 if (dwarf2_read_debug
)
5348 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5352 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5354 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5356 /* Any cached compilation units will be linked by the per-objfile
5357 read_in_chain. Make sure to free them when we're done. */
5358 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5360 build_type_psymtabs (objfile
);
5362 create_all_comp_units (objfile
);
5364 /* Create a temporary address map on a temporary obstack. We later
5365 copy this to the final obstack. */
5366 obstack_init (&temp_obstack
);
5367 make_cleanup_obstack_free (&temp_obstack
);
5368 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5369 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5371 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5373 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5375 process_psymtab_comp_unit (per_cu
, 0);
5378 set_partial_user (objfile
);
5380 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5381 &objfile
->objfile_obstack
);
5382 discard_cleanups (addrmap_cleanup
);
5384 do_cleanups (back_to
);
5386 if (dwarf2_read_debug
)
5387 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5391 /* die_reader_func for load_partial_comp_unit. */
5394 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5396 struct die_info
*comp_unit_die
,
5400 struct dwarf2_cu
*cu
= reader
->cu
;
5402 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5404 /* Check if comp unit has_children.
5405 If so, read the rest of the partial symbols from this comp unit.
5406 If not, there's no more debug_info for this comp unit. */
5408 load_partial_dies (reader
, info_ptr
, 0);
5411 /* Load the partial DIEs for a secondary CU into memory.
5412 This is also used when rereading a primary CU with load_all_dies. */
5415 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5417 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5418 load_partial_comp_unit_reader
, NULL
);
5422 read_comp_units_from_section (struct objfile
*objfile
,
5423 struct dwarf2_section_info
*section
,
5424 unsigned int is_dwz
,
5427 struct dwarf2_per_cu_data
***all_comp_units
)
5430 bfd
*abfd
= section
->asection
->owner
;
5432 dwarf2_read_section (objfile
, section
);
5434 info_ptr
= section
->buffer
;
5436 while (info_ptr
< section
->buffer
+ section
->size
)
5438 unsigned int length
, initial_length_size
;
5439 struct dwarf2_per_cu_data
*this_cu
;
5442 offset
.sect_off
= info_ptr
- section
->buffer
;
5444 /* Read just enough information to find out where the next
5445 compilation unit is. */
5446 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5448 /* Save the compilation unit for later lookup. */
5449 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5450 sizeof (struct dwarf2_per_cu_data
));
5451 memset (this_cu
, 0, sizeof (*this_cu
));
5452 this_cu
->offset
= offset
;
5453 this_cu
->length
= length
+ initial_length_size
;
5454 this_cu
->is_dwz
= is_dwz
;
5455 this_cu
->objfile
= objfile
;
5456 this_cu
->info_or_types_section
= section
;
5458 if (*n_comp_units
== *n_allocated
)
5461 *all_comp_units
= xrealloc (*all_comp_units
,
5463 * sizeof (struct dwarf2_per_cu_data
*));
5465 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5468 info_ptr
= info_ptr
+ this_cu
->length
;
5472 /* Create a list of all compilation units in OBJFILE.
5473 This is only done for -readnow and building partial symtabs. */
5476 create_all_comp_units (struct objfile
*objfile
)
5480 struct dwarf2_per_cu_data
**all_comp_units
;
5484 all_comp_units
= xmalloc (n_allocated
5485 * sizeof (struct dwarf2_per_cu_data
*));
5487 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5488 &n_allocated
, &n_comp_units
, &all_comp_units
);
5490 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5492 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5494 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5495 &n_allocated
, &n_comp_units
,
5499 dwarf2_per_objfile
->all_comp_units
5500 = obstack_alloc (&objfile
->objfile_obstack
,
5501 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5502 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5503 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5504 xfree (all_comp_units
);
5505 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5508 /* Process all loaded DIEs for compilation unit CU, starting at
5509 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5510 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5511 DW_AT_ranges). If NEED_PC is set, then this function will set
5512 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5513 and record the covered ranges in the addrmap. */
5516 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5517 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5519 struct partial_die_info
*pdi
;
5521 /* Now, march along the PDI's, descending into ones which have
5522 interesting children but skipping the children of the other ones,
5523 until we reach the end of the compilation unit. */
5529 fixup_partial_die (pdi
, cu
);
5531 /* Anonymous namespaces or modules have no name but have interesting
5532 children, so we need to look at them. Ditto for anonymous
5535 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5536 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5537 || pdi
->tag
== DW_TAG_imported_unit
)
5541 case DW_TAG_subprogram
:
5542 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5544 case DW_TAG_constant
:
5545 case DW_TAG_variable
:
5546 case DW_TAG_typedef
:
5547 case DW_TAG_union_type
:
5548 if (!pdi
->is_declaration
)
5550 add_partial_symbol (pdi
, cu
);
5553 case DW_TAG_class_type
:
5554 case DW_TAG_interface_type
:
5555 case DW_TAG_structure_type
:
5556 if (!pdi
->is_declaration
)
5558 add_partial_symbol (pdi
, cu
);
5561 case DW_TAG_enumeration_type
:
5562 if (!pdi
->is_declaration
)
5563 add_partial_enumeration (pdi
, cu
);
5565 case DW_TAG_base_type
:
5566 case DW_TAG_subrange_type
:
5567 /* File scope base type definitions are added to the partial
5569 add_partial_symbol (pdi
, cu
);
5571 case DW_TAG_namespace
:
5572 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5575 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5577 case DW_TAG_imported_unit
:
5579 struct dwarf2_per_cu_data
*per_cu
;
5581 /* For now we don't handle imported units in type units. */
5582 if (cu
->per_cu
->is_debug_types
)
5584 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5585 " supported in type units [in module %s]"),
5589 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5593 /* Go read the partial unit, if needed. */
5594 if (per_cu
->v
.psymtab
== NULL
)
5595 process_psymtab_comp_unit (per_cu
, 1);
5597 VEC_safe_push (dwarf2_per_cu_ptr
,
5598 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5606 /* If the die has a sibling, skip to the sibling. */
5608 pdi
= pdi
->die_sibling
;
5612 /* Functions used to compute the fully scoped name of a partial DIE.
5614 Normally, this is simple. For C++, the parent DIE's fully scoped
5615 name is concatenated with "::" and the partial DIE's name. For
5616 Java, the same thing occurs except that "." is used instead of "::".
5617 Enumerators are an exception; they use the scope of their parent
5618 enumeration type, i.e. the name of the enumeration type is not
5619 prepended to the enumerator.
5621 There are two complexities. One is DW_AT_specification; in this
5622 case "parent" means the parent of the target of the specification,
5623 instead of the direct parent of the DIE. The other is compilers
5624 which do not emit DW_TAG_namespace; in this case we try to guess
5625 the fully qualified name of structure types from their members'
5626 linkage names. This must be done using the DIE's children rather
5627 than the children of any DW_AT_specification target. We only need
5628 to do this for structures at the top level, i.e. if the target of
5629 any DW_AT_specification (if any; otherwise the DIE itself) does not
5632 /* Compute the scope prefix associated with PDI's parent, in
5633 compilation unit CU. The result will be allocated on CU's
5634 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5635 field. NULL is returned if no prefix is necessary. */
5637 partial_die_parent_scope (struct partial_die_info
*pdi
,
5638 struct dwarf2_cu
*cu
)
5640 char *grandparent_scope
;
5641 struct partial_die_info
*parent
, *real_pdi
;
5643 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5644 then this means the parent of the specification DIE. */
5647 while (real_pdi
->has_specification
)
5648 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5649 real_pdi
->spec_is_dwz
, cu
);
5651 parent
= real_pdi
->die_parent
;
5655 if (parent
->scope_set
)
5656 return parent
->scope
;
5658 fixup_partial_die (parent
, cu
);
5660 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5662 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5663 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5664 Work around this problem here. */
5665 if (cu
->language
== language_cplus
5666 && parent
->tag
== DW_TAG_namespace
5667 && strcmp (parent
->name
, "::") == 0
5668 && grandparent_scope
== NULL
)
5670 parent
->scope
= NULL
;
5671 parent
->scope_set
= 1;
5675 if (pdi
->tag
== DW_TAG_enumerator
)
5676 /* Enumerators should not get the name of the enumeration as a prefix. */
5677 parent
->scope
= grandparent_scope
;
5678 else if (parent
->tag
== DW_TAG_namespace
5679 || parent
->tag
== DW_TAG_module
5680 || parent
->tag
== DW_TAG_structure_type
5681 || parent
->tag
== DW_TAG_class_type
5682 || parent
->tag
== DW_TAG_interface_type
5683 || parent
->tag
== DW_TAG_union_type
5684 || parent
->tag
== DW_TAG_enumeration_type
)
5686 if (grandparent_scope
== NULL
)
5687 parent
->scope
= parent
->name
;
5689 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5691 parent
->name
, 0, cu
);
5695 /* FIXME drow/2004-04-01: What should we be doing with
5696 function-local names? For partial symbols, we should probably be
5698 complaint (&symfile_complaints
,
5699 _("unhandled containing DIE tag %d for DIE at %d"),
5700 parent
->tag
, pdi
->offset
.sect_off
);
5701 parent
->scope
= grandparent_scope
;
5704 parent
->scope_set
= 1;
5705 return parent
->scope
;
5708 /* Return the fully scoped name associated with PDI, from compilation unit
5709 CU. The result will be allocated with malloc. */
5712 partial_die_full_name (struct partial_die_info
*pdi
,
5713 struct dwarf2_cu
*cu
)
5717 /* If this is a template instantiation, we can not work out the
5718 template arguments from partial DIEs. So, unfortunately, we have
5719 to go through the full DIEs. At least any work we do building
5720 types here will be reused if full symbols are loaded later. */
5721 if (pdi
->has_template_arguments
)
5723 fixup_partial_die (pdi
, cu
);
5725 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5727 struct die_info
*die
;
5728 struct attribute attr
;
5729 struct dwarf2_cu
*ref_cu
= cu
;
5731 /* DW_FORM_ref_addr is using section offset. */
5733 attr
.form
= DW_FORM_ref_addr
;
5734 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5735 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5737 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5741 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5742 if (parent_scope
== NULL
)
5745 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5749 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5751 struct objfile
*objfile
= cu
->objfile
;
5753 char *actual_name
= NULL
;
5755 int built_actual_name
= 0;
5757 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5759 actual_name
= partial_die_full_name (pdi
, cu
);
5761 built_actual_name
= 1;
5763 if (actual_name
== NULL
)
5764 actual_name
= pdi
->name
;
5768 case DW_TAG_subprogram
:
5769 if (pdi
->is_external
|| cu
->language
== language_ada
)
5771 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5772 of the global scope. But in Ada, we want to be able to access
5773 nested procedures globally. So all Ada subprograms are stored
5774 in the global scope. */
5775 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5776 mst_text, objfile); */
5777 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5779 VAR_DOMAIN
, LOC_BLOCK
,
5780 &objfile
->global_psymbols
,
5781 0, pdi
->lowpc
+ baseaddr
,
5782 cu
->language
, objfile
);
5786 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5787 mst_file_text, objfile); */
5788 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5790 VAR_DOMAIN
, LOC_BLOCK
,
5791 &objfile
->static_psymbols
,
5792 0, pdi
->lowpc
+ baseaddr
,
5793 cu
->language
, objfile
);
5796 case DW_TAG_constant
:
5798 struct psymbol_allocation_list
*list
;
5800 if (pdi
->is_external
)
5801 list
= &objfile
->global_psymbols
;
5803 list
= &objfile
->static_psymbols
;
5804 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5805 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5806 list
, 0, 0, cu
->language
, objfile
);
5809 case DW_TAG_variable
:
5811 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5815 && !dwarf2_per_objfile
->has_section_at_zero
)
5817 /* A global or static variable may also have been stripped
5818 out by the linker if unused, in which case its address
5819 will be nullified; do not add such variables into partial
5820 symbol table then. */
5822 else if (pdi
->is_external
)
5825 Don't enter into the minimal symbol tables as there is
5826 a minimal symbol table entry from the ELF symbols already.
5827 Enter into partial symbol table if it has a location
5828 descriptor or a type.
5829 If the location descriptor is missing, new_symbol will create
5830 a LOC_UNRESOLVED symbol, the address of the variable will then
5831 be determined from the minimal symbol table whenever the variable
5833 The address for the partial symbol table entry is not
5834 used by GDB, but it comes in handy for debugging partial symbol
5837 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5838 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5840 VAR_DOMAIN
, LOC_STATIC
,
5841 &objfile
->global_psymbols
,
5843 cu
->language
, objfile
);
5847 /* Static Variable. Skip symbols without location descriptors. */
5848 if (pdi
->d
.locdesc
== NULL
)
5850 if (built_actual_name
)
5851 xfree (actual_name
);
5854 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5855 mst_file_data, objfile); */
5856 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5858 VAR_DOMAIN
, LOC_STATIC
,
5859 &objfile
->static_psymbols
,
5861 cu
->language
, objfile
);
5864 case DW_TAG_typedef
:
5865 case DW_TAG_base_type
:
5866 case DW_TAG_subrange_type
:
5867 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5869 VAR_DOMAIN
, LOC_TYPEDEF
,
5870 &objfile
->static_psymbols
,
5871 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5873 case DW_TAG_namespace
:
5874 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5876 VAR_DOMAIN
, LOC_TYPEDEF
,
5877 &objfile
->global_psymbols
,
5878 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5880 case DW_TAG_class_type
:
5881 case DW_TAG_interface_type
:
5882 case DW_TAG_structure_type
:
5883 case DW_TAG_union_type
:
5884 case DW_TAG_enumeration_type
:
5885 /* Skip external references. The DWARF standard says in the section
5886 about "Structure, Union, and Class Type Entries": "An incomplete
5887 structure, union or class type is represented by a structure,
5888 union or class entry that does not have a byte size attribute
5889 and that has a DW_AT_declaration attribute." */
5890 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5892 if (built_actual_name
)
5893 xfree (actual_name
);
5897 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5898 static vs. global. */
5899 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5901 STRUCT_DOMAIN
, LOC_TYPEDEF
,
5902 (cu
->language
== language_cplus
5903 || cu
->language
== language_java
)
5904 ? &objfile
->global_psymbols
5905 : &objfile
->static_psymbols
,
5906 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5909 case DW_TAG_enumerator
:
5910 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5912 VAR_DOMAIN
, LOC_CONST
,
5913 (cu
->language
== language_cplus
5914 || cu
->language
== language_java
)
5915 ? &objfile
->global_psymbols
5916 : &objfile
->static_psymbols
,
5917 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5923 if (built_actual_name
)
5924 xfree (actual_name
);
5927 /* Read a partial die corresponding to a namespace; also, add a symbol
5928 corresponding to that namespace to the symbol table. NAMESPACE is
5929 the name of the enclosing namespace. */
5932 add_partial_namespace (struct partial_die_info
*pdi
,
5933 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5934 int need_pc
, struct dwarf2_cu
*cu
)
5936 /* Add a symbol for the namespace. */
5938 add_partial_symbol (pdi
, cu
);
5940 /* Now scan partial symbols in that namespace. */
5942 if (pdi
->has_children
)
5943 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5946 /* Read a partial die corresponding to a Fortran module. */
5949 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
5950 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5952 /* Now scan partial symbols in that module. */
5954 if (pdi
->has_children
)
5955 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
5958 /* Read a partial die corresponding to a subprogram and create a partial
5959 symbol for that subprogram. When the CU language allows it, this
5960 routine also defines a partial symbol for each nested subprogram
5961 that this subprogram contains.
5963 DIE my also be a lexical block, in which case we simply search
5964 recursively for suprograms defined inside that lexical block.
5965 Again, this is only performed when the CU language allows this
5966 type of definitions. */
5969 add_partial_subprogram (struct partial_die_info
*pdi
,
5970 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5971 int need_pc
, struct dwarf2_cu
*cu
)
5973 if (pdi
->tag
== DW_TAG_subprogram
)
5975 if (pdi
->has_pc_info
)
5977 if (pdi
->lowpc
< *lowpc
)
5978 *lowpc
= pdi
->lowpc
;
5979 if (pdi
->highpc
> *highpc
)
5980 *highpc
= pdi
->highpc
;
5984 struct objfile
*objfile
= cu
->objfile
;
5986 baseaddr
= ANOFFSET (objfile
->section_offsets
,
5987 SECT_OFF_TEXT (objfile
));
5988 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5989 pdi
->lowpc
+ baseaddr
,
5990 pdi
->highpc
- 1 + baseaddr
,
5991 cu
->per_cu
->v
.psymtab
);
5995 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
5997 if (!pdi
->is_declaration
)
5998 /* Ignore subprogram DIEs that do not have a name, they are
5999 illegal. Do not emit a complaint at this point, we will
6000 do so when we convert this psymtab into a symtab. */
6002 add_partial_symbol (pdi
, cu
);
6006 if (! pdi
->has_children
)
6009 if (cu
->language
== language_ada
)
6011 pdi
= pdi
->die_child
;
6014 fixup_partial_die (pdi
, cu
);
6015 if (pdi
->tag
== DW_TAG_subprogram
6016 || pdi
->tag
== DW_TAG_lexical_block
)
6017 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6018 pdi
= pdi
->die_sibling
;
6023 /* Read a partial die corresponding to an enumeration type. */
6026 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6027 struct dwarf2_cu
*cu
)
6029 struct partial_die_info
*pdi
;
6031 if (enum_pdi
->name
!= NULL
)
6032 add_partial_symbol (enum_pdi
, cu
);
6034 pdi
= enum_pdi
->die_child
;
6037 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6038 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6040 add_partial_symbol (pdi
, cu
);
6041 pdi
= pdi
->die_sibling
;
6045 /* Return the initial uleb128 in the die at INFO_PTR. */
6048 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6050 unsigned int bytes_read
;
6052 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6055 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6056 Return the corresponding abbrev, or NULL if the number is zero (indicating
6057 an empty DIE). In either case *BYTES_READ will be set to the length of
6058 the initial number. */
6060 static struct abbrev_info
*
6061 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6062 struct dwarf2_cu
*cu
)
6064 bfd
*abfd
= cu
->objfile
->obfd
;
6065 unsigned int abbrev_number
;
6066 struct abbrev_info
*abbrev
;
6068 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6070 if (abbrev_number
== 0)
6073 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6076 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6077 abbrev_number
, bfd_get_filename (abfd
));
6083 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6084 Returns a pointer to the end of a series of DIEs, terminated by an empty
6085 DIE. Any children of the skipped DIEs will also be skipped. */
6088 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6090 struct dwarf2_cu
*cu
= reader
->cu
;
6091 struct abbrev_info
*abbrev
;
6092 unsigned int bytes_read
;
6096 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6098 return info_ptr
+ bytes_read
;
6100 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6104 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6105 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6106 abbrev corresponding to that skipped uleb128 should be passed in
6107 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6111 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6112 struct abbrev_info
*abbrev
)
6114 unsigned int bytes_read
;
6115 struct attribute attr
;
6116 bfd
*abfd
= reader
->abfd
;
6117 struct dwarf2_cu
*cu
= reader
->cu
;
6118 gdb_byte
*buffer
= reader
->buffer
;
6119 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6120 gdb_byte
*start_info_ptr
= info_ptr
;
6121 unsigned int form
, i
;
6123 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6125 /* The only abbrev we care about is DW_AT_sibling. */
6126 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6128 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6129 if (attr
.form
== DW_FORM_ref_addr
)
6130 complaint (&symfile_complaints
,
6131 _("ignoring absolute DW_AT_sibling"));
6133 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6136 /* If it isn't DW_AT_sibling, skip this attribute. */
6137 form
= abbrev
->attrs
[i
].form
;
6141 case DW_FORM_ref_addr
:
6142 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6143 and later it is offset sized. */
6144 if (cu
->header
.version
== 2)
6145 info_ptr
+= cu
->header
.addr_size
;
6147 info_ptr
+= cu
->header
.offset_size
;
6149 case DW_FORM_GNU_ref_alt
:
6150 info_ptr
+= cu
->header
.offset_size
;
6153 info_ptr
+= cu
->header
.addr_size
;
6160 case DW_FORM_flag_present
:
6172 case DW_FORM_ref_sig8
:
6175 case DW_FORM_string
:
6176 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6177 info_ptr
+= bytes_read
;
6179 case DW_FORM_sec_offset
:
6181 case DW_FORM_GNU_strp_alt
:
6182 info_ptr
+= cu
->header
.offset_size
;
6184 case DW_FORM_exprloc
:
6186 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6187 info_ptr
+= bytes_read
;
6189 case DW_FORM_block1
:
6190 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6192 case DW_FORM_block2
:
6193 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6195 case DW_FORM_block4
:
6196 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6200 case DW_FORM_ref_udata
:
6201 case DW_FORM_GNU_addr_index
:
6202 case DW_FORM_GNU_str_index
:
6203 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6205 case DW_FORM_indirect
:
6206 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6207 info_ptr
+= bytes_read
;
6208 /* We need to continue parsing from here, so just go back to
6210 goto skip_attribute
;
6213 error (_("Dwarf Error: Cannot handle %s "
6214 "in DWARF reader [in module %s]"),
6215 dwarf_form_name (form
),
6216 bfd_get_filename (abfd
));
6220 if (abbrev
->has_children
)
6221 return skip_children (reader
, info_ptr
);
6226 /* Locate ORIG_PDI's sibling.
6227 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6230 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6231 struct partial_die_info
*orig_pdi
,
6234 /* Do we know the sibling already? */
6236 if (orig_pdi
->sibling
)
6237 return orig_pdi
->sibling
;
6239 /* Are there any children to deal with? */
6241 if (!orig_pdi
->has_children
)
6244 /* Skip the children the long way. */
6246 return skip_children (reader
, info_ptr
);
6249 /* Expand this partial symbol table into a full symbol table. */
6252 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6258 warning (_("bug: psymtab for %s is already read in."),
6265 printf_filtered (_("Reading in symbols for %s..."),
6267 gdb_flush (gdb_stdout
);
6270 /* Restore our global data. */
6271 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6272 dwarf2_objfile_data_key
);
6274 /* If this psymtab is constructed from a debug-only objfile, the
6275 has_section_at_zero flag will not necessarily be correct. We
6276 can get the correct value for this flag by looking at the data
6277 associated with the (presumably stripped) associated objfile. */
6278 if (pst
->objfile
->separate_debug_objfile_backlink
)
6280 struct dwarf2_per_objfile
*dpo_backlink
6281 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6282 dwarf2_objfile_data_key
);
6284 dwarf2_per_objfile
->has_section_at_zero
6285 = dpo_backlink
->has_section_at_zero
;
6288 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6290 psymtab_to_symtab_1 (pst
);
6292 /* Finish up the debug error message. */
6294 printf_filtered (_("done.\n"));
6298 process_cu_includes ();
6301 /* Reading in full CUs. */
6303 /* Add PER_CU to the queue. */
6306 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6307 enum language pretend_language
)
6309 struct dwarf2_queue_item
*item
;
6312 item
= xmalloc (sizeof (*item
));
6313 item
->per_cu
= per_cu
;
6314 item
->pretend_language
= pretend_language
;
6317 if (dwarf2_queue
== NULL
)
6318 dwarf2_queue
= item
;
6320 dwarf2_queue_tail
->next
= item
;
6322 dwarf2_queue_tail
= item
;
6325 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6326 unit and add it to our queue.
6327 The result is non-zero if PER_CU was queued, otherwise the result is zero
6328 meaning either PER_CU is already queued or it is already loaded. */
6331 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6332 struct dwarf2_per_cu_data
*per_cu
,
6333 enum language pretend_language
)
6335 /* We may arrive here during partial symbol reading, if we need full
6336 DIEs to process an unusual case (e.g. template arguments). Do
6337 not queue PER_CU, just tell our caller to load its DIEs. */
6338 if (dwarf2_per_objfile
->reading_partial_symbols
)
6340 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6345 /* Mark the dependence relation so that we don't flush PER_CU
6347 dwarf2_add_dependence (this_cu
, per_cu
);
6349 /* If it's already on the queue, we have nothing to do. */
6353 /* If the compilation unit is already loaded, just mark it as
6355 if (per_cu
->cu
!= NULL
)
6357 per_cu
->cu
->last_used
= 0;
6361 /* Add it to the queue. */
6362 queue_comp_unit (per_cu
, pretend_language
);
6367 /* Process the queue. */
6370 process_queue (void)
6372 struct dwarf2_queue_item
*item
, *next_item
;
6374 if (dwarf2_read_debug
)
6376 fprintf_unfiltered (gdb_stdlog
,
6377 "Expanding one or more symtabs of objfile %s ...\n",
6378 dwarf2_per_objfile
->objfile
->name
);
6381 /* The queue starts out with one item, but following a DIE reference
6382 may load a new CU, adding it to the end of the queue. */
6383 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6385 if (dwarf2_per_objfile
->using_index
6386 ? !item
->per_cu
->v
.quick
->symtab
6387 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6389 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6391 if (dwarf2_read_debug
)
6393 fprintf_unfiltered (gdb_stdlog
,
6394 "Expanding symtab of %s at offset 0x%x\n",
6395 per_cu
->is_debug_types
? "TU" : "CU",
6396 per_cu
->offset
.sect_off
);
6399 if (per_cu
->is_debug_types
)
6400 process_full_type_unit (per_cu
, item
->pretend_language
);
6402 process_full_comp_unit (per_cu
, item
->pretend_language
);
6404 if (dwarf2_read_debug
)
6406 fprintf_unfiltered (gdb_stdlog
,
6407 "Done expanding %s at offset 0x%x\n",
6408 per_cu
->is_debug_types
? "TU" : "CU",
6409 per_cu
->offset
.sect_off
);
6413 item
->per_cu
->queued
= 0;
6414 next_item
= item
->next
;
6418 dwarf2_queue_tail
= NULL
;
6420 if (dwarf2_read_debug
)
6422 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6423 dwarf2_per_objfile
->objfile
->name
);
6427 /* Free all allocated queue entries. This function only releases anything if
6428 an error was thrown; if the queue was processed then it would have been
6429 freed as we went along. */
6432 dwarf2_release_queue (void *dummy
)
6434 struct dwarf2_queue_item
*item
, *last
;
6436 item
= dwarf2_queue
;
6439 /* Anything still marked queued is likely to be in an
6440 inconsistent state, so discard it. */
6441 if (item
->per_cu
->queued
)
6443 if (item
->per_cu
->cu
!= NULL
)
6444 free_one_cached_comp_unit (item
->per_cu
);
6445 item
->per_cu
->queued
= 0;
6453 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6456 /* Read in full symbols for PST, and anything it depends on. */
6459 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6461 struct dwarf2_per_cu_data
*per_cu
;
6467 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6468 if (!pst
->dependencies
[i
]->readin
6469 && pst
->dependencies
[i
]->user
== NULL
)
6471 /* Inform about additional files that need to be read in. */
6474 /* FIXME: i18n: Need to make this a single string. */
6475 fputs_filtered (" ", gdb_stdout
);
6477 fputs_filtered ("and ", gdb_stdout
);
6479 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6480 wrap_here (""); /* Flush output. */
6481 gdb_flush (gdb_stdout
);
6483 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6486 per_cu
= pst
->read_symtab_private
;
6490 /* It's an include file, no symbols to read for it.
6491 Everything is in the parent symtab. */
6496 dw2_do_instantiate_symtab (per_cu
);
6499 /* Trivial hash function for die_info: the hash value of a DIE
6500 is its offset in .debug_info for this objfile. */
6503 die_hash (const void *item
)
6505 const struct die_info
*die
= item
;
6507 return die
->offset
.sect_off
;
6510 /* Trivial comparison function for die_info structures: two DIEs
6511 are equal if they have the same offset. */
6514 die_eq (const void *item_lhs
, const void *item_rhs
)
6516 const struct die_info
*die_lhs
= item_lhs
;
6517 const struct die_info
*die_rhs
= item_rhs
;
6519 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6522 /* die_reader_func for load_full_comp_unit.
6523 This is identical to read_signatured_type_reader,
6524 but is kept separate for now. */
6527 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6529 struct die_info
*comp_unit_die
,
6533 struct dwarf2_cu
*cu
= reader
->cu
;
6534 enum language
*language_ptr
= data
;
6536 gdb_assert (cu
->die_hash
== NULL
);
6538 htab_create_alloc_ex (cu
->header
.length
/ 12,
6542 &cu
->comp_unit_obstack
,
6543 hashtab_obstack_allocate
,
6544 dummy_obstack_deallocate
);
6547 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6548 &info_ptr
, comp_unit_die
);
6549 cu
->dies
= comp_unit_die
;
6550 /* comp_unit_die is not stored in die_hash, no need. */
6552 /* We try not to read any attributes in this function, because not
6553 all CUs needed for references have been loaded yet, and symbol
6554 table processing isn't initialized. But we have to set the CU language,
6555 or we won't be able to build types correctly.
6556 Similarly, if we do not read the producer, we can not apply
6557 producer-specific interpretation. */
6558 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6561 /* Load the DIEs associated with PER_CU into memory. */
6564 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6565 enum language pretend_language
)
6567 gdb_assert (! this_cu
->is_debug_types
);
6569 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6570 load_full_comp_unit_reader
, &pretend_language
);
6573 /* Add a DIE to the delayed physname list. */
6576 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6577 const char *name
, struct die_info
*die
,
6578 struct dwarf2_cu
*cu
)
6580 struct delayed_method_info mi
;
6582 mi
.fnfield_index
= fnfield_index
;
6586 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6589 /* A cleanup for freeing the delayed method list. */
6592 free_delayed_list (void *ptr
)
6594 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6595 if (cu
->method_list
!= NULL
)
6597 VEC_free (delayed_method_info
, cu
->method_list
);
6598 cu
->method_list
= NULL
;
6602 /* Compute the physnames of any methods on the CU's method list.
6604 The computation of method physnames is delayed in order to avoid the
6605 (bad) condition that one of the method's formal parameters is of an as yet
6609 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6612 struct delayed_method_info
*mi
;
6613 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6615 const char *physname
;
6616 struct fn_fieldlist
*fn_flp
6617 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6618 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6619 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6623 /* Go objects should be embedded in a DW_TAG_module DIE,
6624 and it's not clear if/how imported objects will appear.
6625 To keep Go support simple until that's worked out,
6626 go back through what we've read and create something usable.
6627 We could do this while processing each DIE, and feels kinda cleaner,
6628 but that way is more invasive.
6629 This is to, for example, allow the user to type "p var" or "b main"
6630 without having to specify the package name, and allow lookups
6631 of module.object to work in contexts that use the expression
6635 fixup_go_packaging (struct dwarf2_cu
*cu
)
6637 char *package_name
= NULL
;
6638 struct pending
*list
;
6641 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6643 for (i
= 0; i
< list
->nsyms
; ++i
)
6645 struct symbol
*sym
= list
->symbol
[i
];
6647 if (SYMBOL_LANGUAGE (sym
) == language_go
6648 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6650 char *this_package_name
= go_symbol_package_name (sym
);
6652 if (this_package_name
== NULL
)
6654 if (package_name
== NULL
)
6655 package_name
= this_package_name
;
6658 if (strcmp (package_name
, this_package_name
) != 0)
6659 complaint (&symfile_complaints
,
6660 _("Symtab %s has objects from two different Go packages: %s and %s"),
6661 (sym
->symtab
&& sym
->symtab
->filename
6662 ? sym
->symtab
->filename
6663 : cu
->objfile
->name
),
6664 this_package_name
, package_name
);
6665 xfree (this_package_name
);
6671 if (package_name
!= NULL
)
6673 struct objfile
*objfile
= cu
->objfile
;
6674 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6675 package_name
, objfile
);
6678 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6680 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6681 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6682 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6683 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6684 e.g., "main" finds the "main" module and not C's main(). */
6685 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6686 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6687 SYMBOL_TYPE (sym
) = type
;
6689 add_symbol_to_list (sym
, &global_symbols
);
6691 xfree (package_name
);
6695 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6697 /* Return the symtab for PER_CU. This works properly regardless of
6698 whether we're using the index or psymtabs. */
6700 static struct symtab
*
6701 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6703 return (dwarf2_per_objfile
->using_index
6704 ? per_cu
->v
.quick
->symtab
6705 : per_cu
->v
.psymtab
->symtab
);
6708 /* A helper function for computing the list of all symbol tables
6709 included by PER_CU. */
6712 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6713 htab_t all_children
,
6714 struct dwarf2_per_cu_data
*per_cu
)
6718 struct dwarf2_per_cu_data
*iter
;
6720 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6723 /* This inclusion and its children have been processed. */
6728 /* Only add a CU if it has a symbol table. */
6729 if (get_symtab (per_cu
) != NULL
)
6730 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6733 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6735 recursively_compute_inclusions (result
, all_children
, iter
);
6738 /* Compute the symtab 'includes' fields for the symtab related to
6742 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6744 gdb_assert (! per_cu
->is_debug_types
);
6746 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6749 struct dwarf2_per_cu_data
*iter
;
6750 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6751 htab_t all_children
;
6752 struct symtab
*symtab
= get_symtab (per_cu
);
6754 /* If we don't have a symtab, we can just skip this case. */
6758 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6759 NULL
, xcalloc
, xfree
);
6762 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6765 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6767 /* Now we have a transitive closure of all the included CUs, so
6768 we can convert it to a list of symtabs. */
6769 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6771 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6772 (len
+ 1) * sizeof (struct symtab
*));
6774 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6776 symtab
->includes
[ix
] = get_symtab (iter
);
6777 symtab
->includes
[len
] = NULL
;
6779 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6780 htab_delete (all_children
);
6784 /* Compute the 'includes' field for the symtabs of all the CUs we just
6788 process_cu_includes (void)
6791 struct dwarf2_per_cu_data
*iter
;
6794 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6798 if (! iter
->is_debug_types
)
6799 compute_symtab_includes (iter
);
6802 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6805 /* Generate full symbol information for PER_CU, whose DIEs have
6806 already been loaded into memory. */
6809 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6810 enum language pretend_language
)
6812 struct dwarf2_cu
*cu
= per_cu
->cu
;
6813 struct objfile
*objfile
= per_cu
->objfile
;
6814 CORE_ADDR lowpc
, highpc
;
6815 struct symtab
*symtab
;
6816 struct cleanup
*back_to
, *delayed_list_cleanup
;
6818 struct block
*static_block
;
6820 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6823 back_to
= make_cleanup (really_free_pendings
, NULL
);
6824 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6826 cu
->list_in_scope
= &file_symbols
;
6828 cu
->language
= pretend_language
;
6829 cu
->language_defn
= language_def (cu
->language
);
6831 /* Do line number decoding in read_file_scope () */
6832 process_die (cu
->dies
, cu
);
6834 /* For now fudge the Go package. */
6835 if (cu
->language
== language_go
)
6836 fixup_go_packaging (cu
);
6838 /* Now that we have processed all the DIEs in the CU, all the types
6839 should be complete, and it should now be safe to compute all of the
6841 compute_delayed_physnames (cu
);
6842 do_cleanups (delayed_list_cleanup
);
6844 /* Some compilers don't define a DW_AT_high_pc attribute for the
6845 compilation unit. If the DW_AT_high_pc is missing, synthesize
6846 it, by scanning the DIE's below the compilation unit. */
6847 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6850 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
6851 per_cu
->s
.imported_symtabs
!= NULL
);
6853 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6854 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6855 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6856 addrmap to help ensure it has an accurate map of pc values belonging to
6858 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6860 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6861 SECT_OFF_TEXT (objfile
), 0);
6865 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6867 /* Set symtab language to language from DW_AT_language. If the
6868 compilation is from a C file generated by language preprocessors, do
6869 not set the language if it was already deduced by start_subfile. */
6870 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6871 symtab
->language
= cu
->language
;
6873 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6874 produce DW_AT_location with location lists but it can be possibly
6875 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6876 there were bugs in prologue debug info, fixed later in GCC-4.5
6877 by "unwind info for epilogues" patch (which is not directly related).
6879 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6880 needed, it would be wrong due to missing DW_AT_producer there.
6882 Still one can confuse GDB by using non-standard GCC compilation
6883 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6885 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6886 symtab
->locations_valid
= 1;
6888 if (gcc_4_minor
>= 5)
6889 symtab
->epilogue_unwind_valid
= 1;
6891 symtab
->call_site_htab
= cu
->call_site_htab
;
6894 if (dwarf2_per_objfile
->using_index
)
6895 per_cu
->v
.quick
->symtab
= symtab
;
6898 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6899 pst
->symtab
= symtab
;
6903 /* Push it for inclusion processing later. */
6904 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
6906 do_cleanups (back_to
);
6909 /* Generate full symbol information for type unit PER_CU, whose DIEs have
6910 already been loaded into memory. */
6913 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
6914 enum language pretend_language
)
6916 struct dwarf2_cu
*cu
= per_cu
->cu
;
6917 struct objfile
*objfile
= per_cu
->objfile
;
6918 struct symtab
*symtab
;
6919 struct cleanup
*back_to
, *delayed_list_cleanup
;
6922 back_to
= make_cleanup (really_free_pendings
, NULL
);
6923 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6925 cu
->list_in_scope
= &file_symbols
;
6927 cu
->language
= pretend_language
;
6928 cu
->language_defn
= language_def (cu
->language
);
6930 /* The symbol tables are set up in read_type_unit_scope. */
6931 process_die (cu
->dies
, cu
);
6933 /* For now fudge the Go package. */
6934 if (cu
->language
== language_go
)
6935 fixup_go_packaging (cu
);
6937 /* Now that we have processed all the DIEs in the CU, all the types
6938 should be complete, and it should now be safe to compute all of the
6940 compute_delayed_physnames (cu
);
6941 do_cleanups (delayed_list_cleanup
);
6943 /* TUs share symbol tables.
6944 If this is the first TU to use this symtab, complete the construction
6945 of it with end_expandable_symtab. Otherwise, complete the addition of
6946 this TU's symbols to the existing symtab. */
6947 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
6949 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
6950 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
6954 /* Set symtab language to language from DW_AT_language. If the
6955 compilation is from a C file generated by language preprocessors,
6956 do not set the language if it was already deduced by
6958 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6959 symtab
->language
= cu
->language
;
6964 augment_type_symtab (objfile
,
6965 per_cu
->s
.type_unit_group
->primary_symtab
);
6966 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
6969 if (dwarf2_per_objfile
->using_index
)
6970 per_cu
->v
.quick
->symtab
= symtab
;
6973 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
6974 pst
->symtab
= symtab
;
6978 do_cleanups (back_to
);
6981 /* Process an imported unit DIE. */
6984 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
6986 struct attribute
*attr
;
6988 /* For now we don't handle imported units in type units. */
6989 if (cu
->per_cu
->is_debug_types
)
6991 error (_("Dwarf Error: DW_TAG_imported_unit is not"
6992 " supported in type units [in module %s]"),
6996 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
6999 struct dwarf2_per_cu_data
*per_cu
;
7000 struct symtab
*imported_symtab
;
7004 offset
= dwarf2_get_ref_die_offset (attr
);
7005 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7006 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7008 /* Queue the unit, if needed. */
7009 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7010 load_full_comp_unit (per_cu
, cu
->language
);
7012 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7017 /* Process a die and its children. */
7020 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7024 case DW_TAG_padding
:
7026 case DW_TAG_compile_unit
:
7027 case DW_TAG_partial_unit
:
7028 read_file_scope (die
, cu
);
7030 case DW_TAG_type_unit
:
7031 read_type_unit_scope (die
, cu
);
7033 case DW_TAG_subprogram
:
7034 case DW_TAG_inlined_subroutine
:
7035 read_func_scope (die
, cu
);
7037 case DW_TAG_lexical_block
:
7038 case DW_TAG_try_block
:
7039 case DW_TAG_catch_block
:
7040 read_lexical_block_scope (die
, cu
);
7042 case DW_TAG_GNU_call_site
:
7043 read_call_site_scope (die
, cu
);
7045 case DW_TAG_class_type
:
7046 case DW_TAG_interface_type
:
7047 case DW_TAG_structure_type
:
7048 case DW_TAG_union_type
:
7049 process_structure_scope (die
, cu
);
7051 case DW_TAG_enumeration_type
:
7052 process_enumeration_scope (die
, cu
);
7055 /* These dies have a type, but processing them does not create
7056 a symbol or recurse to process the children. Therefore we can
7057 read them on-demand through read_type_die. */
7058 case DW_TAG_subroutine_type
:
7059 case DW_TAG_set_type
:
7060 case DW_TAG_array_type
:
7061 case DW_TAG_pointer_type
:
7062 case DW_TAG_ptr_to_member_type
:
7063 case DW_TAG_reference_type
:
7064 case DW_TAG_string_type
:
7067 case DW_TAG_base_type
:
7068 case DW_TAG_subrange_type
:
7069 case DW_TAG_typedef
:
7070 /* Add a typedef symbol for the type definition, if it has a
7072 new_symbol (die
, read_type_die (die
, cu
), cu
);
7074 case DW_TAG_common_block
:
7075 read_common_block (die
, cu
);
7077 case DW_TAG_common_inclusion
:
7079 case DW_TAG_namespace
:
7080 processing_has_namespace_info
= 1;
7081 read_namespace (die
, cu
);
7084 processing_has_namespace_info
= 1;
7085 read_module (die
, cu
);
7087 case DW_TAG_imported_declaration
:
7088 case DW_TAG_imported_module
:
7089 processing_has_namespace_info
= 1;
7090 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7091 || cu
->language
!= language_fortran
))
7092 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7093 dwarf_tag_name (die
->tag
));
7094 read_import_statement (die
, cu
);
7097 case DW_TAG_imported_unit
:
7098 process_imported_unit_die (die
, cu
);
7102 new_symbol (die
, NULL
, cu
);
7107 /* A helper function for dwarf2_compute_name which determines whether DIE
7108 needs to have the name of the scope prepended to the name listed in the
7112 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7114 struct attribute
*attr
;
7118 case DW_TAG_namespace
:
7119 case DW_TAG_typedef
:
7120 case DW_TAG_class_type
:
7121 case DW_TAG_interface_type
:
7122 case DW_TAG_structure_type
:
7123 case DW_TAG_union_type
:
7124 case DW_TAG_enumeration_type
:
7125 case DW_TAG_enumerator
:
7126 case DW_TAG_subprogram
:
7130 case DW_TAG_variable
:
7131 case DW_TAG_constant
:
7132 /* We only need to prefix "globally" visible variables. These include
7133 any variable marked with DW_AT_external or any variable that
7134 lives in a namespace. [Variables in anonymous namespaces
7135 require prefixing, but they are not DW_AT_external.] */
7137 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7139 struct dwarf2_cu
*spec_cu
= cu
;
7141 return die_needs_namespace (die_specification (die
, &spec_cu
),
7145 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7146 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7147 && die
->parent
->tag
!= DW_TAG_module
)
7149 /* A variable in a lexical block of some kind does not need a
7150 namespace, even though in C++ such variables may be external
7151 and have a mangled name. */
7152 if (die
->parent
->tag
== DW_TAG_lexical_block
7153 || die
->parent
->tag
== DW_TAG_try_block
7154 || die
->parent
->tag
== DW_TAG_catch_block
7155 || die
->parent
->tag
== DW_TAG_subprogram
)
7164 /* Retrieve the last character from a mem_file. */
7167 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7169 char *last_char_p
= (char *) object
;
7172 *last_char_p
= buffer
[length
- 1];
7175 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7176 compute the physname for the object, which include a method's:
7177 - formal parameters (C++/Java),
7178 - receiver type (Go),
7179 - return type (Java).
7181 The term "physname" is a bit confusing.
7182 For C++, for example, it is the demangled name.
7183 For Go, for example, it's the mangled name.
7185 For Ada, return the DIE's linkage name rather than the fully qualified
7186 name. PHYSNAME is ignored..
7188 The result is allocated on the objfile_obstack and canonicalized. */
7191 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7194 struct objfile
*objfile
= cu
->objfile
;
7197 name
= dwarf2_name (die
, cu
);
7199 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7200 compute it by typename_concat inside GDB. */
7201 if (cu
->language
== language_ada
7202 || (cu
->language
== language_fortran
&& physname
))
7204 /* For Ada unit, we prefer the linkage name over the name, as
7205 the former contains the exported name, which the user expects
7206 to be able to reference. Ideally, we want the user to be able
7207 to reference this entity using either natural or linkage name,
7208 but we haven't started looking at this enhancement yet. */
7209 struct attribute
*attr
;
7211 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7213 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7214 if (attr
&& DW_STRING (attr
))
7215 return DW_STRING (attr
);
7218 /* These are the only languages we know how to qualify names in. */
7220 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7221 || cu
->language
== language_fortran
))
7223 if (die_needs_namespace (die
, cu
))
7227 struct ui_file
*buf
;
7229 prefix
= determine_prefix (die
, cu
);
7230 buf
= mem_fileopen ();
7231 if (*prefix
!= '\0')
7233 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7236 fputs_unfiltered (prefixed_name
, buf
);
7237 xfree (prefixed_name
);
7240 fputs_unfiltered (name
, buf
);
7242 /* Template parameters may be specified in the DIE's DW_AT_name, or
7243 as children with DW_TAG_template_type_param or
7244 DW_TAG_value_type_param. If the latter, add them to the name
7245 here. If the name already has template parameters, then
7246 skip this step; some versions of GCC emit both, and
7247 it is more efficient to use the pre-computed name.
7249 Something to keep in mind about this process: it is very
7250 unlikely, or in some cases downright impossible, to produce
7251 something that will match the mangled name of a function.
7252 If the definition of the function has the same debug info,
7253 we should be able to match up with it anyway. But fallbacks
7254 using the minimal symbol, for instance to find a method
7255 implemented in a stripped copy of libstdc++, will not work.
7256 If we do not have debug info for the definition, we will have to
7257 match them up some other way.
7259 When we do name matching there is a related problem with function
7260 templates; two instantiated function templates are allowed to
7261 differ only by their return types, which we do not add here. */
7263 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7265 struct attribute
*attr
;
7266 struct die_info
*child
;
7269 die
->building_fullname
= 1;
7271 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7276 struct dwarf2_locexpr_baton
*baton
;
7279 if (child
->tag
!= DW_TAG_template_type_param
7280 && child
->tag
!= DW_TAG_template_value_param
)
7285 fputs_unfiltered ("<", buf
);
7289 fputs_unfiltered (", ", buf
);
7291 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7294 complaint (&symfile_complaints
,
7295 _("template parameter missing DW_AT_type"));
7296 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7299 type
= die_type (child
, cu
);
7301 if (child
->tag
== DW_TAG_template_type_param
)
7303 c_print_type (type
, "", buf
, -1, 0);
7307 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7310 complaint (&symfile_complaints
,
7311 _("template parameter missing "
7312 "DW_AT_const_value"));
7313 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7317 dwarf2_const_value_attr (attr
, type
, name
,
7318 &cu
->comp_unit_obstack
, cu
,
7319 &value
, &bytes
, &baton
);
7321 if (TYPE_NOSIGN (type
))
7322 /* GDB prints characters as NUMBER 'CHAR'. If that's
7323 changed, this can use value_print instead. */
7324 c_printchar (value
, type
, buf
);
7327 struct value_print_options opts
;
7330 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7334 else if (bytes
!= NULL
)
7336 v
= allocate_value (type
);
7337 memcpy (value_contents_writeable (v
), bytes
,
7338 TYPE_LENGTH (type
));
7341 v
= value_from_longest (type
, value
);
7343 /* Specify decimal so that we do not depend on
7345 get_formatted_print_options (&opts
, 'd');
7347 value_print (v
, buf
, &opts
);
7353 die
->building_fullname
= 0;
7357 /* Close the argument list, with a space if necessary
7358 (nested templates). */
7359 char last_char
= '\0';
7360 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7361 if (last_char
== '>')
7362 fputs_unfiltered (" >", buf
);
7364 fputs_unfiltered (">", buf
);
7368 /* For Java and C++ methods, append formal parameter type
7369 information, if PHYSNAME. */
7371 if (physname
&& die
->tag
== DW_TAG_subprogram
7372 && (cu
->language
== language_cplus
7373 || cu
->language
== language_java
))
7375 struct type
*type
= read_type_die (die
, cu
);
7377 c_type_print_args (type
, buf
, 1, cu
->language
);
7379 if (cu
->language
== language_java
)
7381 /* For java, we must append the return type to method
7383 if (die
->tag
== DW_TAG_subprogram
)
7384 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7387 else if (cu
->language
== language_cplus
)
7389 /* Assume that an artificial first parameter is
7390 "this", but do not crash if it is not. RealView
7391 marks unnamed (and thus unused) parameters as
7392 artificial; there is no way to differentiate
7394 if (TYPE_NFIELDS (type
) > 0
7395 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7396 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7397 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7399 fputs_unfiltered (" const", buf
);
7403 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7405 ui_file_delete (buf
);
7407 if (cu
->language
== language_cplus
)
7410 = dwarf2_canonicalize_name (name
, cu
,
7411 &objfile
->objfile_obstack
);
7422 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7423 If scope qualifiers are appropriate they will be added. The result
7424 will be allocated on the objfile_obstack, or NULL if the DIE does
7425 not have a name. NAME may either be from a previous call to
7426 dwarf2_name or NULL.
7428 The output string will be canonicalized (if C++/Java). */
7431 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7433 return dwarf2_compute_name (name
, die
, cu
, 0);
7436 /* Construct a physname for the given DIE in CU. NAME may either be
7437 from a previous call to dwarf2_name or NULL. The result will be
7438 allocated on the objfile_objstack or NULL if the DIE does not have a
7441 The output string will be canonicalized (if C++/Java). */
7444 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7446 struct objfile
*objfile
= cu
->objfile
;
7447 struct attribute
*attr
;
7448 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7449 struct cleanup
*back_to
;
7452 /* In this case dwarf2_compute_name is just a shortcut not building anything
7454 if (!die_needs_namespace (die
, cu
))
7455 return dwarf2_compute_name (name
, die
, cu
, 1);
7457 back_to
= make_cleanup (null_cleanup
, NULL
);
7459 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7461 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7463 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7465 if (attr
&& DW_STRING (attr
))
7469 mangled
= DW_STRING (attr
);
7471 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7472 type. It is easier for GDB users to search for such functions as
7473 `name(params)' than `long name(params)'. In such case the minimal
7474 symbol names do not match the full symbol names but for template
7475 functions there is never a need to look up their definition from their
7476 declaration so the only disadvantage remains the minimal symbol
7477 variant `long name(params)' does not have the proper inferior type.
7480 if (cu
->language
== language_go
)
7482 /* This is a lie, but we already lie to the caller new_symbol_full.
7483 new_symbol_full assumes we return the mangled name.
7484 This just undoes that lie until things are cleaned up. */
7489 demangled
= cplus_demangle (mangled
,
7490 (DMGL_PARAMS
| DMGL_ANSI
7491 | (cu
->language
== language_java
7492 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7497 make_cleanup (xfree
, demangled
);
7507 if (canon
== NULL
|| check_physname
)
7509 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7511 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7513 /* It may not mean a bug in GDB. The compiler could also
7514 compute DW_AT_linkage_name incorrectly. But in such case
7515 GDB would need to be bug-to-bug compatible. */
7517 complaint (&symfile_complaints
,
7518 _("Computed physname <%s> does not match demangled <%s> "
7519 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7520 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7522 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7523 is available here - over computed PHYSNAME. It is safer
7524 against both buggy GDB and buggy compilers. */
7538 retval
= obsavestring (retval
, strlen (retval
),
7539 &objfile
->objfile_obstack
);
7541 do_cleanups (back_to
);
7545 /* Read the import statement specified by the given die and record it. */
7548 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7550 struct objfile
*objfile
= cu
->objfile
;
7551 struct attribute
*import_attr
;
7552 struct die_info
*imported_die
, *child_die
;
7553 struct dwarf2_cu
*imported_cu
;
7554 const char *imported_name
;
7555 const char *imported_name_prefix
;
7556 const char *canonical_name
;
7557 const char *import_alias
;
7558 const char *imported_declaration
= NULL
;
7559 const char *import_prefix
;
7560 VEC (const_char_ptr
) *excludes
= NULL
;
7561 struct cleanup
*cleanups
;
7565 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7566 if (import_attr
== NULL
)
7568 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7569 dwarf_tag_name (die
->tag
));
7574 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7575 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7576 if (imported_name
== NULL
)
7578 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7580 The import in the following code:
7594 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7595 <52> DW_AT_decl_file : 1
7596 <53> DW_AT_decl_line : 6
7597 <54> DW_AT_import : <0x75>
7598 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7600 <5b> DW_AT_decl_file : 1
7601 <5c> DW_AT_decl_line : 2
7602 <5d> DW_AT_type : <0x6e>
7604 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7605 <76> DW_AT_byte_size : 4
7606 <77> DW_AT_encoding : 5 (signed)
7608 imports the wrong die ( 0x75 instead of 0x58 ).
7609 This case will be ignored until the gcc bug is fixed. */
7613 /* Figure out the local name after import. */
7614 import_alias
= dwarf2_name (die
, cu
);
7616 /* Figure out where the statement is being imported to. */
7617 import_prefix
= determine_prefix (die
, cu
);
7619 /* Figure out what the scope of the imported die is and prepend it
7620 to the name of the imported die. */
7621 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7623 if (imported_die
->tag
!= DW_TAG_namespace
7624 && imported_die
->tag
!= DW_TAG_module
)
7626 imported_declaration
= imported_name
;
7627 canonical_name
= imported_name_prefix
;
7629 else if (strlen (imported_name_prefix
) > 0)
7631 temp
= alloca (strlen (imported_name_prefix
)
7632 + 2 + strlen (imported_name
) + 1);
7633 strcpy (temp
, imported_name_prefix
);
7634 strcat (temp
, "::");
7635 strcat (temp
, imported_name
);
7636 canonical_name
= temp
;
7639 canonical_name
= imported_name
;
7641 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7643 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7644 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7645 child_die
= sibling_die (child_die
))
7647 /* DWARF-4: A Fortran use statement with a “rename list” may be
7648 represented by an imported module entry with an import attribute
7649 referring to the module and owned entries corresponding to those
7650 entities that are renamed as part of being imported. */
7652 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7654 complaint (&symfile_complaints
,
7655 _("child DW_TAG_imported_declaration expected "
7656 "- DIE at 0x%x [in module %s]"),
7657 child_die
->offset
.sect_off
, objfile
->name
);
7661 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7662 if (import_attr
== NULL
)
7664 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7665 dwarf_tag_name (child_die
->tag
));
7670 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7672 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7673 if (imported_name
== NULL
)
7675 complaint (&symfile_complaints
,
7676 _("child DW_TAG_imported_declaration has unknown "
7677 "imported name - DIE at 0x%x [in module %s]"),
7678 child_die
->offset
.sect_off
, objfile
->name
);
7682 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7684 process_die (child_die
, cu
);
7687 cp_add_using_directive (import_prefix
,
7690 imported_declaration
,
7692 &objfile
->objfile_obstack
);
7694 do_cleanups (cleanups
);
7697 /* Cleanup function for handle_DW_AT_stmt_list. */
7700 free_cu_line_header (void *arg
)
7702 struct dwarf2_cu
*cu
= arg
;
7704 free_line_header (cu
->line_header
);
7705 cu
->line_header
= NULL
;
7709 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7710 char **name
, char **comp_dir
)
7712 struct attribute
*attr
;
7717 /* Find the filename. Do not use dwarf2_name here, since the filename
7718 is not a source language identifier. */
7719 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7722 *name
= DW_STRING (attr
);
7725 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7727 *comp_dir
= DW_STRING (attr
);
7728 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
7730 *comp_dir
= ldirname (*name
);
7731 if (*comp_dir
!= NULL
)
7732 make_cleanup (xfree
, *comp_dir
);
7734 if (*comp_dir
!= NULL
)
7736 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7737 directory, get rid of it. */
7738 char *cp
= strchr (*comp_dir
, ':');
7740 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7745 *name
= "<unknown>";
7748 /* Handle DW_AT_stmt_list for a compilation unit.
7749 DIE is the DW_TAG_compile_unit die for CU.
7750 COMP_DIR is the compilation directory.
7751 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7754 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7755 const char *comp_dir
)
7757 struct attribute
*attr
;
7759 gdb_assert (! cu
->per_cu
->is_debug_types
);
7761 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7764 unsigned int line_offset
= DW_UNSND (attr
);
7765 struct line_header
*line_header
7766 = dwarf_decode_line_header (line_offset
, cu
);
7770 cu
->line_header
= line_header
;
7771 make_cleanup (free_cu_line_header
, cu
);
7772 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7777 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7780 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7782 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7783 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7784 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7785 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7786 struct attribute
*attr
;
7788 char *comp_dir
= NULL
;
7789 struct die_info
*child_die
;
7790 bfd
*abfd
= objfile
->obfd
;
7793 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7795 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7797 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7798 from finish_block. */
7799 if (lowpc
== ((CORE_ADDR
) -1))
7804 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7806 prepare_one_comp_unit (cu
, die
, cu
->language
);
7808 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7809 standardised yet. As a workaround for the language detection we fall
7810 back to the DW_AT_producer string. */
7811 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7812 cu
->language
= language_opencl
;
7814 /* Similar hack for Go. */
7815 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7816 set_cu_language (DW_LANG_Go
, cu
);
7818 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7820 /* Decode line number information if present. We do this before
7821 processing child DIEs, so that the line header table is available
7822 for DW_AT_decl_file. */
7823 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7825 /* Process all dies in compilation unit. */
7826 if (die
->child
!= NULL
)
7828 child_die
= die
->child
;
7829 while (child_die
&& child_die
->tag
)
7831 process_die (child_die
, cu
);
7832 child_die
= sibling_die (child_die
);
7836 /* Decode macro information, if present. Dwarf 2 macro information
7837 refers to information in the line number info statement program
7838 header, so we can only read it if we've read the header
7840 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7841 if (attr
&& cu
->line_header
)
7843 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7844 complaint (&symfile_complaints
,
7845 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7847 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7851 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7852 if (attr
&& cu
->line_header
)
7854 unsigned int macro_offset
= DW_UNSND (attr
);
7856 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7860 do_cleanups (back_to
);
7863 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7864 Create the set of symtabs used by this TU, or if this TU is sharing
7865 symtabs with another TU and the symtabs have already been created
7866 then restore those symtabs in the line header.
7867 We don't need the pc/line-number mapping for type units. */
7870 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7872 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7873 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7874 struct type_unit_group
*tu_group
;
7876 struct line_header
*lh
;
7877 struct attribute
*attr
;
7878 unsigned int i
, line_offset
;
7880 gdb_assert (per_cu
->is_debug_types
);
7882 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7884 /* If we're using .gdb_index (includes -readnow) then
7885 per_cu->s.type_unit_group may not have been set up yet. */
7886 if (per_cu
->s
.type_unit_group
== NULL
)
7887 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
7888 tu_group
= per_cu
->s
.type_unit_group
;
7890 /* If we've already processed this stmt_list there's no real need to
7891 do it again, we could fake it and just recreate the part we need
7892 (file name,index -> symtab mapping). If data shows this optimization
7893 is useful we can do it then. */
7894 first_time
= tu_group
->primary_symtab
== NULL
;
7896 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7901 line_offset
= DW_UNSND (attr
);
7902 lh
= dwarf_decode_line_header (line_offset
, cu
);
7907 dwarf2_start_symtab (cu
, "", NULL
, 0);
7910 gdb_assert (tu_group
->symtabs
== NULL
);
7913 /* Note: The primary symtab will get allocated at the end. */
7917 cu
->line_header
= lh
;
7918 make_cleanup (free_cu_line_header
, cu
);
7922 dwarf2_start_symtab (cu
, "", NULL
, 0);
7924 tu_group
->num_symtabs
= lh
->num_file_names
;
7925 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
7927 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7930 struct file_entry
*fe
= &lh
->file_names
[i
];
7933 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7934 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
7936 /* Note: We don't have to watch for the main subfile here, type units
7937 don't have DW_AT_name. */
7939 if (current_subfile
->symtab
== NULL
)
7941 /* NOTE: start_subfile will recognize when it's been passed
7942 a file it has already seen. So we can't assume there's a
7943 simple mapping from lh->file_names to subfiles,
7944 lh->file_names may contain dups. */
7945 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7949 fe
->symtab
= current_subfile
->symtab
;
7950 tu_group
->symtabs
[i
] = fe
->symtab
;
7957 for (i
= 0; i
< lh
->num_file_names
; ++i
)
7959 struct file_entry
*fe
= &lh
->file_names
[i
];
7961 fe
->symtab
= tu_group
->symtabs
[i
];
7965 /* The main symtab is allocated last. Type units don't have DW_AT_name
7966 so they don't have a "real" (so to speak) symtab anyway.
7967 There is later code that will assign the main symtab to all symbols
7968 that don't have one. We need to handle the case of a symbol with a
7969 missing symtab (DW_AT_decl_file) anyway. */
7972 /* Process DW_TAG_type_unit.
7973 For TUs we want to skip the first top level sibling if it's not the
7974 actual type being defined by this TU. In this case the first top
7975 level sibling is there to provide context only. */
7978 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7980 struct die_info
*child_die
;
7982 prepare_one_comp_unit (cu
, die
, language_minimal
);
7984 /* Initialize (or reinitialize) the machinery for building symtabs.
7985 We do this before processing child DIEs, so that the line header table
7986 is available for DW_AT_decl_file. */
7987 setup_type_unit_groups (die
, cu
);
7989 if (die
->child
!= NULL
)
7991 child_die
= die
->child
;
7992 while (child_die
&& child_die
->tag
)
7994 process_die (child_die
, cu
);
7995 child_die
= sibling_die (child_die
);
8003 hash_dwo_file (const void *item
)
8005 const struct dwo_file
*dwo_file
= item
;
8007 return htab_hash_string (dwo_file
->dwo_name
);
8011 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8013 const struct dwo_file
*lhs
= item_lhs
;
8014 const struct dwo_file
*rhs
= item_rhs
;
8016 return strcmp (lhs
->dwo_name
, rhs
->dwo_name
) == 0;
8019 /* Allocate a hash table for DWO files. */
8022 allocate_dwo_file_hash_table (void)
8024 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8026 return htab_create_alloc_ex (41,
8030 &objfile
->objfile_obstack
,
8031 hashtab_obstack_allocate
,
8032 dummy_obstack_deallocate
);
8036 hash_dwo_unit (const void *item
)
8038 const struct dwo_unit
*dwo_unit
= item
;
8040 /* This drops the top 32 bits of the id, but is ok for a hash. */
8041 return dwo_unit
->signature
;
8045 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8047 const struct dwo_unit
*lhs
= item_lhs
;
8048 const struct dwo_unit
*rhs
= item_rhs
;
8050 /* The signature is assumed to be unique within the DWO file.
8051 So while object file CU dwo_id's always have the value zero,
8052 that's OK, assuming each object file DWO file has only one CU,
8053 and that's the rule for now. */
8054 return lhs
->signature
== rhs
->signature
;
8057 /* Allocate a hash table for DWO CUs,TUs.
8058 There is one of these tables for each of CUs,TUs for each DWO file. */
8061 allocate_dwo_unit_table (struct objfile
*objfile
)
8063 /* Start out with a pretty small number.
8064 Generally DWO files contain only one CU and maybe some TUs. */
8065 return htab_create_alloc_ex (3,
8069 &objfile
->objfile_obstack
,
8070 hashtab_obstack_allocate
,
8071 dummy_obstack_deallocate
);
8074 /* This function is mapped across the sections and remembers the offset and
8075 size of each of the DWO debugging sections we are interested in. */
8078 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_file_ptr
)
8080 struct dwo_file
*dwo_file
= dwo_file_ptr
;
8081 const struct dwo_section_names
*names
= &dwo_section_names
;
8083 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8085 dwo_file
->sections
.abbrev
.asection
= sectp
;
8086 dwo_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
8088 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8090 dwo_file
->sections
.info
.asection
= sectp
;
8091 dwo_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
8093 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8095 dwo_file
->sections
.line
.asection
= sectp
;
8096 dwo_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
8098 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8100 dwo_file
->sections
.loc
.asection
= sectp
;
8101 dwo_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
8103 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8105 dwo_file
->sections
.macinfo
.asection
= sectp
;
8106 dwo_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
8108 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8110 dwo_file
->sections
.macro
.asection
= sectp
;
8111 dwo_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
8113 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8115 dwo_file
->sections
.str
.asection
= sectp
;
8116 dwo_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8118 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8120 dwo_file
->sections
.str_offsets
.asection
= sectp
;
8121 dwo_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
8123 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8125 struct dwarf2_section_info type_section
;
8127 memset (&type_section
, 0, sizeof (type_section
));
8128 type_section
.asection
= sectp
;
8129 type_section
.size
= bfd_get_section_size (sectp
);
8130 VEC_safe_push (dwarf2_section_info_def
, dwo_file
->sections
.types
,
8135 /* Structure used to pass data to create_debug_info_hash_table_reader. */
8137 struct create_dwo_info_table_data
8139 struct dwo_file
*dwo_file
;
8143 /* die_reader_func for create_debug_info_hash_table. */
8146 create_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8148 struct die_info
*comp_unit_die
,
8152 struct dwarf2_cu
*cu
= reader
->cu
;
8153 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8154 sect_offset offset
= cu
->per_cu
->offset
;
8155 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8156 struct create_dwo_info_table_data
*data
= datap
;
8157 struct dwo_file
*dwo_file
= data
->dwo_file
;
8158 htab_t cu_htab
= data
->cu_htab
;
8160 struct attribute
*attr
;
8161 struct dwo_unit
*dwo_unit
;
8163 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8166 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8167 " its dwo_id [in module %s]"),
8168 offset
.sect_off
, dwo_file
->dwo_name
);
8172 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8173 dwo_unit
->dwo_file
= dwo_file
;
8174 dwo_unit
->signature
= DW_UNSND (attr
);
8175 dwo_unit
->info_or_types_section
= section
;
8176 dwo_unit
->offset
= offset
;
8177 dwo_unit
->length
= cu
->per_cu
->length
;
8179 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8180 gdb_assert (slot
!= NULL
);
8183 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8185 complaint (&symfile_complaints
,
8186 _("debug entry at offset 0x%x is duplicate to the entry at"
8187 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8188 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8189 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8190 dwo_file
->dwo_name
);
8195 if (dwarf2_read_debug
)
8196 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8198 phex (dwo_unit
->signature
,
8199 sizeof (dwo_unit
->signature
)));
8202 /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */
8205 create_debug_info_hash_table (struct dwo_file
*dwo_file
)
8207 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8208 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8211 gdb_byte
*info_ptr
, *end_ptr
;
8212 struct create_dwo_info_table_data create_dwo_info_table_data
;
8214 dwarf2_read_section (objfile
, section
);
8215 info_ptr
= section
->buffer
;
8217 if (info_ptr
== NULL
)
8220 /* We can't set abfd until now because the section may be empty or
8221 not present, in which case section->asection will be NULL. */
8222 abfd
= section
->asection
->owner
;
8224 if (dwarf2_read_debug
)
8225 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8226 bfd_get_filename (abfd
));
8228 cu_htab
= allocate_dwo_unit_table (objfile
);
8230 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8231 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8233 end_ptr
= info_ptr
+ section
->size
;
8234 while (info_ptr
< end_ptr
)
8236 struct dwarf2_per_cu_data per_cu
;
8238 memset (&per_cu
, 0, sizeof (per_cu
));
8239 per_cu
.objfile
= objfile
;
8240 per_cu
.is_debug_types
= 0;
8241 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8242 per_cu
.info_or_types_section
= section
;
8244 init_cutu_and_read_dies_no_follow (&per_cu
,
8245 &dwo_file
->sections
.abbrev
,
8247 create_debug_info_hash_table_reader
,
8248 &create_dwo_info_table_data
);
8250 info_ptr
+= per_cu
.length
;
8256 /* Subroutine of open_dwo_file to simplify it.
8257 Open the file specified by FILE_NAME and hand it off to BFD for
8258 preliminary analysis. Return a newly initialized bfd *, which
8259 includes a canonicalized copy of FILE_NAME.
8260 In case of trouble, return NULL.
8261 NOTE: This function is derived from symfile_bfd_open. */
8264 try_open_dwo_file (const char *file_name
)
8268 char *absolute_name
;
8270 desc
= openp (debug_file_directory
, OPF_TRY_CWD_FIRST
, file_name
,
8271 O_RDONLY
| O_BINARY
, &absolute_name
);
8275 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8278 xfree (absolute_name
);
8281 gdb_bfd_stash_filename (sym_bfd
);
8282 xfree (absolute_name
);
8283 bfd_set_cacheable (sym_bfd
, 1);
8285 if (!bfd_check_format (sym_bfd
, bfd_object
))
8287 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8294 /* Try to open DWO file DWO_NAME.
8295 COMP_DIR is the DW_AT_comp_dir attribute.
8296 The result is the bfd handle of the file.
8297 If there is a problem finding or opening the file, return NULL.
8298 Upon success, the canonicalized path of the file is stored in the bfd,
8299 same as symfile_bfd_open. */
8302 open_dwo_file (const char *dwo_name
, const char *comp_dir
)
8306 if (IS_ABSOLUTE_PATH (dwo_name
))
8307 return try_open_dwo_file (dwo_name
);
8309 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8311 if (comp_dir
!= NULL
)
8313 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, dwo_name
, NULL
);
8315 /* NOTE: If comp_dir is a relative path, this will also try the
8316 search path, which seems useful. */
8317 abfd
= try_open_dwo_file (path_to_try
);
8318 xfree (path_to_try
);
8323 /* That didn't work, try debug-file-directory, which, despite its name,
8324 is a list of paths. */
8326 if (*debug_file_directory
== '\0')
8329 return try_open_dwo_file (dwo_name
);
8332 /* Initialize the use of the DWO file specified by DWO_NAME. */
8334 static struct dwo_file
*
8335 init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8337 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8338 struct dwo_file
*dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8341 struct cleanup
*cleanups
;
8343 if (dwarf2_read_debug
)
8344 fprintf_unfiltered (gdb_stdlog
, "Reading DWO file %s:\n", dwo_name
);
8346 abfd
= open_dwo_file (dwo_name
, comp_dir
);
8349 dwo_file
->dwo_name
= dwo_name
;
8350 dwo_file
->dwo_bfd
= abfd
;
8352 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8354 bfd_map_over_sections (abfd
, dwarf2_locate_dwo_sections
, dwo_file
);
8356 dwo_file
->cus
= create_debug_info_hash_table (dwo_file
);
8358 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8359 dwo_file
->sections
.types
);
8361 discard_cleanups (cleanups
);
8366 /* Lookup DWO file DWO_NAME. */
8368 static struct dwo_file
*
8369 lookup_dwo_file (char *dwo_name
, const char *comp_dir
)
8371 struct dwo_file
*dwo_file
;
8372 struct dwo_file find_entry
;
8375 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8376 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8378 /* Have we already seen this DWO file? */
8379 find_entry
.dwo_name
= dwo_name
;
8380 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8382 /* If not, read it in and build a table of the DWOs it contains. */
8384 *slot
= init_dwo_file (dwo_name
, comp_dir
);
8386 /* NOTE: This will be NULL if unable to open the file. */
8392 /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME.
8393 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8394 SIGNATURE is the "dwo_id" of the CU (for consistency we use the same
8395 nomenclature as TUs).
8396 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8397 (dwo_id mismatch or couldn't find the DWO file). */
8399 static struct dwo_unit
*
8400 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8401 char *dwo_name
, const char *comp_dir
,
8404 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8405 struct dwo_file
*dwo_file
;
8407 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8408 if (dwo_file
== NULL
)
8411 /* Look up the DWO using its signature(dwo_id). */
8413 if (dwo_file
->cus
!= NULL
)
8415 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8417 find_dwo_cu
.signature
= signature
;
8418 dwo_cu
= htab_find (dwo_file
->cus
, &find_dwo_cu
);
8424 /* We didn't find it. This must mean a dwo_id mismatch. */
8426 complaint (&symfile_complaints
,
8427 _("Could not find DWO CU referenced by CU at offset 0x%x"
8429 this_cu
->offset
.sect_off
, objfile
->name
);
8433 /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME.
8434 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
8435 The result is a pointer to the dwo_unit object or NULL if we didn't find it
8436 (dwo_id mismatch or couldn't find the DWO file). */
8438 static struct dwo_unit
*
8439 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
8440 char *dwo_name
, const char *comp_dir
)
8442 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8443 struct dwo_file
*dwo_file
;
8445 dwo_file
= lookup_dwo_file (dwo_name
, comp_dir
);
8446 if (dwo_file
== NULL
)
8449 /* Look up the DWO using its signature(dwo_id). */
8451 if (dwo_file
->tus
!= NULL
)
8453 struct dwo_unit find_dwo_tu
, *dwo_tu
;
8455 find_dwo_tu
.signature
= this_tu
->signature
;
8456 dwo_tu
= htab_find (dwo_file
->tus
, &find_dwo_tu
);
8462 /* We didn't find it. This must mean a dwo_id mismatch. */
8464 complaint (&symfile_complaints
,
8465 _("Could not find DWO TU referenced by TU at offset 0x%x"
8467 this_tu
->per_cu
.offset
.sect_off
, objfile
->name
);
8471 /* Free all resources associated with DWO_FILE.
8472 Close the DWO file and munmap the sections.
8473 All memory should be on the objfile obstack. */
8476 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
8479 struct dwarf2_section_info
*section
;
8481 gdb_assert (dwo_file
->dwo_bfd
!= objfile
->obfd
);
8482 gdb_bfd_unref (dwo_file
->dwo_bfd
);
8484 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
8487 /* Wrapper for free_dwo_file for use in cleanups. */
8490 free_dwo_file_cleanup (void *arg
)
8492 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
8493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8495 free_dwo_file (dwo_file
, objfile
);
8498 /* Traversal function for free_dwo_files. */
8501 free_dwo_file_from_slot (void **slot
, void *info
)
8503 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8504 struct objfile
*objfile
= (struct objfile
*) info
;
8506 free_dwo_file (dwo_file
, objfile
);
8511 /* Free all resources associated with DWO_FILES. */
8514 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
8516 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
8519 /* Read in various DIEs. */
8521 /* qsort helper for inherit_abstract_dies. */
8524 unsigned_int_compar (const void *ap
, const void *bp
)
8526 unsigned int a
= *(unsigned int *) ap
;
8527 unsigned int b
= *(unsigned int *) bp
;
8529 return (a
> b
) - (b
> a
);
8532 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
8533 Inherit only the children of the DW_AT_abstract_origin DIE not being
8534 already referenced by DW_AT_abstract_origin from the children of the
8538 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
8540 struct die_info
*child_die
;
8541 unsigned die_children_count
;
8542 /* CU offsets which were referenced by children of the current DIE. */
8543 sect_offset
*offsets
;
8544 sect_offset
*offsets_end
, *offsetp
;
8545 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
8546 struct die_info
*origin_die
;
8547 /* Iterator of the ORIGIN_DIE children. */
8548 struct die_info
*origin_child_die
;
8549 struct cleanup
*cleanups
;
8550 struct attribute
*attr
;
8551 struct dwarf2_cu
*origin_cu
;
8552 struct pending
**origin_previous_list_in_scope
;
8554 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
8558 /* Note that following die references may follow to a die in a
8562 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
8564 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
8566 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
8567 origin_cu
->list_in_scope
= cu
->list_in_scope
;
8569 if (die
->tag
!= origin_die
->tag
8570 && !(die
->tag
== DW_TAG_inlined_subroutine
8571 && origin_die
->tag
== DW_TAG_subprogram
))
8572 complaint (&symfile_complaints
,
8573 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
8574 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
8576 child_die
= die
->child
;
8577 die_children_count
= 0;
8578 while (child_die
&& child_die
->tag
)
8580 child_die
= sibling_die (child_die
);
8581 die_children_count
++;
8583 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
8584 cleanups
= make_cleanup (xfree
, offsets
);
8586 offsets_end
= offsets
;
8587 child_die
= die
->child
;
8588 while (child_die
&& child_die
->tag
)
8590 /* For each CHILD_DIE, find the corresponding child of
8591 ORIGIN_DIE. If there is more than one layer of
8592 DW_AT_abstract_origin, follow them all; there shouldn't be,
8593 but GCC versions at least through 4.4 generate this (GCC PR
8595 struct die_info
*child_origin_die
= child_die
;
8596 struct dwarf2_cu
*child_origin_cu
= cu
;
8600 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
8604 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
8608 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
8609 counterpart may exist. */
8610 if (child_origin_die
!= child_die
)
8612 if (child_die
->tag
!= child_origin_die
->tag
8613 && !(child_die
->tag
== DW_TAG_inlined_subroutine
8614 && child_origin_die
->tag
== DW_TAG_subprogram
))
8615 complaint (&symfile_complaints
,
8616 _("Child DIE 0x%x and its abstract origin 0x%x have "
8617 "different tags"), child_die
->offset
.sect_off
,
8618 child_origin_die
->offset
.sect_off
);
8619 if (child_origin_die
->parent
!= origin_die
)
8620 complaint (&symfile_complaints
,
8621 _("Child DIE 0x%x and its abstract origin 0x%x have "
8622 "different parents"), child_die
->offset
.sect_off
,
8623 child_origin_die
->offset
.sect_off
);
8625 *offsets_end
++ = child_origin_die
->offset
;
8627 child_die
= sibling_die (child_die
);
8629 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
8630 unsigned_int_compar
);
8631 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
8632 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
8633 complaint (&symfile_complaints
,
8634 _("Multiple children of DIE 0x%x refer "
8635 "to DIE 0x%x as their abstract origin"),
8636 die
->offset
.sect_off
, offsetp
->sect_off
);
8639 origin_child_die
= origin_die
->child
;
8640 while (origin_child_die
&& origin_child_die
->tag
)
8642 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
8643 while (offsetp
< offsets_end
8644 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
8646 if (offsetp
>= offsets_end
8647 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
8649 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
8650 process_die (origin_child_die
, origin_cu
);
8652 origin_child_die
= sibling_die (origin_child_die
);
8654 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
8656 do_cleanups (cleanups
);
8660 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8662 struct objfile
*objfile
= cu
->objfile
;
8663 struct context_stack
*new;
8666 struct die_info
*child_die
;
8667 struct attribute
*attr
, *call_line
, *call_file
;
8670 struct block
*block
;
8671 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8672 VEC (symbolp
) *template_args
= NULL
;
8673 struct template_symbol
*templ_func
= NULL
;
8677 /* If we do not have call site information, we can't show the
8678 caller of this inlined function. That's too confusing, so
8679 only use the scope for local variables. */
8680 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
8681 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
8682 if (call_line
== NULL
|| call_file
== NULL
)
8684 read_lexical_block_scope (die
, cu
);
8689 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8691 name
= dwarf2_name (die
, cu
);
8693 /* Ignore functions with missing or empty names. These are actually
8694 illegal according to the DWARF standard. */
8697 complaint (&symfile_complaints
,
8698 _("missing name for subprogram DIE at %d"),
8699 die
->offset
.sect_off
);
8703 /* Ignore functions with missing or invalid low and high pc attributes. */
8704 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8706 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
8707 if (!attr
|| !DW_UNSND (attr
))
8708 complaint (&symfile_complaints
,
8709 _("cannot get low and high bounds "
8710 "for subprogram DIE at %d"),
8711 die
->offset
.sect_off
);
8718 /* If we have any template arguments, then we must allocate a
8719 different sort of symbol. */
8720 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
8722 if (child_die
->tag
== DW_TAG_template_type_param
8723 || child_die
->tag
== DW_TAG_template_value_param
)
8725 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8726 struct template_symbol
);
8727 templ_func
->base
.is_cplus_template_function
= 1;
8732 new = push_context (0, lowpc
);
8733 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
8734 (struct symbol
*) templ_func
);
8736 /* If there is a location expression for DW_AT_frame_base, record
8738 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
8740 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
8741 expression is being recorded directly in the function's symbol
8742 and not in a separate frame-base object. I guess this hack is
8743 to avoid adding some sort of frame-base adjunct/annex to the
8744 function's symbol :-(. The problem with doing this is that it
8745 results in a function symbol with a location expression that
8746 has nothing to do with the location of the function, ouch! The
8747 relationship should be: a function's symbol has-a frame base; a
8748 frame-base has-a location expression. */
8749 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
8751 cu
->list_in_scope
= &local_symbols
;
8753 if (die
->child
!= NULL
)
8755 child_die
= die
->child
;
8756 while (child_die
&& child_die
->tag
)
8758 if (child_die
->tag
== DW_TAG_template_type_param
8759 || child_die
->tag
== DW_TAG_template_value_param
)
8761 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
8764 VEC_safe_push (symbolp
, template_args
, arg
);
8767 process_die (child_die
, cu
);
8768 child_die
= sibling_die (child_die
);
8772 inherit_abstract_dies (die
, cu
);
8774 /* If we have a DW_AT_specification, we might need to import using
8775 directives from the context of the specification DIE. See the
8776 comment in determine_prefix. */
8777 if (cu
->language
== language_cplus
8778 && dwarf2_attr (die
, DW_AT_specification
, cu
))
8780 struct dwarf2_cu
*spec_cu
= cu
;
8781 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
8785 child_die
= spec_die
->child
;
8786 while (child_die
&& child_die
->tag
)
8788 if (child_die
->tag
== DW_TAG_imported_module
)
8789 process_die (child_die
, spec_cu
);
8790 child_die
= sibling_die (child_die
);
8793 /* In some cases, GCC generates specification DIEs that
8794 themselves contain DW_AT_specification attributes. */
8795 spec_die
= die_specification (spec_die
, &spec_cu
);
8799 new = pop_context ();
8800 /* Make a block for the local symbols within. */
8801 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
8802 lowpc
, highpc
, objfile
);
8804 /* For C++, set the block's scope. */
8805 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
8806 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
8807 determine_prefix (die
, cu
),
8808 processing_has_namespace_info
);
8810 /* If we have address ranges, record them. */
8811 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8813 /* Attach template arguments to function. */
8814 if (! VEC_empty (symbolp
, template_args
))
8816 gdb_assert (templ_func
!= NULL
);
8818 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
8819 templ_func
->template_arguments
8820 = obstack_alloc (&objfile
->objfile_obstack
,
8821 (templ_func
->n_template_arguments
8822 * sizeof (struct symbol
*)));
8823 memcpy (templ_func
->template_arguments
,
8824 VEC_address (symbolp
, template_args
),
8825 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
8826 VEC_free (symbolp
, template_args
);
8829 /* In C++, we can have functions nested inside functions (e.g., when
8830 a function declares a class that has methods). This means that
8831 when we finish processing a function scope, we may need to go
8832 back to building a containing block's symbol lists. */
8833 local_symbols
= new->locals
;
8834 param_symbols
= new->params
;
8835 using_directives
= new->using_directives
;
8837 /* If we've finished processing a top-level function, subsequent
8838 symbols go in the file symbol list. */
8839 if (outermost_context_p ())
8840 cu
->list_in_scope
= &file_symbols
;
8843 /* Process all the DIES contained within a lexical block scope. Start
8844 a new scope, process the dies, and then close the scope. */
8847 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8849 struct objfile
*objfile
= cu
->objfile
;
8850 struct context_stack
*new;
8851 CORE_ADDR lowpc
, highpc
;
8852 struct die_info
*child_die
;
8855 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8857 /* Ignore blocks with missing or invalid low and high pc attributes. */
8858 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
8859 as multiple lexical blocks? Handling children in a sane way would
8860 be nasty. Might be easier to properly extend generic blocks to
8862 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
8867 push_context (0, lowpc
);
8868 if (die
->child
!= NULL
)
8870 child_die
= die
->child
;
8871 while (child_die
&& child_die
->tag
)
8873 process_die (child_die
, cu
);
8874 child_die
= sibling_die (child_die
);
8877 new = pop_context ();
8879 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
8882 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
8885 /* Note that recording ranges after traversing children, as we
8886 do here, means that recording a parent's ranges entails
8887 walking across all its children's ranges as they appear in
8888 the address map, which is quadratic behavior.
8890 It would be nicer to record the parent's ranges before
8891 traversing its children, simply overriding whatever you find
8892 there. But since we don't even decide whether to create a
8893 block until after we've traversed its children, that's hard
8895 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
8897 local_symbols
= new->locals
;
8898 using_directives
= new->using_directives
;
8901 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
8904 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8906 struct objfile
*objfile
= cu
->objfile
;
8907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8908 CORE_ADDR pc
, baseaddr
;
8909 struct attribute
*attr
;
8910 struct call_site
*call_site
, call_site_local
;
8913 struct die_info
*child_die
;
8915 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8917 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8920 complaint (&symfile_complaints
,
8921 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
8922 "DIE 0x%x [in module %s]"),
8923 die
->offset
.sect_off
, objfile
->name
);
8926 pc
= DW_ADDR (attr
) + baseaddr
;
8928 if (cu
->call_site_htab
== NULL
)
8929 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
8930 NULL
, &objfile
->objfile_obstack
,
8931 hashtab_obstack_allocate
, NULL
);
8932 call_site_local
.pc
= pc
;
8933 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
8936 complaint (&symfile_complaints
,
8937 _("Duplicate PC %s for DW_TAG_GNU_call_site "
8938 "DIE 0x%x [in module %s]"),
8939 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
8943 /* Count parameters at the caller. */
8946 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
8947 child_die
= sibling_die (child_die
))
8949 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
8951 complaint (&symfile_complaints
,
8952 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
8953 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
8954 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
8961 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
8962 (sizeof (*call_site
)
8963 + (sizeof (*call_site
->parameter
)
8966 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
8969 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
8971 struct die_info
*func_die
;
8973 /* Skip also over DW_TAG_inlined_subroutine. */
8974 for (func_die
= die
->parent
;
8975 func_die
&& func_die
->tag
!= DW_TAG_subprogram
8976 && func_die
->tag
!= DW_TAG_subroutine_type
;
8977 func_die
= func_die
->parent
);
8979 /* DW_AT_GNU_all_call_sites is a superset
8980 of DW_AT_GNU_all_tail_call_sites. */
8982 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
8983 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
8985 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
8986 not complete. But keep CALL_SITE for look ups via call_site_htab,
8987 both the initial caller containing the real return address PC and
8988 the final callee containing the current PC of a chain of tail
8989 calls do not need to have the tail call list complete. But any
8990 function candidate for a virtual tail call frame searched via
8991 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
8992 determined unambiguously. */
8996 struct type
*func_type
= NULL
;
8999 func_type
= get_die_type (func_die
, cu
);
9000 if (func_type
!= NULL
)
9002 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9004 /* Enlist this call site to the function. */
9005 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9006 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9009 complaint (&symfile_complaints
,
9010 _("Cannot find function owning DW_TAG_GNU_call_site "
9011 "DIE 0x%x [in module %s]"),
9012 die
->offset
.sect_off
, objfile
->name
);
9016 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9018 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9019 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9020 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9021 /* Keep NULL DWARF_BLOCK. */;
9022 else if (attr_form_is_block (attr
))
9024 struct dwarf2_locexpr_baton
*dlbaton
;
9026 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9027 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9028 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9029 dlbaton
->per_cu
= cu
->per_cu
;
9031 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9033 else if (is_ref_attr (attr
))
9035 struct dwarf2_cu
*target_cu
= cu
;
9036 struct die_info
*target_die
;
9038 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9039 gdb_assert (target_cu
->objfile
== objfile
);
9040 if (die_is_declaration (target_die
, target_cu
))
9042 const char *target_physname
;
9044 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9045 if (target_physname
== NULL
)
9046 complaint (&symfile_complaints
,
9047 _("DW_AT_GNU_call_site_target target DIE has invalid "
9048 "physname, for referencing DIE 0x%x [in module %s]"),
9049 die
->offset
.sect_off
, objfile
->name
);
9051 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9057 /* DW_AT_entry_pc should be preferred. */
9058 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9059 complaint (&symfile_complaints
,
9060 _("DW_AT_GNU_call_site_target target DIE has invalid "
9061 "low pc, for referencing DIE 0x%x [in module %s]"),
9062 die
->offset
.sect_off
, objfile
->name
);
9064 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9068 complaint (&symfile_complaints
,
9069 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9070 "block nor reference, for DIE 0x%x [in module %s]"),
9071 die
->offset
.sect_off
, objfile
->name
);
9073 call_site
->per_cu
= cu
->per_cu
;
9075 for (child_die
= die
->child
;
9076 child_die
&& child_die
->tag
;
9077 child_die
= sibling_die (child_die
))
9079 struct call_site_parameter
*parameter
;
9080 struct attribute
*loc
, *origin
;
9082 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9084 /* Already printed the complaint above. */
9088 gdb_assert (call_site
->parameter_count
< nparams
);
9089 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9091 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9092 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9093 register is contained in DW_AT_GNU_call_site_value. */
9095 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9096 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9097 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9101 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9102 offset
= dwarf2_get_ref_die_offset (origin
);
9103 if (!offset_in_cu_p (&cu
->header
, offset
))
9105 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9106 binding can be done only inside one CU. Such referenced DIE
9107 therefore cannot be even moved to DW_TAG_partial_unit. */
9108 complaint (&symfile_complaints
,
9109 _("DW_AT_abstract_origin offset is not in CU for "
9110 "DW_TAG_GNU_call_site child DIE 0x%x "
9112 child_die
->offset
.sect_off
, objfile
->name
);
9115 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9116 - cu
->header
.offset
.sect_off
);
9118 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9120 complaint (&symfile_complaints
,
9121 _("No DW_FORM_block* DW_AT_location for "
9122 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9123 child_die
->offset
.sect_off
, objfile
->name
);
9128 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9129 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9130 if (parameter
->u
.dwarf_reg
!= -1)
9131 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9132 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9133 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9134 ¶meter
->u
.fb_offset
))
9135 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9138 complaint (&symfile_complaints
,
9139 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9140 "for DW_FORM_block* DW_AT_location is supported for "
9141 "DW_TAG_GNU_call_site child DIE 0x%x "
9143 child_die
->offset
.sect_off
, objfile
->name
);
9148 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9149 if (!attr_form_is_block (attr
))
9151 complaint (&symfile_complaints
,
9152 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9153 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9154 child_die
->offset
.sect_off
, objfile
->name
);
9157 parameter
->value
= DW_BLOCK (attr
)->data
;
9158 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9160 /* Parameters are not pre-cleared by memset above. */
9161 parameter
->data_value
= NULL
;
9162 parameter
->data_value_size
= 0;
9163 call_site
->parameter_count
++;
9165 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9168 if (!attr_form_is_block (attr
))
9169 complaint (&symfile_complaints
,
9170 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9171 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9172 child_die
->offset
.sect_off
, objfile
->name
);
9175 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9176 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9182 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9183 Return 1 if the attributes are present and valid, otherwise, return 0.
9184 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9187 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9188 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9189 struct partial_symtab
*ranges_pst
)
9191 struct objfile
*objfile
= cu
->objfile
;
9192 struct comp_unit_head
*cu_header
= &cu
->header
;
9193 bfd
*obfd
= objfile
->obfd
;
9194 unsigned int addr_size
= cu_header
->addr_size
;
9195 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9196 /* Base address selection entry. */
9207 found_base
= cu
->base_known
;
9208 base
= cu
->base_address
;
9210 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9211 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9213 complaint (&symfile_complaints
,
9214 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9218 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9220 /* Read in the largest possible address. */
9221 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9222 if ((marker
& mask
) == mask
)
9224 /* If we found the largest possible address, then
9225 read the base address. */
9226 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9227 buffer
+= 2 * addr_size
;
9228 offset
+= 2 * addr_size
;
9234 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9238 CORE_ADDR range_beginning
, range_end
;
9240 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9241 buffer
+= addr_size
;
9242 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9243 buffer
+= addr_size
;
9244 offset
+= 2 * addr_size
;
9246 /* An end of list marker is a pair of zero addresses. */
9247 if (range_beginning
== 0 && range_end
== 0)
9248 /* Found the end of list entry. */
9251 /* Each base address selection entry is a pair of 2 values.
9252 The first is the largest possible address, the second is
9253 the base address. Check for a base address here. */
9254 if ((range_beginning
& mask
) == mask
)
9256 /* If we found the largest possible address, then
9257 read the base address. */
9258 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9265 /* We have no valid base address for the ranges
9267 complaint (&symfile_complaints
,
9268 _("Invalid .debug_ranges data (no base address)"));
9272 if (range_beginning
> range_end
)
9274 /* Inverted range entries are invalid. */
9275 complaint (&symfile_complaints
,
9276 _("Invalid .debug_ranges data (inverted range)"));
9280 /* Empty range entries have no effect. */
9281 if (range_beginning
== range_end
)
9284 range_beginning
+= base
;
9287 if (ranges_pst
!= NULL
)
9288 addrmap_set_empty (objfile
->psymtabs_addrmap
,
9289 range_beginning
+ baseaddr
,
9290 range_end
- 1 + baseaddr
,
9293 /* FIXME: This is recording everything as a low-high
9294 segment of consecutive addresses. We should have a
9295 data structure for discontiguous block ranges
9299 low
= range_beginning
;
9305 if (range_beginning
< low
)
9306 low
= range_beginning
;
9307 if (range_end
> high
)
9313 /* If the first entry is an end-of-list marker, the range
9314 describes an empty scope, i.e. no instructions. */
9320 *high_return
= high
;
9324 /* Get low and high pc attributes from a die. Return 1 if the attributes
9325 are present and valid, otherwise, return 0. Return -1 if the range is
9326 discontinuous, i.e. derived from DW_AT_ranges information. */
9329 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
9330 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
9331 struct partial_symtab
*pst
)
9333 struct attribute
*attr
;
9334 struct attribute
*attr_high
;
9339 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9342 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9345 low
= DW_ADDR (attr
);
9346 if (attr_high
->form
== DW_FORM_addr
9347 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9348 high
= DW_ADDR (attr_high
);
9350 high
= low
+ DW_UNSND (attr_high
);
9353 /* Found high w/o low attribute. */
9356 /* Found consecutive range of addresses. */
9361 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9364 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9366 /* Value of the DW_AT_ranges attribute is the offset in the
9367 .debug_ranges section. */
9368 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
9370 /* Found discontinuous range of addresses. */
9375 /* read_partial_die has also the strict LOW < HIGH requirement. */
9379 /* When using the GNU linker, .gnu.linkonce. sections are used to
9380 eliminate duplicate copies of functions and vtables and such.
9381 The linker will arbitrarily choose one and discard the others.
9382 The AT_*_pc values for such functions refer to local labels in
9383 these sections. If the section from that file was discarded, the
9384 labels are not in the output, so the relocs get a value of 0.
9385 If this is a discarded function, mark the pc bounds as invalid,
9386 so that GDB will ignore it. */
9387 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9396 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
9397 its low and high PC addresses. Do nothing if these addresses could not
9398 be determined. Otherwise, set LOWPC to the low address if it is smaller,
9399 and HIGHPC to the high address if greater than HIGHPC. */
9402 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
9403 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9404 struct dwarf2_cu
*cu
)
9406 CORE_ADDR low
, high
;
9407 struct die_info
*child
= die
->child
;
9409 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
9411 *lowpc
= min (*lowpc
, low
);
9412 *highpc
= max (*highpc
, high
);
9415 /* If the language does not allow nested subprograms (either inside
9416 subprograms or lexical blocks), we're done. */
9417 if (cu
->language
!= language_ada
)
9420 /* Check all the children of the given DIE. If it contains nested
9421 subprograms, then check their pc bounds. Likewise, we need to
9422 check lexical blocks as well, as they may also contain subprogram
9424 while (child
&& child
->tag
)
9426 if (child
->tag
== DW_TAG_subprogram
9427 || child
->tag
== DW_TAG_lexical_block
)
9428 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
9429 child
= sibling_die (child
);
9433 /* Get the low and high pc's represented by the scope DIE, and store
9434 them in *LOWPC and *HIGHPC. If the correct values can't be
9435 determined, set *LOWPC to -1 and *HIGHPC to 0. */
9438 get_scope_pc_bounds (struct die_info
*die
,
9439 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9440 struct dwarf2_cu
*cu
)
9442 CORE_ADDR best_low
= (CORE_ADDR
) -1;
9443 CORE_ADDR best_high
= (CORE_ADDR
) 0;
9444 CORE_ADDR current_low
, current_high
;
9446 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
9448 best_low
= current_low
;
9449 best_high
= current_high
;
9453 struct die_info
*child
= die
->child
;
9455 while (child
&& child
->tag
)
9457 switch (child
->tag
) {
9458 case DW_TAG_subprogram
:
9459 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
9461 case DW_TAG_namespace
:
9463 /* FIXME: carlton/2004-01-16: Should we do this for
9464 DW_TAG_class_type/DW_TAG_structure_type, too? I think
9465 that current GCC's always emit the DIEs corresponding
9466 to definitions of methods of classes as children of a
9467 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
9468 the DIEs giving the declarations, which could be
9469 anywhere). But I don't see any reason why the
9470 standards says that they have to be there. */
9471 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
9473 if (current_low
!= ((CORE_ADDR
) -1))
9475 best_low
= min (best_low
, current_low
);
9476 best_high
= max (best_high
, current_high
);
9484 child
= sibling_die (child
);
9489 *highpc
= best_high
;
9492 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
9496 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
9497 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
9499 struct objfile
*objfile
= cu
->objfile
;
9500 struct attribute
*attr
;
9501 struct attribute
*attr_high
;
9503 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
9506 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9509 CORE_ADDR low
= DW_ADDR (attr
);
9511 if (attr_high
->form
== DW_FORM_addr
9512 || attr_high
->form
== DW_FORM_GNU_addr_index
)
9513 high
= DW_ADDR (attr_high
);
9515 high
= low
+ DW_UNSND (attr_high
);
9517 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
9521 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
9524 bfd
*obfd
= objfile
->obfd
;
9526 /* The value of the DW_AT_ranges attribute is the offset of the
9527 address range list in the .debug_ranges section. */
9528 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
9529 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9531 /* For some target architectures, but not others, the
9532 read_address function sign-extends the addresses it returns.
9533 To recognize base address selection entries, we need a
9535 unsigned int addr_size
= cu
->header
.addr_size
;
9536 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9538 /* The base address, to which the next pair is relative. Note
9539 that this 'base' is a DWARF concept: most entries in a range
9540 list are relative, to reduce the number of relocs against the
9541 debugging information. This is separate from this function's
9542 'baseaddr' argument, which GDB uses to relocate debugging
9543 information from a shared library based on the address at
9544 which the library was loaded. */
9545 CORE_ADDR base
= cu
->base_address
;
9546 int base_known
= cu
->base_known
;
9548 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
9549 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9551 complaint (&symfile_complaints
,
9552 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
9559 unsigned int bytes_read
;
9560 CORE_ADDR start
, end
;
9562 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9563 buffer
+= bytes_read
;
9564 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
9565 buffer
+= bytes_read
;
9567 /* Did we find the end of the range list? */
9568 if (start
== 0 && end
== 0)
9571 /* Did we find a base address selection entry? */
9572 else if ((start
& base_select_mask
) == base_select_mask
)
9578 /* We found an ordinary address range. */
9583 complaint (&symfile_complaints
,
9584 _("Invalid .debug_ranges data "
9585 "(no base address)"));
9591 /* Inverted range entries are invalid. */
9592 complaint (&symfile_complaints
,
9593 _("Invalid .debug_ranges data "
9594 "(inverted range)"));
9598 /* Empty range entries have no effect. */
9602 record_block_range (block
,
9603 baseaddr
+ base
+ start
,
9604 baseaddr
+ base
+ end
- 1);
9610 /* Check whether the producer field indicates either of GCC < 4.6, or the
9611 Intel C/C++ compiler, and cache the result in CU. */
9614 check_producer (struct dwarf2_cu
*cu
)
9617 int major
, minor
, release
;
9619 if (cu
->producer
== NULL
)
9621 /* For unknown compilers expect their behavior is DWARF version
9624 GCC started to support .debug_types sections by -gdwarf-4 since
9625 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
9626 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
9627 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
9628 interpreted incorrectly by GDB now - GCC PR debug/48229. */
9630 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
9632 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
9634 cs
= &cu
->producer
[strlen ("GNU ")];
9635 while (*cs
&& !isdigit (*cs
))
9637 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
9639 /* Not recognized as GCC. */
9642 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
9644 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
9645 cu
->producer_is_icc
= 1;
9648 /* For other non-GCC compilers, expect their behavior is DWARF version
9652 cu
->checked_producer
= 1;
9655 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
9656 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
9657 during 4.6.0 experimental. */
9660 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
9662 if (!cu
->checked_producer
)
9663 check_producer (cu
);
9665 return cu
->producer_is_gxx_lt_4_6
;
9668 /* Return the default accessibility type if it is not overriden by
9669 DW_AT_accessibility. */
9671 static enum dwarf_access_attribute
9672 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
9674 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
9676 /* The default DWARF 2 accessibility for members is public, the default
9677 accessibility for inheritance is private. */
9679 if (die
->tag
!= DW_TAG_inheritance
)
9680 return DW_ACCESS_public
;
9682 return DW_ACCESS_private
;
9686 /* DWARF 3+ defines the default accessibility a different way. The same
9687 rules apply now for DW_TAG_inheritance as for the members and it only
9688 depends on the container kind. */
9690 if (die
->parent
->tag
== DW_TAG_class_type
)
9691 return DW_ACCESS_private
;
9693 return DW_ACCESS_public
;
9697 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
9698 offset. If the attribute was not found return 0, otherwise return
9699 1. If it was found but could not properly be handled, set *OFFSET
9703 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
9706 struct attribute
*attr
;
9708 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
9713 /* Note that we do not check for a section offset first here.
9714 This is because DW_AT_data_member_location is new in DWARF 4,
9715 so if we see it, we can assume that a constant form is really
9716 a constant and not a section offset. */
9717 if (attr_form_is_constant (attr
))
9718 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
9719 else if (attr_form_is_section_offset (attr
))
9720 dwarf2_complex_location_expr_complaint ();
9721 else if (attr_form_is_block (attr
))
9722 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
9724 dwarf2_complex_location_expr_complaint ();
9732 /* Add an aggregate field to the field list. */
9735 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
9736 struct dwarf2_cu
*cu
)
9738 struct objfile
*objfile
= cu
->objfile
;
9739 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9740 struct nextfield
*new_field
;
9741 struct attribute
*attr
;
9743 char *fieldname
= "";
9745 /* Allocate a new field list entry and link it in. */
9746 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
9747 make_cleanup (xfree
, new_field
);
9748 memset (new_field
, 0, sizeof (struct nextfield
));
9750 if (die
->tag
== DW_TAG_inheritance
)
9752 new_field
->next
= fip
->baseclasses
;
9753 fip
->baseclasses
= new_field
;
9757 new_field
->next
= fip
->fields
;
9758 fip
->fields
= new_field
;
9762 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
9764 new_field
->accessibility
= DW_UNSND (attr
);
9766 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
9767 if (new_field
->accessibility
!= DW_ACCESS_public
)
9768 fip
->non_public_fields
= 1;
9770 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
9772 new_field
->virtuality
= DW_UNSND (attr
);
9774 new_field
->virtuality
= DW_VIRTUALITY_none
;
9776 fp
= &new_field
->field
;
9778 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
9782 /* Data member other than a C++ static data member. */
9784 /* Get type of field. */
9785 fp
->type
= die_type (die
, cu
);
9787 SET_FIELD_BITPOS (*fp
, 0);
9789 /* Get bit size of field (zero if none). */
9790 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
9793 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
9797 FIELD_BITSIZE (*fp
) = 0;
9800 /* Get bit offset of field. */
9801 if (handle_data_member_location (die
, cu
, &offset
))
9802 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9803 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
9806 if (gdbarch_bits_big_endian (gdbarch
))
9808 /* For big endian bits, the DW_AT_bit_offset gives the
9809 additional bit offset from the MSB of the containing
9810 anonymous object to the MSB of the field. We don't
9811 have to do anything special since we don't need to
9812 know the size of the anonymous object. */
9813 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
9817 /* For little endian bits, compute the bit offset to the
9818 MSB of the anonymous object, subtract off the number of
9819 bits from the MSB of the field to the MSB of the
9820 object, and then subtract off the number of bits of
9821 the field itself. The result is the bit offset of
9822 the LSB of the field. */
9824 int bit_offset
= DW_UNSND (attr
);
9826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
9829 /* The size of the anonymous object containing
9830 the bit field is explicit, so use the
9831 indicated size (in bytes). */
9832 anonymous_size
= DW_UNSND (attr
);
9836 /* The size of the anonymous object containing
9837 the bit field must be inferred from the type
9838 attribute of the data member containing the
9840 anonymous_size
= TYPE_LENGTH (fp
->type
);
9842 SET_FIELD_BITPOS (*fp
,
9844 + anonymous_size
* bits_per_byte
9845 - bit_offset
- FIELD_BITSIZE (*fp
)));
9849 /* Get name of field. */
9850 fieldname
= dwarf2_name (die
, cu
);
9851 if (fieldname
== NULL
)
9854 /* The name is already allocated along with this objfile, so we don't
9855 need to duplicate it for the type. */
9856 fp
->name
= fieldname
;
9858 /* Change accessibility for artificial fields (e.g. virtual table
9859 pointer or virtual base class pointer) to private. */
9860 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
9862 FIELD_ARTIFICIAL (*fp
) = 1;
9863 new_field
->accessibility
= DW_ACCESS_private
;
9864 fip
->non_public_fields
= 1;
9867 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
9869 /* C++ static member. */
9871 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
9872 is a declaration, but all versions of G++ as of this writing
9873 (so through at least 3.2.1) incorrectly generate
9874 DW_TAG_variable tags. */
9876 const char *physname
;
9878 /* Get name of field. */
9879 fieldname
= dwarf2_name (die
, cu
);
9880 if (fieldname
== NULL
)
9883 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9885 /* Only create a symbol if this is an external value.
9886 new_symbol checks this and puts the value in the global symbol
9887 table, which we want. If it is not external, new_symbol
9888 will try to put the value in cu->list_in_scope which is wrong. */
9889 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
9891 /* A static const member, not much different than an enum as far as
9892 we're concerned, except that we can support more types. */
9893 new_symbol (die
, NULL
, cu
);
9896 /* Get physical name. */
9897 physname
= dwarf2_physname (fieldname
, die
, cu
);
9899 /* The name is already allocated along with this objfile, so we don't
9900 need to duplicate it for the type. */
9901 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
9902 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9903 FIELD_NAME (*fp
) = fieldname
;
9905 else if (die
->tag
== DW_TAG_inheritance
)
9909 /* C++ base class field. */
9910 if (handle_data_member_location (die
, cu
, &offset
))
9911 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
9912 FIELD_BITSIZE (*fp
) = 0;
9913 FIELD_TYPE (*fp
) = die_type (die
, cu
);
9914 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
9915 fip
->nbaseclasses
++;
9919 /* Add a typedef defined in the scope of the FIP's class. */
9922 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
9923 struct dwarf2_cu
*cu
)
9925 struct objfile
*objfile
= cu
->objfile
;
9926 struct typedef_field_list
*new_field
;
9927 struct attribute
*attr
;
9928 struct typedef_field
*fp
;
9929 char *fieldname
= "";
9931 /* Allocate a new field list entry and link it in. */
9932 new_field
= xzalloc (sizeof (*new_field
));
9933 make_cleanup (xfree
, new_field
);
9935 gdb_assert (die
->tag
== DW_TAG_typedef
);
9937 fp
= &new_field
->field
;
9939 /* Get name of field. */
9940 fp
->name
= dwarf2_name (die
, cu
);
9941 if (fp
->name
== NULL
)
9944 fp
->type
= read_type_die (die
, cu
);
9946 new_field
->next
= fip
->typedef_field_list
;
9947 fip
->typedef_field_list
= new_field
;
9948 fip
->typedef_field_list_count
++;
9951 /* Create the vector of fields, and attach it to the type. */
9954 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
9955 struct dwarf2_cu
*cu
)
9957 int nfields
= fip
->nfields
;
9959 /* Record the field count, allocate space for the array of fields,
9960 and create blank accessibility bitfields if necessary. */
9961 TYPE_NFIELDS (type
) = nfields
;
9962 TYPE_FIELDS (type
) = (struct field
*)
9963 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
9964 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
9966 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
9968 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9970 TYPE_FIELD_PRIVATE_BITS (type
) =
9971 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9972 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
9974 TYPE_FIELD_PROTECTED_BITS (type
) =
9975 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9976 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
9978 TYPE_FIELD_IGNORE_BITS (type
) =
9979 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
9980 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
9983 /* If the type has baseclasses, allocate and clear a bit vector for
9984 TYPE_FIELD_VIRTUAL_BITS. */
9985 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
9987 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
9988 unsigned char *pointer
;
9990 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
9991 pointer
= TYPE_ALLOC (type
, num_bytes
);
9992 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
9993 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
9994 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
9997 /* Copy the saved-up fields into the field vector. Start from the head of
9998 the list, adding to the tail of the field array, so that they end up in
9999 the same order in the array in which they were added to the list. */
10000 while (nfields
-- > 0)
10002 struct nextfield
*fieldp
;
10006 fieldp
= fip
->fields
;
10007 fip
->fields
= fieldp
->next
;
10011 fieldp
= fip
->baseclasses
;
10012 fip
->baseclasses
= fieldp
->next
;
10015 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10016 switch (fieldp
->accessibility
)
10018 case DW_ACCESS_private
:
10019 if (cu
->language
!= language_ada
)
10020 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10023 case DW_ACCESS_protected
:
10024 if (cu
->language
!= language_ada
)
10025 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10028 case DW_ACCESS_public
:
10032 /* Unknown accessibility. Complain and treat it as public. */
10034 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10035 fieldp
->accessibility
);
10039 if (nfields
< fip
->nbaseclasses
)
10041 switch (fieldp
->virtuality
)
10043 case DW_VIRTUALITY_virtual
:
10044 case DW_VIRTUALITY_pure_virtual
:
10045 if (cu
->language
== language_ada
)
10046 error (_("unexpected virtuality in component of Ada type"));
10047 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10054 /* Add a member function to the proper fieldlist. */
10057 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10058 struct type
*type
, struct dwarf2_cu
*cu
)
10060 struct objfile
*objfile
= cu
->objfile
;
10061 struct attribute
*attr
;
10062 struct fnfieldlist
*flp
;
10064 struct fn_field
*fnp
;
10066 struct nextfnfield
*new_fnfield
;
10067 struct type
*this_type
;
10068 enum dwarf_access_attribute accessibility
;
10070 if (cu
->language
== language_ada
)
10071 error (_("unexpected member function in Ada type"));
10073 /* Get name of member function. */
10074 fieldname
= dwarf2_name (die
, cu
);
10075 if (fieldname
== NULL
)
10078 /* Look up member function name in fieldlist. */
10079 for (i
= 0; i
< fip
->nfnfields
; i
++)
10081 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10085 /* Create new list element if necessary. */
10086 if (i
< fip
->nfnfields
)
10087 flp
= &fip
->fnfieldlists
[i
];
10090 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10092 fip
->fnfieldlists
= (struct fnfieldlist
*)
10093 xrealloc (fip
->fnfieldlists
,
10094 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10095 * sizeof (struct fnfieldlist
));
10096 if (fip
->nfnfields
== 0)
10097 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10099 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10100 flp
->name
= fieldname
;
10103 i
= fip
->nfnfields
++;
10106 /* Create a new member function field and chain it to the field list
10108 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10109 make_cleanup (xfree
, new_fnfield
);
10110 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10111 new_fnfield
->next
= flp
->head
;
10112 flp
->head
= new_fnfield
;
10115 /* Fill in the member function field info. */
10116 fnp
= &new_fnfield
->fnfield
;
10118 /* Delay processing of the physname until later. */
10119 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10121 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10126 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10127 fnp
->physname
= physname
? physname
: "";
10130 fnp
->type
= alloc_type (objfile
);
10131 this_type
= read_type_die (die
, cu
);
10132 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10134 int nparams
= TYPE_NFIELDS (this_type
);
10136 /* TYPE is the domain of this method, and THIS_TYPE is the type
10137 of the method itself (TYPE_CODE_METHOD). */
10138 smash_to_method_type (fnp
->type
, type
,
10139 TYPE_TARGET_TYPE (this_type
),
10140 TYPE_FIELDS (this_type
),
10141 TYPE_NFIELDS (this_type
),
10142 TYPE_VARARGS (this_type
));
10144 /* Handle static member functions.
10145 Dwarf2 has no clean way to discern C++ static and non-static
10146 member functions. G++ helps GDB by marking the first
10147 parameter for non-static member functions (which is the this
10148 pointer) as artificial. We obtain this information from
10149 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10150 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10151 fnp
->voffset
= VOFFSET_STATIC
;
10154 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10155 dwarf2_full_name (fieldname
, die
, cu
));
10157 /* Get fcontext from DW_AT_containing_type if present. */
10158 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10159 fnp
->fcontext
= die_containing_type (die
, cu
);
10161 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10162 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10164 /* Get accessibility. */
10165 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10167 accessibility
= DW_UNSND (attr
);
10169 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10170 switch (accessibility
)
10172 case DW_ACCESS_private
:
10173 fnp
->is_private
= 1;
10175 case DW_ACCESS_protected
:
10176 fnp
->is_protected
= 1;
10180 /* Check for artificial methods. */
10181 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10182 if (attr
&& DW_UNSND (attr
) != 0)
10183 fnp
->is_artificial
= 1;
10185 /* Get index in virtual function table if it is a virtual member
10186 function. For older versions of GCC, this is an offset in the
10187 appropriate virtual table, as specified by DW_AT_containing_type.
10188 For everyone else, it is an expression to be evaluated relative
10189 to the object address. */
10191 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10194 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10196 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10198 /* Old-style GCC. */
10199 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10201 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10202 || (DW_BLOCK (attr
)->size
> 1
10203 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10204 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10206 struct dwarf_block blk
;
10209 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10211 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10212 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10213 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10214 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10215 dwarf2_complex_location_expr_complaint ();
10217 fnp
->voffset
/= cu
->header
.addr_size
;
10221 dwarf2_complex_location_expr_complaint ();
10223 if (!fnp
->fcontext
)
10224 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10226 else if (attr_form_is_section_offset (attr
))
10228 dwarf2_complex_location_expr_complaint ();
10232 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10238 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10239 if (attr
&& DW_UNSND (attr
))
10241 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10242 complaint (&symfile_complaints
,
10243 _("Member function \"%s\" (offset %d) is virtual "
10244 "but the vtable offset is not specified"),
10245 fieldname
, die
->offset
.sect_off
);
10246 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10247 TYPE_CPLUS_DYNAMIC (type
) = 1;
10252 /* Create the vector of member function fields, and attach it to the type. */
10255 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10256 struct dwarf2_cu
*cu
)
10258 struct fnfieldlist
*flp
;
10261 if (cu
->language
== language_ada
)
10262 error (_("unexpected member functions in Ada type"));
10264 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10265 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
10266 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
10268 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
10270 struct nextfnfield
*nfp
= flp
->head
;
10271 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
10274 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
10275 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
10276 fn_flp
->fn_fields
= (struct fn_field
*)
10277 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
10278 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
10279 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
10282 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
10285 /* Returns non-zero if NAME is the name of a vtable member in CU's
10286 language, zero otherwise. */
10288 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
10290 static const char vptr
[] = "_vptr";
10291 static const char vtable
[] = "vtable";
10293 /* Look for the C++ and Java forms of the vtable. */
10294 if ((cu
->language
== language_java
10295 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
10296 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
10297 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
10303 /* GCC outputs unnamed structures that are really pointers to member
10304 functions, with the ABI-specified layout. If TYPE describes
10305 such a structure, smash it into a member function type.
10307 GCC shouldn't do this; it should just output pointer to member DIEs.
10308 This is GCC PR debug/28767. */
10311 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
10313 struct type
*pfn_type
, *domain_type
, *new_type
;
10315 /* Check for a structure with no name and two children. */
10316 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
10319 /* Check for __pfn and __delta members. */
10320 if (TYPE_FIELD_NAME (type
, 0) == NULL
10321 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
10322 || TYPE_FIELD_NAME (type
, 1) == NULL
10323 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
10326 /* Find the type of the method. */
10327 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
10328 if (pfn_type
== NULL
10329 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
10330 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
10333 /* Look for the "this" argument. */
10334 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
10335 if (TYPE_NFIELDS (pfn_type
) == 0
10336 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
10337 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
10340 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
10341 new_type
= alloc_type (objfile
);
10342 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
10343 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
10344 TYPE_VARARGS (pfn_type
));
10345 smash_to_methodptr_type (type
, new_type
);
10348 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
10352 producer_is_icc (struct dwarf2_cu
*cu
)
10354 if (!cu
->checked_producer
)
10355 check_producer (cu
);
10357 return cu
->producer_is_icc
;
10360 /* Called when we find the DIE that starts a structure or union scope
10361 (definition) to create a type for the structure or union. Fill in
10362 the type's name and general properties; the members will not be
10363 processed until process_structure_type.
10365 NOTE: we need to call these functions regardless of whether or not the
10366 DIE has a DW_AT_name attribute, since it might be an anonymous
10367 structure or union. This gets the type entered into our set of
10368 user defined types.
10370 However, if the structure is incomplete (an opaque struct/union)
10371 then suppress creating a symbol table entry for it since gdb only
10372 wants to find the one with the complete definition. Note that if
10373 it is complete, we just call new_symbol, which does it's own
10374 checking about whether the struct/union is anonymous or not (and
10375 suppresses creating a symbol table entry itself). */
10377 static struct type
*
10378 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10380 struct objfile
*objfile
= cu
->objfile
;
10382 struct attribute
*attr
;
10385 /* If the definition of this type lives in .debug_types, read that type.
10386 Don't follow DW_AT_specification though, that will take us back up
10387 the chain and we want to go down. */
10388 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10391 struct dwarf2_cu
*type_cu
= cu
;
10392 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10394 /* We could just recurse on read_structure_type, but we need to call
10395 get_die_type to ensure only one type for this DIE is created.
10396 This is important, for example, because for c++ classes we need
10397 TYPE_NAME set which is only done by new_symbol. Blech. */
10398 type
= read_type_die (type_die
, type_cu
);
10400 /* TYPE_CU may not be the same as CU.
10401 Ensure TYPE is recorded in CU's type_hash table. */
10402 return set_die_type (die
, type
, cu
);
10405 type
= alloc_type (objfile
);
10406 INIT_CPLUS_SPECIFIC (type
);
10408 name
= dwarf2_name (die
, cu
);
10411 if (cu
->language
== language_cplus
10412 || cu
->language
== language_java
)
10414 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
10416 /* dwarf2_full_name might have already finished building the DIE's
10417 type. If so, there is no need to continue. */
10418 if (get_die_type (die
, cu
) != NULL
)
10419 return get_die_type (die
, cu
);
10421 TYPE_TAG_NAME (type
) = full_name
;
10422 if (die
->tag
== DW_TAG_structure_type
10423 || die
->tag
== DW_TAG_class_type
)
10424 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10428 /* The name is already allocated along with this objfile, so
10429 we don't need to duplicate it for the type. */
10430 TYPE_TAG_NAME (type
) = (char *) name
;
10431 if (die
->tag
== DW_TAG_class_type
)
10432 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
10436 if (die
->tag
== DW_TAG_structure_type
)
10438 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10440 else if (die
->tag
== DW_TAG_union_type
)
10442 TYPE_CODE (type
) = TYPE_CODE_UNION
;
10446 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
10449 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
10450 TYPE_DECLARED_CLASS (type
) = 1;
10452 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10455 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10459 TYPE_LENGTH (type
) = 0;
10462 if (producer_is_icc (cu
))
10464 /* ICC does not output the required DW_AT_declaration
10465 on incomplete types, but gives them a size of zero. */
10468 TYPE_STUB_SUPPORTED (type
) = 1;
10470 if (die_is_declaration (die
, cu
))
10471 TYPE_STUB (type
) = 1;
10472 else if (attr
== NULL
&& die
->child
== NULL
10473 && producer_is_realview (cu
->producer
))
10474 /* RealView does not output the required DW_AT_declaration
10475 on incomplete types. */
10476 TYPE_STUB (type
) = 1;
10478 /* We need to add the type field to the die immediately so we don't
10479 infinitely recurse when dealing with pointers to the structure
10480 type within the structure itself. */
10481 set_die_type (die
, type
, cu
);
10483 /* set_die_type should be already done. */
10484 set_descriptive_type (type
, die
, cu
);
10489 /* Finish creating a structure or union type, including filling in
10490 its members and creating a symbol for it. */
10493 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10495 struct objfile
*objfile
= cu
->objfile
;
10496 struct die_info
*child_die
= die
->child
;
10499 type
= get_die_type (die
, cu
);
10501 type
= read_structure_type (die
, cu
);
10503 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
10505 struct field_info fi
;
10506 struct die_info
*child_die
;
10507 VEC (symbolp
) *template_args
= NULL
;
10508 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
10510 memset (&fi
, 0, sizeof (struct field_info
));
10512 child_die
= die
->child
;
10514 while (child_die
&& child_die
->tag
)
10516 if (child_die
->tag
== DW_TAG_member
10517 || child_die
->tag
== DW_TAG_variable
)
10519 /* NOTE: carlton/2002-11-05: A C++ static data member
10520 should be a DW_TAG_member that is a declaration, but
10521 all versions of G++ as of this writing (so through at
10522 least 3.2.1) incorrectly generate DW_TAG_variable
10523 tags for them instead. */
10524 dwarf2_add_field (&fi
, child_die
, cu
);
10526 else if (child_die
->tag
== DW_TAG_subprogram
)
10528 /* C++ member function. */
10529 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
10531 else if (child_die
->tag
== DW_TAG_inheritance
)
10533 /* C++ base class field. */
10534 dwarf2_add_field (&fi
, child_die
, cu
);
10536 else if (child_die
->tag
== DW_TAG_typedef
)
10537 dwarf2_add_typedef (&fi
, child_die
, cu
);
10538 else if (child_die
->tag
== DW_TAG_template_type_param
10539 || child_die
->tag
== DW_TAG_template_value_param
)
10541 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
10544 VEC_safe_push (symbolp
, template_args
, arg
);
10547 child_die
= sibling_die (child_die
);
10550 /* Attach template arguments to type. */
10551 if (! VEC_empty (symbolp
, template_args
))
10553 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10554 TYPE_N_TEMPLATE_ARGUMENTS (type
)
10555 = VEC_length (symbolp
, template_args
);
10556 TYPE_TEMPLATE_ARGUMENTS (type
)
10557 = obstack_alloc (&objfile
->objfile_obstack
,
10558 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10559 * sizeof (struct symbol
*)));
10560 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
10561 VEC_address (symbolp
, template_args
),
10562 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
10563 * sizeof (struct symbol
*)));
10564 VEC_free (symbolp
, template_args
);
10567 /* Attach fields and member functions to the type. */
10569 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
10572 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
10574 /* Get the type which refers to the base class (possibly this
10575 class itself) which contains the vtable pointer for the current
10576 class from the DW_AT_containing_type attribute. This use of
10577 DW_AT_containing_type is a GNU extension. */
10579 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10581 struct type
*t
= die_containing_type (die
, cu
);
10583 TYPE_VPTR_BASETYPE (type
) = t
;
10588 /* Our own class provides vtbl ptr. */
10589 for (i
= TYPE_NFIELDS (t
) - 1;
10590 i
>= TYPE_N_BASECLASSES (t
);
10593 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
10595 if (is_vtable_name (fieldname
, cu
))
10597 TYPE_VPTR_FIELDNO (type
) = i
;
10602 /* Complain if virtual function table field not found. */
10603 if (i
< TYPE_N_BASECLASSES (t
))
10604 complaint (&symfile_complaints
,
10605 _("virtual function table pointer "
10606 "not found when defining class '%s'"),
10607 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
10612 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
10615 else if (cu
->producer
10616 && strncmp (cu
->producer
,
10617 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
10619 /* The IBM XLC compiler does not provide direct indication
10620 of the containing type, but the vtable pointer is
10621 always named __vfp. */
10625 for (i
= TYPE_NFIELDS (type
) - 1;
10626 i
>= TYPE_N_BASECLASSES (type
);
10629 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
10631 TYPE_VPTR_FIELDNO (type
) = i
;
10632 TYPE_VPTR_BASETYPE (type
) = type
;
10639 /* Copy fi.typedef_field_list linked list elements content into the
10640 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
10641 if (fi
.typedef_field_list
)
10643 int i
= fi
.typedef_field_list_count
;
10645 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10646 TYPE_TYPEDEF_FIELD_ARRAY (type
)
10647 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
10648 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
10650 /* Reverse the list order to keep the debug info elements order. */
10653 struct typedef_field
*dest
, *src
;
10655 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
10656 src
= &fi
.typedef_field_list
->field
;
10657 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
10662 do_cleanups (back_to
);
10664 if (HAVE_CPLUS_STRUCT (type
))
10665 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
10668 quirk_gcc_member_function_pointer (type
, objfile
);
10670 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
10671 snapshots) has been known to create a die giving a declaration
10672 for a class that has, as a child, a die giving a definition for a
10673 nested class. So we have to process our children even if the
10674 current die is a declaration. Normally, of course, a declaration
10675 won't have any children at all. */
10677 while (child_die
!= NULL
&& child_die
->tag
)
10679 if (child_die
->tag
== DW_TAG_member
10680 || child_die
->tag
== DW_TAG_variable
10681 || child_die
->tag
== DW_TAG_inheritance
10682 || child_die
->tag
== DW_TAG_template_value_param
10683 || child_die
->tag
== DW_TAG_template_type_param
)
10688 process_die (child_die
, cu
);
10690 child_die
= sibling_die (child_die
);
10693 /* Do not consider external references. According to the DWARF standard,
10694 these DIEs are identified by the fact that they have no byte_size
10695 attribute, and a declaration attribute. */
10696 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
10697 || !die_is_declaration (die
, cu
))
10698 new_symbol (die
, type
, cu
);
10701 /* Given a DW_AT_enumeration_type die, set its type. We do not
10702 complete the type's fields yet, or create any symbols. */
10704 static struct type
*
10705 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10707 struct objfile
*objfile
= cu
->objfile
;
10709 struct attribute
*attr
;
10712 /* If the definition of this type lives in .debug_types, read that type.
10713 Don't follow DW_AT_specification though, that will take us back up
10714 the chain and we want to go down. */
10715 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
10718 struct dwarf2_cu
*type_cu
= cu
;
10719 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
10721 type
= read_type_die (type_die
, type_cu
);
10723 /* TYPE_CU may not be the same as CU.
10724 Ensure TYPE is recorded in CU's type_hash table. */
10725 return set_die_type (die
, type
, cu
);
10728 type
= alloc_type (objfile
);
10730 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
10731 name
= dwarf2_full_name (NULL
, die
, cu
);
10733 TYPE_TAG_NAME (type
) = (char *) name
;
10735 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10738 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10742 TYPE_LENGTH (type
) = 0;
10745 /* The enumeration DIE can be incomplete. In Ada, any type can be
10746 declared as private in the package spec, and then defined only
10747 inside the package body. Such types are known as Taft Amendment
10748 Types. When another package uses such a type, an incomplete DIE
10749 may be generated by the compiler. */
10750 if (die_is_declaration (die
, cu
))
10751 TYPE_STUB (type
) = 1;
10753 return set_die_type (die
, type
, cu
);
10756 /* Given a pointer to a die which begins an enumeration, process all
10757 the dies that define the members of the enumeration, and create the
10758 symbol for the enumeration type.
10760 NOTE: We reverse the order of the element list. */
10763 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10765 struct type
*this_type
;
10767 this_type
= get_die_type (die
, cu
);
10768 if (this_type
== NULL
)
10769 this_type
= read_enumeration_type (die
, cu
);
10771 if (die
->child
!= NULL
)
10773 struct die_info
*child_die
;
10774 struct symbol
*sym
;
10775 struct field
*fields
= NULL
;
10776 int num_fields
= 0;
10777 int unsigned_enum
= 1;
10782 child_die
= die
->child
;
10783 while (child_die
&& child_die
->tag
)
10785 if (child_die
->tag
!= DW_TAG_enumerator
)
10787 process_die (child_die
, cu
);
10791 name
= dwarf2_name (child_die
, cu
);
10794 sym
= new_symbol (child_die
, this_type
, cu
);
10795 if (SYMBOL_VALUE (sym
) < 0)
10800 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
10803 mask
|= SYMBOL_VALUE (sym
);
10805 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10807 fields
= (struct field
*)
10809 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
10810 * sizeof (struct field
));
10813 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
10814 FIELD_TYPE (fields
[num_fields
]) = NULL
;
10815 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
10816 FIELD_BITSIZE (fields
[num_fields
]) = 0;
10822 child_die
= sibling_die (child_die
);
10827 TYPE_NFIELDS (this_type
) = num_fields
;
10828 TYPE_FIELDS (this_type
) = (struct field
*)
10829 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
10830 memcpy (TYPE_FIELDS (this_type
), fields
,
10831 sizeof (struct field
) * num_fields
);
10835 TYPE_UNSIGNED (this_type
) = 1;
10837 TYPE_FLAG_ENUM (this_type
) = 1;
10840 /* If we are reading an enum from a .debug_types unit, and the enum
10841 is a declaration, and the enum is not the signatured type in the
10842 unit, then we do not want to add a symbol for it. Adding a
10843 symbol would in some cases obscure the true definition of the
10844 enum, giving users an incomplete type when the definition is
10845 actually available. Note that we do not want to do this for all
10846 enums which are just declarations, because C++0x allows forward
10847 enum declarations. */
10848 if (cu
->per_cu
->is_debug_types
10849 && die_is_declaration (die
, cu
))
10851 struct signatured_type
*sig_type
;
10854 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
10855 cu
->per_cu
->info_or_types_section
,
10856 cu
->per_cu
->offset
);
10857 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
10858 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
10862 new_symbol (die
, this_type
, cu
);
10865 /* Extract all information from a DW_TAG_array_type DIE and put it in
10866 the DIE's type field. For now, this only handles one dimensional
10869 static struct type
*
10870 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10872 struct objfile
*objfile
= cu
->objfile
;
10873 struct die_info
*child_die
;
10875 struct type
*element_type
, *range_type
, *index_type
;
10876 struct type
**range_types
= NULL
;
10877 struct attribute
*attr
;
10879 struct cleanup
*back_to
;
10882 element_type
= die_type (die
, cu
);
10884 /* The die_type call above may have already set the type for this DIE. */
10885 type
= get_die_type (die
, cu
);
10889 /* Irix 6.2 native cc creates array types without children for
10890 arrays with unspecified length. */
10891 if (die
->child
== NULL
)
10893 index_type
= objfile_type (objfile
)->builtin_int
;
10894 range_type
= create_range_type (NULL
, index_type
, 0, -1);
10895 type
= create_array_type (NULL
, element_type
, range_type
);
10896 return set_die_type (die
, type
, cu
);
10899 back_to
= make_cleanup (null_cleanup
, NULL
);
10900 child_die
= die
->child
;
10901 while (child_die
&& child_die
->tag
)
10903 if (child_die
->tag
== DW_TAG_subrange_type
)
10905 struct type
*child_type
= read_type_die (child_die
, cu
);
10907 if (child_type
!= NULL
)
10909 /* The range type was succesfully read. Save it for the
10910 array type creation. */
10911 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
10913 range_types
= (struct type
**)
10914 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
10915 * sizeof (struct type
*));
10917 make_cleanup (free_current_contents
, &range_types
);
10919 range_types
[ndim
++] = child_type
;
10922 child_die
= sibling_die (child_die
);
10925 /* Dwarf2 dimensions are output from left to right, create the
10926 necessary array types in backwards order. */
10928 type
= element_type
;
10930 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
10935 type
= create_array_type (NULL
, type
, range_types
[i
++]);
10940 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
10943 /* Understand Dwarf2 support for vector types (like they occur on
10944 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
10945 array type. This is not part of the Dwarf2/3 standard yet, but a
10946 custom vendor extension. The main difference between a regular
10947 array and the vector variant is that vectors are passed by value
10949 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
10951 make_vector_type (type
);
10953 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
10954 implementation may choose to implement triple vectors using this
10956 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10959 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
10960 TYPE_LENGTH (type
) = DW_UNSND (attr
);
10962 complaint (&symfile_complaints
,
10963 _("DW_AT_byte_size for array type smaller "
10964 "than the total size of elements"));
10967 name
= dwarf2_name (die
, cu
);
10969 TYPE_NAME (type
) = name
;
10971 /* Install the type in the die. */
10972 set_die_type (die
, type
, cu
);
10974 /* set_die_type should be already done. */
10975 set_descriptive_type (type
, die
, cu
);
10977 do_cleanups (back_to
);
10982 static enum dwarf_array_dim_ordering
10983 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
10985 struct attribute
*attr
;
10987 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
10989 if (attr
) return DW_SND (attr
);
10991 /* GNU F77 is a special case, as at 08/2004 array type info is the
10992 opposite order to the dwarf2 specification, but data is still
10993 laid out as per normal fortran.
10995 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
10996 version checking. */
10998 if (cu
->language
== language_fortran
10999 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11001 return DW_ORD_row_major
;
11004 switch (cu
->language_defn
->la_array_ordering
)
11006 case array_column_major
:
11007 return DW_ORD_col_major
;
11008 case array_row_major
:
11010 return DW_ORD_row_major
;
11014 /* Extract all information from a DW_TAG_set_type DIE and put it in
11015 the DIE's type field. */
11017 static struct type
*
11018 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11020 struct type
*domain_type
, *set_type
;
11021 struct attribute
*attr
;
11023 domain_type
= die_type (die
, cu
);
11025 /* The die_type call above may have already set the type for this DIE. */
11026 set_type
= get_die_type (die
, cu
);
11030 set_type
= create_set_type (NULL
, domain_type
);
11032 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11034 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11036 return set_die_type (die
, set_type
, cu
);
11039 /* First cut: install each common block member as a global variable. */
11042 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11044 struct die_info
*child_die
;
11045 struct attribute
*attr
;
11046 struct symbol
*sym
;
11047 CORE_ADDR base
= (CORE_ADDR
) 0;
11049 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11052 /* Support the .debug_loc offsets. */
11053 if (attr_form_is_block (attr
))
11055 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
11057 else if (attr_form_is_section_offset (attr
))
11059 dwarf2_complex_location_expr_complaint ();
11063 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11064 "common block member");
11067 if (die
->child
!= NULL
)
11069 child_die
= die
->child
;
11070 while (child_die
&& child_die
->tag
)
11074 sym
= new_symbol (child_die
, NULL
, cu
);
11076 && handle_data_member_location (child_die
, cu
, &offset
))
11078 SYMBOL_VALUE_ADDRESS (sym
) = base
+ offset
;
11079 add_symbol_to_list (sym
, &global_symbols
);
11081 child_die
= sibling_die (child_die
);
11086 /* Create a type for a C++ namespace. */
11088 static struct type
*
11089 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11091 struct objfile
*objfile
= cu
->objfile
;
11092 const char *previous_prefix
, *name
;
11096 /* For extensions, reuse the type of the original namespace. */
11097 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
11099 struct die_info
*ext_die
;
11100 struct dwarf2_cu
*ext_cu
= cu
;
11102 ext_die
= dwarf2_extension (die
, &ext_cu
);
11103 type
= read_type_die (ext_die
, ext_cu
);
11105 /* EXT_CU may not be the same as CU.
11106 Ensure TYPE is recorded in CU's type_hash table. */
11107 return set_die_type (die
, type
, cu
);
11110 name
= namespace_name (die
, &is_anonymous
, cu
);
11112 /* Now build the name of the current namespace. */
11114 previous_prefix
= determine_prefix (die
, cu
);
11115 if (previous_prefix
[0] != '\0')
11116 name
= typename_concat (&objfile
->objfile_obstack
,
11117 previous_prefix
, name
, 0, cu
);
11119 /* Create the type. */
11120 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
11122 TYPE_NAME (type
) = (char *) name
;
11123 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11125 return set_die_type (die
, type
, cu
);
11128 /* Read a C++ namespace. */
11131 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11133 struct objfile
*objfile
= cu
->objfile
;
11136 /* Add a symbol associated to this if we haven't seen the namespace
11137 before. Also, add a using directive if it's an anonymous
11140 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
11144 type
= read_type_die (die
, cu
);
11145 new_symbol (die
, type
, cu
);
11147 namespace_name (die
, &is_anonymous
, cu
);
11150 const char *previous_prefix
= determine_prefix (die
, cu
);
11152 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
11153 NULL
, NULL
, &objfile
->objfile_obstack
);
11157 if (die
->child
!= NULL
)
11159 struct die_info
*child_die
= die
->child
;
11161 while (child_die
&& child_die
->tag
)
11163 process_die (child_die
, cu
);
11164 child_die
= sibling_die (child_die
);
11169 /* Read a Fortran module as type. This DIE can be only a declaration used for
11170 imported module. Still we need that type as local Fortran "use ... only"
11171 declaration imports depend on the created type in determine_prefix. */
11173 static struct type
*
11174 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11176 struct objfile
*objfile
= cu
->objfile
;
11180 module_name
= dwarf2_name (die
, cu
);
11182 complaint (&symfile_complaints
,
11183 _("DW_TAG_module has no name, offset 0x%x"),
11184 die
->offset
.sect_off
);
11185 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
11187 /* determine_prefix uses TYPE_TAG_NAME. */
11188 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11190 return set_die_type (die
, type
, cu
);
11193 /* Read a Fortran module. */
11196 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
11198 struct die_info
*child_die
= die
->child
;
11200 while (child_die
&& child_die
->tag
)
11202 process_die (child_die
, cu
);
11203 child_die
= sibling_die (child_die
);
11207 /* Return the name of the namespace represented by DIE. Set
11208 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
11211 static const char *
11212 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
11214 struct die_info
*current_die
;
11215 const char *name
= NULL
;
11217 /* Loop through the extensions until we find a name. */
11219 for (current_die
= die
;
11220 current_die
!= NULL
;
11221 current_die
= dwarf2_extension (die
, &cu
))
11223 name
= dwarf2_name (current_die
, cu
);
11228 /* Is it an anonymous namespace? */
11230 *is_anonymous
= (name
== NULL
);
11232 name
= CP_ANONYMOUS_NAMESPACE_STR
;
11237 /* Extract all information from a DW_TAG_pointer_type DIE and add to
11238 the user defined type vector. */
11240 static struct type
*
11241 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11243 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
11244 struct comp_unit_head
*cu_header
= &cu
->header
;
11246 struct attribute
*attr_byte_size
;
11247 struct attribute
*attr_address_class
;
11248 int byte_size
, addr_class
;
11249 struct type
*target_type
;
11251 target_type
= die_type (die
, cu
);
11253 /* The die_type call above may have already set the type for this DIE. */
11254 type
= get_die_type (die
, cu
);
11258 type
= lookup_pointer_type (target_type
);
11260 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11261 if (attr_byte_size
)
11262 byte_size
= DW_UNSND (attr_byte_size
);
11264 byte_size
= cu_header
->addr_size
;
11266 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
11267 if (attr_address_class
)
11268 addr_class
= DW_UNSND (attr_address_class
);
11270 addr_class
= DW_ADDR_none
;
11272 /* If the pointer size or address class is different than the
11273 default, create a type variant marked as such and set the
11274 length accordingly. */
11275 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
11277 if (gdbarch_address_class_type_flags_p (gdbarch
))
11281 type_flags
= gdbarch_address_class_type_flags
11282 (gdbarch
, byte_size
, addr_class
);
11283 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
11285 type
= make_type_with_address_space (type
, type_flags
);
11287 else if (TYPE_LENGTH (type
) != byte_size
)
11289 complaint (&symfile_complaints
,
11290 _("invalid pointer size %d"), byte_size
);
11294 /* Should we also complain about unhandled address classes? */
11298 TYPE_LENGTH (type
) = byte_size
;
11299 return set_die_type (die
, type
, cu
);
11302 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
11303 the user defined type vector. */
11305 static struct type
*
11306 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11309 struct type
*to_type
;
11310 struct type
*domain
;
11312 to_type
= die_type (die
, cu
);
11313 domain
= die_containing_type (die
, cu
);
11315 /* The calls above may have already set the type for this DIE. */
11316 type
= get_die_type (die
, cu
);
11320 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
11321 type
= lookup_methodptr_type (to_type
);
11323 type
= lookup_memberptr_type (to_type
, domain
);
11325 return set_die_type (die
, type
, cu
);
11328 /* Extract all information from a DW_TAG_reference_type DIE and add to
11329 the user defined type vector. */
11331 static struct type
*
11332 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11334 struct comp_unit_head
*cu_header
= &cu
->header
;
11335 struct type
*type
, *target_type
;
11336 struct attribute
*attr
;
11338 target_type
= die_type (die
, cu
);
11340 /* The die_type call above may have already set the type for this DIE. */
11341 type
= get_die_type (die
, cu
);
11345 type
= lookup_reference_type (target_type
);
11346 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11349 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11353 TYPE_LENGTH (type
) = cu_header
->addr_size
;
11355 return set_die_type (die
, type
, cu
);
11358 static struct type
*
11359 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11361 struct type
*base_type
, *cv_type
;
11363 base_type
= die_type (die
, cu
);
11365 /* The die_type call above may have already set the type for this DIE. */
11366 cv_type
= get_die_type (die
, cu
);
11370 /* In case the const qualifier is applied to an array type, the element type
11371 is so qualified, not the array type (section 6.7.3 of C99). */
11372 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
11374 struct type
*el_type
, *inner_array
;
11376 base_type
= copy_type (base_type
);
11377 inner_array
= base_type
;
11379 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
11381 TYPE_TARGET_TYPE (inner_array
) =
11382 copy_type (TYPE_TARGET_TYPE (inner_array
));
11383 inner_array
= TYPE_TARGET_TYPE (inner_array
);
11386 el_type
= TYPE_TARGET_TYPE (inner_array
);
11387 TYPE_TARGET_TYPE (inner_array
) =
11388 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
11390 return set_die_type (die
, base_type
, cu
);
11393 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
11394 return set_die_type (die
, cv_type
, cu
);
11397 static struct type
*
11398 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11400 struct type
*base_type
, *cv_type
;
11402 base_type
= die_type (die
, cu
);
11404 /* The die_type call above may have already set the type for this DIE. */
11405 cv_type
= get_die_type (die
, cu
);
11409 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
11410 return set_die_type (die
, cv_type
, cu
);
11413 /* Extract all information from a DW_TAG_string_type DIE and add to
11414 the user defined type vector. It isn't really a user defined type,
11415 but it behaves like one, with other DIE's using an AT_user_def_type
11416 attribute to reference it. */
11418 static struct type
*
11419 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11421 struct objfile
*objfile
= cu
->objfile
;
11422 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11423 struct type
*type
, *range_type
, *index_type
, *char_type
;
11424 struct attribute
*attr
;
11425 unsigned int length
;
11427 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
11430 length
= DW_UNSND (attr
);
11434 /* Check for the DW_AT_byte_size attribute. */
11435 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11438 length
= DW_UNSND (attr
);
11446 index_type
= objfile_type (objfile
)->builtin_int
;
11447 range_type
= create_range_type (NULL
, index_type
, 1, length
);
11448 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
11449 type
= create_string_type (NULL
, char_type
, range_type
);
11451 return set_die_type (die
, type
, cu
);
11454 /* Handle DIES due to C code like:
11458 int (*funcp)(int a, long l);
11462 ('funcp' generates a DW_TAG_subroutine_type DIE). */
11464 static struct type
*
11465 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11467 struct objfile
*objfile
= cu
->objfile
;
11468 struct type
*type
; /* Type that this function returns. */
11469 struct type
*ftype
; /* Function that returns above type. */
11470 struct attribute
*attr
;
11472 type
= die_type (die
, cu
);
11474 /* The die_type call above may have already set the type for this DIE. */
11475 ftype
= get_die_type (die
, cu
);
11479 ftype
= lookup_function_type (type
);
11481 /* All functions in C++, Pascal and Java have prototypes. */
11482 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
11483 if ((attr
&& (DW_UNSND (attr
) != 0))
11484 || cu
->language
== language_cplus
11485 || cu
->language
== language_java
11486 || cu
->language
== language_pascal
)
11487 TYPE_PROTOTYPED (ftype
) = 1;
11488 else if (producer_is_realview (cu
->producer
))
11489 /* RealView does not emit DW_AT_prototyped. We can not
11490 distinguish prototyped and unprototyped functions; default to
11491 prototyped, since that is more common in modern code (and
11492 RealView warns about unprototyped functions). */
11493 TYPE_PROTOTYPED (ftype
) = 1;
11495 /* Store the calling convention in the type if it's available in
11496 the subroutine die. Otherwise set the calling convention to
11497 the default value DW_CC_normal. */
11498 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
11500 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
11501 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
11502 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
11504 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
11506 /* We need to add the subroutine type to the die immediately so
11507 we don't infinitely recurse when dealing with parameters
11508 declared as the same subroutine type. */
11509 set_die_type (die
, ftype
, cu
);
11511 if (die
->child
!= NULL
)
11513 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
11514 struct die_info
*child_die
;
11515 int nparams
, iparams
;
11517 /* Count the number of parameters.
11518 FIXME: GDB currently ignores vararg functions, but knows about
11519 vararg member functions. */
11521 child_die
= die
->child
;
11522 while (child_die
&& child_die
->tag
)
11524 if (child_die
->tag
== DW_TAG_formal_parameter
)
11526 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
11527 TYPE_VARARGS (ftype
) = 1;
11528 child_die
= sibling_die (child_die
);
11531 /* Allocate storage for parameters and fill them in. */
11532 TYPE_NFIELDS (ftype
) = nparams
;
11533 TYPE_FIELDS (ftype
) = (struct field
*)
11534 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
11536 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
11537 even if we error out during the parameters reading below. */
11538 for (iparams
= 0; iparams
< nparams
; iparams
++)
11539 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
11542 child_die
= die
->child
;
11543 while (child_die
&& child_die
->tag
)
11545 if (child_die
->tag
== DW_TAG_formal_parameter
)
11547 struct type
*arg_type
;
11549 /* DWARF version 2 has no clean way to discern C++
11550 static and non-static member functions. G++ helps
11551 GDB by marking the first parameter for non-static
11552 member functions (which is the this pointer) as
11553 artificial. We pass this information to
11554 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
11556 DWARF version 3 added DW_AT_object_pointer, which GCC
11557 4.5 does not yet generate. */
11558 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
11560 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
11563 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
11565 /* GCC/43521: In java, the formal parameter
11566 "this" is sometimes not marked with DW_AT_artificial. */
11567 if (cu
->language
== language_java
)
11569 const char *name
= dwarf2_name (child_die
, cu
);
11571 if (name
&& !strcmp (name
, "this"))
11572 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
11575 arg_type
= die_type (child_die
, cu
);
11577 /* RealView does not mark THIS as const, which the testsuite
11578 expects. GCC marks THIS as const in method definitions,
11579 but not in the class specifications (GCC PR 43053). */
11580 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
11581 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
11584 struct dwarf2_cu
*arg_cu
= cu
;
11585 const char *name
= dwarf2_name (child_die
, cu
);
11587 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
11590 /* If the compiler emits this, use it. */
11591 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
11594 else if (name
&& strcmp (name
, "this") == 0)
11595 /* Function definitions will have the argument names. */
11597 else if (name
== NULL
&& iparams
== 0)
11598 /* Declarations may not have the names, so like
11599 elsewhere in GDB, assume an artificial first
11600 argument is "this". */
11604 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
11608 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
11611 child_die
= sibling_die (child_die
);
11618 static struct type
*
11619 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
11621 struct objfile
*objfile
= cu
->objfile
;
11622 const char *name
= NULL
;
11623 struct type
*this_type
, *target_type
;
11625 name
= dwarf2_full_name (NULL
, die
, cu
);
11626 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
11627 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
11628 TYPE_NAME (this_type
) = (char *) name
;
11629 set_die_type (die
, this_type
, cu
);
11630 target_type
= die_type (die
, cu
);
11631 if (target_type
!= this_type
)
11632 TYPE_TARGET_TYPE (this_type
) = target_type
;
11635 /* Self-referential typedefs are, it seems, not allowed by the DWARF
11636 spec and cause infinite loops in GDB. */
11637 complaint (&symfile_complaints
,
11638 _("Self-referential DW_TAG_typedef "
11639 "- DIE at 0x%x [in module %s]"),
11640 die
->offset
.sect_off
, objfile
->name
);
11641 TYPE_TARGET_TYPE (this_type
) = NULL
;
11646 /* Find a representation of a given base type and install
11647 it in the TYPE field of the die. */
11649 static struct type
*
11650 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11652 struct objfile
*objfile
= cu
->objfile
;
11654 struct attribute
*attr
;
11655 int encoding
= 0, size
= 0;
11657 enum type_code code
= TYPE_CODE_INT
;
11658 int type_flags
= 0;
11659 struct type
*target_type
= NULL
;
11661 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
11664 encoding
= DW_UNSND (attr
);
11666 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11669 size
= DW_UNSND (attr
);
11671 name
= dwarf2_name (die
, cu
);
11674 complaint (&symfile_complaints
,
11675 _("DW_AT_name missing from DW_TAG_base_type"));
11680 case DW_ATE_address
:
11681 /* Turn DW_ATE_address into a void * pointer. */
11682 code
= TYPE_CODE_PTR
;
11683 type_flags
|= TYPE_FLAG_UNSIGNED
;
11684 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
11686 case DW_ATE_boolean
:
11687 code
= TYPE_CODE_BOOL
;
11688 type_flags
|= TYPE_FLAG_UNSIGNED
;
11690 case DW_ATE_complex_float
:
11691 code
= TYPE_CODE_COMPLEX
;
11692 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
11694 case DW_ATE_decimal_float
:
11695 code
= TYPE_CODE_DECFLOAT
;
11698 code
= TYPE_CODE_FLT
;
11700 case DW_ATE_signed
:
11702 case DW_ATE_unsigned
:
11703 type_flags
|= TYPE_FLAG_UNSIGNED
;
11704 if (cu
->language
== language_fortran
11706 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
11707 code
= TYPE_CODE_CHAR
;
11709 case DW_ATE_signed_char
:
11710 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11711 || cu
->language
== language_pascal
11712 || cu
->language
== language_fortran
)
11713 code
= TYPE_CODE_CHAR
;
11715 case DW_ATE_unsigned_char
:
11716 if (cu
->language
== language_ada
|| cu
->language
== language_m2
11717 || cu
->language
== language_pascal
11718 || cu
->language
== language_fortran
)
11719 code
= TYPE_CODE_CHAR
;
11720 type_flags
|= TYPE_FLAG_UNSIGNED
;
11723 /* We just treat this as an integer and then recognize the
11724 type by name elsewhere. */
11728 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
11729 dwarf_type_encoding_name (encoding
));
11733 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
11734 TYPE_NAME (type
) = name
;
11735 TYPE_TARGET_TYPE (type
) = target_type
;
11737 if (name
&& strcmp (name
, "char") == 0)
11738 TYPE_NOSIGN (type
) = 1;
11740 return set_die_type (die
, type
, cu
);
11743 /* Read the given DW_AT_subrange DIE. */
11745 static struct type
*
11746 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11748 struct type
*base_type
;
11749 struct type
*range_type
;
11750 struct attribute
*attr
;
11752 int low_default_is_valid
;
11754 LONGEST negative_mask
;
11756 base_type
= die_type (die
, cu
);
11757 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
11758 check_typedef (base_type
);
11760 /* The die_type call above may have already set the type for this DIE. */
11761 range_type
= get_die_type (die
, cu
);
11765 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
11766 omitting DW_AT_lower_bound. */
11767 switch (cu
->language
)
11770 case language_cplus
:
11772 low_default_is_valid
= 1;
11774 case language_fortran
:
11776 low_default_is_valid
= 1;
11779 case language_java
:
11780 case language_objc
:
11782 low_default_is_valid
= (cu
->header
.version
>= 4);
11786 case language_pascal
:
11788 low_default_is_valid
= (cu
->header
.version
>= 4);
11792 low_default_is_valid
= 0;
11796 /* FIXME: For variable sized arrays either of these could be
11797 a variable rather than a constant value. We'll allow it,
11798 but we don't know how to handle it. */
11799 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
11801 low
= dwarf2_get_attr_constant_value (attr
, low
);
11802 else if (!low_default_is_valid
)
11803 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
11804 "- DIE at 0x%x [in module %s]"),
11805 die
->offset
.sect_off
, cu
->objfile
->name
);
11807 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
11810 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
11812 /* GCC encodes arrays with unspecified or dynamic length
11813 with a DW_FORM_block1 attribute or a reference attribute.
11814 FIXME: GDB does not yet know how to handle dynamic
11815 arrays properly, treat them as arrays with unspecified
11818 FIXME: jimb/2003-09-22: GDB does not really know
11819 how to handle arrays of unspecified length
11820 either; we just represent them as zero-length
11821 arrays. Choose an appropriate upper bound given
11822 the lower bound we've computed above. */
11826 high
= dwarf2_get_attr_constant_value (attr
, 1);
11830 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
11833 int count
= dwarf2_get_attr_constant_value (attr
, 1);
11834 high
= low
+ count
- 1;
11838 /* Unspecified array length. */
11843 /* Dwarf-2 specifications explicitly allows to create subrange types
11844 without specifying a base type.
11845 In that case, the base type must be set to the type of
11846 the lower bound, upper bound or count, in that order, if any of these
11847 three attributes references an object that has a type.
11848 If no base type is found, the Dwarf-2 specifications say that
11849 a signed integer type of size equal to the size of an address should
11851 For the following C code: `extern char gdb_int [];'
11852 GCC produces an empty range DIE.
11853 FIXME: muller/2010-05-28: Possible references to object for low bound,
11854 high bound or count are not yet handled by this code. */
11855 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
11857 struct objfile
*objfile
= cu
->objfile
;
11858 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11859 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
11860 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
11862 /* Test "int", "long int", and "long long int" objfile types,
11863 and select the first one having a size above or equal to the
11864 architecture address size. */
11865 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11866 base_type
= int_type
;
11869 int_type
= objfile_type (objfile
)->builtin_long
;
11870 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11871 base_type
= int_type
;
11874 int_type
= objfile_type (objfile
)->builtin_long_long
;
11875 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
11876 base_type
= int_type
;
11882 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
11883 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
11884 low
|= negative_mask
;
11885 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
11886 high
|= negative_mask
;
11888 range_type
= create_range_type (NULL
, base_type
, low
, high
);
11890 /* Mark arrays with dynamic length at least as an array of unspecified
11891 length. GDB could check the boundary but before it gets implemented at
11892 least allow accessing the array elements. */
11893 if (attr
&& attr_form_is_block (attr
))
11894 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11896 /* Ada expects an empty array on no boundary attributes. */
11897 if (attr
== NULL
&& cu
->language
!= language_ada
)
11898 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
11900 name
= dwarf2_name (die
, cu
);
11902 TYPE_NAME (range_type
) = name
;
11904 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11906 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
11908 set_die_type (die
, range_type
, cu
);
11910 /* set_die_type should be already done. */
11911 set_descriptive_type (range_type
, die
, cu
);
11916 static struct type
*
11917 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11921 /* For now, we only support the C meaning of an unspecified type: void. */
11923 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
11924 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
11926 return set_die_type (die
, type
, cu
);
11929 /* Read a single die and all its descendents. Set the die's sibling
11930 field to NULL; set other fields in the die correctly, and set all
11931 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
11932 location of the info_ptr after reading all of those dies. PARENT
11933 is the parent of the die in question. */
11935 static struct die_info
*
11936 read_die_and_children (const struct die_reader_specs
*reader
,
11937 gdb_byte
*info_ptr
,
11938 gdb_byte
**new_info_ptr
,
11939 struct die_info
*parent
)
11941 struct die_info
*die
;
11945 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
11948 *new_info_ptr
= cur_ptr
;
11951 store_in_ref_table (die
, reader
->cu
);
11954 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
11958 *new_info_ptr
= cur_ptr
;
11961 die
->sibling
= NULL
;
11962 die
->parent
= parent
;
11966 /* Read a die, all of its descendents, and all of its siblings; set
11967 all of the fields of all of the dies correctly. Arguments are as
11968 in read_die_and_children. */
11970 static struct die_info
*
11971 read_die_and_siblings (const struct die_reader_specs
*reader
,
11972 gdb_byte
*info_ptr
,
11973 gdb_byte
**new_info_ptr
,
11974 struct die_info
*parent
)
11976 struct die_info
*first_die
, *last_sibling
;
11979 cur_ptr
= info_ptr
;
11980 first_die
= last_sibling
= NULL
;
11984 struct die_info
*die
11985 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
11989 *new_info_ptr
= cur_ptr
;
11996 last_sibling
->sibling
= die
;
11998 last_sibling
= die
;
12002 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12004 The caller is responsible for filling in the extra attributes
12005 and updating (*DIEP)->num_attrs.
12006 Set DIEP to point to a newly allocated die with its information,
12007 except for its child, sibling, and parent fields.
12008 Set HAS_CHILDREN to tell whether the die has children or not. */
12011 read_full_die_1 (const struct die_reader_specs
*reader
,
12012 struct die_info
**diep
, gdb_byte
*info_ptr
,
12013 int *has_children
, int num_extra_attrs
)
12015 unsigned int abbrev_number
, bytes_read
, i
;
12016 sect_offset offset
;
12017 struct abbrev_info
*abbrev
;
12018 struct die_info
*die
;
12019 struct dwarf2_cu
*cu
= reader
->cu
;
12020 bfd
*abfd
= reader
->abfd
;
12022 offset
.sect_off
= info_ptr
- reader
->buffer
;
12023 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12024 info_ptr
+= bytes_read
;
12025 if (!abbrev_number
)
12032 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12034 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12036 bfd_get_filename (abfd
));
12038 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
12039 die
->offset
= offset
;
12040 die
->tag
= abbrev
->tag
;
12041 die
->abbrev
= abbrev_number
;
12043 /* Make the result usable.
12044 The caller needs to update num_attrs after adding the extra
12046 die
->num_attrs
= abbrev
->num_attrs
;
12048 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12049 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
12053 *has_children
= abbrev
->has_children
;
12057 /* Read a die and all its attributes.
12058 Set DIEP to point to a newly allocated die with its information,
12059 except for its child, sibling, and parent fields.
12060 Set HAS_CHILDREN to tell whether the die has children or not. */
12063 read_full_die (const struct die_reader_specs
*reader
,
12064 struct die_info
**diep
, gdb_byte
*info_ptr
,
12067 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
12070 /* Abbreviation tables.
12072 In DWARF version 2, the description of the debugging information is
12073 stored in a separate .debug_abbrev section. Before we read any
12074 dies from a section we read in all abbreviations and install them
12075 in a hash table. */
12077 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12079 static struct abbrev_info
*
12080 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
12082 struct abbrev_info
*abbrev
;
12084 abbrev
= (struct abbrev_info
*)
12085 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
12086 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12090 /* Add an abbreviation to the table. */
12093 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
12094 unsigned int abbrev_number
,
12095 struct abbrev_info
*abbrev
)
12097 unsigned int hash_number
;
12099 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12100 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
12101 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
12104 /* Look up an abbrev in the table.
12105 Returns NULL if the abbrev is not found. */
12107 static struct abbrev_info
*
12108 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
12109 unsigned int abbrev_number
)
12111 unsigned int hash_number
;
12112 struct abbrev_info
*abbrev
;
12114 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12115 abbrev
= abbrev_table
->abbrevs
[hash_number
];
12119 if (abbrev
->number
== abbrev_number
)
12121 abbrev
= abbrev
->next
;
12126 /* Read in an abbrev table. */
12128 static struct abbrev_table
*
12129 abbrev_table_read_table (struct dwarf2_section_info
*section
,
12130 sect_offset offset
)
12132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12133 bfd
*abfd
= section
->asection
->owner
;
12134 struct abbrev_table
*abbrev_table
;
12135 gdb_byte
*abbrev_ptr
;
12136 struct abbrev_info
*cur_abbrev
;
12137 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
12138 unsigned int abbrev_form
;
12139 struct attr_abbrev
*cur_attrs
;
12140 unsigned int allocated_attrs
;
12142 abbrev_table
= XMALLOC (struct abbrev_table
);
12143 abbrev_table
->offset
= offset
;
12144 obstack_init (&abbrev_table
->abbrev_obstack
);
12145 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12147 * sizeof (struct abbrev_info
*)));
12148 memset (abbrev_table
->abbrevs
, 0,
12149 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
12151 dwarf2_read_section (objfile
, section
);
12152 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
12153 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12154 abbrev_ptr
+= bytes_read
;
12156 allocated_attrs
= ATTR_ALLOC_CHUNK
;
12157 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
12159 /* Loop until we reach an abbrev number of 0. */
12160 while (abbrev_number
)
12162 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
12164 /* read in abbrev header */
12165 cur_abbrev
->number
= abbrev_number
;
12166 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12167 abbrev_ptr
+= bytes_read
;
12168 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
12171 /* now read in declarations */
12172 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12173 abbrev_ptr
+= bytes_read
;
12174 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12175 abbrev_ptr
+= bytes_read
;
12176 while (abbrev_name
)
12178 if (cur_abbrev
->num_attrs
== allocated_attrs
)
12180 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
12182 = xrealloc (cur_attrs
, (allocated_attrs
12183 * sizeof (struct attr_abbrev
)));
12186 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
12187 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
12188 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12189 abbrev_ptr
+= bytes_read
;
12190 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12191 abbrev_ptr
+= bytes_read
;
12194 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
12195 (cur_abbrev
->num_attrs
12196 * sizeof (struct attr_abbrev
)));
12197 memcpy (cur_abbrev
->attrs
, cur_attrs
,
12198 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
12200 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
12202 /* Get next abbreviation.
12203 Under Irix6 the abbreviations for a compilation unit are not
12204 always properly terminated with an abbrev number of 0.
12205 Exit loop if we encounter an abbreviation which we have
12206 already read (which means we are about to read the abbreviations
12207 for the next compile unit) or if the end of the abbreviation
12208 table is reached. */
12209 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
12211 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
12212 abbrev_ptr
+= bytes_read
;
12213 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
12218 return abbrev_table
;
12221 /* Free the resources held by ABBREV_TABLE. */
12224 abbrev_table_free (struct abbrev_table
*abbrev_table
)
12226 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
12227 xfree (abbrev_table
);
12230 /* Same as abbrev_table_free but as a cleanup.
12231 We pass in a pointer to the pointer to the table so that we can
12232 set the pointer to NULL when we're done. It also simplifies
12233 build_type_unit_groups. */
12236 abbrev_table_free_cleanup (void *table_ptr
)
12238 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
12240 if (*abbrev_table_ptr
!= NULL
)
12241 abbrev_table_free (*abbrev_table_ptr
);
12242 *abbrev_table_ptr
= NULL
;
12245 /* Read the abbrev table for CU from ABBREV_SECTION. */
12248 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
12249 struct dwarf2_section_info
*abbrev_section
)
12252 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
12255 /* Release the memory used by the abbrev table for a compilation unit. */
12258 dwarf2_free_abbrev_table (void *ptr_to_cu
)
12260 struct dwarf2_cu
*cu
= ptr_to_cu
;
12262 abbrev_table_free (cu
->abbrev_table
);
12263 /* Set this to NULL so that we SEGV if we try to read it later,
12264 and also because free_comp_unit verifies this is NULL. */
12265 cu
->abbrev_table
= NULL
;
12268 /* Returns nonzero if TAG represents a type that we might generate a partial
12272 is_type_tag_for_partial (int tag
)
12277 /* Some types that would be reasonable to generate partial symbols for,
12278 that we don't at present. */
12279 case DW_TAG_array_type
:
12280 case DW_TAG_file_type
:
12281 case DW_TAG_ptr_to_member_type
:
12282 case DW_TAG_set_type
:
12283 case DW_TAG_string_type
:
12284 case DW_TAG_subroutine_type
:
12286 case DW_TAG_base_type
:
12287 case DW_TAG_class_type
:
12288 case DW_TAG_interface_type
:
12289 case DW_TAG_enumeration_type
:
12290 case DW_TAG_structure_type
:
12291 case DW_TAG_subrange_type
:
12292 case DW_TAG_typedef
:
12293 case DW_TAG_union_type
:
12300 /* Load all DIEs that are interesting for partial symbols into memory. */
12302 static struct partial_die_info
*
12303 load_partial_dies (const struct die_reader_specs
*reader
,
12304 gdb_byte
*info_ptr
, int building_psymtab
)
12306 struct dwarf2_cu
*cu
= reader
->cu
;
12307 struct objfile
*objfile
= cu
->objfile
;
12308 struct partial_die_info
*part_die
;
12309 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
12310 struct abbrev_info
*abbrev
;
12311 unsigned int bytes_read
;
12312 unsigned int load_all
= 0;
12313 int nesting_level
= 1;
12318 gdb_assert (cu
->per_cu
!= NULL
);
12319 if (cu
->per_cu
->load_all_dies
)
12323 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12327 &cu
->comp_unit_obstack
,
12328 hashtab_obstack_allocate
,
12329 dummy_obstack_deallocate
);
12331 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12332 sizeof (struct partial_die_info
));
12336 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
12338 /* A NULL abbrev means the end of a series of children. */
12339 if (abbrev
== NULL
)
12341 if (--nesting_level
== 0)
12343 /* PART_DIE was probably the last thing allocated on the
12344 comp_unit_obstack, so we could call obstack_free
12345 here. We don't do that because the waste is small,
12346 and will be cleaned up when we're done with this
12347 compilation unit. This way, we're also more robust
12348 against other users of the comp_unit_obstack. */
12351 info_ptr
+= bytes_read
;
12352 last_die
= parent_die
;
12353 parent_die
= parent_die
->die_parent
;
12357 /* Check for template arguments. We never save these; if
12358 they're seen, we just mark the parent, and go on our way. */
12359 if (parent_die
!= NULL
12360 && cu
->language
== language_cplus
12361 && (abbrev
->tag
== DW_TAG_template_type_param
12362 || abbrev
->tag
== DW_TAG_template_value_param
))
12364 parent_die
->has_template_arguments
= 1;
12368 /* We don't need a partial DIE for the template argument. */
12369 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12374 /* We only recurse into c++ subprograms looking for template arguments.
12375 Skip their other children. */
12377 && cu
->language
== language_cplus
12378 && parent_die
!= NULL
12379 && parent_die
->tag
== DW_TAG_subprogram
)
12381 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12385 /* Check whether this DIE is interesting enough to save. Normally
12386 we would not be interested in members here, but there may be
12387 later variables referencing them via DW_AT_specification (for
12388 static members). */
12390 && !is_type_tag_for_partial (abbrev
->tag
)
12391 && abbrev
->tag
!= DW_TAG_constant
12392 && abbrev
->tag
!= DW_TAG_enumerator
12393 && abbrev
->tag
!= DW_TAG_subprogram
12394 && abbrev
->tag
!= DW_TAG_lexical_block
12395 && abbrev
->tag
!= DW_TAG_variable
12396 && abbrev
->tag
!= DW_TAG_namespace
12397 && abbrev
->tag
!= DW_TAG_module
12398 && abbrev
->tag
!= DW_TAG_member
12399 && abbrev
->tag
!= DW_TAG_imported_unit
)
12401 /* Otherwise we skip to the next sibling, if any. */
12402 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
12406 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
12409 /* This two-pass algorithm for processing partial symbols has a
12410 high cost in cache pressure. Thus, handle some simple cases
12411 here which cover the majority of C partial symbols. DIEs
12412 which neither have specification tags in them, nor could have
12413 specification tags elsewhere pointing at them, can simply be
12414 processed and discarded.
12416 This segment is also optional; scan_partial_symbols and
12417 add_partial_symbol will handle these DIEs if we chain
12418 them in normally. When compilers which do not emit large
12419 quantities of duplicate debug information are more common,
12420 this code can probably be removed. */
12422 /* Any complete simple types at the top level (pretty much all
12423 of them, for a language without namespaces), can be processed
12425 if (parent_die
== NULL
12426 && part_die
->has_specification
== 0
12427 && part_die
->is_declaration
== 0
12428 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
12429 || part_die
->tag
== DW_TAG_base_type
12430 || part_die
->tag
== DW_TAG_subrange_type
))
12432 if (building_psymtab
&& part_die
->name
!= NULL
)
12433 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12434 VAR_DOMAIN
, LOC_TYPEDEF
,
12435 &objfile
->static_psymbols
,
12436 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12437 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12441 /* The exception for DW_TAG_typedef with has_children above is
12442 a workaround of GCC PR debug/47510. In the case of this complaint
12443 type_name_no_tag_or_error will error on such types later.
12445 GDB skipped children of DW_TAG_typedef by the shortcut above and then
12446 it could not find the child DIEs referenced later, this is checked
12447 above. In correct DWARF DW_TAG_typedef should have no children. */
12449 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
12450 complaint (&symfile_complaints
,
12451 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
12452 "- DIE at 0x%x [in module %s]"),
12453 part_die
->offset
.sect_off
, objfile
->name
);
12455 /* If we're at the second level, and we're an enumerator, and
12456 our parent has no specification (meaning possibly lives in a
12457 namespace elsewhere), then we can add the partial symbol now
12458 instead of queueing it. */
12459 if (part_die
->tag
== DW_TAG_enumerator
12460 && parent_die
!= NULL
12461 && parent_die
->die_parent
== NULL
12462 && parent_die
->tag
== DW_TAG_enumeration_type
12463 && parent_die
->has_specification
== 0)
12465 if (part_die
->name
== NULL
)
12466 complaint (&symfile_complaints
,
12467 _("malformed enumerator DIE ignored"));
12468 else if (building_psymtab
)
12469 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
12470 VAR_DOMAIN
, LOC_CONST
,
12471 (cu
->language
== language_cplus
12472 || cu
->language
== language_java
)
12473 ? &objfile
->global_psymbols
12474 : &objfile
->static_psymbols
,
12475 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
12477 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
12481 /* We'll save this DIE so link it in. */
12482 part_die
->die_parent
= parent_die
;
12483 part_die
->die_sibling
= NULL
;
12484 part_die
->die_child
= NULL
;
12486 if (last_die
&& last_die
== parent_die
)
12487 last_die
->die_child
= part_die
;
12489 last_die
->die_sibling
= part_die
;
12491 last_die
= part_die
;
12493 if (first_die
== NULL
)
12494 first_die
= part_die
;
12496 /* Maybe add the DIE to the hash table. Not all DIEs that we
12497 find interesting need to be in the hash table, because we
12498 also have the parent/sibling/child chains; only those that we
12499 might refer to by offset later during partial symbol reading.
12501 For now this means things that might have be the target of a
12502 DW_AT_specification, DW_AT_abstract_origin, or
12503 DW_AT_extension. DW_AT_extension will refer only to
12504 namespaces; DW_AT_abstract_origin refers to functions (and
12505 many things under the function DIE, but we do not recurse
12506 into function DIEs during partial symbol reading) and
12507 possibly variables as well; DW_AT_specification refers to
12508 declarations. Declarations ought to have the DW_AT_declaration
12509 flag. It happens that GCC forgets to put it in sometimes, but
12510 only for functions, not for types.
12512 Adding more things than necessary to the hash table is harmless
12513 except for the performance cost. Adding too few will result in
12514 wasted time in find_partial_die, when we reread the compilation
12515 unit with load_all_dies set. */
12518 || abbrev
->tag
== DW_TAG_constant
12519 || abbrev
->tag
== DW_TAG_subprogram
12520 || abbrev
->tag
== DW_TAG_variable
12521 || abbrev
->tag
== DW_TAG_namespace
12522 || part_die
->is_declaration
)
12526 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
12527 part_die
->offset
.sect_off
, INSERT
);
12531 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
12532 sizeof (struct partial_die_info
));
12534 /* For some DIEs we want to follow their children (if any). For C
12535 we have no reason to follow the children of structures; for other
12536 languages we have to, so that we can get at method physnames
12537 to infer fully qualified class names, for DW_AT_specification,
12538 and for C++ template arguments. For C++, we also look one level
12539 inside functions to find template arguments (if the name of the
12540 function does not already contain the template arguments).
12542 For Ada, we need to scan the children of subprograms and lexical
12543 blocks as well because Ada allows the definition of nested
12544 entities that could be interesting for the debugger, such as
12545 nested subprograms for instance. */
12546 if (last_die
->has_children
12548 || last_die
->tag
== DW_TAG_namespace
12549 || last_die
->tag
== DW_TAG_module
12550 || last_die
->tag
== DW_TAG_enumeration_type
12551 || (cu
->language
== language_cplus
12552 && last_die
->tag
== DW_TAG_subprogram
12553 && (last_die
->name
== NULL
12554 || strchr (last_die
->name
, '<') == NULL
))
12555 || (cu
->language
!= language_c
12556 && (last_die
->tag
== DW_TAG_class_type
12557 || last_die
->tag
== DW_TAG_interface_type
12558 || last_die
->tag
== DW_TAG_structure_type
12559 || last_die
->tag
== DW_TAG_union_type
))
12560 || (cu
->language
== language_ada
12561 && (last_die
->tag
== DW_TAG_subprogram
12562 || last_die
->tag
== DW_TAG_lexical_block
))))
12565 parent_die
= last_die
;
12569 /* Otherwise we skip to the next sibling, if any. */
12570 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
12572 /* Back to the top, do it again. */
12576 /* Read a minimal amount of information into the minimal die structure. */
12579 read_partial_die (const struct die_reader_specs
*reader
,
12580 struct partial_die_info
*part_die
,
12581 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
12582 gdb_byte
*info_ptr
)
12584 struct dwarf2_cu
*cu
= reader
->cu
;
12585 struct objfile
*objfile
= cu
->objfile
;
12586 gdb_byte
*buffer
= reader
->buffer
;
12588 struct attribute attr
;
12589 int has_low_pc_attr
= 0;
12590 int has_high_pc_attr
= 0;
12591 int high_pc_relative
= 0;
12593 memset (part_die
, 0, sizeof (struct partial_die_info
));
12595 part_die
->offset
.sect_off
= info_ptr
- buffer
;
12597 info_ptr
+= abbrev_len
;
12599 if (abbrev
== NULL
)
12602 part_die
->tag
= abbrev
->tag
;
12603 part_die
->has_children
= abbrev
->has_children
;
12605 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12607 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
12609 /* Store the data if it is of an attribute we want to keep in a
12610 partial symbol table. */
12614 switch (part_die
->tag
)
12616 case DW_TAG_compile_unit
:
12617 case DW_TAG_partial_unit
:
12618 case DW_TAG_type_unit
:
12619 /* Compilation units have a DW_AT_name that is a filename, not
12620 a source language identifier. */
12621 case DW_TAG_enumeration_type
:
12622 case DW_TAG_enumerator
:
12623 /* These tags always have simple identifiers already; no need
12624 to canonicalize them. */
12625 part_die
->name
= DW_STRING (&attr
);
12629 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
12630 &objfile
->objfile_obstack
);
12634 case DW_AT_linkage_name
:
12635 case DW_AT_MIPS_linkage_name
:
12636 /* Note that both forms of linkage name might appear. We
12637 assume they will be the same, and we only store the last
12639 if (cu
->language
== language_ada
)
12640 part_die
->name
= DW_STRING (&attr
);
12641 part_die
->linkage_name
= DW_STRING (&attr
);
12644 has_low_pc_attr
= 1;
12645 part_die
->lowpc
= DW_ADDR (&attr
);
12647 case DW_AT_high_pc
:
12648 has_high_pc_attr
= 1;
12649 if (attr
.form
== DW_FORM_addr
12650 || attr
.form
== DW_FORM_GNU_addr_index
)
12651 part_die
->highpc
= DW_ADDR (&attr
);
12654 high_pc_relative
= 1;
12655 part_die
->highpc
= DW_UNSND (&attr
);
12658 case DW_AT_location
:
12659 /* Support the .debug_loc offsets. */
12660 if (attr_form_is_block (&attr
))
12662 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
12664 else if (attr_form_is_section_offset (&attr
))
12666 dwarf2_complex_location_expr_complaint ();
12670 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12671 "partial symbol information");
12674 case DW_AT_external
:
12675 part_die
->is_external
= DW_UNSND (&attr
);
12677 case DW_AT_declaration
:
12678 part_die
->is_declaration
= DW_UNSND (&attr
);
12681 part_die
->has_type
= 1;
12683 case DW_AT_abstract_origin
:
12684 case DW_AT_specification
:
12685 case DW_AT_extension
:
12686 part_die
->has_specification
= 1;
12687 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
12688 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
12689 || cu
->per_cu
->is_dwz
);
12691 case DW_AT_sibling
:
12692 /* Ignore absolute siblings, they might point outside of
12693 the current compile unit. */
12694 if (attr
.form
== DW_FORM_ref_addr
)
12695 complaint (&symfile_complaints
,
12696 _("ignoring absolute DW_AT_sibling"));
12698 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
12700 case DW_AT_byte_size
:
12701 part_die
->has_byte_size
= 1;
12703 case DW_AT_calling_convention
:
12704 /* DWARF doesn't provide a way to identify a program's source-level
12705 entry point. DW_AT_calling_convention attributes are only meant
12706 to describe functions' calling conventions.
12708 However, because it's a necessary piece of information in
12709 Fortran, and because DW_CC_program is the only piece of debugging
12710 information whose definition refers to a 'main program' at all,
12711 several compilers have begun marking Fortran main programs with
12712 DW_CC_program --- even when those functions use the standard
12713 calling conventions.
12715 So until DWARF specifies a way to provide this information and
12716 compilers pick up the new representation, we'll support this
12718 if (DW_UNSND (&attr
) == DW_CC_program
12719 && cu
->language
== language_fortran
)
12721 set_main_name (part_die
->name
);
12723 /* As this DIE has a static linkage the name would be difficult
12724 to look up later. */
12725 language_of_main
= language_fortran
;
12729 if (DW_UNSND (&attr
) == DW_INL_inlined
12730 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
12731 part_die
->may_be_inlined
= 1;
12735 if (part_die
->tag
== DW_TAG_imported_unit
)
12737 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
12738 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
12739 || cu
->per_cu
->is_dwz
);
12748 if (high_pc_relative
)
12749 part_die
->highpc
+= part_die
->lowpc
;
12751 if (has_low_pc_attr
&& has_high_pc_attr
)
12753 /* When using the GNU linker, .gnu.linkonce. sections are used to
12754 eliminate duplicate copies of functions and vtables and such.
12755 The linker will arbitrarily choose one and discard the others.
12756 The AT_*_pc values for such functions refer to local labels in
12757 these sections. If the section from that file was discarded, the
12758 labels are not in the output, so the relocs get a value of 0.
12759 If this is a discarded function, mark the pc bounds as invalid,
12760 so that GDB will ignore it. */
12761 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
12763 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12765 complaint (&symfile_complaints
,
12766 _("DW_AT_low_pc %s is zero "
12767 "for DIE at 0x%x [in module %s]"),
12768 paddress (gdbarch
, part_die
->lowpc
),
12769 part_die
->offset
.sect_off
, objfile
->name
);
12771 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
12772 else if (part_die
->lowpc
>= part_die
->highpc
)
12774 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12776 complaint (&symfile_complaints
,
12777 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
12778 "for DIE at 0x%x [in module %s]"),
12779 paddress (gdbarch
, part_die
->lowpc
),
12780 paddress (gdbarch
, part_die
->highpc
),
12781 part_die
->offset
.sect_off
, objfile
->name
);
12784 part_die
->has_pc_info
= 1;
12790 /* Find a cached partial DIE at OFFSET in CU. */
12792 static struct partial_die_info
*
12793 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
12795 struct partial_die_info
*lookup_die
= NULL
;
12796 struct partial_die_info part_die
;
12798 part_die
.offset
= offset
;
12799 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
12805 /* Find a partial DIE at OFFSET, which may or may not be in CU,
12806 except in the case of .debug_types DIEs which do not reference
12807 outside their CU (they do however referencing other types via
12808 DW_FORM_ref_sig8). */
12810 static struct partial_die_info
*
12811 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
12813 struct objfile
*objfile
= cu
->objfile
;
12814 struct dwarf2_per_cu_data
*per_cu
= NULL
;
12815 struct partial_die_info
*pd
= NULL
;
12817 if (offset_in_dwz
== cu
->per_cu
->is_dwz
12818 && offset_in_cu_p (&cu
->header
, offset
))
12820 pd
= find_partial_die_in_comp_unit (offset
, cu
);
12823 /* We missed recording what we needed.
12824 Load all dies and try again. */
12825 per_cu
= cu
->per_cu
;
12829 /* TUs don't reference other CUs/TUs (except via type signatures). */
12830 if (cu
->per_cu
->is_debug_types
)
12832 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
12833 " external reference to offset 0x%lx [in module %s].\n"),
12834 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
12835 bfd_get_filename (objfile
->obfd
));
12837 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
12840 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
12841 load_partial_comp_unit (per_cu
);
12843 per_cu
->cu
->last_used
= 0;
12844 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12847 /* If we didn't find it, and not all dies have been loaded,
12848 load them all and try again. */
12850 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
12852 per_cu
->load_all_dies
= 1;
12854 /* This is nasty. When we reread the DIEs, somewhere up the call chain
12855 THIS_CU->cu may already be in use. So we can't just free it and
12856 replace its DIEs with the ones we read in. Instead, we leave those
12857 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
12858 and clobber THIS_CU->cu->partial_dies with the hash table for the new
12860 load_partial_comp_unit (per_cu
);
12862 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
12866 internal_error (__FILE__
, __LINE__
,
12867 _("could not find partial DIE 0x%x "
12868 "in cache [from module %s]\n"),
12869 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
12873 /* See if we can figure out if the class lives in a namespace. We do
12874 this by looking for a member function; its demangled name will
12875 contain namespace info, if there is any. */
12878 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
12879 struct dwarf2_cu
*cu
)
12881 /* NOTE: carlton/2003-10-07: Getting the info this way changes
12882 what template types look like, because the demangler
12883 frequently doesn't give the same name as the debug info. We
12884 could fix this by only using the demangled name to get the
12885 prefix (but see comment in read_structure_type). */
12887 struct partial_die_info
*real_pdi
;
12888 struct partial_die_info
*child_pdi
;
12890 /* If this DIE (this DIE's specification, if any) has a parent, then
12891 we should not do this. We'll prepend the parent's fully qualified
12892 name when we create the partial symbol. */
12894 real_pdi
= struct_pdi
;
12895 while (real_pdi
->has_specification
)
12896 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
12897 real_pdi
->spec_is_dwz
, cu
);
12899 if (real_pdi
->die_parent
!= NULL
)
12902 for (child_pdi
= struct_pdi
->die_child
;
12904 child_pdi
= child_pdi
->die_sibling
)
12906 if (child_pdi
->tag
== DW_TAG_subprogram
12907 && child_pdi
->linkage_name
!= NULL
)
12909 char *actual_class_name
12910 = language_class_name_from_physname (cu
->language_defn
,
12911 child_pdi
->linkage_name
);
12912 if (actual_class_name
!= NULL
)
12915 = obsavestring (actual_class_name
,
12916 strlen (actual_class_name
),
12917 &cu
->objfile
->objfile_obstack
);
12918 xfree (actual_class_name
);
12925 /* Adjust PART_DIE before generating a symbol for it. This function
12926 may set the is_external flag or change the DIE's name. */
12929 fixup_partial_die (struct partial_die_info
*part_die
,
12930 struct dwarf2_cu
*cu
)
12932 /* Once we've fixed up a die, there's no point in doing so again.
12933 This also avoids a memory leak if we were to call
12934 guess_partial_die_structure_name multiple times. */
12935 if (part_die
->fixup_called
)
12938 /* If we found a reference attribute and the DIE has no name, try
12939 to find a name in the referred to DIE. */
12941 if (part_die
->name
== NULL
&& part_die
->has_specification
)
12943 struct partial_die_info
*spec_die
;
12945 spec_die
= find_partial_die (part_die
->spec_offset
,
12946 part_die
->spec_is_dwz
, cu
);
12948 fixup_partial_die (spec_die
, cu
);
12950 if (spec_die
->name
)
12952 part_die
->name
= spec_die
->name
;
12954 /* Copy DW_AT_external attribute if it is set. */
12955 if (spec_die
->is_external
)
12956 part_die
->is_external
= spec_die
->is_external
;
12960 /* Set default names for some unnamed DIEs. */
12962 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
12963 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
12965 /* If there is no parent die to provide a namespace, and there are
12966 children, see if we can determine the namespace from their linkage
12968 if (cu
->language
== language_cplus
12969 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
12970 && part_die
->die_parent
== NULL
12971 && part_die
->has_children
12972 && (part_die
->tag
== DW_TAG_class_type
12973 || part_die
->tag
== DW_TAG_structure_type
12974 || part_die
->tag
== DW_TAG_union_type
))
12975 guess_partial_die_structure_name (part_die
, cu
);
12977 /* GCC might emit a nameless struct or union that has a linkage
12978 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12979 if (part_die
->name
== NULL
12980 && (part_die
->tag
== DW_TAG_class_type
12981 || part_die
->tag
== DW_TAG_interface_type
12982 || part_die
->tag
== DW_TAG_structure_type
12983 || part_die
->tag
== DW_TAG_union_type
)
12984 && part_die
->linkage_name
!= NULL
)
12988 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
12993 /* Strip any leading namespaces/classes, keep only the base name.
12994 DW_AT_name for named DIEs does not contain the prefixes. */
12995 base
= strrchr (demangled
, ':');
12996 if (base
&& base
> demangled
&& base
[-1] == ':')
13001 part_die
->name
= obsavestring (base
, strlen (base
),
13002 &cu
->objfile
->objfile_obstack
);
13007 part_die
->fixup_called
= 1;
13010 /* Read an attribute value described by an attribute form. */
13013 read_attribute_value (const struct die_reader_specs
*reader
,
13014 struct attribute
*attr
, unsigned form
,
13015 gdb_byte
*info_ptr
)
13017 struct dwarf2_cu
*cu
= reader
->cu
;
13018 bfd
*abfd
= reader
->abfd
;
13019 struct comp_unit_head
*cu_header
= &cu
->header
;
13020 unsigned int bytes_read
;
13021 struct dwarf_block
*blk
;
13026 case DW_FORM_ref_addr
:
13027 if (cu
->header
.version
== 2)
13028 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13030 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13031 &cu
->header
, &bytes_read
);
13032 info_ptr
+= bytes_read
;
13034 case DW_FORM_GNU_ref_alt
:
13035 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13036 info_ptr
+= bytes_read
;
13039 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13040 info_ptr
+= bytes_read
;
13042 case DW_FORM_block2
:
13043 blk
= dwarf_alloc_block (cu
);
13044 blk
->size
= read_2_bytes (abfd
, info_ptr
);
13046 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13047 info_ptr
+= blk
->size
;
13048 DW_BLOCK (attr
) = blk
;
13050 case DW_FORM_block4
:
13051 blk
= dwarf_alloc_block (cu
);
13052 blk
->size
= read_4_bytes (abfd
, info_ptr
);
13054 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13055 info_ptr
+= blk
->size
;
13056 DW_BLOCK (attr
) = blk
;
13058 case DW_FORM_data2
:
13059 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
13062 case DW_FORM_data4
:
13063 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
13066 case DW_FORM_data8
:
13067 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
13070 case DW_FORM_sec_offset
:
13071 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13072 info_ptr
+= bytes_read
;
13074 case DW_FORM_string
:
13075 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
13076 DW_STRING_IS_CANONICAL (attr
) = 0;
13077 info_ptr
+= bytes_read
;
13080 if (!cu
->per_cu
->is_dwz
)
13082 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
13084 DW_STRING_IS_CANONICAL (attr
) = 0;
13085 info_ptr
+= bytes_read
;
13089 case DW_FORM_GNU_strp_alt
:
13091 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
13092 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
13095 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
13096 DW_STRING_IS_CANONICAL (attr
) = 0;
13097 info_ptr
+= bytes_read
;
13100 case DW_FORM_exprloc
:
13101 case DW_FORM_block
:
13102 blk
= dwarf_alloc_block (cu
);
13103 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13104 info_ptr
+= bytes_read
;
13105 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13106 info_ptr
+= blk
->size
;
13107 DW_BLOCK (attr
) = blk
;
13109 case DW_FORM_block1
:
13110 blk
= dwarf_alloc_block (cu
);
13111 blk
->size
= read_1_byte (abfd
, info_ptr
);
13113 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13114 info_ptr
+= blk
->size
;
13115 DW_BLOCK (attr
) = blk
;
13117 case DW_FORM_data1
:
13118 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13122 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13125 case DW_FORM_flag_present
:
13126 DW_UNSND (attr
) = 1;
13128 case DW_FORM_sdata
:
13129 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
13130 info_ptr
+= bytes_read
;
13132 case DW_FORM_udata
:
13133 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13134 info_ptr
+= bytes_read
;
13137 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13138 + read_1_byte (abfd
, info_ptr
));
13142 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13143 + read_2_bytes (abfd
, info_ptr
));
13147 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13148 + read_4_bytes (abfd
, info_ptr
));
13152 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13153 + read_8_bytes (abfd
, info_ptr
));
13156 case DW_FORM_ref_sig8
:
13157 /* Convert the signature to something we can record in DW_UNSND
13159 NOTE: This is NULL if the type wasn't found. */
13160 DW_SIGNATURED_TYPE (attr
) =
13161 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
13164 case DW_FORM_ref_udata
:
13165 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
13166 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
13167 info_ptr
+= bytes_read
;
13169 case DW_FORM_indirect
:
13170 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13171 info_ptr
+= bytes_read
;
13172 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
13174 case DW_FORM_GNU_addr_index
:
13175 if (reader
->dwo_file
== NULL
)
13177 /* For now flag a hard error.
13178 Later we can turn this into a complaint. */
13179 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13180 dwarf_form_name (form
),
13181 bfd_get_filename (abfd
));
13183 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
13184 info_ptr
+= bytes_read
;
13186 case DW_FORM_GNU_str_index
:
13187 if (reader
->dwo_file
== NULL
)
13189 /* For now flag a hard error.
13190 Later we can turn this into a complaint if warranted. */
13191 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
13192 dwarf_form_name (form
),
13193 bfd_get_filename (abfd
));
13196 ULONGEST str_index
=
13197 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13199 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
13200 DW_STRING_IS_CANONICAL (attr
) = 0;
13201 info_ptr
+= bytes_read
;
13205 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
13206 dwarf_form_name (form
),
13207 bfd_get_filename (abfd
));
13211 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
13212 attr
->form
= DW_FORM_GNU_ref_alt
;
13214 /* We have seen instances where the compiler tried to emit a byte
13215 size attribute of -1 which ended up being encoded as an unsigned
13216 0xffffffff. Although 0xffffffff is technically a valid size value,
13217 an object of this size seems pretty unlikely so we can relatively
13218 safely treat these cases as if the size attribute was invalid and
13219 treat them as zero by default. */
13220 if (attr
->name
== DW_AT_byte_size
13221 && form
== DW_FORM_data4
13222 && DW_UNSND (attr
) >= 0xffffffff)
13225 (&symfile_complaints
,
13226 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
13227 hex_string (DW_UNSND (attr
)));
13228 DW_UNSND (attr
) = 0;
13234 /* Read an attribute described by an abbreviated attribute. */
13237 read_attribute (const struct die_reader_specs
*reader
,
13238 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
13239 gdb_byte
*info_ptr
)
13241 attr
->name
= abbrev
->name
;
13242 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
13245 /* Read dwarf information from a buffer. */
13247 static unsigned int
13248 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
13250 return bfd_get_8 (abfd
, buf
);
13254 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
13256 return bfd_get_signed_8 (abfd
, buf
);
13259 static unsigned int
13260 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
13262 return bfd_get_16 (abfd
, buf
);
13266 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13268 return bfd_get_signed_16 (abfd
, buf
);
13271 static unsigned int
13272 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
13274 return bfd_get_32 (abfd
, buf
);
13278 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
13280 return bfd_get_signed_32 (abfd
, buf
);
13284 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
13286 return bfd_get_64 (abfd
, buf
);
13290 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
13291 unsigned int *bytes_read
)
13293 struct comp_unit_head
*cu_header
= &cu
->header
;
13294 CORE_ADDR retval
= 0;
13296 if (cu_header
->signed_addr_p
)
13298 switch (cu_header
->addr_size
)
13301 retval
= bfd_get_signed_16 (abfd
, buf
);
13304 retval
= bfd_get_signed_32 (abfd
, buf
);
13307 retval
= bfd_get_signed_64 (abfd
, buf
);
13310 internal_error (__FILE__
, __LINE__
,
13311 _("read_address: bad switch, signed [in module %s]"),
13312 bfd_get_filename (abfd
));
13317 switch (cu_header
->addr_size
)
13320 retval
= bfd_get_16 (abfd
, buf
);
13323 retval
= bfd_get_32 (abfd
, buf
);
13326 retval
= bfd_get_64 (abfd
, buf
);
13329 internal_error (__FILE__
, __LINE__
,
13330 _("read_address: bad switch, "
13331 "unsigned [in module %s]"),
13332 bfd_get_filename (abfd
));
13336 *bytes_read
= cu_header
->addr_size
;
13340 /* Read the initial length from a section. The (draft) DWARF 3
13341 specification allows the initial length to take up either 4 bytes
13342 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
13343 bytes describe the length and all offsets will be 8 bytes in length
13346 An older, non-standard 64-bit format is also handled by this
13347 function. The older format in question stores the initial length
13348 as an 8-byte quantity without an escape value. Lengths greater
13349 than 2^32 aren't very common which means that the initial 4 bytes
13350 is almost always zero. Since a length value of zero doesn't make
13351 sense for the 32-bit format, this initial zero can be considered to
13352 be an escape value which indicates the presence of the older 64-bit
13353 format. As written, the code can't detect (old format) lengths
13354 greater than 4GB. If it becomes necessary to handle lengths
13355 somewhat larger than 4GB, we could allow other small values (such
13356 as the non-sensical values of 1, 2, and 3) to also be used as
13357 escape values indicating the presence of the old format.
13359 The value returned via bytes_read should be used to increment the
13360 relevant pointer after calling read_initial_length().
13362 [ Note: read_initial_length() and read_offset() are based on the
13363 document entitled "DWARF Debugging Information Format", revision
13364 3, draft 8, dated November 19, 2001. This document was obtained
13367 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
13369 This document is only a draft and is subject to change. (So beware.)
13371 Details regarding the older, non-standard 64-bit format were
13372 determined empirically by examining 64-bit ELF files produced by
13373 the SGI toolchain on an IRIX 6.5 machine.
13375 - Kevin, July 16, 2002
13379 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
13381 LONGEST length
= bfd_get_32 (abfd
, buf
);
13383 if (length
== 0xffffffff)
13385 length
= bfd_get_64 (abfd
, buf
+ 4);
13388 else if (length
== 0)
13390 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
13391 length
= bfd_get_64 (abfd
, buf
);
13402 /* Cover function for read_initial_length.
13403 Returns the length of the object at BUF, and stores the size of the
13404 initial length in *BYTES_READ and stores the size that offsets will be in
13406 If the initial length size is not equivalent to that specified in
13407 CU_HEADER then issue a complaint.
13408 This is useful when reading non-comp-unit headers. */
13411 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
13412 const struct comp_unit_head
*cu_header
,
13413 unsigned int *bytes_read
,
13414 unsigned int *offset_size
)
13416 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
13418 gdb_assert (cu_header
->initial_length_size
== 4
13419 || cu_header
->initial_length_size
== 8
13420 || cu_header
->initial_length_size
== 12);
13422 if (cu_header
->initial_length_size
!= *bytes_read
)
13423 complaint (&symfile_complaints
,
13424 _("intermixed 32-bit and 64-bit DWARF sections"));
13426 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
13430 /* Read an offset from the data stream. The size of the offset is
13431 given by cu_header->offset_size. */
13434 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
13435 unsigned int *bytes_read
)
13437 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
13439 *bytes_read
= cu_header
->offset_size
;
13443 /* Read an offset from the data stream. */
13446 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
13448 LONGEST retval
= 0;
13450 switch (offset_size
)
13453 retval
= bfd_get_32 (abfd
, buf
);
13456 retval
= bfd_get_64 (abfd
, buf
);
13459 internal_error (__FILE__
, __LINE__
,
13460 _("read_offset_1: bad switch [in module %s]"),
13461 bfd_get_filename (abfd
));
13468 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
13470 /* If the size of a host char is 8 bits, we can return a pointer
13471 to the buffer, otherwise we have to copy the data to a buffer
13472 allocated on the temporary obstack. */
13473 gdb_assert (HOST_CHAR_BIT
== 8);
13478 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13480 /* If the size of a host char is 8 bits, we can return a pointer
13481 to the string, otherwise we have to copy the string to a buffer
13482 allocated on the temporary obstack. */
13483 gdb_assert (HOST_CHAR_BIT
== 8);
13486 *bytes_read_ptr
= 1;
13489 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
13490 return (char *) buf
;
13494 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
13496 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
13497 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
13498 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
13499 bfd_get_filename (abfd
));
13500 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
13501 error (_("DW_FORM_strp pointing outside of "
13502 ".debug_str section [in module %s]"),
13503 bfd_get_filename (abfd
));
13504 gdb_assert (HOST_CHAR_BIT
== 8);
13505 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
13507 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
13510 /* Read a string at offset STR_OFFSET in the .debug_str section from
13511 the .dwz file DWZ. Throw an error if the offset is too large. If
13512 the string consists of a single NUL byte, return NULL; otherwise
13513 return a pointer to the string. */
13516 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
13518 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
13520 if (dwz
->str
.buffer
== NULL
)
13521 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
13522 "section [in module %s]"),
13523 bfd_get_filename (dwz
->dwz_bfd
));
13524 if (str_offset
>= dwz
->str
.size
)
13525 error (_("DW_FORM_GNU_strp_alt pointing outside of "
13526 ".debug_str section [in module %s]"),
13527 bfd_get_filename (dwz
->dwz_bfd
));
13528 gdb_assert (HOST_CHAR_BIT
== 8);
13529 if (dwz
->str
.buffer
[str_offset
] == '\0')
13531 return (char *) (dwz
->str
.buffer
+ str_offset
);
13535 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
13536 const struct comp_unit_head
*cu_header
,
13537 unsigned int *bytes_read_ptr
)
13539 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
13541 return read_indirect_string_at_offset (abfd
, str_offset
);
13545 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13548 unsigned int num_read
;
13550 unsigned char byte
;
13558 byte
= bfd_get_8 (abfd
, buf
);
13561 result
|= ((ULONGEST
) (byte
& 127) << shift
);
13562 if ((byte
& 128) == 0)
13568 *bytes_read_ptr
= num_read
;
13573 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
13576 int i
, shift
, num_read
;
13577 unsigned char byte
;
13585 byte
= bfd_get_8 (abfd
, buf
);
13588 result
|= ((LONGEST
) (byte
& 127) << shift
);
13590 if ((byte
& 128) == 0)
13595 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
13596 result
|= -(((LONGEST
) 1) << shift
);
13597 *bytes_read_ptr
= num_read
;
13601 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
13602 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
13603 ADDR_SIZE is the size of addresses from the CU header. */
13606 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
13608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13609 bfd
*abfd
= objfile
->obfd
;
13610 const gdb_byte
*info_ptr
;
13612 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
13613 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
13614 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
13616 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
13617 error (_("DW_FORM_addr_index pointing outside of "
13618 ".debug_addr section [in module %s]"),
13620 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
13621 + addr_base
+ addr_index
* addr_size
);
13622 if (addr_size
== 4)
13623 return bfd_get_32 (abfd
, info_ptr
);
13625 return bfd_get_64 (abfd
, info_ptr
);
13628 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
13631 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
13633 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
13636 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
13639 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
13640 unsigned int *bytes_read
)
13642 bfd
*abfd
= cu
->objfile
->obfd
;
13643 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
13645 return read_addr_index (cu
, addr_index
);
13648 /* Data structure to pass results from dwarf2_read_addr_index_reader
13649 back to dwarf2_read_addr_index. */
13651 struct dwarf2_read_addr_index_data
13653 ULONGEST addr_base
;
13657 /* die_reader_func for dwarf2_read_addr_index. */
13660 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
13661 gdb_byte
*info_ptr
,
13662 struct die_info
*comp_unit_die
,
13666 struct dwarf2_cu
*cu
= reader
->cu
;
13667 struct dwarf2_read_addr_index_data
*aidata
=
13668 (struct dwarf2_read_addr_index_data
*) data
;
13670 aidata
->addr_base
= cu
->addr_base
;
13671 aidata
->addr_size
= cu
->header
.addr_size
;
13674 /* Given an index in .debug_addr, fetch the value.
13675 NOTE: This can be called during dwarf expression evaluation,
13676 long after the debug information has been read, and thus per_cu->cu
13677 may no longer exist. */
13680 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
13681 unsigned int addr_index
)
13683 struct objfile
*objfile
= per_cu
->objfile
;
13684 struct dwarf2_cu
*cu
= per_cu
->cu
;
13685 ULONGEST addr_base
;
13688 /* This is intended to be called from outside this file. */
13689 dw2_setup (objfile
);
13691 /* We need addr_base and addr_size.
13692 If we don't have PER_CU->cu, we have to get it.
13693 Nasty, but the alternative is storing the needed info in PER_CU,
13694 which at this point doesn't seem justified: it's not clear how frequently
13695 it would get used and it would increase the size of every PER_CU.
13696 Entry points like dwarf2_per_cu_addr_size do a similar thing
13697 so we're not in uncharted territory here.
13698 Alas we need to be a bit more complicated as addr_base is contained
13701 We don't need to read the entire CU(/TU).
13702 We just need the header and top level die.
13703 IWBN to use the aging mechanism to let us lazily later discard the CU.
13704 See however init_cutu_and_read_dies_simple. */
13708 addr_base
= cu
->addr_base
;
13709 addr_size
= cu
->header
.addr_size
;
13713 struct dwarf2_read_addr_index_data aidata
;
13715 init_cutu_and_read_dies_simple (per_cu
, dwarf2_read_addr_index_reader
,
13717 addr_base
= aidata
.addr_base
;
13718 addr_size
= aidata
.addr_size
;
13721 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
13724 /* Given a DW_AT_str_index, fetch the string. */
13727 read_str_index (const struct die_reader_specs
*reader
,
13728 struct dwarf2_cu
*cu
, ULONGEST str_index
)
13730 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13731 const char *dwo_name
= objfile
->name
;
13732 bfd
*abfd
= objfile
->obfd
;
13733 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
13734 gdb_byte
*info_ptr
;
13735 ULONGEST str_offset
;
13737 dwarf2_read_section (objfile
, §ions
->str
);
13738 dwarf2_read_section (objfile
, §ions
->str_offsets
);
13739 if (sections
->str
.buffer
== NULL
)
13740 error (_("DW_FORM_str_index used without .debug_str.dwo section"
13741 " in CU at offset 0x%lx [in module %s]"),
13742 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13743 if (sections
->str_offsets
.buffer
== NULL
)
13744 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
13745 " in CU at offset 0x%lx [in module %s]"),
13746 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13747 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
13748 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
13749 " section in CU at offset 0x%lx [in module %s]"),
13750 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13751 info_ptr
= (sections
->str_offsets
.buffer
13752 + str_index
* cu
->header
.offset_size
);
13753 if (cu
->header
.offset_size
== 4)
13754 str_offset
= bfd_get_32 (abfd
, info_ptr
);
13756 str_offset
= bfd_get_64 (abfd
, info_ptr
);
13757 if (str_offset
>= sections
->str
.size
)
13758 error (_("Offset from DW_FORM_str_index pointing outside of"
13759 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
13760 (long) cu
->header
.offset
.sect_off
, dwo_name
);
13761 return (char *) (sections
->str
.buffer
+ str_offset
);
13764 /* Return the length of an LEB128 number in BUF. */
13767 leb128_size (const gdb_byte
*buf
)
13769 const gdb_byte
*begin
= buf
;
13775 if ((byte
& 128) == 0)
13776 return buf
- begin
;
13781 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
13788 cu
->language
= language_c
;
13790 case DW_LANG_C_plus_plus
:
13791 cu
->language
= language_cplus
;
13794 cu
->language
= language_d
;
13796 case DW_LANG_Fortran77
:
13797 case DW_LANG_Fortran90
:
13798 case DW_LANG_Fortran95
:
13799 cu
->language
= language_fortran
;
13802 cu
->language
= language_go
;
13804 case DW_LANG_Mips_Assembler
:
13805 cu
->language
= language_asm
;
13808 cu
->language
= language_java
;
13810 case DW_LANG_Ada83
:
13811 case DW_LANG_Ada95
:
13812 cu
->language
= language_ada
;
13814 case DW_LANG_Modula2
:
13815 cu
->language
= language_m2
;
13817 case DW_LANG_Pascal83
:
13818 cu
->language
= language_pascal
;
13821 cu
->language
= language_objc
;
13823 case DW_LANG_Cobol74
:
13824 case DW_LANG_Cobol85
:
13826 cu
->language
= language_minimal
;
13829 cu
->language_defn
= language_def (cu
->language
);
13832 /* Return the named attribute or NULL if not there. */
13834 static struct attribute
*
13835 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
13840 struct attribute
*spec
= NULL
;
13842 for (i
= 0; i
< die
->num_attrs
; ++i
)
13844 if (die
->attrs
[i
].name
== name
)
13845 return &die
->attrs
[i
];
13846 if (die
->attrs
[i
].name
== DW_AT_specification
13847 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
13848 spec
= &die
->attrs
[i
];
13854 die
= follow_die_ref (die
, spec
, &cu
);
13860 /* Return the named attribute or NULL if not there,
13861 but do not follow DW_AT_specification, etc.
13862 This is for use in contexts where we're reading .debug_types dies.
13863 Following DW_AT_specification, DW_AT_abstract_origin will take us
13864 back up the chain, and we want to go down. */
13866 static struct attribute
*
13867 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
13871 for (i
= 0; i
< die
->num_attrs
; ++i
)
13872 if (die
->attrs
[i
].name
== name
)
13873 return &die
->attrs
[i
];
13878 /* Return non-zero iff the attribute NAME is defined for the given DIE,
13879 and holds a non-zero value. This function should only be used for
13880 DW_FORM_flag or DW_FORM_flag_present attributes. */
13883 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
13885 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
13887 return (attr
&& DW_UNSND (attr
));
13891 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
13893 /* A DIE is a declaration if it has a DW_AT_declaration attribute
13894 which value is non-zero. However, we have to be careful with
13895 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
13896 (via dwarf2_flag_true_p) follows this attribute. So we may
13897 end up accidently finding a declaration attribute that belongs
13898 to a different DIE referenced by the specification attribute,
13899 even though the given DIE does not have a declaration attribute. */
13900 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
13901 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
13904 /* Return the die giving the specification for DIE, if there is
13905 one. *SPEC_CU is the CU containing DIE on input, and the CU
13906 containing the return value on output. If there is no
13907 specification, but there is an abstract origin, that is
13910 static struct die_info
*
13911 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
13913 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
13916 if (spec_attr
== NULL
)
13917 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
13919 if (spec_attr
== NULL
)
13922 return follow_die_ref (die
, spec_attr
, spec_cu
);
13925 /* Free the line_header structure *LH, and any arrays and strings it
13927 NOTE: This is also used as a "cleanup" function. */
13930 free_line_header (struct line_header
*lh
)
13932 if (lh
->standard_opcode_lengths
)
13933 xfree (lh
->standard_opcode_lengths
);
13935 /* Remember that all the lh->file_names[i].name pointers are
13936 pointers into debug_line_buffer, and don't need to be freed. */
13937 if (lh
->file_names
)
13938 xfree (lh
->file_names
);
13940 /* Similarly for the include directory names. */
13941 if (lh
->include_dirs
)
13942 xfree (lh
->include_dirs
);
13947 /* Add an entry to LH's include directory table. */
13950 add_include_dir (struct line_header
*lh
, char *include_dir
)
13952 /* Grow the array if necessary. */
13953 if (lh
->include_dirs_size
== 0)
13955 lh
->include_dirs_size
= 1; /* for testing */
13956 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
13957 * sizeof (*lh
->include_dirs
));
13959 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
13961 lh
->include_dirs_size
*= 2;
13962 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
13963 (lh
->include_dirs_size
13964 * sizeof (*lh
->include_dirs
)));
13967 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
13970 /* Add an entry to LH's file name table. */
13973 add_file_name (struct line_header
*lh
,
13975 unsigned int dir_index
,
13976 unsigned int mod_time
,
13977 unsigned int length
)
13979 struct file_entry
*fe
;
13981 /* Grow the array if necessary. */
13982 if (lh
->file_names_size
== 0)
13984 lh
->file_names_size
= 1; /* for testing */
13985 lh
->file_names
= xmalloc (lh
->file_names_size
13986 * sizeof (*lh
->file_names
));
13988 else if (lh
->num_file_names
>= lh
->file_names_size
)
13990 lh
->file_names_size
*= 2;
13991 lh
->file_names
= xrealloc (lh
->file_names
,
13992 (lh
->file_names_size
13993 * sizeof (*lh
->file_names
)));
13996 fe
= &lh
->file_names
[lh
->num_file_names
++];
13998 fe
->dir_index
= dir_index
;
13999 fe
->mod_time
= mod_time
;
14000 fe
->length
= length
;
14001 fe
->included_p
= 0;
14005 /* A convenience function to find the proper .debug_line section for a
14008 static struct dwarf2_section_info
*
14009 get_debug_line_section (struct dwarf2_cu
*cu
)
14011 struct dwarf2_section_info
*section
;
14013 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14015 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14016 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14017 else if (cu
->per_cu
->is_dwz
)
14019 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14021 section
= &dwz
->line
;
14024 section
= &dwarf2_per_objfile
->line
;
14029 /* Read the statement program header starting at OFFSET in
14030 .debug_line, or .debug_line.dwo. Return a pointer
14031 to a struct line_header, allocated using xmalloc.
14033 NOTE: the strings in the include directory and file name tables of
14034 the returned object point into the dwarf line section buffer,
14035 and must not be freed. */
14037 static struct line_header
*
14038 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
14040 struct cleanup
*back_to
;
14041 struct line_header
*lh
;
14042 gdb_byte
*line_ptr
;
14043 unsigned int bytes_read
, offset_size
;
14045 char *cur_dir
, *cur_file
;
14046 struct dwarf2_section_info
*section
;
14049 section
= get_debug_line_section (cu
);
14050 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14051 if (section
->buffer
== NULL
)
14053 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14054 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
14056 complaint (&symfile_complaints
, _("missing .debug_line section"));
14060 /* We can't do this until we know the section is non-empty.
14061 Only then do we know we have such a section. */
14062 abfd
= section
->asection
->owner
;
14064 /* Make sure that at least there's room for the total_length field.
14065 That could be 12 bytes long, but we're just going to fudge that. */
14066 if (offset
+ 4 >= section
->size
)
14068 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14072 lh
= xmalloc (sizeof (*lh
));
14073 memset (lh
, 0, sizeof (*lh
));
14074 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
14077 line_ptr
= section
->buffer
+ offset
;
14079 /* Read in the header. */
14081 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
14082 &bytes_read
, &offset_size
);
14083 line_ptr
+= bytes_read
;
14084 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
14086 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14089 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
14090 lh
->version
= read_2_bytes (abfd
, line_ptr
);
14092 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
14093 line_ptr
+= offset_size
;
14094 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
14096 if (lh
->version
>= 4)
14098 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
14102 lh
->maximum_ops_per_instruction
= 1;
14104 if (lh
->maximum_ops_per_instruction
== 0)
14106 lh
->maximum_ops_per_instruction
= 1;
14107 complaint (&symfile_complaints
,
14108 _("invalid maximum_ops_per_instruction "
14109 "in `.debug_line' section"));
14112 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
14114 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
14116 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
14118 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
14120 lh
->standard_opcode_lengths
14121 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
14123 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
14124 for (i
= 1; i
< lh
->opcode_base
; ++i
)
14126 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
14130 /* Read directory table. */
14131 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14133 line_ptr
+= bytes_read
;
14134 add_include_dir (lh
, cur_dir
);
14136 line_ptr
+= bytes_read
;
14138 /* Read file name table. */
14139 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
14141 unsigned int dir_index
, mod_time
, length
;
14143 line_ptr
+= bytes_read
;
14144 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14145 line_ptr
+= bytes_read
;
14146 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14147 line_ptr
+= bytes_read
;
14148 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14149 line_ptr
+= bytes_read
;
14151 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14153 line_ptr
+= bytes_read
;
14154 lh
->statement_program_start
= line_ptr
;
14156 if (line_ptr
> (section
->buffer
+ section
->size
))
14157 complaint (&symfile_complaints
,
14158 _("line number info header doesn't "
14159 "fit in `.debug_line' section"));
14161 discard_cleanups (back_to
);
14165 /* Subroutine of dwarf_decode_lines to simplify it.
14166 Return the file name of the psymtab for included file FILE_INDEX
14167 in line header LH of PST.
14168 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14169 If space for the result is malloc'd, it will be freed by a cleanup.
14170 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
14173 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
14174 const struct partial_symtab
*pst
,
14175 const char *comp_dir
)
14177 const struct file_entry fe
= lh
->file_names
[file_index
];
14178 char *include_name
= fe
.name
;
14179 char *include_name_to_compare
= include_name
;
14180 char *dir_name
= NULL
;
14181 const char *pst_filename
;
14182 char *copied_name
= NULL
;
14186 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
14188 if (!IS_ABSOLUTE_PATH (include_name
)
14189 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
14191 /* Avoid creating a duplicate psymtab for PST.
14192 We do this by comparing INCLUDE_NAME and PST_FILENAME.
14193 Before we do the comparison, however, we need to account
14194 for DIR_NAME and COMP_DIR.
14195 First prepend dir_name (if non-NULL). If we still don't
14196 have an absolute path prepend comp_dir (if non-NULL).
14197 However, the directory we record in the include-file's
14198 psymtab does not contain COMP_DIR (to match the
14199 corresponding symtab(s)).
14204 bash$ gcc -g ./hello.c
14205 include_name = "hello.c"
14207 DW_AT_comp_dir = comp_dir = "/tmp"
14208 DW_AT_name = "./hello.c" */
14210 if (dir_name
!= NULL
)
14212 include_name
= concat (dir_name
, SLASH_STRING
,
14213 include_name
, (char *)NULL
);
14214 include_name_to_compare
= include_name
;
14215 make_cleanup (xfree
, include_name
);
14217 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
14219 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
14220 include_name
, (char *)NULL
);
14224 pst_filename
= pst
->filename
;
14225 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
14227 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
14228 pst_filename
, (char *)NULL
);
14229 pst_filename
= copied_name
;
14232 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
14234 if (include_name_to_compare
!= include_name
)
14235 xfree (include_name_to_compare
);
14236 if (copied_name
!= NULL
)
14237 xfree (copied_name
);
14241 return include_name
;
14244 /* Ignore this record_line request. */
14247 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14252 /* Subroutine of dwarf_decode_lines to simplify it.
14253 Process the line number information in LH. */
14256 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
14257 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
14259 gdb_byte
*line_ptr
, *extended_end
;
14260 gdb_byte
*line_end
;
14261 unsigned int bytes_read
, extended_len
;
14262 unsigned char op_code
, extended_op
, adj_opcode
;
14263 CORE_ADDR baseaddr
;
14264 struct objfile
*objfile
= cu
->objfile
;
14265 bfd
*abfd
= objfile
->obfd
;
14266 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14267 const int decode_for_pst_p
= (pst
!= NULL
);
14268 struct subfile
*last_subfile
= NULL
;
14269 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
14272 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14274 line_ptr
= lh
->statement_program_start
;
14275 line_end
= lh
->statement_program_end
;
14277 /* Read the statement sequences until there's nothing left. */
14278 while (line_ptr
< line_end
)
14280 /* state machine registers */
14281 CORE_ADDR address
= 0;
14282 unsigned int file
= 1;
14283 unsigned int line
= 1;
14284 unsigned int column
= 0;
14285 int is_stmt
= lh
->default_is_stmt
;
14286 int basic_block
= 0;
14287 int end_sequence
= 0;
14289 unsigned char op_index
= 0;
14291 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
14293 /* Start a subfile for the current file of the state machine. */
14294 /* lh->include_dirs and lh->file_names are 0-based, but the
14295 directory and file name numbers in the statement program
14297 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14301 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14303 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14306 /* Decode the table. */
14307 while (!end_sequence
)
14309 op_code
= read_1_byte (abfd
, line_ptr
);
14311 if (line_ptr
> line_end
)
14313 dwarf2_debug_line_missing_end_sequence_complaint ();
14317 if (op_code
>= lh
->opcode_base
)
14319 /* Special operand. */
14320 adj_opcode
= op_code
- lh
->opcode_base
;
14321 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
14322 / lh
->maximum_ops_per_instruction
)
14323 * lh
->minimum_instruction_length
);
14324 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
14325 % lh
->maximum_ops_per_instruction
);
14326 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
14327 if (lh
->num_file_names
< file
|| file
== 0)
14328 dwarf2_debug_line_missing_file_complaint ();
14329 /* For now we ignore lines not starting on an
14330 instruction boundary. */
14331 else if (op_index
== 0)
14333 lh
->file_names
[file
- 1].included_p
= 1;
14334 if (!decode_for_pst_p
&& is_stmt
)
14336 if (last_subfile
!= current_subfile
)
14338 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14340 (*p_record_line
) (last_subfile
, 0, addr
);
14341 last_subfile
= current_subfile
;
14343 /* Append row to matrix using current values. */
14344 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14345 (*p_record_line
) (current_subfile
, line
, addr
);
14350 else switch (op_code
)
14352 case DW_LNS_extended_op
:
14353 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
14355 line_ptr
+= bytes_read
;
14356 extended_end
= line_ptr
+ extended_len
;
14357 extended_op
= read_1_byte (abfd
, line_ptr
);
14359 switch (extended_op
)
14361 case DW_LNE_end_sequence
:
14362 p_record_line
= record_line
;
14365 case DW_LNE_set_address
:
14366 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
14368 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14370 /* This line table is for a function which has been
14371 GCd by the linker. Ignore it. PR gdb/12528 */
14374 = line_ptr
- get_debug_line_section (cu
)->buffer
;
14376 complaint (&symfile_complaints
,
14377 _(".debug_line address at offset 0x%lx is 0 "
14379 line_offset
, objfile
->name
);
14380 p_record_line
= noop_record_line
;
14384 line_ptr
+= bytes_read
;
14385 address
+= baseaddr
;
14387 case DW_LNE_define_file
:
14390 unsigned int dir_index
, mod_time
, length
;
14392 cur_file
= read_direct_string (abfd
, line_ptr
,
14394 line_ptr
+= bytes_read
;
14396 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14397 line_ptr
+= bytes_read
;
14399 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14400 line_ptr
+= bytes_read
;
14402 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14403 line_ptr
+= bytes_read
;
14404 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
14407 case DW_LNE_set_discriminator
:
14408 /* The discriminator is not interesting to the debugger;
14410 line_ptr
= extended_end
;
14413 complaint (&symfile_complaints
,
14414 _("mangled .debug_line section"));
14417 /* Make sure that we parsed the extended op correctly. If e.g.
14418 we expected a different address size than the producer used,
14419 we may have read the wrong number of bytes. */
14420 if (line_ptr
!= extended_end
)
14422 complaint (&symfile_complaints
,
14423 _("mangled .debug_line section"));
14428 if (lh
->num_file_names
< file
|| file
== 0)
14429 dwarf2_debug_line_missing_file_complaint ();
14432 lh
->file_names
[file
- 1].included_p
= 1;
14433 if (!decode_for_pst_p
&& is_stmt
)
14435 if (last_subfile
!= current_subfile
)
14437 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14439 (*p_record_line
) (last_subfile
, 0, addr
);
14440 last_subfile
= current_subfile
;
14442 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14443 (*p_record_line
) (current_subfile
, line
, addr
);
14448 case DW_LNS_advance_pc
:
14451 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14453 address
+= (((op_index
+ adjust
)
14454 / lh
->maximum_ops_per_instruction
)
14455 * lh
->minimum_instruction_length
);
14456 op_index
= ((op_index
+ adjust
)
14457 % lh
->maximum_ops_per_instruction
);
14458 line_ptr
+= bytes_read
;
14461 case DW_LNS_advance_line
:
14462 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
14463 line_ptr
+= bytes_read
;
14465 case DW_LNS_set_file
:
14467 /* The arrays lh->include_dirs and lh->file_names are
14468 0-based, but the directory and file name numbers in
14469 the statement program are 1-based. */
14470 struct file_entry
*fe
;
14473 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14474 line_ptr
+= bytes_read
;
14475 if (lh
->num_file_names
< file
|| file
== 0)
14476 dwarf2_debug_line_missing_file_complaint ();
14479 fe
= &lh
->file_names
[file
- 1];
14481 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14482 if (!decode_for_pst_p
)
14484 last_subfile
= current_subfile
;
14485 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14490 case DW_LNS_set_column
:
14491 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14492 line_ptr
+= bytes_read
;
14494 case DW_LNS_negate_stmt
:
14495 is_stmt
= (!is_stmt
);
14497 case DW_LNS_set_basic_block
:
14500 /* Add to the address register of the state machine the
14501 address increment value corresponding to special opcode
14502 255. I.e., this value is scaled by the minimum
14503 instruction length since special opcode 255 would have
14504 scaled the increment. */
14505 case DW_LNS_const_add_pc
:
14507 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
14509 address
+= (((op_index
+ adjust
)
14510 / lh
->maximum_ops_per_instruction
)
14511 * lh
->minimum_instruction_length
);
14512 op_index
= ((op_index
+ adjust
)
14513 % lh
->maximum_ops_per_instruction
);
14516 case DW_LNS_fixed_advance_pc
:
14517 address
+= read_2_bytes (abfd
, line_ptr
);
14523 /* Unknown standard opcode, ignore it. */
14526 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
14528 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
14529 line_ptr
+= bytes_read
;
14534 if (lh
->num_file_names
< file
|| file
== 0)
14535 dwarf2_debug_line_missing_file_complaint ();
14538 lh
->file_names
[file
- 1].included_p
= 1;
14539 if (!decode_for_pst_p
)
14541 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
14542 (*p_record_line
) (current_subfile
, 0, addr
);
14548 /* Decode the Line Number Program (LNP) for the given line_header
14549 structure and CU. The actual information extracted and the type
14550 of structures created from the LNP depends on the value of PST.
14552 1. If PST is NULL, then this procedure uses the data from the program
14553 to create all necessary symbol tables, and their linetables.
14555 2. If PST is not NULL, this procedure reads the program to determine
14556 the list of files included by the unit represented by PST, and
14557 builds all the associated partial symbol tables.
14559 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
14560 It is used for relative paths in the line table.
14561 NOTE: When processing partial symtabs (pst != NULL),
14562 comp_dir == pst->dirname.
14564 NOTE: It is important that psymtabs have the same file name (via strcmp)
14565 as the corresponding symtab. Since COMP_DIR is not used in the name of the
14566 symtab we don't use it in the name of the psymtabs we create.
14567 E.g. expand_line_sal requires this when finding psymtabs to expand.
14568 A good testcase for this is mb-inline.exp. */
14571 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
14572 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
14573 int want_line_info
)
14575 struct objfile
*objfile
= cu
->objfile
;
14576 const int decode_for_pst_p
= (pst
!= NULL
);
14577 struct subfile
*first_subfile
= current_subfile
;
14579 if (want_line_info
)
14580 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
14582 if (decode_for_pst_p
)
14586 /* Now that we're done scanning the Line Header Program, we can
14587 create the psymtab of each included file. */
14588 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
14589 if (lh
->file_names
[file_index
].included_p
== 1)
14591 char *include_name
=
14592 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
14593 if (include_name
!= NULL
)
14594 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
14599 /* Make sure a symtab is created for every file, even files
14600 which contain only variables (i.e. no code with associated
14604 for (i
= 0; i
< lh
->num_file_names
; i
++)
14607 struct file_entry
*fe
;
14609 fe
= &lh
->file_names
[i
];
14611 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14612 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
14614 /* Skip the main file; we don't need it, and it must be
14615 allocated last, so that it will show up before the
14616 non-primary symtabs in the objfile's symtab list. */
14617 if (current_subfile
== first_subfile
)
14620 if (current_subfile
->symtab
== NULL
)
14621 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
14623 fe
->symtab
= current_subfile
->symtab
;
14628 /* Start a subfile for DWARF. FILENAME is the name of the file and
14629 DIRNAME the name of the source directory which contains FILENAME
14630 or NULL if not known. COMP_DIR is the compilation directory for the
14631 linetable's compilation unit or NULL if not known.
14632 This routine tries to keep line numbers from identical absolute and
14633 relative file names in a common subfile.
14635 Using the `list' example from the GDB testsuite, which resides in
14636 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
14637 of /srcdir/list0.c yields the following debugging information for list0.c:
14639 DW_AT_name: /srcdir/list0.c
14640 DW_AT_comp_dir: /compdir
14641 files.files[0].name: list0.h
14642 files.files[0].dir: /srcdir
14643 files.files[1].name: list0.c
14644 files.files[1].dir: /srcdir
14646 The line number information for list0.c has to end up in a single
14647 subfile, so that `break /srcdir/list0.c:1' works as expected.
14648 start_subfile will ensure that this happens provided that we pass the
14649 concatenation of files.files[1].dir and files.files[1].name as the
14653 dwarf2_start_subfile (char *filename
, const char *dirname
,
14654 const char *comp_dir
)
14658 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
14659 `start_symtab' will always pass the contents of DW_AT_comp_dir as
14660 second argument to start_subfile. To be consistent, we do the
14661 same here. In order not to lose the line information directory,
14662 we concatenate it to the filename when it makes sense.
14663 Note that the Dwarf3 standard says (speaking of filenames in line
14664 information): ``The directory index is ignored for file names
14665 that represent full path names''. Thus ignoring dirname in the
14666 `else' branch below isn't an issue. */
14668 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
14669 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
14671 fullname
= filename
;
14673 start_subfile (fullname
, comp_dir
);
14675 if (fullname
!= filename
)
14679 /* Start a symtab for DWARF.
14680 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
14683 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
14684 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
14686 start_symtab (name
, comp_dir
, low_pc
);
14687 record_debugformat ("DWARF 2");
14688 record_producer (cu
->producer
);
14690 /* We assume that we're processing GCC output. */
14691 processing_gcc_compilation
= 2;
14693 processing_has_namespace_info
= 0;
14697 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
14698 struct dwarf2_cu
*cu
)
14700 struct objfile
*objfile
= cu
->objfile
;
14701 struct comp_unit_head
*cu_header
= &cu
->header
;
14703 /* NOTE drow/2003-01-30: There used to be a comment and some special
14704 code here to turn a symbol with DW_AT_external and a
14705 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
14706 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
14707 with some versions of binutils) where shared libraries could have
14708 relocations against symbols in their debug information - the
14709 minimal symbol would have the right address, but the debug info
14710 would not. It's no longer necessary, because we will explicitly
14711 apply relocations when we read in the debug information now. */
14713 /* A DW_AT_location attribute with no contents indicates that a
14714 variable has been optimized away. */
14715 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
14717 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14721 /* Handle one degenerate form of location expression specially, to
14722 preserve GDB's previous behavior when section offsets are
14723 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
14724 then mark this symbol as LOC_STATIC. */
14726 if (attr_form_is_block (attr
)
14727 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
14728 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
14729 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
14730 && (DW_BLOCK (attr
)->size
14731 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
14733 unsigned int dummy
;
14735 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
14736 SYMBOL_VALUE_ADDRESS (sym
) =
14737 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
14739 SYMBOL_VALUE_ADDRESS (sym
) =
14740 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
14741 SYMBOL_CLASS (sym
) = LOC_STATIC
;
14742 fixup_symbol_section (sym
, objfile
);
14743 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
14744 SYMBOL_SECTION (sym
));
14748 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
14749 expression evaluator, and use LOC_COMPUTED only when necessary
14750 (i.e. when the value of a register or memory location is
14751 referenced, or a thread-local block, etc.). Then again, it might
14752 not be worthwhile. I'm assuming that it isn't unless performance
14753 or memory numbers show me otherwise. */
14755 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
14756 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
14758 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
14759 cu
->has_loclist
= 1;
14762 /* Given a pointer to a DWARF information entry, figure out if we need
14763 to make a symbol table entry for it, and if so, create a new entry
14764 and return a pointer to it.
14765 If TYPE is NULL, determine symbol type from the die, otherwise
14766 used the passed type.
14767 If SPACE is not NULL, use it to hold the new symbol. If it is
14768 NULL, allocate a new symbol on the objfile's obstack. */
14770 static struct symbol
*
14771 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
14772 struct symbol
*space
)
14774 struct objfile
*objfile
= cu
->objfile
;
14775 struct symbol
*sym
= NULL
;
14777 struct attribute
*attr
= NULL
;
14778 struct attribute
*attr2
= NULL
;
14779 CORE_ADDR baseaddr
;
14780 struct pending
**list_to_add
= NULL
;
14782 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14784 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14786 name
= dwarf2_name (die
, cu
);
14789 const char *linkagename
;
14790 int suppress_add
= 0;
14795 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
14796 OBJSTAT (objfile
, n_syms
++);
14798 /* Cache this symbol's name and the name's demangled form (if any). */
14799 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
14800 linkagename
= dwarf2_physname (name
, die
, cu
);
14801 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
14803 /* Fortran does not have mangling standard and the mangling does differ
14804 between gfortran, iFort etc. */
14805 if (cu
->language
== language_fortran
14806 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
14807 symbol_set_demangled_name (&(sym
->ginfo
),
14808 (char *) dwarf2_full_name (name
, die
, cu
),
14811 /* Default assumptions.
14812 Use the passed type or decode it from the die. */
14813 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
14814 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
14816 SYMBOL_TYPE (sym
) = type
;
14818 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
14819 attr
= dwarf2_attr (die
,
14820 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
14824 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
14827 attr
= dwarf2_attr (die
,
14828 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
14832 int file_index
= DW_UNSND (attr
);
14834 if (cu
->line_header
== NULL
14835 || file_index
> cu
->line_header
->num_file_names
)
14836 complaint (&symfile_complaints
,
14837 _("file index out of range"));
14838 else if (file_index
> 0)
14840 struct file_entry
*fe
;
14842 fe
= &cu
->line_header
->file_names
[file_index
- 1];
14843 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
14850 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14853 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
14855 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
14856 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
14857 SYMBOL_CLASS (sym
) = LOC_LABEL
;
14858 add_symbol_to_list (sym
, cu
->list_in_scope
);
14860 case DW_TAG_subprogram
:
14861 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14863 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14864 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14865 if ((attr2
&& (DW_UNSND (attr2
) != 0))
14866 || cu
->language
== language_ada
)
14868 /* Subprograms marked external are stored as a global symbol.
14869 Ada subprograms, whether marked external or not, are always
14870 stored as a global symbol, because we want to be able to
14871 access them globally. For instance, we want to be able
14872 to break on a nested subprogram without having to
14873 specify the context. */
14874 list_to_add
= &global_symbols
;
14878 list_to_add
= cu
->list_in_scope
;
14881 case DW_TAG_inlined_subroutine
:
14882 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
14884 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
14885 SYMBOL_INLINED (sym
) = 1;
14886 list_to_add
= cu
->list_in_scope
;
14888 case DW_TAG_template_value_param
:
14890 /* Fall through. */
14891 case DW_TAG_constant
:
14892 case DW_TAG_variable
:
14893 case DW_TAG_member
:
14894 /* Compilation with minimal debug info may result in
14895 variables with missing type entries. Change the
14896 misleading `void' type to something sensible. */
14897 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
14899 = objfile_type (objfile
)->nodebug_data_symbol
;
14901 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14902 /* In the case of DW_TAG_member, we should only be called for
14903 static const members. */
14904 if (die
->tag
== DW_TAG_member
)
14906 /* dwarf2_add_field uses die_is_declaration,
14907 so we do the same. */
14908 gdb_assert (die_is_declaration (die
, cu
));
14913 dwarf2_const_value (attr
, sym
, cu
);
14914 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14917 if (attr2
&& (DW_UNSND (attr2
) != 0))
14918 list_to_add
= &global_symbols
;
14920 list_to_add
= cu
->list_in_scope
;
14924 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
14927 var_decode_location (attr
, sym
, cu
);
14928 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14929 if (SYMBOL_CLASS (sym
) == LOC_STATIC
14930 && SYMBOL_VALUE_ADDRESS (sym
) == 0
14931 && !dwarf2_per_objfile
->has_section_at_zero
)
14933 /* When a static variable is eliminated by the linker,
14934 the corresponding debug information is not stripped
14935 out, but the variable address is set to null;
14936 do not add such variables into symbol table. */
14938 else if (attr2
&& (DW_UNSND (attr2
) != 0))
14940 /* Workaround gfortran PR debug/40040 - it uses
14941 DW_AT_location for variables in -fPIC libraries which may
14942 get overriden by other libraries/executable and get
14943 a different address. Resolve it by the minimal symbol
14944 which may come from inferior's executable using copy
14945 relocation. Make this workaround only for gfortran as for
14946 other compilers GDB cannot guess the minimal symbol
14947 Fortran mangling kind. */
14948 if (cu
->language
== language_fortran
&& die
->parent
14949 && die
->parent
->tag
== DW_TAG_module
14951 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
14952 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14954 /* A variable with DW_AT_external is never static,
14955 but it may be block-scoped. */
14956 list_to_add
= (cu
->list_in_scope
== &file_symbols
14957 ? &global_symbols
: cu
->list_in_scope
);
14960 list_to_add
= cu
->list_in_scope
;
14964 /* We do not know the address of this symbol.
14965 If it is an external symbol and we have type information
14966 for it, enter the symbol as a LOC_UNRESOLVED symbol.
14967 The address of the variable will then be determined from
14968 the minimal symbol table whenever the variable is
14970 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
14971 if (attr2
&& (DW_UNSND (attr2
) != 0)
14972 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
14974 /* A variable with DW_AT_external is never static, but it
14975 may be block-scoped. */
14976 list_to_add
= (cu
->list_in_scope
== &file_symbols
14977 ? &global_symbols
: cu
->list_in_scope
);
14979 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
14981 else if (!die_is_declaration (die
, cu
))
14983 /* Use the default LOC_OPTIMIZED_OUT class. */
14984 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
14986 list_to_add
= cu
->list_in_scope
;
14990 case DW_TAG_formal_parameter
:
14991 /* If we are inside a function, mark this as an argument. If
14992 not, we might be looking at an argument to an inlined function
14993 when we do not have enough information to show inlined frames;
14994 pretend it's a local variable in that case so that the user can
14996 if (context_stack_depth
> 0
14997 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
14998 SYMBOL_IS_ARGUMENT (sym
) = 1;
14999 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15002 var_decode_location (attr
, sym
, cu
);
15004 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15007 dwarf2_const_value (attr
, sym
, cu
);
15010 list_to_add
= cu
->list_in_scope
;
15012 case DW_TAG_unspecified_parameters
:
15013 /* From varargs functions; gdb doesn't seem to have any
15014 interest in this information, so just ignore it for now.
15017 case DW_TAG_template_type_param
:
15019 /* Fall through. */
15020 case DW_TAG_class_type
:
15021 case DW_TAG_interface_type
:
15022 case DW_TAG_structure_type
:
15023 case DW_TAG_union_type
:
15024 case DW_TAG_set_type
:
15025 case DW_TAG_enumeration_type
:
15026 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15027 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
15030 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15031 really ever be static objects: otherwise, if you try
15032 to, say, break of a class's method and you're in a file
15033 which doesn't mention that class, it won't work unless
15034 the check for all static symbols in lookup_symbol_aux
15035 saves you. See the OtherFileClass tests in
15036 gdb.c++/namespace.exp. */
15040 list_to_add
= (cu
->list_in_scope
== &file_symbols
15041 && (cu
->language
== language_cplus
15042 || cu
->language
== language_java
)
15043 ? &global_symbols
: cu
->list_in_scope
);
15045 /* The semantics of C++ state that "struct foo {
15046 ... }" also defines a typedef for "foo". A Java
15047 class declaration also defines a typedef for the
15049 if (cu
->language
== language_cplus
15050 || cu
->language
== language_java
15051 || cu
->language
== language_ada
)
15053 /* The symbol's name is already allocated along
15054 with this objfile, so we don't need to
15055 duplicate it for the type. */
15056 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
15057 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
15062 case DW_TAG_typedef
:
15063 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15064 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15065 list_to_add
= cu
->list_in_scope
;
15067 case DW_TAG_base_type
:
15068 case DW_TAG_subrange_type
:
15069 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15070 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15071 list_to_add
= cu
->list_in_scope
;
15073 case DW_TAG_enumerator
:
15074 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15077 dwarf2_const_value (attr
, sym
, cu
);
15080 /* NOTE: carlton/2003-11-10: See comment above in the
15081 DW_TAG_class_type, etc. block. */
15083 list_to_add
= (cu
->list_in_scope
== &file_symbols
15084 && (cu
->language
== language_cplus
15085 || cu
->language
== language_java
)
15086 ? &global_symbols
: cu
->list_in_scope
);
15089 case DW_TAG_namespace
:
15090 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15091 list_to_add
= &global_symbols
;
15094 /* Not a tag we recognize. Hopefully we aren't processing
15095 trash data, but since we must specifically ignore things
15096 we don't recognize, there is nothing else we should do at
15098 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
15099 dwarf_tag_name (die
->tag
));
15105 sym
->hash_next
= objfile
->template_symbols
;
15106 objfile
->template_symbols
= sym
;
15107 list_to_add
= NULL
;
15110 if (list_to_add
!= NULL
)
15111 add_symbol_to_list (sym
, list_to_add
);
15113 /* For the benefit of old versions of GCC, check for anonymous
15114 namespaces based on the demangled name. */
15115 if (!processing_has_namespace_info
15116 && cu
->language
== language_cplus
)
15117 cp_scan_for_anonymous_namespaces (sym
, objfile
);
15122 /* A wrapper for new_symbol_full that always allocates a new symbol. */
15124 static struct symbol
*
15125 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15127 return new_symbol_full (die
, type
, cu
, NULL
);
15130 /* Given an attr with a DW_FORM_dataN value in host byte order,
15131 zero-extend it as appropriate for the symbol's type. The DWARF
15132 standard (v4) is not entirely clear about the meaning of using
15133 DW_FORM_dataN for a constant with a signed type, where the type is
15134 wider than the data. The conclusion of a discussion on the DWARF
15135 list was that this is unspecified. We choose to always zero-extend
15136 because that is the interpretation long in use by GCC. */
15139 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
15140 const char *name
, struct obstack
*obstack
,
15141 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
15143 struct objfile
*objfile
= cu
->objfile
;
15144 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
15145 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
15146 LONGEST l
= DW_UNSND (attr
);
15148 if (bits
< sizeof (*value
) * 8)
15150 l
&= ((LONGEST
) 1 << bits
) - 1;
15153 else if (bits
== sizeof (*value
) * 8)
15157 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
15158 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
15165 /* Read a constant value from an attribute. Either set *VALUE, or if
15166 the value does not fit in *VALUE, set *BYTES - either already
15167 allocated on the objfile obstack, or newly allocated on OBSTACK,
15168 or, set *BATON, if we translated the constant to a location
15172 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
15173 const char *name
, struct obstack
*obstack
,
15174 struct dwarf2_cu
*cu
,
15175 LONGEST
*value
, gdb_byte
**bytes
,
15176 struct dwarf2_locexpr_baton
**baton
)
15178 struct objfile
*objfile
= cu
->objfile
;
15179 struct comp_unit_head
*cu_header
= &cu
->header
;
15180 struct dwarf_block
*blk
;
15181 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
15182 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
15188 switch (attr
->form
)
15191 case DW_FORM_GNU_addr_index
:
15195 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
15196 dwarf2_const_value_length_mismatch_complaint (name
,
15197 cu_header
->addr_size
,
15198 TYPE_LENGTH (type
));
15199 /* Symbols of this form are reasonably rare, so we just
15200 piggyback on the existing location code rather than writing
15201 a new implementation of symbol_computed_ops. */
15202 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
15203 sizeof (struct dwarf2_locexpr_baton
));
15204 (*baton
)->per_cu
= cu
->per_cu
;
15205 gdb_assert ((*baton
)->per_cu
);
15207 (*baton
)->size
= 2 + cu_header
->addr_size
;
15208 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
15209 (*baton
)->data
= data
;
15211 data
[0] = DW_OP_addr
;
15212 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
15213 byte_order
, DW_ADDR (attr
));
15214 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
15217 case DW_FORM_string
:
15219 case DW_FORM_GNU_str_index
:
15220 case DW_FORM_GNU_strp_alt
:
15221 /* DW_STRING is already allocated on the objfile obstack, point
15223 *bytes
= (gdb_byte
*) DW_STRING (attr
);
15225 case DW_FORM_block1
:
15226 case DW_FORM_block2
:
15227 case DW_FORM_block4
:
15228 case DW_FORM_block
:
15229 case DW_FORM_exprloc
:
15230 blk
= DW_BLOCK (attr
);
15231 if (TYPE_LENGTH (type
) != blk
->size
)
15232 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
15233 TYPE_LENGTH (type
));
15234 *bytes
= blk
->data
;
15237 /* The DW_AT_const_value attributes are supposed to carry the
15238 symbol's value "represented as it would be on the target
15239 architecture." By the time we get here, it's already been
15240 converted to host endianness, so we just need to sign- or
15241 zero-extend it as appropriate. */
15242 case DW_FORM_data1
:
15243 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15244 obstack
, cu
, value
, 8);
15246 case DW_FORM_data2
:
15247 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15248 obstack
, cu
, value
, 16);
15250 case DW_FORM_data4
:
15251 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15252 obstack
, cu
, value
, 32);
15254 case DW_FORM_data8
:
15255 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
15256 obstack
, cu
, value
, 64);
15259 case DW_FORM_sdata
:
15260 *value
= DW_SND (attr
);
15263 case DW_FORM_udata
:
15264 *value
= DW_UNSND (attr
);
15268 complaint (&symfile_complaints
,
15269 _("unsupported const value attribute form: '%s'"),
15270 dwarf_form_name (attr
->form
));
15277 /* Copy constant value from an attribute to a symbol. */
15280 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
15281 struct dwarf2_cu
*cu
)
15283 struct objfile
*objfile
= cu
->objfile
;
15284 struct comp_unit_head
*cu_header
= &cu
->header
;
15287 struct dwarf2_locexpr_baton
*baton
;
15289 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
15290 SYMBOL_PRINT_NAME (sym
),
15291 &objfile
->objfile_obstack
, cu
,
15292 &value
, &bytes
, &baton
);
15296 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
15297 SYMBOL_LOCATION_BATON (sym
) = baton
;
15298 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15300 else if (bytes
!= NULL
)
15302 SYMBOL_VALUE_BYTES (sym
) = bytes
;
15303 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
15307 SYMBOL_VALUE (sym
) = value
;
15308 SYMBOL_CLASS (sym
) = LOC_CONST
;
15312 /* Return the type of the die in question using its DW_AT_type attribute. */
15314 static struct type
*
15315 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15317 struct attribute
*type_attr
;
15319 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15322 /* A missing DW_AT_type represents a void type. */
15323 return objfile_type (cu
->objfile
)->builtin_void
;
15326 return lookup_die_type (die
, type_attr
, cu
);
15329 /* True iff CU's producer generates GNAT Ada auxiliary information
15330 that allows to find parallel types through that information instead
15331 of having to do expensive parallel lookups by type name. */
15334 need_gnat_info (struct dwarf2_cu
*cu
)
15336 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
15337 of GNAT produces this auxiliary information, without any indication
15338 that it is produced. Part of enhancing the FSF version of GNAT
15339 to produce that information will be to put in place an indicator
15340 that we can use in order to determine whether the descriptive type
15341 info is available or not. One suggestion that has been made is
15342 to use a new attribute, attached to the CU die. For now, assume
15343 that the descriptive type info is not available. */
15347 /* Return the auxiliary type of the die in question using its
15348 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
15349 attribute is not present. */
15351 static struct type
*
15352 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15354 struct attribute
*type_attr
;
15356 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
15360 return lookup_die_type (die
, type_attr
, cu
);
15363 /* If DIE has a descriptive_type attribute, then set the TYPE's
15364 descriptive type accordingly. */
15367 set_descriptive_type (struct type
*type
, struct die_info
*die
,
15368 struct dwarf2_cu
*cu
)
15370 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
15372 if (descriptive_type
)
15374 ALLOCATE_GNAT_AUX_TYPE (type
);
15375 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
15379 /* Return the containing type of the die in question using its
15380 DW_AT_containing_type attribute. */
15382 static struct type
*
15383 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15385 struct attribute
*type_attr
;
15387 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
15389 error (_("Dwarf Error: Problem turning containing type into gdb type "
15390 "[in module %s]"), cu
->objfile
->name
);
15392 return lookup_die_type (die
, type_attr
, cu
);
15395 /* Look up the type of DIE in CU using its type attribute ATTR.
15396 If there is no type substitute an error marker. */
15398 static struct type
*
15399 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
15400 struct dwarf2_cu
*cu
)
15402 struct objfile
*objfile
= cu
->objfile
;
15403 struct type
*this_type
;
15405 /* First see if we have it cached. */
15407 if (attr
->form
== DW_FORM_GNU_ref_alt
)
15409 struct dwarf2_per_cu_data
*per_cu
;
15410 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15412 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
15413 this_type
= get_die_type_at_offset (offset
, per_cu
);
15415 else if (is_ref_attr (attr
))
15417 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
15419 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
15421 else if (attr
->form
== DW_FORM_ref_sig8
)
15423 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
15425 /* sig_type will be NULL if the signatured type is missing from
15427 if (sig_type
== NULL
)
15428 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
15429 "at 0x%x [in module %s]"),
15430 die
->offset
.sect_off
, objfile
->name
);
15432 gdb_assert (sig_type
->per_cu
.is_debug_types
);
15433 /* If we haven't filled in type_offset_in_section yet, then we
15434 haven't read the type in yet. */
15436 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
15439 get_die_type_at_offset (sig_type
->type_offset_in_section
,
15440 &sig_type
->per_cu
);
15445 dump_die_for_error (die
);
15446 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
15447 dwarf_attr_name (attr
->name
), objfile
->name
);
15450 /* If not cached we need to read it in. */
15452 if (this_type
== NULL
)
15454 struct die_info
*type_die
;
15455 struct dwarf2_cu
*type_cu
= cu
;
15457 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
15458 /* If we found the type now, it's probably because the type came
15459 from an inter-CU reference and the type's CU got expanded before
15461 this_type
= get_die_type (type_die
, type_cu
);
15462 if (this_type
== NULL
)
15463 this_type
= read_type_die_1 (type_die
, type_cu
);
15466 /* If we still don't have a type use an error marker. */
15468 if (this_type
== NULL
)
15470 char *message
, *saved
;
15472 /* read_type_die already issued a complaint. */
15473 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
15475 cu
->header
.offset
.sect_off
,
15476 die
->offset
.sect_off
);
15477 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
15478 message
, strlen (message
));
15481 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
15487 /* Return the type in DIE, CU.
15488 Returns NULL for invalid types.
15490 This first does a lookup in the appropriate type_hash table,
15491 and only reads the die in if necessary.
15493 NOTE: This can be called when reading in partial or full symbols. */
15495 static struct type
*
15496 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
15498 struct type
*this_type
;
15500 this_type
= get_die_type (die
, cu
);
15504 return read_type_die_1 (die
, cu
);
15507 /* Read the type in DIE, CU.
15508 Returns NULL for invalid types. */
15510 static struct type
*
15511 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
15513 struct type
*this_type
= NULL
;
15517 case DW_TAG_class_type
:
15518 case DW_TAG_interface_type
:
15519 case DW_TAG_structure_type
:
15520 case DW_TAG_union_type
:
15521 this_type
= read_structure_type (die
, cu
);
15523 case DW_TAG_enumeration_type
:
15524 this_type
= read_enumeration_type (die
, cu
);
15526 case DW_TAG_subprogram
:
15527 case DW_TAG_subroutine_type
:
15528 case DW_TAG_inlined_subroutine
:
15529 this_type
= read_subroutine_type (die
, cu
);
15531 case DW_TAG_array_type
:
15532 this_type
= read_array_type (die
, cu
);
15534 case DW_TAG_set_type
:
15535 this_type
= read_set_type (die
, cu
);
15537 case DW_TAG_pointer_type
:
15538 this_type
= read_tag_pointer_type (die
, cu
);
15540 case DW_TAG_ptr_to_member_type
:
15541 this_type
= read_tag_ptr_to_member_type (die
, cu
);
15543 case DW_TAG_reference_type
:
15544 this_type
= read_tag_reference_type (die
, cu
);
15546 case DW_TAG_const_type
:
15547 this_type
= read_tag_const_type (die
, cu
);
15549 case DW_TAG_volatile_type
:
15550 this_type
= read_tag_volatile_type (die
, cu
);
15552 case DW_TAG_string_type
:
15553 this_type
= read_tag_string_type (die
, cu
);
15555 case DW_TAG_typedef
:
15556 this_type
= read_typedef (die
, cu
);
15558 case DW_TAG_subrange_type
:
15559 this_type
= read_subrange_type (die
, cu
);
15561 case DW_TAG_base_type
:
15562 this_type
= read_base_type (die
, cu
);
15564 case DW_TAG_unspecified_type
:
15565 this_type
= read_unspecified_type (die
, cu
);
15567 case DW_TAG_namespace
:
15568 this_type
= read_namespace_type (die
, cu
);
15570 case DW_TAG_module
:
15571 this_type
= read_module_type (die
, cu
);
15574 complaint (&symfile_complaints
,
15575 _("unexpected tag in read_type_die: '%s'"),
15576 dwarf_tag_name (die
->tag
));
15583 /* See if we can figure out if the class lives in a namespace. We do
15584 this by looking for a member function; its demangled name will
15585 contain namespace info, if there is any.
15586 Return the computed name or NULL.
15587 Space for the result is allocated on the objfile's obstack.
15588 This is the full-die version of guess_partial_die_structure_name.
15589 In this case we know DIE has no useful parent. */
15592 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15594 struct die_info
*spec_die
;
15595 struct dwarf2_cu
*spec_cu
;
15596 struct die_info
*child
;
15599 spec_die
= die_specification (die
, &spec_cu
);
15600 if (spec_die
!= NULL
)
15606 for (child
= die
->child
;
15608 child
= child
->sibling
)
15610 if (child
->tag
== DW_TAG_subprogram
)
15612 struct attribute
*attr
;
15614 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
15616 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
15620 = language_class_name_from_physname (cu
->language_defn
,
15624 if (actual_name
!= NULL
)
15626 char *die_name
= dwarf2_name (die
, cu
);
15628 if (die_name
!= NULL
15629 && strcmp (die_name
, actual_name
) != 0)
15631 /* Strip off the class name from the full name.
15632 We want the prefix. */
15633 int die_name_len
= strlen (die_name
);
15634 int actual_name_len
= strlen (actual_name
);
15636 /* Test for '::' as a sanity check. */
15637 if (actual_name_len
> die_name_len
+ 2
15638 && actual_name
[actual_name_len
15639 - die_name_len
- 1] == ':')
15641 obsavestring (actual_name
,
15642 actual_name_len
- die_name_len
- 2,
15643 &cu
->objfile
->objfile_obstack
);
15646 xfree (actual_name
);
15655 /* GCC might emit a nameless typedef that has a linkage name. Determine the
15656 prefix part in such case. See
15657 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15660 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15662 struct attribute
*attr
;
15665 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
15666 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
15669 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15670 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
15673 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
15675 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
15676 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
15679 /* dwarf2_name had to be already called. */
15680 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
15682 /* Strip the base name, keep any leading namespaces/classes. */
15683 base
= strrchr (DW_STRING (attr
), ':');
15684 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
15687 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
15688 &cu
->objfile
->objfile_obstack
);
15691 /* Return the name of the namespace/class that DIE is defined within,
15692 or "" if we can't tell. The caller should not xfree the result.
15694 For example, if we're within the method foo() in the following
15704 then determine_prefix on foo's die will return "N::C". */
15706 static const char *
15707 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
15709 struct die_info
*parent
, *spec_die
;
15710 struct dwarf2_cu
*spec_cu
;
15711 struct type
*parent_type
;
15714 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
15715 && cu
->language
!= language_fortran
)
15718 retval
= anonymous_struct_prefix (die
, cu
);
15722 /* We have to be careful in the presence of DW_AT_specification.
15723 For example, with GCC 3.4, given the code
15727 // Definition of N::foo.
15731 then we'll have a tree of DIEs like this:
15733 1: DW_TAG_compile_unit
15734 2: DW_TAG_namespace // N
15735 3: DW_TAG_subprogram // declaration of N::foo
15736 4: DW_TAG_subprogram // definition of N::foo
15737 DW_AT_specification // refers to die #3
15739 Thus, when processing die #4, we have to pretend that we're in
15740 the context of its DW_AT_specification, namely the contex of die
15743 spec_die
= die_specification (die
, &spec_cu
);
15744 if (spec_die
== NULL
)
15745 parent
= die
->parent
;
15748 parent
= spec_die
->parent
;
15752 if (parent
== NULL
)
15754 else if (parent
->building_fullname
)
15757 const char *parent_name
;
15759 /* It has been seen on RealView 2.2 built binaries,
15760 DW_TAG_template_type_param types actually _defined_ as
15761 children of the parent class:
15764 template class <class Enum> Class{};
15765 Class<enum E> class_e;
15767 1: DW_TAG_class_type (Class)
15768 2: DW_TAG_enumeration_type (E)
15769 3: DW_TAG_enumerator (enum1:0)
15770 3: DW_TAG_enumerator (enum2:1)
15772 2: DW_TAG_template_type_param
15773 DW_AT_type DW_FORM_ref_udata (E)
15775 Besides being broken debug info, it can put GDB into an
15776 infinite loop. Consider:
15778 When we're building the full name for Class<E>, we'll start
15779 at Class, and go look over its template type parameters,
15780 finding E. We'll then try to build the full name of E, and
15781 reach here. We're now trying to build the full name of E,
15782 and look over the parent DIE for containing scope. In the
15783 broken case, if we followed the parent DIE of E, we'd again
15784 find Class, and once again go look at its template type
15785 arguments, etc., etc. Simply don't consider such parent die
15786 as source-level parent of this die (it can't be, the language
15787 doesn't allow it), and break the loop here. */
15788 name
= dwarf2_name (die
, cu
);
15789 parent_name
= dwarf2_name (parent
, cu
);
15790 complaint (&symfile_complaints
,
15791 _("template param type '%s' defined within parent '%s'"),
15792 name
? name
: "<unknown>",
15793 parent_name
? parent_name
: "<unknown>");
15797 switch (parent
->tag
)
15799 case DW_TAG_namespace
:
15800 parent_type
= read_type_die (parent
, cu
);
15801 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
15802 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
15803 Work around this problem here. */
15804 if (cu
->language
== language_cplus
15805 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
15807 /* We give a name to even anonymous namespaces. */
15808 return TYPE_TAG_NAME (parent_type
);
15809 case DW_TAG_class_type
:
15810 case DW_TAG_interface_type
:
15811 case DW_TAG_structure_type
:
15812 case DW_TAG_union_type
:
15813 case DW_TAG_module
:
15814 parent_type
= read_type_die (parent
, cu
);
15815 if (TYPE_TAG_NAME (parent_type
) != NULL
)
15816 return TYPE_TAG_NAME (parent_type
);
15818 /* An anonymous structure is only allowed non-static data
15819 members; no typedefs, no member functions, et cetera.
15820 So it does not need a prefix. */
15822 case DW_TAG_compile_unit
:
15823 case DW_TAG_partial_unit
:
15824 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
15825 if (cu
->language
== language_cplus
15826 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
15827 && die
->child
!= NULL
15828 && (die
->tag
== DW_TAG_class_type
15829 || die
->tag
== DW_TAG_structure_type
15830 || die
->tag
== DW_TAG_union_type
))
15832 char *name
= guess_full_die_structure_name (die
, cu
);
15838 return determine_prefix (parent
, cu
);
15842 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
15843 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
15844 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
15845 an obconcat, otherwise allocate storage for the result. The CU argument is
15846 used to determine the language and hence, the appropriate separator. */
15848 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
15851 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
15852 int physname
, struct dwarf2_cu
*cu
)
15854 const char *lead
= "";
15857 if (suffix
== NULL
|| suffix
[0] == '\0'
15858 || prefix
== NULL
|| prefix
[0] == '\0')
15860 else if (cu
->language
== language_java
)
15862 else if (cu
->language
== language_fortran
&& physname
)
15864 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
15865 DW_AT_MIPS_linkage_name is preferred and used instead. */
15873 if (prefix
== NULL
)
15875 if (suffix
== NULL
)
15881 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
15883 strcpy (retval
, lead
);
15884 strcat (retval
, prefix
);
15885 strcat (retval
, sep
);
15886 strcat (retval
, suffix
);
15891 /* We have an obstack. */
15892 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
15896 /* Return sibling of die, NULL if no sibling. */
15898 static struct die_info
*
15899 sibling_die (struct die_info
*die
)
15901 return die
->sibling
;
15904 /* Get name of a die, return NULL if not found. */
15907 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
15908 struct obstack
*obstack
)
15910 if (name
&& cu
->language
== language_cplus
)
15912 char *canon_name
= cp_canonicalize_string (name
);
15914 if (canon_name
!= NULL
)
15916 if (strcmp (canon_name
, name
) != 0)
15917 name
= obsavestring (canon_name
, strlen (canon_name
),
15919 xfree (canon_name
);
15926 /* Get name of a die, return NULL if not found. */
15929 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
15931 struct attribute
*attr
;
15933 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
15934 if ((!attr
|| !DW_STRING (attr
))
15935 && die
->tag
!= DW_TAG_class_type
15936 && die
->tag
!= DW_TAG_interface_type
15937 && die
->tag
!= DW_TAG_structure_type
15938 && die
->tag
!= DW_TAG_union_type
)
15943 case DW_TAG_compile_unit
:
15944 case DW_TAG_partial_unit
:
15945 /* Compilation units have a DW_AT_name that is a filename, not
15946 a source language identifier. */
15947 case DW_TAG_enumeration_type
:
15948 case DW_TAG_enumerator
:
15949 /* These tags always have simple identifiers already; no need
15950 to canonicalize them. */
15951 return DW_STRING (attr
);
15953 case DW_TAG_subprogram
:
15954 /* Java constructors will all be named "<init>", so return
15955 the class name when we see this special case. */
15956 if (cu
->language
== language_java
15957 && DW_STRING (attr
) != NULL
15958 && strcmp (DW_STRING (attr
), "<init>") == 0)
15960 struct dwarf2_cu
*spec_cu
= cu
;
15961 struct die_info
*spec_die
;
15963 /* GCJ will output '<init>' for Java constructor names.
15964 For this special case, return the name of the parent class. */
15966 /* GCJ may output suprogram DIEs with AT_specification set.
15967 If so, use the name of the specified DIE. */
15968 spec_die
= die_specification (die
, &spec_cu
);
15969 if (spec_die
!= NULL
)
15970 return dwarf2_name (spec_die
, spec_cu
);
15975 if (die
->tag
== DW_TAG_class_type
)
15976 return dwarf2_name (die
, cu
);
15978 while (die
->tag
!= DW_TAG_compile_unit
15979 && die
->tag
!= DW_TAG_partial_unit
);
15983 case DW_TAG_class_type
:
15984 case DW_TAG_interface_type
:
15985 case DW_TAG_structure_type
:
15986 case DW_TAG_union_type
:
15987 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
15988 structures or unions. These were of the form "._%d" in GCC 4.1,
15989 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
15990 and GCC 4.4. We work around this problem by ignoring these. */
15991 if (attr
&& DW_STRING (attr
)
15992 && (strncmp (DW_STRING (attr
), "._", 2) == 0
15993 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
15996 /* GCC might emit a nameless typedef that has a linkage name. See
15997 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
15998 if (!attr
|| DW_STRING (attr
) == NULL
)
16000 char *demangled
= NULL
;
16002 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16004 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16006 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16009 /* Avoid demangling DW_STRING (attr) the second time on a second
16010 call for the same DIE. */
16011 if (!DW_STRING_IS_CANONICAL (attr
))
16012 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
16018 /* FIXME: we already did this for the partial symbol... */
16019 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
16020 &cu
->objfile
->objfile_obstack
);
16021 DW_STRING_IS_CANONICAL (attr
) = 1;
16024 /* Strip any leading namespaces/classes, keep only the base name.
16025 DW_AT_name for named DIEs does not contain the prefixes. */
16026 base
= strrchr (DW_STRING (attr
), ':');
16027 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
16030 return DW_STRING (attr
);
16039 if (!DW_STRING_IS_CANONICAL (attr
))
16042 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
16043 &cu
->objfile
->objfile_obstack
);
16044 DW_STRING_IS_CANONICAL (attr
) = 1;
16046 return DW_STRING (attr
);
16049 /* Return the die that this die in an extension of, or NULL if there
16050 is none. *EXT_CU is the CU containing DIE on input, and the CU
16051 containing the return value on output. */
16053 static struct die_info
*
16054 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
16056 struct attribute
*attr
;
16058 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
16062 return follow_die_ref (die
, attr
, ext_cu
);
16065 /* Convert a DIE tag into its string name. */
16067 static const char *
16068 dwarf_tag_name (unsigned tag
)
16070 const char *name
= get_DW_TAG_name (tag
);
16073 return "DW_TAG_<unknown>";
16078 /* Convert a DWARF attribute code into its string name. */
16080 static const char *
16081 dwarf_attr_name (unsigned attr
)
16085 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16086 if (attr
== DW_AT_MIPS_fde
)
16087 return "DW_AT_MIPS_fde";
16089 if (attr
== DW_AT_HP_block_index
)
16090 return "DW_AT_HP_block_index";
16093 name
= get_DW_AT_name (attr
);
16096 return "DW_AT_<unknown>";
16101 /* Convert a DWARF value form code into its string name. */
16103 static const char *
16104 dwarf_form_name (unsigned form
)
16106 const char *name
= get_DW_FORM_name (form
);
16109 return "DW_FORM_<unknown>";
16115 dwarf_bool_name (unsigned mybool
)
16123 /* Convert a DWARF type code into its string name. */
16125 static const char *
16126 dwarf_type_encoding_name (unsigned enc
)
16128 const char *name
= get_DW_ATE_name (enc
);
16131 return "DW_ATE_<unknown>";
16137 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
16141 print_spaces (indent
, f
);
16142 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
16143 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
16145 if (die
->parent
!= NULL
)
16147 print_spaces (indent
, f
);
16148 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
16149 die
->parent
->offset
.sect_off
);
16152 print_spaces (indent
, f
);
16153 fprintf_unfiltered (f
, " has children: %s\n",
16154 dwarf_bool_name (die
->child
!= NULL
));
16156 print_spaces (indent
, f
);
16157 fprintf_unfiltered (f
, " attributes:\n");
16159 for (i
= 0; i
< die
->num_attrs
; ++i
)
16161 print_spaces (indent
, f
);
16162 fprintf_unfiltered (f
, " %s (%s) ",
16163 dwarf_attr_name (die
->attrs
[i
].name
),
16164 dwarf_form_name (die
->attrs
[i
].form
));
16166 switch (die
->attrs
[i
].form
)
16169 case DW_FORM_GNU_addr_index
:
16170 fprintf_unfiltered (f
, "address: ");
16171 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
16173 case DW_FORM_block2
:
16174 case DW_FORM_block4
:
16175 case DW_FORM_block
:
16176 case DW_FORM_block1
:
16177 fprintf_unfiltered (f
, "block: size %d",
16178 DW_BLOCK (&die
->attrs
[i
])->size
);
16180 case DW_FORM_exprloc
:
16181 fprintf_unfiltered (f
, "expression: size %u",
16182 DW_BLOCK (&die
->attrs
[i
])->size
);
16184 case DW_FORM_ref_addr
:
16185 fprintf_unfiltered (f
, "ref address: ");
16186 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
16188 case DW_FORM_GNU_ref_alt
:
16189 fprintf_unfiltered (f
, "alt ref address: ");
16190 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
16196 case DW_FORM_ref_udata
:
16197 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
16198 (long) (DW_UNSND (&die
->attrs
[i
])));
16200 case DW_FORM_data1
:
16201 case DW_FORM_data2
:
16202 case DW_FORM_data4
:
16203 case DW_FORM_data8
:
16204 case DW_FORM_udata
:
16205 case DW_FORM_sdata
:
16206 fprintf_unfiltered (f
, "constant: %s",
16207 pulongest (DW_UNSND (&die
->attrs
[i
])));
16209 case DW_FORM_sec_offset
:
16210 fprintf_unfiltered (f
, "section offset: %s",
16211 pulongest (DW_UNSND (&die
->attrs
[i
])));
16213 case DW_FORM_ref_sig8
:
16214 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
16215 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
16216 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
16218 fprintf_unfiltered (f
, "signatured type, offset: unknown");
16220 case DW_FORM_string
:
16222 case DW_FORM_GNU_str_index
:
16223 case DW_FORM_GNU_strp_alt
:
16224 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
16225 DW_STRING (&die
->attrs
[i
])
16226 ? DW_STRING (&die
->attrs
[i
]) : "",
16227 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
16230 if (DW_UNSND (&die
->attrs
[i
]))
16231 fprintf_unfiltered (f
, "flag: TRUE");
16233 fprintf_unfiltered (f
, "flag: FALSE");
16235 case DW_FORM_flag_present
:
16236 fprintf_unfiltered (f
, "flag: TRUE");
16238 case DW_FORM_indirect
:
16239 /* The reader will have reduced the indirect form to
16240 the "base form" so this form should not occur. */
16241 fprintf_unfiltered (f
,
16242 "unexpected attribute form: DW_FORM_indirect");
16245 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
16246 die
->attrs
[i
].form
);
16249 fprintf_unfiltered (f
, "\n");
16254 dump_die_for_error (struct die_info
*die
)
16256 dump_die_shallow (gdb_stderr
, 0, die
);
16260 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
16262 int indent
= level
* 4;
16264 gdb_assert (die
!= NULL
);
16266 if (level
>= max_level
)
16269 dump_die_shallow (f
, indent
, die
);
16271 if (die
->child
!= NULL
)
16273 print_spaces (indent
, f
);
16274 fprintf_unfiltered (f
, " Children:");
16275 if (level
+ 1 < max_level
)
16277 fprintf_unfiltered (f
, "\n");
16278 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
16282 fprintf_unfiltered (f
,
16283 " [not printed, max nesting level reached]\n");
16287 if (die
->sibling
!= NULL
&& level
> 0)
16289 dump_die_1 (f
, level
, max_level
, die
->sibling
);
16293 /* This is called from the pdie macro in gdbinit.in.
16294 It's not static so gcc will keep a copy callable from gdb. */
16297 dump_die (struct die_info
*die
, int max_level
)
16299 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
16303 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
16307 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
16313 /* DW_ADDR is always stored already as sect_offset; despite for the forms
16314 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
16317 is_ref_attr (struct attribute
*attr
)
16319 switch (attr
->form
)
16321 case DW_FORM_ref_addr
:
16326 case DW_FORM_ref_udata
:
16327 case DW_FORM_GNU_ref_alt
:
16334 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
16338 dwarf2_get_ref_die_offset (struct attribute
*attr
)
16340 sect_offset retval
= { DW_UNSND (attr
) };
16342 if (is_ref_attr (attr
))
16345 retval
.sect_off
= 0;
16346 complaint (&symfile_complaints
,
16347 _("unsupported die ref attribute form: '%s'"),
16348 dwarf_form_name (attr
->form
));
16352 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
16353 * the value held by the attribute is not constant. */
16356 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
16358 if (attr
->form
== DW_FORM_sdata
)
16359 return DW_SND (attr
);
16360 else if (attr
->form
== DW_FORM_udata
16361 || attr
->form
== DW_FORM_data1
16362 || attr
->form
== DW_FORM_data2
16363 || attr
->form
== DW_FORM_data4
16364 || attr
->form
== DW_FORM_data8
)
16365 return DW_UNSND (attr
);
16368 complaint (&symfile_complaints
,
16369 _("Attribute value is not a constant (%s)"),
16370 dwarf_form_name (attr
->form
));
16371 return default_value
;
16375 /* Follow reference or signature attribute ATTR of SRC_DIE.
16376 On entry *REF_CU is the CU of SRC_DIE.
16377 On exit *REF_CU is the CU of the result. */
16379 static struct die_info
*
16380 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
16381 struct dwarf2_cu
**ref_cu
)
16383 struct die_info
*die
;
16385 if (is_ref_attr (attr
))
16386 die
= follow_die_ref (src_die
, attr
, ref_cu
);
16387 else if (attr
->form
== DW_FORM_ref_sig8
)
16388 die
= follow_die_sig (src_die
, attr
, ref_cu
);
16391 dump_die_for_error (src_die
);
16392 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
16393 (*ref_cu
)->objfile
->name
);
16399 /* Follow reference OFFSET.
16400 On entry *REF_CU is the CU of the source die referencing OFFSET.
16401 On exit *REF_CU is the CU of the result.
16402 Returns NULL if OFFSET is invalid. */
16404 static struct die_info
*
16405 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
16406 struct dwarf2_cu
**ref_cu
)
16408 struct die_info temp_die
;
16409 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
16411 gdb_assert (cu
->per_cu
!= NULL
);
16415 if (cu
->per_cu
->is_debug_types
)
16417 /* .debug_types CUs cannot reference anything outside their CU.
16418 If they need to, they have to reference a signatured type via
16419 DW_FORM_ref_sig8. */
16420 if (! offset_in_cu_p (&cu
->header
, offset
))
16423 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
16424 || ! offset_in_cu_p (&cu
->header
, offset
))
16426 struct dwarf2_per_cu_data
*per_cu
;
16428 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
16431 /* If necessary, add it to the queue and load its DIEs. */
16432 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
16433 load_full_comp_unit (per_cu
, cu
->language
);
16435 target_cu
= per_cu
->cu
;
16437 else if (cu
->dies
== NULL
)
16439 /* We're loading full DIEs during partial symbol reading. */
16440 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
16441 load_full_comp_unit (cu
->per_cu
, language_minimal
);
16444 *ref_cu
= target_cu
;
16445 temp_die
.offset
= offset
;
16446 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
16449 /* Follow reference attribute ATTR of SRC_DIE.
16450 On entry *REF_CU is the CU of SRC_DIE.
16451 On exit *REF_CU is the CU of the result. */
16453 static struct die_info
*
16454 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
16455 struct dwarf2_cu
**ref_cu
)
16457 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16458 struct dwarf2_cu
*cu
= *ref_cu
;
16459 struct die_info
*die
;
16461 die
= follow_die_offset (offset
,
16462 (attr
->form
== DW_FORM_GNU_ref_alt
16463 || cu
->per_cu
->is_dwz
),
16466 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
16467 "at 0x%x [in module %s]"),
16468 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
16473 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
16474 Returned value is intended for DW_OP_call*. Returned
16475 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
16477 struct dwarf2_locexpr_baton
16478 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
16479 struct dwarf2_per_cu_data
*per_cu
,
16480 CORE_ADDR (*get_frame_pc
) (void *baton
),
16483 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
16484 struct dwarf2_cu
*cu
;
16485 struct die_info
*die
;
16486 struct attribute
*attr
;
16487 struct dwarf2_locexpr_baton retval
;
16489 dw2_setup (per_cu
->objfile
);
16491 if (per_cu
->cu
== NULL
)
16495 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
16497 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
16498 offset
.sect_off
, per_cu
->objfile
->name
);
16500 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16503 /* DWARF: "If there is no such attribute, then there is no effect.".
16504 DATA is ignored if SIZE is 0. */
16506 retval
.data
= NULL
;
16509 else if (attr_form_is_section_offset (attr
))
16511 struct dwarf2_loclist_baton loclist_baton
;
16512 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
16515 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
16517 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
16519 retval
.size
= size
;
16523 if (!attr_form_is_block (attr
))
16524 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
16525 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
16526 offset
.sect_off
, per_cu
->objfile
->name
);
16528 retval
.data
= DW_BLOCK (attr
)->data
;
16529 retval
.size
= DW_BLOCK (attr
)->size
;
16531 retval
.per_cu
= cu
->per_cu
;
16533 age_cached_comp_units ();
16538 /* Return the type of the DIE at DIE_OFFSET in the CU named by
16542 dwarf2_get_die_type (cu_offset die_offset
,
16543 struct dwarf2_per_cu_data
*per_cu
)
16545 sect_offset die_offset_sect
;
16547 dw2_setup (per_cu
->objfile
);
16549 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
16550 return get_die_type_at_offset (die_offset_sect
, per_cu
);
16553 /* Follow the signature attribute ATTR in SRC_DIE.
16554 On entry *REF_CU is the CU of SRC_DIE.
16555 On exit *REF_CU is the CU of the result. */
16557 static struct die_info
*
16558 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
16559 struct dwarf2_cu
**ref_cu
)
16561 struct objfile
*objfile
= (*ref_cu
)->objfile
;
16562 struct die_info temp_die
;
16563 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16564 struct dwarf2_cu
*sig_cu
;
16565 struct die_info
*die
;
16567 /* sig_type will be NULL if the signatured type is missing from
16569 if (sig_type
== NULL
)
16570 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16571 "at 0x%x [in module %s]"),
16572 src_die
->offset
.sect_off
, objfile
->name
);
16574 /* If necessary, add it to the queue and load its DIEs. */
16576 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
16577 read_signatured_type (sig_type
);
16579 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
16581 sig_cu
= sig_type
->per_cu
.cu
;
16582 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
16583 temp_die
.offset
= sig_type
->type_offset_in_section
;
16584 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
16585 temp_die
.offset
.sect_off
);
16592 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
16593 "from DIE at 0x%x [in module %s]"),
16594 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
16597 /* Given an offset of a signatured type, return its signatured_type. */
16599 static struct signatured_type
*
16600 lookup_signatured_type_at_offset (struct objfile
*objfile
,
16601 struct dwarf2_section_info
*section
,
16602 sect_offset offset
)
16604 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
16605 unsigned int length
, initial_length_size
;
16606 unsigned int sig_offset
;
16607 struct signatured_type find_entry
, *sig_type
;
16609 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
16610 sig_offset
= (initial_length_size
16612 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
16613 + 1 /*address_size*/);
16614 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
16615 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
16617 /* This is only used to lookup previously recorded types.
16618 If we didn't find it, it's our bug. */
16619 gdb_assert (sig_type
!= NULL
);
16620 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
16625 /* Load the DIEs associated with type unit PER_CU into memory. */
16628 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
16630 struct signatured_type
*sig_type
;
16632 /* Caller is responsible for ensuring type_unit_groups don't get here. */
16633 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
16635 /* We have the per_cu, but we need the signatured_type.
16636 Fortunately this is an easy translation. */
16637 gdb_assert (per_cu
->is_debug_types
);
16638 sig_type
= (struct signatured_type
*) per_cu
;
16640 gdb_assert (per_cu
->cu
== NULL
);
16642 read_signatured_type (sig_type
);
16644 gdb_assert (per_cu
->cu
!= NULL
);
16647 /* die_reader_func for read_signatured_type.
16648 This is identical to load_full_comp_unit_reader,
16649 but is kept separate for now. */
16652 read_signatured_type_reader (const struct die_reader_specs
*reader
,
16653 gdb_byte
*info_ptr
,
16654 struct die_info
*comp_unit_die
,
16658 struct dwarf2_cu
*cu
= reader
->cu
;
16660 gdb_assert (cu
->die_hash
== NULL
);
16662 htab_create_alloc_ex (cu
->header
.length
/ 12,
16666 &cu
->comp_unit_obstack
,
16667 hashtab_obstack_allocate
,
16668 dummy_obstack_deallocate
);
16671 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
16672 &info_ptr
, comp_unit_die
);
16673 cu
->dies
= comp_unit_die
;
16674 /* comp_unit_die is not stored in die_hash, no need. */
16676 /* We try not to read any attributes in this function, because not
16677 all CUs needed for references have been loaded yet, and symbol
16678 table processing isn't initialized. But we have to set the CU language,
16679 or we won't be able to build types correctly.
16680 Similarly, if we do not read the producer, we can not apply
16681 producer-specific interpretation. */
16682 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
16685 /* Read in a signatured type and build its CU and DIEs.
16686 If the type is a stub for the real type in a DWO file,
16687 read in the real type from the DWO file as well. */
16690 read_signatured_type (struct signatured_type
*sig_type
)
16692 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
16694 gdb_assert (per_cu
->is_debug_types
);
16695 gdb_assert (per_cu
->cu
== NULL
);
16697 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
16698 read_signatured_type_reader
, NULL
);
16701 /* Decode simple location descriptions.
16702 Given a pointer to a dwarf block that defines a location, compute
16703 the location and return the value.
16705 NOTE drow/2003-11-18: This function is called in two situations
16706 now: for the address of static or global variables (partial symbols
16707 only) and for offsets into structures which are expected to be
16708 (more or less) constant. The partial symbol case should go away,
16709 and only the constant case should remain. That will let this
16710 function complain more accurately. A few special modes are allowed
16711 without complaint for global variables (for instance, global
16712 register values and thread-local values).
16714 A location description containing no operations indicates that the
16715 object is optimized out. The return value is 0 for that case.
16716 FIXME drow/2003-11-16: No callers check for this case any more; soon all
16717 callers will only want a very basic result and this can become a
16720 Note that stack[0] is unused except as a default error return. */
16723 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
16725 struct objfile
*objfile
= cu
->objfile
;
16727 int size
= blk
->size
;
16728 gdb_byte
*data
= blk
->data
;
16729 CORE_ADDR stack
[64];
16731 unsigned int bytes_read
, unsnd
;
16737 stack
[++stacki
] = 0;
16776 stack
[++stacki
] = op
- DW_OP_lit0
;
16811 stack
[++stacki
] = op
- DW_OP_reg0
;
16813 dwarf2_complex_location_expr_complaint ();
16817 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
16819 stack
[++stacki
] = unsnd
;
16821 dwarf2_complex_location_expr_complaint ();
16825 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
16830 case DW_OP_const1u
:
16831 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
16835 case DW_OP_const1s
:
16836 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
16840 case DW_OP_const2u
:
16841 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
16845 case DW_OP_const2s
:
16846 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
16850 case DW_OP_const4u
:
16851 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
16855 case DW_OP_const4s
:
16856 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
16860 case DW_OP_const8u
:
16861 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
16866 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
16872 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
16877 stack
[stacki
+ 1] = stack
[stacki
];
16882 stack
[stacki
- 1] += stack
[stacki
];
16886 case DW_OP_plus_uconst
:
16887 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
16893 stack
[stacki
- 1] -= stack
[stacki
];
16898 /* If we're not the last op, then we definitely can't encode
16899 this using GDB's address_class enum. This is valid for partial
16900 global symbols, although the variable's address will be bogus
16903 dwarf2_complex_location_expr_complaint ();
16906 case DW_OP_GNU_push_tls_address
:
16907 /* The top of the stack has the offset from the beginning
16908 of the thread control block at which the variable is located. */
16909 /* Nothing should follow this operator, so the top of stack would
16911 /* This is valid for partial global symbols, but the variable's
16912 address will be bogus in the psymtab. Make it always at least
16913 non-zero to not look as a variable garbage collected by linker
16914 which have DW_OP_addr 0. */
16916 dwarf2_complex_location_expr_complaint ();
16920 case DW_OP_GNU_uninit
:
16923 case DW_OP_GNU_addr_index
:
16924 case DW_OP_GNU_const_index
:
16925 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
16932 const char *name
= get_DW_OP_name (op
);
16935 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
16938 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
16942 return (stack
[stacki
]);
16945 /* Enforce maximum stack depth of SIZE-1 to avoid writing
16946 outside of the allocated space. Also enforce minimum>0. */
16947 if (stacki
>= ARRAY_SIZE (stack
) - 1)
16949 complaint (&symfile_complaints
,
16950 _("location description stack overflow"));
16956 complaint (&symfile_complaints
,
16957 _("location description stack underflow"));
16961 return (stack
[stacki
]);
16964 /* memory allocation interface */
16966 static struct dwarf_block
*
16967 dwarf_alloc_block (struct dwarf2_cu
*cu
)
16969 struct dwarf_block
*blk
;
16971 blk
= (struct dwarf_block
*)
16972 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
16976 static struct die_info
*
16977 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
16979 struct die_info
*die
;
16980 size_t size
= sizeof (struct die_info
);
16983 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
16985 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
16986 memset (die
, 0, sizeof (struct die_info
));
16991 /* Macro support. */
16993 /* Return the full name of file number I in *LH's file name table.
16994 Use COMP_DIR as the name of the current directory of the
16995 compilation. The result is allocated using xmalloc; the caller is
16996 responsible for freeing it. */
16998 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
17000 /* Is the file number a valid index into the line header's file name
17001 table? Remember that file numbers start with one, not zero. */
17002 if (1 <= file
&& file
<= lh
->num_file_names
)
17004 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
17006 if (IS_ABSOLUTE_PATH (fe
->name
))
17007 return xstrdup (fe
->name
);
17015 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17021 dir_len
= strlen (dir
);
17022 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
17023 strcpy (full_name
, dir
);
17024 full_name
[dir_len
] = '/';
17025 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
17029 return xstrdup (fe
->name
);
17034 /* The compiler produced a bogus file number. We can at least
17035 record the macro definitions made in the file, even if we
17036 won't be able to find the file by name. */
17037 char fake_name
[80];
17039 sprintf (fake_name
, "<bad macro file number %d>", file
);
17041 complaint (&symfile_complaints
,
17042 _("bad file number in macro information (%d)"),
17045 return xstrdup (fake_name
);
17050 static struct macro_source_file
*
17051 macro_start_file (int file
, int line
,
17052 struct macro_source_file
*current_file
,
17053 const char *comp_dir
,
17054 struct line_header
*lh
, struct objfile
*objfile
)
17056 /* The full name of this source file. */
17057 char *full_name
= file_full_name (file
, lh
, comp_dir
);
17059 /* We don't create a macro table for this compilation unit
17060 at all until we actually get a filename. */
17061 if (! pending_macros
)
17062 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
17063 objfile
->macro_cache
);
17065 if (! current_file
)
17067 /* If we have no current file, then this must be the start_file
17068 directive for the compilation unit's main source file. */
17069 current_file
= macro_set_main (pending_macros
, full_name
);
17070 macro_define_special (pending_macros
);
17073 current_file
= macro_include (current_file
, line
, full_name
);
17077 return current_file
;
17081 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17082 followed by a null byte. */
17084 copy_string (const char *buf
, int len
)
17086 char *s
= xmalloc (len
+ 1);
17088 memcpy (s
, buf
, len
);
17094 static const char *
17095 consume_improper_spaces (const char *p
, const char *body
)
17099 complaint (&symfile_complaints
,
17100 _("macro definition contains spaces "
17101 "in formal argument list:\n`%s'"),
17113 parse_macro_definition (struct macro_source_file
*file
, int line
,
17118 /* The body string takes one of two forms. For object-like macro
17119 definitions, it should be:
17121 <macro name> " " <definition>
17123 For function-like macro definitions, it should be:
17125 <macro name> "() " <definition>
17127 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
17129 Spaces may appear only where explicitly indicated, and in the
17132 The Dwarf 2 spec says that an object-like macro's name is always
17133 followed by a space, but versions of GCC around March 2002 omit
17134 the space when the macro's definition is the empty string.
17136 The Dwarf 2 spec says that there should be no spaces between the
17137 formal arguments in a function-like macro's formal argument list,
17138 but versions of GCC around March 2002 include spaces after the
17142 /* Find the extent of the macro name. The macro name is terminated
17143 by either a space or null character (for an object-like macro) or
17144 an opening paren (for a function-like macro). */
17145 for (p
= body
; *p
; p
++)
17146 if (*p
== ' ' || *p
== '(')
17149 if (*p
== ' ' || *p
== '\0')
17151 /* It's an object-like macro. */
17152 int name_len
= p
- body
;
17153 char *name
= copy_string (body
, name_len
);
17154 const char *replacement
;
17157 replacement
= body
+ name_len
+ 1;
17160 dwarf2_macro_malformed_definition_complaint (body
);
17161 replacement
= body
+ name_len
;
17164 macro_define_object (file
, line
, name
, replacement
);
17168 else if (*p
== '(')
17170 /* It's a function-like macro. */
17171 char *name
= copy_string (body
, p
- body
);
17174 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
17178 p
= consume_improper_spaces (p
, body
);
17180 /* Parse the formal argument list. */
17181 while (*p
&& *p
!= ')')
17183 /* Find the extent of the current argument name. */
17184 const char *arg_start
= p
;
17186 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
17189 if (! *p
|| p
== arg_start
)
17190 dwarf2_macro_malformed_definition_complaint (body
);
17193 /* Make sure argv has room for the new argument. */
17194 if (argc
>= argv_size
)
17197 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
17200 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
17203 p
= consume_improper_spaces (p
, body
);
17205 /* Consume the comma, if present. */
17210 p
= consume_improper_spaces (p
, body
);
17219 /* Perfectly formed definition, no complaints. */
17220 macro_define_function (file
, line
, name
,
17221 argc
, (const char **) argv
,
17223 else if (*p
== '\0')
17225 /* Complain, but do define it. */
17226 dwarf2_macro_malformed_definition_complaint (body
);
17227 macro_define_function (file
, line
, name
,
17228 argc
, (const char **) argv
,
17232 /* Just complain. */
17233 dwarf2_macro_malformed_definition_complaint (body
);
17236 /* Just complain. */
17237 dwarf2_macro_malformed_definition_complaint (body
);
17243 for (i
= 0; i
< argc
; i
++)
17249 dwarf2_macro_malformed_definition_complaint (body
);
17252 /* Skip some bytes from BYTES according to the form given in FORM.
17253 Returns the new pointer. */
17256 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
17257 enum dwarf_form form
,
17258 unsigned int offset_size
,
17259 struct dwarf2_section_info
*section
)
17261 unsigned int bytes_read
;
17265 case DW_FORM_data1
:
17270 case DW_FORM_data2
:
17274 case DW_FORM_data4
:
17278 case DW_FORM_data8
:
17282 case DW_FORM_string
:
17283 read_direct_string (abfd
, bytes
, &bytes_read
);
17284 bytes
+= bytes_read
;
17287 case DW_FORM_sec_offset
:
17289 case DW_FORM_GNU_strp_alt
:
17290 bytes
+= offset_size
;
17293 case DW_FORM_block
:
17294 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
17295 bytes
+= bytes_read
;
17298 case DW_FORM_block1
:
17299 bytes
+= 1 + read_1_byte (abfd
, bytes
);
17301 case DW_FORM_block2
:
17302 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
17304 case DW_FORM_block4
:
17305 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
17308 case DW_FORM_sdata
:
17309 case DW_FORM_udata
:
17310 case DW_FORM_GNU_addr_index
:
17311 case DW_FORM_GNU_str_index
:
17312 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
17315 dwarf2_section_buffer_overflow_complaint (section
);
17323 complaint (&symfile_complaints
,
17324 _("invalid form 0x%x in `%s'"),
17326 section
->asection
->name
);
17334 /* A helper for dwarf_decode_macros that handles skipping an unknown
17335 opcode. Returns an updated pointer to the macro data buffer; or,
17336 on error, issues a complaint and returns NULL. */
17339 skip_unknown_opcode (unsigned int opcode
,
17340 gdb_byte
**opcode_definitions
,
17341 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17343 unsigned int offset_size
,
17344 struct dwarf2_section_info
*section
)
17346 unsigned int bytes_read
, i
;
17350 if (opcode_definitions
[opcode
] == NULL
)
17352 complaint (&symfile_complaints
,
17353 _("unrecognized DW_MACFINO opcode 0x%x"),
17358 defn
= opcode_definitions
[opcode
];
17359 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
17360 defn
+= bytes_read
;
17362 for (i
= 0; i
< arg
; ++i
)
17364 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
17366 if (mac_ptr
== NULL
)
17368 /* skip_form_bytes already issued the complaint. */
17376 /* A helper function which parses the header of a macro section.
17377 If the macro section is the extended (for now called "GNU") type,
17378 then this updates *OFFSET_SIZE. Returns a pointer to just after
17379 the header, or issues a complaint and returns NULL on error. */
17382 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
17385 unsigned int *offset_size
,
17386 int section_is_gnu
)
17388 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
17390 if (section_is_gnu
)
17392 unsigned int version
, flags
;
17394 version
= read_2_bytes (abfd
, mac_ptr
);
17397 complaint (&symfile_complaints
,
17398 _("unrecognized version `%d' in .debug_macro section"),
17404 flags
= read_1_byte (abfd
, mac_ptr
);
17406 *offset_size
= (flags
& 1) ? 8 : 4;
17408 if ((flags
& 2) != 0)
17409 /* We don't need the line table offset. */
17410 mac_ptr
+= *offset_size
;
17412 /* Vendor opcode descriptions. */
17413 if ((flags
& 4) != 0)
17415 unsigned int i
, count
;
17417 count
= read_1_byte (abfd
, mac_ptr
);
17419 for (i
= 0; i
< count
; ++i
)
17421 unsigned int opcode
, bytes_read
;
17424 opcode
= read_1_byte (abfd
, mac_ptr
);
17426 opcode_definitions
[opcode
] = mac_ptr
;
17427 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17428 mac_ptr
+= bytes_read
;
17437 /* A helper for dwarf_decode_macros that handles the GNU extensions,
17438 including DW_MACRO_GNU_transparent_include. */
17441 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
17442 struct macro_source_file
*current_file
,
17443 struct line_header
*lh
, char *comp_dir
,
17444 struct dwarf2_section_info
*section
,
17445 int section_is_gnu
, int section_is_dwz
,
17446 unsigned int offset_size
,
17447 struct objfile
*objfile
,
17448 htab_t include_hash
)
17450 enum dwarf_macro_record_type macinfo_type
;
17451 int at_commandline
;
17452 gdb_byte
*opcode_definitions
[256];
17454 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17455 &offset_size
, section_is_gnu
);
17456 if (mac_ptr
== NULL
)
17458 /* We already issued a complaint. */
17462 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
17463 GDB is still reading the definitions from command line. First
17464 DW_MACINFO_start_file will need to be ignored as it was already executed
17465 to create CURRENT_FILE for the main source holding also the command line
17466 definitions. On first met DW_MACINFO_start_file this flag is reset to
17467 normally execute all the remaining DW_MACINFO_start_file macinfos. */
17469 at_commandline
= 1;
17473 /* Do we at least have room for a macinfo type byte? */
17474 if (mac_ptr
>= mac_end
)
17476 dwarf2_section_buffer_overflow_complaint (section
);
17480 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17483 /* Note that we rely on the fact that the corresponding GNU and
17484 DWARF constants are the same. */
17485 switch (macinfo_type
)
17487 /* A zero macinfo type indicates the end of the macro
17492 case DW_MACRO_GNU_define
:
17493 case DW_MACRO_GNU_undef
:
17494 case DW_MACRO_GNU_define_indirect
:
17495 case DW_MACRO_GNU_undef_indirect
:
17496 case DW_MACRO_GNU_define_indirect_alt
:
17497 case DW_MACRO_GNU_undef_indirect_alt
:
17499 unsigned int bytes_read
;
17504 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17505 mac_ptr
+= bytes_read
;
17507 if (macinfo_type
== DW_MACRO_GNU_define
17508 || macinfo_type
== DW_MACRO_GNU_undef
)
17510 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17511 mac_ptr
+= bytes_read
;
17515 LONGEST str_offset
;
17517 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17518 mac_ptr
+= offset_size
;
17520 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
17521 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
)
17523 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17525 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
17528 body
= read_indirect_string_at_offset (abfd
, str_offset
);
17531 is_define
= (macinfo_type
== DW_MACRO_GNU_define
17532 || macinfo_type
== DW_MACRO_GNU_define_indirect
17533 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
17534 if (! current_file
)
17536 /* DWARF violation as no main source is present. */
17537 complaint (&symfile_complaints
,
17538 _("debug info with no main source gives macro %s "
17540 is_define
? _("definition") : _("undefinition"),
17544 if ((line
== 0 && !at_commandline
)
17545 || (line
!= 0 && at_commandline
))
17546 complaint (&symfile_complaints
,
17547 _("debug info gives %s macro %s with %s line %d: %s"),
17548 at_commandline
? _("command-line") : _("in-file"),
17549 is_define
? _("definition") : _("undefinition"),
17550 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
17553 parse_macro_definition (current_file
, line
, body
);
17556 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
17557 || macinfo_type
== DW_MACRO_GNU_undef_indirect
17558 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
17559 macro_undef (current_file
, line
, body
);
17564 case DW_MACRO_GNU_start_file
:
17566 unsigned int bytes_read
;
17569 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17570 mac_ptr
+= bytes_read
;
17571 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17572 mac_ptr
+= bytes_read
;
17574 if ((line
== 0 && !at_commandline
)
17575 || (line
!= 0 && at_commandline
))
17576 complaint (&symfile_complaints
,
17577 _("debug info gives source %d included "
17578 "from %s at %s line %d"),
17579 file
, at_commandline
? _("command-line") : _("file"),
17580 line
== 0 ? _("zero") : _("non-zero"), line
);
17582 if (at_commandline
)
17584 /* This DW_MACRO_GNU_start_file was executed in the
17586 at_commandline
= 0;
17589 current_file
= macro_start_file (file
, line
,
17590 current_file
, comp_dir
,
17595 case DW_MACRO_GNU_end_file
:
17596 if (! current_file
)
17597 complaint (&symfile_complaints
,
17598 _("macro debug info has an unmatched "
17599 "`close_file' directive"));
17602 current_file
= current_file
->included_by
;
17603 if (! current_file
)
17605 enum dwarf_macro_record_type next_type
;
17607 /* GCC circa March 2002 doesn't produce the zero
17608 type byte marking the end of the compilation
17609 unit. Complain if it's not there, but exit no
17612 /* Do we at least have room for a macinfo type byte? */
17613 if (mac_ptr
>= mac_end
)
17615 dwarf2_section_buffer_overflow_complaint (section
);
17619 /* We don't increment mac_ptr here, so this is just
17621 next_type
= read_1_byte (abfd
, mac_ptr
);
17622 if (next_type
!= 0)
17623 complaint (&symfile_complaints
,
17624 _("no terminating 0-type entry for "
17625 "macros in `.debug_macinfo' section"));
17632 case DW_MACRO_GNU_transparent_include
:
17633 case DW_MACRO_GNU_transparent_include_alt
:
17638 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
17639 mac_ptr
+= offset_size
;
17641 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17644 /* This has actually happened; see
17645 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
17646 complaint (&symfile_complaints
,
17647 _("recursive DW_MACRO_GNU_transparent_include in "
17648 ".debug_macro section"));
17652 bfd
*include_bfd
= abfd
;
17653 struct dwarf2_section_info
*include_section
= section
;
17654 struct dwarf2_section_info alt_section
;
17655 gdb_byte
*include_mac_end
= mac_end
;
17656 int is_dwz
= section_is_dwz
;
17660 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
17662 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
17664 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
17667 include_bfd
= dwz
->macro
.asection
->owner
;
17668 include_section
= &dwz
->macro
;
17669 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
17673 dwarf_decode_macro_bytes (include_bfd
,
17674 include_section
->buffer
+ offset
,
17675 include_mac_end
, current_file
,
17677 section
, section_is_gnu
, is_dwz
,
17678 offset_size
, objfile
, include_hash
);
17680 htab_remove_elt (include_hash
, mac_ptr
);
17685 case DW_MACINFO_vendor_ext
:
17686 if (!section_is_gnu
)
17688 unsigned int bytes_read
;
17691 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17692 mac_ptr
+= bytes_read
;
17693 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17694 mac_ptr
+= bytes_read
;
17696 /* We don't recognize any vendor extensions. */
17702 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17703 mac_ptr
, mac_end
, abfd
, offset_size
,
17705 if (mac_ptr
== NULL
)
17709 } while (macinfo_type
!= 0);
17713 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
17714 char *comp_dir
, int section_is_gnu
)
17716 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17717 struct line_header
*lh
= cu
->line_header
;
17719 gdb_byte
*mac_ptr
, *mac_end
;
17720 struct macro_source_file
*current_file
= 0;
17721 enum dwarf_macro_record_type macinfo_type
;
17722 unsigned int offset_size
= cu
->header
.offset_size
;
17723 gdb_byte
*opcode_definitions
[256];
17724 struct cleanup
*cleanup
;
17725 htab_t include_hash
;
17727 struct dwarf2_section_info
*section
;
17728 const char *section_name
;
17730 if (cu
->dwo_unit
!= NULL
)
17732 if (section_is_gnu
)
17734 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
17735 section_name
= ".debug_macro.dwo";
17739 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
17740 section_name
= ".debug_macinfo.dwo";
17745 if (section_is_gnu
)
17747 section
= &dwarf2_per_objfile
->macro
;
17748 section_name
= ".debug_macro";
17752 section
= &dwarf2_per_objfile
->macinfo
;
17753 section_name
= ".debug_macinfo";
17757 dwarf2_read_section (objfile
, section
);
17758 if (section
->buffer
== NULL
)
17760 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
17763 abfd
= section
->asection
->owner
;
17765 /* First pass: Find the name of the base filename.
17766 This filename is needed in order to process all macros whose definition
17767 (or undefinition) comes from the command line. These macros are defined
17768 before the first DW_MACINFO_start_file entry, and yet still need to be
17769 associated to the base file.
17771 To determine the base file name, we scan the macro definitions until we
17772 reach the first DW_MACINFO_start_file entry. We then initialize
17773 CURRENT_FILE accordingly so that any macro definition found before the
17774 first DW_MACINFO_start_file can still be associated to the base file. */
17776 mac_ptr
= section
->buffer
+ offset
;
17777 mac_end
= section
->buffer
+ section
->size
;
17779 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
17780 &offset_size
, section_is_gnu
);
17781 if (mac_ptr
== NULL
)
17783 /* We already issued a complaint. */
17789 /* Do we at least have room for a macinfo type byte? */
17790 if (mac_ptr
>= mac_end
)
17792 /* Complaint is printed during the second pass as GDB will probably
17793 stop the first pass earlier upon finding
17794 DW_MACINFO_start_file. */
17798 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
17801 /* Note that we rely on the fact that the corresponding GNU and
17802 DWARF constants are the same. */
17803 switch (macinfo_type
)
17805 /* A zero macinfo type indicates the end of the macro
17810 case DW_MACRO_GNU_define
:
17811 case DW_MACRO_GNU_undef
:
17812 /* Only skip the data by MAC_PTR. */
17814 unsigned int bytes_read
;
17816 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17817 mac_ptr
+= bytes_read
;
17818 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17819 mac_ptr
+= bytes_read
;
17823 case DW_MACRO_GNU_start_file
:
17825 unsigned int bytes_read
;
17828 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17829 mac_ptr
+= bytes_read
;
17830 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17831 mac_ptr
+= bytes_read
;
17833 current_file
= macro_start_file (file
, line
, current_file
,
17834 comp_dir
, lh
, objfile
);
17838 case DW_MACRO_GNU_end_file
:
17839 /* No data to skip by MAC_PTR. */
17842 case DW_MACRO_GNU_define_indirect
:
17843 case DW_MACRO_GNU_undef_indirect
:
17845 unsigned int bytes_read
;
17847 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17848 mac_ptr
+= bytes_read
;
17849 mac_ptr
+= offset_size
;
17853 case DW_MACRO_GNU_transparent_include
:
17854 /* Note that, according to the spec, a transparent include
17855 chain cannot call DW_MACRO_GNU_start_file. So, we can just
17856 skip this opcode. */
17857 mac_ptr
+= offset_size
;
17860 case DW_MACINFO_vendor_ext
:
17861 /* Only skip the data by MAC_PTR. */
17862 if (!section_is_gnu
)
17864 unsigned int bytes_read
;
17866 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
17867 mac_ptr
+= bytes_read
;
17868 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
17869 mac_ptr
+= bytes_read
;
17874 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
17875 mac_ptr
, mac_end
, abfd
, offset_size
,
17877 if (mac_ptr
== NULL
)
17881 } while (macinfo_type
!= 0 && current_file
== NULL
);
17883 /* Second pass: Process all entries.
17885 Use the AT_COMMAND_LINE flag to determine whether we are still processing
17886 command-line macro definitions/undefinitions. This flag is unset when we
17887 reach the first DW_MACINFO_start_file entry. */
17889 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
17890 NULL
, xcalloc
, xfree
);
17891 cleanup
= make_cleanup_htab_delete (include_hash
);
17892 mac_ptr
= section
->buffer
+ offset
;
17893 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
17895 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
17896 current_file
, lh
, comp_dir
, section
,
17898 offset_size
, objfile
, include_hash
);
17899 do_cleanups (cleanup
);
17902 /* Check if the attribute's form is a DW_FORM_block*
17903 if so return true else false. */
17906 attr_form_is_block (struct attribute
*attr
)
17908 return (attr
== NULL
? 0 :
17909 attr
->form
== DW_FORM_block1
17910 || attr
->form
== DW_FORM_block2
17911 || attr
->form
== DW_FORM_block4
17912 || attr
->form
== DW_FORM_block
17913 || attr
->form
== DW_FORM_exprloc
);
17916 /* Return non-zero if ATTR's value is a section offset --- classes
17917 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
17918 You may use DW_UNSND (attr) to retrieve such offsets.
17920 Section 7.5.4, "Attribute Encodings", explains that no attribute
17921 may have a value that belongs to more than one of these classes; it
17922 would be ambiguous if we did, because we use the same forms for all
17926 attr_form_is_section_offset (struct attribute
*attr
)
17928 return (attr
->form
== DW_FORM_data4
17929 || attr
->form
== DW_FORM_data8
17930 || attr
->form
== DW_FORM_sec_offset
);
17933 /* Return non-zero if ATTR's value falls in the 'constant' class, or
17934 zero otherwise. When this function returns true, you can apply
17935 dwarf2_get_attr_constant_value to it.
17937 However, note that for some attributes you must check
17938 attr_form_is_section_offset before using this test. DW_FORM_data4
17939 and DW_FORM_data8 are members of both the constant class, and of
17940 the classes that contain offsets into other debug sections
17941 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
17942 that, if an attribute's can be either a constant or one of the
17943 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
17944 taken as section offsets, not constants. */
17947 attr_form_is_constant (struct attribute
*attr
)
17949 switch (attr
->form
)
17951 case DW_FORM_sdata
:
17952 case DW_FORM_udata
:
17953 case DW_FORM_data1
:
17954 case DW_FORM_data2
:
17955 case DW_FORM_data4
:
17956 case DW_FORM_data8
:
17963 /* Return the .debug_loc section to use for CU.
17964 For DWO files use .debug_loc.dwo. */
17966 static struct dwarf2_section_info
*
17967 cu_debug_loc_section (struct dwarf2_cu
*cu
)
17970 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
17971 return &dwarf2_per_objfile
->loc
;
17974 /* A helper function that fills in a dwarf2_loclist_baton. */
17977 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
17978 struct dwarf2_loclist_baton
*baton
,
17979 struct attribute
*attr
)
17981 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
17983 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
17985 baton
->per_cu
= cu
->per_cu
;
17986 gdb_assert (baton
->per_cu
);
17987 /* We don't know how long the location list is, but make sure we
17988 don't run off the edge of the section. */
17989 baton
->size
= section
->size
- DW_UNSND (attr
);
17990 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
17991 baton
->base_address
= cu
->base_address
;
17992 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
17996 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
17997 struct dwarf2_cu
*cu
)
17999 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18000 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18002 if (attr_form_is_section_offset (attr
)
18003 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18004 the section. If so, fall through to the complaint in the
18006 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
18008 struct dwarf2_loclist_baton
*baton
;
18010 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18011 sizeof (struct dwarf2_loclist_baton
));
18013 fill_in_loclist_baton (cu
, baton
, attr
);
18015 if (cu
->base_known
== 0)
18016 complaint (&symfile_complaints
,
18017 _("Location list used without "
18018 "specifying the CU base address."));
18020 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
18021 SYMBOL_LOCATION_BATON (sym
) = baton
;
18025 struct dwarf2_locexpr_baton
*baton
;
18027 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18028 sizeof (struct dwarf2_locexpr_baton
));
18029 baton
->per_cu
= cu
->per_cu
;
18030 gdb_assert (baton
->per_cu
);
18032 if (attr_form_is_block (attr
))
18034 /* Note that we're just copying the block's data pointer
18035 here, not the actual data. We're still pointing into the
18036 info_buffer for SYM's objfile; right now we never release
18037 that buffer, but when we do clean up properly this may
18039 baton
->size
= DW_BLOCK (attr
)->size
;
18040 baton
->data
= DW_BLOCK (attr
)->data
;
18044 dwarf2_invalid_attrib_class_complaint ("location description",
18045 SYMBOL_NATURAL_NAME (sym
));
18049 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
18050 SYMBOL_LOCATION_BATON (sym
) = baton
;
18054 /* Return the OBJFILE associated with the compilation unit CU. If CU
18055 came from a separate debuginfo file, then the master objfile is
18059 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
18061 struct objfile
*objfile
= per_cu
->objfile
;
18063 /* Return the master objfile, so that we can report and look up the
18064 correct file containing this variable. */
18065 if (objfile
->separate_debug_objfile_backlink
)
18066 objfile
= objfile
->separate_debug_objfile_backlink
;
18071 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18072 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18073 CU_HEADERP first. */
18075 static const struct comp_unit_head
*
18076 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
18077 struct dwarf2_per_cu_data
*per_cu
)
18079 gdb_byte
*info_ptr
;
18082 return &per_cu
->cu
->header
;
18084 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
18086 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
18087 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
18092 /* Return the address size given in the compilation unit header for CU. */
18095 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18097 struct comp_unit_head cu_header_local
;
18098 const struct comp_unit_head
*cu_headerp
;
18100 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18102 return cu_headerp
->addr_size
;
18105 /* Return the offset size given in the compilation unit header for CU. */
18108 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
18110 struct comp_unit_head cu_header_local
;
18111 const struct comp_unit_head
*cu_headerp
;
18113 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18115 return cu_headerp
->offset_size
;
18118 /* See its dwarf2loc.h declaration. */
18121 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18123 struct comp_unit_head cu_header_local
;
18124 const struct comp_unit_head
*cu_headerp
;
18126 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18128 if (cu_headerp
->version
== 2)
18129 return cu_headerp
->addr_size
;
18131 return cu_headerp
->offset_size
;
18134 /* Return the text offset of the CU. The returned offset comes from
18135 this CU's objfile. If this objfile came from a separate debuginfo
18136 file, then the offset may be different from the corresponding
18137 offset in the parent objfile. */
18140 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
18142 struct objfile
*objfile
= per_cu
->objfile
;
18144 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
18147 /* Locate the .debug_info compilation unit from CU's objfile which contains
18148 the DIE at OFFSET. Raises an error on failure. */
18150 static struct dwarf2_per_cu_data
*
18151 dwarf2_find_containing_comp_unit (sect_offset offset
,
18152 unsigned int offset_in_dwz
,
18153 struct objfile
*objfile
)
18155 struct dwarf2_per_cu_data
*this_cu
;
18157 const sect_offset
*cu_off
;
18160 high
= dwarf2_per_objfile
->n_comp_units
- 1;
18163 struct dwarf2_per_cu_data
*mid_cu
;
18164 int mid
= low
+ (high
- low
) / 2;
18166 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
18167 cu_off
= &mid_cu
->offset
;
18168 if (mid_cu
->is_dwz
> offset_in_dwz
18169 || (mid_cu
->is_dwz
== offset_in_dwz
18170 && cu_off
->sect_off
>= offset
.sect_off
))
18175 gdb_assert (low
== high
);
18176 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
18177 cu_off
= &this_cu
->offset
;
18178 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
18180 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
18181 error (_("Dwarf Error: could not find partial DIE containing "
18182 "offset 0x%lx [in module %s]"),
18183 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
18185 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
18186 <= offset
.sect_off
);
18187 return dwarf2_per_objfile
->all_comp_units
[low
-1];
18191 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
18192 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
18193 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
18194 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
18195 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
18200 /* Initialize dwarf2_cu CU, owned by PER_CU. */
18203 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
18205 memset (cu
, 0, sizeof (*cu
));
18207 cu
->per_cu
= per_cu
;
18208 cu
->objfile
= per_cu
->objfile
;
18209 obstack_init (&cu
->comp_unit_obstack
);
18212 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
18215 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
18216 enum language pretend_language
)
18218 struct attribute
*attr
;
18220 /* Set the language we're debugging. */
18221 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
18223 set_cu_language (DW_UNSND (attr
), cu
);
18226 cu
->language
= pretend_language
;
18227 cu
->language_defn
= language_def (cu
->language
);
18230 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
18232 cu
->producer
= DW_STRING (attr
);
18235 /* Release one cached compilation unit, CU. We unlink it from the tree
18236 of compilation units, but we don't remove it from the read_in_chain;
18237 the caller is responsible for that.
18238 NOTE: DATA is a void * because this function is also used as a
18239 cleanup routine. */
18242 free_heap_comp_unit (void *data
)
18244 struct dwarf2_cu
*cu
= data
;
18246 gdb_assert (cu
->per_cu
!= NULL
);
18247 cu
->per_cu
->cu
= NULL
;
18250 obstack_free (&cu
->comp_unit_obstack
, NULL
);
18255 /* This cleanup function is passed the address of a dwarf2_cu on the stack
18256 when we're finished with it. We can't free the pointer itself, but be
18257 sure to unlink it from the cache. Also release any associated storage. */
18260 free_stack_comp_unit (void *data
)
18262 struct dwarf2_cu
*cu
= data
;
18264 gdb_assert (cu
->per_cu
!= NULL
);
18265 cu
->per_cu
->cu
= NULL
;
18268 obstack_free (&cu
->comp_unit_obstack
, NULL
);
18269 cu
->partial_dies
= NULL
;
18272 /* Free all cached compilation units. */
18275 free_cached_comp_units (void *data
)
18277 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18279 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18280 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18281 while (per_cu
!= NULL
)
18283 struct dwarf2_per_cu_data
*next_cu
;
18285 next_cu
= per_cu
->cu
->read_in_chain
;
18287 free_heap_comp_unit (per_cu
->cu
);
18288 *last_chain
= next_cu
;
18294 /* Increase the age counter on each cached compilation unit, and free
18295 any that are too old. */
18298 age_cached_comp_units (void)
18300 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18302 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
18303 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18304 while (per_cu
!= NULL
)
18306 per_cu
->cu
->last_used
++;
18307 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
18308 dwarf2_mark (per_cu
->cu
);
18309 per_cu
= per_cu
->cu
->read_in_chain
;
18312 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18313 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18314 while (per_cu
!= NULL
)
18316 struct dwarf2_per_cu_data
*next_cu
;
18318 next_cu
= per_cu
->cu
->read_in_chain
;
18320 if (!per_cu
->cu
->mark
)
18322 free_heap_comp_unit (per_cu
->cu
);
18323 *last_chain
= next_cu
;
18326 last_chain
= &per_cu
->cu
->read_in_chain
;
18332 /* Remove a single compilation unit from the cache. */
18335 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
18337 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
18339 per_cu
= dwarf2_per_objfile
->read_in_chain
;
18340 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
18341 while (per_cu
!= NULL
)
18343 struct dwarf2_per_cu_data
*next_cu
;
18345 next_cu
= per_cu
->cu
->read_in_chain
;
18347 if (per_cu
== target_per_cu
)
18349 free_heap_comp_unit (per_cu
->cu
);
18351 *last_chain
= next_cu
;
18355 last_chain
= &per_cu
->cu
->read_in_chain
;
18361 /* Release all extra memory associated with OBJFILE. */
18364 dwarf2_free_objfile (struct objfile
*objfile
)
18366 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
18368 if (dwarf2_per_objfile
== NULL
)
18371 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
18372 free_cached_comp_units (NULL
);
18374 if (dwarf2_per_objfile
->quick_file_names_table
)
18375 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
18377 /* Everything else should be on the objfile obstack. */
18380 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
18381 We store these in a hash table separate from the DIEs, and preserve them
18382 when the DIEs are flushed out of cache.
18384 The CU "per_cu" pointer is needed because offset alone is not enough to
18385 uniquely identify the type. A file may have multiple .debug_types sections,
18386 or the type may come from a DWO file. We have to use something in
18387 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
18388 routine, get_die_type_at_offset, from outside this file, and thus won't
18389 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
18392 struct dwarf2_per_cu_offset_and_type
18394 const struct dwarf2_per_cu_data
*per_cu
;
18395 sect_offset offset
;
18399 /* Hash function for a dwarf2_per_cu_offset_and_type. */
18402 per_cu_offset_and_type_hash (const void *item
)
18404 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
18406 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
18409 /* Equality function for a dwarf2_per_cu_offset_and_type. */
18412 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
18414 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
18415 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
18417 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
18418 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
18421 /* Set the type associated with DIE to TYPE. Save it in CU's hash
18422 table if necessary. For convenience, return TYPE.
18424 The DIEs reading must have careful ordering to:
18425 * Not cause infite loops trying to read in DIEs as a prerequisite for
18426 reading current DIE.
18427 * Not trying to dereference contents of still incompletely read in types
18428 while reading in other DIEs.
18429 * Enable referencing still incompletely read in types just by a pointer to
18430 the type without accessing its fields.
18432 Therefore caller should follow these rules:
18433 * Try to fetch any prerequisite types we may need to build this DIE type
18434 before building the type and calling set_die_type.
18435 * After building type call set_die_type for current DIE as soon as
18436 possible before fetching more types to complete the current type.
18437 * Make the type as complete as possible before fetching more types. */
18439 static struct type
*
18440 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
18442 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
18443 struct objfile
*objfile
= cu
->objfile
;
18445 /* For Ada types, make sure that the gnat-specific data is always
18446 initialized (if not already set). There are a few types where
18447 we should not be doing so, because the type-specific area is
18448 already used to hold some other piece of info (eg: TYPE_CODE_FLT
18449 where the type-specific area is used to store the floatformat).
18450 But this is not a problem, because the gnat-specific information
18451 is actually not needed for these types. */
18452 if (need_gnat_info (cu
)
18453 && TYPE_CODE (type
) != TYPE_CODE_FUNC
18454 && TYPE_CODE (type
) != TYPE_CODE_FLT
18455 && !HAVE_GNAT_AUX_INFO (type
))
18456 INIT_GNAT_SPECIFIC (type
);
18458 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18460 dwarf2_per_objfile
->die_type_hash
=
18461 htab_create_alloc_ex (127,
18462 per_cu_offset_and_type_hash
,
18463 per_cu_offset_and_type_eq
,
18465 &objfile
->objfile_obstack
,
18466 hashtab_obstack_allocate
,
18467 dummy_obstack_deallocate
);
18470 ofs
.per_cu
= cu
->per_cu
;
18471 ofs
.offset
= die
->offset
;
18473 slot
= (struct dwarf2_per_cu_offset_and_type
**)
18474 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
18476 complaint (&symfile_complaints
,
18477 _("A problem internal to GDB: DIE 0x%x has type already set"),
18478 die
->offset
.sect_off
);
18479 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
18484 /* Look up the type for the die at OFFSET in the appropriate type_hash
18485 table, or return NULL if the die does not have a saved type. */
18487 static struct type
*
18488 get_die_type_at_offset (sect_offset offset
,
18489 struct dwarf2_per_cu_data
*per_cu
)
18491 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
18493 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
18496 ofs
.per_cu
= per_cu
;
18497 ofs
.offset
= offset
;
18498 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
18505 /* Look up the type for DIE in the appropriate type_hash table,
18506 or return NULL if DIE does not have a saved type. */
18508 static struct type
*
18509 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18511 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
18514 /* Add a dependence relationship from CU to REF_PER_CU. */
18517 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
18518 struct dwarf2_per_cu_data
*ref_per_cu
)
18522 if (cu
->dependencies
== NULL
)
18524 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
18525 NULL
, &cu
->comp_unit_obstack
,
18526 hashtab_obstack_allocate
,
18527 dummy_obstack_deallocate
);
18529 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
18531 *slot
= ref_per_cu
;
18534 /* Subroutine of dwarf2_mark to pass to htab_traverse.
18535 Set the mark field in every compilation unit in the
18536 cache that we must keep because we are keeping CU. */
18539 dwarf2_mark_helper (void **slot
, void *data
)
18541 struct dwarf2_per_cu_data
*per_cu
;
18543 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
18545 /* cu->dependencies references may not yet have been ever read if QUIT aborts
18546 reading of the chain. As such dependencies remain valid it is not much
18547 useful to track and undo them during QUIT cleanups. */
18548 if (per_cu
->cu
== NULL
)
18551 if (per_cu
->cu
->mark
)
18553 per_cu
->cu
->mark
= 1;
18555 if (per_cu
->cu
->dependencies
!= NULL
)
18556 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18561 /* Set the mark field in CU and in every other compilation unit in the
18562 cache that we must keep because we are keeping CU. */
18565 dwarf2_mark (struct dwarf2_cu
*cu
)
18570 if (cu
->dependencies
!= NULL
)
18571 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
18575 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
18579 per_cu
->cu
->mark
= 0;
18580 per_cu
= per_cu
->cu
->read_in_chain
;
18584 /* Trivial hash function for partial_die_info: the hash value of a DIE
18585 is its offset in .debug_info for this objfile. */
18588 partial_die_hash (const void *item
)
18590 const struct partial_die_info
*part_die
= item
;
18592 return part_die
->offset
.sect_off
;
18595 /* Trivial comparison function for partial_die_info structures: two DIEs
18596 are equal if they have the same offset. */
18599 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
18601 const struct partial_die_info
*part_die_lhs
= item_lhs
;
18602 const struct partial_die_info
*part_die_rhs
= item_rhs
;
18604 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
18607 static struct cmd_list_element
*set_dwarf2_cmdlist
;
18608 static struct cmd_list_element
*show_dwarf2_cmdlist
;
18611 set_dwarf2_cmd (char *args
, int from_tty
)
18613 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
18617 show_dwarf2_cmd (char *args
, int from_tty
)
18619 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
18622 /* Free data associated with OBJFILE, if necessary. */
18625 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
18627 struct dwarf2_per_objfile
*data
= d
;
18630 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
18631 VEC_free (dwarf2_per_cu_ptr
,
18632 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
18634 VEC_free (dwarf2_section_info_def
, data
->types
);
18636 if (data
->dwo_files
)
18637 free_dwo_files (data
->dwo_files
, objfile
);
18639 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
18640 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
18644 /* The "save gdb-index" command. */
18646 /* The contents of the hash table we create when building the string
18648 struct strtab_entry
18650 offset_type offset
;
18654 /* Hash function for a strtab_entry.
18656 Function is used only during write_hash_table so no index format backward
18657 compatibility is needed. */
18660 hash_strtab_entry (const void *e
)
18662 const struct strtab_entry
*entry
= e
;
18663 return mapped_index_string_hash (INT_MAX
, entry
->str
);
18666 /* Equality function for a strtab_entry. */
18669 eq_strtab_entry (const void *a
, const void *b
)
18671 const struct strtab_entry
*ea
= a
;
18672 const struct strtab_entry
*eb
= b
;
18673 return !strcmp (ea
->str
, eb
->str
);
18676 /* Create a strtab_entry hash table. */
18679 create_strtab (void)
18681 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
18682 xfree
, xcalloc
, xfree
);
18685 /* Add a string to the constant pool. Return the string's offset in
18689 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
18692 struct strtab_entry entry
;
18693 struct strtab_entry
*result
;
18696 slot
= htab_find_slot (table
, &entry
, INSERT
);
18701 result
= XNEW (struct strtab_entry
);
18702 result
->offset
= obstack_object_size (cpool
);
18704 obstack_grow_str0 (cpool
, str
);
18707 return result
->offset
;
18710 /* An entry in the symbol table. */
18711 struct symtab_index_entry
18713 /* The name of the symbol. */
18715 /* The offset of the name in the constant pool. */
18716 offset_type index_offset
;
18717 /* A sorted vector of the indices of all the CUs that hold an object
18719 VEC (offset_type
) *cu_indices
;
18722 /* The symbol table. This is a power-of-2-sized hash table. */
18723 struct mapped_symtab
18725 offset_type n_elements
;
18727 struct symtab_index_entry
**data
;
18730 /* Hash function for a symtab_index_entry. */
18733 hash_symtab_entry (const void *e
)
18735 const struct symtab_index_entry
*entry
= e
;
18736 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
18737 sizeof (offset_type
) * VEC_length (offset_type
,
18738 entry
->cu_indices
),
18742 /* Equality function for a symtab_index_entry. */
18745 eq_symtab_entry (const void *a
, const void *b
)
18747 const struct symtab_index_entry
*ea
= a
;
18748 const struct symtab_index_entry
*eb
= b
;
18749 int len
= VEC_length (offset_type
, ea
->cu_indices
);
18750 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
18752 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
18753 VEC_address (offset_type
, eb
->cu_indices
),
18754 sizeof (offset_type
) * len
);
18757 /* Destroy a symtab_index_entry. */
18760 delete_symtab_entry (void *p
)
18762 struct symtab_index_entry
*entry
= p
;
18763 VEC_free (offset_type
, entry
->cu_indices
);
18767 /* Create a hash table holding symtab_index_entry objects. */
18770 create_symbol_hash_table (void)
18772 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
18773 delete_symtab_entry
, xcalloc
, xfree
);
18776 /* Create a new mapped symtab object. */
18778 static struct mapped_symtab
*
18779 create_mapped_symtab (void)
18781 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
18782 symtab
->n_elements
= 0;
18783 symtab
->size
= 1024;
18784 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18788 /* Destroy a mapped_symtab. */
18791 cleanup_mapped_symtab (void *p
)
18793 struct mapped_symtab
*symtab
= p
;
18794 /* The contents of the array are freed when the other hash table is
18796 xfree (symtab
->data
);
18800 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
18803 Function is used only during write_hash_table so no index format backward
18804 compatibility is needed. */
18806 static struct symtab_index_entry
**
18807 find_slot (struct mapped_symtab
*symtab
, const char *name
)
18809 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
18811 index
= hash
& (symtab
->size
- 1);
18812 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
18816 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
18817 return &symtab
->data
[index
];
18818 index
= (index
+ step
) & (symtab
->size
- 1);
18822 /* Expand SYMTAB's hash table. */
18825 hash_expand (struct mapped_symtab
*symtab
)
18827 offset_type old_size
= symtab
->size
;
18829 struct symtab_index_entry
**old_entries
= symtab
->data
;
18832 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
18834 for (i
= 0; i
< old_size
; ++i
)
18836 if (old_entries
[i
])
18838 struct symtab_index_entry
**slot
= find_slot (symtab
,
18839 old_entries
[i
]->name
);
18840 *slot
= old_entries
[i
];
18844 xfree (old_entries
);
18847 /* Add an entry to SYMTAB. NAME is the name of the symbol.
18848 CU_INDEX is the index of the CU in which the symbol appears.
18849 IS_STATIC is one if the symbol is static, otherwise zero (global). */
18852 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
18853 int is_static
, gdb_index_symbol_kind kind
,
18854 offset_type cu_index
)
18856 struct symtab_index_entry
**slot
;
18857 offset_type cu_index_and_attrs
;
18859 ++symtab
->n_elements
;
18860 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
18861 hash_expand (symtab
);
18863 slot
= find_slot (symtab
, name
);
18866 *slot
= XNEW (struct symtab_index_entry
);
18867 (*slot
)->name
= name
;
18868 /* index_offset is set later. */
18869 (*slot
)->cu_indices
= NULL
;
18872 cu_index_and_attrs
= 0;
18873 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
18874 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
18875 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
18877 /* We don't want to record an index value twice as we want to avoid the
18879 We process all global symbols and then all static symbols
18880 (which would allow us to avoid the duplication by only having to check
18881 the last entry pushed), but a symbol could have multiple kinds in one CU.
18882 To keep things simple we don't worry about the duplication here and
18883 sort and uniqufy the list after we've processed all symbols. */
18884 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
18887 /* qsort helper routine for uniquify_cu_indices. */
18890 offset_type_compare (const void *ap
, const void *bp
)
18892 offset_type a
= *(offset_type
*) ap
;
18893 offset_type b
= *(offset_type
*) bp
;
18895 return (a
> b
) - (b
> a
);
18898 /* Sort and remove duplicates of all symbols' cu_indices lists. */
18901 uniquify_cu_indices (struct mapped_symtab
*symtab
)
18905 for (i
= 0; i
< symtab
->size
; ++i
)
18907 struct symtab_index_entry
*entry
= symtab
->data
[i
];
18910 && entry
->cu_indices
!= NULL
)
18912 unsigned int next_to_insert
, next_to_check
;
18913 offset_type last_value
;
18915 qsort (VEC_address (offset_type
, entry
->cu_indices
),
18916 VEC_length (offset_type
, entry
->cu_indices
),
18917 sizeof (offset_type
), offset_type_compare
);
18919 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
18920 next_to_insert
= 1;
18921 for (next_to_check
= 1;
18922 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
18925 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
18928 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
18930 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
18935 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
18940 /* Add a vector of indices to the constant pool. */
18943 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
18944 struct symtab_index_entry
*entry
)
18948 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
18951 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
18952 offset_type val
= MAYBE_SWAP (len
);
18957 entry
->index_offset
= obstack_object_size (cpool
);
18959 obstack_grow (cpool
, &val
, sizeof (val
));
18961 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
18964 val
= MAYBE_SWAP (iter
);
18965 obstack_grow (cpool
, &val
, sizeof (val
));
18970 struct symtab_index_entry
*old_entry
= *slot
;
18971 entry
->index_offset
= old_entry
->index_offset
;
18974 return entry
->index_offset
;
18977 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
18978 constant pool entries going into the obstack CPOOL. */
18981 write_hash_table (struct mapped_symtab
*symtab
,
18982 struct obstack
*output
, struct obstack
*cpool
)
18985 htab_t symbol_hash_table
;
18988 symbol_hash_table
= create_symbol_hash_table ();
18989 str_table
= create_strtab ();
18991 /* We add all the index vectors to the constant pool first, to
18992 ensure alignment is ok. */
18993 for (i
= 0; i
< symtab
->size
; ++i
)
18995 if (symtab
->data
[i
])
18996 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
18999 /* Now write out the hash table. */
19000 for (i
= 0; i
< symtab
->size
; ++i
)
19002 offset_type str_off
, vec_off
;
19004 if (symtab
->data
[i
])
19006 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
19007 vec_off
= symtab
->data
[i
]->index_offset
;
19011 /* While 0 is a valid constant pool index, it is not valid
19012 to have 0 for both offsets. */
19017 str_off
= MAYBE_SWAP (str_off
);
19018 vec_off
= MAYBE_SWAP (vec_off
);
19020 obstack_grow (output
, &str_off
, sizeof (str_off
));
19021 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
19024 htab_delete (str_table
);
19025 htab_delete (symbol_hash_table
);
19028 /* Struct to map psymtab to CU index in the index file. */
19029 struct psymtab_cu_index_map
19031 struct partial_symtab
*psymtab
;
19032 unsigned int cu_index
;
19036 hash_psymtab_cu_index (const void *item
)
19038 const struct psymtab_cu_index_map
*map
= item
;
19040 return htab_hash_pointer (map
->psymtab
);
19044 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
19046 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
19047 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
19049 return lhs
->psymtab
== rhs
->psymtab
;
19052 /* Helper struct for building the address table. */
19053 struct addrmap_index_data
19055 struct objfile
*objfile
;
19056 struct obstack
*addr_obstack
;
19057 htab_t cu_index_htab
;
19059 /* Non-zero if the previous_* fields are valid.
19060 We can't write an entry until we see the next entry (since it is only then
19061 that we know the end of the entry). */
19062 int previous_valid
;
19063 /* Index of the CU in the table of all CUs in the index file. */
19064 unsigned int previous_cu_index
;
19065 /* Start address of the CU. */
19066 CORE_ADDR previous_cu_start
;
19069 /* Write an address entry to OBSTACK. */
19072 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
19073 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
19075 offset_type cu_index_to_write
;
19077 CORE_ADDR baseaddr
;
19079 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19081 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
19082 obstack_grow (obstack
, addr
, 8);
19083 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
19084 obstack_grow (obstack
, addr
, 8);
19085 cu_index_to_write
= MAYBE_SWAP (cu_index
);
19086 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
19089 /* Worker function for traversing an addrmap to build the address table. */
19092 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
19094 struct addrmap_index_data
*data
= datap
;
19095 struct partial_symtab
*pst
= obj
;
19097 if (data
->previous_valid
)
19098 add_address_entry (data
->objfile
, data
->addr_obstack
,
19099 data
->previous_cu_start
, start_addr
,
19100 data
->previous_cu_index
);
19102 data
->previous_cu_start
= start_addr
;
19105 struct psymtab_cu_index_map find_map
, *map
;
19106 find_map
.psymtab
= pst
;
19107 map
= htab_find (data
->cu_index_htab
, &find_map
);
19108 gdb_assert (map
!= NULL
);
19109 data
->previous_cu_index
= map
->cu_index
;
19110 data
->previous_valid
= 1;
19113 data
->previous_valid
= 0;
19118 /* Write OBJFILE's address map to OBSTACK.
19119 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
19120 in the index file. */
19123 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
19124 htab_t cu_index_htab
)
19126 struct addrmap_index_data addrmap_index_data
;
19128 /* When writing the address table, we have to cope with the fact that
19129 the addrmap iterator only provides the start of a region; we have to
19130 wait until the next invocation to get the start of the next region. */
19132 addrmap_index_data
.objfile
= objfile
;
19133 addrmap_index_data
.addr_obstack
= obstack
;
19134 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
19135 addrmap_index_data
.previous_valid
= 0;
19137 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
19138 &addrmap_index_data
);
19140 /* It's highly unlikely the last entry (end address = 0xff...ff)
19141 is valid, but we should still handle it.
19142 The end address is recorded as the start of the next region, but that
19143 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
19145 if (addrmap_index_data
.previous_valid
)
19146 add_address_entry (objfile
, obstack
,
19147 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
19148 addrmap_index_data
.previous_cu_index
);
19151 /* Return the symbol kind of PSYM. */
19153 static gdb_index_symbol_kind
19154 symbol_kind (struct partial_symbol
*psym
)
19156 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
19157 enum address_class aclass
= PSYMBOL_CLASS (psym
);
19165 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
19167 return GDB_INDEX_SYMBOL_KIND_TYPE
;
19169 case LOC_CONST_BYTES
:
19170 case LOC_OPTIMIZED_OUT
:
19172 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
19174 /* Note: It's currently impossible to recognize psyms as enum values
19175 short of reading the type info. For now punt. */
19176 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
19178 /* There are other LOC_FOO values that one might want to classify
19179 as variables, but dwarf2read.c doesn't currently use them. */
19180 return GDB_INDEX_SYMBOL_KIND_OTHER
;
19182 case STRUCT_DOMAIN
:
19183 return GDB_INDEX_SYMBOL_KIND_TYPE
;
19185 return GDB_INDEX_SYMBOL_KIND_OTHER
;
19189 /* Add a list of partial symbols to SYMTAB. */
19192 write_psymbols (struct mapped_symtab
*symtab
,
19194 struct partial_symbol
**psymp
,
19196 offset_type cu_index
,
19199 for (; count
-- > 0; ++psymp
)
19201 struct partial_symbol
*psym
= *psymp
;
19204 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
19205 error (_("Ada is not currently supported by the index"));
19207 /* Only add a given psymbol once. */
19208 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
19211 gdb_index_symbol_kind kind
= symbol_kind (psym
);
19214 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
19215 is_static
, kind
, cu_index
);
19220 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
19221 exception if there is an error. */
19224 write_obstack (FILE *file
, struct obstack
*obstack
)
19226 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
19228 != obstack_object_size (obstack
))
19229 error (_("couldn't data write to file"));
19232 /* Unlink a file if the argument is not NULL. */
19235 unlink_if_set (void *p
)
19237 char **filename
= p
;
19239 unlink (*filename
);
19242 /* A helper struct used when iterating over debug_types. */
19243 struct signatured_type_index_data
19245 struct objfile
*objfile
;
19246 struct mapped_symtab
*symtab
;
19247 struct obstack
*types_list
;
19252 /* A helper function that writes a single signatured_type to an
19256 write_one_signatured_type (void **slot
, void *d
)
19258 struct signatured_type_index_data
*info
= d
;
19259 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
19260 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
19261 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19264 write_psymbols (info
->symtab
,
19266 info
->objfile
->global_psymbols
.list
19267 + psymtab
->globals_offset
,
19268 psymtab
->n_global_syms
, info
->cu_index
,
19270 write_psymbols (info
->symtab
,
19272 info
->objfile
->static_psymbols
.list
19273 + psymtab
->statics_offset
,
19274 psymtab
->n_static_syms
, info
->cu_index
,
19277 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19278 entry
->per_cu
.offset
.sect_off
);
19279 obstack_grow (info
->types_list
, val
, 8);
19280 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19281 entry
->type_offset_in_tu
.cu_off
);
19282 obstack_grow (info
->types_list
, val
, 8);
19283 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
19284 obstack_grow (info
->types_list
, val
, 8);
19291 /* Recurse into all "included" dependencies and write their symbols as
19292 if they appeared in this psymtab. */
19295 recursively_write_psymbols (struct objfile
*objfile
,
19296 struct partial_symtab
*psymtab
,
19297 struct mapped_symtab
*symtab
,
19299 offset_type cu_index
)
19303 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
19304 if (psymtab
->dependencies
[i
]->user
!= NULL
)
19305 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
19306 symtab
, psyms_seen
, cu_index
);
19308 write_psymbols (symtab
,
19310 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
19311 psymtab
->n_global_syms
, cu_index
,
19313 write_psymbols (symtab
,
19315 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
19316 psymtab
->n_static_syms
, cu_index
,
19320 /* Create an index file for OBJFILE in the directory DIR. */
19323 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
19325 struct cleanup
*cleanup
;
19326 char *filename
, *cleanup_filename
;
19327 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
19328 struct obstack cu_list
, types_cu_list
;
19331 struct mapped_symtab
*symtab
;
19332 offset_type val
, size_of_contents
, total_len
;
19335 htab_t cu_index_htab
;
19336 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
19338 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
19341 if (dwarf2_per_objfile
->using_index
)
19342 error (_("Cannot use an index to create the index"));
19344 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
19345 error (_("Cannot make an index when the file has multiple .debug_types sections"));
19347 if (stat (objfile
->name
, &st
) < 0)
19348 perror_with_name (objfile
->name
);
19350 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
19351 INDEX_SUFFIX
, (char *) NULL
);
19352 cleanup
= make_cleanup (xfree
, filename
);
19354 out_file
= fopen (filename
, "wb");
19356 error (_("Can't open `%s' for writing"), filename
);
19358 cleanup_filename
= filename
;
19359 make_cleanup (unlink_if_set
, &cleanup_filename
);
19361 symtab
= create_mapped_symtab ();
19362 make_cleanup (cleanup_mapped_symtab
, symtab
);
19364 obstack_init (&addr_obstack
);
19365 make_cleanup_obstack_free (&addr_obstack
);
19367 obstack_init (&cu_list
);
19368 make_cleanup_obstack_free (&cu_list
);
19370 obstack_init (&types_cu_list
);
19371 make_cleanup_obstack_free (&types_cu_list
);
19373 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
19374 NULL
, xcalloc
, xfree
);
19375 make_cleanup_htab_delete (psyms_seen
);
19377 /* While we're scanning CU's create a table that maps a psymtab pointer
19378 (which is what addrmap records) to its index (which is what is recorded
19379 in the index file). This will later be needed to write the address
19381 cu_index_htab
= htab_create_alloc (100,
19382 hash_psymtab_cu_index
,
19383 eq_psymtab_cu_index
,
19384 NULL
, xcalloc
, xfree
);
19385 make_cleanup_htab_delete (cu_index_htab
);
19386 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
19387 xmalloc (sizeof (struct psymtab_cu_index_map
)
19388 * dwarf2_per_objfile
->n_comp_units
);
19389 make_cleanup (xfree
, psymtab_cu_index_map
);
19391 /* The CU list is already sorted, so we don't need to do additional
19392 work here. Also, the debug_types entries do not appear in
19393 all_comp_units, but only in their own hash table. */
19394 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
19396 struct dwarf2_per_cu_data
*per_cu
19397 = dwarf2_per_objfile
->all_comp_units
[i
];
19398 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
19400 struct psymtab_cu_index_map
*map
;
19403 if (psymtab
->user
== NULL
)
19404 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
19406 map
= &psymtab_cu_index_map
[i
];
19407 map
->psymtab
= psymtab
;
19409 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
19410 gdb_assert (slot
!= NULL
);
19411 gdb_assert (*slot
== NULL
);
19414 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
19415 per_cu
->offset
.sect_off
);
19416 obstack_grow (&cu_list
, val
, 8);
19417 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
19418 obstack_grow (&cu_list
, val
, 8);
19421 /* Dump the address map. */
19422 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
19424 /* Write out the .debug_type entries, if any. */
19425 if (dwarf2_per_objfile
->signatured_types
)
19427 struct signatured_type_index_data sig_data
;
19429 sig_data
.objfile
= objfile
;
19430 sig_data
.symtab
= symtab
;
19431 sig_data
.types_list
= &types_cu_list
;
19432 sig_data
.psyms_seen
= psyms_seen
;
19433 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
19434 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
19435 write_one_signatured_type
, &sig_data
);
19438 /* Now that we've processed all symbols we can shrink their cu_indices
19440 uniquify_cu_indices (symtab
);
19442 obstack_init (&constant_pool
);
19443 make_cleanup_obstack_free (&constant_pool
);
19444 obstack_init (&symtab_obstack
);
19445 make_cleanup_obstack_free (&symtab_obstack
);
19446 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
19448 obstack_init (&contents
);
19449 make_cleanup_obstack_free (&contents
);
19450 size_of_contents
= 6 * sizeof (offset_type
);
19451 total_len
= size_of_contents
;
19453 /* The version number. */
19454 val
= MAYBE_SWAP (7);
19455 obstack_grow (&contents
, &val
, sizeof (val
));
19457 /* The offset of the CU list from the start of the file. */
19458 val
= MAYBE_SWAP (total_len
);
19459 obstack_grow (&contents
, &val
, sizeof (val
));
19460 total_len
+= obstack_object_size (&cu_list
);
19462 /* The offset of the types CU list from the start of the file. */
19463 val
= MAYBE_SWAP (total_len
);
19464 obstack_grow (&contents
, &val
, sizeof (val
));
19465 total_len
+= obstack_object_size (&types_cu_list
);
19467 /* The offset of the address table from the start of the file. */
19468 val
= MAYBE_SWAP (total_len
);
19469 obstack_grow (&contents
, &val
, sizeof (val
));
19470 total_len
+= obstack_object_size (&addr_obstack
);
19472 /* The offset of the symbol table from the start of the file. */
19473 val
= MAYBE_SWAP (total_len
);
19474 obstack_grow (&contents
, &val
, sizeof (val
));
19475 total_len
+= obstack_object_size (&symtab_obstack
);
19477 /* The offset of the constant pool from the start of the file. */
19478 val
= MAYBE_SWAP (total_len
);
19479 obstack_grow (&contents
, &val
, sizeof (val
));
19480 total_len
+= obstack_object_size (&constant_pool
);
19482 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
19484 write_obstack (out_file
, &contents
);
19485 write_obstack (out_file
, &cu_list
);
19486 write_obstack (out_file
, &types_cu_list
);
19487 write_obstack (out_file
, &addr_obstack
);
19488 write_obstack (out_file
, &symtab_obstack
);
19489 write_obstack (out_file
, &constant_pool
);
19493 /* We want to keep the file, so we set cleanup_filename to NULL
19494 here. See unlink_if_set. */
19495 cleanup_filename
= NULL
;
19497 do_cleanups (cleanup
);
19500 /* Implementation of the `save gdb-index' command.
19502 Note that the file format used by this command is documented in the
19503 GDB manual. Any changes here must be documented there. */
19506 save_gdb_index_command (char *arg
, int from_tty
)
19508 struct objfile
*objfile
;
19511 error (_("usage: save gdb-index DIRECTORY"));
19513 ALL_OBJFILES (objfile
)
19517 /* If the objfile does not correspond to an actual file, skip it. */
19518 if (stat (objfile
->name
, &st
) < 0)
19521 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19522 if (dwarf2_per_objfile
)
19524 volatile struct gdb_exception except
;
19526 TRY_CATCH (except
, RETURN_MASK_ERROR
)
19528 write_psymtabs_to_index (objfile
, arg
);
19530 if (except
.reason
< 0)
19531 exception_fprintf (gdb_stderr
, except
,
19532 _("Error while writing index for `%s': "),
19540 int dwarf2_always_disassemble
;
19543 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
19544 struct cmd_list_element
*c
, const char *value
)
19546 fprintf_filtered (file
,
19547 _("Whether to always disassemble "
19548 "DWARF expressions is %s.\n"),
19553 show_check_physname (struct ui_file
*file
, int from_tty
,
19554 struct cmd_list_element
*c
, const char *value
)
19556 fprintf_filtered (file
,
19557 _("Whether to check \"physname\" is %s.\n"),
19561 void _initialize_dwarf2_read (void);
19564 _initialize_dwarf2_read (void)
19566 struct cmd_list_element
*c
;
19568 dwarf2_objfile_data_key
19569 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
19571 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
19572 Set DWARF 2 specific variables.\n\
19573 Configure DWARF 2 variables such as the cache size"),
19574 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
19575 0/*allow-unknown*/, &maintenance_set_cmdlist
);
19577 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
19578 Show DWARF 2 specific variables\n\
19579 Show DWARF 2 variables such as the cache size"),
19580 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
19581 0/*allow-unknown*/, &maintenance_show_cmdlist
);
19583 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
19584 &dwarf2_max_cache_age
, _("\
19585 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
19586 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
19587 A higher limit means that cached compilation units will be stored\n\
19588 in memory longer, and more total memory will be used. Zero disables\n\
19589 caching, which can slow down startup."),
19591 show_dwarf2_max_cache_age
,
19592 &set_dwarf2_cmdlist
,
19593 &show_dwarf2_cmdlist
);
19595 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
19596 &dwarf2_always_disassemble
, _("\
19597 Set whether `info address' always disassembles DWARF expressions."), _("\
19598 Show whether `info address' always disassembles DWARF expressions."), _("\
19599 When enabled, DWARF expressions are always printed in an assembly-like\n\
19600 syntax. When disabled, expressions will be printed in a more\n\
19601 conversational style, when possible."),
19603 show_dwarf2_always_disassemble
,
19604 &set_dwarf2_cmdlist
,
19605 &show_dwarf2_cmdlist
);
19607 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
19608 Set debugging of the dwarf2 reader."), _("\
19609 Show debugging of the dwarf2 reader."), _("\
19610 When enabled, debugging messages are printed during dwarf2 reading\n\
19611 and symtab expansion."),
19614 &setdebuglist
, &showdebuglist
);
19616 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
19617 Set debugging of the dwarf2 DIE reader."), _("\
19618 Show debugging of the dwarf2 DIE reader."), _("\
19619 When enabled (non-zero), DIEs are dumped after they are read in.\n\
19620 The value is the maximum depth to print."),
19623 &setdebuglist
, &showdebuglist
);
19625 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
19626 Set cross-checking of \"physname\" code against demangler."), _("\
19627 Show cross-checking of \"physname\" code against demangler."), _("\
19628 When enabled, GDB's internal \"physname\" code is checked against\n\
19630 NULL
, show_check_physname
,
19631 &setdebuglist
, &showdebuglist
);
19633 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
19635 Save a gdb-index file.\n\
19636 Usage: save gdb-index DIRECTORY"),
19638 set_cmd_completer (c
, filename_completer
);