1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2013 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 N.B. This does not apply to DW_AT_ranges appearing in
488 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
489 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
490 DW_AT_ranges_base *would* have to be applied, and we'd have to care
491 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
492 ULONGEST ranges_base
;
494 /* Mark used when releasing cached dies. */
495 unsigned int mark
: 1;
497 /* This CU references .debug_loc. See the symtab->locations_valid field.
498 This test is imperfect as there may exist optimized debug code not using
499 any location list and still facing inlining issues if handled as
500 unoptimized code. For a future better test see GCC PR other/32998. */
501 unsigned int has_loclist
: 1;
503 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
504 if all the producer_is_* fields are valid. This information is cached
505 because profiling CU expansion showed excessive time spent in
506 producer_is_gxx_lt_4_6. */
507 unsigned int checked_producer
: 1;
508 unsigned int producer_is_gxx_lt_4_6
: 1;
509 unsigned int producer_is_gcc_lt_4_3
: 1;
510 unsigned int producer_is_icc
: 1;
513 /* Persistent data held for a compilation unit, even when not
514 processing it. We put a pointer to this structure in the
515 read_symtab_private field of the psymtab. */
517 struct dwarf2_per_cu_data
519 /* The start offset and length of this compilation unit.
520 NOTE: Unlike comp_unit_head.length, this length includes
522 If the DIE refers to a DWO file, this is always of the original die,
527 /* Flag indicating this compilation unit will be read in before
528 any of the current compilation units are processed. */
529 unsigned int queued
: 1;
531 /* This flag will be set when reading partial DIEs if we need to load
532 absolutely all DIEs for this compilation unit, instead of just the ones
533 we think are interesting. It gets set if we look for a DIE in the
534 hash table and don't find it. */
535 unsigned int load_all_dies
: 1;
537 /* Non-zero if this CU is from .debug_types. */
538 unsigned int is_debug_types
: 1;
540 /* Non-zero if this CU is from the .dwz file. */
541 unsigned int is_dwz
: 1;
543 /* The section this CU/TU lives in.
544 If the DIE refers to a DWO file, this is always the original die,
546 struct dwarf2_section_info
*info_or_types_section
;
548 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
549 of the CU cache it gets reset to NULL again. */
550 struct dwarf2_cu
*cu
;
552 /* The corresponding objfile.
553 Normally we can get the objfile from dwarf2_per_objfile.
554 However we can enter this file with just a "per_cu" handle. */
555 struct objfile
*objfile
;
557 /* When using partial symbol tables, the 'psymtab' field is active.
558 Otherwise the 'quick' field is active. */
561 /* The partial symbol table associated with this compilation unit,
562 or NULL for unread partial units. */
563 struct partial_symtab
*psymtab
;
565 /* Data needed by the "quick" functions. */
566 struct dwarf2_per_cu_quick_data
*quick
;
569 /* The CUs we import using DW_TAG_imported_unit. This is filled in
570 while reading psymtabs, used to compute the psymtab dependencies,
571 and then cleared. Then it is filled in again while reading full
572 symbols, and only deleted when the objfile is destroyed.
574 This is also used to work around a difference between the way gold
575 generates .gdb_index version <=7 and the way gdb does. Arguably this
576 is a gold bug. For symbols coming from TUs, gold records in the index
577 the CU that includes the TU instead of the TU itself. This breaks
578 dw2_lookup_symbol: It assumes that if the index says symbol X lives
579 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
580 will find X. Alas TUs live in their own symtab, so after expanding CU Y
581 we need to look in TU Z to find X. Fortunately, this is akin to
582 DW_TAG_imported_unit, so we just use the same mechanism: For
583 .gdb_index version <=7 this also records the TUs that the CU referred
584 to. Concurrently with this change gdb was modified to emit version 8
585 indices so we only pay a price for gold generated indices. */
586 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
588 /* Type units are grouped by their DW_AT_stmt_list entry so that they
589 can share them. If this is a TU, this points to the containing
591 struct type_unit_group
*type_unit_group
;
594 /* Entry in the signatured_types hash table. */
596 struct signatured_type
598 /* The "per_cu" object of this type.
599 N.B.: This is the first member so that it's easy to convert pointers
601 struct dwarf2_per_cu_data per_cu
;
603 /* The type's signature. */
606 /* Offset in the TU of the type's DIE, as read from the TU header.
607 If the definition lives in a DWO file, this value is unusable. */
608 cu_offset type_offset_in_tu
;
610 /* Offset in the section of the type's DIE.
611 If the definition lives in a DWO file, this is the offset in the
612 .debug_types.dwo section.
613 The value is zero until the actual value is known.
614 Zero is otherwise not a valid section offset. */
615 sect_offset type_offset_in_section
;
618 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
619 This includes type_unit_group and quick_file_names. */
621 struct stmt_list_hash
623 /* The DWO unit this table is from or NULL if there is none. */
624 struct dwo_unit
*dwo_unit
;
626 /* Offset in .debug_line or .debug_line.dwo. */
627 sect_offset line_offset
;
630 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
631 an object of this type. */
633 struct type_unit_group
635 /* dwarf2read.c's main "handle" on the symtab.
636 To simplify things we create an artificial CU that "includes" all the
637 type units using this stmt_list so that the rest of the code still has
638 a "per_cu" handle on the symtab.
639 This PER_CU is recognized by having no section. */
640 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
641 struct dwarf2_per_cu_data per_cu
;
645 /* The TUs that share this DW_AT_stmt_list entry.
646 This is added to while parsing type units to build partial symtabs,
647 and is deleted afterwards and not used again. */
648 VEC (dwarf2_per_cu_ptr
) *tus
;
650 /* When reading the line table in "quick" functions, we need a real TU.
651 Any will do, we know they all share the same DW_AT_stmt_list entry.
652 For simplicity's sake, we pick the first one. */
653 struct dwarf2_per_cu_data
*first_tu
;
656 /* The primary symtab.
657 Type units in a group needn't all be defined in the same source file,
658 so we create an essentially anonymous symtab as the primary symtab. */
659 struct symtab
*primary_symtab
;
661 /* The data used to construct the hash key. */
662 struct stmt_list_hash hash
;
664 /* The number of symtabs from the line header.
665 The value here must match line_header.num_file_names. */
666 unsigned int num_symtabs
;
668 /* The symbol tables for this TU (obtained from the files listed in
670 WARNING: The order of entries here must match the order of entries
671 in the line header. After the first TU using this type_unit_group, the
672 line header for the subsequent TUs is recreated from this. This is done
673 because we need to use the same symtabs for each TU using the same
674 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
675 there's no guarantee the line header doesn't have duplicate entries. */
676 struct symtab
**symtabs
;
679 /* These sections are what may appear in a DWO file. */
683 struct dwarf2_section_info abbrev
;
684 struct dwarf2_section_info line
;
685 struct dwarf2_section_info loc
;
686 struct dwarf2_section_info macinfo
;
687 struct dwarf2_section_info macro
;
688 struct dwarf2_section_info str
;
689 struct dwarf2_section_info str_offsets
;
690 /* In the case of a virtual DWO file, these two are unused. */
691 struct dwarf2_section_info info
;
692 VEC (dwarf2_section_info_def
) *types
;
695 /* Common bits of DWO CUs/TUs. */
699 /* Backlink to the containing struct dwo_file. */
700 struct dwo_file
*dwo_file
;
702 /* The "id" that distinguishes this CU/TU.
703 .debug_info calls this "dwo_id", .debug_types calls this "signature".
704 Since signatures came first, we stick with it for consistency. */
707 /* The section this CU/TU lives in, in the DWO file. */
708 struct dwarf2_section_info
*info_or_types_section
;
710 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
714 /* For types, offset in the type's DIE of the type defined by this TU. */
715 cu_offset type_offset_in_tu
;
718 /* Data for one DWO file.
719 This includes virtual DWO files that have been packaged into a
724 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
725 For virtual DWO files the name is constructed from the section offsets
726 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
727 from related CU+TUs. */
730 /* The bfd, when the file is open. Otherwise this is NULL.
731 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
734 /* Section info for this file. */
735 struct dwo_sections sections
;
737 /* Table of CUs in the file.
738 Each element is a struct dwo_unit. */
741 /* Table of TUs in the file.
742 Each element is a struct dwo_unit. */
746 /* These sections are what may appear in a DWP file. */
750 struct dwarf2_section_info str
;
751 struct dwarf2_section_info cu_index
;
752 struct dwarf2_section_info tu_index
;
753 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
754 by section number. We don't need to record them here. */
757 /* These sections are what may appear in a virtual DWO file. */
759 struct virtual_dwo_sections
761 struct dwarf2_section_info abbrev
;
762 struct dwarf2_section_info line
;
763 struct dwarf2_section_info loc
;
764 struct dwarf2_section_info macinfo
;
765 struct dwarf2_section_info macro
;
766 struct dwarf2_section_info str_offsets
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.info_or_types_section. */
769 struct dwarf2_section_info info_or_types
;
772 /* Contents of DWP hash tables. */
774 struct dwp_hash_table
776 uint32_t nr_units
, nr_slots
;
777 const gdb_byte
*hash_table
, *unit_table
, *section_pool
;
780 /* Data for one DWP file. */
784 /* Name of the file. */
787 /* The bfd, when the file is open. Otherwise this is NULL. */
790 /* Section info for this file. */
791 struct dwp_sections sections
;
793 /* Table of CUs in the file. */
794 const struct dwp_hash_table
*cus
;
796 /* Table of TUs in the file. */
797 const struct dwp_hash_table
*tus
;
799 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
802 /* Table to map ELF section numbers to their sections. */
803 unsigned int num_sections
;
804 asection
**elf_sections
;
807 /* This represents a '.dwz' file. */
811 /* A dwz file can only contain a few sections. */
812 struct dwarf2_section_info abbrev
;
813 struct dwarf2_section_info info
;
814 struct dwarf2_section_info str
;
815 struct dwarf2_section_info line
;
816 struct dwarf2_section_info macro
;
817 struct dwarf2_section_info gdb_index
;
823 /* Struct used to pass misc. parameters to read_die_and_children, et
824 al. which are used for both .debug_info and .debug_types dies.
825 All parameters here are unchanging for the life of the call. This
826 struct exists to abstract away the constant parameters of die reading. */
828 struct die_reader_specs
830 /* die_section->asection->owner. */
833 /* The CU of the DIE we are parsing. */
834 struct dwarf2_cu
*cu
;
836 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
837 struct dwo_file
*dwo_file
;
839 /* The section the die comes from.
840 This is either .debug_info or .debug_types, or the .dwo variants. */
841 struct dwarf2_section_info
*die_section
;
843 /* die_section->buffer. */
846 /* The end of the buffer. */
847 const gdb_byte
*buffer_end
;
850 /* Type of function passed to init_cutu_and_read_dies, et.al. */
851 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
853 struct die_info
*comp_unit_die
,
857 /* The line number information for a compilation unit (found in the
858 .debug_line section) begins with a "statement program header",
859 which contains the following information. */
862 unsigned int total_length
;
863 unsigned short version
;
864 unsigned int header_length
;
865 unsigned char minimum_instruction_length
;
866 unsigned char maximum_ops_per_instruction
;
867 unsigned char default_is_stmt
;
869 unsigned char line_range
;
870 unsigned char opcode_base
;
872 /* standard_opcode_lengths[i] is the number of operands for the
873 standard opcode whose value is i. This means that
874 standard_opcode_lengths[0] is unused, and the last meaningful
875 element is standard_opcode_lengths[opcode_base - 1]. */
876 unsigned char *standard_opcode_lengths
;
878 /* The include_directories table. NOTE! These strings are not
879 allocated with xmalloc; instead, they are pointers into
880 debug_line_buffer. If you try to free them, `free' will get
882 unsigned int num_include_dirs
, include_dirs_size
;
885 /* The file_names table. NOTE! These strings are not allocated
886 with xmalloc; instead, they are pointers into debug_line_buffer.
887 Don't try to free them directly. */
888 unsigned int num_file_names
, file_names_size
;
892 unsigned int dir_index
;
893 unsigned int mod_time
;
895 int included_p
; /* Non-zero if referenced by the Line Number Program. */
896 struct symtab
*symtab
; /* The associated symbol table, if any. */
899 /* The start and end of the statement program following this
900 header. These point into dwarf2_per_objfile->line_buffer. */
901 gdb_byte
*statement_program_start
, *statement_program_end
;
904 /* When we construct a partial symbol table entry we only
905 need this much information. */
906 struct partial_die_info
908 /* Offset of this DIE. */
911 /* DWARF-2 tag for this DIE. */
912 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
914 /* Assorted flags describing the data found in this DIE. */
915 unsigned int has_children
: 1;
916 unsigned int is_external
: 1;
917 unsigned int is_declaration
: 1;
918 unsigned int has_type
: 1;
919 unsigned int has_specification
: 1;
920 unsigned int has_pc_info
: 1;
921 unsigned int may_be_inlined
: 1;
923 /* Flag set if the SCOPE field of this structure has been
925 unsigned int scope_set
: 1;
927 /* Flag set if the DIE has a byte_size attribute. */
928 unsigned int has_byte_size
: 1;
930 /* Flag set if any of the DIE's children are template arguments. */
931 unsigned int has_template_arguments
: 1;
933 /* Flag set if fixup_partial_die has been called on this die. */
934 unsigned int fixup_called
: 1;
936 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
937 unsigned int is_dwz
: 1;
939 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
940 unsigned int spec_is_dwz
: 1;
942 /* The name of this DIE. Normally the value of DW_AT_name, but
943 sometimes a default name for unnamed DIEs. */
946 /* The linkage name, if present. */
947 const char *linkage_name
;
949 /* The scope to prepend to our children. This is generally
950 allocated on the comp_unit_obstack, so will disappear
951 when this compilation unit leaves the cache. */
954 /* Some data associated with the partial DIE. The tag determines
955 which field is live. */
958 /* The location description associated with this DIE, if any. */
959 struct dwarf_block
*locdesc
;
960 /* The offset of an import, for DW_TAG_imported_unit. */
964 /* If HAS_PC_INFO, the PC range associated with this DIE. */
968 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
969 DW_AT_sibling, if any. */
970 /* NOTE: This member isn't strictly necessary, read_partial_die could
971 return DW_AT_sibling values to its caller load_partial_dies. */
974 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
975 DW_AT_specification (or DW_AT_abstract_origin or
977 sect_offset spec_offset
;
979 /* Pointers to this DIE's parent, first child, and next sibling,
981 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
984 /* This data structure holds the information of an abbrev. */
987 unsigned int number
; /* number identifying abbrev */
988 enum dwarf_tag tag
; /* dwarf tag */
989 unsigned short has_children
; /* boolean */
990 unsigned short num_attrs
; /* number of attributes */
991 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
992 struct abbrev_info
*next
; /* next in chain */
997 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
998 ENUM_BITFIELD(dwarf_form
) form
: 16;
1001 /* Size of abbrev_table.abbrev_hash_table. */
1002 #define ABBREV_HASH_SIZE 121
1004 /* Top level data structure to contain an abbreviation table. */
1008 /* Where the abbrev table came from.
1009 This is used as a sanity check when the table is used. */
1012 /* Storage for the abbrev table. */
1013 struct obstack abbrev_obstack
;
1015 /* Hash table of abbrevs.
1016 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1017 It could be statically allocated, but the previous code didn't so we
1019 struct abbrev_info
**abbrevs
;
1022 /* Attributes have a name and a value. */
1025 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1026 ENUM_BITFIELD(dwarf_form
) form
: 15;
1028 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1029 field should be in u.str (existing only for DW_STRING) but it is kept
1030 here for better struct attribute alignment. */
1031 unsigned int string_is_canonical
: 1;
1036 struct dwarf_block
*blk
;
1040 struct signatured_type
*signatured_type
;
1045 /* This data structure holds a complete die structure. */
1048 /* DWARF-2 tag for this DIE. */
1049 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1051 /* Number of attributes */
1052 unsigned char num_attrs
;
1054 /* True if we're presently building the full type name for the
1055 type derived from this DIE. */
1056 unsigned char building_fullname
: 1;
1059 unsigned int abbrev
;
1061 /* Offset in .debug_info or .debug_types section. */
1064 /* The dies in a compilation unit form an n-ary tree. PARENT
1065 points to this die's parent; CHILD points to the first child of
1066 this node; and all the children of a given node are chained
1067 together via their SIBLING fields. */
1068 struct die_info
*child
; /* Its first child, if any. */
1069 struct die_info
*sibling
; /* Its next sibling, if any. */
1070 struct die_info
*parent
; /* Its parent, if any. */
1072 /* An array of attributes, with NUM_ATTRS elements. There may be
1073 zero, but it's not common and zero-sized arrays are not
1074 sufficiently portable C. */
1075 struct attribute attrs
[1];
1078 /* Get at parts of an attribute structure. */
1080 #define DW_STRING(attr) ((attr)->u.str)
1081 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1082 #define DW_UNSND(attr) ((attr)->u.unsnd)
1083 #define DW_BLOCK(attr) ((attr)->u.blk)
1084 #define DW_SND(attr) ((attr)->u.snd)
1085 #define DW_ADDR(attr) ((attr)->u.addr)
1086 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1088 /* Blocks are a bunch of untyped bytes. */
1093 /* Valid only if SIZE is not zero. */
1097 #ifndef ATTR_ALLOC_CHUNK
1098 #define ATTR_ALLOC_CHUNK 4
1101 /* Allocate fields for structs, unions and enums in this size. */
1102 #ifndef DW_FIELD_ALLOC_CHUNK
1103 #define DW_FIELD_ALLOC_CHUNK 4
1106 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1107 but this would require a corresponding change in unpack_field_as_long
1109 static int bits_per_byte
= 8;
1111 /* The routines that read and process dies for a C struct or C++ class
1112 pass lists of data member fields and lists of member function fields
1113 in an instance of a field_info structure, as defined below. */
1116 /* List of data member and baseclasses fields. */
1119 struct nextfield
*next
;
1124 *fields
, *baseclasses
;
1126 /* Number of fields (including baseclasses). */
1129 /* Number of baseclasses. */
1132 /* Set if the accesibility of one of the fields is not public. */
1133 int non_public_fields
;
1135 /* Member function fields array, entries are allocated in the order they
1136 are encountered in the object file. */
1139 struct nextfnfield
*next
;
1140 struct fn_field fnfield
;
1144 /* Member function fieldlist array, contains name of possibly overloaded
1145 member function, number of overloaded member functions and a pointer
1146 to the head of the member function field chain. */
1151 struct nextfnfield
*head
;
1155 /* Number of entries in the fnfieldlists array. */
1158 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1159 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1160 struct typedef_field_list
1162 struct typedef_field field
;
1163 struct typedef_field_list
*next
;
1165 *typedef_field_list
;
1166 unsigned typedef_field_list_count
;
1169 /* One item on the queue of compilation units to read in full symbols
1171 struct dwarf2_queue_item
1173 struct dwarf2_per_cu_data
*per_cu
;
1174 enum language pretend_language
;
1175 struct dwarf2_queue_item
*next
;
1178 /* The current queue. */
1179 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1181 /* Loaded secondary compilation units are kept in memory until they
1182 have not been referenced for the processing of this many
1183 compilation units. Set this to zero to disable caching. Cache
1184 sizes of up to at least twenty will improve startup time for
1185 typical inter-CU-reference binaries, at an obvious memory cost. */
1186 static int dwarf2_max_cache_age
= 5;
1188 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
1189 struct cmd_list_element
*c
, const char *value
)
1191 fprintf_filtered (file
, _("The upper bound on the age of cached "
1192 "dwarf2 compilation units is %s.\n"),
1197 /* Various complaints about symbol reading that don't abort the process. */
1200 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1202 complaint (&symfile_complaints
,
1203 _("statement list doesn't fit in .debug_line section"));
1207 dwarf2_debug_line_missing_file_complaint (void)
1209 complaint (&symfile_complaints
,
1210 _(".debug_line section has line data without a file"));
1214 dwarf2_debug_line_missing_end_sequence_complaint (void)
1216 complaint (&symfile_complaints
,
1217 _(".debug_line section has line "
1218 "program sequence without an end"));
1222 dwarf2_complex_location_expr_complaint (void)
1224 complaint (&symfile_complaints
, _("location expression too complex"));
1228 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1231 complaint (&symfile_complaints
,
1232 _("const value length mismatch for '%s', got %d, expected %d"),
1237 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1239 complaint (&symfile_complaints
,
1240 _("debug info runs off end of %s section"
1242 section
->asection
->name
,
1243 bfd_get_filename (section
->asection
->owner
));
1247 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1249 complaint (&symfile_complaints
,
1250 _("macro debug info contains a "
1251 "malformed macro definition:\n`%s'"),
1256 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1258 complaint (&symfile_complaints
,
1259 _("invalid attribute class or form for '%s' in '%s'"),
1263 /* local function prototypes */
1265 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
1267 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
1270 static void dwarf2_find_base_address (struct die_info
*die
,
1271 struct dwarf2_cu
*cu
);
1273 static void dwarf2_build_psymtabs_hard (struct objfile
*);
1275 static void scan_partial_symbols (struct partial_die_info
*,
1276 CORE_ADDR
*, CORE_ADDR
*,
1277 int, struct dwarf2_cu
*);
1279 static void add_partial_symbol (struct partial_die_info
*,
1280 struct dwarf2_cu
*);
1282 static void add_partial_namespace (struct partial_die_info
*pdi
,
1283 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1284 int need_pc
, struct dwarf2_cu
*cu
);
1286 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1287 CORE_ADDR
*highpc
, int need_pc
,
1288 struct dwarf2_cu
*cu
);
1290 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1291 struct dwarf2_cu
*cu
);
1293 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1294 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1295 int need_pc
, struct dwarf2_cu
*cu
);
1297 static void dwarf2_read_symtab (struct partial_symtab
*,
1300 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1302 static struct abbrev_info
*abbrev_table_lookup_abbrev
1303 (const struct abbrev_table
*, unsigned int);
1305 static struct abbrev_table
*abbrev_table_read_table
1306 (struct dwarf2_section_info
*, sect_offset
);
1308 static void abbrev_table_free (struct abbrev_table
*);
1310 static void abbrev_table_free_cleanup (void *);
1312 static void dwarf2_read_abbrevs (struct dwarf2_cu
*,
1313 struct dwarf2_section_info
*);
1315 static void dwarf2_free_abbrev_table (void *);
1317 static unsigned int peek_abbrev_code (bfd
*, gdb_byte
*);
1319 static struct partial_die_info
*load_partial_dies
1320 (const struct die_reader_specs
*, gdb_byte
*, int);
1322 static gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1323 struct partial_die_info
*,
1324 struct abbrev_info
*,
1328 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1329 struct dwarf2_cu
*);
1331 static void fixup_partial_die (struct partial_die_info
*,
1332 struct dwarf2_cu
*);
1334 static gdb_byte
*read_attribute (const struct die_reader_specs
*,
1335 struct attribute
*, struct attr_abbrev
*,
1338 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1340 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1342 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1344 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1346 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1348 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
1351 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
1353 static LONGEST read_checked_initial_length_and_offset
1354 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1355 unsigned int *, unsigned int *);
1357 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
1360 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
1362 static sect_offset
read_abbrev_offset (struct dwarf2_section_info
*,
1365 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
1367 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
1369 static char *read_indirect_string (bfd
*, gdb_byte
*,
1370 const struct comp_unit_head
*,
1373 static char *read_indirect_string_from_dwz (struct dwz_file
*, LONGEST
);
1375 static ULONGEST
read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1377 static LONGEST
read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
1379 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*, gdb_byte
*,
1382 static char *read_str_index (const struct die_reader_specs
*reader
,
1383 struct dwarf2_cu
*cu
, ULONGEST str_index
);
1385 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1387 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1388 struct dwarf2_cu
*);
1390 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1393 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1394 struct dwarf2_cu
*cu
);
1396 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1398 static struct die_info
*die_specification (struct die_info
*die
,
1399 struct dwarf2_cu
**);
1401 static void free_line_header (struct line_header
*lh
);
1403 static void add_file_name (struct line_header
*, char *, unsigned int,
1404 unsigned int, unsigned int);
1406 static struct line_header
*dwarf_decode_line_header (unsigned int offset
,
1407 struct dwarf2_cu
*cu
);
1409 static void dwarf_decode_lines (struct line_header
*, const char *,
1410 struct dwarf2_cu
*, struct partial_symtab
*,
1413 static void dwarf2_start_subfile (char *, const char *, const char *);
1415 static void dwarf2_start_symtab (struct dwarf2_cu
*,
1416 const char *, const char *, CORE_ADDR
);
1418 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1419 struct dwarf2_cu
*);
1421 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1422 struct dwarf2_cu
*, struct symbol
*);
1424 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1425 struct dwarf2_cu
*);
1427 static void dwarf2_const_value_attr (struct attribute
*attr
,
1430 struct obstack
*obstack
,
1431 struct dwarf2_cu
*cu
, LONGEST
*value
,
1433 struct dwarf2_locexpr_baton
**baton
);
1435 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1437 static int need_gnat_info (struct dwarf2_cu
*);
1439 static struct type
*die_descriptive_type (struct die_info
*,
1440 struct dwarf2_cu
*);
1442 static void set_descriptive_type (struct type
*, struct die_info
*,
1443 struct dwarf2_cu
*);
1445 static struct type
*die_containing_type (struct die_info
*,
1446 struct dwarf2_cu
*);
1448 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1449 struct dwarf2_cu
*);
1451 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1453 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1455 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1457 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1458 const char *suffix
, int physname
,
1459 struct dwarf2_cu
*cu
);
1461 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1463 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1465 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1467 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1469 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1471 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1472 struct dwarf2_cu
*, struct partial_symtab
*);
1474 static int dwarf2_get_pc_bounds (struct die_info
*,
1475 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1476 struct partial_symtab
*);
1478 static void get_scope_pc_bounds (struct die_info
*,
1479 CORE_ADDR
*, CORE_ADDR
*,
1480 struct dwarf2_cu
*);
1482 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1483 CORE_ADDR
, struct dwarf2_cu
*);
1485 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1486 struct dwarf2_cu
*);
1488 static void dwarf2_attach_fields_to_type (struct field_info
*,
1489 struct type
*, struct dwarf2_cu
*);
1491 static void dwarf2_add_member_fn (struct field_info
*,
1492 struct die_info
*, struct type
*,
1493 struct dwarf2_cu
*);
1495 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1497 struct dwarf2_cu
*);
1499 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1501 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1503 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1505 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1507 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1509 static struct type
*read_module_type (struct die_info
*die
,
1510 struct dwarf2_cu
*cu
);
1512 static const char *namespace_name (struct die_info
*die
,
1513 int *is_anonymous
, struct dwarf2_cu
*);
1515 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1517 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1519 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1520 struct dwarf2_cu
*);
1522 static struct die_info
*read_die_and_children (const struct die_reader_specs
*,
1524 gdb_byte
**new_info_ptr
,
1525 struct die_info
*parent
);
1527 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1529 gdb_byte
**new_info_ptr
,
1530 struct die_info
*parent
);
1532 static gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1533 struct die_info
**, gdb_byte
*, int *, int);
1535 static gdb_byte
*read_full_die (const struct die_reader_specs
*,
1536 struct die_info
**, gdb_byte
*, int *);
1538 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1540 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1543 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1545 static const char *dwarf2_full_name (const char *name
,
1546 struct die_info
*die
,
1547 struct dwarf2_cu
*cu
);
1549 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1550 struct dwarf2_cu
**);
1552 static const char *dwarf_tag_name (unsigned int);
1554 static const char *dwarf_attr_name (unsigned int);
1556 static const char *dwarf_form_name (unsigned int);
1558 static char *dwarf_bool_name (unsigned int);
1560 static const char *dwarf_type_encoding_name (unsigned int);
1562 static struct die_info
*sibling_die (struct die_info
*);
1564 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1566 static void dump_die_for_error (struct die_info
*);
1568 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1571 /*static*/ void dump_die (struct die_info
*, int max_level
);
1573 static void store_in_ref_table (struct die_info
*,
1574 struct dwarf2_cu
*);
1576 static int is_ref_attr (struct attribute
*);
1578 static sect_offset
dwarf2_get_ref_die_offset (struct attribute
*);
1580 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1582 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1584 struct dwarf2_cu
**);
1586 static struct die_info
*follow_die_ref (struct die_info
*,
1588 struct dwarf2_cu
**);
1590 static struct die_info
*follow_die_sig (struct die_info
*,
1592 struct dwarf2_cu
**);
1594 static struct signatured_type
*lookup_signatured_type_at_offset
1595 (struct objfile
*objfile
,
1596 struct dwarf2_section_info
*section
, sect_offset offset
);
1598 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1600 static void read_signatured_type (struct signatured_type
*);
1602 static struct type_unit_group
*get_type_unit_group
1603 (struct dwarf2_cu
*, struct attribute
*);
1605 static void build_type_unit_groups (die_reader_func_ftype
*, void *);
1607 /* memory allocation interface */
1609 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1611 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1613 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int,
1616 static int attr_form_is_block (struct attribute
*);
1618 static int attr_form_is_section_offset (struct attribute
*);
1620 static int attr_form_is_constant (struct attribute
*);
1622 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1623 struct dwarf2_loclist_baton
*baton
,
1624 struct attribute
*attr
);
1626 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1628 struct dwarf2_cu
*cu
);
1630 static gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1632 struct abbrev_info
*abbrev
);
1634 static void free_stack_comp_unit (void *);
1636 static hashval_t
partial_die_hash (const void *item
);
1638 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1640 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1641 (sect_offset offset
, unsigned int offset_in_dwz
, struct objfile
*objfile
);
1643 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1644 struct dwarf2_per_cu_data
*per_cu
);
1646 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1647 struct die_info
*comp_unit_die
,
1648 enum language pretend_language
);
1650 static void free_heap_comp_unit (void *);
1652 static void free_cached_comp_units (void *);
1654 static void age_cached_comp_units (void);
1656 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1658 static struct type
*set_die_type (struct die_info
*, struct type
*,
1659 struct dwarf2_cu
*);
1661 static void create_all_comp_units (struct objfile
*);
1663 static int create_all_type_units (struct objfile
*);
1665 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1668 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1671 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1674 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1675 struct dwarf2_per_cu_data
*);
1677 static void dwarf2_mark (struct dwarf2_cu
*);
1679 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1681 static struct type
*get_die_type_at_offset (sect_offset
,
1682 struct dwarf2_per_cu_data
*per_cu
);
1684 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1686 static void dwarf2_release_queue (void *dummy
);
1688 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1689 enum language pretend_language
);
1691 static int maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
1692 struct dwarf2_per_cu_data
*per_cu
,
1693 enum language pretend_language
);
1695 static void process_queue (void);
1697 static void find_file_and_directory (struct die_info
*die
,
1698 struct dwarf2_cu
*cu
,
1699 const char **name
, const char **comp_dir
);
1701 static char *file_full_name (int file
, struct line_header
*lh
,
1702 const char *comp_dir
);
1704 static gdb_byte
*read_and_check_comp_unit_head
1705 (struct comp_unit_head
*header
,
1706 struct dwarf2_section_info
*section
,
1707 struct dwarf2_section_info
*abbrev_section
, gdb_byte
*info_ptr
,
1708 int is_debug_types_section
);
1710 static void init_cutu_and_read_dies
1711 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1712 int use_existing_cu
, int keep
,
1713 die_reader_func_ftype
*die_reader_func
, void *data
);
1715 static void init_cutu_and_read_dies_simple
1716 (struct dwarf2_per_cu_data
*this_cu
,
1717 die_reader_func_ftype
*die_reader_func
, void *data
);
1719 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1721 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1723 static struct dwo_unit
*lookup_dwo_comp_unit
1724 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1726 static struct dwo_unit
*lookup_dwo_type_unit
1727 (struct signatured_type
*, const char *, const char *);
1729 static void free_dwo_file_cleanup (void *);
1731 static void process_cu_includes (void);
1733 static void check_producer (struct dwarf2_cu
*cu
);
1737 /* Convert VALUE between big- and little-endian. */
1739 byte_swap (offset_type value
)
1743 result
= (value
& 0xff) << 24;
1744 result
|= (value
& 0xff00) << 8;
1745 result
|= (value
& 0xff0000) >> 8;
1746 result
|= (value
& 0xff000000) >> 24;
1750 #define MAYBE_SWAP(V) byte_swap (V)
1753 #define MAYBE_SWAP(V) (V)
1754 #endif /* WORDS_BIGENDIAN */
1756 /* The suffix for an index file. */
1757 #define INDEX_SUFFIX ".gdb-index"
1759 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1760 struct dwarf2_cu
*cu
);
1762 /* Try to locate the sections we need for DWARF 2 debugging
1763 information and return true if we have enough to do something.
1764 NAMES points to the dwarf2 section names, or is NULL if the standard
1765 ELF names are used. */
1768 dwarf2_has_info (struct objfile
*objfile
,
1769 const struct dwarf2_debug_sections
*names
)
1771 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1772 if (!dwarf2_per_objfile
)
1774 /* Initialize per-objfile state. */
1775 struct dwarf2_per_objfile
*data
1776 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1778 memset (data
, 0, sizeof (*data
));
1779 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1780 dwarf2_per_objfile
= data
;
1782 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
,
1784 dwarf2_per_objfile
->objfile
= objfile
;
1786 return (dwarf2_per_objfile
->info
.asection
!= NULL
1787 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1790 /* When loading sections, we look either for uncompressed section or for
1791 compressed section names. */
1794 section_is_p (const char *section_name
,
1795 const struct dwarf2_section_names
*names
)
1797 if (names
->normal
!= NULL
1798 && strcmp (section_name
, names
->normal
) == 0)
1800 if (names
->compressed
!= NULL
1801 && strcmp (section_name
, names
->compressed
) == 0)
1806 /* This function is mapped across the sections and remembers the
1807 offset and size of each of the debugging sections we are interested
1811 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *vnames
)
1813 const struct dwarf2_debug_sections
*names
;
1814 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
1817 names
= &dwarf2_elf_names
;
1819 names
= (const struct dwarf2_debug_sections
*) vnames
;
1821 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1824 else if (section_is_p (sectp
->name
, &names
->info
))
1826 dwarf2_per_objfile
->info
.asection
= sectp
;
1827 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1829 else if (section_is_p (sectp
->name
, &names
->abbrev
))
1831 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1832 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1834 else if (section_is_p (sectp
->name
, &names
->line
))
1836 dwarf2_per_objfile
->line
.asection
= sectp
;
1837 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1839 else if (section_is_p (sectp
->name
, &names
->loc
))
1841 dwarf2_per_objfile
->loc
.asection
= sectp
;
1842 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1844 else if (section_is_p (sectp
->name
, &names
->macinfo
))
1846 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1847 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1849 else if (section_is_p (sectp
->name
, &names
->macro
))
1851 dwarf2_per_objfile
->macro
.asection
= sectp
;
1852 dwarf2_per_objfile
->macro
.size
= bfd_get_section_size (sectp
);
1854 else if (section_is_p (sectp
->name
, &names
->str
))
1856 dwarf2_per_objfile
->str
.asection
= sectp
;
1857 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1859 else if (section_is_p (sectp
->name
, &names
->addr
))
1861 dwarf2_per_objfile
->addr
.asection
= sectp
;
1862 dwarf2_per_objfile
->addr
.size
= bfd_get_section_size (sectp
);
1864 else if (section_is_p (sectp
->name
, &names
->frame
))
1866 dwarf2_per_objfile
->frame
.asection
= sectp
;
1867 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1869 else if (section_is_p (sectp
->name
, &names
->eh_frame
))
1871 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1872 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1874 else if (section_is_p (sectp
->name
, &names
->ranges
))
1876 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1877 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1879 else if (section_is_p (sectp
->name
, &names
->types
))
1881 struct dwarf2_section_info type_section
;
1883 memset (&type_section
, 0, sizeof (type_section
));
1884 type_section
.asection
= sectp
;
1885 type_section
.size
= bfd_get_section_size (sectp
);
1887 VEC_safe_push (dwarf2_section_info_def
, dwarf2_per_objfile
->types
,
1890 else if (section_is_p (sectp
->name
, &names
->gdb_index
))
1892 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1893 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1896 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1897 && bfd_section_vma (abfd
, sectp
) == 0)
1898 dwarf2_per_objfile
->has_section_at_zero
= 1;
1901 /* A helper function that decides whether a section is empty,
1905 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1907 return info
->asection
== NULL
|| info
->size
== 0;
1910 /* Read the contents of the section INFO.
1911 OBJFILE is the main object file, but not necessarily the file where
1912 the section comes from. E.g., for DWO files INFO->asection->owner
1913 is the bfd of the DWO file.
1914 If the section is compressed, uncompress it before returning. */
1917 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1919 asection
*sectp
= info
->asection
;
1921 gdb_byte
*buf
, *retbuf
;
1922 unsigned char header
[4];
1926 info
->buffer
= NULL
;
1929 if (dwarf2_section_empty_p (info
))
1932 abfd
= sectp
->owner
;
1934 /* If the section has relocations, we must read it ourselves.
1935 Otherwise we attach it to the BFD. */
1936 if ((sectp
->flags
& SEC_RELOC
) == 0)
1938 const gdb_byte
*bytes
= gdb_bfd_map_section (sectp
, &info
->size
);
1940 /* We have to cast away const here for historical reasons.
1941 Fixing dwarf2read to be const-correct would be quite nice. */
1942 info
->buffer
= (gdb_byte
*) bytes
;
1946 buf
= obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1949 /* When debugging .o files, we may need to apply relocations; see
1950 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1951 We never compress sections in .o files, so we only need to
1952 try this when the section is not compressed. */
1953 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1956 info
->buffer
= retbuf
;
1960 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1961 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1962 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1963 bfd_get_filename (abfd
));
1966 /* A helper function that returns the size of a section in a safe way.
1967 If you are positive that the section has been read before using the
1968 size, then it is safe to refer to the dwarf2_section_info object's
1969 "size" field directly. In other cases, you must call this
1970 function, because for compressed sections the size field is not set
1971 correctly until the section has been read. */
1973 static bfd_size_type
1974 dwarf2_section_size (struct objfile
*objfile
,
1975 struct dwarf2_section_info
*info
)
1978 dwarf2_read_section (objfile
, info
);
1982 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1986 dwarf2_get_section_info (struct objfile
*objfile
,
1987 enum dwarf2_section_enum sect
,
1988 asection
**sectp
, gdb_byte
**bufp
,
1989 bfd_size_type
*sizep
)
1991 struct dwarf2_per_objfile
*data
1992 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1993 struct dwarf2_section_info
*info
;
1995 /* We may see an objfile without any DWARF, in which case we just
2006 case DWARF2_DEBUG_FRAME
:
2007 info
= &data
->frame
;
2009 case DWARF2_EH_FRAME
:
2010 info
= &data
->eh_frame
;
2013 gdb_assert_not_reached ("unexpected section");
2016 dwarf2_read_section (objfile
, info
);
2018 *sectp
= info
->asection
;
2019 *bufp
= info
->buffer
;
2020 *sizep
= info
->size
;
2023 /* A helper function to find the sections for a .dwz file. */
2026 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2028 struct dwz_file
*dwz_file
= arg
;
2030 /* Note that we only support the standard ELF names, because .dwz
2031 is ELF-only (at the time of writing). */
2032 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2034 dwz_file
->abbrev
.asection
= sectp
;
2035 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2037 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2039 dwz_file
->info
.asection
= sectp
;
2040 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2042 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2044 dwz_file
->str
.asection
= sectp
;
2045 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2047 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2049 dwz_file
->line
.asection
= sectp
;
2050 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2052 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2054 dwz_file
->macro
.asection
= sectp
;
2055 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2057 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2059 dwz_file
->gdb_index
.asection
= sectp
;
2060 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2064 /* Open the separate '.dwz' debug file, if needed. Error if the file
2067 static struct dwz_file
*
2068 dwarf2_get_dwz_file (void)
2070 bfd
*abfd
, *dwz_bfd
;
2073 struct cleanup
*cleanup
;
2074 const char *filename
;
2075 struct dwz_file
*result
;
2077 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2078 return dwarf2_per_objfile
->dwz_file
;
2080 abfd
= dwarf2_per_objfile
->objfile
->obfd
;
2081 section
= bfd_get_section_by_name (abfd
, ".gnu_debugaltlink");
2082 if (section
== NULL
)
2083 error (_("could not find '.gnu_debugaltlink' section"));
2084 if (!bfd_malloc_and_get_section (abfd
, section
, &data
))
2085 error (_("could not read '.gnu_debugaltlink' section: %s"),
2086 bfd_errmsg (bfd_get_error ()));
2087 cleanup
= make_cleanup (xfree
, data
);
2090 if (!IS_ABSOLUTE_PATH (filename
))
2092 char *abs
= gdb_realpath (dwarf2_per_objfile
->objfile
->name
);
2095 make_cleanup (xfree
, abs
);
2096 abs
= ldirname (abs
);
2097 make_cleanup (xfree
, abs
);
2099 rel
= concat (abs
, SLASH_STRING
, filename
, (char *) NULL
);
2100 make_cleanup (xfree
, rel
);
2104 /* The format is just a NUL-terminated file name, followed by the
2105 build-id. For now, though, we ignore the build-id. */
2106 dwz_bfd
= gdb_bfd_open (filename
, gnutarget
, -1);
2107 if (dwz_bfd
== NULL
)
2108 error (_("could not read '%s': %s"), filename
,
2109 bfd_errmsg (bfd_get_error ()));
2111 if (!bfd_check_format (dwz_bfd
, bfd_object
))
2113 gdb_bfd_unref (dwz_bfd
);
2114 error (_("file '%s' was not usable: %s"), filename
,
2115 bfd_errmsg (bfd_get_error ()));
2118 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2120 result
->dwz_bfd
= dwz_bfd
;
2122 bfd_map_over_sections (dwz_bfd
, locate_dwz_sections
, result
);
2124 do_cleanups (cleanup
);
2126 dwarf2_per_objfile
->dwz_file
= result
;
2130 /* DWARF quick_symbols_functions support. */
2132 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2133 unique line tables, so we maintain a separate table of all .debug_line
2134 derived entries to support the sharing.
2135 All the quick functions need is the list of file names. We discard the
2136 line_header when we're done and don't need to record it here. */
2137 struct quick_file_names
2139 /* The data used to construct the hash key. */
2140 struct stmt_list_hash hash
;
2142 /* The number of entries in file_names, real_names. */
2143 unsigned int num_file_names
;
2145 /* The file names from the line table, after being run through
2147 const char **file_names
;
2149 /* The file names from the line table after being run through
2150 gdb_realpath. These are computed lazily. */
2151 const char **real_names
;
2154 /* When using the index (and thus not using psymtabs), each CU has an
2155 object of this type. This is used to hold information needed by
2156 the various "quick" methods. */
2157 struct dwarf2_per_cu_quick_data
2159 /* The file table. This can be NULL if there was no file table
2160 or it's currently not read in.
2161 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2162 struct quick_file_names
*file_names
;
2164 /* The corresponding symbol table. This is NULL if symbols for this
2165 CU have not yet been read. */
2166 struct symtab
*symtab
;
2168 /* A temporary mark bit used when iterating over all CUs in
2169 expand_symtabs_matching. */
2170 unsigned int mark
: 1;
2172 /* True if we've tried to read the file table and found there isn't one.
2173 There will be no point in trying to read it again next time. */
2174 unsigned int no_file_data
: 1;
2177 /* Utility hash function for a stmt_list_hash. */
2180 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2184 if (stmt_list_hash
->dwo_unit
!= NULL
)
2185 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2186 v
+= stmt_list_hash
->line_offset
.sect_off
;
2190 /* Utility equality function for a stmt_list_hash. */
2193 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2194 const struct stmt_list_hash
*rhs
)
2196 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2198 if (lhs
->dwo_unit
!= NULL
2199 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2202 return lhs
->line_offset
.sect_off
== rhs
->line_offset
.sect_off
;
2205 /* Hash function for a quick_file_names. */
2208 hash_file_name_entry (const void *e
)
2210 const struct quick_file_names
*file_data
= e
;
2212 return hash_stmt_list_entry (&file_data
->hash
);
2215 /* Equality function for a quick_file_names. */
2218 eq_file_name_entry (const void *a
, const void *b
)
2220 const struct quick_file_names
*ea
= a
;
2221 const struct quick_file_names
*eb
= b
;
2223 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2226 /* Delete function for a quick_file_names. */
2229 delete_file_name_entry (void *e
)
2231 struct quick_file_names
*file_data
= e
;
2234 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2236 xfree ((void*) file_data
->file_names
[i
]);
2237 if (file_data
->real_names
)
2238 xfree ((void*) file_data
->real_names
[i
]);
2241 /* The space for the struct itself lives on objfile_obstack,
2242 so we don't free it here. */
2245 /* Create a quick_file_names hash table. */
2248 create_quick_file_names_table (unsigned int nr_initial_entries
)
2250 return htab_create_alloc (nr_initial_entries
,
2251 hash_file_name_entry
, eq_file_name_entry
,
2252 delete_file_name_entry
, xcalloc
, xfree
);
2255 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2256 have to be created afterwards. You should call age_cached_comp_units after
2257 processing PER_CU->CU. dw2_setup must have been already called. */
2260 load_cu (struct dwarf2_per_cu_data
*per_cu
)
2262 if (per_cu
->is_debug_types
)
2263 load_full_type_unit (per_cu
);
2265 load_full_comp_unit (per_cu
, language_minimal
);
2267 gdb_assert (per_cu
->cu
!= NULL
);
2269 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2272 /* Read in the symbols for PER_CU. */
2275 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2277 struct cleanup
*back_to
;
2279 /* Skip type_unit_groups, reading the type units they contain
2280 is handled elsewhere. */
2281 if (IS_TYPE_UNIT_GROUP (per_cu
))
2284 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2286 if (dwarf2_per_objfile
->using_index
2287 ? per_cu
->v
.quick
->symtab
== NULL
2288 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2290 queue_comp_unit (per_cu
, language_minimal
);
2296 /* Age the cache, releasing compilation units that have not
2297 been used recently. */
2298 age_cached_comp_units ();
2300 do_cleanups (back_to
);
2303 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2304 the objfile from which this CU came. Returns the resulting symbol
2307 static struct symtab
*
2308 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
2310 gdb_assert (dwarf2_per_objfile
->using_index
);
2311 if (!per_cu
->v
.quick
->symtab
)
2313 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2314 increment_reading_symtab ();
2315 dw2_do_instantiate_symtab (per_cu
);
2316 process_cu_includes ();
2317 do_cleanups (back_to
);
2319 return per_cu
->v
.quick
->symtab
;
2322 /* Return the CU given its index.
2324 This is intended for loops like:
2326 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2327 + dwarf2_per_objfile->n_type_units); ++i)
2329 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2335 static struct dwarf2_per_cu_data
*
2336 dw2_get_cu (int index
)
2338 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2340 index
-= dwarf2_per_objfile
->n_comp_units
;
2341 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
2342 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
2345 return dwarf2_per_objfile
->all_comp_units
[index
];
2348 /* Return the primary CU given its index.
2349 The difference between this function and dw2_get_cu is in the handling
2350 of type units (TUs). Here we return the type_unit_group object.
2352 This is intended for loops like:
2354 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2355 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2357 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2363 static struct dwarf2_per_cu_data
*
2364 dw2_get_primary_cu (int index
)
2366 if (index
>= dwarf2_per_objfile
->n_comp_units
)
2368 index
-= dwarf2_per_objfile
->n_comp_units
;
2369 gdb_assert (index
< dwarf2_per_objfile
->n_type_unit_groups
);
2370 return &dwarf2_per_objfile
->all_type_unit_groups
[index
]->per_cu
;
2373 return dwarf2_per_objfile
->all_comp_units
[index
];
2376 /* A helper for create_cus_from_index that handles a given list of
2380 create_cus_from_index_list (struct objfile
*objfile
,
2381 const gdb_byte
*cu_list
, offset_type n_elements
,
2382 struct dwarf2_section_info
*section
,
2388 for (i
= 0; i
< n_elements
; i
+= 2)
2390 struct dwarf2_per_cu_data
*the_cu
;
2391 ULONGEST offset
, length
;
2393 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2394 offset
= extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2395 length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2398 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2399 struct dwarf2_per_cu_data
);
2400 the_cu
->offset
.sect_off
= offset
;
2401 the_cu
->length
= length
;
2402 the_cu
->objfile
= objfile
;
2403 the_cu
->info_or_types_section
= section
;
2404 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2405 struct dwarf2_per_cu_quick_data
);
2406 the_cu
->is_dwz
= is_dwz
;
2407 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2] = the_cu
;
2411 /* Read the CU list from the mapped index, and use it to create all
2412 the CU objects for this objfile. */
2415 create_cus_from_index (struct objfile
*objfile
,
2416 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2417 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2419 struct dwz_file
*dwz
;
2421 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
2422 dwarf2_per_objfile
->all_comp_units
2423 = obstack_alloc (&objfile
->objfile_obstack
,
2424 dwarf2_per_objfile
->n_comp_units
2425 * sizeof (struct dwarf2_per_cu_data
*));
2427 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
2428 &dwarf2_per_objfile
->info
, 0, 0);
2430 if (dwz_elements
== 0)
2433 dwz
= dwarf2_get_dwz_file ();
2434 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
2435 cu_list_elements
/ 2);
2438 /* Create the signatured type hash table from the index. */
2441 create_signatured_type_table_from_index (struct objfile
*objfile
,
2442 struct dwarf2_section_info
*section
,
2443 const gdb_byte
*bytes
,
2444 offset_type elements
)
2447 htab_t sig_types_hash
;
2449 dwarf2_per_objfile
->n_type_units
= elements
/ 3;
2450 dwarf2_per_objfile
->all_type_units
2451 = obstack_alloc (&objfile
->objfile_obstack
,
2452 dwarf2_per_objfile
->n_type_units
2453 * sizeof (struct signatured_type
*));
2455 sig_types_hash
= allocate_signatured_type_table (objfile
);
2457 for (i
= 0; i
< elements
; i
+= 3)
2459 struct signatured_type
*sig_type
;
2460 ULONGEST offset
, type_offset_in_tu
, signature
;
2463 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2464 offset
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2465 type_offset_in_tu
= extract_unsigned_integer (bytes
+ 8, 8,
2467 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2470 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2471 struct signatured_type
);
2472 sig_type
->signature
= signature
;
2473 sig_type
->type_offset_in_tu
.cu_off
= type_offset_in_tu
;
2474 sig_type
->per_cu
.is_debug_types
= 1;
2475 sig_type
->per_cu
.info_or_types_section
= section
;
2476 sig_type
->per_cu
.offset
.sect_off
= offset
;
2477 sig_type
->per_cu
.objfile
= objfile
;
2478 sig_type
->per_cu
.v
.quick
2479 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2480 struct dwarf2_per_cu_quick_data
);
2482 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2485 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
2488 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2491 /* Read the address map data from the mapped index, and use it to
2492 populate the objfile's psymtabs_addrmap. */
2495 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
2497 const gdb_byte
*iter
, *end
;
2498 struct obstack temp_obstack
;
2499 struct addrmap
*mutable_map
;
2500 struct cleanup
*cleanup
;
2503 obstack_init (&temp_obstack
);
2504 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
2505 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2507 iter
= index
->address_table
;
2508 end
= iter
+ index
->address_table_size
;
2510 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2514 ULONGEST hi
, lo
, cu_index
;
2515 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2517 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2519 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2522 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
2523 dw2_get_cu (cu_index
));
2526 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
2527 &objfile
->objfile_obstack
);
2528 do_cleanups (cleanup
);
2531 /* The hash function for strings in the mapped index. This is the same as
2532 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2533 implementation. This is necessary because the hash function is tied to the
2534 format of the mapped index file. The hash values do not have to match with
2537 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2540 mapped_index_string_hash (int index_version
, const void *p
)
2542 const unsigned char *str
= (const unsigned char *) p
;
2546 while ((c
= *str
++) != 0)
2548 if (index_version
>= 5)
2550 r
= r
* 67 + c
- 113;
2556 /* Find a slot in the mapped index INDEX for the object named NAME.
2557 If NAME is found, set *VEC_OUT to point to the CU vector in the
2558 constant pool and return 1. If NAME cannot be found, return 0. */
2561 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2562 offset_type
**vec_out
)
2564 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2566 offset_type slot
, step
;
2567 int (*cmp
) (const char *, const char *);
2569 if (current_language
->la_language
== language_cplus
2570 || current_language
->la_language
== language_java
2571 || current_language
->la_language
== language_fortran
)
2573 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2575 const char *paren
= strchr (name
, '(');
2581 dup
= xmalloc (paren
- name
+ 1);
2582 memcpy (dup
, name
, paren
- name
);
2583 dup
[paren
- name
] = 0;
2585 make_cleanup (xfree
, dup
);
2590 /* Index version 4 did not support case insensitive searches. But the
2591 indices for case insensitive languages are built in lowercase, therefore
2592 simulate our NAME being searched is also lowercased. */
2593 hash
= mapped_index_string_hash ((index
->version
== 4
2594 && case_sensitivity
== case_sensitive_off
2595 ? 5 : index
->version
),
2598 slot
= hash
& (index
->symbol_table_slots
- 1);
2599 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2600 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2604 /* Convert a slot number to an offset into the table. */
2605 offset_type i
= 2 * slot
;
2607 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2609 do_cleanups (back_to
);
2613 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2614 if (!cmp (name
, str
))
2616 *vec_out
= (offset_type
*) (index
->constant_pool
2617 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2618 do_cleanups (back_to
);
2622 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2626 /* A helper function that reads the .gdb_index from SECTION and fills
2627 in MAP. FILENAME is the name of the file containing the section;
2628 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2629 ok to use deprecated sections.
2631 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2632 out parameters that are filled in with information about the CU and
2633 TU lists in the section.
2635 Returns 1 if all went well, 0 otherwise. */
2638 read_index_from_section (struct objfile
*objfile
,
2639 const char *filename
,
2641 struct dwarf2_section_info
*section
,
2642 struct mapped_index
*map
,
2643 const gdb_byte
**cu_list
,
2644 offset_type
*cu_list_elements
,
2645 const gdb_byte
**types_list
,
2646 offset_type
*types_list_elements
)
2649 offset_type version
;
2650 offset_type
*metadata
;
2653 if (dwarf2_section_empty_p (section
))
2656 /* Older elfutils strip versions could keep the section in the main
2657 executable while splitting it for the separate debug info file. */
2658 if ((bfd_get_file_flags (section
->asection
) & SEC_HAS_CONTENTS
) == 0)
2661 dwarf2_read_section (objfile
, section
);
2663 addr
= section
->buffer
;
2664 /* Version check. */
2665 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2666 /* Versions earlier than 3 emitted every copy of a psymbol. This
2667 causes the index to behave very poorly for certain requests. Version 3
2668 contained incomplete addrmap. So, it seems better to just ignore such
2672 static int warning_printed
= 0;
2673 if (!warning_printed
)
2675 warning (_("Skipping obsolete .gdb_index section in %s."),
2677 warning_printed
= 1;
2681 /* Index version 4 uses a different hash function than index version
2684 Versions earlier than 6 did not emit psymbols for inlined
2685 functions. Using these files will cause GDB not to be able to
2686 set breakpoints on inlined functions by name, so we ignore these
2687 indices unless the user has done
2688 "set use-deprecated-index-sections on". */
2689 if (version
< 6 && !deprecated_ok
)
2691 static int warning_printed
= 0;
2692 if (!warning_printed
)
2695 Skipping deprecated .gdb_index section in %s.\n\
2696 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2697 to use the section anyway."),
2699 warning_printed
= 1;
2703 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2704 of the TU (for symbols coming from TUs). It's just a performance bug, and
2705 we can't distinguish gdb-generated indices from gold-generated ones, so
2706 nothing to do here. */
2708 /* Indexes with higher version than the one supported by GDB may be no
2709 longer backward compatible. */
2713 map
->version
= version
;
2714 map
->total_size
= section
->size
;
2716 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2719 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2720 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2724 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2725 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2726 - MAYBE_SWAP (metadata
[i
]))
2730 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2731 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2732 - MAYBE_SWAP (metadata
[i
]));
2735 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2736 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2737 - MAYBE_SWAP (metadata
[i
]))
2738 / (2 * sizeof (offset_type
)));
2741 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2747 /* Read the index file. If everything went ok, initialize the "quick"
2748 elements of all the CUs and return 1. Otherwise, return 0. */
2751 dwarf2_read_index (struct objfile
*objfile
)
2753 struct mapped_index local_map
, *map
;
2754 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2755 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2757 if (!read_index_from_section (objfile
, objfile
->name
,
2758 use_deprecated_index_sections
,
2759 &dwarf2_per_objfile
->gdb_index
, &local_map
,
2760 &cu_list
, &cu_list_elements
,
2761 &types_list
, &types_list_elements
))
2764 /* Don't use the index if it's empty. */
2765 if (local_map
.symbol_table_slots
== 0)
2768 /* If there is a .dwz file, read it so we can get its CU list as
2770 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
2772 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
2773 struct mapped_index dwz_map
;
2774 const gdb_byte
*dwz_types_ignore
;
2775 offset_type dwz_types_elements_ignore
;
2777 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
2779 &dwz
->gdb_index
, &dwz_map
,
2780 &dwz_list
, &dwz_list_elements
,
2782 &dwz_types_elements_ignore
))
2784 warning (_("could not read '.gdb_index' section from %s; skipping"),
2785 bfd_get_filename (dwz
->dwz_bfd
));
2790 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
2793 if (types_list_elements
)
2795 struct dwarf2_section_info
*section
;
2797 /* We can only handle a single .debug_types when we have an
2799 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
2802 section
= VEC_index (dwarf2_section_info_def
,
2803 dwarf2_per_objfile
->types
, 0);
2805 create_signatured_type_table_from_index (objfile
, section
, types_list
,
2806 types_list_elements
);
2809 create_addrmap_from_index (objfile
, &local_map
);
2811 map
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct mapped_index
));
2814 dwarf2_per_objfile
->index_table
= map
;
2815 dwarf2_per_objfile
->using_index
= 1;
2816 dwarf2_per_objfile
->quick_file_names_table
=
2817 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2822 /* A helper for the "quick" functions which sets the global
2823 dwarf2_per_objfile according to OBJFILE. */
2826 dw2_setup (struct objfile
*objfile
)
2828 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2829 gdb_assert (dwarf2_per_objfile
);
2832 /* die_reader_func for dw2_get_file_names. */
2835 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
2837 struct die_info
*comp_unit_die
,
2841 struct dwarf2_cu
*cu
= reader
->cu
;
2842 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
2843 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2844 struct dwarf2_per_cu_data
*lh_cu
;
2845 struct line_header
*lh
;
2846 struct attribute
*attr
;
2848 const char *name
, *comp_dir
;
2850 struct quick_file_names
*qfn
;
2851 unsigned int line_offset
;
2853 /* Our callers never want to match partial units -- instead they
2854 will match the enclosing full CU. */
2855 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2857 this_cu
->v
.quick
->no_file_data
= 1;
2861 /* If we're reading the line header for TUs, store it in the "per_cu"
2863 if (this_cu
->is_debug_types
)
2865 struct type_unit_group
*tu_group
= data
;
2867 gdb_assert (tu_group
!= NULL
);
2868 lh_cu
= &tu_group
->per_cu
;
2877 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
2880 struct quick_file_names find_entry
;
2882 line_offset
= DW_UNSND (attr
);
2884 /* We may have already read in this line header (TU line header sharing).
2885 If we have we're done. */
2886 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
2887 find_entry
.hash
.line_offset
.sect_off
= line_offset
;
2888 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2889 &find_entry
, INSERT
);
2892 lh_cu
->v
.quick
->file_names
= *slot
;
2896 lh
= dwarf_decode_line_header (line_offset
, cu
);
2900 lh_cu
->v
.quick
->no_file_data
= 1;
2904 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2905 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
2906 qfn
->hash
.line_offset
.sect_off
= line_offset
;
2907 gdb_assert (slot
!= NULL
);
2910 find_file_and_directory (comp_unit_die
, cu
, &name
, &comp_dir
);
2912 qfn
->num_file_names
= lh
->num_file_names
;
2913 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2914 lh
->num_file_names
* sizeof (char *));
2915 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2916 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2917 qfn
->real_names
= NULL
;
2919 free_line_header (lh
);
2921 lh_cu
->v
.quick
->file_names
= qfn
;
2924 /* A helper for the "quick" functions which attempts to read the line
2925 table for THIS_CU. */
2927 static struct quick_file_names
*
2928 dw2_get_file_names (struct objfile
*objfile
,
2929 struct dwarf2_per_cu_data
*this_cu
)
2931 /* For TUs this should only be called on the parent group. */
2932 if (this_cu
->is_debug_types
)
2933 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu
));
2935 if (this_cu
->v
.quick
->file_names
!= NULL
)
2936 return this_cu
->v
.quick
->file_names
;
2937 /* If we know there is no line data, no point in looking again. */
2938 if (this_cu
->v
.quick
->no_file_data
)
2941 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2942 in the stub for CUs, there's is no need to lookup the DWO file.
2943 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2945 if (this_cu
->is_debug_types
)
2947 struct type_unit_group
*tu_group
= this_cu
->type_unit_group
;
2949 init_cutu_and_read_dies (tu_group
->t
.first_tu
, NULL
, 0, 0,
2950 dw2_get_file_names_reader
, tu_group
);
2953 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
2955 if (this_cu
->v
.quick
->no_file_data
)
2957 return this_cu
->v
.quick
->file_names
;
2960 /* A helper for the "quick" functions which computes and caches the
2961 real path for a given file name from the line table. */
2964 dw2_get_real_path (struct objfile
*objfile
,
2965 struct quick_file_names
*qfn
, int index
)
2967 if (qfn
->real_names
== NULL
)
2968 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2969 qfn
->num_file_names
, sizeof (char *));
2971 if (qfn
->real_names
[index
] == NULL
)
2972 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2974 return qfn
->real_names
[index
];
2977 static struct symtab
*
2978 dw2_find_last_source_symtab (struct objfile
*objfile
)
2982 dw2_setup (objfile
);
2983 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2984 return dw2_instantiate_symtab (dw2_get_cu (index
));
2987 /* Traversal function for dw2_forget_cached_source_info. */
2990 dw2_free_cached_file_names (void **slot
, void *info
)
2992 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2994 if (file_data
->real_names
)
2998 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3000 xfree ((void*) file_data
->real_names
[i
]);
3001 file_data
->real_names
[i
] = NULL
;
3009 dw2_forget_cached_source_info (struct objfile
*objfile
)
3011 dw2_setup (objfile
);
3013 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3014 dw2_free_cached_file_names
, NULL
);
3017 /* Helper function for dw2_map_symtabs_matching_filename that expands
3018 the symtabs and calls the iterator. */
3021 dw2_map_expand_apply (struct objfile
*objfile
,
3022 struct dwarf2_per_cu_data
*per_cu
,
3024 const char *full_path
, const char *real_path
,
3025 int (*callback
) (struct symtab
*, void *),
3028 struct symtab
*last_made
= objfile
->symtabs
;
3030 /* Don't visit already-expanded CUs. */
3031 if (per_cu
->v
.quick
->symtab
)
3034 /* This may expand more than one symtab, and we want to iterate over
3036 dw2_instantiate_symtab (per_cu
);
3038 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
3039 objfile
->symtabs
, last_made
);
3042 /* Implementation of the map_symtabs_matching_filename method. */
3045 dw2_map_symtabs_matching_filename (struct objfile
*objfile
, const char *name
,
3046 const char *full_path
, const char *real_path
,
3047 int (*callback
) (struct symtab
*, void *),
3051 const char *name_basename
= lbasename (name
);
3052 int is_abs
= IS_ABSOLUTE_PATH (name
);
3054 dw2_setup (objfile
);
3056 /* The rule is CUs specify all the files, including those used by
3057 any TU, so there's no need to scan TUs here. */
3059 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3062 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3063 struct quick_file_names
*file_data
;
3065 /* We only need to look at symtabs not already expanded. */
3066 if (per_cu
->v
.quick
->symtab
)
3069 file_data
= dw2_get_file_names (objfile
, per_cu
);
3070 if (file_data
== NULL
)
3073 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3075 const char *this_name
= file_data
->file_names
[j
];
3077 if (FILENAME_CMP (name
, this_name
) == 0
3078 || (!is_abs
&& compare_filenames_for_search (this_name
, name
)))
3080 if (dw2_map_expand_apply (objfile
, per_cu
,
3081 name
, full_path
, real_path
,
3086 /* Before we invoke realpath, which can get expensive when many
3087 files are involved, do a quick comparison of the basenames. */
3088 if (! basenames_may_differ
3089 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3092 if (full_path
!= NULL
)
3094 const char *this_real_name
= dw2_get_real_path (objfile
,
3097 if (this_real_name
!= NULL
3098 && (FILENAME_CMP (full_path
, this_real_name
) == 0
3100 && compare_filenames_for_search (this_real_name
,
3103 if (dw2_map_expand_apply (objfile
, per_cu
,
3104 name
, full_path
, real_path
,
3110 if (real_path
!= NULL
)
3112 const char *this_real_name
= dw2_get_real_path (objfile
,
3115 if (this_real_name
!= NULL
3116 && (FILENAME_CMP (real_path
, this_real_name
) == 0
3118 && compare_filenames_for_search (this_real_name
,
3121 if (dw2_map_expand_apply (objfile
, per_cu
,
3122 name
, full_path
, real_path
,
3133 /* Struct used to manage iterating over all CUs looking for a symbol. */
3135 struct dw2_symtab_iterator
3137 /* The internalized form of .gdb_index. */
3138 struct mapped_index
*index
;
3139 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3140 int want_specific_block
;
3141 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3142 Unused if !WANT_SPECIFIC_BLOCK. */
3144 /* The kind of symbol we're looking for. */
3146 /* The list of CUs from the index entry of the symbol,
3147 or NULL if not found. */
3149 /* The next element in VEC to look at. */
3151 /* The number of elements in VEC, or zero if there is no match. */
3155 /* Initialize the index symtab iterator ITER.
3156 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3157 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3160 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3161 struct mapped_index
*index
,
3162 int want_specific_block
,
3167 iter
->index
= index
;
3168 iter
->want_specific_block
= want_specific_block
;
3169 iter
->block_index
= block_index
;
3170 iter
->domain
= domain
;
3173 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3174 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3182 /* Return the next matching CU or NULL if there are no more. */
3184 static struct dwarf2_per_cu_data
*
3185 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3187 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3189 offset_type cu_index_and_attrs
=
3190 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3191 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3192 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
3193 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
3194 /* This value is only valid for index versions >= 7. */
3195 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3196 gdb_index_symbol_kind symbol_kind
=
3197 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3198 /* Only check the symbol attributes if they're present.
3199 Indices prior to version 7 don't record them,
3200 and indices >= 7 may elide them for certain symbols
3201 (gold does this). */
3203 (iter
->index
->version
>= 7
3204 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3206 /* Skip if already read in. */
3207 if (per_cu
->v
.quick
->symtab
)
3211 && iter
->want_specific_block
3212 && want_static
!= is_static
)
3215 /* Only check the symbol's kind if it has one. */
3218 switch (iter
->domain
)
3221 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3222 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3223 /* Some types are also in VAR_DOMAIN. */
3224 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3228 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3232 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3247 static struct symtab
*
3248 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
3249 const char *name
, domain_enum domain
)
3251 struct symtab
*stab_best
= NULL
;
3252 struct mapped_index
*index
;
3254 dw2_setup (objfile
);
3256 index
= dwarf2_per_objfile
->index_table
;
3258 /* index is NULL if OBJF_READNOW. */
3261 struct dw2_symtab_iterator iter
;
3262 struct dwarf2_per_cu_data
*per_cu
;
3264 dw2_symtab_iter_init (&iter
, index
, 1, block_index
, domain
, name
);
3266 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3268 struct symbol
*sym
= NULL
;
3269 struct symtab
*stab
= dw2_instantiate_symtab (per_cu
);
3271 /* Some caution must be observed with overloaded functions
3272 and methods, since the index will not contain any overload
3273 information (but NAME might contain it). */
3276 struct blockvector
*bv
= BLOCKVECTOR (stab
);
3277 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3279 sym
= lookup_block_symbol (block
, name
, domain
);
3282 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
3284 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
3290 /* Keep looking through other CUs. */
3298 dw2_print_stats (struct objfile
*objfile
)
3302 dw2_setup (objfile
);
3304 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3305 + dwarf2_per_objfile
->n_type_units
); ++i
)
3307 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3309 if (!per_cu
->v
.quick
->symtab
)
3312 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3316 dw2_dump (struct objfile
*objfile
)
3318 /* Nothing worth printing. */
3322 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
3323 struct section_offsets
*delta
)
3325 /* There's nothing to relocate here. */
3329 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3330 const char *func_name
)
3332 struct mapped_index
*index
;
3334 dw2_setup (objfile
);
3336 index
= dwarf2_per_objfile
->index_table
;
3338 /* index is NULL if OBJF_READNOW. */
3341 struct dw2_symtab_iterator iter
;
3342 struct dwarf2_per_cu_data
*per_cu
;
3344 /* Note: It doesn't matter what we pass for block_index here. */
3345 dw2_symtab_iter_init (&iter
, index
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
3348 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3349 dw2_instantiate_symtab (per_cu
);
3354 dw2_expand_all_symtabs (struct objfile
*objfile
)
3358 dw2_setup (objfile
);
3360 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3361 + dwarf2_per_objfile
->n_type_units
); ++i
)
3363 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3365 dw2_instantiate_symtab (per_cu
);
3370 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
3371 const char *filename
)
3375 dw2_setup (objfile
);
3377 /* We don't need to consider type units here.
3378 This is only called for examining code, e.g. expand_line_sal.
3379 There can be an order of magnitude (or more) more type units
3380 than comp units, and we avoid them if we can. */
3382 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3385 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3386 struct quick_file_names
*file_data
;
3388 /* We only need to look at symtabs not already expanded. */
3389 if (per_cu
->v
.quick
->symtab
)
3392 file_data
= dw2_get_file_names (objfile
, per_cu
);
3393 if (file_data
== NULL
)
3396 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3398 const char *this_name
= file_data
->file_names
[j
];
3399 if (FILENAME_CMP (this_name
, filename
) == 0)
3401 dw2_instantiate_symtab (per_cu
);
3408 /* A helper function for dw2_find_symbol_file that finds the primary
3409 file name for a given CU. This is a die_reader_func. */
3412 dw2_get_primary_filename_reader (const struct die_reader_specs
*reader
,
3414 struct die_info
*comp_unit_die
,
3418 const char **result_ptr
= data
;
3419 struct dwarf2_cu
*cu
= reader
->cu
;
3420 struct attribute
*attr
;
3422 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
3426 *result_ptr
= DW_STRING (attr
);
3430 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
3432 struct dwarf2_per_cu_data
*per_cu
;
3434 const char *filename
;
3436 dw2_setup (objfile
);
3438 /* index_table is NULL if OBJF_READNOW. */
3439 if (!dwarf2_per_objfile
->index_table
)
3443 ALL_OBJFILE_PRIMARY_SYMTABS (objfile
, s
)
3445 struct blockvector
*bv
= BLOCKVECTOR (s
);
3446 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
3447 struct symbol
*sym
= lookup_block_symbol (block
, name
, VAR_DOMAIN
);
3450 return SYMBOL_SYMTAB (sym
)->filename
;
3455 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
3459 /* Note that this just looks at the very first one named NAME -- but
3460 actually we are looking for a function. find_main_filename
3461 should be rewritten so that it doesn't require a custom hook. It
3462 could just use the ordinary symbol tables. */
3463 /* vec[0] is the length, which must always be >0. */
3464 per_cu
= dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec
[1])));
3466 if (per_cu
->v
.quick
->symtab
!= NULL
)
3467 return per_cu
->v
.quick
->symtab
->filename
;
3469 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
3470 dw2_get_primary_filename_reader
, &filename
);
3476 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
3477 struct objfile
*objfile
, int global
,
3478 int (*callback
) (struct block
*,
3479 struct symbol
*, void *),
3480 void *data
, symbol_compare_ftype
*match
,
3481 symbol_compare_ftype
*ordered_compare
)
3483 /* Currently unimplemented; used for Ada. The function can be called if the
3484 current language is Ada for a non-Ada objfile using GNU index. As Ada
3485 does not look for non-Ada symbols this function should just return. */
3489 dw2_expand_symtabs_matching
3490 (struct objfile
*objfile
,
3491 int (*file_matcher
) (const char *, void *),
3492 int (*name_matcher
) (const char *, void *),
3493 enum search_domain kind
,
3498 struct mapped_index
*index
;
3500 dw2_setup (objfile
);
3502 /* index_table is NULL if OBJF_READNOW. */
3503 if (!dwarf2_per_objfile
->index_table
)
3505 index
= dwarf2_per_objfile
->index_table
;
3507 if (file_matcher
!= NULL
)
3509 struct cleanup
*cleanup
;
3510 htab_t visited_found
, visited_not_found
;
3512 visited_found
= htab_create_alloc (10,
3513 htab_hash_pointer
, htab_eq_pointer
,
3514 NULL
, xcalloc
, xfree
);
3515 cleanup
= make_cleanup_htab_delete (visited_found
);
3516 visited_not_found
= htab_create_alloc (10,
3517 htab_hash_pointer
, htab_eq_pointer
,
3518 NULL
, xcalloc
, xfree
);
3519 make_cleanup_htab_delete (visited_not_found
);
3521 /* The rule is CUs specify all the files, including those used by
3522 any TU, so there's no need to scan TUs here. */
3524 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3527 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3528 struct quick_file_names
*file_data
;
3531 per_cu
->v
.quick
->mark
= 0;
3533 /* We only need to look at symtabs not already expanded. */
3534 if (per_cu
->v
.quick
->symtab
)
3537 file_data
= dw2_get_file_names (objfile
, per_cu
);
3538 if (file_data
== NULL
)
3541 if (htab_find (visited_not_found
, file_data
) != NULL
)
3543 else if (htab_find (visited_found
, file_data
) != NULL
)
3545 per_cu
->v
.quick
->mark
= 1;
3549 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3551 if (file_matcher (file_data
->file_names
[j
], data
))
3553 per_cu
->v
.quick
->mark
= 1;
3558 slot
= htab_find_slot (per_cu
->v
.quick
->mark
3560 : visited_not_found
,
3565 do_cleanups (cleanup
);
3568 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
3570 offset_type idx
= 2 * iter
;
3572 offset_type
*vec
, vec_len
, vec_idx
;
3574 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
3577 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
3579 if (! (*name_matcher
) (name
, data
))
3582 /* The name was matched, now expand corresponding CUs that were
3584 vec
= (offset_type
*) (index
->constant_pool
3585 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
3586 vec_len
= MAYBE_SWAP (vec
[0]);
3587 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
3589 struct dwarf2_per_cu_data
*per_cu
;
3590 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
3591 gdb_index_symbol_kind symbol_kind
=
3592 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3593 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3595 /* Don't crash on bad data. */
3596 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
3597 + dwarf2_per_objfile
->n_type_units
))
3600 /* Only check the symbol's kind if it has one.
3601 Indices prior to version 7 don't record it. */
3602 if (index
->version
>= 7)
3606 case VARIABLES_DOMAIN
:
3607 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
3610 case FUNCTIONS_DOMAIN
:
3611 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
3615 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3623 per_cu
= dw2_get_cu (cu_index
);
3624 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
3625 dw2_instantiate_symtab (per_cu
);
3630 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3633 static struct symtab
*
3634 recursively_find_pc_sect_symtab (struct symtab
*symtab
, CORE_ADDR pc
)
3638 if (BLOCKVECTOR (symtab
) != NULL
3639 && blockvector_contains_pc (BLOCKVECTOR (symtab
), pc
))
3642 if (symtab
->includes
== NULL
)
3645 for (i
= 0; symtab
->includes
[i
]; ++i
)
3647 struct symtab
*s
= symtab
->includes
[i
];
3649 s
= recursively_find_pc_sect_symtab (s
, pc
);
3657 static struct symtab
*
3658 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
3659 struct minimal_symbol
*msymbol
,
3661 struct obj_section
*section
,
3664 struct dwarf2_per_cu_data
*data
;
3665 struct symtab
*result
;
3667 dw2_setup (objfile
);
3669 if (!objfile
->psymtabs_addrmap
)
3672 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
3676 if (warn_if_readin
&& data
->v
.quick
->symtab
)
3677 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3678 paddress (get_objfile_arch (objfile
), pc
));
3680 result
= recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data
), pc
);
3681 gdb_assert (result
!= NULL
);
3686 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
3687 void *data
, int need_fullname
)
3690 struct cleanup
*cleanup
;
3691 htab_t visited
= htab_create_alloc (10, htab_hash_pointer
, htab_eq_pointer
,
3692 NULL
, xcalloc
, xfree
);
3694 cleanup
= make_cleanup_htab_delete (visited
);
3695 dw2_setup (objfile
);
3697 /* The rule is CUs specify all the files, including those used by
3698 any TU, so there's no need to scan TUs here.
3699 We can ignore file names coming from already-expanded CUs. */
3701 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3703 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3705 if (per_cu
->v
.quick
->symtab
)
3707 void **slot
= htab_find_slot (visited
, per_cu
->v
.quick
->file_names
,
3710 *slot
= per_cu
->v
.quick
->file_names
;
3714 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
3717 struct dwarf2_per_cu_data
*per_cu
= dw2_get_primary_cu (i
);
3718 struct quick_file_names
*file_data
;
3721 /* We only need to look at symtabs not already expanded. */
3722 if (per_cu
->v
.quick
->symtab
)
3725 file_data
= dw2_get_file_names (objfile
, per_cu
);
3726 if (file_data
== NULL
)
3729 slot
= htab_find_slot (visited
, file_data
, INSERT
);
3732 /* Already visited. */
3737 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
3739 const char *this_real_name
;
3742 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3744 this_real_name
= NULL
;
3745 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
3749 do_cleanups (cleanup
);
3753 dw2_has_symbols (struct objfile
*objfile
)
3758 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
3761 dw2_find_last_source_symtab
,
3762 dw2_forget_cached_source_info
,
3763 dw2_map_symtabs_matching_filename
,
3768 dw2_expand_symtabs_for_function
,
3769 dw2_expand_all_symtabs
,
3770 dw2_expand_symtabs_with_filename
,
3771 dw2_find_symbol_file
,
3772 dw2_map_matching_symbols
,
3773 dw2_expand_symtabs_matching
,
3774 dw2_find_pc_sect_symtab
,
3775 dw2_map_symbol_filenames
3778 /* Initialize for reading DWARF for this objfile. Return 0 if this
3779 file will use psymtabs, or 1 if using the GNU index. */
3782 dwarf2_initialize_objfile (struct objfile
*objfile
)
3784 /* If we're about to read full symbols, don't bother with the
3785 indices. In this case we also don't care if some other debug
3786 format is making psymtabs, because they are all about to be
3788 if ((objfile
->flags
& OBJF_READNOW
))
3792 dwarf2_per_objfile
->using_index
= 1;
3793 create_all_comp_units (objfile
);
3794 create_all_type_units (objfile
);
3795 dwarf2_per_objfile
->quick_file_names_table
=
3796 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3798 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
3799 + dwarf2_per_objfile
->n_type_units
); ++i
)
3801 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
3803 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3804 struct dwarf2_per_cu_quick_data
);
3807 /* Return 1 so that gdb sees the "quick" functions. However,
3808 these functions will be no-ops because we will have expanded
3813 if (dwarf2_read_index (objfile
))
3821 /* Build a partial symbol table. */
3824 dwarf2_build_psymtabs (struct objfile
*objfile
)
3826 volatile struct gdb_exception except
;
3828 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
3830 init_psymbol_list (objfile
, 1024);
3833 TRY_CATCH (except
, RETURN_MASK_ERROR
)
3835 /* This isn't really ideal: all the data we allocate on the
3836 objfile's obstack is still uselessly kept around. However,
3837 freeing it seems unsafe. */
3838 struct cleanup
*cleanups
= make_cleanup_discard_psymtabs (objfile
);
3840 dwarf2_build_psymtabs_hard (objfile
);
3841 discard_cleanups (cleanups
);
3843 if (except
.reason
< 0)
3844 exception_print (gdb_stderr
, except
);
3847 /* Return the total length of the CU described by HEADER. */
3850 get_cu_length (const struct comp_unit_head
*header
)
3852 return header
->initial_length_size
+ header
->length
;
3855 /* Return TRUE if OFFSET is within CU_HEADER. */
3858 offset_in_cu_p (const struct comp_unit_head
*cu_header
, sect_offset offset
)
3860 sect_offset bottom
= { cu_header
->offset
.sect_off
};
3861 sect_offset top
= { cu_header
->offset
.sect_off
+ get_cu_length (cu_header
) };
3863 return (offset
.sect_off
>= bottom
.sect_off
&& offset
.sect_off
< top
.sect_off
);
3866 /* Find the base address of the compilation unit for range lists and
3867 location lists. It will normally be specified by DW_AT_low_pc.
3868 In DWARF-3 draft 4, the base address could be overridden by
3869 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3870 compilation units with discontinuous ranges. */
3873 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3875 struct attribute
*attr
;
3878 cu
->base_address
= 0;
3880 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3883 cu
->base_address
= DW_ADDR (attr
);
3888 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3891 cu
->base_address
= DW_ADDR (attr
);
3897 /* Read in the comp unit header information from the debug_info at info_ptr.
3898 NOTE: This leaves members offset, first_die_offset to be filled in
3902 read_comp_unit_head (struct comp_unit_head
*cu_header
,
3903 gdb_byte
*info_ptr
, bfd
*abfd
)
3906 unsigned int bytes_read
;
3908 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
3909 cu_header
->initial_length_size
= bytes_read
;
3910 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
3911 info_ptr
+= bytes_read
;
3912 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
3914 cu_header
->abbrev_offset
.sect_off
= read_offset (abfd
, info_ptr
, cu_header
,
3916 info_ptr
+= bytes_read
;
3917 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
3919 signed_addr
= bfd_get_sign_extend_vma (abfd
);
3920 if (signed_addr
< 0)
3921 internal_error (__FILE__
, __LINE__
,
3922 _("read_comp_unit_head: dwarf from non elf file"));
3923 cu_header
->signed_addr_p
= signed_addr
;
3928 /* Helper function that returns the proper abbrev section for
3931 static struct dwarf2_section_info
*
3932 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
3934 struct dwarf2_section_info
*abbrev
;
3936 if (this_cu
->is_dwz
)
3937 abbrev
= &dwarf2_get_dwz_file ()->abbrev
;
3939 abbrev
= &dwarf2_per_objfile
->abbrev
;
3944 /* Subroutine of read_and_check_comp_unit_head and
3945 read_and_check_type_unit_head to simplify them.
3946 Perform various error checking on the header. */
3949 error_check_comp_unit_head (struct comp_unit_head
*header
,
3950 struct dwarf2_section_info
*section
,
3951 struct dwarf2_section_info
*abbrev_section
)
3953 bfd
*abfd
= section
->asection
->owner
;
3954 const char *filename
= bfd_get_filename (abfd
);
3956 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
3957 error (_("Dwarf Error: wrong version in compilation unit header "
3958 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
3961 if (header
->abbrev_offset
.sect_off
3962 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
3963 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3964 "(offset 0x%lx + 6) [in module %s]"),
3965 (long) header
->abbrev_offset
.sect_off
, (long) header
->offset
.sect_off
,
3968 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3969 avoid potential 32-bit overflow. */
3970 if (((unsigned long) header
->offset
.sect_off
+ get_cu_length (header
))
3972 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3973 "(offset 0x%lx + 0) [in module %s]"),
3974 (long) header
->length
, (long) header
->offset
.sect_off
,
3978 /* Read in a CU/TU header and perform some basic error checking.
3979 The contents of the header are stored in HEADER.
3980 The result is a pointer to the start of the first DIE. */
3983 read_and_check_comp_unit_head (struct comp_unit_head
*header
,
3984 struct dwarf2_section_info
*section
,
3985 struct dwarf2_section_info
*abbrev_section
,
3987 int is_debug_types_section
)
3989 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3990 bfd
*abfd
= section
->asection
->owner
;
3992 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
3994 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
3996 /* If we're reading a type unit, skip over the signature and
3997 type_offset fields. */
3998 if (is_debug_types_section
)
3999 info_ptr
+= 8 /*signature*/ + header
->offset_size
;
4001 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4003 error_check_comp_unit_head (header
, section
, abbrev_section
);
4008 /* Read in the types comp unit header information from .debug_types entry at
4009 types_ptr. The result is a pointer to one past the end of the header. */
4012 read_and_check_type_unit_head (struct comp_unit_head
*header
,
4013 struct dwarf2_section_info
*section
,
4014 struct dwarf2_section_info
*abbrev_section
,
4016 ULONGEST
*signature
,
4017 cu_offset
*type_offset_in_tu
)
4019 gdb_byte
*beg_of_comp_unit
= info_ptr
;
4020 bfd
*abfd
= section
->asection
->owner
;
4022 header
->offset
.sect_off
= beg_of_comp_unit
- section
->buffer
;
4024 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
4026 /* If we're reading a type unit, skip over the signature and
4027 type_offset fields. */
4028 if (signature
!= NULL
)
4029 *signature
= read_8_bytes (abfd
, info_ptr
);
4031 if (type_offset_in_tu
!= NULL
)
4032 type_offset_in_tu
->cu_off
= read_offset_1 (abfd
, info_ptr
,
4033 header
->offset_size
);
4034 info_ptr
+= header
->offset_size
;
4036 header
->first_die_offset
.cu_off
= info_ptr
- beg_of_comp_unit
;
4038 error_check_comp_unit_head (header
, section
, abbrev_section
);
4043 /* Fetch the abbreviation table offset from a comp or type unit header. */
4046 read_abbrev_offset (struct dwarf2_section_info
*section
,
4049 bfd
*abfd
= section
->asection
->owner
;
4051 unsigned int length
, initial_length_size
, offset_size
;
4052 sect_offset abbrev_offset
;
4054 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
4055 info_ptr
= section
->buffer
+ offset
.sect_off
;
4056 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
4057 offset_size
= initial_length_size
== 4 ? 4 : 8;
4058 info_ptr
+= initial_length_size
+ 2 /*version*/;
4059 abbrev_offset
.sect_off
= read_offset_1 (abfd
, info_ptr
, offset_size
);
4060 return abbrev_offset
;
4063 /* Allocate a new partial symtab for file named NAME and mark this new
4064 partial symtab as being an include of PST. */
4067 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
4068 struct objfile
*objfile
)
4070 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
4072 subpst
->section_offsets
= pst
->section_offsets
;
4073 subpst
->textlow
= 0;
4074 subpst
->texthigh
= 0;
4076 subpst
->dependencies
= (struct partial_symtab
**)
4077 obstack_alloc (&objfile
->objfile_obstack
,
4078 sizeof (struct partial_symtab
*));
4079 subpst
->dependencies
[0] = pst
;
4080 subpst
->number_of_dependencies
= 1;
4082 subpst
->globals_offset
= 0;
4083 subpst
->n_global_syms
= 0;
4084 subpst
->statics_offset
= 0;
4085 subpst
->n_static_syms
= 0;
4086 subpst
->symtab
= NULL
;
4087 subpst
->read_symtab
= pst
->read_symtab
;
4090 /* No private part is necessary for include psymtabs. This property
4091 can be used to differentiate between such include psymtabs and
4092 the regular ones. */
4093 subpst
->read_symtab_private
= NULL
;
4096 /* Read the Line Number Program data and extract the list of files
4097 included by the source file represented by PST. Build an include
4098 partial symtab for each of these included files. */
4101 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
4102 struct die_info
*die
,
4103 struct partial_symtab
*pst
)
4105 struct line_header
*lh
= NULL
;
4106 struct attribute
*attr
;
4108 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4110 lh
= dwarf_decode_line_header (DW_UNSND (attr
), cu
);
4112 return; /* No linetable, so no includes. */
4114 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4115 dwarf_decode_lines (lh
, pst
->dirname
, cu
, pst
, 1);
4117 free_line_header (lh
);
4121 hash_signatured_type (const void *item
)
4123 const struct signatured_type
*sig_type
= item
;
4125 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4126 return sig_type
->signature
;
4130 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
4132 const struct signatured_type
*lhs
= item_lhs
;
4133 const struct signatured_type
*rhs
= item_rhs
;
4135 return lhs
->signature
== rhs
->signature
;
4138 /* Allocate a hash table for signatured types. */
4141 allocate_signatured_type_table (struct objfile
*objfile
)
4143 return htab_create_alloc_ex (41,
4144 hash_signatured_type
,
4147 &objfile
->objfile_obstack
,
4148 hashtab_obstack_allocate
,
4149 dummy_obstack_deallocate
);
4152 /* A helper function to add a signatured type CU to a table. */
4155 add_signatured_type_cu_to_table (void **slot
, void *datum
)
4157 struct signatured_type
*sigt
= *slot
;
4158 struct signatured_type
***datap
= datum
;
4166 /* Create the hash table of all entries in the .debug_types section.
4167 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4169 Note: This function processes DWO files only, not DWP files.
4170 The result is a pointer to the hash table or NULL if there are
4174 create_debug_types_hash_table (struct dwo_file
*dwo_file
,
4175 VEC (dwarf2_section_info_def
) *types
)
4177 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4178 htab_t types_htab
= NULL
;
4180 struct dwarf2_section_info
*section
;
4181 struct dwarf2_section_info
*abbrev_section
;
4183 if (VEC_empty (dwarf2_section_info_def
, types
))
4186 abbrev_section
= (dwo_file
!= NULL
4187 ? &dwo_file
->sections
.abbrev
4188 : &dwarf2_per_objfile
->abbrev
);
4190 if (dwarf2_read_debug
)
4191 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_types%s for %s:\n",
4192 dwo_file
? ".dwo" : "",
4193 bfd_get_filename (abbrev_section
->asection
->owner
));
4196 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
4200 gdb_byte
*info_ptr
, *end_ptr
;
4201 struct dwarf2_section_info
*abbrev_section
;
4203 dwarf2_read_section (objfile
, section
);
4204 info_ptr
= section
->buffer
;
4206 if (info_ptr
== NULL
)
4209 /* We can't set abfd until now because the section may be empty or
4210 not present, in which case section->asection will be NULL. */
4211 abfd
= section
->asection
->owner
;
4214 abbrev_section
= &dwo_file
->sections
.abbrev
;
4216 abbrev_section
= &dwarf2_per_objfile
->abbrev
;
4218 if (types_htab
== NULL
)
4221 types_htab
= allocate_dwo_unit_table (objfile
);
4223 types_htab
= allocate_signatured_type_table (objfile
);
4226 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4227 because we don't need to read any dies: the signature is in the
4230 end_ptr
= info_ptr
+ section
->size
;
4231 while (info_ptr
< end_ptr
)
4234 cu_offset type_offset_in_tu
;
4236 struct signatured_type
*sig_type
;
4237 struct dwo_unit
*dwo_tu
;
4239 gdb_byte
*ptr
= info_ptr
;
4240 struct comp_unit_head header
;
4241 unsigned int length
;
4243 offset
.sect_off
= ptr
- section
->buffer
;
4245 /* We need to read the type's signature in order to build the hash
4246 table, but we don't need anything else just yet. */
4248 ptr
= read_and_check_type_unit_head (&header
, section
,
4249 abbrev_section
, ptr
,
4250 &signature
, &type_offset_in_tu
);
4252 length
= get_cu_length (&header
);
4254 /* Skip dummy type units. */
4255 if (ptr
>= info_ptr
+ length
4256 || peek_abbrev_code (abfd
, ptr
) == 0)
4265 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4267 dwo_tu
->dwo_file
= dwo_file
;
4268 dwo_tu
->signature
= signature
;
4269 dwo_tu
->type_offset_in_tu
= type_offset_in_tu
;
4270 dwo_tu
->info_or_types_section
= section
;
4271 dwo_tu
->offset
= offset
;
4272 dwo_tu
->length
= length
;
4276 /* N.B.: type_offset is not usable if this type uses a DWO file.
4277 The real type_offset is in the DWO file. */
4279 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
4280 struct signatured_type
);
4281 sig_type
->signature
= signature
;
4282 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
4283 sig_type
->per_cu
.objfile
= objfile
;
4284 sig_type
->per_cu
.is_debug_types
= 1;
4285 sig_type
->per_cu
.info_or_types_section
= section
;
4286 sig_type
->per_cu
.offset
= offset
;
4287 sig_type
->per_cu
.length
= length
;
4290 slot
= htab_find_slot (types_htab
,
4291 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
4293 gdb_assert (slot
!= NULL
);
4296 sect_offset dup_offset
;
4300 const struct dwo_unit
*dup_tu
= *slot
;
4302 dup_offset
= dup_tu
->offset
;
4306 const struct signatured_type
*dup_tu
= *slot
;
4308 dup_offset
= dup_tu
->per_cu
.offset
;
4311 complaint (&symfile_complaints
,
4312 _("debug type entry at offset 0x%x is duplicate to the "
4313 "entry at offset 0x%x, signature 0x%s"),
4314 offset
.sect_off
, dup_offset
.sect_off
,
4315 phex (signature
, sizeof (signature
)));
4317 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
4319 if (dwarf2_read_debug
)
4320 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
4322 phex (signature
, sizeof (signature
)));
4331 /* Create the hash table of all entries in the .debug_types section,
4332 and initialize all_type_units.
4333 The result is zero if there is an error (e.g. missing .debug_types section),
4334 otherwise non-zero. */
4337 create_all_type_units (struct objfile
*objfile
)
4340 struct signatured_type
**iter
;
4342 types_htab
= create_debug_types_hash_table (NULL
, dwarf2_per_objfile
->types
);
4343 if (types_htab
== NULL
)
4345 dwarf2_per_objfile
->signatured_types
= NULL
;
4349 dwarf2_per_objfile
->signatured_types
= types_htab
;
4351 dwarf2_per_objfile
->n_type_units
= htab_elements (types_htab
);
4352 dwarf2_per_objfile
->all_type_units
4353 = obstack_alloc (&objfile
->objfile_obstack
,
4354 dwarf2_per_objfile
->n_type_units
4355 * sizeof (struct signatured_type
*));
4356 iter
= &dwarf2_per_objfile
->all_type_units
[0];
4357 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
4358 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
4359 == dwarf2_per_objfile
->n_type_units
);
4364 /* Lookup a signature based type for DW_FORM_ref_sig8.
4365 Returns NULL if signature SIG is not present in the table. */
4367 static struct signatured_type
*
4368 lookup_signatured_type (ULONGEST sig
)
4370 struct signatured_type find_entry
, *entry
;
4372 if (dwarf2_per_objfile
->signatured_types
== NULL
)
4374 complaint (&symfile_complaints
,
4375 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4379 find_entry
.signature
= sig
;
4380 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
4384 /* Low level DIE reading support. */
4386 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4389 init_cu_die_reader (struct die_reader_specs
*reader
,
4390 struct dwarf2_cu
*cu
,
4391 struct dwarf2_section_info
*section
,
4392 struct dwo_file
*dwo_file
)
4394 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
4395 reader
->abfd
= section
->asection
->owner
;
4397 reader
->dwo_file
= dwo_file
;
4398 reader
->die_section
= section
;
4399 reader
->buffer
= section
->buffer
;
4400 reader
->buffer_end
= section
->buffer
+ section
->size
;
4403 /* Initialize a CU (or TU) and read its DIEs.
4404 If the CU defers to a DWO file, read the DWO file as well.
4406 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4407 Otherwise the table specified in the comp unit header is read in and used.
4408 This is an optimization for when we already have the abbrev table.
4410 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4411 Otherwise, a new CU is allocated with xmalloc.
4413 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4414 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4416 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4417 linker) then DIE_READER_FUNC will not get called. */
4420 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
4421 struct abbrev_table
*abbrev_table
,
4422 int use_existing_cu
, int keep
,
4423 die_reader_func_ftype
*die_reader_func
,
4426 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4427 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4428 bfd
*abfd
= section
->asection
->owner
;
4429 struct dwarf2_cu
*cu
;
4430 gdb_byte
*begin_info_ptr
, *info_ptr
;
4431 struct die_reader_specs reader
;
4432 struct die_info
*comp_unit_die
;
4434 struct attribute
*attr
;
4435 struct cleanup
*cleanups
, *free_cu_cleanup
= NULL
;
4436 struct signatured_type
*sig_type
= NULL
;
4437 struct dwarf2_section_info
*abbrev_section
;
4438 /* Non-zero if CU currently points to a DWO file and we need to
4439 reread it. When this happens we need to reread the skeleton die
4440 before we can reread the DWO file. */
4441 int rereading_dwo_cu
= 0;
4443 if (dwarf2_die_debug
)
4444 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4445 this_cu
->is_debug_types
? "type" : "comp",
4446 this_cu
->offset
.sect_off
);
4448 if (use_existing_cu
)
4451 cleanups
= make_cleanup (null_cleanup
, NULL
);
4453 /* This is cheap if the section is already read in. */
4454 dwarf2_read_section (objfile
, section
);
4456 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4458 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
4460 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
4464 /* If this CU is from a DWO file we need to start over, we need to
4465 refetch the attributes from the skeleton CU.
4466 This could be optimized by retrieving those attributes from when we
4467 were here the first time: the previous comp_unit_die was stored in
4468 comp_unit_obstack. But there's no data yet that we need this
4470 if (cu
->dwo_unit
!= NULL
)
4471 rereading_dwo_cu
= 1;
4475 /* If !use_existing_cu, this_cu->cu must be NULL. */
4476 gdb_assert (this_cu
->cu
== NULL
);
4478 cu
= xmalloc (sizeof (*cu
));
4479 init_one_comp_unit (cu
, this_cu
);
4481 /* If an error occurs while loading, release our storage. */
4482 free_cu_cleanup
= make_cleanup (free_heap_comp_unit
, cu
);
4485 if (cu
->header
.first_die_offset
.cu_off
!= 0 && ! rereading_dwo_cu
)
4487 /* We already have the header, there's no need to read it in again. */
4488 info_ptr
+= cu
->header
.first_die_offset
.cu_off
;
4492 if (this_cu
->is_debug_types
)
4495 cu_offset type_offset_in_tu
;
4497 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4498 abbrev_section
, info_ptr
,
4500 &type_offset_in_tu
);
4502 /* Since per_cu is the first member of struct signatured_type,
4503 we can go from a pointer to one to a pointer to the other. */
4504 sig_type
= (struct signatured_type
*) this_cu
;
4505 gdb_assert (sig_type
->signature
== signature
);
4506 gdb_assert (sig_type
->type_offset_in_tu
.cu_off
4507 == type_offset_in_tu
.cu_off
);
4508 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4510 /* LENGTH has not been set yet for type units if we're
4511 using .gdb_index. */
4512 this_cu
->length
= get_cu_length (&cu
->header
);
4514 /* Establish the type offset that can be used to lookup the type. */
4515 sig_type
->type_offset_in_section
.sect_off
=
4516 this_cu
->offset
.sect_off
+ sig_type
->type_offset_in_tu
.cu_off
;
4520 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4524 gdb_assert (this_cu
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4525 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
4529 /* Skip dummy compilation units. */
4530 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4531 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4533 do_cleanups (cleanups
);
4537 /* If we don't have them yet, read the abbrevs for this compilation unit.
4538 And if we need to read them now, make sure they're freed when we're
4539 done. Note that it's important that if the CU had an abbrev table
4540 on entry we don't free it when we're done: Somewhere up the call stack
4541 it may be in use. */
4542 if (abbrev_table
!= NULL
)
4544 gdb_assert (cu
->abbrev_table
== NULL
);
4545 gdb_assert (cu
->header
.abbrev_offset
.sect_off
4546 == abbrev_table
->offset
.sect_off
);
4547 cu
->abbrev_table
= abbrev_table
;
4549 else if (cu
->abbrev_table
== NULL
)
4551 dwarf2_read_abbrevs (cu
, abbrev_section
);
4552 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4554 else if (rereading_dwo_cu
)
4556 dwarf2_free_abbrev_table (cu
);
4557 dwarf2_read_abbrevs (cu
, abbrev_section
);
4560 /* Read the top level CU/TU die. */
4561 init_cu_die_reader (&reader
, cu
, section
, NULL
);
4562 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4564 /* If we have a DWO stub, process it and then read in the DWO file.
4565 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4566 a DWO CU, that this test will fail. */
4567 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
4570 const char *dwo_name
= DW_STRING (attr
);
4571 const char *comp_dir_string
;
4572 struct dwo_unit
*dwo_unit
;
4573 ULONGEST signature
; /* Or dwo_id. */
4574 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
4575 int i
,num_extra_attrs
;
4576 struct dwarf2_section_info
*dwo_abbrev_section
;
4579 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4580 " has children (offset 0x%x) [in module %s]"),
4581 this_cu
->offset
.sect_off
, bfd_get_filename (abfd
));
4583 /* These attributes aren't processed until later:
4584 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4585 However, the attribute is found in the stub which we won't have later.
4586 In order to not impose this complication on the rest of the code,
4587 we read them here and copy them to the DWO CU/TU die. */
4589 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4592 if (! this_cu
->is_debug_types
)
4593 stmt_list
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4594 low_pc
= dwarf2_attr (comp_unit_die
, DW_AT_low_pc
, cu
);
4595 high_pc
= dwarf2_attr (comp_unit_die
, DW_AT_high_pc
, cu
);
4596 ranges
= dwarf2_attr (comp_unit_die
, DW_AT_ranges
, cu
);
4597 comp_dir
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4599 /* There should be a DW_AT_addr_base attribute here (if needed).
4600 We need the value before we can process DW_FORM_GNU_addr_index. */
4602 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
4604 cu
->addr_base
= DW_UNSND (attr
);
4606 /* There should be a DW_AT_ranges_base attribute here (if needed).
4607 We need the value before we can process DW_AT_ranges. */
4608 cu
->ranges_base
= 0;
4609 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
4611 cu
->ranges_base
= DW_UNSND (attr
);
4613 if (this_cu
->is_debug_types
)
4615 gdb_assert (sig_type
!= NULL
);
4616 signature
= sig_type
->signature
;
4620 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
4622 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4624 signature
= DW_UNSND (attr
);
4627 /* We may need the comp_dir in order to find the DWO file. */
4628 comp_dir_string
= NULL
;
4630 comp_dir_string
= DW_STRING (comp_dir
);
4632 if (this_cu
->is_debug_types
)
4633 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir_string
);
4635 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir_string
,
4638 if (dwo_unit
== NULL
)
4640 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4641 " with ID %s [in module %s]"),
4642 this_cu
->offset
.sect_off
,
4643 phex (signature
, sizeof (signature
)),
4647 /* Set up for reading the DWO CU/TU. */
4648 cu
->dwo_unit
= dwo_unit
;
4649 section
= dwo_unit
->info_or_types_section
;
4650 dwarf2_read_section (objfile
, section
);
4651 begin_info_ptr
= info_ptr
= section
->buffer
+ dwo_unit
->offset
.sect_off
;
4652 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
4653 init_cu_die_reader (&reader
, cu
, section
, dwo_unit
->dwo_file
);
4655 if (this_cu
->is_debug_types
)
4658 cu_offset type_offset_in_tu
;
4660 info_ptr
= read_and_check_type_unit_head (&cu
->header
, section
,
4664 &type_offset_in_tu
);
4665 gdb_assert (sig_type
->signature
== signature
);
4666 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4667 /* For DWOs coming from DWP files, we don't know the CU length
4668 nor the type's offset in the TU until now. */
4669 dwo_unit
->length
= get_cu_length (&cu
->header
);
4670 dwo_unit
->type_offset_in_tu
= type_offset_in_tu
;
4672 /* Establish the type offset that can be used to lookup the type.
4673 For DWO files, we don't know it until now. */
4674 sig_type
->type_offset_in_section
.sect_off
=
4675 dwo_unit
->offset
.sect_off
+ dwo_unit
->type_offset_in_tu
.cu_off
;
4679 info_ptr
= read_and_check_comp_unit_head (&cu
->header
, section
,
4682 gdb_assert (dwo_unit
->offset
.sect_off
== cu
->header
.offset
.sect_off
);
4683 /* For DWOs coming from DWP files, we don't know the CU length
4685 dwo_unit
->length
= get_cu_length (&cu
->header
);
4688 /* Discard the original CU's abbrev table, and read the DWO's. */
4689 if (abbrev_table
== NULL
)
4691 dwarf2_free_abbrev_table (cu
);
4692 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4696 dwarf2_read_abbrevs (cu
, dwo_abbrev_section
);
4697 make_cleanup (dwarf2_free_abbrev_table
, cu
);
4700 /* Read in the die, but leave space to copy over the attributes
4701 from the stub. This has the benefit of simplifying the rest of
4702 the code - all the real work is done here. */
4703 num_extra_attrs
= ((stmt_list
!= NULL
)
4707 + (comp_dir
!= NULL
));
4708 info_ptr
= read_full_die_1 (&reader
, &comp_unit_die
, info_ptr
,
4709 &has_children
, num_extra_attrs
);
4711 /* Copy over the attributes from the stub to the DWO die. */
4712 i
= comp_unit_die
->num_attrs
;
4713 if (stmt_list
!= NULL
)
4714 comp_unit_die
->attrs
[i
++] = *stmt_list
;
4716 comp_unit_die
->attrs
[i
++] = *low_pc
;
4717 if (high_pc
!= NULL
)
4718 comp_unit_die
->attrs
[i
++] = *high_pc
;
4720 comp_unit_die
->attrs
[i
++] = *ranges
;
4721 if (comp_dir
!= NULL
)
4722 comp_unit_die
->attrs
[i
++] = *comp_dir
;
4723 comp_unit_die
->num_attrs
+= num_extra_attrs
;
4725 /* Skip dummy compilation units. */
4726 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
4727 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4729 do_cleanups (cleanups
);
4734 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4736 if (free_cu_cleanup
!= NULL
)
4740 /* We've successfully allocated this compilation unit. Let our
4741 caller clean it up when finished with it. */
4742 discard_cleanups (free_cu_cleanup
);
4744 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4745 So we have to manually free the abbrev table. */
4746 dwarf2_free_abbrev_table (cu
);
4748 /* Link this CU into read_in_chain. */
4749 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4750 dwarf2_per_objfile
->read_in_chain
= this_cu
;
4753 do_cleanups (free_cu_cleanup
);
4756 do_cleanups (cleanups
);
4759 /* Read CU/TU THIS_CU in section SECTION,
4760 but do not follow DW_AT_GNU_dwo_name if present.
4761 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4762 to have already done the lookup to find the DWO/DWP file).
4764 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4765 THIS_CU->is_debug_types, but nothing else.
4767 We fill in THIS_CU->length.
4769 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4770 linker) then DIE_READER_FUNC will not get called.
4772 THIS_CU->cu is always freed when done.
4773 This is done in order to not leave THIS_CU->cu in a state where we have
4774 to care whether it refers to the "main" CU or the DWO CU. */
4777 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
4778 struct dwarf2_section_info
*abbrev_section
,
4779 struct dwo_file
*dwo_file
,
4780 die_reader_func_ftype
*die_reader_func
,
4783 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4784 struct dwarf2_section_info
*section
= this_cu
->info_or_types_section
;
4785 bfd
*abfd
= section
->asection
->owner
;
4786 struct dwarf2_cu cu
;
4787 gdb_byte
*begin_info_ptr
, *info_ptr
;
4788 struct die_reader_specs reader
;
4789 struct cleanup
*cleanups
;
4790 struct die_info
*comp_unit_die
;
4793 if (dwarf2_die_debug
)
4794 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
4795 this_cu
->is_debug_types
? "type" : "comp",
4796 this_cu
->offset
.sect_off
);
4798 gdb_assert (this_cu
->cu
== NULL
);
4800 /* This is cheap if the section is already read in. */
4801 dwarf2_read_section (objfile
, section
);
4803 init_one_comp_unit (&cu
, this_cu
);
4805 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
4807 begin_info_ptr
= info_ptr
= section
->buffer
+ this_cu
->offset
.sect_off
;
4808 info_ptr
= read_and_check_comp_unit_head (&cu
.header
, section
,
4809 abbrev_section
, info_ptr
,
4810 this_cu
->is_debug_types
);
4812 this_cu
->length
= get_cu_length (&cu
.header
);
4814 /* Skip dummy compilation units. */
4815 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
4816 || peek_abbrev_code (abfd
, info_ptr
) == 0)
4818 do_cleanups (cleanups
);
4822 dwarf2_read_abbrevs (&cu
, abbrev_section
);
4823 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
4825 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
);
4826 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
4828 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
4830 do_cleanups (cleanups
);
4833 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4834 does not lookup the specified DWO file.
4835 This cannot be used to read DWO files.
4837 THIS_CU->cu is always freed when done.
4838 This is done in order to not leave THIS_CU->cu in a state where we have
4839 to care whether it refers to the "main" CU or the DWO CU.
4840 We can revisit this if the data shows there's a performance issue. */
4843 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
4844 die_reader_func_ftype
*die_reader_func
,
4847 init_cutu_and_read_dies_no_follow (this_cu
,
4848 get_abbrev_section_for_cu (this_cu
),
4850 die_reader_func
, data
);
4853 /* Create a psymtab named NAME and assign it to PER_CU.
4855 The caller must fill in the following details:
4856 dirname, textlow, texthigh. */
4858 static struct partial_symtab
*
4859 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
4861 struct objfile
*objfile
= per_cu
->objfile
;
4862 struct partial_symtab
*pst
;
4864 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
4866 objfile
->global_psymbols
.next
,
4867 objfile
->static_psymbols
.next
);
4869 pst
->psymtabs_addrmap_supported
= 1;
4871 /* This is the glue that links PST into GDB's symbol API. */
4872 pst
->read_symtab_private
= per_cu
;
4873 pst
->read_symtab
= dwarf2_read_symtab
;
4874 per_cu
->v
.psymtab
= pst
;
4879 /* die_reader_func for process_psymtab_comp_unit. */
4882 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
4884 struct die_info
*comp_unit_die
,
4888 struct dwarf2_cu
*cu
= reader
->cu
;
4889 struct objfile
*objfile
= cu
->objfile
;
4890 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
4891 struct attribute
*attr
;
4893 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
4894 struct partial_symtab
*pst
;
4896 const char *filename
;
4897 int *want_partial_unit_ptr
= data
;
4899 if (comp_unit_die
->tag
== DW_TAG_partial_unit
4900 && (want_partial_unit_ptr
== NULL
4901 || !*want_partial_unit_ptr
))
4904 gdb_assert (! per_cu
->is_debug_types
);
4906 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
4908 cu
->list_in_scope
= &file_symbols
;
4910 /* Allocate a new partial symbol table structure. */
4911 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, cu
);
4912 if (attr
== NULL
|| !DW_STRING (attr
))
4915 filename
= DW_STRING (attr
);
4917 pst
= create_partial_symtab (per_cu
, filename
);
4919 /* This must be done before calling dwarf2_build_include_psymtabs. */
4920 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
4922 pst
->dirname
= DW_STRING (attr
);
4924 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4926 dwarf2_find_base_address (comp_unit_die
, cu
);
4928 /* Possibly set the default values of LOWPC and HIGHPC from
4930 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
4931 &best_highpc
, cu
, pst
);
4932 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
4933 /* Store the contiguous range if it is not empty; it can be empty for
4934 CUs with no code. */
4935 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4936 best_lowpc
+ baseaddr
,
4937 best_highpc
+ baseaddr
- 1, pst
);
4939 /* Check if comp unit has_children.
4940 If so, read the rest of the partial symbols from this comp unit.
4941 If not, there's no more debug_info for this comp unit. */
4944 struct partial_die_info
*first_die
;
4945 CORE_ADDR lowpc
, highpc
;
4947 lowpc
= ((CORE_ADDR
) -1);
4948 highpc
= ((CORE_ADDR
) 0);
4950 first_die
= load_partial_dies (reader
, info_ptr
, 1);
4952 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
4955 /* If we didn't find a lowpc, set it to highpc to avoid
4956 complaints from `maint check'. */
4957 if (lowpc
== ((CORE_ADDR
) -1))
4960 /* If the compilation unit didn't have an explicit address range,
4961 then use the information extracted from its child dies. */
4965 best_highpc
= highpc
;
4968 pst
->textlow
= best_lowpc
+ baseaddr
;
4969 pst
->texthigh
= best_highpc
+ baseaddr
;
4971 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
4972 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
4973 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
4974 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4975 sort_pst_symbols (objfile
, pst
);
4977 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
4980 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4981 struct dwarf2_per_cu_data
*iter
;
4983 /* Fill in 'dependencies' here; we fill in 'users' in a
4985 pst
->number_of_dependencies
= len
;
4986 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
4987 len
* sizeof (struct symtab
*));
4989 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
4992 pst
->dependencies
[i
] = iter
->v
.psymtab
;
4994 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
4997 /* Get the list of files included in the current compilation unit,
4998 and build a psymtab for each of them. */
4999 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
5001 if (dwarf2_read_debug
)
5003 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5005 fprintf_unfiltered (gdb_stdlog
,
5006 "Psymtab for %s unit @0x%x: %s - %s"
5007 ", %d global, %d static syms\n",
5008 per_cu
->is_debug_types
? "type" : "comp",
5009 per_cu
->offset
.sect_off
,
5010 paddress (gdbarch
, pst
->textlow
),
5011 paddress (gdbarch
, pst
->texthigh
),
5012 pst
->n_global_syms
, pst
->n_static_syms
);
5016 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5017 Process compilation unit THIS_CU for a psymtab. */
5020 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
5021 int want_partial_unit
)
5023 /* If this compilation unit was already read in, free the
5024 cached copy in order to read it in again. This is
5025 necessary because we skipped some symbols when we first
5026 read in the compilation unit (see load_partial_dies).
5027 This problem could be avoided, but the benefit is unclear. */
5028 if (this_cu
->cu
!= NULL
)
5029 free_one_cached_comp_unit (this_cu
);
5031 gdb_assert (! this_cu
->is_debug_types
);
5032 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
5033 process_psymtab_comp_unit_reader
,
5034 &want_partial_unit
);
5036 /* Age out any secondary CUs. */
5037 age_cached_comp_units ();
5041 hash_type_unit_group (const void *item
)
5043 const struct type_unit_group
*tu_group
= item
;
5045 return hash_stmt_list_entry (&tu_group
->hash
);
5049 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
5051 const struct type_unit_group
*lhs
= item_lhs
;
5052 const struct type_unit_group
*rhs
= item_rhs
;
5054 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
5057 /* Allocate a hash table for type unit groups. */
5060 allocate_type_unit_groups_table (void)
5062 return htab_create_alloc_ex (3,
5063 hash_type_unit_group
,
5066 &dwarf2_per_objfile
->objfile
->objfile_obstack
,
5067 hashtab_obstack_allocate
,
5068 dummy_obstack_deallocate
);
5071 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5072 partial symtabs. We combine several TUs per psymtab to not let the size
5073 of any one psymtab grow too big. */
5074 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5075 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5077 /* Helper routine for get_type_unit_group.
5078 Create the type_unit_group object used to hold one or more TUs. */
5080 static struct type_unit_group
*
5081 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
5083 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5084 struct dwarf2_per_cu_data
*per_cu
;
5085 struct type_unit_group
*tu_group
;
5087 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5088 struct type_unit_group
);
5089 per_cu
= &tu_group
->per_cu
;
5090 per_cu
->objfile
= objfile
;
5091 per_cu
->is_debug_types
= 1;
5092 per_cu
->type_unit_group
= tu_group
;
5094 if (dwarf2_per_objfile
->using_index
)
5096 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5097 struct dwarf2_per_cu_quick_data
);
5098 tu_group
->t
.first_tu
= cu
->per_cu
;
5102 unsigned int line_offset
= line_offset_struct
.sect_off
;
5103 struct partial_symtab
*pst
;
5106 /* Give the symtab a useful name for debug purposes. */
5107 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
5108 name
= xstrprintf ("<type_units_%d>",
5109 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
5111 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
5113 pst
= create_partial_symtab (per_cu
, name
);
5119 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
5120 tu_group
->hash
.line_offset
= line_offset_struct
;
5125 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5126 STMT_LIST is a DW_AT_stmt_list attribute. */
5128 static struct type_unit_group
*
5129 get_type_unit_group (struct dwarf2_cu
*cu
, struct attribute
*stmt_list
)
5131 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5132 struct type_unit_group
*tu_group
;
5134 unsigned int line_offset
;
5135 struct type_unit_group type_unit_group_for_lookup
;
5137 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
5139 dwarf2_per_objfile
->type_unit_groups
=
5140 allocate_type_unit_groups_table ();
5143 /* Do we need to create a new group, or can we use an existing one? */
5147 line_offset
= DW_UNSND (stmt_list
);
5148 ++tu_stats
->nr_symtab_sharers
;
5152 /* Ugh, no stmt_list. Rare, but we have to handle it.
5153 We can do various things here like create one group per TU or
5154 spread them over multiple groups to split up the expansion work.
5155 To avoid worst case scenarios (too many groups or too large groups)
5156 we, umm, group them in bunches. */
5157 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5158 | (tu_stats
->nr_stmt_less_type_units
5159 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
5160 ++tu_stats
->nr_stmt_less_type_units
;
5163 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
5164 type_unit_group_for_lookup
.hash
.line_offset
.sect_off
= line_offset
;
5165 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
5166 &type_unit_group_for_lookup
, INSERT
);
5170 gdb_assert (tu_group
!= NULL
);
5174 sect_offset line_offset_struct
;
5176 line_offset_struct
.sect_off
= line_offset
;
5177 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
5179 ++tu_stats
->nr_symtabs
;
5185 /* Struct used to sort TUs by their abbreviation table offset. */
5187 struct tu_abbrev_offset
5189 struct signatured_type
*sig_type
;
5190 sect_offset abbrev_offset
;
5193 /* Helper routine for build_type_unit_groups, passed to qsort. */
5196 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
5198 const struct tu_abbrev_offset
* const *a
= ap
;
5199 const struct tu_abbrev_offset
* const *b
= bp
;
5200 unsigned int aoff
= (*a
)->abbrev_offset
.sect_off
;
5201 unsigned int boff
= (*b
)->abbrev_offset
.sect_off
;
5203 return (aoff
> boff
) - (aoff
< boff
);
5206 /* A helper function to add a type_unit_group to a table. */
5209 add_type_unit_group_to_table (void **slot
, void *datum
)
5211 struct type_unit_group
*tu_group
= *slot
;
5212 struct type_unit_group
***datap
= datum
;
5220 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5221 each one passing FUNC,DATA.
5223 The efficiency is because we sort TUs by the abbrev table they use and
5224 only read each abbrev table once. In one program there are 200K TUs
5225 sharing 8K abbrev tables.
5227 The main purpose of this function is to support building the
5228 dwarf2_per_objfile->type_unit_groups table.
5229 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5230 can collapse the search space by grouping them by stmt_list.
5231 The savings can be significant, in the same program from above the 200K TUs
5232 share 8K stmt_list tables.
5234 FUNC is expected to call get_type_unit_group, which will create the
5235 struct type_unit_group if necessary and add it to
5236 dwarf2_per_objfile->type_unit_groups. */
5239 build_type_unit_groups (die_reader_func_ftype
*func
, void *data
)
5241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5242 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
5243 struct cleanup
*cleanups
;
5244 struct abbrev_table
*abbrev_table
;
5245 sect_offset abbrev_offset
;
5246 struct tu_abbrev_offset
*sorted_by_abbrev
;
5247 struct type_unit_group
**iter
;
5250 /* It's up to the caller to not call us multiple times. */
5251 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
5253 if (dwarf2_per_objfile
->n_type_units
== 0)
5256 /* TUs typically share abbrev tables, and there can be way more TUs than
5257 abbrev tables. Sort by abbrev table to reduce the number of times we
5258 read each abbrev table in.
5259 Alternatives are to punt or to maintain a cache of abbrev tables.
5260 This is simpler and efficient enough for now.
5262 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5263 symtab to use). Typically TUs with the same abbrev offset have the same
5264 stmt_list value too so in practice this should work well.
5266 The basic algorithm here is:
5268 sort TUs by abbrev table
5269 for each TU with same abbrev table:
5270 read abbrev table if first user
5271 read TU top level DIE
5272 [IWBN if DWO skeletons had DW_AT_stmt_list]
5275 if (dwarf2_read_debug
)
5276 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
5278 /* Sort in a separate table to maintain the order of all_type_units
5279 for .gdb_index: TU indices directly index all_type_units. */
5280 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
5281 dwarf2_per_objfile
->n_type_units
);
5282 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5284 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
5286 sorted_by_abbrev
[i
].sig_type
= sig_type
;
5287 sorted_by_abbrev
[i
].abbrev_offset
=
5288 read_abbrev_offset (sig_type
->per_cu
.info_or_types_section
,
5289 sig_type
->per_cu
.offset
);
5291 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
5292 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
5293 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
5295 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5296 called any number of times, so we don't reset tu_stats here. */
5298 abbrev_offset
.sect_off
= ~(unsigned) 0;
5299 abbrev_table
= NULL
;
5300 make_cleanup (abbrev_table_free_cleanup
, &abbrev_table
);
5302 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
5304 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
5306 /* Switch to the next abbrev table if necessary. */
5307 if (abbrev_table
== NULL
5308 || tu
->abbrev_offset
.sect_off
!= abbrev_offset
.sect_off
)
5310 if (abbrev_table
!= NULL
)
5312 abbrev_table_free (abbrev_table
);
5313 /* Reset to NULL in case abbrev_table_read_table throws
5314 an error: abbrev_table_free_cleanup will get called. */
5315 abbrev_table
= NULL
;
5317 abbrev_offset
= tu
->abbrev_offset
;
5319 abbrev_table_read_table (&dwarf2_per_objfile
->abbrev
,
5321 ++tu_stats
->nr_uniq_abbrev_tables
;
5324 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
, 0, 0,
5328 /* Create a vector of pointers to primary type units to make it easy to
5329 iterate over them and CUs. See dw2_get_primary_cu. */
5330 dwarf2_per_objfile
->n_type_unit_groups
=
5331 htab_elements (dwarf2_per_objfile
->type_unit_groups
);
5332 dwarf2_per_objfile
->all_type_unit_groups
=
5333 obstack_alloc (&objfile
->objfile_obstack
,
5334 dwarf2_per_objfile
->n_type_unit_groups
5335 * sizeof (struct type_unit_group
*));
5336 iter
= &dwarf2_per_objfile
->all_type_unit_groups
[0];
5337 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5338 add_type_unit_group_to_table
, &iter
);
5339 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_unit_groups
[0]
5340 == dwarf2_per_objfile
->n_type_unit_groups
);
5342 do_cleanups (cleanups
);
5344 if (dwarf2_read_debug
)
5346 fprintf_unfiltered (gdb_stdlog
, "Done building type unit groups:\n");
5347 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
5348 dwarf2_per_objfile
->n_type_units
);
5349 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
5350 tu_stats
->nr_uniq_abbrev_tables
);
5351 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
5352 tu_stats
->nr_symtabs
);
5353 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
5354 tu_stats
->nr_symtab_sharers
);
5355 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
5356 tu_stats
->nr_stmt_less_type_units
);
5360 /* Reader function for build_type_psymtabs. */
5363 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
5365 struct die_info
*type_unit_die
,
5369 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5370 struct dwarf2_cu
*cu
= reader
->cu
;
5371 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
5372 struct type_unit_group
*tu_group
;
5373 struct attribute
*attr
;
5374 struct partial_die_info
*first_die
;
5375 CORE_ADDR lowpc
, highpc
;
5376 struct partial_symtab
*pst
;
5378 gdb_assert (data
== NULL
);
5383 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
5384 tu_group
= get_type_unit_group (cu
, attr
);
5386 VEC_safe_push (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, per_cu
);
5388 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
5389 cu
->list_in_scope
= &file_symbols
;
5390 pst
= create_partial_symtab (per_cu
, "");
5393 first_die
= load_partial_dies (reader
, info_ptr
, 1);
5395 lowpc
= (CORE_ADDR
) -1;
5396 highpc
= (CORE_ADDR
) 0;
5397 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
5399 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
5400 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
5401 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
5402 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
5403 sort_pst_symbols (objfile
, pst
);
5406 /* Traversal function for build_type_psymtabs. */
5409 build_type_psymtab_dependencies (void **slot
, void *info
)
5411 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5412 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
5413 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
5414 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5415 int len
= VEC_length (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5416 struct dwarf2_per_cu_data
*iter
;
5419 gdb_assert (len
> 0);
5421 pst
->number_of_dependencies
= len
;
5422 pst
->dependencies
= obstack_alloc (&objfile
->objfile_obstack
,
5423 len
* sizeof (struct psymtab
*));
5425 VEC_iterate (dwarf2_per_cu_ptr
, tu_group
->t
.tus
, i
, iter
);
5428 pst
->dependencies
[i
] = iter
->v
.psymtab
;
5429 iter
->type_unit_group
= tu_group
;
5432 VEC_free (dwarf2_per_cu_ptr
, tu_group
->t
.tus
);
5437 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5438 Build partial symbol tables for the .debug_types comp-units. */
5441 build_type_psymtabs (struct objfile
*objfile
)
5443 if (! create_all_type_units (objfile
))
5446 build_type_unit_groups (build_type_psymtabs_reader
, NULL
);
5448 /* Now that all TUs have been processed we can fill in the dependencies. */
5449 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
5450 build_type_psymtab_dependencies
, NULL
);
5453 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5456 psymtabs_addrmap_cleanup (void *o
)
5458 struct objfile
*objfile
= o
;
5460 objfile
->psymtabs_addrmap
= NULL
;
5463 /* Compute the 'user' field for each psymtab in OBJFILE. */
5466 set_partial_user (struct objfile
*objfile
)
5470 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5472 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5473 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
5479 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
5481 /* Set the 'user' field only if it is not already set. */
5482 if (pst
->dependencies
[j
]->user
== NULL
)
5483 pst
->dependencies
[j
]->user
= pst
;
5488 /* Build the partial symbol table by doing a quick pass through the
5489 .debug_info and .debug_abbrev sections. */
5492 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
5494 struct cleanup
*back_to
, *addrmap_cleanup
;
5495 struct obstack temp_obstack
;
5498 if (dwarf2_read_debug
)
5500 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
5504 dwarf2_per_objfile
->reading_partial_symbols
= 1;
5506 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
5508 /* Any cached compilation units will be linked by the per-objfile
5509 read_in_chain. Make sure to free them when we're done. */
5510 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
5512 build_type_psymtabs (objfile
);
5514 create_all_comp_units (objfile
);
5516 /* Create a temporary address map on a temporary obstack. We later
5517 copy this to the final obstack. */
5518 obstack_init (&temp_obstack
);
5519 make_cleanup_obstack_free (&temp_obstack
);
5520 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
5521 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
5523 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5525 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
5527 process_psymtab_comp_unit (per_cu
, 0);
5530 set_partial_user (objfile
);
5532 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
5533 &objfile
->objfile_obstack
);
5534 discard_cleanups (addrmap_cleanup
);
5536 do_cleanups (back_to
);
5538 if (dwarf2_read_debug
)
5539 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
5543 /* die_reader_func for load_partial_comp_unit. */
5546 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
5548 struct die_info
*comp_unit_die
,
5552 struct dwarf2_cu
*cu
= reader
->cu
;
5554 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
5556 /* Check if comp unit has_children.
5557 If so, read the rest of the partial symbols from this comp unit.
5558 If not, there's no more debug_info for this comp unit. */
5560 load_partial_dies (reader
, info_ptr
, 0);
5563 /* Load the partial DIEs for a secondary CU into memory.
5564 This is also used when rereading a primary CU with load_all_dies. */
5567 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
5569 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
5570 load_partial_comp_unit_reader
, NULL
);
5574 read_comp_units_from_section (struct objfile
*objfile
,
5575 struct dwarf2_section_info
*section
,
5576 unsigned int is_dwz
,
5579 struct dwarf2_per_cu_data
***all_comp_units
)
5582 bfd
*abfd
= section
->asection
->owner
;
5584 dwarf2_read_section (objfile
, section
);
5586 info_ptr
= section
->buffer
;
5588 while (info_ptr
< section
->buffer
+ section
->size
)
5590 unsigned int length
, initial_length_size
;
5591 struct dwarf2_per_cu_data
*this_cu
;
5594 offset
.sect_off
= info_ptr
- section
->buffer
;
5596 /* Read just enough information to find out where the next
5597 compilation unit is. */
5598 length
= read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5600 /* Save the compilation unit for later lookup. */
5601 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
5602 sizeof (struct dwarf2_per_cu_data
));
5603 memset (this_cu
, 0, sizeof (*this_cu
));
5604 this_cu
->offset
= offset
;
5605 this_cu
->length
= length
+ initial_length_size
;
5606 this_cu
->is_dwz
= is_dwz
;
5607 this_cu
->objfile
= objfile
;
5608 this_cu
->info_or_types_section
= section
;
5610 if (*n_comp_units
== *n_allocated
)
5613 *all_comp_units
= xrealloc (*all_comp_units
,
5615 * sizeof (struct dwarf2_per_cu_data
*));
5617 (*all_comp_units
)[*n_comp_units
] = this_cu
;
5620 info_ptr
= info_ptr
+ this_cu
->length
;
5624 /* Create a list of all compilation units in OBJFILE.
5625 This is only done for -readnow and building partial symtabs. */
5628 create_all_comp_units (struct objfile
*objfile
)
5632 struct dwarf2_per_cu_data
**all_comp_units
;
5636 all_comp_units
= xmalloc (n_allocated
5637 * sizeof (struct dwarf2_per_cu_data
*));
5639 read_comp_units_from_section (objfile
, &dwarf2_per_objfile
->info
, 0,
5640 &n_allocated
, &n_comp_units
, &all_comp_units
);
5642 if (bfd_get_section_by_name (objfile
->obfd
, ".gnu_debugaltlink") != NULL
)
5644 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
5646 read_comp_units_from_section (objfile
, &dwz
->info
, 1,
5647 &n_allocated
, &n_comp_units
,
5651 dwarf2_per_objfile
->all_comp_units
5652 = obstack_alloc (&objfile
->objfile_obstack
,
5653 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5654 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
5655 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
5656 xfree (all_comp_units
);
5657 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
5660 /* Process all loaded DIEs for compilation unit CU, starting at
5661 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5662 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5663 DW_AT_ranges). If NEED_PC is set, then this function will set
5664 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5665 and record the covered ranges in the addrmap. */
5668 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
5669 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
5671 struct partial_die_info
*pdi
;
5673 /* Now, march along the PDI's, descending into ones which have
5674 interesting children but skipping the children of the other ones,
5675 until we reach the end of the compilation unit. */
5681 fixup_partial_die (pdi
, cu
);
5683 /* Anonymous namespaces or modules have no name but have interesting
5684 children, so we need to look at them. Ditto for anonymous
5687 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
5688 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
5689 || pdi
->tag
== DW_TAG_imported_unit
)
5693 case DW_TAG_subprogram
:
5694 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
5696 case DW_TAG_constant
:
5697 case DW_TAG_variable
:
5698 case DW_TAG_typedef
:
5699 case DW_TAG_union_type
:
5700 if (!pdi
->is_declaration
)
5702 add_partial_symbol (pdi
, cu
);
5705 case DW_TAG_class_type
:
5706 case DW_TAG_interface_type
:
5707 case DW_TAG_structure_type
:
5708 if (!pdi
->is_declaration
)
5710 add_partial_symbol (pdi
, cu
);
5713 case DW_TAG_enumeration_type
:
5714 if (!pdi
->is_declaration
)
5715 add_partial_enumeration (pdi
, cu
);
5717 case DW_TAG_base_type
:
5718 case DW_TAG_subrange_type
:
5719 /* File scope base type definitions are added to the partial
5721 add_partial_symbol (pdi
, cu
);
5723 case DW_TAG_namespace
:
5724 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
5727 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
5729 case DW_TAG_imported_unit
:
5731 struct dwarf2_per_cu_data
*per_cu
;
5733 /* For now we don't handle imported units in type units. */
5734 if (cu
->per_cu
->is_debug_types
)
5736 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5737 " supported in type units [in module %s]"),
5741 per_cu
= dwarf2_find_containing_comp_unit (pdi
->d
.offset
,
5745 /* Go read the partial unit, if needed. */
5746 if (per_cu
->v
.psymtab
== NULL
)
5747 process_psymtab_comp_unit (per_cu
, 1);
5749 VEC_safe_push (dwarf2_per_cu_ptr
,
5750 cu
->per_cu
->imported_symtabs
, per_cu
);
5758 /* If the die has a sibling, skip to the sibling. */
5760 pdi
= pdi
->die_sibling
;
5764 /* Functions used to compute the fully scoped name of a partial DIE.
5766 Normally, this is simple. For C++, the parent DIE's fully scoped
5767 name is concatenated with "::" and the partial DIE's name. For
5768 Java, the same thing occurs except that "." is used instead of "::".
5769 Enumerators are an exception; they use the scope of their parent
5770 enumeration type, i.e. the name of the enumeration type is not
5771 prepended to the enumerator.
5773 There are two complexities. One is DW_AT_specification; in this
5774 case "parent" means the parent of the target of the specification,
5775 instead of the direct parent of the DIE. The other is compilers
5776 which do not emit DW_TAG_namespace; in this case we try to guess
5777 the fully qualified name of structure types from their members'
5778 linkage names. This must be done using the DIE's children rather
5779 than the children of any DW_AT_specification target. We only need
5780 to do this for structures at the top level, i.e. if the target of
5781 any DW_AT_specification (if any; otherwise the DIE itself) does not
5784 /* Compute the scope prefix associated with PDI's parent, in
5785 compilation unit CU. The result will be allocated on CU's
5786 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5787 field. NULL is returned if no prefix is necessary. */
5789 partial_die_parent_scope (struct partial_die_info
*pdi
,
5790 struct dwarf2_cu
*cu
)
5792 const char *grandparent_scope
;
5793 struct partial_die_info
*parent
, *real_pdi
;
5795 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5796 then this means the parent of the specification DIE. */
5799 while (real_pdi
->has_specification
)
5800 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
5801 real_pdi
->spec_is_dwz
, cu
);
5803 parent
= real_pdi
->die_parent
;
5807 if (parent
->scope_set
)
5808 return parent
->scope
;
5810 fixup_partial_die (parent
, cu
);
5812 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
5814 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5815 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5816 Work around this problem here. */
5817 if (cu
->language
== language_cplus
5818 && parent
->tag
== DW_TAG_namespace
5819 && strcmp (parent
->name
, "::") == 0
5820 && grandparent_scope
== NULL
)
5822 parent
->scope
= NULL
;
5823 parent
->scope_set
= 1;
5827 if (pdi
->tag
== DW_TAG_enumerator
)
5828 /* Enumerators should not get the name of the enumeration as a prefix. */
5829 parent
->scope
= grandparent_scope
;
5830 else if (parent
->tag
== DW_TAG_namespace
5831 || parent
->tag
== DW_TAG_module
5832 || parent
->tag
== DW_TAG_structure_type
5833 || parent
->tag
== DW_TAG_class_type
5834 || parent
->tag
== DW_TAG_interface_type
5835 || parent
->tag
== DW_TAG_union_type
5836 || parent
->tag
== DW_TAG_enumeration_type
)
5838 if (grandparent_scope
== NULL
)
5839 parent
->scope
= parent
->name
;
5841 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
5843 parent
->name
, 0, cu
);
5847 /* FIXME drow/2004-04-01: What should we be doing with
5848 function-local names? For partial symbols, we should probably be
5850 complaint (&symfile_complaints
,
5851 _("unhandled containing DIE tag %d for DIE at %d"),
5852 parent
->tag
, pdi
->offset
.sect_off
);
5853 parent
->scope
= grandparent_scope
;
5856 parent
->scope_set
= 1;
5857 return parent
->scope
;
5860 /* Return the fully scoped name associated with PDI, from compilation unit
5861 CU. The result will be allocated with malloc. */
5864 partial_die_full_name (struct partial_die_info
*pdi
,
5865 struct dwarf2_cu
*cu
)
5867 const char *parent_scope
;
5869 /* If this is a template instantiation, we can not work out the
5870 template arguments from partial DIEs. So, unfortunately, we have
5871 to go through the full DIEs. At least any work we do building
5872 types here will be reused if full symbols are loaded later. */
5873 if (pdi
->has_template_arguments
)
5875 fixup_partial_die (pdi
, cu
);
5877 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
5879 struct die_info
*die
;
5880 struct attribute attr
;
5881 struct dwarf2_cu
*ref_cu
= cu
;
5883 /* DW_FORM_ref_addr is using section offset. */
5885 attr
.form
= DW_FORM_ref_addr
;
5886 attr
.u
.unsnd
= pdi
->offset
.sect_off
;
5887 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
5889 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
5893 parent_scope
= partial_die_parent_scope (pdi
, cu
);
5894 if (parent_scope
== NULL
)
5897 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
5901 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
5903 struct objfile
*objfile
= cu
->objfile
;
5905 const char *actual_name
= NULL
;
5907 char *built_actual_name
;
5909 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5911 built_actual_name
= partial_die_full_name (pdi
, cu
);
5912 if (built_actual_name
!= NULL
)
5913 actual_name
= built_actual_name
;
5915 if (actual_name
== NULL
)
5916 actual_name
= pdi
->name
;
5920 case DW_TAG_subprogram
:
5921 if (pdi
->is_external
|| cu
->language
== language_ada
)
5923 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5924 of the global scope. But in Ada, we want to be able to access
5925 nested procedures globally. So all Ada subprograms are stored
5926 in the global scope. */
5927 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5928 mst_text, objfile); */
5929 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5930 built_actual_name
!= NULL
,
5931 VAR_DOMAIN
, LOC_BLOCK
,
5932 &objfile
->global_psymbols
,
5933 0, pdi
->lowpc
+ baseaddr
,
5934 cu
->language
, objfile
);
5938 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5939 mst_file_text, objfile); */
5940 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5941 built_actual_name
!= NULL
,
5942 VAR_DOMAIN
, LOC_BLOCK
,
5943 &objfile
->static_psymbols
,
5944 0, pdi
->lowpc
+ baseaddr
,
5945 cu
->language
, objfile
);
5948 case DW_TAG_constant
:
5950 struct psymbol_allocation_list
*list
;
5952 if (pdi
->is_external
)
5953 list
= &objfile
->global_psymbols
;
5955 list
= &objfile
->static_psymbols
;
5956 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5957 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
5958 list
, 0, 0, cu
->language
, objfile
);
5961 case DW_TAG_variable
:
5963 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
5967 && !dwarf2_per_objfile
->has_section_at_zero
)
5969 /* A global or static variable may also have been stripped
5970 out by the linker if unused, in which case its address
5971 will be nullified; do not add such variables into partial
5972 symbol table then. */
5974 else if (pdi
->is_external
)
5977 Don't enter into the minimal symbol tables as there is
5978 a minimal symbol table entry from the ELF symbols already.
5979 Enter into partial symbol table if it has a location
5980 descriptor or a type.
5981 If the location descriptor is missing, new_symbol will create
5982 a LOC_UNRESOLVED symbol, the address of the variable will then
5983 be determined from the minimal symbol table whenever the variable
5985 The address for the partial symbol table entry is not
5986 used by GDB, but it comes in handy for debugging partial symbol
5989 if (pdi
->d
.locdesc
|| pdi
->has_type
)
5990 add_psymbol_to_list (actual_name
, strlen (actual_name
),
5991 built_actual_name
!= NULL
,
5992 VAR_DOMAIN
, LOC_STATIC
,
5993 &objfile
->global_psymbols
,
5995 cu
->language
, objfile
);
5999 /* Static Variable. Skip symbols without location descriptors. */
6000 if (pdi
->d
.locdesc
== NULL
)
6002 xfree (built_actual_name
);
6005 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6006 mst_file_data, objfile); */
6007 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6008 built_actual_name
!= NULL
,
6009 VAR_DOMAIN
, LOC_STATIC
,
6010 &objfile
->static_psymbols
,
6012 cu
->language
, objfile
);
6015 case DW_TAG_typedef
:
6016 case DW_TAG_base_type
:
6017 case DW_TAG_subrange_type
:
6018 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6019 built_actual_name
!= NULL
,
6020 VAR_DOMAIN
, LOC_TYPEDEF
,
6021 &objfile
->static_psymbols
,
6022 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6024 case DW_TAG_namespace
:
6025 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6026 built_actual_name
!= NULL
,
6027 VAR_DOMAIN
, LOC_TYPEDEF
,
6028 &objfile
->global_psymbols
,
6029 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6031 case DW_TAG_class_type
:
6032 case DW_TAG_interface_type
:
6033 case DW_TAG_structure_type
:
6034 case DW_TAG_union_type
:
6035 case DW_TAG_enumeration_type
:
6036 /* Skip external references. The DWARF standard says in the section
6037 about "Structure, Union, and Class Type Entries": "An incomplete
6038 structure, union or class type is represented by a structure,
6039 union or class entry that does not have a byte size attribute
6040 and that has a DW_AT_declaration attribute." */
6041 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
6043 xfree (built_actual_name
);
6047 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6048 static vs. global. */
6049 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6050 built_actual_name
!= NULL
,
6051 STRUCT_DOMAIN
, LOC_TYPEDEF
,
6052 (cu
->language
== language_cplus
6053 || cu
->language
== language_java
)
6054 ? &objfile
->global_psymbols
6055 : &objfile
->static_psymbols
,
6056 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6059 case DW_TAG_enumerator
:
6060 add_psymbol_to_list (actual_name
, strlen (actual_name
),
6061 built_actual_name
!= NULL
,
6062 VAR_DOMAIN
, LOC_CONST
,
6063 (cu
->language
== language_cplus
6064 || cu
->language
== language_java
)
6065 ? &objfile
->global_psymbols
6066 : &objfile
->static_psymbols
,
6067 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
6073 xfree (built_actual_name
);
6076 /* Read a partial die corresponding to a namespace; also, add a symbol
6077 corresponding to that namespace to the symbol table. NAMESPACE is
6078 the name of the enclosing namespace. */
6081 add_partial_namespace (struct partial_die_info
*pdi
,
6082 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6083 int need_pc
, struct dwarf2_cu
*cu
)
6085 /* Add a symbol for the namespace. */
6087 add_partial_symbol (pdi
, cu
);
6089 /* Now scan partial symbols in that namespace. */
6091 if (pdi
->has_children
)
6092 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6095 /* Read a partial die corresponding to a Fortran module. */
6098 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
6099 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
6101 /* Now scan partial symbols in that module. */
6103 if (pdi
->has_children
)
6104 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
6107 /* Read a partial die corresponding to a subprogram and create a partial
6108 symbol for that subprogram. When the CU language allows it, this
6109 routine also defines a partial symbol for each nested subprogram
6110 that this subprogram contains.
6112 DIE my also be a lexical block, in which case we simply search
6113 recursively for suprograms defined inside that lexical block.
6114 Again, this is only performed when the CU language allows this
6115 type of definitions. */
6118 add_partial_subprogram (struct partial_die_info
*pdi
,
6119 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6120 int need_pc
, struct dwarf2_cu
*cu
)
6122 if (pdi
->tag
== DW_TAG_subprogram
)
6124 if (pdi
->has_pc_info
)
6126 if (pdi
->lowpc
< *lowpc
)
6127 *lowpc
= pdi
->lowpc
;
6128 if (pdi
->highpc
> *highpc
)
6129 *highpc
= pdi
->highpc
;
6133 struct objfile
*objfile
= cu
->objfile
;
6135 baseaddr
= ANOFFSET (objfile
->section_offsets
,
6136 SECT_OFF_TEXT (objfile
));
6137 addrmap_set_empty (objfile
->psymtabs_addrmap
,
6138 pdi
->lowpc
+ baseaddr
,
6139 pdi
->highpc
- 1 + baseaddr
,
6140 cu
->per_cu
->v
.psymtab
);
6144 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
6146 if (!pdi
->is_declaration
)
6147 /* Ignore subprogram DIEs that do not have a name, they are
6148 illegal. Do not emit a complaint at this point, we will
6149 do so when we convert this psymtab into a symtab. */
6151 add_partial_symbol (pdi
, cu
);
6155 if (! pdi
->has_children
)
6158 if (cu
->language
== language_ada
)
6160 pdi
= pdi
->die_child
;
6163 fixup_partial_die (pdi
, cu
);
6164 if (pdi
->tag
== DW_TAG_subprogram
6165 || pdi
->tag
== DW_TAG_lexical_block
)
6166 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
6167 pdi
= pdi
->die_sibling
;
6172 /* Read a partial die corresponding to an enumeration type. */
6175 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
6176 struct dwarf2_cu
*cu
)
6178 struct partial_die_info
*pdi
;
6180 if (enum_pdi
->name
!= NULL
)
6181 add_partial_symbol (enum_pdi
, cu
);
6183 pdi
= enum_pdi
->die_child
;
6186 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
6187 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6189 add_partial_symbol (pdi
, cu
);
6190 pdi
= pdi
->die_sibling
;
6194 /* Return the initial uleb128 in the die at INFO_PTR. */
6197 peek_abbrev_code (bfd
*abfd
, gdb_byte
*info_ptr
)
6199 unsigned int bytes_read
;
6201 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6204 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6205 Return the corresponding abbrev, or NULL if the number is zero (indicating
6206 an empty DIE). In either case *BYTES_READ will be set to the length of
6207 the initial number. */
6209 static struct abbrev_info
*
6210 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
6211 struct dwarf2_cu
*cu
)
6213 bfd
*abfd
= cu
->objfile
->obfd
;
6214 unsigned int abbrev_number
;
6215 struct abbrev_info
*abbrev
;
6217 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
6219 if (abbrev_number
== 0)
6222 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
6225 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6226 abbrev_number
, bfd_get_filename (abfd
));
6232 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6233 Returns a pointer to the end of a series of DIEs, terminated by an empty
6234 DIE. Any children of the skipped DIEs will also be skipped. */
6237 skip_children (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
)
6239 struct dwarf2_cu
*cu
= reader
->cu
;
6240 struct abbrev_info
*abbrev
;
6241 unsigned int bytes_read
;
6245 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6247 return info_ptr
+ bytes_read
;
6249 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
6253 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6254 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6255 abbrev corresponding to that skipped uleb128 should be passed in
6256 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6260 skip_one_die (const struct die_reader_specs
*reader
, gdb_byte
*info_ptr
,
6261 struct abbrev_info
*abbrev
)
6263 unsigned int bytes_read
;
6264 struct attribute attr
;
6265 bfd
*abfd
= reader
->abfd
;
6266 struct dwarf2_cu
*cu
= reader
->cu
;
6267 gdb_byte
*buffer
= reader
->buffer
;
6268 const gdb_byte
*buffer_end
= reader
->buffer_end
;
6269 gdb_byte
*start_info_ptr
= info_ptr
;
6270 unsigned int form
, i
;
6272 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
6274 /* The only abbrev we care about is DW_AT_sibling. */
6275 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
6277 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
6278 if (attr
.form
== DW_FORM_ref_addr
)
6279 complaint (&symfile_complaints
,
6280 _("ignoring absolute DW_AT_sibling"));
6282 return buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
6285 /* If it isn't DW_AT_sibling, skip this attribute. */
6286 form
= abbrev
->attrs
[i
].form
;
6290 case DW_FORM_ref_addr
:
6291 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6292 and later it is offset sized. */
6293 if (cu
->header
.version
== 2)
6294 info_ptr
+= cu
->header
.addr_size
;
6296 info_ptr
+= cu
->header
.offset_size
;
6298 case DW_FORM_GNU_ref_alt
:
6299 info_ptr
+= cu
->header
.offset_size
;
6302 info_ptr
+= cu
->header
.addr_size
;
6309 case DW_FORM_flag_present
:
6321 case DW_FORM_ref_sig8
:
6324 case DW_FORM_string
:
6325 read_direct_string (abfd
, info_ptr
, &bytes_read
);
6326 info_ptr
+= bytes_read
;
6328 case DW_FORM_sec_offset
:
6330 case DW_FORM_GNU_strp_alt
:
6331 info_ptr
+= cu
->header
.offset_size
;
6333 case DW_FORM_exprloc
:
6335 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6336 info_ptr
+= bytes_read
;
6338 case DW_FORM_block1
:
6339 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
6341 case DW_FORM_block2
:
6342 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
6344 case DW_FORM_block4
:
6345 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
6349 case DW_FORM_ref_udata
:
6350 case DW_FORM_GNU_addr_index
:
6351 case DW_FORM_GNU_str_index
:
6352 info_ptr
= (gdb_byte
*) safe_skip_leb128 (info_ptr
, buffer_end
);
6354 case DW_FORM_indirect
:
6355 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6356 info_ptr
+= bytes_read
;
6357 /* We need to continue parsing from here, so just go back to
6359 goto skip_attribute
;
6362 error (_("Dwarf Error: Cannot handle %s "
6363 "in DWARF reader [in module %s]"),
6364 dwarf_form_name (form
),
6365 bfd_get_filename (abfd
));
6369 if (abbrev
->has_children
)
6370 return skip_children (reader
, info_ptr
);
6375 /* Locate ORIG_PDI's sibling.
6376 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6379 locate_pdi_sibling (const struct die_reader_specs
*reader
,
6380 struct partial_die_info
*orig_pdi
,
6383 /* Do we know the sibling already? */
6385 if (orig_pdi
->sibling
)
6386 return orig_pdi
->sibling
;
6388 /* Are there any children to deal with? */
6390 if (!orig_pdi
->has_children
)
6393 /* Skip the children the long way. */
6395 return skip_children (reader
, info_ptr
);
6398 /* Expand this partial symbol table into a full symbol table. SELF is
6402 dwarf2_read_symtab (struct partial_symtab
*self
,
6403 struct objfile
*objfile
)
6407 warning (_("bug: psymtab for %s is already read in."),
6414 printf_filtered (_("Reading in symbols for %s..."),
6416 gdb_flush (gdb_stdout
);
6419 /* Restore our global data. */
6420 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
6422 /* If this psymtab is constructed from a debug-only objfile, the
6423 has_section_at_zero flag will not necessarily be correct. We
6424 can get the correct value for this flag by looking at the data
6425 associated with the (presumably stripped) associated objfile. */
6426 if (objfile
->separate_debug_objfile_backlink
)
6428 struct dwarf2_per_objfile
*dpo_backlink
6429 = objfile_data (objfile
->separate_debug_objfile_backlink
,
6430 dwarf2_objfile_data_key
);
6432 dwarf2_per_objfile
->has_section_at_zero
6433 = dpo_backlink
->has_section_at_zero
;
6436 dwarf2_per_objfile
->reading_partial_symbols
= 0;
6438 psymtab_to_symtab_1 (self
);
6440 /* Finish up the debug error message. */
6442 printf_filtered (_("done.\n"));
6445 process_cu_includes ();
6448 /* Reading in full CUs. */
6450 /* Add PER_CU to the queue. */
6453 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6454 enum language pretend_language
)
6456 struct dwarf2_queue_item
*item
;
6459 item
= xmalloc (sizeof (*item
));
6460 item
->per_cu
= per_cu
;
6461 item
->pretend_language
= pretend_language
;
6464 if (dwarf2_queue
== NULL
)
6465 dwarf2_queue
= item
;
6467 dwarf2_queue_tail
->next
= item
;
6469 dwarf2_queue_tail
= item
;
6472 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6473 unit and add it to our queue.
6474 The result is non-zero if PER_CU was queued, otherwise the result is zero
6475 meaning either PER_CU is already queued or it is already loaded. */
6478 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
6479 struct dwarf2_per_cu_data
*per_cu
,
6480 enum language pretend_language
)
6482 /* We may arrive here during partial symbol reading, if we need full
6483 DIEs to process an unusual case (e.g. template arguments). Do
6484 not queue PER_CU, just tell our caller to load its DIEs. */
6485 if (dwarf2_per_objfile
->reading_partial_symbols
)
6487 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
6492 /* Mark the dependence relation so that we don't flush PER_CU
6494 dwarf2_add_dependence (this_cu
, per_cu
);
6496 /* If it's already on the queue, we have nothing to do. */
6500 /* If the compilation unit is already loaded, just mark it as
6502 if (per_cu
->cu
!= NULL
)
6504 per_cu
->cu
->last_used
= 0;
6508 /* Add it to the queue. */
6509 queue_comp_unit (per_cu
, pretend_language
);
6514 /* Process the queue. */
6517 process_queue (void)
6519 struct dwarf2_queue_item
*item
, *next_item
;
6521 if (dwarf2_read_debug
)
6523 fprintf_unfiltered (gdb_stdlog
,
6524 "Expanding one or more symtabs of objfile %s ...\n",
6525 dwarf2_per_objfile
->objfile
->name
);
6528 /* The queue starts out with one item, but following a DIE reference
6529 may load a new CU, adding it to the end of the queue. */
6530 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
6532 if (dwarf2_per_objfile
->using_index
6533 ? !item
->per_cu
->v
.quick
->symtab
6534 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
6536 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
6538 if (dwarf2_read_debug
)
6540 fprintf_unfiltered (gdb_stdlog
,
6541 "Expanding symtab of %s at offset 0x%x\n",
6542 per_cu
->is_debug_types
? "TU" : "CU",
6543 per_cu
->offset
.sect_off
);
6546 if (per_cu
->is_debug_types
)
6547 process_full_type_unit (per_cu
, item
->pretend_language
);
6549 process_full_comp_unit (per_cu
, item
->pretend_language
);
6551 if (dwarf2_read_debug
)
6553 fprintf_unfiltered (gdb_stdlog
,
6554 "Done expanding %s at offset 0x%x\n",
6555 per_cu
->is_debug_types
? "TU" : "CU",
6556 per_cu
->offset
.sect_off
);
6560 item
->per_cu
->queued
= 0;
6561 next_item
= item
->next
;
6565 dwarf2_queue_tail
= NULL
;
6567 if (dwarf2_read_debug
)
6569 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
6570 dwarf2_per_objfile
->objfile
->name
);
6574 /* Free all allocated queue entries. This function only releases anything if
6575 an error was thrown; if the queue was processed then it would have been
6576 freed as we went along. */
6579 dwarf2_release_queue (void *dummy
)
6581 struct dwarf2_queue_item
*item
, *last
;
6583 item
= dwarf2_queue
;
6586 /* Anything still marked queued is likely to be in an
6587 inconsistent state, so discard it. */
6588 if (item
->per_cu
->queued
)
6590 if (item
->per_cu
->cu
!= NULL
)
6591 free_one_cached_comp_unit (item
->per_cu
);
6592 item
->per_cu
->queued
= 0;
6600 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
6603 /* Read in full symbols for PST, and anything it depends on. */
6606 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
6608 struct dwarf2_per_cu_data
*per_cu
;
6614 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
6615 if (!pst
->dependencies
[i
]->readin
6616 && pst
->dependencies
[i
]->user
== NULL
)
6618 /* Inform about additional files that need to be read in. */
6621 /* FIXME: i18n: Need to make this a single string. */
6622 fputs_filtered (" ", gdb_stdout
);
6624 fputs_filtered ("and ", gdb_stdout
);
6626 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
6627 wrap_here (""); /* Flush output. */
6628 gdb_flush (gdb_stdout
);
6630 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
6633 per_cu
= pst
->read_symtab_private
;
6637 /* It's an include file, no symbols to read for it.
6638 Everything is in the parent symtab. */
6643 dw2_do_instantiate_symtab (per_cu
);
6646 /* Trivial hash function for die_info: the hash value of a DIE
6647 is its offset in .debug_info for this objfile. */
6650 die_hash (const void *item
)
6652 const struct die_info
*die
= item
;
6654 return die
->offset
.sect_off
;
6657 /* Trivial comparison function for die_info structures: two DIEs
6658 are equal if they have the same offset. */
6661 die_eq (const void *item_lhs
, const void *item_rhs
)
6663 const struct die_info
*die_lhs
= item_lhs
;
6664 const struct die_info
*die_rhs
= item_rhs
;
6666 return die_lhs
->offset
.sect_off
== die_rhs
->offset
.sect_off
;
6669 /* die_reader_func for load_full_comp_unit.
6670 This is identical to read_signatured_type_reader,
6671 but is kept separate for now. */
6674 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
6676 struct die_info
*comp_unit_die
,
6680 struct dwarf2_cu
*cu
= reader
->cu
;
6681 enum language
*language_ptr
= data
;
6683 gdb_assert (cu
->die_hash
== NULL
);
6685 htab_create_alloc_ex (cu
->header
.length
/ 12,
6689 &cu
->comp_unit_obstack
,
6690 hashtab_obstack_allocate
,
6691 dummy_obstack_deallocate
);
6694 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
6695 &info_ptr
, comp_unit_die
);
6696 cu
->dies
= comp_unit_die
;
6697 /* comp_unit_die is not stored in die_hash, no need. */
6699 /* We try not to read any attributes in this function, because not
6700 all CUs needed for references have been loaded yet, and symbol
6701 table processing isn't initialized. But we have to set the CU language,
6702 or we won't be able to build types correctly.
6703 Similarly, if we do not read the producer, we can not apply
6704 producer-specific interpretation. */
6705 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
6708 /* Load the DIEs associated with PER_CU into memory. */
6711 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
6712 enum language pretend_language
)
6714 gdb_assert (! this_cu
->is_debug_types
);
6716 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
6717 load_full_comp_unit_reader
, &pretend_language
);
6720 /* Add a DIE to the delayed physname list. */
6723 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
6724 const char *name
, struct die_info
*die
,
6725 struct dwarf2_cu
*cu
)
6727 struct delayed_method_info mi
;
6729 mi
.fnfield_index
= fnfield_index
;
6733 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
6736 /* A cleanup for freeing the delayed method list. */
6739 free_delayed_list (void *ptr
)
6741 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
6742 if (cu
->method_list
!= NULL
)
6744 VEC_free (delayed_method_info
, cu
->method_list
);
6745 cu
->method_list
= NULL
;
6749 /* Compute the physnames of any methods on the CU's method list.
6751 The computation of method physnames is delayed in order to avoid the
6752 (bad) condition that one of the method's formal parameters is of an as yet
6756 compute_delayed_physnames (struct dwarf2_cu
*cu
)
6759 struct delayed_method_info
*mi
;
6760 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
6762 const char *physname
;
6763 struct fn_fieldlist
*fn_flp
6764 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
6765 physname
= dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
6766 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
6770 /* Go objects should be embedded in a DW_TAG_module DIE,
6771 and it's not clear if/how imported objects will appear.
6772 To keep Go support simple until that's worked out,
6773 go back through what we've read and create something usable.
6774 We could do this while processing each DIE, and feels kinda cleaner,
6775 but that way is more invasive.
6776 This is to, for example, allow the user to type "p var" or "b main"
6777 without having to specify the package name, and allow lookups
6778 of module.object to work in contexts that use the expression
6782 fixup_go_packaging (struct dwarf2_cu
*cu
)
6784 char *package_name
= NULL
;
6785 struct pending
*list
;
6788 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
6790 for (i
= 0; i
< list
->nsyms
; ++i
)
6792 struct symbol
*sym
= list
->symbol
[i
];
6794 if (SYMBOL_LANGUAGE (sym
) == language_go
6795 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
6797 char *this_package_name
= go_symbol_package_name (sym
);
6799 if (this_package_name
== NULL
)
6801 if (package_name
== NULL
)
6802 package_name
= this_package_name
;
6805 if (strcmp (package_name
, this_package_name
) != 0)
6806 complaint (&symfile_complaints
,
6807 _("Symtab %s has objects from two different Go packages: %s and %s"),
6808 (SYMBOL_SYMTAB (sym
)
6809 ? SYMBOL_SYMTAB (sym
)->filename
6810 : cu
->objfile
->name
),
6811 this_package_name
, package_name
);
6812 xfree (this_package_name
);
6818 if (package_name
!= NULL
)
6820 struct objfile
*objfile
= cu
->objfile
;
6821 const char *saved_package_name
= obstack_copy0 (&objfile
->objfile_obstack
,
6823 strlen (package_name
));
6824 struct type
*type
= init_type (TYPE_CODE_MODULE
, 0, 0,
6825 saved_package_name
, objfile
);
6828 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6830 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
6831 SYMBOL_SET_LANGUAGE (sym
, language_go
);
6832 SYMBOL_SET_NAMES (sym
, saved_package_name
,
6833 strlen (saved_package_name
), 0, objfile
);
6834 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6835 e.g., "main" finds the "main" module and not C's main(). */
6836 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6837 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6838 SYMBOL_TYPE (sym
) = type
;
6840 add_symbol_to_list (sym
, &global_symbols
);
6842 xfree (package_name
);
6846 static void compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
);
6848 /* Return the symtab for PER_CU. This works properly regardless of
6849 whether we're using the index or psymtabs. */
6851 static struct symtab
*
6852 get_symtab (struct dwarf2_per_cu_data
*per_cu
)
6854 return (dwarf2_per_objfile
->using_index
6855 ? per_cu
->v
.quick
->symtab
6856 : per_cu
->v
.psymtab
->symtab
);
6859 /* A helper function for computing the list of all symbol tables
6860 included by PER_CU. */
6863 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr
) **result
,
6864 htab_t all_children
,
6865 struct dwarf2_per_cu_data
*per_cu
)
6869 struct dwarf2_per_cu_data
*iter
;
6871 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
6874 /* This inclusion and its children have been processed. */
6879 /* Only add a CU if it has a symbol table. */
6880 if (get_symtab (per_cu
) != NULL
)
6881 VEC_safe_push (dwarf2_per_cu_ptr
, *result
, per_cu
);
6884 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
6886 recursively_compute_inclusions (result
, all_children
, iter
);
6889 /* Compute the symtab 'includes' fields for the symtab related to
6893 compute_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
6895 gdb_assert (! per_cu
->is_debug_types
);
6897 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
6900 struct dwarf2_per_cu_data
*iter
;
6901 VEC (dwarf2_per_cu_ptr
) *result_children
= NULL
;
6902 htab_t all_children
;
6903 struct symtab
*symtab
= get_symtab (per_cu
);
6905 /* If we don't have a symtab, we can just skip this case. */
6909 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
6910 NULL
, xcalloc
, xfree
);
6913 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
6916 recursively_compute_inclusions (&result_children
, all_children
, iter
);
6918 /* Now we have a transitive closure of all the included CUs, and
6919 for .gdb_index version 7 the included TUs, so we can convert it
6920 to a list of symtabs. */
6921 len
= VEC_length (dwarf2_per_cu_ptr
, result_children
);
6923 = obstack_alloc (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
6924 (len
+ 1) * sizeof (struct symtab
*));
6926 VEC_iterate (dwarf2_per_cu_ptr
, result_children
, ix
, iter
);
6928 symtab
->includes
[ix
] = get_symtab (iter
);
6929 symtab
->includes
[len
] = NULL
;
6931 VEC_free (dwarf2_per_cu_ptr
, result_children
);
6932 htab_delete (all_children
);
6936 /* Compute the 'includes' field for the symtabs of all the CUs we just
6940 process_cu_includes (void)
6943 struct dwarf2_per_cu_data
*iter
;
6946 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
6950 if (! iter
->is_debug_types
)
6951 compute_symtab_includes (iter
);
6954 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
6957 /* Generate full symbol information for PER_CU, whose DIEs have
6958 already been loaded into memory. */
6961 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
6962 enum language pretend_language
)
6964 struct dwarf2_cu
*cu
= per_cu
->cu
;
6965 struct objfile
*objfile
= per_cu
->objfile
;
6966 CORE_ADDR lowpc
, highpc
;
6967 struct symtab
*symtab
;
6968 struct cleanup
*back_to
, *delayed_list_cleanup
;
6970 struct block
*static_block
;
6972 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6975 back_to
= make_cleanup (really_free_pendings
, NULL
);
6976 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
6978 cu
->list_in_scope
= &file_symbols
;
6980 cu
->language
= pretend_language
;
6981 cu
->language_defn
= language_def (cu
->language
);
6983 /* Do line number decoding in read_file_scope () */
6984 process_die (cu
->dies
, cu
);
6986 /* For now fudge the Go package. */
6987 if (cu
->language
== language_go
)
6988 fixup_go_packaging (cu
);
6990 /* Now that we have processed all the DIEs in the CU, all the types
6991 should be complete, and it should now be safe to compute all of the
6993 compute_delayed_physnames (cu
);
6994 do_cleanups (delayed_list_cleanup
);
6996 /* Some compilers don't define a DW_AT_high_pc attribute for the
6997 compilation unit. If the DW_AT_high_pc is missing, synthesize
6998 it, by scanning the DIE's below the compilation unit. */
6999 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
7002 = end_symtab_get_static_block (highpc
+ baseaddr
, objfile
, 0,
7003 per_cu
->imported_symtabs
!= NULL
);
7005 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7006 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7007 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7008 addrmap to help ensure it has an accurate map of pc values belonging to
7010 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
7012 symtab
= end_symtab_from_static_block (static_block
, objfile
,
7013 SECT_OFF_TEXT (objfile
), 0);
7017 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
7019 /* Set symtab language to language from DW_AT_language. If the
7020 compilation is from a C file generated by language preprocessors, do
7021 not set the language if it was already deduced by start_subfile. */
7022 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7023 symtab
->language
= cu
->language
;
7025 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7026 produce DW_AT_location with location lists but it can be possibly
7027 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7028 there were bugs in prologue debug info, fixed later in GCC-4.5
7029 by "unwind info for epilogues" patch (which is not directly related).
7031 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7032 needed, it would be wrong due to missing DW_AT_producer there.
7034 Still one can confuse GDB by using non-standard GCC compilation
7035 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7037 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
7038 symtab
->locations_valid
= 1;
7040 if (gcc_4_minor
>= 5)
7041 symtab
->epilogue_unwind_valid
= 1;
7043 symtab
->call_site_htab
= cu
->call_site_htab
;
7046 if (dwarf2_per_objfile
->using_index
)
7047 per_cu
->v
.quick
->symtab
= symtab
;
7050 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7051 pst
->symtab
= symtab
;
7055 /* Push it for inclusion processing later. */
7056 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
7058 do_cleanups (back_to
);
7061 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7062 already been loaded into memory. */
7065 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
7066 enum language pretend_language
)
7068 struct dwarf2_cu
*cu
= per_cu
->cu
;
7069 struct objfile
*objfile
= per_cu
->objfile
;
7070 struct symtab
*symtab
;
7071 struct cleanup
*back_to
, *delayed_list_cleanup
;
7074 back_to
= make_cleanup (really_free_pendings
, NULL
);
7075 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
7077 cu
->list_in_scope
= &file_symbols
;
7079 cu
->language
= pretend_language
;
7080 cu
->language_defn
= language_def (cu
->language
);
7082 /* The symbol tables are set up in read_type_unit_scope. */
7083 process_die (cu
->dies
, cu
);
7085 /* For now fudge the Go package. */
7086 if (cu
->language
== language_go
)
7087 fixup_go_packaging (cu
);
7089 /* Now that we have processed all the DIEs in the CU, all the types
7090 should be complete, and it should now be safe to compute all of the
7092 compute_delayed_physnames (cu
);
7093 do_cleanups (delayed_list_cleanup
);
7095 /* TUs share symbol tables.
7096 If this is the first TU to use this symtab, complete the construction
7097 of it with end_expandable_symtab. Otherwise, complete the addition of
7098 this TU's symbols to the existing symtab. */
7099 if (per_cu
->type_unit_group
->primary_symtab
== NULL
)
7101 symtab
= end_expandable_symtab (0, objfile
, SECT_OFF_TEXT (objfile
));
7102 per_cu
->type_unit_group
->primary_symtab
= symtab
;
7106 /* Set symtab language to language from DW_AT_language. If the
7107 compilation is from a C file generated by language preprocessors,
7108 do not set the language if it was already deduced by
7110 if (!(cu
->language
== language_c
&& symtab
->language
!= language_c
))
7111 symtab
->language
= cu
->language
;
7116 augment_type_symtab (objfile
,
7117 per_cu
->type_unit_group
->primary_symtab
);
7118 symtab
= per_cu
->type_unit_group
->primary_symtab
;
7121 if (dwarf2_per_objfile
->using_index
)
7122 per_cu
->v
.quick
->symtab
= symtab
;
7125 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
7126 pst
->symtab
= symtab
;
7130 do_cleanups (back_to
);
7133 /* Process an imported unit DIE. */
7136 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7138 struct attribute
*attr
;
7140 /* For now we don't handle imported units in type units. */
7141 if (cu
->per_cu
->is_debug_types
)
7143 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7144 " supported in type units [in module %s]"),
7148 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7151 struct dwarf2_per_cu_data
*per_cu
;
7152 struct symtab
*imported_symtab
;
7156 offset
= dwarf2_get_ref_die_offset (attr
);
7157 is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
7158 per_cu
= dwarf2_find_containing_comp_unit (offset
, is_dwz
, cu
->objfile
);
7160 /* Queue the unit, if needed. */
7161 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
7162 load_full_comp_unit (per_cu
, cu
->language
);
7164 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
7169 /* Process a die and its children. */
7172 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7176 case DW_TAG_padding
:
7178 case DW_TAG_compile_unit
:
7179 case DW_TAG_partial_unit
:
7180 read_file_scope (die
, cu
);
7182 case DW_TAG_type_unit
:
7183 read_type_unit_scope (die
, cu
);
7185 case DW_TAG_subprogram
:
7186 case DW_TAG_inlined_subroutine
:
7187 read_func_scope (die
, cu
);
7189 case DW_TAG_lexical_block
:
7190 case DW_TAG_try_block
:
7191 case DW_TAG_catch_block
:
7192 read_lexical_block_scope (die
, cu
);
7194 case DW_TAG_GNU_call_site
:
7195 read_call_site_scope (die
, cu
);
7197 case DW_TAG_class_type
:
7198 case DW_TAG_interface_type
:
7199 case DW_TAG_structure_type
:
7200 case DW_TAG_union_type
:
7201 process_structure_scope (die
, cu
);
7203 case DW_TAG_enumeration_type
:
7204 process_enumeration_scope (die
, cu
);
7207 /* These dies have a type, but processing them does not create
7208 a symbol or recurse to process the children. Therefore we can
7209 read them on-demand through read_type_die. */
7210 case DW_TAG_subroutine_type
:
7211 case DW_TAG_set_type
:
7212 case DW_TAG_array_type
:
7213 case DW_TAG_pointer_type
:
7214 case DW_TAG_ptr_to_member_type
:
7215 case DW_TAG_reference_type
:
7216 case DW_TAG_string_type
:
7219 case DW_TAG_base_type
:
7220 case DW_TAG_subrange_type
:
7221 case DW_TAG_typedef
:
7222 /* Add a typedef symbol for the type definition, if it has a
7224 new_symbol (die
, read_type_die (die
, cu
), cu
);
7226 case DW_TAG_common_block
:
7227 read_common_block (die
, cu
);
7229 case DW_TAG_common_inclusion
:
7231 case DW_TAG_namespace
:
7232 processing_has_namespace_info
= 1;
7233 read_namespace (die
, cu
);
7236 processing_has_namespace_info
= 1;
7237 read_module (die
, cu
);
7239 case DW_TAG_imported_declaration
:
7240 case DW_TAG_imported_module
:
7241 processing_has_namespace_info
= 1;
7242 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
7243 || cu
->language
!= language_fortran
))
7244 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
7245 dwarf_tag_name (die
->tag
));
7246 read_import_statement (die
, cu
);
7249 case DW_TAG_imported_unit
:
7250 process_imported_unit_die (die
, cu
);
7254 new_symbol (die
, NULL
, cu
);
7259 /* A helper function for dwarf2_compute_name which determines whether DIE
7260 needs to have the name of the scope prepended to the name listed in the
7264 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7266 struct attribute
*attr
;
7270 case DW_TAG_namespace
:
7271 case DW_TAG_typedef
:
7272 case DW_TAG_class_type
:
7273 case DW_TAG_interface_type
:
7274 case DW_TAG_structure_type
:
7275 case DW_TAG_union_type
:
7276 case DW_TAG_enumeration_type
:
7277 case DW_TAG_enumerator
:
7278 case DW_TAG_subprogram
:
7282 case DW_TAG_variable
:
7283 case DW_TAG_constant
:
7284 /* We only need to prefix "globally" visible variables. These include
7285 any variable marked with DW_AT_external or any variable that
7286 lives in a namespace. [Variables in anonymous namespaces
7287 require prefixing, but they are not DW_AT_external.] */
7289 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
7291 struct dwarf2_cu
*spec_cu
= cu
;
7293 return die_needs_namespace (die_specification (die
, &spec_cu
),
7297 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
7298 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
7299 && die
->parent
->tag
!= DW_TAG_module
)
7301 /* A variable in a lexical block of some kind does not need a
7302 namespace, even though in C++ such variables may be external
7303 and have a mangled name. */
7304 if (die
->parent
->tag
== DW_TAG_lexical_block
7305 || die
->parent
->tag
== DW_TAG_try_block
7306 || die
->parent
->tag
== DW_TAG_catch_block
7307 || die
->parent
->tag
== DW_TAG_subprogram
)
7316 /* Retrieve the last character from a mem_file. */
7319 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
7321 char *last_char_p
= (char *) object
;
7324 *last_char_p
= buffer
[length
- 1];
7327 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7328 compute the physname for the object, which include a method's:
7329 - formal parameters (C++/Java),
7330 - receiver type (Go),
7331 - return type (Java).
7333 The term "physname" is a bit confusing.
7334 For C++, for example, it is the demangled name.
7335 For Go, for example, it's the mangled name.
7337 For Ada, return the DIE's linkage name rather than the fully qualified
7338 name. PHYSNAME is ignored..
7340 The result is allocated on the objfile_obstack and canonicalized. */
7343 dwarf2_compute_name (const char *name
,
7344 struct die_info
*die
, struct dwarf2_cu
*cu
,
7347 struct objfile
*objfile
= cu
->objfile
;
7350 name
= dwarf2_name (die
, cu
);
7352 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7353 compute it by typename_concat inside GDB. */
7354 if (cu
->language
== language_ada
7355 || (cu
->language
== language_fortran
&& physname
))
7357 /* For Ada unit, we prefer the linkage name over the name, as
7358 the former contains the exported name, which the user expects
7359 to be able to reference. Ideally, we want the user to be able
7360 to reference this entity using either natural or linkage name,
7361 but we haven't started looking at this enhancement yet. */
7362 struct attribute
*attr
;
7364 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7366 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7367 if (attr
&& DW_STRING (attr
))
7368 return DW_STRING (attr
);
7371 /* These are the only languages we know how to qualify names in. */
7373 && (cu
->language
== language_cplus
|| cu
->language
== language_java
7374 || cu
->language
== language_fortran
))
7376 if (die_needs_namespace (die
, cu
))
7380 struct ui_file
*buf
;
7382 prefix
= determine_prefix (die
, cu
);
7383 buf
= mem_fileopen ();
7384 if (*prefix
!= '\0')
7386 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
7389 fputs_unfiltered (prefixed_name
, buf
);
7390 xfree (prefixed_name
);
7393 fputs_unfiltered (name
, buf
);
7395 /* Template parameters may be specified in the DIE's DW_AT_name, or
7396 as children with DW_TAG_template_type_param or
7397 DW_TAG_value_type_param. If the latter, add them to the name
7398 here. If the name already has template parameters, then
7399 skip this step; some versions of GCC emit both, and
7400 it is more efficient to use the pre-computed name.
7402 Something to keep in mind about this process: it is very
7403 unlikely, or in some cases downright impossible, to produce
7404 something that will match the mangled name of a function.
7405 If the definition of the function has the same debug info,
7406 we should be able to match up with it anyway. But fallbacks
7407 using the minimal symbol, for instance to find a method
7408 implemented in a stripped copy of libstdc++, will not work.
7409 If we do not have debug info for the definition, we will have to
7410 match them up some other way.
7412 When we do name matching there is a related problem with function
7413 templates; two instantiated function templates are allowed to
7414 differ only by their return types, which we do not add here. */
7416 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
7418 struct attribute
*attr
;
7419 struct die_info
*child
;
7422 die
->building_fullname
= 1;
7424 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
7429 struct dwarf2_locexpr_baton
*baton
;
7432 if (child
->tag
!= DW_TAG_template_type_param
7433 && child
->tag
!= DW_TAG_template_value_param
)
7438 fputs_unfiltered ("<", buf
);
7442 fputs_unfiltered (", ", buf
);
7444 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
7447 complaint (&symfile_complaints
,
7448 _("template parameter missing DW_AT_type"));
7449 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
7452 type
= die_type (child
, cu
);
7454 if (child
->tag
== DW_TAG_template_type_param
)
7456 c_print_type (type
, "", buf
, -1, 0, &type_print_raw_options
);
7460 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
7463 complaint (&symfile_complaints
,
7464 _("template parameter missing "
7465 "DW_AT_const_value"));
7466 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
7470 dwarf2_const_value_attr (attr
, type
, name
,
7471 &cu
->comp_unit_obstack
, cu
,
7472 &value
, &bytes
, &baton
);
7474 if (TYPE_NOSIGN (type
))
7475 /* GDB prints characters as NUMBER 'CHAR'. If that's
7476 changed, this can use value_print instead. */
7477 c_printchar (value
, type
, buf
);
7480 struct value_print_options opts
;
7483 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
7487 else if (bytes
!= NULL
)
7489 v
= allocate_value (type
);
7490 memcpy (value_contents_writeable (v
), bytes
,
7491 TYPE_LENGTH (type
));
7494 v
= value_from_longest (type
, value
);
7496 /* Specify decimal so that we do not depend on
7498 get_formatted_print_options (&opts
, 'd');
7500 value_print (v
, buf
, &opts
);
7506 die
->building_fullname
= 0;
7510 /* Close the argument list, with a space if necessary
7511 (nested templates). */
7512 char last_char
= '\0';
7513 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
7514 if (last_char
== '>')
7515 fputs_unfiltered (" >", buf
);
7517 fputs_unfiltered (">", buf
);
7521 /* For Java and C++ methods, append formal parameter type
7522 information, if PHYSNAME. */
7524 if (physname
&& die
->tag
== DW_TAG_subprogram
7525 && (cu
->language
== language_cplus
7526 || cu
->language
== language_java
))
7528 struct type
*type
= read_type_die (die
, cu
);
7530 c_type_print_args (type
, buf
, 1, cu
->language
,
7531 &type_print_raw_options
);
7533 if (cu
->language
== language_java
)
7535 /* For java, we must append the return type to method
7537 if (die
->tag
== DW_TAG_subprogram
)
7538 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
7539 0, 0, &type_print_raw_options
);
7541 else if (cu
->language
== language_cplus
)
7543 /* Assume that an artificial first parameter is
7544 "this", but do not crash if it is not. RealView
7545 marks unnamed (and thus unused) parameters as
7546 artificial; there is no way to differentiate
7548 if (TYPE_NFIELDS (type
) > 0
7549 && TYPE_FIELD_ARTIFICIAL (type
, 0)
7550 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
7551 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
7553 fputs_unfiltered (" const", buf
);
7557 name
= ui_file_obsavestring (buf
, &objfile
->objfile_obstack
,
7559 ui_file_delete (buf
);
7561 if (cu
->language
== language_cplus
)
7564 = dwarf2_canonicalize_name (name
, cu
,
7565 &objfile
->objfile_obstack
);
7576 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7577 If scope qualifiers are appropriate they will be added. The result
7578 will be allocated on the objfile_obstack, or NULL if the DIE does
7579 not have a name. NAME may either be from a previous call to
7580 dwarf2_name or NULL.
7582 The output string will be canonicalized (if C++/Java). */
7585 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7587 return dwarf2_compute_name (name
, die
, cu
, 0);
7590 /* Construct a physname for the given DIE in CU. NAME may either be
7591 from a previous call to dwarf2_name or NULL. The result will be
7592 allocated on the objfile_objstack or NULL if the DIE does not have a
7595 The output string will be canonicalized (if C++/Java). */
7598 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
7600 struct objfile
*objfile
= cu
->objfile
;
7601 struct attribute
*attr
;
7602 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
7603 struct cleanup
*back_to
;
7606 /* In this case dwarf2_compute_name is just a shortcut not building anything
7608 if (!die_needs_namespace (die
, cu
))
7609 return dwarf2_compute_name (name
, die
, cu
, 1);
7611 back_to
= make_cleanup (null_cleanup
, NULL
);
7613 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
7615 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7617 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7619 if (attr
&& DW_STRING (attr
))
7623 mangled
= DW_STRING (attr
);
7625 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7626 type. It is easier for GDB users to search for such functions as
7627 `name(params)' than `long name(params)'. In such case the minimal
7628 symbol names do not match the full symbol names but for template
7629 functions there is never a need to look up their definition from their
7630 declaration so the only disadvantage remains the minimal symbol
7631 variant `long name(params)' does not have the proper inferior type.
7634 if (cu
->language
== language_go
)
7636 /* This is a lie, but we already lie to the caller new_symbol_full.
7637 new_symbol_full assumes we return the mangled name.
7638 This just undoes that lie until things are cleaned up. */
7643 demangled
= cplus_demangle (mangled
,
7644 (DMGL_PARAMS
| DMGL_ANSI
7645 | (cu
->language
== language_java
7646 ? DMGL_JAVA
| DMGL_RET_POSTFIX
7651 make_cleanup (xfree
, demangled
);
7661 if (canon
== NULL
|| check_physname
)
7663 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
7665 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
7667 /* It may not mean a bug in GDB. The compiler could also
7668 compute DW_AT_linkage_name incorrectly. But in such case
7669 GDB would need to be bug-to-bug compatible. */
7671 complaint (&symfile_complaints
,
7672 _("Computed physname <%s> does not match demangled <%s> "
7673 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7674 physname
, canon
, mangled
, die
->offset
.sect_off
, objfile
->name
);
7676 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7677 is available here - over computed PHYSNAME. It is safer
7678 against both buggy GDB and buggy compilers. */
7692 retval
= obstack_copy0 (&objfile
->objfile_obstack
, retval
, strlen (retval
));
7694 do_cleanups (back_to
);
7698 /* Read the import statement specified by the given die and record it. */
7701 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
7703 struct objfile
*objfile
= cu
->objfile
;
7704 struct attribute
*import_attr
;
7705 struct die_info
*imported_die
, *child_die
;
7706 struct dwarf2_cu
*imported_cu
;
7707 const char *imported_name
;
7708 const char *imported_name_prefix
;
7709 const char *canonical_name
;
7710 const char *import_alias
;
7711 const char *imported_declaration
= NULL
;
7712 const char *import_prefix
;
7713 VEC (const_char_ptr
) *excludes
= NULL
;
7714 struct cleanup
*cleanups
;
7716 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
7717 if (import_attr
== NULL
)
7719 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7720 dwarf_tag_name (die
->tag
));
7725 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
7726 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7727 if (imported_name
== NULL
)
7729 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7731 The import in the following code:
7745 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7746 <52> DW_AT_decl_file : 1
7747 <53> DW_AT_decl_line : 6
7748 <54> DW_AT_import : <0x75>
7749 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7751 <5b> DW_AT_decl_file : 1
7752 <5c> DW_AT_decl_line : 2
7753 <5d> DW_AT_type : <0x6e>
7755 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7756 <76> DW_AT_byte_size : 4
7757 <77> DW_AT_encoding : 5 (signed)
7759 imports the wrong die ( 0x75 instead of 0x58 ).
7760 This case will be ignored until the gcc bug is fixed. */
7764 /* Figure out the local name after import. */
7765 import_alias
= dwarf2_name (die
, cu
);
7767 /* Figure out where the statement is being imported to. */
7768 import_prefix
= determine_prefix (die
, cu
);
7770 /* Figure out what the scope of the imported die is and prepend it
7771 to the name of the imported die. */
7772 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
7774 if (imported_die
->tag
!= DW_TAG_namespace
7775 && imported_die
->tag
!= DW_TAG_module
)
7777 imported_declaration
= imported_name
;
7778 canonical_name
= imported_name_prefix
;
7780 else if (strlen (imported_name_prefix
) > 0)
7781 canonical_name
= obconcat (&objfile
->objfile_obstack
,
7782 imported_name_prefix
, "::", imported_name
,
7785 canonical_name
= imported_name
;
7787 cleanups
= make_cleanup (VEC_cleanup (const_char_ptr
), &excludes
);
7789 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
7790 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
7791 child_die
= sibling_die (child_die
))
7793 /* DWARF-4: A Fortran use statement with a “rename list” may be
7794 represented by an imported module entry with an import attribute
7795 referring to the module and owned entries corresponding to those
7796 entities that are renamed as part of being imported. */
7798 if (child_die
->tag
!= DW_TAG_imported_declaration
)
7800 complaint (&symfile_complaints
,
7801 _("child DW_TAG_imported_declaration expected "
7802 "- DIE at 0x%x [in module %s]"),
7803 child_die
->offset
.sect_off
, objfile
->name
);
7807 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
7808 if (import_attr
== NULL
)
7810 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
7811 dwarf_tag_name (child_die
->tag
));
7816 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
7818 imported_name
= dwarf2_name (imported_die
, imported_cu
);
7819 if (imported_name
== NULL
)
7821 complaint (&symfile_complaints
,
7822 _("child DW_TAG_imported_declaration has unknown "
7823 "imported name - DIE at 0x%x [in module %s]"),
7824 child_die
->offset
.sect_off
, objfile
->name
);
7828 VEC_safe_push (const_char_ptr
, excludes
, imported_name
);
7830 process_die (child_die
, cu
);
7833 cp_add_using_directive (import_prefix
,
7836 imported_declaration
,
7839 &objfile
->objfile_obstack
);
7841 do_cleanups (cleanups
);
7844 /* Cleanup function for handle_DW_AT_stmt_list. */
7847 free_cu_line_header (void *arg
)
7849 struct dwarf2_cu
*cu
= arg
;
7851 free_line_header (cu
->line_header
);
7852 cu
->line_header
= NULL
;
7855 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7856 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7857 this, it was first present in GCC release 4.3.0. */
7860 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
7862 if (!cu
->checked_producer
)
7863 check_producer (cu
);
7865 return cu
->producer_is_gcc_lt_4_3
;
7869 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
7870 const char **name
, const char **comp_dir
)
7872 struct attribute
*attr
;
7877 /* Find the filename. Do not use dwarf2_name here, since the filename
7878 is not a source language identifier. */
7879 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7882 *name
= DW_STRING (attr
);
7885 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
7887 *comp_dir
= DW_STRING (attr
);
7888 else if (producer_is_gcc_lt_4_3 (cu
) && *name
!= NULL
7889 && IS_ABSOLUTE_PATH (*name
))
7891 char *d
= ldirname (*name
);
7895 make_cleanup (xfree
, d
);
7897 if (*comp_dir
!= NULL
)
7899 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7900 directory, get rid of it. */
7901 char *cp
= strchr (*comp_dir
, ':');
7903 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
7908 *name
= "<unknown>";
7911 /* Handle DW_AT_stmt_list for a compilation unit.
7912 DIE is the DW_TAG_compile_unit die for CU.
7913 COMP_DIR is the compilation directory.
7914 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7917 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
7918 const char *comp_dir
)
7920 struct attribute
*attr
;
7922 gdb_assert (! cu
->per_cu
->is_debug_types
);
7924 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7927 unsigned int line_offset
= DW_UNSND (attr
);
7928 struct line_header
*line_header
7929 = dwarf_decode_line_header (line_offset
, cu
);
7933 cu
->line_header
= line_header
;
7934 make_cleanup (free_cu_line_header
, cu
);
7935 dwarf_decode_lines (line_header
, comp_dir
, cu
, NULL
, 1);
7940 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7943 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7945 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7946 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7947 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
7948 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
7949 struct attribute
*attr
;
7950 const char *name
= NULL
;
7951 const char *comp_dir
= NULL
;
7952 struct die_info
*child_die
;
7953 bfd
*abfd
= objfile
->obfd
;
7956 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7958 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
7960 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7961 from finish_block. */
7962 if (lowpc
== ((CORE_ADDR
) -1))
7967 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
7969 prepare_one_comp_unit (cu
, die
, cu
->language
);
7971 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7972 standardised yet. As a workaround for the language detection we fall
7973 back to the DW_AT_producer string. */
7974 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
7975 cu
->language
= language_opencl
;
7977 /* Similar hack for Go. */
7978 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
7979 set_cu_language (DW_LANG_Go
, cu
);
7981 dwarf2_start_symtab (cu
, name
, comp_dir
, lowpc
);
7983 /* Decode line number information if present. We do this before
7984 processing child DIEs, so that the line header table is available
7985 for DW_AT_decl_file. */
7986 handle_DW_AT_stmt_list (die
, cu
, comp_dir
);
7988 /* Process all dies in compilation unit. */
7989 if (die
->child
!= NULL
)
7991 child_die
= die
->child
;
7992 while (child_die
&& child_die
->tag
)
7994 process_die (child_die
, cu
);
7995 child_die
= sibling_die (child_die
);
7999 /* Decode macro information, if present. Dwarf 2 macro information
8000 refers to information in the line number info statement program
8001 header, so we can only read it if we've read the header
8003 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
8004 if (attr
&& cu
->line_header
)
8006 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
8007 complaint (&symfile_complaints
,
8008 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8010 dwarf_decode_macros (cu
, DW_UNSND (attr
), comp_dir
, 1);
8014 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
8015 if (attr
&& cu
->line_header
)
8017 unsigned int macro_offset
= DW_UNSND (attr
);
8019 dwarf_decode_macros (cu
, macro_offset
, comp_dir
, 0);
8023 do_cleanups (back_to
);
8026 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8027 Create the set of symtabs used by this TU, or if this TU is sharing
8028 symtabs with another TU and the symtabs have already been created
8029 then restore those symtabs in the line header.
8030 We don't need the pc/line-number mapping for type units. */
8033 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
8035 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8036 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8037 struct type_unit_group
*tu_group
;
8039 struct line_header
*lh
;
8040 struct attribute
*attr
;
8041 unsigned int i
, line_offset
;
8043 gdb_assert (per_cu
->is_debug_types
);
8045 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
8047 /* If we're using .gdb_index (includes -readnow) then
8048 per_cu->s.type_unit_group may not have been set up yet. */
8049 if (per_cu
->type_unit_group
== NULL
)
8050 per_cu
->type_unit_group
= get_type_unit_group (cu
, attr
);
8051 tu_group
= per_cu
->type_unit_group
;
8053 /* If we've already processed this stmt_list there's no real need to
8054 do it again, we could fake it and just recreate the part we need
8055 (file name,index -> symtab mapping). If data shows this optimization
8056 is useful we can do it then. */
8057 first_time
= tu_group
->primary_symtab
== NULL
;
8059 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8064 line_offset
= DW_UNSND (attr
);
8065 lh
= dwarf_decode_line_header (line_offset
, cu
);
8070 dwarf2_start_symtab (cu
, "", NULL
, 0);
8073 gdb_assert (tu_group
->symtabs
== NULL
);
8076 /* Note: The primary symtab will get allocated at the end. */
8080 cu
->line_header
= lh
;
8081 make_cleanup (free_cu_line_header
, cu
);
8085 dwarf2_start_symtab (cu
, "", NULL
, 0);
8087 tu_group
->num_symtabs
= lh
->num_file_names
;
8088 tu_group
->symtabs
= XNEWVEC (struct symtab
*, lh
->num_file_names
);
8090 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8093 struct file_entry
*fe
= &lh
->file_names
[i
];
8096 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8097 dwarf2_start_subfile (fe
->name
, dir
, NULL
);
8099 /* Note: We don't have to watch for the main subfile here, type units
8100 don't have DW_AT_name. */
8102 if (current_subfile
->symtab
== NULL
)
8104 /* NOTE: start_subfile will recognize when it's been passed
8105 a file it has already seen. So we can't assume there's a
8106 simple mapping from lh->file_names to subfiles,
8107 lh->file_names may contain dups. */
8108 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8112 fe
->symtab
= current_subfile
->symtab
;
8113 tu_group
->symtabs
[i
] = fe
->symtab
;
8120 for (i
= 0; i
< lh
->num_file_names
; ++i
)
8122 struct file_entry
*fe
= &lh
->file_names
[i
];
8124 fe
->symtab
= tu_group
->symtabs
[i
];
8128 /* The main symtab is allocated last. Type units don't have DW_AT_name
8129 so they don't have a "real" (so to speak) symtab anyway.
8130 There is later code that will assign the main symtab to all symbols
8131 that don't have one. We need to handle the case of a symbol with a
8132 missing symtab (DW_AT_decl_file) anyway. */
8135 /* Process DW_TAG_type_unit.
8136 For TUs we want to skip the first top level sibling if it's not the
8137 actual type being defined by this TU. In this case the first top
8138 level sibling is there to provide context only. */
8141 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
8143 struct die_info
*child_die
;
8145 prepare_one_comp_unit (cu
, die
, language_minimal
);
8147 /* Initialize (or reinitialize) the machinery for building symtabs.
8148 We do this before processing child DIEs, so that the line header table
8149 is available for DW_AT_decl_file. */
8150 setup_type_unit_groups (die
, cu
);
8152 if (die
->child
!= NULL
)
8154 child_die
= die
->child
;
8155 while (child_die
&& child_die
->tag
)
8157 process_die (child_die
, cu
);
8158 child_die
= sibling_die (child_die
);
8165 http://gcc.gnu.org/wiki/DebugFission
8166 http://gcc.gnu.org/wiki/DebugFissionDWP
8168 To simplify handling of both DWO files ("object" files with the DWARF info)
8169 and DWP files (a file with the DWOs packaged up into one file), we treat
8170 DWP files as having a collection of virtual DWO files. */
8173 hash_dwo_file (const void *item
)
8175 const struct dwo_file
*dwo_file
= item
;
8177 return htab_hash_string (dwo_file
->name
);
8181 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
8183 const struct dwo_file
*lhs
= item_lhs
;
8184 const struct dwo_file
*rhs
= item_rhs
;
8186 return strcmp (lhs
->name
, rhs
->name
) == 0;
8189 /* Allocate a hash table for DWO files. */
8192 allocate_dwo_file_hash_table (void)
8194 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8196 return htab_create_alloc_ex (41,
8200 &objfile
->objfile_obstack
,
8201 hashtab_obstack_allocate
,
8202 dummy_obstack_deallocate
);
8205 /* Lookup DWO file DWO_NAME. */
8208 lookup_dwo_file_slot (const char *dwo_name
)
8210 struct dwo_file find_entry
;
8213 if (dwarf2_per_objfile
->dwo_files
== NULL
)
8214 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
8216 memset (&find_entry
, 0, sizeof (find_entry
));
8217 find_entry
.name
= dwo_name
;
8218 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
8224 hash_dwo_unit (const void *item
)
8226 const struct dwo_unit
*dwo_unit
= item
;
8228 /* This drops the top 32 bits of the id, but is ok for a hash. */
8229 return dwo_unit
->signature
;
8233 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
8235 const struct dwo_unit
*lhs
= item_lhs
;
8236 const struct dwo_unit
*rhs
= item_rhs
;
8238 /* The signature is assumed to be unique within the DWO file.
8239 So while object file CU dwo_id's always have the value zero,
8240 that's OK, assuming each object file DWO file has only one CU,
8241 and that's the rule for now. */
8242 return lhs
->signature
== rhs
->signature
;
8245 /* Allocate a hash table for DWO CUs,TUs.
8246 There is one of these tables for each of CUs,TUs for each DWO file. */
8249 allocate_dwo_unit_table (struct objfile
*objfile
)
8251 /* Start out with a pretty small number.
8252 Generally DWO files contain only one CU and maybe some TUs. */
8253 return htab_create_alloc_ex (3,
8257 &objfile
->objfile_obstack
,
8258 hashtab_obstack_allocate
,
8259 dummy_obstack_deallocate
);
8262 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8264 struct create_dwo_info_table_data
8266 struct dwo_file
*dwo_file
;
8270 /* die_reader_func for create_dwo_debug_info_hash_table. */
8273 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs
*reader
,
8275 struct die_info
*comp_unit_die
,
8279 struct dwarf2_cu
*cu
= reader
->cu
;
8280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8281 sect_offset offset
= cu
->per_cu
->offset
;
8282 struct dwarf2_section_info
*section
= cu
->per_cu
->info_or_types_section
;
8283 struct create_dwo_info_table_data
*data
= datap
;
8284 struct dwo_file
*dwo_file
= data
->dwo_file
;
8285 htab_t cu_htab
= data
->cu_htab
;
8287 struct attribute
*attr
;
8288 struct dwo_unit
*dwo_unit
;
8290 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
8293 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8294 " its dwo_id [in module %s]"),
8295 offset
.sect_off
, dwo_file
->name
);
8299 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8300 dwo_unit
->dwo_file
= dwo_file
;
8301 dwo_unit
->signature
= DW_UNSND (attr
);
8302 dwo_unit
->info_or_types_section
= section
;
8303 dwo_unit
->offset
= offset
;
8304 dwo_unit
->length
= cu
->per_cu
->length
;
8306 slot
= htab_find_slot (cu_htab
, dwo_unit
, INSERT
);
8307 gdb_assert (slot
!= NULL
);
8310 const struct dwo_unit
*dup_dwo_unit
= *slot
;
8312 complaint (&symfile_complaints
,
8313 _("debug entry at offset 0x%x is duplicate to the entry at"
8314 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8315 offset
.sect_off
, dup_dwo_unit
->offset
.sect_off
,
8316 phex (dwo_unit
->signature
, sizeof (dwo_unit
->signature
)),
8322 if (dwarf2_read_debug
)
8323 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id 0x%s\n",
8325 phex (dwo_unit
->signature
,
8326 sizeof (dwo_unit
->signature
)));
8329 /* Create a hash table to map DWO IDs to their CU entry in
8330 .debug_info.dwo in DWO_FILE.
8331 Note: This function processes DWO files only, not DWP files. */
8334 create_dwo_debug_info_hash_table (struct dwo_file
*dwo_file
)
8336 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8337 struct dwarf2_section_info
*section
= &dwo_file
->sections
.info
;
8340 gdb_byte
*info_ptr
, *end_ptr
;
8341 struct create_dwo_info_table_data create_dwo_info_table_data
;
8343 dwarf2_read_section (objfile
, section
);
8344 info_ptr
= section
->buffer
;
8346 if (info_ptr
== NULL
)
8349 /* We can't set abfd until now because the section may be empty or
8350 not present, in which case section->asection will be NULL. */
8351 abfd
= section
->asection
->owner
;
8353 if (dwarf2_read_debug
)
8354 fprintf_unfiltered (gdb_stdlog
, "Reading .debug_info.dwo for %s:\n",
8355 bfd_get_filename (abfd
));
8357 cu_htab
= allocate_dwo_unit_table (objfile
);
8359 create_dwo_info_table_data
.dwo_file
= dwo_file
;
8360 create_dwo_info_table_data
.cu_htab
= cu_htab
;
8362 end_ptr
= info_ptr
+ section
->size
;
8363 while (info_ptr
< end_ptr
)
8365 struct dwarf2_per_cu_data per_cu
;
8367 memset (&per_cu
, 0, sizeof (per_cu
));
8368 per_cu
.objfile
= objfile
;
8369 per_cu
.is_debug_types
= 0;
8370 per_cu
.offset
.sect_off
= info_ptr
- section
->buffer
;
8371 per_cu
.info_or_types_section
= section
;
8373 init_cutu_and_read_dies_no_follow (&per_cu
,
8374 &dwo_file
->sections
.abbrev
,
8376 create_dwo_debug_info_hash_table_reader
,
8377 &create_dwo_info_table_data
);
8379 info_ptr
+= per_cu
.length
;
8385 /* DWP file .debug_{cu,tu}_index section format:
8386 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8388 Both index sections have the same format, and serve to map a 64-bit
8389 signature to a set of section numbers. Each section begins with a header,
8390 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8391 indexes, and a pool of 32-bit section numbers. The index sections will be
8392 aligned at 8-byte boundaries in the file.
8394 The index section header contains two unsigned 32-bit values (using the
8395 byte order of the application binary):
8397 N, the number of compilation units or type units in the index
8398 M, the number of slots in the hash table
8400 (We assume that N and M will not exceed 2^32 - 1.)
8402 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8404 The hash table begins at offset 8 in the section, and consists of an array
8405 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8406 order of the application binary). Unused slots in the hash table are 0.
8407 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8409 The parallel table begins immediately after the hash table
8410 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8411 array of 32-bit indexes (using the byte order of the application binary),
8412 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8413 table contains a 32-bit index into the pool of section numbers. For unused
8414 hash table slots, the corresponding entry in the parallel table will be 0.
8416 Given a 64-bit compilation unit signature or a type signature S, an entry
8417 in the hash table is located as follows:
8419 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8420 the low-order k bits all set to 1.
8422 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8424 3) If the hash table entry at index H matches the signature, use that
8425 entry. If the hash table entry at index H is unused (all zeroes),
8426 terminate the search: the signature is not present in the table.
8428 4) Let H = (H + H') modulo M. Repeat at Step 3.
8430 Because M > N and H' and M are relatively prime, the search is guaranteed
8431 to stop at an unused slot or find the match.
8433 The pool of section numbers begins immediately following the hash table
8434 (at offset 8 + 12 * M from the beginning of the section). The pool of
8435 section numbers consists of an array of 32-bit words (using the byte order
8436 of the application binary). Each item in the array is indexed starting
8437 from 0. The hash table entry provides the index of the first section
8438 number in the set. Additional section numbers in the set follow, and the
8439 set is terminated by a 0 entry (section number 0 is not used in ELF).
8441 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8442 section must be the first entry in the set, and the .debug_abbrev.dwo must
8443 be the second entry. Other members of the set may follow in any order. */
8445 /* Create a hash table to map DWO IDs to their CU/TU entry in
8446 .debug_{info,types}.dwo in DWP_FILE.
8447 Returns NULL if there isn't one.
8448 Note: This function processes DWP files only, not DWO files. */
8450 static struct dwp_hash_table
*
8451 create_dwp_hash_table (struct dwp_file
*dwp_file
, int is_debug_types
)
8453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8454 bfd
*dbfd
= dwp_file
->dbfd
;
8455 char *index_ptr
, *index_end
;
8456 struct dwarf2_section_info
*index
;
8457 uint32_t version
, nr_units
, nr_slots
;
8458 struct dwp_hash_table
*htab
;
8461 index
= &dwp_file
->sections
.tu_index
;
8463 index
= &dwp_file
->sections
.cu_index
;
8465 if (dwarf2_section_empty_p (index
))
8467 dwarf2_read_section (objfile
, index
);
8469 index_ptr
= index
->buffer
;
8470 index_end
= index_ptr
+ index
->size
;
8472 version
= read_4_bytes (dbfd
, index_ptr
);
8473 index_ptr
+= 8; /* Skip the unused word. */
8474 nr_units
= read_4_bytes (dbfd
, index_ptr
);
8476 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
8481 error (_("Dwarf Error: unsupported DWP file version (%u)"
8483 version
, dwp_file
->name
);
8485 if (nr_slots
!= (nr_slots
& -nr_slots
))
8487 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8488 " is not power of 2 [in module %s]"),
8489 nr_slots
, dwp_file
->name
);
8492 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
8493 htab
->nr_units
= nr_units
;
8494 htab
->nr_slots
= nr_slots
;
8495 htab
->hash_table
= index_ptr
;
8496 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
8497 htab
->section_pool
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
8502 /* Update SECTIONS with the data from SECTP.
8504 This function is like the other "locate" section routines that are
8505 passed to bfd_map_over_sections, but in this context the sections to
8506 read comes from the DWP hash table, not the full ELF section table.
8508 The result is non-zero for success, or zero if an error was found. */
8511 locate_virtual_dwo_sections (asection
*sectp
,
8512 struct virtual_dwo_sections
*sections
)
8514 const struct dwop_section_names
*names
= &dwop_section_names
;
8516 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8518 /* There can be only one. */
8519 if (sections
->abbrev
.asection
!= NULL
)
8521 sections
->abbrev
.asection
= sectp
;
8522 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8524 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
8525 || section_is_p (sectp
->name
, &names
->types_dwo
))
8527 /* There can be only one. */
8528 if (sections
->info_or_types
.asection
!= NULL
)
8530 sections
->info_or_types
.asection
= sectp
;
8531 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
8533 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8535 /* There can be only one. */
8536 if (sections
->line
.asection
!= NULL
)
8538 sections
->line
.asection
= sectp
;
8539 sections
->line
.size
= bfd_get_section_size (sectp
);
8541 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8543 /* There can be only one. */
8544 if (sections
->loc
.asection
!= NULL
)
8546 sections
->loc
.asection
= sectp
;
8547 sections
->loc
.size
= bfd_get_section_size (sectp
);
8549 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8551 /* There can be only one. */
8552 if (sections
->macinfo
.asection
!= NULL
)
8554 sections
->macinfo
.asection
= sectp
;
8555 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8557 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8559 /* There can be only one. */
8560 if (sections
->macro
.asection
!= NULL
)
8562 sections
->macro
.asection
= sectp
;
8563 sections
->macro
.size
= bfd_get_section_size (sectp
);
8565 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8567 /* There can be only one. */
8568 if (sections
->str_offsets
.asection
!= NULL
)
8570 sections
->str_offsets
.asection
= sectp
;
8571 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8575 /* No other kind of section is valid. */
8582 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8583 HTAB is the hash table from the DWP file.
8584 SECTION_INDEX is the index of the DWO in HTAB. */
8586 static struct dwo_unit
*
8587 create_dwo_in_dwp (struct dwp_file
*dwp_file
,
8588 const struct dwp_hash_table
*htab
,
8589 uint32_t section_index
,
8590 ULONGEST signature
, int is_debug_types
)
8592 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8593 bfd
*dbfd
= dwp_file
->dbfd
;
8594 const char *kind
= is_debug_types
? "TU" : "CU";
8595 struct dwo_file
*dwo_file
;
8596 struct dwo_unit
*dwo_unit
;
8597 struct virtual_dwo_sections sections
;
8598 void **dwo_file_slot
;
8599 char *virtual_dwo_name
;
8600 struct dwarf2_section_info
*cutu
;
8601 struct cleanup
*cleanups
;
8604 if (dwarf2_read_debug
)
8606 fprintf_unfiltered (gdb_stdlog
, "Reading %s %u/0x%s in DWP file: %s\n",
8608 section_index
, phex (signature
, sizeof (signature
)),
8612 /* Fetch the sections of this DWO.
8613 Put a limit on the number of sections we look for so that bad data
8614 doesn't cause us to loop forever. */
8616 #define MAX_NR_DWO_SECTIONS \
8617 (1 /* .debug_info or .debug_types */ \
8618 + 1 /* .debug_abbrev */ \
8619 + 1 /* .debug_line */ \
8620 + 1 /* .debug_loc */ \
8621 + 1 /* .debug_str_offsets */ \
8622 + 1 /* .debug_macro */ \
8623 + 1 /* .debug_macinfo */ \
8624 + 1 /* trailing zero */)
8626 memset (§ions
, 0, sizeof (sections
));
8627 cleanups
= make_cleanup (null_cleanup
, 0);
8629 for (i
= 0; i
< MAX_NR_DWO_SECTIONS
; ++i
)
8632 uint32_t section_nr
=
8635 + (section_index
+ i
) * sizeof (uint32_t));
8637 if (section_nr
== 0)
8639 if (section_nr
>= dwp_file
->num_sections
)
8641 error (_("Dwarf Error: bad DWP hash table, section number too large"
8646 sectp
= dwp_file
->elf_sections
[section_nr
];
8647 if (! locate_virtual_dwo_sections (sectp
, §ions
))
8649 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8656 || sections
.info_or_types
.asection
== NULL
8657 || sections
.abbrev
.asection
== NULL
)
8659 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8663 if (i
== MAX_NR_DWO_SECTIONS
)
8665 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8670 /* It's easier for the rest of the code if we fake a struct dwo_file and
8671 have dwo_unit "live" in that. At least for now.
8673 The DWP file can be made up of a random collection of CUs and TUs.
8674 However, for each CU + set of TUs that came from the same original DWO
8675 file, we want to combine them back into a virtual DWO file to save space
8676 (fewer struct dwo_file objects to allocated). Remember that for really
8677 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8680 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8681 sections
.abbrev
.asection
? sections
.abbrev
.asection
->id
: 0,
8682 sections
.line
.asection
? sections
.line
.asection
->id
: 0,
8683 sections
.loc
.asection
? sections
.loc
.asection
->id
: 0,
8684 (sections
.str_offsets
.asection
8685 ? sections
.str_offsets
.asection
->id
8687 make_cleanup (xfree
, virtual_dwo_name
);
8688 /* Can we use an existing virtual DWO file? */
8689 dwo_file_slot
= lookup_dwo_file_slot (virtual_dwo_name
);
8690 /* Create one if necessary. */
8691 if (*dwo_file_slot
== NULL
)
8693 if (dwarf2_read_debug
)
8695 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
8698 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8699 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8701 strlen (virtual_dwo_name
));
8702 dwo_file
->sections
.abbrev
= sections
.abbrev
;
8703 dwo_file
->sections
.line
= sections
.line
;
8704 dwo_file
->sections
.loc
= sections
.loc
;
8705 dwo_file
->sections
.macinfo
= sections
.macinfo
;
8706 dwo_file
->sections
.macro
= sections
.macro
;
8707 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
8708 /* The "str" section is global to the entire DWP file. */
8709 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
8710 /* The info or types section is assigned later to dwo_unit,
8711 there's no need to record it in dwo_file.
8712 Also, we can't simply record type sections in dwo_file because
8713 we record a pointer into the vector in dwo_unit. As we collect more
8714 types we'll grow the vector and eventually have to reallocate space
8715 for it, invalidating all the pointers into the current copy. */
8716 *dwo_file_slot
= dwo_file
;
8720 if (dwarf2_read_debug
)
8722 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
8725 dwo_file
= *dwo_file_slot
;
8727 do_cleanups (cleanups
);
8729 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
8730 dwo_unit
->dwo_file
= dwo_file
;
8731 dwo_unit
->signature
= signature
;
8732 dwo_unit
->info_or_types_section
=
8733 obstack_alloc (&objfile
->objfile_obstack
,
8734 sizeof (struct dwarf2_section_info
));
8735 *dwo_unit
->info_or_types_section
= sections
.info_or_types
;
8736 /* offset, length, type_offset_in_tu are set later. */
8741 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8743 static struct dwo_unit
*
8744 lookup_dwo_in_dwp (struct dwp_file
*dwp_file
,
8745 const struct dwp_hash_table
*htab
,
8746 ULONGEST signature
, int is_debug_types
)
8748 bfd
*dbfd
= dwp_file
->dbfd
;
8749 uint32_t mask
= htab
->nr_slots
- 1;
8750 uint32_t hash
= signature
& mask
;
8751 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
8754 struct dwo_unit find_dwo_cu
, *dwo_cu
;
8756 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
8757 find_dwo_cu
.signature
= signature
;
8758 slot
= htab_find_slot (dwp_file
->loaded_cutus
, &find_dwo_cu
, INSERT
);
8763 /* Use a for loop so that we don't loop forever on bad debug info. */
8764 for (i
= 0; i
< htab
->nr_slots
; ++i
)
8766 ULONGEST signature_in_table
;
8768 signature_in_table
=
8769 read_8_bytes (dbfd
, htab
->hash_table
+ hash
* sizeof (uint64_t));
8770 if (signature_in_table
== signature
)
8772 uint32_t section_index
=
8773 read_4_bytes (dbfd
, htab
->unit_table
+ hash
* sizeof (uint32_t));
8775 *slot
= create_dwo_in_dwp (dwp_file
, htab
, section_index
,
8776 signature
, is_debug_types
);
8779 if (signature_in_table
== 0)
8781 hash
= (hash
+ hash2
) & mask
;
8784 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8789 /* Subroutine of open_dwop_file to simplify it.
8790 Open the file specified by FILE_NAME and hand it off to BFD for
8791 preliminary analysis. Return a newly initialized bfd *, which
8792 includes a canonicalized copy of FILE_NAME.
8793 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8794 In case of trouble, return NULL.
8795 NOTE: This function is derived from symfile_bfd_open. */
8798 try_open_dwop_file (const char *file_name
, int is_dwp
)
8802 char *absolute_name
;
8804 flags
= OPF_TRY_CWD_FIRST
;
8806 flags
|= OPF_SEARCH_IN_PATH
;
8807 desc
= openp (debug_file_directory
, flags
, file_name
,
8808 O_RDONLY
| O_BINARY
, &absolute_name
);
8812 sym_bfd
= gdb_bfd_open (absolute_name
, gnutarget
, desc
);
8815 xfree (absolute_name
);
8818 xfree (absolute_name
);
8819 bfd_set_cacheable (sym_bfd
, 1);
8821 if (!bfd_check_format (sym_bfd
, bfd_object
))
8823 gdb_bfd_unref (sym_bfd
); /* This also closes desc. */
8830 /* Try to open DWO/DWP file FILE_NAME.
8831 COMP_DIR is the DW_AT_comp_dir attribute.
8832 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8833 The result is the bfd handle of the file.
8834 If there is a problem finding or opening the file, return NULL.
8835 Upon success, the canonicalized path of the file is stored in the bfd,
8836 same as symfile_bfd_open. */
8839 open_dwop_file (const char *file_name
, const char *comp_dir
, int is_dwp
)
8843 if (IS_ABSOLUTE_PATH (file_name
))
8844 return try_open_dwop_file (file_name
, is_dwp
);
8846 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8848 if (comp_dir
!= NULL
)
8850 char *path_to_try
= concat (comp_dir
, SLASH_STRING
, file_name
, NULL
);
8852 /* NOTE: If comp_dir is a relative path, this will also try the
8853 search path, which seems useful. */
8854 abfd
= try_open_dwop_file (path_to_try
, is_dwp
);
8855 xfree (path_to_try
);
8860 /* That didn't work, try debug-file-directory, which, despite its name,
8861 is a list of paths. */
8863 if (*debug_file_directory
== '\0')
8866 return try_open_dwop_file (file_name
, is_dwp
);
8869 /* This function is mapped across the sections and remembers the offset and
8870 size of each of the DWO debugging sections we are interested in. */
8873 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
8875 struct dwo_sections
*dwo_sections
= dwo_sections_ptr
;
8876 const struct dwop_section_names
*names
= &dwop_section_names
;
8878 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
8880 dwo_sections
->abbrev
.asection
= sectp
;
8881 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
8883 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
8885 dwo_sections
->info
.asection
= sectp
;
8886 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
8888 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
8890 dwo_sections
->line
.asection
= sectp
;
8891 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
8893 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
8895 dwo_sections
->loc
.asection
= sectp
;
8896 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
8898 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
8900 dwo_sections
->macinfo
.asection
= sectp
;
8901 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
8903 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
8905 dwo_sections
->macro
.asection
= sectp
;
8906 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
8908 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
8910 dwo_sections
->str
.asection
= sectp
;
8911 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
8913 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
8915 dwo_sections
->str_offsets
.asection
= sectp
;
8916 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
8918 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
8920 struct dwarf2_section_info type_section
;
8922 memset (&type_section
, 0, sizeof (type_section
));
8923 type_section
.asection
= sectp
;
8924 type_section
.size
= bfd_get_section_size (sectp
);
8925 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
8930 /* Initialize the use of the DWO file specified by DWO_NAME.
8931 The result is NULL if DWO_NAME can't be found. */
8933 static struct dwo_file
*
8934 open_and_init_dwo_file (const char *dwo_name
, const char *comp_dir
)
8936 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8937 struct dwo_file
*dwo_file
;
8939 struct cleanup
*cleanups
;
8941 dbfd
= open_dwop_file (dwo_name
, comp_dir
, 0);
8944 if (dwarf2_read_debug
)
8945 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
8948 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
8949 dwo_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
8950 dwo_name
, strlen (dwo_name
));
8951 dwo_file
->dbfd
= dbfd
;
8953 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwo_file
);
8955 bfd_map_over_sections (dbfd
, dwarf2_locate_dwo_sections
, &dwo_file
->sections
);
8957 dwo_file
->cus
= create_dwo_debug_info_hash_table (dwo_file
);
8959 dwo_file
->tus
= create_debug_types_hash_table (dwo_file
,
8960 dwo_file
->sections
.types
);
8962 discard_cleanups (cleanups
);
8964 if (dwarf2_read_debug
)
8965 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
8970 /* This function is mapped across the sections and remembers the offset and
8971 size of each of the DWP debugging sections we are interested in. */
8974 dwarf2_locate_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
8976 struct dwp_file
*dwp_file
= dwp_file_ptr
;
8977 const struct dwop_section_names
*names
= &dwop_section_names
;
8978 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
8980 /* Record the ELF section number for later lookup: this is what the
8981 .debug_cu_index,.debug_tu_index tables use. */
8982 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
8983 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
8985 /* Look for specific sections that we need. */
8986 if (section_is_p (sectp
->name
, &names
->str_dwo
))
8988 dwp_file
->sections
.str
.asection
= sectp
;
8989 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
8991 else if (section_is_p (sectp
->name
, &names
->cu_index
))
8993 dwp_file
->sections
.cu_index
.asection
= sectp
;
8994 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
8996 else if (section_is_p (sectp
->name
, &names
->tu_index
))
8998 dwp_file
->sections
.tu_index
.asection
= sectp
;
8999 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
9003 /* Hash function for dwp_file loaded CUs/TUs. */
9006 hash_dwp_loaded_cutus (const void *item
)
9008 const struct dwo_unit
*dwo_unit
= item
;
9010 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9011 return dwo_unit
->signature
;
9014 /* Equality function for dwp_file loaded CUs/TUs. */
9017 eq_dwp_loaded_cutus (const void *a
, const void *b
)
9019 const struct dwo_unit
*dua
= a
;
9020 const struct dwo_unit
*dub
= b
;
9022 return dua
->signature
== dub
->signature
;
9025 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9028 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
9030 return htab_create_alloc_ex (3,
9031 hash_dwp_loaded_cutus
,
9032 eq_dwp_loaded_cutus
,
9034 &objfile
->objfile_obstack
,
9035 hashtab_obstack_allocate
,
9036 dummy_obstack_deallocate
);
9039 /* Initialize the use of the DWP file for the current objfile.
9040 By convention the name of the DWP file is ${objfile}.dwp.
9041 The result is NULL if it can't be found. */
9043 static struct dwp_file
*
9044 open_and_init_dwp_file (const char *comp_dir
)
9046 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9047 struct dwp_file
*dwp_file
;
9050 struct cleanup
*cleanups
;
9052 dwp_name
= xstrprintf ("%s.dwp", dwarf2_per_objfile
->objfile
->name
);
9053 cleanups
= make_cleanup (xfree
, dwp_name
);
9055 dbfd
= open_dwop_file (dwp_name
, comp_dir
, 1);
9058 if (dwarf2_read_debug
)
9059 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
);
9060 do_cleanups (cleanups
);
9063 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
9064 dwp_file
->name
= obstack_copy0 (&objfile
->objfile_obstack
,
9065 dwp_name
, strlen (dwp_name
));
9066 dwp_file
->dbfd
= dbfd
;
9067 do_cleanups (cleanups
);
9069 cleanups
= make_cleanup (free_dwo_file_cleanup
, dwp_file
);
9071 /* +1: section 0 is unused */
9072 dwp_file
->num_sections
= bfd_count_sections (dbfd
) + 1;
9073 dwp_file
->elf_sections
=
9074 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
9075 dwp_file
->num_sections
, asection
*);
9077 bfd_map_over_sections (dbfd
, dwarf2_locate_dwp_sections
, dwp_file
);
9079 dwp_file
->cus
= create_dwp_hash_table (dwp_file
, 0);
9081 dwp_file
->tus
= create_dwp_hash_table (dwp_file
, 1);
9083 dwp_file
->loaded_cutus
= allocate_dwp_loaded_cutus_table (objfile
);
9085 discard_cleanups (cleanups
);
9087 if (dwarf2_read_debug
)
9089 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
9090 fprintf_unfiltered (gdb_stdlog
,
9091 " %u CUs, %u TUs\n",
9092 dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0,
9093 dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0);
9099 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9100 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9101 or in the DWP file for the objfile, referenced by THIS_UNIT.
9102 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9103 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9105 This is called, for example, when wanting to read a variable with a
9106 complex location. Therefore we don't want to do file i/o for every call.
9107 Therefore we don't want to look for a DWO file on every call.
9108 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9109 then we check if we've already seen DWO_NAME, and only THEN do we check
9112 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9113 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9115 static struct dwo_unit
*
9116 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
9117 const char *dwo_name
, const char *comp_dir
,
9118 ULONGEST signature
, int is_debug_types
)
9120 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9121 const char *kind
= is_debug_types
? "TU" : "CU";
9122 void **dwo_file_slot
;
9123 struct dwo_file
*dwo_file
;
9124 struct dwp_file
*dwp_file
;
9126 /* Have we already read SIGNATURE from a DWP file? */
9128 if (! dwarf2_per_objfile
->dwp_checked
)
9130 dwarf2_per_objfile
->dwp_file
= open_and_init_dwp_file (comp_dir
);
9131 dwarf2_per_objfile
->dwp_checked
= 1;
9133 dwp_file
= dwarf2_per_objfile
->dwp_file
;
9135 if (dwp_file
!= NULL
)
9137 const struct dwp_hash_table
*dwp_htab
=
9138 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
9140 if (dwp_htab
!= NULL
)
9142 struct dwo_unit
*dwo_cutu
=
9143 lookup_dwo_in_dwp (dwp_file
, dwp_htab
, signature
, is_debug_types
);
9145 if (dwo_cutu
!= NULL
)
9147 if (dwarf2_read_debug
)
9149 fprintf_unfiltered (gdb_stdlog
,
9150 "Virtual DWO %s %s found: @%s\n",
9151 kind
, hex_string (signature
),
9152 host_address_to_string (dwo_cutu
));
9159 /* Have we already seen DWO_NAME? */
9161 dwo_file_slot
= lookup_dwo_file_slot (dwo_name
);
9162 if (*dwo_file_slot
== NULL
)
9164 /* Read in the file and build a table of the DWOs it contains. */
9165 *dwo_file_slot
= open_and_init_dwo_file (dwo_name
, comp_dir
);
9167 /* NOTE: This will be NULL if unable to open the file. */
9168 dwo_file
= *dwo_file_slot
;
9170 if (dwo_file
!= NULL
)
9172 htab_t htab
= is_debug_types
? dwo_file
->tus
: dwo_file
->cus
;
9176 struct dwo_unit find_dwo_cutu
, *dwo_cutu
;
9178 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
9179 find_dwo_cutu
.signature
= signature
;
9180 dwo_cutu
= htab_find (htab
, &find_dwo_cutu
);
9182 if (dwo_cutu
!= NULL
)
9184 if (dwarf2_read_debug
)
9186 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
9187 kind
, dwo_name
, hex_string (signature
),
9188 host_address_to_string (dwo_cutu
));
9195 /* We didn't find it. This could mean a dwo_id mismatch, or
9196 someone deleted the DWO/DWP file, or the search path isn't set up
9197 correctly to find the file. */
9199 if (dwarf2_read_debug
)
9201 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
9202 kind
, dwo_name
, hex_string (signature
));
9205 complaint (&symfile_complaints
,
9206 _("Could not find DWO CU referenced by CU at offset 0x%x"
9208 this_unit
->offset
.sect_off
, objfile
->name
);
9212 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9213 See lookup_dwo_cutu_unit for details. */
9215 static struct dwo_unit
*
9216 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9217 const char *dwo_name
, const char *comp_dir
,
9220 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
9223 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9224 See lookup_dwo_cutu_unit for details. */
9226 static struct dwo_unit
*
9227 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
9228 const char *dwo_name
, const char *comp_dir
)
9230 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
9233 /* Free all resources associated with DWO_FILE.
9234 Close the DWO file and munmap the sections.
9235 All memory should be on the objfile obstack. */
9238 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
9241 struct dwarf2_section_info
*section
;
9243 gdb_assert (dwo_file
->dbfd
!= objfile
->obfd
);
9244 gdb_bfd_unref (dwo_file
->dbfd
);
9246 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
9249 /* Wrapper for free_dwo_file for use in cleanups. */
9252 free_dwo_file_cleanup (void *arg
)
9254 struct dwo_file
*dwo_file
= (struct dwo_file
*) arg
;
9255 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9257 free_dwo_file (dwo_file
, objfile
);
9260 /* Traversal function for free_dwo_files. */
9263 free_dwo_file_from_slot (void **slot
, void *info
)
9265 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
9266 struct objfile
*objfile
= (struct objfile
*) info
;
9268 free_dwo_file (dwo_file
, objfile
);
9273 /* Free all resources associated with DWO_FILES. */
9276 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
9278 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
9281 /* Read in various DIEs. */
9283 /* qsort helper for inherit_abstract_dies. */
9286 unsigned_int_compar (const void *ap
, const void *bp
)
9288 unsigned int a
= *(unsigned int *) ap
;
9289 unsigned int b
= *(unsigned int *) bp
;
9291 return (a
> b
) - (b
> a
);
9294 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9295 Inherit only the children of the DW_AT_abstract_origin DIE not being
9296 already referenced by DW_AT_abstract_origin from the children of the
9300 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
9302 struct die_info
*child_die
;
9303 unsigned die_children_count
;
9304 /* CU offsets which were referenced by children of the current DIE. */
9305 sect_offset
*offsets
;
9306 sect_offset
*offsets_end
, *offsetp
;
9307 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9308 struct die_info
*origin_die
;
9309 /* Iterator of the ORIGIN_DIE children. */
9310 struct die_info
*origin_child_die
;
9311 struct cleanup
*cleanups
;
9312 struct attribute
*attr
;
9313 struct dwarf2_cu
*origin_cu
;
9314 struct pending
**origin_previous_list_in_scope
;
9316 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9320 /* Note that following die references may follow to a die in a
9324 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
9326 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9328 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
9329 origin_cu
->list_in_scope
= cu
->list_in_scope
;
9331 if (die
->tag
!= origin_die
->tag
9332 && !(die
->tag
== DW_TAG_inlined_subroutine
9333 && origin_die
->tag
== DW_TAG_subprogram
))
9334 complaint (&symfile_complaints
,
9335 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9336 die
->offset
.sect_off
, origin_die
->offset
.sect_off
);
9338 child_die
= die
->child
;
9339 die_children_count
= 0;
9340 while (child_die
&& child_die
->tag
)
9342 child_die
= sibling_die (child_die
);
9343 die_children_count
++;
9345 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
9346 cleanups
= make_cleanup (xfree
, offsets
);
9348 offsets_end
= offsets
;
9349 child_die
= die
->child
;
9350 while (child_die
&& child_die
->tag
)
9352 /* For each CHILD_DIE, find the corresponding child of
9353 ORIGIN_DIE. If there is more than one layer of
9354 DW_AT_abstract_origin, follow them all; there shouldn't be,
9355 but GCC versions at least through 4.4 generate this (GCC PR
9357 struct die_info
*child_origin_die
= child_die
;
9358 struct dwarf2_cu
*child_origin_cu
= cu
;
9362 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
9366 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
9370 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9371 counterpart may exist. */
9372 if (child_origin_die
!= child_die
)
9374 if (child_die
->tag
!= child_origin_die
->tag
9375 && !(child_die
->tag
== DW_TAG_inlined_subroutine
9376 && child_origin_die
->tag
== DW_TAG_subprogram
))
9377 complaint (&symfile_complaints
,
9378 _("Child DIE 0x%x and its abstract origin 0x%x have "
9379 "different tags"), child_die
->offset
.sect_off
,
9380 child_origin_die
->offset
.sect_off
);
9381 if (child_origin_die
->parent
!= origin_die
)
9382 complaint (&symfile_complaints
,
9383 _("Child DIE 0x%x and its abstract origin 0x%x have "
9384 "different parents"), child_die
->offset
.sect_off
,
9385 child_origin_die
->offset
.sect_off
);
9387 *offsets_end
++ = child_origin_die
->offset
;
9389 child_die
= sibling_die (child_die
);
9391 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
9392 unsigned_int_compar
);
9393 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
9394 if (offsetp
[-1].sect_off
== offsetp
->sect_off
)
9395 complaint (&symfile_complaints
,
9396 _("Multiple children of DIE 0x%x refer "
9397 "to DIE 0x%x as their abstract origin"),
9398 die
->offset
.sect_off
, offsetp
->sect_off
);
9401 origin_child_die
= origin_die
->child
;
9402 while (origin_child_die
&& origin_child_die
->tag
)
9404 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9405 while (offsetp
< offsets_end
9406 && offsetp
->sect_off
< origin_child_die
->offset
.sect_off
)
9408 if (offsetp
>= offsets_end
9409 || offsetp
->sect_off
> origin_child_die
->offset
.sect_off
)
9411 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9412 process_die (origin_child_die
, origin_cu
);
9414 origin_child_die
= sibling_die (origin_child_die
);
9416 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
9418 do_cleanups (cleanups
);
9422 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9424 struct objfile
*objfile
= cu
->objfile
;
9425 struct context_stack
*new;
9428 struct die_info
*child_die
;
9429 struct attribute
*attr
, *call_line
, *call_file
;
9432 struct block
*block
;
9433 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9434 VEC (symbolp
) *template_args
= NULL
;
9435 struct template_symbol
*templ_func
= NULL
;
9439 /* If we do not have call site information, we can't show the
9440 caller of this inlined function. That's too confusing, so
9441 only use the scope for local variables. */
9442 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
9443 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
9444 if (call_line
== NULL
|| call_file
== NULL
)
9446 read_lexical_block_scope (die
, cu
);
9451 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9453 name
= dwarf2_name (die
, cu
);
9455 /* Ignore functions with missing or empty names. These are actually
9456 illegal according to the DWARF standard. */
9459 complaint (&symfile_complaints
,
9460 _("missing name for subprogram DIE at %d"),
9461 die
->offset
.sect_off
);
9465 /* Ignore functions with missing or invalid low and high pc attributes. */
9466 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9468 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9469 if (!attr
|| !DW_UNSND (attr
))
9470 complaint (&symfile_complaints
,
9471 _("cannot get low and high bounds "
9472 "for subprogram DIE at %d"),
9473 die
->offset
.sect_off
);
9480 /* If we have any template arguments, then we must allocate a
9481 different sort of symbol. */
9482 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
9484 if (child_die
->tag
== DW_TAG_template_type_param
9485 || child_die
->tag
== DW_TAG_template_value_param
)
9487 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
9488 struct template_symbol
);
9489 templ_func
->base
.is_cplus_template_function
= 1;
9494 new = push_context (0, lowpc
);
9495 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
9496 (struct symbol
*) templ_func
);
9498 /* If there is a location expression for DW_AT_frame_base, record
9500 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
9502 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9503 expression is being recorded directly in the function's symbol
9504 and not in a separate frame-base object. I guess this hack is
9505 to avoid adding some sort of frame-base adjunct/annex to the
9506 function's symbol :-(. The problem with doing this is that it
9507 results in a function symbol with a location expression that
9508 has nothing to do with the location of the function, ouch! The
9509 relationship should be: a function's symbol has-a frame base; a
9510 frame-base has-a location expression. */
9511 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
9513 cu
->list_in_scope
= &local_symbols
;
9515 if (die
->child
!= NULL
)
9517 child_die
= die
->child
;
9518 while (child_die
&& child_die
->tag
)
9520 if (child_die
->tag
== DW_TAG_template_type_param
9521 || child_die
->tag
== DW_TAG_template_value_param
)
9523 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
9526 VEC_safe_push (symbolp
, template_args
, arg
);
9529 process_die (child_die
, cu
);
9530 child_die
= sibling_die (child_die
);
9534 inherit_abstract_dies (die
, cu
);
9536 /* If we have a DW_AT_specification, we might need to import using
9537 directives from the context of the specification DIE. See the
9538 comment in determine_prefix. */
9539 if (cu
->language
== language_cplus
9540 && dwarf2_attr (die
, DW_AT_specification
, cu
))
9542 struct dwarf2_cu
*spec_cu
= cu
;
9543 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
9547 child_die
= spec_die
->child
;
9548 while (child_die
&& child_die
->tag
)
9550 if (child_die
->tag
== DW_TAG_imported_module
)
9551 process_die (child_die
, spec_cu
);
9552 child_die
= sibling_die (child_die
);
9555 /* In some cases, GCC generates specification DIEs that
9556 themselves contain DW_AT_specification attributes. */
9557 spec_die
= die_specification (spec_die
, &spec_cu
);
9561 new = pop_context ();
9562 /* Make a block for the local symbols within. */
9563 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
9564 lowpc
, highpc
, objfile
);
9566 /* For C++, set the block's scope. */
9567 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
9568 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
9569 determine_prefix (die
, cu
),
9570 processing_has_namespace_info
);
9572 /* If we have address ranges, record them. */
9573 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9575 /* Attach template arguments to function. */
9576 if (! VEC_empty (symbolp
, template_args
))
9578 gdb_assert (templ_func
!= NULL
);
9580 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
9581 templ_func
->template_arguments
9582 = obstack_alloc (&objfile
->objfile_obstack
,
9583 (templ_func
->n_template_arguments
9584 * sizeof (struct symbol
*)));
9585 memcpy (templ_func
->template_arguments
,
9586 VEC_address (symbolp
, template_args
),
9587 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
9588 VEC_free (symbolp
, template_args
);
9591 /* In C++, we can have functions nested inside functions (e.g., when
9592 a function declares a class that has methods). This means that
9593 when we finish processing a function scope, we may need to go
9594 back to building a containing block's symbol lists. */
9595 local_symbols
= new->locals
;
9596 using_directives
= new->using_directives
;
9598 /* If we've finished processing a top-level function, subsequent
9599 symbols go in the file symbol list. */
9600 if (outermost_context_p ())
9601 cu
->list_in_scope
= &file_symbols
;
9604 /* Process all the DIES contained within a lexical block scope. Start
9605 a new scope, process the dies, and then close the scope. */
9608 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9610 struct objfile
*objfile
= cu
->objfile
;
9611 struct context_stack
*new;
9612 CORE_ADDR lowpc
, highpc
;
9613 struct die_info
*child_die
;
9616 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9618 /* Ignore blocks with missing or invalid low and high pc attributes. */
9619 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9620 as multiple lexical blocks? Handling children in a sane way would
9621 be nasty. Might be easier to properly extend generic blocks to
9623 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
9628 push_context (0, lowpc
);
9629 if (die
->child
!= NULL
)
9631 child_die
= die
->child
;
9632 while (child_die
&& child_die
->tag
)
9634 process_die (child_die
, cu
);
9635 child_die
= sibling_die (child_die
);
9638 new = pop_context ();
9640 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
9643 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
9646 /* Note that recording ranges after traversing children, as we
9647 do here, means that recording a parent's ranges entails
9648 walking across all its children's ranges as they appear in
9649 the address map, which is quadratic behavior.
9651 It would be nicer to record the parent's ranges before
9652 traversing its children, simply overriding whatever you find
9653 there. But since we don't even decide whether to create a
9654 block until after we've traversed its children, that's hard
9656 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
9658 local_symbols
= new->locals
;
9659 using_directives
= new->using_directives
;
9662 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9665 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
9667 struct objfile
*objfile
= cu
->objfile
;
9668 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9669 CORE_ADDR pc
, baseaddr
;
9670 struct attribute
*attr
;
9671 struct call_site
*call_site
, call_site_local
;
9674 struct die_info
*child_die
;
9676 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9678 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9681 complaint (&symfile_complaints
,
9682 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9683 "DIE 0x%x [in module %s]"),
9684 die
->offset
.sect_off
, objfile
->name
);
9687 pc
= DW_ADDR (attr
) + baseaddr
;
9689 if (cu
->call_site_htab
== NULL
)
9690 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
9691 NULL
, &objfile
->objfile_obstack
,
9692 hashtab_obstack_allocate
, NULL
);
9693 call_site_local
.pc
= pc
;
9694 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
9697 complaint (&symfile_complaints
,
9698 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9699 "DIE 0x%x [in module %s]"),
9700 paddress (gdbarch
, pc
), die
->offset
.sect_off
, objfile
->name
);
9704 /* Count parameters at the caller. */
9707 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
9708 child_die
= sibling_die (child_die
))
9710 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9712 complaint (&symfile_complaints
,
9713 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9714 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9715 child_die
->tag
, child_die
->offset
.sect_off
, objfile
->name
);
9722 call_site
= obstack_alloc (&objfile
->objfile_obstack
,
9723 (sizeof (*call_site
)
9724 + (sizeof (*call_site
->parameter
)
9727 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
9730 if (dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
9732 struct die_info
*func_die
;
9734 /* Skip also over DW_TAG_inlined_subroutine. */
9735 for (func_die
= die
->parent
;
9736 func_die
&& func_die
->tag
!= DW_TAG_subprogram
9737 && func_die
->tag
!= DW_TAG_subroutine_type
;
9738 func_die
= func_die
->parent
);
9740 /* DW_AT_GNU_all_call_sites is a superset
9741 of DW_AT_GNU_all_tail_call_sites. */
9743 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
9744 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
9746 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9747 not complete. But keep CALL_SITE for look ups via call_site_htab,
9748 both the initial caller containing the real return address PC and
9749 the final callee containing the current PC of a chain of tail
9750 calls do not need to have the tail call list complete. But any
9751 function candidate for a virtual tail call frame searched via
9752 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9753 determined unambiguously. */
9757 struct type
*func_type
= NULL
;
9760 func_type
= get_die_type (func_die
, cu
);
9761 if (func_type
!= NULL
)
9763 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
9765 /* Enlist this call site to the function. */
9766 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
9767 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
9770 complaint (&symfile_complaints
,
9771 _("Cannot find function owning DW_TAG_GNU_call_site "
9772 "DIE 0x%x [in module %s]"),
9773 die
->offset
.sect_off
, objfile
->name
);
9777 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
9779 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
9780 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
9781 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
9782 /* Keep NULL DWARF_BLOCK. */;
9783 else if (attr_form_is_block (attr
))
9785 struct dwarf2_locexpr_baton
*dlbaton
;
9787 dlbaton
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*dlbaton
));
9788 dlbaton
->data
= DW_BLOCK (attr
)->data
;
9789 dlbaton
->size
= DW_BLOCK (attr
)->size
;
9790 dlbaton
->per_cu
= cu
->per_cu
;
9792 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
9794 else if (is_ref_attr (attr
))
9796 struct dwarf2_cu
*target_cu
= cu
;
9797 struct die_info
*target_die
;
9799 target_die
= follow_die_ref_or_sig (die
, attr
, &target_cu
);
9800 gdb_assert (target_cu
->objfile
== objfile
);
9801 if (die_is_declaration (target_die
, target_cu
))
9803 const char *target_physname
;
9805 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
9806 if (target_physname
== NULL
)
9807 complaint (&symfile_complaints
,
9808 _("DW_AT_GNU_call_site_target target DIE has invalid "
9809 "physname, for referencing DIE 0x%x [in module %s]"),
9810 die
->offset
.sect_off
, objfile
->name
);
9812 SET_FIELD_PHYSNAME (call_site
->target
, (char *) target_physname
);
9818 /* DW_AT_entry_pc should be preferred. */
9819 if (!dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
))
9820 complaint (&symfile_complaints
,
9821 _("DW_AT_GNU_call_site_target target DIE has invalid "
9822 "low pc, for referencing DIE 0x%x [in module %s]"),
9823 die
->offset
.sect_off
, objfile
->name
);
9825 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
+ baseaddr
);
9829 complaint (&symfile_complaints
,
9830 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9831 "block nor reference, for DIE 0x%x [in module %s]"),
9832 die
->offset
.sect_off
, objfile
->name
);
9834 call_site
->per_cu
= cu
->per_cu
;
9836 for (child_die
= die
->child
;
9837 child_die
&& child_die
->tag
;
9838 child_die
= sibling_die (child_die
))
9840 struct call_site_parameter
*parameter
;
9841 struct attribute
*loc
, *origin
;
9843 if (child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
9845 /* Already printed the complaint above. */
9849 gdb_assert (call_site
->parameter_count
< nparams
);
9850 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
9852 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9853 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9854 register is contained in DW_AT_GNU_call_site_value. */
9856 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
9857 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
9858 if (loc
== NULL
&& origin
!= NULL
&& is_ref_attr (origin
))
9862 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
9863 offset
= dwarf2_get_ref_die_offset (origin
);
9864 if (!offset_in_cu_p (&cu
->header
, offset
))
9866 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9867 binding can be done only inside one CU. Such referenced DIE
9868 therefore cannot be even moved to DW_TAG_partial_unit. */
9869 complaint (&symfile_complaints
,
9870 _("DW_AT_abstract_origin offset is not in CU for "
9871 "DW_TAG_GNU_call_site child DIE 0x%x "
9873 child_die
->offset
.sect_off
, objfile
->name
);
9876 parameter
->u
.param_offset
.cu_off
= (offset
.sect_off
9877 - cu
->header
.offset
.sect_off
);
9879 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
9881 complaint (&symfile_complaints
,
9882 _("No DW_FORM_block* DW_AT_location for "
9883 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9884 child_die
->offset
.sect_off
, objfile
->name
);
9889 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
9890 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
9891 if (parameter
->u
.dwarf_reg
!= -1)
9892 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
9893 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
9894 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
9895 ¶meter
->u
.fb_offset
))
9896 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
9899 complaint (&symfile_complaints
,
9900 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9901 "for DW_FORM_block* DW_AT_location is supported for "
9902 "DW_TAG_GNU_call_site child DIE 0x%x "
9904 child_die
->offset
.sect_off
, objfile
->name
);
9909 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
9910 if (!attr_form_is_block (attr
))
9912 complaint (&symfile_complaints
,
9913 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9914 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9915 child_die
->offset
.sect_off
, objfile
->name
);
9918 parameter
->value
= DW_BLOCK (attr
)->data
;
9919 parameter
->value_size
= DW_BLOCK (attr
)->size
;
9921 /* Parameters are not pre-cleared by memset above. */
9922 parameter
->data_value
= NULL
;
9923 parameter
->data_value_size
= 0;
9924 call_site
->parameter_count
++;
9926 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
9929 if (!attr_form_is_block (attr
))
9930 complaint (&symfile_complaints
,
9931 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9932 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9933 child_die
->offset
.sect_off
, objfile
->name
);
9936 parameter
->data_value
= DW_BLOCK (attr
)->data
;
9937 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
9943 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9944 Return 1 if the attributes are present and valid, otherwise, return 0.
9945 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9948 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
9949 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
9950 struct partial_symtab
*ranges_pst
)
9952 struct objfile
*objfile
= cu
->objfile
;
9953 struct comp_unit_head
*cu_header
= &cu
->header
;
9954 bfd
*obfd
= objfile
->obfd
;
9955 unsigned int addr_size
= cu_header
->addr_size
;
9956 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
9957 /* Base address selection entry. */
9968 found_base
= cu
->base_known
;
9969 base
= cu
->base_address
;
9971 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
9972 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
9974 complaint (&symfile_complaints
,
9975 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9979 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
9981 /* Read in the largest possible address. */
9982 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
9983 if ((marker
& mask
) == mask
)
9985 /* If we found the largest possible address, then
9986 read the base address. */
9987 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
9988 buffer
+= 2 * addr_size
;
9989 offset
+= 2 * addr_size
;
9995 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9999 CORE_ADDR range_beginning
, range_end
;
10001 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
10002 buffer
+= addr_size
;
10003 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
10004 buffer
+= addr_size
;
10005 offset
+= 2 * addr_size
;
10007 /* An end of list marker is a pair of zero addresses. */
10008 if (range_beginning
== 0 && range_end
== 0)
10009 /* Found the end of list entry. */
10012 /* Each base address selection entry is a pair of 2 values.
10013 The first is the largest possible address, the second is
10014 the base address. Check for a base address here. */
10015 if ((range_beginning
& mask
) == mask
)
10017 /* If we found the largest possible address, then
10018 read the base address. */
10019 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
10026 /* We have no valid base address for the ranges
10028 complaint (&symfile_complaints
,
10029 _("Invalid .debug_ranges data (no base address)"));
10033 if (range_beginning
> range_end
)
10035 /* Inverted range entries are invalid. */
10036 complaint (&symfile_complaints
,
10037 _("Invalid .debug_ranges data (inverted range)"));
10041 /* Empty range entries have no effect. */
10042 if (range_beginning
== range_end
)
10045 range_beginning
+= base
;
10048 /* A not-uncommon case of bad debug info.
10049 Don't pollute the addrmap with bad data. */
10050 if (range_beginning
+ baseaddr
== 0
10051 && !dwarf2_per_objfile
->has_section_at_zero
)
10053 complaint (&symfile_complaints
,
10054 _(".debug_ranges entry has start address of zero"
10055 " [in module %s]"), objfile
->name
);
10059 if (ranges_pst
!= NULL
)
10060 addrmap_set_empty (objfile
->psymtabs_addrmap
,
10061 range_beginning
+ baseaddr
,
10062 range_end
- 1 + baseaddr
,
10065 /* FIXME: This is recording everything as a low-high
10066 segment of consecutive addresses. We should have a
10067 data structure for discontiguous block ranges
10071 low
= range_beginning
;
10077 if (range_beginning
< low
)
10078 low
= range_beginning
;
10079 if (range_end
> high
)
10085 /* If the first entry is an end-of-list marker, the range
10086 describes an empty scope, i.e. no instructions. */
10092 *high_return
= high
;
10096 /* Get low and high pc attributes from a die. Return 1 if the attributes
10097 are present and valid, otherwise, return 0. Return -1 if the range is
10098 discontinuous, i.e. derived from DW_AT_ranges information. */
10101 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
10102 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
10103 struct partial_symtab
*pst
)
10105 struct attribute
*attr
;
10106 struct attribute
*attr_high
;
10108 CORE_ADDR high
= 0;
10111 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10114 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10117 low
= DW_ADDR (attr
);
10118 if (attr_high
->form
== DW_FORM_addr
10119 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10120 high
= DW_ADDR (attr_high
);
10122 high
= low
+ DW_UNSND (attr_high
);
10125 /* Found high w/o low attribute. */
10128 /* Found consecutive range of addresses. */
10133 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10136 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10137 We take advantage of the fact that DW_AT_ranges does not appear
10138 in DW_TAG_compile_unit of DWO files. */
10139 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10140 unsigned int ranges_offset
= (DW_UNSND (attr
)
10141 + (need_ranges_base
10145 /* Value of the DW_AT_ranges attribute is the offset in the
10146 .debug_ranges section. */
10147 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
10149 /* Found discontinuous range of addresses. */
10154 /* read_partial_die has also the strict LOW < HIGH requirement. */
10158 /* When using the GNU linker, .gnu.linkonce. sections are used to
10159 eliminate duplicate copies of functions and vtables and such.
10160 The linker will arbitrarily choose one and discard the others.
10161 The AT_*_pc values for such functions refer to local labels in
10162 these sections. If the section from that file was discarded, the
10163 labels are not in the output, so the relocs get a value of 0.
10164 If this is a discarded function, mark the pc bounds as invalid,
10165 so that GDB will ignore it. */
10166 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10175 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10176 its low and high PC addresses. Do nothing if these addresses could not
10177 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10178 and HIGHPC to the high address if greater than HIGHPC. */
10181 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
10182 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10183 struct dwarf2_cu
*cu
)
10185 CORE_ADDR low
, high
;
10186 struct die_info
*child
= die
->child
;
10188 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
10190 *lowpc
= min (*lowpc
, low
);
10191 *highpc
= max (*highpc
, high
);
10194 /* If the language does not allow nested subprograms (either inside
10195 subprograms or lexical blocks), we're done. */
10196 if (cu
->language
!= language_ada
)
10199 /* Check all the children of the given DIE. If it contains nested
10200 subprograms, then check their pc bounds. Likewise, we need to
10201 check lexical blocks as well, as they may also contain subprogram
10203 while (child
&& child
->tag
)
10205 if (child
->tag
== DW_TAG_subprogram
10206 || child
->tag
== DW_TAG_lexical_block
)
10207 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
10208 child
= sibling_die (child
);
10212 /* Get the low and high pc's represented by the scope DIE, and store
10213 them in *LOWPC and *HIGHPC. If the correct values can't be
10214 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10217 get_scope_pc_bounds (struct die_info
*die
,
10218 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
10219 struct dwarf2_cu
*cu
)
10221 CORE_ADDR best_low
= (CORE_ADDR
) -1;
10222 CORE_ADDR best_high
= (CORE_ADDR
) 0;
10223 CORE_ADDR current_low
, current_high
;
10225 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
10227 best_low
= current_low
;
10228 best_high
= current_high
;
10232 struct die_info
*child
= die
->child
;
10234 while (child
&& child
->tag
)
10236 switch (child
->tag
) {
10237 case DW_TAG_subprogram
:
10238 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
10240 case DW_TAG_namespace
:
10241 case DW_TAG_module
:
10242 /* FIXME: carlton/2004-01-16: Should we do this for
10243 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10244 that current GCC's always emit the DIEs corresponding
10245 to definitions of methods of classes as children of a
10246 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10247 the DIEs giving the declarations, which could be
10248 anywhere). But I don't see any reason why the
10249 standards says that they have to be there. */
10250 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
10252 if (current_low
!= ((CORE_ADDR
) -1))
10254 best_low
= min (best_low
, current_low
);
10255 best_high
= max (best_high
, current_high
);
10263 child
= sibling_die (child
);
10268 *highpc
= best_high
;
10271 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10275 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
10276 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
10278 struct objfile
*objfile
= cu
->objfile
;
10279 struct attribute
*attr
;
10280 struct attribute
*attr_high
;
10282 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
10285 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10288 CORE_ADDR low
= DW_ADDR (attr
);
10290 if (attr_high
->form
== DW_FORM_addr
10291 || attr_high
->form
== DW_FORM_GNU_addr_index
)
10292 high
= DW_ADDR (attr_high
);
10294 high
= low
+ DW_UNSND (attr_high
);
10296 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
10300 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
10303 bfd
*obfd
= objfile
->obfd
;
10304 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10305 We take advantage of the fact that DW_AT_ranges does not appear
10306 in DW_TAG_compile_unit of DWO files. */
10307 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
10309 /* The value of the DW_AT_ranges attribute is the offset of the
10310 address range list in the .debug_ranges section. */
10311 unsigned long offset
= (DW_UNSND (attr
)
10312 + (need_ranges_base
? cu
->ranges_base
: 0));
10313 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
10315 /* For some target architectures, but not others, the
10316 read_address function sign-extends the addresses it returns.
10317 To recognize base address selection entries, we need a
10319 unsigned int addr_size
= cu
->header
.addr_size
;
10320 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
10322 /* The base address, to which the next pair is relative. Note
10323 that this 'base' is a DWARF concept: most entries in a range
10324 list are relative, to reduce the number of relocs against the
10325 debugging information. This is separate from this function's
10326 'baseaddr' argument, which GDB uses to relocate debugging
10327 information from a shared library based on the address at
10328 which the library was loaded. */
10329 CORE_ADDR base
= cu
->base_address
;
10330 int base_known
= cu
->base_known
;
10332 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
10333 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
10335 complaint (&symfile_complaints
,
10336 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10343 unsigned int bytes_read
;
10344 CORE_ADDR start
, end
;
10346 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10347 buffer
+= bytes_read
;
10348 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
10349 buffer
+= bytes_read
;
10351 /* Did we find the end of the range list? */
10352 if (start
== 0 && end
== 0)
10355 /* Did we find a base address selection entry? */
10356 else if ((start
& base_select_mask
) == base_select_mask
)
10362 /* We found an ordinary address range. */
10367 complaint (&symfile_complaints
,
10368 _("Invalid .debug_ranges data "
10369 "(no base address)"));
10375 /* Inverted range entries are invalid. */
10376 complaint (&symfile_complaints
,
10377 _("Invalid .debug_ranges data "
10378 "(inverted range)"));
10382 /* Empty range entries have no effect. */
10386 start
+= base
+ baseaddr
;
10387 end
+= base
+ baseaddr
;
10389 /* A not-uncommon case of bad debug info.
10390 Don't pollute the addrmap with bad data. */
10391 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10393 complaint (&symfile_complaints
,
10394 _(".debug_ranges entry has start address of zero"
10395 " [in module %s]"), objfile
->name
);
10399 record_block_range (block
, start
, end
- 1);
10405 /* Check whether the producer field indicates either of GCC < 4.6, or the
10406 Intel C/C++ compiler, and cache the result in CU. */
10409 check_producer (struct dwarf2_cu
*cu
)
10412 int major
, minor
, release
;
10414 if (cu
->producer
== NULL
)
10416 /* For unknown compilers expect their behavior is DWARF version
10419 GCC started to support .debug_types sections by -gdwarf-4 since
10420 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10421 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10422 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10423 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10425 else if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) == 0)
10427 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10429 cs
= &cu
->producer
[strlen ("GNU ")];
10430 while (*cs
&& !isdigit (*cs
))
10432 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
10434 /* Not recognized as GCC. */
10438 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
10439 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
10442 else if (strncmp (cu
->producer
, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10443 cu
->producer_is_icc
= 1;
10446 /* For other non-GCC compilers, expect their behavior is DWARF version
10450 cu
->checked_producer
= 1;
10453 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10454 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10455 during 4.6.0 experimental. */
10458 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
10460 if (!cu
->checked_producer
)
10461 check_producer (cu
);
10463 return cu
->producer_is_gxx_lt_4_6
;
10466 /* Return the default accessibility type if it is not overriden by
10467 DW_AT_accessibility. */
10469 static enum dwarf_access_attribute
10470 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
10472 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
10474 /* The default DWARF 2 accessibility for members is public, the default
10475 accessibility for inheritance is private. */
10477 if (die
->tag
!= DW_TAG_inheritance
)
10478 return DW_ACCESS_public
;
10480 return DW_ACCESS_private
;
10484 /* DWARF 3+ defines the default accessibility a different way. The same
10485 rules apply now for DW_TAG_inheritance as for the members and it only
10486 depends on the container kind. */
10488 if (die
->parent
->tag
== DW_TAG_class_type
)
10489 return DW_ACCESS_private
;
10491 return DW_ACCESS_public
;
10495 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10496 offset. If the attribute was not found return 0, otherwise return
10497 1. If it was found but could not properly be handled, set *OFFSET
10501 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
10504 struct attribute
*attr
;
10506 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
10511 /* Note that we do not check for a section offset first here.
10512 This is because DW_AT_data_member_location is new in DWARF 4,
10513 so if we see it, we can assume that a constant form is really
10514 a constant and not a section offset. */
10515 if (attr_form_is_constant (attr
))
10516 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
10517 else if (attr_form_is_section_offset (attr
))
10518 dwarf2_complex_location_expr_complaint ();
10519 else if (attr_form_is_block (attr
))
10520 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
10522 dwarf2_complex_location_expr_complaint ();
10530 /* Add an aggregate field to the field list. */
10533 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
10534 struct dwarf2_cu
*cu
)
10536 struct objfile
*objfile
= cu
->objfile
;
10537 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10538 struct nextfield
*new_field
;
10539 struct attribute
*attr
;
10541 const char *fieldname
= "";
10543 /* Allocate a new field list entry and link it in. */
10544 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
10545 make_cleanup (xfree
, new_field
);
10546 memset (new_field
, 0, sizeof (struct nextfield
));
10548 if (die
->tag
== DW_TAG_inheritance
)
10550 new_field
->next
= fip
->baseclasses
;
10551 fip
->baseclasses
= new_field
;
10555 new_field
->next
= fip
->fields
;
10556 fip
->fields
= new_field
;
10560 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10562 new_field
->accessibility
= DW_UNSND (attr
);
10564 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
10565 if (new_field
->accessibility
!= DW_ACCESS_public
)
10566 fip
->non_public_fields
= 1;
10568 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
10570 new_field
->virtuality
= DW_UNSND (attr
);
10572 new_field
->virtuality
= DW_VIRTUALITY_none
;
10574 fp
= &new_field
->field
;
10576 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
10580 /* Data member other than a C++ static data member. */
10582 /* Get type of field. */
10583 fp
->type
= die_type (die
, cu
);
10585 SET_FIELD_BITPOS (*fp
, 0);
10587 /* Get bit size of field (zero if none). */
10588 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
10591 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
10595 FIELD_BITSIZE (*fp
) = 0;
10598 /* Get bit offset of field. */
10599 if (handle_data_member_location (die
, cu
, &offset
))
10600 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10601 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
10604 if (gdbarch_bits_big_endian (gdbarch
))
10606 /* For big endian bits, the DW_AT_bit_offset gives the
10607 additional bit offset from the MSB of the containing
10608 anonymous object to the MSB of the field. We don't
10609 have to do anything special since we don't need to
10610 know the size of the anonymous object. */
10611 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
10615 /* For little endian bits, compute the bit offset to the
10616 MSB of the anonymous object, subtract off the number of
10617 bits from the MSB of the field to the MSB of the
10618 object, and then subtract off the number of bits of
10619 the field itself. The result is the bit offset of
10620 the LSB of the field. */
10621 int anonymous_size
;
10622 int bit_offset
= DW_UNSND (attr
);
10624 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
10627 /* The size of the anonymous object containing
10628 the bit field is explicit, so use the
10629 indicated size (in bytes). */
10630 anonymous_size
= DW_UNSND (attr
);
10634 /* The size of the anonymous object containing
10635 the bit field must be inferred from the type
10636 attribute of the data member containing the
10638 anonymous_size
= TYPE_LENGTH (fp
->type
);
10640 SET_FIELD_BITPOS (*fp
,
10641 (FIELD_BITPOS (*fp
)
10642 + anonymous_size
* bits_per_byte
10643 - bit_offset
- FIELD_BITSIZE (*fp
)));
10647 /* Get name of field. */
10648 fieldname
= dwarf2_name (die
, cu
);
10649 if (fieldname
== NULL
)
10652 /* The name is already allocated along with this objfile, so we don't
10653 need to duplicate it for the type. */
10654 fp
->name
= fieldname
;
10656 /* Change accessibility for artificial fields (e.g. virtual table
10657 pointer or virtual base class pointer) to private. */
10658 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
10660 FIELD_ARTIFICIAL (*fp
) = 1;
10661 new_field
->accessibility
= DW_ACCESS_private
;
10662 fip
->non_public_fields
= 1;
10665 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
10667 /* C++ static member. */
10669 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10670 is a declaration, but all versions of G++ as of this writing
10671 (so through at least 3.2.1) incorrectly generate
10672 DW_TAG_variable tags. */
10674 const char *physname
;
10676 /* Get name of field. */
10677 fieldname
= dwarf2_name (die
, cu
);
10678 if (fieldname
== NULL
)
10681 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10683 /* Only create a symbol if this is an external value.
10684 new_symbol checks this and puts the value in the global symbol
10685 table, which we want. If it is not external, new_symbol
10686 will try to put the value in cu->list_in_scope which is wrong. */
10687 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
10689 /* A static const member, not much different than an enum as far as
10690 we're concerned, except that we can support more types. */
10691 new_symbol (die
, NULL
, cu
);
10694 /* Get physical name. */
10695 physname
= dwarf2_physname (fieldname
, die
, cu
);
10697 /* The name is already allocated along with this objfile, so we don't
10698 need to duplicate it for the type. */
10699 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
10700 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10701 FIELD_NAME (*fp
) = fieldname
;
10703 else if (die
->tag
== DW_TAG_inheritance
)
10707 /* C++ base class field. */
10708 if (handle_data_member_location (die
, cu
, &offset
))
10709 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
10710 FIELD_BITSIZE (*fp
) = 0;
10711 FIELD_TYPE (*fp
) = die_type (die
, cu
);
10712 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
10713 fip
->nbaseclasses
++;
10717 /* Add a typedef defined in the scope of the FIP's class. */
10720 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
10721 struct dwarf2_cu
*cu
)
10723 struct objfile
*objfile
= cu
->objfile
;
10724 struct typedef_field_list
*new_field
;
10725 struct attribute
*attr
;
10726 struct typedef_field
*fp
;
10727 char *fieldname
= "";
10729 /* Allocate a new field list entry and link it in. */
10730 new_field
= xzalloc (sizeof (*new_field
));
10731 make_cleanup (xfree
, new_field
);
10733 gdb_assert (die
->tag
== DW_TAG_typedef
);
10735 fp
= &new_field
->field
;
10737 /* Get name of field. */
10738 fp
->name
= dwarf2_name (die
, cu
);
10739 if (fp
->name
== NULL
)
10742 fp
->type
= read_type_die (die
, cu
);
10744 new_field
->next
= fip
->typedef_field_list
;
10745 fip
->typedef_field_list
= new_field
;
10746 fip
->typedef_field_list_count
++;
10749 /* Create the vector of fields, and attach it to the type. */
10752 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
10753 struct dwarf2_cu
*cu
)
10755 int nfields
= fip
->nfields
;
10757 /* Record the field count, allocate space for the array of fields,
10758 and create blank accessibility bitfields if necessary. */
10759 TYPE_NFIELDS (type
) = nfields
;
10760 TYPE_FIELDS (type
) = (struct field
*)
10761 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
10762 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
10764 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
10766 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10768 TYPE_FIELD_PRIVATE_BITS (type
) =
10769 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10770 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
10772 TYPE_FIELD_PROTECTED_BITS (type
) =
10773 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10774 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
10776 TYPE_FIELD_IGNORE_BITS (type
) =
10777 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
10778 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
10781 /* If the type has baseclasses, allocate and clear a bit vector for
10782 TYPE_FIELD_VIRTUAL_BITS. */
10783 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
10785 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
10786 unsigned char *pointer
;
10788 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
10789 pointer
= TYPE_ALLOC (type
, num_bytes
);
10790 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
10791 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
10792 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
10795 /* Copy the saved-up fields into the field vector. Start from the head of
10796 the list, adding to the tail of the field array, so that they end up in
10797 the same order in the array in which they were added to the list. */
10798 while (nfields
-- > 0)
10800 struct nextfield
*fieldp
;
10804 fieldp
= fip
->fields
;
10805 fip
->fields
= fieldp
->next
;
10809 fieldp
= fip
->baseclasses
;
10810 fip
->baseclasses
= fieldp
->next
;
10813 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
10814 switch (fieldp
->accessibility
)
10816 case DW_ACCESS_private
:
10817 if (cu
->language
!= language_ada
)
10818 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
10821 case DW_ACCESS_protected
:
10822 if (cu
->language
!= language_ada
)
10823 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
10826 case DW_ACCESS_public
:
10830 /* Unknown accessibility. Complain and treat it as public. */
10832 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
10833 fieldp
->accessibility
);
10837 if (nfields
< fip
->nbaseclasses
)
10839 switch (fieldp
->virtuality
)
10841 case DW_VIRTUALITY_virtual
:
10842 case DW_VIRTUALITY_pure_virtual
:
10843 if (cu
->language
== language_ada
)
10844 error (_("unexpected virtuality in component of Ada type"));
10845 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
10852 /* Return true if this member function is a constructor, false
10856 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
10858 const char *fieldname
;
10859 const char *typename
;
10862 if (die
->parent
== NULL
)
10865 if (die
->parent
->tag
!= DW_TAG_structure_type
10866 && die
->parent
->tag
!= DW_TAG_union_type
10867 && die
->parent
->tag
!= DW_TAG_class_type
)
10870 fieldname
= dwarf2_name (die
, cu
);
10871 typename
= dwarf2_name (die
->parent
, cu
);
10872 if (fieldname
== NULL
|| typename
== NULL
)
10875 len
= strlen (fieldname
);
10876 return (strncmp (fieldname
, typename
, len
) == 0
10877 && (typename
[len
] == '\0' || typename
[len
] == '<'));
10880 /* Add a member function to the proper fieldlist. */
10883 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
10884 struct type
*type
, struct dwarf2_cu
*cu
)
10886 struct objfile
*objfile
= cu
->objfile
;
10887 struct attribute
*attr
;
10888 struct fnfieldlist
*flp
;
10890 struct fn_field
*fnp
;
10891 const char *fieldname
;
10892 struct nextfnfield
*new_fnfield
;
10893 struct type
*this_type
;
10894 enum dwarf_access_attribute accessibility
;
10896 if (cu
->language
== language_ada
)
10897 error (_("unexpected member function in Ada type"));
10899 /* Get name of member function. */
10900 fieldname
= dwarf2_name (die
, cu
);
10901 if (fieldname
== NULL
)
10904 /* Look up member function name in fieldlist. */
10905 for (i
= 0; i
< fip
->nfnfields
; i
++)
10907 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
10911 /* Create new list element if necessary. */
10912 if (i
< fip
->nfnfields
)
10913 flp
= &fip
->fnfieldlists
[i
];
10916 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
10918 fip
->fnfieldlists
= (struct fnfieldlist
*)
10919 xrealloc (fip
->fnfieldlists
,
10920 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
10921 * sizeof (struct fnfieldlist
));
10922 if (fip
->nfnfields
== 0)
10923 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
10925 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
10926 flp
->name
= fieldname
;
10929 i
= fip
->nfnfields
++;
10932 /* Create a new member function field and chain it to the field list
10934 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
10935 make_cleanup (xfree
, new_fnfield
);
10936 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
10937 new_fnfield
->next
= flp
->head
;
10938 flp
->head
= new_fnfield
;
10941 /* Fill in the member function field info. */
10942 fnp
= &new_fnfield
->fnfield
;
10944 /* Delay processing of the physname until later. */
10945 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
10947 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
10952 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
10953 fnp
->physname
= physname
? physname
: "";
10956 fnp
->type
= alloc_type (objfile
);
10957 this_type
= read_type_die (die
, cu
);
10958 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
10960 int nparams
= TYPE_NFIELDS (this_type
);
10962 /* TYPE is the domain of this method, and THIS_TYPE is the type
10963 of the method itself (TYPE_CODE_METHOD). */
10964 smash_to_method_type (fnp
->type
, type
,
10965 TYPE_TARGET_TYPE (this_type
),
10966 TYPE_FIELDS (this_type
),
10967 TYPE_NFIELDS (this_type
),
10968 TYPE_VARARGS (this_type
));
10970 /* Handle static member functions.
10971 Dwarf2 has no clean way to discern C++ static and non-static
10972 member functions. G++ helps GDB by marking the first
10973 parameter for non-static member functions (which is the this
10974 pointer) as artificial. We obtain this information from
10975 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10976 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
10977 fnp
->voffset
= VOFFSET_STATIC
;
10980 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
10981 dwarf2_full_name (fieldname
, die
, cu
));
10983 /* Get fcontext from DW_AT_containing_type if present. */
10984 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
10985 fnp
->fcontext
= die_containing_type (die
, cu
);
10987 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10988 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10990 /* Get accessibility. */
10991 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
10993 accessibility
= DW_UNSND (attr
);
10995 accessibility
= dwarf2_default_access_attribute (die
, cu
);
10996 switch (accessibility
)
10998 case DW_ACCESS_private
:
10999 fnp
->is_private
= 1;
11001 case DW_ACCESS_protected
:
11002 fnp
->is_protected
= 1;
11006 /* Check for artificial methods. */
11007 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
11008 if (attr
&& DW_UNSND (attr
) != 0)
11009 fnp
->is_artificial
= 1;
11011 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
11013 /* Get index in virtual function table if it is a virtual member
11014 function. For older versions of GCC, this is an offset in the
11015 appropriate virtual table, as specified by DW_AT_containing_type.
11016 For everyone else, it is an expression to be evaluated relative
11017 to the object address. */
11019 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
11022 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
11024 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
11026 /* Old-style GCC. */
11027 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
11029 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11030 || (DW_BLOCK (attr
)->size
> 1
11031 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
11032 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
11034 struct dwarf_block blk
;
11037 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
11039 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
11040 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
11041 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
11042 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
11043 dwarf2_complex_location_expr_complaint ();
11045 fnp
->voffset
/= cu
->header
.addr_size
;
11049 dwarf2_complex_location_expr_complaint ();
11051 if (!fnp
->fcontext
)
11052 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
11054 else if (attr_form_is_section_offset (attr
))
11056 dwarf2_complex_location_expr_complaint ();
11060 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
11066 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
11067 if (attr
&& DW_UNSND (attr
))
11069 /* GCC does this, as of 2008-08-25; PR debug/37237. */
11070 complaint (&symfile_complaints
,
11071 _("Member function \"%s\" (offset %d) is virtual "
11072 "but the vtable offset is not specified"),
11073 fieldname
, die
->offset
.sect_off
);
11074 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11075 TYPE_CPLUS_DYNAMIC (type
) = 1;
11080 /* Create the vector of member function fields, and attach it to the type. */
11083 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
11084 struct dwarf2_cu
*cu
)
11086 struct fnfieldlist
*flp
;
11089 if (cu
->language
== language_ada
)
11090 error (_("unexpected member functions in Ada type"));
11092 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11093 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
11094 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
11096 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
11098 struct nextfnfield
*nfp
= flp
->head
;
11099 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
11102 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
11103 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
11104 fn_flp
->fn_fields
= (struct fn_field
*)
11105 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
11106 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
11107 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
11110 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
11113 /* Returns non-zero if NAME is the name of a vtable member in CU's
11114 language, zero otherwise. */
11116 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
11118 static const char vptr
[] = "_vptr";
11119 static const char vtable
[] = "vtable";
11121 /* Look for the C++ and Java forms of the vtable. */
11122 if ((cu
->language
== language_java
11123 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
11124 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
11125 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
11131 /* GCC outputs unnamed structures that are really pointers to member
11132 functions, with the ABI-specified layout. If TYPE describes
11133 such a structure, smash it into a member function type.
11135 GCC shouldn't do this; it should just output pointer to member DIEs.
11136 This is GCC PR debug/28767. */
11139 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
11141 struct type
*pfn_type
, *domain_type
, *new_type
;
11143 /* Check for a structure with no name and two children. */
11144 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
11147 /* Check for __pfn and __delta members. */
11148 if (TYPE_FIELD_NAME (type
, 0) == NULL
11149 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
11150 || TYPE_FIELD_NAME (type
, 1) == NULL
11151 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
11154 /* Find the type of the method. */
11155 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
11156 if (pfn_type
== NULL
11157 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
11158 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
11161 /* Look for the "this" argument. */
11162 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
11163 if (TYPE_NFIELDS (pfn_type
) == 0
11164 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11165 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
11168 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
11169 new_type
= alloc_type (objfile
);
11170 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
11171 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
11172 TYPE_VARARGS (pfn_type
));
11173 smash_to_methodptr_type (type
, new_type
);
11176 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11180 producer_is_icc (struct dwarf2_cu
*cu
)
11182 if (!cu
->checked_producer
)
11183 check_producer (cu
);
11185 return cu
->producer_is_icc
;
11188 /* Called when we find the DIE that starts a structure or union scope
11189 (definition) to create a type for the structure or union. Fill in
11190 the type's name and general properties; the members will not be
11191 processed until process_structure_type.
11193 NOTE: we need to call these functions regardless of whether or not the
11194 DIE has a DW_AT_name attribute, since it might be an anonymous
11195 structure or union. This gets the type entered into our set of
11196 user defined types.
11198 However, if the structure is incomplete (an opaque struct/union)
11199 then suppress creating a symbol table entry for it since gdb only
11200 wants to find the one with the complete definition. Note that if
11201 it is complete, we just call new_symbol, which does it's own
11202 checking about whether the struct/union is anonymous or not (and
11203 suppresses creating a symbol table entry itself). */
11205 static struct type
*
11206 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11208 struct objfile
*objfile
= cu
->objfile
;
11210 struct attribute
*attr
;
11213 /* If the definition of this type lives in .debug_types, read that type.
11214 Don't follow DW_AT_specification though, that will take us back up
11215 the chain and we want to go down. */
11216 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11219 struct dwarf2_cu
*type_cu
= cu
;
11220 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11222 /* We could just recurse on read_structure_type, but we need to call
11223 get_die_type to ensure only one type for this DIE is created.
11224 This is important, for example, because for c++ classes we need
11225 TYPE_NAME set which is only done by new_symbol. Blech. */
11226 type
= read_type_die (type_die
, type_cu
);
11228 /* TYPE_CU may not be the same as CU.
11229 Ensure TYPE is recorded in CU's type_hash table. */
11230 return set_die_type (die
, type
, cu
);
11233 type
= alloc_type (objfile
);
11234 INIT_CPLUS_SPECIFIC (type
);
11236 name
= dwarf2_name (die
, cu
);
11239 if (cu
->language
== language_cplus
11240 || cu
->language
== language_java
)
11242 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
11244 /* dwarf2_full_name might have already finished building the DIE's
11245 type. If so, there is no need to continue. */
11246 if (get_die_type (die
, cu
) != NULL
)
11247 return get_die_type (die
, cu
);
11249 TYPE_TAG_NAME (type
) = full_name
;
11250 if (die
->tag
== DW_TAG_structure_type
11251 || die
->tag
== DW_TAG_class_type
)
11252 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11256 /* The name is already allocated along with this objfile, so
11257 we don't need to duplicate it for the type. */
11258 TYPE_TAG_NAME (type
) = (char *) name
;
11259 if (die
->tag
== DW_TAG_class_type
)
11260 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
11264 if (die
->tag
== DW_TAG_structure_type
)
11266 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
11268 else if (die
->tag
== DW_TAG_union_type
)
11270 TYPE_CODE (type
) = TYPE_CODE_UNION
;
11274 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
11277 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
11278 TYPE_DECLARED_CLASS (type
) = 1;
11280 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11283 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11287 TYPE_LENGTH (type
) = 0;
11290 if (producer_is_icc (cu
))
11292 /* ICC does not output the required DW_AT_declaration
11293 on incomplete types, but gives them a size of zero. */
11296 TYPE_STUB_SUPPORTED (type
) = 1;
11298 if (die_is_declaration (die
, cu
))
11299 TYPE_STUB (type
) = 1;
11300 else if (attr
== NULL
&& die
->child
== NULL
11301 && producer_is_realview (cu
->producer
))
11302 /* RealView does not output the required DW_AT_declaration
11303 on incomplete types. */
11304 TYPE_STUB (type
) = 1;
11306 /* We need to add the type field to the die immediately so we don't
11307 infinitely recurse when dealing with pointers to the structure
11308 type within the structure itself. */
11309 set_die_type (die
, type
, cu
);
11311 /* set_die_type should be already done. */
11312 set_descriptive_type (type
, die
, cu
);
11317 /* Finish creating a structure or union type, including filling in
11318 its members and creating a symbol for it. */
11321 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11323 struct objfile
*objfile
= cu
->objfile
;
11324 struct die_info
*child_die
= die
->child
;
11327 type
= get_die_type (die
, cu
);
11329 type
= read_structure_type (die
, cu
);
11331 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
11333 struct field_info fi
;
11334 struct die_info
*child_die
;
11335 VEC (symbolp
) *template_args
= NULL
;
11336 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
11338 memset (&fi
, 0, sizeof (struct field_info
));
11340 child_die
= die
->child
;
11342 while (child_die
&& child_die
->tag
)
11344 if (child_die
->tag
== DW_TAG_member
11345 || child_die
->tag
== DW_TAG_variable
)
11347 /* NOTE: carlton/2002-11-05: A C++ static data member
11348 should be a DW_TAG_member that is a declaration, but
11349 all versions of G++ as of this writing (so through at
11350 least 3.2.1) incorrectly generate DW_TAG_variable
11351 tags for them instead. */
11352 dwarf2_add_field (&fi
, child_die
, cu
);
11354 else if (child_die
->tag
== DW_TAG_subprogram
)
11356 /* C++ member function. */
11357 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
11359 else if (child_die
->tag
== DW_TAG_inheritance
)
11361 /* C++ base class field. */
11362 dwarf2_add_field (&fi
, child_die
, cu
);
11364 else if (child_die
->tag
== DW_TAG_typedef
)
11365 dwarf2_add_typedef (&fi
, child_die
, cu
);
11366 else if (child_die
->tag
== DW_TAG_template_type_param
11367 || child_die
->tag
== DW_TAG_template_value_param
)
11369 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
11372 VEC_safe_push (symbolp
, template_args
, arg
);
11375 child_die
= sibling_die (child_die
);
11378 /* Attach template arguments to type. */
11379 if (! VEC_empty (symbolp
, template_args
))
11381 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11382 TYPE_N_TEMPLATE_ARGUMENTS (type
)
11383 = VEC_length (symbolp
, template_args
);
11384 TYPE_TEMPLATE_ARGUMENTS (type
)
11385 = obstack_alloc (&objfile
->objfile_obstack
,
11386 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11387 * sizeof (struct symbol
*)));
11388 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
11389 VEC_address (symbolp
, template_args
),
11390 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
11391 * sizeof (struct symbol
*)));
11392 VEC_free (symbolp
, template_args
);
11395 /* Attach fields and member functions to the type. */
11397 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
11400 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
11402 /* Get the type which refers to the base class (possibly this
11403 class itself) which contains the vtable pointer for the current
11404 class from the DW_AT_containing_type attribute. This use of
11405 DW_AT_containing_type is a GNU extension. */
11407 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
11409 struct type
*t
= die_containing_type (die
, cu
);
11411 TYPE_VPTR_BASETYPE (type
) = t
;
11416 /* Our own class provides vtbl ptr. */
11417 for (i
= TYPE_NFIELDS (t
) - 1;
11418 i
>= TYPE_N_BASECLASSES (t
);
11421 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
11423 if (is_vtable_name (fieldname
, cu
))
11425 TYPE_VPTR_FIELDNO (type
) = i
;
11430 /* Complain if virtual function table field not found. */
11431 if (i
< TYPE_N_BASECLASSES (t
))
11432 complaint (&symfile_complaints
,
11433 _("virtual function table pointer "
11434 "not found when defining class '%s'"),
11435 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
11440 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
11443 else if (cu
->producer
11444 && strncmp (cu
->producer
,
11445 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11447 /* The IBM XLC compiler does not provide direct indication
11448 of the containing type, but the vtable pointer is
11449 always named __vfp. */
11453 for (i
= TYPE_NFIELDS (type
) - 1;
11454 i
>= TYPE_N_BASECLASSES (type
);
11457 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
11459 TYPE_VPTR_FIELDNO (type
) = i
;
11460 TYPE_VPTR_BASETYPE (type
) = type
;
11467 /* Copy fi.typedef_field_list linked list elements content into the
11468 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11469 if (fi
.typedef_field_list
)
11471 int i
= fi
.typedef_field_list_count
;
11473 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
11474 TYPE_TYPEDEF_FIELD_ARRAY (type
)
11475 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
11476 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
11478 /* Reverse the list order to keep the debug info elements order. */
11481 struct typedef_field
*dest
, *src
;
11483 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
11484 src
= &fi
.typedef_field_list
->field
;
11485 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
11490 do_cleanups (back_to
);
11492 if (HAVE_CPLUS_STRUCT (type
))
11493 TYPE_CPLUS_REALLY_JAVA (type
) = cu
->language
== language_java
;
11496 quirk_gcc_member_function_pointer (type
, objfile
);
11498 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11499 snapshots) has been known to create a die giving a declaration
11500 for a class that has, as a child, a die giving a definition for a
11501 nested class. So we have to process our children even if the
11502 current die is a declaration. Normally, of course, a declaration
11503 won't have any children at all. */
11505 while (child_die
!= NULL
&& child_die
->tag
)
11507 if (child_die
->tag
== DW_TAG_member
11508 || child_die
->tag
== DW_TAG_variable
11509 || child_die
->tag
== DW_TAG_inheritance
11510 || child_die
->tag
== DW_TAG_template_value_param
11511 || child_die
->tag
== DW_TAG_template_type_param
)
11516 process_die (child_die
, cu
);
11518 child_die
= sibling_die (child_die
);
11521 /* Do not consider external references. According to the DWARF standard,
11522 these DIEs are identified by the fact that they have no byte_size
11523 attribute, and a declaration attribute. */
11524 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
11525 || !die_is_declaration (die
, cu
))
11526 new_symbol (die
, type
, cu
);
11529 /* Given a DW_AT_enumeration_type die, set its type. We do not
11530 complete the type's fields yet, or create any symbols. */
11532 static struct type
*
11533 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11535 struct objfile
*objfile
= cu
->objfile
;
11537 struct attribute
*attr
;
11540 /* If the definition of this type lives in .debug_types, read that type.
11541 Don't follow DW_AT_specification though, that will take us back up
11542 the chain and we want to go down. */
11543 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
11546 struct dwarf2_cu
*type_cu
= cu
;
11547 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11549 type
= read_type_die (type_die
, type_cu
);
11551 /* TYPE_CU may not be the same as CU.
11552 Ensure TYPE is recorded in CU's type_hash table. */
11553 return set_die_type (die
, type
, cu
);
11556 type
= alloc_type (objfile
);
11558 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
11559 name
= dwarf2_full_name (NULL
, die
, cu
);
11561 TYPE_TAG_NAME (type
) = (char *) name
;
11563 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11566 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11570 TYPE_LENGTH (type
) = 0;
11573 /* The enumeration DIE can be incomplete. In Ada, any type can be
11574 declared as private in the package spec, and then defined only
11575 inside the package body. Such types are known as Taft Amendment
11576 Types. When another package uses such a type, an incomplete DIE
11577 may be generated by the compiler. */
11578 if (die_is_declaration (die
, cu
))
11579 TYPE_STUB (type
) = 1;
11581 return set_die_type (die
, type
, cu
);
11584 /* Given a pointer to a die which begins an enumeration, process all
11585 the dies that define the members of the enumeration, and create the
11586 symbol for the enumeration type.
11588 NOTE: We reverse the order of the element list. */
11591 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11593 struct type
*this_type
;
11595 this_type
= get_die_type (die
, cu
);
11596 if (this_type
== NULL
)
11597 this_type
= read_enumeration_type (die
, cu
);
11599 if (die
->child
!= NULL
)
11601 struct die_info
*child_die
;
11602 struct symbol
*sym
;
11603 struct field
*fields
= NULL
;
11604 int num_fields
= 0;
11605 int unsigned_enum
= 1;
11610 child_die
= die
->child
;
11611 while (child_die
&& child_die
->tag
)
11613 if (child_die
->tag
!= DW_TAG_enumerator
)
11615 process_die (child_die
, cu
);
11619 name
= dwarf2_name (child_die
, cu
);
11622 sym
= new_symbol (child_die
, this_type
, cu
);
11623 if (SYMBOL_VALUE (sym
) < 0)
11628 else if ((mask
& SYMBOL_VALUE (sym
)) != 0)
11631 mask
|= SYMBOL_VALUE (sym
);
11633 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
11635 fields
= (struct field
*)
11637 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
11638 * sizeof (struct field
));
11641 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
11642 FIELD_TYPE (fields
[num_fields
]) = NULL
;
11643 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
11644 FIELD_BITSIZE (fields
[num_fields
]) = 0;
11650 child_die
= sibling_die (child_die
);
11655 TYPE_NFIELDS (this_type
) = num_fields
;
11656 TYPE_FIELDS (this_type
) = (struct field
*)
11657 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
11658 memcpy (TYPE_FIELDS (this_type
), fields
,
11659 sizeof (struct field
) * num_fields
);
11663 TYPE_UNSIGNED (this_type
) = 1;
11665 TYPE_FLAG_ENUM (this_type
) = 1;
11668 /* If we are reading an enum from a .debug_types unit, and the enum
11669 is a declaration, and the enum is not the signatured type in the
11670 unit, then we do not want to add a symbol for it. Adding a
11671 symbol would in some cases obscure the true definition of the
11672 enum, giving users an incomplete type when the definition is
11673 actually available. Note that we do not want to do this for all
11674 enums which are just declarations, because C++0x allows forward
11675 enum declarations. */
11676 if (cu
->per_cu
->is_debug_types
11677 && die_is_declaration (die
, cu
))
11679 struct signatured_type
*sig_type
;
11682 = lookup_signatured_type_at_offset (dwarf2_per_objfile
->objfile
,
11683 cu
->per_cu
->info_or_types_section
,
11684 cu
->per_cu
->offset
);
11685 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
11686 if (sig_type
->type_offset_in_section
.sect_off
!= die
->offset
.sect_off
)
11690 new_symbol (die
, this_type
, cu
);
11693 /* Extract all information from a DW_TAG_array_type DIE and put it in
11694 the DIE's type field. For now, this only handles one dimensional
11697 static struct type
*
11698 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11700 struct objfile
*objfile
= cu
->objfile
;
11701 struct die_info
*child_die
;
11703 struct type
*element_type
, *range_type
, *index_type
;
11704 struct type
**range_types
= NULL
;
11705 struct attribute
*attr
;
11707 struct cleanup
*back_to
;
11710 element_type
= die_type (die
, cu
);
11712 /* The die_type call above may have already set the type for this DIE. */
11713 type
= get_die_type (die
, cu
);
11717 /* Irix 6.2 native cc creates array types without children for
11718 arrays with unspecified length. */
11719 if (die
->child
== NULL
)
11721 index_type
= objfile_type (objfile
)->builtin_int
;
11722 range_type
= create_range_type (NULL
, index_type
, 0, -1);
11723 type
= create_array_type (NULL
, element_type
, range_type
);
11724 return set_die_type (die
, type
, cu
);
11727 back_to
= make_cleanup (null_cleanup
, NULL
);
11728 child_die
= die
->child
;
11729 while (child_die
&& child_die
->tag
)
11731 if (child_die
->tag
== DW_TAG_subrange_type
)
11733 struct type
*child_type
= read_type_die (child_die
, cu
);
11735 if (child_type
!= NULL
)
11737 /* The range type was succesfully read. Save it for the
11738 array type creation. */
11739 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
11741 range_types
= (struct type
**)
11742 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
11743 * sizeof (struct type
*));
11745 make_cleanup (free_current_contents
, &range_types
);
11747 range_types
[ndim
++] = child_type
;
11750 child_die
= sibling_die (child_die
);
11753 /* Dwarf2 dimensions are output from left to right, create the
11754 necessary array types in backwards order. */
11756 type
= element_type
;
11758 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
11763 type
= create_array_type (NULL
, type
, range_types
[i
++]);
11768 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
11771 /* Understand Dwarf2 support for vector types (like they occur on
11772 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11773 array type. This is not part of the Dwarf2/3 standard yet, but a
11774 custom vendor extension. The main difference between a regular
11775 array and the vector variant is that vectors are passed by value
11777 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
11779 make_vector_type (type
);
11781 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11782 implementation may choose to implement triple vectors using this
11784 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11787 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
11788 TYPE_LENGTH (type
) = DW_UNSND (attr
);
11790 complaint (&symfile_complaints
,
11791 _("DW_AT_byte_size for array type smaller "
11792 "than the total size of elements"));
11795 name
= dwarf2_name (die
, cu
);
11797 TYPE_NAME (type
) = name
;
11799 /* Install the type in the die. */
11800 set_die_type (die
, type
, cu
);
11802 /* set_die_type should be already done. */
11803 set_descriptive_type (type
, die
, cu
);
11805 do_cleanups (back_to
);
11810 static enum dwarf_array_dim_ordering
11811 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
11813 struct attribute
*attr
;
11815 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
11817 if (attr
) return DW_SND (attr
);
11819 /* GNU F77 is a special case, as at 08/2004 array type info is the
11820 opposite order to the dwarf2 specification, but data is still
11821 laid out as per normal fortran.
11823 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11824 version checking. */
11826 if (cu
->language
== language_fortran
11827 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
11829 return DW_ORD_row_major
;
11832 switch (cu
->language_defn
->la_array_ordering
)
11834 case array_column_major
:
11835 return DW_ORD_col_major
;
11836 case array_row_major
:
11838 return DW_ORD_row_major
;
11842 /* Extract all information from a DW_TAG_set_type DIE and put it in
11843 the DIE's type field. */
11845 static struct type
*
11846 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11848 struct type
*domain_type
, *set_type
;
11849 struct attribute
*attr
;
11851 domain_type
= die_type (die
, cu
);
11853 /* The die_type call above may have already set the type for this DIE. */
11854 set_type
= get_die_type (die
, cu
);
11858 set_type
= create_set_type (NULL
, domain_type
);
11860 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
11862 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
11864 return set_die_type (die
, set_type
, cu
);
11867 /* A helper for read_common_block that creates a locexpr baton.
11868 SYM is the symbol which we are marking as computed.
11869 COMMON_DIE is the DIE for the common block.
11870 COMMON_LOC is the location expression attribute for the common
11872 MEMBER_LOC is the location expression attribute for the particular
11873 member of the common block that we are processing.
11874 CU is the CU from which the above come. */
11877 mark_common_block_symbol_computed (struct symbol
*sym
,
11878 struct die_info
*common_die
,
11879 struct attribute
*common_loc
,
11880 struct attribute
*member_loc
,
11881 struct dwarf2_cu
*cu
)
11883 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11884 struct dwarf2_locexpr_baton
*baton
;
11886 unsigned int cu_off
;
11887 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
11888 LONGEST offset
= 0;
11890 gdb_assert (common_loc
&& member_loc
);
11891 gdb_assert (attr_form_is_block (common_loc
));
11892 gdb_assert (attr_form_is_block (member_loc
)
11893 || attr_form_is_constant (member_loc
));
11895 baton
= obstack_alloc (&objfile
->objfile_obstack
,
11896 sizeof (struct dwarf2_locexpr_baton
));
11897 baton
->per_cu
= cu
->per_cu
;
11898 gdb_assert (baton
->per_cu
);
11900 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11902 if (attr_form_is_constant (member_loc
))
11904 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
11905 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
11908 baton
->size
+= DW_BLOCK (member_loc
)->size
;
11910 ptr
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
11913 *ptr
++ = DW_OP_call4
;
11914 cu_off
= common_die
->offset
.sect_off
- cu
->per_cu
->offset
.sect_off
;
11915 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
11918 if (attr_form_is_constant (member_loc
))
11920 *ptr
++ = DW_OP_addr
;
11921 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
11922 ptr
+= cu
->header
.addr_size
;
11926 /* We have to copy the data here, because DW_OP_call4 will only
11927 use a DW_AT_location attribute. */
11928 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
11929 ptr
+= DW_BLOCK (member_loc
)->size
;
11932 *ptr
++ = DW_OP_plus
;
11933 gdb_assert (ptr
- baton
->data
== baton
->size
);
11935 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11936 SYMBOL_LOCATION_BATON (sym
) = baton
;
11937 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11940 /* Create appropriate locally-scoped variables for all the
11941 DW_TAG_common_block entries. Also create a struct common_block
11942 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11943 is used to sepate the common blocks name namespace from regular
11947 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
11949 struct attribute
*attr
;
11951 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11954 /* Support the .debug_loc offsets. */
11955 if (attr_form_is_block (attr
))
11959 else if (attr_form_is_section_offset (attr
))
11961 dwarf2_complex_location_expr_complaint ();
11966 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11967 "common block member");
11972 if (die
->child
!= NULL
)
11974 struct objfile
*objfile
= cu
->objfile
;
11975 struct die_info
*child_die
;
11976 size_t n_entries
= 0, size
;
11977 struct common_block
*common_block
;
11978 struct symbol
*sym
;
11980 for (child_die
= die
->child
;
11981 child_die
&& child_die
->tag
;
11982 child_die
= sibling_die (child_die
))
11985 size
= (sizeof (struct common_block
)
11986 + (n_entries
- 1) * sizeof (struct symbol
*));
11987 common_block
= obstack_alloc (&objfile
->objfile_obstack
, size
);
11988 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
11989 common_block
->n_entries
= 0;
11991 for (child_die
= die
->child
;
11992 child_die
&& child_die
->tag
;
11993 child_die
= sibling_die (child_die
))
11995 /* Create the symbol in the DW_TAG_common_block block in the current
11997 sym
= new_symbol (child_die
, NULL
, cu
);
12000 struct attribute
*member_loc
;
12002 common_block
->contents
[common_block
->n_entries
++] = sym
;
12004 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
12008 /* GDB has handled this for a long time, but it is
12009 not specified by DWARF. It seems to have been
12010 emitted by gfortran at least as recently as:
12011 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
12012 complaint (&symfile_complaints
,
12013 _("Variable in common block has "
12014 "DW_AT_data_member_location "
12015 "- DIE at 0x%x [in module %s]"),
12016 child_die
->offset
.sect_off
, cu
->objfile
->name
);
12018 if (attr_form_is_section_offset (member_loc
))
12019 dwarf2_complex_location_expr_complaint ();
12020 else if (attr_form_is_constant (member_loc
)
12021 || attr_form_is_block (member_loc
))
12024 mark_common_block_symbol_computed (sym
, die
, attr
,
12028 dwarf2_complex_location_expr_complaint ();
12033 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
12034 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
12038 /* Create a type for a C++ namespace. */
12040 static struct type
*
12041 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12043 struct objfile
*objfile
= cu
->objfile
;
12044 const char *previous_prefix
, *name
;
12048 /* For extensions, reuse the type of the original namespace. */
12049 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
12051 struct die_info
*ext_die
;
12052 struct dwarf2_cu
*ext_cu
= cu
;
12054 ext_die
= dwarf2_extension (die
, &ext_cu
);
12055 type
= read_type_die (ext_die
, ext_cu
);
12057 /* EXT_CU may not be the same as CU.
12058 Ensure TYPE is recorded in CU's type_hash table. */
12059 return set_die_type (die
, type
, cu
);
12062 name
= namespace_name (die
, &is_anonymous
, cu
);
12064 /* Now build the name of the current namespace. */
12066 previous_prefix
= determine_prefix (die
, cu
);
12067 if (previous_prefix
[0] != '\0')
12068 name
= typename_concat (&objfile
->objfile_obstack
,
12069 previous_prefix
, name
, 0, cu
);
12071 /* Create the type. */
12072 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
12074 TYPE_NAME (type
) = (char *) name
;
12075 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12077 return set_die_type (die
, type
, cu
);
12080 /* Read a C++ namespace. */
12083 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
12085 struct objfile
*objfile
= cu
->objfile
;
12088 /* Add a symbol associated to this if we haven't seen the namespace
12089 before. Also, add a using directive if it's an anonymous
12092 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
12096 type
= read_type_die (die
, cu
);
12097 new_symbol (die
, type
, cu
);
12099 namespace_name (die
, &is_anonymous
, cu
);
12102 const char *previous_prefix
= determine_prefix (die
, cu
);
12104 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
12105 NULL
, NULL
, 0, &objfile
->objfile_obstack
);
12109 if (die
->child
!= NULL
)
12111 struct die_info
*child_die
= die
->child
;
12113 while (child_die
&& child_die
->tag
)
12115 process_die (child_die
, cu
);
12116 child_die
= sibling_die (child_die
);
12121 /* Read a Fortran module as type. This DIE can be only a declaration used for
12122 imported module. Still we need that type as local Fortran "use ... only"
12123 declaration imports depend on the created type in determine_prefix. */
12125 static struct type
*
12126 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12128 struct objfile
*objfile
= cu
->objfile
;
12129 const char *module_name
;
12132 module_name
= dwarf2_name (die
, cu
);
12134 complaint (&symfile_complaints
,
12135 _("DW_TAG_module has no name, offset 0x%x"),
12136 die
->offset
.sect_off
);
12137 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
12139 /* determine_prefix uses TYPE_TAG_NAME. */
12140 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
12142 return set_die_type (die
, type
, cu
);
12145 /* Read a Fortran module. */
12148 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
12150 struct die_info
*child_die
= die
->child
;
12152 while (child_die
&& child_die
->tag
)
12154 process_die (child_die
, cu
);
12155 child_die
= sibling_die (child_die
);
12159 /* Return the name of the namespace represented by DIE. Set
12160 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12163 static const char *
12164 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
12166 struct die_info
*current_die
;
12167 const char *name
= NULL
;
12169 /* Loop through the extensions until we find a name. */
12171 for (current_die
= die
;
12172 current_die
!= NULL
;
12173 current_die
= dwarf2_extension (die
, &cu
))
12175 name
= dwarf2_name (current_die
, cu
);
12180 /* Is it an anonymous namespace? */
12182 *is_anonymous
= (name
== NULL
);
12184 name
= CP_ANONYMOUS_NAMESPACE_STR
;
12189 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12190 the user defined type vector. */
12192 static struct type
*
12193 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12195 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
12196 struct comp_unit_head
*cu_header
= &cu
->header
;
12198 struct attribute
*attr_byte_size
;
12199 struct attribute
*attr_address_class
;
12200 int byte_size
, addr_class
;
12201 struct type
*target_type
;
12203 target_type
= die_type (die
, cu
);
12205 /* The die_type call above may have already set the type for this DIE. */
12206 type
= get_die_type (die
, cu
);
12210 type
= lookup_pointer_type (target_type
);
12212 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12213 if (attr_byte_size
)
12214 byte_size
= DW_UNSND (attr_byte_size
);
12216 byte_size
= cu_header
->addr_size
;
12218 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
12219 if (attr_address_class
)
12220 addr_class
= DW_UNSND (attr_address_class
);
12222 addr_class
= DW_ADDR_none
;
12224 /* If the pointer size or address class is different than the
12225 default, create a type variant marked as such and set the
12226 length accordingly. */
12227 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
12229 if (gdbarch_address_class_type_flags_p (gdbarch
))
12233 type_flags
= gdbarch_address_class_type_flags
12234 (gdbarch
, byte_size
, addr_class
);
12235 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
12237 type
= make_type_with_address_space (type
, type_flags
);
12239 else if (TYPE_LENGTH (type
) != byte_size
)
12241 complaint (&symfile_complaints
,
12242 _("invalid pointer size %d"), byte_size
);
12246 /* Should we also complain about unhandled address classes? */
12250 TYPE_LENGTH (type
) = byte_size
;
12251 return set_die_type (die
, type
, cu
);
12254 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12255 the user defined type vector. */
12257 static struct type
*
12258 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12261 struct type
*to_type
;
12262 struct type
*domain
;
12264 to_type
= die_type (die
, cu
);
12265 domain
= die_containing_type (die
, cu
);
12267 /* The calls above may have already set the type for this DIE. */
12268 type
= get_die_type (die
, cu
);
12272 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
12273 type
= lookup_methodptr_type (to_type
);
12275 type
= lookup_memberptr_type (to_type
, domain
);
12277 return set_die_type (die
, type
, cu
);
12280 /* Extract all information from a DW_TAG_reference_type DIE and add to
12281 the user defined type vector. */
12283 static struct type
*
12284 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12286 struct comp_unit_head
*cu_header
= &cu
->header
;
12287 struct type
*type
, *target_type
;
12288 struct attribute
*attr
;
12290 target_type
= die_type (die
, cu
);
12292 /* The die_type call above may have already set the type for this DIE. */
12293 type
= get_die_type (die
, cu
);
12297 type
= lookup_reference_type (target_type
);
12298 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12301 TYPE_LENGTH (type
) = DW_UNSND (attr
);
12305 TYPE_LENGTH (type
) = cu_header
->addr_size
;
12307 return set_die_type (die
, type
, cu
);
12310 static struct type
*
12311 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12313 struct type
*base_type
, *cv_type
;
12315 base_type
= die_type (die
, cu
);
12317 /* The die_type call above may have already set the type for this DIE. */
12318 cv_type
= get_die_type (die
, cu
);
12322 /* In case the const qualifier is applied to an array type, the element type
12323 is so qualified, not the array type (section 6.7.3 of C99). */
12324 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
12326 struct type
*el_type
, *inner_array
;
12328 base_type
= copy_type (base_type
);
12329 inner_array
= base_type
;
12331 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
12333 TYPE_TARGET_TYPE (inner_array
) =
12334 copy_type (TYPE_TARGET_TYPE (inner_array
));
12335 inner_array
= TYPE_TARGET_TYPE (inner_array
);
12338 el_type
= TYPE_TARGET_TYPE (inner_array
);
12339 TYPE_TARGET_TYPE (inner_array
) =
12340 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
12342 return set_die_type (die
, base_type
, cu
);
12345 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
12346 return set_die_type (die
, cv_type
, cu
);
12349 static struct type
*
12350 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12352 struct type
*base_type
, *cv_type
;
12354 base_type
= die_type (die
, cu
);
12356 /* The die_type call above may have already set the type for this DIE. */
12357 cv_type
= get_die_type (die
, cu
);
12361 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
12362 return set_die_type (die
, cv_type
, cu
);
12365 /* Handle DW_TAG_restrict_type. */
12367 static struct type
*
12368 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12370 struct type
*base_type
, *cv_type
;
12372 base_type
= die_type (die
, cu
);
12374 /* The die_type call above may have already set the type for this DIE. */
12375 cv_type
= get_die_type (die
, cu
);
12379 cv_type
= make_restrict_type (base_type
);
12380 return set_die_type (die
, cv_type
, cu
);
12383 /* Extract all information from a DW_TAG_string_type DIE and add to
12384 the user defined type vector. It isn't really a user defined type,
12385 but it behaves like one, with other DIE's using an AT_user_def_type
12386 attribute to reference it. */
12388 static struct type
*
12389 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12391 struct objfile
*objfile
= cu
->objfile
;
12392 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12393 struct type
*type
, *range_type
, *index_type
, *char_type
;
12394 struct attribute
*attr
;
12395 unsigned int length
;
12397 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
12400 length
= DW_UNSND (attr
);
12404 /* Check for the DW_AT_byte_size attribute. */
12405 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12408 length
= DW_UNSND (attr
);
12416 index_type
= objfile_type (objfile
)->builtin_int
;
12417 range_type
= create_range_type (NULL
, index_type
, 1, length
);
12418 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
12419 type
= create_string_type (NULL
, char_type
, range_type
);
12421 return set_die_type (die
, type
, cu
);
12424 /* Handle DIES due to C code like:
12428 int (*funcp)(int a, long l);
12432 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12434 static struct type
*
12435 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12437 struct objfile
*objfile
= cu
->objfile
;
12438 struct type
*type
; /* Type that this function returns. */
12439 struct type
*ftype
; /* Function that returns above type. */
12440 struct attribute
*attr
;
12442 type
= die_type (die
, cu
);
12444 /* The die_type call above may have already set the type for this DIE. */
12445 ftype
= get_die_type (die
, cu
);
12449 ftype
= lookup_function_type (type
);
12451 /* All functions in C++, Pascal and Java have prototypes. */
12452 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
12453 if ((attr
&& (DW_UNSND (attr
) != 0))
12454 || cu
->language
== language_cplus
12455 || cu
->language
== language_java
12456 || cu
->language
== language_pascal
)
12457 TYPE_PROTOTYPED (ftype
) = 1;
12458 else if (producer_is_realview (cu
->producer
))
12459 /* RealView does not emit DW_AT_prototyped. We can not
12460 distinguish prototyped and unprototyped functions; default to
12461 prototyped, since that is more common in modern code (and
12462 RealView warns about unprototyped functions). */
12463 TYPE_PROTOTYPED (ftype
) = 1;
12465 /* Store the calling convention in the type if it's available in
12466 the subroutine die. Otherwise set the calling convention to
12467 the default value DW_CC_normal. */
12468 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
12470 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
12471 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
12472 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
12474 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
12476 /* We need to add the subroutine type to the die immediately so
12477 we don't infinitely recurse when dealing with parameters
12478 declared as the same subroutine type. */
12479 set_die_type (die
, ftype
, cu
);
12481 if (die
->child
!= NULL
)
12483 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
12484 struct die_info
*child_die
;
12485 int nparams
, iparams
;
12487 /* Count the number of parameters.
12488 FIXME: GDB currently ignores vararg functions, but knows about
12489 vararg member functions. */
12491 child_die
= die
->child
;
12492 while (child_die
&& child_die
->tag
)
12494 if (child_die
->tag
== DW_TAG_formal_parameter
)
12496 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
12497 TYPE_VARARGS (ftype
) = 1;
12498 child_die
= sibling_die (child_die
);
12501 /* Allocate storage for parameters and fill them in. */
12502 TYPE_NFIELDS (ftype
) = nparams
;
12503 TYPE_FIELDS (ftype
) = (struct field
*)
12504 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
12506 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12507 even if we error out during the parameters reading below. */
12508 for (iparams
= 0; iparams
< nparams
; iparams
++)
12509 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
12512 child_die
= die
->child
;
12513 while (child_die
&& child_die
->tag
)
12515 if (child_die
->tag
== DW_TAG_formal_parameter
)
12517 struct type
*arg_type
;
12519 /* DWARF version 2 has no clean way to discern C++
12520 static and non-static member functions. G++ helps
12521 GDB by marking the first parameter for non-static
12522 member functions (which is the this pointer) as
12523 artificial. We pass this information to
12524 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12526 DWARF version 3 added DW_AT_object_pointer, which GCC
12527 4.5 does not yet generate. */
12528 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
12530 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
12533 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
12535 /* GCC/43521: In java, the formal parameter
12536 "this" is sometimes not marked with DW_AT_artificial. */
12537 if (cu
->language
== language_java
)
12539 const char *name
= dwarf2_name (child_die
, cu
);
12541 if (name
&& !strcmp (name
, "this"))
12542 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
12545 arg_type
= die_type (child_die
, cu
);
12547 /* RealView does not mark THIS as const, which the testsuite
12548 expects. GCC marks THIS as const in method definitions,
12549 but not in the class specifications (GCC PR 43053). */
12550 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
12551 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
12554 struct dwarf2_cu
*arg_cu
= cu
;
12555 const char *name
= dwarf2_name (child_die
, cu
);
12557 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
12560 /* If the compiler emits this, use it. */
12561 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
12564 else if (name
&& strcmp (name
, "this") == 0)
12565 /* Function definitions will have the argument names. */
12567 else if (name
== NULL
&& iparams
== 0)
12568 /* Declarations may not have the names, so like
12569 elsewhere in GDB, assume an artificial first
12570 argument is "this". */
12574 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
12578 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
12581 child_die
= sibling_die (child_die
);
12588 static struct type
*
12589 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
12591 struct objfile
*objfile
= cu
->objfile
;
12592 const char *name
= NULL
;
12593 struct type
*this_type
, *target_type
;
12595 name
= dwarf2_full_name (NULL
, die
, cu
);
12596 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
12597 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
12598 TYPE_NAME (this_type
) = (char *) name
;
12599 set_die_type (die
, this_type
, cu
);
12600 target_type
= die_type (die
, cu
);
12601 if (target_type
!= this_type
)
12602 TYPE_TARGET_TYPE (this_type
) = target_type
;
12605 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12606 spec and cause infinite loops in GDB. */
12607 complaint (&symfile_complaints
,
12608 _("Self-referential DW_TAG_typedef "
12609 "- DIE at 0x%x [in module %s]"),
12610 die
->offset
.sect_off
, objfile
->name
);
12611 TYPE_TARGET_TYPE (this_type
) = NULL
;
12616 /* Find a representation of a given base type and install
12617 it in the TYPE field of the die. */
12619 static struct type
*
12620 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12622 struct objfile
*objfile
= cu
->objfile
;
12624 struct attribute
*attr
;
12625 int encoding
= 0, size
= 0;
12627 enum type_code code
= TYPE_CODE_INT
;
12628 int type_flags
= 0;
12629 struct type
*target_type
= NULL
;
12631 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
12634 encoding
= DW_UNSND (attr
);
12636 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12639 size
= DW_UNSND (attr
);
12641 name
= dwarf2_name (die
, cu
);
12644 complaint (&symfile_complaints
,
12645 _("DW_AT_name missing from DW_TAG_base_type"));
12650 case DW_ATE_address
:
12651 /* Turn DW_ATE_address into a void * pointer. */
12652 code
= TYPE_CODE_PTR
;
12653 type_flags
|= TYPE_FLAG_UNSIGNED
;
12654 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
12656 case DW_ATE_boolean
:
12657 code
= TYPE_CODE_BOOL
;
12658 type_flags
|= TYPE_FLAG_UNSIGNED
;
12660 case DW_ATE_complex_float
:
12661 code
= TYPE_CODE_COMPLEX
;
12662 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
12664 case DW_ATE_decimal_float
:
12665 code
= TYPE_CODE_DECFLOAT
;
12668 code
= TYPE_CODE_FLT
;
12670 case DW_ATE_signed
:
12672 case DW_ATE_unsigned
:
12673 type_flags
|= TYPE_FLAG_UNSIGNED
;
12674 if (cu
->language
== language_fortran
12676 && strncmp (name
, "character(", sizeof ("character(") - 1) == 0)
12677 code
= TYPE_CODE_CHAR
;
12679 case DW_ATE_signed_char
:
12680 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12681 || cu
->language
== language_pascal
12682 || cu
->language
== language_fortran
)
12683 code
= TYPE_CODE_CHAR
;
12685 case DW_ATE_unsigned_char
:
12686 if (cu
->language
== language_ada
|| cu
->language
== language_m2
12687 || cu
->language
== language_pascal
12688 || cu
->language
== language_fortran
)
12689 code
= TYPE_CODE_CHAR
;
12690 type_flags
|= TYPE_FLAG_UNSIGNED
;
12693 /* We just treat this as an integer and then recognize the
12694 type by name elsewhere. */
12698 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
12699 dwarf_type_encoding_name (encoding
));
12703 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
12704 TYPE_NAME (type
) = name
;
12705 TYPE_TARGET_TYPE (type
) = target_type
;
12707 if (name
&& strcmp (name
, "char") == 0)
12708 TYPE_NOSIGN (type
) = 1;
12710 return set_die_type (die
, type
, cu
);
12713 /* Read the given DW_AT_subrange DIE. */
12715 static struct type
*
12716 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12718 struct type
*base_type
;
12719 struct type
*range_type
;
12720 struct attribute
*attr
;
12722 int low_default_is_valid
;
12724 LONGEST negative_mask
;
12726 base_type
= die_type (die
, cu
);
12727 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12728 check_typedef (base_type
);
12730 /* The die_type call above may have already set the type for this DIE. */
12731 range_type
= get_die_type (die
, cu
);
12735 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12736 omitting DW_AT_lower_bound. */
12737 switch (cu
->language
)
12740 case language_cplus
:
12742 low_default_is_valid
= 1;
12744 case language_fortran
:
12746 low_default_is_valid
= 1;
12749 case language_java
:
12750 case language_objc
:
12752 low_default_is_valid
= (cu
->header
.version
>= 4);
12756 case language_pascal
:
12758 low_default_is_valid
= (cu
->header
.version
>= 4);
12762 low_default_is_valid
= 0;
12766 /* FIXME: For variable sized arrays either of these could be
12767 a variable rather than a constant value. We'll allow it,
12768 but we don't know how to handle it. */
12769 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
12771 low
= dwarf2_get_attr_constant_value (attr
, low
);
12772 else if (!low_default_is_valid
)
12773 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
12774 "- DIE at 0x%x [in module %s]"),
12775 die
->offset
.sect_off
, cu
->objfile
->name
);
12777 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
12780 if (attr_form_is_block (attr
) || is_ref_attr (attr
))
12782 /* GCC encodes arrays with unspecified or dynamic length
12783 with a DW_FORM_block1 attribute or a reference attribute.
12784 FIXME: GDB does not yet know how to handle dynamic
12785 arrays properly, treat them as arrays with unspecified
12788 FIXME: jimb/2003-09-22: GDB does not really know
12789 how to handle arrays of unspecified length
12790 either; we just represent them as zero-length
12791 arrays. Choose an appropriate upper bound given
12792 the lower bound we've computed above. */
12796 high
= dwarf2_get_attr_constant_value (attr
, 1);
12800 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
12803 int count
= dwarf2_get_attr_constant_value (attr
, 1);
12804 high
= low
+ count
- 1;
12808 /* Unspecified array length. */
12813 /* Dwarf-2 specifications explicitly allows to create subrange types
12814 without specifying a base type.
12815 In that case, the base type must be set to the type of
12816 the lower bound, upper bound or count, in that order, if any of these
12817 three attributes references an object that has a type.
12818 If no base type is found, the Dwarf-2 specifications say that
12819 a signed integer type of size equal to the size of an address should
12821 For the following C code: `extern char gdb_int [];'
12822 GCC produces an empty range DIE.
12823 FIXME: muller/2010-05-28: Possible references to object for low bound,
12824 high bound or count are not yet handled by this code. */
12825 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
12827 struct objfile
*objfile
= cu
->objfile
;
12828 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12829 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
12830 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
12832 /* Test "int", "long int", and "long long int" objfile types,
12833 and select the first one having a size above or equal to the
12834 architecture address size. */
12835 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12836 base_type
= int_type
;
12839 int_type
= objfile_type (objfile
)->builtin_long
;
12840 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12841 base_type
= int_type
;
12844 int_type
= objfile_type (objfile
)->builtin_long_long
;
12845 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
12846 base_type
= int_type
;
12852 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
12853 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
12854 low
|= negative_mask
;
12855 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
12856 high
|= negative_mask
;
12858 range_type
= create_range_type (NULL
, base_type
, low
, high
);
12860 /* Mark arrays with dynamic length at least as an array of unspecified
12861 length. GDB could check the boundary but before it gets implemented at
12862 least allow accessing the array elements. */
12863 if (attr
&& attr_form_is_block (attr
))
12864 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12866 /* Ada expects an empty array on no boundary attributes. */
12867 if (attr
== NULL
&& cu
->language
!= language_ada
)
12868 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
12870 name
= dwarf2_name (die
, cu
);
12872 TYPE_NAME (range_type
) = name
;
12874 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
12876 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
12878 set_die_type (die
, range_type
, cu
);
12880 /* set_die_type should be already done. */
12881 set_descriptive_type (range_type
, die
, cu
);
12886 static struct type
*
12887 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12891 /* For now, we only support the C meaning of an unspecified type: void. */
12893 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
12894 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
12896 return set_die_type (die
, type
, cu
);
12899 /* Read a single die and all its descendents. Set the die's sibling
12900 field to NULL; set other fields in the die correctly, and set all
12901 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12902 location of the info_ptr after reading all of those dies. PARENT
12903 is the parent of the die in question. */
12905 static struct die_info
*
12906 read_die_and_children (const struct die_reader_specs
*reader
,
12907 gdb_byte
*info_ptr
,
12908 gdb_byte
**new_info_ptr
,
12909 struct die_info
*parent
)
12911 struct die_info
*die
;
12915 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
12918 *new_info_ptr
= cur_ptr
;
12921 store_in_ref_table (die
, reader
->cu
);
12924 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
12928 *new_info_ptr
= cur_ptr
;
12931 die
->sibling
= NULL
;
12932 die
->parent
= parent
;
12936 /* Read a die, all of its descendents, and all of its siblings; set
12937 all of the fields of all of the dies correctly. Arguments are as
12938 in read_die_and_children. */
12940 static struct die_info
*
12941 read_die_and_siblings (const struct die_reader_specs
*reader
,
12942 gdb_byte
*info_ptr
,
12943 gdb_byte
**new_info_ptr
,
12944 struct die_info
*parent
)
12946 struct die_info
*first_die
, *last_sibling
;
12949 cur_ptr
= info_ptr
;
12950 first_die
= last_sibling
= NULL
;
12954 struct die_info
*die
12955 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
12959 *new_info_ptr
= cur_ptr
;
12966 last_sibling
->sibling
= die
;
12968 last_sibling
= die
;
12972 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12974 The caller is responsible for filling in the extra attributes
12975 and updating (*DIEP)->num_attrs.
12976 Set DIEP to point to a newly allocated die with its information,
12977 except for its child, sibling, and parent fields.
12978 Set HAS_CHILDREN to tell whether the die has children or not. */
12981 read_full_die_1 (const struct die_reader_specs
*reader
,
12982 struct die_info
**diep
, gdb_byte
*info_ptr
,
12983 int *has_children
, int num_extra_attrs
)
12985 unsigned int abbrev_number
, bytes_read
, i
;
12986 sect_offset offset
;
12987 struct abbrev_info
*abbrev
;
12988 struct die_info
*die
;
12989 struct dwarf2_cu
*cu
= reader
->cu
;
12990 bfd
*abfd
= reader
->abfd
;
12992 offset
.sect_off
= info_ptr
- reader
->buffer
;
12993 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
12994 info_ptr
+= bytes_read
;
12995 if (!abbrev_number
)
13002 abbrev
= abbrev_table_lookup_abbrev (cu
->abbrev_table
, abbrev_number
);
13004 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
13006 bfd_get_filename (abfd
));
13008 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
13009 die
->offset
= offset
;
13010 die
->tag
= abbrev
->tag
;
13011 die
->abbrev
= abbrev_number
;
13013 /* Make the result usable.
13014 The caller needs to update num_attrs after adding the extra
13016 die
->num_attrs
= abbrev
->num_attrs
;
13018 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13019 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
13023 *has_children
= abbrev
->has_children
;
13027 /* Read a die and all its attributes.
13028 Set DIEP to point to a newly allocated die with its information,
13029 except for its child, sibling, and parent fields.
13030 Set HAS_CHILDREN to tell whether the die has children or not. */
13033 read_full_die (const struct die_reader_specs
*reader
,
13034 struct die_info
**diep
, gdb_byte
*info_ptr
,
13037 return read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
13040 /* Abbreviation tables.
13042 In DWARF version 2, the description of the debugging information is
13043 stored in a separate .debug_abbrev section. Before we read any
13044 dies from a section we read in all abbreviations and install them
13045 in a hash table. */
13047 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
13049 static struct abbrev_info
*
13050 abbrev_table_alloc_abbrev (struct abbrev_table
*abbrev_table
)
13052 struct abbrev_info
*abbrev
;
13054 abbrev
= (struct abbrev_info
*)
13055 obstack_alloc (&abbrev_table
->abbrev_obstack
, sizeof (struct abbrev_info
));
13056 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13060 /* Add an abbreviation to the table. */
13063 abbrev_table_add_abbrev (struct abbrev_table
*abbrev_table
,
13064 unsigned int abbrev_number
,
13065 struct abbrev_info
*abbrev
)
13067 unsigned int hash_number
;
13069 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13070 abbrev
->next
= abbrev_table
->abbrevs
[hash_number
];
13071 abbrev_table
->abbrevs
[hash_number
] = abbrev
;
13074 /* Look up an abbrev in the table.
13075 Returns NULL if the abbrev is not found. */
13077 static struct abbrev_info
*
13078 abbrev_table_lookup_abbrev (const struct abbrev_table
*abbrev_table
,
13079 unsigned int abbrev_number
)
13081 unsigned int hash_number
;
13082 struct abbrev_info
*abbrev
;
13084 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
13085 abbrev
= abbrev_table
->abbrevs
[hash_number
];
13089 if (abbrev
->number
== abbrev_number
)
13091 abbrev
= abbrev
->next
;
13096 /* Read in an abbrev table. */
13098 static struct abbrev_table
*
13099 abbrev_table_read_table (struct dwarf2_section_info
*section
,
13100 sect_offset offset
)
13102 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13103 bfd
*abfd
= section
->asection
->owner
;
13104 struct abbrev_table
*abbrev_table
;
13105 gdb_byte
*abbrev_ptr
;
13106 struct abbrev_info
*cur_abbrev
;
13107 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
13108 unsigned int abbrev_form
;
13109 struct attr_abbrev
*cur_attrs
;
13110 unsigned int allocated_attrs
;
13112 abbrev_table
= XMALLOC (struct abbrev_table
);
13113 abbrev_table
->offset
= offset
;
13114 obstack_init (&abbrev_table
->abbrev_obstack
);
13115 abbrev_table
->abbrevs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13117 * sizeof (struct abbrev_info
*)));
13118 memset (abbrev_table
->abbrevs
, 0,
13119 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
13121 dwarf2_read_section (objfile
, section
);
13122 abbrev_ptr
= section
->buffer
+ offset
.sect_off
;
13123 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13124 abbrev_ptr
+= bytes_read
;
13126 allocated_attrs
= ATTR_ALLOC_CHUNK
;
13127 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
13129 /* Loop until we reach an abbrev number of 0. */
13130 while (abbrev_number
)
13132 cur_abbrev
= abbrev_table_alloc_abbrev (abbrev_table
);
13134 /* read in abbrev header */
13135 cur_abbrev
->number
= abbrev_number
;
13136 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13137 abbrev_ptr
+= bytes_read
;
13138 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
13141 /* now read in declarations */
13142 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13143 abbrev_ptr
+= bytes_read
;
13144 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13145 abbrev_ptr
+= bytes_read
;
13146 while (abbrev_name
)
13148 if (cur_abbrev
->num_attrs
== allocated_attrs
)
13150 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
13152 = xrealloc (cur_attrs
, (allocated_attrs
13153 * sizeof (struct attr_abbrev
)));
13156 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
13157 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
13158 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13159 abbrev_ptr
+= bytes_read
;
13160 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13161 abbrev_ptr
+= bytes_read
;
13164 cur_abbrev
->attrs
= obstack_alloc (&abbrev_table
->abbrev_obstack
,
13165 (cur_abbrev
->num_attrs
13166 * sizeof (struct attr_abbrev
)));
13167 memcpy (cur_abbrev
->attrs
, cur_attrs
,
13168 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
13170 abbrev_table_add_abbrev (abbrev_table
, abbrev_number
, cur_abbrev
);
13172 /* Get next abbreviation.
13173 Under Irix6 the abbreviations for a compilation unit are not
13174 always properly terminated with an abbrev number of 0.
13175 Exit loop if we encounter an abbreviation which we have
13176 already read (which means we are about to read the abbreviations
13177 for the next compile unit) or if the end of the abbreviation
13178 table is reached. */
13179 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
13181 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
13182 abbrev_ptr
+= bytes_read
;
13183 if (abbrev_table_lookup_abbrev (abbrev_table
, abbrev_number
) != NULL
)
13188 return abbrev_table
;
13191 /* Free the resources held by ABBREV_TABLE. */
13194 abbrev_table_free (struct abbrev_table
*abbrev_table
)
13196 obstack_free (&abbrev_table
->abbrev_obstack
, NULL
);
13197 xfree (abbrev_table
);
13200 /* Same as abbrev_table_free but as a cleanup.
13201 We pass in a pointer to the pointer to the table so that we can
13202 set the pointer to NULL when we're done. It also simplifies
13203 build_type_unit_groups. */
13206 abbrev_table_free_cleanup (void *table_ptr
)
13208 struct abbrev_table
**abbrev_table_ptr
= table_ptr
;
13210 if (*abbrev_table_ptr
!= NULL
)
13211 abbrev_table_free (*abbrev_table_ptr
);
13212 *abbrev_table_ptr
= NULL
;
13215 /* Read the abbrev table for CU from ABBREV_SECTION. */
13218 dwarf2_read_abbrevs (struct dwarf2_cu
*cu
,
13219 struct dwarf2_section_info
*abbrev_section
)
13222 abbrev_table_read_table (abbrev_section
, cu
->header
.abbrev_offset
);
13225 /* Release the memory used by the abbrev table for a compilation unit. */
13228 dwarf2_free_abbrev_table (void *ptr_to_cu
)
13230 struct dwarf2_cu
*cu
= ptr_to_cu
;
13232 abbrev_table_free (cu
->abbrev_table
);
13233 /* Set this to NULL so that we SEGV if we try to read it later,
13234 and also because free_comp_unit verifies this is NULL. */
13235 cu
->abbrev_table
= NULL
;
13238 /* Returns nonzero if TAG represents a type that we might generate a partial
13242 is_type_tag_for_partial (int tag
)
13247 /* Some types that would be reasonable to generate partial symbols for,
13248 that we don't at present. */
13249 case DW_TAG_array_type
:
13250 case DW_TAG_file_type
:
13251 case DW_TAG_ptr_to_member_type
:
13252 case DW_TAG_set_type
:
13253 case DW_TAG_string_type
:
13254 case DW_TAG_subroutine_type
:
13256 case DW_TAG_base_type
:
13257 case DW_TAG_class_type
:
13258 case DW_TAG_interface_type
:
13259 case DW_TAG_enumeration_type
:
13260 case DW_TAG_structure_type
:
13261 case DW_TAG_subrange_type
:
13262 case DW_TAG_typedef
:
13263 case DW_TAG_union_type
:
13270 /* Load all DIEs that are interesting for partial symbols into memory. */
13272 static struct partial_die_info
*
13273 load_partial_dies (const struct die_reader_specs
*reader
,
13274 gdb_byte
*info_ptr
, int building_psymtab
)
13276 struct dwarf2_cu
*cu
= reader
->cu
;
13277 struct objfile
*objfile
= cu
->objfile
;
13278 struct partial_die_info
*part_die
;
13279 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
13280 struct abbrev_info
*abbrev
;
13281 unsigned int bytes_read
;
13282 unsigned int load_all
= 0;
13283 int nesting_level
= 1;
13288 gdb_assert (cu
->per_cu
!= NULL
);
13289 if (cu
->per_cu
->load_all_dies
)
13293 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13297 &cu
->comp_unit_obstack
,
13298 hashtab_obstack_allocate
,
13299 dummy_obstack_deallocate
);
13301 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13302 sizeof (struct partial_die_info
));
13306 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
13308 /* A NULL abbrev means the end of a series of children. */
13309 if (abbrev
== NULL
)
13311 if (--nesting_level
== 0)
13313 /* PART_DIE was probably the last thing allocated on the
13314 comp_unit_obstack, so we could call obstack_free
13315 here. We don't do that because the waste is small,
13316 and will be cleaned up when we're done with this
13317 compilation unit. This way, we're also more robust
13318 against other users of the comp_unit_obstack. */
13321 info_ptr
+= bytes_read
;
13322 last_die
= parent_die
;
13323 parent_die
= parent_die
->die_parent
;
13327 /* Check for template arguments. We never save these; if
13328 they're seen, we just mark the parent, and go on our way. */
13329 if (parent_die
!= NULL
13330 && cu
->language
== language_cplus
13331 && (abbrev
->tag
== DW_TAG_template_type_param
13332 || abbrev
->tag
== DW_TAG_template_value_param
))
13334 parent_die
->has_template_arguments
= 1;
13338 /* We don't need a partial DIE for the template argument. */
13339 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13344 /* We only recurse into c++ subprograms looking for template arguments.
13345 Skip their other children. */
13347 && cu
->language
== language_cplus
13348 && parent_die
!= NULL
13349 && parent_die
->tag
== DW_TAG_subprogram
)
13351 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13355 /* Check whether this DIE is interesting enough to save. Normally
13356 we would not be interested in members here, but there may be
13357 later variables referencing them via DW_AT_specification (for
13358 static members). */
13360 && !is_type_tag_for_partial (abbrev
->tag
)
13361 && abbrev
->tag
!= DW_TAG_constant
13362 && abbrev
->tag
!= DW_TAG_enumerator
13363 && abbrev
->tag
!= DW_TAG_subprogram
13364 && abbrev
->tag
!= DW_TAG_lexical_block
13365 && abbrev
->tag
!= DW_TAG_variable
13366 && abbrev
->tag
!= DW_TAG_namespace
13367 && abbrev
->tag
!= DW_TAG_module
13368 && abbrev
->tag
!= DW_TAG_member
13369 && abbrev
->tag
!= DW_TAG_imported_unit
)
13371 /* Otherwise we skip to the next sibling, if any. */
13372 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
13376 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
13379 /* This two-pass algorithm for processing partial symbols has a
13380 high cost in cache pressure. Thus, handle some simple cases
13381 here which cover the majority of C partial symbols. DIEs
13382 which neither have specification tags in them, nor could have
13383 specification tags elsewhere pointing at them, can simply be
13384 processed and discarded.
13386 This segment is also optional; scan_partial_symbols and
13387 add_partial_symbol will handle these DIEs if we chain
13388 them in normally. When compilers which do not emit large
13389 quantities of duplicate debug information are more common,
13390 this code can probably be removed. */
13392 /* Any complete simple types at the top level (pretty much all
13393 of them, for a language without namespaces), can be processed
13395 if (parent_die
== NULL
13396 && part_die
->has_specification
== 0
13397 && part_die
->is_declaration
== 0
13398 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
13399 || part_die
->tag
== DW_TAG_base_type
13400 || part_die
->tag
== DW_TAG_subrange_type
))
13402 if (building_psymtab
&& part_die
->name
!= NULL
)
13403 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13404 VAR_DOMAIN
, LOC_TYPEDEF
,
13405 &objfile
->static_psymbols
,
13406 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13407 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13411 /* The exception for DW_TAG_typedef with has_children above is
13412 a workaround of GCC PR debug/47510. In the case of this complaint
13413 type_name_no_tag_or_error will error on such types later.
13415 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13416 it could not find the child DIEs referenced later, this is checked
13417 above. In correct DWARF DW_TAG_typedef should have no children. */
13419 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
13420 complaint (&symfile_complaints
,
13421 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13422 "- DIE at 0x%x [in module %s]"),
13423 part_die
->offset
.sect_off
, objfile
->name
);
13425 /* If we're at the second level, and we're an enumerator, and
13426 our parent has no specification (meaning possibly lives in a
13427 namespace elsewhere), then we can add the partial symbol now
13428 instead of queueing it. */
13429 if (part_die
->tag
== DW_TAG_enumerator
13430 && parent_die
!= NULL
13431 && parent_die
->die_parent
== NULL
13432 && parent_die
->tag
== DW_TAG_enumeration_type
13433 && parent_die
->has_specification
== 0)
13435 if (part_die
->name
== NULL
)
13436 complaint (&symfile_complaints
,
13437 _("malformed enumerator DIE ignored"));
13438 else if (building_psymtab
)
13439 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
13440 VAR_DOMAIN
, LOC_CONST
,
13441 (cu
->language
== language_cplus
13442 || cu
->language
== language_java
)
13443 ? &objfile
->global_psymbols
13444 : &objfile
->static_psymbols
,
13445 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
13447 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
13451 /* We'll save this DIE so link it in. */
13452 part_die
->die_parent
= parent_die
;
13453 part_die
->die_sibling
= NULL
;
13454 part_die
->die_child
= NULL
;
13456 if (last_die
&& last_die
== parent_die
)
13457 last_die
->die_child
= part_die
;
13459 last_die
->die_sibling
= part_die
;
13461 last_die
= part_die
;
13463 if (first_die
== NULL
)
13464 first_die
= part_die
;
13466 /* Maybe add the DIE to the hash table. Not all DIEs that we
13467 find interesting need to be in the hash table, because we
13468 also have the parent/sibling/child chains; only those that we
13469 might refer to by offset later during partial symbol reading.
13471 For now this means things that might have be the target of a
13472 DW_AT_specification, DW_AT_abstract_origin, or
13473 DW_AT_extension. DW_AT_extension will refer only to
13474 namespaces; DW_AT_abstract_origin refers to functions (and
13475 many things under the function DIE, but we do not recurse
13476 into function DIEs during partial symbol reading) and
13477 possibly variables as well; DW_AT_specification refers to
13478 declarations. Declarations ought to have the DW_AT_declaration
13479 flag. It happens that GCC forgets to put it in sometimes, but
13480 only for functions, not for types.
13482 Adding more things than necessary to the hash table is harmless
13483 except for the performance cost. Adding too few will result in
13484 wasted time in find_partial_die, when we reread the compilation
13485 unit with load_all_dies set. */
13488 || abbrev
->tag
== DW_TAG_constant
13489 || abbrev
->tag
== DW_TAG_subprogram
13490 || abbrev
->tag
== DW_TAG_variable
13491 || abbrev
->tag
== DW_TAG_namespace
13492 || part_die
->is_declaration
)
13496 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
13497 part_die
->offset
.sect_off
, INSERT
);
13501 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
13502 sizeof (struct partial_die_info
));
13504 /* For some DIEs we want to follow their children (if any). For C
13505 we have no reason to follow the children of structures; for other
13506 languages we have to, so that we can get at method physnames
13507 to infer fully qualified class names, for DW_AT_specification,
13508 and for C++ template arguments. For C++, we also look one level
13509 inside functions to find template arguments (if the name of the
13510 function does not already contain the template arguments).
13512 For Ada, we need to scan the children of subprograms and lexical
13513 blocks as well because Ada allows the definition of nested
13514 entities that could be interesting for the debugger, such as
13515 nested subprograms for instance. */
13516 if (last_die
->has_children
13518 || last_die
->tag
== DW_TAG_namespace
13519 || last_die
->tag
== DW_TAG_module
13520 || last_die
->tag
== DW_TAG_enumeration_type
13521 || (cu
->language
== language_cplus
13522 && last_die
->tag
== DW_TAG_subprogram
13523 && (last_die
->name
== NULL
13524 || strchr (last_die
->name
, '<') == NULL
))
13525 || (cu
->language
!= language_c
13526 && (last_die
->tag
== DW_TAG_class_type
13527 || last_die
->tag
== DW_TAG_interface_type
13528 || last_die
->tag
== DW_TAG_structure_type
13529 || last_die
->tag
== DW_TAG_union_type
))
13530 || (cu
->language
== language_ada
13531 && (last_die
->tag
== DW_TAG_subprogram
13532 || last_die
->tag
== DW_TAG_lexical_block
))))
13535 parent_die
= last_die
;
13539 /* Otherwise we skip to the next sibling, if any. */
13540 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
13542 /* Back to the top, do it again. */
13546 /* Read a minimal amount of information into the minimal die structure. */
13549 read_partial_die (const struct die_reader_specs
*reader
,
13550 struct partial_die_info
*part_die
,
13551 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
13552 gdb_byte
*info_ptr
)
13554 struct dwarf2_cu
*cu
= reader
->cu
;
13555 struct objfile
*objfile
= cu
->objfile
;
13556 gdb_byte
*buffer
= reader
->buffer
;
13558 struct attribute attr
;
13559 int has_low_pc_attr
= 0;
13560 int has_high_pc_attr
= 0;
13561 int high_pc_relative
= 0;
13563 memset (part_die
, 0, sizeof (struct partial_die_info
));
13565 part_die
->offset
.sect_off
= info_ptr
- buffer
;
13567 info_ptr
+= abbrev_len
;
13569 if (abbrev
== NULL
)
13572 part_die
->tag
= abbrev
->tag
;
13573 part_die
->has_children
= abbrev
->has_children
;
13575 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
13577 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
13579 /* Store the data if it is of an attribute we want to keep in a
13580 partial symbol table. */
13584 switch (part_die
->tag
)
13586 case DW_TAG_compile_unit
:
13587 case DW_TAG_partial_unit
:
13588 case DW_TAG_type_unit
:
13589 /* Compilation units have a DW_AT_name that is a filename, not
13590 a source language identifier. */
13591 case DW_TAG_enumeration_type
:
13592 case DW_TAG_enumerator
:
13593 /* These tags always have simple identifiers already; no need
13594 to canonicalize them. */
13595 part_die
->name
= DW_STRING (&attr
);
13599 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
13600 &objfile
->objfile_obstack
);
13604 case DW_AT_linkage_name
:
13605 case DW_AT_MIPS_linkage_name
:
13606 /* Note that both forms of linkage name might appear. We
13607 assume they will be the same, and we only store the last
13609 if (cu
->language
== language_ada
)
13610 part_die
->name
= DW_STRING (&attr
);
13611 part_die
->linkage_name
= DW_STRING (&attr
);
13614 has_low_pc_attr
= 1;
13615 part_die
->lowpc
= DW_ADDR (&attr
);
13617 case DW_AT_high_pc
:
13618 has_high_pc_attr
= 1;
13619 if (attr
.form
== DW_FORM_addr
13620 || attr
.form
== DW_FORM_GNU_addr_index
)
13621 part_die
->highpc
= DW_ADDR (&attr
);
13624 high_pc_relative
= 1;
13625 part_die
->highpc
= DW_UNSND (&attr
);
13628 case DW_AT_location
:
13629 /* Support the .debug_loc offsets. */
13630 if (attr_form_is_block (&attr
))
13632 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
13634 else if (attr_form_is_section_offset (&attr
))
13636 dwarf2_complex_location_expr_complaint ();
13640 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13641 "partial symbol information");
13644 case DW_AT_external
:
13645 part_die
->is_external
= DW_UNSND (&attr
);
13647 case DW_AT_declaration
:
13648 part_die
->is_declaration
= DW_UNSND (&attr
);
13651 part_die
->has_type
= 1;
13653 case DW_AT_abstract_origin
:
13654 case DW_AT_specification
:
13655 case DW_AT_extension
:
13656 part_die
->has_specification
= 1;
13657 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
13658 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13659 || cu
->per_cu
->is_dwz
);
13661 case DW_AT_sibling
:
13662 /* Ignore absolute siblings, they might point outside of
13663 the current compile unit. */
13664 if (attr
.form
== DW_FORM_ref_addr
)
13665 complaint (&symfile_complaints
,
13666 _("ignoring absolute DW_AT_sibling"));
13668 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
).sect_off
;
13670 case DW_AT_byte_size
:
13671 part_die
->has_byte_size
= 1;
13673 case DW_AT_calling_convention
:
13674 /* DWARF doesn't provide a way to identify a program's source-level
13675 entry point. DW_AT_calling_convention attributes are only meant
13676 to describe functions' calling conventions.
13678 However, because it's a necessary piece of information in
13679 Fortran, and because DW_CC_program is the only piece of debugging
13680 information whose definition refers to a 'main program' at all,
13681 several compilers have begun marking Fortran main programs with
13682 DW_CC_program --- even when those functions use the standard
13683 calling conventions.
13685 So until DWARF specifies a way to provide this information and
13686 compilers pick up the new representation, we'll support this
13688 if (DW_UNSND (&attr
) == DW_CC_program
13689 && cu
->language
== language_fortran
)
13691 set_main_name (part_die
->name
);
13693 /* As this DIE has a static linkage the name would be difficult
13694 to look up later. */
13695 language_of_main
= language_fortran
;
13699 if (DW_UNSND (&attr
) == DW_INL_inlined
13700 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
13701 part_die
->may_be_inlined
= 1;
13705 if (part_die
->tag
== DW_TAG_imported_unit
)
13707 part_die
->d
.offset
= dwarf2_get_ref_die_offset (&attr
);
13708 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
13709 || cu
->per_cu
->is_dwz
);
13718 if (high_pc_relative
)
13719 part_die
->highpc
+= part_die
->lowpc
;
13721 if (has_low_pc_attr
&& has_high_pc_attr
)
13723 /* When using the GNU linker, .gnu.linkonce. sections are used to
13724 eliminate duplicate copies of functions and vtables and such.
13725 The linker will arbitrarily choose one and discard the others.
13726 The AT_*_pc values for such functions refer to local labels in
13727 these sections. If the section from that file was discarded, the
13728 labels are not in the output, so the relocs get a value of 0.
13729 If this is a discarded function, mark the pc bounds as invalid,
13730 so that GDB will ignore it. */
13731 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13733 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13735 complaint (&symfile_complaints
,
13736 _("DW_AT_low_pc %s is zero "
13737 "for DIE at 0x%x [in module %s]"),
13738 paddress (gdbarch
, part_die
->lowpc
),
13739 part_die
->offset
.sect_off
, objfile
->name
);
13741 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13742 else if (part_die
->lowpc
>= part_die
->highpc
)
13744 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13746 complaint (&symfile_complaints
,
13747 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13748 "for DIE at 0x%x [in module %s]"),
13749 paddress (gdbarch
, part_die
->lowpc
),
13750 paddress (gdbarch
, part_die
->highpc
),
13751 part_die
->offset
.sect_off
, objfile
->name
);
13754 part_die
->has_pc_info
= 1;
13760 /* Find a cached partial DIE at OFFSET in CU. */
13762 static struct partial_die_info
*
13763 find_partial_die_in_comp_unit (sect_offset offset
, struct dwarf2_cu
*cu
)
13765 struct partial_die_info
*lookup_die
= NULL
;
13766 struct partial_die_info part_die
;
13768 part_die
.offset
= offset
;
13769 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
,
13775 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13776 except in the case of .debug_types DIEs which do not reference
13777 outside their CU (they do however referencing other types via
13778 DW_FORM_ref_sig8). */
13780 static struct partial_die_info
*
13781 find_partial_die (sect_offset offset
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
13783 struct objfile
*objfile
= cu
->objfile
;
13784 struct dwarf2_per_cu_data
*per_cu
= NULL
;
13785 struct partial_die_info
*pd
= NULL
;
13787 if (offset_in_dwz
== cu
->per_cu
->is_dwz
13788 && offset_in_cu_p (&cu
->header
, offset
))
13790 pd
= find_partial_die_in_comp_unit (offset
, cu
);
13793 /* We missed recording what we needed.
13794 Load all dies and try again. */
13795 per_cu
= cu
->per_cu
;
13799 /* TUs don't reference other CUs/TUs (except via type signatures). */
13800 if (cu
->per_cu
->is_debug_types
)
13802 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13803 " external reference to offset 0x%lx [in module %s].\n"),
13804 (long) cu
->header
.offset
.sect_off
, (long) offset
.sect_off
,
13805 bfd_get_filename (objfile
->obfd
));
13807 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
13810 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
13811 load_partial_comp_unit (per_cu
);
13813 per_cu
->cu
->last_used
= 0;
13814 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13817 /* If we didn't find it, and not all dies have been loaded,
13818 load them all and try again. */
13820 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
13822 per_cu
->load_all_dies
= 1;
13824 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13825 THIS_CU->cu may already be in use. So we can't just free it and
13826 replace its DIEs with the ones we read in. Instead, we leave those
13827 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13828 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13830 load_partial_comp_unit (per_cu
);
13832 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
13836 internal_error (__FILE__
, __LINE__
,
13837 _("could not find partial DIE 0x%x "
13838 "in cache [from module %s]\n"),
13839 offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
13843 /* See if we can figure out if the class lives in a namespace. We do
13844 this by looking for a member function; its demangled name will
13845 contain namespace info, if there is any. */
13848 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
13849 struct dwarf2_cu
*cu
)
13851 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13852 what template types look like, because the demangler
13853 frequently doesn't give the same name as the debug info. We
13854 could fix this by only using the demangled name to get the
13855 prefix (but see comment in read_structure_type). */
13857 struct partial_die_info
*real_pdi
;
13858 struct partial_die_info
*child_pdi
;
13860 /* If this DIE (this DIE's specification, if any) has a parent, then
13861 we should not do this. We'll prepend the parent's fully qualified
13862 name when we create the partial symbol. */
13864 real_pdi
= struct_pdi
;
13865 while (real_pdi
->has_specification
)
13866 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
13867 real_pdi
->spec_is_dwz
, cu
);
13869 if (real_pdi
->die_parent
!= NULL
)
13872 for (child_pdi
= struct_pdi
->die_child
;
13874 child_pdi
= child_pdi
->die_sibling
)
13876 if (child_pdi
->tag
== DW_TAG_subprogram
13877 && child_pdi
->linkage_name
!= NULL
)
13879 char *actual_class_name
13880 = language_class_name_from_physname (cu
->language_defn
,
13881 child_pdi
->linkage_name
);
13882 if (actual_class_name
!= NULL
)
13885 = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
13887 strlen (actual_class_name
));
13888 xfree (actual_class_name
);
13895 /* Adjust PART_DIE before generating a symbol for it. This function
13896 may set the is_external flag or change the DIE's name. */
13899 fixup_partial_die (struct partial_die_info
*part_die
,
13900 struct dwarf2_cu
*cu
)
13902 /* Once we've fixed up a die, there's no point in doing so again.
13903 This also avoids a memory leak if we were to call
13904 guess_partial_die_structure_name multiple times. */
13905 if (part_die
->fixup_called
)
13908 /* If we found a reference attribute and the DIE has no name, try
13909 to find a name in the referred to DIE. */
13911 if (part_die
->name
== NULL
&& part_die
->has_specification
)
13913 struct partial_die_info
*spec_die
;
13915 spec_die
= find_partial_die (part_die
->spec_offset
,
13916 part_die
->spec_is_dwz
, cu
);
13918 fixup_partial_die (spec_die
, cu
);
13920 if (spec_die
->name
)
13922 part_die
->name
= spec_die
->name
;
13924 /* Copy DW_AT_external attribute if it is set. */
13925 if (spec_die
->is_external
)
13926 part_die
->is_external
= spec_die
->is_external
;
13930 /* Set default names for some unnamed DIEs. */
13932 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
13933 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
13935 /* If there is no parent die to provide a namespace, and there are
13936 children, see if we can determine the namespace from their linkage
13938 if (cu
->language
== language_cplus
13939 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
13940 && part_die
->die_parent
== NULL
13941 && part_die
->has_children
13942 && (part_die
->tag
== DW_TAG_class_type
13943 || part_die
->tag
== DW_TAG_structure_type
13944 || part_die
->tag
== DW_TAG_union_type
))
13945 guess_partial_die_structure_name (part_die
, cu
);
13947 /* GCC might emit a nameless struct or union that has a linkage
13948 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13949 if (part_die
->name
== NULL
13950 && (part_die
->tag
== DW_TAG_class_type
13951 || part_die
->tag
== DW_TAG_interface_type
13952 || part_die
->tag
== DW_TAG_structure_type
13953 || part_die
->tag
== DW_TAG_union_type
)
13954 && part_die
->linkage_name
!= NULL
)
13958 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
13963 /* Strip any leading namespaces/classes, keep only the base name.
13964 DW_AT_name for named DIEs does not contain the prefixes. */
13965 base
= strrchr (demangled
, ':');
13966 if (base
&& base
> demangled
&& base
[-1] == ':')
13971 part_die
->name
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
13972 base
, strlen (base
));
13977 part_die
->fixup_called
= 1;
13980 /* Read an attribute value described by an attribute form. */
13983 read_attribute_value (const struct die_reader_specs
*reader
,
13984 struct attribute
*attr
, unsigned form
,
13985 gdb_byte
*info_ptr
)
13987 struct dwarf2_cu
*cu
= reader
->cu
;
13988 bfd
*abfd
= reader
->abfd
;
13989 struct comp_unit_head
*cu_header
= &cu
->header
;
13990 unsigned int bytes_read
;
13991 struct dwarf_block
*blk
;
13996 case DW_FORM_ref_addr
:
13997 if (cu
->header
.version
== 2)
13998 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14000 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
14001 &cu
->header
, &bytes_read
);
14002 info_ptr
+= bytes_read
;
14004 case DW_FORM_GNU_ref_alt
:
14005 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14006 info_ptr
+= bytes_read
;
14009 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
14010 info_ptr
+= bytes_read
;
14012 case DW_FORM_block2
:
14013 blk
= dwarf_alloc_block (cu
);
14014 blk
->size
= read_2_bytes (abfd
, info_ptr
);
14016 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14017 info_ptr
+= blk
->size
;
14018 DW_BLOCK (attr
) = blk
;
14020 case DW_FORM_block4
:
14021 blk
= dwarf_alloc_block (cu
);
14022 blk
->size
= read_4_bytes (abfd
, info_ptr
);
14024 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14025 info_ptr
+= blk
->size
;
14026 DW_BLOCK (attr
) = blk
;
14028 case DW_FORM_data2
:
14029 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
14032 case DW_FORM_data4
:
14033 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
14036 case DW_FORM_data8
:
14037 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
14040 case DW_FORM_sec_offset
:
14041 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
14042 info_ptr
+= bytes_read
;
14044 case DW_FORM_string
:
14045 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
14046 DW_STRING_IS_CANONICAL (attr
) = 0;
14047 info_ptr
+= bytes_read
;
14050 if (!cu
->per_cu
->is_dwz
)
14052 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
14054 DW_STRING_IS_CANONICAL (attr
) = 0;
14055 info_ptr
+= bytes_read
;
14059 case DW_FORM_GNU_strp_alt
:
14061 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14062 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
14065 DW_STRING (attr
) = read_indirect_string_from_dwz (dwz
, str_offset
);
14066 DW_STRING_IS_CANONICAL (attr
) = 0;
14067 info_ptr
+= bytes_read
;
14070 case DW_FORM_exprloc
:
14071 case DW_FORM_block
:
14072 blk
= dwarf_alloc_block (cu
);
14073 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14074 info_ptr
+= bytes_read
;
14075 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14076 info_ptr
+= blk
->size
;
14077 DW_BLOCK (attr
) = blk
;
14079 case DW_FORM_block1
:
14080 blk
= dwarf_alloc_block (cu
);
14081 blk
->size
= read_1_byte (abfd
, info_ptr
);
14083 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
14084 info_ptr
+= blk
->size
;
14085 DW_BLOCK (attr
) = blk
;
14087 case DW_FORM_data1
:
14088 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14092 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
14095 case DW_FORM_flag_present
:
14096 DW_UNSND (attr
) = 1;
14098 case DW_FORM_sdata
:
14099 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
14100 info_ptr
+= bytes_read
;
14102 case DW_FORM_udata
:
14103 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14104 info_ptr
+= bytes_read
;
14107 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14108 + read_1_byte (abfd
, info_ptr
));
14112 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14113 + read_2_bytes (abfd
, info_ptr
));
14117 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14118 + read_4_bytes (abfd
, info_ptr
));
14122 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14123 + read_8_bytes (abfd
, info_ptr
));
14126 case DW_FORM_ref_sig8
:
14127 /* Convert the signature to something we can record in DW_UNSND
14129 NOTE: This is NULL if the type wasn't found. */
14130 DW_SIGNATURED_TYPE (attr
) =
14131 lookup_signatured_type (read_8_bytes (abfd
, info_ptr
));
14134 case DW_FORM_ref_udata
:
14135 DW_UNSND (attr
) = (cu
->header
.offset
.sect_off
14136 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
14137 info_ptr
+= bytes_read
;
14139 case DW_FORM_indirect
:
14140 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14141 info_ptr
+= bytes_read
;
14142 info_ptr
= read_attribute_value (reader
, attr
, form
, info_ptr
);
14144 case DW_FORM_GNU_addr_index
:
14145 if (reader
->dwo_file
== NULL
)
14147 /* For now flag a hard error.
14148 Later we can turn this into a complaint. */
14149 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14150 dwarf_form_name (form
),
14151 bfd_get_filename (abfd
));
14153 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
14154 info_ptr
+= bytes_read
;
14156 case DW_FORM_GNU_str_index
:
14157 if (reader
->dwo_file
== NULL
)
14159 /* For now flag a hard error.
14160 Later we can turn this into a complaint if warranted. */
14161 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14162 dwarf_form_name (form
),
14163 bfd_get_filename (abfd
));
14166 ULONGEST str_index
=
14167 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
14169 DW_STRING (attr
) = read_str_index (reader
, cu
, str_index
);
14170 DW_STRING_IS_CANONICAL (attr
) = 0;
14171 info_ptr
+= bytes_read
;
14175 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14176 dwarf_form_name (form
),
14177 bfd_get_filename (abfd
));
14181 if (cu
->per_cu
->is_dwz
&& is_ref_attr (attr
))
14182 attr
->form
= DW_FORM_GNU_ref_alt
;
14184 /* We have seen instances where the compiler tried to emit a byte
14185 size attribute of -1 which ended up being encoded as an unsigned
14186 0xffffffff. Although 0xffffffff is technically a valid size value,
14187 an object of this size seems pretty unlikely so we can relatively
14188 safely treat these cases as if the size attribute was invalid and
14189 treat them as zero by default. */
14190 if (attr
->name
== DW_AT_byte_size
14191 && form
== DW_FORM_data4
14192 && DW_UNSND (attr
) >= 0xffffffff)
14195 (&symfile_complaints
,
14196 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14197 hex_string (DW_UNSND (attr
)));
14198 DW_UNSND (attr
) = 0;
14204 /* Read an attribute described by an abbreviated attribute. */
14207 read_attribute (const struct die_reader_specs
*reader
,
14208 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
14209 gdb_byte
*info_ptr
)
14211 attr
->name
= abbrev
->name
;
14212 return read_attribute_value (reader
, attr
, abbrev
->form
, info_ptr
);
14215 /* Read dwarf information from a buffer. */
14217 static unsigned int
14218 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
14220 return bfd_get_8 (abfd
, buf
);
14224 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
14226 return bfd_get_signed_8 (abfd
, buf
);
14229 static unsigned int
14230 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14232 return bfd_get_16 (abfd
, buf
);
14236 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14238 return bfd_get_signed_16 (abfd
, buf
);
14241 static unsigned int
14242 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14244 return bfd_get_32 (abfd
, buf
);
14248 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14250 return bfd_get_signed_32 (abfd
, buf
);
14254 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
14256 return bfd_get_64 (abfd
, buf
);
14260 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
14261 unsigned int *bytes_read
)
14263 struct comp_unit_head
*cu_header
= &cu
->header
;
14264 CORE_ADDR retval
= 0;
14266 if (cu_header
->signed_addr_p
)
14268 switch (cu_header
->addr_size
)
14271 retval
= bfd_get_signed_16 (abfd
, buf
);
14274 retval
= bfd_get_signed_32 (abfd
, buf
);
14277 retval
= bfd_get_signed_64 (abfd
, buf
);
14280 internal_error (__FILE__
, __LINE__
,
14281 _("read_address: bad switch, signed [in module %s]"),
14282 bfd_get_filename (abfd
));
14287 switch (cu_header
->addr_size
)
14290 retval
= bfd_get_16 (abfd
, buf
);
14293 retval
= bfd_get_32 (abfd
, buf
);
14296 retval
= bfd_get_64 (abfd
, buf
);
14299 internal_error (__FILE__
, __LINE__
,
14300 _("read_address: bad switch, "
14301 "unsigned [in module %s]"),
14302 bfd_get_filename (abfd
));
14306 *bytes_read
= cu_header
->addr_size
;
14310 /* Read the initial length from a section. The (draft) DWARF 3
14311 specification allows the initial length to take up either 4 bytes
14312 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14313 bytes describe the length and all offsets will be 8 bytes in length
14316 An older, non-standard 64-bit format is also handled by this
14317 function. The older format in question stores the initial length
14318 as an 8-byte quantity without an escape value. Lengths greater
14319 than 2^32 aren't very common which means that the initial 4 bytes
14320 is almost always zero. Since a length value of zero doesn't make
14321 sense for the 32-bit format, this initial zero can be considered to
14322 be an escape value which indicates the presence of the older 64-bit
14323 format. As written, the code can't detect (old format) lengths
14324 greater than 4GB. If it becomes necessary to handle lengths
14325 somewhat larger than 4GB, we could allow other small values (such
14326 as the non-sensical values of 1, 2, and 3) to also be used as
14327 escape values indicating the presence of the old format.
14329 The value returned via bytes_read should be used to increment the
14330 relevant pointer after calling read_initial_length().
14332 [ Note: read_initial_length() and read_offset() are based on the
14333 document entitled "DWARF Debugging Information Format", revision
14334 3, draft 8, dated November 19, 2001. This document was obtained
14337 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14339 This document is only a draft and is subject to change. (So beware.)
14341 Details regarding the older, non-standard 64-bit format were
14342 determined empirically by examining 64-bit ELF files produced by
14343 the SGI toolchain on an IRIX 6.5 machine.
14345 - Kevin, July 16, 2002
14349 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
14351 LONGEST length
= bfd_get_32 (abfd
, buf
);
14353 if (length
== 0xffffffff)
14355 length
= bfd_get_64 (abfd
, buf
+ 4);
14358 else if (length
== 0)
14360 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14361 length
= bfd_get_64 (abfd
, buf
);
14372 /* Cover function for read_initial_length.
14373 Returns the length of the object at BUF, and stores the size of the
14374 initial length in *BYTES_READ and stores the size that offsets will be in
14376 If the initial length size is not equivalent to that specified in
14377 CU_HEADER then issue a complaint.
14378 This is useful when reading non-comp-unit headers. */
14381 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
14382 const struct comp_unit_head
*cu_header
,
14383 unsigned int *bytes_read
,
14384 unsigned int *offset_size
)
14386 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
14388 gdb_assert (cu_header
->initial_length_size
== 4
14389 || cu_header
->initial_length_size
== 8
14390 || cu_header
->initial_length_size
== 12);
14392 if (cu_header
->initial_length_size
!= *bytes_read
)
14393 complaint (&symfile_complaints
,
14394 _("intermixed 32-bit and 64-bit DWARF sections"));
14396 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
14400 /* Read an offset from the data stream. The size of the offset is
14401 given by cu_header->offset_size. */
14404 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
14405 unsigned int *bytes_read
)
14407 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
14409 *bytes_read
= cu_header
->offset_size
;
14413 /* Read an offset from the data stream. */
14416 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
14418 LONGEST retval
= 0;
14420 switch (offset_size
)
14423 retval
= bfd_get_32 (abfd
, buf
);
14426 retval
= bfd_get_64 (abfd
, buf
);
14429 internal_error (__FILE__
, __LINE__
,
14430 _("read_offset_1: bad switch [in module %s]"),
14431 bfd_get_filename (abfd
));
14438 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
14440 /* If the size of a host char is 8 bits, we can return a pointer
14441 to the buffer, otherwise we have to copy the data to a buffer
14442 allocated on the temporary obstack. */
14443 gdb_assert (HOST_CHAR_BIT
== 8);
14448 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14450 /* If the size of a host char is 8 bits, we can return a pointer
14451 to the string, otherwise we have to copy the string to a buffer
14452 allocated on the temporary obstack. */
14453 gdb_assert (HOST_CHAR_BIT
== 8);
14456 *bytes_read_ptr
= 1;
14459 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
14460 return (char *) buf
;
14464 read_indirect_string_at_offset (bfd
*abfd
, LONGEST str_offset
)
14466 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
14467 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
14468 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14469 bfd_get_filename (abfd
));
14470 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
14471 error (_("DW_FORM_strp pointing outside of "
14472 ".debug_str section [in module %s]"),
14473 bfd_get_filename (abfd
));
14474 gdb_assert (HOST_CHAR_BIT
== 8);
14475 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
14477 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
14480 /* Read a string at offset STR_OFFSET in the .debug_str section from
14481 the .dwz file DWZ. Throw an error if the offset is too large. If
14482 the string consists of a single NUL byte, return NULL; otherwise
14483 return a pointer to the string. */
14486 read_indirect_string_from_dwz (struct dwz_file
*dwz
, LONGEST str_offset
)
14488 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwz
->str
);
14490 if (dwz
->str
.buffer
== NULL
)
14491 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14492 "section [in module %s]"),
14493 bfd_get_filename (dwz
->dwz_bfd
));
14494 if (str_offset
>= dwz
->str
.size
)
14495 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14496 ".debug_str section [in module %s]"),
14497 bfd_get_filename (dwz
->dwz_bfd
));
14498 gdb_assert (HOST_CHAR_BIT
== 8);
14499 if (dwz
->str
.buffer
[str_offset
] == '\0')
14501 return (char *) (dwz
->str
.buffer
+ str_offset
);
14505 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
14506 const struct comp_unit_head
*cu_header
,
14507 unsigned int *bytes_read_ptr
)
14509 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
14511 return read_indirect_string_at_offset (abfd
, str_offset
);
14515 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14518 unsigned int num_read
;
14520 unsigned char byte
;
14528 byte
= bfd_get_8 (abfd
, buf
);
14531 result
|= ((ULONGEST
) (byte
& 127) << shift
);
14532 if ((byte
& 128) == 0)
14538 *bytes_read_ptr
= num_read
;
14543 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
14546 int i
, shift
, num_read
;
14547 unsigned char byte
;
14555 byte
= bfd_get_8 (abfd
, buf
);
14558 result
|= ((LONGEST
) (byte
& 127) << shift
);
14560 if ((byte
& 128) == 0)
14565 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
14566 result
|= -(((LONGEST
) 1) << shift
);
14567 *bytes_read_ptr
= num_read
;
14571 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14572 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14573 ADDR_SIZE is the size of addresses from the CU header. */
14576 read_addr_index_1 (unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
14578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14579 bfd
*abfd
= objfile
->obfd
;
14580 const gdb_byte
*info_ptr
;
14582 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
14583 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
14584 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14586 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
14587 error (_("DW_FORM_addr_index pointing outside of "
14588 ".debug_addr section [in module %s]"),
14590 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
14591 + addr_base
+ addr_index
* addr_size
);
14592 if (addr_size
== 4)
14593 return bfd_get_32 (abfd
, info_ptr
);
14595 return bfd_get_64 (abfd
, info_ptr
);
14598 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14601 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
14603 return read_addr_index_1 (addr_index
, cu
->addr_base
, cu
->header
.addr_size
);
14606 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14609 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, gdb_byte
*info_ptr
,
14610 unsigned int *bytes_read
)
14612 bfd
*abfd
= cu
->objfile
->obfd
;
14613 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
14615 return read_addr_index (cu
, addr_index
);
14618 /* Data structure to pass results from dwarf2_read_addr_index_reader
14619 back to dwarf2_read_addr_index. */
14621 struct dwarf2_read_addr_index_data
14623 ULONGEST addr_base
;
14627 /* die_reader_func for dwarf2_read_addr_index. */
14630 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
14631 gdb_byte
*info_ptr
,
14632 struct die_info
*comp_unit_die
,
14636 struct dwarf2_cu
*cu
= reader
->cu
;
14637 struct dwarf2_read_addr_index_data
*aidata
=
14638 (struct dwarf2_read_addr_index_data
*) data
;
14640 aidata
->addr_base
= cu
->addr_base
;
14641 aidata
->addr_size
= cu
->header
.addr_size
;
14644 /* Given an index in .debug_addr, fetch the value.
14645 NOTE: This can be called during dwarf expression evaluation,
14646 long after the debug information has been read, and thus per_cu->cu
14647 may no longer exist. */
14650 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
14651 unsigned int addr_index
)
14653 struct objfile
*objfile
= per_cu
->objfile
;
14654 struct dwarf2_cu
*cu
= per_cu
->cu
;
14655 ULONGEST addr_base
;
14658 /* This is intended to be called from outside this file. */
14659 dw2_setup (objfile
);
14661 /* We need addr_base and addr_size.
14662 If we don't have PER_CU->cu, we have to get it.
14663 Nasty, but the alternative is storing the needed info in PER_CU,
14664 which at this point doesn't seem justified: it's not clear how frequently
14665 it would get used and it would increase the size of every PER_CU.
14666 Entry points like dwarf2_per_cu_addr_size do a similar thing
14667 so we're not in uncharted territory here.
14668 Alas we need to be a bit more complicated as addr_base is contained
14671 We don't need to read the entire CU(/TU).
14672 We just need the header and top level die.
14674 IWBN to use the aging mechanism to let us lazily later discard the CU.
14675 For now we skip this optimization. */
14679 addr_base
= cu
->addr_base
;
14680 addr_size
= cu
->header
.addr_size
;
14684 struct dwarf2_read_addr_index_data aidata
;
14686 /* Note: We can't use init_cutu_and_read_dies_simple here,
14687 we need addr_base. */
14688 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
14689 dwarf2_read_addr_index_reader
, &aidata
);
14690 addr_base
= aidata
.addr_base
;
14691 addr_size
= aidata
.addr_size
;
14694 return read_addr_index_1 (addr_index
, addr_base
, addr_size
);
14697 /* Given a DW_AT_str_index, fetch the string. */
14700 read_str_index (const struct die_reader_specs
*reader
,
14701 struct dwarf2_cu
*cu
, ULONGEST str_index
)
14703 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14704 const char *dwo_name
= objfile
->name
;
14705 bfd
*abfd
= objfile
->obfd
;
14706 struct dwo_sections
*sections
= &reader
->dwo_file
->sections
;
14707 gdb_byte
*info_ptr
;
14708 ULONGEST str_offset
;
14710 dwarf2_read_section (objfile
, §ions
->str
);
14711 dwarf2_read_section (objfile
, §ions
->str_offsets
);
14712 if (sections
->str
.buffer
== NULL
)
14713 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14714 " in CU at offset 0x%lx [in module %s]"),
14715 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14716 if (sections
->str_offsets
.buffer
== NULL
)
14717 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14718 " in CU at offset 0x%lx [in module %s]"),
14719 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14720 if (str_index
* cu
->header
.offset_size
>= sections
->str_offsets
.size
)
14721 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14722 " section in CU at offset 0x%lx [in module %s]"),
14723 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14724 info_ptr
= (sections
->str_offsets
.buffer
14725 + str_index
* cu
->header
.offset_size
);
14726 if (cu
->header
.offset_size
== 4)
14727 str_offset
= bfd_get_32 (abfd
, info_ptr
);
14729 str_offset
= bfd_get_64 (abfd
, info_ptr
);
14730 if (str_offset
>= sections
->str
.size
)
14731 error (_("Offset from DW_FORM_str_index pointing outside of"
14732 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14733 (long) cu
->header
.offset
.sect_off
, dwo_name
);
14734 return (char *) (sections
->str
.buffer
+ str_offset
);
14737 /* Return the length of an LEB128 number in BUF. */
14740 leb128_size (const gdb_byte
*buf
)
14742 const gdb_byte
*begin
= buf
;
14748 if ((byte
& 128) == 0)
14749 return buf
- begin
;
14754 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
14761 cu
->language
= language_c
;
14763 case DW_LANG_C_plus_plus
:
14764 cu
->language
= language_cplus
;
14767 cu
->language
= language_d
;
14769 case DW_LANG_Fortran77
:
14770 case DW_LANG_Fortran90
:
14771 case DW_LANG_Fortran95
:
14772 cu
->language
= language_fortran
;
14775 cu
->language
= language_go
;
14777 case DW_LANG_Mips_Assembler
:
14778 cu
->language
= language_asm
;
14781 cu
->language
= language_java
;
14783 case DW_LANG_Ada83
:
14784 case DW_LANG_Ada95
:
14785 cu
->language
= language_ada
;
14787 case DW_LANG_Modula2
:
14788 cu
->language
= language_m2
;
14790 case DW_LANG_Pascal83
:
14791 cu
->language
= language_pascal
;
14794 cu
->language
= language_objc
;
14796 case DW_LANG_Cobol74
:
14797 case DW_LANG_Cobol85
:
14799 cu
->language
= language_minimal
;
14802 cu
->language_defn
= language_def (cu
->language
);
14805 /* Return the named attribute or NULL if not there. */
14807 static struct attribute
*
14808 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
14813 struct attribute
*spec
= NULL
;
14815 for (i
= 0; i
< die
->num_attrs
; ++i
)
14817 if (die
->attrs
[i
].name
== name
)
14818 return &die
->attrs
[i
];
14819 if (die
->attrs
[i
].name
== DW_AT_specification
14820 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
14821 spec
= &die
->attrs
[i
];
14827 die
= follow_die_ref (die
, spec
, &cu
);
14833 /* Return the named attribute or NULL if not there,
14834 but do not follow DW_AT_specification, etc.
14835 This is for use in contexts where we're reading .debug_types dies.
14836 Following DW_AT_specification, DW_AT_abstract_origin will take us
14837 back up the chain, and we want to go down. */
14839 static struct attribute
*
14840 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
14844 for (i
= 0; i
< die
->num_attrs
; ++i
)
14845 if (die
->attrs
[i
].name
== name
)
14846 return &die
->attrs
[i
];
14851 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14852 and holds a non-zero value. This function should only be used for
14853 DW_FORM_flag or DW_FORM_flag_present attributes. */
14856 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
14858 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
14860 return (attr
&& DW_UNSND (attr
));
14864 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
14866 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14867 which value is non-zero. However, we have to be careful with
14868 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14869 (via dwarf2_flag_true_p) follows this attribute. So we may
14870 end up accidently finding a declaration attribute that belongs
14871 to a different DIE referenced by the specification attribute,
14872 even though the given DIE does not have a declaration attribute. */
14873 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
14874 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
14877 /* Return the die giving the specification for DIE, if there is
14878 one. *SPEC_CU is the CU containing DIE on input, and the CU
14879 containing the return value on output. If there is no
14880 specification, but there is an abstract origin, that is
14883 static struct die_info
*
14884 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
14886 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
14889 if (spec_attr
== NULL
)
14890 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
14892 if (spec_attr
== NULL
)
14895 return follow_die_ref (die
, spec_attr
, spec_cu
);
14898 /* Free the line_header structure *LH, and any arrays and strings it
14900 NOTE: This is also used as a "cleanup" function. */
14903 free_line_header (struct line_header
*lh
)
14905 if (lh
->standard_opcode_lengths
)
14906 xfree (lh
->standard_opcode_lengths
);
14908 /* Remember that all the lh->file_names[i].name pointers are
14909 pointers into debug_line_buffer, and don't need to be freed. */
14910 if (lh
->file_names
)
14911 xfree (lh
->file_names
);
14913 /* Similarly for the include directory names. */
14914 if (lh
->include_dirs
)
14915 xfree (lh
->include_dirs
);
14920 /* Add an entry to LH's include directory table. */
14923 add_include_dir (struct line_header
*lh
, char *include_dir
)
14925 /* Grow the array if necessary. */
14926 if (lh
->include_dirs_size
== 0)
14928 lh
->include_dirs_size
= 1; /* for testing */
14929 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
14930 * sizeof (*lh
->include_dirs
));
14932 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
14934 lh
->include_dirs_size
*= 2;
14935 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
14936 (lh
->include_dirs_size
14937 * sizeof (*lh
->include_dirs
)));
14940 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
14943 /* Add an entry to LH's file name table. */
14946 add_file_name (struct line_header
*lh
,
14948 unsigned int dir_index
,
14949 unsigned int mod_time
,
14950 unsigned int length
)
14952 struct file_entry
*fe
;
14954 /* Grow the array if necessary. */
14955 if (lh
->file_names_size
== 0)
14957 lh
->file_names_size
= 1; /* for testing */
14958 lh
->file_names
= xmalloc (lh
->file_names_size
14959 * sizeof (*lh
->file_names
));
14961 else if (lh
->num_file_names
>= lh
->file_names_size
)
14963 lh
->file_names_size
*= 2;
14964 lh
->file_names
= xrealloc (lh
->file_names
,
14965 (lh
->file_names_size
14966 * sizeof (*lh
->file_names
)));
14969 fe
= &lh
->file_names
[lh
->num_file_names
++];
14971 fe
->dir_index
= dir_index
;
14972 fe
->mod_time
= mod_time
;
14973 fe
->length
= length
;
14974 fe
->included_p
= 0;
14978 /* A convenience function to find the proper .debug_line section for a
14981 static struct dwarf2_section_info
*
14982 get_debug_line_section (struct dwarf2_cu
*cu
)
14984 struct dwarf2_section_info
*section
;
14986 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14988 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
14989 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
14990 else if (cu
->per_cu
->is_dwz
)
14992 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
14994 section
= &dwz
->line
;
14997 section
= &dwarf2_per_objfile
->line
;
15002 /* Read the statement program header starting at OFFSET in
15003 .debug_line, or .debug_line.dwo. Return a pointer
15004 to a struct line_header, allocated using xmalloc.
15006 NOTE: the strings in the include directory and file name tables of
15007 the returned object point into the dwarf line section buffer,
15008 and must not be freed. */
15010 static struct line_header
*
15011 dwarf_decode_line_header (unsigned int offset
, struct dwarf2_cu
*cu
)
15013 struct cleanup
*back_to
;
15014 struct line_header
*lh
;
15015 gdb_byte
*line_ptr
;
15016 unsigned int bytes_read
, offset_size
;
15018 char *cur_dir
, *cur_file
;
15019 struct dwarf2_section_info
*section
;
15022 section
= get_debug_line_section (cu
);
15023 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
15024 if (section
->buffer
== NULL
)
15026 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
15027 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
15029 complaint (&symfile_complaints
, _("missing .debug_line section"));
15033 /* We can't do this until we know the section is non-empty.
15034 Only then do we know we have such a section. */
15035 abfd
= section
->asection
->owner
;
15037 /* Make sure that at least there's room for the total_length field.
15038 That could be 12 bytes long, but we're just going to fudge that. */
15039 if (offset
+ 4 >= section
->size
)
15041 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15045 lh
= xmalloc (sizeof (*lh
));
15046 memset (lh
, 0, sizeof (*lh
));
15047 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
15050 line_ptr
= section
->buffer
+ offset
;
15052 /* Read in the header. */
15054 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
15055 &bytes_read
, &offset_size
);
15056 line_ptr
+= bytes_read
;
15057 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
15059 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15062 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
15063 lh
->version
= read_2_bytes (abfd
, line_ptr
);
15065 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
15066 line_ptr
+= offset_size
;
15067 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
15069 if (lh
->version
>= 4)
15071 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
15075 lh
->maximum_ops_per_instruction
= 1;
15077 if (lh
->maximum_ops_per_instruction
== 0)
15079 lh
->maximum_ops_per_instruction
= 1;
15080 complaint (&symfile_complaints
,
15081 _("invalid maximum_ops_per_instruction "
15082 "in `.debug_line' section"));
15085 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
15087 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
15089 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
15091 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
15093 lh
->standard_opcode_lengths
15094 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
15096 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
15097 for (i
= 1; i
< lh
->opcode_base
; ++i
)
15099 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
15103 /* Read directory table. */
15104 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15106 line_ptr
+= bytes_read
;
15107 add_include_dir (lh
, cur_dir
);
15109 line_ptr
+= bytes_read
;
15111 /* Read file name table. */
15112 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
15114 unsigned int dir_index
, mod_time
, length
;
15116 line_ptr
+= bytes_read
;
15117 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15118 line_ptr
+= bytes_read
;
15119 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15120 line_ptr
+= bytes_read
;
15121 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15122 line_ptr
+= bytes_read
;
15124 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15126 line_ptr
+= bytes_read
;
15127 lh
->statement_program_start
= line_ptr
;
15129 if (line_ptr
> (section
->buffer
+ section
->size
))
15130 complaint (&symfile_complaints
,
15131 _("line number info header doesn't "
15132 "fit in `.debug_line' section"));
15134 discard_cleanups (back_to
);
15138 /* Subroutine of dwarf_decode_lines to simplify it.
15139 Return the file name of the psymtab for included file FILE_INDEX
15140 in line header LH of PST.
15141 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15142 If space for the result is malloc'd, it will be freed by a cleanup.
15143 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
15145 The function creates dangling cleanup registration. */
15148 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
15149 const struct partial_symtab
*pst
,
15150 const char *comp_dir
)
15152 const struct file_entry fe
= lh
->file_names
[file_index
];
15153 char *include_name
= fe
.name
;
15154 char *include_name_to_compare
= include_name
;
15155 char *dir_name
= NULL
;
15156 const char *pst_filename
;
15157 char *copied_name
= NULL
;
15161 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
15163 if (!IS_ABSOLUTE_PATH (include_name
)
15164 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
15166 /* Avoid creating a duplicate psymtab for PST.
15167 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15168 Before we do the comparison, however, we need to account
15169 for DIR_NAME and COMP_DIR.
15170 First prepend dir_name (if non-NULL). If we still don't
15171 have an absolute path prepend comp_dir (if non-NULL).
15172 However, the directory we record in the include-file's
15173 psymtab does not contain COMP_DIR (to match the
15174 corresponding symtab(s)).
15179 bash$ gcc -g ./hello.c
15180 include_name = "hello.c"
15182 DW_AT_comp_dir = comp_dir = "/tmp"
15183 DW_AT_name = "./hello.c" */
15185 if (dir_name
!= NULL
)
15187 include_name
= concat (dir_name
, SLASH_STRING
,
15188 include_name
, (char *)NULL
);
15189 include_name_to_compare
= include_name
;
15190 make_cleanup (xfree
, include_name
);
15192 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
15194 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
15195 include_name
, (char *)NULL
);
15199 pst_filename
= pst
->filename
;
15200 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
15202 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
15203 pst_filename
, (char *)NULL
);
15204 pst_filename
= copied_name
;
15207 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
15209 if (include_name_to_compare
!= include_name
)
15210 xfree (include_name_to_compare
);
15211 if (copied_name
!= NULL
)
15212 xfree (copied_name
);
15216 return include_name
;
15219 /* Ignore this record_line request. */
15222 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15227 /* Subroutine of dwarf_decode_lines to simplify it.
15228 Process the line number information in LH. */
15231 dwarf_decode_lines_1 (struct line_header
*lh
, const char *comp_dir
,
15232 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
15234 gdb_byte
*line_ptr
, *extended_end
;
15235 gdb_byte
*line_end
;
15236 unsigned int bytes_read
, extended_len
;
15237 unsigned char op_code
, extended_op
, adj_opcode
;
15238 CORE_ADDR baseaddr
;
15239 struct objfile
*objfile
= cu
->objfile
;
15240 bfd
*abfd
= objfile
->obfd
;
15241 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15242 const int decode_for_pst_p
= (pst
!= NULL
);
15243 struct subfile
*last_subfile
= NULL
;
15244 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
15247 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15249 line_ptr
= lh
->statement_program_start
;
15250 line_end
= lh
->statement_program_end
;
15252 /* Read the statement sequences until there's nothing left. */
15253 while (line_ptr
< line_end
)
15255 /* state machine registers */
15256 CORE_ADDR address
= 0;
15257 unsigned int file
= 1;
15258 unsigned int line
= 1;
15259 unsigned int column
= 0;
15260 int is_stmt
= lh
->default_is_stmt
;
15261 int basic_block
= 0;
15262 int end_sequence
= 0;
15264 unsigned char op_index
= 0;
15266 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
15268 /* Start a subfile for the current file of the state machine. */
15269 /* lh->include_dirs and lh->file_names are 0-based, but the
15270 directory and file name numbers in the statement program
15272 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
15276 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15278 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15281 /* Decode the table. */
15282 while (!end_sequence
)
15284 op_code
= read_1_byte (abfd
, line_ptr
);
15286 if (line_ptr
> line_end
)
15288 dwarf2_debug_line_missing_end_sequence_complaint ();
15292 if (op_code
>= lh
->opcode_base
)
15294 /* Special operand. */
15295 adj_opcode
= op_code
- lh
->opcode_base
;
15296 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
15297 / lh
->maximum_ops_per_instruction
)
15298 * lh
->minimum_instruction_length
);
15299 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
15300 % lh
->maximum_ops_per_instruction
);
15301 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
15302 if (lh
->num_file_names
< file
|| file
== 0)
15303 dwarf2_debug_line_missing_file_complaint ();
15304 /* For now we ignore lines not starting on an
15305 instruction boundary. */
15306 else if (op_index
== 0)
15308 lh
->file_names
[file
- 1].included_p
= 1;
15309 if (!decode_for_pst_p
&& is_stmt
)
15311 if (last_subfile
!= current_subfile
)
15313 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15315 (*p_record_line
) (last_subfile
, 0, addr
);
15316 last_subfile
= current_subfile
;
15318 /* Append row to matrix using current values. */
15319 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15320 (*p_record_line
) (current_subfile
, line
, addr
);
15325 else switch (op_code
)
15327 case DW_LNS_extended_op
:
15328 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
15330 line_ptr
+= bytes_read
;
15331 extended_end
= line_ptr
+ extended_len
;
15332 extended_op
= read_1_byte (abfd
, line_ptr
);
15334 switch (extended_op
)
15336 case DW_LNE_end_sequence
:
15337 p_record_line
= record_line
;
15340 case DW_LNE_set_address
:
15341 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
15343 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15345 /* This line table is for a function which has been
15346 GCd by the linker. Ignore it. PR gdb/12528 */
15349 = line_ptr
- get_debug_line_section (cu
)->buffer
;
15351 complaint (&symfile_complaints
,
15352 _(".debug_line address at offset 0x%lx is 0 "
15354 line_offset
, objfile
->name
);
15355 p_record_line
= noop_record_line
;
15359 line_ptr
+= bytes_read
;
15360 address
+= baseaddr
;
15362 case DW_LNE_define_file
:
15365 unsigned int dir_index
, mod_time
, length
;
15367 cur_file
= read_direct_string (abfd
, line_ptr
,
15369 line_ptr
+= bytes_read
;
15371 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15372 line_ptr
+= bytes_read
;
15374 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15375 line_ptr
+= bytes_read
;
15377 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15378 line_ptr
+= bytes_read
;
15379 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
15382 case DW_LNE_set_discriminator
:
15383 /* The discriminator is not interesting to the debugger;
15385 line_ptr
= extended_end
;
15388 complaint (&symfile_complaints
,
15389 _("mangled .debug_line section"));
15392 /* Make sure that we parsed the extended op correctly. If e.g.
15393 we expected a different address size than the producer used,
15394 we may have read the wrong number of bytes. */
15395 if (line_ptr
!= extended_end
)
15397 complaint (&symfile_complaints
,
15398 _("mangled .debug_line section"));
15403 if (lh
->num_file_names
< file
|| file
== 0)
15404 dwarf2_debug_line_missing_file_complaint ();
15407 lh
->file_names
[file
- 1].included_p
= 1;
15408 if (!decode_for_pst_p
&& is_stmt
)
15410 if (last_subfile
!= current_subfile
)
15412 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15414 (*p_record_line
) (last_subfile
, 0, addr
);
15415 last_subfile
= current_subfile
;
15417 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15418 (*p_record_line
) (current_subfile
, line
, addr
);
15423 case DW_LNS_advance_pc
:
15426 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15428 address
+= (((op_index
+ adjust
)
15429 / lh
->maximum_ops_per_instruction
)
15430 * lh
->minimum_instruction_length
);
15431 op_index
= ((op_index
+ adjust
)
15432 % lh
->maximum_ops_per_instruction
);
15433 line_ptr
+= bytes_read
;
15436 case DW_LNS_advance_line
:
15437 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
15438 line_ptr
+= bytes_read
;
15440 case DW_LNS_set_file
:
15442 /* The arrays lh->include_dirs and lh->file_names are
15443 0-based, but the directory and file name numbers in
15444 the statement program are 1-based. */
15445 struct file_entry
*fe
;
15448 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15449 line_ptr
+= bytes_read
;
15450 if (lh
->num_file_names
< file
|| file
== 0)
15451 dwarf2_debug_line_missing_file_complaint ();
15454 fe
= &lh
->file_names
[file
- 1];
15456 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15457 if (!decode_for_pst_p
)
15459 last_subfile
= current_subfile
;
15460 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15465 case DW_LNS_set_column
:
15466 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15467 line_ptr
+= bytes_read
;
15469 case DW_LNS_negate_stmt
:
15470 is_stmt
= (!is_stmt
);
15472 case DW_LNS_set_basic_block
:
15475 /* Add to the address register of the state machine the
15476 address increment value corresponding to special opcode
15477 255. I.e., this value is scaled by the minimum
15478 instruction length since special opcode 255 would have
15479 scaled the increment. */
15480 case DW_LNS_const_add_pc
:
15482 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
15484 address
+= (((op_index
+ adjust
)
15485 / lh
->maximum_ops_per_instruction
)
15486 * lh
->minimum_instruction_length
);
15487 op_index
= ((op_index
+ adjust
)
15488 % lh
->maximum_ops_per_instruction
);
15491 case DW_LNS_fixed_advance_pc
:
15492 address
+= read_2_bytes (abfd
, line_ptr
);
15498 /* Unknown standard opcode, ignore it. */
15501 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
15503 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
15504 line_ptr
+= bytes_read
;
15509 if (lh
->num_file_names
< file
|| file
== 0)
15510 dwarf2_debug_line_missing_file_complaint ();
15513 lh
->file_names
[file
- 1].included_p
= 1;
15514 if (!decode_for_pst_p
)
15516 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
15517 (*p_record_line
) (current_subfile
, 0, addr
);
15523 /* Decode the Line Number Program (LNP) for the given line_header
15524 structure and CU. The actual information extracted and the type
15525 of structures created from the LNP depends on the value of PST.
15527 1. If PST is NULL, then this procedure uses the data from the program
15528 to create all necessary symbol tables, and their linetables.
15530 2. If PST is not NULL, this procedure reads the program to determine
15531 the list of files included by the unit represented by PST, and
15532 builds all the associated partial symbol tables.
15534 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15535 It is used for relative paths in the line table.
15536 NOTE: When processing partial symtabs (pst != NULL),
15537 comp_dir == pst->dirname.
15539 NOTE: It is important that psymtabs have the same file name (via strcmp)
15540 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15541 symtab we don't use it in the name of the psymtabs we create.
15542 E.g. expand_line_sal requires this when finding psymtabs to expand.
15543 A good testcase for this is mb-inline.exp. */
15546 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
15547 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
15548 int want_line_info
)
15550 struct objfile
*objfile
= cu
->objfile
;
15551 const int decode_for_pst_p
= (pst
!= NULL
);
15552 struct subfile
*first_subfile
= current_subfile
;
15554 if (want_line_info
)
15555 dwarf_decode_lines_1 (lh
, comp_dir
, cu
, pst
);
15557 if (decode_for_pst_p
)
15561 /* Now that we're done scanning the Line Header Program, we can
15562 create the psymtab of each included file. */
15563 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
15564 if (lh
->file_names
[file_index
].included_p
== 1)
15566 char *include_name
=
15567 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
15568 if (include_name
!= NULL
)
15569 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
15574 /* Make sure a symtab is created for every file, even files
15575 which contain only variables (i.e. no code with associated
15579 for (i
= 0; i
< lh
->num_file_names
; i
++)
15582 struct file_entry
*fe
;
15584 fe
= &lh
->file_names
[i
];
15586 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
15587 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
15589 /* Skip the main file; we don't need it, and it must be
15590 allocated last, so that it will show up before the
15591 non-primary symtabs in the objfile's symtab list. */
15592 if (current_subfile
== first_subfile
)
15595 if (current_subfile
->symtab
== NULL
)
15596 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
15598 fe
->symtab
= current_subfile
->symtab
;
15603 /* Start a subfile for DWARF. FILENAME is the name of the file and
15604 DIRNAME the name of the source directory which contains FILENAME
15605 or NULL if not known. COMP_DIR is the compilation directory for the
15606 linetable's compilation unit or NULL if not known.
15607 This routine tries to keep line numbers from identical absolute and
15608 relative file names in a common subfile.
15610 Using the `list' example from the GDB testsuite, which resides in
15611 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15612 of /srcdir/list0.c yields the following debugging information for list0.c:
15614 DW_AT_name: /srcdir/list0.c
15615 DW_AT_comp_dir: /compdir
15616 files.files[0].name: list0.h
15617 files.files[0].dir: /srcdir
15618 files.files[1].name: list0.c
15619 files.files[1].dir: /srcdir
15621 The line number information for list0.c has to end up in a single
15622 subfile, so that `break /srcdir/list0.c:1' works as expected.
15623 start_subfile will ensure that this happens provided that we pass the
15624 concatenation of files.files[1].dir and files.files[1].name as the
15628 dwarf2_start_subfile (char *filename
, const char *dirname
,
15629 const char *comp_dir
)
15633 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15634 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15635 second argument to start_subfile. To be consistent, we do the
15636 same here. In order not to lose the line information directory,
15637 we concatenate it to the filename when it makes sense.
15638 Note that the Dwarf3 standard says (speaking of filenames in line
15639 information): ``The directory index is ignored for file names
15640 that represent full path names''. Thus ignoring dirname in the
15641 `else' branch below isn't an issue. */
15643 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
15644 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
15646 fullname
= filename
;
15648 start_subfile (fullname
, comp_dir
);
15650 if (fullname
!= filename
)
15654 /* Start a symtab for DWARF.
15655 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15658 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
15659 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
15661 start_symtab (name
, comp_dir
, low_pc
);
15662 record_debugformat ("DWARF 2");
15663 record_producer (cu
->producer
);
15665 /* We assume that we're processing GCC output. */
15666 processing_gcc_compilation
= 2;
15668 processing_has_namespace_info
= 0;
15672 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
15673 struct dwarf2_cu
*cu
)
15675 struct objfile
*objfile
= cu
->objfile
;
15676 struct comp_unit_head
*cu_header
= &cu
->header
;
15678 /* NOTE drow/2003-01-30: There used to be a comment and some special
15679 code here to turn a symbol with DW_AT_external and a
15680 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15681 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15682 with some versions of binutils) where shared libraries could have
15683 relocations against symbols in their debug information - the
15684 minimal symbol would have the right address, but the debug info
15685 would not. It's no longer necessary, because we will explicitly
15686 apply relocations when we read in the debug information now. */
15688 /* A DW_AT_location attribute with no contents indicates that a
15689 variable has been optimized away. */
15690 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
15692 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15696 /* Handle one degenerate form of location expression specially, to
15697 preserve GDB's previous behavior when section offsets are
15698 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15699 then mark this symbol as LOC_STATIC. */
15701 if (attr_form_is_block (attr
)
15702 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
15703 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
15704 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
15705 && (DW_BLOCK (attr
)->size
15706 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
15708 unsigned int dummy
;
15710 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
15711 SYMBOL_VALUE_ADDRESS (sym
) =
15712 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
15714 SYMBOL_VALUE_ADDRESS (sym
) =
15715 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
15716 SYMBOL_CLASS (sym
) = LOC_STATIC
;
15717 fixup_symbol_section (sym
, objfile
);
15718 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
15719 SYMBOL_SECTION (sym
));
15723 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15724 expression evaluator, and use LOC_COMPUTED only when necessary
15725 (i.e. when the value of a register or memory location is
15726 referenced, or a thread-local block, etc.). Then again, it might
15727 not be worthwhile. I'm assuming that it isn't unless performance
15728 or memory numbers show me otherwise. */
15730 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
15731 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
15733 if (SYMBOL_COMPUTED_OPS (sym
) == &dwarf2_loclist_funcs
)
15734 cu
->has_loclist
= 1;
15737 /* Given a pointer to a DWARF information entry, figure out if we need
15738 to make a symbol table entry for it, and if so, create a new entry
15739 and return a pointer to it.
15740 If TYPE is NULL, determine symbol type from the die, otherwise
15741 used the passed type.
15742 If SPACE is not NULL, use it to hold the new symbol. If it is
15743 NULL, allocate a new symbol on the objfile's obstack. */
15745 static struct symbol
*
15746 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
15747 struct symbol
*space
)
15749 struct objfile
*objfile
= cu
->objfile
;
15750 struct symbol
*sym
= NULL
;
15752 struct attribute
*attr
= NULL
;
15753 struct attribute
*attr2
= NULL
;
15754 CORE_ADDR baseaddr
;
15755 struct pending
**list_to_add
= NULL
;
15757 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
15759 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15761 name
= dwarf2_name (die
, cu
);
15764 const char *linkagename
;
15765 int suppress_add
= 0;
15770 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
15771 OBJSTAT (objfile
, n_syms
++);
15773 /* Cache this symbol's name and the name's demangled form (if any). */
15774 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
15775 linkagename
= dwarf2_physname (name
, die
, cu
);
15776 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
15778 /* Fortran does not have mangling standard and the mangling does differ
15779 between gfortran, iFort etc. */
15780 if (cu
->language
== language_fortran
15781 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
15782 symbol_set_demangled_name (&(sym
->ginfo
),
15783 dwarf2_full_name (name
, die
, cu
),
15786 /* Default assumptions.
15787 Use the passed type or decode it from the die. */
15788 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
15789 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
15791 SYMBOL_TYPE (sym
) = type
;
15793 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
15794 attr
= dwarf2_attr (die
,
15795 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
15799 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
15802 attr
= dwarf2_attr (die
,
15803 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
15807 int file_index
= DW_UNSND (attr
);
15809 if (cu
->line_header
== NULL
15810 || file_index
> cu
->line_header
->num_file_names
)
15811 complaint (&symfile_complaints
,
15812 _("file index out of range"));
15813 else if (file_index
> 0)
15815 struct file_entry
*fe
;
15817 fe
= &cu
->line_header
->file_names
[file_index
- 1];
15818 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
15825 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15828 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
15830 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
15831 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
15832 SYMBOL_CLASS (sym
) = LOC_LABEL
;
15833 add_symbol_to_list (sym
, cu
->list_in_scope
);
15835 case DW_TAG_subprogram
:
15836 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15838 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15839 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15840 if ((attr2
&& (DW_UNSND (attr2
) != 0))
15841 || cu
->language
== language_ada
)
15843 /* Subprograms marked external are stored as a global symbol.
15844 Ada subprograms, whether marked external or not, are always
15845 stored as a global symbol, because we want to be able to
15846 access them globally. For instance, we want to be able
15847 to break on a nested subprogram without having to
15848 specify the context. */
15849 list_to_add
= &global_symbols
;
15853 list_to_add
= cu
->list_in_scope
;
15856 case DW_TAG_inlined_subroutine
:
15857 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15859 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
15860 SYMBOL_INLINED (sym
) = 1;
15861 list_to_add
= cu
->list_in_scope
;
15863 case DW_TAG_template_value_param
:
15865 /* Fall through. */
15866 case DW_TAG_constant
:
15867 case DW_TAG_variable
:
15868 case DW_TAG_member
:
15869 /* Compilation with minimal debug info may result in
15870 variables with missing type entries. Change the
15871 misleading `void' type to something sensible. */
15872 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
15874 = objfile_type (objfile
)->nodebug_data_symbol
;
15876 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15877 /* In the case of DW_TAG_member, we should only be called for
15878 static const members. */
15879 if (die
->tag
== DW_TAG_member
)
15881 /* dwarf2_add_field uses die_is_declaration,
15882 so we do the same. */
15883 gdb_assert (die_is_declaration (die
, cu
));
15888 dwarf2_const_value (attr
, sym
, cu
);
15889 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15892 if (attr2
&& (DW_UNSND (attr2
) != 0))
15893 list_to_add
= &global_symbols
;
15895 list_to_add
= cu
->list_in_scope
;
15899 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15902 var_decode_location (attr
, sym
, cu
);
15903 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15905 /* Fortran explicitly imports any global symbols to the local
15906 scope by DW_TAG_common_block. */
15907 if (cu
->language
== language_fortran
&& die
->parent
15908 && die
->parent
->tag
== DW_TAG_common_block
)
15911 if (SYMBOL_CLASS (sym
) == LOC_STATIC
15912 && SYMBOL_VALUE_ADDRESS (sym
) == 0
15913 && !dwarf2_per_objfile
->has_section_at_zero
)
15915 /* When a static variable is eliminated by the linker,
15916 the corresponding debug information is not stripped
15917 out, but the variable address is set to null;
15918 do not add such variables into symbol table. */
15920 else if (attr2
&& (DW_UNSND (attr2
) != 0))
15922 /* Workaround gfortran PR debug/40040 - it uses
15923 DW_AT_location for variables in -fPIC libraries which may
15924 get overriden by other libraries/executable and get
15925 a different address. Resolve it by the minimal symbol
15926 which may come from inferior's executable using copy
15927 relocation. Make this workaround only for gfortran as for
15928 other compilers GDB cannot guess the minimal symbol
15929 Fortran mangling kind. */
15930 if (cu
->language
== language_fortran
&& die
->parent
15931 && die
->parent
->tag
== DW_TAG_module
15933 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
15934 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15936 /* A variable with DW_AT_external is never static,
15937 but it may be block-scoped. */
15938 list_to_add
= (cu
->list_in_scope
== &file_symbols
15939 ? &global_symbols
: cu
->list_in_scope
);
15942 list_to_add
= cu
->list_in_scope
;
15946 /* We do not know the address of this symbol.
15947 If it is an external symbol and we have type information
15948 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15949 The address of the variable will then be determined from
15950 the minimal symbol table whenever the variable is
15952 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
15954 /* Fortran explicitly imports any global symbols to the local
15955 scope by DW_TAG_common_block. */
15956 if (cu
->language
== language_fortran
&& die
->parent
15957 && die
->parent
->tag
== DW_TAG_common_block
)
15959 /* SYMBOL_CLASS doesn't matter here because
15960 read_common_block is going to reset it. */
15962 list_to_add
= cu
->list_in_scope
;
15964 else if (attr2
&& (DW_UNSND (attr2
) != 0)
15965 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
15967 /* A variable with DW_AT_external is never static, but it
15968 may be block-scoped. */
15969 list_to_add
= (cu
->list_in_scope
== &file_symbols
15970 ? &global_symbols
: cu
->list_in_scope
);
15972 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
15974 else if (!die_is_declaration (die
, cu
))
15976 /* Use the default LOC_OPTIMIZED_OUT class. */
15977 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
15979 list_to_add
= cu
->list_in_scope
;
15983 case DW_TAG_formal_parameter
:
15984 /* If we are inside a function, mark this as an argument. If
15985 not, we might be looking at an argument to an inlined function
15986 when we do not have enough information to show inlined frames;
15987 pretend it's a local variable in that case so that the user can
15989 if (context_stack_depth
> 0
15990 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
15991 SYMBOL_IS_ARGUMENT (sym
) = 1;
15992 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15995 var_decode_location (attr
, sym
, cu
);
15997 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16000 dwarf2_const_value (attr
, sym
, cu
);
16003 list_to_add
= cu
->list_in_scope
;
16005 case DW_TAG_unspecified_parameters
:
16006 /* From varargs functions; gdb doesn't seem to have any
16007 interest in this information, so just ignore it for now.
16010 case DW_TAG_template_type_param
:
16012 /* Fall through. */
16013 case DW_TAG_class_type
:
16014 case DW_TAG_interface_type
:
16015 case DW_TAG_structure_type
:
16016 case DW_TAG_union_type
:
16017 case DW_TAG_set_type
:
16018 case DW_TAG_enumeration_type
:
16019 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16020 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
16023 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
16024 really ever be static objects: otherwise, if you try
16025 to, say, break of a class's method and you're in a file
16026 which doesn't mention that class, it won't work unless
16027 the check for all static symbols in lookup_symbol_aux
16028 saves you. See the OtherFileClass tests in
16029 gdb.c++/namespace.exp. */
16033 list_to_add
= (cu
->list_in_scope
== &file_symbols
16034 && (cu
->language
== language_cplus
16035 || cu
->language
== language_java
)
16036 ? &global_symbols
: cu
->list_in_scope
);
16038 /* The semantics of C++ state that "struct foo {
16039 ... }" also defines a typedef for "foo". A Java
16040 class declaration also defines a typedef for the
16042 if (cu
->language
== language_cplus
16043 || cu
->language
== language_java
16044 || cu
->language
== language_ada
)
16046 /* The symbol's name is already allocated along
16047 with this objfile, so we don't need to
16048 duplicate it for the type. */
16049 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
16050 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
16055 case DW_TAG_typedef
:
16056 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16057 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16058 list_to_add
= cu
->list_in_scope
;
16060 case DW_TAG_base_type
:
16061 case DW_TAG_subrange_type
:
16062 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16063 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
16064 list_to_add
= cu
->list_in_scope
;
16066 case DW_TAG_enumerator
:
16067 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
16070 dwarf2_const_value (attr
, sym
, cu
);
16073 /* NOTE: carlton/2003-11-10: See comment above in the
16074 DW_TAG_class_type, etc. block. */
16076 list_to_add
= (cu
->list_in_scope
== &file_symbols
16077 && (cu
->language
== language_cplus
16078 || cu
->language
== language_java
)
16079 ? &global_symbols
: cu
->list_in_scope
);
16082 case DW_TAG_namespace
:
16083 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
16084 list_to_add
= &global_symbols
;
16086 case DW_TAG_common_block
:
16087 SYMBOL_CLASS (sym
) = LOC_COMMON_BLOCK
;
16088 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
16089 add_symbol_to_list (sym
, cu
->list_in_scope
);
16092 /* Not a tag we recognize. Hopefully we aren't processing
16093 trash data, but since we must specifically ignore things
16094 we don't recognize, there is nothing else we should do at
16096 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
16097 dwarf_tag_name (die
->tag
));
16103 sym
->hash_next
= objfile
->template_symbols
;
16104 objfile
->template_symbols
= sym
;
16105 list_to_add
= NULL
;
16108 if (list_to_add
!= NULL
)
16109 add_symbol_to_list (sym
, list_to_add
);
16111 /* For the benefit of old versions of GCC, check for anonymous
16112 namespaces based on the demangled name. */
16113 if (!processing_has_namespace_info
16114 && cu
->language
== language_cplus
)
16115 cp_scan_for_anonymous_namespaces (sym
, objfile
);
16120 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16122 static struct symbol
*
16123 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
16125 return new_symbol_full (die
, type
, cu
, NULL
);
16128 /* Given an attr with a DW_FORM_dataN value in host byte order,
16129 zero-extend it as appropriate for the symbol's type. The DWARF
16130 standard (v4) is not entirely clear about the meaning of using
16131 DW_FORM_dataN for a constant with a signed type, where the type is
16132 wider than the data. The conclusion of a discussion on the DWARF
16133 list was that this is unspecified. We choose to always zero-extend
16134 because that is the interpretation long in use by GCC. */
16137 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
16138 const char *name
, struct obstack
*obstack
,
16139 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
16141 struct objfile
*objfile
= cu
->objfile
;
16142 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
16143 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
16144 LONGEST l
= DW_UNSND (attr
);
16146 if (bits
< sizeof (*value
) * 8)
16148 l
&= ((LONGEST
) 1 << bits
) - 1;
16151 else if (bits
== sizeof (*value
) * 8)
16155 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
16156 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
16163 /* Read a constant value from an attribute. Either set *VALUE, or if
16164 the value does not fit in *VALUE, set *BYTES - either already
16165 allocated on the objfile obstack, or newly allocated on OBSTACK,
16166 or, set *BATON, if we translated the constant to a location
16170 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
16171 const char *name
, struct obstack
*obstack
,
16172 struct dwarf2_cu
*cu
,
16173 LONGEST
*value
, gdb_byte
**bytes
,
16174 struct dwarf2_locexpr_baton
**baton
)
16176 struct objfile
*objfile
= cu
->objfile
;
16177 struct comp_unit_head
*cu_header
= &cu
->header
;
16178 struct dwarf_block
*blk
;
16179 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
16180 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
16186 switch (attr
->form
)
16189 case DW_FORM_GNU_addr_index
:
16193 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
16194 dwarf2_const_value_length_mismatch_complaint (name
,
16195 cu_header
->addr_size
,
16196 TYPE_LENGTH (type
));
16197 /* Symbols of this form are reasonably rare, so we just
16198 piggyback on the existing location code rather than writing
16199 a new implementation of symbol_computed_ops. */
16200 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
16201 sizeof (struct dwarf2_locexpr_baton
));
16202 (*baton
)->per_cu
= cu
->per_cu
;
16203 gdb_assert ((*baton
)->per_cu
);
16205 (*baton
)->size
= 2 + cu_header
->addr_size
;
16206 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
16207 (*baton
)->data
= data
;
16209 data
[0] = DW_OP_addr
;
16210 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
16211 byte_order
, DW_ADDR (attr
));
16212 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
16215 case DW_FORM_string
:
16217 case DW_FORM_GNU_str_index
:
16218 case DW_FORM_GNU_strp_alt
:
16219 /* DW_STRING is already allocated on the objfile obstack, point
16221 *bytes
= (gdb_byte
*) DW_STRING (attr
);
16223 case DW_FORM_block1
:
16224 case DW_FORM_block2
:
16225 case DW_FORM_block4
:
16226 case DW_FORM_block
:
16227 case DW_FORM_exprloc
:
16228 blk
= DW_BLOCK (attr
);
16229 if (TYPE_LENGTH (type
) != blk
->size
)
16230 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
16231 TYPE_LENGTH (type
));
16232 *bytes
= blk
->data
;
16235 /* The DW_AT_const_value attributes are supposed to carry the
16236 symbol's value "represented as it would be on the target
16237 architecture." By the time we get here, it's already been
16238 converted to host endianness, so we just need to sign- or
16239 zero-extend it as appropriate. */
16240 case DW_FORM_data1
:
16241 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16242 obstack
, cu
, value
, 8);
16244 case DW_FORM_data2
:
16245 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16246 obstack
, cu
, value
, 16);
16248 case DW_FORM_data4
:
16249 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16250 obstack
, cu
, value
, 32);
16252 case DW_FORM_data8
:
16253 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
16254 obstack
, cu
, value
, 64);
16257 case DW_FORM_sdata
:
16258 *value
= DW_SND (attr
);
16261 case DW_FORM_udata
:
16262 *value
= DW_UNSND (attr
);
16266 complaint (&symfile_complaints
,
16267 _("unsupported const value attribute form: '%s'"),
16268 dwarf_form_name (attr
->form
));
16275 /* Copy constant value from an attribute to a symbol. */
16278 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
16279 struct dwarf2_cu
*cu
)
16281 struct objfile
*objfile
= cu
->objfile
;
16282 struct comp_unit_head
*cu_header
= &cu
->header
;
16285 struct dwarf2_locexpr_baton
*baton
;
16287 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
16288 SYMBOL_PRINT_NAME (sym
),
16289 &objfile
->objfile_obstack
, cu
,
16290 &value
, &bytes
, &baton
);
16294 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
16295 SYMBOL_LOCATION_BATON (sym
) = baton
;
16296 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
16298 else if (bytes
!= NULL
)
16300 SYMBOL_VALUE_BYTES (sym
) = bytes
;
16301 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
16305 SYMBOL_VALUE (sym
) = value
;
16306 SYMBOL_CLASS (sym
) = LOC_CONST
;
16310 /* Return the type of the die in question using its DW_AT_type attribute. */
16312 static struct type
*
16313 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16315 struct attribute
*type_attr
;
16317 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16320 /* A missing DW_AT_type represents a void type. */
16321 return objfile_type (cu
->objfile
)->builtin_void
;
16324 return lookup_die_type (die
, type_attr
, cu
);
16327 /* True iff CU's producer generates GNAT Ada auxiliary information
16328 that allows to find parallel types through that information instead
16329 of having to do expensive parallel lookups by type name. */
16332 need_gnat_info (struct dwarf2_cu
*cu
)
16334 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16335 of GNAT produces this auxiliary information, without any indication
16336 that it is produced. Part of enhancing the FSF version of GNAT
16337 to produce that information will be to put in place an indicator
16338 that we can use in order to determine whether the descriptive type
16339 info is available or not. One suggestion that has been made is
16340 to use a new attribute, attached to the CU die. For now, assume
16341 that the descriptive type info is not available. */
16345 /* Return the auxiliary type of the die in question using its
16346 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16347 attribute is not present. */
16349 static struct type
*
16350 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16352 struct attribute
*type_attr
;
16354 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
16358 return lookup_die_type (die
, type_attr
, cu
);
16361 /* If DIE has a descriptive_type attribute, then set the TYPE's
16362 descriptive type accordingly. */
16365 set_descriptive_type (struct type
*type
, struct die_info
*die
,
16366 struct dwarf2_cu
*cu
)
16368 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
16370 if (descriptive_type
)
16372 ALLOCATE_GNAT_AUX_TYPE (type
);
16373 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
16377 /* Return the containing type of the die in question using its
16378 DW_AT_containing_type attribute. */
16380 static struct type
*
16381 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16383 struct attribute
*type_attr
;
16385 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
16387 error (_("Dwarf Error: Problem turning containing type into gdb type "
16388 "[in module %s]"), cu
->objfile
->name
);
16390 return lookup_die_type (die
, type_attr
, cu
);
16393 /* Look up the type of DIE in CU using its type attribute ATTR.
16394 If there is no type substitute an error marker. */
16396 static struct type
*
16397 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
16398 struct dwarf2_cu
*cu
)
16400 struct objfile
*objfile
= cu
->objfile
;
16401 struct type
*this_type
;
16403 /* First see if we have it cached. */
16405 if (attr
->form
== DW_FORM_GNU_ref_alt
)
16407 struct dwarf2_per_cu_data
*per_cu
;
16408 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16410 per_cu
= dwarf2_find_containing_comp_unit (offset
, 1, cu
->objfile
);
16411 this_type
= get_die_type_at_offset (offset
, per_cu
);
16413 else if (is_ref_attr (attr
))
16415 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
16417 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
16419 else if (attr
->form
== DW_FORM_ref_sig8
)
16421 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
16423 /* sig_type will be NULL if the signatured type is missing from
16425 if (sig_type
== NULL
)
16426 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16427 "at 0x%x [in module %s]"),
16428 die
->offset
.sect_off
, objfile
->name
);
16430 gdb_assert (sig_type
->per_cu
.is_debug_types
);
16431 /* If we haven't filled in type_offset_in_section yet, then we
16432 haven't read the type in yet. */
16434 if (sig_type
->type_offset_in_section
.sect_off
!= 0)
16437 get_die_type_at_offset (sig_type
->type_offset_in_section
,
16438 &sig_type
->per_cu
);
16443 dump_die_for_error (die
);
16444 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16445 dwarf_attr_name (attr
->name
), objfile
->name
);
16448 /* If not cached we need to read it in. */
16450 if (this_type
== NULL
)
16452 struct die_info
*type_die
;
16453 struct dwarf2_cu
*type_cu
= cu
;
16455 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
16456 /* If we found the type now, it's probably because the type came
16457 from an inter-CU reference and the type's CU got expanded before
16459 this_type
= get_die_type (type_die
, type_cu
);
16460 if (this_type
== NULL
)
16461 this_type
= read_type_die_1 (type_die
, type_cu
);
16464 /* If we still don't have a type use an error marker. */
16466 if (this_type
== NULL
)
16468 char *message
, *saved
;
16470 /* read_type_die already issued a complaint. */
16471 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16473 cu
->header
.offset
.sect_off
,
16474 die
->offset
.sect_off
);
16475 saved
= obstack_copy0 (&objfile
->objfile_obstack
,
16476 message
, strlen (message
));
16479 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, objfile
);
16485 /* Return the type in DIE, CU.
16486 Returns NULL for invalid types.
16488 This first does a lookup in the appropriate type_hash table,
16489 and only reads the die in if necessary.
16491 NOTE: This can be called when reading in partial or full symbols. */
16493 static struct type
*
16494 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
16496 struct type
*this_type
;
16498 this_type
= get_die_type (die
, cu
);
16502 return read_type_die_1 (die
, cu
);
16505 /* Read the type in DIE, CU.
16506 Returns NULL for invalid types. */
16508 static struct type
*
16509 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
16511 struct type
*this_type
= NULL
;
16515 case DW_TAG_class_type
:
16516 case DW_TAG_interface_type
:
16517 case DW_TAG_structure_type
:
16518 case DW_TAG_union_type
:
16519 this_type
= read_structure_type (die
, cu
);
16521 case DW_TAG_enumeration_type
:
16522 this_type
= read_enumeration_type (die
, cu
);
16524 case DW_TAG_subprogram
:
16525 case DW_TAG_subroutine_type
:
16526 case DW_TAG_inlined_subroutine
:
16527 this_type
= read_subroutine_type (die
, cu
);
16529 case DW_TAG_array_type
:
16530 this_type
= read_array_type (die
, cu
);
16532 case DW_TAG_set_type
:
16533 this_type
= read_set_type (die
, cu
);
16535 case DW_TAG_pointer_type
:
16536 this_type
= read_tag_pointer_type (die
, cu
);
16538 case DW_TAG_ptr_to_member_type
:
16539 this_type
= read_tag_ptr_to_member_type (die
, cu
);
16541 case DW_TAG_reference_type
:
16542 this_type
= read_tag_reference_type (die
, cu
);
16544 case DW_TAG_const_type
:
16545 this_type
= read_tag_const_type (die
, cu
);
16547 case DW_TAG_volatile_type
:
16548 this_type
= read_tag_volatile_type (die
, cu
);
16550 case DW_TAG_restrict_type
:
16551 this_type
= read_tag_restrict_type (die
, cu
);
16553 case DW_TAG_string_type
:
16554 this_type
= read_tag_string_type (die
, cu
);
16556 case DW_TAG_typedef
:
16557 this_type
= read_typedef (die
, cu
);
16559 case DW_TAG_subrange_type
:
16560 this_type
= read_subrange_type (die
, cu
);
16562 case DW_TAG_base_type
:
16563 this_type
= read_base_type (die
, cu
);
16565 case DW_TAG_unspecified_type
:
16566 this_type
= read_unspecified_type (die
, cu
);
16568 case DW_TAG_namespace
:
16569 this_type
= read_namespace_type (die
, cu
);
16571 case DW_TAG_module
:
16572 this_type
= read_module_type (die
, cu
);
16575 complaint (&symfile_complaints
,
16576 _("unexpected tag in read_type_die: '%s'"),
16577 dwarf_tag_name (die
->tag
));
16584 /* See if we can figure out if the class lives in a namespace. We do
16585 this by looking for a member function; its demangled name will
16586 contain namespace info, if there is any.
16587 Return the computed name or NULL.
16588 Space for the result is allocated on the objfile's obstack.
16589 This is the full-die version of guess_partial_die_structure_name.
16590 In this case we know DIE has no useful parent. */
16593 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16595 struct die_info
*spec_die
;
16596 struct dwarf2_cu
*spec_cu
;
16597 struct die_info
*child
;
16600 spec_die
= die_specification (die
, &spec_cu
);
16601 if (spec_die
!= NULL
)
16607 for (child
= die
->child
;
16609 child
= child
->sibling
)
16611 if (child
->tag
== DW_TAG_subprogram
)
16613 struct attribute
*attr
;
16615 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
16617 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
16621 = language_class_name_from_physname (cu
->language_defn
,
16625 if (actual_name
!= NULL
)
16627 const char *die_name
= dwarf2_name (die
, cu
);
16629 if (die_name
!= NULL
16630 && strcmp (die_name
, actual_name
) != 0)
16632 /* Strip off the class name from the full name.
16633 We want the prefix. */
16634 int die_name_len
= strlen (die_name
);
16635 int actual_name_len
= strlen (actual_name
);
16637 /* Test for '::' as a sanity check. */
16638 if (actual_name_len
> die_name_len
+ 2
16639 && actual_name
[actual_name_len
16640 - die_name_len
- 1] == ':')
16642 obstack_copy0 (&cu
->objfile
->objfile_obstack
,
16644 actual_name_len
- die_name_len
- 2);
16647 xfree (actual_name
);
16656 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16657 prefix part in such case. See
16658 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16661 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16663 struct attribute
*attr
;
16666 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
16667 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
16670 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16671 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
16674 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
16676 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
16677 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
16680 /* dwarf2_name had to be already called. */
16681 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
16683 /* Strip the base name, keep any leading namespaces/classes. */
16684 base
= strrchr (DW_STRING (attr
), ':');
16685 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
16688 return obstack_copy0 (&cu
->objfile
->objfile_obstack
,
16689 DW_STRING (attr
), &base
[-1] - DW_STRING (attr
));
16692 /* Return the name of the namespace/class that DIE is defined within,
16693 or "" if we can't tell. The caller should not xfree the result.
16695 For example, if we're within the method foo() in the following
16705 then determine_prefix on foo's die will return "N::C". */
16707 static const char *
16708 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
16710 struct die_info
*parent
, *spec_die
;
16711 struct dwarf2_cu
*spec_cu
;
16712 struct type
*parent_type
;
16715 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
16716 && cu
->language
!= language_fortran
)
16719 retval
= anonymous_struct_prefix (die
, cu
);
16723 /* We have to be careful in the presence of DW_AT_specification.
16724 For example, with GCC 3.4, given the code
16728 // Definition of N::foo.
16732 then we'll have a tree of DIEs like this:
16734 1: DW_TAG_compile_unit
16735 2: DW_TAG_namespace // N
16736 3: DW_TAG_subprogram // declaration of N::foo
16737 4: DW_TAG_subprogram // definition of N::foo
16738 DW_AT_specification // refers to die #3
16740 Thus, when processing die #4, we have to pretend that we're in
16741 the context of its DW_AT_specification, namely the contex of die
16744 spec_die
= die_specification (die
, &spec_cu
);
16745 if (spec_die
== NULL
)
16746 parent
= die
->parent
;
16749 parent
= spec_die
->parent
;
16753 if (parent
== NULL
)
16755 else if (parent
->building_fullname
)
16758 const char *parent_name
;
16760 /* It has been seen on RealView 2.2 built binaries,
16761 DW_TAG_template_type_param types actually _defined_ as
16762 children of the parent class:
16765 template class <class Enum> Class{};
16766 Class<enum E> class_e;
16768 1: DW_TAG_class_type (Class)
16769 2: DW_TAG_enumeration_type (E)
16770 3: DW_TAG_enumerator (enum1:0)
16771 3: DW_TAG_enumerator (enum2:1)
16773 2: DW_TAG_template_type_param
16774 DW_AT_type DW_FORM_ref_udata (E)
16776 Besides being broken debug info, it can put GDB into an
16777 infinite loop. Consider:
16779 When we're building the full name for Class<E>, we'll start
16780 at Class, and go look over its template type parameters,
16781 finding E. We'll then try to build the full name of E, and
16782 reach here. We're now trying to build the full name of E,
16783 and look over the parent DIE for containing scope. In the
16784 broken case, if we followed the parent DIE of E, we'd again
16785 find Class, and once again go look at its template type
16786 arguments, etc., etc. Simply don't consider such parent die
16787 as source-level parent of this die (it can't be, the language
16788 doesn't allow it), and break the loop here. */
16789 name
= dwarf2_name (die
, cu
);
16790 parent_name
= dwarf2_name (parent
, cu
);
16791 complaint (&symfile_complaints
,
16792 _("template param type '%s' defined within parent '%s'"),
16793 name
? name
: "<unknown>",
16794 parent_name
? parent_name
: "<unknown>");
16798 switch (parent
->tag
)
16800 case DW_TAG_namespace
:
16801 parent_type
= read_type_die (parent
, cu
);
16802 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16803 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16804 Work around this problem here. */
16805 if (cu
->language
== language_cplus
16806 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
16808 /* We give a name to even anonymous namespaces. */
16809 return TYPE_TAG_NAME (parent_type
);
16810 case DW_TAG_class_type
:
16811 case DW_TAG_interface_type
:
16812 case DW_TAG_structure_type
:
16813 case DW_TAG_union_type
:
16814 case DW_TAG_module
:
16815 parent_type
= read_type_die (parent
, cu
);
16816 if (TYPE_TAG_NAME (parent_type
) != NULL
)
16817 return TYPE_TAG_NAME (parent_type
);
16819 /* An anonymous structure is only allowed non-static data
16820 members; no typedefs, no member functions, et cetera.
16821 So it does not need a prefix. */
16823 case DW_TAG_compile_unit
:
16824 case DW_TAG_partial_unit
:
16825 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16826 if (cu
->language
== language_cplus
16827 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
16828 && die
->child
!= NULL
16829 && (die
->tag
== DW_TAG_class_type
16830 || die
->tag
== DW_TAG_structure_type
16831 || die
->tag
== DW_TAG_union_type
))
16833 char *name
= guess_full_die_structure_name (die
, cu
);
16839 return determine_prefix (parent
, cu
);
16843 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16844 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16845 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16846 an obconcat, otherwise allocate storage for the result. The CU argument is
16847 used to determine the language and hence, the appropriate separator. */
16849 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16852 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
16853 int physname
, struct dwarf2_cu
*cu
)
16855 const char *lead
= "";
16858 if (suffix
== NULL
|| suffix
[0] == '\0'
16859 || prefix
== NULL
|| prefix
[0] == '\0')
16861 else if (cu
->language
== language_java
)
16863 else if (cu
->language
== language_fortran
&& physname
)
16865 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16866 DW_AT_MIPS_linkage_name is preferred and used instead. */
16874 if (prefix
== NULL
)
16876 if (suffix
== NULL
)
16882 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
16884 strcpy (retval
, lead
);
16885 strcat (retval
, prefix
);
16886 strcat (retval
, sep
);
16887 strcat (retval
, suffix
);
16892 /* We have an obstack. */
16893 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
16897 /* Return sibling of die, NULL if no sibling. */
16899 static struct die_info
*
16900 sibling_die (struct die_info
*die
)
16902 return die
->sibling
;
16905 /* Get name of a die, return NULL if not found. */
16907 static const char *
16908 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
16909 struct obstack
*obstack
)
16911 if (name
&& cu
->language
== language_cplus
)
16913 char *canon_name
= cp_canonicalize_string (name
);
16915 if (canon_name
!= NULL
)
16917 if (strcmp (canon_name
, name
) != 0)
16918 name
= obstack_copy0 (obstack
, canon_name
, strlen (canon_name
));
16919 xfree (canon_name
);
16926 /* Get name of a die, return NULL if not found. */
16928 static const char *
16929 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
16931 struct attribute
*attr
;
16933 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
16934 if ((!attr
|| !DW_STRING (attr
))
16935 && die
->tag
!= DW_TAG_class_type
16936 && die
->tag
!= DW_TAG_interface_type
16937 && die
->tag
!= DW_TAG_structure_type
16938 && die
->tag
!= DW_TAG_union_type
)
16943 case DW_TAG_compile_unit
:
16944 case DW_TAG_partial_unit
:
16945 /* Compilation units have a DW_AT_name that is a filename, not
16946 a source language identifier. */
16947 case DW_TAG_enumeration_type
:
16948 case DW_TAG_enumerator
:
16949 /* These tags always have simple identifiers already; no need
16950 to canonicalize them. */
16951 return DW_STRING (attr
);
16953 case DW_TAG_subprogram
:
16954 /* Java constructors will all be named "<init>", so return
16955 the class name when we see this special case. */
16956 if (cu
->language
== language_java
16957 && DW_STRING (attr
) != NULL
16958 && strcmp (DW_STRING (attr
), "<init>") == 0)
16960 struct dwarf2_cu
*spec_cu
= cu
;
16961 struct die_info
*spec_die
;
16963 /* GCJ will output '<init>' for Java constructor names.
16964 For this special case, return the name of the parent class. */
16966 /* GCJ may output suprogram DIEs with AT_specification set.
16967 If so, use the name of the specified DIE. */
16968 spec_die
= die_specification (die
, &spec_cu
);
16969 if (spec_die
!= NULL
)
16970 return dwarf2_name (spec_die
, spec_cu
);
16975 if (die
->tag
== DW_TAG_class_type
)
16976 return dwarf2_name (die
, cu
);
16978 while (die
->tag
!= DW_TAG_compile_unit
16979 && die
->tag
!= DW_TAG_partial_unit
);
16983 case DW_TAG_class_type
:
16984 case DW_TAG_interface_type
:
16985 case DW_TAG_structure_type
:
16986 case DW_TAG_union_type
:
16987 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16988 structures or unions. These were of the form "._%d" in GCC 4.1,
16989 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16990 and GCC 4.4. We work around this problem by ignoring these. */
16991 if (attr
&& DW_STRING (attr
)
16992 && (strncmp (DW_STRING (attr
), "._", 2) == 0
16993 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
16996 /* GCC might emit a nameless typedef that has a linkage name. See
16997 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16998 if (!attr
|| DW_STRING (attr
) == NULL
)
17000 char *demangled
= NULL
;
17002 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
17004 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
17006 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
17009 /* Avoid demangling DW_STRING (attr) the second time on a second
17010 call for the same DIE. */
17011 if (!DW_STRING_IS_CANONICAL (attr
))
17012 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
17018 /* FIXME: we already did this for the partial symbol... */
17019 DW_STRING (attr
) = obstack_copy0 (&cu
->objfile
->objfile_obstack
,
17020 demangled
, strlen (demangled
));
17021 DW_STRING_IS_CANONICAL (attr
) = 1;
17024 /* Strip any leading namespaces/classes, keep only the base name.
17025 DW_AT_name for named DIEs does not contain the prefixes. */
17026 base
= strrchr (DW_STRING (attr
), ':');
17027 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
17030 return DW_STRING (attr
);
17039 if (!DW_STRING_IS_CANONICAL (attr
))
17042 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
17043 &cu
->objfile
->objfile_obstack
);
17044 DW_STRING_IS_CANONICAL (attr
) = 1;
17046 return DW_STRING (attr
);
17049 /* Return the die that this die in an extension of, or NULL if there
17050 is none. *EXT_CU is the CU containing DIE on input, and the CU
17051 containing the return value on output. */
17053 static struct die_info
*
17054 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
17056 struct attribute
*attr
;
17058 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
17062 return follow_die_ref (die
, attr
, ext_cu
);
17065 /* Convert a DIE tag into its string name. */
17067 static const char *
17068 dwarf_tag_name (unsigned tag
)
17070 const char *name
= get_DW_TAG_name (tag
);
17073 return "DW_TAG_<unknown>";
17078 /* Convert a DWARF attribute code into its string name. */
17080 static const char *
17081 dwarf_attr_name (unsigned attr
)
17085 #ifdef MIPS /* collides with DW_AT_HP_block_index */
17086 if (attr
== DW_AT_MIPS_fde
)
17087 return "DW_AT_MIPS_fde";
17089 if (attr
== DW_AT_HP_block_index
)
17090 return "DW_AT_HP_block_index";
17093 name
= get_DW_AT_name (attr
);
17096 return "DW_AT_<unknown>";
17101 /* Convert a DWARF value form code into its string name. */
17103 static const char *
17104 dwarf_form_name (unsigned form
)
17106 const char *name
= get_DW_FORM_name (form
);
17109 return "DW_FORM_<unknown>";
17115 dwarf_bool_name (unsigned mybool
)
17123 /* Convert a DWARF type code into its string name. */
17125 static const char *
17126 dwarf_type_encoding_name (unsigned enc
)
17128 const char *name
= get_DW_ATE_name (enc
);
17131 return "DW_ATE_<unknown>";
17137 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
17141 print_spaces (indent
, f
);
17142 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
17143 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
.sect_off
);
17145 if (die
->parent
!= NULL
)
17147 print_spaces (indent
, f
);
17148 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
17149 die
->parent
->offset
.sect_off
);
17152 print_spaces (indent
, f
);
17153 fprintf_unfiltered (f
, " has children: %s\n",
17154 dwarf_bool_name (die
->child
!= NULL
));
17156 print_spaces (indent
, f
);
17157 fprintf_unfiltered (f
, " attributes:\n");
17159 for (i
= 0; i
< die
->num_attrs
; ++i
)
17161 print_spaces (indent
, f
);
17162 fprintf_unfiltered (f
, " %s (%s) ",
17163 dwarf_attr_name (die
->attrs
[i
].name
),
17164 dwarf_form_name (die
->attrs
[i
].form
));
17166 switch (die
->attrs
[i
].form
)
17169 case DW_FORM_GNU_addr_index
:
17170 fprintf_unfiltered (f
, "address: ");
17171 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
17173 case DW_FORM_block2
:
17174 case DW_FORM_block4
:
17175 case DW_FORM_block
:
17176 case DW_FORM_block1
:
17177 fprintf_unfiltered (f
, "block: size %s",
17178 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17180 case DW_FORM_exprloc
:
17181 fprintf_unfiltered (f
, "expression: size %s",
17182 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
17184 case DW_FORM_ref_addr
:
17185 fprintf_unfiltered (f
, "ref address: ");
17186 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17188 case DW_FORM_GNU_ref_alt
:
17189 fprintf_unfiltered (f
, "alt ref address: ");
17190 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
17196 case DW_FORM_ref_udata
:
17197 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
17198 (long) (DW_UNSND (&die
->attrs
[i
])));
17200 case DW_FORM_data1
:
17201 case DW_FORM_data2
:
17202 case DW_FORM_data4
:
17203 case DW_FORM_data8
:
17204 case DW_FORM_udata
:
17205 case DW_FORM_sdata
:
17206 fprintf_unfiltered (f
, "constant: %s",
17207 pulongest (DW_UNSND (&die
->attrs
[i
])));
17209 case DW_FORM_sec_offset
:
17210 fprintf_unfiltered (f
, "section offset: %s",
17211 pulongest (DW_UNSND (&die
->attrs
[i
])));
17213 case DW_FORM_ref_sig8
:
17214 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
17215 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
17216 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->per_cu
.offset
.sect_off
);
17218 fprintf_unfiltered (f
, "signatured type, offset: unknown");
17220 case DW_FORM_string
:
17222 case DW_FORM_GNU_str_index
:
17223 case DW_FORM_GNU_strp_alt
:
17224 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
17225 DW_STRING (&die
->attrs
[i
])
17226 ? DW_STRING (&die
->attrs
[i
]) : "",
17227 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
17230 if (DW_UNSND (&die
->attrs
[i
]))
17231 fprintf_unfiltered (f
, "flag: TRUE");
17233 fprintf_unfiltered (f
, "flag: FALSE");
17235 case DW_FORM_flag_present
:
17236 fprintf_unfiltered (f
, "flag: TRUE");
17238 case DW_FORM_indirect
:
17239 /* The reader will have reduced the indirect form to
17240 the "base form" so this form should not occur. */
17241 fprintf_unfiltered (f
,
17242 "unexpected attribute form: DW_FORM_indirect");
17245 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
17246 die
->attrs
[i
].form
);
17249 fprintf_unfiltered (f
, "\n");
17254 dump_die_for_error (struct die_info
*die
)
17256 dump_die_shallow (gdb_stderr
, 0, die
);
17260 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
17262 int indent
= level
* 4;
17264 gdb_assert (die
!= NULL
);
17266 if (level
>= max_level
)
17269 dump_die_shallow (f
, indent
, die
);
17271 if (die
->child
!= NULL
)
17273 print_spaces (indent
, f
);
17274 fprintf_unfiltered (f
, " Children:");
17275 if (level
+ 1 < max_level
)
17277 fprintf_unfiltered (f
, "\n");
17278 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
17282 fprintf_unfiltered (f
,
17283 " [not printed, max nesting level reached]\n");
17287 if (die
->sibling
!= NULL
&& level
> 0)
17289 dump_die_1 (f
, level
, max_level
, die
->sibling
);
17293 /* This is called from the pdie macro in gdbinit.in.
17294 It's not static so gcc will keep a copy callable from gdb. */
17297 dump_die (struct die_info
*die
, int max_level
)
17299 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
17303 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
17307 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
.sect_off
,
17313 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17314 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17317 is_ref_attr (struct attribute
*attr
)
17319 switch (attr
->form
)
17321 case DW_FORM_ref_addr
:
17326 case DW_FORM_ref_udata
:
17327 case DW_FORM_GNU_ref_alt
:
17334 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17338 dwarf2_get_ref_die_offset (struct attribute
*attr
)
17340 sect_offset retval
= { DW_UNSND (attr
) };
17342 if (is_ref_attr (attr
))
17345 retval
.sect_off
= 0;
17346 complaint (&symfile_complaints
,
17347 _("unsupported die ref attribute form: '%s'"),
17348 dwarf_form_name (attr
->form
));
17352 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17353 * the value held by the attribute is not constant. */
17356 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
17358 if (attr
->form
== DW_FORM_sdata
)
17359 return DW_SND (attr
);
17360 else if (attr
->form
== DW_FORM_udata
17361 || attr
->form
== DW_FORM_data1
17362 || attr
->form
== DW_FORM_data2
17363 || attr
->form
== DW_FORM_data4
17364 || attr
->form
== DW_FORM_data8
)
17365 return DW_UNSND (attr
);
17368 complaint (&symfile_complaints
,
17369 _("Attribute value is not a constant (%s)"),
17370 dwarf_form_name (attr
->form
));
17371 return default_value
;
17375 /* Follow reference or signature attribute ATTR of SRC_DIE.
17376 On entry *REF_CU is the CU of SRC_DIE.
17377 On exit *REF_CU is the CU of the result. */
17379 static struct die_info
*
17380 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
17381 struct dwarf2_cu
**ref_cu
)
17383 struct die_info
*die
;
17385 if (is_ref_attr (attr
))
17386 die
= follow_die_ref (src_die
, attr
, ref_cu
);
17387 else if (attr
->form
== DW_FORM_ref_sig8
)
17388 die
= follow_die_sig (src_die
, attr
, ref_cu
);
17391 dump_die_for_error (src_die
);
17392 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17393 (*ref_cu
)->objfile
->name
);
17399 /* Follow reference OFFSET.
17400 On entry *REF_CU is the CU of the source die referencing OFFSET.
17401 On exit *REF_CU is the CU of the result.
17402 Returns NULL if OFFSET is invalid. */
17404 static struct die_info
*
17405 follow_die_offset (sect_offset offset
, int offset_in_dwz
,
17406 struct dwarf2_cu
**ref_cu
)
17408 struct die_info temp_die
;
17409 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
17411 gdb_assert (cu
->per_cu
!= NULL
);
17415 if (cu
->per_cu
->is_debug_types
)
17417 /* .debug_types CUs cannot reference anything outside their CU.
17418 If they need to, they have to reference a signatured type via
17419 DW_FORM_ref_sig8. */
17420 if (! offset_in_cu_p (&cu
->header
, offset
))
17423 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
17424 || ! offset_in_cu_p (&cu
->header
, offset
))
17426 struct dwarf2_per_cu_data
*per_cu
;
17428 per_cu
= dwarf2_find_containing_comp_unit (offset
, offset_in_dwz
,
17431 /* If necessary, add it to the queue and load its DIEs. */
17432 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
17433 load_full_comp_unit (per_cu
, cu
->language
);
17435 target_cu
= per_cu
->cu
;
17437 else if (cu
->dies
== NULL
)
17439 /* We're loading full DIEs during partial symbol reading. */
17440 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
17441 load_full_comp_unit (cu
->per_cu
, language_minimal
);
17444 *ref_cu
= target_cu
;
17445 temp_die
.offset
= offset
;
17446 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
.sect_off
);
17449 /* Follow reference attribute ATTR of SRC_DIE.
17450 On entry *REF_CU is the CU of SRC_DIE.
17451 On exit *REF_CU is the CU of the result. */
17453 static struct die_info
*
17454 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
17455 struct dwarf2_cu
**ref_cu
)
17457 sect_offset offset
= dwarf2_get_ref_die_offset (attr
);
17458 struct dwarf2_cu
*cu
= *ref_cu
;
17459 struct die_info
*die
;
17461 die
= follow_die_offset (offset
,
17462 (attr
->form
== DW_FORM_GNU_ref_alt
17463 || cu
->per_cu
->is_dwz
),
17466 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17467 "at 0x%x [in module %s]"),
17468 offset
.sect_off
, src_die
->offset
.sect_off
, cu
->objfile
->name
);
17473 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17474 Returned value is intended for DW_OP_call*. Returned
17475 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17477 struct dwarf2_locexpr_baton
17478 dwarf2_fetch_die_loc_sect_off (sect_offset offset
,
17479 struct dwarf2_per_cu_data
*per_cu
,
17480 CORE_ADDR (*get_frame_pc
) (void *baton
),
17483 struct dwarf2_cu
*cu
;
17484 struct die_info
*die
;
17485 struct attribute
*attr
;
17486 struct dwarf2_locexpr_baton retval
;
17488 dw2_setup (per_cu
->objfile
);
17490 if (per_cu
->cu
== NULL
)
17494 die
= follow_die_offset (offset
, per_cu
->is_dwz
, &cu
);
17496 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17497 offset
.sect_off
, per_cu
->objfile
->name
);
17499 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17502 /* DWARF: "If there is no such attribute, then there is no effect.".
17503 DATA is ignored if SIZE is 0. */
17505 retval
.data
= NULL
;
17508 else if (attr_form_is_section_offset (attr
))
17510 struct dwarf2_loclist_baton loclist_baton
;
17511 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
17514 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
17516 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
17518 retval
.size
= size
;
17522 if (!attr_form_is_block (attr
))
17523 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17524 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17525 offset
.sect_off
, per_cu
->objfile
->name
);
17527 retval
.data
= DW_BLOCK (attr
)->data
;
17528 retval
.size
= DW_BLOCK (attr
)->size
;
17530 retval
.per_cu
= cu
->per_cu
;
17532 age_cached_comp_units ();
17537 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17540 struct dwarf2_locexpr_baton
17541 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
17542 struct dwarf2_per_cu_data
*per_cu
,
17543 CORE_ADDR (*get_frame_pc
) (void *baton
),
17546 sect_offset offset
= { per_cu
->offset
.sect_off
+ offset_in_cu
.cu_off
};
17548 return dwarf2_fetch_die_loc_sect_off (offset
, per_cu
, get_frame_pc
, baton
);
17551 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17555 dwarf2_get_die_type (cu_offset die_offset
,
17556 struct dwarf2_per_cu_data
*per_cu
)
17558 sect_offset die_offset_sect
;
17560 dw2_setup (per_cu
->objfile
);
17562 die_offset_sect
.sect_off
= per_cu
->offset
.sect_off
+ die_offset
.cu_off
;
17563 return get_die_type_at_offset (die_offset_sect
, per_cu
);
17566 /* Follow the signature attribute ATTR in SRC_DIE.
17567 On entry *REF_CU is the CU of SRC_DIE.
17568 On exit *REF_CU is the CU of the result. */
17570 static struct die_info
*
17571 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
17572 struct dwarf2_cu
**ref_cu
)
17574 struct objfile
*objfile
= (*ref_cu
)->objfile
;
17575 struct die_info temp_die
;
17576 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
17577 struct dwarf2_cu
*sig_cu
;
17578 struct die_info
*die
;
17580 /* sig_type will be NULL if the signatured type is missing from
17582 if (sig_type
== NULL
)
17583 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17584 "at 0x%x [in module %s]"),
17585 src_die
->offset
.sect_off
, objfile
->name
);
17587 /* If necessary, add it to the queue and load its DIEs. */
17589 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
17590 read_signatured_type (sig_type
);
17592 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
17594 sig_cu
= sig_type
->per_cu
.cu
;
17595 gdb_assert (sig_type
->type_offset_in_section
.sect_off
!= 0);
17596 temp_die
.offset
= sig_type
->type_offset_in_section
;
17597 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
17598 temp_die
.offset
.sect_off
);
17601 /* For .gdb_index version 7 keep track of included TUs.
17602 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
17603 if (dwarf2_per_objfile
->index_table
!= NULL
17604 && dwarf2_per_objfile
->index_table
->version
<= 7)
17606 VEC_safe_push (dwarf2_per_cu_ptr
,
17607 (*ref_cu
)->per_cu
->imported_symtabs
,
17615 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17616 "from DIE at 0x%x [in module %s]"),
17617 temp_die
.offset
.sect_off
, src_die
->offset
.sect_off
, objfile
->name
);
17620 /* Given an offset of a signatured type, return its signatured_type. */
17622 static struct signatured_type
*
17623 lookup_signatured_type_at_offset (struct objfile
*objfile
,
17624 struct dwarf2_section_info
*section
,
17625 sect_offset offset
)
17627 gdb_byte
*info_ptr
= section
->buffer
+ offset
.sect_off
;
17628 unsigned int length
, initial_length_size
;
17629 unsigned int sig_offset
;
17630 struct signatured_type find_entry
, *sig_type
;
17632 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
17633 sig_offset
= (initial_length_size
17635 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
17636 + 1 /*address_size*/);
17637 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
17638 sig_type
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
17640 /* This is only used to lookup previously recorded types.
17641 If we didn't find it, it's our bug. */
17642 gdb_assert (sig_type
!= NULL
);
17643 gdb_assert (offset
.sect_off
== sig_type
->per_cu
.offset
.sect_off
);
17648 /* Load the DIEs associated with type unit PER_CU into memory. */
17651 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
17653 struct signatured_type
*sig_type
;
17655 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17656 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
17658 /* We have the per_cu, but we need the signatured_type.
17659 Fortunately this is an easy translation. */
17660 gdb_assert (per_cu
->is_debug_types
);
17661 sig_type
= (struct signatured_type
*) per_cu
;
17663 gdb_assert (per_cu
->cu
== NULL
);
17665 read_signatured_type (sig_type
);
17667 gdb_assert (per_cu
->cu
!= NULL
);
17670 /* die_reader_func for read_signatured_type.
17671 This is identical to load_full_comp_unit_reader,
17672 but is kept separate for now. */
17675 read_signatured_type_reader (const struct die_reader_specs
*reader
,
17676 gdb_byte
*info_ptr
,
17677 struct die_info
*comp_unit_die
,
17681 struct dwarf2_cu
*cu
= reader
->cu
;
17683 gdb_assert (cu
->die_hash
== NULL
);
17685 htab_create_alloc_ex (cu
->header
.length
/ 12,
17689 &cu
->comp_unit_obstack
,
17690 hashtab_obstack_allocate
,
17691 dummy_obstack_deallocate
);
17694 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
17695 &info_ptr
, comp_unit_die
);
17696 cu
->dies
= comp_unit_die
;
17697 /* comp_unit_die is not stored in die_hash, no need. */
17699 /* We try not to read any attributes in this function, because not
17700 all CUs needed for references have been loaded yet, and symbol
17701 table processing isn't initialized. But we have to set the CU language,
17702 or we won't be able to build types correctly.
17703 Similarly, if we do not read the producer, we can not apply
17704 producer-specific interpretation. */
17705 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
17708 /* Read in a signatured type and build its CU and DIEs.
17709 If the type is a stub for the real type in a DWO file,
17710 read in the real type from the DWO file as well. */
17713 read_signatured_type (struct signatured_type
*sig_type
)
17715 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
17717 gdb_assert (per_cu
->is_debug_types
);
17718 gdb_assert (per_cu
->cu
== NULL
);
17720 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
17721 read_signatured_type_reader
, NULL
);
17724 /* Decode simple location descriptions.
17725 Given a pointer to a dwarf block that defines a location, compute
17726 the location and return the value.
17728 NOTE drow/2003-11-18: This function is called in two situations
17729 now: for the address of static or global variables (partial symbols
17730 only) and for offsets into structures which are expected to be
17731 (more or less) constant. The partial symbol case should go away,
17732 and only the constant case should remain. That will let this
17733 function complain more accurately. A few special modes are allowed
17734 without complaint for global variables (for instance, global
17735 register values and thread-local values).
17737 A location description containing no operations indicates that the
17738 object is optimized out. The return value is 0 for that case.
17739 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17740 callers will only want a very basic result and this can become a
17743 Note that stack[0] is unused except as a default error return. */
17746 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
17748 struct objfile
*objfile
= cu
->objfile
;
17750 size_t size
= blk
->size
;
17751 gdb_byte
*data
= blk
->data
;
17752 CORE_ADDR stack
[64];
17754 unsigned int bytes_read
, unsnd
;
17760 stack
[++stacki
] = 0;
17799 stack
[++stacki
] = op
- DW_OP_lit0
;
17834 stack
[++stacki
] = op
- DW_OP_reg0
;
17836 dwarf2_complex_location_expr_complaint ();
17840 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
17842 stack
[++stacki
] = unsnd
;
17844 dwarf2_complex_location_expr_complaint ();
17848 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
17853 case DW_OP_const1u
:
17854 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
17858 case DW_OP_const1s
:
17859 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
17863 case DW_OP_const2u
:
17864 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
17868 case DW_OP_const2s
:
17869 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
17873 case DW_OP_const4u
:
17874 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
17878 case DW_OP_const4s
:
17879 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
17883 case DW_OP_const8u
:
17884 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
17889 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
17895 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
17900 stack
[stacki
+ 1] = stack
[stacki
];
17905 stack
[stacki
- 1] += stack
[stacki
];
17909 case DW_OP_plus_uconst
:
17910 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
17916 stack
[stacki
- 1] -= stack
[stacki
];
17921 /* If we're not the last op, then we definitely can't encode
17922 this using GDB's address_class enum. This is valid for partial
17923 global symbols, although the variable's address will be bogus
17926 dwarf2_complex_location_expr_complaint ();
17929 case DW_OP_GNU_push_tls_address
:
17930 /* The top of the stack has the offset from the beginning
17931 of the thread control block at which the variable is located. */
17932 /* Nothing should follow this operator, so the top of stack would
17934 /* This is valid for partial global symbols, but the variable's
17935 address will be bogus in the psymtab. Make it always at least
17936 non-zero to not look as a variable garbage collected by linker
17937 which have DW_OP_addr 0. */
17939 dwarf2_complex_location_expr_complaint ();
17943 case DW_OP_GNU_uninit
:
17946 case DW_OP_GNU_addr_index
:
17947 case DW_OP_GNU_const_index
:
17948 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
17955 const char *name
= get_DW_OP_name (op
);
17958 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
17961 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
17965 return (stack
[stacki
]);
17968 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17969 outside of the allocated space. Also enforce minimum>0. */
17970 if (stacki
>= ARRAY_SIZE (stack
) - 1)
17972 complaint (&symfile_complaints
,
17973 _("location description stack overflow"));
17979 complaint (&symfile_complaints
,
17980 _("location description stack underflow"));
17984 return (stack
[stacki
]);
17987 /* memory allocation interface */
17989 static struct dwarf_block
*
17990 dwarf_alloc_block (struct dwarf2_cu
*cu
)
17992 struct dwarf_block
*blk
;
17994 blk
= (struct dwarf_block
*)
17995 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
17999 static struct die_info
*
18000 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
18002 struct die_info
*die
;
18003 size_t size
= sizeof (struct die_info
);
18006 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
18008 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
18009 memset (die
, 0, sizeof (struct die_info
));
18014 /* Macro support. */
18016 /* Return the full name of file number I in *LH's file name table.
18017 Use COMP_DIR as the name of the current directory of the
18018 compilation. The result is allocated using xmalloc; the caller is
18019 responsible for freeing it. */
18021 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
18023 /* Is the file number a valid index into the line header's file name
18024 table? Remember that file numbers start with one, not zero. */
18025 if (1 <= file
&& file
<= lh
->num_file_names
)
18027 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
18029 if (IS_ABSOLUTE_PATH (fe
->name
))
18030 return xstrdup (fe
->name
);
18038 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
18044 dir_len
= strlen (dir
);
18045 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
18046 strcpy (full_name
, dir
);
18047 full_name
[dir_len
] = '/';
18048 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
18052 return xstrdup (fe
->name
);
18057 /* The compiler produced a bogus file number. We can at least
18058 record the macro definitions made in the file, even if we
18059 won't be able to find the file by name. */
18060 char fake_name
[80];
18062 xsnprintf (fake_name
, sizeof (fake_name
),
18063 "<bad macro file number %d>", file
);
18065 complaint (&symfile_complaints
,
18066 _("bad file number in macro information (%d)"),
18069 return xstrdup (fake_name
);
18074 static struct macro_source_file
*
18075 macro_start_file (int file
, int line
,
18076 struct macro_source_file
*current_file
,
18077 const char *comp_dir
,
18078 struct line_header
*lh
, struct objfile
*objfile
)
18080 /* The full name of this source file. */
18081 char *full_name
= file_full_name (file
, lh
, comp_dir
);
18083 /* We don't create a macro table for this compilation unit
18084 at all until we actually get a filename. */
18085 if (! pending_macros
)
18086 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
18087 objfile
->per_bfd
->macro_cache
);
18089 if (! current_file
)
18091 /* If we have no current file, then this must be the start_file
18092 directive for the compilation unit's main source file. */
18093 current_file
= macro_set_main (pending_macros
, full_name
);
18094 macro_define_special (pending_macros
);
18097 current_file
= macro_include (current_file
, line
, full_name
);
18101 return current_file
;
18105 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
18106 followed by a null byte. */
18108 copy_string (const char *buf
, int len
)
18110 char *s
= xmalloc (len
+ 1);
18112 memcpy (s
, buf
, len
);
18118 static const char *
18119 consume_improper_spaces (const char *p
, const char *body
)
18123 complaint (&symfile_complaints
,
18124 _("macro definition contains spaces "
18125 "in formal argument list:\n`%s'"),
18137 parse_macro_definition (struct macro_source_file
*file
, int line
,
18142 /* The body string takes one of two forms. For object-like macro
18143 definitions, it should be:
18145 <macro name> " " <definition>
18147 For function-like macro definitions, it should be:
18149 <macro name> "() " <definition>
18151 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18153 Spaces may appear only where explicitly indicated, and in the
18156 The Dwarf 2 spec says that an object-like macro's name is always
18157 followed by a space, but versions of GCC around March 2002 omit
18158 the space when the macro's definition is the empty string.
18160 The Dwarf 2 spec says that there should be no spaces between the
18161 formal arguments in a function-like macro's formal argument list,
18162 but versions of GCC around March 2002 include spaces after the
18166 /* Find the extent of the macro name. The macro name is terminated
18167 by either a space or null character (for an object-like macro) or
18168 an opening paren (for a function-like macro). */
18169 for (p
= body
; *p
; p
++)
18170 if (*p
== ' ' || *p
== '(')
18173 if (*p
== ' ' || *p
== '\0')
18175 /* It's an object-like macro. */
18176 int name_len
= p
- body
;
18177 char *name
= copy_string (body
, name_len
);
18178 const char *replacement
;
18181 replacement
= body
+ name_len
+ 1;
18184 dwarf2_macro_malformed_definition_complaint (body
);
18185 replacement
= body
+ name_len
;
18188 macro_define_object (file
, line
, name
, replacement
);
18192 else if (*p
== '(')
18194 /* It's a function-like macro. */
18195 char *name
= copy_string (body
, p
- body
);
18198 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
18202 p
= consume_improper_spaces (p
, body
);
18204 /* Parse the formal argument list. */
18205 while (*p
&& *p
!= ')')
18207 /* Find the extent of the current argument name. */
18208 const char *arg_start
= p
;
18210 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
18213 if (! *p
|| p
== arg_start
)
18214 dwarf2_macro_malformed_definition_complaint (body
);
18217 /* Make sure argv has room for the new argument. */
18218 if (argc
>= argv_size
)
18221 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
18224 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
18227 p
= consume_improper_spaces (p
, body
);
18229 /* Consume the comma, if present. */
18234 p
= consume_improper_spaces (p
, body
);
18243 /* Perfectly formed definition, no complaints. */
18244 macro_define_function (file
, line
, name
,
18245 argc
, (const char **) argv
,
18247 else if (*p
== '\0')
18249 /* Complain, but do define it. */
18250 dwarf2_macro_malformed_definition_complaint (body
);
18251 macro_define_function (file
, line
, name
,
18252 argc
, (const char **) argv
,
18256 /* Just complain. */
18257 dwarf2_macro_malformed_definition_complaint (body
);
18260 /* Just complain. */
18261 dwarf2_macro_malformed_definition_complaint (body
);
18267 for (i
= 0; i
< argc
; i
++)
18273 dwarf2_macro_malformed_definition_complaint (body
);
18276 /* Skip some bytes from BYTES according to the form given in FORM.
18277 Returns the new pointer. */
18280 skip_form_bytes (bfd
*abfd
, gdb_byte
*bytes
, gdb_byte
*buffer_end
,
18281 enum dwarf_form form
,
18282 unsigned int offset_size
,
18283 struct dwarf2_section_info
*section
)
18285 unsigned int bytes_read
;
18289 case DW_FORM_data1
:
18294 case DW_FORM_data2
:
18298 case DW_FORM_data4
:
18302 case DW_FORM_data8
:
18306 case DW_FORM_string
:
18307 read_direct_string (abfd
, bytes
, &bytes_read
);
18308 bytes
+= bytes_read
;
18311 case DW_FORM_sec_offset
:
18313 case DW_FORM_GNU_strp_alt
:
18314 bytes
+= offset_size
;
18317 case DW_FORM_block
:
18318 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
18319 bytes
+= bytes_read
;
18322 case DW_FORM_block1
:
18323 bytes
+= 1 + read_1_byte (abfd
, bytes
);
18325 case DW_FORM_block2
:
18326 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
18328 case DW_FORM_block4
:
18329 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
18332 case DW_FORM_sdata
:
18333 case DW_FORM_udata
:
18334 case DW_FORM_GNU_addr_index
:
18335 case DW_FORM_GNU_str_index
:
18336 bytes
= (gdb_byte
*) gdb_skip_leb128 (bytes
, buffer_end
);
18339 dwarf2_section_buffer_overflow_complaint (section
);
18347 complaint (&symfile_complaints
,
18348 _("invalid form 0x%x in `%s'"),
18350 section
->asection
->name
);
18358 /* A helper for dwarf_decode_macros that handles skipping an unknown
18359 opcode. Returns an updated pointer to the macro data buffer; or,
18360 on error, issues a complaint and returns NULL. */
18363 skip_unknown_opcode (unsigned int opcode
,
18364 gdb_byte
**opcode_definitions
,
18365 gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18367 unsigned int offset_size
,
18368 struct dwarf2_section_info
*section
)
18370 unsigned int bytes_read
, i
;
18374 if (opcode_definitions
[opcode
] == NULL
)
18376 complaint (&symfile_complaints
,
18377 _("unrecognized DW_MACFINO opcode 0x%x"),
18382 defn
= opcode_definitions
[opcode
];
18383 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
18384 defn
+= bytes_read
;
18386 for (i
= 0; i
< arg
; ++i
)
18388 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
, defn
[i
], offset_size
,
18390 if (mac_ptr
== NULL
)
18392 /* skip_form_bytes already issued the complaint. */
18400 /* A helper function which parses the header of a macro section.
18401 If the macro section is the extended (for now called "GNU") type,
18402 then this updates *OFFSET_SIZE. Returns a pointer to just after
18403 the header, or issues a complaint and returns NULL on error. */
18406 dwarf_parse_macro_header (gdb_byte
**opcode_definitions
,
18409 unsigned int *offset_size
,
18410 int section_is_gnu
)
18412 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
18414 if (section_is_gnu
)
18416 unsigned int version
, flags
;
18418 version
= read_2_bytes (abfd
, mac_ptr
);
18421 complaint (&symfile_complaints
,
18422 _("unrecognized version `%d' in .debug_macro section"),
18428 flags
= read_1_byte (abfd
, mac_ptr
);
18430 *offset_size
= (flags
& 1) ? 8 : 4;
18432 if ((flags
& 2) != 0)
18433 /* We don't need the line table offset. */
18434 mac_ptr
+= *offset_size
;
18436 /* Vendor opcode descriptions. */
18437 if ((flags
& 4) != 0)
18439 unsigned int i
, count
;
18441 count
= read_1_byte (abfd
, mac_ptr
);
18443 for (i
= 0; i
< count
; ++i
)
18445 unsigned int opcode
, bytes_read
;
18448 opcode
= read_1_byte (abfd
, mac_ptr
);
18450 opcode_definitions
[opcode
] = mac_ptr
;
18451 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18452 mac_ptr
+= bytes_read
;
18461 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18462 including DW_MACRO_GNU_transparent_include. */
18465 dwarf_decode_macro_bytes (bfd
*abfd
, gdb_byte
*mac_ptr
, gdb_byte
*mac_end
,
18466 struct macro_source_file
*current_file
,
18467 struct line_header
*lh
, const char *comp_dir
,
18468 struct dwarf2_section_info
*section
,
18469 int section_is_gnu
, int section_is_dwz
,
18470 unsigned int offset_size
,
18471 struct objfile
*objfile
,
18472 htab_t include_hash
)
18474 enum dwarf_macro_record_type macinfo_type
;
18475 int at_commandline
;
18476 gdb_byte
*opcode_definitions
[256];
18478 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18479 &offset_size
, section_is_gnu
);
18480 if (mac_ptr
== NULL
)
18482 /* We already issued a complaint. */
18486 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18487 GDB is still reading the definitions from command line. First
18488 DW_MACINFO_start_file will need to be ignored as it was already executed
18489 to create CURRENT_FILE for the main source holding also the command line
18490 definitions. On first met DW_MACINFO_start_file this flag is reset to
18491 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18493 at_commandline
= 1;
18497 /* Do we at least have room for a macinfo type byte? */
18498 if (mac_ptr
>= mac_end
)
18500 dwarf2_section_buffer_overflow_complaint (section
);
18504 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18507 /* Note that we rely on the fact that the corresponding GNU and
18508 DWARF constants are the same. */
18509 switch (macinfo_type
)
18511 /* A zero macinfo type indicates the end of the macro
18516 case DW_MACRO_GNU_define
:
18517 case DW_MACRO_GNU_undef
:
18518 case DW_MACRO_GNU_define_indirect
:
18519 case DW_MACRO_GNU_undef_indirect
:
18520 case DW_MACRO_GNU_define_indirect_alt
:
18521 case DW_MACRO_GNU_undef_indirect_alt
:
18523 unsigned int bytes_read
;
18528 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18529 mac_ptr
+= bytes_read
;
18531 if (macinfo_type
== DW_MACRO_GNU_define
18532 || macinfo_type
== DW_MACRO_GNU_undef
)
18534 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18535 mac_ptr
+= bytes_read
;
18539 LONGEST str_offset
;
18541 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18542 mac_ptr
+= offset_size
;
18544 if (macinfo_type
== DW_MACRO_GNU_define_indirect_alt
18545 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
18548 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18550 body
= read_indirect_string_from_dwz (dwz
, str_offset
);
18553 body
= read_indirect_string_at_offset (abfd
, str_offset
);
18556 is_define
= (macinfo_type
== DW_MACRO_GNU_define
18557 || macinfo_type
== DW_MACRO_GNU_define_indirect
18558 || macinfo_type
== DW_MACRO_GNU_define_indirect_alt
);
18559 if (! current_file
)
18561 /* DWARF violation as no main source is present. */
18562 complaint (&symfile_complaints
,
18563 _("debug info with no main source gives macro %s "
18565 is_define
? _("definition") : _("undefinition"),
18569 if ((line
== 0 && !at_commandline
)
18570 || (line
!= 0 && at_commandline
))
18571 complaint (&symfile_complaints
,
18572 _("debug info gives %s macro %s with %s line %d: %s"),
18573 at_commandline
? _("command-line") : _("in-file"),
18574 is_define
? _("definition") : _("undefinition"),
18575 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
18578 parse_macro_definition (current_file
, line
, body
);
18581 gdb_assert (macinfo_type
== DW_MACRO_GNU_undef
18582 || macinfo_type
== DW_MACRO_GNU_undef_indirect
18583 || macinfo_type
== DW_MACRO_GNU_undef_indirect_alt
);
18584 macro_undef (current_file
, line
, body
);
18589 case DW_MACRO_GNU_start_file
:
18591 unsigned int bytes_read
;
18594 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18595 mac_ptr
+= bytes_read
;
18596 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18597 mac_ptr
+= bytes_read
;
18599 if ((line
== 0 && !at_commandline
)
18600 || (line
!= 0 && at_commandline
))
18601 complaint (&symfile_complaints
,
18602 _("debug info gives source %d included "
18603 "from %s at %s line %d"),
18604 file
, at_commandline
? _("command-line") : _("file"),
18605 line
== 0 ? _("zero") : _("non-zero"), line
);
18607 if (at_commandline
)
18609 /* This DW_MACRO_GNU_start_file was executed in the
18611 at_commandline
= 0;
18614 current_file
= macro_start_file (file
, line
,
18615 current_file
, comp_dir
,
18620 case DW_MACRO_GNU_end_file
:
18621 if (! current_file
)
18622 complaint (&symfile_complaints
,
18623 _("macro debug info has an unmatched "
18624 "`close_file' directive"));
18627 current_file
= current_file
->included_by
;
18628 if (! current_file
)
18630 enum dwarf_macro_record_type next_type
;
18632 /* GCC circa March 2002 doesn't produce the zero
18633 type byte marking the end of the compilation
18634 unit. Complain if it's not there, but exit no
18637 /* Do we at least have room for a macinfo type byte? */
18638 if (mac_ptr
>= mac_end
)
18640 dwarf2_section_buffer_overflow_complaint (section
);
18644 /* We don't increment mac_ptr here, so this is just
18646 next_type
= read_1_byte (abfd
, mac_ptr
);
18647 if (next_type
!= 0)
18648 complaint (&symfile_complaints
,
18649 _("no terminating 0-type entry for "
18650 "macros in `.debug_macinfo' section"));
18657 case DW_MACRO_GNU_transparent_include
:
18658 case DW_MACRO_GNU_transparent_include_alt
:
18662 bfd
*include_bfd
= abfd
;
18663 struct dwarf2_section_info
*include_section
= section
;
18664 struct dwarf2_section_info alt_section
;
18665 gdb_byte
*include_mac_end
= mac_end
;
18666 int is_dwz
= section_is_dwz
;
18667 gdb_byte
*new_mac_ptr
;
18669 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
18670 mac_ptr
+= offset_size
;
18672 if (macinfo_type
== DW_MACRO_GNU_transparent_include_alt
)
18674 struct dwz_file
*dwz
= dwarf2_get_dwz_file ();
18676 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
18679 include_bfd
= dwz
->macro
.asection
->owner
;
18680 include_section
= &dwz
->macro
;
18681 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
18685 new_mac_ptr
= include_section
->buffer
+ offset
;
18686 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
18690 /* This has actually happened; see
18691 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18692 complaint (&symfile_complaints
,
18693 _("recursive DW_MACRO_GNU_transparent_include in "
18694 ".debug_macro section"));
18698 *slot
= new_mac_ptr
;
18700 dwarf_decode_macro_bytes (include_bfd
, new_mac_ptr
,
18701 include_mac_end
, current_file
,
18703 section
, section_is_gnu
, is_dwz
,
18704 offset_size
, objfile
, include_hash
);
18706 htab_remove_elt (include_hash
, new_mac_ptr
);
18711 case DW_MACINFO_vendor_ext
:
18712 if (!section_is_gnu
)
18714 unsigned int bytes_read
;
18717 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18718 mac_ptr
+= bytes_read
;
18719 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18720 mac_ptr
+= bytes_read
;
18722 /* We don't recognize any vendor extensions. */
18728 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18729 mac_ptr
, mac_end
, abfd
, offset_size
,
18731 if (mac_ptr
== NULL
)
18735 } while (macinfo_type
!= 0);
18739 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
18740 const char *comp_dir
, int section_is_gnu
)
18742 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18743 struct line_header
*lh
= cu
->line_header
;
18745 gdb_byte
*mac_ptr
, *mac_end
;
18746 struct macro_source_file
*current_file
= 0;
18747 enum dwarf_macro_record_type macinfo_type
;
18748 unsigned int offset_size
= cu
->header
.offset_size
;
18749 gdb_byte
*opcode_definitions
[256];
18750 struct cleanup
*cleanup
;
18751 htab_t include_hash
;
18753 struct dwarf2_section_info
*section
;
18754 const char *section_name
;
18756 if (cu
->dwo_unit
!= NULL
)
18758 if (section_is_gnu
)
18760 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
18761 section_name
= ".debug_macro.dwo";
18765 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
18766 section_name
= ".debug_macinfo.dwo";
18771 if (section_is_gnu
)
18773 section
= &dwarf2_per_objfile
->macro
;
18774 section_name
= ".debug_macro";
18778 section
= &dwarf2_per_objfile
->macinfo
;
18779 section_name
= ".debug_macinfo";
18783 dwarf2_read_section (objfile
, section
);
18784 if (section
->buffer
== NULL
)
18786 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
18789 abfd
= section
->asection
->owner
;
18791 /* First pass: Find the name of the base filename.
18792 This filename is needed in order to process all macros whose definition
18793 (or undefinition) comes from the command line. These macros are defined
18794 before the first DW_MACINFO_start_file entry, and yet still need to be
18795 associated to the base file.
18797 To determine the base file name, we scan the macro definitions until we
18798 reach the first DW_MACINFO_start_file entry. We then initialize
18799 CURRENT_FILE accordingly so that any macro definition found before the
18800 first DW_MACINFO_start_file can still be associated to the base file. */
18802 mac_ptr
= section
->buffer
+ offset
;
18803 mac_end
= section
->buffer
+ section
->size
;
18805 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
18806 &offset_size
, section_is_gnu
);
18807 if (mac_ptr
== NULL
)
18809 /* We already issued a complaint. */
18815 /* Do we at least have room for a macinfo type byte? */
18816 if (mac_ptr
>= mac_end
)
18818 /* Complaint is printed during the second pass as GDB will probably
18819 stop the first pass earlier upon finding
18820 DW_MACINFO_start_file. */
18824 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
18827 /* Note that we rely on the fact that the corresponding GNU and
18828 DWARF constants are the same. */
18829 switch (macinfo_type
)
18831 /* A zero macinfo type indicates the end of the macro
18836 case DW_MACRO_GNU_define
:
18837 case DW_MACRO_GNU_undef
:
18838 /* Only skip the data by MAC_PTR. */
18840 unsigned int bytes_read
;
18842 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18843 mac_ptr
+= bytes_read
;
18844 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18845 mac_ptr
+= bytes_read
;
18849 case DW_MACRO_GNU_start_file
:
18851 unsigned int bytes_read
;
18854 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18855 mac_ptr
+= bytes_read
;
18856 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18857 mac_ptr
+= bytes_read
;
18859 current_file
= macro_start_file (file
, line
, current_file
,
18860 comp_dir
, lh
, objfile
);
18864 case DW_MACRO_GNU_end_file
:
18865 /* No data to skip by MAC_PTR. */
18868 case DW_MACRO_GNU_define_indirect
:
18869 case DW_MACRO_GNU_undef_indirect
:
18870 case DW_MACRO_GNU_define_indirect_alt
:
18871 case DW_MACRO_GNU_undef_indirect_alt
:
18873 unsigned int bytes_read
;
18875 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18876 mac_ptr
+= bytes_read
;
18877 mac_ptr
+= offset_size
;
18881 case DW_MACRO_GNU_transparent_include
:
18882 case DW_MACRO_GNU_transparent_include_alt
:
18883 /* Note that, according to the spec, a transparent include
18884 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18885 skip this opcode. */
18886 mac_ptr
+= offset_size
;
18889 case DW_MACINFO_vendor_ext
:
18890 /* Only skip the data by MAC_PTR. */
18891 if (!section_is_gnu
)
18893 unsigned int bytes_read
;
18895 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
18896 mac_ptr
+= bytes_read
;
18897 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
18898 mac_ptr
+= bytes_read
;
18903 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
18904 mac_ptr
, mac_end
, abfd
, offset_size
,
18906 if (mac_ptr
== NULL
)
18910 } while (macinfo_type
!= 0 && current_file
== NULL
);
18912 /* Second pass: Process all entries.
18914 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18915 command-line macro definitions/undefinitions. This flag is unset when we
18916 reach the first DW_MACINFO_start_file entry. */
18918 include_hash
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
18919 NULL
, xcalloc
, xfree
);
18920 cleanup
= make_cleanup_htab_delete (include_hash
);
18921 mac_ptr
= section
->buffer
+ offset
;
18922 slot
= htab_find_slot (include_hash
, mac_ptr
, INSERT
);
18924 dwarf_decode_macro_bytes (abfd
, mac_ptr
, mac_end
,
18925 current_file
, lh
, comp_dir
, section
,
18927 offset_size
, objfile
, include_hash
);
18928 do_cleanups (cleanup
);
18931 /* Check if the attribute's form is a DW_FORM_block*
18932 if so return true else false. */
18935 attr_form_is_block (struct attribute
*attr
)
18937 return (attr
== NULL
? 0 :
18938 attr
->form
== DW_FORM_block1
18939 || attr
->form
== DW_FORM_block2
18940 || attr
->form
== DW_FORM_block4
18941 || attr
->form
== DW_FORM_block
18942 || attr
->form
== DW_FORM_exprloc
);
18945 /* Return non-zero if ATTR's value is a section offset --- classes
18946 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18947 You may use DW_UNSND (attr) to retrieve such offsets.
18949 Section 7.5.4, "Attribute Encodings", explains that no attribute
18950 may have a value that belongs to more than one of these classes; it
18951 would be ambiguous if we did, because we use the same forms for all
18955 attr_form_is_section_offset (struct attribute
*attr
)
18957 return (attr
->form
== DW_FORM_data4
18958 || attr
->form
== DW_FORM_data8
18959 || attr
->form
== DW_FORM_sec_offset
);
18962 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18963 zero otherwise. When this function returns true, you can apply
18964 dwarf2_get_attr_constant_value to it.
18966 However, note that for some attributes you must check
18967 attr_form_is_section_offset before using this test. DW_FORM_data4
18968 and DW_FORM_data8 are members of both the constant class, and of
18969 the classes that contain offsets into other debug sections
18970 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18971 that, if an attribute's can be either a constant or one of the
18972 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18973 taken as section offsets, not constants. */
18976 attr_form_is_constant (struct attribute
*attr
)
18978 switch (attr
->form
)
18980 case DW_FORM_sdata
:
18981 case DW_FORM_udata
:
18982 case DW_FORM_data1
:
18983 case DW_FORM_data2
:
18984 case DW_FORM_data4
:
18985 case DW_FORM_data8
:
18992 /* Return the .debug_loc section to use for CU.
18993 For DWO files use .debug_loc.dwo. */
18995 static struct dwarf2_section_info
*
18996 cu_debug_loc_section (struct dwarf2_cu
*cu
)
18999 return &cu
->dwo_unit
->dwo_file
->sections
.loc
;
19000 return &dwarf2_per_objfile
->loc
;
19003 /* A helper function that fills in a dwarf2_loclist_baton. */
19006 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
19007 struct dwarf2_loclist_baton
*baton
,
19008 struct attribute
*attr
)
19010 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19012 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
19014 baton
->per_cu
= cu
->per_cu
;
19015 gdb_assert (baton
->per_cu
);
19016 /* We don't know how long the location list is, but make sure we
19017 don't run off the edge of the section. */
19018 baton
->size
= section
->size
- DW_UNSND (attr
);
19019 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
19020 baton
->base_address
= cu
->base_address
;
19021 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
19025 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
19026 struct dwarf2_cu
*cu
)
19028 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19029 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19031 if (attr_form_is_section_offset (attr
)
19032 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
19033 the section. If so, fall through to the complaint in the
19035 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
19037 struct dwarf2_loclist_baton
*baton
;
19039 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19040 sizeof (struct dwarf2_loclist_baton
));
19042 fill_in_loclist_baton (cu
, baton
, attr
);
19044 if (cu
->base_known
== 0)
19045 complaint (&symfile_complaints
,
19046 _("Location list used without "
19047 "specifying the CU base address."));
19049 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
19050 SYMBOL_LOCATION_BATON (sym
) = baton
;
19054 struct dwarf2_locexpr_baton
*baton
;
19056 baton
= obstack_alloc (&objfile
->objfile_obstack
,
19057 sizeof (struct dwarf2_locexpr_baton
));
19058 baton
->per_cu
= cu
->per_cu
;
19059 gdb_assert (baton
->per_cu
);
19061 if (attr_form_is_block (attr
))
19063 /* Note that we're just copying the block's data pointer
19064 here, not the actual data. We're still pointing into the
19065 info_buffer for SYM's objfile; right now we never release
19066 that buffer, but when we do clean up properly this may
19068 baton
->size
= DW_BLOCK (attr
)->size
;
19069 baton
->data
= DW_BLOCK (attr
)->data
;
19073 dwarf2_invalid_attrib_class_complaint ("location description",
19074 SYMBOL_NATURAL_NAME (sym
));
19078 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
19079 SYMBOL_LOCATION_BATON (sym
) = baton
;
19083 /* Return the OBJFILE associated with the compilation unit CU. If CU
19084 came from a separate debuginfo file, then the master objfile is
19088 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
19090 struct objfile
*objfile
= per_cu
->objfile
;
19092 /* Return the master objfile, so that we can report and look up the
19093 correct file containing this variable. */
19094 if (objfile
->separate_debug_objfile_backlink
)
19095 objfile
= objfile
->separate_debug_objfile_backlink
;
19100 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
19101 (CU_HEADERP is unused in such case) or prepare a temporary copy at
19102 CU_HEADERP first. */
19104 static const struct comp_unit_head
*
19105 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
19106 struct dwarf2_per_cu_data
*per_cu
)
19108 gdb_byte
*info_ptr
;
19111 return &per_cu
->cu
->header
;
19113 info_ptr
= per_cu
->info_or_types_section
->buffer
+ per_cu
->offset
.sect_off
;
19115 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
19116 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->objfile
->obfd
);
19121 /* Return the address size given in the compilation unit header for CU. */
19124 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19126 struct comp_unit_head cu_header_local
;
19127 const struct comp_unit_head
*cu_headerp
;
19129 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19131 return cu_headerp
->addr_size
;
19134 /* Return the offset size given in the compilation unit header for CU. */
19137 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
19139 struct comp_unit_head cu_header_local
;
19140 const struct comp_unit_head
*cu_headerp
;
19142 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19144 return cu_headerp
->offset_size
;
19147 /* See its dwarf2loc.h declaration. */
19150 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
19152 struct comp_unit_head cu_header_local
;
19153 const struct comp_unit_head
*cu_headerp
;
19155 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
19157 if (cu_headerp
->version
== 2)
19158 return cu_headerp
->addr_size
;
19160 return cu_headerp
->offset_size
;
19163 /* Return the text offset of the CU. The returned offset comes from
19164 this CU's objfile. If this objfile came from a separate debuginfo
19165 file, then the offset may be different from the corresponding
19166 offset in the parent objfile. */
19169 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
19171 struct objfile
*objfile
= per_cu
->objfile
;
19173 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
19176 /* Locate the .debug_info compilation unit from CU's objfile which contains
19177 the DIE at OFFSET. Raises an error on failure. */
19179 static struct dwarf2_per_cu_data
*
19180 dwarf2_find_containing_comp_unit (sect_offset offset
,
19181 unsigned int offset_in_dwz
,
19182 struct objfile
*objfile
)
19184 struct dwarf2_per_cu_data
*this_cu
;
19186 const sect_offset
*cu_off
;
19189 high
= dwarf2_per_objfile
->n_comp_units
- 1;
19192 struct dwarf2_per_cu_data
*mid_cu
;
19193 int mid
= low
+ (high
- low
) / 2;
19195 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
19196 cu_off
= &mid_cu
->offset
;
19197 if (mid_cu
->is_dwz
> offset_in_dwz
19198 || (mid_cu
->is_dwz
== offset_in_dwz
19199 && cu_off
->sect_off
>= offset
.sect_off
))
19204 gdb_assert (low
== high
);
19205 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19206 cu_off
= &this_cu
->offset
;
19207 if (this_cu
->is_dwz
!= offset_in_dwz
|| cu_off
->sect_off
> offset
.sect_off
)
19209 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
19210 error (_("Dwarf Error: could not find partial DIE containing "
19211 "offset 0x%lx [in module %s]"),
19212 (long) offset
.sect_off
, bfd_get_filename (objfile
->obfd
));
19214 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
.sect_off
19215 <= offset
.sect_off
);
19216 return dwarf2_per_objfile
->all_comp_units
[low
-1];
19220 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
19221 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
19222 && offset
.sect_off
>= this_cu
->offset
.sect_off
+ this_cu
->length
)
19223 error (_("invalid dwarf2 offset %u"), offset
.sect_off
);
19224 gdb_assert (offset
.sect_off
< this_cu
->offset
.sect_off
+ this_cu
->length
);
19229 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19232 init_one_comp_unit (struct dwarf2_cu
*cu
, struct dwarf2_per_cu_data
*per_cu
)
19234 memset (cu
, 0, sizeof (*cu
));
19236 cu
->per_cu
= per_cu
;
19237 cu
->objfile
= per_cu
->objfile
;
19238 obstack_init (&cu
->comp_unit_obstack
);
19241 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19244 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
19245 enum language pretend_language
)
19247 struct attribute
*attr
;
19249 /* Set the language we're debugging. */
19250 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
19252 set_cu_language (DW_UNSND (attr
), cu
);
19255 cu
->language
= pretend_language
;
19256 cu
->language_defn
= language_def (cu
->language
);
19259 attr
= dwarf2_attr (comp_unit_die
, DW_AT_producer
, cu
);
19261 cu
->producer
= DW_STRING (attr
);
19264 /* Release one cached compilation unit, CU. We unlink it from the tree
19265 of compilation units, but we don't remove it from the read_in_chain;
19266 the caller is responsible for that.
19267 NOTE: DATA is a void * because this function is also used as a
19268 cleanup routine. */
19271 free_heap_comp_unit (void *data
)
19273 struct dwarf2_cu
*cu
= data
;
19275 gdb_assert (cu
->per_cu
!= NULL
);
19276 cu
->per_cu
->cu
= NULL
;
19279 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19284 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19285 when we're finished with it. We can't free the pointer itself, but be
19286 sure to unlink it from the cache. Also release any associated storage. */
19289 free_stack_comp_unit (void *data
)
19291 struct dwarf2_cu
*cu
= data
;
19293 gdb_assert (cu
->per_cu
!= NULL
);
19294 cu
->per_cu
->cu
= NULL
;
19297 obstack_free (&cu
->comp_unit_obstack
, NULL
);
19298 cu
->partial_dies
= NULL
;
19301 /* Free all cached compilation units. */
19304 free_cached_comp_units (void *data
)
19306 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19308 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19309 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19310 while (per_cu
!= NULL
)
19312 struct dwarf2_per_cu_data
*next_cu
;
19314 next_cu
= per_cu
->cu
->read_in_chain
;
19316 free_heap_comp_unit (per_cu
->cu
);
19317 *last_chain
= next_cu
;
19323 /* Increase the age counter on each cached compilation unit, and free
19324 any that are too old. */
19327 age_cached_comp_units (void)
19329 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19331 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
19332 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19333 while (per_cu
!= NULL
)
19335 per_cu
->cu
->last_used
++;
19336 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
19337 dwarf2_mark (per_cu
->cu
);
19338 per_cu
= per_cu
->cu
->read_in_chain
;
19341 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19342 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19343 while (per_cu
!= NULL
)
19345 struct dwarf2_per_cu_data
*next_cu
;
19347 next_cu
= per_cu
->cu
->read_in_chain
;
19349 if (!per_cu
->cu
->mark
)
19351 free_heap_comp_unit (per_cu
->cu
);
19352 *last_chain
= next_cu
;
19355 last_chain
= &per_cu
->cu
->read_in_chain
;
19361 /* Remove a single compilation unit from the cache. */
19364 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
19366 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
19368 per_cu
= dwarf2_per_objfile
->read_in_chain
;
19369 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
19370 while (per_cu
!= NULL
)
19372 struct dwarf2_per_cu_data
*next_cu
;
19374 next_cu
= per_cu
->cu
->read_in_chain
;
19376 if (per_cu
== target_per_cu
)
19378 free_heap_comp_unit (per_cu
->cu
);
19380 *last_chain
= next_cu
;
19384 last_chain
= &per_cu
->cu
->read_in_chain
;
19390 /* Release all extra memory associated with OBJFILE. */
19393 dwarf2_free_objfile (struct objfile
*objfile
)
19395 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
19397 if (dwarf2_per_objfile
== NULL
)
19400 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19401 free_cached_comp_units (NULL
);
19403 if (dwarf2_per_objfile
->quick_file_names_table
)
19404 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
19406 /* Everything else should be on the objfile obstack. */
19409 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19410 We store these in a hash table separate from the DIEs, and preserve them
19411 when the DIEs are flushed out of cache.
19413 The CU "per_cu" pointer is needed because offset alone is not enough to
19414 uniquely identify the type. A file may have multiple .debug_types sections,
19415 or the type may come from a DWO file. We have to use something in
19416 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19417 routine, get_die_type_at_offset, from outside this file, and thus won't
19418 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19421 struct dwarf2_per_cu_offset_and_type
19423 const struct dwarf2_per_cu_data
*per_cu
;
19424 sect_offset offset
;
19428 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19431 per_cu_offset_and_type_hash (const void *item
)
19433 const struct dwarf2_per_cu_offset_and_type
*ofs
= item
;
19435 return (uintptr_t) ofs
->per_cu
+ ofs
->offset
.sect_off
;
19438 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19441 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
19443 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
= item_lhs
;
19444 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
= item_rhs
;
19446 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
19447 && ofs_lhs
->offset
.sect_off
== ofs_rhs
->offset
.sect_off
);
19450 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19451 table if necessary. For convenience, return TYPE.
19453 The DIEs reading must have careful ordering to:
19454 * Not cause infite loops trying to read in DIEs as a prerequisite for
19455 reading current DIE.
19456 * Not trying to dereference contents of still incompletely read in types
19457 while reading in other DIEs.
19458 * Enable referencing still incompletely read in types just by a pointer to
19459 the type without accessing its fields.
19461 Therefore caller should follow these rules:
19462 * Try to fetch any prerequisite types we may need to build this DIE type
19463 before building the type and calling set_die_type.
19464 * After building type call set_die_type for current DIE as soon as
19465 possible before fetching more types to complete the current type.
19466 * Make the type as complete as possible before fetching more types. */
19468 static struct type
*
19469 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
19471 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
19472 struct objfile
*objfile
= cu
->objfile
;
19474 /* For Ada types, make sure that the gnat-specific data is always
19475 initialized (if not already set). There are a few types where
19476 we should not be doing so, because the type-specific area is
19477 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19478 where the type-specific area is used to store the floatformat).
19479 But this is not a problem, because the gnat-specific information
19480 is actually not needed for these types. */
19481 if (need_gnat_info (cu
)
19482 && TYPE_CODE (type
) != TYPE_CODE_FUNC
19483 && TYPE_CODE (type
) != TYPE_CODE_FLT
19484 && !HAVE_GNAT_AUX_INFO (type
))
19485 INIT_GNAT_SPECIFIC (type
);
19487 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19489 dwarf2_per_objfile
->die_type_hash
=
19490 htab_create_alloc_ex (127,
19491 per_cu_offset_and_type_hash
,
19492 per_cu_offset_and_type_eq
,
19494 &objfile
->objfile_obstack
,
19495 hashtab_obstack_allocate
,
19496 dummy_obstack_deallocate
);
19499 ofs
.per_cu
= cu
->per_cu
;
19500 ofs
.offset
= die
->offset
;
19502 slot
= (struct dwarf2_per_cu_offset_and_type
**)
19503 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
19505 complaint (&symfile_complaints
,
19506 _("A problem internal to GDB: DIE 0x%x has type already set"),
19507 die
->offset
.sect_off
);
19508 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
19513 /* Look up the type for the die at OFFSET in the appropriate type_hash
19514 table, or return NULL if the die does not have a saved type. */
19516 static struct type
*
19517 get_die_type_at_offset (sect_offset offset
,
19518 struct dwarf2_per_cu_data
*per_cu
)
19520 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
19522 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
19525 ofs
.per_cu
= per_cu
;
19526 ofs
.offset
= offset
;
19527 slot
= htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
);
19534 /* Look up the type for DIE in the appropriate type_hash table,
19535 or return NULL if DIE does not have a saved type. */
19537 static struct type
*
19538 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19540 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
19543 /* Add a dependence relationship from CU to REF_PER_CU. */
19546 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
19547 struct dwarf2_per_cu_data
*ref_per_cu
)
19551 if (cu
->dependencies
== NULL
)
19553 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
19554 NULL
, &cu
->comp_unit_obstack
,
19555 hashtab_obstack_allocate
,
19556 dummy_obstack_deallocate
);
19558 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
19560 *slot
= ref_per_cu
;
19563 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19564 Set the mark field in every compilation unit in the
19565 cache that we must keep because we are keeping CU. */
19568 dwarf2_mark_helper (void **slot
, void *data
)
19570 struct dwarf2_per_cu_data
*per_cu
;
19572 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
19574 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19575 reading of the chain. As such dependencies remain valid it is not much
19576 useful to track and undo them during QUIT cleanups. */
19577 if (per_cu
->cu
== NULL
)
19580 if (per_cu
->cu
->mark
)
19582 per_cu
->cu
->mark
= 1;
19584 if (per_cu
->cu
->dependencies
!= NULL
)
19585 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19590 /* Set the mark field in CU and in every other compilation unit in the
19591 cache that we must keep because we are keeping CU. */
19594 dwarf2_mark (struct dwarf2_cu
*cu
)
19599 if (cu
->dependencies
!= NULL
)
19600 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
19604 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
19608 per_cu
->cu
->mark
= 0;
19609 per_cu
= per_cu
->cu
->read_in_chain
;
19613 /* Trivial hash function for partial_die_info: the hash value of a DIE
19614 is its offset in .debug_info for this objfile. */
19617 partial_die_hash (const void *item
)
19619 const struct partial_die_info
*part_die
= item
;
19621 return part_die
->offset
.sect_off
;
19624 /* Trivial comparison function for partial_die_info structures: two DIEs
19625 are equal if they have the same offset. */
19628 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
19630 const struct partial_die_info
*part_die_lhs
= item_lhs
;
19631 const struct partial_die_info
*part_die_rhs
= item_rhs
;
19633 return part_die_lhs
->offset
.sect_off
== part_die_rhs
->offset
.sect_off
;
19636 static struct cmd_list_element
*set_dwarf2_cmdlist
;
19637 static struct cmd_list_element
*show_dwarf2_cmdlist
;
19640 set_dwarf2_cmd (char *args
, int from_tty
)
19642 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
19646 show_dwarf2_cmd (char *args
, int from_tty
)
19648 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
19651 /* Free data associated with OBJFILE, if necessary. */
19654 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
19656 struct dwarf2_per_objfile
*data
= d
;
19659 for (ix
= 0; ix
< dwarf2_per_objfile
->n_comp_units
; ++ix
)
19660 VEC_free (dwarf2_per_cu_ptr
,
19661 dwarf2_per_objfile
->all_comp_units
[ix
]->imported_symtabs
);
19663 for (ix
= 0; ix
< dwarf2_per_objfile
->n_type_units
; ++ix
)
19664 VEC_free (dwarf2_per_cu_ptr
,
19665 dwarf2_per_objfile
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
19667 VEC_free (dwarf2_section_info_def
, data
->types
);
19669 if (data
->dwo_files
)
19670 free_dwo_files (data
->dwo_files
, objfile
);
19672 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
19673 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
19677 /* The "save gdb-index" command. */
19679 /* The contents of the hash table we create when building the string
19681 struct strtab_entry
19683 offset_type offset
;
19687 /* Hash function for a strtab_entry.
19689 Function is used only during write_hash_table so no index format backward
19690 compatibility is needed. */
19693 hash_strtab_entry (const void *e
)
19695 const struct strtab_entry
*entry
= e
;
19696 return mapped_index_string_hash (INT_MAX
, entry
->str
);
19699 /* Equality function for a strtab_entry. */
19702 eq_strtab_entry (const void *a
, const void *b
)
19704 const struct strtab_entry
*ea
= a
;
19705 const struct strtab_entry
*eb
= b
;
19706 return !strcmp (ea
->str
, eb
->str
);
19709 /* Create a strtab_entry hash table. */
19712 create_strtab (void)
19714 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
19715 xfree
, xcalloc
, xfree
);
19718 /* Add a string to the constant pool. Return the string's offset in
19722 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
19725 struct strtab_entry entry
;
19726 struct strtab_entry
*result
;
19729 slot
= htab_find_slot (table
, &entry
, INSERT
);
19734 result
= XNEW (struct strtab_entry
);
19735 result
->offset
= obstack_object_size (cpool
);
19737 obstack_grow_str0 (cpool
, str
);
19740 return result
->offset
;
19743 /* An entry in the symbol table. */
19744 struct symtab_index_entry
19746 /* The name of the symbol. */
19748 /* The offset of the name in the constant pool. */
19749 offset_type index_offset
;
19750 /* A sorted vector of the indices of all the CUs that hold an object
19752 VEC (offset_type
) *cu_indices
;
19755 /* The symbol table. This is a power-of-2-sized hash table. */
19756 struct mapped_symtab
19758 offset_type n_elements
;
19760 struct symtab_index_entry
**data
;
19763 /* Hash function for a symtab_index_entry. */
19766 hash_symtab_entry (const void *e
)
19768 const struct symtab_index_entry
*entry
= e
;
19769 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
19770 sizeof (offset_type
) * VEC_length (offset_type
,
19771 entry
->cu_indices
),
19775 /* Equality function for a symtab_index_entry. */
19778 eq_symtab_entry (const void *a
, const void *b
)
19780 const struct symtab_index_entry
*ea
= a
;
19781 const struct symtab_index_entry
*eb
= b
;
19782 int len
= VEC_length (offset_type
, ea
->cu_indices
);
19783 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
19785 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
19786 VEC_address (offset_type
, eb
->cu_indices
),
19787 sizeof (offset_type
) * len
);
19790 /* Destroy a symtab_index_entry. */
19793 delete_symtab_entry (void *p
)
19795 struct symtab_index_entry
*entry
= p
;
19796 VEC_free (offset_type
, entry
->cu_indices
);
19800 /* Create a hash table holding symtab_index_entry objects. */
19803 create_symbol_hash_table (void)
19805 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
19806 delete_symtab_entry
, xcalloc
, xfree
);
19809 /* Create a new mapped symtab object. */
19811 static struct mapped_symtab
*
19812 create_mapped_symtab (void)
19814 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
19815 symtab
->n_elements
= 0;
19816 symtab
->size
= 1024;
19817 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19821 /* Destroy a mapped_symtab. */
19824 cleanup_mapped_symtab (void *p
)
19826 struct mapped_symtab
*symtab
= p
;
19827 /* The contents of the array are freed when the other hash table is
19829 xfree (symtab
->data
);
19833 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19836 Function is used only during write_hash_table so no index format backward
19837 compatibility is needed. */
19839 static struct symtab_index_entry
**
19840 find_slot (struct mapped_symtab
*symtab
, const char *name
)
19842 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
19844 index
= hash
& (symtab
->size
- 1);
19845 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
19849 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
19850 return &symtab
->data
[index
];
19851 index
= (index
+ step
) & (symtab
->size
- 1);
19855 /* Expand SYMTAB's hash table. */
19858 hash_expand (struct mapped_symtab
*symtab
)
19860 offset_type old_size
= symtab
->size
;
19862 struct symtab_index_entry
**old_entries
= symtab
->data
;
19865 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
19867 for (i
= 0; i
< old_size
; ++i
)
19869 if (old_entries
[i
])
19871 struct symtab_index_entry
**slot
= find_slot (symtab
,
19872 old_entries
[i
]->name
);
19873 *slot
= old_entries
[i
];
19877 xfree (old_entries
);
19880 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19881 CU_INDEX is the index of the CU in which the symbol appears.
19882 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19885 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
19886 int is_static
, gdb_index_symbol_kind kind
,
19887 offset_type cu_index
)
19889 struct symtab_index_entry
**slot
;
19890 offset_type cu_index_and_attrs
;
19892 ++symtab
->n_elements
;
19893 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
19894 hash_expand (symtab
);
19896 slot
= find_slot (symtab
, name
);
19899 *slot
= XNEW (struct symtab_index_entry
);
19900 (*slot
)->name
= name
;
19901 /* index_offset is set later. */
19902 (*slot
)->cu_indices
= NULL
;
19905 cu_index_and_attrs
= 0;
19906 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
19907 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
19908 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
19910 /* We don't want to record an index value twice as we want to avoid the
19912 We process all global symbols and then all static symbols
19913 (which would allow us to avoid the duplication by only having to check
19914 the last entry pushed), but a symbol could have multiple kinds in one CU.
19915 To keep things simple we don't worry about the duplication here and
19916 sort and uniqufy the list after we've processed all symbols. */
19917 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index_and_attrs
);
19920 /* qsort helper routine for uniquify_cu_indices. */
19923 offset_type_compare (const void *ap
, const void *bp
)
19925 offset_type a
= *(offset_type
*) ap
;
19926 offset_type b
= *(offset_type
*) bp
;
19928 return (a
> b
) - (b
> a
);
19931 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19934 uniquify_cu_indices (struct mapped_symtab
*symtab
)
19938 for (i
= 0; i
< symtab
->size
; ++i
)
19940 struct symtab_index_entry
*entry
= symtab
->data
[i
];
19943 && entry
->cu_indices
!= NULL
)
19945 unsigned int next_to_insert
, next_to_check
;
19946 offset_type last_value
;
19948 qsort (VEC_address (offset_type
, entry
->cu_indices
),
19949 VEC_length (offset_type
, entry
->cu_indices
),
19950 sizeof (offset_type
), offset_type_compare
);
19952 last_value
= VEC_index (offset_type
, entry
->cu_indices
, 0);
19953 next_to_insert
= 1;
19954 for (next_to_check
= 1;
19955 next_to_check
< VEC_length (offset_type
, entry
->cu_indices
);
19958 if (VEC_index (offset_type
, entry
->cu_indices
, next_to_check
)
19961 last_value
= VEC_index (offset_type
, entry
->cu_indices
,
19963 VEC_replace (offset_type
, entry
->cu_indices
, next_to_insert
,
19968 VEC_truncate (offset_type
, entry
->cu_indices
, next_to_insert
);
19973 /* Add a vector of indices to the constant pool. */
19976 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
19977 struct symtab_index_entry
*entry
)
19981 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
19984 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
19985 offset_type val
= MAYBE_SWAP (len
);
19990 entry
->index_offset
= obstack_object_size (cpool
);
19992 obstack_grow (cpool
, &val
, sizeof (val
));
19994 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
19997 val
= MAYBE_SWAP (iter
);
19998 obstack_grow (cpool
, &val
, sizeof (val
));
20003 struct symtab_index_entry
*old_entry
= *slot
;
20004 entry
->index_offset
= old_entry
->index_offset
;
20007 return entry
->index_offset
;
20010 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
20011 constant pool entries going into the obstack CPOOL. */
20014 write_hash_table (struct mapped_symtab
*symtab
,
20015 struct obstack
*output
, struct obstack
*cpool
)
20018 htab_t symbol_hash_table
;
20021 symbol_hash_table
= create_symbol_hash_table ();
20022 str_table
= create_strtab ();
20024 /* We add all the index vectors to the constant pool first, to
20025 ensure alignment is ok. */
20026 for (i
= 0; i
< symtab
->size
; ++i
)
20028 if (symtab
->data
[i
])
20029 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
20032 /* Now write out the hash table. */
20033 for (i
= 0; i
< symtab
->size
; ++i
)
20035 offset_type str_off
, vec_off
;
20037 if (symtab
->data
[i
])
20039 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
20040 vec_off
= symtab
->data
[i
]->index_offset
;
20044 /* While 0 is a valid constant pool index, it is not valid
20045 to have 0 for both offsets. */
20050 str_off
= MAYBE_SWAP (str_off
);
20051 vec_off
= MAYBE_SWAP (vec_off
);
20053 obstack_grow (output
, &str_off
, sizeof (str_off
));
20054 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
20057 htab_delete (str_table
);
20058 htab_delete (symbol_hash_table
);
20061 /* Struct to map psymtab to CU index in the index file. */
20062 struct psymtab_cu_index_map
20064 struct partial_symtab
*psymtab
;
20065 unsigned int cu_index
;
20069 hash_psymtab_cu_index (const void *item
)
20071 const struct psymtab_cu_index_map
*map
= item
;
20073 return htab_hash_pointer (map
->psymtab
);
20077 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
20079 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
20080 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
20082 return lhs
->psymtab
== rhs
->psymtab
;
20085 /* Helper struct for building the address table. */
20086 struct addrmap_index_data
20088 struct objfile
*objfile
;
20089 struct obstack
*addr_obstack
;
20090 htab_t cu_index_htab
;
20092 /* Non-zero if the previous_* fields are valid.
20093 We can't write an entry until we see the next entry (since it is only then
20094 that we know the end of the entry). */
20095 int previous_valid
;
20096 /* Index of the CU in the table of all CUs in the index file. */
20097 unsigned int previous_cu_index
;
20098 /* Start address of the CU. */
20099 CORE_ADDR previous_cu_start
;
20102 /* Write an address entry to OBSTACK. */
20105 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
20106 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
20108 offset_type cu_index_to_write
;
20110 CORE_ADDR baseaddr
;
20112 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20114 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
20115 obstack_grow (obstack
, addr
, 8);
20116 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
20117 obstack_grow (obstack
, addr
, 8);
20118 cu_index_to_write
= MAYBE_SWAP (cu_index
);
20119 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
20122 /* Worker function for traversing an addrmap to build the address table. */
20125 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
20127 struct addrmap_index_data
*data
= datap
;
20128 struct partial_symtab
*pst
= obj
;
20130 if (data
->previous_valid
)
20131 add_address_entry (data
->objfile
, data
->addr_obstack
,
20132 data
->previous_cu_start
, start_addr
,
20133 data
->previous_cu_index
);
20135 data
->previous_cu_start
= start_addr
;
20138 struct psymtab_cu_index_map find_map
, *map
;
20139 find_map
.psymtab
= pst
;
20140 map
= htab_find (data
->cu_index_htab
, &find_map
);
20141 gdb_assert (map
!= NULL
);
20142 data
->previous_cu_index
= map
->cu_index
;
20143 data
->previous_valid
= 1;
20146 data
->previous_valid
= 0;
20151 /* Write OBJFILE's address map to OBSTACK.
20152 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20153 in the index file. */
20156 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
20157 htab_t cu_index_htab
)
20159 struct addrmap_index_data addrmap_index_data
;
20161 /* When writing the address table, we have to cope with the fact that
20162 the addrmap iterator only provides the start of a region; we have to
20163 wait until the next invocation to get the start of the next region. */
20165 addrmap_index_data
.objfile
= objfile
;
20166 addrmap_index_data
.addr_obstack
= obstack
;
20167 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
20168 addrmap_index_data
.previous_valid
= 0;
20170 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
20171 &addrmap_index_data
);
20173 /* It's highly unlikely the last entry (end address = 0xff...ff)
20174 is valid, but we should still handle it.
20175 The end address is recorded as the start of the next region, but that
20176 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20178 if (addrmap_index_data
.previous_valid
)
20179 add_address_entry (objfile
, obstack
,
20180 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
20181 addrmap_index_data
.previous_cu_index
);
20184 /* Return the symbol kind of PSYM. */
20186 static gdb_index_symbol_kind
20187 symbol_kind (struct partial_symbol
*psym
)
20189 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
20190 enum address_class aclass
= PSYMBOL_CLASS (psym
);
20198 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
20200 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20202 case LOC_CONST_BYTES
:
20203 case LOC_OPTIMIZED_OUT
:
20205 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20207 /* Note: It's currently impossible to recognize psyms as enum values
20208 short of reading the type info. For now punt. */
20209 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
20211 /* There are other LOC_FOO values that one might want to classify
20212 as variables, but dwarf2read.c doesn't currently use them. */
20213 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20215 case STRUCT_DOMAIN
:
20216 return GDB_INDEX_SYMBOL_KIND_TYPE
;
20218 return GDB_INDEX_SYMBOL_KIND_OTHER
;
20222 /* Add a list of partial symbols to SYMTAB. */
20225 write_psymbols (struct mapped_symtab
*symtab
,
20227 struct partial_symbol
**psymp
,
20229 offset_type cu_index
,
20232 for (; count
-- > 0; ++psymp
)
20234 struct partial_symbol
*psym
= *psymp
;
20237 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
20238 error (_("Ada is not currently supported by the index"));
20240 /* Only add a given psymbol once. */
20241 slot
= htab_find_slot (psyms_seen
, psym
, INSERT
);
20244 gdb_index_symbol_kind kind
= symbol_kind (psym
);
20247 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
20248 is_static
, kind
, cu_index
);
20253 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20254 exception if there is an error. */
20257 write_obstack (FILE *file
, struct obstack
*obstack
)
20259 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
20261 != obstack_object_size (obstack
))
20262 error (_("couldn't data write to file"));
20265 /* Unlink a file if the argument is not NULL. */
20268 unlink_if_set (void *p
)
20270 char **filename
= p
;
20272 unlink (*filename
);
20275 /* A helper struct used when iterating over debug_types. */
20276 struct signatured_type_index_data
20278 struct objfile
*objfile
;
20279 struct mapped_symtab
*symtab
;
20280 struct obstack
*types_list
;
20285 /* A helper function that writes a single signatured_type to an
20289 write_one_signatured_type (void **slot
, void *d
)
20291 struct signatured_type_index_data
*info
= d
;
20292 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
20293 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
20294 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20297 write_psymbols (info
->symtab
,
20299 info
->objfile
->global_psymbols
.list
20300 + psymtab
->globals_offset
,
20301 psymtab
->n_global_syms
, info
->cu_index
,
20303 write_psymbols (info
->symtab
,
20305 info
->objfile
->static_psymbols
.list
20306 + psymtab
->statics_offset
,
20307 psymtab
->n_static_syms
, info
->cu_index
,
20310 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20311 entry
->per_cu
.offset
.sect_off
);
20312 obstack_grow (info
->types_list
, val
, 8);
20313 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20314 entry
->type_offset_in_tu
.cu_off
);
20315 obstack_grow (info
->types_list
, val
, 8);
20316 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
20317 obstack_grow (info
->types_list
, val
, 8);
20324 /* Recurse into all "included" dependencies and write their symbols as
20325 if they appeared in this psymtab. */
20328 recursively_write_psymbols (struct objfile
*objfile
,
20329 struct partial_symtab
*psymtab
,
20330 struct mapped_symtab
*symtab
,
20332 offset_type cu_index
)
20336 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
20337 if (psymtab
->dependencies
[i
]->user
!= NULL
)
20338 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
20339 symtab
, psyms_seen
, cu_index
);
20341 write_psymbols (symtab
,
20343 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
20344 psymtab
->n_global_syms
, cu_index
,
20346 write_psymbols (symtab
,
20348 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
20349 psymtab
->n_static_syms
, cu_index
,
20353 /* Create an index file for OBJFILE in the directory DIR. */
20356 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
20358 struct cleanup
*cleanup
;
20359 char *filename
, *cleanup_filename
;
20360 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
20361 struct obstack cu_list
, types_cu_list
;
20364 struct mapped_symtab
*symtab
;
20365 offset_type val
, size_of_contents
, total_len
;
20368 htab_t cu_index_htab
;
20369 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
20371 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
20374 if (dwarf2_per_objfile
->using_index
)
20375 error (_("Cannot use an index to create the index"));
20377 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
20378 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20380 if (stat (objfile
->name
, &st
) < 0)
20381 perror_with_name (objfile
->name
);
20383 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
20384 INDEX_SUFFIX
, (char *) NULL
);
20385 cleanup
= make_cleanup (xfree
, filename
);
20387 out_file
= fopen (filename
, "wb");
20389 error (_("Can't open `%s' for writing"), filename
);
20391 cleanup_filename
= filename
;
20392 make_cleanup (unlink_if_set
, &cleanup_filename
);
20394 symtab
= create_mapped_symtab ();
20395 make_cleanup (cleanup_mapped_symtab
, symtab
);
20397 obstack_init (&addr_obstack
);
20398 make_cleanup_obstack_free (&addr_obstack
);
20400 obstack_init (&cu_list
);
20401 make_cleanup_obstack_free (&cu_list
);
20403 obstack_init (&types_cu_list
);
20404 make_cleanup_obstack_free (&types_cu_list
);
20406 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
20407 NULL
, xcalloc
, xfree
);
20408 make_cleanup_htab_delete (psyms_seen
);
20410 /* While we're scanning CU's create a table that maps a psymtab pointer
20411 (which is what addrmap records) to its index (which is what is recorded
20412 in the index file). This will later be needed to write the address
20414 cu_index_htab
= htab_create_alloc (100,
20415 hash_psymtab_cu_index
,
20416 eq_psymtab_cu_index
,
20417 NULL
, xcalloc
, xfree
);
20418 make_cleanup_htab_delete (cu_index_htab
);
20419 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
20420 xmalloc (sizeof (struct psymtab_cu_index_map
)
20421 * dwarf2_per_objfile
->n_comp_units
);
20422 make_cleanup (xfree
, psymtab_cu_index_map
);
20424 /* The CU list is already sorted, so we don't need to do additional
20425 work here. Also, the debug_types entries do not appear in
20426 all_comp_units, but only in their own hash table. */
20427 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
20429 struct dwarf2_per_cu_data
*per_cu
20430 = dwarf2_per_objfile
->all_comp_units
[i
];
20431 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
20433 struct psymtab_cu_index_map
*map
;
20436 if (psymtab
->user
== NULL
)
20437 recursively_write_psymbols (objfile
, psymtab
, symtab
, psyms_seen
, i
);
20439 map
= &psymtab_cu_index_map
[i
];
20440 map
->psymtab
= psymtab
;
20442 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
20443 gdb_assert (slot
!= NULL
);
20444 gdb_assert (*slot
== NULL
);
20447 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
,
20448 per_cu
->offset
.sect_off
);
20449 obstack_grow (&cu_list
, val
, 8);
20450 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
20451 obstack_grow (&cu_list
, val
, 8);
20454 /* Dump the address map. */
20455 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
20457 /* Write out the .debug_type entries, if any. */
20458 if (dwarf2_per_objfile
->signatured_types
)
20460 struct signatured_type_index_data sig_data
;
20462 sig_data
.objfile
= objfile
;
20463 sig_data
.symtab
= symtab
;
20464 sig_data
.types_list
= &types_cu_list
;
20465 sig_data
.psyms_seen
= psyms_seen
;
20466 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
20467 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
20468 write_one_signatured_type
, &sig_data
);
20471 /* Now that we've processed all symbols we can shrink their cu_indices
20473 uniquify_cu_indices (symtab
);
20475 obstack_init (&constant_pool
);
20476 make_cleanup_obstack_free (&constant_pool
);
20477 obstack_init (&symtab_obstack
);
20478 make_cleanup_obstack_free (&symtab_obstack
);
20479 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
20481 obstack_init (&contents
);
20482 make_cleanup_obstack_free (&contents
);
20483 size_of_contents
= 6 * sizeof (offset_type
);
20484 total_len
= size_of_contents
;
20486 /* The version number. */
20487 val
= MAYBE_SWAP (8);
20488 obstack_grow (&contents
, &val
, sizeof (val
));
20490 /* The offset of the CU list from the start of the file. */
20491 val
= MAYBE_SWAP (total_len
);
20492 obstack_grow (&contents
, &val
, sizeof (val
));
20493 total_len
+= obstack_object_size (&cu_list
);
20495 /* The offset of the types CU list from the start of the file. */
20496 val
= MAYBE_SWAP (total_len
);
20497 obstack_grow (&contents
, &val
, sizeof (val
));
20498 total_len
+= obstack_object_size (&types_cu_list
);
20500 /* The offset of the address table from the start of the file. */
20501 val
= MAYBE_SWAP (total_len
);
20502 obstack_grow (&contents
, &val
, sizeof (val
));
20503 total_len
+= obstack_object_size (&addr_obstack
);
20505 /* The offset of the symbol table from the start of the file. */
20506 val
= MAYBE_SWAP (total_len
);
20507 obstack_grow (&contents
, &val
, sizeof (val
));
20508 total_len
+= obstack_object_size (&symtab_obstack
);
20510 /* The offset of the constant pool from the start of the file. */
20511 val
= MAYBE_SWAP (total_len
);
20512 obstack_grow (&contents
, &val
, sizeof (val
));
20513 total_len
+= obstack_object_size (&constant_pool
);
20515 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
20517 write_obstack (out_file
, &contents
);
20518 write_obstack (out_file
, &cu_list
);
20519 write_obstack (out_file
, &types_cu_list
);
20520 write_obstack (out_file
, &addr_obstack
);
20521 write_obstack (out_file
, &symtab_obstack
);
20522 write_obstack (out_file
, &constant_pool
);
20526 /* We want to keep the file, so we set cleanup_filename to NULL
20527 here. See unlink_if_set. */
20528 cleanup_filename
= NULL
;
20530 do_cleanups (cleanup
);
20533 /* Implementation of the `save gdb-index' command.
20535 Note that the file format used by this command is documented in the
20536 GDB manual. Any changes here must be documented there. */
20539 save_gdb_index_command (char *arg
, int from_tty
)
20541 struct objfile
*objfile
;
20544 error (_("usage: save gdb-index DIRECTORY"));
20546 ALL_OBJFILES (objfile
)
20550 /* If the objfile does not correspond to an actual file, skip it. */
20551 if (stat (objfile
->name
, &st
) < 0)
20554 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
20555 if (dwarf2_per_objfile
)
20557 volatile struct gdb_exception except
;
20559 TRY_CATCH (except
, RETURN_MASK_ERROR
)
20561 write_psymtabs_to_index (objfile
, arg
);
20563 if (except
.reason
< 0)
20564 exception_fprintf (gdb_stderr
, except
,
20565 _("Error while writing index for `%s': "),
20573 int dwarf2_always_disassemble
;
20576 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
20577 struct cmd_list_element
*c
, const char *value
)
20579 fprintf_filtered (file
,
20580 _("Whether to always disassemble "
20581 "DWARF expressions is %s.\n"),
20586 show_check_physname (struct ui_file
*file
, int from_tty
,
20587 struct cmd_list_element
*c
, const char *value
)
20589 fprintf_filtered (file
,
20590 _("Whether to check \"physname\" is %s.\n"),
20594 void _initialize_dwarf2_read (void);
20597 _initialize_dwarf2_read (void)
20599 struct cmd_list_element
*c
;
20601 dwarf2_objfile_data_key
20602 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
20604 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
20605 Set DWARF 2 specific variables.\n\
20606 Configure DWARF 2 variables such as the cache size"),
20607 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
20608 0/*allow-unknown*/, &maintenance_set_cmdlist
);
20610 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
20611 Show DWARF 2 specific variables\n\
20612 Show DWARF 2 variables such as the cache size"),
20613 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
20614 0/*allow-unknown*/, &maintenance_show_cmdlist
);
20616 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
20617 &dwarf2_max_cache_age
, _("\
20618 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20619 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20620 A higher limit means that cached compilation units will be stored\n\
20621 in memory longer, and more total memory will be used. Zero disables\n\
20622 caching, which can slow down startup."),
20624 show_dwarf2_max_cache_age
,
20625 &set_dwarf2_cmdlist
,
20626 &show_dwarf2_cmdlist
);
20628 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
20629 &dwarf2_always_disassemble
, _("\
20630 Set whether `info address' always disassembles DWARF expressions."), _("\
20631 Show whether `info address' always disassembles DWARF expressions."), _("\
20632 When enabled, DWARF expressions are always printed in an assembly-like\n\
20633 syntax. When disabled, expressions will be printed in a more\n\
20634 conversational style, when possible."),
20636 show_dwarf2_always_disassemble
,
20637 &set_dwarf2_cmdlist
,
20638 &show_dwarf2_cmdlist
);
20640 add_setshow_boolean_cmd ("dwarf2-read", no_class
, &dwarf2_read_debug
, _("\
20641 Set debugging of the dwarf2 reader."), _("\
20642 Show debugging of the dwarf2 reader."), _("\
20643 When enabled, debugging messages are printed during dwarf2 reading\n\
20644 and symtab expansion."),
20647 &setdebuglist
, &showdebuglist
);
20649 add_setshow_zuinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
20650 Set debugging of the dwarf2 DIE reader."), _("\
20651 Show debugging of the dwarf2 DIE reader."), _("\
20652 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20653 The value is the maximum depth to print."),
20656 &setdebuglist
, &showdebuglist
);
20658 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
20659 Set cross-checking of \"physname\" code against demangler."), _("\
20660 Show cross-checking of \"physname\" code against demangler."), _("\
20661 When enabled, GDB's internal \"physname\" code is checked against\n\
20663 NULL
, show_check_physname
,
20664 &setdebuglist
, &showdebuglist
);
20666 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20667 no_class
, &use_deprecated_index_sections
, _("\
20668 Set whether to use deprecated gdb_index sections."), _("\
20669 Show whether to use deprecated gdb_index sections."), _("\
20670 When enabled, deprecated .gdb_index sections are used anyway.\n\
20671 Normally they are ignored either because of a missing feature or\n\
20672 performance issue.\n\
20673 Warning: This option must be enabled before gdb reads the file."),
20676 &setlist
, &showlist
);
20678 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
20680 Save a gdb-index file.\n\
20681 Usage: save gdb-index DIRECTORY"),
20683 set_cmd_completer (c
, filename_completer
);