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. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
72 #include "gdb_string.h"
73 #include "gdb_assert.h"
74 #include <sys/types.h>
76 typedef struct symbol
*symbolp
;
79 /* When non-zero, print basic high level tracing messages.
80 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
81 static int dwarf2_read_debug
= 0;
83 /* When non-zero, dump DIEs after they are read in. */
84 static unsigned int dwarf2_die_debug
= 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname
= 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 static int use_deprecated_index_sections
= 0;
92 /* When set, the file that we're processing is known to have debugging
93 info for C++ namespaces. GCC 3.3.x did not produce this information,
94 but later versions do. */
96 static int processing_has_namespace_info
;
98 static const struct objfile_data
*dwarf2_objfile_data_key
;
100 struct dwarf2_section_info
105 /* True if we have tried to read this section. */
109 typedef struct dwarf2_section_info dwarf2_section_info_def
;
110 DEF_VEC_O (dwarf2_section_info_def
);
112 /* All offsets in the index are of this type. It must be
113 architecture-independent. */
114 typedef uint32_t offset_type
;
116 DEF_VEC_I (offset_type
);
118 /* Ensure only legit values are used. */
119 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
121 gdb_assert ((unsigned int) (value) <= 1); \
122 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
125 /* Ensure only legit values are used. */
126 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
128 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
129 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
130 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
133 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
134 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
136 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
137 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* Index data format version. */
147 /* The total length of the buffer. */
150 /* A pointer to the address table data. */
151 const gdb_byte
*address_table
;
153 /* Size of the address table data in bytes. */
154 offset_type address_table_size
;
156 /* The symbol table, implemented as a hash table. */
157 const offset_type
*symbol_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots
;
162 /* A pointer to the constant pool. */
163 const char *constant_pool
;
166 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
167 DEF_VEC_P (dwarf2_per_cu_ptr
);
169 /* Collection of data recorded per objfile.
170 This hangs off of dwarf2_objfile_data_key. */
172 struct dwarf2_per_objfile
174 struct dwarf2_section_info info
;
175 struct dwarf2_section_info abbrev
;
176 struct dwarf2_section_info line
;
177 struct dwarf2_section_info loc
;
178 struct dwarf2_section_info macinfo
;
179 struct dwarf2_section_info macro
;
180 struct dwarf2_section_info str
;
181 struct dwarf2_section_info ranges
;
182 struct dwarf2_section_info addr
;
183 struct dwarf2_section_info frame
;
184 struct dwarf2_section_info eh_frame
;
185 struct dwarf2_section_info gdb_index
;
187 VEC (dwarf2_section_info_def
) *types
;
190 struct objfile
*objfile
;
192 /* Table of all the compilation units. This is used to locate
193 the target compilation unit of a particular reference. */
194 struct dwarf2_per_cu_data
**all_comp_units
;
196 /* The number of compilation units in ALL_COMP_UNITS. */
199 /* The number of .debug_types-related CUs. */
202 /* The .debug_types-related CUs (TUs). */
203 struct signatured_type
**all_type_units
;
205 /* The number of entries in all_type_unit_groups. */
206 int n_type_unit_groups
;
208 /* Table of type unit groups.
209 This exists to make it easy to iterate over all CUs and TU groups. */
210 struct type_unit_group
**all_type_unit_groups
;
212 /* Table of struct type_unit_group objects.
213 The hash key is the DW_AT_stmt_list value. */
214 htab_t type_unit_groups
;
216 /* A table mapping .debug_types signatures to its signatured_type entry.
217 This is NULL if the .debug_types section hasn't been read in yet. */
218 htab_t signatured_types
;
220 /* Type unit statistics, to see how well the scaling improvements
224 int nr_uniq_abbrev_tables
;
226 int nr_symtab_sharers
;
227 int nr_stmt_less_type_units
;
230 /* A chain of compilation units that are currently read in, so that
231 they can be freed later. */
232 struct dwarf2_per_cu_data
*read_in_chain
;
234 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
235 This is NULL if the table hasn't been allocated yet. */
238 /* Non-zero if we've check for whether there is a DWP file. */
241 /* The DWP file if there is one, or NULL. */
242 struct dwp_file
*dwp_file
;
244 /* The shared '.dwz' file, if one exists. This is used when the
245 original data was compressed using 'dwz -m'. */
246 struct dwz_file
*dwz_file
;
248 /* A flag indicating wether this objfile has a section loaded at a
250 int has_section_at_zero
;
252 /* True if we are using the mapped index,
253 or we are faking it for OBJF_READNOW's sake. */
254 unsigned char using_index
;
256 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
257 struct mapped_index
*index_table
;
259 /* When using index_table, this keeps track of all quick_file_names entries.
260 TUs typically share line table entries with a CU, so we maintain a
261 separate table of all line table entries to support the sharing.
262 Note that while there can be way more TUs than CUs, we've already
263 sorted all the TUs into "type unit groups", grouped by their
264 DW_AT_stmt_list value. Therefore the only sharing done here is with a
265 CU and its associated TU group if there is one. */
266 htab_t quick_file_names_table
;
268 /* Set during partial symbol reading, to prevent queueing of full
270 int reading_partial_symbols
;
272 /* Table mapping type DIEs to their struct type *.
273 This is NULL if not allocated yet.
274 The mapping is done via (CU/TU signature + DIE offset) -> type. */
275 htab_t die_type_hash
;
277 /* The CUs we recently read. */
278 VEC (dwarf2_per_cu_ptr
) *just_read_cus
;
281 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
283 /* Default names of the debugging sections. */
285 /* Note that if the debugging section has been compressed, it might
286 have a name like .zdebug_info. */
288 static const struct dwarf2_debug_sections dwarf2_elf_names
=
290 { ".debug_info", ".zdebug_info" },
291 { ".debug_abbrev", ".zdebug_abbrev" },
292 { ".debug_line", ".zdebug_line" },
293 { ".debug_loc", ".zdebug_loc" },
294 { ".debug_macinfo", ".zdebug_macinfo" },
295 { ".debug_macro", ".zdebug_macro" },
296 { ".debug_str", ".zdebug_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_types", ".zdebug_types" },
299 { ".debug_addr", ".zdebug_addr" },
300 { ".debug_frame", ".zdebug_frame" },
301 { ".eh_frame", NULL
},
302 { ".gdb_index", ".zgdb_index" },
306 /* List of DWO/DWP sections. */
308 static const struct dwop_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names macinfo_dwo
;
315 struct dwarf2_section_names macro_dwo
;
316 struct dwarf2_section_names str_dwo
;
317 struct dwarf2_section_names str_offsets_dwo
;
318 struct dwarf2_section_names types_dwo
;
319 struct dwarf2_section_names cu_index
;
320 struct dwarf2_section_names tu_index
;
324 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
325 { ".debug_info.dwo", ".zdebug_info.dwo" },
326 { ".debug_line.dwo", ".zdebug_line.dwo" },
327 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_offset
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 /* Offset to the first byte of this compilation unit header in the
356 .debug_info section, for resolving relative reference dies. */
359 /* Offset to first die in this cu from the start of the cu.
360 This will be the first byte following the compilation unit header. */
361 cu_offset first_die_offset
;
364 /* Type used for delaying computation of method physnames.
365 See comments for compute_delayed_physnames. */
366 struct delayed_method_info
368 /* The type to which the method is attached, i.e., its parent class. */
371 /* The index of the method in the type's function fieldlists. */
374 /* The index of the method in the fieldlist. */
377 /* The name of the DIE. */
380 /* The DIE associated with this method. */
381 struct die_info
*die
;
384 typedef struct delayed_method_info delayed_method_info
;
385 DEF_VEC_O (delayed_method_info
);
387 /* Internal state when decoding a particular compilation unit. */
390 /* The objfile containing this compilation unit. */
391 struct objfile
*objfile
;
393 /* The header of the compilation unit. */
394 struct comp_unit_head header
;
396 /* Base address of this compilation unit. */
397 CORE_ADDR base_address
;
399 /* Non-zero if base_address has been set. */
402 /* The language we are debugging. */
403 enum language language
;
404 const struct language_defn
*language_defn
;
406 const char *producer
;
408 /* The generic symbol table building routines have separate lists for
409 file scope symbols and all all other scopes (local scopes). So
410 we need to select the right one to pass to add_symbol_to_list().
411 We do it by keeping a pointer to the correct list in list_in_scope.
413 FIXME: The original dwarf code just treated the file scope as the
414 first local scope, and all other local scopes as nested local
415 scopes, and worked fine. Check to see if we really need to
416 distinguish these in buildsym.c. */
417 struct pending
**list_in_scope
;
419 /* The abbrev table for this CU.
420 Normally this points to the abbrev table in the objfile.
421 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
422 struct abbrev_table
*abbrev_table
;
424 /* Hash table holding all the loaded partial DIEs
425 with partial_die->offset.SECT_OFF as hash. */
428 /* Storage for things with the same lifetime as this read-in compilation
429 unit, including partial DIEs. */
430 struct obstack comp_unit_obstack
;
432 /* When multiple dwarf2_cu structures are living in memory, this field
433 chains them all together, so that they can be released efficiently.
434 We will probably also want a generation counter so that most-recently-used
435 compilation units are cached... */
436 struct dwarf2_per_cu_data
*read_in_chain
;
438 /* Backchain to our per_cu entry if the tree has been built. */
439 struct dwarf2_per_cu_data
*per_cu
;
441 /* How many compilation units ago was this CU last referenced? */
444 /* A hash table of DIE cu_offset for following references with
445 die_info->offset.sect_off as hash. */
448 /* Full DIEs if read in. */
449 struct die_info
*dies
;
451 /* A set of pointers to dwarf2_per_cu_data objects for compilation
452 units referenced by this one. Only set during full symbol processing;
453 partial symbol tables do not have dependencies. */
456 /* Header data from the line table, during full symbol processing. */
457 struct line_header
*line_header
;
459 /* A list of methods which need to have physnames computed
460 after all type information has been read. */
461 VEC (delayed_method_info
) *method_list
;
463 /* To be copied to symtab->call_site_htab. */
464 htab_t call_site_htab
;
466 /* Non-NULL if this CU came from a DWO file.
467 There is an invariant here that is important to remember:
468 Except for attributes copied from the top level DIE in the "main"
469 (or "stub") file in preparation for reading the DWO file
470 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
471 Either there isn't a DWO file (in which case this is NULL and the point
472 is moot), or there is and either we're not going to read it (in which
473 case this is NULL) or there is and we are reading it (in which case this
475 struct dwo_unit
*dwo_unit
;
477 /* The DW_AT_addr_base attribute if present, zero otherwise
478 (zero is a valid value though).
479 Note this value comes from the stub CU/TU's DIE. */
482 /* The DW_AT_ranges_base attribute if present, zero otherwise
483 (zero is a valid value though).
484 Note this value comes from the stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not. */
487 ULONGEST ranges_base
;
489 /* Mark used when releasing cached dies. */
490 unsigned int mark
: 1;
492 /* This CU references .debug_loc. See the symtab->locations_valid field.
493 This test is imperfect as there may exist optimized debug code not using
494 any location list and still facing inlining issues if handled as
495 unoptimized code. For a future better test see GCC PR other/32998. */
496 unsigned int has_loclist
: 1;
498 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
499 if all the producer_is_* fields are valid. This information is cached
500 because profiling CU expansion showed excessive time spent in
501 producer_is_gxx_lt_4_6. */
502 unsigned int checked_producer
: 1;
503 unsigned int producer_is_gxx_lt_4_6
: 1;
504 unsigned int producer_is_gcc_lt_4_3
: 1;
505 unsigned int producer_is_icc
: 1;
508 /* Persistent data held for a compilation unit, even when not
509 processing it. We put a pointer to this structure in the
510 read_symtab_private field of the psymtab. */
512 struct dwarf2_per_cu_data
514 /* The start offset and length of this compilation unit.
515 NOTE: Unlike comp_unit_head.length, this length includes
517 If the DIE refers to a DWO file, this is always of the original die,
522 /* Flag indicating this compilation unit will be read in before
523 any of the current compilation units are processed. */
524 unsigned int queued
: 1;
526 /* This flag will be set when reading partial DIEs if we need to load
527 absolutely all DIEs for this compilation unit, instead of just the ones
528 we think are interesting. It gets set if we look for a DIE in the
529 hash table and don't find it. */
530 unsigned int load_all_dies
: 1;
532 /* Non-zero if this CU is from .debug_types. */
533 unsigned int is_debug_types
: 1;
535 /* Non-zero if this CU is from the .dwz file. */
536 unsigned int is_dwz
: 1;
538 /* The section this CU/TU lives in.
539 If the DIE refers to a DWO file, this is always the original die,
541 struct dwarf2_section_info
*info_or_types_section
;
543 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
544 of the CU cache it gets reset to NULL again. */
545 struct dwarf2_cu
*cu
;
547 /* The corresponding objfile.
548 Normally we can get the objfile from dwarf2_per_objfile.
549 However we can enter this file with just a "per_cu" handle. */
550 struct objfile
*objfile
;
552 /* When using partial symbol tables, the 'psymtab' field is active.
553 Otherwise the 'quick' field is active. */
556 /* The partial symbol table associated with this compilation unit,
557 or NULL for unread partial units. */
558 struct partial_symtab
*psymtab
;
560 /* Data needed by the "quick" functions. */
561 struct dwarf2_per_cu_quick_data
*quick
;
566 /* The CUs we import using DW_TAG_imported_unit. This is filled in
567 while reading psymtabs, used to compute the psymtab dependencies,
568 and then cleared. Then it is filled in again while reading full
569 symbols, and only deleted when the objfile is destroyed. */
570 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
572 /* Type units are grouped by their DW_AT_stmt_list entry so that they
573 can share them. If this is a TU, this points to the containing
575 struct type_unit_group
*type_unit_group
;
579 /* Entry in the signatured_types hash table. */
581 struct signatured_type
583 /* The "per_cu" object of this type.
584 N.B.: This is the first member so that it's easy to convert pointers
586 struct dwarf2_per_cu_data per_cu
;
588 /* The type's signature. */
591 /* Offset in the TU of the type's DIE, as read from the TU header.
592 If the definition lives in a DWO file, this value is unusable. */
593 cu_offset type_offset_in_tu
;
595 /* Offset in the section of the type's DIE.
596 If the definition lives in a DWO file, this is the offset in the
597 .debug_types.dwo section.
598 The value is zero until the actual value is known.
599 Zero is otherwise not a valid section offset. */
600 sect_offset type_offset_in_section
;
603 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
604 This includes type_unit_group and quick_file_names. */
606 struct stmt_list_hash
608 /* The DWO unit this table is from or NULL if there is none. */
609 struct dwo_unit
*dwo_unit
;
611 /* Offset in .debug_line or .debug_line.dwo. */
612 sect_offset line_offset
;
615 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
616 an object of this type. */
618 struct type_unit_group
620 /* dwarf2read.c's main "handle" on the symtab.
621 To simplify things we create an artificial CU that "includes" all the
622 type units using this stmt_list so that the rest of the code still has
623 a "per_cu" handle on the symtab.
624 This PER_CU is recognized by having no section. */
625 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
626 struct dwarf2_per_cu_data per_cu
;
630 /* The TUs that share this DW_AT_stmt_list entry.
631 This is added to while parsing type units to build partial symtabs,
632 and is deleted afterwards and not used again. */
633 VEC (dwarf2_per_cu_ptr
) *tus
;
635 /* When reading the line table in "quick" functions, we need a real TU.
636 Any will do, we know they all share the same DW_AT_stmt_list entry.
637 For simplicity's sake, we pick the first one. */
638 struct dwarf2_per_cu_data
*first_tu
;
641 /* The primary symtab.
642 Type units in a group needn't all be defined in the same source file,
643 so we create an essentially anonymous symtab as the primary symtab. */
644 struct symtab
*primary_symtab
;
646 /* The data used to construct the hash key. */
647 struct stmt_list_hash hash
;
649 /* The number of symtabs from the line header.
650 The value here must match line_header.num_file_names. */
651 unsigned int num_symtabs
;
653 /* The symbol tables for this TU (obtained from the files listed in
655 WARNING: The order of entries here must match the order of entries
656 in the line header. After the first TU using this type_unit_group, the
657 line header for the subsequent TUs is recreated from this. This is done
658 because we need to use the same symtabs for each TU using the same
659 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
660 there's no guarantee the line header doesn't have duplicate entries. */
661 struct symtab
**symtabs
;
664 /* These sections are what may appear in a DWO file. */
668 struct dwarf2_section_info abbrev
;
669 struct dwarf2_section_info line
;
670 struct dwarf2_section_info loc
;
671 struct dwarf2_section_info macinfo
;
672 struct dwarf2_section_info macro
;
673 struct dwarf2_section_info str
;
674 struct dwarf2_section_info str_offsets
;
675 /* In the case of a virtual DWO file, these two are unused. */
676 struct dwarf2_section_info info
;
677 VEC (dwarf2_section_info_def
) *types
;
680 /* Common bits of DWO CUs/TUs. */
684 /* Backlink to the containing struct dwo_file. */
685 struct dwo_file
*dwo_file
;
687 /* The "id" that distinguishes this CU/TU.
688 .debug_info calls this "dwo_id", .debug_types calls this "signature".
689 Since signatures came first, we stick with it for consistency. */
692 /* The section this CU/TU lives in, in the DWO file. */
693 struct dwarf2_section_info
*info_or_types_section
;
695 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
699 /* For types, offset in the type's DIE of the type defined by this TU. */
700 cu_offset type_offset_in_tu
;
703 /* Data for one DWO file.
704 This includes virtual DWO files that have been packaged into a
709 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
710 For virtual DWO files the name is constructed from the section offsets
711 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
712 from related CU+TUs. */
715 /* The bfd, when the file is open. Otherwise this is NULL.
716 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 /* Section info for this file. */
720 struct dwo_sections sections
;
722 /* Table of CUs in the file.
723 Each element is a struct dwo_unit. */
726 /* Table of TUs in the file.
727 Each element is a struct dwo_unit. */
731 /* These sections are what may appear in a DWP file. */
735 struct dwarf2_section_info str
;
736 struct dwarf2_section_info cu_index
;
737 struct dwarf2_section_info tu_index
;
738 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
739 by section number. We don't need to record them here. */
742 /* These sections are what may appear in a virtual DWO file. */
744 struct virtual_dwo_sections
746 struct dwarf2_section_info abbrev
;
747 struct dwarf2_section_info line
;
748 struct dwarf2_section_info loc
;
749 struct dwarf2_section_info macinfo
;
750 struct dwarf2_section_info macro
;
751 struct dwarf2_section_info str_offsets
;
752 /* Each DWP hash table entry records one CU or one TU.
753 That is recorded here, and copied to dwo_unit.info_or_types_section. */
754 struct dwarf2_section_info info_or_types
;
757 /* Contents of DWP hash tables. */
759 struct dwp_hash_table
761 uint32_t nr_units
, nr_slots
;
762 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
765 /* Data for one DWP file. */
769 /* Name of the file. */
772 /* The bfd, when the file is open. Otherwise this is NULL. */
775 /* Section info for this file. */
776 struct dwp_sections sections
;
778 /* Table of CUs in the file. */
779 const struct dwp_hash_table
*cus
;
781 /* Table of TUs in the file. */
782 const struct dwp_hash_table
*tus
;
784 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
787 /* Table to map ELF section numbers to their sections. */
788 unsigned int num_sections
;
789 asection
**elf_sections
;
792 /* This represents a '.dwz' file. */
796 /* A dwz file can only contain a few sections. */
797 struct dwarf2_section_info abbrev
;
798 struct dwarf2_section_info info
;
799 struct dwarf2_section_info str
;
800 struct dwarf2_section_info line
;
801 struct dwarf2_section_info macro
;
802 struct dwarf2_section_info gdb_index
;
808 /* Struct used to pass misc. parameters to read_die_and_children, et
809 al. which are used for both .debug_info and .debug_types dies.
810 All parameters here are unchanging for the life of the call. This
811 struct exists to abstract away the constant parameters of die reading. */
813 struct die_reader_specs
815 /* die_section->asection->owner. */
818 /* The CU of the DIE we are parsing. */
819 struct dwarf2_cu
*cu
;
821 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
822 struct dwo_file
*dwo_file
;
824 /* The section the die comes from.
825 This is either .debug_info or .debug_types, or the .dwo variants. */
826 struct dwarf2_section_info
*die_section
;
828 /* die_section->buffer. */
831 /* The end of the buffer. */
832 const gdb_byte
*buffer_end
;
835 /* Type of function passed to init_cutu_and_read_dies, et.al. */
836 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
838 struct die_info
*comp_unit_die
,
842 /* The line number information for a compilation unit (found in the
843 .debug_line section) begins with a "statement program header",
844 which contains the following information. */
847 unsigned int total_length
;
848 unsigned short version
;
849 unsigned int header_length
;
850 unsigned char minimum_instruction_length
;
851 unsigned char maximum_ops_per_instruction
;
852 unsigned char default_is_stmt
;
854 unsigned char line_range
;
855 unsigned char opcode_base
;
857 /* standard_opcode_lengths[i] is the number of operands for the
858 standard opcode whose value is i. This means that
859 standard_opcode_lengths[0] is unused, and the last meaningful
860 element is standard_opcode_lengths[opcode_base - 1]. */
861 unsigned char *standard_opcode_lengths
;
863 /* The include_directories table. NOTE! These strings are not
864 allocated with xmalloc; instead, they are pointers into
865 debug_line_buffer. If you try to free them, `free' will get
867 unsigned int num_include_dirs
, include_dirs_size
;
870 /* The file_names table. NOTE! These strings are not allocated
871 with xmalloc; instead, they are pointers into debug_line_buffer.
872 Don't try to free them directly. */
873 unsigned int num_file_names
, file_names_size
;
877 unsigned int dir_index
;
878 unsigned int mod_time
;
880 int included_p
; /* Non-zero if referenced by the Line Number Program. */
881 struct symtab
*symtab
; /* The associated symbol table, if any. */
884 /* The start and end of the statement program following this
885 header. These point into dwarf2_per_objfile->line_buffer. */
886 gdb_byte
*statement_program_start
, *statement_program_end
;
889 /* When we construct a partial symbol table entry we only
890 need this much information. */
891 struct partial_die_info
893 /* Offset of this DIE. */
896 /* DWARF-2 tag for this DIE. */
897 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
899 /* Assorted flags describing the data found in this DIE. */
900 unsigned int has_children
: 1;
901 unsigned int is_external
: 1;
902 unsigned int is_declaration
: 1;
903 unsigned int has_type
: 1;
904 unsigned int has_specification
: 1;
905 unsigned int has_pc_info
: 1;
906 unsigned int may_be_inlined
: 1;
908 /* Flag set if the SCOPE field of this structure has been
910 unsigned int scope_set
: 1;
912 /* Flag set if the DIE has a byte_size attribute. */
913 unsigned int has_byte_size
: 1;
915 /* Flag set if any of the DIE's children are template arguments. */
916 unsigned int has_template_arguments
: 1;
918 /* Flag set if fixup_partial_die has been called on this die. */
919 unsigned int fixup_called
: 1;
921 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
922 unsigned int is_dwz
: 1;
924 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
925 unsigned int spec_is_dwz
: 1;
927 /* The name of this DIE. Normally the value of DW_AT_name, but
928 sometimes a default name for unnamed DIEs. */
931 /* The linkage name, if present. */
932 const char *linkage_name
;
934 /* The scope to prepend to our children. This is generally
935 allocated on the comp_unit_obstack, so will disappear
936 when this compilation unit leaves the cache. */
939 /* Some data associated with the partial DIE. The tag determines
940 which field is live. */
943 /* The location description associated with this DIE, if any. */
944 struct dwarf_block
*locdesc
;
945 /* The offset of an import, for DW_TAG_imported_unit. */
949 /* If HAS_PC_INFO, the PC range associated with this DIE. */
953 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
954 DW_AT_sibling, if any. */
955 /* NOTE: This member isn't strictly necessary, read_partial_die could
956 return DW_AT_sibling values to its caller load_partial_dies. */
959 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
960 DW_AT_specification (or DW_AT_abstract_origin or
962 sect_offset spec_offset
;
964 /* Pointers to this DIE's parent, first child, and next sibling,
966 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
969 /* This data structure holds the information of an abbrev. */
972 unsigned int number
; /* number identifying abbrev */
973 enum dwarf_tag tag
; /* dwarf tag */
974 unsigned short has_children
; /* boolean */
975 unsigned short num_attrs
; /* number of attributes */
976 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
977 struct abbrev_info
*next
; /* next in chain */
982 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
983 ENUM_BITFIELD(dwarf_form
) form
: 16;
986 /* Size of abbrev_table.abbrev_hash_table. */
987 #define ABBREV_HASH_SIZE 121
989 /* Top level data structure to contain an abbreviation table. */
993 /* Where the abbrev table came from.
994 This is used as a sanity check when the table is used. */
997 /* Storage for the abbrev table. */
998 struct obstack abbrev_obstack
;
1000 /* Hash table of abbrevs.
1001 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1002 It could be statically allocated, but the previous code didn't so we
1004 struct abbrev_info
**abbrevs
;
1007 /* Attributes have a name and a value. */
1010 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1011 ENUM_BITFIELD(dwarf_form
) form
: 15;
1013 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1014 field should be in u.str (existing only for DW_STRING) but it is kept
1015 here for better struct attribute alignment. */
1016 unsigned int string_is_canonical
: 1;
1021 struct dwarf_block
*blk
;
1025 struct signatured_type
*signatured_type
;
1030 /* This data structure holds a complete die structure. */
1033 /* DWARF-2 tag for this DIE. */
1034 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1036 /* Number of attributes */
1037 unsigned char num_attrs
;
1039 /* True if we're presently building the full type name for the
1040 type derived from this DIE. */
1041 unsigned char building_fullname
: 1;
1044 unsigned int abbrev
;
1046 /* Offset in .debug_info or .debug_types section. */
1049 /* The dies in a compilation unit form an n-ary tree. PARENT
1050 points to this die's parent; CHILD points to the first child of
1051 this node; and all the children of a given node are chained
1052 together via their SIBLING fields. */
1053 struct die_info
*child
; /* Its first child, if any. */
1054 struct die_info
*sibling
; /* Its next sibling, if any. */
1055 struct die_info
*parent
; /* Its parent, if any. */
1057 /* An array of attributes, with NUM_ATTRS elements. There may be
1058 zero, but it's not common and zero-sized arrays are not
1059 sufficiently portable C. */
1060 struct attribute attrs
[1];
1063 /* Get at parts of an attribute structure. */
1065 #define DW_STRING(attr) ((attr)->u.str)
1066 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1067 #define DW_UNSND(attr) ((attr)->u.unsnd)
1068 #define DW_BLOCK(attr) ((attr)->u.blk)
1069 #define DW_SND(attr) ((attr)->u.snd)
1070 #define DW_ADDR(attr) ((attr)->u.addr)
1071 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1073 /* Blocks are a bunch of untyped bytes. */
1078 /* Valid only if SIZE is not zero. */
1082 #ifndef ATTR_ALLOC_CHUNK
1083 #define ATTR_ALLOC_CHUNK 4
1086 /* Allocate fields for structs, unions and enums in this size. */
1087 #ifndef DW_FIELD_ALLOC_CHUNK
1088 #define DW_FIELD_ALLOC_CHUNK 4
1091 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1092 but this would require a corresponding change in unpack_field_as_long
1094 static int bits_per_byte
= 8;
1096 /* The routines that read and process dies for a C struct or C++ class
1097 pass lists of data member fields and lists of member function fields
1098 in an instance of a field_info structure, as defined below. */
1101 /* List of data member and baseclasses fields. */
1104 struct nextfield
*next
;
1109 *fields
, *baseclasses
;
1111 /* Number of fields (including baseclasses). */
1114 /* Number of baseclasses. */
1117 /* Set if the accesibility of one of the fields is not public. */
1118 int non_public_fields
;
1120 /* Member function fields array, entries are allocated in the order they
1121 are encountered in the object file. */
1124 struct nextfnfield
*next
;
1125 struct fn_field fnfield
;
1129 /* Member function fieldlist array, contains name of possibly overloaded
1130 member function, number of overloaded member functions and a pointer
1131 to the head of the member function field chain. */
1136 struct nextfnfield
*head
;
1140 /* Number of entries in the fnfieldlists array. */
1143 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1144 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1145 struct typedef_field_list
1147 struct typedef_field field
;
1148 struct typedef_field_list
*next
;
1150 *typedef_field_list
;
1151 unsigned typedef_field_list_count
;
1154 /* One item on the queue of compilation units to read in full symbols
1156 struct dwarf2_queue_item
1158 struct dwarf2_per_cu_data
*per_cu
;
1159 enum language pretend_language
;
1160 struct dwarf2_queue_item
*next
;
1163 /* The current queue. */
1164 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1166 /* Loaded secondary compilation units are kept in memory until they
1167 have not been referenced for the processing of this many
1168 compilation units. Set this to zero to disable caching. Cache
1169 sizes of up to at least twenty will improve startup time for
1170 typical inter-CU-reference binaries, at an obvious memory cost. */
1171 static int dwarf2_max_cache_age
= 5;
1173 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1174 struct cmd_list_element
*c
, const char *value
)
1176 fprintf_filtered (file
, _("The upper bound on the age of cached "
1177 "dwarf2 compilation units is %s.\n"),
1182 /* Various complaints about symbol reading that don't abort the process. */
1185 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1187 complaint (&symfile_complaints
,
1188 _("statement list doesn't fit in .debug_line section"));
1192 dwarf2_debug_line_missing_file_complaint (void)
1194 complaint (&symfile_complaints
,
1195 _(".debug_line section has line data without a file"));
1199 dwarf2_debug_line_missing_end_sequence_complaint (void)
1201 complaint (&symfile_complaints
,
1202 _(".debug_line section has line "
1203 "program sequence without an end"));
1207 dwarf2_complex_location_expr_complaint (void)
1209 complaint (&symfile_complaints
, _("location expression too complex"));
1213 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1216 complaint (&symfile_complaints
,
1217 _("const value length mismatch for '%s', got %d, expected %d"),
1222 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1224 complaint (&symfile_complaints
,
1225 _("debug info runs off end of %s section"
1227 section
->asection
->name
,
1228 bfd_get_filename (section
->asection
->owner
));
1232 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1234 complaint (&symfile_complaints
,
1235 _("macro debug info contains a "
1236 "malformed macro definition:\n`%s'"),
1241 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1243 complaint (&symfile_complaints
,
1244 _("invalid attribute class or form for '%s' in '%s'"),
1248 /* local function prototypes */
1250 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1252 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1255 static void dwarf2_find_base_address (struct die_info
*die
,
1256 struct dwarf2_cu
*cu
);
1258 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1260 static void scan_partial_symbols (struct partial_die_info
*,
1261 CORE_ADDR
*, CORE_ADDR
*,
1262 int, struct dwarf2_cu
*);
1264 static void add_partial_symbol (struct partial_die_info
*,
1265 struct dwarf2_cu
*);
1267 static void add_partial_namespace (struct partial_die_info
*pdi
,
1268 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1269 int need_pc
, struct dwarf2_cu
*cu
);
1271 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1272 CORE_ADDR
*highpc
, int need_pc
,
1273 struct dwarf2_cu
*cu
);
1275 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1276 struct dwarf2_cu
*cu
);
1278 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1279 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1280 int need_pc
, struct dwarf2_cu
*cu
);
1282 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
1284 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1286 static struct abbrev_info
*abbrev_table_lookup_abbrev
1287 (const struct abbrev_table
*, unsigned int);
1289 static struct abbrev_table
*abbrev_table_read_table
1290 (struct dwarf2_section_info
*, sect_offset
);
1292 static void abbrev_table_free (struct abbrev_table
*);
1294 static void abbrev_table_free_cleanup (void *);
1296 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1297 struct dwarf2_section_info
*);
1299 static void dwarf2_free_abbrev_table (void *);
1301 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1303 static struct partial_die_info
*load_partial_dies
1304 (const struct die_reader_specs
*, gdb_byte
*, int);
1306 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1307 struct partial_die_info
*,
1308 struct abbrev_info
*,
1312 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1313 struct dwarf2_cu
*);
1315 static void fixup_partial_die (struct partial_die_info
*,
1316 struct dwarf2_cu
*);
1318 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1319 struct attribute
*, struct attr_abbrev
*,
1322 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1324 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1326 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1328 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1330 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1332 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1335 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1337 static LONGEST read_checked_initial_length_and_offset
1338 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1339 unsigned int *, unsigned int *);
1341 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1344 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1346 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1349 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1351 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1353 static char *read_indirect_string (bfd
*, gdb_byte
*,
1354 const struct comp_unit_head
*,
1357 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1359 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1361 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1363 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1366 static char *read_str_index (const struct die_reader_specs
*reader
,
1367 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1369 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1371 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1372 struct dwarf2_cu
*);
1374 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1377 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1378 struct dwarf2_cu
*cu
);
1380 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1382 static struct die_info
*die_specification (struct die_info
*die
,
1383 struct dwarf2_cu
**);
1385 static void free_line_header (struct line_header
*lh
);
1387 static void add_file_name (struct line_header
*, char *, unsigned int,
1388 unsigned int, unsigned int);
1390 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1391 struct dwarf2_cu
*cu
);
1393 static void dwarf_decode_lines (struct line_header
*, const char *,
1394 struct dwarf2_cu
*, struct partial_symtab
*,
1397 static void dwarf2_start_subfile (char *, const char *, const char *);
1399 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1400 char *, char *, CORE_ADDR
);
1402 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1403 struct dwarf2_cu
*);
1405 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1406 struct dwarf2_cu
*, struct symbol
*);
1408 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1409 struct dwarf2_cu
*);
1411 static void dwarf2_const_value_attr (struct attribute
*attr
,
1414 struct obstack
*obstack
,
1415 struct dwarf2_cu
*cu
, LONGEST
*value
,
1417 struct dwarf2_locexpr_baton
**baton
);
1419 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1421 static int need_gnat_info (struct dwarf2_cu
*);
1423 static struct type
*die_descriptive_type (struct die_info
*,
1424 struct dwarf2_cu
*);
1426 static void set_descriptive_type (struct type
*, struct die_info
*,
1427 struct dwarf2_cu
*);
1429 static struct type
*die_containing_type (struct die_info
*,
1430 struct dwarf2_cu
*);
1432 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1433 struct dwarf2_cu
*);
1435 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1437 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1439 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1441 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1442 const char *suffix
, int physname
,
1443 struct dwarf2_cu
*cu
);
1445 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1447 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1449 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1451 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1453 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1455 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1456 struct dwarf2_cu
*, struct partial_symtab
*);
1458 static int dwarf2_get_pc_bounds (struct die_info
*,
1459 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1460 struct partial_symtab
*);
1462 static void get_scope_pc_bounds (struct die_info
*,
1463 CORE_ADDR
*, CORE_ADDR
*,
1464 struct dwarf2_cu
*);
1466 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1467 CORE_ADDR
, struct dwarf2_cu
*);
1469 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1470 struct dwarf2_cu
*);
1472 static void dwarf2_attach_fields_to_type (struct field_info
*,
1473 struct type
*, struct dwarf2_cu
*);
1475 static void dwarf2_add_member_fn (struct field_info
*,
1476 struct die_info
*, struct type
*,
1477 struct dwarf2_cu
*);
1479 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1481 struct dwarf2_cu
*);
1483 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1485 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1487 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1489 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1491 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1493 static struct type
*read_module_type (struct die_info
*die
,
1494 struct dwarf2_cu
*cu
);
1496 static const char *namespace_name (struct die_info
*die
,
1497 int *is_anonymous
, struct dwarf2_cu
*);
1499 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1501 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1503 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1504 struct dwarf2_cu
*);
1506 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1508 gdb_byte
**new_info_ptr
,
1509 struct die_info
*parent
);
1511 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1513 gdb_byte
**new_info_ptr
,
1514 struct die_info
*parent
);
1516 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1517 struct die_info
**, gdb_byte
*, int *, int);
1519 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1520 struct die_info
**, gdb_byte
*, int *);
1522 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1524 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1527 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1529 static const char *dwarf2_full_name (char *name
,
1530 struct die_info
*die
,
1531 struct dwarf2_cu
*cu
);
1533 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1534 struct dwarf2_cu
**);
1536 static const char *dwarf_tag_name (unsigned int);
1538 static const char *dwarf_attr_name (unsigned int);
1540 static const char *dwarf_form_name (unsigned int);
1542 static char *dwarf_bool_name (unsigned int);
1544 static const char *dwarf_type_encoding_name (unsigned int);
1546 static struct die_info
*sibling_die (struct die_info
*);
1548 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1550 static void dump_die_for_error (struct die_info
*);
1552 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1555 /*static*/ void dump_die (struct die_info
*, int max_level
);
1557 static void store_in_ref_table (struct die_info
*,
1558 struct dwarf2_cu
*);
1560 static int is_ref_attr (struct attribute
*);
1562 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1564 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1566 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1568 struct dwarf2_cu
**);
1570 static struct die_info
*follow_die_ref (struct die_info
*,
1572 struct dwarf2_cu
**);
1574 static struct die_info
*follow_die_sig (struct die_info
*,
1576 struct dwarf2_cu
**);
1578 static struct signatured_type
*lookup_signatured_type_at_offset
1579 (struct objfile
*objfile
,
1580 struct dwarf2_section_info
*section
, sect_offset offset
);
1582 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1584 static void read_signatured_type (struct signatured_type
*);
1586 static struct type_unit_group
*get_type_unit_group
1587 (struct dwarf2_cu
*, struct attribute
*);
1589 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1591 /* memory allocation interface */
1593 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1595 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1597 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1600 static int attr_form_is_block (struct attribute
*);
1602 static int attr_form_is_section_offset (struct attribute
*);
1604 static int attr_form_is_constant (struct attribute
*);
1606 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1607 struct dwarf2_loclist_baton
*baton
,
1608 struct attribute
*attr
);
1610 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1612 struct dwarf2_cu
*cu
);
1614 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1616 struct abbrev_info
*abbrev
);
1618 static void free_stack_comp_unit (void *);
1620 static hashval_t
partial_die_hash (const void *item
);
1622 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1624 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1625 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1627 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1628 struct dwarf2_per_cu_data
*per_cu
);
1630 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1631 struct die_info
*comp_unit_die
,
1632 enum language pretend_language
);
1634 static void free_heap_comp_unit (void *);
1636 static void free_cached_comp_units (void *);
1638 static void age_cached_comp_units (void);
1640 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1642 static struct type
*set_die_type (struct die_info
*, struct type
*,
1643 struct dwarf2_cu
*);
1645 static void create_all_comp_units (struct objfile
*);
1647 static int create_all_type_units (struct objfile
*);
1649 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1652 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1655 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1658 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1659 struct dwarf2_per_cu_data
*);
1661 static void dwarf2_mark (struct dwarf2_cu
*);
1663 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1665 static struct type
*get_die_type_at_offset (sect_offset
,
1666 struct dwarf2_per_cu_data
*per_cu
);
1668 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1670 static void dwarf2_release_queue (void *dummy
);
1672 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1673 enum language pretend_language
);
1675 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1676 struct dwarf2_per_cu_data
*per_cu
,
1677 enum language pretend_language
);
1679 static void process_queue (void);
1681 static void find_file_and_directory (struct die_info
*die
,
1682 struct dwarf2_cu
*cu
,
1683 char **name
, char **comp_dir
);
1685 static char *file_full_name (int file
, struct line_header
*lh
,
1686 const char *comp_dir
);
1688 static gdb_byte
*read_and_check_comp_unit_head
1689 (struct comp_unit_head
*header
,
1690 struct dwarf2_section_info
*section
,
1691 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1692 int is_debug_types_section
);
1694 static void init_cutu_and_read_dies
1695 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1696 int use_existing_cu
, int keep
,
1697 die_reader_func_ftype
*die_reader_func
, void *data
);
1699 static void init_cutu_and_read_dies_simple
1700 (struct dwarf2_per_cu_data
*this_cu
,
1701 die_reader_func_ftype
*die_reader_func
, void *data
);
1703 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1705 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1707 static struct dwo_unit
*lookup_dwo_comp_unit
1708 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1710 static struct dwo_unit
*lookup_dwo_type_unit
1711 (struct signatured_type
*, const char *, const char *);
1713 static void free_dwo_file_cleanup (void *);
1715 static void process_cu_includes (void);
1717 static void check_producer (struct dwarf2_cu
*cu
);
1721 /* Convert VALUE between big- and little-endian. */
1723 byte_swap (offset_type value
)
1727 result
= (value
& 0xff) << 24;
1728 result
|= (value
& 0xff00) << 8;
1729 result
|= (value
& 0xff0000) >> 8;
1730 result
|= (value
& 0xff000000) >> 24;
1734 #define MAYBE_SWAP(V) byte_swap (V)
1737 #define MAYBE_SWAP(V) (V)
1738 #endif /* WORDS_BIGENDIAN */
1740 /* The suffix for an index file. */
1741 #define INDEX_SUFFIX ".gdb-index"
1743 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1744 struct dwarf2_cu
*cu
);
1746 /* Try to locate the sections we need for DWARF 2 debugging
1747 information and return true if we have enough to do something.
1748 NAMES points to the dwarf2 section names, or is NULL if the standard
1749 ELF names are used. */
1752 dwarf2_has_info (struct objfile
*objfile
,
1753 const struct dwarf2_debug_sections
*names
)
1755 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1756 if (!dwarf2_per_objfile
)
1758 /* Initialize per-objfile state. */
1759 struct dwarf2_per_objfile
*data
1760 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1762 memset (data
, 0, sizeof (*data
));
1763 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1764 dwarf2_per_objfile
= data
;
1766 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1768 dwarf2_per_objfile
->objfile
= objfile
;
1770 return (dwarf2_per_objfile
->info
.asection
!= NULL
1771 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1774 /* When loading sections, we look either for uncompressed section or for
1775 compressed section names. */
1778 section_is_p (const char *section_name
,
1779 const struct dwarf2_section_names
*names
)
1781 if (names
->normal
!= NULL
1782 && strcmp (section_name
, names
->normal
) == 0)
1784 if (names
->compressed
!= NULL
1785 && strcmp (section_name
, names
->compressed
) == 0)
1790 /* This function is mapped across the sections and remembers the
1791 offset and size of each of the debugging sections we are interested
1795 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1797 const struct dwarf2_debug_sections
*names
;
1798 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1801 names
= &dwarf2_elf_names
;
1803 names
= (const struct dwarf2_debug_sections
*) vnames
;
1805 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1808 else if (section_is_p (sectp
->name
, &names
->info
))
1810 dwarf2_per_objfile
->info
.asection
= sectp
;
1811 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1813 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1815 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1816 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1818 else if (section_is_p (sectp
->name
, &names
->line
))
1820 dwarf2_per_objfile
->line
.asection
= sectp
;
1821 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1823 else if (section_is_p (sectp
->name
, &names
->loc
))
1825 dwarf2_per_objfile
->loc
.asection
= sectp
;
1826 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1828 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1830 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1831 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1833 else if (section_is_p (sectp
->name
, &names
->macro
))
1835 dwarf2_per_objfile
->macro
.asection
= sectp
;
1836 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1838 else if (section_is_p (sectp
->name
, &names
->str
))
1840 dwarf2_per_objfile
->str
.asection
= sectp
;
1841 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1843 else if (section_is_p (sectp
->name
, &names
->addr
))
1845 dwarf2_per_objfile
->addr
.asection
= sectp
;
1846 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1848 else if (section_is_p (sectp
->name
, &names
->frame
))
1850 dwarf2_per_objfile
->frame
.asection
= sectp
;
1851 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1853 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1855 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1856 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1858 else if (section_is_p (sectp
->name
, &names
->ranges
))
1860 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1861 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1863 else if (section_is_p (sectp
->name
, &names
->types
))
1865 struct dwarf2_section_info type_section
;
1867 memset (&type_section
, 0, sizeof (type_section
));
1868 type_section
.asection
= sectp
;
1869 type_section
.size
= bfd_get_section_size (sectp
);
1871 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1874 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1876 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1877 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1880 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1881 && bfd_section_vma (abfd
, sectp
) == 0)
1882 dwarf2_per_objfile
->has_section_at_zero
= 1;
1885 /* A helper function that decides whether a section is empty,
1889 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1891 return info
->asection
== NULL
|| info
->size
== 0;
1894 /* Read the contents of the section INFO.
1895 OBJFILE is the main object file, but not necessarily the file where
1896 the section comes from. E.g., for DWO files INFO->asection->owner
1897 is the bfd of the DWO file.
1898 If the section is compressed, uncompress it before returning. */
1901 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1903 asection
*sectp
= info
->asection
;
1905 gdb_byte
*buf
, *retbuf
;
1906 unsigned char header
[4];
1910 info
->buffer
= NULL
;
1913 if (dwarf2_section_empty_p (info
))
1916 abfd
= sectp
->owner
;
1918 /* If the section has relocations, we must read it ourselves.
1919 Otherwise we attach it to the BFD. */
1920 if ((sectp
->flags
& SEC_RELOC
) == 0)
1922 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1924 /* We have to cast away const here for historical reasons.
1925 Fixing dwarf2read to be const-correct would be quite nice. */
1926 info
->buffer
= (gdb_byte
*) bytes
;
1930 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1933 /* When debugging .o files, we may need to apply relocations; see
1934 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1935 We never compress sections in .o files, so we only need to
1936 try this when the section is not compressed. */
1937 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1940 info
->buffer
= retbuf
;
1944 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1945 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1946 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1947 bfd_get_filename (abfd
));
1950 /* A helper function that returns the size of a section in a safe way.
1951 If you are positive that the section has been read before using the
1952 size, then it is safe to refer to the dwarf2_section_info object's
1953 "size" field directly. In other cases, you must call this
1954 function, because for compressed sections the size field is not set
1955 correctly until the section has been read. */
1957 static bfd_size_type
1958 dwarf2_section_size (struct objfile
*objfile
,
1959 struct dwarf2_section_info
*info
)
1962 dwarf2_read_section (objfile
, info
);
1966 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1970 dwarf2_get_section_info (struct objfile
*objfile
,
1971 enum dwarf2_section_enum sect
,
1972 asection
**sectp
, gdb_byte
**bufp
,
1973 bfd_size_type
*sizep
)
1975 struct dwarf2_per_objfile
*data
1976 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1977 struct dwarf2_section_info
*info
;
1979 /* We may see an objfile without any DWARF, in which case we just
1990 case DWARF2_DEBUG_FRAME
:
1991 info
= &data
->frame
;
1993 case DWARF2_EH_FRAME
:
1994 info
= &data
->eh_frame
;
1997 gdb_assert_not_reached ("unexpected section");
2000 dwarf2_read_section (objfile
, info
);
2002 *sectp
= info
->asection
;
2003 *bufp
= info
->buffer
;
2004 *sizep
= info
->size
;
2007 /* A helper function to find the sections for a .dwz file. */
2010 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2012 struct dwz_file
*dwz_file
= arg
;
2014 /* Note that we only support the standard ELF names, because .dwz
2015 is ELF-only (at the time of writing). */
2016 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2018 dwz_file
->abbrev
.asection
= sectp
;
2019 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2021 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2023 dwz_file
->info
.asection
= sectp
;
2024 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2026 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2028 dwz_file
->str
.asection
= sectp
;
2029 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2031 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2033 dwz_file
->line
.asection
= sectp
;
2034 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2036 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2038 dwz_file
->macro
.asection
= sectp
;
2039 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2041 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2043 dwz_file
->gdb_index
.asection
= sectp
;
2044 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2048 /* Open the separate '.dwz' debug file, if needed. Error if the file
2051 static struct dwz_file
*
2052 dwarf2_get_dwz_file (void)
2054 bfd
*abfd
, *dwz_bfd
;
2057 struct cleanup
*cleanup
;
2058 const char *filename
;
2059 struct dwz_file
*result
;
2061 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2062 return dwarf2_per_objfile
->dwz_file
;
2064 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2065 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2066 if (section
== NULL
)
2067 error (_("could not find '.gnu_debugaltlink' section"));
2068 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2069 error (_("could not read '.gnu_debugaltlink' section: %s"),
2070 bfd_errmsg (bfd_get_error ()));
2071 cleanup
= make_cleanup (xfree
, data
);
2074 if (!IS_ABSOLUTE_PATH (filename
))
2076 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2079 make_cleanup (xfree
, abs
);
2080 abs
= ldirname (abs
);
2081 make_cleanup (xfree
, abs
);
2083 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2084 make_cleanup (xfree
, rel
);
2088 /* The format is just a NUL-terminated file name, followed by the
2089 build-id. For now, though, we ignore the build-id. */
2090 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2091 if (dwz_bfd
== NULL
)
2092 error (_("could not read '%s': %s"), filename
,
2093 bfd_errmsg (bfd_get_error ()));
2095 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2097 gdb_bfd_unref (dwz_bfd
);
2098 error (_("file '%s' was not usable: %s"), filename
,
2099 bfd_errmsg (bfd_get_error ()));
2102 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2104 result
->dwz_bfd
= dwz_bfd
;
2106 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2108 do_cleanups (cleanup
);
2113 /* DWARF quick_symbols_functions support. */
2115 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2116 unique line tables, so we maintain a separate table of all .debug_line
2117 derived entries to support the sharing.
2118 All the quick functions need is the list of file names. We discard the
2119 line_header when we're done and don't need to record it here. */
2120 struct quick_file_names
2122 /* The data used to construct the hash key. */
2123 struct stmt_list_hash hash
;
2125 /* The number of entries in file_names, real_names. */
2126 unsigned int num_file_names
;
2128 /* The file names from the line table, after being run through
2130 const char **file_names
;
2132 /* The file names from the line table after being run through
2133 gdb_realpath. These are computed lazily. */
2134 const char **real_names
;
2137 /* When using the index (and thus not using psymtabs), each CU has an
2138 object of this type. This is used to hold information needed by
2139 the various "quick" methods. */
2140 struct dwarf2_per_cu_quick_data
2142 /* The file table. This can be NULL if there was no file table
2143 or it's currently not read in.
2144 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2145 struct quick_file_names
*file_names
;
2147 /* The corresponding symbol table. This is NULL if symbols for this
2148 CU have not yet been read. */
2149 struct symtab
*symtab
;
2151 /* A temporary mark bit used when iterating over all CUs in
2152 expand_symtabs_matching. */
2153 unsigned int mark
: 1;
2155 /* True if we've tried to read the file table and found there isn't one.
2156 There will be no point in trying to read it again next time. */
2157 unsigned int no_file_data
: 1;
2160 /* Utility hash function for a stmt_list_hash. */
2163 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2167 if (stmt_list_hash
->dwo_unit
!= NULL
)
2168 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2169 v
+= stmt_list_hash
->line_offset
.sect_off
;
2173 /* Utility equality function for a stmt_list_hash. */
2176 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2177 const struct stmt_list_hash
*rhs
)
2179 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2181 if (lhs
->dwo_unit
!= NULL
2182 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2185 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2188 /* Hash function for a quick_file_names. */
2191 hash_file_name_entry (const void *e
)
2193 const struct quick_file_names
*file_data
= e
;
2195 return hash_stmt_list_entry (&file_data
->hash
);
2198 /* Equality function for a quick_file_names. */
2201 eq_file_name_entry (const void *a
, const void *b
)
2203 const struct quick_file_names
*ea
= a
;
2204 const struct quick_file_names
*eb
= b
;
2206 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2209 /* Delete function for a quick_file_names. */
2212 delete_file_name_entry (void *e
)
2214 struct quick_file_names
*file_data
= e
;
2217 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2219 xfree ((void*) file_data
->file_names
[i
]);
2220 if (file_data
->real_names
)
2221 xfree ((void*) file_data
->real_names
[i
]);
2224 /* The space for the struct itself lives on objfile_obstack,
2225 so we don't free it here. */
2228 /* Create a quick_file_names hash table. */
2231 create_quick_file_names_table (unsigned int nr_initial_entries
)
2233 return htab_create_alloc (nr_initial_entries
,
2234 hash_file_name_entry
, eq_file_name_entry
,
2235 delete_file_name_entry
, xcalloc
, xfree
);
2238 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2239 have to be created afterwards. You should call age_cached_comp_units after
2240 processing PER_CU->CU. dw2_setup must have been already called. */
2243 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2245 if (per_cu
->is_debug_types
)
2246 load_full_type_unit (per_cu
);
2248 load_full_comp_unit (per_cu
, language_minimal
);
2250 gdb_assert (per_cu
->cu
!= NULL
);
2252 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2255 /* Read in the symbols for PER_CU. */
2258 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2260 struct cleanup
*back_to
;
2262 /* Skip type_unit_groups, reading the type units they contain
2263 is handled elsewhere. */
2264 if (IS_TYPE_UNIT_GROUP (per_cu
))
2267 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2269 if (dwarf2_per_objfile
->using_index
2270 ? per_cu
->v
.quick
->symtab
== NULL
2271 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2273 queue_comp_unit (per_cu
, language_minimal
);
2279 /* Age the cache, releasing compilation units that have not
2280 been used recently. */
2281 age_cached_comp_units ();
2283 do_cleanups (back_to
);
2286 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2287 the objfile from which this CU came. Returns the resulting symbol
2290 static struct symtab
*
2291 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2293 gdb_assert (dwarf2_per_objfile
->using_index
);
2294 if (!per_cu
->v
.quick
->symtab
)
2296 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2297 increment_reading_symtab ();
2298 dw2_do_instantiate_symtab (per_cu
);
2299 process_cu_includes ();
2300 do_cleanups (back_to
);
2302 return per_cu
->v
.quick
->symtab
;
2305 /* Return the CU given its index.
2307 This is intended for loops like:
2309 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2310 + dwarf2_per_objfile->n_type_units); ++i)
2312 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2318 static struct dwarf2_per_cu_data
*
2319 dw2_get_cu (int index
)
2321 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2323 index
-= dwarf2_per_objfile
->n_comp_units
;
2324 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2325 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2328 return dwarf2_per_objfile
->all_comp_units
[index
];
2331 /* Return the primary CU given its index.
2332 The difference between this function and dw2_get_cu is in the handling
2333 of type units (TUs). Here we return the type_unit_group object.
2335 This is intended for loops like:
2337 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2338 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2340 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2346 static struct dwarf2_per_cu_data
*
2347 dw2_get_primary_cu (int index
)
2349 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2351 index
-= dwarf2_per_objfile
->n_comp_units
;
2352 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2353 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2356 return dwarf2_per_objfile
->all_comp_units
[index
];
2359 /* A helper function that knows how to read a 64-bit value in a way
2360 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2364 extract_cu_value (const char *bytes
, ULONGEST
*result
)
2366 if (sizeof (ULONGEST
) < 8)
2370 /* Ignore the upper 4 bytes if they are all zero. */
2371 for (i
= 0; i
< 4; ++i
)
2372 if (bytes
[i
+ 4] != 0)
2375 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
2378 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2382 /* A helper for create_cus_from_index that handles a given list of
2386 create_cus_from_index_list (struct objfile
*objfile
,
2387 const gdb_byte
*cu_list
, offset_type n_elements
,
2388 struct dwarf2_section_info
*section
,
2394 for (i
= 0; i
< n_elements
; i
+= 2)
2396 struct dwarf2_per_cu_data
*the_cu
;
2397 ULONGEST offset
, length
;
2399 if (!extract_cu_value (cu_list
, &offset
)
2400 || !extract_cu_value (cu_list
+ 8, &length
))
2404 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2405 struct dwarf2_per_cu_data
);
2406 the_cu
->offset
.sect_off
= offset
;
2407 the_cu
->length
= length
;
2408 the_cu
->objfile
= objfile
;
2409 the_cu
->info_or_types_section
= section
;
2410 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2411 struct dwarf2_per_cu_quick_data
);
2412 the_cu
->is_dwz
= is_dwz
;
2413 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2419 /* Read the CU list from the mapped index, and use it to create all
2420 the CU objects for this objfile. Return 0 if something went wrong,
2421 1 if everything went ok. */
2424 create_cus_from_index (struct objfile
*objfile
,
2425 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2426 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2428 struct dwz_file
*dwz
;
2430 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2431 dwarf2_per_objfile
->all_comp_units
2432 = obstack_alloc (&objfile
->objfile_obstack
,
2433 dwarf2_per_objfile
->n_comp_units
2434 * sizeof (struct dwarf2_per_cu_data
*));
2436 if (!create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2437 &dwarf2_per_objfile
->info
, 0, 0))
2440 if (dwz_elements
== 0)
2443 dwz
= dwarf2_get_dwz_file ();
2444 return create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
,
2445 &dwz
->info
, 1, cu_list_elements
/ 2);
2448 /* Create the signatured type hash table from the index. */
2451 create_signatured_type_table_from_index (struct objfile
*objfile
,
2452 struct dwarf2_section_info
*section
,
2453 const gdb_byte
*bytes
,
2454 offset_type elements
)
2457 htab_t sig_types_hash
;
2459 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2460 dwarf2_per_objfile
->all_type_units
2461 = obstack_alloc (&objfile
->objfile_obstack
,
2462 dwarf2_per_objfile
->n_type_units
2463 * sizeof (struct signatured_type
*));
2465 sig_types_hash
= allocate_signatured_type_table (objfile
);
2467 for (i
= 0; i
< elements
; i
+= 3)
2469 struct signatured_type
*sig_type
;
2470 ULONGEST offset
, type_offset_in_tu
, signature
;
2473 if (!extract_cu_value (bytes
, &offset
)
2474 || !extract_cu_value (bytes
+ 8, &type_offset_in_tu
))
2476 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2479 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2480 struct signatured_type
);
2481 sig_type
->signature
= signature
;
2482 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2483 sig_type
->per_cu
.is_debug_types
= 1;
2484 sig_type
->per_cu
.info_or_types_section
= section
;
2485 sig_type
->per_cu
.offset
.sect_off
= offset
;
2486 sig_type
->per_cu
.objfile
= objfile
;
2487 sig_type
->per_cu
.v
.quick
2488 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2489 struct dwarf2_per_cu_quick_data
);
2491 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2494 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2497 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2502 /* Read the address map data from the mapped index, and use it to
2503 populate the objfile's psymtabs_addrmap. */
2506 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2508 const gdb_byte
*iter
, *end
;
2509 struct obstack temp_obstack
;
2510 struct addrmap
*mutable_map
;
2511 struct cleanup
*cleanup
;
2514 obstack_init (&temp_obstack
);
2515 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2516 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2518 iter
= index
->address_table
;
2519 end
= iter
+ index
->address_table_size
;
2521 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2525 ULONGEST hi
, lo
, cu_index
;
2526 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2528 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2530 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2533 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2534 dw2_get_cu (cu_index
));
2537 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2538 &objfile
->objfile_obstack
);
2539 do_cleanups (cleanup
);
2542 /* The hash function for strings in the mapped index. This is the same as
2543 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2544 implementation. This is necessary because the hash function is tied to the
2545 format of the mapped index file. The hash values do not have to match with
2548 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2551 mapped_index_string_hash (int index_version
, const void *p
)
2553 const unsigned char *str
= (const unsigned char *) p
;
2557 while ((c
= *str
++) != 0)
2559 if (index_version
>= 5)
2561 r
= r
* 67 + c
- 113;
2567 /* Find a slot in the mapped index INDEX for the object named NAME.
2568 If NAME is found, set *VEC_OUT to point to the CU vector in the
2569 constant pool and return 1. If NAME cannot be found, return 0. */
2572 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2573 offset_type
**vec_out
)
2575 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2577 offset_type slot
, step
;
2578 int (*cmp
) (const char *, const char *);
2580 if (current_language
->la_language
== language_cplus
2581 || current_language
->la_language
== language_java
2582 || current_language
->la_language
== language_fortran
)
2584 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2586 const char *paren
= strchr (name
, '(');
2592 dup
= xmalloc (paren
- name
+ 1);
2593 memcpy (dup
, name
, paren
- name
);
2594 dup
[paren
- name
] = 0;
2596 make_cleanup (xfree
, dup
);
2601 /* Index version 4 did not support case insensitive searches. But the
2602 indices for case insensitive languages are built in lowercase, therefore
2603 simulate our NAME being searched is also lowercased. */
2604 hash
= mapped_index_string_hash ((index
->version
== 4
2605 && case_sensitivity
== case_sensitive_off
2606 ? 5 : index
->version
),
2609 slot
= hash
& (index
->symbol_table_slots
- 1);
2610 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2611 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2615 /* Convert a slot number to an offset into the table. */
2616 offset_type i
= 2 * slot
;
2618 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2620 do_cleanups (back_to
);
2624 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2625 if (!cmp (name
, str
))
2627 *vec_out
= (offset_type
*) (index
->constant_pool
2628 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2629 do_cleanups (back_to
);
2633 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2637 /* A helper function that reads the .gdb_index from SECTION and fills
2638 in MAP. FILENAME is the name of the file containing the section;
2639 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2640 ok to use deprecated sections.
2642 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2643 out parameters that are filled in with information about the CU and
2644 TU lists in the section.
2646 Returns 1 if all went well, 0 otherwise. */
2649 read_index_from_section (struct objfile
*objfile
,
2650 const char *filename
,
2652 struct dwarf2_section_info
*section
,
2653 struct mapped_index
*map
,
2654 const gdb_byte
**cu_list
,
2655 offset_type
*cu_list_elements
,
2656 const gdb_byte
**types_list
,
2657 offset_type
*types_list_elements
)
2660 offset_type version
;
2661 offset_type
*metadata
;
2664 if (dwarf2_section_empty_p (section
))
2667 /* Older elfutils strip versions could keep the section in the main
2668 executable while splitting it for the separate debug info file. */
2669 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2672 dwarf2_read_section (objfile
, section
);
2674 addr
= section
->buffer
;
2675 /* Version check. */
2676 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2677 /* Versions earlier than 3 emitted every copy of a psymbol. This
2678 causes the index to behave very poorly for certain requests. Version 3
2679 contained incomplete addrmap. So, it seems better to just ignore such
2683 static int warning_printed
= 0;
2684 if (!warning_printed
)
2686 warning (_("Skipping obsolete .gdb_index section in %s."),
2688 warning_printed
= 1;
2692 /* Index version 4 uses a different hash function than index version
2695 Versions earlier than 6 did not emit psymbols for inlined
2696 functions. Using these files will cause GDB not to be able to
2697 set breakpoints on inlined functions by name, so we ignore these
2698 indices unless the user has done
2699 "set use-deprecated-index-sections on". */
2700 if (version
< 6 && !deprecated_ok
)
2702 static int warning_printed
= 0;
2703 if (!warning_printed
)
2706 Skipping deprecated .gdb_index section in %s.\n\
2707 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2708 to use the section anyway."),
2710 warning_printed
= 1;
2714 /* Indexes with higher version than the one supported by GDB may be no
2715 longer backward compatible. */
2719 map
->version
= version
;
2720 map
->total_size
= section
->size
;
2722 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2725 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2726 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2730 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2731 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2732 - MAYBE_SWAP (metadata
[i
]))
2736 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2737 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2738 - MAYBE_SWAP (metadata
[i
]));
2741 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2742 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2743 - MAYBE_SWAP (metadata
[i
]))
2744 / (2 * sizeof (offset_type
)));
2747 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2753 /* Read the index file. If everything went ok, initialize the "quick"
2754 elements of all the CUs and return 1. Otherwise, return 0. */
2757 dwarf2_read_index (struct objfile
*objfile
)
2759 struct mapped_index local_map
, *map
;
2760 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2761 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2763 if (!read_index_from_section (objfile
, objfile
->name
,
2764 use_deprecated_index_sections
,
2765 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2766 &cu_list
, &cu_list_elements
,
2767 &types_list
, &types_list_elements
))
2770 /* Don't use the index if it's empty. */
2771 if (local_map
.symbol_table_slots
== 0)
2774 /* If there is a .dwz file, read it so we can get its CU list as
2776 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2778 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2779 struct mapped_index dwz_map
;
2780 const gdb_byte
*dwz_types_ignore
;
2781 offset_type dwz_types_elements_ignore
;
2783 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2785 &dwz
->gdb_index
, &dwz_map
,
2786 &dwz_list
, &dwz_list_elements
,
2788 &dwz_types_elements_ignore
))
2790 warning (_("could not read '.gdb_index' section from %s; skipping"),
2791 bfd_get_filename (dwz
->dwz_bfd
));
2796 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
,
2797 dwz_list
, dwz_list_elements
))
2800 if (types_list_elements
)
2802 struct dwarf2_section_info
*section
;
2804 /* We can only handle a single .debug_types when we have an
2806 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2809 section
= VEC_index (dwarf2_section_info_def
,
2810 dwarf2_per_objfile
->types
, 0);
2812 if (!create_signatured_type_table_from_index (objfile
, section
,
2814 types_list_elements
))
2818 create_addrmap_from_index (objfile
, &local_map
);
2820 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2823 dwarf2_per_objfile
->index_table
= map
;
2824 dwarf2_per_objfile
->using_index
= 1;
2825 dwarf2_per_objfile
->quick_file_names_table
=
2826 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2831 /* A helper for the "quick" functions which sets the global
2832 dwarf2_per_objfile according to OBJFILE. */
2835 dw2_setup (struct objfile
*objfile
)
2837 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2838 gdb_assert (dwarf2_per_objfile
);
2841 /* Reader function for dw2_build_type_unit_groups. */
2844 dw2_build_type_unit_groups_reader (const struct die_reader_specs
*reader
,
2846 struct die_info
*type_unit_die
,
2850 struct dwarf2_cu
*cu
= reader
->cu
;
2851 struct attribute
*attr
;
2852 struct type_unit_group
*tu_group
;
2854 gdb_assert (data
== NULL
);
2859 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
2860 /* Call this for its side-effect of creating the associated
2861 struct type_unit_group if it doesn't already exist. */
2862 tu_group
= get_type_unit_group (cu
, attr
);
2865 /* Build dwarf2_per_objfile->type_unit_groups.
2866 This function may be called multiple times. */
2869 dw2_build_type_unit_groups (void)
2871 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
2872 build_type_unit_groups (dw2_build_type_unit_groups_reader
, NULL
);
2875 /* die_reader_func for dw2_get_file_names. */
2878 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2880 struct die_info
*comp_unit_die
,
2884 struct dwarf2_cu
*cu
= reader
->cu
;
2885 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2886 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2887 struct dwarf2_per_cu_data
*lh_cu
;
2888 struct line_header
*lh
;
2889 struct attribute
*attr
;
2891 char *name
, *comp_dir
;
2893 struct quick_file_names
*qfn
;
2894 unsigned int line_offset
;
2896 /* Our callers never want to match partial units -- instead they
2897 will match the enclosing full CU. */
2898 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2900 this_cu
->v
.quick
->no_file_data
= 1;
2904 /* If we're reading the line header for TUs, store it in the "per_cu"
2906 if (this_cu
->is_debug_types
)
2908 struct type_unit_group
*tu_group
= data
;
2910 gdb_assert (tu_group
!= NULL
);
2911 lh_cu
= &tu_group
->per_cu
;
2920 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2923 struct quick_file_names find_entry
;
2925 line_offset
= DW_UNSND (attr
);
2927 /* We may have already read in this line header (TU line header sharing).
2928 If we have we're done. */
2929 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2930 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2931 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2932 &find_entry
, INSERT
);
2935 lh_cu
->v
.quick
->file_names
= *slot
;
2939 lh
= dwarf_decode_line_header (line_offset
, cu
);
2943 lh_cu
->v
.quick
->no_file_data
= 1;
2947 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2948 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2949 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2950 gdb_assert (slot
!= NULL
);
2953 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2955 qfn
->num_file_names
= lh
->num_file_names
;
2956 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2957 lh
->num_file_names
* sizeof (char *));
2958 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2959 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2960 qfn
->real_names
= NULL
;
2962 free_line_header (lh
);
2964 lh_cu
->v
.quick
->file_names
= qfn
;
2967 /* A helper for the "quick" functions which attempts to read the line
2968 table for THIS_CU. */
2970 static struct quick_file_names
*
2971 dw2_get_file_names (struct objfile
*objfile
,
2972 struct dwarf2_per_cu_data
*this_cu
)
2974 /* For TUs this should only be called on the parent group. */
2975 if (this_cu
->is_debug_types
)
2976 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2978 if (this_cu
->v
.quick
->file_names
!= NULL
)
2979 return this_cu
->v
.quick
->file_names
;
2980 /* If we know there is no line data, no point in looking again. */
2981 if (this_cu
->v
.quick
->no_file_data
)
2984 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2985 in the stub for CUs, there's is no need to lookup the DWO file.
2986 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2988 if (this_cu
->is_debug_types
)
2990 struct type_unit_group
*tu_group
= this_cu
->s
.type_unit_group
;
2992 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2993 dw2_get_file_names_reader
, tu_group
);
2996 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2998 if (this_cu
->v
.quick
->no_file_data
)
3000 return this_cu
->v
.quick
->file_names
;
3003 /* A helper for the "quick" functions which computes and caches the
3004 real path for a given file name from the line table. */
3007 dw2_get_real_path (struct objfile
*objfile
,
3008 struct quick_file_names
*qfn
, int index
)
3010 if (qfn
->real_names
== NULL
)
3011 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3012 qfn
->num_file_names
, sizeof (char *));
3014 if (qfn
->real_names
[index
] == NULL
)
3015 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
3017 return qfn
->real_names
[index
];
3020 static struct symtab
*
3021 dw2_find_last_source_symtab (struct objfile
*objfile
)
3025 dw2_setup (objfile
);
3026 index
= dwarf2_per_objfile
->n_comp_units
- 1;
3027 return dw2_instantiate_symtab (dw2_get_cu (index
));
3030 /* Traversal function for dw2_forget_cached_source_info. */
3033 dw2_free_cached_file_names (void **slot
, void *info
)
3035 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3037 if (file_data
->real_names
)
3041 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3043 xfree ((void*) file_data
->real_names
[i
]);
3044 file_data
->real_names
[i
] = NULL
;
3052 dw2_forget_cached_source_info (struct objfile
*objfile
)
3054 dw2_setup (objfile
);
3056 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3057 dw2_free_cached_file_names
, NULL
);
3060 /* Helper function for dw2_map_symtabs_matching_filename that expands
3061 the symtabs and calls the iterator. */
3064 dw2_map_expand_apply (struct objfile
*objfile
,
3065 struct dwarf2_per_cu_data
*per_cu
,
3067 const char *full_path
, const char *real_path
,
3068 int (*callback
) (struct symtab
*, void *),
3071 struct symtab
*last_made
= objfile
->symtabs
;
3073 /* Don't visit already-expanded CUs. */
3074 if (per_cu
->v
.quick
->symtab
)
3077 /* This may expand more than one symtab, and we want to iterate over
3079 dw2_instantiate_symtab (per_cu
);
3081 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3082 objfile
->symtabs
, last_made
);
3085 /* Implementation of the map_symtabs_matching_filename method. */
3088 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3089 const char *full_path
, const char *real_path
,
3090 int (*callback
) (struct symtab
*, void *),
3094 const char *name_basename
= lbasename (name
);
3095 int name_len
= strlen (name
);
3096 int is_abs
= IS_ABSOLUTE_PATH (name
);
3098 dw2_setup (objfile
);
3100 dw2_build_type_unit_groups ();
3102 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3103 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3106 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3107 struct quick_file_names
*file_data
;
3109 /* We only need to look at symtabs not already expanded. */
3110 if (per_cu
->v
.quick
->symtab
)
3113 file_data
= dw2_get_file_names (objfile
, per_cu
);
3114 if (file_data
== NULL
)
3117 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3119 const char *this_name
= file_data
->file_names
[j
];
3121 if (FILENAME_CMP (name
, this_name
) == 0
3122 || (!is_abs
&& compare_filenames_for_search (this_name
,
3125 if (dw2_map_expand_apply (objfile
, per_cu
,
3126 name
, full_path
, real_path
,
3131 /* Before we invoke realpath, which can get expensive when many
3132 files are involved, do a quick comparison of the basenames. */
3133 if (! basenames_may_differ
3134 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3137 if (full_path
!= NULL
)
3139 const char *this_real_name
= dw2_get_real_path (objfile
,
3142 if (this_real_name
!= NULL
3143 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3145 && compare_filenames_for_search (this_real_name
,
3148 if (dw2_map_expand_apply (objfile
, per_cu
,
3149 name
, full_path
, real_path
,
3155 if (real_path
!= NULL
)
3157 const char *this_real_name
= dw2_get_real_path (objfile
,
3160 if (this_real_name
!= NULL
3161 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3163 && compare_filenames_for_search (this_real_name
,
3166 if (dw2_map_expand_apply (objfile
, per_cu
,
3167 name
, full_path
, real_path
,
3178 static struct symtab
*
3179 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3180 const char *name
, domain_enum domain
)
3182 /* We do all the work in the pre_expand_symtabs_matching hook
3187 /* A helper function that expands all symtabs that hold an object
3188 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3189 symbols in block BLOCK_KIND. */
3192 dw2_do_expand_symtabs_matching (struct objfile
*objfile
,
3193 int want_specific_block
,
3194 enum block_enum block_kind
,
3195 const char *name
, domain_enum domain
)
3197 struct mapped_index
*index
;
3199 dw2_setup (objfile
);
3201 index
= dwarf2_per_objfile
->index_table
;
3203 /* index_table is NULL if OBJF_READNOW. */
3208 if (find_slot_in_mapped_hash (index
, name
, &vec
))
3210 offset_type i
, len
= MAYBE_SWAP (*vec
);
3211 for (i
= 0; i
< len
; ++i
)
3213 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[i
+ 1]);
3214 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3215 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3216 int want_static
= block_kind
!= GLOBAL_BLOCK
;
3217 /* This value is only valid for index versions >= 7. */
3218 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3219 gdb_index_symbol_kind symbol_kind
=
3220 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3221 /* Only check the symbol attributes if they're present.
3222 Indices prior to version 7 don't record them,
3223 and indices >= 7 may elide them for certain symbols
3224 (gold does this). */
3226 (index
->version
>= 7
3227 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3230 && want_specific_block
3231 && want_static
!= is_static
)
3234 /* Only check the symbol's kind if it has one. */
3240 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3241 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3242 /* Some types are also in VAR_DOMAIN. */
3243 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3247 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3251 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3259 dw2_instantiate_symtab (per_cu
);
3266 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
3267 enum block_enum block_kind
, const char *name
,
3270 dw2_do_expand_symtabs_matching (objfile
, 1, block_kind
, name
, domain
);
3274 dw2_print_stats (struct objfile
*objfile
)
3278 dw2_setup (objfile
);
3280 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3281 + dwarf2_per_objfile
->n_type_units
); ++i
)
3283 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3285 if (!per_cu
->v
.quick
->symtab
)
3288 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3292 dw2_dump (struct objfile
*objfile
)
3294 /* Nothing worth printing. */
3298 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3299 struct section_offsets
*delta
)
3301 /* There's nothing to relocate here. */
3305 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3306 const char *func_name
)
3308 /* Note: It doesn't matter what we pass for block_kind here. */
3309 dw2_do_expand_symtabs_matching (objfile
, 0, GLOBAL_BLOCK
, func_name
,
3314 dw2_expand_all_symtabs (struct objfile
*objfile
)
3318 dw2_setup (objfile
);
3320 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3321 + dwarf2_per_objfile
->n_type_units
); ++i
)
3323 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3325 dw2_instantiate_symtab (per_cu
);
3330 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3331 const char *filename
)
3335 dw2_setup (objfile
);
3337 /* We don't need to consider type units here.
3338 This is only called for examining code, e.g. expand_line_sal.
3339 There can be an order of magnitude (or more) more type units
3340 than comp units, and we avoid them if we can. */
3342 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3345 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3346 struct quick_file_names
*file_data
;
3348 /* We only need to look at symtabs not already expanded. */
3349 if (per_cu
->v
.quick
->symtab
)
3352 file_data
= dw2_get_file_names (objfile
, per_cu
);
3353 if (file_data
== NULL
)
3356 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3358 const char *this_name
= file_data
->file_names
[j
];
3359 if (FILENAME_CMP (this_name
, filename
) == 0)
3361 dw2_instantiate_symtab (per_cu
);
3368 /* A helper function for dw2_find_symbol_file that finds the primary
3369 file name for a given CU. This is a die_reader_func. */
3372 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3374 struct die_info
*comp_unit_die
,
3378 const char **result_ptr
= data
;
3379 struct dwarf2_cu
*cu
= reader
->cu
;
3380 struct attribute
*attr
;
3382 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3386 *result_ptr
= DW_STRING (attr
);
3390 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3392 struct dwarf2_per_cu_data
*per_cu
;
3394 const char *filename
;
3396 dw2_setup (objfile
);
3398 /* index_table is NULL if OBJF_READNOW. */
3399 if (!dwarf2_per_objfile
->index_table
)
3403 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3405 struct blockvector
*bv
= BLOCKVECTOR (s
);
3406 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3407 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3410 return SYMBOL_SYMTAB (sym
)->filename
;
3415 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3419 /* Note that this just looks at the very first one named NAME -- but
3420 actually we are looking for a function. find_main_filename
3421 should be rewritten so that it doesn't require a custom hook. It
3422 could just use the ordinary symbol tables. */
3423 /* vec[0] is the length, which must always be >0. */
3424 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3426 if (per_cu
->v
.quick
->symtab
!= NULL
)
3427 return per_cu
->v
.quick
->symtab
->filename
;
3429 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3430 dw2_get_primary_filename_reader
, &filename
);
3436 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3437 struct objfile
*objfile
, int global
,
3438 int (*callback
) (struct block
*,
3439 struct symbol
*, void *),
3440 void *data
, symbol_compare_ftype
*match
,
3441 symbol_compare_ftype
*ordered_compare
)
3443 /* Currently unimplemented; used for Ada. The function can be called if the
3444 current language is Ada for a non-Ada objfile using GNU index. As Ada
3445 does not look for non-Ada symbols this function should just return. */
3449 dw2_expand_symtabs_matching
3450 (struct objfile
*objfile
,
3451 int (*file_matcher
) (const char *, void *),
3452 int (*name_matcher
) (const char *, void *),
3453 enum search_domain kind
,
3458 struct mapped_index
*index
;
3460 dw2_setup (objfile
);
3462 /* index_table is NULL if OBJF_READNOW. */
3463 if (!dwarf2_per_objfile
->index_table
)
3465 index
= dwarf2_per_objfile
->index_table
;
3467 if (file_matcher
!= NULL
)
3469 struct cleanup
*cleanup
;
3470 htab_t visited_found
, visited_not_found
;
3472 dw2_build_type_unit_groups ();
3474 visited_found
= htab_create_alloc (10,
3475 htab_hash_pointer
, htab_eq_pointer
,
3476 NULL
, xcalloc
, xfree
);
3477 cleanup
= make_cleanup_htab_delete (visited_found
);
3478 visited_not_found
= htab_create_alloc (10,
3479 htab_hash_pointer
, htab_eq_pointer
,
3480 NULL
, xcalloc
, xfree
);
3481 make_cleanup_htab_delete (visited_not_found
);
3483 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3484 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3487 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3488 struct quick_file_names
*file_data
;
3491 per_cu
->v
.quick
->mark
= 0;
3493 /* We only need to look at symtabs not already expanded. */
3494 if (per_cu
->v
.quick
->symtab
)
3497 file_data
= dw2_get_file_names (objfile
, per_cu
);
3498 if (file_data
== NULL
)
3501 if (htab_find (visited_not_found
, file_data
) != NULL
)
3503 else if (htab_find (visited_found
, file_data
) != NULL
)
3505 per_cu
->v
.quick
->mark
= 1;
3509 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3511 if (file_matcher (file_data
->file_names
[j
], data
))
3513 per_cu
->v
.quick
->mark
= 1;
3518 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3520 : visited_not_found
,
3525 do_cleanups (cleanup
);
3528 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3530 offset_type idx
= 2 * iter
;
3532 offset_type
*vec
, vec_len
, vec_idx
;
3534 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3537 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3539 if (! (*name_matcher
) (name
, data
))
3542 /* The name was matched, now expand corresponding CUs that were
3544 vec
= (offset_type
*) (index
->constant_pool
3545 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3546 vec_len
= MAYBE_SWAP (vec
[0]);
3547 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3549 struct dwarf2_per_cu_data
*per_cu
;
3550 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3551 gdb_index_symbol_kind symbol_kind
=
3552 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3553 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3555 /* Don't crash on bad data. */
3556 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3557 + dwarf2_per_objfile
->n_type_units
))
3560 /* Only check the symbol's kind if it has one.
3561 Indices prior to version 7 don't record it. */
3562 if (index
->version
>= 7)
3566 case VARIABLES_DOMAIN
:
3567 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3570 case FUNCTIONS_DOMAIN
:
3571 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3575 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3583 per_cu
= dw2_get_cu (cu_index
);
3584 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3585 dw2_instantiate_symtab (per_cu
);
3590 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3593 static struct symtab
*
3594 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3598 if (BLOCKVECTOR (symtab
) != NULL
3599 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3602 if (symtab
->includes
== NULL
)
3605 for (i
= 0; symtab
->includes
[i
]; ++i
)
3607 struct symtab
*s
= symtab
->includes
[i
];
3609 s
= recursively_find_pc_sect_symtab (s
, pc
);
3617 static struct symtab
*
3618 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3619 struct minimal_symbol
*msymbol
,
3621 struct obj_section
*section
,
3624 struct dwarf2_per_cu_data
*data
;
3625 struct symtab
*result
;
3627 dw2_setup (objfile
);
3629 if (!objfile
->psymtabs_addrmap
)
3632 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3636 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3637 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3638 paddress (get_objfile_arch (objfile
), pc
));
3640 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3641 gdb_assert (result
!= NULL
);
3646 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3647 void *data
, int need_fullname
)
3650 struct cleanup
*cleanup
;
3651 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3652 NULL
, xcalloc
, xfree
);
3654 cleanup
= make_cleanup_htab_delete (visited
);
3655 dw2_setup (objfile
);
3657 dw2_build_type_unit_groups ();
3659 /* We can ignore file names coming from already-expanded CUs. */
3660 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3661 + dwarf2_per_objfile
->n_type_units
); ++i
)
3663 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3665 if (per_cu
->v
.quick
->symtab
)
3667 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3670 *slot
= per_cu
->v
.quick
->file_names
;
3674 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3675 + dwarf2_per_objfile
->n_type_unit_groups
); ++i
)
3678 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3679 struct quick_file_names
*file_data
;
3682 /* We only need to look at symtabs not already expanded. */
3683 if (per_cu
->v
.quick
->symtab
)
3686 file_data
= dw2_get_file_names (objfile
, per_cu
);
3687 if (file_data
== NULL
)
3690 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3693 /* Already visited. */
3698 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3700 const char *this_real_name
;
3703 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3705 this_real_name
= NULL
;
3706 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3710 do_cleanups (cleanup
);
3714 dw2_has_symbols (struct objfile
*objfile
)
3719 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3722 dw2_find_last_source_symtab
,
3723 dw2_forget_cached_source_info
,
3724 dw2_map_symtabs_matching_filename
,
3726 dw2_pre_expand_symtabs_matching
,
3730 dw2_expand_symtabs_for_function
,
3731 dw2_expand_all_symtabs
,
3732 dw2_expand_symtabs_with_filename
,
3733 dw2_find_symbol_file
,
3734 dw2_map_matching_symbols
,
3735 dw2_expand_symtabs_matching
,
3736 dw2_find_pc_sect_symtab
,
3737 dw2_map_symbol_filenames
3740 /* Initialize for reading DWARF for this objfile. Return 0 if this
3741 file will use psymtabs, or 1 if using the GNU index. */
3744 dwarf2_initialize_objfile (struct objfile
*objfile
)
3746 /* If we're about to read full symbols, don't bother with the
3747 indices. In this case we also don't care if some other debug
3748 format is making psymtabs, because they are all about to be
3750 if ((objfile
->flags
& OBJF_READNOW
))
3754 dwarf2_per_objfile
->using_index
= 1;
3755 create_all_comp_units (objfile
);
3756 create_all_type_units (objfile
);
3757 dwarf2_per_objfile
->quick_file_names_table
=
3758 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3760 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3761 + dwarf2_per_objfile
->n_type_units
); ++i
)
3763 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3765 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3766 struct dwarf2_per_cu_quick_data
);
3769 /* Return 1 so that gdb sees the "quick" functions. However,
3770 these functions will be no-ops because we will have expanded
3775 if (dwarf2_read_index (objfile
))
3783 /* Build a partial symbol table. */
3786 dwarf2_build_psymtabs (struct objfile
*objfile
)
3788 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3790 init_psymbol_list (objfile
, 1024);
3793 dwarf2_build_psymtabs_hard (objfile
);
3796 /* Return the total length of the CU described by HEADER. */
3799 get_cu_length (const struct comp_unit_head
*header
)
3801 return header
->initial_length_size
+ header
->length
;
3804 /* Return TRUE if OFFSET is within CU_HEADER. */
3807 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3809 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3810 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3812 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3815 /* Find the base address of the compilation unit for range lists and
3816 location lists. It will normally be specified by DW_AT_low_pc.
3817 In DWARF-3 draft 4, the base address could be overridden by
3818 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3819 compilation units with discontinuous ranges. */
3822 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3824 struct attribute
*attr
;
3827 cu
->base_address
= 0;
3829 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3832 cu
->base_address
= DW_ADDR (attr
);
3837 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3840 cu
->base_address
= DW_ADDR (attr
);
3846 /* Read in the comp unit header information from the debug_info at info_ptr.
3847 NOTE: This leaves members offset, first_die_offset to be filled in
3851 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3852 gdb_byte
*info_ptr
, bfd
*abfd
)
3855 unsigned int bytes_read
;
3857 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3858 cu_header
->initial_length_size
= bytes_read
;
3859 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3860 info_ptr
+= bytes_read
;
3861 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3863 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3865 info_ptr
+= bytes_read
;
3866 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3868 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3869 if (signed_addr
< 0)
3870 internal_error (__FILE__
, __LINE__
,
3871 _("read_comp_unit_head: dwarf from non elf file"));
3872 cu_header
->signed_addr_p
= signed_addr
;
3877 /* Helper function that returns the proper abbrev section for
3880 static struct dwarf2_section_info
*
3881 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3883 struct dwarf2_section_info
*abbrev
;
3885 if (this_cu
->is_dwz
)
3886 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3888 abbrev
= &dwarf2_per_objfile
->abbrev
;
3893 /* Subroutine of read_and_check_comp_unit_head and
3894 read_and_check_type_unit_head to simplify them.
3895 Perform various error checking on the header. */
3898 error_check_comp_unit_head (struct comp_unit_head
*header
,
3899 struct dwarf2_section_info
*section
,
3900 struct dwarf2_section_info
*abbrev_section
)
3902 bfd
*abfd
= section
->asection
->owner
;
3903 const char *filename
= bfd_get_filename (abfd
);
3905 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3906 error (_("Dwarf Error: wrong version in compilation unit header "
3907 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3910 if (header
->abbrev_offset
.sect_off
3911 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3912 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3913 "(offset 0x%lx + 6) [in module %s]"),
3914 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3917 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3918 avoid potential 32-bit overflow. */
3919 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3921 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3922 "(offset 0x%lx + 0) [in module %s]"),
3923 (long) header
->length
, (long) header
->offset
.sect_off
,
3927 /* Read in a CU/TU header and perform some basic error checking.
3928 The contents of the header are stored in HEADER.
3929 The result is a pointer to the start of the first DIE. */
3932 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3933 struct dwarf2_section_info
*section
,
3934 struct dwarf2_section_info
*abbrev_section
,
3936 int is_debug_types_section
)
3938 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3939 bfd
*abfd
= section
->asection
->owner
;
3941 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3943 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3945 /* If we're reading a type unit, skip over the signature and
3946 type_offset fields. */
3947 if (is_debug_types_section
)
3948 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
3950 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3952 error_check_comp_unit_head (header
, section
, abbrev_section
);
3957 /* Read in the types comp unit header information from .debug_types entry at
3958 types_ptr. The result is a pointer to one past the end of the header. */
3961 read_and_check_type_unit_head (struct comp_unit_head
*header
,
3962 struct dwarf2_section_info
*section
,
3963 struct dwarf2_section_info
*abbrev_section
,
3965 ULONGEST
*signature
,
3966 cu_offset
*type_offset_in_tu
)
3968 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3969 bfd
*abfd
= section
->asection
->owner
;
3971 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3973 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3975 /* If we're reading a type unit, skip over the signature and
3976 type_offset fields. */
3977 if (signature
!= NULL
)
3978 *signature
= read_8_bytes (abfd
, info_ptr
);
3980 if (type_offset_in_tu
!= NULL
)
3981 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
3982 header
->offset_size
);
3983 info_ptr
+= header
->offset_size
;
3985 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
3987 error_check_comp_unit_head (header
, section
, abbrev_section
);
3992 /* Fetch the abbreviation table offset from a comp or type unit header. */
3995 read_abbrev_offset (struct dwarf2_section_info
*section
,
3998 bfd
*abfd
= section
->asection
->owner
;
4000 unsigned int length
, initial_length_size
, offset_size
;
4001 sect_offset abbrev_offset
;
4003 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4004 info_ptr
= section
->buffer
+ offset
.sect_off
;
4005 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4006 offset_size
= initial_length_size
== 4 ? 4 : 8;
4007 info_ptr
+= initial_length_size
+ 2 /*version*/;
4008 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4009 return abbrev_offset
;
4012 /* Allocate a new partial symtab for file named NAME and mark this new
4013 partial symtab as being an include of PST. */
4016 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
4017 struct objfile
*objfile
)
4019 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4021 subpst
->section_offsets
= pst
->section_offsets
;
4022 subpst
->textlow
= 0;
4023 subpst
->texthigh
= 0;
4025 subpst
->dependencies
= (struct partial_symtab
**)
4026 obstack_alloc (&objfile
->objfile_obstack
,
4027 sizeof (struct partial_symtab
*));
4028 subpst
->dependencies
[0] = pst
;
4029 subpst
->number_of_dependencies
= 1;
4031 subpst
->globals_offset
= 0;
4032 subpst
->n_global_syms
= 0;
4033 subpst
->statics_offset
= 0;
4034 subpst
->n_static_syms
= 0;
4035 subpst
->symtab
= NULL
;
4036 subpst
->read_symtab
= pst
->read_symtab
;
4039 /* No private part is necessary for include psymtabs. This property
4040 can be used to differentiate between such include psymtabs and
4041 the regular ones. */
4042 subpst
->read_symtab_private
= NULL
;
4045 /* Read the Line Number Program data and extract the list of files
4046 included by the source file represented by PST. Build an include
4047 partial symtab for each of these included files. */
4050 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4051 struct die_info
*die
,
4052 struct partial_symtab
*pst
)
4054 struct line_header
*lh
= NULL
;
4055 struct attribute
*attr
;
4057 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4059 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4061 return; /* No linetable, so no includes. */
4063 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4064 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4066 free_line_header (lh
);
4070 hash_signatured_type (const void *item
)
4072 const struct signatured_type
*sig_type
= item
;
4074 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4075 return sig_type
->signature
;
4079 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4081 const struct signatured_type
*lhs
= item_lhs
;
4082 const struct signatured_type
*rhs
= item_rhs
;
4084 return lhs
->signature
== rhs
->signature
;
4087 /* Allocate a hash table for signatured types. */
4090 allocate_signatured_type_table (struct objfile
*objfile
)
4092 return htab_create_alloc_ex (41,
4093 hash_signatured_type
,
4096 &objfile
->objfile_obstack
,
4097 hashtab_obstack_allocate
,
4098 dummy_obstack_deallocate
);
4101 /* A helper function to add a signatured type CU to a table. */
4104 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4106 struct signatured_type
*sigt
= *slot
;
4107 struct signatured_type
***datap
= datum
;
4115 /* Create the hash table of all entries in the .debug_types section.
4116 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4118 Note: This function processes DWO files only, not DWP files.
4119 The result is a pointer to the hash table or NULL if there are
4123 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4124 VEC (dwarf2_section_info_def
) *types
)
4126 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4127 htab_t types_htab
= NULL
;
4129 struct dwarf2_section_info
*section
;
4130 struct dwarf2_section_info
*abbrev_section
;
4132 if (VEC_empty (dwarf2_section_info_def
, types
))
4135 abbrev_section
= (dwo_file
!= NULL
4136 ? &dwo_file
->sections
.abbrev
4137 : &dwarf2_per_objfile
->abbrev
);
4139 if (dwarf2_read_debug
)
4140 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4141 dwo_file
? ".dwo" : "",
4142 bfd_get_filename (abbrev_section
->asection
->owner
));
4145 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4149 gdb_byte
*info_ptr
, *end_ptr
;
4150 struct dwarf2_section_info
*abbrev_section
;
4152 dwarf2_read_section (objfile
, section
);
4153 info_ptr
= section
->buffer
;
4155 if (info_ptr
== NULL
)
4158 /* We can't set abfd until now because the section may be empty or
4159 not present, in which case section->asection will be NULL. */
4160 abfd
= section
->asection
->owner
;
4163 abbrev_section
= &dwo_file
->sections
.abbrev
;
4165 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4167 if (types_htab
== NULL
)
4170 types_htab
= allocate_dwo_unit_table (objfile
);
4172 types_htab
= allocate_signatured_type_table (objfile
);
4175 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4176 because we don't need to read any dies: the signature is in the
4179 end_ptr
= info_ptr
+ section
->size
;
4180 while (info_ptr
< end_ptr
)
4183 cu_offset type_offset_in_tu
;
4185 struct signatured_type
*sig_type
;
4186 struct dwo_unit
*dwo_tu
;
4188 gdb_byte
*ptr
= info_ptr
;
4189 struct comp_unit_head header
;
4190 unsigned int length
;
4192 offset
.sect_off
= ptr
- section
->buffer
;
4194 /* We need to read the type's signature in order to build the hash
4195 table, but we don't need anything else just yet. */
4197 ptr
= read_and_check_type_unit_head (&header
, section
,
4198 abbrev_section
, ptr
,
4199 &signature
, &type_offset_in_tu
);
4201 length
= get_cu_length (&header
);
4203 /* Skip dummy type units. */
4204 if (ptr
>= info_ptr
+ length
4205 || peek_abbrev_code (abfd
, ptr
) == 0)
4214 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4216 dwo_tu
->dwo_file
= dwo_file
;
4217 dwo_tu
->signature
= signature
;
4218 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4219 dwo_tu
->info_or_types_section
= section
;
4220 dwo_tu
->offset
= offset
;
4221 dwo_tu
->length
= length
;
4225 /* N.B.: type_offset is not usable if this type uses a DWO file.
4226 The real type_offset is in the DWO file. */
4228 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4229 struct signatured_type
);
4230 sig_type
->signature
= signature
;
4231 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4232 sig_type
->per_cu
.objfile
= objfile
;
4233 sig_type
->per_cu
.is_debug_types
= 1;
4234 sig_type
->per_cu
.info_or_types_section
= section
;
4235 sig_type
->per_cu
.offset
= offset
;
4236 sig_type
->per_cu
.length
= length
;
4239 slot
= htab_find_slot (types_htab
,
4240 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4242 gdb_assert (slot
!= NULL
);
4245 sect_offset dup_offset
;
4249 const struct dwo_unit
*dup_tu
= *slot
;
4251 dup_offset
= dup_tu
->offset
;
4255 const struct signatured_type
*dup_tu
= *slot
;
4257 dup_offset
= dup_tu
->per_cu
.offset
;
4260 complaint (&symfile_complaints
,
4261 _("debug type entry at offset 0x%x is duplicate to the "
4262 "entry at offset 0x%x, signature 0x%s"),
4263 offset
.sect_off
, dup_offset
.sect_off
,
4264 phex (signature
, sizeof (signature
)));
4266 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4268 if (dwarf2_read_debug
)
4269 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4271 phex (signature
, sizeof (signature
)));
4280 /* Create the hash table of all entries in the .debug_types section,
4281 and initialize all_type_units.
4282 The result is zero if there is an error (e.g. missing .debug_types section),
4283 otherwise non-zero. */
4286 create_all_type_units (struct objfile
*objfile
)
4289 struct signatured_type
**iter
;
4291 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4292 if (types_htab
== NULL
)
4294 dwarf2_per_objfile
->signatured_types
= NULL
;
4298 dwarf2_per_objfile
->signatured_types
= types_htab
;
4300 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4301 dwarf2_per_objfile
->all_type_units
4302 = obstack_alloc (&objfile
->objfile_obstack
,
4303 dwarf2_per_objfile
->n_type_units
4304 * sizeof (struct signatured_type
*));
4305 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4306 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4307 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4308 == dwarf2_per_objfile
->n_type_units
);
4313 /* Lookup a signature based type for DW_FORM_ref_sig8.
4314 Returns NULL if signature SIG is not present in the table. */
4316 static struct signatured_type
*
4317 lookup_signatured_type (ULONGEST sig
)
4319 struct signatured_type find_entry
, *entry
;
4321 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4323 complaint (&symfile_complaints
,
4324 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4328 find_entry
.signature
= sig
;
4329 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4333 /* Low level DIE reading support. */
4335 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4338 init_cu_die_reader (struct die_reader_specs
*reader
,
4339 struct dwarf2_cu
*cu
,
4340 struct dwarf2_section_info
*section
,
4341 struct dwo_file
*dwo_file
)
4343 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4344 reader
->abfd
= section
->asection
->owner
;
4346 reader
->dwo_file
= dwo_file
;
4347 reader
->die_section
= section
;
4348 reader
->buffer
= section
->buffer
;
4349 reader
->buffer_end
= section
->buffer
+ section
->size
;
4352 /* Initialize a CU (or TU) and read its DIEs.
4353 If the CU defers to a DWO file, read the DWO file as well.
4355 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4356 Otherwise the table specified in the comp unit header is read in and used.
4357 This is an optimization for when we already have the abbrev table.
4359 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4360 Otherwise, a new CU is allocated with xmalloc.
4362 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4363 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4365 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4366 linker) then DIE_READER_FUNC will not get called. */
4369 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4370 struct abbrev_table
*abbrev_table
,
4371 int use_existing_cu
, int keep
,
4372 die_reader_func_ftype
*die_reader_func
,
4375 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4376 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4377 bfd
*abfd
= section
->asection
->owner
;
4378 struct dwarf2_cu
*cu
;
4379 gdb_byte
*begin_info_ptr
, *info_ptr
;
4380 struct die_reader_specs reader
;
4381 struct die_info
*comp_unit_die
;
4383 struct attribute
*attr
;
4384 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4385 struct signatured_type
*sig_type
= NULL
;
4386 struct dwarf2_section_info
*abbrev_section
;
4387 /* Non-zero if CU currently points to a DWO file and we need to
4388 reread it. When this happens we need to reread the skeleton die
4389 before we can reread the DWO file. */
4390 int rereading_dwo_cu
= 0;
4392 if (dwarf2_die_debug
)
4393 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4394 this_cu
->is_debug_types
? "type" : "comp",
4395 this_cu
->offset
.sect_off
);
4397 if (use_existing_cu
)
4400 cleanups
= make_cleanup (null_cleanup
, NULL
);
4402 /* This is cheap if the section is already read in. */
4403 dwarf2_read_section (objfile
, section
);
4405 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4407 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4409 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4413 /* If this CU is from a DWO file we need to start over, we need to
4414 refetch the attributes from the skeleton CU.
4415 This could be optimized by retrieving those attributes from when we
4416 were here the first time: the previous comp_unit_die was stored in
4417 comp_unit_obstack. But there's no data yet that we need this
4419 if (cu
->dwo_unit
!= NULL
)
4420 rereading_dwo_cu
= 1;
4424 /* If !use_existing_cu, this_cu->cu must be NULL. */
4425 gdb_assert (this_cu
->cu
== NULL
);
4427 cu
= xmalloc (sizeof (*cu
));
4428 init_one_comp_unit (cu
, this_cu
);
4430 /* If an error occurs while loading, release our storage. */
4431 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4434 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4436 /* We already have the header, there's no need to read it in again. */
4437 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4441 if (this_cu
->is_debug_types
)
4444 cu_offset type_offset_in_tu
;
4446 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4447 abbrev_section
, info_ptr
,
4449 &type_offset_in_tu
);
4451 /* Since per_cu is the first member of struct signatured_type,
4452 we can go from a pointer to one to a pointer to the other. */
4453 sig_type
= (struct signatured_type
*) this_cu
;
4454 gdb_assert (sig_type
->signature
== signature
);
4455 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4456 == type_offset_in_tu
.cu_off
);
4457 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4459 /* LENGTH has not been set yet for type units if we're
4460 using .gdb_index. */
4461 this_cu
->length
= get_cu_length (&cu
->header
);
4463 /* Establish the type offset that can be used to lookup the type. */
4464 sig_type
->type_offset_in_section
.sect_off
=
4465 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4469 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4473 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4474 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4478 /* Skip dummy compilation units. */
4479 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4480 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4482 do_cleanups (cleanups
);
4486 /* If we don't have them yet, read the abbrevs for this compilation unit.
4487 And if we need to read them now, make sure they're freed when we're
4488 done. Note that it's important that if the CU had an abbrev table
4489 on entry we don't free it when we're done: Somewhere up the call stack
4490 it may be in use. */
4491 if (abbrev_table
!= NULL
)
4493 gdb_assert (cu
->abbrev_table
== NULL
);
4494 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4495 == abbrev_table
->offset
.sect_off
);
4496 cu
->abbrev_table
= abbrev_table
;
4498 else if (cu
->abbrev_table
== NULL
)
4500 dwarf2_read_abbrevs (cu
, abbrev_section
);
4501 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4503 else if (rereading_dwo_cu
)
4505 dwarf2_free_abbrev_table (cu
);
4506 dwarf2_read_abbrevs (cu
, abbrev_section
);
4509 /* Read the top level CU/TU die. */
4510 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4511 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4513 /* If we have a DWO stub, process it and then read in the DWO file.
4514 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4515 a DWO CU, that this test will fail. */
4516 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4519 char *dwo_name
= DW_STRING (attr
);
4520 const char *comp_dir_string
;
4521 struct dwo_unit
*dwo_unit
;
4522 ULONGEST signature
; /* Or dwo_id. */
4523 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4524 int i
,num_extra_attrs
;
4525 struct dwarf2_section_info
*dwo_abbrev_section
;
4528 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4529 " has children (offset 0x%x) [in module %s]"),
4530 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4532 /* These attributes aren't processed until later:
4533 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4534 However, the attribute is found in the stub which we won't have later.
4535 In order to not impose this complication on the rest of the code,
4536 we read them here and copy them to the DWO CU/TU die. */
4538 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4541 if (! this_cu
->is_debug_types
)
4542 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4543 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4544 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4545 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4546 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4548 /* There should be a DW_AT_addr_base attribute here (if needed).
4549 We need the value before we can process DW_FORM_GNU_addr_index. */
4551 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4553 cu
->addr_base
= DW_UNSND (attr
);
4555 /* There should be a DW_AT_ranges_base attribute here (if needed).
4556 We need the value before we can process DW_AT_ranges. */
4557 cu
->ranges_base
= 0;
4558 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4560 cu
->ranges_base
= DW_UNSND (attr
);
4562 if (this_cu
->is_debug_types
)
4564 gdb_assert (sig_type
!= NULL
);
4565 signature
= sig_type
->signature
;
4569 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4571 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4573 signature
= DW_UNSND (attr
);
4576 /* We may need the comp_dir in order to find the DWO file. */
4577 comp_dir_string
= NULL
;
4579 comp_dir_string
= DW_STRING (comp_dir
);
4581 if (this_cu
->is_debug_types
)
4582 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4584 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4587 if (dwo_unit
== NULL
)
4589 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4590 " with ID %s [in module %s]"),
4591 this_cu
->offset
.sect_off
,
4592 phex (signature
, sizeof (signature
)),
4596 /* Set up for reading the DWO CU/TU. */
4597 cu
->dwo_unit
= dwo_unit
;
4598 section
= dwo_unit
->info_or_types_section
;
4599 dwarf2_read_section (objfile
, section
);
4600 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4601 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4602 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4604 if (this_cu
->is_debug_types
)
4607 cu_offset type_offset_in_tu
;
4609 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4613 &type_offset_in_tu
);
4614 gdb_assert (sig_type
->signature
== signature
);
4615 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4616 /* For DWOs coming from DWP files, we don't know the CU length
4617 nor the type's offset in the TU until now. */
4618 dwo_unit
->length
= get_cu_length (&cu
->header
);
4619 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4621 /* Establish the type offset that can be used to lookup the type.
4622 For DWO files, we don't know it until now. */
4623 sig_type
->type_offset_in_section
.sect_off
=
4624 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4628 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4631 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4632 /* For DWOs coming from DWP files, we don't know the CU length
4634 dwo_unit
->length
= get_cu_length (&cu
->header
);
4637 /* Discard the original CU's abbrev table, and read the DWO's. */
4638 if (abbrev_table
== NULL
)
4640 dwarf2_free_abbrev_table (cu
);
4641 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4645 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4646 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4649 /* Read in the die, but leave space to copy over the attributes
4650 from the stub. This has the benefit of simplifying the rest of
4651 the code - all the real work is done here. */
4652 num_extra_attrs
= ((stmt_list
!= NULL
)
4656 + (comp_dir
!= NULL
));
4657 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4658 &has_children
, num_extra_attrs
);
4660 /* Copy over the attributes from the stub to the DWO die. */
4661 i
= comp_unit_die
->num_attrs
;
4662 if (stmt_list
!= NULL
)
4663 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4665 comp_unit_die
->attrs
[i
++] = *low_pc
;
4666 if (high_pc
!= NULL
)
4667 comp_unit_die
->attrs
[i
++] = *high_pc
;
4669 comp_unit_die
->attrs
[i
++] = *ranges
;
4670 if (comp_dir
!= NULL
)
4671 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4672 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4674 /* Skip dummy compilation units. */
4675 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4676 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4678 do_cleanups (cleanups
);
4683 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4685 if (free_cu_cleanup
!= NULL
)
4689 /* We've successfully allocated this compilation unit. Let our
4690 caller clean it up when finished with it. */
4691 discard_cleanups (free_cu_cleanup
);
4693 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4694 So we have to manually free the abbrev table. */
4695 dwarf2_free_abbrev_table (cu
);
4697 /* Link this CU into read_in_chain. */
4698 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4699 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4702 do_cleanups (free_cu_cleanup
);
4705 do_cleanups (cleanups
);
4708 /* Read CU/TU THIS_CU in section SECTION,
4709 but do not follow DW_AT_GNU_dwo_name if present.
4710 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4711 to have already done the lookup to find the DWO/DWP file).
4713 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4714 THIS_CU->is_debug_types, but nothing else.
4716 We fill in THIS_CU->length.
4718 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4719 linker) then DIE_READER_FUNC will not get called.
4721 THIS_CU->cu is always freed when done.
4722 This is done in order to not leave THIS_CU->cu in a state where we have
4723 to care whether it refers to the "main" CU or the DWO CU. */
4726 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4727 struct dwarf2_section_info
*abbrev_section
,
4728 struct dwo_file
*dwo_file
,
4729 die_reader_func_ftype
*die_reader_func
,
4732 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4733 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4734 bfd
*abfd
= section
->asection
->owner
;
4735 struct dwarf2_cu cu
;
4736 gdb_byte
*begin_info_ptr
, *info_ptr
;
4737 struct die_reader_specs reader
;
4738 struct cleanup
*cleanups
;
4739 struct die_info
*comp_unit_die
;
4742 if (dwarf2_die_debug
)
4743 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4744 this_cu
->is_debug_types
? "type" : "comp",
4745 this_cu
->offset
.sect_off
);
4747 gdb_assert (this_cu
->cu
== NULL
);
4749 /* This is cheap if the section is already read in. */
4750 dwarf2_read_section (objfile
, section
);
4752 init_one_comp_unit (&cu
, this_cu
);
4754 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4756 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4757 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4758 abbrev_section
, info_ptr
,
4759 this_cu
->is_debug_types
);
4761 this_cu
->length
= get_cu_length (&cu
.header
);
4763 /* Skip dummy compilation units. */
4764 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4765 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4767 do_cleanups (cleanups
);
4771 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4772 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4774 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4775 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4777 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4779 do_cleanups (cleanups
);
4782 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4783 does not lookup the specified DWO file.
4784 This cannot be used to read DWO files.
4786 THIS_CU->cu is always freed when done.
4787 This is done in order to not leave THIS_CU->cu in a state where we have
4788 to care whether it refers to the "main" CU or the DWO CU.
4789 We can revisit this if the data shows there's a performance issue. */
4792 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4793 die_reader_func_ftype
*die_reader_func
,
4796 init_cutu_and_read_dies_no_follow (this_cu
,
4797 get_abbrev_section_for_cu (this_cu
),
4799 die_reader_func
, data
);
4802 /* Create a psymtab named NAME and assign it to PER_CU.
4804 The caller must fill in the following details:
4805 dirname, textlow, texthigh. */
4807 static struct partial_symtab
*
4808 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4810 struct objfile
*objfile
= per_cu
->objfile
;
4811 struct partial_symtab
*pst
;
4813 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4815 objfile
->global_psymbols
.next
,
4816 objfile
->static_psymbols
.next
);
4818 pst
->psymtabs_addrmap_supported
= 1;
4820 /* This is the glue that links PST into GDB's symbol API. */
4821 pst
->read_symtab_private
= per_cu
;
4822 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
4823 per_cu
->v
.psymtab
= pst
;
4828 /* die_reader_func for process_psymtab_comp_unit. */
4831 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4833 struct die_info
*comp_unit_die
,
4837 struct dwarf2_cu
*cu
= reader
->cu
;
4838 struct objfile
*objfile
= cu
->objfile
;
4839 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4840 struct attribute
*attr
;
4842 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4843 struct partial_symtab
*pst
;
4845 const char *filename
;
4846 int *want_partial_unit_ptr
= data
;
4848 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4849 && (want_partial_unit_ptr
== NULL
4850 || !*want_partial_unit_ptr
))
4853 gdb_assert (! per_cu
->is_debug_types
);
4855 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4857 cu
->list_in_scope
= &file_symbols
;
4859 /* Allocate a new partial symbol table structure. */
4860 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4861 if (attr
== NULL
|| !DW_STRING (attr
))
4864 filename
= DW_STRING (attr
);
4866 pst
= create_partial_symtab (per_cu
, filename
);
4868 /* This must be done before calling dwarf2_build_include_psymtabs. */
4869 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4871 pst
->dirname
= DW_STRING (attr
);
4873 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4875 dwarf2_find_base_address (comp_unit_die
, cu
);
4877 /* Possibly set the default values of LOWPC and HIGHPC from
4879 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4880 &best_highpc
, cu
, pst
);
4881 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4882 /* Store the contiguous range if it is not empty; it can be empty for
4883 CUs with no code. */
4884 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4885 best_lowpc
+ baseaddr
,
4886 best_highpc
+ baseaddr
- 1, pst
);
4888 /* Check if comp unit has_children.
4889 If so, read the rest of the partial symbols from this comp unit.
4890 If not, there's no more debug_info for this comp unit. */
4893 struct partial_die_info
*first_die
;
4894 CORE_ADDR lowpc
, highpc
;
4896 lowpc
= ((CORE_ADDR
) -1);
4897 highpc
= ((CORE_ADDR
) 0);
4899 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4901 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4904 /* If we didn't find a lowpc, set it to highpc to avoid
4905 complaints from `maint check'. */
4906 if (lowpc
== ((CORE_ADDR
) -1))
4909 /* If the compilation unit didn't have an explicit address range,
4910 then use the information extracted from its child dies. */
4914 best_highpc
= highpc
;
4917 pst
->textlow
= best_lowpc
+ baseaddr
;
4918 pst
->texthigh
= best_highpc
+ baseaddr
;
4920 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4921 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4922 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4923 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4924 sort_pst_symbols (pst
);
4926 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
))
4929 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4930 struct dwarf2_per_cu_data
*iter
;
4932 /* Fill in 'dependencies' here; we fill in 'users' in a
4934 pst
->number_of_dependencies
= len
;
4935 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4936 len
* sizeof (struct symtab
*));
4938 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
4941 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4943 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
);
4946 /* Get the list of files included in the current compilation unit,
4947 and build a psymtab for each of them. */
4948 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
4950 if (dwarf2_read_debug
)
4952 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4954 fprintf_unfiltered (gdb_stdlog
,
4955 "Psymtab for %s unit @0x%x: %s - %s"
4956 ", %d global, %d static syms\n",
4957 per_cu
->is_debug_types
? "type" : "comp",
4958 per_cu
->offset
.sect_off
,
4959 paddress (gdbarch
, pst
->textlow
),
4960 paddress (gdbarch
, pst
->texthigh
),
4961 pst
->n_global_syms
, pst
->n_static_syms
);
4965 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4966 Process compilation unit THIS_CU for a psymtab. */
4969 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
4970 int want_partial_unit
)
4972 /* If this compilation unit was already read in, free the
4973 cached copy in order to read it in again. This is
4974 necessary because we skipped some symbols when we first
4975 read in the compilation unit (see load_partial_dies).
4976 This problem could be avoided, but the benefit is unclear. */
4977 if (this_cu
->cu
!= NULL
)
4978 free_one_cached_comp_unit (this_cu
);
4980 gdb_assert (! this_cu
->is_debug_types
);
4981 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
4982 process_psymtab_comp_unit_reader
,
4983 &want_partial_unit
);
4985 /* Age out any secondary CUs. */
4986 age_cached_comp_units ();
4990 hash_type_unit_group (const void *item
)
4992 const struct type_unit_group
*tu_group
= item
;
4994 return hash_stmt_list_entry (&tu_group
->hash
);
4998 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5000 const struct type_unit_group
*lhs
= item_lhs
;
5001 const struct type_unit_group
*rhs
= item_rhs
;
5003 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5006 /* Allocate a hash table for type unit groups. */
5009 allocate_type_unit_groups_table (void)
5011 return htab_create_alloc_ex (3,
5012 hash_type_unit_group
,
5015 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5016 hashtab_obstack_allocate
,
5017 dummy_obstack_deallocate
);
5020 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5021 partial symtabs. We combine several TUs per psymtab to not let the size
5022 of any one psymtab grow too big. */
5023 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5024 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5026 /* Helper routine for get_type_unit_group.
5027 Create the type_unit_group object used to hold one or more TUs. */
5029 static struct type_unit_group
*
5030 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5033 struct dwarf2_per_cu_data
*per_cu
;
5034 struct type_unit_group
*tu_group
;
5036 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5037 struct type_unit_group
);
5038 per_cu
= &tu_group
->per_cu
;
5039 per_cu
->objfile
= objfile
;
5040 per_cu
->is_debug_types
= 1;
5041 per_cu
->s
.type_unit_group
= tu_group
;
5043 if (dwarf2_per_objfile
->using_index
)
5045 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5046 struct dwarf2_per_cu_quick_data
);
5047 tu_group
->t
.first_tu
= cu
->per_cu
;
5051 unsigned int line_offset
= line_offset_struct
.sect_off
;
5052 struct partial_symtab
*pst
;
5055 /* Give the symtab a useful name for debug purposes. */
5056 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5057 name
= xstrprintf ("<type_units_%d>",
5058 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5060 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5062 pst
= create_partial_symtab (per_cu
, name
);
5068 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5069 tu_group
->hash
.line_offset
= line_offset_struct
;
5074 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5075 STMT_LIST is a DW_AT_stmt_list attribute. */
5077 static struct type_unit_group
*
5078 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5080 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5081 struct type_unit_group
*tu_group
;
5083 unsigned int line_offset
;
5084 struct type_unit_group type_unit_group_for_lookup
;
5086 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5088 dwarf2_per_objfile
->type_unit_groups
=
5089 allocate_type_unit_groups_table ();
5092 /* Do we need to create a new group, or can we use an existing one? */
5096 line_offset
= DW_UNSND (stmt_list
);
5097 ++tu_stats
->nr_symtab_sharers
;
5101 /* Ugh, no stmt_list. Rare, but we have to handle it.
5102 We can do various things here like create one group per TU or
5103 spread them over multiple groups to split up the expansion work.
5104 To avoid worst case scenarios (too many groups or too large groups)
5105 we, umm, group them in bunches. */
5106 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5107 | (tu_stats
->nr_stmt_less_type_units
5108 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5109 ++tu_stats
->nr_stmt_less_type_units
;
5112 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5113 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5114 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5115 &type_unit_group_for_lookup
, INSERT
);
5119 gdb_assert (tu_group
!= NULL
);
5123 sect_offset line_offset_struct
;
5125 line_offset_struct
.sect_off
= line_offset
;
5126 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5128 ++tu_stats
->nr_symtabs
;
5134 /* Struct used to sort TUs by their abbreviation table offset. */
5136 struct tu_abbrev_offset
5138 struct signatured_type
*sig_type
;
5139 sect_offset abbrev_offset
;
5142 /* Helper routine for build_type_unit_groups, passed to qsort. */
5145 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5147 const struct tu_abbrev_offset
* const *a
= ap
;
5148 const struct tu_abbrev_offset
* const *b
= bp
;
5149 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5150 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5152 return (aoff
> boff
) - (aoff
< boff
);
5155 /* A helper function to add a type_unit_group to a table. */
5158 add_type_unit_group_to_table (void **slot
, void *datum
)
5160 struct type_unit_group
*tu_group
= *slot
;
5161 struct type_unit_group
***datap
= datum
;
5169 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5170 each one passing FUNC,DATA.
5172 The efficiency is because we sort TUs by the abbrev table they use and
5173 only read each abbrev table once. In one program there are 200K TUs
5174 sharing 8K abbrev tables.
5176 The main purpose of this function is to support building the
5177 dwarf2_per_objfile->type_unit_groups table.
5178 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5179 can collapse the search space by grouping them by stmt_list.
5180 The savings can be significant, in the same program from above the 200K TUs
5181 share 8K stmt_list tables.
5183 FUNC is expected to call get_type_unit_group, which will create the
5184 struct type_unit_group if necessary and add it to
5185 dwarf2_per_objfile->type_unit_groups. */
5188 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5190 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5191 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5192 struct cleanup
*cleanups
;
5193 struct abbrev_table
*abbrev_table
;
5194 sect_offset abbrev_offset
;
5195 struct tu_abbrev_offset
*sorted_by_abbrev
;
5196 struct type_unit_group
**iter
;
5199 /* It's up to the caller to not call us multiple times. */
5200 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5202 if (dwarf2_per_objfile
->n_type_units
== 0)
5205 /* TUs typically share abbrev tables, and there can be way more TUs than
5206 abbrev tables. Sort by abbrev table to reduce the number of times we
5207 read each abbrev table in.
5208 Alternatives are to punt or to maintain a cache of abbrev tables.
5209 This is simpler and efficient enough for now.
5211 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5212 symtab to use). Typically TUs with the same abbrev offset have the same
5213 stmt_list value too so in practice this should work well.
5215 The basic algorithm here is:
5217 sort TUs by abbrev table
5218 for each TU with same abbrev table:
5219 read abbrev table if first user
5220 read TU top level DIE
5221 [IWBN if DWO skeletons had DW_AT_stmt_list]
5224 if (dwarf2_read_debug
)
5225 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5227 /* Sort in a separate table to maintain the order of all_type_units
5228 for .gdb_index: TU indices directly index all_type_units. */
5229 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5230 dwarf2_per_objfile
->n_type_units
);
5231 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5233 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5235 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5236 sorted_by_abbrev
[i
].abbrev_offset
=
5237 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5238 sig_type
->per_cu
.offset
);
5240 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5241 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5242 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5244 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5245 called any number of times, so we don't reset tu_stats here. */
5247 abbrev_offset
.sect_off
= ~(unsigned) 0;
5248 abbrev_table
= NULL
;
5249 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5251 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5253 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5255 /* Switch to the next abbrev table if necessary. */
5256 if (abbrev_table
== NULL
5257 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5259 if (abbrev_table
!= NULL
)
5261 abbrev_table_free (abbrev_table
);
5262 /* Reset to NULL in case abbrev_table_read_table throws
5263 an error: abbrev_table_free_cleanup will get called. */
5264 abbrev_table
= NULL
;
5266 abbrev_offset
= tu
->abbrev_offset
;
5268 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5270 ++tu_stats
->nr_uniq_abbrev_tables
;
5273 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5277 /* Create a vector of pointers to primary type units to make it easy to
5278 iterate over them and CUs. See dw2_get_primary_cu. */
5279 dwarf2_per_objfile
->n_type_unit_groups
=
5280 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5281 dwarf2_per_objfile
->all_type_unit_groups
=
5282 obstack_alloc (&objfile
->objfile_obstack
,
5283 dwarf2_per_objfile
->n_type_unit_groups
5284 * sizeof (struct type_unit_group
*));
5285 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5286 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5287 add_type_unit_group_to_table
, &iter
);
5288 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5289 == dwarf2_per_objfile
->n_type_unit_groups
);
5291 do_cleanups (cleanups
);
5293 if (dwarf2_read_debug
)
5295 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5296 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5297 dwarf2_per_objfile
->n_type_units
);
5298 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5299 tu_stats
->nr_uniq_abbrev_tables
);
5300 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5301 tu_stats
->nr_symtabs
);
5302 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5303 tu_stats
->nr_symtab_sharers
);
5304 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5305 tu_stats
->nr_stmt_less_type_units
);
5309 /* Reader function for build_type_psymtabs. */
5312 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5314 struct die_info
*type_unit_die
,
5318 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5319 struct dwarf2_cu
*cu
= reader
->cu
;
5320 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5321 struct type_unit_group
*tu_group
;
5322 struct attribute
*attr
;
5323 struct partial_die_info
*first_die
;
5324 CORE_ADDR lowpc
, highpc
;
5325 struct partial_symtab
*pst
;
5327 gdb_assert (data
== NULL
);
5332 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5333 tu_group
= get_type_unit_group (cu
, attr
);
5335 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5337 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5338 cu
->list_in_scope
= &file_symbols
;
5339 pst
= create_partial_symtab (per_cu
, "");
5342 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5344 lowpc
= (CORE_ADDR
) -1;
5345 highpc
= (CORE_ADDR
) 0;
5346 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5348 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5349 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5350 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5351 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5352 sort_pst_symbols (pst
);
5355 /* Traversal function for build_type_psymtabs. */
5358 build_type_psymtab_dependencies (void **slot
, void *info
)
5360 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5361 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5362 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5363 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5364 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5365 struct dwarf2_per_cu_data
*iter
;
5368 gdb_assert (len
> 0);
5370 pst
->number_of_dependencies
= len
;
5371 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5372 len
* sizeof (struct psymtab
*));
5374 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5377 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5378 iter
->s
.type_unit_group
= tu_group
;
5381 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5386 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5387 Build partial symbol tables for the .debug_types comp-units. */
5390 build_type_psymtabs (struct objfile
*objfile
)
5392 if (! create_all_type_units (objfile
))
5395 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5397 /* Now that all TUs have been processed we can fill in the dependencies. */
5398 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5399 build_type_psymtab_dependencies
, NULL
);
5402 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5405 psymtabs_addrmap_cleanup (void *o
)
5407 struct objfile
*objfile
= o
;
5409 objfile
->psymtabs_addrmap
= NULL
;
5412 /* Compute the 'user' field for each psymtab in OBJFILE. */
5415 set_partial_user (struct objfile
*objfile
)
5419 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5421 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5422 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5428 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5430 /* Set the 'user' field only if it is not already set. */
5431 if (pst
->dependencies
[j
]->user
== NULL
)
5432 pst
->dependencies
[j
]->user
= pst
;
5437 /* Build the partial symbol table by doing a quick pass through the
5438 .debug_info and .debug_abbrev sections. */
5441 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5443 struct cleanup
*back_to
, *addrmap_cleanup
;
5444 struct obstack temp_obstack
;
5447 if (dwarf2_read_debug
)
5449 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5453 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5455 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5457 /* Any cached compilation units will be linked by the per-objfile
5458 read_in_chain. Make sure to free them when we're done. */
5459 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5461 build_type_psymtabs (objfile
);
5463 create_all_comp_units (objfile
);
5465 /* Create a temporary address map on a temporary obstack. We later
5466 copy this to the final obstack. */
5467 obstack_init (&temp_obstack
);
5468 make_cleanup_obstack_free (&temp_obstack
);
5469 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5470 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5472 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5474 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5476 process_psymtab_comp_unit (per_cu
, 0);
5479 set_partial_user (objfile
);
5481 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5482 &objfile
->objfile_obstack
);
5483 discard_cleanups (addrmap_cleanup
);
5485 do_cleanups (back_to
);
5487 if (dwarf2_read_debug
)
5488 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5492 /* die_reader_func for load_partial_comp_unit. */
5495 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5497 struct die_info
*comp_unit_die
,
5501 struct dwarf2_cu
*cu
= reader
->cu
;
5503 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5505 /* Check if comp unit has_children.
5506 If so, read the rest of the partial symbols from this comp unit.
5507 If not, there's no more debug_info for this comp unit. */
5509 load_partial_dies (reader
, info_ptr
, 0);
5512 /* Load the partial DIEs for a secondary CU into memory.
5513 This is also used when rereading a primary CU with load_all_dies. */
5516 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5518 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5519 load_partial_comp_unit_reader
, NULL
);
5523 read_comp_units_from_section (struct objfile
*objfile
,
5524 struct dwarf2_section_info
*section
,
5525 unsigned int is_dwz
,
5528 struct dwarf2_per_cu_data
***all_comp_units
)
5531 bfd
*abfd
= section
->asection
->owner
;
5533 dwarf2_read_section (objfile
, section
);
5535 info_ptr
= section
->buffer
;
5537 while (info_ptr
< section
->buffer
+ section
->size
)
5539 unsigned int length
, initial_length_size
;
5540 struct dwarf2_per_cu_data
*this_cu
;
5543 offset
.sect_off
= info_ptr
- section
->buffer
;
5545 /* Read just enough information to find out where the next
5546 compilation unit is. */
5547 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5549 /* Save the compilation unit for later lookup. */
5550 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5551 sizeof (struct dwarf2_per_cu_data
));
5552 memset (this_cu
, 0, sizeof (*this_cu
));
5553 this_cu
->offset
= offset
;
5554 this_cu
->length
= length
+ initial_length_size
;
5555 this_cu
->is_dwz
= is_dwz
;
5556 this_cu
->objfile
= objfile
;
5557 this_cu
->info_or_types_section
= section
;
5559 if (*n_comp_units
== *n_allocated
)
5562 *all_comp_units
= xrealloc (*all_comp_units
,
5564 * sizeof (struct dwarf2_per_cu_data
*));
5566 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5569 info_ptr
= info_ptr
+ this_cu
->length
;
5573 /* Create a list of all compilation units in OBJFILE.
5574 This is only done for -readnow and building partial symtabs. */
5577 create_all_comp_units (struct objfile
*objfile
)
5581 struct dwarf2_per_cu_data
**all_comp_units
;
5585 all_comp_units
= xmalloc (n_allocated
5586 * sizeof (struct dwarf2_per_cu_data
*));
5588 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5589 &n_allocated
, &n_comp_units
, &all_comp_units
);
5591 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5593 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5595 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5596 &n_allocated
, &n_comp_units
,
5600 dwarf2_per_objfile
->all_comp_units
5601 = obstack_alloc (&objfile
->objfile_obstack
,
5602 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5603 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5604 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5605 xfree (all_comp_units
);
5606 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5609 /* Process all loaded DIEs for compilation unit CU, starting at
5610 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5611 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5612 DW_AT_ranges). If NEED_PC is set, then this function will set
5613 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5614 and record the covered ranges in the addrmap. */
5617 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5618 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5620 struct partial_die_info
*pdi
;
5622 /* Now, march along the PDI's, descending into ones which have
5623 interesting children but skipping the children of the other ones,
5624 until we reach the end of the compilation unit. */
5630 fixup_partial_die (pdi
, cu
);
5632 /* Anonymous namespaces or modules have no name but have interesting
5633 children, so we need to look at them. Ditto for anonymous
5636 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5637 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5638 || pdi
->tag
== DW_TAG_imported_unit
)
5642 case DW_TAG_subprogram
:
5643 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5645 case DW_TAG_constant
:
5646 case DW_TAG_variable
:
5647 case DW_TAG_typedef
:
5648 case DW_TAG_union_type
:
5649 if (!pdi
->is_declaration
)
5651 add_partial_symbol (pdi
, cu
);
5654 case DW_TAG_class_type
:
5655 case DW_TAG_interface_type
:
5656 case DW_TAG_structure_type
:
5657 if (!pdi
->is_declaration
)
5659 add_partial_symbol (pdi
, cu
);
5662 case DW_TAG_enumeration_type
:
5663 if (!pdi
->is_declaration
)
5664 add_partial_enumeration (pdi
, cu
);
5666 case DW_TAG_base_type
:
5667 case DW_TAG_subrange_type
:
5668 /* File scope base type definitions are added to the partial
5670 add_partial_symbol (pdi
, cu
);
5672 case DW_TAG_namespace
:
5673 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5676 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5678 case DW_TAG_imported_unit
:
5680 struct dwarf2_per_cu_data
*per_cu
;
5682 /* For now we don't handle imported units in type units. */
5683 if (cu
->per_cu
->is_debug_types
)
5685 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5686 " supported in type units [in module %s]"),
5690 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5694 /* Go read the partial unit, if needed. */
5695 if (per_cu
->v
.psymtab
== NULL
)
5696 process_psymtab_comp_unit (per_cu
, 1);
5698 VEC_safe_push (dwarf2_per_cu_ptr
,
5699 cu
->per_cu
->s
.imported_symtabs
, per_cu
);
5707 /* If the die has a sibling, skip to the sibling. */
5709 pdi
= pdi
->die_sibling
;
5713 /* Functions used to compute the fully scoped name of a partial DIE.
5715 Normally, this is simple. For C++, the parent DIE's fully scoped
5716 name is concatenated with "::" and the partial DIE's name. For
5717 Java, the same thing occurs except that "." is used instead of "::".
5718 Enumerators are an exception; they use the scope of their parent
5719 enumeration type, i.e. the name of the enumeration type is not
5720 prepended to the enumerator.
5722 There are two complexities. One is DW_AT_specification; in this
5723 case "parent" means the parent of the target of the specification,
5724 instead of the direct parent of the DIE. The other is compilers
5725 which do not emit DW_TAG_namespace; in this case we try to guess
5726 the fully qualified name of structure types from their members'
5727 linkage names. This must be done using the DIE's children rather
5728 than the children of any DW_AT_specification target. We only need
5729 to do this for structures at the top level, i.e. if the target of
5730 any DW_AT_specification (if any; otherwise the DIE itself) does not
5733 /* Compute the scope prefix associated with PDI's parent, in
5734 compilation unit CU. The result will be allocated on CU's
5735 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5736 field. NULL is returned if no prefix is necessary. */
5738 partial_die_parent_scope (struct partial_die_info
*pdi
,
5739 struct dwarf2_cu
*cu
)
5741 char *grandparent_scope
;
5742 struct partial_die_info
*parent
, *real_pdi
;
5744 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5745 then this means the parent of the specification DIE. */
5748 while (real_pdi
->has_specification
)
5749 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5750 real_pdi
->spec_is_dwz
, cu
);
5752 parent
= real_pdi
->die_parent
;
5756 if (parent
->scope_set
)
5757 return parent
->scope
;
5759 fixup_partial_die (parent
, cu
);
5761 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5763 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5764 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5765 Work around this problem here. */
5766 if (cu
->language
== language_cplus
5767 && parent
->tag
== DW_TAG_namespace
5768 && strcmp (parent
->name
, "::") == 0
5769 && grandparent_scope
== NULL
)
5771 parent
->scope
= NULL
;
5772 parent
->scope_set
= 1;
5776 if (pdi
->tag
== DW_TAG_enumerator
)
5777 /* Enumerators should not get the name of the enumeration as a prefix. */
5778 parent
->scope
= grandparent_scope
;
5779 else if (parent
->tag
== DW_TAG_namespace
5780 || parent
->tag
== DW_TAG_module
5781 || parent
->tag
== DW_TAG_structure_type
5782 || parent
->tag
== DW_TAG_class_type
5783 || parent
->tag
== DW_TAG_interface_type
5784 || parent
->tag
== DW_TAG_union_type
5785 || parent
->tag
== DW_TAG_enumeration_type
)
5787 if (grandparent_scope
== NULL
)
5788 parent
->scope
= parent
->name
;
5790 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5792 parent
->name
, 0, cu
);
5796 /* FIXME drow/2004-04-01: What should we be doing with
5797 function-local names? For partial symbols, we should probably be
5799 complaint (&symfile_complaints
,
5800 _("unhandled containing DIE tag %d for DIE at %d"),
5801 parent
->tag
, pdi
->offset
.sect_off
);
5802 parent
->scope
= grandparent_scope
;
5805 parent
->scope_set
= 1;
5806 return parent
->scope
;
5809 /* Return the fully scoped name associated with PDI, from compilation unit
5810 CU. The result will be allocated with malloc. */
5813 partial_die_full_name (struct partial_die_info
*pdi
,
5814 struct dwarf2_cu
*cu
)
5818 /* If this is a template instantiation, we can not work out the
5819 template arguments from partial DIEs. So, unfortunately, we have
5820 to go through the full DIEs. At least any work we do building
5821 types here will be reused if full symbols are loaded later. */
5822 if (pdi
->has_template_arguments
)
5824 fixup_partial_die (pdi
, cu
);
5826 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5828 struct die_info
*die
;
5829 struct attribute attr
;
5830 struct dwarf2_cu
*ref_cu
= cu
;
5832 /* DW_FORM_ref_addr is using section offset. */
5834 attr
.form
= DW_FORM_ref_addr
;
5835 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5836 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5838 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5842 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5843 if (parent_scope
== NULL
)
5846 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5850 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5852 struct objfile
*objfile
= cu
->objfile
;
5854 char *actual_name
= NULL
;
5856 int built_actual_name
= 0;
5858 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5860 actual_name
= partial_die_full_name (pdi
, cu
);
5862 built_actual_name
= 1;
5864 if (actual_name
== NULL
)
5865 actual_name
= pdi
->name
;
5869 case DW_TAG_subprogram
:
5870 if (pdi
->is_external
|| cu
->language
== language_ada
)
5872 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5873 of the global scope. But in Ada, we want to be able to access
5874 nested procedures globally. So all Ada subprograms are stored
5875 in the global scope. */
5876 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5877 mst_text, objfile); */
5878 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5880 VAR_DOMAIN
, LOC_BLOCK
,
5881 &objfile
->global_psymbols
,
5882 0, pdi
->lowpc
+ baseaddr
,
5883 cu
->language
, objfile
);
5887 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5888 mst_file_text, objfile); */
5889 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5891 VAR_DOMAIN
, LOC_BLOCK
,
5892 &objfile
->static_psymbols
,
5893 0, pdi
->lowpc
+ baseaddr
,
5894 cu
->language
, objfile
);
5897 case DW_TAG_constant
:
5899 struct psymbol_allocation_list
*list
;
5901 if (pdi
->is_external
)
5902 list
= &objfile
->global_psymbols
;
5904 list
= &objfile
->static_psymbols
;
5905 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5906 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
5907 list
, 0, 0, cu
->language
, objfile
);
5910 case DW_TAG_variable
:
5912 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5916 && !dwarf2_per_objfile
->has_section_at_zero
)
5918 /* A global or static variable may also have been stripped
5919 out by the linker if unused, in which case its address
5920 will be nullified; do not add such variables into partial
5921 symbol table then. */
5923 else if (pdi
->is_external
)
5926 Don't enter into the minimal symbol tables as there is
5927 a minimal symbol table entry from the ELF symbols already.
5928 Enter into partial symbol table if it has a location
5929 descriptor or a type.
5930 If the location descriptor is missing, new_symbol will create
5931 a LOC_UNRESOLVED symbol, the address of the variable will then
5932 be determined from the minimal symbol table whenever the variable
5934 The address for the partial symbol table entry is not
5935 used by GDB, but it comes in handy for debugging partial symbol
5938 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5939 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5941 VAR_DOMAIN
, LOC_STATIC
,
5942 &objfile
->global_psymbols
,
5944 cu
->language
, objfile
);
5948 /* Static Variable. Skip symbols without location descriptors. */
5949 if (pdi
->d
.locdesc
== NULL
)
5951 if (built_actual_name
)
5952 xfree (actual_name
);
5955 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5956 mst_file_data, objfile); */
5957 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5959 VAR_DOMAIN
, LOC_STATIC
,
5960 &objfile
->static_psymbols
,
5962 cu
->language
, objfile
);
5965 case DW_TAG_typedef
:
5966 case DW_TAG_base_type
:
5967 case DW_TAG_subrange_type
:
5968 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5970 VAR_DOMAIN
, LOC_TYPEDEF
,
5971 &objfile
->static_psymbols
,
5972 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5974 case DW_TAG_namespace
:
5975 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5977 VAR_DOMAIN
, LOC_TYPEDEF
,
5978 &objfile
->global_psymbols
,
5979 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
5981 case DW_TAG_class_type
:
5982 case DW_TAG_interface_type
:
5983 case DW_TAG_structure_type
:
5984 case DW_TAG_union_type
:
5985 case DW_TAG_enumeration_type
:
5986 /* Skip external references. The DWARF standard says in the section
5987 about "Structure, Union, and Class Type Entries": "An incomplete
5988 structure, union or class type is represented by a structure,
5989 union or class entry that does not have a byte size attribute
5990 and that has a DW_AT_declaration attribute." */
5991 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
5993 if (built_actual_name
)
5994 xfree (actual_name
);
5998 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5999 static vs. global. */
6000 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6002 STRUCT_DOMAIN
, LOC_TYPEDEF
,
6003 (cu
->language
== language_cplus
6004 || cu
->language
== language_java
)
6005 ? &objfile
->global_psymbols
6006 : &objfile
->static_psymbols
,
6007 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6010 case DW_TAG_enumerator
:
6011 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6013 VAR_DOMAIN
, LOC_CONST
,
6014 (cu
->language
== language_cplus
6015 || cu
->language
== language_java
)
6016 ? &objfile
->global_psymbols
6017 : &objfile
->static_psymbols
,
6018 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6024 if (built_actual_name
)
6025 xfree (actual_name
);
6028 /* Read a partial die corresponding to a namespace; also, add a symbol
6029 corresponding to that namespace to the symbol table. NAMESPACE is
6030 the name of the enclosing namespace. */
6033 add_partial_namespace (struct partial_die_info
*pdi
,
6034 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6035 int need_pc
, struct dwarf2_cu
*cu
)
6037 /* Add a symbol for the namespace. */
6039 add_partial_symbol (pdi
, cu
);
6041 /* Now scan partial symbols in that namespace. */
6043 if (pdi
->has_children
)
6044 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6047 /* Read a partial die corresponding to a Fortran module. */
6050 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6051 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6053 /* Now scan partial symbols in that module. */
6055 if (pdi
->has_children
)
6056 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6059 /* Read a partial die corresponding to a subprogram and create a partial
6060 symbol for that subprogram. When the CU language allows it, this
6061 routine also defines a partial symbol for each nested subprogram
6062 that this subprogram contains.
6064 DIE my also be a lexical block, in which case we simply search
6065 recursively for suprograms defined inside that lexical block.
6066 Again, this is only performed when the CU language allows this
6067 type of definitions. */
6070 add_partial_subprogram (struct partial_die_info
*pdi
,
6071 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6072 int need_pc
, struct dwarf2_cu
*cu
)
6074 if (pdi
->tag
== DW_TAG_subprogram
)
6076 if (pdi
->has_pc_info
)
6078 if (pdi
->lowpc
< *lowpc
)
6079 *lowpc
= pdi
->lowpc
;
6080 if (pdi
->highpc
> *highpc
)
6081 *highpc
= pdi
->highpc
;
6085 struct objfile
*objfile
= cu
->objfile
;
6087 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6088 SECT_OFF_TEXT (objfile
));
6089 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6090 pdi
->lowpc
+ baseaddr
,
6091 pdi
->highpc
- 1 + baseaddr
,
6092 cu
->per_cu
->v
.psymtab
);
6096 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6098 if (!pdi
->is_declaration
)
6099 /* Ignore subprogram DIEs that do not have a name, they are
6100 illegal. Do not emit a complaint at this point, we will
6101 do so when we convert this psymtab into a symtab. */
6103 add_partial_symbol (pdi
, cu
);
6107 if (! pdi
->has_children
)
6110 if (cu
->language
== language_ada
)
6112 pdi
= pdi
->die_child
;
6115 fixup_partial_die (pdi
, cu
);
6116 if (pdi
->tag
== DW_TAG_subprogram
6117 || pdi
->tag
== DW_TAG_lexical_block
)
6118 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6119 pdi
= pdi
->die_sibling
;
6124 /* Read a partial die corresponding to an enumeration type. */
6127 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6128 struct dwarf2_cu
*cu
)
6130 struct partial_die_info
*pdi
;
6132 if (enum_pdi
->name
!= NULL
)
6133 add_partial_symbol (enum_pdi
, cu
);
6135 pdi
= enum_pdi
->die_child
;
6138 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6139 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6141 add_partial_symbol (pdi
, cu
);
6142 pdi
= pdi
->die_sibling
;
6146 /* Return the initial uleb128 in the die at INFO_PTR. */
6149 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6151 unsigned int bytes_read
;
6153 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6156 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6157 Return the corresponding abbrev, or NULL if the number is zero (indicating
6158 an empty DIE). In either case *BYTES_READ will be set to the length of
6159 the initial number. */
6161 static struct abbrev_info
*
6162 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6163 struct dwarf2_cu
*cu
)
6165 bfd
*abfd
= cu
->objfile
->obfd
;
6166 unsigned int abbrev_number
;
6167 struct abbrev_info
*abbrev
;
6169 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6171 if (abbrev_number
== 0)
6174 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6177 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6178 abbrev_number
, bfd_get_filename (abfd
));
6184 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6185 Returns a pointer to the end of a series of DIEs, terminated by an empty
6186 DIE. Any children of the skipped DIEs will also be skipped. */
6189 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6191 struct dwarf2_cu
*cu
= reader
->cu
;
6192 struct abbrev_info
*abbrev
;
6193 unsigned int bytes_read
;
6197 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6199 return info_ptr
+ bytes_read
;
6201 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6205 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6206 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6207 abbrev corresponding to that skipped uleb128 should be passed in
6208 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6212 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6213 struct abbrev_info
*abbrev
)
6215 unsigned int bytes_read
;
6216 struct attribute attr
;
6217 bfd
*abfd
= reader
->abfd
;
6218 struct dwarf2_cu
*cu
= reader
->cu
;
6219 gdb_byte
*buffer
= reader
->buffer
;
6220 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6221 gdb_byte
*start_info_ptr
= info_ptr
;
6222 unsigned int form
, i
;
6224 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6226 /* The only abbrev we care about is DW_AT_sibling. */
6227 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6229 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6230 if (attr
.form
== DW_FORM_ref_addr
)
6231 complaint (&symfile_complaints
,
6232 _("ignoring absolute DW_AT_sibling"));
6234 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6237 /* If it isn't DW_AT_sibling, skip this attribute. */
6238 form
= abbrev
->attrs
[i
].form
;
6242 case DW_FORM_ref_addr
:
6243 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6244 and later it is offset sized. */
6245 if (cu
->header
.version
== 2)
6246 info_ptr
+= cu
->header
.addr_size
;
6248 info_ptr
+= cu
->header
.offset_size
;
6250 case DW_FORM_GNU_ref_alt
:
6251 info_ptr
+= cu
->header
.offset_size
;
6254 info_ptr
+= cu
->header
.addr_size
;
6261 case DW_FORM_flag_present
:
6273 case DW_FORM_ref_sig8
:
6276 case DW_FORM_string
:
6277 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6278 info_ptr
+= bytes_read
;
6280 case DW_FORM_sec_offset
:
6282 case DW_FORM_GNU_strp_alt
:
6283 info_ptr
+= cu
->header
.offset_size
;
6285 case DW_FORM_exprloc
:
6287 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6288 info_ptr
+= bytes_read
;
6290 case DW_FORM_block1
:
6291 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6293 case DW_FORM_block2
:
6294 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6296 case DW_FORM_block4
:
6297 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6301 case DW_FORM_ref_udata
:
6302 case DW_FORM_GNU_addr_index
:
6303 case DW_FORM_GNU_str_index
:
6304 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6306 case DW_FORM_indirect
:
6307 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6308 info_ptr
+= bytes_read
;
6309 /* We need to continue parsing from here, so just go back to
6311 goto skip_attribute
;
6314 error (_("Dwarf Error: Cannot handle %s "
6315 "in DWARF reader [in module %s]"),
6316 dwarf_form_name (form
),
6317 bfd_get_filename (abfd
));
6321 if (abbrev
->has_children
)
6322 return skip_children (reader
, info_ptr
);
6327 /* Locate ORIG_PDI's sibling.
6328 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6331 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6332 struct partial_die_info
*orig_pdi
,
6335 /* Do we know the sibling already? */
6337 if (orig_pdi
->sibling
)
6338 return orig_pdi
->sibling
;
6340 /* Are there any children to deal with? */
6342 if (!orig_pdi
->has_children
)
6345 /* Skip the children the long way. */
6347 return skip_children (reader
, info_ptr
);
6350 /* Expand this partial symbol table into a full symbol table. */
6353 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
6359 warning (_("bug: psymtab for %s is already read in."),
6366 printf_filtered (_("Reading in symbols for %s..."),
6368 gdb_flush (gdb_stdout
);
6371 /* Restore our global data. */
6372 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
6373 dwarf2_objfile_data_key
);
6375 /* If this psymtab is constructed from a debug-only objfile, the
6376 has_section_at_zero flag will not necessarily be correct. We
6377 can get the correct value for this flag by looking at the data
6378 associated with the (presumably stripped) associated objfile. */
6379 if (pst
->objfile
->separate_debug_objfile_backlink
)
6381 struct dwarf2_per_objfile
*dpo_backlink
6382 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
6383 dwarf2_objfile_data_key
);
6385 dwarf2_per_objfile
->has_section_at_zero
6386 = dpo_backlink
->has_section_at_zero
;
6389 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6391 psymtab_to_symtab_1 (pst
);
6393 /* Finish up the debug error message. */
6395 printf_filtered (_("done.\n"));
6399 process_cu_includes ();
6402 /* Reading in full CUs. */
6404 /* Add PER_CU to the queue. */
6407 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6408 enum language pretend_language
)
6410 struct dwarf2_queue_item
*item
;
6413 item
= xmalloc (sizeof (*item
));
6414 item
->per_cu
= per_cu
;
6415 item
->pretend_language
= pretend_language
;
6418 if (dwarf2_queue
== NULL
)
6419 dwarf2_queue
= item
;
6421 dwarf2_queue_tail
->next
= item
;
6423 dwarf2_queue_tail
= item
;
6426 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6427 unit and add it to our queue.
6428 The result is non-zero if PER_CU was queued, otherwise the result is zero
6429 meaning either PER_CU is already queued or it is already loaded. */
6432 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6433 struct dwarf2_per_cu_data
*per_cu
,
6434 enum language pretend_language
)
6436 /* We may arrive here during partial symbol reading, if we need full
6437 DIEs to process an unusual case (e.g. template arguments). Do
6438 not queue PER_CU, just tell our caller to load its DIEs. */
6439 if (dwarf2_per_objfile
->reading_partial_symbols
)
6441 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6446 /* Mark the dependence relation so that we don't flush PER_CU
6448 dwarf2_add_dependence (this_cu
, per_cu
);
6450 /* If it's already on the queue, we have nothing to do. */
6454 /* If the compilation unit is already loaded, just mark it as
6456 if (per_cu
->cu
!= NULL
)
6458 per_cu
->cu
->last_used
= 0;
6462 /* Add it to the queue. */
6463 queue_comp_unit (per_cu
, pretend_language
);
6468 /* Process the queue. */
6471 process_queue (void)
6473 struct dwarf2_queue_item
*item
, *next_item
;
6475 if (dwarf2_read_debug
)
6477 fprintf_unfiltered (gdb_stdlog
,
6478 "Expanding one or more symtabs of objfile %s ...\n",
6479 dwarf2_per_objfile
->objfile
->name
);
6482 /* The queue starts out with one item, but following a DIE reference
6483 may load a new CU, adding it to the end of the queue. */
6484 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6486 if (dwarf2_per_objfile
->using_index
6487 ? !item
->per_cu
->v
.quick
->symtab
6488 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6490 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6492 if (dwarf2_read_debug
)
6494 fprintf_unfiltered (gdb_stdlog
,
6495 "Expanding symtab of %s at offset 0x%x\n",
6496 per_cu
->is_debug_types
? "TU" : "CU",
6497 per_cu
->offset
.sect_off
);
6500 if (per_cu
->is_debug_types
)
6501 process_full_type_unit (per_cu
, item
->pretend_language
);
6503 process_full_comp_unit (per_cu
, item
->pretend_language
);
6505 if (dwarf2_read_debug
)
6507 fprintf_unfiltered (gdb_stdlog
,
6508 "Done expanding %s at offset 0x%x\n",
6509 per_cu
->is_debug_types
? "TU" : "CU",
6510 per_cu
->offset
.sect_off
);
6514 item
->per_cu
->queued
= 0;
6515 next_item
= item
->next
;
6519 dwarf2_queue_tail
= NULL
;
6521 if (dwarf2_read_debug
)
6523 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6524 dwarf2_per_objfile
->objfile
->name
);
6528 /* Free all allocated queue entries. This function only releases anything if
6529 an error was thrown; if the queue was processed then it would have been
6530 freed as we went along. */
6533 dwarf2_release_queue (void *dummy
)
6535 struct dwarf2_queue_item
*item
, *last
;
6537 item
= dwarf2_queue
;
6540 /* Anything still marked queued is likely to be in an
6541 inconsistent state, so discard it. */
6542 if (item
->per_cu
->queued
)
6544 if (item
->per_cu
->cu
!= NULL
)
6545 free_one_cached_comp_unit (item
->per_cu
);
6546 item
->per_cu
->queued
= 0;
6554 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6557 /* Read in full symbols for PST, and anything it depends on. */
6560 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6562 struct dwarf2_per_cu_data
*per_cu
;
6568 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6569 if (!pst
->dependencies
[i
]->readin
6570 && pst
->dependencies
[i
]->user
== NULL
)
6572 /* Inform about additional files that need to be read in. */
6575 /* FIXME: i18n: Need to make this a single string. */
6576 fputs_filtered (" ", gdb_stdout
);
6578 fputs_filtered ("and ", gdb_stdout
);
6580 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6581 wrap_here (""); /* Flush output. */
6582 gdb_flush (gdb_stdout
);
6584 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6587 per_cu
= pst
->read_symtab_private
;
6591 /* It's an include file, no symbols to read for it.
6592 Everything is in the parent symtab. */
6597 dw2_do_instantiate_symtab (per_cu
);
6600 /* Trivial hash function for die_info: the hash value of a DIE
6601 is its offset in .debug_info for this objfile. */
6604 die_hash (const void *item
)
6606 const struct die_info
*die
= item
;
6608 return die
->offset
.sect_off
;
6611 /* Trivial comparison function for die_info structures: two DIEs
6612 are equal if they have the same offset. */
6615 die_eq (const void *item_lhs
, const void *item_rhs
)
6617 const struct die_info
*die_lhs
= item_lhs
;
6618 const struct die_info
*die_rhs
= item_rhs
;
6620 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6623 /* die_reader_func for load_full_comp_unit.
6624 This is identical to read_signatured_type_reader,
6625 but is kept separate for now. */
6628 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6630 struct die_info
*comp_unit_die
,
6634 struct dwarf2_cu
*cu
= reader
->cu
;
6635 enum language
*language_ptr
= data
;
6637 gdb_assert (cu
->die_hash
== NULL
);
6639 htab_create_alloc_ex (cu
->header
.length
/ 12,
6643 &cu
->comp_unit_obstack
,
6644 hashtab_obstack_allocate
,
6645 dummy_obstack_deallocate
);
6648 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6649 &info_ptr
, comp_unit_die
);
6650 cu
->dies
= comp_unit_die
;
6651 /* comp_unit_die is not stored in die_hash, no need. */
6653 /* We try not to read any attributes in this function, because not
6654 all CUs needed for references have been loaded yet, and symbol
6655 table processing isn't initialized. But we have to set the CU language,
6656 or we won't be able to build types correctly.
6657 Similarly, if we do not read the producer, we can not apply
6658 producer-specific interpretation. */
6659 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6662 /* Load the DIEs associated with PER_CU into memory. */
6665 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6666 enum language pretend_language
)
6668 gdb_assert (! this_cu
->is_debug_types
);
6670 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6671 load_full_comp_unit_reader
, &pretend_language
);
6674 /* Add a DIE to the delayed physname list. */
6677 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6678 const char *name
, struct die_info
*die
,
6679 struct dwarf2_cu
*cu
)
6681 struct delayed_method_info mi
;
6683 mi
.fnfield_index
= fnfield_index
;
6687 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6690 /* A cleanup for freeing the delayed method list. */
6693 free_delayed_list (void *ptr
)
6695 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6696 if (cu
->method_list
!= NULL
)
6698 VEC_free (delayed_method_info
, cu
->method_list
);
6699 cu
->method_list
= NULL
;
6703 /* Compute the physnames of any methods on the CU's method list.
6705 The computation of method physnames is delayed in order to avoid the
6706 (bad) condition that one of the method's formal parameters is of an as yet
6710 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6713 struct delayed_method_info
*mi
;
6714 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6716 const char *physname
;
6717 struct fn_fieldlist
*fn_flp
6718 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6719 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6720 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6724 /* Go objects should be embedded in a DW_TAG_module DIE,
6725 and it's not clear if/how imported objects will appear.
6726 To keep Go support simple until that's worked out,
6727 go back through what we've read and create something usable.
6728 We could do this while processing each DIE, and feels kinda cleaner,
6729 but that way is more invasive.
6730 This is to, for example, allow the user to type "p var" or "b main"
6731 without having to specify the package name, and allow lookups
6732 of module.object to work in contexts that use the expression
6736 fixup_go_packaging (struct dwarf2_cu
*cu
)
6738 char *package_name
= NULL
;
6739 struct pending
*list
;
6742 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6744 for (i
= 0; i
< list
->nsyms
; ++i
)
6746 struct symbol
*sym
= list
->symbol
[i
];
6748 if (SYMBOL_LANGUAGE (sym
) == language_go
6749 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6751 char *this_package_name
= go_symbol_package_name (sym
);
6753 if (this_package_name
== NULL
)
6755 if (package_name
== NULL
)
6756 package_name
= this_package_name
;
6759 if (strcmp (package_name
, this_package_name
) != 0)
6760 complaint (&symfile_complaints
,
6761 _("Symtab %s has objects from two different Go packages: %s and %s"),
6762 (SYMBOL_SYMTAB (sym
)
6763 && SYMBOL_SYMTAB (sym
)->filename
6764 ? SYMBOL_SYMTAB (sym
)->filename
6765 : cu
->objfile
->name
),
6766 this_package_name
, package_name
);
6767 xfree (this_package_name
);
6773 if (package_name
!= NULL
)
6775 struct objfile
*objfile
= cu
->objfile
;
6776 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6777 package_name
, objfile
);
6780 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6782 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6783 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6784 SYMBOL_SET_NAMES (sym
, package_name
, strlen (package_name
), 1, objfile
);
6785 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6786 e.g., "main" finds the "main" module and not C's main(). */
6787 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6788 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6789 SYMBOL_TYPE (sym
) = type
;
6791 add_symbol_to_list (sym
, &global_symbols
);
6793 xfree (package_name
);
6797 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6799 /* Return the symtab for PER_CU. This works properly regardless of
6800 whether we're using the index or psymtabs. */
6802 static struct symtab
*
6803 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6805 return (dwarf2_per_objfile
->using_index
6806 ? per_cu
->v
.quick
->symtab
6807 : per_cu
->v
.psymtab
->symtab
);
6810 /* A helper function for computing the list of all symbol tables
6811 included by PER_CU. */
6814 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6815 htab_t all_children
,
6816 struct dwarf2_per_cu_data
*per_cu
)
6820 struct dwarf2_per_cu_data
*iter
;
6822 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6825 /* This inclusion and its children have been processed. */
6830 /* Only add a CU if it has a symbol table. */
6831 if (get_symtab (per_cu
) != NULL
)
6832 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6835 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
, ix
, iter
);
6837 recursively_compute_inclusions (result
, all_children
, iter
);
6840 /* Compute the symtab 'includes' fields for the symtab related to
6844 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6846 gdb_assert (! per_cu
->is_debug_types
);
6848 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
))
6851 struct dwarf2_per_cu_data
*iter
;
6852 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6853 htab_t all_children
;
6854 struct symtab
*symtab
= get_symtab (per_cu
);
6856 /* If we don't have a symtab, we can just skip this case. */
6860 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6861 NULL
, xcalloc
, xfree
);
6864 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->s
.imported_symtabs
,
6867 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6869 /* Now we have a transitive closure of all the included CUs, so
6870 we can convert it to a list of symtabs. */
6871 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6873 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6874 (len
+ 1) * sizeof (struct symtab
*));
6876 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6878 symtab
->includes
[ix
] = get_symtab (iter
);
6879 symtab
->includes
[len
] = NULL
;
6881 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6882 htab_delete (all_children
);
6886 /* Compute the 'includes' field for the symtabs of all the CUs we just
6890 process_cu_includes (void)
6893 struct dwarf2_per_cu_data
*iter
;
6896 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6900 if (! iter
->is_debug_types
)
6901 compute_symtab_includes (iter
);
6904 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6907 /* Generate full symbol information for PER_CU, whose DIEs have
6908 already been loaded into memory. */
6911 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6912 enum language pretend_language
)
6914 struct dwarf2_cu
*cu
= per_cu
->cu
;
6915 struct objfile
*objfile
= per_cu
->objfile
;
6916 CORE_ADDR lowpc
, highpc
;
6917 struct symtab
*symtab
;
6918 struct cleanup
*back_to
, *delayed_list_cleanup
;
6920 struct block
*static_block
;
6922 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6925 back_to
= make_cleanup (really_free_pendings
, NULL
);
6926 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6928 cu
->list_in_scope
= &file_symbols
;
6930 cu
->language
= pretend_language
;
6931 cu
->language_defn
= language_def (cu
->language
);
6933 /* Do line number decoding in read_file_scope () */
6934 process_die (cu
->dies
, cu
);
6936 /* For now fudge the Go package. */
6937 if (cu
->language
== language_go
)
6938 fixup_go_packaging (cu
);
6940 /* Now that we have processed all the DIEs in the CU, all the types
6941 should be complete, and it should now be safe to compute all of the
6943 compute_delayed_physnames (cu
);
6944 do_cleanups (delayed_list_cleanup
);
6946 /* Some compilers don't define a DW_AT_high_pc attribute for the
6947 compilation unit. If the DW_AT_high_pc is missing, synthesize
6948 it, by scanning the DIE's below the compilation unit. */
6949 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
6952 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
6953 per_cu
->s
.imported_symtabs
!= NULL
);
6955 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6956 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6957 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6958 addrmap to help ensure it has an accurate map of pc values belonging to
6960 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
6962 symtab
= end_symtab_from_static_block (static_block
, objfile
,
6963 SECT_OFF_TEXT (objfile
), 0);
6967 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
6969 /* Set symtab language to language from DW_AT_language. If the
6970 compilation is from a C file generated by language preprocessors, do
6971 not set the language if it was already deduced by start_subfile. */
6972 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
6973 symtab
->language
= cu
->language
;
6975 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6976 produce DW_AT_location with location lists but it can be possibly
6977 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6978 there were bugs in prologue debug info, fixed later in GCC-4.5
6979 by "unwind info for epilogues" patch (which is not directly related).
6981 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6982 needed, it would be wrong due to missing DW_AT_producer there.
6984 Still one can confuse GDB by using non-standard GCC compilation
6985 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6987 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
6988 symtab
->locations_valid
= 1;
6990 if (gcc_4_minor
>= 5)
6991 symtab
->epilogue_unwind_valid
= 1;
6993 symtab
->call_site_htab
= cu
->call_site_htab
;
6996 if (dwarf2_per_objfile
->using_index
)
6997 per_cu
->v
.quick
->symtab
= symtab
;
7000 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7001 pst
->symtab
= symtab
;
7005 /* Push it for inclusion processing later. */
7006 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7008 do_cleanups (back_to
);
7011 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7012 already been loaded into memory. */
7015 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7016 enum language pretend_language
)
7018 struct dwarf2_cu
*cu
= per_cu
->cu
;
7019 struct objfile
*objfile
= per_cu
->objfile
;
7020 struct symtab
*symtab
;
7021 struct cleanup
*back_to
, *delayed_list_cleanup
;
7024 back_to
= make_cleanup (really_free_pendings
, NULL
);
7025 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7027 cu
->list_in_scope
= &file_symbols
;
7029 cu
->language
= pretend_language
;
7030 cu
->language_defn
= language_def (cu
->language
);
7032 /* The symbol tables are set up in read_type_unit_scope. */
7033 process_die (cu
->dies
, cu
);
7035 /* For now fudge the Go package. */
7036 if (cu
->language
== language_go
)
7037 fixup_go_packaging (cu
);
7039 /* Now that we have processed all the DIEs in the CU, all the types
7040 should be complete, and it should now be safe to compute all of the
7042 compute_delayed_physnames (cu
);
7043 do_cleanups (delayed_list_cleanup
);
7045 /* TUs share symbol tables.
7046 If this is the first TU to use this symtab, complete the construction
7047 of it with end_expandable_symtab. Otherwise, complete the addition of
7048 this TU's symbols to the existing symtab. */
7049 if (per_cu
->s
.type_unit_group
->primary_symtab
== NULL
)
7051 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7052 per_cu
->s
.type_unit_group
->primary_symtab
= symtab
;
7056 /* Set symtab language to language from DW_AT_language. If the
7057 compilation is from a C file generated by language preprocessors,
7058 do not set the language if it was already deduced by
7060 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7061 symtab
->language
= cu
->language
;
7066 augment_type_symtab (objfile
,
7067 per_cu
->s
.type_unit_group
->primary_symtab
);
7068 symtab
= per_cu
->s
.type_unit_group
->primary_symtab
;
7071 if (dwarf2_per_objfile
->using_index
)
7072 per_cu
->v
.quick
->symtab
= symtab
;
7075 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7076 pst
->symtab
= symtab
;
7080 do_cleanups (back_to
);
7083 /* Process an imported unit DIE. */
7086 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7088 struct attribute
*attr
;
7090 /* For now we don't handle imported units in type units. */
7091 if (cu
->per_cu
->is_debug_types
)
7093 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7094 " supported in type units [in module %s]"),
7098 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7101 struct dwarf2_per_cu_data
*per_cu
;
7102 struct symtab
*imported_symtab
;
7106 offset
= dwarf2_get_ref_die_offset (attr
);
7107 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7108 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7110 /* Queue the unit, if needed. */
7111 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7112 load_full_comp_unit (per_cu
, cu
->language
);
7114 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->s
.imported_symtabs
,
7119 /* Process a die and its children. */
7122 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7126 case DW_TAG_padding
:
7128 case DW_TAG_compile_unit
:
7129 case DW_TAG_partial_unit
:
7130 read_file_scope (die
, cu
);
7132 case DW_TAG_type_unit
:
7133 read_type_unit_scope (die
, cu
);
7135 case DW_TAG_subprogram
:
7136 case DW_TAG_inlined_subroutine
:
7137 read_func_scope (die
, cu
);
7139 case DW_TAG_lexical_block
:
7140 case DW_TAG_try_block
:
7141 case DW_TAG_catch_block
:
7142 read_lexical_block_scope (die
, cu
);
7144 case DW_TAG_GNU_call_site
:
7145 read_call_site_scope (die
, cu
);
7147 case DW_TAG_class_type
:
7148 case DW_TAG_interface_type
:
7149 case DW_TAG_structure_type
:
7150 case DW_TAG_union_type
:
7151 process_structure_scope (die
, cu
);
7153 case DW_TAG_enumeration_type
:
7154 process_enumeration_scope (die
, cu
);
7157 /* These dies have a type, but processing them does not create
7158 a symbol or recurse to process the children. Therefore we can
7159 read them on-demand through read_type_die. */
7160 case DW_TAG_subroutine_type
:
7161 case DW_TAG_set_type
:
7162 case DW_TAG_array_type
:
7163 case DW_TAG_pointer_type
:
7164 case DW_TAG_ptr_to_member_type
:
7165 case DW_TAG_reference_type
:
7166 case DW_TAG_string_type
:
7169 case DW_TAG_base_type
:
7170 case DW_TAG_subrange_type
:
7171 case DW_TAG_typedef
:
7172 /* Add a typedef symbol for the type definition, if it has a
7174 new_symbol (die
, read_type_die (die
, cu
), cu
);
7176 case DW_TAG_common_block
:
7177 read_common_block (die
, cu
);
7179 case DW_TAG_common_inclusion
:
7181 case DW_TAG_namespace
:
7182 processing_has_namespace_info
= 1;
7183 read_namespace (die
, cu
);
7186 processing_has_namespace_info
= 1;
7187 read_module (die
, cu
);
7189 case DW_TAG_imported_declaration
:
7190 case DW_TAG_imported_module
:
7191 processing_has_namespace_info
= 1;
7192 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7193 || cu
->language
!= language_fortran
))
7194 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7195 dwarf_tag_name (die
->tag
));
7196 read_import_statement (die
, cu
);
7199 case DW_TAG_imported_unit
:
7200 process_imported_unit_die (die
, cu
);
7204 new_symbol (die
, NULL
, cu
);
7209 /* A helper function for dwarf2_compute_name which determines whether DIE
7210 needs to have the name of the scope prepended to the name listed in the
7214 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7216 struct attribute
*attr
;
7220 case DW_TAG_namespace
:
7221 case DW_TAG_typedef
:
7222 case DW_TAG_class_type
:
7223 case DW_TAG_interface_type
:
7224 case DW_TAG_structure_type
:
7225 case DW_TAG_union_type
:
7226 case DW_TAG_enumeration_type
:
7227 case DW_TAG_enumerator
:
7228 case DW_TAG_subprogram
:
7232 case DW_TAG_variable
:
7233 case DW_TAG_constant
:
7234 /* We only need to prefix "globally" visible variables. These include
7235 any variable marked with DW_AT_external or any variable that
7236 lives in a namespace. [Variables in anonymous namespaces
7237 require prefixing, but they are not DW_AT_external.] */
7239 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7241 struct dwarf2_cu
*spec_cu
= cu
;
7243 return die_needs_namespace (die_specification (die
, &spec_cu
),
7247 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7248 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7249 && die
->parent
->tag
!= DW_TAG_module
)
7251 /* A variable in a lexical block of some kind does not need a
7252 namespace, even though in C++ such variables may be external
7253 and have a mangled name. */
7254 if (die
->parent
->tag
== DW_TAG_lexical_block
7255 || die
->parent
->tag
== DW_TAG_try_block
7256 || die
->parent
->tag
== DW_TAG_catch_block
7257 || die
->parent
->tag
== DW_TAG_subprogram
)
7266 /* Retrieve the last character from a mem_file. */
7269 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7271 char *last_char_p
= (char *) object
;
7274 *last_char_p
= buffer
[length
- 1];
7277 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7278 compute the physname for the object, which include a method's:
7279 - formal parameters (C++/Java),
7280 - receiver type (Go),
7281 - return type (Java).
7283 The term "physname" is a bit confusing.
7284 For C++, for example, it is the demangled name.
7285 For Go, for example, it's the mangled name.
7287 For Ada, return the DIE's linkage name rather than the fully qualified
7288 name. PHYSNAME is ignored..
7290 The result is allocated on the objfile_obstack and canonicalized. */
7293 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
7296 struct objfile
*objfile
= cu
->objfile
;
7299 name
= dwarf2_name (die
, cu
);
7301 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7302 compute it by typename_concat inside GDB. */
7303 if (cu
->language
== language_ada
7304 || (cu
->language
== language_fortran
&& physname
))
7306 /* For Ada unit, we prefer the linkage name over the name, as
7307 the former contains the exported name, which the user expects
7308 to be able to reference. Ideally, we want the user to be able
7309 to reference this entity using either natural or linkage name,
7310 but we haven't started looking at this enhancement yet. */
7311 struct attribute
*attr
;
7313 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7315 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7316 if (attr
&& DW_STRING (attr
))
7317 return DW_STRING (attr
);
7320 /* These are the only languages we know how to qualify names in. */
7322 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7323 || cu
->language
== language_fortran
))
7325 if (die_needs_namespace (die
, cu
))
7329 struct ui_file
*buf
;
7331 prefix
= determine_prefix (die
, cu
);
7332 buf
= mem_fileopen ();
7333 if (*prefix
!= '\0')
7335 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7338 fputs_unfiltered (prefixed_name
, buf
);
7339 xfree (prefixed_name
);
7342 fputs_unfiltered (name
, buf
);
7344 /* Template parameters may be specified in the DIE's DW_AT_name, or
7345 as children with DW_TAG_template_type_param or
7346 DW_TAG_value_type_param. If the latter, add them to the name
7347 here. If the name already has template parameters, then
7348 skip this step; some versions of GCC emit both, and
7349 it is more efficient to use the pre-computed name.
7351 Something to keep in mind about this process: it is very
7352 unlikely, or in some cases downright impossible, to produce
7353 something that will match the mangled name of a function.
7354 If the definition of the function has the same debug info,
7355 we should be able to match up with it anyway. But fallbacks
7356 using the minimal symbol, for instance to find a method
7357 implemented in a stripped copy of libstdc++, will not work.
7358 If we do not have debug info for the definition, we will have to
7359 match them up some other way.
7361 When we do name matching there is a related problem with function
7362 templates; two instantiated function templates are allowed to
7363 differ only by their return types, which we do not add here. */
7365 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7367 struct attribute
*attr
;
7368 struct die_info
*child
;
7371 die
->building_fullname
= 1;
7373 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7378 struct dwarf2_locexpr_baton
*baton
;
7381 if (child
->tag
!= DW_TAG_template_type_param
7382 && child
->tag
!= DW_TAG_template_value_param
)
7387 fputs_unfiltered ("<", buf
);
7391 fputs_unfiltered (", ", buf
);
7393 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7396 complaint (&symfile_complaints
,
7397 _("template parameter missing DW_AT_type"));
7398 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7401 type
= die_type (child
, cu
);
7403 if (child
->tag
== DW_TAG_template_type_param
)
7405 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7409 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7412 complaint (&symfile_complaints
,
7413 _("template parameter missing "
7414 "DW_AT_const_value"));
7415 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7419 dwarf2_const_value_attr (attr
, type
, name
,
7420 &cu
->comp_unit_obstack
, cu
,
7421 &value
, &bytes
, &baton
);
7423 if (TYPE_NOSIGN (type
))
7424 /* GDB prints characters as NUMBER 'CHAR'. If that's
7425 changed, this can use value_print instead. */
7426 c_printchar (value
, type
, buf
);
7429 struct value_print_options opts
;
7432 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7436 else if (bytes
!= NULL
)
7438 v
= allocate_value (type
);
7439 memcpy (value_contents_writeable (v
), bytes
,
7440 TYPE_LENGTH (type
));
7443 v
= value_from_longest (type
, value
);
7445 /* Specify decimal so that we do not depend on
7447 get_formatted_print_options (&opts
, 'd');
7449 value_print (v
, buf
, &opts
);
7455 die
->building_fullname
= 0;
7459 /* Close the argument list, with a space if necessary
7460 (nested templates). */
7461 char last_char
= '\0';
7462 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7463 if (last_char
== '>')
7464 fputs_unfiltered (" >", buf
);
7466 fputs_unfiltered (">", buf
);
7470 /* For Java and C++ methods, append formal parameter type
7471 information, if PHYSNAME. */
7473 if (physname
&& die
->tag
== DW_TAG_subprogram
7474 && (cu
->language
== language_cplus
7475 || cu
->language
== language_java
))
7477 struct type
*type
= read_type_die (die
, cu
);
7479 c_type_print_args (type
, buf
, 1, cu
->language
,
7480 &type_print_raw_options
);
7482 if (cu
->language
== language_java
)
7484 /* For java, we must append the return type to method
7486 if (die
->tag
== DW_TAG_subprogram
)
7487 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7488 0, 0, &type_print_raw_options
);
7490 else if (cu
->language
== language_cplus
)
7492 /* Assume that an artificial first parameter is
7493 "this", but do not crash if it is not. RealView
7494 marks unnamed (and thus unused) parameters as
7495 artificial; there is no way to differentiate
7497 if (TYPE_NFIELDS (type
) > 0
7498 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7499 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7500 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7502 fputs_unfiltered (" const", buf
);
7506 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7508 ui_file_delete (buf
);
7510 if (cu
->language
== language_cplus
)
7513 = dwarf2_canonicalize_name (name
, cu
,
7514 &objfile
->objfile_obstack
);
7525 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7526 If scope qualifiers are appropriate they will be added. The result
7527 will be allocated on the objfile_obstack, or NULL if the DIE does
7528 not have a name. NAME may either be from a previous call to
7529 dwarf2_name or NULL.
7531 The output string will be canonicalized (if C++/Java). */
7534 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7536 return dwarf2_compute_name (name
, die
, cu
, 0);
7539 /* Construct a physname for the given DIE in CU. NAME may either be
7540 from a previous call to dwarf2_name or NULL. The result will be
7541 allocated on the objfile_objstack or NULL if the DIE does not have a
7544 The output string will be canonicalized (if C++/Java). */
7547 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7549 struct objfile
*objfile
= cu
->objfile
;
7550 struct attribute
*attr
;
7551 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7552 struct cleanup
*back_to
;
7555 /* In this case dwarf2_compute_name is just a shortcut not building anything
7557 if (!die_needs_namespace (die
, cu
))
7558 return dwarf2_compute_name (name
, die
, cu
, 1);
7560 back_to
= make_cleanup (null_cleanup
, NULL
);
7562 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7564 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7566 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7568 if (attr
&& DW_STRING (attr
))
7572 mangled
= DW_STRING (attr
);
7574 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7575 type. It is easier for GDB users to search for such functions as
7576 `name(params)' than `long name(params)'. In such case the minimal
7577 symbol names do not match the full symbol names but for template
7578 functions there is never a need to look up their definition from their
7579 declaration so the only disadvantage remains the minimal symbol
7580 variant `long name(params)' does not have the proper inferior type.
7583 if (cu
->language
== language_go
)
7585 /* This is a lie, but we already lie to the caller new_symbol_full.
7586 new_symbol_full assumes we return the mangled name.
7587 This just undoes that lie until things are cleaned up. */
7592 demangled
= cplus_demangle (mangled
,
7593 (DMGL_PARAMS
| DMGL_ANSI
7594 | (cu
->language
== language_java
7595 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7600 make_cleanup (xfree
, demangled
);
7610 if (canon
== NULL
|| check_physname
)
7612 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7614 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7616 /* It may not mean a bug in GDB. The compiler could also
7617 compute DW_AT_linkage_name incorrectly. But in such case
7618 GDB would need to be bug-to-bug compatible. */
7620 complaint (&symfile_complaints
,
7621 _("Computed physname <%s> does not match demangled <%s> "
7622 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7623 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7625 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7626 is available here - over computed PHYSNAME. It is safer
7627 against both buggy GDB and buggy compilers. */
7641 retval
= obsavestring (retval
, strlen (retval
),
7642 &objfile
->objfile_obstack
);
7644 do_cleanups (back_to
);
7648 /* Read the import statement specified by the given die and record it. */
7651 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7653 struct objfile
*objfile
= cu
->objfile
;
7654 struct attribute
*import_attr
;
7655 struct die_info
*imported_die
, *child_die
;
7656 struct dwarf2_cu
*imported_cu
;
7657 const char *imported_name
;
7658 const char *imported_name_prefix
;
7659 const char *canonical_name
;
7660 const char *import_alias
;
7661 const char *imported_declaration
= NULL
;
7662 const char *import_prefix
;
7663 VEC (const_char_ptr
) *excludes
= NULL
;
7664 struct cleanup
*cleanups
;
7668 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7669 if (import_attr
== NULL
)
7671 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7672 dwarf_tag_name (die
->tag
));
7677 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7678 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7679 if (imported_name
== NULL
)
7681 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7683 The import in the following code:
7697 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7698 <52> DW_AT_decl_file : 1
7699 <53> DW_AT_decl_line : 6
7700 <54> DW_AT_import : <0x75>
7701 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7703 <5b> DW_AT_decl_file : 1
7704 <5c> DW_AT_decl_line : 2
7705 <5d> DW_AT_type : <0x6e>
7707 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7708 <76> DW_AT_byte_size : 4
7709 <77> DW_AT_encoding : 5 (signed)
7711 imports the wrong die ( 0x75 instead of 0x58 ).
7712 This case will be ignored until the gcc bug is fixed. */
7716 /* Figure out the local name after import. */
7717 import_alias
= dwarf2_name (die
, cu
);
7719 /* Figure out where the statement is being imported to. */
7720 import_prefix
= determine_prefix (die
, cu
);
7722 /* Figure out what the scope of the imported die is and prepend it
7723 to the name of the imported die. */
7724 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7726 if (imported_die
->tag
!= DW_TAG_namespace
7727 && imported_die
->tag
!= DW_TAG_module
)
7729 imported_declaration
= imported_name
;
7730 canonical_name
= imported_name_prefix
;
7732 else if (strlen (imported_name_prefix
) > 0)
7734 temp
= alloca (strlen (imported_name_prefix
)
7735 + 2 + strlen (imported_name
) + 1);
7736 strcpy (temp
, imported_name_prefix
);
7737 strcat (temp
, "::");
7738 strcat (temp
, imported_name
);
7739 canonical_name
= temp
;
7742 canonical_name
= imported_name
;
7744 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7746 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7747 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7748 child_die
= sibling_die (child_die
))
7750 /* DWARF-4: A Fortran use statement with a “rename list” may be
7751 represented by an imported module entry with an import attribute
7752 referring to the module and owned entries corresponding to those
7753 entities that are renamed as part of being imported. */
7755 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7757 complaint (&symfile_complaints
,
7758 _("child DW_TAG_imported_declaration expected "
7759 "- DIE at 0x%x [in module %s]"),
7760 child_die
->offset
.sect_off
, objfile
->name
);
7764 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7765 if (import_attr
== NULL
)
7767 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7768 dwarf_tag_name (child_die
->tag
));
7773 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7775 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7776 if (imported_name
== NULL
)
7778 complaint (&symfile_complaints
,
7779 _("child DW_TAG_imported_declaration has unknown "
7780 "imported name - DIE at 0x%x [in module %s]"),
7781 child_die
->offset
.sect_off
, objfile
->name
);
7785 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7787 process_die (child_die
, cu
);
7790 cp_add_using_directive (import_prefix
,
7793 imported_declaration
,
7795 &objfile
->objfile_obstack
);
7797 do_cleanups (cleanups
);
7800 /* Cleanup function for handle_DW_AT_stmt_list. */
7803 free_cu_line_header (void *arg
)
7805 struct dwarf2_cu
*cu
= arg
;
7807 free_line_header (cu
->line_header
);
7808 cu
->line_header
= NULL
;
7811 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7812 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7813 this, it was first present in GCC release 4.3.0. */
7816 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7818 if (!cu
->checked_producer
)
7819 check_producer (cu
);
7821 return cu
->producer_is_gcc_lt_4_3
;
7825 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7826 char **name
, char **comp_dir
)
7828 struct attribute
*attr
;
7833 /* Find the filename. Do not use dwarf2_name here, since the filename
7834 is not a source language identifier. */
7835 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7838 *name
= DW_STRING (attr
);
7841 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7843 *comp_dir
= DW_STRING (attr
);
7844 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
7845 && IS_ABSOLUTE_PATH (*name
))
7847 *comp_dir
= ldirname (*name
);
7848 if (*comp_dir
!= NULL
)
7849 make_cleanup (xfree
, *comp_dir
);
7851 if (*comp_dir
!= NULL
)
7853 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7854 directory, get rid of it. */
7855 char *cp
= strchr (*comp_dir
, ':');
7857 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7862 *name
= "<unknown>";
7865 /* Handle DW_AT_stmt_list for a compilation unit.
7866 DIE is the DW_TAG_compile_unit die for CU.
7867 COMP_DIR is the compilation directory.
7868 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7871 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7872 const char *comp_dir
)
7874 struct attribute
*attr
;
7876 gdb_assert (! cu
->per_cu
->is_debug_types
);
7878 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7881 unsigned int line_offset
= DW_UNSND (attr
);
7882 struct line_header
*line_header
7883 = dwarf_decode_line_header (line_offset
, cu
);
7887 cu
->line_header
= line_header
;
7888 make_cleanup (free_cu_line_header
, cu
);
7889 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7894 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7897 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7899 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7900 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7901 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7902 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7903 struct attribute
*attr
;
7905 char *comp_dir
= NULL
;
7906 struct die_info
*child_die
;
7907 bfd
*abfd
= objfile
->obfd
;
7910 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7912 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7914 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7915 from finish_block. */
7916 if (lowpc
== ((CORE_ADDR
) -1))
7921 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7923 prepare_one_comp_unit (cu
, die
, cu
->language
);
7925 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7926 standardised yet. As a workaround for the language detection we fall
7927 back to the DW_AT_producer string. */
7928 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7929 cu
->language
= language_opencl
;
7931 /* Similar hack for Go. */
7932 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7933 set_cu_language (DW_LANG_Go
, cu
);
7935 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7937 /* Decode line number information if present. We do this before
7938 processing child DIEs, so that the line header table is available
7939 for DW_AT_decl_file. */
7940 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7942 /* Process all dies in compilation unit. */
7943 if (die
->child
!= NULL
)
7945 child_die
= die
->child
;
7946 while (child_die
&& child_die
->tag
)
7948 process_die (child_die
, cu
);
7949 child_die
= sibling_die (child_die
);
7953 /* Decode macro information, if present. Dwarf 2 macro information
7954 refers to information in the line number info statement program
7955 header, so we can only read it if we've read the header
7957 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
7958 if (attr
&& cu
->line_header
)
7960 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
7961 complaint (&symfile_complaints
,
7962 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7964 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
7968 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
7969 if (attr
&& cu
->line_header
)
7971 unsigned int macro_offset
= DW_UNSND (attr
);
7973 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
7977 do_cleanups (back_to
);
7980 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7981 Create the set of symtabs used by this TU, or if this TU is sharing
7982 symtabs with another TU and the symtabs have already been created
7983 then restore those symtabs in the line header.
7984 We don't need the pc/line-number mapping for type units. */
7987 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
7989 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7990 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7991 struct type_unit_group
*tu_group
;
7993 struct line_header
*lh
;
7994 struct attribute
*attr
;
7995 unsigned int i
, line_offset
;
7997 gdb_assert (per_cu
->is_debug_types
);
7999 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8001 /* If we're using .gdb_index (includes -readnow) then
8002 per_cu->s.type_unit_group may not have been set up yet. */
8003 if (per_cu
->s
.type_unit_group
== NULL
)
8004 per_cu
->s
.type_unit_group
= get_type_unit_group (cu
, attr
);
8005 tu_group
= per_cu
->s
.type_unit_group
;
8007 /* If we've already processed this stmt_list there's no real need to
8008 do it again, we could fake it and just recreate the part we need
8009 (file name,index -> symtab mapping). If data shows this optimization
8010 is useful we can do it then. */
8011 first_time
= tu_group
->primary_symtab
== NULL
;
8013 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8018 line_offset
= DW_UNSND (attr
);
8019 lh
= dwarf_decode_line_header (line_offset
, cu
);
8024 dwarf2_start_symtab (cu
, "", NULL
, 0);
8027 gdb_assert (tu_group
->symtabs
== NULL
);
8030 /* Note: The primary symtab will get allocated at the end. */
8034 cu
->line_header
= lh
;
8035 make_cleanup (free_cu_line_header
, cu
);
8039 dwarf2_start_symtab (cu
, "", NULL
, 0);
8041 tu_group
->num_symtabs
= lh
->num_file_names
;
8042 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8044 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8047 struct file_entry
*fe
= &lh
->file_names
[i
];
8050 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8051 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8053 /* Note: We don't have to watch for the main subfile here, type units
8054 don't have DW_AT_name. */
8056 if (current_subfile
->symtab
== NULL
)
8058 /* NOTE: start_subfile will recognize when it's been passed
8059 a file it has already seen. So we can't assume there's a
8060 simple mapping from lh->file_names to subfiles,
8061 lh->file_names may contain dups. */
8062 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8066 fe
->symtab
= current_subfile
->symtab
;
8067 tu_group
->symtabs
[i
] = fe
->symtab
;
8074 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8076 struct file_entry
*fe
= &lh
->file_names
[i
];
8078 fe
->symtab
= tu_group
->symtabs
[i
];
8082 /* The main symtab is allocated last. Type units don't have DW_AT_name
8083 so they don't have a "real" (so to speak) symtab anyway.
8084 There is later code that will assign the main symtab to all symbols
8085 that don't have one. We need to handle the case of a symbol with a
8086 missing symtab (DW_AT_decl_file) anyway. */
8089 /* Process DW_TAG_type_unit.
8090 For TUs we want to skip the first top level sibling if it's not the
8091 actual type being defined by this TU. In this case the first top
8092 level sibling is there to provide context only. */
8095 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8097 struct die_info
*child_die
;
8099 prepare_one_comp_unit (cu
, die
, language_minimal
);
8101 /* Initialize (or reinitialize) the machinery for building symtabs.
8102 We do this before processing child DIEs, so that the line header table
8103 is available for DW_AT_decl_file. */
8104 setup_type_unit_groups (die
, cu
);
8106 if (die
->child
!= NULL
)
8108 child_die
= die
->child
;
8109 while (child_die
&& child_die
->tag
)
8111 process_die (child_die
, cu
);
8112 child_die
= sibling_die (child_die
);
8119 http://gcc.gnu.org/wiki/DebugFission
8120 http://gcc.gnu.org/wiki/DebugFissionDWP
8122 To simplify handling of both DWO files ("object" files with the DWARF info)
8123 and DWP files (a file with the DWOs packaged up into one file), we treat
8124 DWP files as having a collection of virtual DWO files. */
8127 hash_dwo_file (const void *item
)
8129 const struct dwo_file
*dwo_file
= item
;
8131 return htab_hash_string (dwo_file
->name
);
8135 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8137 const struct dwo_file
*lhs
= item_lhs
;
8138 const struct dwo_file
*rhs
= item_rhs
;
8140 return strcmp (lhs
->name
, rhs
->name
) == 0;
8143 /* Allocate a hash table for DWO files. */
8146 allocate_dwo_file_hash_table (void)
8148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8150 return htab_create_alloc_ex (41,
8154 &objfile
->objfile_obstack
,
8155 hashtab_obstack_allocate
,
8156 dummy_obstack_deallocate
);
8159 /* Lookup DWO file DWO_NAME. */
8162 lookup_dwo_file_slot (const char *dwo_name
)
8164 struct dwo_file find_entry
;
8167 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8168 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8170 memset (&find_entry
, 0, sizeof (find_entry
));
8171 find_entry
.name
= dwo_name
;
8172 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8178 hash_dwo_unit (const void *item
)
8180 const struct dwo_unit
*dwo_unit
= item
;
8182 /* This drops the top 32 bits of the id, but is ok for a hash. */
8183 return dwo_unit
->signature
;
8187 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8189 const struct dwo_unit
*lhs
= item_lhs
;
8190 const struct dwo_unit
*rhs
= item_rhs
;
8192 /* The signature is assumed to be unique within the DWO file.
8193 So while object file CU dwo_id's always have the value zero,
8194 that's OK, assuming each object file DWO file has only one CU,
8195 and that's the rule for now. */
8196 return lhs
->signature
== rhs
->signature
;
8199 /* Allocate a hash table for DWO CUs,TUs.
8200 There is one of these tables for each of CUs,TUs for each DWO file. */
8203 allocate_dwo_unit_table (struct objfile
*objfile
)
8205 /* Start out with a pretty small number.
8206 Generally DWO files contain only one CU and maybe some TUs. */
8207 return htab_create_alloc_ex (3,
8211 &objfile
->objfile_obstack
,
8212 hashtab_obstack_allocate
,
8213 dummy_obstack_deallocate
);
8216 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8218 struct create_dwo_info_table_data
8220 struct dwo_file
*dwo_file
;
8224 /* die_reader_func for create_dwo_debug_info_hash_table. */
8227 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8229 struct die_info
*comp_unit_die
,
8233 struct dwarf2_cu
*cu
= reader
->cu
;
8234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8235 sect_offset offset
= cu
->per_cu
->offset
;
8236 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8237 struct create_dwo_info_table_data
*data
= datap
;
8238 struct dwo_file
*dwo_file
= data
->dwo_file
;
8239 htab_t cu_htab
= data
->cu_htab
;
8241 struct attribute
*attr
;
8242 struct dwo_unit
*dwo_unit
;
8244 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8247 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8248 " its dwo_id [in module %s]"),
8249 offset
.sect_off
, dwo_file
->name
);
8253 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8254 dwo_unit
->dwo_file
= dwo_file
;
8255 dwo_unit
->signature
= DW_UNSND (attr
);
8256 dwo_unit
->info_or_types_section
= section
;
8257 dwo_unit
->offset
= offset
;
8258 dwo_unit
->length
= cu
->per_cu
->length
;
8260 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8261 gdb_assert (slot
!= NULL
);
8264 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8266 complaint (&symfile_complaints
,
8267 _("debug entry at offset 0x%x is duplicate to the entry at"
8268 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8269 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8270 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8276 if (dwarf2_read_debug
)
8277 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8279 phex (dwo_unit
->signature
,
8280 sizeof (dwo_unit
->signature
)));
8283 /* Create a hash table to map DWO IDs to their CU entry in
8284 .debug_info.dwo in DWO_FILE.
8285 Note: This function processes DWO files only, not DWP files. */
8288 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8291 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8294 gdb_byte
*info_ptr
, *end_ptr
;
8295 struct create_dwo_info_table_data create_dwo_info_table_data
;
8297 dwarf2_read_section (objfile
, section
);
8298 info_ptr
= section
->buffer
;
8300 if (info_ptr
== NULL
)
8303 /* We can't set abfd until now because the section may be empty or
8304 not present, in which case section->asection will be NULL. */
8305 abfd
= section
->asection
->owner
;
8307 if (dwarf2_read_debug
)
8308 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8309 bfd_get_filename (abfd
));
8311 cu_htab
= allocate_dwo_unit_table (objfile
);
8313 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8314 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8316 end_ptr
= info_ptr
+ section
->size
;
8317 while (info_ptr
< end_ptr
)
8319 struct dwarf2_per_cu_data per_cu
;
8321 memset (&per_cu
, 0, sizeof (per_cu
));
8322 per_cu
.objfile
= objfile
;
8323 per_cu
.is_debug_types
= 0;
8324 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8325 per_cu
.info_or_types_section
= section
;
8327 init_cutu_and_read_dies_no_follow (&per_cu
,
8328 &dwo_file
->sections
.abbrev
,
8330 create_dwo_debug_info_hash_table_reader
,
8331 &create_dwo_info_table_data
);
8333 info_ptr
+= per_cu
.length
;
8339 /* DWP file .debug_{cu,tu}_index section format:
8340 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8342 Both index sections have the same format, and serve to map a 64-bit
8343 signature to a set of section numbers. Each section begins with a header,
8344 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8345 indexes, and a pool of 32-bit section numbers. The index sections will be
8346 aligned at 8-byte boundaries in the file.
8348 The index section header contains two unsigned 32-bit values (using the
8349 byte order of the application binary):
8351 N, the number of compilation units or type units in the index
8352 M, the number of slots in the hash table
8354 (We assume that N and M will not exceed 2^32 - 1.)
8356 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8358 The hash table begins at offset 8 in the section, and consists of an array
8359 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8360 order of the application binary). Unused slots in the hash table are 0.
8361 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8363 The parallel table begins immediately after the hash table
8364 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8365 array of 32-bit indexes (using the byte order of the application binary),
8366 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8367 table contains a 32-bit index into the pool of section numbers. For unused
8368 hash table slots, the corresponding entry in the parallel table will be 0.
8370 Given a 64-bit compilation unit signature or a type signature S, an entry
8371 in the hash table is located as follows:
8373 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8374 the low-order k bits all set to 1.
8376 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8378 3) If the hash table entry at index H matches the signature, use that
8379 entry. If the hash table entry at index H is unused (all zeroes),
8380 terminate the search: the signature is not present in the table.
8382 4) Let H = (H + H') modulo M. Repeat at Step 3.
8384 Because M > N and H' and M are relatively prime, the search is guaranteed
8385 to stop at an unused slot or find the match.
8387 The pool of section numbers begins immediately following the hash table
8388 (at offset 8 + 12 * M from the beginning of the section). The pool of
8389 section numbers consists of an array of 32-bit words (using the byte order
8390 of the application binary). Each item in the array is indexed starting
8391 from 0. The hash table entry provides the index of the first section
8392 number in the set. Additional section numbers in the set follow, and the
8393 set is terminated by a 0 entry (section number 0 is not used in ELF).
8395 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8396 section must be the first entry in the set, and the .debug_abbrev.dwo must
8397 be the second entry. Other members of the set may follow in any order. */
8399 /* Create a hash table to map DWO IDs to their CU/TU entry in
8400 .debug_{info,types}.dwo in DWP_FILE.
8401 Returns NULL if there isn't one.
8402 Note: This function processes DWP files only, not DWO files. */
8404 static struct dwp_hash_table
*
8405 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8407 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8408 bfd
*dbfd
= dwp_file
->dbfd
;
8409 char *index_ptr
, *index_end
;
8410 struct dwarf2_section_info
*index
;
8411 uint32_t version
, nr_units
, nr_slots
;
8412 struct dwp_hash_table
*htab
;
8415 index
= &dwp_file
->sections
.tu_index
;
8417 index
= &dwp_file
->sections
.cu_index
;
8419 if (dwarf2_section_empty_p (index
))
8421 dwarf2_read_section (objfile
, index
);
8423 index_ptr
= index
->buffer
;
8424 index_end
= index_ptr
+ index
->size
;
8426 version
= read_4_bytes (dbfd
, index_ptr
);
8427 index_ptr
+= 8; /* Skip the unused word. */
8428 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8430 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8435 error (_("Dwarf Error: unsupported DWP file version (%u)"
8437 version
, dwp_file
->name
);
8439 if (nr_slots
!= (nr_slots
& -nr_slots
))
8441 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8442 " is not power of 2 [in module %s]"),
8443 nr_slots
, dwp_file
->name
);
8446 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8447 htab
->nr_units
= nr_units
;
8448 htab
->nr_slots
= nr_slots
;
8449 htab
->hash_table
= index_ptr
;
8450 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8451 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8456 /* Update SECTIONS with the data from SECTP.
8458 This function is like the other "locate" section routines that are
8459 passed to bfd_map_over_sections, but in this context the sections to
8460 read comes from the DWP hash table, not the full ELF section table.
8462 The result is non-zero for success, or zero if an error was found. */
8465 locate_virtual_dwo_sections (asection
*sectp
,
8466 struct virtual_dwo_sections
*sections
)
8468 const struct dwop_section_names
*names
= &dwop_section_names
;
8470 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8472 /* There can be only one. */
8473 if (sections
->abbrev
.asection
!= NULL
)
8475 sections
->abbrev
.asection
= sectp
;
8476 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8478 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8479 || section_is_p (sectp
->name
, &names
->types_dwo
))
8481 /* There can be only one. */
8482 if (sections
->info_or_types
.asection
!= NULL
)
8484 sections
->info_or_types
.asection
= sectp
;
8485 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8487 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8489 /* There can be only one. */
8490 if (sections
->line
.asection
!= NULL
)
8492 sections
->line
.asection
= sectp
;
8493 sections
->line
.size
= bfd_get_section_size (sectp
);
8495 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8497 /* There can be only one. */
8498 if (sections
->loc
.asection
!= NULL
)
8500 sections
->loc
.asection
= sectp
;
8501 sections
->loc
.size
= bfd_get_section_size (sectp
);
8503 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8505 /* There can be only one. */
8506 if (sections
->macinfo
.asection
!= NULL
)
8508 sections
->macinfo
.asection
= sectp
;
8509 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8511 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8513 /* There can be only one. */
8514 if (sections
->macro
.asection
!= NULL
)
8516 sections
->macro
.asection
= sectp
;
8517 sections
->macro
.size
= bfd_get_section_size (sectp
);
8519 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8521 /* There can be only one. */
8522 if (sections
->str_offsets
.asection
!= NULL
)
8524 sections
->str_offsets
.asection
= sectp
;
8525 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8529 /* No other kind of section is valid. */
8536 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8537 HTAB is the hash table from the DWP file.
8538 SECTION_INDEX is the index of the DWO in HTAB. */
8540 static struct dwo_unit
*
8541 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8542 const struct dwp_hash_table
*htab
,
8543 uint32_t section_index
,
8544 ULONGEST signature
, int is_debug_types
)
8546 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8547 bfd
*dbfd
= dwp_file
->dbfd
;
8548 const char *kind
= is_debug_types
? "TU" : "CU";
8549 struct dwo_file
*dwo_file
;
8550 struct dwo_unit
*dwo_unit
;
8551 struct virtual_dwo_sections sections
;
8552 void **dwo_file_slot
;
8553 char *virtual_dwo_name
;
8554 struct dwarf2_section_info
*cutu
;
8555 struct cleanup
*cleanups
;
8558 if (dwarf2_read_debug
)
8560 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8562 section_index
, phex (signature
, sizeof (signature
)),
8566 /* Fetch the sections of this DWO.
8567 Put a limit on the number of sections we look for so that bad data
8568 doesn't cause us to loop forever. */
8570 #define MAX_NR_DWO_SECTIONS \
8571 (1 /* .debug_info or .debug_types */ \
8572 + 1 /* .debug_abbrev */ \
8573 + 1 /* .debug_line */ \
8574 + 1 /* .debug_loc */ \
8575 + 1 /* .debug_str_offsets */ \
8576 + 1 /* .debug_macro */ \
8577 + 1 /* .debug_macinfo */ \
8578 + 1 /* trailing zero */)
8580 memset (§ions
, 0, sizeof (sections
));
8581 cleanups
= make_cleanup (null_cleanup
, 0);
8583 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8586 uint32_t section_nr
=
8589 + (section_index
+ i
) * sizeof (uint32_t));
8591 if (section_nr
== 0)
8593 if (section_nr
>= dwp_file
->num_sections
)
8595 error (_("Dwarf Error: bad DWP hash table, section number too large"
8600 sectp
= dwp_file
->elf_sections
[section_nr
];
8601 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8603 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8610 || sections
.info_or_types
.asection
== NULL
8611 || sections
.abbrev
.asection
== NULL
)
8613 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8617 if (i
== MAX_NR_DWO_SECTIONS
)
8619 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8624 /* It's easier for the rest of the code if we fake a struct dwo_file and
8625 have dwo_unit "live" in that. At least for now.
8627 The DWP file can be made up of a random collection of CUs and TUs.
8628 However, for each CU + set of TUs that came from the same original
8629 DWO file, we want combine them back into a virtual DWO file to save space
8630 (fewer struct dwo_file objects to allocated). Remember that for really
8631 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8634 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8635 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8636 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8637 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8638 (sections
.str_offsets
.asection
8639 ? sections
.str_offsets
.asection
->id
8641 make_cleanup (xfree
, virtual_dwo_name
);
8642 /* Can we use an existing virtual DWO file? */
8643 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8644 /* Create one if necessary. */
8645 if (*dwo_file_slot
== NULL
)
8647 if (dwarf2_read_debug
)
8649 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8652 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8653 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8655 strlen (virtual_dwo_name
));
8656 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8657 dwo_file
->sections
.line
= sections
.line
;
8658 dwo_file
->sections
.loc
= sections
.loc
;
8659 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8660 dwo_file
->sections
.macro
= sections
.macro
;
8661 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8662 /* The "str" section is global to the entire DWP file. */
8663 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8664 /* The info or types section is assigned later to dwo_unit,
8665 there's no need to record it in dwo_file.
8666 Also, we can't simply record type sections in dwo_file because
8667 we record a pointer into the vector in dwo_unit. As we collect more
8668 types we'll grow the vector and eventually have to reallocate space
8669 for it, invalidating all the pointers into the current copy. */
8670 *dwo_file_slot
= dwo_file
;
8674 if (dwarf2_read_debug
)
8676 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8679 dwo_file
= *dwo_file_slot
;
8681 do_cleanups (cleanups
);
8683 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8684 dwo_unit
->dwo_file
= dwo_file
;
8685 dwo_unit
->signature
= signature
;
8686 dwo_unit
->info_or_types_section
=
8687 obstack_alloc (&objfile
->objfile_obstack
,
8688 sizeof (struct dwarf2_section_info
));
8689 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8690 /* offset, length, type_offset_in_tu are set later. */
8695 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8697 static struct dwo_unit
*
8698 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8699 const struct dwp_hash_table
*htab
,
8700 ULONGEST signature
, int is_debug_types
)
8702 bfd
*dbfd
= dwp_file
->dbfd
;
8703 uint32_t mask
= htab
->nr_slots
- 1;
8704 uint32_t hash
= signature
& mask
;
8705 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8708 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8710 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8711 find_dwo_cu
.signature
= signature
;
8712 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8717 /* Use a for loop so that we don't loop forever on bad debug info. */
8718 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8720 ULONGEST signature_in_table
;
8722 signature_in_table
=
8723 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8724 if (signature_in_table
== signature
)
8726 uint32_t section_index
=
8727 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8729 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8730 signature
, is_debug_types
);
8733 if (signature_in_table
== 0)
8735 hash
= (hash
+ hash2
) & mask
;
8738 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8743 /* Subroutine of open_dwop_file to simplify it.
8744 Open the file specified by FILE_NAME and hand it off to BFD for
8745 preliminary analysis. Return a newly initialized bfd *, which
8746 includes a canonicalized copy of FILE_NAME.
8747 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8748 In case of trouble, return NULL.
8749 NOTE: This function is derived from symfile_bfd_open. */
8752 try_open_dwop_file (const char *file_name
, int is_dwp
)
8756 char *absolute_name
;
8758 flags
= OPF_TRY_CWD_FIRST
;
8760 flags
|= OPF_SEARCH_IN_PATH
;
8761 desc
= openp (debug_file_directory
, flags
, file_name
,
8762 O_RDONLY
| O_BINARY
, &absolute_name
);
8766 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8769 xfree (absolute_name
);
8772 xfree (absolute_name
);
8773 bfd_set_cacheable (sym_bfd
, 1);
8775 if (!bfd_check_format (sym_bfd
, bfd_object
))
8777 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8784 /* Try to open DWO/DWP file FILE_NAME.
8785 COMP_DIR is the DW_AT_comp_dir attribute.
8786 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8787 The result is the bfd handle of the file.
8788 If there is a problem finding or opening the file, return NULL.
8789 Upon success, the canonicalized path of the file is stored in the bfd,
8790 same as symfile_bfd_open. */
8793 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8797 if (IS_ABSOLUTE_PATH (file_name
))
8798 return try_open_dwop_file (file_name
, is_dwp
);
8800 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8802 if (comp_dir
!= NULL
)
8804 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8806 /* NOTE: If comp_dir is a relative path, this will also try the
8807 search path, which seems useful. */
8808 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8809 xfree (path_to_try
);
8814 /* That didn't work, try debug-file-directory, which, despite its name,
8815 is a list of paths. */
8817 if (*debug_file_directory
== '\0')
8820 return try_open_dwop_file (file_name
, is_dwp
);
8823 /* This function is mapped across the sections and remembers the offset and
8824 size of each of the DWO debugging sections we are interested in. */
8827 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8829 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8830 const struct dwop_section_names
*names
= &dwop_section_names
;
8832 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8834 dwo_sections
->abbrev
.asection
= sectp
;
8835 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8837 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8839 dwo_sections
->info
.asection
= sectp
;
8840 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8842 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8844 dwo_sections
->line
.asection
= sectp
;
8845 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8847 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8849 dwo_sections
->loc
.asection
= sectp
;
8850 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8852 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8854 dwo_sections
->macinfo
.asection
= sectp
;
8855 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8857 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8859 dwo_sections
->macro
.asection
= sectp
;
8860 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8862 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8864 dwo_sections
->str
.asection
= sectp
;
8865 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8867 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8869 dwo_sections
->str_offsets
.asection
= sectp
;
8870 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8872 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8874 struct dwarf2_section_info type_section
;
8876 memset (&type_section
, 0, sizeof (type_section
));
8877 type_section
.asection
= sectp
;
8878 type_section
.size
= bfd_get_section_size (sectp
);
8879 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8884 /* Initialize the use of the DWO file specified by DWO_NAME.
8885 The result is NULL if DWO_NAME can't be found. */
8887 static struct dwo_file
*
8888 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8890 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8891 struct dwo_file
*dwo_file
;
8893 struct cleanup
*cleanups
;
8895 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8898 if (dwarf2_read_debug
)
8899 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8902 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8903 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8904 dwo_name
, strlen (dwo_name
));
8905 dwo_file
->dbfd
= dbfd
;
8907 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8909 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8911 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8913 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8914 dwo_file
->sections
.types
);
8916 discard_cleanups (cleanups
);
8918 if (dwarf2_read_debug
)
8919 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8924 /* This function is mapped across the sections and remembers the offset and
8925 size of each of the DWP debugging sections we are interested in. */
8928 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8930 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8931 const struct dwop_section_names
*names
= &dwop_section_names
;
8932 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
8934 /* Record the ELF section number for later lookup: this is what the
8935 .debug_cu_index,.debug_tu_index tables use. */
8936 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
8937 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
8939 /* Look for specific sections that we need. */
8940 if (section_is_p (sectp
->name
, &names
->str_dwo
))
8942 dwp_file
->sections
.str
.asection
= sectp
;
8943 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8945 else if (section_is_p (sectp
->name
, &names
->cu_index
))
8947 dwp_file
->sections
.cu_index
.asection
= sectp
;
8948 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
8950 else if (section_is_p (sectp
->name
, &names
->tu_index
))
8952 dwp_file
->sections
.tu_index
.asection
= sectp
;
8953 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
8957 /* Hash function for dwp_file loaded CUs/TUs. */
8960 hash_dwp_loaded_cutus (const void *item
)
8962 const struct dwo_unit
*dwo_unit
= item
;
8964 /* This drops the top 32 bits of the signature, but is ok for a hash. */
8965 return dwo_unit
->signature
;
8968 /* Equality function for dwp_file loaded CUs/TUs. */
8971 eq_dwp_loaded_cutus (const void *a
, const void *b
)
8973 const struct dwo_unit
*dua
= a
;
8974 const struct dwo_unit
*dub
= b
;
8976 return dua
->signature
== dub
->signature
;
8979 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
8982 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
8984 return htab_create_alloc_ex (3,
8985 hash_dwp_loaded_cutus
,
8986 eq_dwp_loaded_cutus
,
8988 &objfile
->objfile_obstack
,
8989 hashtab_obstack_allocate
,
8990 dummy_obstack_deallocate
);
8993 /* Initialize the use of the DWP file for the current objfile.
8994 By convention the name of the DWP file is ${objfile}.dwp.
8995 The result is NULL if it can't be found. */
8997 static struct dwp_file
*
8998 open_and_init_dwp_file (const char *comp_dir
)
9000 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9001 struct dwp_file
*dwp_file
;
9004 struct cleanup
*cleanups
;
9006 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
9007 cleanups
= make_cleanup (xfree
, dwp_name
);
9009 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
9012 if (dwarf2_read_debug
)
9013 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
9014 do_cleanups (cleanups
);
9017 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
9018 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
9019 dwp_name
, strlen (dwp_name
));
9020 dwp_file
->dbfd
= dbfd
;
9021 do_cleanups (cleanups
);
9023 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
9025 /* +1: section 0 is unused */
9026 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9027 dwp_file
->elf_sections
=
9028 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9029 dwp_file
->num_sections
, asection
*);
9031 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9033 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9035 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9037 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9039 discard_cleanups (cleanups
);
9041 if (dwarf2_read_debug
)
9043 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9044 fprintf_unfiltered (gdb_stdlog
,
9045 " %u CUs, %u TUs\n",
9046 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9047 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9053 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9054 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9055 or in the DWP file for the objfile, referenced by THIS_UNIT.
9056 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9057 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9059 This is called, for example, when wanting to read a variable with a
9060 complex location. Therefore we don't want to do file i/o for every call.
9061 Therefore we don't want to look for a DWO file on every call.
9062 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9063 then we check if we've already seen DWO_NAME, and only THEN do we check
9066 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9067 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9069 static struct dwo_unit
*
9070 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9071 const char *dwo_name
, const char *comp_dir
,
9072 ULONGEST signature
, int is_debug_types
)
9074 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9075 const char *kind
= is_debug_types
? "TU" : "CU";
9076 void **dwo_file_slot
;
9077 struct dwo_file
*dwo_file
;
9078 struct dwp_file
*dwp_file
;
9080 /* Have we already read SIGNATURE from a DWP file? */
9082 if (! dwarf2_per_objfile
->dwp_checked
)
9084 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9085 dwarf2_per_objfile
->dwp_checked
= 1;
9087 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9089 if (dwp_file
!= NULL
)
9091 const struct dwp_hash_table
*dwp_htab
=
9092 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9094 if (dwp_htab
!= NULL
)
9096 struct dwo_unit
*dwo_cutu
=
9097 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9099 if (dwo_cutu
!= NULL
)
9101 if (dwarf2_read_debug
)
9103 fprintf_unfiltered (gdb_stdlog
,
9104 "Virtual DWO %s %s found: @%s\n",
9105 kind
, hex_string (signature
),
9106 host_address_to_string (dwo_cutu
));
9113 /* Have we already seen DWO_NAME? */
9115 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9116 if (*dwo_file_slot
== NULL
)
9118 /* Read in the file and build a table of the DWOs it contains. */
9119 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9121 /* NOTE: This will be NULL if unable to open the file. */
9122 dwo_file
= *dwo_file_slot
;
9124 if (dwo_file
!= NULL
)
9126 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9130 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9132 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9133 find_dwo_cutu
.signature
= signature
;
9134 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9136 if (dwo_cutu
!= NULL
)
9138 if (dwarf2_read_debug
)
9140 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9141 kind
, dwo_name
, hex_string (signature
),
9142 host_address_to_string (dwo_cutu
));
9149 /* We didn't find it. This could mean a dwo_id mismatch, or
9150 someone deleted the DWO/DWP file, or the search path isn't set up
9151 correctly to find the file. */
9153 if (dwarf2_read_debug
)
9155 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9156 kind
, dwo_name
, hex_string (signature
));
9159 complaint (&symfile_complaints
,
9160 _("Could not find DWO CU referenced by CU at offset 0x%x"
9162 this_unit
->offset
.sect_off
, objfile
->name
);
9166 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9167 See lookup_dwo_cutu_unit for details. */
9169 static struct dwo_unit
*
9170 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9171 const char *dwo_name
, const char *comp_dir
,
9174 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9177 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9178 See lookup_dwo_cutu_unit for details. */
9180 static struct dwo_unit
*
9181 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9182 const char *dwo_name
, const char *comp_dir
)
9184 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9187 /* Free all resources associated with DWO_FILE.
9188 Close the DWO file and munmap the sections.
9189 All memory should be on the objfile obstack. */
9192 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9195 struct dwarf2_section_info
*section
;
9197 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9198 gdb_bfd_unref (dwo_file
->dbfd
);
9200 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9203 /* Wrapper for free_dwo_file for use in cleanups. */
9206 free_dwo_file_cleanup (void *arg
)
9208 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9211 free_dwo_file (dwo_file
, objfile
);
9214 /* Traversal function for free_dwo_files. */
9217 free_dwo_file_from_slot (void **slot
, void *info
)
9219 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9220 struct objfile
*objfile
= (struct objfile
*) info
;
9222 free_dwo_file (dwo_file
, objfile
);
9227 /* Free all resources associated with DWO_FILES. */
9230 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9232 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9235 /* Read in various DIEs. */
9237 /* qsort helper for inherit_abstract_dies. */
9240 unsigned_int_compar (const void *ap
, const void *bp
)
9242 unsigned int a
= *(unsigned int *) ap
;
9243 unsigned int b
= *(unsigned int *) bp
;
9245 return (a
> b
) - (b
> a
);
9248 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9249 Inherit only the children of the DW_AT_abstract_origin DIE not being
9250 already referenced by DW_AT_abstract_origin from the children of the
9254 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9256 struct die_info
*child_die
;
9257 unsigned die_children_count
;
9258 /* CU offsets which were referenced by children of the current DIE. */
9259 sect_offset
*offsets
;
9260 sect_offset
*offsets_end
, *offsetp
;
9261 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9262 struct die_info
*origin_die
;
9263 /* Iterator of the ORIGIN_DIE children. */
9264 struct die_info
*origin_child_die
;
9265 struct cleanup
*cleanups
;
9266 struct attribute
*attr
;
9267 struct dwarf2_cu
*origin_cu
;
9268 struct pending
**origin_previous_list_in_scope
;
9270 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9274 /* Note that following die references may follow to a die in a
9278 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9280 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9282 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9283 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9285 if (die
->tag
!= origin_die
->tag
9286 && !(die
->tag
== DW_TAG_inlined_subroutine
9287 && origin_die
->tag
== DW_TAG_subprogram
))
9288 complaint (&symfile_complaints
,
9289 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9290 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9292 child_die
= die
->child
;
9293 die_children_count
= 0;
9294 while (child_die
&& child_die
->tag
)
9296 child_die
= sibling_die (child_die
);
9297 die_children_count
++;
9299 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9300 cleanups
= make_cleanup (xfree
, offsets
);
9302 offsets_end
= offsets
;
9303 child_die
= die
->child
;
9304 while (child_die
&& child_die
->tag
)
9306 /* For each CHILD_DIE, find the corresponding child of
9307 ORIGIN_DIE. If there is more than one layer of
9308 DW_AT_abstract_origin, follow them all; there shouldn't be,
9309 but GCC versions at least through 4.4 generate this (GCC PR
9311 struct die_info
*child_origin_die
= child_die
;
9312 struct dwarf2_cu
*child_origin_cu
= cu
;
9316 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9320 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9324 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9325 counterpart may exist. */
9326 if (child_origin_die
!= child_die
)
9328 if (child_die
->tag
!= child_origin_die
->tag
9329 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9330 && child_origin_die
->tag
== DW_TAG_subprogram
))
9331 complaint (&symfile_complaints
,
9332 _("Child DIE 0x%x and its abstract origin 0x%x have "
9333 "different tags"), child_die
->offset
.sect_off
,
9334 child_origin_die
->offset
.sect_off
);
9335 if (child_origin_die
->parent
!= origin_die
)
9336 complaint (&symfile_complaints
,
9337 _("Child DIE 0x%x and its abstract origin 0x%x have "
9338 "different parents"), child_die
->offset
.sect_off
,
9339 child_origin_die
->offset
.sect_off
);
9341 *offsets_end
++ = child_origin_die
->offset
;
9343 child_die
= sibling_die (child_die
);
9345 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9346 unsigned_int_compar
);
9347 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9348 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9349 complaint (&symfile_complaints
,
9350 _("Multiple children of DIE 0x%x refer "
9351 "to DIE 0x%x as their abstract origin"),
9352 die
->offset
.sect_off
, offsetp
->sect_off
);
9355 origin_child_die
= origin_die
->child
;
9356 while (origin_child_die
&& origin_child_die
->tag
)
9358 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9359 while (offsetp
< offsets_end
9360 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9362 if (offsetp
>= offsets_end
9363 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9365 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9366 process_die (origin_child_die
, origin_cu
);
9368 origin_child_die
= sibling_die (origin_child_die
);
9370 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9372 do_cleanups (cleanups
);
9376 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9378 struct objfile
*objfile
= cu
->objfile
;
9379 struct context_stack
*new;
9382 struct die_info
*child_die
;
9383 struct attribute
*attr
, *call_line
, *call_file
;
9386 struct block
*block
;
9387 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9388 VEC (symbolp
) *template_args
= NULL
;
9389 struct template_symbol
*templ_func
= NULL
;
9393 /* If we do not have call site information, we can't show the
9394 caller of this inlined function. That's too confusing, so
9395 only use the scope for local variables. */
9396 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9397 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9398 if (call_line
== NULL
|| call_file
== NULL
)
9400 read_lexical_block_scope (die
, cu
);
9405 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9407 name
= dwarf2_name (die
, cu
);
9409 /* Ignore functions with missing or empty names. These are actually
9410 illegal according to the DWARF standard. */
9413 complaint (&symfile_complaints
,
9414 _("missing name for subprogram DIE at %d"),
9415 die
->offset
.sect_off
);
9419 /* Ignore functions with missing or invalid low and high pc attributes. */
9420 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9422 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9423 if (!attr
|| !DW_UNSND (attr
))
9424 complaint (&symfile_complaints
,
9425 _("cannot get low and high bounds "
9426 "for subprogram DIE at %d"),
9427 die
->offset
.sect_off
);
9434 /* If we have any template arguments, then we must allocate a
9435 different sort of symbol. */
9436 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9438 if (child_die
->tag
== DW_TAG_template_type_param
9439 || child_die
->tag
== DW_TAG_template_value_param
)
9441 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9442 struct template_symbol
);
9443 templ_func
->base
.is_cplus_template_function
= 1;
9448 new = push_context (0, lowpc
);
9449 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9450 (struct symbol
*) templ_func
);
9452 /* If there is a location expression for DW_AT_frame_base, record
9454 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9456 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9457 expression is being recorded directly in the function's symbol
9458 and not in a separate frame-base object. I guess this hack is
9459 to avoid adding some sort of frame-base adjunct/annex to the
9460 function's symbol :-(. The problem with doing this is that it
9461 results in a function symbol with a location expression that
9462 has nothing to do with the location of the function, ouch! The
9463 relationship should be: a function's symbol has-a frame base; a
9464 frame-base has-a location expression. */
9465 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9467 cu
->list_in_scope
= &local_symbols
;
9469 if (die
->child
!= NULL
)
9471 child_die
= die
->child
;
9472 while (child_die
&& child_die
->tag
)
9474 if (child_die
->tag
== DW_TAG_template_type_param
9475 || child_die
->tag
== DW_TAG_template_value_param
)
9477 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9480 VEC_safe_push (symbolp
, template_args
, arg
);
9483 process_die (child_die
, cu
);
9484 child_die
= sibling_die (child_die
);
9488 inherit_abstract_dies (die
, cu
);
9490 /* If we have a DW_AT_specification, we might need to import using
9491 directives from the context of the specification DIE. See the
9492 comment in determine_prefix. */
9493 if (cu
->language
== language_cplus
9494 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9496 struct dwarf2_cu
*spec_cu
= cu
;
9497 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9501 child_die
= spec_die
->child
;
9502 while (child_die
&& child_die
->tag
)
9504 if (child_die
->tag
== DW_TAG_imported_module
)
9505 process_die (child_die
, spec_cu
);
9506 child_die
= sibling_die (child_die
);
9509 /* In some cases, GCC generates specification DIEs that
9510 themselves contain DW_AT_specification attributes. */
9511 spec_die
= die_specification (spec_die
, &spec_cu
);
9515 new = pop_context ();
9516 /* Make a block for the local symbols within. */
9517 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9518 lowpc
, highpc
, objfile
);
9520 /* For C++, set the block's scope. */
9521 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9522 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9523 determine_prefix (die
, cu
),
9524 processing_has_namespace_info
);
9526 /* If we have address ranges, record them. */
9527 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9529 /* Attach template arguments to function. */
9530 if (! VEC_empty (symbolp
, template_args
))
9532 gdb_assert (templ_func
!= NULL
);
9534 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9535 templ_func
->template_arguments
9536 = obstack_alloc (&objfile
->objfile_obstack
,
9537 (templ_func
->n_template_arguments
9538 * sizeof (struct symbol
*)));
9539 memcpy (templ_func
->template_arguments
,
9540 VEC_address (symbolp
, template_args
),
9541 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9542 VEC_free (symbolp
, template_args
);
9545 /* In C++, we can have functions nested inside functions (e.g., when
9546 a function declares a class that has methods). This means that
9547 when we finish processing a function scope, we may need to go
9548 back to building a containing block's symbol lists. */
9549 local_symbols
= new->locals
;
9550 using_directives
= new->using_directives
;
9552 /* If we've finished processing a top-level function, subsequent
9553 symbols go in the file symbol list. */
9554 if (outermost_context_p ())
9555 cu
->list_in_scope
= &file_symbols
;
9558 /* Process all the DIES contained within a lexical block scope. Start
9559 a new scope, process the dies, and then close the scope. */
9562 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9564 struct objfile
*objfile
= cu
->objfile
;
9565 struct context_stack
*new;
9566 CORE_ADDR lowpc
, highpc
;
9567 struct die_info
*child_die
;
9570 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9572 /* Ignore blocks with missing or invalid low and high pc attributes. */
9573 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9574 as multiple lexical blocks? Handling children in a sane way would
9575 be nasty. Might be easier to properly extend generic blocks to
9577 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9582 push_context (0, lowpc
);
9583 if (die
->child
!= NULL
)
9585 child_die
= die
->child
;
9586 while (child_die
&& child_die
->tag
)
9588 process_die (child_die
, cu
);
9589 child_die
= sibling_die (child_die
);
9592 new = pop_context ();
9594 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9597 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9600 /* Note that recording ranges after traversing children, as we
9601 do here, means that recording a parent's ranges entails
9602 walking across all its children's ranges as they appear in
9603 the address map, which is quadratic behavior.
9605 It would be nicer to record the parent's ranges before
9606 traversing its children, simply overriding whatever you find
9607 there. But since we don't even decide whether to create a
9608 block until after we've traversed its children, that's hard
9610 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9612 local_symbols
= new->locals
;
9613 using_directives
= new->using_directives
;
9616 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9619 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9621 struct objfile
*objfile
= cu
->objfile
;
9622 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9623 CORE_ADDR pc
, baseaddr
;
9624 struct attribute
*attr
;
9625 struct call_site
*call_site
, call_site_local
;
9628 struct die_info
*child_die
;
9630 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9632 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9635 complaint (&symfile_complaints
,
9636 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9637 "DIE 0x%x [in module %s]"),
9638 die
->offset
.sect_off
, objfile
->name
);
9641 pc
= DW_ADDR (attr
) + baseaddr
;
9643 if (cu
->call_site_htab
== NULL
)
9644 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9645 NULL
, &objfile
->objfile_obstack
,
9646 hashtab_obstack_allocate
, NULL
);
9647 call_site_local
.pc
= pc
;
9648 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9651 complaint (&symfile_complaints
,
9652 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9653 "DIE 0x%x [in module %s]"),
9654 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9658 /* Count parameters at the caller. */
9661 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9662 child_die
= sibling_die (child_die
))
9664 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9666 complaint (&symfile_complaints
,
9667 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9668 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9669 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9676 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9677 (sizeof (*call_site
)
9678 + (sizeof (*call_site
->parameter
)
9681 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9684 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9686 struct die_info
*func_die
;
9688 /* Skip also over DW_TAG_inlined_subroutine. */
9689 for (func_die
= die
->parent
;
9690 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9691 && func_die
->tag
!= DW_TAG_subroutine_type
;
9692 func_die
= func_die
->parent
);
9694 /* DW_AT_GNU_all_call_sites is a superset
9695 of DW_AT_GNU_all_tail_call_sites. */
9697 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9698 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9700 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9701 not complete. But keep CALL_SITE for look ups via call_site_htab,
9702 both the initial caller containing the real return address PC and
9703 the final callee containing the current PC of a chain of tail
9704 calls do not need to have the tail call list complete. But any
9705 function candidate for a virtual tail call frame searched via
9706 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9707 determined unambiguously. */
9711 struct type
*func_type
= NULL
;
9714 func_type
= get_die_type (func_die
, cu
);
9715 if (func_type
!= NULL
)
9717 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9719 /* Enlist this call site to the function. */
9720 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9721 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9724 complaint (&symfile_complaints
,
9725 _("Cannot find function owning DW_TAG_GNU_call_site "
9726 "DIE 0x%x [in module %s]"),
9727 die
->offset
.sect_off
, objfile
->name
);
9731 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9733 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9734 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9735 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9736 /* Keep NULL DWARF_BLOCK. */;
9737 else if (attr_form_is_block (attr
))
9739 struct dwarf2_locexpr_baton
*dlbaton
;
9741 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9742 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9743 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9744 dlbaton
->per_cu
= cu
->per_cu
;
9746 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9748 else if (is_ref_attr (attr
))
9750 struct dwarf2_cu
*target_cu
= cu
;
9751 struct die_info
*target_die
;
9753 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9754 gdb_assert (target_cu
->objfile
== objfile
);
9755 if (die_is_declaration (target_die
, target_cu
))
9757 const char *target_physname
;
9759 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9760 if (target_physname
== NULL
)
9761 complaint (&symfile_complaints
,
9762 _("DW_AT_GNU_call_site_target target DIE has invalid "
9763 "physname, for referencing DIE 0x%x [in module %s]"),
9764 die
->offset
.sect_off
, objfile
->name
);
9766 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9772 /* DW_AT_entry_pc should be preferred. */
9773 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9774 complaint (&symfile_complaints
,
9775 _("DW_AT_GNU_call_site_target target DIE has invalid "
9776 "low pc, for referencing DIE 0x%x [in module %s]"),
9777 die
->offset
.sect_off
, objfile
->name
);
9779 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9783 complaint (&symfile_complaints
,
9784 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9785 "block nor reference, for DIE 0x%x [in module %s]"),
9786 die
->offset
.sect_off
, objfile
->name
);
9788 call_site
->per_cu
= cu
->per_cu
;
9790 for (child_die
= die
->child
;
9791 child_die
&& child_die
->tag
;
9792 child_die
= sibling_die (child_die
))
9794 struct call_site_parameter
*parameter
;
9795 struct attribute
*loc
, *origin
;
9797 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9799 /* Already printed the complaint above. */
9803 gdb_assert (call_site
->parameter_count
< nparams
);
9804 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9806 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9807 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9808 register is contained in DW_AT_GNU_call_site_value. */
9810 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9811 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9812 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9816 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9817 offset
= dwarf2_get_ref_die_offset (origin
);
9818 if (!offset_in_cu_p (&cu
->header
, offset
))
9820 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9821 binding can be done only inside one CU. Such referenced DIE
9822 therefore cannot be even moved to DW_TAG_partial_unit. */
9823 complaint (&symfile_complaints
,
9824 _("DW_AT_abstract_origin offset is not in CU for "
9825 "DW_TAG_GNU_call_site child DIE 0x%x "
9827 child_die
->offset
.sect_off
, objfile
->name
);
9830 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9831 - cu
->header
.offset
.sect_off
);
9833 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9835 complaint (&symfile_complaints
,
9836 _("No DW_FORM_block* DW_AT_location for "
9837 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9838 child_die
->offset
.sect_off
, objfile
->name
);
9843 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9844 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9845 if (parameter
->u
.dwarf_reg
!= -1)
9846 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9847 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9848 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9849 ¶meter
->u
.fb_offset
))
9850 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9853 complaint (&symfile_complaints
,
9854 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9855 "for DW_FORM_block* DW_AT_location is supported for "
9856 "DW_TAG_GNU_call_site child DIE 0x%x "
9858 child_die
->offset
.sect_off
, objfile
->name
);
9863 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9864 if (!attr_form_is_block (attr
))
9866 complaint (&symfile_complaints
,
9867 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9868 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9869 child_die
->offset
.sect_off
, objfile
->name
);
9872 parameter
->value
= DW_BLOCK (attr
)->data
;
9873 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9875 /* Parameters are not pre-cleared by memset above. */
9876 parameter
->data_value
= NULL
;
9877 parameter
->data_value_size
= 0;
9878 call_site
->parameter_count
++;
9880 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9883 if (!attr_form_is_block (attr
))
9884 complaint (&symfile_complaints
,
9885 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9886 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9887 child_die
->offset
.sect_off
, objfile
->name
);
9890 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9891 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9897 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9898 Return 1 if the attributes are present and valid, otherwise, return 0.
9899 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9902 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9903 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9904 struct partial_symtab
*ranges_pst
)
9906 struct objfile
*objfile
= cu
->objfile
;
9907 struct comp_unit_head
*cu_header
= &cu
->header
;
9908 bfd
*obfd
= objfile
->obfd
;
9909 unsigned int addr_size
= cu_header
->addr_size
;
9910 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9911 /* Base address selection entry. */
9922 found_base
= cu
->base_known
;
9923 base
= cu
->base_address
;
9925 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9926 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9928 complaint (&symfile_complaints
,
9929 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9933 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9935 /* Read in the largest possible address. */
9936 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9937 if ((marker
& mask
) == mask
)
9939 /* If we found the largest possible address, then
9940 read the base address. */
9941 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9942 buffer
+= 2 * addr_size
;
9943 offset
+= 2 * addr_size
;
9949 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9953 CORE_ADDR range_beginning
, range_end
;
9955 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
9956 buffer
+= addr_size
;
9957 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
9958 buffer
+= addr_size
;
9959 offset
+= 2 * addr_size
;
9961 /* An end of list marker is a pair of zero addresses. */
9962 if (range_beginning
== 0 && range_end
== 0)
9963 /* Found the end of list entry. */
9966 /* Each base address selection entry is a pair of 2 values.
9967 The first is the largest possible address, the second is
9968 the base address. Check for a base address here. */
9969 if ((range_beginning
& mask
) == mask
)
9971 /* If we found the largest possible address, then
9972 read the base address. */
9973 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9980 /* We have no valid base address for the ranges
9982 complaint (&symfile_complaints
,
9983 _("Invalid .debug_ranges data (no base address)"));
9987 if (range_beginning
> range_end
)
9989 /* Inverted range entries are invalid. */
9990 complaint (&symfile_complaints
,
9991 _("Invalid .debug_ranges data (inverted range)"));
9995 /* Empty range entries have no effect. */
9996 if (range_beginning
== range_end
)
9999 range_beginning
+= base
;
10002 /* A not-uncommon case of bad debug info.
10003 Don't pollute the addrmap with bad data. */
10004 if (range_beginning
+ baseaddr
== 0
10005 && !dwarf2_per_objfile
->has_section_at_zero
)
10007 complaint (&symfile_complaints
,
10008 _(".debug_ranges entry has start address of zero"
10009 " [in module %s]"), objfile
->name
);
10013 if (ranges_pst
!= NULL
)
10014 addrmap_set_empty (objfile
->psymtabs_addrmap
,
10015 range_beginning
+ baseaddr
,
10016 range_end
- 1 + baseaddr
,
10019 /* FIXME: This is recording everything as a low-high
10020 segment of consecutive addresses. We should have a
10021 data structure for discontiguous block ranges
10025 low
= range_beginning
;
10031 if (range_beginning
< low
)
10032 low
= range_beginning
;
10033 if (range_end
> high
)
10039 /* If the first entry is an end-of-list marker, the range
10040 describes an empty scope, i.e. no instructions. */
10046 *high_return
= high
;
10050 /* Get low and high pc attributes from a die. Return 1 if the attributes
10051 are present and valid, otherwise, return 0. Return -1 if the range is
10052 discontinuous, i.e. derived from DW_AT_ranges information. */
10055 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10056 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10057 struct partial_symtab
*pst
)
10059 struct attribute
*attr
;
10060 struct attribute
*attr_high
;
10062 CORE_ADDR high
= 0;
10065 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10068 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10071 low
= DW_ADDR (attr
);
10072 if (attr_high
->form
== DW_FORM_addr
10073 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10074 high
= DW_ADDR (attr_high
);
10076 high
= low
+ DW_UNSND (attr_high
);
10079 /* Found high w/o low attribute. */
10082 /* Found consecutive range of addresses. */
10087 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10090 unsigned int ranges_offset
= DW_UNSND (attr
) + cu
->ranges_base
;
10092 /* Value of the DW_AT_ranges attribute is the offset in the
10093 .debug_ranges section. */
10094 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10096 /* Found discontinuous range of addresses. */
10101 /* read_partial_die has also the strict LOW < HIGH requirement. */
10105 /* When using the GNU linker, .gnu.linkonce. sections are used to
10106 eliminate duplicate copies of functions and vtables and such.
10107 The linker will arbitrarily choose one and discard the others.
10108 The AT_*_pc values for such functions refer to local labels in
10109 these sections. If the section from that file was discarded, the
10110 labels are not in the output, so the relocs get a value of 0.
10111 If this is a discarded function, mark the pc bounds as invalid,
10112 so that GDB will ignore it. */
10113 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10122 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10123 its low and high PC addresses. Do nothing if these addresses could not
10124 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10125 and HIGHPC to the high address if greater than HIGHPC. */
10128 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10129 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10130 struct dwarf2_cu
*cu
)
10132 CORE_ADDR low
, high
;
10133 struct die_info
*child
= die
->child
;
10135 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10137 *lowpc
= min (*lowpc
, low
);
10138 *highpc
= max (*highpc
, high
);
10141 /* If the language does not allow nested subprograms (either inside
10142 subprograms or lexical blocks), we're done. */
10143 if (cu
->language
!= language_ada
)
10146 /* Check all the children of the given DIE. If it contains nested
10147 subprograms, then check their pc bounds. Likewise, we need to
10148 check lexical blocks as well, as they may also contain subprogram
10150 while (child
&& child
->tag
)
10152 if (child
->tag
== DW_TAG_subprogram
10153 || child
->tag
== DW_TAG_lexical_block
)
10154 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10155 child
= sibling_die (child
);
10159 /* Get the low and high pc's represented by the scope DIE, and store
10160 them in *LOWPC and *HIGHPC. If the correct values can't be
10161 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10164 get_scope_pc_bounds (struct die_info
*die
,
10165 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10166 struct dwarf2_cu
*cu
)
10168 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10169 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10170 CORE_ADDR current_low
, current_high
;
10172 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10174 best_low
= current_low
;
10175 best_high
= current_high
;
10179 struct die_info
*child
= die
->child
;
10181 while (child
&& child
->tag
)
10183 switch (child
->tag
) {
10184 case DW_TAG_subprogram
:
10185 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10187 case DW_TAG_namespace
:
10188 case DW_TAG_module
:
10189 /* FIXME: carlton/2004-01-16: Should we do this for
10190 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10191 that current GCC's always emit the DIEs corresponding
10192 to definitions of methods of classes as children of a
10193 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10194 the DIEs giving the declarations, which could be
10195 anywhere). But I don't see any reason why the
10196 standards says that they have to be there. */
10197 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10199 if (current_low
!= ((CORE_ADDR
) -1))
10201 best_low
= min (best_low
, current_low
);
10202 best_high
= max (best_high
, current_high
);
10210 child
= sibling_die (child
);
10215 *highpc
= best_high
;
10218 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10222 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10223 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10225 struct objfile
*objfile
= cu
->objfile
;
10226 struct attribute
*attr
;
10227 struct attribute
*attr_high
;
10229 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10232 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10235 CORE_ADDR low
= DW_ADDR (attr
);
10237 if (attr_high
->form
== DW_FORM_addr
10238 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10239 high
= DW_ADDR (attr_high
);
10241 high
= low
+ DW_UNSND (attr_high
);
10243 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10247 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10250 bfd
*obfd
= objfile
->obfd
;
10252 /* The value of the DW_AT_ranges attribute is the offset of the
10253 address range list in the .debug_ranges section. */
10254 unsigned long offset
= DW_UNSND (attr
) + cu
->ranges_base
;
10255 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10257 /* For some target architectures, but not others, the
10258 read_address function sign-extends the addresses it returns.
10259 To recognize base address selection entries, we need a
10261 unsigned int addr_size
= cu
->header
.addr_size
;
10262 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10264 /* The base address, to which the next pair is relative. Note
10265 that this 'base' is a DWARF concept: most entries in a range
10266 list are relative, to reduce the number of relocs against the
10267 debugging information. This is separate from this function's
10268 'baseaddr' argument, which GDB uses to relocate debugging
10269 information from a shared library based on the address at
10270 which the library was loaded. */
10271 CORE_ADDR base
= cu
->base_address
;
10272 int base_known
= cu
->base_known
;
10274 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10275 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10277 complaint (&symfile_complaints
,
10278 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10285 unsigned int bytes_read
;
10286 CORE_ADDR start
, end
;
10288 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10289 buffer
+= bytes_read
;
10290 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10291 buffer
+= bytes_read
;
10293 /* Did we find the end of the range list? */
10294 if (start
== 0 && end
== 0)
10297 /* Did we find a base address selection entry? */
10298 else if ((start
& base_select_mask
) == base_select_mask
)
10304 /* We found an ordinary address range. */
10309 complaint (&symfile_complaints
,
10310 _("Invalid .debug_ranges data "
10311 "(no base address)"));
10317 /* Inverted range entries are invalid. */
10318 complaint (&symfile_complaints
,
10319 _("Invalid .debug_ranges data "
10320 "(inverted range)"));
10324 /* Empty range entries have no effect. */
10328 start
+= base
+ baseaddr
;
10329 end
+= base
+ baseaddr
;
10331 /* A not-uncommon case of bad debug info.
10332 Don't pollute the addrmap with bad data. */
10333 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10335 complaint (&symfile_complaints
,
10336 _(".debug_ranges entry has start address of zero"
10337 " [in module %s]"), objfile
->name
);
10341 record_block_range (block
, start
, end
- 1);
10347 /* Check whether the producer field indicates either of GCC < 4.6, or the
10348 Intel C/C++ compiler, and cache the result in CU. */
10351 check_producer (struct dwarf2_cu
*cu
)
10354 int major
, minor
, release
;
10356 if (cu
->producer
== NULL
)
10358 /* For unknown compilers expect their behavior is DWARF version
10361 GCC started to support .debug_types sections by -gdwarf-4 since
10362 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10363 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10364 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10365 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10367 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10369 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10371 cs
= &cu
->producer
[strlen ("GNU ")];
10372 while (*cs
&& !isdigit (*cs
))
10374 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10376 /* Not recognized as GCC. */
10380 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10381 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10384 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10385 cu
->producer_is_icc
= 1;
10388 /* For other non-GCC compilers, expect their behavior is DWARF version
10392 cu
->checked_producer
= 1;
10395 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10396 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10397 during 4.6.0 experimental. */
10400 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10402 if (!cu
->checked_producer
)
10403 check_producer (cu
);
10405 return cu
->producer_is_gxx_lt_4_6
;
10408 /* Return the default accessibility type if it is not overriden by
10409 DW_AT_accessibility. */
10411 static enum dwarf_access_attribute
10412 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10414 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10416 /* The default DWARF 2 accessibility for members is public, the default
10417 accessibility for inheritance is private. */
10419 if (die
->tag
!= DW_TAG_inheritance
)
10420 return DW_ACCESS_public
;
10422 return DW_ACCESS_private
;
10426 /* DWARF 3+ defines the default accessibility a different way. The same
10427 rules apply now for DW_TAG_inheritance as for the members and it only
10428 depends on the container kind. */
10430 if (die
->parent
->tag
== DW_TAG_class_type
)
10431 return DW_ACCESS_private
;
10433 return DW_ACCESS_public
;
10437 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10438 offset. If the attribute was not found return 0, otherwise return
10439 1. If it was found but could not properly be handled, set *OFFSET
10443 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10446 struct attribute
*attr
;
10448 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10453 /* Note that we do not check for a section offset first here.
10454 This is because DW_AT_data_member_location is new in DWARF 4,
10455 so if we see it, we can assume that a constant form is really
10456 a constant and not a section offset. */
10457 if (attr_form_is_constant (attr
))
10458 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10459 else if (attr_form_is_section_offset (attr
))
10460 dwarf2_complex_location_expr_complaint ();
10461 else if (attr_form_is_block (attr
))
10462 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10464 dwarf2_complex_location_expr_complaint ();
10472 /* Add an aggregate field to the field list. */
10475 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10476 struct dwarf2_cu
*cu
)
10478 struct objfile
*objfile
= cu
->objfile
;
10479 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10480 struct nextfield
*new_field
;
10481 struct attribute
*attr
;
10483 char *fieldname
= "";
10485 /* Allocate a new field list entry and link it in. */
10486 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10487 make_cleanup (xfree
, new_field
);
10488 memset (new_field
, 0, sizeof (struct nextfield
));
10490 if (die
->tag
== DW_TAG_inheritance
)
10492 new_field
->next
= fip
->baseclasses
;
10493 fip
->baseclasses
= new_field
;
10497 new_field
->next
= fip
->fields
;
10498 fip
->fields
= new_field
;
10502 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10504 new_field
->accessibility
= DW_UNSND (attr
);
10506 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10507 if (new_field
->accessibility
!= DW_ACCESS_public
)
10508 fip
->non_public_fields
= 1;
10510 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10512 new_field
->virtuality
= DW_UNSND (attr
);
10514 new_field
->virtuality
= DW_VIRTUALITY_none
;
10516 fp
= &new_field
->field
;
10518 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10522 /* Data member other than a C++ static data member. */
10524 /* Get type of field. */
10525 fp
->type
= die_type (die
, cu
);
10527 SET_FIELD_BITPOS (*fp
, 0);
10529 /* Get bit size of field (zero if none). */
10530 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10533 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10537 FIELD_BITSIZE (*fp
) = 0;
10540 /* Get bit offset of field. */
10541 if (handle_data_member_location (die
, cu
, &offset
))
10542 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10543 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10546 if (gdbarch_bits_big_endian (gdbarch
))
10548 /* For big endian bits, the DW_AT_bit_offset gives the
10549 additional bit offset from the MSB of the containing
10550 anonymous object to the MSB of the field. We don't
10551 have to do anything special since we don't need to
10552 know the size of the anonymous object. */
10553 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10557 /* For little endian bits, compute the bit offset to the
10558 MSB of the anonymous object, subtract off the number of
10559 bits from the MSB of the field to the MSB of the
10560 object, and then subtract off the number of bits of
10561 the field itself. The result is the bit offset of
10562 the LSB of the field. */
10563 int anonymous_size
;
10564 int bit_offset
= DW_UNSND (attr
);
10566 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10569 /* The size of the anonymous object containing
10570 the bit field is explicit, so use the
10571 indicated size (in bytes). */
10572 anonymous_size
= DW_UNSND (attr
);
10576 /* The size of the anonymous object containing
10577 the bit field must be inferred from the type
10578 attribute of the data member containing the
10580 anonymous_size
= TYPE_LENGTH (fp
->type
);
10582 SET_FIELD_BITPOS (*fp
,
10583 (FIELD_BITPOS (*fp
)
10584 + anonymous_size
* bits_per_byte
10585 - bit_offset
- FIELD_BITSIZE (*fp
)));
10589 /* Get name of field. */
10590 fieldname
= dwarf2_name (die
, cu
);
10591 if (fieldname
== NULL
)
10594 /* The name is already allocated along with this objfile, so we don't
10595 need to duplicate it for the type. */
10596 fp
->name
= fieldname
;
10598 /* Change accessibility for artificial fields (e.g. virtual table
10599 pointer or virtual base class pointer) to private. */
10600 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10602 FIELD_ARTIFICIAL (*fp
) = 1;
10603 new_field
->accessibility
= DW_ACCESS_private
;
10604 fip
->non_public_fields
= 1;
10607 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10609 /* C++ static member. */
10611 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10612 is a declaration, but all versions of G++ as of this writing
10613 (so through at least 3.2.1) incorrectly generate
10614 DW_TAG_variable tags. */
10616 const char *physname
;
10618 /* Get name of field. */
10619 fieldname
= dwarf2_name (die
, cu
);
10620 if (fieldname
== NULL
)
10623 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10625 /* Only create a symbol if this is an external value.
10626 new_symbol checks this and puts the value in the global symbol
10627 table, which we want. If it is not external, new_symbol
10628 will try to put the value in cu->list_in_scope which is wrong. */
10629 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10631 /* A static const member, not much different than an enum as far as
10632 we're concerned, except that we can support more types. */
10633 new_symbol (die
, NULL
, cu
);
10636 /* Get physical name. */
10637 physname
= dwarf2_physname (fieldname
, die
, cu
);
10639 /* The name is already allocated along with this objfile, so we don't
10640 need to duplicate it for the type. */
10641 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10642 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10643 FIELD_NAME (*fp
) = fieldname
;
10645 else if (die
->tag
== DW_TAG_inheritance
)
10649 /* C++ base class field. */
10650 if (handle_data_member_location (die
, cu
, &offset
))
10651 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10652 FIELD_BITSIZE (*fp
) = 0;
10653 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10654 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10655 fip
->nbaseclasses
++;
10659 /* Add a typedef defined in the scope of the FIP's class. */
10662 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10663 struct dwarf2_cu
*cu
)
10665 struct objfile
*objfile
= cu
->objfile
;
10666 struct typedef_field_list
*new_field
;
10667 struct attribute
*attr
;
10668 struct typedef_field
*fp
;
10669 char *fieldname
= "";
10671 /* Allocate a new field list entry and link it in. */
10672 new_field
= xzalloc (sizeof (*new_field
));
10673 make_cleanup (xfree
, new_field
);
10675 gdb_assert (die
->tag
== DW_TAG_typedef
);
10677 fp
= &new_field
->field
;
10679 /* Get name of field. */
10680 fp
->name
= dwarf2_name (die
, cu
);
10681 if (fp
->name
== NULL
)
10684 fp
->type
= read_type_die (die
, cu
);
10686 new_field
->next
= fip
->typedef_field_list
;
10687 fip
->typedef_field_list
= new_field
;
10688 fip
->typedef_field_list_count
++;
10691 /* Create the vector of fields, and attach it to the type. */
10694 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10695 struct dwarf2_cu
*cu
)
10697 int nfields
= fip
->nfields
;
10699 /* Record the field count, allocate space for the array of fields,
10700 and create blank accessibility bitfields if necessary. */
10701 TYPE_NFIELDS (type
) = nfields
;
10702 TYPE_FIELDS (type
) = (struct field
*)
10703 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10704 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10706 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10708 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10710 TYPE_FIELD_PRIVATE_BITS (type
) =
10711 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10712 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10714 TYPE_FIELD_PROTECTED_BITS (type
) =
10715 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10716 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10718 TYPE_FIELD_IGNORE_BITS (type
) =
10719 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10720 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10723 /* If the type has baseclasses, allocate and clear a bit vector for
10724 TYPE_FIELD_VIRTUAL_BITS. */
10725 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10727 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10728 unsigned char *pointer
;
10730 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10731 pointer
= TYPE_ALLOC (type
, num_bytes
);
10732 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10733 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10734 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10737 /* Copy the saved-up fields into the field vector. Start from the head of
10738 the list, adding to the tail of the field array, so that they end up in
10739 the same order in the array in which they were added to the list. */
10740 while (nfields
-- > 0)
10742 struct nextfield
*fieldp
;
10746 fieldp
= fip
->fields
;
10747 fip
->fields
= fieldp
->next
;
10751 fieldp
= fip
->baseclasses
;
10752 fip
->baseclasses
= fieldp
->next
;
10755 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10756 switch (fieldp
->accessibility
)
10758 case DW_ACCESS_private
:
10759 if (cu
->language
!= language_ada
)
10760 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10763 case DW_ACCESS_protected
:
10764 if (cu
->language
!= language_ada
)
10765 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10768 case DW_ACCESS_public
:
10772 /* Unknown accessibility. Complain and treat it as public. */
10774 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10775 fieldp
->accessibility
);
10779 if (nfields
< fip
->nbaseclasses
)
10781 switch (fieldp
->virtuality
)
10783 case DW_VIRTUALITY_virtual
:
10784 case DW_VIRTUALITY_pure_virtual
:
10785 if (cu
->language
== language_ada
)
10786 error (_("unexpected virtuality in component of Ada type"));
10787 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10794 /* Add a member function to the proper fieldlist. */
10797 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10798 struct type
*type
, struct dwarf2_cu
*cu
)
10800 struct objfile
*objfile
= cu
->objfile
;
10801 struct attribute
*attr
;
10802 struct fnfieldlist
*flp
;
10804 struct fn_field
*fnp
;
10806 struct nextfnfield
*new_fnfield
;
10807 struct type
*this_type
;
10808 enum dwarf_access_attribute accessibility
;
10810 if (cu
->language
== language_ada
)
10811 error (_("unexpected member function in Ada type"));
10813 /* Get name of member function. */
10814 fieldname
= dwarf2_name (die
, cu
);
10815 if (fieldname
== NULL
)
10818 /* Look up member function name in fieldlist. */
10819 for (i
= 0; i
< fip
->nfnfields
; i
++)
10821 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10825 /* Create new list element if necessary. */
10826 if (i
< fip
->nfnfields
)
10827 flp
= &fip
->fnfieldlists
[i
];
10830 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10832 fip
->fnfieldlists
= (struct fnfieldlist
*)
10833 xrealloc (fip
->fnfieldlists
,
10834 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10835 * sizeof (struct fnfieldlist
));
10836 if (fip
->nfnfields
== 0)
10837 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10839 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10840 flp
->name
= fieldname
;
10843 i
= fip
->nfnfields
++;
10846 /* Create a new member function field and chain it to the field list
10848 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10849 make_cleanup (xfree
, new_fnfield
);
10850 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10851 new_fnfield
->next
= flp
->head
;
10852 flp
->head
= new_fnfield
;
10855 /* Fill in the member function field info. */
10856 fnp
= &new_fnfield
->fnfield
;
10858 /* Delay processing of the physname until later. */
10859 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10861 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10866 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10867 fnp
->physname
= physname
? physname
: "";
10870 fnp
->type
= alloc_type (objfile
);
10871 this_type
= read_type_die (die
, cu
);
10872 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10874 int nparams
= TYPE_NFIELDS (this_type
);
10876 /* TYPE is the domain of this method, and THIS_TYPE is the type
10877 of the method itself (TYPE_CODE_METHOD). */
10878 smash_to_method_type (fnp
->type
, type
,
10879 TYPE_TARGET_TYPE (this_type
),
10880 TYPE_FIELDS (this_type
),
10881 TYPE_NFIELDS (this_type
),
10882 TYPE_VARARGS (this_type
));
10884 /* Handle static member functions.
10885 Dwarf2 has no clean way to discern C++ static and non-static
10886 member functions. G++ helps GDB by marking the first
10887 parameter for non-static member functions (which is the this
10888 pointer) as artificial. We obtain this information from
10889 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10890 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10891 fnp
->voffset
= VOFFSET_STATIC
;
10894 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10895 dwarf2_full_name (fieldname
, die
, cu
));
10897 /* Get fcontext from DW_AT_containing_type if present. */
10898 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10899 fnp
->fcontext
= die_containing_type (die
, cu
);
10901 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10902 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10904 /* Get accessibility. */
10905 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10907 accessibility
= DW_UNSND (attr
);
10909 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10910 switch (accessibility
)
10912 case DW_ACCESS_private
:
10913 fnp
->is_private
= 1;
10915 case DW_ACCESS_protected
:
10916 fnp
->is_protected
= 1;
10920 /* Check for artificial methods. */
10921 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
10922 if (attr
&& DW_UNSND (attr
) != 0)
10923 fnp
->is_artificial
= 1;
10925 /* Get index in virtual function table if it is a virtual member
10926 function. For older versions of GCC, this is an offset in the
10927 appropriate virtual table, as specified by DW_AT_containing_type.
10928 For everyone else, it is an expression to be evaluated relative
10929 to the object address. */
10931 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
10934 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
10936 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
10938 /* Old-style GCC. */
10939 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
10941 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10942 || (DW_BLOCK (attr
)->size
> 1
10943 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
10944 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
10946 struct dwarf_block blk
;
10949 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
10951 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
10952 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
10953 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10954 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
10955 dwarf2_complex_location_expr_complaint ();
10957 fnp
->voffset
/= cu
->header
.addr_size
;
10961 dwarf2_complex_location_expr_complaint ();
10963 if (!fnp
->fcontext
)
10964 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
10966 else if (attr_form_is_section_offset (attr
))
10968 dwarf2_complex_location_expr_complaint ();
10972 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10978 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10979 if (attr
&& DW_UNSND (attr
))
10981 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10982 complaint (&symfile_complaints
,
10983 _("Member function \"%s\" (offset %d) is virtual "
10984 "but the vtable offset is not specified"),
10985 fieldname
, die
->offset
.sect_off
);
10986 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10987 TYPE_CPLUS_DYNAMIC (type
) = 1;
10992 /* Create the vector of member function fields, and attach it to the type. */
10995 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
10996 struct dwarf2_cu
*cu
)
10998 struct fnfieldlist
*flp
;
11001 if (cu
->language
== language_ada
)
11002 error (_("unexpected member functions in Ada type"));
11004 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11005 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
11006 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
11008 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
11010 struct nextfnfield
*nfp
= flp
->head
;
11011 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
11014 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
11015 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
11016 fn_flp
->fn_fields
= (struct fn_field
*)
11017 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
11018 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
11019 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
11022 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11025 /* Returns non-zero if NAME is the name of a vtable member in CU's
11026 language, zero otherwise. */
11028 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11030 static const char vptr
[] = "_vptr";
11031 static const char vtable
[] = "vtable";
11033 /* Look for the C++ and Java forms of the vtable. */
11034 if ((cu
->language
== language_java
11035 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11036 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11037 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11043 /* GCC outputs unnamed structures that are really pointers to member
11044 functions, with the ABI-specified layout. If TYPE describes
11045 such a structure, smash it into a member function type.
11047 GCC shouldn't do this; it should just output pointer to member DIEs.
11048 This is GCC PR debug/28767. */
11051 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11053 struct type
*pfn_type
, *domain_type
, *new_type
;
11055 /* Check for a structure with no name and two children. */
11056 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11059 /* Check for __pfn and __delta members. */
11060 if (TYPE_FIELD_NAME (type
, 0) == NULL
11061 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11062 || TYPE_FIELD_NAME (type
, 1) == NULL
11063 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11066 /* Find the type of the method. */
11067 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11068 if (pfn_type
== NULL
11069 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11070 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11073 /* Look for the "this" argument. */
11074 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11075 if (TYPE_NFIELDS (pfn_type
) == 0
11076 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11077 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11080 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11081 new_type
= alloc_type (objfile
);
11082 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11083 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11084 TYPE_VARARGS (pfn_type
));
11085 smash_to_methodptr_type (type
, new_type
);
11088 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11092 producer_is_icc (struct dwarf2_cu
*cu
)
11094 if (!cu
->checked_producer
)
11095 check_producer (cu
);
11097 return cu
->producer_is_icc
;
11100 /* Called when we find the DIE that starts a structure or union scope
11101 (definition) to create a type for the structure or union. Fill in
11102 the type's name and general properties; the members will not be
11103 processed until process_structure_type.
11105 NOTE: we need to call these functions regardless of whether or not the
11106 DIE has a DW_AT_name attribute, since it might be an anonymous
11107 structure or union. This gets the type entered into our set of
11108 user defined types.
11110 However, if the structure is incomplete (an opaque struct/union)
11111 then suppress creating a symbol table entry for it since gdb only
11112 wants to find the one with the complete definition. Note that if
11113 it is complete, we just call new_symbol, which does it's own
11114 checking about whether the struct/union is anonymous or not (and
11115 suppresses creating a symbol table entry itself). */
11117 static struct type
*
11118 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11120 struct objfile
*objfile
= cu
->objfile
;
11122 struct attribute
*attr
;
11125 /* If the definition of this type lives in .debug_types, read that type.
11126 Don't follow DW_AT_specification though, that will take us back up
11127 the chain and we want to go down. */
11128 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11131 struct dwarf2_cu
*type_cu
= cu
;
11132 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11134 /* We could just recurse on read_structure_type, but we need to call
11135 get_die_type to ensure only one type for this DIE is created.
11136 This is important, for example, because for c++ classes we need
11137 TYPE_NAME set which is only done by new_symbol. Blech. */
11138 type
= read_type_die (type_die
, type_cu
);
11140 /* TYPE_CU may not be the same as CU.
11141 Ensure TYPE is recorded in CU's type_hash table. */
11142 return set_die_type (die
, type
, cu
);
11145 type
= alloc_type (objfile
);
11146 INIT_CPLUS_SPECIFIC (type
);
11148 name
= dwarf2_name (die
, cu
);
11151 if (cu
->language
== language_cplus
11152 || cu
->language
== language_java
)
11154 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
11156 /* dwarf2_full_name might have already finished building the DIE's
11157 type. If so, there is no need to continue. */
11158 if (get_die_type (die
, cu
) != NULL
)
11159 return get_die_type (die
, cu
);
11161 TYPE_TAG_NAME (type
) = full_name
;
11162 if (die
->tag
== DW_TAG_structure_type
11163 || die
->tag
== DW_TAG_class_type
)
11164 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11168 /* The name is already allocated along with this objfile, so
11169 we don't need to duplicate it for the type. */
11170 TYPE_TAG_NAME (type
) = (char *) name
;
11171 if (die
->tag
== DW_TAG_class_type
)
11172 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11176 if (die
->tag
== DW_TAG_structure_type
)
11178 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11180 else if (die
->tag
== DW_TAG_union_type
)
11182 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11186 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11189 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11190 TYPE_DECLARED_CLASS (type
) = 1;
11192 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11195 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11199 TYPE_LENGTH (type
) = 0;
11202 if (producer_is_icc (cu
))
11204 /* ICC does not output the required DW_AT_declaration
11205 on incomplete types, but gives them a size of zero. */
11208 TYPE_STUB_SUPPORTED (type
) = 1;
11210 if (die_is_declaration (die
, cu
))
11211 TYPE_STUB (type
) = 1;
11212 else if (attr
== NULL
&& die
->child
== NULL
11213 && producer_is_realview (cu
->producer
))
11214 /* RealView does not output the required DW_AT_declaration
11215 on incomplete types. */
11216 TYPE_STUB (type
) = 1;
11218 /* We need to add the type field to the die immediately so we don't
11219 infinitely recurse when dealing with pointers to the structure
11220 type within the structure itself. */
11221 set_die_type (die
, type
, cu
);
11223 /* set_die_type should be already done. */
11224 set_descriptive_type (type
, die
, cu
);
11229 /* Finish creating a structure or union type, including filling in
11230 its members and creating a symbol for it. */
11233 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11235 struct objfile
*objfile
= cu
->objfile
;
11236 struct die_info
*child_die
= die
->child
;
11239 type
= get_die_type (die
, cu
);
11241 type
= read_structure_type (die
, cu
);
11243 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11245 struct field_info fi
;
11246 struct die_info
*child_die
;
11247 VEC (symbolp
) *template_args
= NULL
;
11248 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11250 memset (&fi
, 0, sizeof (struct field_info
));
11252 child_die
= die
->child
;
11254 while (child_die
&& child_die
->tag
)
11256 if (child_die
->tag
== DW_TAG_member
11257 || child_die
->tag
== DW_TAG_variable
)
11259 /* NOTE: carlton/2002-11-05: A C++ static data member
11260 should be a DW_TAG_member that is a declaration, but
11261 all versions of G++ as of this writing (so through at
11262 least 3.2.1) incorrectly generate DW_TAG_variable
11263 tags for them instead. */
11264 dwarf2_add_field (&fi
, child_die
, cu
);
11266 else if (child_die
->tag
== DW_TAG_subprogram
)
11268 /* C++ member function. */
11269 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11271 else if (child_die
->tag
== DW_TAG_inheritance
)
11273 /* C++ base class field. */
11274 dwarf2_add_field (&fi
, child_die
, cu
);
11276 else if (child_die
->tag
== DW_TAG_typedef
)
11277 dwarf2_add_typedef (&fi
, child_die
, cu
);
11278 else if (child_die
->tag
== DW_TAG_template_type_param
11279 || child_die
->tag
== DW_TAG_template_value_param
)
11281 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11284 VEC_safe_push (symbolp
, template_args
, arg
);
11287 child_die
= sibling_die (child_die
);
11290 /* Attach template arguments to type. */
11291 if (! VEC_empty (symbolp
, template_args
))
11293 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11294 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11295 = VEC_length (symbolp
, template_args
);
11296 TYPE_TEMPLATE_ARGUMENTS (type
)
11297 = obstack_alloc (&objfile
->objfile_obstack
,
11298 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11299 * sizeof (struct symbol
*)));
11300 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11301 VEC_address (symbolp
, template_args
),
11302 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11303 * sizeof (struct symbol
*)));
11304 VEC_free (symbolp
, template_args
);
11307 /* Attach fields and member functions to the type. */
11309 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11312 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11314 /* Get the type which refers to the base class (possibly this
11315 class itself) which contains the vtable pointer for the current
11316 class from the DW_AT_containing_type attribute. This use of
11317 DW_AT_containing_type is a GNU extension. */
11319 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11321 struct type
*t
= die_containing_type (die
, cu
);
11323 TYPE_VPTR_BASETYPE (type
) = t
;
11328 /* Our own class provides vtbl ptr. */
11329 for (i
= TYPE_NFIELDS (t
) - 1;
11330 i
>= TYPE_N_BASECLASSES (t
);
11333 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11335 if (is_vtable_name (fieldname
, cu
))
11337 TYPE_VPTR_FIELDNO (type
) = i
;
11342 /* Complain if virtual function table field not found. */
11343 if (i
< TYPE_N_BASECLASSES (t
))
11344 complaint (&symfile_complaints
,
11345 _("virtual function table pointer "
11346 "not found when defining class '%s'"),
11347 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11352 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11355 else if (cu
->producer
11356 && strncmp (cu
->producer
,
11357 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11359 /* The IBM XLC compiler does not provide direct indication
11360 of the containing type, but the vtable pointer is
11361 always named __vfp. */
11365 for (i
= TYPE_NFIELDS (type
) - 1;
11366 i
>= TYPE_N_BASECLASSES (type
);
11369 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11371 TYPE_VPTR_FIELDNO (type
) = i
;
11372 TYPE_VPTR_BASETYPE (type
) = type
;
11379 /* Copy fi.typedef_field_list linked list elements content into the
11380 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11381 if (fi
.typedef_field_list
)
11383 int i
= fi
.typedef_field_list_count
;
11385 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11386 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11387 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11388 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11390 /* Reverse the list order to keep the debug info elements order. */
11393 struct typedef_field
*dest
, *src
;
11395 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11396 src
= &fi
.typedef_field_list
->field
;
11397 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11402 do_cleanups (back_to
);
11404 if (HAVE_CPLUS_STRUCT (type
))
11405 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11408 quirk_gcc_member_function_pointer (type
, objfile
);
11410 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11411 snapshots) has been known to create a die giving a declaration
11412 for a class that has, as a child, a die giving a definition for a
11413 nested class. So we have to process our children even if the
11414 current die is a declaration. Normally, of course, a declaration
11415 won't have any children at all. */
11417 while (child_die
!= NULL
&& child_die
->tag
)
11419 if (child_die
->tag
== DW_TAG_member
11420 || child_die
->tag
== DW_TAG_variable
11421 || child_die
->tag
== DW_TAG_inheritance
11422 || child_die
->tag
== DW_TAG_template_value_param
11423 || child_die
->tag
== DW_TAG_template_type_param
)
11428 process_die (child_die
, cu
);
11430 child_die
= sibling_die (child_die
);
11433 /* Do not consider external references. According to the DWARF standard,
11434 these DIEs are identified by the fact that they have no byte_size
11435 attribute, and a declaration attribute. */
11436 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11437 || !die_is_declaration (die
, cu
))
11438 new_symbol (die
, type
, cu
);
11441 /* Given a DW_AT_enumeration_type die, set its type. We do not
11442 complete the type's fields yet, or create any symbols. */
11444 static struct type
*
11445 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11447 struct objfile
*objfile
= cu
->objfile
;
11449 struct attribute
*attr
;
11452 /* If the definition of this type lives in .debug_types, read that type.
11453 Don't follow DW_AT_specification though, that will take us back up
11454 the chain and we want to go down. */
11455 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11458 struct dwarf2_cu
*type_cu
= cu
;
11459 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11461 type
= read_type_die (type_die
, type_cu
);
11463 /* TYPE_CU may not be the same as CU.
11464 Ensure TYPE is recorded in CU's type_hash table. */
11465 return set_die_type (die
, type
, cu
);
11468 type
= alloc_type (objfile
);
11470 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11471 name
= dwarf2_full_name (NULL
, die
, cu
);
11473 TYPE_TAG_NAME (type
) = (char *) name
;
11475 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11478 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11482 TYPE_LENGTH (type
) = 0;
11485 /* The enumeration DIE can be incomplete. In Ada, any type can be
11486 declared as private in the package spec, and then defined only
11487 inside the package body. Such types are known as Taft Amendment
11488 Types. When another package uses such a type, an incomplete DIE
11489 may be generated by the compiler. */
11490 if (die_is_declaration (die
, cu
))
11491 TYPE_STUB (type
) = 1;
11493 return set_die_type (die
, type
, cu
);
11496 /* Given a pointer to a die which begins an enumeration, process all
11497 the dies that define the members of the enumeration, and create the
11498 symbol for the enumeration type.
11500 NOTE: We reverse the order of the element list. */
11503 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11505 struct type
*this_type
;
11507 this_type
= get_die_type (die
, cu
);
11508 if (this_type
== NULL
)
11509 this_type
= read_enumeration_type (die
, cu
);
11511 if (die
->child
!= NULL
)
11513 struct die_info
*child_die
;
11514 struct symbol
*sym
;
11515 struct field
*fields
= NULL
;
11516 int num_fields
= 0;
11517 int unsigned_enum
= 1;
11522 child_die
= die
->child
;
11523 while (child_die
&& child_die
->tag
)
11525 if (child_die
->tag
!= DW_TAG_enumerator
)
11527 process_die (child_die
, cu
);
11531 name
= dwarf2_name (child_die
, cu
);
11534 sym
= new_symbol (child_die
, this_type
, cu
);
11535 if (SYMBOL_VALUE (sym
) < 0)
11540 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11543 mask
|= SYMBOL_VALUE (sym
);
11545 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11547 fields
= (struct field
*)
11549 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11550 * sizeof (struct field
));
11553 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11554 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11555 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11556 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11562 child_die
= sibling_die (child_die
);
11567 TYPE_NFIELDS (this_type
) = num_fields
;
11568 TYPE_FIELDS (this_type
) = (struct field
*)
11569 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11570 memcpy (TYPE_FIELDS (this_type
), fields
,
11571 sizeof (struct field
) * num_fields
);
11575 TYPE_UNSIGNED (this_type
) = 1;
11577 TYPE_FLAG_ENUM (this_type
) = 1;
11580 /* If we are reading an enum from a .debug_types unit, and the enum
11581 is a declaration, and the enum is not the signatured type in the
11582 unit, then we do not want to add a symbol for it. Adding a
11583 symbol would in some cases obscure the true definition of the
11584 enum, giving users an incomplete type when the definition is
11585 actually available. Note that we do not want to do this for all
11586 enums which are just declarations, because C++0x allows forward
11587 enum declarations. */
11588 if (cu
->per_cu
->is_debug_types
11589 && die_is_declaration (die
, cu
))
11591 struct signatured_type
*sig_type
;
11594 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11595 cu
->per_cu
->info_or_types_section
,
11596 cu
->per_cu
->offset
);
11597 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11598 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11602 new_symbol (die
, this_type
, cu
);
11605 /* Extract all information from a DW_TAG_array_type DIE and put it in
11606 the DIE's type field. For now, this only handles one dimensional
11609 static struct type
*
11610 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11612 struct objfile
*objfile
= cu
->objfile
;
11613 struct die_info
*child_die
;
11615 struct type
*element_type
, *range_type
, *index_type
;
11616 struct type
**range_types
= NULL
;
11617 struct attribute
*attr
;
11619 struct cleanup
*back_to
;
11622 element_type
= die_type (die
, cu
);
11624 /* The die_type call above may have already set the type for this DIE. */
11625 type
= get_die_type (die
, cu
);
11629 /* Irix 6.2 native cc creates array types without children for
11630 arrays with unspecified length. */
11631 if (die
->child
== NULL
)
11633 index_type
= objfile_type (objfile
)->builtin_int
;
11634 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11635 type
= create_array_type (NULL
, element_type
, range_type
);
11636 return set_die_type (die
, type
, cu
);
11639 back_to
= make_cleanup (null_cleanup
, NULL
);
11640 child_die
= die
->child
;
11641 while (child_die
&& child_die
->tag
)
11643 if (child_die
->tag
== DW_TAG_subrange_type
)
11645 struct type
*child_type
= read_type_die (child_die
, cu
);
11647 if (child_type
!= NULL
)
11649 /* The range type was succesfully read. Save it for the
11650 array type creation. */
11651 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11653 range_types
= (struct type
**)
11654 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11655 * sizeof (struct type
*));
11657 make_cleanup (free_current_contents
, &range_types
);
11659 range_types
[ndim
++] = child_type
;
11662 child_die
= sibling_die (child_die
);
11665 /* Dwarf2 dimensions are output from left to right, create the
11666 necessary array types in backwards order. */
11668 type
= element_type
;
11670 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11675 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11680 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11683 /* Understand Dwarf2 support for vector types (like they occur on
11684 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11685 array type. This is not part of the Dwarf2/3 standard yet, but a
11686 custom vendor extension. The main difference between a regular
11687 array and the vector variant is that vectors are passed by value
11689 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11691 make_vector_type (type
);
11693 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11694 implementation may choose to implement triple vectors using this
11696 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11699 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11700 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11702 complaint (&symfile_complaints
,
11703 _("DW_AT_byte_size for array type smaller "
11704 "than the total size of elements"));
11707 name
= dwarf2_name (die
, cu
);
11709 TYPE_NAME (type
) = name
;
11711 /* Install the type in the die. */
11712 set_die_type (die
, type
, cu
);
11714 /* set_die_type should be already done. */
11715 set_descriptive_type (type
, die
, cu
);
11717 do_cleanups (back_to
);
11722 static enum dwarf_array_dim_ordering
11723 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11725 struct attribute
*attr
;
11727 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11729 if (attr
) return DW_SND (attr
);
11731 /* GNU F77 is a special case, as at 08/2004 array type info is the
11732 opposite order to the dwarf2 specification, but data is still
11733 laid out as per normal fortran.
11735 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11736 version checking. */
11738 if (cu
->language
== language_fortran
11739 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11741 return DW_ORD_row_major
;
11744 switch (cu
->language_defn
->la_array_ordering
)
11746 case array_column_major
:
11747 return DW_ORD_col_major
;
11748 case array_row_major
:
11750 return DW_ORD_row_major
;
11754 /* Extract all information from a DW_TAG_set_type DIE and put it in
11755 the DIE's type field. */
11757 static struct type
*
11758 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11760 struct type
*domain_type
, *set_type
;
11761 struct attribute
*attr
;
11763 domain_type
= die_type (die
, cu
);
11765 /* The die_type call above may have already set the type for this DIE. */
11766 set_type
= get_die_type (die
, cu
);
11770 set_type
= create_set_type (NULL
, domain_type
);
11772 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11774 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11776 return set_die_type (die
, set_type
, cu
);
11779 /* A helper for read_common_block that creates a locexpr baton.
11780 SYM is the symbol which we are marking as computed.
11781 COMMON_DIE is the DIE for the common block.
11782 COMMON_LOC is the location expression attribute for the common
11784 MEMBER_LOC is the location expression attribute for the particular
11785 member of the common block that we are processing.
11786 CU is the CU from which the above come. */
11789 mark_common_block_symbol_computed (struct symbol
*sym
,
11790 struct die_info
*common_die
,
11791 struct attribute
*common_loc
,
11792 struct attribute
*member_loc
,
11793 struct dwarf2_cu
*cu
)
11795 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11796 struct dwarf2_locexpr_baton
*baton
;
11798 unsigned int cu_off
;
11799 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11800 LONGEST offset
= 0;
11802 gdb_assert (common_loc
&& member_loc
);
11803 gdb_assert (attr_form_is_block (common_loc
));
11804 gdb_assert (attr_form_is_block (member_loc
)
11805 || attr_form_is_constant (member_loc
));
11807 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11808 sizeof (struct dwarf2_locexpr_baton
));
11809 baton
->per_cu
= cu
->per_cu
;
11810 gdb_assert (baton
->per_cu
);
11812 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11814 if (attr_form_is_constant (member_loc
))
11816 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11817 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11820 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11822 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11825 *ptr
++ = DW_OP_call4
;
11826 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11827 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11830 if (attr_form_is_constant (member_loc
))
11832 *ptr
++ = DW_OP_addr
;
11833 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11834 ptr
+= cu
->header
.addr_size
;
11838 /* We have to copy the data here, because DW_OP_call4 will only
11839 use a DW_AT_location attribute. */
11840 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11841 ptr
+= DW_BLOCK (member_loc
)->size
;
11844 *ptr
++ = DW_OP_plus
;
11845 gdb_assert (ptr
- baton
->data
== baton
->size
);
11847 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11848 SYMBOL_LOCATION_BATON (sym
) = baton
;
11849 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11852 /* Create appropriate locally-scoped variables for all the
11853 DW_TAG_common_block entries. Also create a struct common_block
11854 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11855 is used to sepate the common blocks name namespace from regular
11859 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11861 struct attribute
*attr
;
11863 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11866 /* Support the .debug_loc offsets. */
11867 if (attr_form_is_block (attr
))
11871 else if (attr_form_is_section_offset (attr
))
11873 dwarf2_complex_location_expr_complaint ();
11878 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11879 "common block member");
11884 if (die
->child
!= NULL
)
11886 struct objfile
*objfile
= cu
->objfile
;
11887 struct die_info
*child_die
;
11888 size_t n_entries
= 0, size
;
11889 struct common_block
*common_block
;
11890 struct symbol
*sym
;
11892 for (child_die
= die
->child
;
11893 child_die
&& child_die
->tag
;
11894 child_die
= sibling_die (child_die
))
11897 size
= (sizeof (struct common_block
)
11898 + (n_entries
- 1) * sizeof (struct symbol
*));
11899 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
11900 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
11901 common_block
->n_entries
= 0;
11903 for (child_die
= die
->child
;
11904 child_die
&& child_die
->tag
;
11905 child_die
= sibling_die (child_die
))
11907 /* Create the symbol in the DW_TAG_common_block block in the current
11909 sym
= new_symbol (child_die
, NULL
, cu
);
11912 struct attribute
*member_loc
;
11914 common_block
->contents
[common_block
->n_entries
++] = sym
;
11916 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
11920 /* GDB has handled this for a long time, but it is
11921 not specified by DWARF. It seems to have been
11922 emitted by gfortran at least as recently as:
11923 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
11924 complaint (&symfile_complaints
,
11925 _("Variable in common block has "
11926 "DW_AT_data_member_location "
11927 "- DIE at 0x%x [in module %s]"),
11928 child_die
->offset
.sect_off
, cu
->objfile
->name
);
11930 if (attr_form_is_section_offset (member_loc
))
11931 dwarf2_complex_location_expr_complaint ();
11932 else if (attr_form_is_constant (member_loc
)
11933 || attr_form_is_block (member_loc
))
11936 mark_common_block_symbol_computed (sym
, die
, attr
,
11940 dwarf2_complex_location_expr_complaint ();
11945 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
11946 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
11950 /* Create a type for a C++ namespace. */
11952 static struct type
*
11953 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11955 struct objfile
*objfile
= cu
->objfile
;
11956 const char *previous_prefix
, *name
;
11960 /* For extensions, reuse the type of the original namespace. */
11961 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
11963 struct die_info
*ext_die
;
11964 struct dwarf2_cu
*ext_cu
= cu
;
11966 ext_die
= dwarf2_extension (die
, &ext_cu
);
11967 type
= read_type_die (ext_die
, ext_cu
);
11969 /* EXT_CU may not be the same as CU.
11970 Ensure TYPE is recorded in CU's type_hash table. */
11971 return set_die_type (die
, type
, cu
);
11974 name
= namespace_name (die
, &is_anonymous
, cu
);
11976 /* Now build the name of the current namespace. */
11978 previous_prefix
= determine_prefix (die
, cu
);
11979 if (previous_prefix
[0] != '\0')
11980 name
= typename_concat (&objfile
->objfile_obstack
,
11981 previous_prefix
, name
, 0, cu
);
11983 /* Create the type. */
11984 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
11986 TYPE_NAME (type
) = (char *) name
;
11987 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
11989 return set_die_type (die
, type
, cu
);
11992 /* Read a C++ namespace. */
11995 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11997 struct objfile
*objfile
= cu
->objfile
;
12000 /* Add a symbol associated to this if we haven't seen the namespace
12001 before. Also, add a using directive if it's an anonymous
12004 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
12008 type
= read_type_die (die
, cu
);
12009 new_symbol (die
, type
, cu
);
12011 namespace_name (die
, &is_anonymous
, cu
);
12014 const char *previous_prefix
= determine_prefix (die
, cu
);
12016 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
12017 NULL
, NULL
, &objfile
->objfile_obstack
);
12021 if (die
->child
!= NULL
)
12023 struct die_info
*child_die
= die
->child
;
12025 while (child_die
&& child_die
->tag
)
12027 process_die (child_die
, cu
);
12028 child_die
= sibling_die (child_die
);
12033 /* Read a Fortran module as type. This DIE can be only a declaration used for
12034 imported module. Still we need that type as local Fortran "use ... only"
12035 declaration imports depend on the created type in determine_prefix. */
12037 static struct type
*
12038 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12040 struct objfile
*objfile
= cu
->objfile
;
12044 module_name
= dwarf2_name (die
, cu
);
12046 complaint (&symfile_complaints
,
12047 _("DW_TAG_module has no name, offset 0x%x"),
12048 die
->offset
.sect_off
);
12049 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12051 /* determine_prefix uses TYPE_TAG_NAME. */
12052 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12054 return set_die_type (die
, type
, cu
);
12057 /* Read a Fortran module. */
12060 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12062 struct die_info
*child_die
= die
->child
;
12064 while (child_die
&& child_die
->tag
)
12066 process_die (child_die
, cu
);
12067 child_die
= sibling_die (child_die
);
12071 /* Return the name of the namespace represented by DIE. Set
12072 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12075 static const char *
12076 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12078 struct die_info
*current_die
;
12079 const char *name
= NULL
;
12081 /* Loop through the extensions until we find a name. */
12083 for (current_die
= die
;
12084 current_die
!= NULL
;
12085 current_die
= dwarf2_extension (die
, &cu
))
12087 name
= dwarf2_name (current_die
, cu
);
12092 /* Is it an anonymous namespace? */
12094 *is_anonymous
= (name
== NULL
);
12096 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12101 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12102 the user defined type vector. */
12104 static struct type
*
12105 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12107 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12108 struct comp_unit_head
*cu_header
= &cu
->header
;
12110 struct attribute
*attr_byte_size
;
12111 struct attribute
*attr_address_class
;
12112 int byte_size
, addr_class
;
12113 struct type
*target_type
;
12115 target_type
= die_type (die
, cu
);
12117 /* The die_type call above may have already set the type for this DIE. */
12118 type
= get_die_type (die
, cu
);
12122 type
= lookup_pointer_type (target_type
);
12124 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12125 if (attr_byte_size
)
12126 byte_size
= DW_UNSND (attr_byte_size
);
12128 byte_size
= cu_header
->addr_size
;
12130 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12131 if (attr_address_class
)
12132 addr_class
= DW_UNSND (attr_address_class
);
12134 addr_class
= DW_ADDR_none
;
12136 /* If the pointer size or address class is different than the
12137 default, create a type variant marked as such and set the
12138 length accordingly. */
12139 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12141 if (gdbarch_address_class_type_flags_p (gdbarch
))
12145 type_flags
= gdbarch_address_class_type_flags
12146 (gdbarch
, byte_size
, addr_class
);
12147 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12149 type
= make_type_with_address_space (type
, type_flags
);
12151 else if (TYPE_LENGTH (type
) != byte_size
)
12153 complaint (&symfile_complaints
,
12154 _("invalid pointer size %d"), byte_size
);
12158 /* Should we also complain about unhandled address classes? */
12162 TYPE_LENGTH (type
) = byte_size
;
12163 return set_die_type (die
, type
, cu
);
12166 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12167 the user defined type vector. */
12169 static struct type
*
12170 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12173 struct type
*to_type
;
12174 struct type
*domain
;
12176 to_type
= die_type (die
, cu
);
12177 domain
= die_containing_type (die
, cu
);
12179 /* The calls above may have already set the type for this DIE. */
12180 type
= get_die_type (die
, cu
);
12184 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12185 type
= lookup_methodptr_type (to_type
);
12187 type
= lookup_memberptr_type (to_type
, domain
);
12189 return set_die_type (die
, type
, cu
);
12192 /* Extract all information from a DW_TAG_reference_type DIE and add to
12193 the user defined type vector. */
12195 static struct type
*
12196 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12198 struct comp_unit_head
*cu_header
= &cu
->header
;
12199 struct type
*type
, *target_type
;
12200 struct attribute
*attr
;
12202 target_type
= die_type (die
, cu
);
12204 /* The die_type call above may have already set the type for this DIE. */
12205 type
= get_die_type (die
, cu
);
12209 type
= lookup_reference_type (target_type
);
12210 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12213 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12217 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12219 return set_die_type (die
, type
, cu
);
12222 static struct type
*
12223 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12225 struct type
*base_type
, *cv_type
;
12227 base_type
= die_type (die
, cu
);
12229 /* The die_type call above may have already set the type for this DIE. */
12230 cv_type
= get_die_type (die
, cu
);
12234 /* In case the const qualifier is applied to an array type, the element type
12235 is so qualified, not the array type (section 6.7.3 of C99). */
12236 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12238 struct type
*el_type
, *inner_array
;
12240 base_type
= copy_type (base_type
);
12241 inner_array
= base_type
;
12243 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12245 TYPE_TARGET_TYPE (inner_array
) =
12246 copy_type (TYPE_TARGET_TYPE (inner_array
));
12247 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12250 el_type
= TYPE_TARGET_TYPE (inner_array
);
12251 TYPE_TARGET_TYPE (inner_array
) =
12252 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12254 return set_die_type (die
, base_type
, cu
);
12257 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12258 return set_die_type (die
, cv_type
, cu
);
12261 static struct type
*
12262 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12264 struct type
*base_type
, *cv_type
;
12266 base_type
= die_type (die
, cu
);
12268 /* The die_type call above may have already set the type for this DIE. */
12269 cv_type
= get_die_type (die
, cu
);
12273 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12274 return set_die_type (die
, cv_type
, cu
);
12277 /* Extract all information from a DW_TAG_string_type DIE and add to
12278 the user defined type vector. It isn't really a user defined type,
12279 but it behaves like one, with other DIE's using an AT_user_def_type
12280 attribute to reference it. */
12282 static struct type
*
12283 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12285 struct objfile
*objfile
= cu
->objfile
;
12286 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12287 struct type
*type
, *range_type
, *index_type
, *char_type
;
12288 struct attribute
*attr
;
12289 unsigned int length
;
12291 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12294 length
= DW_UNSND (attr
);
12298 /* Check for the DW_AT_byte_size attribute. */
12299 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12302 length
= DW_UNSND (attr
);
12310 index_type
= objfile_type (objfile
)->builtin_int
;
12311 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12312 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12313 type
= create_string_type (NULL
, char_type
, range_type
);
12315 return set_die_type (die
, type
, cu
);
12318 /* Handle DIES due to C code like:
12322 int (*funcp)(int a, long l);
12326 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12328 static struct type
*
12329 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12331 struct objfile
*objfile
= cu
->objfile
;
12332 struct type
*type
; /* Type that this function returns. */
12333 struct type
*ftype
; /* Function that returns above type. */
12334 struct attribute
*attr
;
12336 type
= die_type (die
, cu
);
12338 /* The die_type call above may have already set the type for this DIE. */
12339 ftype
= get_die_type (die
, cu
);
12343 ftype
= lookup_function_type (type
);
12345 /* All functions in C++, Pascal and Java have prototypes. */
12346 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12347 if ((attr
&& (DW_UNSND (attr
) != 0))
12348 || cu
->language
== language_cplus
12349 || cu
->language
== language_java
12350 || cu
->language
== language_pascal
)
12351 TYPE_PROTOTYPED (ftype
) = 1;
12352 else if (producer_is_realview (cu
->producer
))
12353 /* RealView does not emit DW_AT_prototyped. We can not
12354 distinguish prototyped and unprototyped functions; default to
12355 prototyped, since that is more common in modern code (and
12356 RealView warns about unprototyped functions). */
12357 TYPE_PROTOTYPED (ftype
) = 1;
12359 /* Store the calling convention in the type if it's available in
12360 the subroutine die. Otherwise set the calling convention to
12361 the default value DW_CC_normal. */
12362 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12364 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12365 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12366 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12368 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12370 /* We need to add the subroutine type to the die immediately so
12371 we don't infinitely recurse when dealing with parameters
12372 declared as the same subroutine type. */
12373 set_die_type (die
, ftype
, cu
);
12375 if (die
->child
!= NULL
)
12377 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12378 struct die_info
*child_die
;
12379 int nparams
, iparams
;
12381 /* Count the number of parameters.
12382 FIXME: GDB currently ignores vararg functions, but knows about
12383 vararg member functions. */
12385 child_die
= die
->child
;
12386 while (child_die
&& child_die
->tag
)
12388 if (child_die
->tag
== DW_TAG_formal_parameter
)
12390 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12391 TYPE_VARARGS (ftype
) = 1;
12392 child_die
= sibling_die (child_die
);
12395 /* Allocate storage for parameters and fill them in. */
12396 TYPE_NFIELDS (ftype
) = nparams
;
12397 TYPE_FIELDS (ftype
) = (struct field
*)
12398 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12400 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12401 even if we error out during the parameters reading below. */
12402 for (iparams
= 0; iparams
< nparams
; iparams
++)
12403 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12406 child_die
= die
->child
;
12407 while (child_die
&& child_die
->tag
)
12409 if (child_die
->tag
== DW_TAG_formal_parameter
)
12411 struct type
*arg_type
;
12413 /* DWARF version 2 has no clean way to discern C++
12414 static and non-static member functions. G++ helps
12415 GDB by marking the first parameter for non-static
12416 member functions (which is the this pointer) as
12417 artificial. We pass this information to
12418 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12420 DWARF version 3 added DW_AT_object_pointer, which GCC
12421 4.5 does not yet generate. */
12422 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12424 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12427 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12429 /* GCC/43521: In java, the formal parameter
12430 "this" is sometimes not marked with DW_AT_artificial. */
12431 if (cu
->language
== language_java
)
12433 const char *name
= dwarf2_name (child_die
, cu
);
12435 if (name
&& !strcmp (name
, "this"))
12436 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12439 arg_type
= die_type (child_die
, cu
);
12441 /* RealView does not mark THIS as const, which the testsuite
12442 expects. GCC marks THIS as const in method definitions,
12443 but not in the class specifications (GCC PR 43053). */
12444 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12445 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12448 struct dwarf2_cu
*arg_cu
= cu
;
12449 const char *name
= dwarf2_name (child_die
, cu
);
12451 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12454 /* If the compiler emits this, use it. */
12455 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12458 else if (name
&& strcmp (name
, "this") == 0)
12459 /* Function definitions will have the argument names. */
12461 else if (name
== NULL
&& iparams
== 0)
12462 /* Declarations may not have the names, so like
12463 elsewhere in GDB, assume an artificial first
12464 argument is "this". */
12468 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12472 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12475 child_die
= sibling_die (child_die
);
12482 static struct type
*
12483 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12485 struct objfile
*objfile
= cu
->objfile
;
12486 const char *name
= NULL
;
12487 struct type
*this_type
, *target_type
;
12489 name
= dwarf2_full_name (NULL
, die
, cu
);
12490 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12491 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12492 TYPE_NAME (this_type
) = (char *) name
;
12493 set_die_type (die
, this_type
, cu
);
12494 target_type
= die_type (die
, cu
);
12495 if (target_type
!= this_type
)
12496 TYPE_TARGET_TYPE (this_type
) = target_type
;
12499 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12500 spec and cause infinite loops in GDB. */
12501 complaint (&symfile_complaints
,
12502 _("Self-referential DW_TAG_typedef "
12503 "- DIE at 0x%x [in module %s]"),
12504 die
->offset
.sect_off
, objfile
->name
);
12505 TYPE_TARGET_TYPE (this_type
) = NULL
;
12510 /* Find a representation of a given base type and install
12511 it in the TYPE field of the die. */
12513 static struct type
*
12514 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12516 struct objfile
*objfile
= cu
->objfile
;
12518 struct attribute
*attr
;
12519 int encoding
= 0, size
= 0;
12521 enum type_code code
= TYPE_CODE_INT
;
12522 int type_flags
= 0;
12523 struct type
*target_type
= NULL
;
12525 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12528 encoding
= DW_UNSND (attr
);
12530 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12533 size
= DW_UNSND (attr
);
12535 name
= dwarf2_name (die
, cu
);
12538 complaint (&symfile_complaints
,
12539 _("DW_AT_name missing from DW_TAG_base_type"));
12544 case DW_ATE_address
:
12545 /* Turn DW_ATE_address into a void * pointer. */
12546 code
= TYPE_CODE_PTR
;
12547 type_flags
|= TYPE_FLAG_UNSIGNED
;
12548 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12550 case DW_ATE_boolean
:
12551 code
= TYPE_CODE_BOOL
;
12552 type_flags
|= TYPE_FLAG_UNSIGNED
;
12554 case DW_ATE_complex_float
:
12555 code
= TYPE_CODE_COMPLEX
;
12556 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12558 case DW_ATE_decimal_float
:
12559 code
= TYPE_CODE_DECFLOAT
;
12562 code
= TYPE_CODE_FLT
;
12564 case DW_ATE_signed
:
12566 case DW_ATE_unsigned
:
12567 type_flags
|= TYPE_FLAG_UNSIGNED
;
12568 if (cu
->language
== language_fortran
12570 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12571 code
= TYPE_CODE_CHAR
;
12573 case DW_ATE_signed_char
:
12574 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12575 || cu
->language
== language_pascal
12576 || cu
->language
== language_fortran
)
12577 code
= TYPE_CODE_CHAR
;
12579 case DW_ATE_unsigned_char
:
12580 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12581 || cu
->language
== language_pascal
12582 || cu
->language
== language_fortran
)
12583 code
= TYPE_CODE_CHAR
;
12584 type_flags
|= TYPE_FLAG_UNSIGNED
;
12587 /* We just treat this as an integer and then recognize the
12588 type by name elsewhere. */
12592 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12593 dwarf_type_encoding_name (encoding
));
12597 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12598 TYPE_NAME (type
) = name
;
12599 TYPE_TARGET_TYPE (type
) = target_type
;
12601 if (name
&& strcmp (name
, "char") == 0)
12602 TYPE_NOSIGN (type
) = 1;
12604 return set_die_type (die
, type
, cu
);
12607 /* Read the given DW_AT_subrange DIE. */
12609 static struct type
*
12610 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12612 struct type
*base_type
;
12613 struct type
*range_type
;
12614 struct attribute
*attr
;
12616 int low_default_is_valid
;
12618 LONGEST negative_mask
;
12620 base_type
= die_type (die
, cu
);
12621 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12622 check_typedef (base_type
);
12624 /* The die_type call above may have already set the type for this DIE. */
12625 range_type
= get_die_type (die
, cu
);
12629 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12630 omitting DW_AT_lower_bound. */
12631 switch (cu
->language
)
12634 case language_cplus
:
12636 low_default_is_valid
= 1;
12638 case language_fortran
:
12640 low_default_is_valid
= 1;
12643 case language_java
:
12644 case language_objc
:
12646 low_default_is_valid
= (cu
->header
.version
>= 4);
12650 case language_pascal
:
12652 low_default_is_valid
= (cu
->header
.version
>= 4);
12656 low_default_is_valid
= 0;
12660 /* FIXME: For variable sized arrays either of these could be
12661 a variable rather than a constant value. We'll allow it,
12662 but we don't know how to handle it. */
12663 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12665 low
= dwarf2_get_attr_constant_value (attr
, low
);
12666 else if (!low_default_is_valid
)
12667 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12668 "- DIE at 0x%x [in module %s]"),
12669 die
->offset
.sect_off
, cu
->objfile
->name
);
12671 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12674 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12676 /* GCC encodes arrays with unspecified or dynamic length
12677 with a DW_FORM_block1 attribute or a reference attribute.
12678 FIXME: GDB does not yet know how to handle dynamic
12679 arrays properly, treat them as arrays with unspecified
12682 FIXME: jimb/2003-09-22: GDB does not really know
12683 how to handle arrays of unspecified length
12684 either; we just represent them as zero-length
12685 arrays. Choose an appropriate upper bound given
12686 the lower bound we've computed above. */
12690 high
= dwarf2_get_attr_constant_value (attr
, 1);
12694 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12697 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12698 high
= low
+ count
- 1;
12702 /* Unspecified array length. */
12707 /* Dwarf-2 specifications explicitly allows to create subrange types
12708 without specifying a base type.
12709 In that case, the base type must be set to the type of
12710 the lower bound, upper bound or count, in that order, if any of these
12711 three attributes references an object that has a type.
12712 If no base type is found, the Dwarf-2 specifications say that
12713 a signed integer type of size equal to the size of an address should
12715 For the following C code: `extern char gdb_int [];'
12716 GCC produces an empty range DIE.
12717 FIXME: muller/2010-05-28: Possible references to object for low bound,
12718 high bound or count are not yet handled by this code. */
12719 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12721 struct objfile
*objfile
= cu
->objfile
;
12722 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12723 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12724 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12726 /* Test "int", "long int", and "long long int" objfile types,
12727 and select the first one having a size above or equal to the
12728 architecture address size. */
12729 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12730 base_type
= int_type
;
12733 int_type
= objfile_type (objfile
)->builtin_long
;
12734 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12735 base_type
= int_type
;
12738 int_type
= objfile_type (objfile
)->builtin_long_long
;
12739 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12740 base_type
= int_type
;
12746 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12747 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12748 low
|= negative_mask
;
12749 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12750 high
|= negative_mask
;
12752 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12754 /* Mark arrays with dynamic length at least as an array of unspecified
12755 length. GDB could check the boundary but before it gets implemented at
12756 least allow accessing the array elements. */
12757 if (attr
&& attr_form_is_block (attr
))
12758 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12760 /* Ada expects an empty array on no boundary attributes. */
12761 if (attr
== NULL
&& cu
->language
!= language_ada
)
12762 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12764 name
= dwarf2_name (die
, cu
);
12766 TYPE_NAME (range_type
) = name
;
12768 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12770 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12772 set_die_type (die
, range_type
, cu
);
12774 /* set_die_type should be already done. */
12775 set_descriptive_type (range_type
, die
, cu
);
12780 static struct type
*
12781 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12785 /* For now, we only support the C meaning of an unspecified type: void. */
12787 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12788 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12790 return set_die_type (die
, type
, cu
);
12793 /* Read a single die and all its descendents. Set the die's sibling
12794 field to NULL; set other fields in the die correctly, and set all
12795 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12796 location of the info_ptr after reading all of those dies. PARENT
12797 is the parent of the die in question. */
12799 static struct die_info
*
12800 read_die_and_children (const struct die_reader_specs
*reader
,
12801 gdb_byte
*info_ptr
,
12802 gdb_byte
**new_info_ptr
,
12803 struct die_info
*parent
)
12805 struct die_info
*die
;
12809 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12812 *new_info_ptr
= cur_ptr
;
12815 store_in_ref_table (die
, reader
->cu
);
12818 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12822 *new_info_ptr
= cur_ptr
;
12825 die
->sibling
= NULL
;
12826 die
->parent
= parent
;
12830 /* Read a die, all of its descendents, and all of its siblings; set
12831 all of the fields of all of the dies correctly. Arguments are as
12832 in read_die_and_children. */
12834 static struct die_info
*
12835 read_die_and_siblings (const struct die_reader_specs
*reader
,
12836 gdb_byte
*info_ptr
,
12837 gdb_byte
**new_info_ptr
,
12838 struct die_info
*parent
)
12840 struct die_info
*first_die
, *last_sibling
;
12843 cur_ptr
= info_ptr
;
12844 first_die
= last_sibling
= NULL
;
12848 struct die_info
*die
12849 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12853 *new_info_ptr
= cur_ptr
;
12860 last_sibling
->sibling
= die
;
12862 last_sibling
= die
;
12866 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12868 The caller is responsible for filling in the extra attributes
12869 and updating (*DIEP)->num_attrs.
12870 Set DIEP to point to a newly allocated die with its information,
12871 except for its child, sibling, and parent fields.
12872 Set HAS_CHILDREN to tell whether the die has children or not. */
12875 read_full_die_1 (const struct die_reader_specs
*reader
,
12876 struct die_info
**diep
, gdb_byte
*info_ptr
,
12877 int *has_children
, int num_extra_attrs
)
12879 unsigned int abbrev_number
, bytes_read
, i
;
12880 sect_offset offset
;
12881 struct abbrev_info
*abbrev
;
12882 struct die_info
*die
;
12883 struct dwarf2_cu
*cu
= reader
->cu
;
12884 bfd
*abfd
= reader
->abfd
;
12886 offset
.sect_off
= info_ptr
- reader
->buffer
;
12887 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12888 info_ptr
+= bytes_read
;
12889 if (!abbrev_number
)
12896 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
12898 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12900 bfd_get_filename (abfd
));
12902 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
12903 die
->offset
= offset
;
12904 die
->tag
= abbrev
->tag
;
12905 die
->abbrev
= abbrev_number
;
12907 /* Make the result usable.
12908 The caller needs to update num_attrs after adding the extra
12910 die
->num_attrs
= abbrev
->num_attrs
;
12912 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
12913 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
12917 *has_children
= abbrev
->has_children
;
12921 /* Read a die and all its attributes.
12922 Set DIEP to point to a newly allocated die with its information,
12923 except for its child, sibling, and parent fields.
12924 Set HAS_CHILDREN to tell whether the die has children or not. */
12927 read_full_die (const struct die_reader_specs
*reader
,
12928 struct die_info
**diep
, gdb_byte
*info_ptr
,
12931 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
12934 /* Abbreviation tables.
12936 In DWARF version 2, the description of the debugging information is
12937 stored in a separate .debug_abbrev section. Before we read any
12938 dies from a section we read in all abbreviations and install them
12939 in a hash table. */
12941 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12943 static struct abbrev_info
*
12944 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
12946 struct abbrev_info
*abbrev
;
12948 abbrev
= (struct abbrev_info
*)
12949 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
12950 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12954 /* Add an abbreviation to the table. */
12957 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
12958 unsigned int abbrev_number
,
12959 struct abbrev_info
*abbrev
)
12961 unsigned int hash_number
;
12963 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12964 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
12965 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
12968 /* Look up an abbrev in the table.
12969 Returns NULL if the abbrev is not found. */
12971 static struct abbrev_info
*
12972 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
12973 unsigned int abbrev_number
)
12975 unsigned int hash_number
;
12976 struct abbrev_info
*abbrev
;
12978 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
12979 abbrev
= abbrev_table
->abbrevs
[hash_number
];
12983 if (abbrev
->number
== abbrev_number
)
12985 abbrev
= abbrev
->next
;
12990 /* Read in an abbrev table. */
12992 static struct abbrev_table
*
12993 abbrev_table_read_table (struct dwarf2_section_info
*section
,
12994 sect_offset offset
)
12996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12997 bfd
*abfd
= section
->asection
->owner
;
12998 struct abbrev_table
*abbrev_table
;
12999 gdb_byte
*abbrev_ptr
;
13000 struct abbrev_info
*cur_abbrev
;
13001 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
13002 unsigned int abbrev_form
;
13003 struct attr_abbrev
*cur_attrs
;
13004 unsigned int allocated_attrs
;
13006 abbrev_table
= XMALLOC (struct abbrev_table
);
13007 abbrev_table
->offset
= offset
;
13008 obstack_init (&abbrev_table
->abbrev_obstack
);
13009 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13011 * sizeof (struct abbrev_info
*)));
13012 memset (abbrev_table
->abbrevs
, 0,
13013 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
13015 dwarf2_read_section (objfile
, section
);
13016 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
13017 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13018 abbrev_ptr
+= bytes_read
;
13020 allocated_attrs
= ATTR_ALLOC_CHUNK
;
13021 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
13023 /* Loop until we reach an abbrev number of 0. */
13024 while (abbrev_number
)
13026 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13028 /* read in abbrev header */
13029 cur_abbrev
->number
= abbrev_number
;
13030 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13031 abbrev_ptr
+= bytes_read
;
13032 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13035 /* now read in declarations */
13036 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13037 abbrev_ptr
+= bytes_read
;
13038 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13039 abbrev_ptr
+= bytes_read
;
13040 while (abbrev_name
)
13042 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13044 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13046 = xrealloc (cur_attrs
, (allocated_attrs
13047 * sizeof (struct attr_abbrev
)));
13050 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13051 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13052 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13053 abbrev_ptr
+= bytes_read
;
13054 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13055 abbrev_ptr
+= bytes_read
;
13058 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13059 (cur_abbrev
->num_attrs
13060 * sizeof (struct attr_abbrev
)));
13061 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13062 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13064 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13066 /* Get next abbreviation.
13067 Under Irix6 the abbreviations for a compilation unit are not
13068 always properly terminated with an abbrev number of 0.
13069 Exit loop if we encounter an abbreviation which we have
13070 already read (which means we are about to read the abbreviations
13071 for the next compile unit) or if the end of the abbreviation
13072 table is reached. */
13073 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13075 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13076 abbrev_ptr
+= bytes_read
;
13077 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13082 return abbrev_table
;
13085 /* Free the resources held by ABBREV_TABLE. */
13088 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13090 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13091 xfree (abbrev_table
);
13094 /* Same as abbrev_table_free but as a cleanup.
13095 We pass in a pointer to the pointer to the table so that we can
13096 set the pointer to NULL when we're done. It also simplifies
13097 build_type_unit_groups. */
13100 abbrev_table_free_cleanup (void *table_ptr
)
13102 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13104 if (*abbrev_table_ptr
!= NULL
)
13105 abbrev_table_free (*abbrev_table_ptr
);
13106 *abbrev_table_ptr
= NULL
;
13109 /* Read the abbrev table for CU from ABBREV_SECTION. */
13112 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13113 struct dwarf2_section_info
*abbrev_section
)
13116 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13119 /* Release the memory used by the abbrev table for a compilation unit. */
13122 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13124 struct dwarf2_cu
*cu
= ptr_to_cu
;
13126 abbrev_table_free (cu
->abbrev_table
);
13127 /* Set this to NULL so that we SEGV if we try to read it later,
13128 and also because free_comp_unit verifies this is NULL. */
13129 cu
->abbrev_table
= NULL
;
13132 /* Returns nonzero if TAG represents a type that we might generate a partial
13136 is_type_tag_for_partial (int tag
)
13141 /* Some types that would be reasonable to generate partial symbols for,
13142 that we don't at present. */
13143 case DW_TAG_array_type
:
13144 case DW_TAG_file_type
:
13145 case DW_TAG_ptr_to_member_type
:
13146 case DW_TAG_set_type
:
13147 case DW_TAG_string_type
:
13148 case DW_TAG_subroutine_type
:
13150 case DW_TAG_base_type
:
13151 case DW_TAG_class_type
:
13152 case DW_TAG_interface_type
:
13153 case DW_TAG_enumeration_type
:
13154 case DW_TAG_structure_type
:
13155 case DW_TAG_subrange_type
:
13156 case DW_TAG_typedef
:
13157 case DW_TAG_union_type
:
13164 /* Load all DIEs that are interesting for partial symbols into memory. */
13166 static struct partial_die_info
*
13167 load_partial_dies (const struct die_reader_specs
*reader
,
13168 gdb_byte
*info_ptr
, int building_psymtab
)
13170 struct dwarf2_cu
*cu
= reader
->cu
;
13171 struct objfile
*objfile
= cu
->objfile
;
13172 struct partial_die_info
*part_die
;
13173 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13174 struct abbrev_info
*abbrev
;
13175 unsigned int bytes_read
;
13176 unsigned int load_all
= 0;
13177 int nesting_level
= 1;
13182 gdb_assert (cu
->per_cu
!= NULL
);
13183 if (cu
->per_cu
->load_all_dies
)
13187 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13191 &cu
->comp_unit_obstack
,
13192 hashtab_obstack_allocate
,
13193 dummy_obstack_deallocate
);
13195 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13196 sizeof (struct partial_die_info
));
13200 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13202 /* A NULL abbrev means the end of a series of children. */
13203 if (abbrev
== NULL
)
13205 if (--nesting_level
== 0)
13207 /* PART_DIE was probably the last thing allocated on the
13208 comp_unit_obstack, so we could call obstack_free
13209 here. We don't do that because the waste is small,
13210 and will be cleaned up when we're done with this
13211 compilation unit. This way, we're also more robust
13212 against other users of the comp_unit_obstack. */
13215 info_ptr
+= bytes_read
;
13216 last_die
= parent_die
;
13217 parent_die
= parent_die
->die_parent
;
13221 /* Check for template arguments. We never save these; if
13222 they're seen, we just mark the parent, and go on our way. */
13223 if (parent_die
!= NULL
13224 && cu
->language
== language_cplus
13225 && (abbrev
->tag
== DW_TAG_template_type_param
13226 || abbrev
->tag
== DW_TAG_template_value_param
))
13228 parent_die
->has_template_arguments
= 1;
13232 /* We don't need a partial DIE for the template argument. */
13233 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13238 /* We only recurse into c++ subprograms looking for template arguments.
13239 Skip their other children. */
13241 && cu
->language
== language_cplus
13242 && parent_die
!= NULL
13243 && parent_die
->tag
== DW_TAG_subprogram
)
13245 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13249 /* Check whether this DIE is interesting enough to save. Normally
13250 we would not be interested in members here, but there may be
13251 later variables referencing them via DW_AT_specification (for
13252 static members). */
13254 && !is_type_tag_for_partial (abbrev
->tag
)
13255 && abbrev
->tag
!= DW_TAG_constant
13256 && abbrev
->tag
!= DW_TAG_enumerator
13257 && abbrev
->tag
!= DW_TAG_subprogram
13258 && abbrev
->tag
!= DW_TAG_lexical_block
13259 && abbrev
->tag
!= DW_TAG_variable
13260 && abbrev
->tag
!= DW_TAG_namespace
13261 && abbrev
->tag
!= DW_TAG_module
13262 && abbrev
->tag
!= DW_TAG_member
13263 && abbrev
->tag
!= DW_TAG_imported_unit
)
13265 /* Otherwise we skip to the next sibling, if any. */
13266 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13270 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13273 /* This two-pass algorithm for processing partial symbols has a
13274 high cost in cache pressure. Thus, handle some simple cases
13275 here which cover the majority of C partial symbols. DIEs
13276 which neither have specification tags in them, nor could have
13277 specification tags elsewhere pointing at them, can simply be
13278 processed and discarded.
13280 This segment is also optional; scan_partial_symbols and
13281 add_partial_symbol will handle these DIEs if we chain
13282 them in normally. When compilers which do not emit large
13283 quantities of duplicate debug information are more common,
13284 this code can probably be removed. */
13286 /* Any complete simple types at the top level (pretty much all
13287 of them, for a language without namespaces), can be processed
13289 if (parent_die
== NULL
13290 && part_die
->has_specification
== 0
13291 && part_die
->is_declaration
== 0
13292 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13293 || part_die
->tag
== DW_TAG_base_type
13294 || part_die
->tag
== DW_TAG_subrange_type
))
13296 if (building_psymtab
&& part_die
->name
!= NULL
)
13297 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13298 VAR_DOMAIN
, LOC_TYPEDEF
,
13299 &objfile
->static_psymbols
,
13300 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13301 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13305 /* The exception for DW_TAG_typedef with has_children above is
13306 a workaround of GCC PR debug/47510. In the case of this complaint
13307 type_name_no_tag_or_error will error on such types later.
13309 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13310 it could not find the child DIEs referenced later, this is checked
13311 above. In correct DWARF DW_TAG_typedef should have no children. */
13313 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13314 complaint (&symfile_complaints
,
13315 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13316 "- DIE at 0x%x [in module %s]"),
13317 part_die
->offset
.sect_off
, objfile
->name
);
13319 /* If we're at the second level, and we're an enumerator, and
13320 our parent has no specification (meaning possibly lives in a
13321 namespace elsewhere), then we can add the partial symbol now
13322 instead of queueing it. */
13323 if (part_die
->tag
== DW_TAG_enumerator
13324 && parent_die
!= NULL
13325 && parent_die
->die_parent
== NULL
13326 && parent_die
->tag
== DW_TAG_enumeration_type
13327 && parent_die
->has_specification
== 0)
13329 if (part_die
->name
== NULL
)
13330 complaint (&symfile_complaints
,
13331 _("malformed enumerator DIE ignored"));
13332 else if (building_psymtab
)
13333 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13334 VAR_DOMAIN
, LOC_CONST
,
13335 (cu
->language
== language_cplus
13336 || cu
->language
== language_java
)
13337 ? &objfile
->global_psymbols
13338 : &objfile
->static_psymbols
,
13339 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13341 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13345 /* We'll save this DIE so link it in. */
13346 part_die
->die_parent
= parent_die
;
13347 part_die
->die_sibling
= NULL
;
13348 part_die
->die_child
= NULL
;
13350 if (last_die
&& last_die
== parent_die
)
13351 last_die
->die_child
= part_die
;
13353 last_die
->die_sibling
= part_die
;
13355 last_die
= part_die
;
13357 if (first_die
== NULL
)
13358 first_die
= part_die
;
13360 /* Maybe add the DIE to the hash table. Not all DIEs that we
13361 find interesting need to be in the hash table, because we
13362 also have the parent/sibling/child chains; only those that we
13363 might refer to by offset later during partial symbol reading.
13365 For now this means things that might have be the target of a
13366 DW_AT_specification, DW_AT_abstract_origin, or
13367 DW_AT_extension. DW_AT_extension will refer only to
13368 namespaces; DW_AT_abstract_origin refers to functions (and
13369 many things under the function DIE, but we do not recurse
13370 into function DIEs during partial symbol reading) and
13371 possibly variables as well; DW_AT_specification refers to
13372 declarations. Declarations ought to have the DW_AT_declaration
13373 flag. It happens that GCC forgets to put it in sometimes, but
13374 only for functions, not for types.
13376 Adding more things than necessary to the hash table is harmless
13377 except for the performance cost. Adding too few will result in
13378 wasted time in find_partial_die, when we reread the compilation
13379 unit with load_all_dies set. */
13382 || abbrev
->tag
== DW_TAG_constant
13383 || abbrev
->tag
== DW_TAG_subprogram
13384 || abbrev
->tag
== DW_TAG_variable
13385 || abbrev
->tag
== DW_TAG_namespace
13386 || part_die
->is_declaration
)
13390 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13391 part_die
->offset
.sect_off
, INSERT
);
13395 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13396 sizeof (struct partial_die_info
));
13398 /* For some DIEs we want to follow their children (if any). For C
13399 we have no reason to follow the children of structures; for other
13400 languages we have to, so that we can get at method physnames
13401 to infer fully qualified class names, for DW_AT_specification,
13402 and for C++ template arguments. For C++, we also look one level
13403 inside functions to find template arguments (if the name of the
13404 function does not already contain the template arguments).
13406 For Ada, we need to scan the children of subprograms and lexical
13407 blocks as well because Ada allows the definition of nested
13408 entities that could be interesting for the debugger, such as
13409 nested subprograms for instance. */
13410 if (last_die
->has_children
13412 || last_die
->tag
== DW_TAG_namespace
13413 || last_die
->tag
== DW_TAG_module
13414 || last_die
->tag
== DW_TAG_enumeration_type
13415 || (cu
->language
== language_cplus
13416 && last_die
->tag
== DW_TAG_subprogram
13417 && (last_die
->name
== NULL
13418 || strchr (last_die
->name
, '<') == NULL
))
13419 || (cu
->language
!= language_c
13420 && (last_die
->tag
== DW_TAG_class_type
13421 || last_die
->tag
== DW_TAG_interface_type
13422 || last_die
->tag
== DW_TAG_structure_type
13423 || last_die
->tag
== DW_TAG_union_type
))
13424 || (cu
->language
== language_ada
13425 && (last_die
->tag
== DW_TAG_subprogram
13426 || last_die
->tag
== DW_TAG_lexical_block
))))
13429 parent_die
= last_die
;
13433 /* Otherwise we skip to the next sibling, if any. */
13434 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13436 /* Back to the top, do it again. */
13440 /* Read a minimal amount of information into the minimal die structure. */
13443 read_partial_die (const struct die_reader_specs
*reader
,
13444 struct partial_die_info
*part_die
,
13445 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13446 gdb_byte
*info_ptr
)
13448 struct dwarf2_cu
*cu
= reader
->cu
;
13449 struct objfile
*objfile
= cu
->objfile
;
13450 gdb_byte
*buffer
= reader
->buffer
;
13452 struct attribute attr
;
13453 int has_low_pc_attr
= 0;
13454 int has_high_pc_attr
= 0;
13455 int high_pc_relative
= 0;
13457 memset (part_die
, 0, sizeof (struct partial_die_info
));
13459 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13461 info_ptr
+= abbrev_len
;
13463 if (abbrev
== NULL
)
13466 part_die
->tag
= abbrev
->tag
;
13467 part_die
->has_children
= abbrev
->has_children
;
13469 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13471 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13473 /* Store the data if it is of an attribute we want to keep in a
13474 partial symbol table. */
13478 switch (part_die
->tag
)
13480 case DW_TAG_compile_unit
:
13481 case DW_TAG_partial_unit
:
13482 case DW_TAG_type_unit
:
13483 /* Compilation units have a DW_AT_name that is a filename, not
13484 a source language identifier. */
13485 case DW_TAG_enumeration_type
:
13486 case DW_TAG_enumerator
:
13487 /* These tags always have simple identifiers already; no need
13488 to canonicalize them. */
13489 part_die
->name
= DW_STRING (&attr
);
13493 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13494 &objfile
->objfile_obstack
);
13498 case DW_AT_linkage_name
:
13499 case DW_AT_MIPS_linkage_name
:
13500 /* Note that both forms of linkage name might appear. We
13501 assume they will be the same, and we only store the last
13503 if (cu
->language
== language_ada
)
13504 part_die
->name
= DW_STRING (&attr
);
13505 part_die
->linkage_name
= DW_STRING (&attr
);
13508 has_low_pc_attr
= 1;
13509 part_die
->lowpc
= DW_ADDR (&attr
);
13511 case DW_AT_high_pc
:
13512 has_high_pc_attr
= 1;
13513 if (attr
.form
== DW_FORM_addr
13514 || attr
.form
== DW_FORM_GNU_addr_index
)
13515 part_die
->highpc
= DW_ADDR (&attr
);
13518 high_pc_relative
= 1;
13519 part_die
->highpc
= DW_UNSND (&attr
);
13522 case DW_AT_location
:
13523 /* Support the .debug_loc offsets. */
13524 if (attr_form_is_block (&attr
))
13526 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13528 else if (attr_form_is_section_offset (&attr
))
13530 dwarf2_complex_location_expr_complaint ();
13534 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13535 "partial symbol information");
13538 case DW_AT_external
:
13539 part_die
->is_external
= DW_UNSND (&attr
);
13541 case DW_AT_declaration
:
13542 part_die
->is_declaration
= DW_UNSND (&attr
);
13545 part_die
->has_type
= 1;
13547 case DW_AT_abstract_origin
:
13548 case DW_AT_specification
:
13549 case DW_AT_extension
:
13550 part_die
->has_specification
= 1;
13551 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13552 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13553 || cu
->per_cu
->is_dwz
);
13555 case DW_AT_sibling
:
13556 /* Ignore absolute siblings, they might point outside of
13557 the current compile unit. */
13558 if (attr
.form
== DW_FORM_ref_addr
)
13559 complaint (&symfile_complaints
,
13560 _("ignoring absolute DW_AT_sibling"));
13562 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13564 case DW_AT_byte_size
:
13565 part_die
->has_byte_size
= 1;
13567 case DW_AT_calling_convention
:
13568 /* DWARF doesn't provide a way to identify a program's source-level
13569 entry point. DW_AT_calling_convention attributes are only meant
13570 to describe functions' calling conventions.
13572 However, because it's a necessary piece of information in
13573 Fortran, and because DW_CC_program is the only piece of debugging
13574 information whose definition refers to a 'main program' at all,
13575 several compilers have begun marking Fortran main programs with
13576 DW_CC_program --- even when those functions use the standard
13577 calling conventions.
13579 So until DWARF specifies a way to provide this information and
13580 compilers pick up the new representation, we'll support this
13582 if (DW_UNSND (&attr
) == DW_CC_program
13583 && cu
->language
== language_fortran
)
13585 set_main_name (part_die
->name
);
13587 /* As this DIE has a static linkage the name would be difficult
13588 to look up later. */
13589 language_of_main
= language_fortran
;
13593 if (DW_UNSND (&attr
) == DW_INL_inlined
13594 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13595 part_die
->may_be_inlined
= 1;
13599 if (part_die
->tag
== DW_TAG_imported_unit
)
13601 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13602 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13603 || cu
->per_cu
->is_dwz
);
13612 if (high_pc_relative
)
13613 part_die
->highpc
+= part_die
->lowpc
;
13615 if (has_low_pc_attr
&& has_high_pc_attr
)
13617 /* When using the GNU linker, .gnu.linkonce. sections are used to
13618 eliminate duplicate copies of functions and vtables and such.
13619 The linker will arbitrarily choose one and discard the others.
13620 The AT_*_pc values for such functions refer to local labels in
13621 these sections. If the section from that file was discarded, the
13622 labels are not in the output, so the relocs get a value of 0.
13623 If this is a discarded function, mark the pc bounds as invalid,
13624 so that GDB will ignore it. */
13625 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13627 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13629 complaint (&symfile_complaints
,
13630 _("DW_AT_low_pc %s is zero "
13631 "for DIE at 0x%x [in module %s]"),
13632 paddress (gdbarch
, part_die
->lowpc
),
13633 part_die
->offset
.sect_off
, objfile
->name
);
13635 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13636 else if (part_die
->lowpc
>= part_die
->highpc
)
13638 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13640 complaint (&symfile_complaints
,
13641 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13642 "for DIE at 0x%x [in module %s]"),
13643 paddress (gdbarch
, part_die
->lowpc
),
13644 paddress (gdbarch
, part_die
->highpc
),
13645 part_die
->offset
.sect_off
, objfile
->name
);
13648 part_die
->has_pc_info
= 1;
13654 /* Find a cached partial DIE at OFFSET in CU. */
13656 static struct partial_die_info
*
13657 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13659 struct partial_die_info
*lookup_die
= NULL
;
13660 struct partial_die_info part_die
;
13662 part_die
.offset
= offset
;
13663 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13669 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13670 except in the case of .debug_types DIEs which do not reference
13671 outside their CU (they do however referencing other types via
13672 DW_FORM_ref_sig8). */
13674 static struct partial_die_info
*
13675 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13677 struct objfile
*objfile
= cu
->objfile
;
13678 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13679 struct partial_die_info
*pd
= NULL
;
13681 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13682 && offset_in_cu_p (&cu
->header
, offset
))
13684 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13687 /* We missed recording what we needed.
13688 Load all dies and try again. */
13689 per_cu
= cu
->per_cu
;
13693 /* TUs don't reference other CUs/TUs (except via type signatures). */
13694 if (cu
->per_cu
->is_debug_types
)
13696 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13697 " external reference to offset 0x%lx [in module %s].\n"),
13698 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13699 bfd_get_filename (objfile
->obfd
));
13701 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13704 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13705 load_partial_comp_unit (per_cu
);
13707 per_cu
->cu
->last_used
= 0;
13708 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13711 /* If we didn't find it, and not all dies have been loaded,
13712 load them all and try again. */
13714 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13716 per_cu
->load_all_dies
= 1;
13718 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13719 THIS_CU->cu may already be in use. So we can't just free it and
13720 replace its DIEs with the ones we read in. Instead, we leave those
13721 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13722 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13724 load_partial_comp_unit (per_cu
);
13726 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13730 internal_error (__FILE__
, __LINE__
,
13731 _("could not find partial DIE 0x%x "
13732 "in cache [from module %s]\n"),
13733 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13737 /* See if we can figure out if the class lives in a namespace. We do
13738 this by looking for a member function; its demangled name will
13739 contain namespace info, if there is any. */
13742 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13743 struct dwarf2_cu
*cu
)
13745 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13746 what template types look like, because the demangler
13747 frequently doesn't give the same name as the debug info. We
13748 could fix this by only using the demangled name to get the
13749 prefix (but see comment in read_structure_type). */
13751 struct partial_die_info
*real_pdi
;
13752 struct partial_die_info
*child_pdi
;
13754 /* If this DIE (this DIE's specification, if any) has a parent, then
13755 we should not do this. We'll prepend the parent's fully qualified
13756 name when we create the partial symbol. */
13758 real_pdi
= struct_pdi
;
13759 while (real_pdi
->has_specification
)
13760 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13761 real_pdi
->spec_is_dwz
, cu
);
13763 if (real_pdi
->die_parent
!= NULL
)
13766 for (child_pdi
= struct_pdi
->die_child
;
13768 child_pdi
= child_pdi
->die_sibling
)
13770 if (child_pdi
->tag
== DW_TAG_subprogram
13771 && child_pdi
->linkage_name
!= NULL
)
13773 char *actual_class_name
13774 = language_class_name_from_physname (cu
->language_defn
,
13775 child_pdi
->linkage_name
);
13776 if (actual_class_name
!= NULL
)
13779 = obsavestring (actual_class_name
,
13780 strlen (actual_class_name
),
13781 &cu
->objfile
->objfile_obstack
);
13782 xfree (actual_class_name
);
13789 /* Adjust PART_DIE before generating a symbol for it. This function
13790 may set the is_external flag or change the DIE's name. */
13793 fixup_partial_die (struct partial_die_info
*part_die
,
13794 struct dwarf2_cu
*cu
)
13796 /* Once we've fixed up a die, there's no point in doing so again.
13797 This also avoids a memory leak if we were to call
13798 guess_partial_die_structure_name multiple times. */
13799 if (part_die
->fixup_called
)
13802 /* If we found a reference attribute and the DIE has no name, try
13803 to find a name in the referred to DIE. */
13805 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13807 struct partial_die_info
*spec_die
;
13809 spec_die
= find_partial_die (part_die
->spec_offset
,
13810 part_die
->spec_is_dwz
, cu
);
13812 fixup_partial_die (spec_die
, cu
);
13814 if (spec_die
->name
)
13816 part_die
->name
= spec_die
->name
;
13818 /* Copy DW_AT_external attribute if it is set. */
13819 if (spec_die
->is_external
)
13820 part_die
->is_external
= spec_die
->is_external
;
13824 /* Set default names for some unnamed DIEs. */
13826 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13827 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13829 /* If there is no parent die to provide a namespace, and there are
13830 children, see if we can determine the namespace from their linkage
13832 if (cu
->language
== language_cplus
13833 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13834 && part_die
->die_parent
== NULL
13835 && part_die
->has_children
13836 && (part_die
->tag
== DW_TAG_class_type
13837 || part_die
->tag
== DW_TAG_structure_type
13838 || part_die
->tag
== DW_TAG_union_type
))
13839 guess_partial_die_structure_name (part_die
, cu
);
13841 /* GCC might emit a nameless struct or union that has a linkage
13842 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13843 if (part_die
->name
== NULL
13844 && (part_die
->tag
== DW_TAG_class_type
13845 || part_die
->tag
== DW_TAG_interface_type
13846 || part_die
->tag
== DW_TAG_structure_type
13847 || part_die
->tag
== DW_TAG_union_type
)
13848 && part_die
->linkage_name
!= NULL
)
13852 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13857 /* Strip any leading namespaces/classes, keep only the base name.
13858 DW_AT_name for named DIEs does not contain the prefixes. */
13859 base
= strrchr (demangled
, ':');
13860 if (base
&& base
> demangled
&& base
[-1] == ':')
13865 part_die
->name
= obsavestring (base
, strlen (base
),
13866 &cu
->objfile
->objfile_obstack
);
13871 part_die
->fixup_called
= 1;
13874 /* Read an attribute value described by an attribute form. */
13877 read_attribute_value (const struct die_reader_specs
*reader
,
13878 struct attribute
*attr
, unsigned form
,
13879 gdb_byte
*info_ptr
)
13881 struct dwarf2_cu
*cu
= reader
->cu
;
13882 bfd
*abfd
= reader
->abfd
;
13883 struct comp_unit_head
*cu_header
= &cu
->header
;
13884 unsigned int bytes_read
;
13885 struct dwarf_block
*blk
;
13890 case DW_FORM_ref_addr
:
13891 if (cu
->header
.version
== 2)
13892 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13894 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
13895 &cu
->header
, &bytes_read
);
13896 info_ptr
+= bytes_read
;
13898 case DW_FORM_GNU_ref_alt
:
13899 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13900 info_ptr
+= bytes_read
;
13903 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
13904 info_ptr
+= bytes_read
;
13906 case DW_FORM_block2
:
13907 blk
= dwarf_alloc_block (cu
);
13908 blk
->size
= read_2_bytes (abfd
, info_ptr
);
13910 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13911 info_ptr
+= blk
->size
;
13912 DW_BLOCK (attr
) = blk
;
13914 case DW_FORM_block4
:
13915 blk
= dwarf_alloc_block (cu
);
13916 blk
->size
= read_4_bytes (abfd
, info_ptr
);
13918 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13919 info_ptr
+= blk
->size
;
13920 DW_BLOCK (attr
) = blk
;
13922 case DW_FORM_data2
:
13923 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
13926 case DW_FORM_data4
:
13927 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
13930 case DW_FORM_data8
:
13931 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
13934 case DW_FORM_sec_offset
:
13935 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
13936 info_ptr
+= bytes_read
;
13938 case DW_FORM_string
:
13939 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
13940 DW_STRING_IS_CANONICAL (attr
) = 0;
13941 info_ptr
+= bytes_read
;
13944 if (!cu
->per_cu
->is_dwz
)
13946 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
13948 DW_STRING_IS_CANONICAL (attr
) = 0;
13949 info_ptr
+= bytes_read
;
13953 case DW_FORM_GNU_strp_alt
:
13955 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
13956 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
13959 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
13960 DW_STRING_IS_CANONICAL (attr
) = 0;
13961 info_ptr
+= bytes_read
;
13964 case DW_FORM_exprloc
:
13965 case DW_FORM_block
:
13966 blk
= dwarf_alloc_block (cu
);
13967 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13968 info_ptr
+= bytes_read
;
13969 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13970 info_ptr
+= blk
->size
;
13971 DW_BLOCK (attr
) = blk
;
13973 case DW_FORM_block1
:
13974 blk
= dwarf_alloc_block (cu
);
13975 blk
->size
= read_1_byte (abfd
, info_ptr
);
13977 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
13978 info_ptr
+= blk
->size
;
13979 DW_BLOCK (attr
) = blk
;
13981 case DW_FORM_data1
:
13982 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13986 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
13989 case DW_FORM_flag_present
:
13990 DW_UNSND (attr
) = 1;
13992 case DW_FORM_sdata
:
13993 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
13994 info_ptr
+= bytes_read
;
13996 case DW_FORM_udata
:
13997 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
13998 info_ptr
+= bytes_read
;
14001 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14002 + read_1_byte (abfd
, info_ptr
));
14006 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14007 + read_2_bytes (abfd
, info_ptr
));
14011 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14012 + read_4_bytes (abfd
, info_ptr
));
14016 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14017 + read_8_bytes (abfd
, info_ptr
));
14020 case DW_FORM_ref_sig8
:
14021 /* Convert the signature to something we can record in DW_UNSND
14023 NOTE: This is NULL if the type wasn't found. */
14024 DW_SIGNATURED_TYPE (attr
) =
14025 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
14028 case DW_FORM_ref_udata
:
14029 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14030 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14031 info_ptr
+= bytes_read
;
14033 case DW_FORM_indirect
:
14034 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14035 info_ptr
+= bytes_read
;
14036 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14038 case DW_FORM_GNU_addr_index
:
14039 if (reader
->dwo_file
== NULL
)
14041 /* For now flag a hard error.
14042 Later we can turn this into a complaint. */
14043 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14044 dwarf_form_name (form
),
14045 bfd_get_filename (abfd
));
14047 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14048 info_ptr
+= bytes_read
;
14050 case DW_FORM_GNU_str_index
:
14051 if (reader
->dwo_file
== NULL
)
14053 /* For now flag a hard error.
14054 Later we can turn this into a complaint if warranted. */
14055 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14056 dwarf_form_name (form
),
14057 bfd_get_filename (abfd
));
14060 ULONGEST str_index
=
14061 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14063 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14064 DW_STRING_IS_CANONICAL (attr
) = 0;
14065 info_ptr
+= bytes_read
;
14069 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14070 dwarf_form_name (form
),
14071 bfd_get_filename (abfd
));
14075 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14076 attr
->form
= DW_FORM_GNU_ref_alt
;
14078 /* We have seen instances where the compiler tried to emit a byte
14079 size attribute of -1 which ended up being encoded as an unsigned
14080 0xffffffff. Although 0xffffffff is technically a valid size value,
14081 an object of this size seems pretty unlikely so we can relatively
14082 safely treat these cases as if the size attribute was invalid and
14083 treat them as zero by default. */
14084 if (attr
->name
== DW_AT_byte_size
14085 && form
== DW_FORM_data4
14086 && DW_UNSND (attr
) >= 0xffffffff)
14089 (&symfile_complaints
,
14090 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14091 hex_string (DW_UNSND (attr
)));
14092 DW_UNSND (attr
) = 0;
14098 /* Read an attribute described by an abbreviated attribute. */
14101 read_attribute (const struct die_reader_specs
*reader
,
14102 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14103 gdb_byte
*info_ptr
)
14105 attr
->name
= abbrev
->name
;
14106 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14109 /* Read dwarf information from a buffer. */
14111 static unsigned int
14112 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14114 return bfd_get_8 (abfd
, buf
);
14118 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14120 return bfd_get_signed_8 (abfd
, buf
);
14123 static unsigned int
14124 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14126 return bfd_get_16 (abfd
, buf
);
14130 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14132 return bfd_get_signed_16 (abfd
, buf
);
14135 static unsigned int
14136 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14138 return bfd_get_32 (abfd
, buf
);
14142 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14144 return bfd_get_signed_32 (abfd
, buf
);
14148 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14150 return bfd_get_64 (abfd
, buf
);
14154 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14155 unsigned int *bytes_read
)
14157 struct comp_unit_head
*cu_header
= &cu
->header
;
14158 CORE_ADDR retval
= 0;
14160 if (cu_header
->signed_addr_p
)
14162 switch (cu_header
->addr_size
)
14165 retval
= bfd_get_signed_16 (abfd
, buf
);
14168 retval
= bfd_get_signed_32 (abfd
, buf
);
14171 retval
= bfd_get_signed_64 (abfd
, buf
);
14174 internal_error (__FILE__
, __LINE__
,
14175 _("read_address: bad switch, signed [in module %s]"),
14176 bfd_get_filename (abfd
));
14181 switch (cu_header
->addr_size
)
14184 retval
= bfd_get_16 (abfd
, buf
);
14187 retval
= bfd_get_32 (abfd
, buf
);
14190 retval
= bfd_get_64 (abfd
, buf
);
14193 internal_error (__FILE__
, __LINE__
,
14194 _("read_address: bad switch, "
14195 "unsigned [in module %s]"),
14196 bfd_get_filename (abfd
));
14200 *bytes_read
= cu_header
->addr_size
;
14204 /* Read the initial length from a section. The (draft) DWARF 3
14205 specification allows the initial length to take up either 4 bytes
14206 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14207 bytes describe the length and all offsets will be 8 bytes in length
14210 An older, non-standard 64-bit format is also handled by this
14211 function. The older format in question stores the initial length
14212 as an 8-byte quantity without an escape value. Lengths greater
14213 than 2^32 aren't very common which means that the initial 4 bytes
14214 is almost always zero. Since a length value of zero doesn't make
14215 sense for the 32-bit format, this initial zero can be considered to
14216 be an escape value which indicates the presence of the older 64-bit
14217 format. As written, the code can't detect (old format) lengths
14218 greater than 4GB. If it becomes necessary to handle lengths
14219 somewhat larger than 4GB, we could allow other small values (such
14220 as the non-sensical values of 1, 2, and 3) to also be used as
14221 escape values indicating the presence of the old format.
14223 The value returned via bytes_read should be used to increment the
14224 relevant pointer after calling read_initial_length().
14226 [ Note: read_initial_length() and read_offset() are based on the
14227 document entitled "DWARF Debugging Information Format", revision
14228 3, draft 8, dated November 19, 2001. This document was obtained
14231 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14233 This document is only a draft and is subject to change. (So beware.)
14235 Details regarding the older, non-standard 64-bit format were
14236 determined empirically by examining 64-bit ELF files produced by
14237 the SGI toolchain on an IRIX 6.5 machine.
14239 - Kevin, July 16, 2002
14243 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14245 LONGEST length
= bfd_get_32 (abfd
, buf
);
14247 if (length
== 0xffffffff)
14249 length
= bfd_get_64 (abfd
, buf
+ 4);
14252 else if (length
== 0)
14254 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14255 length
= bfd_get_64 (abfd
, buf
);
14266 /* Cover function for read_initial_length.
14267 Returns the length of the object at BUF, and stores the size of the
14268 initial length in *BYTES_READ and stores the size that offsets will be in
14270 If the initial length size is not equivalent to that specified in
14271 CU_HEADER then issue a complaint.
14272 This is useful when reading non-comp-unit headers. */
14275 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14276 const struct comp_unit_head
*cu_header
,
14277 unsigned int *bytes_read
,
14278 unsigned int *offset_size
)
14280 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14282 gdb_assert (cu_header
->initial_length_size
== 4
14283 || cu_header
->initial_length_size
== 8
14284 || cu_header
->initial_length_size
== 12);
14286 if (cu_header
->initial_length_size
!= *bytes_read
)
14287 complaint (&symfile_complaints
,
14288 _("intermixed 32-bit and 64-bit DWARF sections"));
14290 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14294 /* Read an offset from the data stream. The size of the offset is
14295 given by cu_header->offset_size. */
14298 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14299 unsigned int *bytes_read
)
14301 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14303 *bytes_read
= cu_header
->offset_size
;
14307 /* Read an offset from the data stream. */
14310 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14312 LONGEST retval
= 0;
14314 switch (offset_size
)
14317 retval
= bfd_get_32 (abfd
, buf
);
14320 retval
= bfd_get_64 (abfd
, buf
);
14323 internal_error (__FILE__
, __LINE__
,
14324 _("read_offset_1: bad switch [in module %s]"),
14325 bfd_get_filename (abfd
));
14332 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14334 /* If the size of a host char is 8 bits, we can return a pointer
14335 to the buffer, otherwise we have to copy the data to a buffer
14336 allocated on the temporary obstack. */
14337 gdb_assert (HOST_CHAR_BIT
== 8);
14342 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14344 /* If the size of a host char is 8 bits, we can return a pointer
14345 to the string, otherwise we have to copy the string to a buffer
14346 allocated on the temporary obstack. */
14347 gdb_assert (HOST_CHAR_BIT
== 8);
14350 *bytes_read_ptr
= 1;
14353 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14354 return (char *) buf
;
14358 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14360 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14361 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14362 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14363 bfd_get_filename (abfd
));
14364 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14365 error (_("DW_FORM_strp pointing outside of "
14366 ".debug_str section [in module %s]"),
14367 bfd_get_filename (abfd
));
14368 gdb_assert (HOST_CHAR_BIT
== 8);
14369 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14371 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14374 /* Read a string at offset STR_OFFSET in the .debug_str section from
14375 the .dwz file DWZ. Throw an error if the offset is too large. If
14376 the string consists of a single NUL byte, return NULL; otherwise
14377 return a pointer to the string. */
14380 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14382 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14384 if (dwz
->str
.buffer
== NULL
)
14385 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14386 "section [in module %s]"),
14387 bfd_get_filename (dwz
->dwz_bfd
));
14388 if (str_offset
>= dwz
->str
.size
)
14389 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14390 ".debug_str section [in module %s]"),
14391 bfd_get_filename (dwz
->dwz_bfd
));
14392 gdb_assert (HOST_CHAR_BIT
== 8);
14393 if (dwz
->str
.buffer
[str_offset
] == '\0')
14395 return (char *) (dwz
->str
.buffer
+ str_offset
);
14399 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14400 const struct comp_unit_head
*cu_header
,
14401 unsigned int *bytes_read_ptr
)
14403 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14405 return read_indirect_string_at_offset (abfd
, str_offset
);
14409 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14412 unsigned int num_read
;
14414 unsigned char byte
;
14422 byte
= bfd_get_8 (abfd
, buf
);
14425 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14426 if ((byte
& 128) == 0)
14432 *bytes_read_ptr
= num_read
;
14437 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14440 int i
, shift
, num_read
;
14441 unsigned char byte
;
14449 byte
= bfd_get_8 (abfd
, buf
);
14452 result
|= ((LONGEST
) (byte
& 127) << shift
);
14454 if ((byte
& 128) == 0)
14459 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14460 result
|= -(((LONGEST
) 1) << shift
);
14461 *bytes_read_ptr
= num_read
;
14465 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14466 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14467 ADDR_SIZE is the size of addresses from the CU header. */
14470 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14472 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14473 bfd
*abfd
= objfile
->obfd
;
14474 const gdb_byte
*info_ptr
;
14476 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14477 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14478 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14480 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14481 error (_("DW_FORM_addr_index pointing outside of "
14482 ".debug_addr section [in module %s]"),
14484 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14485 + addr_base
+ addr_index
* addr_size
);
14486 if (addr_size
== 4)
14487 return bfd_get_32 (abfd
, info_ptr
);
14489 return bfd_get_64 (abfd
, info_ptr
);
14492 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14495 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14497 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14500 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14503 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14504 unsigned int *bytes_read
)
14506 bfd
*abfd
= cu
->objfile
->obfd
;
14507 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14509 return read_addr_index (cu
, addr_index
);
14512 /* Data structure to pass results from dwarf2_read_addr_index_reader
14513 back to dwarf2_read_addr_index. */
14515 struct dwarf2_read_addr_index_data
14517 ULONGEST addr_base
;
14521 /* die_reader_func for dwarf2_read_addr_index. */
14524 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14525 gdb_byte
*info_ptr
,
14526 struct die_info
*comp_unit_die
,
14530 struct dwarf2_cu
*cu
= reader
->cu
;
14531 struct dwarf2_read_addr_index_data
*aidata
=
14532 (struct dwarf2_read_addr_index_data
*) data
;
14534 aidata
->addr_base
= cu
->addr_base
;
14535 aidata
->addr_size
= cu
->header
.addr_size
;
14538 /* Given an index in .debug_addr, fetch the value.
14539 NOTE: This can be called during dwarf expression evaluation,
14540 long after the debug information has been read, and thus per_cu->cu
14541 may no longer exist. */
14544 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14545 unsigned int addr_index
)
14547 struct objfile
*objfile
= per_cu
->objfile
;
14548 struct dwarf2_cu
*cu
= per_cu
->cu
;
14549 ULONGEST addr_base
;
14552 /* This is intended to be called from outside this file. */
14553 dw2_setup (objfile
);
14555 /* We need addr_base and addr_size.
14556 If we don't have PER_CU->cu, we have to get it.
14557 Nasty, but the alternative is storing the needed info in PER_CU,
14558 which at this point doesn't seem justified: it's not clear how frequently
14559 it would get used and it would increase the size of every PER_CU.
14560 Entry points like dwarf2_per_cu_addr_size do a similar thing
14561 so we're not in uncharted territory here.
14562 Alas we need to be a bit more complicated as addr_base is contained
14565 We don't need to read the entire CU(/TU).
14566 We just need the header and top level die.
14568 IWBN to use the aging mechanism to let us lazily later discard the CU.
14569 For now we skip this optimization. */
14573 addr_base
= cu
->addr_base
;
14574 addr_size
= cu
->header
.addr_size
;
14578 struct dwarf2_read_addr_index_data aidata
;
14580 /* Note: We can't use init_cutu_and_read_dies_simple here,
14581 we need addr_base. */
14582 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14583 dwarf2_read_addr_index_reader
, &aidata
);
14584 addr_base
= aidata
.addr_base
;
14585 addr_size
= aidata
.addr_size
;
14588 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14591 /* Given a DW_AT_str_index, fetch the string. */
14594 read_str_index (const struct die_reader_specs
*reader
,
14595 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14597 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14598 const char *dwo_name
= objfile
->name
;
14599 bfd
*abfd
= objfile
->obfd
;
14600 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14601 gdb_byte
*info_ptr
;
14602 ULONGEST str_offset
;
14604 dwarf2_read_section (objfile
, §ions
->str
);
14605 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14606 if (sections
->str
.buffer
== NULL
)
14607 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14608 " in CU at offset 0x%lx [in module %s]"),
14609 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14610 if (sections
->str_offsets
.buffer
== NULL
)
14611 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14612 " in CU at offset 0x%lx [in module %s]"),
14613 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14614 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14615 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14616 " section in CU at offset 0x%lx [in module %s]"),
14617 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14618 info_ptr
= (sections
->str_offsets
.buffer
14619 + str_index
* cu
->header
.offset_size
);
14620 if (cu
->header
.offset_size
== 4)
14621 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14623 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14624 if (str_offset
>= sections
->str
.size
)
14625 error (_("Offset from DW_FORM_str_index pointing outside of"
14626 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14627 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14628 return (char *) (sections
->str
.buffer
+ str_offset
);
14631 /* Return the length of an LEB128 number in BUF. */
14634 leb128_size (const gdb_byte
*buf
)
14636 const gdb_byte
*begin
= buf
;
14642 if ((byte
& 128) == 0)
14643 return buf
- begin
;
14648 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14655 cu
->language
= language_c
;
14657 case DW_LANG_C_plus_plus
:
14658 cu
->language
= language_cplus
;
14661 cu
->language
= language_d
;
14663 case DW_LANG_Fortran77
:
14664 case DW_LANG_Fortran90
:
14665 case DW_LANG_Fortran95
:
14666 cu
->language
= language_fortran
;
14669 cu
->language
= language_go
;
14671 case DW_LANG_Mips_Assembler
:
14672 cu
->language
= language_asm
;
14675 cu
->language
= language_java
;
14677 case DW_LANG_Ada83
:
14678 case DW_LANG_Ada95
:
14679 cu
->language
= language_ada
;
14681 case DW_LANG_Modula2
:
14682 cu
->language
= language_m2
;
14684 case DW_LANG_Pascal83
:
14685 cu
->language
= language_pascal
;
14688 cu
->language
= language_objc
;
14690 case DW_LANG_Cobol74
:
14691 case DW_LANG_Cobol85
:
14693 cu
->language
= language_minimal
;
14696 cu
->language_defn
= language_def (cu
->language
);
14699 /* Return the named attribute or NULL if not there. */
14701 static struct attribute
*
14702 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14707 struct attribute
*spec
= NULL
;
14709 for (i
= 0; i
< die
->num_attrs
; ++i
)
14711 if (die
->attrs
[i
].name
== name
)
14712 return &die
->attrs
[i
];
14713 if (die
->attrs
[i
].name
== DW_AT_specification
14714 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14715 spec
= &die
->attrs
[i
];
14721 die
= follow_die_ref (die
, spec
, &cu
);
14727 /* Return the named attribute or NULL if not there,
14728 but do not follow DW_AT_specification, etc.
14729 This is for use in contexts where we're reading .debug_types dies.
14730 Following DW_AT_specification, DW_AT_abstract_origin will take us
14731 back up the chain, and we want to go down. */
14733 static struct attribute
*
14734 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14738 for (i
= 0; i
< die
->num_attrs
; ++i
)
14739 if (die
->attrs
[i
].name
== name
)
14740 return &die
->attrs
[i
];
14745 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14746 and holds a non-zero value. This function should only be used for
14747 DW_FORM_flag or DW_FORM_flag_present attributes. */
14750 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14752 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14754 return (attr
&& DW_UNSND (attr
));
14758 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14760 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14761 which value is non-zero. However, we have to be careful with
14762 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14763 (via dwarf2_flag_true_p) follows this attribute. So we may
14764 end up accidently finding a declaration attribute that belongs
14765 to a different DIE referenced by the specification attribute,
14766 even though the given DIE does not have a declaration attribute. */
14767 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14768 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14771 /* Return the die giving the specification for DIE, if there is
14772 one. *SPEC_CU is the CU containing DIE on input, and the CU
14773 containing the return value on output. If there is no
14774 specification, but there is an abstract origin, that is
14777 static struct die_info
*
14778 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14780 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14783 if (spec_attr
== NULL
)
14784 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14786 if (spec_attr
== NULL
)
14789 return follow_die_ref (die
, spec_attr
, spec_cu
);
14792 /* Free the line_header structure *LH, and any arrays and strings it
14794 NOTE: This is also used as a "cleanup" function. */
14797 free_line_header (struct line_header
*lh
)
14799 if (lh
->standard_opcode_lengths
)
14800 xfree (lh
->standard_opcode_lengths
);
14802 /* Remember that all the lh->file_names[i].name pointers are
14803 pointers into debug_line_buffer, and don't need to be freed. */
14804 if (lh
->file_names
)
14805 xfree (lh
->file_names
);
14807 /* Similarly for the include directory names. */
14808 if (lh
->include_dirs
)
14809 xfree (lh
->include_dirs
);
14814 /* Add an entry to LH's include directory table. */
14817 add_include_dir (struct line_header
*lh
, char *include_dir
)
14819 /* Grow the array if necessary. */
14820 if (lh
->include_dirs_size
== 0)
14822 lh
->include_dirs_size
= 1; /* for testing */
14823 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14824 * sizeof (*lh
->include_dirs
));
14826 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14828 lh
->include_dirs_size
*= 2;
14829 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14830 (lh
->include_dirs_size
14831 * sizeof (*lh
->include_dirs
)));
14834 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14837 /* Add an entry to LH's file name table. */
14840 add_file_name (struct line_header
*lh
,
14842 unsigned int dir_index
,
14843 unsigned int mod_time
,
14844 unsigned int length
)
14846 struct file_entry
*fe
;
14848 /* Grow the array if necessary. */
14849 if (lh
->file_names_size
== 0)
14851 lh
->file_names_size
= 1; /* for testing */
14852 lh
->file_names
= xmalloc (lh
->file_names_size
14853 * sizeof (*lh
->file_names
));
14855 else if (lh
->num_file_names
>= lh
->file_names_size
)
14857 lh
->file_names_size
*= 2;
14858 lh
->file_names
= xrealloc (lh
->file_names
,
14859 (lh
->file_names_size
14860 * sizeof (*lh
->file_names
)));
14863 fe
= &lh
->file_names
[lh
->num_file_names
++];
14865 fe
->dir_index
= dir_index
;
14866 fe
->mod_time
= mod_time
;
14867 fe
->length
= length
;
14868 fe
->included_p
= 0;
14872 /* A convenience function to find the proper .debug_line section for a
14875 static struct dwarf2_section_info
*
14876 get_debug_line_section (struct dwarf2_cu
*cu
)
14878 struct dwarf2_section_info
*section
;
14880 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14882 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14883 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14884 else if (cu
->per_cu
->is_dwz
)
14886 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14888 section
= &dwz
->line
;
14891 section
= &dwarf2_per_objfile
->line
;
14896 /* Read the statement program header starting at OFFSET in
14897 .debug_line, or .debug_line.dwo. Return a pointer
14898 to a struct line_header, allocated using xmalloc.
14900 NOTE: the strings in the include directory and file name tables of
14901 the returned object point into the dwarf line section buffer,
14902 and must not be freed. */
14904 static struct line_header
*
14905 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
14907 struct cleanup
*back_to
;
14908 struct line_header
*lh
;
14909 gdb_byte
*line_ptr
;
14910 unsigned int bytes_read
, offset_size
;
14912 char *cur_dir
, *cur_file
;
14913 struct dwarf2_section_info
*section
;
14916 section
= get_debug_line_section (cu
);
14917 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
14918 if (section
->buffer
== NULL
)
14920 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14921 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
14923 complaint (&symfile_complaints
, _("missing .debug_line section"));
14927 /* We can't do this until we know the section is non-empty.
14928 Only then do we know we have such a section. */
14929 abfd
= section
->asection
->owner
;
14931 /* Make sure that at least there's room for the total_length field.
14932 That could be 12 bytes long, but we're just going to fudge that. */
14933 if (offset
+ 4 >= section
->size
)
14935 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14939 lh
= xmalloc (sizeof (*lh
));
14940 memset (lh
, 0, sizeof (*lh
));
14941 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
14944 line_ptr
= section
->buffer
+ offset
;
14946 /* Read in the header. */
14948 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
14949 &bytes_read
, &offset_size
);
14950 line_ptr
+= bytes_read
;
14951 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
14953 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14956 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
14957 lh
->version
= read_2_bytes (abfd
, line_ptr
);
14959 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
14960 line_ptr
+= offset_size
;
14961 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
14963 if (lh
->version
>= 4)
14965 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
14969 lh
->maximum_ops_per_instruction
= 1;
14971 if (lh
->maximum_ops_per_instruction
== 0)
14973 lh
->maximum_ops_per_instruction
= 1;
14974 complaint (&symfile_complaints
,
14975 _("invalid maximum_ops_per_instruction "
14976 "in `.debug_line' section"));
14979 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
14981 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
14983 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
14985 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
14987 lh
->standard_opcode_lengths
14988 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
14990 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
14991 for (i
= 1; i
< lh
->opcode_base
; ++i
)
14993 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
14997 /* Read directory table. */
14998 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15000 line_ptr
+= bytes_read
;
15001 add_include_dir (lh
, cur_dir
);
15003 line_ptr
+= bytes_read
;
15005 /* Read file name table. */
15006 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15008 unsigned int dir_index
, mod_time
, length
;
15010 line_ptr
+= bytes_read
;
15011 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15012 line_ptr
+= bytes_read
;
15013 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15014 line_ptr
+= bytes_read
;
15015 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15016 line_ptr
+= bytes_read
;
15018 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15020 line_ptr
+= bytes_read
;
15021 lh
->statement_program_start
= line_ptr
;
15023 if (line_ptr
> (section
->buffer
+ section
->size
))
15024 complaint (&symfile_complaints
,
15025 _("line number info header doesn't "
15026 "fit in `.debug_line' section"));
15028 discard_cleanups (back_to
);
15032 /* Subroutine of dwarf_decode_lines to simplify it.
15033 Return the file name of the psymtab for included file FILE_INDEX
15034 in line header LH of PST.
15035 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15036 If space for the result is malloc'd, it will be freed by a cleanup.
15037 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15040 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15041 const struct partial_symtab
*pst
,
15042 const char *comp_dir
)
15044 const struct file_entry fe
= lh
->file_names
[file_index
];
15045 char *include_name
= fe
.name
;
15046 char *include_name_to_compare
= include_name
;
15047 char *dir_name
= NULL
;
15048 const char *pst_filename
;
15049 char *copied_name
= NULL
;
15053 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15055 if (!IS_ABSOLUTE_PATH (include_name
)
15056 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15058 /* Avoid creating a duplicate psymtab for PST.
15059 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15060 Before we do the comparison, however, we need to account
15061 for DIR_NAME and COMP_DIR.
15062 First prepend dir_name (if non-NULL). If we still don't
15063 have an absolute path prepend comp_dir (if non-NULL).
15064 However, the directory we record in the include-file's
15065 psymtab does not contain COMP_DIR (to match the
15066 corresponding symtab(s)).
15071 bash$ gcc -g ./hello.c
15072 include_name = "hello.c"
15074 DW_AT_comp_dir = comp_dir = "/tmp"
15075 DW_AT_name = "./hello.c" */
15077 if (dir_name
!= NULL
)
15079 include_name
= concat (dir_name
, SLASH_STRING
,
15080 include_name
, (char *)NULL
);
15081 include_name_to_compare
= include_name
;
15082 make_cleanup (xfree
, include_name
);
15084 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15086 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15087 include_name
, (char *)NULL
);
15091 pst_filename
= pst
->filename
;
15092 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15094 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15095 pst_filename
, (char *)NULL
);
15096 pst_filename
= copied_name
;
15099 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15101 if (include_name_to_compare
!= include_name
)
15102 xfree (include_name_to_compare
);
15103 if (copied_name
!= NULL
)
15104 xfree (copied_name
);
15108 return include_name
;
15111 /* Ignore this record_line request. */
15114 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15119 /* Subroutine of dwarf_decode_lines to simplify it.
15120 Process the line number information in LH. */
15123 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15124 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15126 gdb_byte
*line_ptr
, *extended_end
;
15127 gdb_byte
*line_end
;
15128 unsigned int bytes_read
, extended_len
;
15129 unsigned char op_code
, extended_op
, adj_opcode
;
15130 CORE_ADDR baseaddr
;
15131 struct objfile
*objfile
= cu
->objfile
;
15132 bfd
*abfd
= objfile
->obfd
;
15133 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15134 const int decode_for_pst_p
= (pst
!= NULL
);
15135 struct subfile
*last_subfile
= NULL
;
15136 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15139 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15141 line_ptr
= lh
->statement_program_start
;
15142 line_end
= lh
->statement_program_end
;
15144 /* Read the statement sequences until there's nothing left. */
15145 while (line_ptr
< line_end
)
15147 /* state machine registers */
15148 CORE_ADDR address
= 0;
15149 unsigned int file
= 1;
15150 unsigned int line
= 1;
15151 unsigned int column
= 0;
15152 int is_stmt
= lh
->default_is_stmt
;
15153 int basic_block
= 0;
15154 int end_sequence
= 0;
15156 unsigned char op_index
= 0;
15158 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15160 /* Start a subfile for the current file of the state machine. */
15161 /* lh->include_dirs and lh->file_names are 0-based, but the
15162 directory and file name numbers in the statement program
15164 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15168 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15170 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15173 /* Decode the table. */
15174 while (!end_sequence
)
15176 op_code
= read_1_byte (abfd
, line_ptr
);
15178 if (line_ptr
> line_end
)
15180 dwarf2_debug_line_missing_end_sequence_complaint ();
15184 if (op_code
>= lh
->opcode_base
)
15186 /* Special operand. */
15187 adj_opcode
= op_code
- lh
->opcode_base
;
15188 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15189 / lh
->maximum_ops_per_instruction
)
15190 * lh
->minimum_instruction_length
);
15191 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15192 % lh
->maximum_ops_per_instruction
);
15193 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15194 if (lh
->num_file_names
< file
|| file
== 0)
15195 dwarf2_debug_line_missing_file_complaint ();
15196 /* For now we ignore lines not starting on an
15197 instruction boundary. */
15198 else if (op_index
== 0)
15200 lh
->file_names
[file
- 1].included_p
= 1;
15201 if (!decode_for_pst_p
&& is_stmt
)
15203 if (last_subfile
!= current_subfile
)
15205 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15207 (*p_record_line
) (last_subfile
, 0, addr
);
15208 last_subfile
= current_subfile
;
15210 /* Append row to matrix using current values. */
15211 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15212 (*p_record_line
) (current_subfile
, line
, addr
);
15217 else switch (op_code
)
15219 case DW_LNS_extended_op
:
15220 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15222 line_ptr
+= bytes_read
;
15223 extended_end
= line_ptr
+ extended_len
;
15224 extended_op
= read_1_byte (abfd
, line_ptr
);
15226 switch (extended_op
)
15228 case DW_LNE_end_sequence
:
15229 p_record_line
= record_line
;
15232 case DW_LNE_set_address
:
15233 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15235 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15237 /* This line table is for a function which has been
15238 GCd by the linker. Ignore it. PR gdb/12528 */
15241 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15243 complaint (&symfile_complaints
,
15244 _(".debug_line address at offset 0x%lx is 0 "
15246 line_offset
, objfile
->name
);
15247 p_record_line
= noop_record_line
;
15251 line_ptr
+= bytes_read
;
15252 address
+= baseaddr
;
15254 case DW_LNE_define_file
:
15257 unsigned int dir_index
, mod_time
, length
;
15259 cur_file
= read_direct_string (abfd
, line_ptr
,
15261 line_ptr
+= bytes_read
;
15263 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15264 line_ptr
+= bytes_read
;
15266 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15267 line_ptr
+= bytes_read
;
15269 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15270 line_ptr
+= bytes_read
;
15271 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15274 case DW_LNE_set_discriminator
:
15275 /* The discriminator is not interesting to the debugger;
15277 line_ptr
= extended_end
;
15280 complaint (&symfile_complaints
,
15281 _("mangled .debug_line section"));
15284 /* Make sure that we parsed the extended op correctly. If e.g.
15285 we expected a different address size than the producer used,
15286 we may have read the wrong number of bytes. */
15287 if (line_ptr
!= extended_end
)
15289 complaint (&symfile_complaints
,
15290 _("mangled .debug_line section"));
15295 if (lh
->num_file_names
< file
|| file
== 0)
15296 dwarf2_debug_line_missing_file_complaint ();
15299 lh
->file_names
[file
- 1].included_p
= 1;
15300 if (!decode_for_pst_p
&& is_stmt
)
15302 if (last_subfile
!= current_subfile
)
15304 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15306 (*p_record_line
) (last_subfile
, 0, addr
);
15307 last_subfile
= current_subfile
;
15309 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15310 (*p_record_line
) (current_subfile
, line
, addr
);
15315 case DW_LNS_advance_pc
:
15318 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15320 address
+= (((op_index
+ adjust
)
15321 / lh
->maximum_ops_per_instruction
)
15322 * lh
->minimum_instruction_length
);
15323 op_index
= ((op_index
+ adjust
)
15324 % lh
->maximum_ops_per_instruction
);
15325 line_ptr
+= bytes_read
;
15328 case DW_LNS_advance_line
:
15329 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15330 line_ptr
+= bytes_read
;
15332 case DW_LNS_set_file
:
15334 /* The arrays lh->include_dirs and lh->file_names are
15335 0-based, but the directory and file name numbers in
15336 the statement program are 1-based. */
15337 struct file_entry
*fe
;
15340 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15341 line_ptr
+= bytes_read
;
15342 if (lh
->num_file_names
< file
|| file
== 0)
15343 dwarf2_debug_line_missing_file_complaint ();
15346 fe
= &lh
->file_names
[file
- 1];
15348 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15349 if (!decode_for_pst_p
)
15351 last_subfile
= current_subfile
;
15352 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15357 case DW_LNS_set_column
:
15358 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15359 line_ptr
+= bytes_read
;
15361 case DW_LNS_negate_stmt
:
15362 is_stmt
= (!is_stmt
);
15364 case DW_LNS_set_basic_block
:
15367 /* Add to the address register of the state machine the
15368 address increment value corresponding to special opcode
15369 255. I.e., this value is scaled by the minimum
15370 instruction length since special opcode 255 would have
15371 scaled the increment. */
15372 case DW_LNS_const_add_pc
:
15374 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15376 address
+= (((op_index
+ adjust
)
15377 / lh
->maximum_ops_per_instruction
)
15378 * lh
->minimum_instruction_length
);
15379 op_index
= ((op_index
+ adjust
)
15380 % lh
->maximum_ops_per_instruction
);
15383 case DW_LNS_fixed_advance_pc
:
15384 address
+= read_2_bytes (abfd
, line_ptr
);
15390 /* Unknown standard opcode, ignore it. */
15393 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15395 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15396 line_ptr
+= bytes_read
;
15401 if (lh
->num_file_names
< file
|| file
== 0)
15402 dwarf2_debug_line_missing_file_complaint ();
15405 lh
->file_names
[file
- 1].included_p
= 1;
15406 if (!decode_for_pst_p
)
15408 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15409 (*p_record_line
) (current_subfile
, 0, addr
);
15415 /* Decode the Line Number Program (LNP) for the given line_header
15416 structure and CU. The actual information extracted and the type
15417 of structures created from the LNP depends on the value of PST.
15419 1. If PST is NULL, then this procedure uses the data from the program
15420 to create all necessary symbol tables, and their linetables.
15422 2. If PST is not NULL, this procedure reads the program to determine
15423 the list of files included by the unit represented by PST, and
15424 builds all the associated partial symbol tables.
15426 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15427 It is used for relative paths in the line table.
15428 NOTE: When processing partial symtabs (pst != NULL),
15429 comp_dir == pst->dirname.
15431 NOTE: It is important that psymtabs have the same file name (via strcmp)
15432 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15433 symtab we don't use it in the name of the psymtabs we create.
15434 E.g. expand_line_sal requires this when finding psymtabs to expand.
15435 A good testcase for this is mb-inline.exp. */
15438 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15439 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15440 int want_line_info
)
15442 struct objfile
*objfile
= cu
->objfile
;
15443 const int decode_for_pst_p
= (pst
!= NULL
);
15444 struct subfile
*first_subfile
= current_subfile
;
15446 if (want_line_info
)
15447 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15449 if (decode_for_pst_p
)
15453 /* Now that we're done scanning the Line Header Program, we can
15454 create the psymtab of each included file. */
15455 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15456 if (lh
->file_names
[file_index
].included_p
== 1)
15458 char *include_name
=
15459 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15460 if (include_name
!= NULL
)
15461 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15466 /* Make sure a symtab is created for every file, even files
15467 which contain only variables (i.e. no code with associated
15471 for (i
= 0; i
< lh
->num_file_names
; i
++)
15474 struct file_entry
*fe
;
15476 fe
= &lh
->file_names
[i
];
15478 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15479 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15481 /* Skip the main file; we don't need it, and it must be
15482 allocated last, so that it will show up before the
15483 non-primary symtabs in the objfile's symtab list. */
15484 if (current_subfile
== first_subfile
)
15487 if (current_subfile
->symtab
== NULL
)
15488 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15490 fe
->symtab
= current_subfile
->symtab
;
15495 /* Start a subfile for DWARF. FILENAME is the name of the file and
15496 DIRNAME the name of the source directory which contains FILENAME
15497 or NULL if not known. COMP_DIR is the compilation directory for the
15498 linetable's compilation unit or NULL if not known.
15499 This routine tries to keep line numbers from identical absolute and
15500 relative file names in a common subfile.
15502 Using the `list' example from the GDB testsuite, which resides in
15503 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15504 of /srcdir/list0.c yields the following debugging information for list0.c:
15506 DW_AT_name: /srcdir/list0.c
15507 DW_AT_comp_dir: /compdir
15508 files.files[0].name: list0.h
15509 files.files[0].dir: /srcdir
15510 files.files[1].name: list0.c
15511 files.files[1].dir: /srcdir
15513 The line number information for list0.c has to end up in a single
15514 subfile, so that `break /srcdir/list0.c:1' works as expected.
15515 start_subfile will ensure that this happens provided that we pass the
15516 concatenation of files.files[1].dir and files.files[1].name as the
15520 dwarf2_start_subfile (char *filename
, const char *dirname
,
15521 const char *comp_dir
)
15525 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15526 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15527 second argument to start_subfile. To be consistent, we do the
15528 same here. In order not to lose the line information directory,
15529 we concatenate it to the filename when it makes sense.
15530 Note that the Dwarf3 standard says (speaking of filenames in line
15531 information): ``The directory index is ignored for file names
15532 that represent full path names''. Thus ignoring dirname in the
15533 `else' branch below isn't an issue. */
15535 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15536 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15538 fullname
= filename
;
15540 start_subfile (fullname
, comp_dir
);
15542 if (fullname
!= filename
)
15546 /* Start a symtab for DWARF.
15547 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15550 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15551 char *name
, char *comp_dir
, CORE_ADDR low_pc
)
15553 start_symtab (name
, comp_dir
, low_pc
);
15554 record_debugformat ("DWARF 2");
15555 record_producer (cu
->producer
);
15557 /* We assume that we're processing GCC output. */
15558 processing_gcc_compilation
= 2;
15560 processing_has_namespace_info
= 0;
15564 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15565 struct dwarf2_cu
*cu
)
15567 struct objfile
*objfile
= cu
->objfile
;
15568 struct comp_unit_head
*cu_header
= &cu
->header
;
15570 /* NOTE drow/2003-01-30: There used to be a comment and some special
15571 code here to turn a symbol with DW_AT_external and a
15572 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15573 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15574 with some versions of binutils) where shared libraries could have
15575 relocations against symbols in their debug information - the
15576 minimal symbol would have the right address, but the debug info
15577 would not. It's no longer necessary, because we will explicitly
15578 apply relocations when we read in the debug information now. */
15580 /* A DW_AT_location attribute with no contents indicates that a
15581 variable has been optimized away. */
15582 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15584 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15588 /* Handle one degenerate form of location expression specially, to
15589 preserve GDB's previous behavior when section offsets are
15590 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15591 then mark this symbol as LOC_STATIC. */
15593 if (attr_form_is_block (attr
)
15594 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15595 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15596 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15597 && (DW_BLOCK (attr
)->size
15598 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15600 unsigned int dummy
;
15602 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15603 SYMBOL_VALUE_ADDRESS (sym
) =
15604 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15606 SYMBOL_VALUE_ADDRESS (sym
) =
15607 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15608 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15609 fixup_symbol_section (sym
, objfile
);
15610 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15611 SYMBOL_SECTION (sym
));
15615 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15616 expression evaluator, and use LOC_COMPUTED only when necessary
15617 (i.e. when the value of a register or memory location is
15618 referenced, or a thread-local block, etc.). Then again, it might
15619 not be worthwhile. I'm assuming that it isn't unless performance
15620 or memory numbers show me otherwise. */
15622 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15623 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15625 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15626 cu
->has_loclist
= 1;
15629 /* Given a pointer to a DWARF information entry, figure out if we need
15630 to make a symbol table entry for it, and if so, create a new entry
15631 and return a pointer to it.
15632 If TYPE is NULL, determine symbol type from the die, otherwise
15633 used the passed type.
15634 If SPACE is not NULL, use it to hold the new symbol. If it is
15635 NULL, allocate a new symbol on the objfile's obstack. */
15637 static struct symbol
*
15638 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15639 struct symbol
*space
)
15641 struct objfile
*objfile
= cu
->objfile
;
15642 struct symbol
*sym
= NULL
;
15644 struct attribute
*attr
= NULL
;
15645 struct attribute
*attr2
= NULL
;
15646 CORE_ADDR baseaddr
;
15647 struct pending
**list_to_add
= NULL
;
15649 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15651 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15653 name
= dwarf2_name (die
, cu
);
15656 const char *linkagename
;
15657 int suppress_add
= 0;
15662 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15663 OBJSTAT (objfile
, n_syms
++);
15665 /* Cache this symbol's name and the name's demangled form (if any). */
15666 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15667 linkagename
= dwarf2_physname (name
, die
, cu
);
15668 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15670 /* Fortran does not have mangling standard and the mangling does differ
15671 between gfortran, iFort etc. */
15672 if (cu
->language
== language_fortran
15673 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15674 symbol_set_demangled_name (&(sym
->ginfo
),
15675 (char *) dwarf2_full_name (name
, die
, cu
),
15678 /* Default assumptions.
15679 Use the passed type or decode it from the die. */
15680 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15681 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15683 SYMBOL_TYPE (sym
) = type
;
15685 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15686 attr
= dwarf2_attr (die
,
15687 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15691 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15694 attr
= dwarf2_attr (die
,
15695 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15699 int file_index
= DW_UNSND (attr
);
15701 if (cu
->line_header
== NULL
15702 || file_index
> cu
->line_header
->num_file_names
)
15703 complaint (&symfile_complaints
,
15704 _("file index out of range"));
15705 else if (file_index
> 0)
15707 struct file_entry
*fe
;
15709 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15710 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15717 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15720 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15722 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15723 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15724 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15725 add_symbol_to_list (sym
, cu
->list_in_scope
);
15727 case DW_TAG_subprogram
:
15728 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15730 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15731 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15732 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15733 || cu
->language
== language_ada
)
15735 /* Subprograms marked external are stored as a global symbol.
15736 Ada subprograms, whether marked external or not, are always
15737 stored as a global symbol, because we want to be able to
15738 access them globally. For instance, we want to be able
15739 to break on a nested subprogram without having to
15740 specify the context. */
15741 list_to_add
= &global_symbols
;
15745 list_to_add
= cu
->list_in_scope
;
15748 case DW_TAG_inlined_subroutine
:
15749 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15751 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15752 SYMBOL_INLINED (sym
) = 1;
15753 list_to_add
= cu
->list_in_scope
;
15755 case DW_TAG_template_value_param
:
15757 /* Fall through. */
15758 case DW_TAG_constant
:
15759 case DW_TAG_variable
:
15760 case DW_TAG_member
:
15761 /* Compilation with minimal debug info may result in
15762 variables with missing type entries. Change the
15763 misleading `void' type to something sensible. */
15764 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15766 = objfile_type (objfile
)->nodebug_data_symbol
;
15768 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15769 /* In the case of DW_TAG_member, we should only be called for
15770 static const members. */
15771 if (die
->tag
== DW_TAG_member
)
15773 /* dwarf2_add_field uses die_is_declaration,
15774 so we do the same. */
15775 gdb_assert (die_is_declaration (die
, cu
));
15780 dwarf2_const_value (attr
, sym
, cu
);
15781 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15784 if (attr2
&& (DW_UNSND (attr2
) != 0))
15785 list_to_add
= &global_symbols
;
15787 list_to_add
= cu
->list_in_scope
;
15791 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15794 var_decode_location (attr
, sym
, cu
);
15795 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15797 /* Fortran explicitly imports any global symbols to the local
15798 scope by DW_TAG_common_block. */
15799 if (cu
->language
== language_fortran
&& die
->parent
15800 && die
->parent
->tag
== DW_TAG_common_block
)
15803 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15804 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15805 && !dwarf2_per_objfile
->has_section_at_zero
)
15807 /* When a static variable is eliminated by the linker,
15808 the corresponding debug information is not stripped
15809 out, but the variable address is set to null;
15810 do not add such variables into symbol table. */
15812 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15814 /* Workaround gfortran PR debug/40040 - it uses
15815 DW_AT_location for variables in -fPIC libraries which may
15816 get overriden by other libraries/executable and get
15817 a different address. Resolve it by the minimal symbol
15818 which may come from inferior's executable using copy
15819 relocation. Make this workaround only for gfortran as for
15820 other compilers GDB cannot guess the minimal symbol
15821 Fortran mangling kind. */
15822 if (cu
->language
== language_fortran
&& die
->parent
15823 && die
->parent
->tag
== DW_TAG_module
15825 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15826 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15828 /* A variable with DW_AT_external is never static,
15829 but it may be block-scoped. */
15830 list_to_add
= (cu
->list_in_scope
== &file_symbols
15831 ? &global_symbols
: cu
->list_in_scope
);
15834 list_to_add
= cu
->list_in_scope
;
15838 /* We do not know the address of this symbol.
15839 If it is an external symbol and we have type information
15840 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15841 The address of the variable will then be determined from
15842 the minimal symbol table whenever the variable is
15844 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15846 /* Fortran explicitly imports any global symbols to the local
15847 scope by DW_TAG_common_block. */
15848 if (cu
->language
== language_fortran
&& die
->parent
15849 && die
->parent
->tag
== DW_TAG_common_block
)
15851 /* SYMBOL_CLASS doesn't matter here because
15852 read_common_block is going to reset it. */
15854 list_to_add
= cu
->list_in_scope
;
15856 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15857 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15859 /* A variable with DW_AT_external is never static, but it
15860 may be block-scoped. */
15861 list_to_add
= (cu
->list_in_scope
== &file_symbols
15862 ? &global_symbols
: cu
->list_in_scope
);
15864 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15866 else if (!die_is_declaration (die
, cu
))
15868 /* Use the default LOC_OPTIMIZED_OUT class. */
15869 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15871 list_to_add
= cu
->list_in_scope
;
15875 case DW_TAG_formal_parameter
:
15876 /* If we are inside a function, mark this as an argument. If
15877 not, we might be looking at an argument to an inlined function
15878 when we do not have enough information to show inlined frames;
15879 pretend it's a local variable in that case so that the user can
15881 if (context_stack_depth
> 0
15882 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15883 SYMBOL_IS_ARGUMENT (sym
) = 1;
15884 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15887 var_decode_location (attr
, sym
, cu
);
15889 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15892 dwarf2_const_value (attr
, sym
, cu
);
15895 list_to_add
= cu
->list_in_scope
;
15897 case DW_TAG_unspecified_parameters
:
15898 /* From varargs functions; gdb doesn't seem to have any
15899 interest in this information, so just ignore it for now.
15902 case DW_TAG_template_type_param
:
15904 /* Fall through. */
15905 case DW_TAG_class_type
:
15906 case DW_TAG_interface_type
:
15907 case DW_TAG_structure_type
:
15908 case DW_TAG_union_type
:
15909 case DW_TAG_set_type
:
15910 case DW_TAG_enumeration_type
:
15911 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15912 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
15915 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15916 really ever be static objects: otherwise, if you try
15917 to, say, break of a class's method and you're in a file
15918 which doesn't mention that class, it won't work unless
15919 the check for all static symbols in lookup_symbol_aux
15920 saves you. See the OtherFileClass tests in
15921 gdb.c++/namespace.exp. */
15925 list_to_add
= (cu
->list_in_scope
== &file_symbols
15926 && (cu
->language
== language_cplus
15927 || cu
->language
== language_java
)
15928 ? &global_symbols
: cu
->list_in_scope
);
15930 /* The semantics of C++ state that "struct foo {
15931 ... }" also defines a typedef for "foo". A Java
15932 class declaration also defines a typedef for the
15934 if (cu
->language
== language_cplus
15935 || cu
->language
== language_java
15936 || cu
->language
== language_ada
)
15938 /* The symbol's name is already allocated along
15939 with this objfile, so we don't need to
15940 duplicate it for the type. */
15941 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
15942 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
15947 case DW_TAG_typedef
:
15948 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15949 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15950 list_to_add
= cu
->list_in_scope
;
15952 case DW_TAG_base_type
:
15953 case DW_TAG_subrange_type
:
15954 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15955 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15956 list_to_add
= cu
->list_in_scope
;
15958 case DW_TAG_enumerator
:
15959 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15962 dwarf2_const_value (attr
, sym
, cu
);
15965 /* NOTE: carlton/2003-11-10: See comment above in the
15966 DW_TAG_class_type, etc. block. */
15968 list_to_add
= (cu
->list_in_scope
== &file_symbols
15969 && (cu
->language
== language_cplus
15970 || cu
->language
== language_java
)
15971 ? &global_symbols
: cu
->list_in_scope
);
15974 case DW_TAG_namespace
:
15975 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
15976 list_to_add
= &global_symbols
;
15978 case DW_TAG_common_block
:
15979 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15980 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
15981 add_symbol_to_list (sym
, cu
->list_in_scope
);
15984 /* Not a tag we recognize. Hopefully we aren't processing
15985 trash data, but since we must specifically ignore things
15986 we don't recognize, there is nothing else we should do at
15988 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
15989 dwarf_tag_name (die
->tag
));
15995 sym
->hash_next
= objfile
->template_symbols
;
15996 objfile
->template_symbols
= sym
;
15997 list_to_add
= NULL
;
16000 if (list_to_add
!= NULL
)
16001 add_symbol_to_list (sym
, list_to_add
);
16003 /* For the benefit of old versions of GCC, check for anonymous
16004 namespaces based on the demangled name. */
16005 if (!processing_has_namespace_info
16006 && cu
->language
== language_cplus
)
16007 cp_scan_for_anonymous_namespaces (sym
, objfile
);
16012 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16014 static struct symbol
*
16015 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16017 return new_symbol_full (die
, type
, cu
, NULL
);
16020 /* Given an attr with a DW_FORM_dataN value in host byte order,
16021 zero-extend it as appropriate for the symbol's type. The DWARF
16022 standard (v4) is not entirely clear about the meaning of using
16023 DW_FORM_dataN for a constant with a signed type, where the type is
16024 wider than the data. The conclusion of a discussion on the DWARF
16025 list was that this is unspecified. We choose to always zero-extend
16026 because that is the interpretation long in use by GCC. */
16029 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
16030 const char *name
, struct obstack
*obstack
,
16031 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16033 struct objfile
*objfile
= cu
->objfile
;
16034 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16035 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16036 LONGEST l
= DW_UNSND (attr
);
16038 if (bits
< sizeof (*value
) * 8)
16040 l
&= ((LONGEST
) 1 << bits
) - 1;
16043 else if (bits
== sizeof (*value
) * 8)
16047 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16048 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16055 /* Read a constant value from an attribute. Either set *VALUE, or if
16056 the value does not fit in *VALUE, set *BYTES - either already
16057 allocated on the objfile obstack, or newly allocated on OBSTACK,
16058 or, set *BATON, if we translated the constant to a location
16062 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16063 const char *name
, struct obstack
*obstack
,
16064 struct dwarf2_cu
*cu
,
16065 LONGEST
*value
, gdb_byte
**bytes
,
16066 struct dwarf2_locexpr_baton
**baton
)
16068 struct objfile
*objfile
= cu
->objfile
;
16069 struct comp_unit_head
*cu_header
= &cu
->header
;
16070 struct dwarf_block
*blk
;
16071 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16072 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16078 switch (attr
->form
)
16081 case DW_FORM_GNU_addr_index
:
16085 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16086 dwarf2_const_value_length_mismatch_complaint (name
,
16087 cu_header
->addr_size
,
16088 TYPE_LENGTH (type
));
16089 /* Symbols of this form are reasonably rare, so we just
16090 piggyback on the existing location code rather than writing
16091 a new implementation of symbol_computed_ops. */
16092 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16093 sizeof (struct dwarf2_locexpr_baton
));
16094 (*baton
)->per_cu
= cu
->per_cu
;
16095 gdb_assert ((*baton
)->per_cu
);
16097 (*baton
)->size
= 2 + cu_header
->addr_size
;
16098 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16099 (*baton
)->data
= data
;
16101 data
[0] = DW_OP_addr
;
16102 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16103 byte_order
, DW_ADDR (attr
));
16104 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16107 case DW_FORM_string
:
16109 case DW_FORM_GNU_str_index
:
16110 case DW_FORM_GNU_strp_alt
:
16111 /* DW_STRING is already allocated on the objfile obstack, point
16113 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16115 case DW_FORM_block1
:
16116 case DW_FORM_block2
:
16117 case DW_FORM_block4
:
16118 case DW_FORM_block
:
16119 case DW_FORM_exprloc
:
16120 blk
= DW_BLOCK (attr
);
16121 if (TYPE_LENGTH (type
) != blk
->size
)
16122 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16123 TYPE_LENGTH (type
));
16124 *bytes
= blk
->data
;
16127 /* The DW_AT_const_value attributes are supposed to carry the
16128 symbol's value "represented as it would be on the target
16129 architecture." By the time we get here, it's already been
16130 converted to host endianness, so we just need to sign- or
16131 zero-extend it as appropriate. */
16132 case DW_FORM_data1
:
16133 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16134 obstack
, cu
, value
, 8);
16136 case DW_FORM_data2
:
16137 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16138 obstack
, cu
, value
, 16);
16140 case DW_FORM_data4
:
16141 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16142 obstack
, cu
, value
, 32);
16144 case DW_FORM_data8
:
16145 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16146 obstack
, cu
, value
, 64);
16149 case DW_FORM_sdata
:
16150 *value
= DW_SND (attr
);
16153 case DW_FORM_udata
:
16154 *value
= DW_UNSND (attr
);
16158 complaint (&symfile_complaints
,
16159 _("unsupported const value attribute form: '%s'"),
16160 dwarf_form_name (attr
->form
));
16167 /* Copy constant value from an attribute to a symbol. */
16170 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16171 struct dwarf2_cu
*cu
)
16173 struct objfile
*objfile
= cu
->objfile
;
16174 struct comp_unit_head
*cu_header
= &cu
->header
;
16177 struct dwarf2_locexpr_baton
*baton
;
16179 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16180 SYMBOL_PRINT_NAME (sym
),
16181 &objfile
->objfile_obstack
, cu
,
16182 &value
, &bytes
, &baton
);
16186 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16187 SYMBOL_LOCATION_BATON (sym
) = baton
;
16188 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16190 else if (bytes
!= NULL
)
16192 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16193 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16197 SYMBOL_VALUE (sym
) = value
;
16198 SYMBOL_CLASS (sym
) = LOC_CONST
;
16202 /* Return the type of the die in question using its DW_AT_type attribute. */
16204 static struct type
*
16205 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16207 struct attribute
*type_attr
;
16209 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16212 /* A missing DW_AT_type represents a void type. */
16213 return objfile_type (cu
->objfile
)->builtin_void
;
16216 return lookup_die_type (die
, type_attr
, cu
);
16219 /* True iff CU's producer generates GNAT Ada auxiliary information
16220 that allows to find parallel types through that information instead
16221 of having to do expensive parallel lookups by type name. */
16224 need_gnat_info (struct dwarf2_cu
*cu
)
16226 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16227 of GNAT produces this auxiliary information, without any indication
16228 that it is produced. Part of enhancing the FSF version of GNAT
16229 to produce that information will be to put in place an indicator
16230 that we can use in order to determine whether the descriptive type
16231 info is available or not. One suggestion that has been made is
16232 to use a new attribute, attached to the CU die. For now, assume
16233 that the descriptive type info is not available. */
16237 /* Return the auxiliary type of the die in question using its
16238 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16239 attribute is not present. */
16241 static struct type
*
16242 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16244 struct attribute
*type_attr
;
16246 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16250 return lookup_die_type (die
, type_attr
, cu
);
16253 /* If DIE has a descriptive_type attribute, then set the TYPE's
16254 descriptive type accordingly. */
16257 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16258 struct dwarf2_cu
*cu
)
16260 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16262 if (descriptive_type
)
16264 ALLOCATE_GNAT_AUX_TYPE (type
);
16265 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16269 /* Return the containing type of the die in question using its
16270 DW_AT_containing_type attribute. */
16272 static struct type
*
16273 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16275 struct attribute
*type_attr
;
16277 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16279 error (_("Dwarf Error: Problem turning containing type into gdb type "
16280 "[in module %s]"), cu
->objfile
->name
);
16282 return lookup_die_type (die
, type_attr
, cu
);
16285 /* Look up the type of DIE in CU using its type attribute ATTR.
16286 If there is no type substitute an error marker. */
16288 static struct type
*
16289 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16290 struct dwarf2_cu
*cu
)
16292 struct objfile
*objfile
= cu
->objfile
;
16293 struct type
*this_type
;
16295 /* First see if we have it cached. */
16297 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16299 struct dwarf2_per_cu_data
*per_cu
;
16300 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16302 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16303 this_type
= get_die_type_at_offset (offset
, per_cu
);
16305 else if (is_ref_attr (attr
))
16307 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16309 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16311 else if (attr
->form
== DW_FORM_ref_sig8
)
16313 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16315 /* sig_type will be NULL if the signatured type is missing from
16317 if (sig_type
== NULL
)
16318 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16319 "at 0x%x [in module %s]"),
16320 die
->offset
.sect_off
, objfile
->name
);
16322 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16323 /* If we haven't filled in type_offset_in_section yet, then we
16324 haven't read the type in yet. */
16326 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16329 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16330 &sig_type
->per_cu
);
16335 dump_die_for_error (die
);
16336 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16337 dwarf_attr_name (attr
->name
), objfile
->name
);
16340 /* If not cached we need to read it in. */
16342 if (this_type
== NULL
)
16344 struct die_info
*type_die
;
16345 struct dwarf2_cu
*type_cu
= cu
;
16347 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16348 /* If we found the type now, it's probably because the type came
16349 from an inter-CU reference and the type's CU got expanded before
16351 this_type
= get_die_type (type_die
, type_cu
);
16352 if (this_type
== NULL
)
16353 this_type
= read_type_die_1 (type_die
, type_cu
);
16356 /* If we still don't have a type use an error marker. */
16358 if (this_type
== NULL
)
16360 char *message
, *saved
;
16362 /* read_type_die already issued a complaint. */
16363 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16365 cu
->header
.offset
.sect_off
,
16366 die
->offset
.sect_off
);
16367 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16368 message
, strlen (message
));
16371 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16377 /* Return the type in DIE, CU.
16378 Returns NULL for invalid types.
16380 This first does a lookup in the appropriate type_hash table,
16381 and only reads the die in if necessary.
16383 NOTE: This can be called when reading in partial or full symbols. */
16385 static struct type
*
16386 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16388 struct type
*this_type
;
16390 this_type
= get_die_type (die
, cu
);
16394 return read_type_die_1 (die
, cu
);
16397 /* Read the type in DIE, CU.
16398 Returns NULL for invalid types. */
16400 static struct type
*
16401 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16403 struct type
*this_type
= NULL
;
16407 case DW_TAG_class_type
:
16408 case DW_TAG_interface_type
:
16409 case DW_TAG_structure_type
:
16410 case DW_TAG_union_type
:
16411 this_type
= read_structure_type (die
, cu
);
16413 case DW_TAG_enumeration_type
:
16414 this_type
= read_enumeration_type (die
, cu
);
16416 case DW_TAG_subprogram
:
16417 case DW_TAG_subroutine_type
:
16418 case DW_TAG_inlined_subroutine
:
16419 this_type
= read_subroutine_type (die
, cu
);
16421 case DW_TAG_array_type
:
16422 this_type
= read_array_type (die
, cu
);
16424 case DW_TAG_set_type
:
16425 this_type
= read_set_type (die
, cu
);
16427 case DW_TAG_pointer_type
:
16428 this_type
= read_tag_pointer_type (die
, cu
);
16430 case DW_TAG_ptr_to_member_type
:
16431 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16433 case DW_TAG_reference_type
:
16434 this_type
= read_tag_reference_type (die
, cu
);
16436 case DW_TAG_const_type
:
16437 this_type
= read_tag_const_type (die
, cu
);
16439 case DW_TAG_volatile_type
:
16440 this_type
= read_tag_volatile_type (die
, cu
);
16442 case DW_TAG_string_type
:
16443 this_type
= read_tag_string_type (die
, cu
);
16445 case DW_TAG_typedef
:
16446 this_type
= read_typedef (die
, cu
);
16448 case DW_TAG_subrange_type
:
16449 this_type
= read_subrange_type (die
, cu
);
16451 case DW_TAG_base_type
:
16452 this_type
= read_base_type (die
, cu
);
16454 case DW_TAG_unspecified_type
:
16455 this_type
= read_unspecified_type (die
, cu
);
16457 case DW_TAG_namespace
:
16458 this_type
= read_namespace_type (die
, cu
);
16460 case DW_TAG_module
:
16461 this_type
= read_module_type (die
, cu
);
16464 complaint (&symfile_complaints
,
16465 _("unexpected tag in read_type_die: '%s'"),
16466 dwarf_tag_name (die
->tag
));
16473 /* See if we can figure out if the class lives in a namespace. We do
16474 this by looking for a member function; its demangled name will
16475 contain namespace info, if there is any.
16476 Return the computed name or NULL.
16477 Space for the result is allocated on the objfile's obstack.
16478 This is the full-die version of guess_partial_die_structure_name.
16479 In this case we know DIE has no useful parent. */
16482 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16484 struct die_info
*spec_die
;
16485 struct dwarf2_cu
*spec_cu
;
16486 struct die_info
*child
;
16489 spec_die
= die_specification (die
, &spec_cu
);
16490 if (spec_die
!= NULL
)
16496 for (child
= die
->child
;
16498 child
= child
->sibling
)
16500 if (child
->tag
== DW_TAG_subprogram
)
16502 struct attribute
*attr
;
16504 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16506 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16510 = language_class_name_from_physname (cu
->language_defn
,
16514 if (actual_name
!= NULL
)
16516 char *die_name
= dwarf2_name (die
, cu
);
16518 if (die_name
!= NULL
16519 && strcmp (die_name
, actual_name
) != 0)
16521 /* Strip off the class name from the full name.
16522 We want the prefix. */
16523 int die_name_len
= strlen (die_name
);
16524 int actual_name_len
= strlen (actual_name
);
16526 /* Test for '::' as a sanity check. */
16527 if (actual_name_len
> die_name_len
+ 2
16528 && actual_name
[actual_name_len
16529 - die_name_len
- 1] == ':')
16531 obsavestring (actual_name
,
16532 actual_name_len
- die_name_len
- 2,
16533 &cu
->objfile
->objfile_obstack
);
16536 xfree (actual_name
);
16545 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16546 prefix part in such case. See
16547 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16550 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16552 struct attribute
*attr
;
16555 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16556 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16559 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16560 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16563 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16565 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16566 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16569 /* dwarf2_name had to be already called. */
16570 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16572 /* Strip the base name, keep any leading namespaces/classes. */
16573 base
= strrchr (DW_STRING (attr
), ':');
16574 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16577 return obsavestring (DW_STRING (attr
), &base
[-1] - DW_STRING (attr
),
16578 &cu
->objfile
->objfile_obstack
);
16581 /* Return the name of the namespace/class that DIE is defined within,
16582 or "" if we can't tell. The caller should not xfree the result.
16584 For example, if we're within the method foo() in the following
16594 then determine_prefix on foo's die will return "N::C". */
16596 static const char *
16597 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16599 struct die_info
*parent
, *spec_die
;
16600 struct dwarf2_cu
*spec_cu
;
16601 struct type
*parent_type
;
16604 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16605 && cu
->language
!= language_fortran
)
16608 retval
= anonymous_struct_prefix (die
, cu
);
16612 /* We have to be careful in the presence of DW_AT_specification.
16613 For example, with GCC 3.4, given the code
16617 // Definition of N::foo.
16621 then we'll have a tree of DIEs like this:
16623 1: DW_TAG_compile_unit
16624 2: DW_TAG_namespace // N
16625 3: DW_TAG_subprogram // declaration of N::foo
16626 4: DW_TAG_subprogram // definition of N::foo
16627 DW_AT_specification // refers to die #3
16629 Thus, when processing die #4, we have to pretend that we're in
16630 the context of its DW_AT_specification, namely the contex of die
16633 spec_die
= die_specification (die
, &spec_cu
);
16634 if (spec_die
== NULL
)
16635 parent
= die
->parent
;
16638 parent
= spec_die
->parent
;
16642 if (parent
== NULL
)
16644 else if (parent
->building_fullname
)
16647 const char *parent_name
;
16649 /* It has been seen on RealView 2.2 built binaries,
16650 DW_TAG_template_type_param types actually _defined_ as
16651 children of the parent class:
16654 template class <class Enum> Class{};
16655 Class<enum E> class_e;
16657 1: DW_TAG_class_type (Class)
16658 2: DW_TAG_enumeration_type (E)
16659 3: DW_TAG_enumerator (enum1:0)
16660 3: DW_TAG_enumerator (enum2:1)
16662 2: DW_TAG_template_type_param
16663 DW_AT_type DW_FORM_ref_udata (E)
16665 Besides being broken debug info, it can put GDB into an
16666 infinite loop. Consider:
16668 When we're building the full name for Class<E>, we'll start
16669 at Class, and go look over its template type parameters,
16670 finding E. We'll then try to build the full name of E, and
16671 reach here. We're now trying to build the full name of E,
16672 and look over the parent DIE for containing scope. In the
16673 broken case, if we followed the parent DIE of E, we'd again
16674 find Class, and once again go look at its template type
16675 arguments, etc., etc. Simply don't consider such parent die
16676 as source-level parent of this die (it can't be, the language
16677 doesn't allow it), and break the loop here. */
16678 name
= dwarf2_name (die
, cu
);
16679 parent_name
= dwarf2_name (parent
, cu
);
16680 complaint (&symfile_complaints
,
16681 _("template param type '%s' defined within parent '%s'"),
16682 name
? name
: "<unknown>",
16683 parent_name
? parent_name
: "<unknown>");
16687 switch (parent
->tag
)
16689 case DW_TAG_namespace
:
16690 parent_type
= read_type_die (parent
, cu
);
16691 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16692 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16693 Work around this problem here. */
16694 if (cu
->language
== language_cplus
16695 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16697 /* We give a name to even anonymous namespaces. */
16698 return TYPE_TAG_NAME (parent_type
);
16699 case DW_TAG_class_type
:
16700 case DW_TAG_interface_type
:
16701 case DW_TAG_structure_type
:
16702 case DW_TAG_union_type
:
16703 case DW_TAG_module
:
16704 parent_type
= read_type_die (parent
, cu
);
16705 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16706 return TYPE_TAG_NAME (parent_type
);
16708 /* An anonymous structure is only allowed non-static data
16709 members; no typedefs, no member functions, et cetera.
16710 So it does not need a prefix. */
16712 case DW_TAG_compile_unit
:
16713 case DW_TAG_partial_unit
:
16714 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16715 if (cu
->language
== language_cplus
16716 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16717 && die
->child
!= NULL
16718 && (die
->tag
== DW_TAG_class_type
16719 || die
->tag
== DW_TAG_structure_type
16720 || die
->tag
== DW_TAG_union_type
))
16722 char *name
= guess_full_die_structure_name (die
, cu
);
16728 return determine_prefix (parent
, cu
);
16732 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16733 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16734 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16735 an obconcat, otherwise allocate storage for the result. The CU argument is
16736 used to determine the language and hence, the appropriate separator. */
16738 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16741 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16742 int physname
, struct dwarf2_cu
*cu
)
16744 const char *lead
= "";
16747 if (suffix
== NULL
|| suffix
[0] == '\0'
16748 || prefix
== NULL
|| prefix
[0] == '\0')
16750 else if (cu
->language
== language_java
)
16752 else if (cu
->language
== language_fortran
&& physname
)
16754 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16755 DW_AT_MIPS_linkage_name is preferred and used instead. */
16763 if (prefix
== NULL
)
16765 if (suffix
== NULL
)
16771 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16773 strcpy (retval
, lead
);
16774 strcat (retval
, prefix
);
16775 strcat (retval
, sep
);
16776 strcat (retval
, suffix
);
16781 /* We have an obstack. */
16782 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16786 /* Return sibling of die, NULL if no sibling. */
16788 static struct die_info
*
16789 sibling_die (struct die_info
*die
)
16791 return die
->sibling
;
16794 /* Get name of a die, return NULL if not found. */
16797 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
16798 struct obstack
*obstack
)
16800 if (name
&& cu
->language
== language_cplus
)
16802 char *canon_name
= cp_canonicalize_string (name
);
16804 if (canon_name
!= NULL
)
16806 if (strcmp (canon_name
, name
) != 0)
16807 name
= obsavestring (canon_name
, strlen (canon_name
),
16809 xfree (canon_name
);
16816 /* Get name of a die, return NULL if not found. */
16819 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16821 struct attribute
*attr
;
16823 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16824 if ((!attr
|| !DW_STRING (attr
))
16825 && die
->tag
!= DW_TAG_class_type
16826 && die
->tag
!= DW_TAG_interface_type
16827 && die
->tag
!= DW_TAG_structure_type
16828 && die
->tag
!= DW_TAG_union_type
)
16833 case DW_TAG_compile_unit
:
16834 case DW_TAG_partial_unit
:
16835 /* Compilation units have a DW_AT_name that is a filename, not
16836 a source language identifier. */
16837 case DW_TAG_enumeration_type
:
16838 case DW_TAG_enumerator
:
16839 /* These tags always have simple identifiers already; no need
16840 to canonicalize them. */
16841 return DW_STRING (attr
);
16843 case DW_TAG_subprogram
:
16844 /* Java constructors will all be named "<init>", so return
16845 the class name when we see this special case. */
16846 if (cu
->language
== language_java
16847 && DW_STRING (attr
) != NULL
16848 && strcmp (DW_STRING (attr
), "<init>") == 0)
16850 struct dwarf2_cu
*spec_cu
= cu
;
16851 struct die_info
*spec_die
;
16853 /* GCJ will output '<init>' for Java constructor names.
16854 For this special case, return the name of the parent class. */
16856 /* GCJ may output suprogram DIEs with AT_specification set.
16857 If so, use the name of the specified DIE. */
16858 spec_die
= die_specification (die
, &spec_cu
);
16859 if (spec_die
!= NULL
)
16860 return dwarf2_name (spec_die
, spec_cu
);
16865 if (die
->tag
== DW_TAG_class_type
)
16866 return dwarf2_name (die
, cu
);
16868 while (die
->tag
!= DW_TAG_compile_unit
16869 && die
->tag
!= DW_TAG_partial_unit
);
16873 case DW_TAG_class_type
:
16874 case DW_TAG_interface_type
:
16875 case DW_TAG_structure_type
:
16876 case DW_TAG_union_type
:
16877 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16878 structures or unions. These were of the form "._%d" in GCC 4.1,
16879 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16880 and GCC 4.4. We work around this problem by ignoring these. */
16881 if (attr
&& DW_STRING (attr
)
16882 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16883 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16886 /* GCC might emit a nameless typedef that has a linkage name. See
16887 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16888 if (!attr
|| DW_STRING (attr
) == NULL
)
16890 char *demangled
= NULL
;
16892 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16894 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16896 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16899 /* Avoid demangling DW_STRING (attr) the second time on a second
16900 call for the same DIE. */
16901 if (!DW_STRING_IS_CANONICAL (attr
))
16902 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
16908 /* FIXME: we already did this for the partial symbol... */
16909 DW_STRING (attr
) = obsavestring (demangled
, strlen (demangled
),
16910 &cu
->objfile
->objfile_obstack
);
16911 DW_STRING_IS_CANONICAL (attr
) = 1;
16914 /* Strip any leading namespaces/classes, keep only the base name.
16915 DW_AT_name for named DIEs does not contain the prefixes. */
16916 base
= strrchr (DW_STRING (attr
), ':');
16917 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
16920 return DW_STRING (attr
);
16929 if (!DW_STRING_IS_CANONICAL (attr
))
16932 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
16933 &cu
->objfile
->objfile_obstack
);
16934 DW_STRING_IS_CANONICAL (attr
) = 1;
16936 return DW_STRING (attr
);
16939 /* Return the die that this die in an extension of, or NULL if there
16940 is none. *EXT_CU is the CU containing DIE on input, and the CU
16941 containing the return value on output. */
16943 static struct die_info
*
16944 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
16946 struct attribute
*attr
;
16948 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
16952 return follow_die_ref (die
, attr
, ext_cu
);
16955 /* Convert a DIE tag into its string name. */
16957 static const char *
16958 dwarf_tag_name (unsigned tag
)
16960 const char *name
= get_DW_TAG_name (tag
);
16963 return "DW_TAG_<unknown>";
16968 /* Convert a DWARF attribute code into its string name. */
16970 static const char *
16971 dwarf_attr_name (unsigned attr
)
16975 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16976 if (attr
== DW_AT_MIPS_fde
)
16977 return "DW_AT_MIPS_fde";
16979 if (attr
== DW_AT_HP_block_index
)
16980 return "DW_AT_HP_block_index";
16983 name
= get_DW_AT_name (attr
);
16986 return "DW_AT_<unknown>";
16991 /* Convert a DWARF value form code into its string name. */
16993 static const char *
16994 dwarf_form_name (unsigned form
)
16996 const char *name
= get_DW_FORM_name (form
);
16999 return "DW_FORM_<unknown>";
17005 dwarf_bool_name (unsigned mybool
)
17013 /* Convert a DWARF type code into its string name. */
17015 static const char *
17016 dwarf_type_encoding_name (unsigned enc
)
17018 const char *name
= get_DW_ATE_name (enc
);
17021 return "DW_ATE_<unknown>";
17027 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17031 print_spaces (indent
, f
);
17032 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17033 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17035 if (die
->parent
!= NULL
)
17037 print_spaces (indent
, f
);
17038 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17039 die
->parent
->offset
.sect_off
);
17042 print_spaces (indent
, f
);
17043 fprintf_unfiltered (f
, " has children: %s\n",
17044 dwarf_bool_name (die
->child
!= NULL
));
17046 print_spaces (indent
, f
);
17047 fprintf_unfiltered (f
, " attributes:\n");
17049 for (i
= 0; i
< die
->num_attrs
; ++i
)
17051 print_spaces (indent
, f
);
17052 fprintf_unfiltered (f
, " %s (%s) ",
17053 dwarf_attr_name (die
->attrs
[i
].name
),
17054 dwarf_form_name (die
->attrs
[i
].form
));
17056 switch (die
->attrs
[i
].form
)
17059 case DW_FORM_GNU_addr_index
:
17060 fprintf_unfiltered (f
, "address: ");
17061 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17063 case DW_FORM_block2
:
17064 case DW_FORM_block4
:
17065 case DW_FORM_block
:
17066 case DW_FORM_block1
:
17067 fprintf_unfiltered (f
, "block: size %s",
17068 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17070 case DW_FORM_exprloc
:
17071 fprintf_unfiltered (f
, "expression: size %s",
17072 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17074 case DW_FORM_ref_addr
:
17075 fprintf_unfiltered (f
, "ref address: ");
17076 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17078 case DW_FORM_GNU_ref_alt
:
17079 fprintf_unfiltered (f
, "alt ref address: ");
17080 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17086 case DW_FORM_ref_udata
:
17087 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17088 (long) (DW_UNSND (&die
->attrs
[i
])));
17090 case DW_FORM_data1
:
17091 case DW_FORM_data2
:
17092 case DW_FORM_data4
:
17093 case DW_FORM_data8
:
17094 case DW_FORM_udata
:
17095 case DW_FORM_sdata
:
17096 fprintf_unfiltered (f
, "constant: %s",
17097 pulongest (DW_UNSND (&die
->attrs
[i
])));
17099 case DW_FORM_sec_offset
:
17100 fprintf_unfiltered (f
, "section offset: %s",
17101 pulongest (DW_UNSND (&die
->attrs
[i
])));
17103 case DW_FORM_ref_sig8
:
17104 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17105 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17106 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17108 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17110 case DW_FORM_string
:
17112 case DW_FORM_GNU_str_index
:
17113 case DW_FORM_GNU_strp_alt
:
17114 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17115 DW_STRING (&die
->attrs
[i
])
17116 ? DW_STRING (&die
->attrs
[i
]) : "",
17117 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17120 if (DW_UNSND (&die
->attrs
[i
]))
17121 fprintf_unfiltered (f
, "flag: TRUE");
17123 fprintf_unfiltered (f
, "flag: FALSE");
17125 case DW_FORM_flag_present
:
17126 fprintf_unfiltered (f
, "flag: TRUE");
17128 case DW_FORM_indirect
:
17129 /* The reader will have reduced the indirect form to
17130 the "base form" so this form should not occur. */
17131 fprintf_unfiltered (f
,
17132 "unexpected attribute form: DW_FORM_indirect");
17135 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17136 die
->attrs
[i
].form
);
17139 fprintf_unfiltered (f
, "\n");
17144 dump_die_for_error (struct die_info
*die
)
17146 dump_die_shallow (gdb_stderr
, 0, die
);
17150 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17152 int indent
= level
* 4;
17154 gdb_assert (die
!= NULL
);
17156 if (level
>= max_level
)
17159 dump_die_shallow (f
, indent
, die
);
17161 if (die
->child
!= NULL
)
17163 print_spaces (indent
, f
);
17164 fprintf_unfiltered (f
, " Children:");
17165 if (level
+ 1 < max_level
)
17167 fprintf_unfiltered (f
, "\n");
17168 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17172 fprintf_unfiltered (f
,
17173 " [not printed, max nesting level reached]\n");
17177 if (die
->sibling
!= NULL
&& level
> 0)
17179 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17183 /* This is called from the pdie macro in gdbinit.in.
17184 It's not static so gcc will keep a copy callable from gdb. */
17187 dump_die (struct die_info
*die
, int max_level
)
17189 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17193 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17197 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17203 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17204 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17207 is_ref_attr (struct attribute
*attr
)
17209 switch (attr
->form
)
17211 case DW_FORM_ref_addr
:
17216 case DW_FORM_ref_udata
:
17217 case DW_FORM_GNU_ref_alt
:
17224 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17228 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17230 sect_offset retval
= { DW_UNSND (attr
) };
17232 if (is_ref_attr (attr
))
17235 retval
.sect_off
= 0;
17236 complaint (&symfile_complaints
,
17237 _("unsupported die ref attribute form: '%s'"),
17238 dwarf_form_name (attr
->form
));
17242 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17243 * the value held by the attribute is not constant. */
17246 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17248 if (attr
->form
== DW_FORM_sdata
)
17249 return DW_SND (attr
);
17250 else if (attr
->form
== DW_FORM_udata
17251 || attr
->form
== DW_FORM_data1
17252 || attr
->form
== DW_FORM_data2
17253 || attr
->form
== DW_FORM_data4
17254 || attr
->form
== DW_FORM_data8
)
17255 return DW_UNSND (attr
);
17258 complaint (&symfile_complaints
,
17259 _("Attribute value is not a constant (%s)"),
17260 dwarf_form_name (attr
->form
));
17261 return default_value
;
17265 /* Follow reference or signature attribute ATTR of SRC_DIE.
17266 On entry *REF_CU is the CU of SRC_DIE.
17267 On exit *REF_CU is the CU of the result. */
17269 static struct die_info
*
17270 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17271 struct dwarf2_cu
**ref_cu
)
17273 struct die_info
*die
;
17275 if (is_ref_attr (attr
))
17276 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17277 else if (attr
->form
== DW_FORM_ref_sig8
)
17278 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17281 dump_die_for_error (src_die
);
17282 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17283 (*ref_cu
)->objfile
->name
);
17289 /* Follow reference OFFSET.
17290 On entry *REF_CU is the CU of the source die referencing OFFSET.
17291 On exit *REF_CU is the CU of the result.
17292 Returns NULL if OFFSET is invalid. */
17294 static struct die_info
*
17295 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17296 struct dwarf2_cu
**ref_cu
)
17298 struct die_info temp_die
;
17299 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17301 gdb_assert (cu
->per_cu
!= NULL
);
17305 if (cu
->per_cu
->is_debug_types
)
17307 /* .debug_types CUs cannot reference anything outside their CU.
17308 If they need to, they have to reference a signatured type via
17309 DW_FORM_ref_sig8. */
17310 if (! offset_in_cu_p (&cu
->header
, offset
))
17313 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17314 || ! offset_in_cu_p (&cu
->header
, offset
))
17316 struct dwarf2_per_cu_data
*per_cu
;
17318 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17321 /* If necessary, add it to the queue and load its DIEs. */
17322 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17323 load_full_comp_unit (per_cu
, cu
->language
);
17325 target_cu
= per_cu
->cu
;
17327 else if (cu
->dies
== NULL
)
17329 /* We're loading full DIEs during partial symbol reading. */
17330 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17331 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17334 *ref_cu
= target_cu
;
17335 temp_die
.offset
= offset
;
17336 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17339 /* Follow reference attribute ATTR of SRC_DIE.
17340 On entry *REF_CU is the CU of SRC_DIE.
17341 On exit *REF_CU is the CU of the result. */
17343 static struct die_info
*
17344 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17345 struct dwarf2_cu
**ref_cu
)
17347 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17348 struct dwarf2_cu
*cu
= *ref_cu
;
17349 struct die_info
*die
;
17351 die
= follow_die_offset (offset
,
17352 (attr
->form
== DW_FORM_GNU_ref_alt
17353 || cu
->per_cu
->is_dwz
),
17356 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17357 "at 0x%x [in module %s]"),
17358 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17363 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17364 Returned value is intended for DW_OP_call*. Returned
17365 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17367 struct dwarf2_locexpr_baton
17368 dwarf2_fetch_die_location_block (cu_offset offset_in_cu
,
17369 struct dwarf2_per_cu_data
*per_cu
,
17370 CORE_ADDR (*get_frame_pc
) (void *baton
),
17373 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17374 struct dwarf2_cu
*cu
;
17375 struct die_info
*die
;
17376 struct attribute
*attr
;
17377 struct dwarf2_locexpr_baton retval
;
17379 dw2_setup (per_cu
->objfile
);
17381 if (per_cu
->cu
== NULL
)
17385 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17387 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17388 offset
.sect_off
, per_cu
->objfile
->name
);
17390 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17393 /* DWARF: "If there is no such attribute, then there is no effect.".
17394 DATA is ignored if SIZE is 0. */
17396 retval
.data
= NULL
;
17399 else if (attr_form_is_section_offset (attr
))
17401 struct dwarf2_loclist_baton loclist_baton
;
17402 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17405 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17407 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17409 retval
.size
= size
;
17413 if (!attr_form_is_block (attr
))
17414 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17415 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17416 offset
.sect_off
, per_cu
->objfile
->name
);
17418 retval
.data
= DW_BLOCK (attr
)->data
;
17419 retval
.size
= DW_BLOCK (attr
)->size
;
17421 retval
.per_cu
= cu
->per_cu
;
17423 age_cached_comp_units ();
17428 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17432 dwarf2_get_die_type (cu_offset die_offset
,
17433 struct dwarf2_per_cu_data
*per_cu
)
17435 sect_offset die_offset_sect
;
17437 dw2_setup (per_cu
->objfile
);
17439 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17440 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17443 /* Follow the signature attribute ATTR in SRC_DIE.
17444 On entry *REF_CU is the CU of SRC_DIE.
17445 On exit *REF_CU is the CU of the result. */
17447 static struct die_info
*
17448 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17449 struct dwarf2_cu
**ref_cu
)
17451 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17452 struct die_info temp_die
;
17453 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17454 struct dwarf2_cu
*sig_cu
;
17455 struct die_info
*die
;
17457 /* sig_type will be NULL if the signatured type is missing from
17459 if (sig_type
== NULL
)
17460 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17461 "at 0x%x [in module %s]"),
17462 src_die
->offset
.sect_off
, objfile
->name
);
17464 /* If necessary, add it to the queue and load its DIEs. */
17466 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17467 read_signatured_type (sig_type
);
17469 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17471 sig_cu
= sig_type
->per_cu
.cu
;
17472 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17473 temp_die
.offset
= sig_type
->type_offset_in_section
;
17474 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17475 temp_die
.offset
.sect_off
);
17482 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17483 "from DIE at 0x%x [in module %s]"),
17484 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17487 /* Given an offset of a signatured type, return its signatured_type. */
17489 static struct signatured_type
*
17490 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17491 struct dwarf2_section_info
*section
,
17492 sect_offset offset
)
17494 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17495 unsigned int length
, initial_length_size
;
17496 unsigned int sig_offset
;
17497 struct signatured_type find_entry
, *sig_type
;
17499 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17500 sig_offset
= (initial_length_size
17502 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17503 + 1 /*address_size*/);
17504 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17505 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17507 /* This is only used to lookup previously recorded types.
17508 If we didn't find it, it's our bug. */
17509 gdb_assert (sig_type
!= NULL
);
17510 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17515 /* Load the DIEs associated with type unit PER_CU into memory. */
17518 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17520 struct signatured_type
*sig_type
;
17522 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17523 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17525 /* We have the per_cu, but we need the signatured_type.
17526 Fortunately this is an easy translation. */
17527 gdb_assert (per_cu
->is_debug_types
);
17528 sig_type
= (struct signatured_type
*) per_cu
;
17530 gdb_assert (per_cu
->cu
== NULL
);
17532 read_signatured_type (sig_type
);
17534 gdb_assert (per_cu
->cu
!= NULL
);
17537 /* die_reader_func for read_signatured_type.
17538 This is identical to load_full_comp_unit_reader,
17539 but is kept separate for now. */
17542 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17543 gdb_byte
*info_ptr
,
17544 struct die_info
*comp_unit_die
,
17548 struct dwarf2_cu
*cu
= reader
->cu
;
17550 gdb_assert (cu
->die_hash
== NULL
);
17552 htab_create_alloc_ex (cu
->header
.length
/ 12,
17556 &cu
->comp_unit_obstack
,
17557 hashtab_obstack_allocate
,
17558 dummy_obstack_deallocate
);
17561 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17562 &info_ptr
, comp_unit_die
);
17563 cu
->dies
= comp_unit_die
;
17564 /* comp_unit_die is not stored in die_hash, no need. */
17566 /* We try not to read any attributes in this function, because not
17567 all CUs needed for references have been loaded yet, and symbol
17568 table processing isn't initialized. But we have to set the CU language,
17569 or we won't be able to build types correctly.
17570 Similarly, if we do not read the producer, we can not apply
17571 producer-specific interpretation. */
17572 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17575 /* Read in a signatured type and build its CU and DIEs.
17576 If the type is a stub for the real type in a DWO file,
17577 read in the real type from the DWO file as well. */
17580 read_signatured_type (struct signatured_type
*sig_type
)
17582 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17584 gdb_assert (per_cu
->is_debug_types
);
17585 gdb_assert (per_cu
->cu
== NULL
);
17587 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17588 read_signatured_type_reader
, NULL
);
17591 /* Decode simple location descriptions.
17592 Given a pointer to a dwarf block that defines a location, compute
17593 the location and return the value.
17595 NOTE drow/2003-11-18: This function is called in two situations
17596 now: for the address of static or global variables (partial symbols
17597 only) and for offsets into structures which are expected to be
17598 (more or less) constant. The partial symbol case should go away,
17599 and only the constant case should remain. That will let this
17600 function complain more accurately. A few special modes are allowed
17601 without complaint for global variables (for instance, global
17602 register values and thread-local values).
17604 A location description containing no operations indicates that the
17605 object is optimized out. The return value is 0 for that case.
17606 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17607 callers will only want a very basic result and this can become a
17610 Note that stack[0] is unused except as a default error return. */
17613 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17615 struct objfile
*objfile
= cu
->objfile
;
17617 size_t size
= blk
->size
;
17618 gdb_byte
*data
= blk
->data
;
17619 CORE_ADDR stack
[64];
17621 unsigned int bytes_read
, unsnd
;
17627 stack
[++stacki
] = 0;
17666 stack
[++stacki
] = op
- DW_OP_lit0
;
17701 stack
[++stacki
] = op
- DW_OP_reg0
;
17703 dwarf2_complex_location_expr_complaint ();
17707 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17709 stack
[++stacki
] = unsnd
;
17711 dwarf2_complex_location_expr_complaint ();
17715 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17720 case DW_OP_const1u
:
17721 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17725 case DW_OP_const1s
:
17726 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17730 case DW_OP_const2u
:
17731 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17735 case DW_OP_const2s
:
17736 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17740 case DW_OP_const4u
:
17741 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17745 case DW_OP_const4s
:
17746 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17750 case DW_OP_const8u
:
17751 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17756 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17762 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17767 stack
[stacki
+ 1] = stack
[stacki
];
17772 stack
[stacki
- 1] += stack
[stacki
];
17776 case DW_OP_plus_uconst
:
17777 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17783 stack
[stacki
- 1] -= stack
[stacki
];
17788 /* If we're not the last op, then we definitely can't encode
17789 this using GDB's address_class enum. This is valid for partial
17790 global symbols, although the variable's address will be bogus
17793 dwarf2_complex_location_expr_complaint ();
17796 case DW_OP_GNU_push_tls_address
:
17797 /* The top of the stack has the offset from the beginning
17798 of the thread control block at which the variable is located. */
17799 /* Nothing should follow this operator, so the top of stack would
17801 /* This is valid for partial global symbols, but the variable's
17802 address will be bogus in the psymtab. Make it always at least
17803 non-zero to not look as a variable garbage collected by linker
17804 which have DW_OP_addr 0. */
17806 dwarf2_complex_location_expr_complaint ();
17810 case DW_OP_GNU_uninit
:
17813 case DW_OP_GNU_addr_index
:
17814 case DW_OP_GNU_const_index
:
17815 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17822 const char *name
= get_DW_OP_name (op
);
17825 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17828 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17832 return (stack
[stacki
]);
17835 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17836 outside of the allocated space. Also enforce minimum>0. */
17837 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17839 complaint (&symfile_complaints
,
17840 _("location description stack overflow"));
17846 complaint (&symfile_complaints
,
17847 _("location description stack underflow"));
17851 return (stack
[stacki
]);
17854 /* memory allocation interface */
17856 static struct dwarf_block
*
17857 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17859 struct dwarf_block
*blk
;
17861 blk
= (struct dwarf_block
*)
17862 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17866 static struct die_info
*
17867 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
17869 struct die_info
*die
;
17870 size_t size
= sizeof (struct die_info
);
17873 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
17875 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
17876 memset (die
, 0, sizeof (struct die_info
));
17881 /* Macro support. */
17883 /* Return the full name of file number I in *LH's file name table.
17884 Use COMP_DIR as the name of the current directory of the
17885 compilation. The result is allocated using xmalloc; the caller is
17886 responsible for freeing it. */
17888 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
17890 /* Is the file number a valid index into the line header's file name
17891 table? Remember that file numbers start with one, not zero. */
17892 if (1 <= file
&& file
<= lh
->num_file_names
)
17894 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
17896 if (IS_ABSOLUTE_PATH (fe
->name
))
17897 return xstrdup (fe
->name
);
17905 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
17911 dir_len
= strlen (dir
);
17912 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
17913 strcpy (full_name
, dir
);
17914 full_name
[dir_len
] = '/';
17915 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
17919 return xstrdup (fe
->name
);
17924 /* The compiler produced a bogus file number. We can at least
17925 record the macro definitions made in the file, even if we
17926 won't be able to find the file by name. */
17927 char fake_name
[80];
17929 xsnprintf (fake_name
, sizeof (fake_name
),
17930 "<bad macro file number %d>", file
);
17932 complaint (&symfile_complaints
,
17933 _("bad file number in macro information (%d)"),
17936 return xstrdup (fake_name
);
17941 static struct macro_source_file
*
17942 macro_start_file (int file
, int line
,
17943 struct macro_source_file
*current_file
,
17944 const char *comp_dir
,
17945 struct line_header
*lh
, struct objfile
*objfile
)
17947 /* The full name of this source file. */
17948 char *full_name
= file_full_name (file
, lh
, comp_dir
);
17950 /* We don't create a macro table for this compilation unit
17951 at all until we actually get a filename. */
17952 if (! pending_macros
)
17953 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
17954 objfile
->per_bfd
->macro_cache
);
17956 if (! current_file
)
17958 /* If we have no current file, then this must be the start_file
17959 directive for the compilation unit's main source file. */
17960 current_file
= macro_set_main (pending_macros
, full_name
);
17961 macro_define_special (pending_macros
);
17964 current_file
= macro_include (current_file
, line
, full_name
);
17968 return current_file
;
17972 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17973 followed by a null byte. */
17975 copy_string (const char *buf
, int len
)
17977 char *s
= xmalloc (len
+ 1);
17979 memcpy (s
, buf
, len
);
17985 static const char *
17986 consume_improper_spaces (const char *p
, const char *body
)
17990 complaint (&symfile_complaints
,
17991 _("macro definition contains spaces "
17992 "in formal argument list:\n`%s'"),
18004 parse_macro_definition (struct macro_source_file
*file
, int line
,
18009 /* The body string takes one of two forms. For object-like macro
18010 definitions, it should be:
18012 <macro name> " " <definition>
18014 For function-like macro definitions, it should be:
18016 <macro name> "() " <definition>
18018 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18020 Spaces may appear only where explicitly indicated, and in the
18023 The Dwarf 2 spec says that an object-like macro's name is always
18024 followed by a space, but versions of GCC around March 2002 omit
18025 the space when the macro's definition is the empty string.
18027 The Dwarf 2 spec says that there should be no spaces between the
18028 formal arguments in a function-like macro's formal argument list,
18029 but versions of GCC around March 2002 include spaces after the
18033 /* Find the extent of the macro name. The macro name is terminated
18034 by either a space or null character (for an object-like macro) or
18035 an opening paren (for a function-like macro). */
18036 for (p
= body
; *p
; p
++)
18037 if (*p
== ' ' || *p
== '(')
18040 if (*p
== ' ' || *p
== '\0')
18042 /* It's an object-like macro. */
18043 int name_len
= p
- body
;
18044 char *name
= copy_string (body
, name_len
);
18045 const char *replacement
;
18048 replacement
= body
+ name_len
+ 1;
18051 dwarf2_macro_malformed_definition_complaint (body
);
18052 replacement
= body
+ name_len
;
18055 macro_define_object (file
, line
, name
, replacement
);
18059 else if (*p
== '(')
18061 /* It's a function-like macro. */
18062 char *name
= copy_string (body
, p
- body
);
18065 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18069 p
= consume_improper_spaces (p
, body
);
18071 /* Parse the formal argument list. */
18072 while (*p
&& *p
!= ')')
18074 /* Find the extent of the current argument name. */
18075 const char *arg_start
= p
;
18077 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18080 if (! *p
|| p
== arg_start
)
18081 dwarf2_macro_malformed_definition_complaint (body
);
18084 /* Make sure argv has room for the new argument. */
18085 if (argc
>= argv_size
)
18088 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18091 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18094 p
= consume_improper_spaces (p
, body
);
18096 /* Consume the comma, if present. */
18101 p
= consume_improper_spaces (p
, body
);
18110 /* Perfectly formed definition, no complaints. */
18111 macro_define_function (file
, line
, name
,
18112 argc
, (const char **) argv
,
18114 else if (*p
== '\0')
18116 /* Complain, but do define it. */
18117 dwarf2_macro_malformed_definition_complaint (body
);
18118 macro_define_function (file
, line
, name
,
18119 argc
, (const char **) argv
,
18123 /* Just complain. */
18124 dwarf2_macro_malformed_definition_complaint (body
);
18127 /* Just complain. */
18128 dwarf2_macro_malformed_definition_complaint (body
);
18134 for (i
= 0; i
< argc
; i
++)
18140 dwarf2_macro_malformed_definition_complaint (body
);
18143 /* Skip some bytes from BYTES according to the form given in FORM.
18144 Returns the new pointer. */
18147 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18148 enum dwarf_form form
,
18149 unsigned int offset_size
,
18150 struct dwarf2_section_info
*section
)
18152 unsigned int bytes_read
;
18156 case DW_FORM_data1
:
18161 case DW_FORM_data2
:
18165 case DW_FORM_data4
:
18169 case DW_FORM_data8
:
18173 case DW_FORM_string
:
18174 read_direct_string (abfd
, bytes
, &bytes_read
);
18175 bytes
+= bytes_read
;
18178 case DW_FORM_sec_offset
:
18180 case DW_FORM_GNU_strp_alt
:
18181 bytes
+= offset_size
;
18184 case DW_FORM_block
:
18185 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18186 bytes
+= bytes_read
;
18189 case DW_FORM_block1
:
18190 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18192 case DW_FORM_block2
:
18193 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18195 case DW_FORM_block4
:
18196 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18199 case DW_FORM_sdata
:
18200 case DW_FORM_udata
:
18201 case DW_FORM_GNU_addr_index
:
18202 case DW_FORM_GNU_str_index
:
18203 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18206 dwarf2_section_buffer_overflow_complaint (section
);
18214 complaint (&symfile_complaints
,
18215 _("invalid form 0x%x in `%s'"),
18217 section
->asection
->name
);
18225 /* A helper for dwarf_decode_macros that handles skipping an unknown
18226 opcode. Returns an updated pointer to the macro data buffer; or,
18227 on error, issues a complaint and returns NULL. */
18230 skip_unknown_opcode (unsigned int opcode
,
18231 gdb_byte
**opcode_definitions
,
18232 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18234 unsigned int offset_size
,
18235 struct dwarf2_section_info
*section
)
18237 unsigned int bytes_read
, i
;
18241 if (opcode_definitions
[opcode
] == NULL
)
18243 complaint (&symfile_complaints
,
18244 _("unrecognized DW_MACFINO opcode 0x%x"),
18249 defn
= opcode_definitions
[opcode
];
18250 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18251 defn
+= bytes_read
;
18253 for (i
= 0; i
< arg
; ++i
)
18255 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18257 if (mac_ptr
== NULL
)
18259 /* skip_form_bytes already issued the complaint. */
18267 /* A helper function which parses the header of a macro section.
18268 If the macro section is the extended (for now called "GNU") type,
18269 then this updates *OFFSET_SIZE. Returns a pointer to just after
18270 the header, or issues a complaint and returns NULL on error. */
18273 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18276 unsigned int *offset_size
,
18277 int section_is_gnu
)
18279 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18281 if (section_is_gnu
)
18283 unsigned int version
, flags
;
18285 version
= read_2_bytes (abfd
, mac_ptr
);
18288 complaint (&symfile_complaints
,
18289 _("unrecognized version `%d' in .debug_macro section"),
18295 flags
= read_1_byte (abfd
, mac_ptr
);
18297 *offset_size
= (flags
& 1) ? 8 : 4;
18299 if ((flags
& 2) != 0)
18300 /* We don't need the line table offset. */
18301 mac_ptr
+= *offset_size
;
18303 /* Vendor opcode descriptions. */
18304 if ((flags
& 4) != 0)
18306 unsigned int i
, count
;
18308 count
= read_1_byte (abfd
, mac_ptr
);
18310 for (i
= 0; i
< count
; ++i
)
18312 unsigned int opcode
, bytes_read
;
18315 opcode
= read_1_byte (abfd
, mac_ptr
);
18317 opcode_definitions
[opcode
] = mac_ptr
;
18318 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18319 mac_ptr
+= bytes_read
;
18328 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18329 including DW_MACRO_GNU_transparent_include. */
18332 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18333 struct macro_source_file
*current_file
,
18334 struct line_header
*lh
, char *comp_dir
,
18335 struct dwarf2_section_info
*section
,
18336 int section_is_gnu
, int section_is_dwz
,
18337 unsigned int offset_size
,
18338 struct objfile
*objfile
,
18339 htab_t include_hash
)
18341 enum dwarf_macro_record_type macinfo_type
;
18342 int at_commandline
;
18343 gdb_byte
*opcode_definitions
[256];
18345 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18346 &offset_size
, section_is_gnu
);
18347 if (mac_ptr
== NULL
)
18349 /* We already issued a complaint. */
18353 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18354 GDB is still reading the definitions from command line. First
18355 DW_MACINFO_start_file will need to be ignored as it was already executed
18356 to create CURRENT_FILE for the main source holding also the command line
18357 definitions. On first met DW_MACINFO_start_file this flag is reset to
18358 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18360 at_commandline
= 1;
18364 /* Do we at least have room for a macinfo type byte? */
18365 if (mac_ptr
>= mac_end
)
18367 dwarf2_section_buffer_overflow_complaint (section
);
18371 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18374 /* Note that we rely on the fact that the corresponding GNU and
18375 DWARF constants are the same. */
18376 switch (macinfo_type
)
18378 /* A zero macinfo type indicates the end of the macro
18383 case DW_MACRO_GNU_define
:
18384 case DW_MACRO_GNU_undef
:
18385 case DW_MACRO_GNU_define_indirect
:
18386 case DW_MACRO_GNU_undef_indirect
:
18387 case DW_MACRO_GNU_define_indirect_alt
:
18388 case DW_MACRO_GNU_undef_indirect_alt
:
18390 unsigned int bytes_read
;
18395 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18396 mac_ptr
+= bytes_read
;
18398 if (macinfo_type
== DW_MACRO_GNU_define
18399 || macinfo_type
== DW_MACRO_GNU_undef
)
18401 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18402 mac_ptr
+= bytes_read
;
18406 LONGEST str_offset
;
18408 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18409 mac_ptr
+= offset_size
;
18411 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18412 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18415 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18417 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18420 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18423 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18424 || macinfo_type
== DW_MACRO_GNU_define_indirect
18425 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18426 if (! current_file
)
18428 /* DWARF violation as no main source is present. */
18429 complaint (&symfile_complaints
,
18430 _("debug info with no main source gives macro %s "
18432 is_define
? _("definition") : _("undefinition"),
18436 if ((line
== 0 && !at_commandline
)
18437 || (line
!= 0 && at_commandline
))
18438 complaint (&symfile_complaints
,
18439 _("debug info gives %s macro %s with %s line %d: %s"),
18440 at_commandline
? _("command-line") : _("in-file"),
18441 is_define
? _("definition") : _("undefinition"),
18442 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18445 parse_macro_definition (current_file
, line
, body
);
18448 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18449 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18450 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18451 macro_undef (current_file
, line
, body
);
18456 case DW_MACRO_GNU_start_file
:
18458 unsigned int bytes_read
;
18461 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18462 mac_ptr
+= bytes_read
;
18463 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18464 mac_ptr
+= bytes_read
;
18466 if ((line
== 0 && !at_commandline
)
18467 || (line
!= 0 && at_commandline
))
18468 complaint (&symfile_complaints
,
18469 _("debug info gives source %d included "
18470 "from %s at %s line %d"),
18471 file
, at_commandline
? _("command-line") : _("file"),
18472 line
== 0 ? _("zero") : _("non-zero"), line
);
18474 if (at_commandline
)
18476 /* This DW_MACRO_GNU_start_file was executed in the
18478 at_commandline
= 0;
18481 current_file
= macro_start_file (file
, line
,
18482 current_file
, comp_dir
,
18487 case DW_MACRO_GNU_end_file
:
18488 if (! current_file
)
18489 complaint (&symfile_complaints
,
18490 _("macro debug info has an unmatched "
18491 "`close_file' directive"));
18494 current_file
= current_file
->included_by
;
18495 if (! current_file
)
18497 enum dwarf_macro_record_type next_type
;
18499 /* GCC circa March 2002 doesn't produce the zero
18500 type byte marking the end of the compilation
18501 unit. Complain if it's not there, but exit no
18504 /* Do we at least have room for a macinfo type byte? */
18505 if (mac_ptr
>= mac_end
)
18507 dwarf2_section_buffer_overflow_complaint (section
);
18511 /* We don't increment mac_ptr here, so this is just
18513 next_type
= read_1_byte (abfd
, mac_ptr
);
18514 if (next_type
!= 0)
18515 complaint (&symfile_complaints
,
18516 _("no terminating 0-type entry for "
18517 "macros in `.debug_macinfo' section"));
18524 case DW_MACRO_GNU_transparent_include
:
18525 case DW_MACRO_GNU_transparent_include_alt
:
18529 bfd
*include_bfd
= abfd
;
18530 struct dwarf2_section_info
*include_section
= section
;
18531 struct dwarf2_section_info alt_section
;
18532 gdb_byte
*include_mac_end
= mac_end
;
18533 int is_dwz
= section_is_dwz
;
18534 gdb_byte
*new_mac_ptr
;
18536 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18537 mac_ptr
+= offset_size
;
18539 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18541 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18543 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18546 include_bfd
= dwz
->macro
.asection
->owner
;
18547 include_section
= &dwz
->macro
;
18548 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18552 new_mac_ptr
= include_section
->buffer
+ offset
;
18553 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18557 /* This has actually happened; see
18558 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18559 complaint (&symfile_complaints
,
18560 _("recursive DW_MACRO_GNU_transparent_include in "
18561 ".debug_macro section"));
18565 *slot
= new_mac_ptr
;
18567 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18568 include_mac_end
, current_file
,
18570 section
, section_is_gnu
, is_dwz
,
18571 offset_size
, objfile
, include_hash
);
18573 htab_remove_elt (include_hash
, new_mac_ptr
);
18578 case DW_MACINFO_vendor_ext
:
18579 if (!section_is_gnu
)
18581 unsigned int bytes_read
;
18584 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18585 mac_ptr
+= bytes_read
;
18586 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18587 mac_ptr
+= bytes_read
;
18589 /* We don't recognize any vendor extensions. */
18595 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18596 mac_ptr
, mac_end
, abfd
, offset_size
,
18598 if (mac_ptr
== NULL
)
18602 } while (macinfo_type
!= 0);
18606 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18607 char *comp_dir
, int section_is_gnu
)
18609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18610 struct line_header
*lh
= cu
->line_header
;
18612 gdb_byte
*mac_ptr
, *mac_end
;
18613 struct macro_source_file
*current_file
= 0;
18614 enum dwarf_macro_record_type macinfo_type
;
18615 unsigned int offset_size
= cu
->header
.offset_size
;
18616 gdb_byte
*opcode_definitions
[256];
18617 struct cleanup
*cleanup
;
18618 htab_t include_hash
;
18620 struct dwarf2_section_info
*section
;
18621 const char *section_name
;
18623 if (cu
->dwo_unit
!= NULL
)
18625 if (section_is_gnu
)
18627 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18628 section_name
= ".debug_macro.dwo";
18632 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18633 section_name
= ".debug_macinfo.dwo";
18638 if (section_is_gnu
)
18640 section
= &dwarf2_per_objfile
->macro
;
18641 section_name
= ".debug_macro";
18645 section
= &dwarf2_per_objfile
->macinfo
;
18646 section_name
= ".debug_macinfo";
18650 dwarf2_read_section (objfile
, section
);
18651 if (section
->buffer
== NULL
)
18653 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18656 abfd
= section
->asection
->owner
;
18658 /* First pass: Find the name of the base filename.
18659 This filename is needed in order to process all macros whose definition
18660 (or undefinition) comes from the command line. These macros are defined
18661 before the first DW_MACINFO_start_file entry, and yet still need to be
18662 associated to the base file.
18664 To determine the base file name, we scan the macro definitions until we
18665 reach the first DW_MACINFO_start_file entry. We then initialize
18666 CURRENT_FILE accordingly so that any macro definition found before the
18667 first DW_MACINFO_start_file can still be associated to the base file. */
18669 mac_ptr
= section
->buffer
+ offset
;
18670 mac_end
= section
->buffer
+ section
->size
;
18672 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18673 &offset_size
, section_is_gnu
);
18674 if (mac_ptr
== NULL
)
18676 /* We already issued a complaint. */
18682 /* Do we at least have room for a macinfo type byte? */
18683 if (mac_ptr
>= mac_end
)
18685 /* Complaint is printed during the second pass as GDB will probably
18686 stop the first pass earlier upon finding
18687 DW_MACINFO_start_file. */
18691 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18694 /* Note that we rely on the fact that the corresponding GNU and
18695 DWARF constants are the same. */
18696 switch (macinfo_type
)
18698 /* A zero macinfo type indicates the end of the macro
18703 case DW_MACRO_GNU_define
:
18704 case DW_MACRO_GNU_undef
:
18705 /* Only skip the data by MAC_PTR. */
18707 unsigned int bytes_read
;
18709 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18710 mac_ptr
+= bytes_read
;
18711 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18712 mac_ptr
+= bytes_read
;
18716 case DW_MACRO_GNU_start_file
:
18718 unsigned int bytes_read
;
18721 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18722 mac_ptr
+= bytes_read
;
18723 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18724 mac_ptr
+= bytes_read
;
18726 current_file
= macro_start_file (file
, line
, current_file
,
18727 comp_dir
, lh
, objfile
);
18731 case DW_MACRO_GNU_end_file
:
18732 /* No data to skip by MAC_PTR. */
18735 case DW_MACRO_GNU_define_indirect
:
18736 case DW_MACRO_GNU_undef_indirect
:
18737 case DW_MACRO_GNU_define_indirect_alt
:
18738 case DW_MACRO_GNU_undef_indirect_alt
:
18740 unsigned int bytes_read
;
18742 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18743 mac_ptr
+= bytes_read
;
18744 mac_ptr
+= offset_size
;
18748 case DW_MACRO_GNU_transparent_include
:
18749 case DW_MACRO_GNU_transparent_include_alt
:
18750 /* Note that, according to the spec, a transparent include
18751 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18752 skip this opcode. */
18753 mac_ptr
+= offset_size
;
18756 case DW_MACINFO_vendor_ext
:
18757 /* Only skip the data by MAC_PTR. */
18758 if (!section_is_gnu
)
18760 unsigned int bytes_read
;
18762 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18763 mac_ptr
+= bytes_read
;
18764 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18765 mac_ptr
+= bytes_read
;
18770 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18771 mac_ptr
, mac_end
, abfd
, offset_size
,
18773 if (mac_ptr
== NULL
)
18777 } while (macinfo_type
!= 0 && current_file
== NULL
);
18779 /* Second pass: Process all entries.
18781 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18782 command-line macro definitions/undefinitions. This flag is unset when we
18783 reach the first DW_MACINFO_start_file entry. */
18785 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18786 NULL
, xcalloc
, xfree
);
18787 cleanup
= make_cleanup_htab_delete (include_hash
);
18788 mac_ptr
= section
->buffer
+ offset
;
18789 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18791 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18792 current_file
, lh
, comp_dir
, section
,
18794 offset_size
, objfile
, include_hash
);
18795 do_cleanups (cleanup
);
18798 /* Check if the attribute's form is a DW_FORM_block*
18799 if so return true else false. */
18802 attr_form_is_block (struct attribute
*attr
)
18804 return (attr
== NULL
? 0 :
18805 attr
->form
== DW_FORM_block1
18806 || attr
->form
== DW_FORM_block2
18807 || attr
->form
== DW_FORM_block4
18808 || attr
->form
== DW_FORM_block
18809 || attr
->form
== DW_FORM_exprloc
);
18812 /* Return non-zero if ATTR's value is a section offset --- classes
18813 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18814 You may use DW_UNSND (attr) to retrieve such offsets.
18816 Section 7.5.4, "Attribute Encodings", explains that no attribute
18817 may have a value that belongs to more than one of these classes; it
18818 would be ambiguous if we did, because we use the same forms for all
18822 attr_form_is_section_offset (struct attribute
*attr
)
18824 return (attr
->form
== DW_FORM_data4
18825 || attr
->form
== DW_FORM_data8
18826 || attr
->form
== DW_FORM_sec_offset
);
18829 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18830 zero otherwise. When this function returns true, you can apply
18831 dwarf2_get_attr_constant_value to it.
18833 However, note that for some attributes you must check
18834 attr_form_is_section_offset before using this test. DW_FORM_data4
18835 and DW_FORM_data8 are members of both the constant class, and of
18836 the classes that contain offsets into other debug sections
18837 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18838 that, if an attribute's can be either a constant or one of the
18839 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18840 taken as section offsets, not constants. */
18843 attr_form_is_constant (struct attribute
*attr
)
18845 switch (attr
->form
)
18847 case DW_FORM_sdata
:
18848 case DW_FORM_udata
:
18849 case DW_FORM_data1
:
18850 case DW_FORM_data2
:
18851 case DW_FORM_data4
:
18852 case DW_FORM_data8
:
18859 /* Return the .debug_loc section to use for CU.
18860 For DWO files use .debug_loc.dwo. */
18862 static struct dwarf2_section_info
*
18863 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18866 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
18867 return &dwarf2_per_objfile
->loc
;
18870 /* A helper function that fills in a dwarf2_loclist_baton. */
18873 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
18874 struct dwarf2_loclist_baton
*baton
,
18875 struct attribute
*attr
)
18877 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18879 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
18881 baton
->per_cu
= cu
->per_cu
;
18882 gdb_assert (baton
->per_cu
);
18883 /* We don't know how long the location list is, but make sure we
18884 don't run off the edge of the section. */
18885 baton
->size
= section
->size
- DW_UNSND (attr
);
18886 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
18887 baton
->base_address
= cu
->base_address
;
18888 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
18892 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
18893 struct dwarf2_cu
*cu
)
18895 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18896 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18898 if (attr_form_is_section_offset (attr
)
18899 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18900 the section. If so, fall through to the complaint in the
18902 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
18904 struct dwarf2_loclist_baton
*baton
;
18906 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18907 sizeof (struct dwarf2_loclist_baton
));
18909 fill_in_loclist_baton (cu
, baton
, attr
);
18911 if (cu
->base_known
== 0)
18912 complaint (&symfile_complaints
,
18913 _("Location list used without "
18914 "specifying the CU base address."));
18916 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
18917 SYMBOL_LOCATION_BATON (sym
) = baton
;
18921 struct dwarf2_locexpr_baton
*baton
;
18923 baton
= obstack_alloc (&objfile
->objfile_obstack
,
18924 sizeof (struct dwarf2_locexpr_baton
));
18925 baton
->per_cu
= cu
->per_cu
;
18926 gdb_assert (baton
->per_cu
);
18928 if (attr_form_is_block (attr
))
18930 /* Note that we're just copying the block's data pointer
18931 here, not the actual data. We're still pointing into the
18932 info_buffer for SYM's objfile; right now we never release
18933 that buffer, but when we do clean up properly this may
18935 baton
->size
= DW_BLOCK (attr
)->size
;
18936 baton
->data
= DW_BLOCK (attr
)->data
;
18940 dwarf2_invalid_attrib_class_complaint ("location description",
18941 SYMBOL_NATURAL_NAME (sym
));
18945 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
18946 SYMBOL_LOCATION_BATON (sym
) = baton
;
18950 /* Return the OBJFILE associated with the compilation unit CU. If CU
18951 came from a separate debuginfo file, then the master objfile is
18955 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
18957 struct objfile
*objfile
= per_cu
->objfile
;
18959 /* Return the master objfile, so that we can report and look up the
18960 correct file containing this variable. */
18961 if (objfile
->separate_debug_objfile_backlink
)
18962 objfile
= objfile
->separate_debug_objfile_backlink
;
18967 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18968 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18969 CU_HEADERP first. */
18971 static const struct comp_unit_head
*
18972 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
18973 struct dwarf2_per_cu_data
*per_cu
)
18975 gdb_byte
*info_ptr
;
18978 return &per_cu
->cu
->header
;
18980 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
18982 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
18983 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
18988 /* Return the address size given in the compilation unit header for CU. */
18991 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
18993 struct comp_unit_head cu_header_local
;
18994 const struct comp_unit_head
*cu_headerp
;
18996 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
18998 return cu_headerp
->addr_size
;
19001 /* Return the offset size given in the compilation unit header for CU. */
19004 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
19006 struct comp_unit_head cu_header_local
;
19007 const struct comp_unit_head
*cu_headerp
;
19009 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19011 return cu_headerp
->offset_size
;
19014 /* See its dwarf2loc.h declaration. */
19017 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19019 struct comp_unit_head cu_header_local
;
19020 const struct comp_unit_head
*cu_headerp
;
19022 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19024 if (cu_headerp
->version
== 2)
19025 return cu_headerp
->addr_size
;
19027 return cu_headerp
->offset_size
;
19030 /* Return the text offset of the CU. The returned offset comes from
19031 this CU's objfile. If this objfile came from a separate debuginfo
19032 file, then the offset may be different from the corresponding
19033 offset in the parent objfile. */
19036 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19038 struct objfile
*objfile
= per_cu
->objfile
;
19040 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19043 /* Locate the .debug_info compilation unit from CU's objfile which contains
19044 the DIE at OFFSET. Raises an error on failure. */
19046 static struct dwarf2_per_cu_data
*
19047 dwarf2_find_containing_comp_unit (sect_offset offset
,
19048 unsigned int offset_in_dwz
,
19049 struct objfile
*objfile
)
19051 struct dwarf2_per_cu_data
*this_cu
;
19053 const sect_offset
*cu_off
;
19056 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19059 struct dwarf2_per_cu_data
*mid_cu
;
19060 int mid
= low
+ (high
- low
) / 2;
19062 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19063 cu_off
= &mid_cu
->offset
;
19064 if (mid_cu
->is_dwz
> offset_in_dwz
19065 || (mid_cu
->is_dwz
== offset_in_dwz
19066 && cu_off
->sect_off
>= offset
.sect_off
))
19071 gdb_assert (low
== high
);
19072 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19073 cu_off
= &this_cu
->offset
;
19074 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19076 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19077 error (_("Dwarf Error: could not find partial DIE containing "
19078 "offset 0x%lx [in module %s]"),
19079 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19081 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19082 <= offset
.sect_off
);
19083 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19087 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19088 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19089 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19090 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19091 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19096 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19099 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19101 memset (cu
, 0, sizeof (*cu
));
19103 cu
->per_cu
= per_cu
;
19104 cu
->objfile
= per_cu
->objfile
;
19105 obstack_init (&cu
->comp_unit_obstack
);
19108 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19111 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19112 enum language pretend_language
)
19114 struct attribute
*attr
;
19116 /* Set the language we're debugging. */
19117 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19119 set_cu_language (DW_UNSND (attr
), cu
);
19122 cu
->language
= pretend_language
;
19123 cu
->language_defn
= language_def (cu
->language
);
19126 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19128 cu
->producer
= DW_STRING (attr
);
19131 /* Release one cached compilation unit, CU. We unlink it from the tree
19132 of compilation units, but we don't remove it from the read_in_chain;
19133 the caller is responsible for that.
19134 NOTE: DATA is a void * because this function is also used as a
19135 cleanup routine. */
19138 free_heap_comp_unit (void *data
)
19140 struct dwarf2_cu
*cu
= data
;
19142 gdb_assert (cu
->per_cu
!= NULL
);
19143 cu
->per_cu
->cu
= NULL
;
19146 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19151 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19152 when we're finished with it. We can't free the pointer itself, but be
19153 sure to unlink it from the cache. Also release any associated storage. */
19156 free_stack_comp_unit (void *data
)
19158 struct dwarf2_cu
*cu
= data
;
19160 gdb_assert (cu
->per_cu
!= NULL
);
19161 cu
->per_cu
->cu
= NULL
;
19164 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19165 cu
->partial_dies
= NULL
;
19168 /* Free all cached compilation units. */
19171 free_cached_comp_units (void *data
)
19173 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19175 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19176 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19177 while (per_cu
!= NULL
)
19179 struct dwarf2_per_cu_data
*next_cu
;
19181 next_cu
= per_cu
->cu
->read_in_chain
;
19183 free_heap_comp_unit (per_cu
->cu
);
19184 *last_chain
= next_cu
;
19190 /* Increase the age counter on each cached compilation unit, and free
19191 any that are too old. */
19194 age_cached_comp_units (void)
19196 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19198 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19199 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19200 while (per_cu
!= NULL
)
19202 per_cu
->cu
->last_used
++;
19203 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19204 dwarf2_mark (per_cu
->cu
);
19205 per_cu
= per_cu
->cu
->read_in_chain
;
19208 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19209 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19210 while (per_cu
!= NULL
)
19212 struct dwarf2_per_cu_data
*next_cu
;
19214 next_cu
= per_cu
->cu
->read_in_chain
;
19216 if (!per_cu
->cu
->mark
)
19218 free_heap_comp_unit (per_cu
->cu
);
19219 *last_chain
= next_cu
;
19222 last_chain
= &per_cu
->cu
->read_in_chain
;
19228 /* Remove a single compilation unit from the cache. */
19231 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19233 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19235 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19236 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19237 while (per_cu
!= NULL
)
19239 struct dwarf2_per_cu_data
*next_cu
;
19241 next_cu
= per_cu
->cu
->read_in_chain
;
19243 if (per_cu
== target_per_cu
)
19245 free_heap_comp_unit (per_cu
->cu
);
19247 *last_chain
= next_cu
;
19251 last_chain
= &per_cu
->cu
->read_in_chain
;
19257 /* Release all extra memory associated with OBJFILE. */
19260 dwarf2_free_objfile (struct objfile
*objfile
)
19262 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19264 if (dwarf2_per_objfile
== NULL
)
19267 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19268 free_cached_comp_units (NULL
);
19270 if (dwarf2_per_objfile
->quick_file_names_table
)
19271 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19273 /* Everything else should be on the objfile obstack. */
19276 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19277 We store these in a hash table separate from the DIEs, and preserve them
19278 when the DIEs are flushed out of cache.
19280 The CU "per_cu" pointer is needed because offset alone is not enough to
19281 uniquely identify the type. A file may have multiple .debug_types sections,
19282 or the type may come from a DWO file. We have to use something in
19283 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19284 routine, get_die_type_at_offset, from outside this file, and thus won't
19285 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19288 struct dwarf2_per_cu_offset_and_type
19290 const struct dwarf2_per_cu_data
*per_cu
;
19291 sect_offset offset
;
19295 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19298 per_cu_offset_and_type_hash (const void *item
)
19300 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19302 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19305 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19308 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19310 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19311 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19313 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19314 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19317 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19318 table if necessary. For convenience, return TYPE.
19320 The DIEs reading must have careful ordering to:
19321 * Not cause infite loops trying to read in DIEs as a prerequisite for
19322 reading current DIE.
19323 * Not trying to dereference contents of still incompletely read in types
19324 while reading in other DIEs.
19325 * Enable referencing still incompletely read in types just by a pointer to
19326 the type without accessing its fields.
19328 Therefore caller should follow these rules:
19329 * Try to fetch any prerequisite types we may need to build this DIE type
19330 before building the type and calling set_die_type.
19331 * After building type call set_die_type for current DIE as soon as
19332 possible before fetching more types to complete the current type.
19333 * Make the type as complete as possible before fetching more types. */
19335 static struct type
*
19336 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19338 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19339 struct objfile
*objfile
= cu
->objfile
;
19341 /* For Ada types, make sure that the gnat-specific data is always
19342 initialized (if not already set). There are a few types where
19343 we should not be doing so, because the type-specific area is
19344 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19345 where the type-specific area is used to store the floatformat).
19346 But this is not a problem, because the gnat-specific information
19347 is actually not needed for these types. */
19348 if (need_gnat_info (cu
)
19349 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19350 && TYPE_CODE (type
) != TYPE_CODE_FLT
19351 && !HAVE_GNAT_AUX_INFO (type
))
19352 INIT_GNAT_SPECIFIC (type
);
19354 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19356 dwarf2_per_objfile
->die_type_hash
=
19357 htab_create_alloc_ex (127,
19358 per_cu_offset_and_type_hash
,
19359 per_cu_offset_and_type_eq
,
19361 &objfile
->objfile_obstack
,
19362 hashtab_obstack_allocate
,
19363 dummy_obstack_deallocate
);
19366 ofs
.per_cu
= cu
->per_cu
;
19367 ofs
.offset
= die
->offset
;
19369 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19370 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19372 complaint (&symfile_complaints
,
19373 _("A problem internal to GDB: DIE 0x%x has type already set"),
19374 die
->offset
.sect_off
);
19375 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19380 /* Look up the type for the die at OFFSET in the appropriate type_hash
19381 table, or return NULL if the die does not have a saved type. */
19383 static struct type
*
19384 get_die_type_at_offset (sect_offset offset
,
19385 struct dwarf2_per_cu_data
*per_cu
)
19387 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19389 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19392 ofs
.per_cu
= per_cu
;
19393 ofs
.offset
= offset
;
19394 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19401 /* Look up the type for DIE in the appropriate type_hash table,
19402 or return NULL if DIE does not have a saved type. */
19404 static struct type
*
19405 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19407 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19410 /* Add a dependence relationship from CU to REF_PER_CU. */
19413 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19414 struct dwarf2_per_cu_data
*ref_per_cu
)
19418 if (cu
->dependencies
== NULL
)
19420 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19421 NULL
, &cu
->comp_unit_obstack
,
19422 hashtab_obstack_allocate
,
19423 dummy_obstack_deallocate
);
19425 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19427 *slot
= ref_per_cu
;
19430 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19431 Set the mark field in every compilation unit in the
19432 cache that we must keep because we are keeping CU. */
19435 dwarf2_mark_helper (void **slot
, void *data
)
19437 struct dwarf2_per_cu_data
*per_cu
;
19439 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19441 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19442 reading of the chain. As such dependencies remain valid it is not much
19443 useful to track and undo them during QUIT cleanups. */
19444 if (per_cu
->cu
== NULL
)
19447 if (per_cu
->cu
->mark
)
19449 per_cu
->cu
->mark
= 1;
19451 if (per_cu
->cu
->dependencies
!= NULL
)
19452 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19457 /* Set the mark field in CU and in every other compilation unit in the
19458 cache that we must keep because we are keeping CU. */
19461 dwarf2_mark (struct dwarf2_cu
*cu
)
19466 if (cu
->dependencies
!= NULL
)
19467 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19471 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19475 per_cu
->cu
->mark
= 0;
19476 per_cu
= per_cu
->cu
->read_in_chain
;
19480 /* Trivial hash function for partial_die_info: the hash value of a DIE
19481 is its offset in .debug_info for this objfile. */
19484 partial_die_hash (const void *item
)
19486 const struct partial_die_info
*part_die
= item
;
19488 return part_die
->offset
.sect_off
;
19491 /* Trivial comparison function for partial_die_info structures: two DIEs
19492 are equal if they have the same offset. */
19495 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19497 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19498 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19500 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19503 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19504 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19507 set_dwarf2_cmd (char *args
, int from_tty
)
19509 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19513 show_dwarf2_cmd (char *args
, int from_tty
)
19515 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19518 /* Free data associated with OBJFILE, if necessary. */
19521 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19523 struct dwarf2_per_objfile
*data
= d
;
19526 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19527 VEC_free (dwarf2_per_cu_ptr
,
19528 dwarf2_per_objfile
->all_comp_units
[ix
]->s
.imported_symtabs
);
19530 VEC_free (dwarf2_section_info_def
, data
->types
);
19532 if (data
->dwo_files
)
19533 free_dwo_files (data
->dwo_files
, objfile
);
19535 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19536 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19540 /* The "save gdb-index" command. */
19542 /* The contents of the hash table we create when building the string
19544 struct strtab_entry
19546 offset_type offset
;
19550 /* Hash function for a strtab_entry.
19552 Function is used only during write_hash_table so no index format backward
19553 compatibility is needed. */
19556 hash_strtab_entry (const void *e
)
19558 const struct strtab_entry
*entry
= e
;
19559 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19562 /* Equality function for a strtab_entry. */
19565 eq_strtab_entry (const void *a
, const void *b
)
19567 const struct strtab_entry
*ea
= a
;
19568 const struct strtab_entry
*eb
= b
;
19569 return !strcmp (ea
->str
, eb
->str
);
19572 /* Create a strtab_entry hash table. */
19575 create_strtab (void)
19577 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19578 xfree
, xcalloc
, xfree
);
19581 /* Add a string to the constant pool. Return the string's offset in
19585 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19588 struct strtab_entry entry
;
19589 struct strtab_entry
*result
;
19592 slot
= htab_find_slot (table
, &entry
, INSERT
);
19597 result
= XNEW (struct strtab_entry
);
19598 result
->offset
= obstack_object_size (cpool
);
19600 obstack_grow_str0 (cpool
, str
);
19603 return result
->offset
;
19606 /* An entry in the symbol table. */
19607 struct symtab_index_entry
19609 /* The name of the symbol. */
19611 /* The offset of the name in the constant pool. */
19612 offset_type index_offset
;
19613 /* A sorted vector of the indices of all the CUs that hold an object
19615 VEC (offset_type
) *cu_indices
;
19618 /* The symbol table. This is a power-of-2-sized hash table. */
19619 struct mapped_symtab
19621 offset_type n_elements
;
19623 struct symtab_index_entry
**data
;
19626 /* Hash function for a symtab_index_entry. */
19629 hash_symtab_entry (const void *e
)
19631 const struct symtab_index_entry
*entry
= e
;
19632 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19633 sizeof (offset_type
) * VEC_length (offset_type
,
19634 entry
->cu_indices
),
19638 /* Equality function for a symtab_index_entry. */
19641 eq_symtab_entry (const void *a
, const void *b
)
19643 const struct symtab_index_entry
*ea
= a
;
19644 const struct symtab_index_entry
*eb
= b
;
19645 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19646 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19648 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19649 VEC_address (offset_type
, eb
->cu_indices
),
19650 sizeof (offset_type
) * len
);
19653 /* Destroy a symtab_index_entry. */
19656 delete_symtab_entry (void *p
)
19658 struct symtab_index_entry
*entry
= p
;
19659 VEC_free (offset_type
, entry
->cu_indices
);
19663 /* Create a hash table holding symtab_index_entry objects. */
19666 create_symbol_hash_table (void)
19668 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19669 delete_symtab_entry
, xcalloc
, xfree
);
19672 /* Create a new mapped symtab object. */
19674 static struct mapped_symtab
*
19675 create_mapped_symtab (void)
19677 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19678 symtab
->n_elements
= 0;
19679 symtab
->size
= 1024;
19680 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19684 /* Destroy a mapped_symtab. */
19687 cleanup_mapped_symtab (void *p
)
19689 struct mapped_symtab
*symtab
= p
;
19690 /* The contents of the array are freed when the other hash table is
19692 xfree (symtab
->data
);
19696 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19699 Function is used only during write_hash_table so no index format backward
19700 compatibility is needed. */
19702 static struct symtab_index_entry
**
19703 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19705 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19707 index
= hash
& (symtab
->size
- 1);
19708 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19712 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19713 return &symtab
->data
[index
];
19714 index
= (index
+ step
) & (symtab
->size
- 1);
19718 /* Expand SYMTAB's hash table. */
19721 hash_expand (struct mapped_symtab
*symtab
)
19723 offset_type old_size
= symtab
->size
;
19725 struct symtab_index_entry
**old_entries
= symtab
->data
;
19728 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19730 for (i
= 0; i
< old_size
; ++i
)
19732 if (old_entries
[i
])
19734 struct symtab_index_entry
**slot
= find_slot (symtab
,
19735 old_entries
[i
]->name
);
19736 *slot
= old_entries
[i
];
19740 xfree (old_entries
);
19743 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19744 CU_INDEX is the index of the CU in which the symbol appears.
19745 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19748 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19749 int is_static
, gdb_index_symbol_kind kind
,
19750 offset_type cu_index
)
19752 struct symtab_index_entry
**slot
;
19753 offset_type cu_index_and_attrs
;
19755 ++symtab
->n_elements
;
19756 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19757 hash_expand (symtab
);
19759 slot
= find_slot (symtab
, name
);
19762 *slot
= XNEW (struct symtab_index_entry
);
19763 (*slot
)->name
= name
;
19764 /* index_offset is set later. */
19765 (*slot
)->cu_indices
= NULL
;
19768 cu_index_and_attrs
= 0;
19769 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19770 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19771 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19773 /* We don't want to record an index value twice as we want to avoid the
19775 We process all global symbols and then all static symbols
19776 (which would allow us to avoid the duplication by only having to check
19777 the last entry pushed), but a symbol could have multiple kinds in one CU.
19778 To keep things simple we don't worry about the duplication here and
19779 sort and uniqufy the list after we've processed all symbols. */
19780 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19783 /* qsort helper routine for uniquify_cu_indices. */
19786 offset_type_compare (const void *ap
, const void *bp
)
19788 offset_type a
= *(offset_type
*) ap
;
19789 offset_type b
= *(offset_type
*) bp
;
19791 return (a
> b
) - (b
> a
);
19794 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19797 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19801 for (i
= 0; i
< symtab
->size
; ++i
)
19803 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19806 && entry
->cu_indices
!= NULL
)
19808 unsigned int next_to_insert
, next_to_check
;
19809 offset_type last_value
;
19811 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19812 VEC_length (offset_type
, entry
->cu_indices
),
19813 sizeof (offset_type
), offset_type_compare
);
19815 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19816 next_to_insert
= 1;
19817 for (next_to_check
= 1;
19818 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19821 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19824 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19826 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19831 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19836 /* Add a vector of indices to the constant pool. */
19839 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19840 struct symtab_index_entry
*entry
)
19844 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19847 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19848 offset_type val
= MAYBE_SWAP (len
);
19853 entry
->index_offset
= obstack_object_size (cpool
);
19855 obstack_grow (cpool
, &val
, sizeof (val
));
19857 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19860 val
= MAYBE_SWAP (iter
);
19861 obstack_grow (cpool
, &val
, sizeof (val
));
19866 struct symtab_index_entry
*old_entry
= *slot
;
19867 entry
->index_offset
= old_entry
->index_offset
;
19870 return entry
->index_offset
;
19873 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19874 constant pool entries going into the obstack CPOOL. */
19877 write_hash_table (struct mapped_symtab
*symtab
,
19878 struct obstack
*output
, struct obstack
*cpool
)
19881 htab_t symbol_hash_table
;
19884 symbol_hash_table
= create_symbol_hash_table ();
19885 str_table
= create_strtab ();
19887 /* We add all the index vectors to the constant pool first, to
19888 ensure alignment is ok. */
19889 for (i
= 0; i
< symtab
->size
; ++i
)
19891 if (symtab
->data
[i
])
19892 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
19895 /* Now write out the hash table. */
19896 for (i
= 0; i
< symtab
->size
; ++i
)
19898 offset_type str_off
, vec_off
;
19900 if (symtab
->data
[i
])
19902 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
19903 vec_off
= symtab
->data
[i
]->index_offset
;
19907 /* While 0 is a valid constant pool index, it is not valid
19908 to have 0 for both offsets. */
19913 str_off
= MAYBE_SWAP (str_off
);
19914 vec_off
= MAYBE_SWAP (vec_off
);
19916 obstack_grow (output
, &str_off
, sizeof (str_off
));
19917 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
19920 htab_delete (str_table
);
19921 htab_delete (symbol_hash_table
);
19924 /* Struct to map psymtab to CU index in the index file. */
19925 struct psymtab_cu_index_map
19927 struct partial_symtab
*psymtab
;
19928 unsigned int cu_index
;
19932 hash_psymtab_cu_index (const void *item
)
19934 const struct psymtab_cu_index_map
*map
= item
;
19936 return htab_hash_pointer (map
->psymtab
);
19940 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
19942 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
19943 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
19945 return lhs
->psymtab
== rhs
->psymtab
;
19948 /* Helper struct for building the address table. */
19949 struct addrmap_index_data
19951 struct objfile
*objfile
;
19952 struct obstack
*addr_obstack
;
19953 htab_t cu_index_htab
;
19955 /* Non-zero if the previous_* fields are valid.
19956 We can't write an entry until we see the next entry (since it is only then
19957 that we know the end of the entry). */
19958 int previous_valid
;
19959 /* Index of the CU in the table of all CUs in the index file. */
19960 unsigned int previous_cu_index
;
19961 /* Start address of the CU. */
19962 CORE_ADDR previous_cu_start
;
19965 /* Write an address entry to OBSTACK. */
19968 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
19969 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
19971 offset_type cu_index_to_write
;
19973 CORE_ADDR baseaddr
;
19975 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19977 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
19978 obstack_grow (obstack
, addr
, 8);
19979 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
19980 obstack_grow (obstack
, addr
, 8);
19981 cu_index_to_write
= MAYBE_SWAP (cu_index
);
19982 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
19985 /* Worker function for traversing an addrmap to build the address table. */
19988 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
19990 struct addrmap_index_data
*data
= datap
;
19991 struct partial_symtab
*pst
= obj
;
19993 if (data
->previous_valid
)
19994 add_address_entry (data
->objfile
, data
->addr_obstack
,
19995 data
->previous_cu_start
, start_addr
,
19996 data
->previous_cu_index
);
19998 data
->previous_cu_start
= start_addr
;
20001 struct psymtab_cu_index_map find_map
, *map
;
20002 find_map
.psymtab
= pst
;
20003 map
= htab_find (data
->cu_index_htab
, &find_map
);
20004 gdb_assert (map
!= NULL
);
20005 data
->previous_cu_index
= map
->cu_index
;
20006 data
->previous_valid
= 1;
20009 data
->previous_valid
= 0;
20014 /* Write OBJFILE's address map to OBSTACK.
20015 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20016 in the index file. */
20019 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20020 htab_t cu_index_htab
)
20022 struct addrmap_index_data addrmap_index_data
;
20024 /* When writing the address table, we have to cope with the fact that
20025 the addrmap iterator only provides the start of a region; we have to
20026 wait until the next invocation to get the start of the next region. */
20028 addrmap_index_data
.objfile
= objfile
;
20029 addrmap_index_data
.addr_obstack
= obstack
;
20030 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20031 addrmap_index_data
.previous_valid
= 0;
20033 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20034 &addrmap_index_data
);
20036 /* It's highly unlikely the last entry (end address = 0xff...ff)
20037 is valid, but we should still handle it.
20038 The end address is recorded as the start of the next region, but that
20039 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20041 if (addrmap_index_data
.previous_valid
)
20042 add_address_entry (objfile
, obstack
,
20043 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20044 addrmap_index_data
.previous_cu_index
);
20047 /* Return the symbol kind of PSYM. */
20049 static gdb_index_symbol_kind
20050 symbol_kind (struct partial_symbol
*psym
)
20052 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20053 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20061 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20063 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20065 case LOC_CONST_BYTES
:
20066 case LOC_OPTIMIZED_OUT
:
20068 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20070 /* Note: It's currently impossible to recognize psyms as enum values
20071 short of reading the type info. For now punt. */
20072 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20074 /* There are other LOC_FOO values that one might want to classify
20075 as variables, but dwarf2read.c doesn't currently use them. */
20076 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20078 case STRUCT_DOMAIN
:
20079 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20081 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20085 /* Add a list of partial symbols to SYMTAB. */
20088 write_psymbols (struct mapped_symtab
*symtab
,
20090 struct partial_symbol
**psymp
,
20092 offset_type cu_index
,
20095 for (; count
-- > 0; ++psymp
)
20097 struct partial_symbol
*psym
= *psymp
;
20100 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20101 error (_("Ada is not currently supported by the index"));
20103 /* Only add a given psymbol once. */
20104 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20107 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20110 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20111 is_static
, kind
, cu_index
);
20116 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20117 exception if there is an error. */
20120 write_obstack (FILE *file
, struct obstack
*obstack
)
20122 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20124 != obstack_object_size (obstack
))
20125 error (_("couldn't data write to file"));
20128 /* Unlink a file if the argument is not NULL. */
20131 unlink_if_set (void *p
)
20133 char **filename
= p
;
20135 unlink (*filename
);
20138 /* A helper struct used when iterating over debug_types. */
20139 struct signatured_type_index_data
20141 struct objfile
*objfile
;
20142 struct mapped_symtab
*symtab
;
20143 struct obstack
*types_list
;
20148 /* A helper function that writes a single signatured_type to an
20152 write_one_signatured_type (void **slot
, void *d
)
20154 struct signatured_type_index_data
*info
= d
;
20155 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20156 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20157 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20160 write_psymbols (info
->symtab
,
20162 info
->objfile
->global_psymbols
.list
20163 + psymtab
->globals_offset
,
20164 psymtab
->n_global_syms
, info
->cu_index
,
20166 write_psymbols (info
->symtab
,
20168 info
->objfile
->static_psymbols
.list
20169 + psymtab
->statics_offset
,
20170 psymtab
->n_static_syms
, info
->cu_index
,
20173 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20174 entry
->per_cu
.offset
.sect_off
);
20175 obstack_grow (info
->types_list
, val
, 8);
20176 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20177 entry
->type_offset_in_tu
.cu_off
);
20178 obstack_grow (info
->types_list
, val
, 8);
20179 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20180 obstack_grow (info
->types_list
, val
, 8);
20187 /* Recurse into all "included" dependencies and write their symbols as
20188 if they appeared in this psymtab. */
20191 recursively_write_psymbols (struct objfile
*objfile
,
20192 struct partial_symtab
*psymtab
,
20193 struct mapped_symtab
*symtab
,
20195 offset_type cu_index
)
20199 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20200 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20201 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20202 symtab
, psyms_seen
, cu_index
);
20204 write_psymbols (symtab
,
20206 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20207 psymtab
->n_global_syms
, cu_index
,
20209 write_psymbols (symtab
,
20211 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20212 psymtab
->n_static_syms
, cu_index
,
20216 /* Create an index file for OBJFILE in the directory DIR. */
20219 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20221 struct cleanup
*cleanup
;
20222 char *filename
, *cleanup_filename
;
20223 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20224 struct obstack cu_list
, types_cu_list
;
20227 struct mapped_symtab
*symtab
;
20228 offset_type val
, size_of_contents
, total_len
;
20231 htab_t cu_index_htab
;
20232 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20234 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20237 if (dwarf2_per_objfile
->using_index
)
20238 error (_("Cannot use an index to create the index"));
20240 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20241 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20243 if (stat (objfile
->name
, &st
) < 0)
20244 perror_with_name (objfile
->name
);
20246 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20247 INDEX_SUFFIX
, (char *) NULL
);
20248 cleanup
= make_cleanup (xfree
, filename
);
20250 out_file
= fopen (filename
, "wb");
20252 error (_("Can't open `%s' for writing"), filename
);
20254 cleanup_filename
= filename
;
20255 make_cleanup (unlink_if_set
, &cleanup_filename
);
20257 symtab
= create_mapped_symtab ();
20258 make_cleanup (cleanup_mapped_symtab
, symtab
);
20260 obstack_init (&addr_obstack
);
20261 make_cleanup_obstack_free (&addr_obstack
);
20263 obstack_init (&cu_list
);
20264 make_cleanup_obstack_free (&cu_list
);
20266 obstack_init (&types_cu_list
);
20267 make_cleanup_obstack_free (&types_cu_list
);
20269 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20270 NULL
, xcalloc
, xfree
);
20271 make_cleanup_htab_delete (psyms_seen
);
20273 /* While we're scanning CU's create a table that maps a psymtab pointer
20274 (which is what addrmap records) to its index (which is what is recorded
20275 in the index file). This will later be needed to write the address
20277 cu_index_htab
= htab_create_alloc (100,
20278 hash_psymtab_cu_index
,
20279 eq_psymtab_cu_index
,
20280 NULL
, xcalloc
, xfree
);
20281 make_cleanup_htab_delete (cu_index_htab
);
20282 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20283 xmalloc (sizeof (struct psymtab_cu_index_map
)
20284 * dwarf2_per_objfile
->n_comp_units
);
20285 make_cleanup (xfree
, psymtab_cu_index_map
);
20287 /* The CU list is already sorted, so we don't need to do additional
20288 work here. Also, the debug_types entries do not appear in
20289 all_comp_units, but only in their own hash table. */
20290 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20292 struct dwarf2_per_cu_data
*per_cu
20293 = dwarf2_per_objfile
->all_comp_units
[i
];
20294 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20296 struct psymtab_cu_index_map
*map
;
20299 if (psymtab
->user
== NULL
)
20300 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20302 map
= &psymtab_cu_index_map
[i
];
20303 map
->psymtab
= psymtab
;
20305 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20306 gdb_assert (slot
!= NULL
);
20307 gdb_assert (*slot
== NULL
);
20310 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20311 per_cu
->offset
.sect_off
);
20312 obstack_grow (&cu_list
, val
, 8);
20313 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20314 obstack_grow (&cu_list
, val
, 8);
20317 /* Dump the address map. */
20318 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20320 /* Write out the .debug_type entries, if any. */
20321 if (dwarf2_per_objfile
->signatured_types
)
20323 struct signatured_type_index_data sig_data
;
20325 sig_data
.objfile
= objfile
;
20326 sig_data
.symtab
= symtab
;
20327 sig_data
.types_list
= &types_cu_list
;
20328 sig_data
.psyms_seen
= psyms_seen
;
20329 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20330 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20331 write_one_signatured_type
, &sig_data
);
20334 /* Now that we've processed all symbols we can shrink their cu_indices
20336 uniquify_cu_indices (symtab
);
20338 obstack_init (&constant_pool
);
20339 make_cleanup_obstack_free (&constant_pool
);
20340 obstack_init (&symtab_obstack
);
20341 make_cleanup_obstack_free (&symtab_obstack
);
20342 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20344 obstack_init (&contents
);
20345 make_cleanup_obstack_free (&contents
);
20346 size_of_contents
= 6 * sizeof (offset_type
);
20347 total_len
= size_of_contents
;
20349 /* The version number. */
20350 val
= MAYBE_SWAP (7);
20351 obstack_grow (&contents
, &val
, sizeof (val
));
20353 /* The offset of the CU list from the start of the file. */
20354 val
= MAYBE_SWAP (total_len
);
20355 obstack_grow (&contents
, &val
, sizeof (val
));
20356 total_len
+= obstack_object_size (&cu_list
);
20358 /* The offset of the types CU list from the start of the file. */
20359 val
= MAYBE_SWAP (total_len
);
20360 obstack_grow (&contents
, &val
, sizeof (val
));
20361 total_len
+= obstack_object_size (&types_cu_list
);
20363 /* The offset of the address table from the start of the file. */
20364 val
= MAYBE_SWAP (total_len
);
20365 obstack_grow (&contents
, &val
, sizeof (val
));
20366 total_len
+= obstack_object_size (&addr_obstack
);
20368 /* The offset of the symbol table from the start of the file. */
20369 val
= MAYBE_SWAP (total_len
);
20370 obstack_grow (&contents
, &val
, sizeof (val
));
20371 total_len
+= obstack_object_size (&symtab_obstack
);
20373 /* The offset of the constant pool from the start of the file. */
20374 val
= MAYBE_SWAP (total_len
);
20375 obstack_grow (&contents
, &val
, sizeof (val
));
20376 total_len
+= obstack_object_size (&constant_pool
);
20378 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20380 write_obstack (out_file
, &contents
);
20381 write_obstack (out_file
, &cu_list
);
20382 write_obstack (out_file
, &types_cu_list
);
20383 write_obstack (out_file
, &addr_obstack
);
20384 write_obstack (out_file
, &symtab_obstack
);
20385 write_obstack (out_file
, &constant_pool
);
20389 /* We want to keep the file, so we set cleanup_filename to NULL
20390 here. See unlink_if_set. */
20391 cleanup_filename
= NULL
;
20393 do_cleanups (cleanup
);
20396 /* Implementation of the `save gdb-index' command.
20398 Note that the file format used by this command is documented in the
20399 GDB manual. Any changes here must be documented there. */
20402 save_gdb_index_command (char *arg
, int from_tty
)
20404 struct objfile
*objfile
;
20407 error (_("usage: save gdb-index DIRECTORY"));
20409 ALL_OBJFILES (objfile
)
20413 /* If the objfile does not correspond to an actual file, skip it. */
20414 if (stat (objfile
->name
, &st
) < 0)
20417 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20418 if (dwarf2_per_objfile
)
20420 volatile struct gdb_exception except
;
20422 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20424 write_psymtabs_to_index (objfile
, arg
);
20426 if (except
.reason
< 0)
20427 exception_fprintf (gdb_stderr
, except
,
20428 _("Error while writing index for `%s': "),
20436 int dwarf2_always_disassemble
;
20439 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20440 struct cmd_list_element
*c
, const char *value
)
20442 fprintf_filtered (file
,
20443 _("Whether to always disassemble "
20444 "DWARF expressions is %s.\n"),
20449 show_check_physname (struct ui_file
*file
, int from_tty
,
20450 struct cmd_list_element
*c
, const char *value
)
20452 fprintf_filtered (file
,
20453 _("Whether to check \"physname\" is %s.\n"),
20457 void _initialize_dwarf2_read (void);
20460 _initialize_dwarf2_read (void)
20462 struct cmd_list_element
*c
;
20464 dwarf2_objfile_data_key
20465 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20467 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20468 Set DWARF 2 specific variables.\n\
20469 Configure DWARF 2 variables such as the cache size"),
20470 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20471 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20473 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20474 Show DWARF 2 specific variables\n\
20475 Show DWARF 2 variables such as the cache size"),
20476 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20477 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20479 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20480 &dwarf2_max_cache_age
, _("\
20481 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20482 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20483 A higher limit means that cached compilation units will be stored\n\
20484 in memory longer, and more total memory will be used. Zero disables\n\
20485 caching, which can slow down startup."),
20487 show_dwarf2_max_cache_age
,
20488 &set_dwarf2_cmdlist
,
20489 &show_dwarf2_cmdlist
);
20491 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20492 &dwarf2_always_disassemble
, _("\
20493 Set whether `info address' always disassembles DWARF expressions."), _("\
20494 Show whether `info address' always disassembles DWARF expressions."), _("\
20495 When enabled, DWARF expressions are always printed in an assembly-like\n\
20496 syntax. When disabled, expressions will be printed in a more\n\
20497 conversational style, when possible."),
20499 show_dwarf2_always_disassemble
,
20500 &set_dwarf2_cmdlist
,
20501 &show_dwarf2_cmdlist
);
20503 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20504 Set debugging of the dwarf2 reader."), _("\
20505 Show debugging of the dwarf2 reader."), _("\
20506 When enabled, debugging messages are printed during dwarf2 reading\n\
20507 and symtab expansion."),
20510 &setdebuglist
, &showdebuglist
);
20512 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20513 Set debugging of the dwarf2 DIE reader."), _("\
20514 Show debugging of the dwarf2 DIE reader."), _("\
20515 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20516 The value is the maximum depth to print."),
20519 &setdebuglist
, &showdebuglist
);
20521 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20522 Set cross-checking of \"physname\" code against demangler."), _("\
20523 Show cross-checking of \"physname\" code against demangler."), _("\
20524 When enabled, GDB's internal \"physname\" code is checked against\n\
20526 NULL
, show_check_physname
,
20527 &setdebuglist
, &showdebuglist
);
20529 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20530 no_class
, &use_deprecated_index_sections
, _("\
20531 Set whether to use deprecated gdb_index sections."), _("\
20532 Show whether to use deprecated gdb_index sections."), _("\
20533 When enabled, deprecated .gdb_index sections are used anyway.\n\
20534 Normally they are ignored either because of a missing feature or\n\
20535 performance issue.\n\
20536 Warning: This option must be enabled before gdb reads the file."),
20539 &setlist
, &showlist
);
20541 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20543 Save a gdb-index file.\n\
20544 Usage: save gdb-index DIRECTORY"),
20546 set_cmd_completer (c
, filename_completer
);